From 8ef802b0b8fad5f750accda533b65533fabbdc61 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:05:23 -0400 Subject: [PATCH 0001/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index 663f0ba3..7fb1f6d0 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -27,8 +27,8 @@ 10 10 - 721 - 501 + 831 + 581 @@ -71,7 +71,7 @@ 10 460 - 701 + 717 30 @@ -92,9 +92,9 @@ 560 - 20 + 18 161 - 391 + 431 @@ -110,8 +110,8 @@ - 595 - 420 + 625 + 520 100 30 From c8115c25906cce4ba090719d7bc6f4fb4e14454e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:10:53 -0400 Subject: [PATCH 0002/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index 7fb1f6d0..7403c95e 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -111,7 +111,7 @@ 625 - 520 + 500 100 30 From 2144e307823f3e36a0b6219ba2fecbd4101a461c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:36:43 -0400 Subject: [PATCH 0003/1324] Add files via upload --- src/qt/res/icons/crownium/chat.png | Bin 0 -> 1039 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/crownium/chat.png diff --git a/src/qt/res/icons/crownium/chat.png b/src/qt/res/icons/crownium/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..062143454d03d156cc938a2467b36a563e37733e GIT binary patch literal 1039 zcmV+q1n~QbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1EfhrK~z{rwU^s( z3~?04&u{F^cDEH05hXRWq;5e%(rUYe5(M#B9z3X9QV|abO(b4~xU?_AgM_NYi$6dR zs%f?~R>Y+U&8Cz2SX>jBH80d=>G~>2BytCJLL?)%YwtQYkS8Y+ zy=^SH`@9fG9k*h!TF=2bh9N^NwqBiE6)U;d=SET~ zYze6IS9Za`zzUN2C0O`SdlwFo5@aj^ANjZi=fnnT)bh|BQi9YB@HPLjXV)K+0{`MN zm=Gu+<&HIELj37lQqGu77lWU+RmZuVN`P-TJYuP6JouzTb)-g4yyZ6h4!8L%gECy+PxVnmc%n28-s&^FYz>(eF2i-q`R7QrR69?qK$pjpN6-YS91 z<_1a;0Y#^ za2z>DmUX<0{Qpk@cCX@{2Y5gp*bV0M-4k!25Z=A=dz$2!;WObldVj%y7JXF2%~TyQ zPc=^=GcPy>N0bY#saUB5M3088Gs$s-1p>FCo5}}C+Uuw~Z)GR%UP Date: Thu, 4 Jun 2020 15:37:01 -0400 Subject: [PATCH 0004/1324] Add files via upload --- src/qt/res/icons/drkblue/chat.png | Bin 0 -> 1039 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/drkblue/chat.png diff --git a/src/qt/res/icons/drkblue/chat.png b/src/qt/res/icons/drkblue/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..062143454d03d156cc938a2467b36a563e37733e GIT binary patch literal 1039 zcmV+q1n~QbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1EfhrK~z{rwU^s( z3~?04&u{F^cDEH05hXRWq;5e%(rUYe5(M#B9z3X9QV|abO(b4~xU?_AgM_NYi$6dR zs%f?~R>Y+U&8Cz2SX>jBH80d=>G~>2BytCJLL?)%YwtQYkS8Y+ zy=^SH`@9fG9k*h!TF=2bh9N^NwqBiE6)U;d=SET~ zYze6IS9Za`zzUN2C0O`SdlwFo5@aj^ANjZi=fnnT)bh|BQi9YB@HPLjXV)K+0{`MN zm=Gu+<&HIELj37lQqGu77lWU+RmZuVN`P-TJYuP6JouzTb)-g4yyZ6h4!8L%gECy+PxVnmc%n28-s&^FYz>(eF2i-q`R7QrR69?qK$pjpN6-YS91 z<_1a;0Y#^ za2z>DmUX<0{Qpk@cCX@{2Y5gp*bV0M-4k!25Z=A=dz$2!;WObldVj%y7JXF2%~TyQ zPc=^=GcPy>N0bY#saUB5M3088Gs$s-1p>FCo5}}C+Uuw~Z)GR%UP Date: Thu, 4 Jun 2020 15:37:17 -0400 Subject: [PATCH 0005/1324] Add files via upload --- src/qt/res/icons/light-retro/chat.png | Bin 0 -> 1039 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/light-retro/chat.png diff --git a/src/qt/res/icons/light-retro/chat.png b/src/qt/res/icons/light-retro/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..062143454d03d156cc938a2467b36a563e37733e GIT binary patch literal 1039 zcmV+q1n~QbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1EfhrK~z{rwU^s( z3~?04&u{F^cDEH05hXRWq;5e%(rUYe5(M#B9z3X9QV|abO(b4~xU?_AgM_NYi$6dR zs%f?~R>Y+U&8Cz2SX>jBH80d=>G~>2BytCJLL?)%YwtQYkS8Y+ zy=^SH`@9fG9k*h!TF=2bh9N^NwqBiE6)U;d=SET~ zYze6IS9Za`zzUN2C0O`SdlwFo5@aj^ANjZi=fnnT)bh|BQi9YB@HPLjXV)K+0{`MN zm=Gu+<&HIELj37lQqGu77lWU+RmZuVN`P-TJYuP6JouzTb)-g4yyZ6h4!8L%gECy+PxVnmc%n28-s&^FYz>(eF2i-q`R7QrR69?qK$pjpN6-YS91 z<_1a;0Y#^ za2z>DmUX<0{Qpk@cCX@{2Y5gp*bV0M-4k!25Z=A=dz$2!;WObldVj%y7JXF2%~TyQ zPc=^=GcPy>N0bY#saUB5M3088Gs$s-1p>FCo5}}C+Uuw~Z)GR%UP Date: Thu, 4 Jun 2020 15:37:37 -0400 Subject: [PATCH 0006/1324] Add files via upload --- src/qt/res/icons/light/chat.png | Bin 0 -> 1039 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/light/chat.png diff --git a/src/qt/res/icons/light/chat.png b/src/qt/res/icons/light/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..062143454d03d156cc938a2467b36a563e37733e GIT binary patch literal 1039 zcmV+q1n~QbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1EfhrK~z{rwU^s( z3~?04&u{F^cDEH05hXRWq;5e%(rUYe5(M#B9z3X9QV|abO(b4~xU?_AgM_NYi$6dR zs%f?~R>Y+U&8Cz2SX>jBH80d=>G~>2BytCJLL?)%YwtQYkS8Y+ zy=^SH`@9fG9k*h!TF=2bh9N^NwqBiE6)U;d=SET~ zYze6IS9Za`zzUN2C0O`SdlwFo5@aj^ANjZi=fnnT)bh|BQi9YB@HPLjXV)K+0{`MN zm=Gu+<&HIELj37lQqGu77lWU+RmZuVN`P-TJYuP6JouzTb)-g4yyZ6h4!8L%gECy+PxVnmc%n28-s&^FYz>(eF2i-q`R7QrR69?qK$pjpN6-YS91 z<_1a;0Y#^ za2z>DmUX<0{Qpk@cCX@{2Y5gp*bV0M-4k!25Z=A=dz$2!;WObldVj%y7JXF2%~TyQ zPc=^=GcPy>N0bY#saUB5M3088Gs$s-1p>FCo5}}C+Uuw~Z)GR%UP Date: Thu, 4 Jun 2020 15:37:57 -0400 Subject: [PATCH 0007/1324] Add files via upload --- src/qt/res/icons/trad/chat.png | Bin 0 -> 1039 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/trad/chat.png diff --git a/src/qt/res/icons/trad/chat.png b/src/qt/res/icons/trad/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..062143454d03d156cc938a2467b36a563e37733e GIT binary patch literal 1039 zcmV+q1n~QbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1EfhrK~z{rwU^s( z3~?04&u{F^cDEH05hXRWq;5e%(rUYe5(M#B9z3X9QV|abO(b4~xU?_AgM_NYi$6dR zs%f?~R>Y+U&8Cz2SX>jBH80d=>G~>2BytCJLL?)%YwtQYkS8Y+ zy=^SH`@9fG9k*h!TF=2bh9N^NwqBiE6)U;d=SET~ zYze6IS9Za`zzUN2C0O`SdlwFo5@aj^ANjZi=fnnT)bh|BQi9YB@HPLjXV)K+0{`MN zm=Gu+<&HIELj37lQqGu77lWU+RmZuVN`P-TJYuP6JouzTb)-g4yyZ6h4!8L%gECy+PxVnmc%n28-s&^FYz>(eF2i-q`R7QrR69?qK$pjpN6-YS91 z<_1a;0Y#^ za2z>DmUX<0{Qpk@cCX@{2Y5gp*bV0M-4k!25Z=A=dz$2!;WObldVj%y7JXF2%~TyQ zPc=^=GcPy>N0bY#saUB5M3088Gs$s-1p>FCo5}}C+Uuw~Z)GR%UP Date: Thu, 4 Jun 2020 15:39:00 -0400 Subject: [PATCH 0008/1324] Add files via upload From f2faccf07a30a15740e8139699d577fc456b451c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:39:53 -0400 Subject: [PATCH 0009/1324] Delete hd_disabled.png --- src/qt/res/icons/light-retro/hd_disabled.png | Bin 2198 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/light-retro/hd_disabled.png diff --git a/src/qt/res/icons/light-retro/hd_disabled.png b/src/qt/res/icons/light-retro/hd_disabled.png deleted file mode 100644 index b6fce2eaca5aaa05e1439ac07cf8b51d812b9aae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2198 zcmZuzX*kq<7ykWcEb}sCDIv>HWTupeLDrbYmc7NUW?F>M^V%o#519!svc#aY*&_Q^ zmYGsfrg%zkGRjm8WqTNx8fKc;^WpjSemLh`=X|)Y>)hv@>ps^!-HCEC>M{TTIcFzF z@68DRZ77LNABL~B0{|7|>}cbyh`+1J=`qW0GbSnN}W*fPKv%jc-v~^M=s3?x}Ink9q<4 zNI`qr`_t61#-(!0&?&2ND-#;V87bMc0;Ph0OapC&uF(B z6ZVon-ms-5!P<-;jQ5y+G#{UL+J}PhP(aiiJf3wX(frQ5&tE9<$WWc5 z(Z~CR%@k>csXO7uUE9G+UqEr`Xb_mX&E-FT2vlFtK-ubRab{qFl{_?|PtcDkOFMBZ zvh=*it zLb2?&Ns$c}83@5o+Bbk%{P_D;hQnLpQ`N;^td14ymXk> zej5?vo|T>X2gq2rHG1A5^rASN6uI-WucxWZ^r{X3r_(o^&&Bjc3gW%9?)1HMLy~h> z*f2WR2cW+O1@TXe$V8V|Jr87fS6U?#0uh)BoHc)Ax%AZUxb*ERkvQ}xem3mw-9d|b8boeUhKo(v)RN;|1Cl~DaLmEA zxX*flZ{|{MEp8lPr&_4h*R8C51YVdm>UK%Rm5Qz)j&Nlyw$BHYZF@AcssJ|$Lh?z; z^9#bQW=!jHM2#nT|93@zM=+yia3TihKy7=|%k=4i=8h^!q*b5GWZ)bHguf?n*G$jQSZ1%Vj3&6J_nvF6`*G zmiZmMs0=^6A6`1#Z2E_uCHU+)rS>T@9C8pH*Xl6r+aj(!Dsp?j)wN=T#X8W*=jqc8+SmEVKzGp0_6Iy673$&g9U0&-ge@J{9uo;8ClbvwXF#lmBr z?cgyOx3XaAsDViEzJ4Z>4Mp#y-6@(@=P}8`Ipz>%Lq&}U@~7H#hn7fa_+wzI|Kcc~ zYUpffeK-e9)JX=uxyJ=_Ghbs6*T|Em`cS9Uem9f@u@awqOQC<*!Z*r%ozR7pjvN037NZS zms3l@t6eqaqS}&qxqOyOY7)=mi!@h8Pw}A31u)n#reI$>g+Bo7q#BVu&KXsL-KyGN z)irvsF9SF1nl>%0BaLXY&i7r#@j#LV&Q zm<}130re*ATr{ik8tg{DlfiS&68wU<=;x;%#9)uSKP~fx6jJW;%%8Jk3vX zp|OP<62wai)_k8t2=<}Tgg@d0^m|sXZr(Mik=z%~5Hn)hnSCCNRWy7=;NzQoRr#d5 zg89>@po|?FdWwFjXk+=7&BCv8)=p)rf3OX}hhZr=d zs)MIIX1^V0WhlD>o0ZJh1Q?o25Ff89Uhn=kNr?n*(?n~2>sWZ97>)fK?6m)vt{Z}L zpcK2USWXrcf_Yt^55f!jnF&(Bq4tU)k7+)pli$yyI^LicgZgykj?01l9~WHsv0#3n zqhLEy<(eE@W$KVD*@bo45{fbs{cb3<-Sx|)`w*cl9N&nP~XOC$dD=a4J4A?#gcV2PkjQre-l6Q$$UCM(N%2MB|N}?6ApAtCS({9QA22 zN5q?Jki7JCLyei8gs1X|E$VJ$twR Date: Thu, 4 Jun 2020 15:40:01 -0400 Subject: [PATCH 0010/1324] Delete hd_enabled.png --- src/qt/res/icons/light-retro/hd_enabled.png | Bin 688 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/light-retro/hd_enabled.png diff --git a/src/qt/res/icons/light-retro/hd_enabled.png b/src/qt/res/icons/light-retro/hd_enabled.png deleted file mode 100644 index c65c8ddc8a5726ae459a55732923929723543c15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 688 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H0wgodS2{2-FqM0{IEGZ*dVAYCLnKh-*vI|5 z>^xIMw{6(yl_iHj9?=PS|l?D!1XtRwIU*v{(I6JO}@sW4|%IFu%1oXYs+( zeOnl2Bsxnn*2Tt}RLu1**m#G5A$#YP%g1bNQ`s3TW?eo}$;u#crjoBjn?dJc+Kp3j ztPC#_?f%&=U|=}xcuYr>x1s8W&w4fnA2v<)Zsr*Y3*Kh^D{eULc&hagL)VJ^>;)Pg znX4GSxW>nbHbhPM6voQ1FKwC6Ylc0i&Rt}b2xpfFX0Mnu(`Y&K2PNaD&V>w@d$z?s z{?GUzIPFyM)bhqs$5XkY4Z4n}I=CFB7_DF`Q1*Cvonb|rw5lm@L-NO2q6}fJ|JmnW zW02sAUa8HHld9)Yv2KI$mYL;=%EwRhZ)l&np;vR)Y2FK`Gv0My@ASJbXYXXX_}b>q zyK|l-c7H#|8K!-nL-p6z_9f>s{5$U^wHh7R+ZxrF#1*4ujLuas^Wr%l`a3qR-**@5UUW;uAUUOX~hIcx+Yr7I|}~7ceC< Nc)I$ztaD0e0suYl4uAjv From 8b7da9cfb242a3244c6fef81af1f4aef72305773 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:40:11 -0400 Subject: [PATCH 0011/1324] Add files via upload --- src/qt/res/icons/light-retro/hd_disabled.png | Bin 0 -> 3333 bytes src/qt/res/icons/light-retro/hd_enabled.png | Bin 0 -> 674 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/light-retro/hd_disabled.png create mode 100644 src/qt/res/icons/light-retro/hd_enabled.png diff --git a/src/qt/res/icons/light-retro/hd_disabled.png b/src/qt/res/icons/light-retro/hd_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..385949a4f0b414bbffee109abb93a1873a8febee GIT binary patch literal 3333 zcmZu!c{r3^AAZI(RI-(Z@@5%hi7AzgL`e2Ek|n#8RF<+7GsBRSC6VnVOQE#bcY}u_ zOJyc0d!Aw>dU-H-%uLMZ{r>&F>$-pEzJ9;!oa;L0I`{oM*NH!CZ6dUD|4sk^gv?A0 z?Y5ZuZ*1q^8as5oK5P*x*v`ZND5w85yOnJ7J#BRw0ID7e{_(nQr^Zl z;sdvy;%UtU5PKDynvwCoZ+*PJ*m0guweuPeW-n+Vk+QX z>@q=j@E}p0Pf*t6M9Y*5l-zwXQU*@W6!T7S$k7jV9oO5;Z8-D83bGY{C)!v4hOY;O z8=D~_`J2ZHZ_||%7`w#p1`^8Lkylr$F<9!oqgFNFJ*UD=9!y-^6P{>3Ni!hl&~Y91 zzZ_9ZFOOo;Zzh{G`*F9OW94Ho-)*mCMV-Ip`vHpI=c|<?k_O08 zo&)Its_gIFkTemz0z`BIijw3Z5g;V>@C&LfzM3+zHZf4(ihEm2E=XuBkC!XFN_YD6 ztSnE8M75=ICZZOh8JUJhBA`GnUS`pc%$yO7!(H#-cLJRGpNEWP!)=5($>eeMr49WM zbyME7@FK=M&`XNg&ewzMAN){I2=eavb&br>DX?Js?4g(KS z)v?zh1Xb7B9LZY`zLhaV?7JLoRVfg(uYnvWIViZu6xiw8mK(5)`UmC8Tui>?*m=@r z$k`3lI5(5txKJWMZpGP|RyMA6&*o!l+xddxul(Nou>0g=SVE4~`usVC7AeYqYWUn; z_`HW#>CMxm_(J6p=QI4Cs7C$bm*rIr*KG2(D{$P4JpR~M2D*L)6PmQ?7o*XOlKQwW z2zcj#I?q=D!edI^^5O7h^xc|GWqCG$rQ+L>`Nz+@R`TV2Pk-!2vaMzn(V*j3P|MwE zQEX@6dg}HAX}11xQWL*OCd4aEDmSGK7KQamgz#-Sxj zxmPrYcBP-v6Sc};rKo(iwxsnoq_}O%ZV}Oj<-QG3a&?U9{lf7*W1tO2r5(jcG1=XF zs~@Ro${+)RvS-};7v!Ifdet9dAYd#Ux?9%&vO*JQeO}K;=x{V9MN#$3d8W{O*s%bKB$JUf{c&YJ0`Rz0QMK3dff9rdnmZ4|h*Snsf|+%lr0gSs!cv9YKTFF_@AtSU zrWx}EAqR#Us6c9(;aPgSk0k z^Lw9=HPXR z#e_9gdP*X|%&(7M~GF==9VOOkY{tnEB1(^0N9 z@wt+~ZvWO5&}k-F$&MtFtg9-G zMSgE+OlC(&X%e$zdOV(mM1N+y!WyBU&aJvQ-!bXw3YTDDseU={pO#4&l4!c_T`rBV zdXqxLu}rw^L(`VTD#5~qB0qC}oAG7b?3!^tftvi&h&8I2wc2^{o`qc42PAsZLYnZn z##wxLxHA}|Pl*a-ynI-n)3vYu!yR}!2}Z|1EiB|;@mx|!ypjcv+;At-qT0`GP2}0k zaZ8MpN065Lwe7WPudoM%(;X_HxBI(JJ?-1M7x1Nz`A>2xK8Sx%!wf)I%$qmU{p5dQ(z^EVk$Z@C89uSf^Y<1uyO5aTReAvJiIRFRx1bN1kHsjcF#Jm6Qp1Ek{+^!i|wQZFOq zn96TVJ0;4ic;-t$6?yak1P`h9oMOt=&xgt`jZCl(RbK!?Dk}UTJL$yk?_$3e*pYg< zZAufmQGp6>#*=xLMkO1G+2D`5H1|gB!4Xc<_H6i42>T;a_(9K#j?%%MhT%&r{bqbH)J-YpY=3a z^U%)u-M?4k3>=nGvl!1ZhNBTeU?7{Zum+DgrP=A&RIa9mQ)g4Zh}_U{POa4~Xsgxv zSDl+nGl6BUi?eua(or8JnG^>=?S+UPWHLfTT3M@m(G(fw+zrF<`Fb|)FZEBI*8=b| zL9Re1oS0EW$ebZbPA=i>#0$ifbL$A=k+(kX@W4;heKk+s*?tN-v&_C01HYcrQ`>%5 zv(#7UB4A2eRmgFbFVX{QE?xVwHzIrYG@9gKLQfPY7mQDHy9*l1TEe(GV!}*Uj_%sO zZ=H;yj$;F4wg29eSnx1RuQnw<%1fx_T`@W57TTh{3_iV8Rf3O(r$g8qGId**o)gB_ zlaQO-?RQXiG-Aa6lpEk*iSVo3benW>GAL2F5e2D^;41SVI&gcN-K&#oS zn>9A}A9*3wh01ghyr|2t3iS-^F>c&UxxK9TP6N`kg@zJDdv|wW0gf(j-?Ai?v#Auo z%~#&fiA*;eL7#I{s5wA=1VJUV)3r)>41KVEQlyb5-F%}iv%MXQ9{L>(zsCNf+QlU8$(*l$ zpx{xr7NKOrF#W-Wp2DqtPrjYfik=mPXGj?wkaJ;66`MNTMB~2v@j|Dw&r)BxA zA{)i$GFV8SRWo^ldVBvM`lA#1AHhZo?DfZrZ4KZ7es<)zR`VN4lCpUUCNZU1|3?pD# zOnK$UZ)e{ZeU5q`zjxg)$>}dj<>c?#?)~w5TgAUm!P|d73)=0UaDHyxHRYzb=Z0B7 z{u^6$?SASZV0qxP`_GVYCXO{O1^Llm6&oG|vDjC~@v<0n3LR|DEtO&PQE~lXD?2Y| zbuveSk!I8RmmhMXw+bI<31X4I{P5wnEae8zr5yXF&Guz6*!bzthE4{x>r#ztAJkvD zvvBL}?d~>Bo2R`^4sVd2!d`ylUcI*m6UT!U0$Cgi6Q*%wt!HB5P;)gXQDf?OK0&-~ zx{!mzR)1Dge`cnLISgXke+LC`W)yba(!1bwkA--6!%@zJLZ%(5-|TWZfDDil^@amg zd-wjC4Q6H4AKl%~AZDJTed9jMwT+@aF?DwtyOk4ZnZv2aK#*bTA9&j1#oc1uCX-35B55|l> zTD<=!{Fl;d;9UC9-m6{y_Nrb6waIP&EoArQt}bJm;UQJ`@A}91ZC4F}0r;uu{q=2D zeGE^^yfa<42l%%iYpTsQKJ^fn{n#p Z7xu2jM Date: Thu, 4 Jun 2020 15:40:37 -0400 Subject: [PATCH 0012/1324] Delete hd_disabled.png --- src/qt/res/icons/light/hd_disabled.png | Bin 4136 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/light/hd_disabled.png diff --git a/src/qt/res/icons/light/hd_disabled.png b/src/qt/res/icons/light/hd_disabled.png deleted file mode 100644 index 9c369b3a9b6215462cc1b3c9b174332f3dda6818..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4136 zcmZ`+c{tSH_kWLUDaNjBV@Z~ZEb)mfjb-d(2}Mzqtu(SE(u`ymqtr(c!`O=K3R#AX zE!ituO!nQ_-^0w9@AUkBe}2DzocnstbI-ZYx%ZxP&wa()SR=T(M7aO};5IWgvSVVz zU*TkDj;(sPx|sk8v_rsw(q8c;ro!rV+3GR?RA7(MZm}`-qyDDX0s(-h^{+rWQ15R8 z0JPD}=<=0Eu4|bbSA?8II|zs};pgX;MLk+vBNgHj@G_c4_bOg`Y8Fd^r%tb518Xy? zMtia*dQN+#dZ(*C^f+=>Apt*9URGgjBx12z@pOj+#UPz8hr-{6szW8QRGo$HM$(a^ z4GeG{GvC{&eu|fqmF1~{)PI5O_VaHot@sjo3wbYc&g;1!lVO>X!W1`8M%0!`tMR^m z01P-E$|tCHmNc_J%~tl-Gi>Mz_4QTi(GGc|rh7eJT%t221EC_yUF}XZ3J7kyYgEHa z=VoucVEsyptJ&l!rKkTMob`d^$*P3=zXE60Ra8Y43%UW{(MmZl1m9(aNVs(ooD##$ zvPs2XjOP5-+gpIHIHM$tdk}zsAi`sZM(cS&;yBk8E(=B^K{nkGfxsrMCqv8U&*6!0 z;9g3TqoP9O+XrH^QTW-<=0=ba&Q&l@Zc*8|_LQ8Q?QL_lu-?Jp*Zx1dPJwy027Gwn z9xzH4;3G_hv(OH2%sdg#`JiK@PA6PV@AP{e$MXKxcex@NjaO1@A1qytZC%Q{WXy%>MuO-6@K(LyM@D5|3c8drE$;Ms!RP) zzQd&wUg4~r(`OEM)bYT_<5b;rEZ<-XX0cy7OlRTqyfjHwJ%gVeD~m#*toH@~n1yYQ0KKDVTtRRrN1tvFUSh@*A9HH|@Y#vj!(i(lGRcsStVGbz{u}v1 zB9s8t)E?;VeDA(FEKOO)8BeRbvzD{)V%SCZ+-t^bP(vfIy_IS3?pTA7gm%!M=Vd$R zA~qP)M#u0#5bIZ+oPEwsm)_LWR3F!Qt44Yja(jdf2H=Hk0c~lju3NGgasSoGg`l>K z;Xv=)=cMi9Zmb6hBH>q}^V#|dU=}yW96JA1Im zPAzzL(v@2JBxr|Ja>&*4n=Ksc>+4oqTU*|yzn#B*SWv{o&h7Mta>=Y)|bEqo@ks|6zMK)Rz$GB z$Za<-SwbhEAcK?^`_Hj{gT$SC+WdTS@qK6*8uAQpvMEtn>4R$Sbl-%@#<*C7n+Qh8 z{Rvtn$CwBnLwSyn7w*vW_HULA3|VSxhq3=GcEa{%>L3n}u82{{6K|w2qe^isHWp1U zG(V9oq@|^aXniTqI%ST>tKjB~GEkVq&QxA*%C!cxH1bnE-LD1}@E^@5HAJBXtm(vLHN;;T!mN1X3Qap(!PfcC!z`}-m z$N~pZwhO(POI@k*f}8}5T{P)TUe<5tC>@^mWF*?DZbizO#B6;0 z$|}e$s_|#%YvrA8cry0w#Ty5Blk;4cUe^mVcg{W?f(Wd<)fxk7=ukd^#tfvYtoyY7 zCbxJRHPiODL+5%$v(imAj8BzRzjpZ<#{%%;oUWXf9s6A$f{oMyz%qL5=+EJavUa`s{3_@7%!l4u!>gm*`=n!8eq`9E~N0gkWaStH1j0?QJth%L8Sx2`xr`x-Mw{d9TWTVV%{7@h%1N@H%W zY+-{=p$ZW>XT)~N{fby{DIj&osu3=d^cgC7DLZ>&C3u@EmwP&(y_E*zd%^3r`ISGA z^2T7j=~ zA)zq6yk<)9j^)an;~urWY3JvnnVo1%r1s*y>TsPTZg&wjn^n-&)ir4T`$;aHMnpYn zVb-pJ)NhAo*x*(`P2)A?2sJdL{qwHI%B><#0_aYFX26p~FDT7{d!}pW01AECQP+H* z4wW2Zypy~ZU5(tMf)CrqUX#)gC1-(2z1Jfs!Tp1SCu}m72Q#~x)RNu+C_A^6WTP9M%N4K zE>a5VSIBwn2zjD2f9GQEKg1wLqgW`SROw^rRQuRai>5w{0nJ~dgRcoIsf%yUT&ZUE z7Di=D;`}s&ttIV2ajnhE(F+C^k3#~C)8b~1O>jOJi5h$aH>{aANQ z`|?_IQsoGQuw5l%6BFg=jc}4{1_$m?yzXwWZ#5u=eykyf))z!$;N!8b_`re}FWVd8 zy}iAHFc?y$FcV)}TT9(a^Aok`rJg*_81ysxY3IQPY$CE1=Rjoe232m?HCt%PK2PIP z7~8pk-sW2OKU#ap!9>mH`P1F6CIa8b`KmBKN+S5~?n1G}d9W_Dx{)fi1%ibiKc40K zT^YIlBWpjrY2`!P^vn>W;kSd;C+3R~)Ob{((farJFZhkU8XO!{pfn4s zg^e~)l+S(0@^eM@$DW0&aDclYgG?dkPQkRwrU*oL48tzLT8>;j!{U z2`H=qZPHsKQ}t>iAe!g3DPBJdim15e-RhY6&~G@Cqenx#)ZAPiD#X4e4QE=^dTt0H zF5LRbvY0exc|xR(0qr8^u3zt81=m+WLwUO@&z{AD-IY&m%kfvb5HubjCn#g!KZf*$jj#OV;+n*$+g?^V3_Pp~Nwdrsy#&uf#i%7)fF=Yw! zi7&yqJ3B!Ww8OwMw}Isf`#F)tnavL!+CSw8DkjLylQ)k2txSoFR%6OfmImcS1A=1j zqe(R?`nNMG`G$_Ow}x9U^Yb=6n`Evj6ak}U)gU+5`X`gI1t)8ImzKc@Skf=(blF^< zGGuB$>B{5clg8eEuaXc&nh8RV=>;=mYWw`~WT+e(%Fl=9WgM3eX5%C)VU|liJDb@< zHXix}5}+eZ=F~k!!GS`_b3QkS8vATZ6~#Hcj9a$8jPk|G4M#VA&ku!`+!KwPRg|0= zG5CoiRQhut3Ff-T9pmlp+ zcZ7^+|ComhuAOd2qcms9h>cWLm|#B3U3@JdMd8(;-L`~HD(l{JJMJ@ixfM+wO<*~4 zgn7cGxDe^4VH7lf|TOo>OEV^6K=blm%KQfeMiRWu%#u?Pc6X5(5S15 z|0QpOofC7~_CCa5qs4oKj2jvv>pys$bpVo82nIOW$)}Wt>n=8iG(58lXL$cBC0=&D z4sKtX^`njKQO{wYD17dp85dk5+f-Vh%=>HRLI81L++(9vU@@e=#s+_+dT^MGftQoE zm!+O^+u)Un7#=IGuU^0Qc7xh)Q13*lp)o+q0w}CIVsKO9yTg1A4ws&PBb-7 z^CG~Mh&8(35x`{LRA0#WU{I?ZGFRhJ<8MR^UTg`w4&2SmGK`hQclKC0LxN7U43k4ixaJsD6~JdZ@A8;&3Ck#1 zD=9;oVBjVNmpYulU%A=+Mg-6|jUN+rc(+$UqO#lh`R;|AQz0KY4C`D0Kka_Q}gkItFQG PvU|YH*xINRelzkvT_YQz From 9a2749afba3f3c1be979c6cd19aadd89ffc132eb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:40:44 -0400 Subject: [PATCH 0013/1324] Delete hd_enabled.png --- src/qt/res/icons/light/hd_enabled.png | Bin 808 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/light/hd_enabled.png diff --git a/src/qt/res/icons/light/hd_enabled.png b/src/qt/res/icons/light/hd_enabled.png deleted file mode 100644 index 9bc5e6dd87c52995807ccba98c07cddef9e65067..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 808 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qt-3`~1HT^vIy;@;l1&b#U$!uEj0(V->W*^!^y zVbPKlUY$v%7cMH9F=#JveFK`0 z3SL~T+vXa#x4wMd?(4sPJj=aWeaB^W;gmmjq;$`Fu6)#ZWzHNi_B&ZJYrE^GO5Are zS)QCPxqZ`8X2E@v6&oZExn?Od%IklVDGwi43%vhs`+c>q<^HsW|F0`F;&S>o$G@)Jc9dlSzkBey zM>AaQp63}dzBn;Opr!q$m|(*>7mig~LYof+z5{ap&2i_5ds0`-bYZ#v&1qWyRwpyw zP%MB7oR{ucAFKWe7js(W{w^jvGXFYIVkl1^GfuP_+h-perOcy95HvI9c= zO}j-K7Jm3$c&;ti-6>$zmxC8|6CRgoGl+-(JL+>_Ygs*WpqT^X!I`5O)|Z|J^a)5GO3|6S_sISeHl>;A>>1Twxn zFWu&vbzO;NfxiCZSN|vc?iOh9<5^v|vG!En#2vrnp8`GlfuzBMjnd-}&2fAE7wx9nm-@msK7#&ZT@87&JyPu&%kE>q2`+f^UiB?zL zgx3GY`!2OHl&EmkS%}zj?>|v57izk7iq7p%jYu6{1-oD!M Date: Thu, 4 Jun 2020 15:40:53 -0400 Subject: [PATCH 0014/1324] Add files via upload --- src/qt/res/icons/light/hd_disabled.png | Bin 0 -> 3333 bytes src/qt/res/icons/light/hd_enabled.png | Bin 0 -> 674 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/light/hd_disabled.png create mode 100644 src/qt/res/icons/light/hd_enabled.png diff --git a/src/qt/res/icons/light/hd_disabled.png b/src/qt/res/icons/light/hd_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..385949a4f0b414bbffee109abb93a1873a8febee GIT binary patch literal 3333 zcmZu!c{r3^AAZI(RI-(Z@@5%hi7AzgL`e2Ek|n#8RF<+7GsBRSC6VnVOQE#bcY}u_ zOJyc0d!Aw>dU-H-%uLMZ{r>&F>$-pEzJ9;!oa;L0I`{oM*NH!CZ6dUD|4sk^gv?A0 z?Y5ZuZ*1q^8as5oK5P*x*v`ZND5w85yOnJ7J#BRw0ID7e{_(nQr^Zl z;sdvy;%UtU5PKDynvwCoZ+*PJ*m0guweuPeW-n+Vk+QX z>@q=j@E}p0Pf*t6M9Y*5l-zwXQU*@W6!T7S$k7jV9oO5;Z8-D83bGY{C)!v4hOY;O z8=D~_`J2ZHZ_||%7`w#p1`^8Lkylr$F<9!oqgFNFJ*UD=9!y-^6P{>3Ni!hl&~Y91 zzZ_9ZFOOo;Zzh{G`*F9OW94Ho-)*mCMV-Ip`vHpI=c|<?k_O08 zo&)Its_gIFkTemz0z`BIijw3Z5g;V>@C&LfzM3+zHZf4(ihEm2E=XuBkC!XFN_YD6 ztSnE8M75=ICZZOh8JUJhBA`GnUS`pc%$yO7!(H#-cLJRGpNEWP!)=5($>eeMr49WM zbyME7@FK=M&`XNg&ewzMAN){I2=eavb&br>DX?Js?4g(KS z)v?zh1Xb7B9LZY`zLhaV?7JLoRVfg(uYnvWIViZu6xiw8mK(5)`UmC8Tui>?*m=@r z$k`3lI5(5txKJWMZpGP|RyMA6&*o!l+xddxul(Nou>0g=SVE4~`usVC7AeYqYWUn; z_`HW#>CMxm_(J6p=QI4Cs7C$bm*rIr*KG2(D{$P4JpR~M2D*L)6PmQ?7o*XOlKQwW z2zcj#I?q=D!edI^^5O7h^xc|GWqCG$rQ+L>`Nz+@R`TV2Pk-!2vaMzn(V*j3P|MwE zQEX@6dg}HAX}11xQWL*OCd4aEDmSGK7KQamgz#-Sxj zxmPrYcBP-v6Sc};rKo(iwxsnoq_}O%ZV}Oj<-QG3a&?U9{lf7*W1tO2r5(jcG1=XF zs~@Ro${+)RvS-};7v!Ifdet9dAYd#Ux?9%&vO*JQeO}K;=x{V9MN#$3d8W{O*s%bKB$JUf{c&YJ0`Rz0QMK3dff9rdnmZ4|h*Snsf|+%lr0gSs!cv9YKTFF_@AtSU zrWx}EAqR#Us6c9(;aPgSk0k z^Lw9=HPXR z#e_9gdP*X|%&(7M~GF==9VOOkY{tnEB1(^0N9 z@wt+~ZvWO5&}k-F$&MtFtg9-G zMSgE+OlC(&X%e$zdOV(mM1N+y!WyBU&aJvQ-!bXw3YTDDseU={pO#4&l4!c_T`rBV zdXqxLu}rw^L(`VTD#5~qB0qC}oAG7b?3!^tftvi&h&8I2wc2^{o`qc42PAsZLYnZn z##wxLxHA}|Pl*a-ynI-n)3vYu!yR}!2}Z|1EiB|;@mx|!ypjcv+;At-qT0`GP2}0k zaZ8MpN065Lwe7WPudoM%(;X_HxBI(JJ?-1M7x1Nz`A>2xK8Sx%!wf)I%$qmU{p5dQ(z^EVk$Z@C89uSf^Y<1uyO5aTReAvJiIRFRx1bN1kHsjcF#Jm6Qp1Ek{+^!i|wQZFOq zn96TVJ0;4ic;-t$6?yak1P`h9oMOt=&xgt`jZCl(RbK!?Dk}UTJL$yk?_$3e*pYg< zZAufmQGp6>#*=xLMkO1G+2D`5H1|gB!4Xc<_H6i42>T;a_(9K#j?%%MhT%&r{bqbH)J-YpY=3a z^U%)u-M?4k3>=nGvl!1ZhNBTeU?7{Zum+DgrP=A&RIa9mQ)g4Zh}_U{POa4~Xsgxv zSDl+nGl6BUi?eua(or8JnG^>=?S+UPWHLfTT3M@m(G(fw+zrF<`Fb|)FZEBI*8=b| zL9Re1oS0EW$ebZbPA=i>#0$ifbL$A=k+(kX@W4;heKk+s*?tN-v&_C01HYcrQ`>%5 zv(#7UB4A2eRmgFbFVX{QE?xVwHzIrYG@9gKLQfPY7mQDHy9*l1TEe(GV!}*Uj_%sO zZ=H;yj$;F4wg29eSnx1RuQnw<%1fx_T`@W57TTh{3_iV8Rf3O(r$g8qGId**o)gB_ zlaQO-?RQXiG-Aa6lpEk*iSVo3benW>GAL2F5e2D^;41SVI&gcN-K&#oS zn>9A}A9*3wh01ghyr|2t3iS-^F>c&UxxK9TP6N`kg@zJDdv|wW0gf(j-?Ai?v#Auo z%~#&fiA*;eL7#I{s5wA=1VJUV)3r)>41KVEQlyb5-F%}iv%MXQ9{L>(zsCNf+QlU8$(*l$ zpx{xr7NKOrF#W-Wp2DqtPrjYfik=mPXGj?wkaJ;66`MNTMB~2v@j|Dw&r)BxA zA{)i$GFV8SRWo^ldVBvM`lA#1AHhZo?DfZrZ4KZ7es<)zR`VN4lCpUUCNZU1|3?pD# zOnK$UZ)e{ZeU5q`zjxg)$>}dj<>c?#?)~w5TgAUm!P|d73)=0UaDHyxHRYzb=Z0B7 z{u^6$?SASZV0qxP`_GVYCXO{O1^Llm6&oG|vDjC~@v<0n3LR|DEtO&PQE~lXD?2Y| zbuveSk!I8RmmhMXw+bI<31X4I{P5wnEae8zr5yXF&Guz6*!bzthE4{x>r#ztAJkvD zvvBL}?d~>Bo2R`^4sVd2!d`ylUcI*m6UT!U0$Cgi6Q*%wt!HB5P;)gXQDf?OK0&-~ zx{!mzR)1Dge`cnLISgXke+LC`W)yba(!1bwkA--6!%@zJLZ%(5-|TWZfDDil^@amg zd-wjC4Q6H4AKl%~AZDJTed9jMwT+@aF?DwtyOk4ZnZv2aK#*bTA9&j1#oc1uCX-35B55|l> zTD<=!{Fl;d;9UC9-m6{y_Nrb6waIP&EoArQt}bJm;UQJ`@A}91ZC4F}0r;uu{q=2D zeGE^^yfa<42l%%iYpTsQKJ^fn{n#p Z7xu2jM Date: Thu, 4 Jun 2020 15:41:44 -0400 Subject: [PATCH 0015/1324] Delete hd_disabled.png --- src/qt/res/icons/trad/hd_disabled.png | Bin 2198 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/trad/hd_disabled.png diff --git a/src/qt/res/icons/trad/hd_disabled.png b/src/qt/res/icons/trad/hd_disabled.png deleted file mode 100644 index b6fce2eaca5aaa05e1439ac07cf8b51d812b9aae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2198 zcmZuzX*kq<7ykWcEb}sCDIv>HWTupeLDrbYmc7NUW?F>M^V%o#519!svc#aY*&_Q^ zmYGsfrg%zkGRjm8WqTNx8fKc;^WpjSemLh`=X|)Y>)hv@>ps^!-HCEC>M{TTIcFzF z@68DRZ77LNABL~B0{|7|>}cbyh`+1J=`qW0GbSnN}W*fPKv%jc-v~^M=s3?x}Ink9q<4 zNI`qr`_t61#-(!0&?&2ND-#;V87bMc0;Ph0OapC&uF(B z6ZVon-ms-5!P<-;jQ5y+G#{UL+J}PhP(aiiJf3wX(frQ5&tE9<$WWc5 z(Z~CR%@k>csXO7uUE9G+UqEr`Xb_mX&E-FT2vlFtK-ubRab{qFl{_?|PtcDkOFMBZ zvh=*it zLb2?&Ns$c}83@5o+Bbk%{P_D;hQnLpQ`N;^td14ymXk> zej5?vo|T>X2gq2rHG1A5^rASN6uI-WucxWZ^r{X3r_(o^&&Bjc3gW%9?)1HMLy~h> z*f2WR2cW+O1@TXe$V8V|Jr87fS6U?#0uh)BoHc)Ax%AZUxb*ERkvQ}xem3mw-9d|b8boeUhKo(v)RN;|1Cl~DaLmEA zxX*flZ{|{MEp8lPr&_4h*R8C51YVdm>UK%Rm5Qz)j&Nlyw$BHYZF@AcssJ|$Lh?z; z^9#bQW=!jHM2#nT|93@zM=+yia3TihKy7=|%k=4i=8h^!q*b5GWZ)bHguf?n*G$jQSZ1%Vj3&6J_nvF6`*G zmiZmMs0=^6A6`1#Z2E_uCHU+)rS>T@9C8pH*Xl6r+aj(!Dsp?j)wN=T#X8W*=jqc8+SmEVKzGp0_6Iy673$&g9U0&-ge@J{9uo;8ClbvwXF#lmBr z?cgyOx3XaAsDViEzJ4Z>4Mp#y-6@(@=P}8`Ipz>%Lq&}U@~7H#hn7fa_+wzI|Kcc~ zYUpffeK-e9)JX=uxyJ=_Ghbs6*T|Em`cS9Uem9f@u@awqOQC<*!Z*r%ozR7pjvN037NZS zms3l@t6eqaqS}&qxqOyOY7)=mi!@h8Pw}A31u)n#reI$>g+Bo7q#BVu&KXsL-KyGN z)irvsF9SF1nl>%0BaLXY&i7r#@j#LV&Q zm<}130re*ATr{ik8tg{DlfiS&68wU<=;x;%#9)uSKP~fx6jJW;%%8Jk3vX zp|OP<62wai)_k8t2=<}Tgg@d0^m|sXZr(Mik=z%~5Hn)hnSCCNRWy7=;NzQoRr#d5 zg89>@po|?FdWwFjXk+=7&BCv8)=p)rf3OX}hhZr=d zs)MIIX1^V0WhlD>o0ZJh1Q?o25Ff89Uhn=kNr?n*(?n~2>sWZ97>)fK?6m)vt{Z}L zpcK2USWXrcf_Yt^55f!jnF&(Bq4tU)k7+)pli$yyI^LicgZgykj?01l9~WHsv0#3n zqhLEy<(eE@W$KVD*@bo45{fbs{cb3<-Sx|)`w*cl9N&nP~XOC$dD=a4J4A?#gcV2PkjQre-l6Q$$UCM(N%2MB|N}?6ApAtCS({9QA22 zN5q?Jki7JCLyei8gs1X|E$VJ$twR Date: Thu, 4 Jun 2020 15:41:54 -0400 Subject: [PATCH 0016/1324] Delete hd_enabled.png --- src/qt/res/icons/trad/hd_enabled.png | Bin 688 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/res/icons/trad/hd_enabled.png diff --git a/src/qt/res/icons/trad/hd_enabled.png b/src/qt/res/icons/trad/hd_enabled.png deleted file mode 100644 index c65c8ddc8a5726ae459a55732923929723543c15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 688 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H0wgodS2{2-FqM0{IEGZ*dVAYCLnKh-*vI|5 z>^xIMw{6(yl_iHj9?=PS|l?D!1XtRwIU*v{(I6JO}@sW4|%IFu%1oXYs+( zeOnl2Bsxnn*2Tt}RLu1**m#G5A$#YP%g1bNQ`s3TW?eo}$;u#crjoBjn?dJc+Kp3j ztPC#_?f%&=U|=}xcuYr>x1s8W&w4fnA2v<)Zsr*Y3*Kh^D{eULc&hagL)VJ^>;)Pg znX4GSxW>nbHbhPM6voQ1FKwC6Ylc0i&Rt}b2xpfFX0Mnu(`Y&K2PNaD&V>w@d$z?s z{?GUzIPFyM)bhqs$5XkY4Z4n}I=CFB7_DF`Q1*Cvonb|rw5lm@L-NO2q6}fJ|JmnW zW02sAUa8HHld9)Yv2KI$mYL;=%EwRhZ)l&np;vR)Y2FK`Gv0My@ASJbXYXXX_}b>q zyK|l-c7H#|8K!-nL-p6z_9f>s{5$U^wHh7R+ZxrF#1*4ujLuas^Wr%l`a3qR-**@5UUW;uAUUOX~hIcx+Yr7I|}~7ceC< Nc)I$ztaD0e0suYl4uAjv From 9d962cc384b6bdb47d80789bd83194297d087ab7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:42:03 -0400 Subject: [PATCH 0017/1324] Add files via upload --- src/qt/res/icons/trad/hd_disabled.png | Bin 0 -> 3333 bytes src/qt/res/icons/trad/hd_enabled.png | Bin 0 -> 674 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/trad/hd_disabled.png create mode 100644 src/qt/res/icons/trad/hd_enabled.png diff --git a/src/qt/res/icons/trad/hd_disabled.png b/src/qt/res/icons/trad/hd_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..385949a4f0b414bbffee109abb93a1873a8febee GIT binary patch literal 3333 zcmZu!c{r3^AAZI(RI-(Z@@5%hi7AzgL`e2Ek|n#8RF<+7GsBRSC6VnVOQE#bcY}u_ zOJyc0d!Aw>dU-H-%uLMZ{r>&F>$-pEzJ9;!oa;L0I`{oM*NH!CZ6dUD|4sk^gv?A0 z?Y5ZuZ*1q^8as5oK5P*x*v`ZND5w85yOnJ7J#BRw0ID7e{_(nQr^Zl z;sdvy;%UtU5PKDynvwCoZ+*PJ*m0guweuPeW-n+Vk+QX z>@q=j@E}p0Pf*t6M9Y*5l-zwXQU*@W6!T7S$k7jV9oO5;Z8-D83bGY{C)!v4hOY;O z8=D~_`J2ZHZ_||%7`w#p1`^8Lkylr$F<9!oqgFNFJ*UD=9!y-^6P{>3Ni!hl&~Y91 zzZ_9ZFOOo;Zzh{G`*F9OW94Ho-)*mCMV-Ip`vHpI=c|<?k_O08 zo&)Its_gIFkTemz0z`BIijw3Z5g;V>@C&LfzM3+zHZf4(ihEm2E=XuBkC!XFN_YD6 ztSnE8M75=ICZZOh8JUJhBA`GnUS`pc%$yO7!(H#-cLJRGpNEWP!)=5($>eeMr49WM zbyME7@FK=M&`XNg&ewzMAN){I2=eavb&br>DX?Js?4g(KS z)v?zh1Xb7B9LZY`zLhaV?7JLoRVfg(uYnvWIViZu6xiw8mK(5)`UmC8Tui>?*m=@r z$k`3lI5(5txKJWMZpGP|RyMA6&*o!l+xddxul(Nou>0g=SVE4~`usVC7AeYqYWUn; z_`HW#>CMxm_(J6p=QI4Cs7C$bm*rIr*KG2(D{$P4JpR~M2D*L)6PmQ?7o*XOlKQwW z2zcj#I?q=D!edI^^5O7h^xc|GWqCG$rQ+L>`Nz+@R`TV2Pk-!2vaMzn(V*j3P|MwE zQEX@6dg}HAX}11xQWL*OCd4aEDmSGK7KQamgz#-Sxj zxmPrYcBP-v6Sc};rKo(iwxsnoq_}O%ZV}Oj<-QG3a&?U9{lf7*W1tO2r5(jcG1=XF zs~@Ro${+)RvS-};7v!Ifdet9dAYd#Ux?9%&vO*JQeO}K;=x{V9MN#$3d8W{O*s%bKB$JUf{c&YJ0`Rz0QMK3dff9rdnmZ4|h*Snsf|+%lr0gSs!cv9YKTFF_@AtSU zrWx}EAqR#Us6c9(;aPgSk0k z^Lw9=HPXR z#e_9gdP*X|%&(7M~GF==9VOOkY{tnEB1(^0N9 z@wt+~ZvWO5&}k-F$&MtFtg9-G zMSgE+OlC(&X%e$zdOV(mM1N+y!WyBU&aJvQ-!bXw3YTDDseU={pO#4&l4!c_T`rBV zdXqxLu}rw^L(`VTD#5~qB0qC}oAG7b?3!^tftvi&h&8I2wc2^{o`qc42PAsZLYnZn z##wxLxHA}|Pl*a-ynI-n)3vYu!yR}!2}Z|1EiB|;@mx|!ypjcv+;At-qT0`GP2}0k zaZ8MpN065Lwe7WPudoM%(;X_HxBI(JJ?-1M7x1Nz`A>2xK8Sx%!wf)I%$qmU{p5dQ(z^EVk$Z@C89uSf^Y<1uyO5aTReAvJiIRFRx1bN1kHsjcF#Jm6Qp1Ek{+^!i|wQZFOq zn96TVJ0;4ic;-t$6?yak1P`h9oMOt=&xgt`jZCl(RbK!?Dk}UTJL$yk?_$3e*pYg< zZAufmQGp6>#*=xLMkO1G+2D`5H1|gB!4Xc<_H6i42>T;a_(9K#j?%%MhT%&r{bqbH)J-YpY=3a z^U%)u-M?4k3>=nGvl!1ZhNBTeU?7{Zum+DgrP=A&RIa9mQ)g4Zh}_U{POa4~Xsgxv zSDl+nGl6BUi?eua(or8JnG^>=?S+UPWHLfTT3M@m(G(fw+zrF<`Fb|)FZEBI*8=b| zL9Re1oS0EW$ebZbPA=i>#0$ifbL$A=k+(kX@W4;heKk+s*?tN-v&_C01HYcrQ`>%5 zv(#7UB4A2eRmgFbFVX{QE?xVwHzIrYG@9gKLQfPY7mQDHy9*l1TEe(GV!}*Uj_%sO zZ=H;yj$;F4wg29eSnx1RuQnw<%1fx_T`@W57TTh{3_iV8Rf3O(r$g8qGId**o)gB_ zlaQO-?RQXiG-Aa6lpEk*iSVo3benW>GAL2F5e2D^;41SVI&gcN-K&#oS zn>9A}A9*3wh01ghyr|2t3iS-^F>c&UxxK9TP6N`kg@zJDdv|wW0gf(j-?Ai?v#Auo z%~#&fiA*;eL7#I{s5wA=1VJUV)3r)>41KVEQlyb5-F%}iv%MXQ9{L>(zsCNf+QlU8$(*l$ zpx{xr7NKOrF#W-Wp2DqtPrjYfik=mPXGj?wkaJ;66`MNTMB~2v@j|Dw&r)BxA zA{)i$GFV8SRWo^ldVBvM`lA#1AHhZo?DfZrZ4KZ7es<)zR`VN4lCpUUCNZU1|3?pD# zOnK$UZ)e{ZeU5q`zjxg)$>}dj<>c?#?)~w5TgAUm!P|d73)=0UaDHyxHRYzb=Z0B7 z{u^6$?SASZV0qxP`_GVYCXO{O1^Llm6&oG|vDjC~@v<0n3LR|DEtO&PQE~lXD?2Y| zbuveSk!I8RmmhMXw+bI<31X4I{P5wnEae8zr5yXF&Guz6*!bzthE4{x>r#ztAJkvD zvvBL}?d~>Bo2R`^4sVd2!d`ylUcI*m6UT!U0$Cgi6Q*%wt!HB5P;)gXQDf?OK0&-~ zx{!mzR)1Dge`cnLISgXke+LC`W)yba(!1bwkA--6!%@zJLZ%(5-|TWZfDDil^@amg zd-wjC4Q6H4AKl%~AZDJTed9jMwT+@aF?DwtyOk4ZnZv2aK#*bTA9&j1#oc1uCX-35B55|l> zTD<=!{Fl;d;9UC9-m6{y_Nrb6waIP&EoArQt}bJm;UQJ`@A}91ZC4F}0r;uu{q=2D zeGE^^yfa<42l%%iYpTsQKJ^fn{n#p Z7xu2jM Date: Thu, 4 Jun 2020 15:49:23 -0400 Subject: [PATCH 0018/1324] Update helpthehomeless.qrc --- src/qt/helpthehomeless.qrc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 842849b5..0354c803 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -84,6 +84,7 @@ res/icons/webs.png res/icons/icon_reddit.png res/icons/icon_medium.png + res/icons/chat.png res/icons/crownium/address-book.png @@ -152,6 +153,7 @@ res/icons/webs.png res/icons/icon_reddit.png res/icons/icon_medium.png + res/icons/chat.png res/icons/light/address-book.png @@ -220,6 +222,7 @@ res/icons/webs.png res/icons/icon_reddit.png res/icons/icon_medium.png + res/icons/chat.png res/icons/light-retro/address-book.png @@ -288,6 +291,7 @@ res/icons/webs.png res/icons/icon_reddit.png res/icons/icon_medium.png + res/icons/chat.png res/icons/trad/address-book.png @@ -356,6 +360,7 @@ res/icons/webs.png res/icons/icon_reddit.png res/icons/icon_medium.png + res/icons/chat.png res/css/drkblue.css From 01529f50bc35d1c6da4f125c82fe83faa46cefb4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:58:24 -0400 Subject: [PATCH 0019/1324] Update helpthehomeless.qrc --- src/qt/helpthehomeless.qrc | 130 ++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 0354c803..914e2c60 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -72,19 +72,19 @@ res/icons/drkblue/fontsmaller.png res/icons/drkblue/transaction_abandoned.png res/icons/drkblue/network_disabled.png - res/icons/chevron.png - res/icons/warning.png - res/icons/bitcoin.png - res/icons/mcm.png - res/icons/twitter.png - res/icons/discord.png - res/icons/web.png - res/icons/website.png - res/icons/www.png - res/icons/webs.png - res/icons/icon_reddit.png - res/icons/icon_medium.png - res/icons/chat.png + res/icons/drkblue/chevron.png + res/icons/drkblue/warning.png + res/icons/drkblue/bitcoin.png + res/icons/drkblue/mcm.png + res/icons/drkblue/twitter.png + res/icons/drkblue/discord.png + res/icons/drkblue/web.png + res/icons/drkblue/website.png + res/icons/drkblue/www.png + res/icons/drkblue/webs.png + res/icons/drkblue/icon_reddit.png + res/icons/drkblue/icon_medium.png + res/icons/drkblue/chat.png res/icons/crownium/address-book.png @@ -141,19 +141,19 @@ res/icons/crownium/fontsmaller.png res/icons/crownium/transaction_abandoned.png res/icons/crownium/network_disabled.png - res/icons/chevron.png - res/icons/warning.png - res/icons/bitcoin.png - res/icons/mcm.png - res/icons/twitter.png - res/icons/discord.png - res/icons/web.png - res/icons/website.png - res/icons/www.png - res/icons/webs.png - res/icons/icon_reddit.png - res/icons/icon_medium.png - res/icons/chat.png + res/icons/crownium/chevron.png + res/icons/crownium/warning.png + res/icons/crownium/bitcoin.png + res/icons/crownium/mcm.png + res/icons/crownium/twitter.png + res/icons/crownium/discord.png + res/icons/crownium/web.png + res/icons/crownium/website.png + res/icons/crownium/www.png + res/icons/crownium/webs.png + res/icons/crownium/icon_reddit.png + res/icons/crownium/icon_medium.png + res/icons/crownium/chat.png res/icons/light/address-book.png @@ -210,19 +210,19 @@ res/icons/light/fontsmaller.png res/icons/light/transaction_abandoned.png res/icons/light/network_disabled.png - res/icons/chevron.png - res/icons/warning.png - res/icons/bitcoin.png - res/icons/mcm.png - res/icons/twitter.png - res/icons/discord.png - res/icons/web.png - res/icons/website.png - res/icons/www.png - res/icons/webs.png - res/icons/icon_reddit.png - res/icons/icon_medium.png - res/icons/chat.png + res/icons/light/chevron.png + res/icons/light/warning.png + res/icons/light/bitcoin.png + res/icons/light/mcm.png + res/icons/light/twitter.png + res/icons/light/discord.png + res/icons/light/web.png + res/icons/light/website.png + res/icons/light/www.png + res/icons/light/webs.png + res/icons/light/icon_reddit.png + res/icons/light/icon_medium.png + res/icons/light/chat.png res/icons/light-retro/address-book.png @@ -279,19 +279,19 @@ res/icons/light-retro/fontsmaller.png res/icons/light-retro/transaction_abandoned.png res/icons/light-retro/network_disabled.png - res/icons/chevron.png - res/icons/warning.png - res/icons/bitcoin.png - res/icons/mcm.png - res/icons/twitter.png - res/icons/discord.png - res/icons/web.png - res/icons/website.png - res/icons/www.png - res/icons/webs.png - res/icons/icon_reddit.png - res/icons/icon_medium.png - res/icons/chat.png + res/icons/light-retro/chevron.png + res/icons/light-retro/warning.png + res/icons/light-retro/bitcoin.png + res/icons/light-retro/mcm.png + res/icons/light-retro/twitter.png + res/icons/light-retro/discord.png + res/icons/light-retro/web.png + res/icons/light-retro/website.png + res/icons/light-retro/www.png + res/icons/light-retro/webs.png + res/icons/light-retro/icon_reddit.png + res/icons/light-retro/icon_medium.png + res/icons/light-retro/chat.png res/icons/trad/address-book.png @@ -348,19 +348,19 @@ res/icons/trad/fontsmaller.png res/icons/trad/transaction_abandoned.png res/icons/trad/network_disabled.png - res/icons/chevron.png - res/icons/warning.png - res/icons/bitcoin.png - res/icons/mcm.png - res/icons/twitter.png - res/icons/discord.png - res/icons/web.png - res/icons/website.png - res/icons/www.png - res/icons/webs.png - res/icons/icon_reddit.png - res/icons/icon_medium.png - res/icons/chat.png + res/icons/trad/chevron.png + res/icons/trad/warning.png + res/icons/trad/bitcoin.png + res/icons/trad/mcm.png + res/icons/trad/twitter.png + res/icons/trad/discord.png + res/icons/trad/web.png + res/icons/trad/website.png + res/icons/trad/www.png + res/icons/trad/webs.png + res/icons/trad/icon_reddit.png + res/icons/trad/icon_medium.png + res/icons/trad/chat.png res/css/drkblue.css From 3fb5a2c3d8375a838cba5e81d7ec43365f60bbe9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 16:01:44 -0400 Subject: [PATCH 0020/1324] Add files via upload --- src/qt/res/icons/drkblue/chevron.png | Bin 0 -> 666 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/qt/res/icons/drkblue/chevron.png diff --git a/src/qt/res/icons/drkblue/chevron.png b/src/qt/res/icons/drkblue/chevron.png new file mode 100644 index 0000000000000000000000000000000000000000..6460ace67254ac6366ac61a55a302880759379d3 GIT binary patch literal 666 zcmV;L0%iS)P)-g&9(oc9h+cmZodF3Cxfu9jJmdN@BpN_b- z#2cUBEu2N(e8GS}@O)hdtpmC%_>Vg8h%!Tdz>n*`-h^~l@S7MnbD5kzJYG;yiBES0 zzl=>E)rIfG4&|!kHR1DuD6~pJ58f{fp=b22{IzuH?%+LK3F)(1VeN!C=bF_@Bxc0) zPg<#)oc>uW=PXba(idsafJ0tPU#d+{0uEzTg!Hd8YQP~UrY}EEPYMn>@wvWClLj1y zC=2PU|1TmX2~U)sEF9i*A*8R Date: Thu, 4 Jun 2020 16:04:42 -0400 Subject: [PATCH 0021/1324] Update helpthehomeless.qrc --- src/qt/helpthehomeless.qrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 914e2c60..863d1e22 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -72,7 +72,7 @@ res/icons/drkblue/fontsmaller.png res/icons/drkblue/transaction_abandoned.png res/icons/drkblue/network_disabled.png - res/icons/drkblue/chevron.png + res/icons/chevron.png res/icons/drkblue/warning.png res/icons/drkblue/bitcoin.png res/icons/drkblue/mcm.png From 32d3e6a9c0c76f3bffdb94bfd6cb8b8ae2e5b627 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 16:07:16 -0400 Subject: [PATCH 0022/1324] Update helpthehomeless.qrc --- src/qt/helpthehomeless.qrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 863d1e22..0cd3eae8 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -73,7 +73,7 @@ res/icons/drkblue/transaction_abandoned.png res/icons/drkblue/network_disabled.png res/icons/chevron.png - res/icons/drkblue/warning.png + res/icons/warning.png res/icons/drkblue/bitcoin.png res/icons/drkblue/mcm.png res/icons/drkblue/twitter.png From 0297fe4ec589bece7da6f035d4938609327ed2e1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 16:09:57 -0400 Subject: [PATCH 0023/1324] Update helpthehomeless.qrc --- src/qt/helpthehomeless.qrc | 116 ++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 0cd3eae8..37032de7 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -74,16 +74,16 @@ res/icons/drkblue/network_disabled.png res/icons/chevron.png res/icons/warning.png - res/icons/drkblue/bitcoin.png - res/icons/drkblue/mcm.png - res/icons/drkblue/twitter.png - res/icons/drkblue/discord.png - res/icons/drkblue/web.png - res/icons/drkblue/website.png - res/icons/drkblue/www.png - res/icons/drkblue/webs.png - res/icons/drkblue/icon_reddit.png - res/icons/drkblue/icon_medium.png + res/icons/bitcoin.png + res/icons/mcm.png + res/icons/twitter.png + res/icons/discord.png + res/icons/web.png + res/icons/website.png + res/icons/www.png + res/icons/webs.png + res/icons/icon_reddit.png + res/icons/icon_medium.png res/icons/drkblue/chat.png @@ -141,18 +141,18 @@ res/icons/crownium/fontsmaller.png res/icons/crownium/transaction_abandoned.png res/icons/crownium/network_disabled.png - res/icons/crownium/chevron.png - res/icons/crownium/warning.png - res/icons/crownium/bitcoin.png - res/icons/crownium/mcm.png - res/icons/crownium/twitter.png - res/icons/crownium/discord.png - res/icons/crownium/web.png - res/icons/crownium/website.png - res/icons/crownium/www.png - res/icons/crownium/webs.png - res/icons/crownium/icon_reddit.png - res/icons/crownium/icon_medium.png + res/icons/chevron.png + res/icons/warning.png + res/icons/bitcoin.png + res/icons/mcm.png + res/icons/twitter.png + res/icons/discord.png + res/icons/web.png + res/icons/website.png + res/icons/www.png + res/icons/webs.png + res/icons/icon_reddit.png + res/icons/icon_medium.png res/icons/crownium/chat.png @@ -210,18 +210,18 @@ res/icons/light/fontsmaller.png res/icons/light/transaction_abandoned.png res/icons/light/network_disabled.png - res/icons/light/chevron.png - res/icons/light/warning.png - res/icons/light/bitcoin.png - res/icons/light/mcm.png - res/icons/light/twitter.png - res/icons/light/discord.png - res/icons/light/web.png - res/icons/light/website.png - res/icons/light/www.png - res/icons/light/webs.png - res/icons/light/icon_reddit.png - res/icons/light/icon_medium.png + res/icons/chevron.png + res/icons/warning.png + res/icons/bitcoin.png + res/icons/mcm.png + res/icons/twitter.png + res/icons/discord.png + res/icons/web.png + res/icons/website.png + res/icons/www.png + res/icons/webs.png + res/icons/icon_reddit.png + res/icons/icon_medium.png res/icons/light/chat.png @@ -279,18 +279,18 @@ res/icons/light-retro/fontsmaller.png res/icons/light-retro/transaction_abandoned.png res/icons/light-retro/network_disabled.png - res/icons/light-retro/chevron.png - res/icons/light-retro/warning.png - res/icons/light-retro/bitcoin.png - res/icons/light-retro/mcm.png - res/icons/light-retro/twitter.png - res/icons/light-retro/discord.png - res/icons/light-retro/web.png - res/icons/light-retro/website.png - res/icons/light-retro/www.png - res/icons/light-retro/webs.png - res/icons/light-retro/icon_reddit.png - res/icons/light-retro/icon_medium.png + res/icons/chevron.png + res/icons/warning.png + res/icons/bitcoin.png + res/icons/mcm.png + res/icons/twitter.png + res/icons/discord.png + res/icons/web.png + res/icons/website.png + res/icons/www.png + res/icons/webs.png + res/icons/icon_reddit.png + res/icons/icon_medium.png res/icons/light-retro/chat.png @@ -348,18 +348,18 @@ res/icons/trad/fontsmaller.png res/icons/trad/transaction_abandoned.png res/icons/trad/network_disabled.png - res/icons/trad/chevron.png - res/icons/trad/warning.png - res/icons/trad/bitcoin.png - res/icons/trad/mcm.png - res/icons/trad/twitter.png - res/icons/trad/discord.png - res/icons/trad/web.png - res/icons/trad/website.png - res/icons/trad/www.png - res/icons/trad/webs.png - res/icons/trad/icon_reddit.png - res/icons/trad/icon_medium.png + res/icons/chevron.png + res/icons/warning.png + res/icons/bitcoin.png + res/icons/mcm.png + res/icons/twitter.png + res/icons/discord.png + res/icons/web.png + res/icons/website.png + res/icons/www.png + res/icons/webs.png + res/icons/icon_reddit.png + res/icons/icon_medium.png res/icons/trad/chat.png From 86f6ddcb75ba7397aa5c4fa24640f19e87f712c1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 19:26:13 -0400 Subject: [PATCH 0024/1324] Update chainparams.cpp --- src/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6cad2142..97ca6cf7 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -313,7 +313,7 @@ class CMainParams : public CChainParams { assert(consensus.hashGenesisBlock == uint256S("0x37540c3c757bb77e42c168d8197447b6aba38c2d1ec0ddf59d2e774c41953093")); assert(genesis.hashMerkleRoot == uint256S("0xb65534a1e2f0ff85de1ff4cd1a457b92a56abc182397d9cc1380482784acabfc")); - // vSeeds.push_back(CDNSSeedData("dash.org", "dnsseed.dash.org")); + vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); // vSeeds.push_back(CDNSSeedData("dashdot.io", "dnsseed.dashdot.io")); // vSeeds.push_back(CDNSSeedData("masternode.io", "dnsseed.masternode.io")); From ee115ef8d5da355baf5518fe58f94182e3e99f81 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 19:28:38 -0400 Subject: [PATCH 0025/1324] Update chainparams.cpp --- src/chainparams.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 97ca6cf7..ce4461d7 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -314,8 +314,8 @@ class CMainParams : public CChainParams { assert(genesis.hashMerkleRoot == uint256S("0xb65534a1e2f0ff85de1ff4cd1a457b92a56abc182397d9cc1380482784acabfc")); vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); - // vSeeds.push_back(CDNSSeedData("dashdot.io", "dnsseed.dashdot.io")); - // vSeeds.push_back(CDNSSeedData("masternode.io", "dnsseed.masternode.io")); + vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); + vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); // Dash addresses start with 'h' base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,100); From 552af747a498b2a7df845221ace087f3a40a34bf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 19:29:23 -0400 Subject: [PATCH 0026/1324] Update chainparams.cpp --- src/chainparams.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index ce4461d7..dfa3e578 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -313,9 +313,9 @@ class CMainParams : public CChainParams { assert(consensus.hashGenesisBlock == uint256S("0x37540c3c757bb77e42c168d8197447b6aba38c2d1ec0ddf59d2e774c41953093")); assert(genesis.hashMerkleRoot == uint256S("0xb65534a1e2f0ff85de1ff4cd1a457b92a56abc182397d9cc1380482784acabfc")); - vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); - vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); - vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); + // vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); + // vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); + // vSeeds.push_back(CDNSSeedData("51.105.25.2:49999")); // Dash addresses start with 'h' base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,100); From 615a9cc69500fca006b37bc4ce0e6e8e119933ae Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 20:58:45 -0400 Subject: [PATCH 0027/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 334 +++++++++++++++----------------------- 1 file changed, 127 insertions(+), 207 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 87bff742..670744da 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -1,231 +1,151 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include #include "chatwindowpage.h" -#include "ui_chatwindowpage.h" - -#include -#include -#include -#include -#include -#include ChatWindowPage::ChatWindowPage(QWidget *parent) - : QWidget(parent), ui(new Ui::ChatWindowPage) + : QDialog(parent) { - ui->setupUi(this); - setFixedSize(750,600); - ui->splitter->hide(); - - connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(connecte())); - - connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); - connect(ui->actionCloseTab, SIGNAL(triggered()), this, SLOT(closeTab())); - - connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(sendCommande())); - - - ui->pushButton_WebChat->setStatusTip(tr("Visit Help The Homeless Worldwide Web Chat")); - - - - - - connect(ui->disconnect, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); - connect(ui->tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); - connect(ui->tab, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosing(int)) ); - + setupUi(this); + + lineEdit->setFocusPolicy(Qt::StrongFocus); + textEdit->setFocusPolicy(Qt::NoFocus); + textEdit->setReadOnly(true); + listWidget->setFocusPolicy(Qt::NoFocus); + + connect(lineEdit, &QLineEdit::returnPressed, + this, &ChatDialog::returnPressed); + connect(&client, &Client::newMessage, + this, &ChatDialog::appendMessage); + connect(&client, &Client::newParticipant, + this, &ChatDialog::newParticipant); + connect(&client, &Client::participantLeft, + this, &ChatDialog::participantLeft); + + myNickName = client.nickName(); + newParticipant(myNickName); + tableFormat.setBorder(0); + QTimer::singleShot(10 * 1000, this, SLOT(showInformation())); } - - -void ChatWindowPage::tabChanged(int index) +void ChatWindowPage::appendMessage(const QString &from, const QString &message) { - if(index!=0 && joining == false) - currentTab()->updateUsersList(ui->tab->tabText(index)); + if (from.isEmpty() || message.isEmpty()) + return; + + QTextCursor cursor(textEdit->textCursor()); + cursor.movePosition(QTextCursor::End); + QTextTable *table = cursor.insertTable(1, 2, tableFormat); + table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + "> "); + table->cellAt(0, 1).firstCursorPosition().insertText(message); + QScrollBar *bar = textEdit->verticalScrollBar(); + bar->setValue(bar->maximum()); } -void ChatWindowPage::tabClosing(int index) -{ - currentTab()->leave(ui->tab->tabText(index)); -} -/*void ChatWindow::tabRemoved(int index) +void ChatWindowPage::returnPressed() { - currentTab()->leave(ui->tab->tabText(index)); -}*/ - -void ChatWindowPage::disconnectFromServer() { - - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } + QString text = lineEdit->text(); + if (text.isEmpty()) + return; + + if (text.startsWith(QChar('/'))) { + QColor color = textEdit->textColor(); + textEdit->setTextColor(Qt::red); + textEdit->append(tr("! Unknown command: %1") + .arg(text.left(text.indexOf(' ')))); + textEdit->setTextColor(color); + } else { + client.sendMessage(text); + appendMessage(myNickName, text); } - - ui->splitter->hide(); - ui->hide3->show(); - -} - -Serveur *ChatWindowPage::currentTab() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - return serveurs[tooltip]; - //return ui->tab->currentWidget()->findChild(); -} - -void ChatWindowPage::closeTab() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - QString txt=ui->tab->tabText(ui->tab->currentIndex()); - - if(txt==tooltip) - { - QMapIterator i(serveurs[tooltip]->conversations); - - int count=ui->tab->currentIndex()+1; - - while(i.hasNext()) - { - i.next(); - ui->tab->removeTab(count); - } - - currentTab()->abort(); - ui->tab->removeTab(ui->tab->currentIndex()); - } - else - { - - ui->tab->removeTab(ui->tab->currentIndex()); - currentTab()->conversations.remove(txt); - } -} - -void ChatWindowPage::sendCommande() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - QString txt=ui->tab->tabText(ui->tab->currentIndex()); - if(txt==tooltip) - { - currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text(),true) ); - } - else - { - currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text()) ); - } - ui->lineEdit->clear(); - ui->lineEdit->setFocus(); + lineEdit->clear(); } -void ChatWindowPage::tabJoined() +void ChatWindowPage::newParticipant(const QString &nick) { - joining=true; -} -void ChatWindowPage::tabJoining() -{ - joining=false; -} - -void ChatWindowPage::connecte() -{ - - ui->splitter->show(); - Serveur *serveur=new Serveur; - QTextEdit *textEdit=new QTextEdit; - ui->hide3->hide(); - - ui->tab->addTab(textEdit,"Console/PM"); - ui->tab->setTabToolTip(ui->tab->count()-1,"irc.freenode.net"); - // current tab is now the last, therefore remove all but the last - for (int i = ui->tab->count(); i > 1; --i) { - ui->tab->removeTab(0); - } - - serveurs.insert("irc.freenode.net",serveur); - - serveur->pseudo=ui->editPseudo->text(); - serveur->serveur="irc.freenode.net"; - serveur->port=6667; - serveur->affichage=textEdit; - serveur->tab=ui->tab; - serveur->userList=ui->userView; - serveur->parent=this; - - textEdit->setReadOnly(true); - - connect(serveur, SIGNAL(joinTab()),this, SLOT(tabJoined() )); - connect(serveur, SIGNAL(tabJoined()),this, SLOT(tabJoining() )); - - serveur->connectToHost("irc.freenode.net",6667); - - ui->tab->setCurrentIndex(ui->tab->count()-1); + if (nick.isEmpty()) + return; + + QColor color = textEdit->textColor(); + textEdit->setTextColor(Qt::gray); + textEdit->append(tr("* %1 has joined").arg(nick)); + textEdit->setTextColor(color); + listWidget->addItem(nick); } -void ChatWindowPage::closeEvent(QCloseEvent *event) +void ChatWindowPage::participantLeft(const QString &nick) { - (void) event; - - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } - } + if (nick.isEmpty()) + return; + + QList items = listWidget->findItems(nick, + Qt::MatchExactly); + if (items.isEmpty()) + return; + + delete items.at(0); + QColor color = textEdit->textColor(); + textEdit->setTextColor(Qt::gray); + textEdit->append(tr("* %1 has left").arg(nick)); + textEdit->setTextColor(color); } -void ChatWindowPage ::setModel(ClientModel *model) -{ - this->model = model; -} - -void ChatWindowPage::on_pushButton_WebChat_clicked() { // #HTHWorld Chat - - QDesktopServices::openUrl(QUrl("https://webchat.freenode.net//", QUrl::TolerantMode)); - -} - -ChatWindowPage::~ChatWindowPage() +void ChatWindowPage::showInformation() { - delete ui; - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } + if (listWidget->count() == 1) { + QMessageBox::information(this, tr("Chat"), + tr("Launch several instances of this " + "program on your local network and " + "start chatting!")); } } From 5fb59a595f5222c16ab633487215f942925fef88 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:00:02 -0400 Subject: [PATCH 0028/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 122 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index 2beba14b..82d0d0c7 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -1,73 +1,79 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef CHATWINDOWPAGE_H #define CHATWINDOWPAGE_H -#include -#include -#include "clientmodel.h" -#include "serveur.h" +#include "ui_chatwindowpage.h" +#include "client.h" -#include -#include -#include - - - -namespace Ui -{ - class ChatWindowPage; -} - -class ChatWindowPage : public QWidget +class ChatWindowPage : public QDialog, private Ui::ChatWindowPage { Q_OBJECT public: - ChatWindowPage(QWidget *parent = 0); - ~ChatWindowPage(); - void setModel(ClientModel *model); - Serveur * currentTab(); - Q_SIGNALS: - void changeTab(); - - public Q_SLOTS: - void sendCommande(); - void connecte(); - void closeTab(); + ChatWindowPage(QWidget *parent = nullptr); - void tabChanged(int index); - - void tabJoined(); - void tabJoining(); - void disconnectFromServer(); - void tabClosing(int index); +public Q_SLOTS: + void appendMessage(const QString &from, const QString &message); +private Q_SLOTS: + void returnPressed(); + void newParticipant(const QString &nick); + void participantLeft(const QString &nick); + void showInformation(); private: - Ui::ChatWindowPage *ui; - ClientModel *model; - QMap serveurs; - bool joining; - void closeEvent(QCloseEvent *event); - -private Q_SLOTS: - void on_pushButton_WebChat_clicked(); - + Client client; + QString myNickName; + QTextTableFormat tableFormat; }; -#endif // CHATWINDOWPAGE_H +#endif From ceb482f7fdc3626e2c370d9a7c51efbb0c8205a7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:00:40 -0400 Subject: [PATCH 0029/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 378 ++++++--------------------------- 1 file changed, 67 insertions(+), 311 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index 7403c95e..f2fdc185 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -1,323 +1,79 @@ - - + ChatWindowPage - - + + 0 0 - 878 - 692 + 513 + 349 - - - - 0 - 50 - 851 - 611 - - - - - true - - - - 10 - 10 - 831 - 581 - - - - - - - - - 10 - 0 - 541 - 451 - - - - - - - QTabWidget::Rounded - - - 1 - - - false - - - - Tab 1 - - - - - Tab 2 - - - - - - - 10 - 460 - 717 - 30 - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - - - - 560 - 18 - 161 - 431 - - - - - 0 - 300 - - - - border-radius:10px; - - - - - - 625 - 500 - 100 - 30 - - - - - 100 - 30 - - - - - 100 - 30 - - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - Leave - - - - - - - 10 - 10 - 851 - 671 - - - - - - 179 - 40 - 241 - 29 - - - - - 7 - - - - - font-weight: bold; -font-size: 20px; - - - HTH World Chat - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 60 - 20 - - - - - - - - - - 185 - 210 - 151 - 22 - - - - - - - - - - 80 - 210 - 81 - 21 - - - - Nickname: - - - - - - 185 - 275 - 151 - 41 - - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - Click to Connect - - - - - - 140 - 142 - 251 - 25 - - - - <html><head/><body><p><span style=" font-weight:600;">Connect to #HTHWorld TrollBox</span></p></body></html> - - - Qt::AlignCenter - - - - - - 200 - 380 - 231 - 61 - - - - <html><head/><body><p>Enter your Nick</p><p>Enter #HTHWorld as Channel</p></body></html> - - - - - - 30 - 400 - 120 - 30 - - - - - 100 - 30 - - - - - 120 - 30 - - - - Visit HTH World Web Chat - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - #HTHWorld - - - - - - - Quitter - - - Ctrl+Q + + Chat + + + + 9 - - - - Fermer l'onglet + + 6 - + + + + 0 + + + 6 + + + + + Qt::NoFocus + + + true + + + + + + + + 180 + 16777215 + + + + Qt::NoFocus + + + + + + + + + 0 + + + 6 + + + + + Message: + + + + + + + + + - From c789f079328199d1d6dacec19ee6e492121c49d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:01:09 -0400 Subject: [PATCH 0030/1324] Create client.cpp --- src/qt/client.cpp | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/qt/client.cpp diff --git a/src/qt/client.cpp b/src/qt/client.cpp new file mode 100644 index 00000000..fe35d535 --- /dev/null +++ b/src/qt/client.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "client.h" +#include "connection.h" +#include "peermanager.h" + +Client::Client() +{ + peerManager = new PeerManager(this); + peerManager->setServerPort(server.serverPort()); + peerManager->startBroadcasting(); + + connect(peerManager, &PeerManager::newConnection, + this, &Client::newConnection); + connect(&server, &Server::newConnection, + this, &Client::newConnection); +} + +void Client::sendMessage(const QString &message) +{ + if (message.isEmpty()) + return; + + for (Connection *connection : qAsConst(peers)) + connection->sendMessage(message); +} + +QString Client::nickName() const +{ + return peerManager->userName() + '@' + QHostInfo::localHostName() + + ':' + QString::number(server.serverPort()); +} + +bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const +{ + if (senderPort == -1) + return peers.contains(senderIp); + + if (!peers.contains(senderIp)) + return false; + + const QList connections = peers.values(senderIp); + for (const Connection *connection : connections) { + if (connection->peerPort() == senderPort) + return true; + } + + return false; +} + +void Client::newConnection(Connection *connection) +{ + connection->setGreetingMessage(peerManager->userName()); + + connect(connection, &Connection::errorOccurred, this, &Client::connectionError); + connect(connection, &Connection::disconnected, this, &Client::disconnected); + connect(connection, &Connection::readyForUse, this, &Client::readyForUse); +} + +void Client::readyForUse() +{ + Connection *connection = qobject_cast(sender()); + if (!connection || hasConnection(connection->peerAddress(), + connection->peerPort())) + return; + + connect(connection, &Connection::newMessage, + this, &Client::newMessage); + + peers.insert(connection->peerAddress(), connection); + QString nick = connection->name(); + if (!nick.isEmpty()) + emit newParticipant(nick); +} + +void Client::disconnected() +{ + if (Connection *connection = qobject_cast(sender())) + removeConnection(connection); +} + +void Client::connectionError(QAbstractSocket::SocketError /* socketError */) +{ + if (Connection *connection = qobject_cast(sender())) + removeConnection(connection); +} + +void Client::removeConnection(Connection *connection) +{ + if (peers.contains(connection->peerAddress())) { + peers.remove(connection->peerAddress()); + QString nick = connection->name(); + if (!nick.isEmpty()) + emit participantLeft(nick); + } + connection->deleteLater(); +} From 01d146f8a56a91b19969495133597854511e781a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:01:57 -0400 Subject: [PATCH 0031/1324] Create client.h --- src/qt/client.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/qt/client.h diff --git a/src/qt/client.h b/src/qt/client.h new file mode 100644 index 00000000..d0a0c0d3 --- /dev/null +++ b/src/qt/client.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CLIENT_H +#define CLIENT_H + +#include +#include +#include + +#include "server.h" + +class PeerManager; + +class Client : public QObject +{ + Q_OBJECT + +public: + Client(); + + void sendMessage(const QString &message); + QString nickName() const; + bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const; + +Q_SIGNALS: + void newMessage(const QString &from, const QString &message); + void newParticipant(const QString &nick); + void participantLeft(const QString &nick); + +private Q_SLOTS: + void newConnection(Connection *connection); + void connectionError(QAbstractSocket::SocketError socketError); + void disconnected(); + void readyForUse(); + +private: + void removeConnection(Connection *connection); + + PeerManager *peerManager; + Server server; + QMultiHash peers; +}; + +#endif From 2102947f84cf6ef6c272f12d607d7382572b3795 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:02:26 -0400 Subject: [PATCH 0032/1324] Create connection.cpp --- src/qt/connection.cpp | 278 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 src/qt/connection.cpp diff --git a/src/qt/connection.cpp b/src/qt/connection.cpp new file mode 100644 index 00000000..cffd4953 --- /dev/null +++ b/src/qt/connection.cpp @@ -0,0 +1,278 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "connection.h" + +#include + +static const int TransferTimeout = 30 * 1000; +static const int PongTimeout = 60 * 1000; +static const int PingInterval = 5 * 1000; + +/* + * Protocol is defined as follows, using the CBOR Data Definition Language: + * + * protocol = [ + * greeting, ; must start with a greeting command + * * command ; zero or more regular commands after + * ] + * command = plaintext / ping / pong / greeting + * plaintext = { 0 => text } + * ping = { 1 => null } + * pong = { 2 => null } + * greeting = { 3 => text } + */ + +Connection::Connection(QObject *parent) + : QTcpSocket(parent), writer(this) +{ + greetingMessage = tr("undefined"); + username = tr("unknown"); + state = WaitingForGreeting; + currentDataType = Undefined; + transferTimerId = -1; + isGreetingMessageSent = false; + pingTimer.setInterval(PingInterval); + + connect(this, &QTcpSocket::readyRead, this, + &Connection::processReadyRead); + connect(this, &QTcpSocket::disconnected, + &pingTimer, &QTimer::stop); + connect(&pingTimer, &QTimer::timeout, + this, &Connection::sendPing); + connect(this, &QTcpSocket::connected, + this, &Connection::sendGreetingMessage); +} + +Connection::Connection(qintptr socketDescriptor, QObject *parent) + : Connection(parent) +{ + setSocketDescriptor(socketDescriptor); + reader.setDevice(this); +} + +Connection::~Connection() +{ + if (isGreetingMessageSent) { + // Indicate clean shutdown. + writer.endArray(); + waitForBytesWritten(2000); + } +} + +QString Connection::name() const +{ + return username; +} + +void Connection::setGreetingMessage(const QString &message) +{ + greetingMessage = message; +} + +bool Connection::sendMessage(const QString &message) +{ + if (message.isEmpty()) + return false; + + writer.startMap(1); + writer.append(PlainText); + writer.append(message); + writer.endMap(); + return true; +} + +void Connection::timerEvent(QTimerEvent *timerEvent) +{ + if (timerEvent->timerId() == transferTimerId) { + abort(); + killTimer(transferTimerId); + transferTimerId = -1; + } +} + +void Connection::processReadyRead() +{ + // we've got more data, let's parse + reader.reparse(); + while (reader.lastError() == QCborError::NoError) { + if (state == WaitingForGreeting) { + if (!reader.isArray()) + break; // protocol error + + reader.enterContainer(); // we'll be in this array forever + state = ReadingGreeting; + } else if (reader.containerDepth() == 1) { + // Current state: no command read + // Next state: read command ID + if (!reader.hasNext()) { + reader.leaveContainer(); + disconnectFromHost(); + return; + } + + if (!reader.isMap() || !reader.isLengthKnown() || reader.length() != 1) + break; // protocol error + reader.enterContainer(); + } else if (currentDataType == Undefined) { + // Current state: read command ID + // Next state: read command payload + if (!reader.isInteger()) + break; // protocol error + currentDataType = DataType(reader.toInteger()); + reader.next(); + } else { + // Current state: read command payload + if (reader.isString()) { + auto r = reader.readString(); + buffer += r.data; + if (r.status != QCborStreamReader::EndOfString) + continue; + } else if (reader.isNull()) { + reader.next(); + } else { + break; // protocol error + } + + // Next state: no command read + reader.leaveContainer(); + if (transferTimerId != -1) { + killTimer(transferTimerId); + transferTimerId = -1; + } + + if (state == ReadingGreeting) { + if (currentDataType != Greeting) + break; // protocol error + processGreeting(); + } else { + processData(); + } + } + } + + if (reader.lastError() != QCborError::EndOfFile) + abort(); // parse error + + if (transferTimerId != -1 && reader.containerDepth() > 1) + transferTimerId = startTimer(TransferTimeout); +} + +void Connection::sendPing() +{ + if (pongTime.elapsed() > PongTimeout) { + abort(); + return; + } + + writer.startMap(1); + writer.append(Ping); + writer.append(nullptr); // no payload + writer.endMap(); +} + +void Connection::sendGreetingMessage() +{ + writer.startArray(); // this array never ends + + writer.startMap(1); + writer.append(Greeting); + writer.append(greetingMessage); + writer.endMap(); + isGreetingMessageSent = true; + + if (!reader.device()) + reader.setDevice(this); +} + +void Connection::processGreeting() +{ + username = buffer + '@' + peerAddress().toString() + ':' + + QString::number(peerPort()); + currentDataType = Undefined; + buffer.clear(); + + if (!isValid()) { + abort(); + return; + } + + if (!isGreetingMessageSent) + sendGreetingMessage(); + + pingTimer.start(); + pongTime.start(); + state = ReadyForUse; + emit readyForUse(); +} + +void Connection::processData() +{ + switch (currentDataType) { + case PlainText: + emit newMessage(username, buffer); + break; + case Ping: + writer.startMap(1); + writer.append(Pong); + writer.append(nullptr); // no payload + writer.endMap(); + break; + case Pong: + pongTime.restart(); + break; + default: + break; + } + + currentDataType = Undefined; + buffer.clear(); +} From 524f7bf3ceafe5d79b87b08e5dd4f64aa2539da1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:03:01 -0400 Subject: [PATCH 0033/1324] Create connection.h --- src/qt/connection.h | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/qt/connection.h diff --git a/src/qt/connection.h b/src/qt/connection.h new file mode 100644 index 00000000..af5fa0ae --- /dev/null +++ b/src/qt/connection.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONNECTION_H +#define CONNECTION_H + +#include +#include +#include +#include +#include +#include +#include + +static const int MaxBufferSize = 1024000; + +class Connection : public QTcpSocket +{ + Q_OBJECT + +public: + enum ConnectionState { + WaitingForGreeting, + ReadingGreeting, + ReadyForUse + }; + enum DataType { + PlainText, + Ping, + Pong, + Greeting, + Undefined + }; + + Connection(QObject *parent = nullptr); + Connection(qintptr socketDescriptor, QObject *parent = nullptr); + ~Connection(); + + QString name() const; + void setGreetingMessage(const QString &message); + bool sendMessage(const QString &message); + +Q_SIGNALS: + void readyForUse(); + void newMessage(const QString &from, const QString &message); + +protected: + void timerEvent(QTimerEvent *timerEvent) override; + +private Q_SLOTS: + void processReadyRead(); + void sendPing(); + void sendGreetingMessage(); + +private: + bool hasEnoughData(); + void processGreeting(); + void processData(); + + QCborStreamReader reader; + QCborStreamWriter writer; + QString greetingMessage; + QString username; + QTimer pingTimer; + QElapsedTimer pongTime; + QString buffer; + ConnectionState state; + DataType currentDataType; + int transferTimerId; + bool isGreetingMessageSent; +}; + +#endif From 7beb55e15ae16b6d112aefb571debd83e39ef661 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:03:33 -0400 Subject: [PATCH 0034/1324] Create peermanager.cpp --- src/qt/peermanager.cpp | 196 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 src/qt/peermanager.cpp diff --git a/src/qt/peermanager.cpp b/src/qt/peermanager.cpp new file mode 100644 index 00000000..2c9d1822 --- /dev/null +++ b/src/qt/peermanager.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "client.h" +#include "connection.h" +#include "peermanager.h" + +static const qint32 BroadcastInterval = 2000; +static const unsigned broadcastPort = 45000; + +PeerManager::PeerManager(Client *client) + : QObject(client) +{ + this->client = client; + + static const char *envVariables[] = { + "USERNAME", "USER", "USERDOMAIN", "HOSTNAME", "DOMAINNAME" + }; + + for (const char *varname : envVariables) { + username = qEnvironmentVariable(varname); + if (!username.isNull()) + break; + } + + if (username.isEmpty()) + username = "unknown"; + + updateAddresses(); + serverPort = 0; + + broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress + | QUdpSocket::ReuseAddressHint); + connect(&broadcastSocket, &QUdpSocket::readyRead, + this, &PeerManager::readBroadcastDatagram); + + broadcastTimer.setInterval(BroadcastInterval); + connect(&broadcastTimer, &QTimer::timeout, + this, &PeerManager::sendBroadcastDatagram); +} + +void PeerManager::setServerPort(int port) +{ + serverPort = port; +} + +QString PeerManager::userName() const +{ + return username; +} + +void PeerManager::startBroadcasting() +{ + broadcastTimer.start(); +} + +bool PeerManager::isLocalHostAddress(const QHostAddress &address) const +{ + for (const QHostAddress &localAddress : ipAddresses) { + if (address.isEqual(localAddress)) + return true; + } + return false; +} + +void PeerManager::sendBroadcastDatagram() +{ + QByteArray datagram; + { + QCborStreamWriter writer(&datagram); + writer.startArray(2); + writer.append(username); + writer.append(serverPort); + writer.endArray(); + } + + bool validBroadcastAddresses = true; + for (const QHostAddress &address : qAsConst(broadcastAddresses)) { + if (broadcastSocket.writeDatagram(datagram, address, + broadcastPort) == -1) + validBroadcastAddresses = false; + } + + if (!validBroadcastAddresses) + updateAddresses(); +} + +void PeerManager::readBroadcastDatagram() +{ + while (broadcastSocket.hasPendingDatagrams()) { + QHostAddress senderIp; + quint16 senderPort; + QByteArray datagram; + datagram.resize(broadcastSocket.pendingDatagramSize()); + if (broadcastSocket.readDatagram(datagram.data(), datagram.size(), + &senderIp, &senderPort) == -1) + continue; + + int senderServerPort; + { + // decode the datagram + QCborStreamReader reader(datagram); + if (reader.lastError() != QCborError::NoError || !reader.isArray()) + continue; + if (!reader.isLengthKnown() || reader.length() != 2) + continue; + + reader.enterContainer(); + if (reader.lastError() != QCborError::NoError || !reader.isString()) + continue; + while (reader.readString().status == QCborStreamReader::Ok) { + // we don't actually need the username right now + } + + if (reader.lastError() != QCborError::NoError || !reader.isUnsignedInteger()) + continue; + senderServerPort = reader.toInteger(); + } + + if (isLocalHostAddress(senderIp) && senderServerPort == serverPort) + continue; + + if (!client->hasConnection(senderIp)) { + Connection *connection = new Connection(this); + emit newConnection(connection); + connection->connectToHost(senderIp, senderServerPort); + } + } +} + +void PeerManager::updateAddresses() +{ + broadcastAddresses.clear(); + ipAddresses.clear(); + const QList interfaces = QNetworkInterface::allInterfaces(); + for (const QNetworkInterface &interface : interfaces) { + const QList entries = interface.addressEntries(); + for (const QNetworkAddressEntry &entry : entries) { + QHostAddress broadcastAddress = entry.broadcast(); + if (broadcastAddress != QHostAddress::Null && entry.ip() != QHostAddress::LocalHost) { + broadcastAddresses << broadcastAddress; + ipAddresses << entry.ip(); + } + } + } +} From bcd75f0013190b1ecaf77580af9511d679cc1247 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:04:06 -0400 Subject: [PATCH 0035/1324] Create peermanager.h --- src/qt/peermanager.h | 94 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/qt/peermanager.h diff --git a/src/qt/peermanager.h b/src/qt/peermanager.h new file mode 100644 index 00000000..f5e9d6ee --- /dev/null +++ b/src/qt/peermanager.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PEERMANAGER_H +#define PEERMANAGER_H + +#include +#include +#include +#include +#include + +class Client; +class Connection; + +class PeerManager : public QObject +{ + Q_OBJECT + +public: + PeerManager(Client *client); + + void setServerPort(int port); + QString userName() const; + void startBroadcasting(); + bool isLocalHostAddress(const QHostAddress &address) const; + +Q_SIGNALS: + void newConnection(Connection *connection); + +private Q_SLOTS: + void sendBroadcastDatagram(); + void readBroadcastDatagram(); + +private: + void updateAddresses(); + + Client *client; + QList broadcastAddresses; + QList ipAddresses; + QUdpSocket broadcastSocket; + QTimer broadcastTimer; + QString username; + int serverPort; +}; + +#endif From 638dc5b130d106a2f3a1b456692e5c5ee89de90a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:04:43 -0400 Subject: [PATCH 0036/1324] Update and rename serveur.cpp to server.cpp --- src/qt/server.cpp | 66 +++++++++ src/qt/serveur.cpp | 359 --------------------------------------------- 2 files changed, 66 insertions(+), 359 deletions(-) create mode 100644 src/qt/server.cpp delete mode 100644 src/qt/serveur.cpp diff --git a/src/qt/server.cpp b/src/qt/server.cpp new file mode 100644 index 00000000..b3e4a07f --- /dev/null +++ b/src/qt/server.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "connection.h" +#include "server.h" + +Server::Server(QObject *parent) + : QTcpServer(parent) +{ + listen(QHostAddress::Any); +} + +void Server::incomingConnection(qintptr socketDescriptor) +{ + Connection *connection = new Connection(socketDescriptor, this); + emit newConnection(connection); +} diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp deleted file mode 100644 index 8178aec1..00000000 --- a/src/qt/serveur.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ -#include -#include "serveur.h" - QStringList users; - bool delist = true; -Serveur::Serveur() -{ - connect(this, SIGNAL(readyRead()), this, SLOT(readServeur())); - connect(this, SIGNAL(connected()), this, SLOT(connected())); - connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorSocket(QAbstractSocket::SocketError))); - - updateUsers=false; -} - - - - -void Serveur::errorSocket(QAbstractSocket::SocketError error) -{ - switch(error) - { - case QAbstractSocket::HostNotFoundError: - affichage->append(tr("ERROR : can't find HTHWorld server.")); - break; - case QAbstractSocket::ConnectionRefusedError: - affichage->append(tr("ERROR : server refused connection")); - break; - case QAbstractSocket::RemoteHostClosedError: - affichage->append(tr("ERROR : server cut connection")); - break; - default: - affichage->append(tr("ERROR : ") + this->errorString() + tr("")); - } -} - -void Serveur::connected() -{ - affichage->append("Connecting... to HTHWorld IRC. Please wait."); - - sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); - sendData("NICK "+pseudo); - affichage->append("Connected to HTHWorld IRC."); - -} - -void Serveur::joins() -{ - join("#HTHWorld"); -} - -void Serveur::readServeur() -{ - QString message=QString::fromUtf8(this->readAll()); - - - QString currentChan=tab->tabText(tab->currentIndex()); - - if(message.startsWith("PING :")) - { - QStringList liste=message.split(" "); - QString msg="PONG "+liste.at(1); - sendData(msg); - } - else if(message.contains("Nickname is already in use.")) - { - pseudo=pseudo+"_2"; - pseudo.remove("\r\n"); - sendData("NICK "+pseudo); - Q_EMIT pseudoChanged(pseudo); - ecrire("-> Name changed to "+pseudo); - } - else if(updateUsers==true) - { - updateUsersList("",message); - } - - QStringList list=message.split("\r\n"); - Q_FOREACH(QString msg,list) - { - if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 <\\1> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 join \\2
"),"",msg2.replace(reg,"-> \\1 join \\2")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 quit \\2 (\\3)
"),"",msg2.replace(reg,"-> \\1 quit \\2")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 quit this server (\\2)
"),"",msg2.replace(reg,"-> \\1 left")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\1 is now called \\2
"),"",msg2.replace(reg,"-> \\1 is now called \\2")); - updateUsersList(currentChan); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 kicked \\3 (\\4)
"),"",msg2.replace(reg,"-> \\1 quit \\3")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) - { - if(conversations.contains(currentChan)) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); - ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
"),currentChan); - } - else if(currentChan==serveur) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); - ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
")); - } - } - else if(msg.contains("/MOTD command.")) - { - joins(); - - - } - - - - } - - //} -} - -void Serveur::sendData(QString txt) -{ - if(this->state()==QAbstractSocket::ConnectedState) - { - this->write((txt+"\r\n").toUtf8()); - } -} - -QString Serveur::parseCommande(QString comm,bool serveur) -{ - if(comm.startsWith("/")) - { - comm.remove(0,1); - QString pref=comm.split(" ").first(); - QStringList args=comm.split(" "); - args.removeFirst(); - QString destChan=tab->tabText(tab->currentIndex()); - QString msg=args.join(" "); - - if(pref=="me") - return "PRIVMSG "+destChan+" ACTION " + msg + ""; - else if(pref=="msg") - return "MSG "+destChan+" ACTION " + msg + ""; - else if(pref=="join") - { - join(msg); - return " "; - } - else if(pref=="quit") - { - if(msg == "") - return "QUIT "+msgQuit; - else - return "QUIT "+msg; - } - else if(pref=="part") - { - tab->removeTab(tab->currentIndex()); - - if(msg == "") - { - if(msg.startsWith("#")) - destChan=msg.split(" ").first(); - - if(msgQuit=="") - return "PART "+destChan+" using IrcLightClient"; - else - return "PART "+destChan+" "+msgQuit; - } - else - return "PART "+destChan+" "+msg; - - conversations.remove(destChan); - } - else if(pref=="kick") - { - QStringList tableau=msg.split(" "); - QString c1,c2,c3; - if(tableau.count() > 0) c1=" "+tableau.first(); - else c1=""; - if(tableau.count() > 1) c2=" "+tableau.at(1); - else c2=""; - if(tableau.count() > 2) c3=" "+tableau.at(2); - else c3=""; - - if(c1.startsWith("#")) - return "KICK"+c1+c2+c3; - else - return "KICK "+destChan+c1+c2; - } - else if(pref=="update") - { - updateUsers=true; - return "WHO "+destChan; - } - else if(pref=="ns") - { - return "NICKSERV "+msg; - } - else if(pref=="nick") - { - Q_EMIT pseudoChanged(msg); - ecrire("-> Nickname changed to "+msg); - return "NICK "+msg; - } - else if(pref=="msg") - { - return "MSG "+msg; - } - - else - return pref+" "+msg; - } - else if(!serveur) - { - QString destChan=tab->tabText(tab->currentIndex()); - if(comm.endsWith("
")) - comm=comm.remove(QRegExp("
$")); - ecrire("<"+pseudo+"> "+comm,destChan); - - if(comm.startsWith(":")) - comm.insert(0,":"); - - return "PRIVMSG "+destChan+" "+comm.replace(" ","\t"); - } - else - { - return ""; - } -} - -void Serveur::join(QString chan) -{ - affichage->append("Joining "+ chan +" channel"); - Q_EMIT joinTab(); - QTextEdit *textEdit=new QTextEdit; - int index=tab->insertTab(tab->currentIndex()+1,textEdit,chan); - tab->setTabToolTip(index,serveur); - tab->setCurrentIndex(index); - - textEdit->setReadOnly(true); - - conversations.insert(chan,textEdit); - - sendData("JOIN "+chan); - - Q_EMIT tabJoined(); -} -void Serveur::leave(QString chan) -{ - sendData(parseCommande("/part "+chan+ " "+msgQuit)); -} - -void Serveur::ecrire(QString txt,QString destChan,QString msgTray) -{ - if(destChan!="") - { - conversations[destChan]->setHtml(conversations[destChan]->toHtml()+txt); - QScrollBar *sb = conversations[destChan]->verticalScrollBar(); - sb->setValue(sb->maximum()); - } - else if(txt.startsWith("#")) - { - QString dest=txt.split(" ").first(); - QStringList list=txt.split(" "); - list.removeFirst(); - txt=list.join(" "); - conversations[dest]->setHtml(conversations[dest]->toHtml()+txt); - QScrollBar *sb = conversations[dest]->verticalScrollBar(); - sb->setValue(sb->maximum()); } - else - { - txt.replace("\r\n","
"); - affichage->setHtml(affichage->toHtml()+txt+"
"); - QScrollBar *sb = affichage->verticalScrollBar(); - sb->setValue(sb->maximum()); - } - - -} - -void Serveur::updateUsersList(QString chan,QString message) -{ - message = message.replace("\r\n",""); - message = message.replace("\r",""); - if(chan!=serveur) - { - if(updateUsers==true || message != "") - { - QString liste2=message.replace(":",""); - QStringList liste=liste2.split(" "); - - if (delist == true) users.clear(); - - for(int i=5; i < liste.count(); i++) - { - users.append(liste.at(i)); - } - updateUsers=false; - if (liste.count() < 53) delist = true; - else delist = false; - QStringListModel *model = new QStringListModel(users); - userList->setModel(model); - userList->update(); - } - else - { - updateUsers=true; - sendData("NAMES "+chan); - } - } - else - { - QStringListModel model; - userList->setModel(&model); - userList->update(); - } -} From f38b2a8047ab54d903e7af6494397e3e4c0e2064 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:05:13 -0400 Subject: [PATCH 0037/1324] Update and rename serveur.h to server.h --- src/qt/server.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ src/qt/serveur.h | 67 -------------------------------------------- 2 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 src/qt/server.h delete mode 100644 src/qt/serveur.h diff --git a/src/qt/server.h b/src/qt/server.h new file mode 100644 index 00000000..ec0993f3 --- /dev/null +++ b/src/qt/server.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SERVER_H +#define SERVER_H + +#include + +class Connection; + +class Server : public QTcpServer +{ + Q_OBJECT + +public: + Server(QObject *parent = nullptr); + +Q_SIGNALS: + void newConnection(Connection *connection); + +protected: + void incomingConnection(qintptr socketDescriptor) override; +}; + +#endif diff --git a/src/qt/serveur.h b/src/qt/serveur.h deleted file mode 100644 index 9d2f6270..00000000 --- a/src/qt/serveur.h +++ /dev/null @@ -1,67 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ - -#ifndef SERVEUR_H -#define SERVEUR_H - -#include -#include -#include -#include -#include -#include - -class Serveur : public QTcpSocket -{ - Q_OBJECT - - public: - Serveur(); - QTextEdit *affichage; - QListView *userList; - QString pseudo,serveur,msgQuit; - int port; - QTabWidget *tab; - QMap conversations; - QSystemTrayIcon *tray; - - bool updateUsers; - - QString parseCommande(QString comm,bool serveur=false); - - QWidget *parent; - - - Q_SIGNALS: - void pseudoChanged(QString newPseudo); - void joinTab(); - void tabJoined(); - - public Q_SLOTS: - void readServeur(); - void errorSocket(QAbstractSocket::SocketError); - void connected(); - void joins(); - void sendData(QString txt); - void join(QString chan); - void leave(QString chan); - void ecrire(QString txt,QString destChan="",QString msgTray=""); - void updateUsersList(QString chan="",QString message=""); - - //void tabChanged(int index); -}; - -#endif // SERVEUR_H From 246317a7f16100f4f6f8d7d52bd038d0888d8bde Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:07:15 -0400 Subject: [PATCH 0038/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 8f8ce63d..a7ddde2a 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -17,7 +17,8 @@ FORMS += \ ../src/qt/forms/sendcoinsdialog.ui \ ../src/qt/forms/sendcoinsentry.ui \ ../src/qt/forms/signverifymessagedialog.ui \ - ../src/qt/forms/transactiondescdialog.ui + ../src/qt/forms/transactiondescdialog.ui \ + ../src/qt/forms/chatdialog.ui RESOURCES += \ ../src/qt/dash.qrc @@ -28,3 +29,24 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe + +HEADERS = chatdialog.h \ + client.h \ + connection.h \ + peermanager.h \ + server.h + +SOURCES = chatdialog.cpp \ + client.cpp \ + connection.cpp \ + main.cpp \ + peermanager.cpp \ + server.cpp + +QT += network widgets +requires(qtConfig(udpsocket)) +requires(qtConfig(listwidget)) + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/network/network-chat +INSTALLS += target From e420585404e1bb7e02e5873976854eb5be370b8f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:08:13 -0400 Subject: [PATCH 0039/1324] Create main.cpp --- src/qt/main.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..18681351 --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "chatwindowpage.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + ChatWindowPage dialog; + dialog.show(); + return app.exec(); +} From 149e3cc45591aa8e24579925db67af1e34fdf401 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:08:54 -0400 Subject: [PATCH 0040/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 670744da..1cefc43d 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -63,13 +63,13 @@ ChatWindowPage::ChatWindowPage(QWidget *parent) listWidget->setFocusPolicy(Qt::NoFocus); connect(lineEdit, &QLineEdit::returnPressed, - this, &ChatDialog::returnPressed); + this, &ChatWindowPage::returnPressed); connect(&client, &Client::newMessage, - this, &ChatDialog::appendMessage); + this, &ChatWindowPage::appendMessage); connect(&client, &Client::newParticipant, - this, &ChatDialog::newParticipant); + this, &ChatWindowPage::newParticipant); connect(&client, &Client::participantLeft, - this, &ChatDialog::participantLeft); + this, &ChatWindowPage::participantLeft); myNickName = client.nickName(); newParticipant(myNickName); From 65088ad25aca3a581d092f1e607d2d8e3c72eadb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:11:42 -0400 Subject: [PATCH 0041/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 0d1aa4d7..cb3080ec 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -96,7 +96,6 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ - qt/moc_serveur.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -178,7 +177,6 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ - qt/serveur.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -524,7 +522,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ - qt/serveur.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From b23a00389b4072a3132a46a635e6cc621144edfa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:26:21 -0400 Subject: [PATCH 0042/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index a7ddde2a..bf0d5423 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -17,8 +17,7 @@ FORMS += \ ../src/qt/forms/sendcoinsdialog.ui \ ../src/qt/forms/sendcoinsentry.ui \ ../src/qt/forms/signverifymessagedialog.ui \ - ../src/qt/forms/transactiondescdialog.ui \ - ../src/qt/forms/chatdialog.ui + ../src/qt/forms/transactiondescdialog.ui RESOURCES += \ ../src/qt/dash.qrc @@ -30,14 +29,12 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe -HEADERS = chatdialog.h \ - client.h \ +HEADERS = client.h \ connection.h \ peermanager.h \ server.h -SOURCES = chatdialog.cpp \ - client.cpp \ +SOURCES = client.cpp \ connection.cpp \ main.cpp \ peermanager.cpp \ From 2cd799a1242051de3b465dc62d8c2ffcd9c11456 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:31:36 -0400 Subject: [PATCH 0043/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index cb3080ec..cb4656b0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -66,9 +66,11 @@ QT_MOC_CPP = \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ qt/moc_chatwindowpage.cpp \ + qt/moc_client.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ + qt/moc_connection.cpp \ qt/moc_csvmodelwriter.cpp \ qt/moc_editaddressdialog.cpp \ qt/moc_governancelist.cpp \ @@ -77,6 +79,7 @@ QT_MOC_CPP = \ qt/moc_intro.cpp \ qt/moc_macdockiconhandler.cpp \ qt/moc_macnotificationhandler.cpp \ + qt/moc_main.cpp \ qt/moc_modaloverlay.cpp \ qt/moc_masternodelist.cpp \ qt/moc_notificator.cpp \ @@ -85,6 +88,7 @@ QT_MOC_CPP = \ qt/moc_optionsmodel.cpp \ qt/moc_overviewpage.cpp \ qt/moc_privatesendpage.cpp \ + qt/moc_peermanager.cpp \ qt/moc_peertablemodel.cpp \ qt/moc_paymentserver.cpp \ qt/moc_qrdialog.cpp \ @@ -96,6 +100,7 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ + qt/moc_server.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -142,9 +147,11 @@ BITCOIN_QT_H = \ qt/bitcoingui.h \ qt/bitcoinunits.h \ qt/chatwindowpage.h \ + qt/client.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ + qt/connection.h \ qt/csvmodelwriter.h \ qt/editaddressdialog.h \ qt/governancelist.h \ @@ -166,6 +173,7 @@ BITCOIN_QT_H = \ qt/privatesendpage.h \ qt/paymentrequestplus.h \ qt/paymentserver.h \ + qt/peermanager.h \ qt/peertablemodel.h \ qt/platformstyle.h \ qt/qrdialog.h \ @@ -177,6 +185,7 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ + qt/server.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -479,20 +488,24 @@ BITCOIN_QT_BASE_CPP = \ qt/bitcoinamountfield.cpp \ qt/bitcoingui.cpp \ qt/bitcoinunits.cpp \ + qt/client.cpp \ qt/clientmodel.cpp \ qt/csvmodelwriter.cpp \ qt/guiutil.cpp \ qt/intro.cpp \ + qt/main.cpp \ qt/modaloverlay.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ qt/optionsdialog.cpp \ qt/optionsmodel.cpp \ + qt/peermanager.cpp \ qt/peertablemodel.cpp \ qt/platformstyle.cpp \ qt/qvalidatedlineedit.cpp \ qt/qvaluecombobox.cpp \ qt/rpcconsole.cpp \ + qt/server.cpp \ qt/splashscreen.cpp \ qt/trafficgraphdata.cpp \ qt/trafficgraphwidget.cpp \ @@ -505,23 +518,28 @@ BITCOIN_QT_WALLET_CPP = \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ qt/chatwindowpage.cpp \ + qt/client.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ + qt/connection.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ + qt/main.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ qt/privatesendpage.cpp \ qt/paymentrequestplus.cpp \ qt/paymentserver.cpp \ + qt/peermanager.cpp \ qt/qrdialog.cpp \ qt/receivecoinsdialog.cpp \ qt/receiverequestdialog.cpp \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ + qt/server.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From 4c5f93eb829b09dca80056818cf82ffeda2915d3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:35:32 -0400 Subject: [PATCH 0044/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index bf0d5423..2f238d68 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -41,6 +41,7 @@ SOURCES = client.cpp \ server.cpp QT += network widgets + core requires(qtConfig(udpsocket)) requires(qtConfig(listwidget)) From 15821f00d964c443e6ea1c51a48f5675adb8ae90 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:38:58 -0400 Subject: [PATCH 0045/1324] Update qt.mk --- depends/packages/qt.mk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9579f605..c00606d6 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,9 +1,9 @@ PACKAGE=qt -$(package)_version=5.7.1 -$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.gz +$(package)_version=5.12.8 +$(package)_download_path=https://download.qt.io/new_archive/qt/5.12/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 +$(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase @@ -14,11 +14,11 @@ $(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpe # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d +$(package)_qttranslations_sha256_hash=180ea07c0aff6803ffad214c34f8ed1a77f8cac02e62f6e219bd1ede1dd66b6e $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f +$(package)_qttools_sha256_hash=21347e8e2422689d63a08195e27c637983c0d4261d5205ce6b493a2adfe826b4 $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) From 91abcb6f5590b969952d21c9db266712af904e05 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:41:28 -0400 Subject: [PATCH 0046/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index c00606d6..dfcd2e6d 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,6 +1,6 @@ PACKAGE=qt $(package)_version=5.12.8 -$(package)_download_path=https://download.qt.io/new_archive/qt/5.12/$($(package)_version)/submodules +$(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules $(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) $(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 From b73ca5f980609933fa3b3570a25b56c8fbef2d46 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:42:15 -0400 Subject: [PATCH 0047/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index dfcd2e6d..d04de6c4 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,7 +1,7 @@ PACKAGE=qt $(package)_version=5.12.8 $(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.xz +$(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) $(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 $(package)_dependencies=openssl zlib From f21b45ddad870bdea6413b1879049e4cfcd7f8f7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:03:14 -0400 Subject: [PATCH 0048/1324] Update qt.mk --- depends/packages/qt.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index d04de6c4..36f8c139 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,9 +1,9 @@ PACKAGE=qt -$(package)_version=5.12.8 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules +$(package)_version=5.13.2 +$(package)_download_path=https://download.qt.io/official_releases/qt/5.13/$($(package)_version)/submodules $(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 +$(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase @@ -14,11 +14,11 @@ $(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpe # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=180ea07c0aff6803ffad214c34f8ed1a77f8cac02e62f6e219bd1ede1dd66b6e +$(package)_qttranslations_sha256_hash=25755941a2525de2d7ae48e0011d04db7cc09e4e73fe83293206ceafa0aa82d9 $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=21347e8e2422689d63a08195e27c637983c0d4261d5205ce6b493a2adfe826b4 +$(package)_qttools_sha256_hash=919a2713b6d2d7873a09ad85bd93cf4282606e5bf84d5884250f665a253ec06e $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) From 61be5ffa9af52251e151d1fd49ea61d244ed9756 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:31:37 -0400 Subject: [PATCH 0049/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 2f238d68..ca0889ec 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -24,6 +24,8 @@ RESOURCES += \ CONFIG += c++11 +CODECFORTR = UTF-8 + SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ From 73d5c2e9427fa16671b889b7709f14f40cc1c3fd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:49:52 -0400 Subject: [PATCH 0050/1324] Update qt.mk --- depends/packages/qt.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 36f8c139..eaa10b49 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,9 +1,9 @@ PACKAGE=qt -$(package)_version=5.13.2 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.13/$($(package)_version)/submodules +$(package)_version=5.9.9 +$(package)_download_path=https://download.qt.io/official_releases/qt/5.9/$($(package)_version)/submodules $(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 +$(package)_sha256_hash=d5a97381b9339c0fbaf13f0c05d599a5c999dcf94145044058198987183fed65 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase @@ -14,11 +14,11 @@ $(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpe # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=25755941a2525de2d7ae48e0011d04db7cc09e4e73fe83293206ceafa0aa82d9 +$(package)_qttranslations_sha256_hash=f7474f260a1382549720081bf2359a3d425ec3bf7d31976c512834303d30d73b $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=919a2713b6d2d7873a09ad85bd93cf4282606e5bf84d5884250f665a253ec06e +$(package)_qttools_sha256_hash=fce6e0fd39a40bcef880c669080087dba94af1ec442296222210472e0852bf98 $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) From f9e25ddec7bc7c14f6efd4a11ac086dccf8c6cab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:50:22 -0400 Subject: [PATCH 0051/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index eaa10b49..95240b41 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,7 +1,7 @@ PACKAGE=qt $(package)_version=5.9.9 $(package)_download_path=https://download.qt.io/official_releases/qt/5.9/$($(package)_version)/submodules -$(package)_suffix=everywhere-src-$($(package)_version).tar.xz +$(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) $(package)_sha256_hash=d5a97381b9339c0fbaf13f0c05d599a5c999dcf94145044058198987183fed65 $(package)_dependencies=openssl zlib From c261291ca94a98bc74d86cc1572dd87e7f6a1ead Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:53:42 -0400 Subject: [PATCH 0052/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 95240b41..5e73ac3c 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -9,7 +9,7 @@ $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib $(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch -$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch +$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch xkb-default.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. From 46f922b7cd779d75c76a11dcb0f87395e9a87bcf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:54:36 -0400 Subject: [PATCH 0053/1324] Create fix_configure_mac.patch --- depends/patches/qt/fix_configure_mac.patch | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 depends/patches/qt/fix_configure_mac.patch diff --git a/depends/patches/qt/fix_configure_mac.patch b/depends/patches/qt/fix_configure_mac.patch new file mode 100644 index 00000000..2d9c20f5 --- /dev/null +++ b/depends/patches/qt/fix_configure_mac.patch @@ -0,0 +1,48 @@ +--- old/qtbase/mkspecs/features/mac/sdk.prf 2018-02-08 10:24:48.000000000 -0800 ++++ new/qtbase/mkspecs/features/mac/sdk.prf 2018-03-23 10:38:56.000000000 -0700 +@@ -8,21 +8,21 @@ + defineReplace(xcodeSDKInfo) { + info = $$1 + equals(info, "Path"): \ +- info = --show-sdk-path ++ infoarg = --show-sdk-path + equals(info, "PlatformPath"): \ +- info = --show-sdk-platform-path ++ infoarg = --show-sdk-platform-path + equals(info, "SDKVersion"): \ +- info = --show-sdk-version ++ infoarg = --show-sdk-version + sdk = $$2 + isEmpty(sdk): \ + sdk = $$QMAKE_MAC_SDK + + isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}) { +- QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcrun --sdk $$sdk $$info 2>/dev/null") ++ QMAKE_MAC_SDK.$${sdk}.$${info} = $$system("/usr/bin/xcrun --sdk $$sdk $$infoarg 2>/dev/null") + # --show-sdk-platform-path won't work for Command Line Tools; this is fine + # only used by the XCTest backend to testlib +- isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}):if(!isEmpty(QMAKE_XCODEBUILD_PATH)|!equals(info, "--show-sdk-platform-path")): \ +- error("Could not resolve SDK $$info for \'$$sdk\'") ++ isEmpty(QMAKE_MAC_SDK.$${sdk}.$${info}):if(!isEmpty(QMAKE_XCODEBUILD_PATH)|!equals(infoarg, "--show-sdk-platform-path")): \ ++ error("Could not resolve SDK $$info for \'$$sdk\' using $$infoarg") + cache(QMAKE_MAC_SDK.$${sdk}.$${info}, set stash, QMAKE_MAC_SDK.$${sdk}.$${info}) + } + +--- old/qtbase/configure 2018-02-08 10:24:48.000000000 -0800 ++++ new/qtbase/configure 2018-03-23 05:42:29.000000000 -0700 +@@ -232,8 +232,13 @@ + + sdk=$(getSingleQMakeVariable "QMAKE_MAC_SDK" "$1") + if [ -z "$sdk" ]; then echo "QMAKE_MAC_SDK must be set when building on Mac" >&2; exit 1; fi +- sysroot=$(/usr/bin/xcrun --sdk $sdk --show-sdk-path 2>/dev/null) +- if [ -z "$sysroot" ]; then echo "Failed to resolve SDK path for '$sdk'" >&2; exit 1; fi ++ sysroot=$(getSingleQMakeVariable "QMAKE_MAC_SDK_PATH" "$1") ++ ++ echo "sysroot pre-configured as $sysroot"; ++ if [ -z "$sysroot" ]; then ++ sysroot=$(/usr/bin/xcrun --sdk $sdk --show-sdk-path 2>/dev/null) ++ if [ -z "$sysroot" ]; then echo "Failed to resolve SDK path for '$sdk'" >&2; exit 1; fi ++ fi + + case "$sdk" in + macosx*) From 54e793bbff7b63e01d2c7e92ad669af8b5a1aff0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:54:57 -0400 Subject: [PATCH 0054/1324] Create fix_no_printer.patch --- depends/patches/qt/fix_no_printer.patch | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 depends/patches/qt/fix_no_printer.patch diff --git a/depends/patches/qt/fix_no_printer.patch b/depends/patches/qt/fix_no_printer.patch new file mode 100644 index 00000000..f868ca25 --- /dev/null +++ b/depends/patches/qt/fix_no_printer.patch @@ -0,0 +1,19 @@ +--- x/qtbase/src/plugins/platforms/cocoa/qprintengine_mac_p.h ++++ y/qtbase/src/plugins/platforms/cocoa/qprintengine_mac_p.h +@@ -52,6 +52,7 @@ + // + + #include ++#include + + #ifndef QT_NO_PRINTER + +--- x/qtbase/src/plugins/plugins.pro ++++ y/qtbase/src/plugins/plugins.pro +@@ -8,6 +8,3 @@ qtHaveModule(gui) { + qtConfig(imageformatplugin): SUBDIRS *= imageformats + !android:qtConfig(library): SUBDIRS *= generic + } +- +-!winrt:qtHaveModule(printsupport): \ +- SUBDIRS += printsupport From 689c4372a8c2fc2858b7d7ecf29b30bc6dcefc2d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:55:18 -0400 Subject: [PATCH 0055/1324] Create fix_rcc_determinism.patch --- depends/patches/qt/fix_rcc_determinism.patch | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 depends/patches/qt/fix_rcc_determinism.patch diff --git a/depends/patches/qt/fix_rcc_determinism.patch b/depends/patches/qt/fix_rcc_determinism.patch new file mode 100644 index 00000000..c1b07fe2 --- /dev/null +++ b/depends/patches/qt/fix_rcc_determinism.patch @@ -0,0 +1,15 @@ +--- old/qtbase/src/tools/rcc/rcc.cpp ++++ new/qtbase/src/tools/rcc/rcc.cpp +@@ -207,7 +207,11 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib) + if (lib.formatVersion() >= 2) { + // last modified time stamp + const QDateTime lastModified = m_fileInfo.lastModified(); +- lib.writeNumber8(quint64(lastModified.isValid() ? lastModified.toMSecsSinceEpoch() : 0)); ++ quint64 lastmod = quint64(lastModified.isValid() ? lastModified.toMSecsSinceEpoch() : 0); ++ static const quint64 sourceDate = 1000 * qgetenv("QT_RCC_SOURCE_DATE_OVERRIDE").toULongLong(); ++ if (sourceDate != 0) ++ lastmod = sourceDate; ++ lib.writeNumber8(lastmod); + if (text || pass1) + lib.writeChar('\n'); + } From 108017230ca67e0786af632c84fe0775887a3c36 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:56:21 -0400 Subject: [PATCH 0056/1324] Create xkb-default.patch --- depends/patches/qt/xkb-default.patch | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 depends/patches/qt/xkb-default.patch diff --git a/depends/patches/qt/xkb-default.patch b/depends/patches/qt/xkb-default.patch new file mode 100644 index 00000000..165abf3e --- /dev/null +++ b/depends/patches/qt/xkb-default.patch @@ -0,0 +1,26 @@ +--- old/qtbase/src/gui/configure.pri 2018-06-06 17:28:10.000000000 -0400 ++++ new/qtbase/src/gui/configure.pri 2018-08-17 18:43:01.589384567 -0400 +@@ -43,18 +43,11 @@ + } + + defineTest(qtConfTest_xkbConfigRoot) { +- qtConfTest_getPkgConfigVariable($${1}): return(true) +- +- for (dir, $$list("/usr/share/X11/xkb", "/usr/local/share/X11/xkb")) { +- exists($$dir) { +- $${1}.value = $$dir +- export($${1}.value) +- $${1}.cache += value +- export($${1}.cache) +- return(true) +- } +- } +- return(false) ++ $${1}.value = "/usr/share/X11/xkb" ++ export($${1}.value) ++ $${1}.cache += value ++ export($${1}.cache) ++ return(true) + } + + defineTest(qtConfTest_qpaDefaultPlatform) { From 3b47f45c6dd5e6d7bd240a8119e329d2e25d4753 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:57:35 -0400 Subject: [PATCH 0057/1324] Update qt.mk --- depends/packages/qt.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 5e73ac3c..04fda29b 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -147,6 +147,11 @@ define $(package)_preprocess_cmds patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ + patch -p1 -i $($(package)_patch_dir)/fix_qt_pkgconfig.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_configure_mac.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_no_printer.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ + patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From 543ec428a3f1405f0ffb68185f5e3a6698bb8603 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:59:44 -0400 Subject: [PATCH 0058/1324] Update qt.mk --- depends/packages/qt.mk | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 04fda29b..9579f605 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,24 +1,24 @@ PACKAGE=qt -$(package)_version=5.9.9 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.9/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.xz +$(package)_version=5.7.1 +$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.gz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=d5a97381b9339c0fbaf13f0c05d599a5c999dcf94145044058198987183fed65 +$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib $(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch -$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch xkb-default.patch +$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=f7474f260a1382549720081bf2359a3d425ec3bf7d31976c512834303d30d73b +$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=fce6e0fd39a40bcef880c669080087dba94af1ec442296222210472e0852bf98 +$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) @@ -147,11 +147,6 @@ define $(package)_preprocess_cmds patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ - patch -p1 -i $($(package)_patch_dir)/fix_qt_pkgconfig.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_configure_mac.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_no_printer.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ - patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From 944983611cb321aaf1a5d5ed485ac0dbf91b9669 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:14:41 -0400 Subject: [PATCH 0059/1324] Update qt.mk --- depends/packages/qt.mk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9579f605..efb538dd 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,9 +1,9 @@ PACKAGE=qt -$(package)_version=5.7.1 -$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.gz +$(package)_version=5.13.2 +$(package)_download_path=https://download.qt.io/new_archive/qt/5.13/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 +$(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase @@ -14,11 +14,11 @@ $(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpe # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d +$(package)_qttranslations_sha256_hash=25755941a2525de2d7ae48e0011d04db7cc09e4e73fe83293206ceafa0aa82d9 $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f +$(package)_qttools_sha256_hash=919a2713b6d2d7873a09ad85bd93cf4282606e5bf84d5884250f665a253ec06e $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) From 16fd809d877f6d916866c977c8c99f5e6593a3d1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:15:10 -0400 Subject: [PATCH 0060/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index efb538dd..7c2bf46f 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,6 +1,6 @@ PACKAGE=qt $(package)_version=5.13.2 -$(package)_download_path=https://download.qt.io/new_archive/qt/5.13/$($(package)_version)/submodules +$(package)_download_path=https://download.qt.io/official_releases/qt/5.13/$($(package)_version)/submodules $(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) $(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 From 0eeb1436ff6415c7f409fb4f0150bbd0be7c2b84 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:15:49 -0400 Subject: [PATCH 0061/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 7c2bf46f..36f8c139 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,7 +1,7 @@ PACKAGE=qt $(package)_version=5.13.2 $(package)_download_path=https://download.qt.io/official_releases/qt/5.13/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.xz +$(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) $(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 $(package)_dependencies=openssl zlib From 4d56f33521691218ab31b9dff7f3e21d85a7a344 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:16:47 -0400 Subject: [PATCH 0062/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 36f8c139..74459fb7 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,7 +8,7 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +/*$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch */ $(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. From ce2a80ea45ffb7302e6e7346b1827135a7bb179d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:17:42 -0400 Subject: [PATCH 0063/1324] Update qt.mk --- depends/packages/qt.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 74459fb7..1e364153 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,8 +8,8 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -/*$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch */ -$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch +#$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +#$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. @@ -140,13 +140,13 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ - patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ - patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ - patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ + # patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ + # patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ + # patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ + # patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ + # patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ + # patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ + # patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From b80c76fa6a1c730dbf26b33837d3c64abe5860a1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:20:05 -0400 Subject: [PATCH 0064/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 1e364153..c33bdee5 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -139,7 +139,7 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ - cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ + cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && # patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ # patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ # patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ From 6b4fd3b534a88d72fa420fbd0a2afec43195343e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:22:31 -0400 Subject: [PATCH 0065/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index c33bdee5..1e364153 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -139,7 +139,7 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ - cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && + cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ # patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ # patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ # patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ From 5cd7b8ec7c84cfb01fadf82648a265c4172e06b9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:26:25 -0400 Subject: [PATCH 0066/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 1e364153..72bbe77f 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -139,7 +139,7 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ - cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ + cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ # patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ # patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ # patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ From ae3f90f99b63d9e22832467838c5d6e7fb6dc06e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:34:24 -0400 Subject: [PATCH 0067/1324] Update qt.mk --- depends/packages/qt.mk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 72bbe77f..3a9cfcdd 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -140,13 +140,13 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ - # patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ - # patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ - # patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ - # patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ - # patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ - # patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ - # patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ + patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ + patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ + patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From e5956b9f40379a506a1a97a8b88ee99871e7bc46 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:35:01 -0400 Subject: [PATCH 0068/1324] Update qt.mk --- depends/packages/qt.mk | 7 ------- 1 file changed, 7 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 3a9cfcdd..ee712b95 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -140,13 +140,6 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ - patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ - patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ - patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From 4404dda531dc814158fb6a3b8c78bfae7538f553 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:38:08 -0400 Subject: [PATCH 0069/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index ee712b95..6be656fe 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,7 +8,7 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -#$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +$(package)_patches=mac-qmake.conf #mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch #$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. From 46ded06bce8ce4ca3479ce9061ee914ddbaeff83 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:40:59 -0400 Subject: [PATCH 0070/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 6be656fe..cccad63c 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -31,7 +31,6 @@ $(package)_config_opts += -c++std c++11 $(package)_config_opts += -confirm-license $(package)_config_opts += -dbus-runtime $(package)_config_opts += -hostprefix $(build_prefix) -$(package)_config_opts += -no-alsa $(package)_config_opts += -no-audio-backend $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl From db4cdcccd674876ed81c3a900c8dcde634ce531f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:43:55 -0400 Subject: [PATCH 0071/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index cccad63c..acbbad25 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -31,7 +31,6 @@ $(package)_config_opts += -c++std c++11 $(package)_config_opts += -confirm-license $(package)_config_opts += -dbus-runtime $(package)_config_opts += -hostprefix $(build_prefix) -$(package)_config_opts += -no-audio-backend $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs From cdf09a1fdb11423be9ee4b9c81043a2545ae73ad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:46:30 -0400 Subject: [PATCH 0072/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index acbbad25..0ff63dfc 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -34,7 +34,6 @@ $(package)_config_opts += -hostprefix $(build_prefix) $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs -$(package)_config_opts += -no-feature-style-windowsmobile $(package)_config_opts += -no-feature-style-windowsce $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif From c09d81bf2d4f477e1ecd0840ccfc67aa46496cf7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:48:41 -0400 Subject: [PATCH 0073/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 0ff63dfc..38720536 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -34,7 +34,6 @@ $(package)_config_opts += -hostprefix $(build_prefix) $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs -$(package)_config_opts += -no-feature-style-windowsce $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif $(package)_config_opts += -no-glib From 8561f472760c6f8d9501c303e667b0b504734ca3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:50:48 -0400 Subject: [PATCH 0074/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 38720536..9b5d22ec 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -37,7 +37,6 @@ $(package)_config_opts += -no-eglfs $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif $(package)_config_opts += -no-glib -$(package)_config_opts += -no-gstreamer $(package)_config_opts += -no-icu $(package)_config_opts += -no-iconv $(package)_config_opts += -no-kms From bfba254a85c13ddf7fbc947d6129a439f13f4abc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:52:35 -0400 Subject: [PATCH 0075/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9b5d22ec..2425bc56 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -42,7 +42,6 @@ $(package)_config_opts += -no-iconv $(package)_config_opts += -no-kms $(package)_config_opts += -no-linuxfb $(package)_config_opts += -no-libudev -$(package)_config_opts += -no-mitshm $(package)_config_opts += -no-mtdev $(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg From f454e1d5929a583793ba05d40382cbd141b66c94 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:54:18 -0400 Subject: [PATCH 0076/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 2425bc56..34dd14df 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -43,7 +43,6 @@ $(package)_config_opts += -no-kms $(package)_config_opts += -no-linuxfb $(package)_config_opts += -no-libudev $(package)_config_opts += -no-mtdev -$(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug From 0786db0e5c7a03e6ca690279179881e7926552db Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 4 Jun 2020 23:59:07 -0400 Subject: [PATCH 0077/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 34dd14df..d1e6aa37 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -45,7 +45,6 @@ $(package)_config_opts += -no-libudev $(package)_config_opts += -no-mtdev $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations -$(package)_config_opts += -no-qml-debug $(package)_config_opts += -no-sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci From 0f90f2d82166f39badb4d78928d26d6e0bf2ed1d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:03:23 -0400 Subject: [PATCH 0078/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index d1e6aa37..f1e53a20 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -55,7 +55,6 @@ $(package)_config_opts += -no-sql-psql $(package)_config_opts += -no-sql-sqlite $(package)_config_opts += -no-sql-sqlite2 $(package)_config_opts += -no-use-gold-linker -$(package)_config_opts += -no-xinput2 $(package)_config_opts += -no-xrender $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests From 0f6fdc855f9c6e85a11872fe846124003544a838 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:07:06 -0400 Subject: [PATCH 0079/1324] Update qt.mk --- depends/packages/qt.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index f1e53a20..92e19c52 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -55,7 +55,6 @@ $(package)_config_opts += -no-sql-psql $(package)_config_opts += -no-sql-sqlite $(package)_config_opts += -no-sql-sqlite2 $(package)_config_opts += -no-use-gold-linker -$(package)_config_opts += -no-xrender $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource From 3f81dd7bef1e4ff45a7e3354d7103f947fbf8b40 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:14:54 -0400 Subject: [PATCH 0080/1324] Update qt.mk --- depends/packages/qt.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 92e19c52..49dc1678 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -58,17 +58,13 @@ $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource -$(package)_config_opts += -openssl-linked $(package)_config_opts += -optimized-qmake $(package)_config_opts += -pch -$(package)_config_opts += -pkg-config $(package)_config_opts += -prefix $(host_prefix) $(package)_config_opts += -qt-libpng $(package)_config_opts += -qt-libjpeg $(package)_config_opts += -qt-pcre $(package)_config_opts += -qt-harfbuzz -$(package)_config_opts += -system-zlib -$(package)_config_opts += -reduce-exports $(package)_config_opts += -static $(package)_config_opts += -silent $(package)_config_opts += -v From 3eb27ac1cf0d9a8e0fb74a6ab0dcbdb72de6087a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:38:42 -0400 Subject: [PATCH 0081/1324] Update qt.mk --- depends/packages/qt.mk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 49dc1678..5620bc82 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,8 +8,8 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=mac-qmake.conf #mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch -#$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch +$(package)_patches=mac-qmake.conf fix_qt_pkgconfig.patch #mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +#$(package)_patches+=fix_qt_configure.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. @@ -60,6 +60,7 @@ $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource $(package)_config_opts += -optimized-qmake $(package)_config_opts += -pch +$(package)_config_opts += -pkg-config $(package)_config_opts += -prefix $(host_prefix) $(package)_config_opts += -qt-libpng $(package)_config_opts += -qt-libjpeg @@ -67,6 +68,7 @@ $(package)_config_opts += -qt-pcre $(package)_config_opts += -qt-harfbuzz $(package)_config_opts += -static $(package)_config_opts += -silent +$(package)_config_opts += -system-zlib $(package)_config_opts += -v $(package)_config_opts += -no-feature-printer $(package)_config_opts += -no-feature-printdialog @@ -126,6 +128,7 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ + patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From 19f63cecbe5d360175dcfda277826a5f64ed640a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:51:35 -0400 Subject: [PATCH 0082/1324] Update qt.mk --- depends/packages/qt.mk | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 5620bc82..4ee1d0e0 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,24 +1,24 @@ PACKAGE=qt $(package)_version=5.13.2 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.13/$($(package)_version)/submodules +$(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules $(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=26b6b686d66a7ad28eaca349e55e2894e5a735f3831e45f2049e93b1daa92121 +$(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=mac-qmake.conf fix_qt_pkgconfig.patch #mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +$(package)_patches=mac-qmake.conf #fix_qt_pkgconfig.patch mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch #$(package)_patches+=fix_qt_configure.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=25755941a2525de2d7ae48e0011d04db7cc09e4e73fe83293206ceafa0aa82d9 +$(package)_qttranslations_sha256_hash=180ea07c0aff6803ffad214c34f8ed1a77f8cac02e62f6e219bd1ede1dd66b6e $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=919a2713b6d2d7873a09ad85bd93cf4282606e5bf84d5884250f665a253ec06e +$(package)_qttools_sha256_hash=21347e8e2422689d63a08195e27c637983c0d4261d5205ce6b493a2adfe826b4 $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) @@ -128,7 +128,6 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ - patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From d370a81c6ee7751786be3d0ce61e3bf232d18a12 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 00:51:50 -0400 Subject: [PATCH 0083/1324] Update qt.mk --- depends/packages/qt.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 4ee1d0e0..095d03ad 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,5 +1,5 @@ PACKAGE=qt -$(package)_version=5.13.2 +$(package)_version=5.12.8 $(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules $(package)_suffix=everywhere-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) From e880b726b24cc000295a27d79da0c248a9683d33 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:24:46 -0400 Subject: [PATCH 0084/1324] Update connection.h --- src/qt/connection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/connection.h b/src/qt/connection.h index af5fa0ae..47ebfb25 100644 --- a/src/qt/connection.h +++ b/src/qt/connection.h @@ -51,8 +51,8 @@ #ifndef CONNECTION_H #define CONNECTION_H -#include -#include +/*#include +#include */ #include #include #include From a4ed9bfa670d8701a72bcd6b1376b216b4305982 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:27:42 -0400 Subject: [PATCH 0085/1324] Update client.cpp --- src/qt/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/client.cpp b/src/qt/client.cpp index fe35d535..11c0f22c 100644 --- a/src/qt/client.cpp +++ b/src/qt/client.cpp @@ -120,7 +120,7 @@ void Client::readyForUse() peers.insert(connection->peerAddress(), connection); QString nick = connection->name(); if (!nick.isEmpty()) - emit newParticipant(nick); + Q_EMIT newParticipant(nick); } void Client::disconnected() @@ -141,7 +141,7 @@ void Client::removeConnection(Connection *connection) peers.remove(connection->peerAddress()); QString nick = connection->name(); if (!nick.isEmpty()) - emit participantLeft(nick); + Q_EMIT participantLeft(nick); } connection->deleteLater(); } From 820768c873ce1b603362d5117775e2f6af0e7c09 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:28:17 -0400 Subject: [PATCH 0086/1324] Update server.cpp --- src/qt/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/server.cpp b/src/qt/server.cpp index b3e4a07f..930d711f 100644 --- a/src/qt/server.cpp +++ b/src/qt/server.cpp @@ -62,5 +62,5 @@ Server::Server(QObject *parent) void Server::incomingConnection(qintptr socketDescriptor) { Connection *connection = new Connection(socketDescriptor, this); - emit newConnection(connection); + Q_EMIT newConnection(connection); } From 0b4a3d03d71f95249989bddd93f4ba4c593eb35b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:29:16 -0400 Subject: [PATCH 0087/1324] Update peermanager.cpp --- src/qt/peermanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/peermanager.cpp b/src/qt/peermanager.cpp index 2c9d1822..7267616c 100644 --- a/src/qt/peermanager.cpp +++ b/src/qt/peermanager.cpp @@ -172,7 +172,7 @@ void PeerManager::readBroadcastDatagram() if (!client->hasConnection(senderIp)) { Connection *connection = new Connection(this); - emit newConnection(connection); + Q_EMIT newConnection(connection); connection->connectToHost(senderIp, senderServerPort); } } From 0e85e3ccbd5d4452c26d972e49fea678a123aec2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:30:25 -0400 Subject: [PATCH 0088/1324] Update connection.cpp --- src/qt/connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/connection.cpp b/src/qt/connection.cpp index cffd4953..5cd32cf3 100644 --- a/src/qt/connection.cpp +++ b/src/qt/connection.cpp @@ -251,7 +251,7 @@ void Connection::processGreeting() pingTimer.start(); pongTime.start(); state = ReadyForUse; - emit readyForUse(); + Q_EMIT readyForUse(); } void Connection::processData() From 0eecfb6302eba8ed29a41899989bda03396789fa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:31:21 -0400 Subject: [PATCH 0089/1324] Update connection.h --- src/qt/connection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/connection.h b/src/qt/connection.h index 47ebfb25..af5fa0ae 100644 --- a/src/qt/connection.h +++ b/src/qt/connection.h @@ -51,8 +51,8 @@ #ifndef CONNECTION_H #define CONNECTION_H -/*#include -#include */ +#include +#include #include #include #include From ccd41cbfb820ac726a4cd31e32adbe996a50318a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:48:06 -0400 Subject: [PATCH 0090/1324] Update connection.h --- src/qt/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/connection.h b/src/qt/connection.h index af5fa0ae..cb36ab21 100644 --- a/src/qt/connection.h +++ b/src/qt/connection.h @@ -51,7 +51,7 @@ #ifndef CONNECTION_H #define CONNECTION_H -#include +#include #include #include #include From 31f735995d93fc079ee6d6c653aa4508a0a7a91f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 5 Jun 2020 01:48:49 -0400 Subject: [PATCH 0091/1324] Update connection.h --- src/qt/connection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/connection.h b/src/qt/connection.h index cb36ab21..af5fa0ae 100644 --- a/src/qt/connection.h +++ b/src/qt/connection.h @@ -51,7 +51,7 @@ #ifndef CONNECTION_H #define CONNECTION_H -#include +#include #include #include #include From 65eb0ec4453bc42104c1b62c16241f7417dd2755 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:18:42 -0400 Subject: [PATCH 0092/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 143 ++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 67 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index f2fdc185..e989da41 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -1,79 +1,88 @@ - + + ChatWindowPage - - + + 0 0 - 513 - 349 + 400 + 300 - - Chat + + ChatWindowPage - - - 9 + + + + + 210 + 20 + 111 + 31 + + + + Start + + + + + + 40 + 20 + 171 + 31 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">5002</p></body></html> + + + + + + 40 + 80 + 281 + 101 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Status..</p></body></html> + + + + + + + 0 + 0 + 400 + 22 + - - 6 - - - - - 0 - - - 6 - - - - - Qt::NoFocus - - - true - - - - - - - - 180 - 16777215 - - - - Qt::NoFocus - - - - - - - - - 0 - - - 6 - - - - - Message: - - - - - - - - - + + + + TopToolBarArea + + + false + + + + From e65fffd5675f341bb23bd18f7e4967a3c614e747 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:19:27 -0400 Subject: [PATCH 0093/1324] Update main.cpp --- src/qt/main.cpp | 63 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 58 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 18681351..b78fe24a 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,64 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - #include "chatwindowpage.h" - -#include +#include int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QApplication a(argc, argv); + ChatWindowPage w; + w.show(); - ChatWindowPage dialog; - dialog.show(); - return app.exec(); + return a.exec(); } From 72419658d7d9f07be5cb241e351b56ebe2c2d1a6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:21:03 -0400 Subject: [PATCH 0094/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 81 +++++++---------------------------------- 1 file changed, 14 insertions(+), 67 deletions(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index 82d0d0c7..91e7016e 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -1,79 +1,26 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - #ifndef CHATWINDOWPAGE_H #define CHATWINDOWPAGE_H -#include "ui_chatwindowpage.h" -#include "client.h" - -class ChatWindowPage : public QDialog, private Ui::ChatWindowPage +#include +#include"servedev.h" +namespace Ui { +class ChatWindowPage; +} +class servedev; +class ChatWindowPage : public QMainWindow { Q_OBJECT public: - ChatWindowPage(QWidget *parent = nullptr); - -public Q_SLOTS: - void appendMessage(const QString &from, const QString &message); - + explicit ChatWindowPage(QWidget *parent = 0); + ~ChatWindowPage(); + void addMessage(QString Msg); + servedev* m_pBoxServer; private Q_SLOTS: - void returnPressed(); - void newParticipant(const QString &nick); - void participantLeft(const QString &nick); - void showInformation(); + void on_pushButtonStart_clicked(); private: - Client client; - QString myNickName; - QTextTableFormat tableFormat; + Ui::ChatWindowPage *ui; }; -#endif +#endif // CHATWINDOWPAGE_H From d63ad2769a69d0bd96020c050cb72035b8d1e192 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:22:50 -0400 Subject: [PATCH 0095/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 155 ++++++-------------------------------- 1 file changed, 22 insertions(+), 133 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 1cefc43d..4911223c 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -1,151 +1,40 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - #include "chatwindowpage.h" - -ChatWindowPage::ChatWindowPage(QWidget *parent) - : QDialog(parent) +#include "ui_chatwindowpage.h" +#include"servedev.h" +ChatWindowPage::ChatWindowPage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ChatWindowPage) { - setupUi(this); - - lineEdit->setFocusPolicy(Qt::StrongFocus); - textEdit->setFocusPolicy(Qt::NoFocus); - textEdit->setReadOnly(true); - listWidget->setFocusPolicy(Qt::NoFocus); + ui->setupUi(this); + //m_pBoxServer = new servedev(this); - connect(lineEdit, &QLineEdit::returnPressed, - this, &ChatWindowPage::returnPressed); - connect(&client, &Client::newMessage, - this, &ChatWindowPage::appendMessage); - connect(&client, &Client::newParticipant, - this, &ChatWindowPage::newParticipant); - connect(&client, &Client::participantLeft, - this, &ChatWindowPage::participantLeft); - - myNickName = client.nickName(); - newParticipant(myNickName); - tableFormat.setBorder(0); - QTimer::singleShot(10 * 1000, this, SLOT(showInformation())); } -void ChatWindowPage::appendMessage(const QString &from, const QString &message) +ChatWindowPage::~ChatWindowPage() { - if (from.isEmpty() || message.isEmpty()) - return; - - QTextCursor cursor(textEdit->textCursor()); - cursor.movePosition(QTextCursor::End); - QTextTable *table = cursor.insertTable(1, 2, tableFormat); - table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + "> "); - table->cellAt(0, 1).firstCursorPosition().insertText(message); - QScrollBar *bar = textEdit->verticalScrollBar(); - bar->setValue(bar->maximum()); + delete ui; } -void ChatWindowPage::returnPressed() +void ChatWindowPage::addMessage(QString Msg) { - QString text = lineEdit->text(); - if (text.isEmpty()) - return; - - if (text.startsWith(QChar('/'))) { - QColor color = textEdit->textColor(); - textEdit->setTextColor(Qt::red); - textEdit->append(tr("! Unknown command: %1") - .arg(text.left(text.indexOf(' ')))); - textEdit->setTextColor(color); - } else { - client.sendMessage(text); - appendMessage(myNickName, text); - } - lineEdit->clear(); -} - -void ChatWindowPage::newParticipant(const QString &nick) -{ - if (nick.isEmpty()) - return; + ui->textEditStatus->setText(Msg); - QColor color = textEdit->textColor(); - textEdit->setTextColor(Qt::gray); - textEdit->append(tr("* %1 has joined").arg(nick)); - textEdit->setTextColor(color); - listWidget->addItem(nick); } -void ChatWindowPage::participantLeft(const QString &nick) +void ChatWindowPage::on_pushButtonStart_clicked() { - if (nick.isEmpty()) - return; - - QList items = listWidget->findItems(nick, - Qt::MatchExactly); - if (items.isEmpty()) - return; + m_pBoxServer = new servedev(this); - delete items.at(0); - QColor color = textEdit->textColor(); - textEdit->setTextColor(Qt::gray); - textEdit->append(tr("* %1 has left").arg(nick)); - textEdit->setTextColor(color); -} + bool success = m_pBoxServer->listen(QHostAddress::Any, quint16(ui->textEditPort->toPlainText().toInt())); + if(!success) + { + addMessage("Server failed..."); -void ChatWindowPage::showInformation() -{ - if (listWidget->count() == 1) { - QMessageBox::information(this, tr("Chat"), - tr("Launch several instances of this " - "program on your local network and " - "start chatting!")); } + else + { + addMessage("Server Started..."); + } + } From 8a70ee89074da47fe8f1bdadca3fd3f5cd7edf2e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:24:30 -0400 Subject: [PATCH 0096/1324] Update and rename server.cpp to servedev.cpp --- src/qt/servedev.cpp | 41 ++++++++++++++++++++++++++++ src/qt/server.cpp | 66 --------------------------------------------- 2 files changed, 41 insertions(+), 66 deletions(-) create mode 100644 src/qt/servedev.cpp delete mode 100644 src/qt/server.cpp diff --git a/src/qt/servedev.cpp b/src/qt/servedev.cpp new file mode 100644 index 00000000..a098ca78 --- /dev/null +++ b/src/qt/servedev.cpp @@ -0,0 +1,41 @@ +#include "servedev.h" +#include + +servedev::servedev(ChatWindowPage* pHelloServer,QObject *parent) : QTcpServer(parent) +{ + m_pHelloWindow=pHelloServer; +} + +void servedev::incomingConnection(int socketfd) +{ + QTcpSocket *client = new QTcpSocket(this); + client->setSocketDescriptor(socketfd); + clients.insert(client); + + m_pHelloWindow->addMessage("New client from: "+client->peerAddress().toString()); + + connect(client, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(client, SIGNAL(disconnected()), this, SLOT(disconnected())); +} + +void servedev::readyRead() +{ + QTcpSocket *client = (QTcpSocket*)sender(); + while(client->canReadLine()) + { + QString line = QString::fromUtf8(client->readLine()).trimmed(); + //qDebug() << "Read line:" << line; + m_pHelloWindow->addMessage(line); + + } +} + +void servedev::disconnected() +{ + QTcpSocket *client = (QTcpSocket*)sender(); + qDebug() << "Client disconnected:" << client->peerAddress().toString(); + + clients.remove(client); + + +} diff --git a/src/qt/server.cpp b/src/qt/server.cpp deleted file mode 100644 index 930d711f..00000000 --- a/src/qt/server.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "connection.h" -#include "server.h" - -Server::Server(QObject *parent) - : QTcpServer(parent) -{ - listen(QHostAddress::Any); -} - -void Server::incomingConnection(qintptr socketDescriptor) -{ - Connection *connection = new Connection(socketDescriptor, this); - Q_EMIT newConnection(connection); -} From 9a92b8be57f289ef8d86e932dc0a0ec68d13443c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:25:45 -0400 Subject: [PATCH 0097/1324] Update and rename server.h to servedev.h --- src/qt/servedev.h | 28 ++++++++++++++++++ src/qt/server.h | 72 ----------------------------------------------- 2 files changed, 28 insertions(+), 72 deletions(-) create mode 100644 src/qt/servedev.h delete mode 100644 src/qt/server.h diff --git a/src/qt/servedev.h b/src/qt/servedev.h new file mode 100644 index 00000000..2b87eae9 --- /dev/null +++ b/src/qt/servedev.h @@ -0,0 +1,28 @@ +#ifndef SERVEDEV_H +#define SERVEDEV_H +#include +#include"chatwindowpage.h" +class ChatWindowPage; +class servedev : public QTcpServer +{ +public: + + Q_OBJECT + + public: + servedev(ChatWindowPage* pHelloServer,QObject *parent=0); + ChatWindowPage* m_pHelloWindow; + + private Q_SLOTS: + void readyRead(); + void disconnected(); + + protected: + void incomingConnection(int socketfd); + + private: + QSet clients; + +}; + +#endif // SERVEDEV_H diff --git a/src/qt/server.h b/src/qt/server.h deleted file mode 100644 index ec0993f3..00000000 --- a/src/qt/server.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SERVER_H -#define SERVER_H - -#include - -class Connection; - -class Server : public QTcpServer -{ - Q_OBJECT - -public: - Server(QObject *parent = nullptr); - -Q_SIGNALS: - void newConnection(Connection *connection); - -protected: - void incomingConnection(qintptr socketDescriptor) override; -}; - -#endif From bf3ca4f56c475e97c387de276f76e61b69eae6f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:30:12 -0400 Subject: [PATCH 0098/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index cb4656b0..92af0d49 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -66,11 +66,9 @@ QT_MOC_CPP = \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ qt/moc_chatwindowpage.cpp \ - qt/moc_client.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ - qt/moc_connection.cpp \ qt/moc_csvmodelwriter.cpp \ qt/moc_editaddressdialog.cpp \ qt/moc_governancelist.cpp \ @@ -88,7 +86,6 @@ QT_MOC_CPP = \ qt/moc_optionsmodel.cpp \ qt/moc_overviewpage.cpp \ qt/moc_privatesendpage.cpp \ - qt/moc_peermanager.cpp \ qt/moc_peertablemodel.cpp \ qt/moc_paymentserver.cpp \ qt/moc_qrdialog.cpp \ @@ -100,7 +97,7 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ - qt/moc_server.cpp \ + qt/moc_servedev.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -147,11 +144,9 @@ BITCOIN_QT_H = \ qt/bitcoingui.h \ qt/bitcoinunits.h \ qt/chatwindowpage.h \ - qt/client.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ - qt/connection.h \ qt/csvmodelwriter.h \ qt/editaddressdialog.h \ qt/governancelist.h \ @@ -173,7 +168,6 @@ BITCOIN_QT_H = \ qt/privatesendpage.h \ qt/paymentrequestplus.h \ qt/paymentserver.h \ - qt/peermanager.h \ qt/peertablemodel.h \ qt/platformstyle.h \ qt/qrdialog.h \ @@ -185,7 +179,7 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ - qt/server.h \ + qt/servedev.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -488,7 +482,6 @@ BITCOIN_QT_BASE_CPP = \ qt/bitcoinamountfield.cpp \ qt/bitcoingui.cpp \ qt/bitcoinunits.cpp \ - qt/client.cpp \ qt/clientmodel.cpp \ qt/csvmodelwriter.cpp \ qt/guiutil.cpp \ @@ -499,13 +492,12 @@ BITCOIN_QT_BASE_CPP = \ qt/notificator.cpp \ qt/optionsdialog.cpp \ qt/optionsmodel.cpp \ - qt/peermanager.cpp \ qt/peertablemodel.cpp \ qt/platformstyle.cpp \ qt/qvalidatedlineedit.cpp \ qt/qvaluecombobox.cpp \ qt/rpcconsole.cpp \ - qt/server.cpp \ + qt/servedev.cpp \ qt/splashscreen.cpp \ qt/trafficgraphdata.cpp \ qt/trafficgraphwidget.cpp \ @@ -518,7 +510,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ qt/chatwindowpage.cpp \ - qt/client.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/connection.cpp \ @@ -532,14 +523,13 @@ BITCOIN_QT_WALLET_CPP = \ qt/privatesendpage.cpp \ qt/paymentrequestplus.cpp \ qt/paymentserver.cpp \ - qt/peermanager.cpp \ qt/qrdialog.cpp \ qt/receivecoinsdialog.cpp \ qt/receiverequestdialog.cpp \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ - qt/server.cpp \ + qt/servedev.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From a9477a00aada5d21c6728b93448c045f53df8392 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:31:20 -0400 Subject: [PATCH 0099/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index ca0889ec..37bf1063 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -31,15 +31,9 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe -HEADERS = client.h \ - connection.h \ - peermanager.h \ - server.h +HEADERS = servedev.h -SOURCES = client.cpp \ - connection.cpp \ - main.cpp \ - peermanager.cpp \ +SOURCES = main.cpp \ server.cpp QT += network widgets From 0f91887a8d38a8448a2d026c79cfbe9ceab94bc3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:31:50 -0400 Subject: [PATCH 0100/1324] Delete client.cpp --- src/qt/client.cpp | 147 ---------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 src/qt/client.cpp diff --git a/src/qt/client.cpp b/src/qt/client.cpp deleted file mode 100644 index 11c0f22c..00000000 --- a/src/qt/client.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "client.h" -#include "connection.h" -#include "peermanager.h" - -Client::Client() -{ - peerManager = new PeerManager(this); - peerManager->setServerPort(server.serverPort()); - peerManager->startBroadcasting(); - - connect(peerManager, &PeerManager::newConnection, - this, &Client::newConnection); - connect(&server, &Server::newConnection, - this, &Client::newConnection); -} - -void Client::sendMessage(const QString &message) -{ - if (message.isEmpty()) - return; - - for (Connection *connection : qAsConst(peers)) - connection->sendMessage(message); -} - -QString Client::nickName() const -{ - return peerManager->userName() + '@' + QHostInfo::localHostName() - + ':' + QString::number(server.serverPort()); -} - -bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const -{ - if (senderPort == -1) - return peers.contains(senderIp); - - if (!peers.contains(senderIp)) - return false; - - const QList connections = peers.values(senderIp); - for (const Connection *connection : connections) { - if (connection->peerPort() == senderPort) - return true; - } - - return false; -} - -void Client::newConnection(Connection *connection) -{ - connection->setGreetingMessage(peerManager->userName()); - - connect(connection, &Connection::errorOccurred, this, &Client::connectionError); - connect(connection, &Connection::disconnected, this, &Client::disconnected); - connect(connection, &Connection::readyForUse, this, &Client::readyForUse); -} - -void Client::readyForUse() -{ - Connection *connection = qobject_cast(sender()); - if (!connection || hasConnection(connection->peerAddress(), - connection->peerPort())) - return; - - connect(connection, &Connection::newMessage, - this, &Client::newMessage); - - peers.insert(connection->peerAddress(), connection); - QString nick = connection->name(); - if (!nick.isEmpty()) - Q_EMIT newParticipant(nick); -} - -void Client::disconnected() -{ - if (Connection *connection = qobject_cast(sender())) - removeConnection(connection); -} - -void Client::connectionError(QAbstractSocket::SocketError /* socketError */) -{ - if (Connection *connection = qobject_cast(sender())) - removeConnection(connection); -} - -void Client::removeConnection(Connection *connection) -{ - if (peers.contains(connection->peerAddress())) { - peers.remove(connection->peerAddress()); - QString nick = connection->name(); - if (!nick.isEmpty()) - Q_EMIT participantLeft(nick); - } - connection->deleteLater(); -} From 4d596fa92cb484f407bf6a669bfdd1c310425318 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:31:59 -0400 Subject: [PATCH 0101/1324] Delete client.h --- src/qt/client.h | 92 ------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 src/qt/client.h diff --git a/src/qt/client.h b/src/qt/client.h deleted file mode 100644 index d0a0c0d3..00000000 --- a/src/qt/client.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CLIENT_H -#define CLIENT_H - -#include -#include -#include - -#include "server.h" - -class PeerManager; - -class Client : public QObject -{ - Q_OBJECT - -public: - Client(); - - void sendMessage(const QString &message); - QString nickName() const; - bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const; - -Q_SIGNALS: - void newMessage(const QString &from, const QString &message); - void newParticipant(const QString &nick); - void participantLeft(const QString &nick); - -private Q_SLOTS: - void newConnection(Connection *connection); - void connectionError(QAbstractSocket::SocketError socketError); - void disconnected(); - void readyForUse(); - -private: - void removeConnection(Connection *connection); - - PeerManager *peerManager; - Server server; - QMultiHash peers; -}; - -#endif From 37a505b6d25f3fd34b7d7d786fa2e06b5e7f2226 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:32:07 -0400 Subject: [PATCH 0102/1324] Delete connection.cpp --- src/qt/connection.cpp | 278 ------------------------------------------ 1 file changed, 278 deletions(-) delete mode 100644 src/qt/connection.cpp diff --git a/src/qt/connection.cpp b/src/qt/connection.cpp deleted file mode 100644 index 5cd32cf3..00000000 --- a/src/qt/connection.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2018 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "connection.h" - -#include - -static const int TransferTimeout = 30 * 1000; -static const int PongTimeout = 60 * 1000; -static const int PingInterval = 5 * 1000; - -/* - * Protocol is defined as follows, using the CBOR Data Definition Language: - * - * protocol = [ - * greeting, ; must start with a greeting command - * * command ; zero or more regular commands after - * ] - * command = plaintext / ping / pong / greeting - * plaintext = { 0 => text } - * ping = { 1 => null } - * pong = { 2 => null } - * greeting = { 3 => text } - */ - -Connection::Connection(QObject *parent) - : QTcpSocket(parent), writer(this) -{ - greetingMessage = tr("undefined"); - username = tr("unknown"); - state = WaitingForGreeting; - currentDataType = Undefined; - transferTimerId = -1; - isGreetingMessageSent = false; - pingTimer.setInterval(PingInterval); - - connect(this, &QTcpSocket::readyRead, this, - &Connection::processReadyRead); - connect(this, &QTcpSocket::disconnected, - &pingTimer, &QTimer::stop); - connect(&pingTimer, &QTimer::timeout, - this, &Connection::sendPing); - connect(this, &QTcpSocket::connected, - this, &Connection::sendGreetingMessage); -} - -Connection::Connection(qintptr socketDescriptor, QObject *parent) - : Connection(parent) -{ - setSocketDescriptor(socketDescriptor); - reader.setDevice(this); -} - -Connection::~Connection() -{ - if (isGreetingMessageSent) { - // Indicate clean shutdown. - writer.endArray(); - waitForBytesWritten(2000); - } -} - -QString Connection::name() const -{ - return username; -} - -void Connection::setGreetingMessage(const QString &message) -{ - greetingMessage = message; -} - -bool Connection::sendMessage(const QString &message) -{ - if (message.isEmpty()) - return false; - - writer.startMap(1); - writer.append(PlainText); - writer.append(message); - writer.endMap(); - return true; -} - -void Connection::timerEvent(QTimerEvent *timerEvent) -{ - if (timerEvent->timerId() == transferTimerId) { - abort(); - killTimer(transferTimerId); - transferTimerId = -1; - } -} - -void Connection::processReadyRead() -{ - // we've got more data, let's parse - reader.reparse(); - while (reader.lastError() == QCborError::NoError) { - if (state == WaitingForGreeting) { - if (!reader.isArray()) - break; // protocol error - - reader.enterContainer(); // we'll be in this array forever - state = ReadingGreeting; - } else if (reader.containerDepth() == 1) { - // Current state: no command read - // Next state: read command ID - if (!reader.hasNext()) { - reader.leaveContainer(); - disconnectFromHost(); - return; - } - - if (!reader.isMap() || !reader.isLengthKnown() || reader.length() != 1) - break; // protocol error - reader.enterContainer(); - } else if (currentDataType == Undefined) { - // Current state: read command ID - // Next state: read command payload - if (!reader.isInteger()) - break; // protocol error - currentDataType = DataType(reader.toInteger()); - reader.next(); - } else { - // Current state: read command payload - if (reader.isString()) { - auto r = reader.readString(); - buffer += r.data; - if (r.status != QCborStreamReader::EndOfString) - continue; - } else if (reader.isNull()) { - reader.next(); - } else { - break; // protocol error - } - - // Next state: no command read - reader.leaveContainer(); - if (transferTimerId != -1) { - killTimer(transferTimerId); - transferTimerId = -1; - } - - if (state == ReadingGreeting) { - if (currentDataType != Greeting) - break; // protocol error - processGreeting(); - } else { - processData(); - } - } - } - - if (reader.lastError() != QCborError::EndOfFile) - abort(); // parse error - - if (transferTimerId != -1 && reader.containerDepth() > 1) - transferTimerId = startTimer(TransferTimeout); -} - -void Connection::sendPing() -{ - if (pongTime.elapsed() > PongTimeout) { - abort(); - return; - } - - writer.startMap(1); - writer.append(Ping); - writer.append(nullptr); // no payload - writer.endMap(); -} - -void Connection::sendGreetingMessage() -{ - writer.startArray(); // this array never ends - - writer.startMap(1); - writer.append(Greeting); - writer.append(greetingMessage); - writer.endMap(); - isGreetingMessageSent = true; - - if (!reader.device()) - reader.setDevice(this); -} - -void Connection::processGreeting() -{ - username = buffer + '@' + peerAddress().toString() + ':' - + QString::number(peerPort()); - currentDataType = Undefined; - buffer.clear(); - - if (!isValid()) { - abort(); - return; - } - - if (!isGreetingMessageSent) - sendGreetingMessage(); - - pingTimer.start(); - pongTime.start(); - state = ReadyForUse; - Q_EMIT readyForUse(); -} - -void Connection::processData() -{ - switch (currentDataType) { - case PlainText: - emit newMessage(username, buffer); - break; - case Ping: - writer.startMap(1); - writer.append(Pong); - writer.append(nullptr); // no payload - writer.endMap(); - break; - case Pong: - pongTime.restart(); - break; - default: - break; - } - - currentDataType = Undefined; - buffer.clear(); -} From 9ccc3d2148bd1e4a1bd9a015e0973ae6eb8ba316 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:32:15 -0400 Subject: [PATCH 0103/1324] Delete connection.h --- src/qt/connection.h | 120 -------------------------------------------- 1 file changed, 120 deletions(-) delete mode 100644 src/qt/connection.h diff --git a/src/qt/connection.h b/src/qt/connection.h deleted file mode 100644 index af5fa0ae..00000000 --- a/src/qt/connection.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CONNECTION_H -#define CONNECTION_H - -#include -#include -#include -#include -#include -#include -#include - -static const int MaxBufferSize = 1024000; - -class Connection : public QTcpSocket -{ - Q_OBJECT - -public: - enum ConnectionState { - WaitingForGreeting, - ReadingGreeting, - ReadyForUse - }; - enum DataType { - PlainText, - Ping, - Pong, - Greeting, - Undefined - }; - - Connection(QObject *parent = nullptr); - Connection(qintptr socketDescriptor, QObject *parent = nullptr); - ~Connection(); - - QString name() const; - void setGreetingMessage(const QString &message); - bool sendMessage(const QString &message); - -Q_SIGNALS: - void readyForUse(); - void newMessage(const QString &from, const QString &message); - -protected: - void timerEvent(QTimerEvent *timerEvent) override; - -private Q_SLOTS: - void processReadyRead(); - void sendPing(); - void sendGreetingMessage(); - -private: - bool hasEnoughData(); - void processGreeting(); - void processData(); - - QCborStreamReader reader; - QCborStreamWriter writer; - QString greetingMessage; - QString username; - QTimer pingTimer; - QElapsedTimer pongTime; - QString buffer; - ConnectionState state; - DataType currentDataType; - int transferTimerId; - bool isGreetingMessageSent; -}; - -#endif From 641e91356d2ea1034dea66dc3843bb0bbce6f78d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:32:27 -0400 Subject: [PATCH 0104/1324] Delete peermanager.cpp --- src/qt/peermanager.cpp | 196 ----------------------------------------- 1 file changed, 196 deletions(-) delete mode 100644 src/qt/peermanager.cpp diff --git a/src/qt/peermanager.cpp b/src/qt/peermanager.cpp deleted file mode 100644 index 7267616c..00000000 --- a/src/qt/peermanager.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2018 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "client.h" -#include "connection.h" -#include "peermanager.h" - -static const qint32 BroadcastInterval = 2000; -static const unsigned broadcastPort = 45000; - -PeerManager::PeerManager(Client *client) - : QObject(client) -{ - this->client = client; - - static const char *envVariables[] = { - "USERNAME", "USER", "USERDOMAIN", "HOSTNAME", "DOMAINNAME" - }; - - for (const char *varname : envVariables) { - username = qEnvironmentVariable(varname); - if (!username.isNull()) - break; - } - - if (username.isEmpty()) - username = "unknown"; - - updateAddresses(); - serverPort = 0; - - broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress - | QUdpSocket::ReuseAddressHint); - connect(&broadcastSocket, &QUdpSocket::readyRead, - this, &PeerManager::readBroadcastDatagram); - - broadcastTimer.setInterval(BroadcastInterval); - connect(&broadcastTimer, &QTimer::timeout, - this, &PeerManager::sendBroadcastDatagram); -} - -void PeerManager::setServerPort(int port) -{ - serverPort = port; -} - -QString PeerManager::userName() const -{ - return username; -} - -void PeerManager::startBroadcasting() -{ - broadcastTimer.start(); -} - -bool PeerManager::isLocalHostAddress(const QHostAddress &address) const -{ - for (const QHostAddress &localAddress : ipAddresses) { - if (address.isEqual(localAddress)) - return true; - } - return false; -} - -void PeerManager::sendBroadcastDatagram() -{ - QByteArray datagram; - { - QCborStreamWriter writer(&datagram); - writer.startArray(2); - writer.append(username); - writer.append(serverPort); - writer.endArray(); - } - - bool validBroadcastAddresses = true; - for (const QHostAddress &address : qAsConst(broadcastAddresses)) { - if (broadcastSocket.writeDatagram(datagram, address, - broadcastPort) == -1) - validBroadcastAddresses = false; - } - - if (!validBroadcastAddresses) - updateAddresses(); -} - -void PeerManager::readBroadcastDatagram() -{ - while (broadcastSocket.hasPendingDatagrams()) { - QHostAddress senderIp; - quint16 senderPort; - QByteArray datagram; - datagram.resize(broadcastSocket.pendingDatagramSize()); - if (broadcastSocket.readDatagram(datagram.data(), datagram.size(), - &senderIp, &senderPort) == -1) - continue; - - int senderServerPort; - { - // decode the datagram - QCborStreamReader reader(datagram); - if (reader.lastError() != QCborError::NoError || !reader.isArray()) - continue; - if (!reader.isLengthKnown() || reader.length() != 2) - continue; - - reader.enterContainer(); - if (reader.lastError() != QCborError::NoError || !reader.isString()) - continue; - while (reader.readString().status == QCborStreamReader::Ok) { - // we don't actually need the username right now - } - - if (reader.lastError() != QCborError::NoError || !reader.isUnsignedInteger()) - continue; - senderServerPort = reader.toInteger(); - } - - if (isLocalHostAddress(senderIp) && senderServerPort == serverPort) - continue; - - if (!client->hasConnection(senderIp)) { - Connection *connection = new Connection(this); - Q_EMIT newConnection(connection); - connection->connectToHost(senderIp, senderServerPort); - } - } -} - -void PeerManager::updateAddresses() -{ - broadcastAddresses.clear(); - ipAddresses.clear(); - const QList interfaces = QNetworkInterface::allInterfaces(); - for (const QNetworkInterface &interface : interfaces) { - const QList entries = interface.addressEntries(); - for (const QNetworkAddressEntry &entry : entries) { - QHostAddress broadcastAddress = entry.broadcast(); - if (broadcastAddress != QHostAddress::Null && entry.ip() != QHostAddress::LocalHost) { - broadcastAddresses << broadcastAddress; - ipAddresses << entry.ip(); - } - } - } -} From cbfabf8127a602fa0e187ff33f7d25a93f9139c5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:32:37 -0400 Subject: [PATCH 0105/1324] Delete peermanager.h --- src/qt/peermanager.h | 94 -------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 src/qt/peermanager.h diff --git a/src/qt/peermanager.h b/src/qt/peermanager.h deleted file mode 100644 index f5e9d6ee..00000000 --- a/src/qt/peermanager.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PEERMANAGER_H -#define PEERMANAGER_H - -#include -#include -#include -#include -#include - -class Client; -class Connection; - -class PeerManager : public QObject -{ - Q_OBJECT - -public: - PeerManager(Client *client); - - void setServerPort(int port); - QString userName() const; - void startBroadcasting(); - bool isLocalHostAddress(const QHostAddress &address) const; - -Q_SIGNALS: - void newConnection(Connection *connection); - -private Q_SLOTS: - void sendBroadcastDatagram(); - void readBroadcastDatagram(); - -private: - void updateAddresses(); - - Client *client; - QList broadcastAddresses; - QList ipAddresses; - QUdpSocket broadcastSocket; - QTimer broadcastTimer; - QString username; - int serverPort; -}; - -#endif From e6a089787e107a3c304bd7378d5dca8fff329353 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:34:38 -0400 Subject: [PATCH 0106/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 92af0d49..f1572450 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -512,7 +512,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ - qt/connection.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ From 66648e34770f2280a206ae28dee8e60b2cf3a085 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:44:42 -0400 Subject: [PATCH 0107/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index f1572450..fe456e3f 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -77,7 +77,6 @@ QT_MOC_CPP = \ qt/moc_intro.cpp \ qt/moc_macdockiconhandler.cpp \ qt/moc_macnotificationhandler.cpp \ - qt/moc_main.cpp \ qt/moc_modaloverlay.cpp \ qt/moc_masternodelist.cpp \ qt/moc_notificator.cpp \ From 4fc20b6d1d484a7e467059be0c8e5840f9b30642 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:50:33 -0400 Subject: [PATCH 0108/1324] Update qt.mk --- depends/packages/qt.mk | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 095d03ad..9579f605 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,24 +1,24 @@ PACKAGE=qt -$(package)_version=5.12.8 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.12/$($(package)_version)/submodules -$(package)_suffix=everywhere-src-$($(package)_version).tar.xz +$(package)_version=5.7.1 +$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.gz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=19592fbd0a524a17c35e413988fe494251103619ef7dd49aecdf3170973aabd8 +$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=mac-qmake.conf #fix_qt_pkgconfig.patch mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch -#$(package)_patches+=fix_qt_configure.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch +$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch # NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. # Remove it after bumping $(package)_version to 5.8+. $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=180ea07c0aff6803ffad214c34f8ed1a77f8cac02e62f6e219bd1ede1dd66b6e +$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=21347e8e2422689d63a08195e27c637983c0d4261d5205ce6b493a2adfe826b4 +$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) @@ -31,20 +31,28 @@ $(package)_config_opts += -c++std c++11 $(package)_config_opts += -confirm-license $(package)_config_opts += -dbus-runtime $(package)_config_opts += -hostprefix $(build_prefix) +$(package)_config_opts += -no-alsa +$(package)_config_opts += -no-audio-backend $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs +$(package)_config_opts += -no-feature-style-windowsmobile +$(package)_config_opts += -no-feature-style-windowsce $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif $(package)_config_opts += -no-glib +$(package)_config_opts += -no-gstreamer $(package)_config_opts += -no-icu $(package)_config_opts += -no-iconv $(package)_config_opts += -no-kms $(package)_config_opts += -no-linuxfb $(package)_config_opts += -no-libudev +$(package)_config_opts += -no-mitshm $(package)_config_opts += -no-mtdev +$(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations +$(package)_config_opts += -no-qml-debug $(package)_config_opts += -no-sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci @@ -55,9 +63,12 @@ $(package)_config_opts += -no-sql-psql $(package)_config_opts += -no-sql-sqlite $(package)_config_opts += -no-sql-sqlite2 $(package)_config_opts += -no-use-gold-linker +$(package)_config_opts += -no-xinput2 +$(package)_config_opts += -no-xrender $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource +$(package)_config_opts += -openssl-linked $(package)_config_opts += -optimized-qmake $(package)_config_opts += -pch $(package)_config_opts += -pkg-config @@ -66,9 +77,10 @@ $(package)_config_opts += -qt-libpng $(package)_config_opts += -qt-libjpeg $(package)_config_opts += -qt-pcre $(package)_config_opts += -qt-harfbuzz +$(package)_config_opts += -system-zlib +$(package)_config_opts += -reduce-exports $(package)_config_opts += -static $(package)_config_opts += -silent -$(package)_config_opts += -system-zlib $(package)_config_opts += -v $(package)_config_opts += -no-feature-printer $(package)_config_opts += -no-feature-printdialog @@ -127,7 +139,14 @@ define $(package)_preprocess_cmds cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ - cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf &&\ + cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ + patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ + patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ + patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ From eae6732f1674dc1f8a426876a92fde70c5d51ae3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:07:14 -0400 Subject: [PATCH 0109/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 37bf1063..8f8ce63d 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -24,23 +24,7 @@ RESOURCES += \ CONFIG += c++11 -CODECFORTR = UTF-8 - SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe - -HEADERS = servedev.h - -SOURCES = main.cpp \ - server.cpp - -QT += network widgets - core -requires(qtConfig(udpsocket)) -requires(qtConfig(listwidget)) - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/network/network-chat -INSTALLS += target From badd5b44fdcd9e96b0e50fc8eea432c68d51f22e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:14:39 -0400 Subject: [PATCH 0110/1324] Create dialog.cpp --- src/qt/dialog.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/qt/dialog.cpp diff --git a/src/qt/dialog.cpp b/src/qt/dialog.cpp new file mode 100644 index 00000000..c3f8eca5 --- /dev/null +++ b/src/qt/dialog.cpp @@ -0,0 +1,63 @@ +#include "dialog.h" +#include "ui_dialog.h" +#include +Dialog::Dialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::Dialog) +{ + m_pClientsocket = new QTcpSocket(this); + ui->setupUi(this); +} + +Dialog::~Dialog() +{ + + delete ui; +} + + +void Dialog::on_Connect_clicked() +{ + m_pClientsocket->connectToHost(ui->textEditIP->toPlainText(),quint16(ui->textEditPort->toPlainText().toInt()) ); + connect(m_pClientsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); +} + +void Dialog::on_Send_clicked() +{ + QString message = ui->textEdit_3->toPlainText().trimmed(); + //if chat server is not empty + if(!message.isEmpty()) + { + m_pClientsocket->write(QString (message + "\n").toUtf8()); + + } + //chat out the input box + ui->textEdit_3->clear(); + + ui->textEdit_3->setFocus(); +} +void Dialog::displayError ( QAbstractSocket::SocketError socketError ) +{ + switch (socketError) { + case QAbstractSocket::RemoteHostClosedError: + break; + case QAbstractSocket::HostNotFoundError: + QMessageBox::information(this, tr("Fortune Client"), + tr("The host was not found. Please check the " + "host name and port settings.")); + break; + case QAbstractSocket::ConnectionRefusedError: + QMessageBox::information(this, tr("Fortune Client"), + tr("The connection was refused by the peer. " + "Make sure the fortune server is running, " + "and check that the host name and port " + "settings are correct.")); + break; + default: + QMessageBox::information(this, tr("Fortune Client"), + tr("The following error occurred: %1.") + .arg(m_pClientsocket->errorString())); + } + + +} From 4b0dabb9882043824248fa161d8f94371098bd14 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:15:21 -0400 Subject: [PATCH 0111/1324] Create dialog.h --- src/qt/dialog.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/qt/dialog.h diff --git a/src/qt/dialog.h b/src/qt/dialog.h new file mode 100644 index 00000000..7739865e --- /dev/null +++ b/src/qt/dialog.h @@ -0,0 +1,29 @@ +#ifndef DIALOG_H +#define DIALOG_H + +#include +#include +namespace Ui { +class Dialog; +} + +class Dialog : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog(QWidget *parent = 0); + ~Dialog(); + QTcpSocket *m_pClientsocket; +private Q_SLOTS: + void displayError ( QAbstractSocket::SocketError socketError); +private Q_SLOTS: + void on_Connect_clicked(); + + void on_Send_clicked(); + +private: + Ui::Dialog *ui; +}; + +#endif // DIALOG_H From 7f2037ca1bbe75b22905ab2a7c267a6e87aeb2a7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:15:51 -0400 Subject: [PATCH 0112/1324] Create dialog.ui --- src/qt/forms/dialog.ui | 115 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/qt/forms/dialog.ui diff --git a/src/qt/forms/dialog.ui b/src/qt/forms/dialog.ui new file mode 100644 index 00000000..78743731 --- /dev/null +++ b/src/qt/forms/dialog.ui @@ -0,0 +1,115 @@ + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 20 + 40 + 71 + 20 + + + + IP Address + + + + + + 20 + 80 + 81 + 20 + + + + PORT + + + + + + 100 + 30 + 241 + 31 + + + + + + + 100 + 80 + 241 + 31 + + + + + + + 260 + 130 + 89 + 25 + + + + Connect + + + + + + 10 + 170 + 81 + 20 + + + + Message + + + + + + 80 + 170 + 271 + 51 + + + + + + + 260 + 230 + 89 + 25 + + + + Send + + + + + + + From fecafaf673287c428e021dbca829ab75e5afdfc3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:17:00 -0400 Subject: [PATCH 0113/1324] Create maindialog.cpp --- src/qt/maindialog.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/qt/maindialog.cpp diff --git a/src/qt/maindialog.cpp b/src/qt/maindialog.cpp new file mode 100644 index 00000000..c6efa744 --- /dev/null +++ b/src/qt/maindialog.cpp @@ -0,0 +1,11 @@ +#include "dialog.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Dialog w; + w.show(); + + return a.exec(); +} From 7203d00c8c7a24fc24741ed14efee965c71bf20b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:20:03 -0400 Subject: [PATCH 0114/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index fe456e3f..12c2eafd 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -35,6 +35,7 @@ QT_FORMS_UI = \ qt/forms/askpassphrasedialog.ui \ qt/forms/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ + qt/forms/dialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ qt/forms/governancedialog.ui \ @@ -70,6 +71,7 @@ QT_MOC_CPP = \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ qt/moc_csvmodelwriter.cpp \ + qt/moc_dialog.cpp \ qt/moc_editaddressdialog.cpp \ qt/moc_governancelist.cpp \ qt/moc_governancedialog.cpp \ @@ -147,6 +149,7 @@ BITCOIN_QT_H = \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ qt/csvmodelwriter.h \ + qt/dialog.h \ qt/editaddressdialog.h \ qt/governancelist.h \ qt/governancedialog.h \ @@ -486,6 +489,7 @@ BITCOIN_QT_BASE_CPP = \ qt/guiutil.cpp \ qt/intro.cpp \ qt/main.cpp \ + qt/maindialog.cpp \ qt/modaloverlay.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ @@ -511,10 +515,12 @@ BITCOIN_QT_WALLET_CPP = \ qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ + qt/dialog.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ qt/main.cpp \ + qt/maindialog.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ From efdaf3fcb2c7df861faa8e6d729270b6a5ef643b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:23:14 -0400 Subject: [PATCH 0115/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 12c2eafd..e0d872f5 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,9 +33,7 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ - qt/forms/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ - qt/forms/dialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ qt/forms/governancedialog.ui \ @@ -66,12 +64,10 @@ QT_MOC_CPP = \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ - qt/moc_chatwindowpage.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ qt/moc_csvmodelwriter.cpp \ - qt/moc_dialog.cpp \ qt/moc_editaddressdialog.cpp \ qt/moc_governancelist.cpp \ qt/moc_governancedialog.cpp \ @@ -98,7 +94,6 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ - qt/moc_servedev.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -144,12 +139,10 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ - qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ qt/csvmodelwriter.h \ - qt/dialog.h \ qt/editaddressdialog.h \ qt/governancelist.h \ qt/governancedialog.h \ @@ -181,7 +174,6 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ - qt/servedev.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -488,8 +480,6 @@ BITCOIN_QT_BASE_CPP = \ qt/csvmodelwriter.cpp \ qt/guiutil.cpp \ qt/intro.cpp \ - qt/main.cpp \ - qt/maindialog.cpp \ qt/modaloverlay.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ @@ -500,7 +490,6 @@ BITCOIN_QT_BASE_CPP = \ qt/qvalidatedlineedit.cpp \ qt/qvaluecombobox.cpp \ qt/rpcconsole.cpp \ - qt/servedev.cpp \ qt/splashscreen.cpp \ qt/trafficgraphdata.cpp \ qt/trafficgraphwidget.cpp \ @@ -512,15 +501,11 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ - qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ - qt/dialog.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ - qt/main.cpp \ - qt/maindialog.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ @@ -533,7 +518,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ - qt/servedev.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From cafc44315b8482eb87d91a12a1d28aaa0089c963 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:23:48 -0400 Subject: [PATCH 0116/1324] Delete chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 88 ---------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 src/qt/forms/chatwindowpage.ui diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui deleted file mode 100644 index e989da41..00000000 --- a/src/qt/forms/chatwindowpage.ui +++ /dev/null @@ -1,88 +0,0 @@ - - - ChatWindowPage - - - - 0 - 0 - 400 - 300 - - - - ChatWindowPage - - - - - - 210 - 20 - 111 - 31 - - - - Start - - - - - - 40 - 20 - 171 - 31 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">5002</p></body></html> - - - - - - 40 - 80 - 281 - 101 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Status..</p></body></html> - - - - - - - 0 - 0 - 400 - 22 - - - - - - TopToolBarArea - - - false - - - - - - - - From 00bc07155f2c392669e909552d7df77198481271 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:23:54 -0400 Subject: [PATCH 0117/1324] Delete dialog.ui --- src/qt/forms/dialog.ui | 115 ----------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 src/qt/forms/dialog.ui diff --git a/src/qt/forms/dialog.ui b/src/qt/forms/dialog.ui deleted file mode 100644 index 78743731..00000000 --- a/src/qt/forms/dialog.ui +++ /dev/null @@ -1,115 +0,0 @@ - - - Dialog - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - - 20 - 40 - 71 - 20 - - - - IP Address - - - - - - 20 - 80 - 81 - 20 - - - - PORT - - - - - - 100 - 30 - 241 - 31 - - - - - - - 100 - 80 - 241 - 31 - - - - - - - 260 - 130 - 89 - 25 - - - - Connect - - - - - - 10 - 170 - 81 - 20 - - - - Message - - - - - - 80 - 170 - 271 - 51 - - - - - - - 260 - 230 - 89 - 25 - - - - Send - - - - - - - From d0f71662bc52e2c0ac19ab85f5d17a9c1b305f79 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:08 -0400 Subject: [PATCH 0118/1324] Delete chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 40 --------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/qt/chatwindowpage.cpp diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp deleted file mode 100644 index 4911223c..00000000 --- a/src/qt/chatwindowpage.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "chatwindowpage.h" -#include "ui_chatwindowpage.h" -#include"servedev.h" -ChatWindowPage::ChatWindowPage(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::ChatWindowPage) -{ - ui->setupUi(this); - //m_pBoxServer = new servedev(this); - -} - -ChatWindowPage::~ChatWindowPage() -{ - delete ui; -} - -void ChatWindowPage::addMessage(QString Msg) -{ - - ui->textEditStatus->setText(Msg); - -} - -void ChatWindowPage::on_pushButtonStart_clicked() -{ - m_pBoxServer = new servedev(this); - - bool success = m_pBoxServer->listen(QHostAddress::Any, quint16(ui->textEditPort->toPlainText().toInt())); - if(!success) - { - addMessage("Server failed..."); - - } - else - { - addMessage("Server Started..."); - } - -} From 310aae2b467c8be8300f6b82603d87350e760bcf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:17 -0400 Subject: [PATCH 0119/1324] Delete chatwindowpage.h --- src/qt/chatwindowpage.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/chatwindowpage.h diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h deleted file mode 100644 index 91e7016e..00000000 --- a/src/qt/chatwindowpage.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CHATWINDOWPAGE_H -#define CHATWINDOWPAGE_H - -#include -#include"servedev.h" -namespace Ui { -class ChatWindowPage; -} -class servedev; -class ChatWindowPage : public QMainWindow -{ - Q_OBJECT - -public: - explicit ChatWindowPage(QWidget *parent = 0); - ~ChatWindowPage(); - void addMessage(QString Msg); - servedev* m_pBoxServer; -private Q_SLOTS: - void on_pushButtonStart_clicked(); - -private: - Ui::ChatWindowPage *ui; -}; - -#endif // CHATWINDOWPAGE_H From 5745a4d1c3a88bccfa8604a82c2af759035a0602 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:25 -0400 Subject: [PATCH 0120/1324] Delete dialog.cpp --- src/qt/dialog.cpp | 63 ----------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/qt/dialog.cpp diff --git a/src/qt/dialog.cpp b/src/qt/dialog.cpp deleted file mode 100644 index c3f8eca5..00000000 --- a/src/qt/dialog.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "dialog.h" -#include "ui_dialog.h" -#include -Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) -{ - m_pClientsocket = new QTcpSocket(this); - ui->setupUi(this); -} - -Dialog::~Dialog() -{ - - delete ui; -} - - -void Dialog::on_Connect_clicked() -{ - m_pClientsocket->connectToHost(ui->textEditIP->toPlainText(),quint16(ui->textEditPort->toPlainText().toInt()) ); - connect(m_pClientsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); -} - -void Dialog::on_Send_clicked() -{ - QString message = ui->textEdit_3->toPlainText().trimmed(); - //if chat server is not empty - if(!message.isEmpty()) - { - m_pClientsocket->write(QString (message + "\n").toUtf8()); - - } - //chat out the input box - ui->textEdit_3->clear(); - - ui->textEdit_3->setFocus(); -} -void Dialog::displayError ( QAbstractSocket::SocketError socketError ) -{ - switch (socketError) { - case QAbstractSocket::RemoteHostClosedError: - break; - case QAbstractSocket::HostNotFoundError: - QMessageBox::information(this, tr("Fortune Client"), - tr("The host was not found. Please check the " - "host name and port settings.")); - break; - case QAbstractSocket::ConnectionRefusedError: - QMessageBox::information(this, tr("Fortune Client"), - tr("The connection was refused by the peer. " - "Make sure the fortune server is running, " - "and check that the host name and port " - "settings are correct.")); - break; - default: - QMessageBox::information(this, tr("Fortune Client"), - tr("The following error occurred: %1.") - .arg(m_pClientsocket->errorString())); - } - - -} From 44103a84ba11a95319f8af9428e2e9c74c4ded5f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:32 -0400 Subject: [PATCH 0121/1324] Delete dialog.h --- src/qt/dialog.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/qt/dialog.h diff --git a/src/qt/dialog.h b/src/qt/dialog.h deleted file mode 100644 index 7739865e..00000000 --- a/src/qt/dialog.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DIALOG_H -#define DIALOG_H - -#include -#include -namespace Ui { -class Dialog; -} - -class Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit Dialog(QWidget *parent = 0); - ~Dialog(); - QTcpSocket *m_pClientsocket; -private Q_SLOTS: - void displayError ( QAbstractSocket::SocketError socketError); -private Q_SLOTS: - void on_Connect_clicked(); - - void on_Send_clicked(); - -private: - Ui::Dialog *ui; -}; - -#endif // DIALOG_H From d425895a9b2f6ac396484c192998446dcce1fc64 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:43 -0400 Subject: [PATCH 0122/1324] Delete main.cpp --- src/qt/main.cpp | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp deleted file mode 100644 index b78fe24a..00000000 --- a/src/qt/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "chatwindowpage.h" -#include - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - ChatWindowPage w; - w.show(); - - return a.exec(); -} From d1d79b000df7315ef3ae5e557430b762a0dc8dd5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:24:51 -0400 Subject: [PATCH 0123/1324] Delete maindialog.cpp --- src/qt/maindialog.cpp | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/qt/maindialog.cpp diff --git a/src/qt/maindialog.cpp b/src/qt/maindialog.cpp deleted file mode 100644 index c6efa744..00000000 --- a/src/qt/maindialog.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "dialog.h" -#include - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - Dialog w; - w.show(); - - return a.exec(); -} From f62c9650accbf66c75de9b61b1375d4fb8cae2cd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:25:04 -0400 Subject: [PATCH 0124/1324] Delete servedev.cpp --- src/qt/servedev.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/qt/servedev.cpp diff --git a/src/qt/servedev.cpp b/src/qt/servedev.cpp deleted file mode 100644 index a098ca78..00000000 --- a/src/qt/servedev.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "servedev.h" -#include - -servedev::servedev(ChatWindowPage* pHelloServer,QObject *parent) : QTcpServer(parent) -{ - m_pHelloWindow=pHelloServer; -} - -void servedev::incomingConnection(int socketfd) -{ - QTcpSocket *client = new QTcpSocket(this); - client->setSocketDescriptor(socketfd); - clients.insert(client); - - m_pHelloWindow->addMessage("New client from: "+client->peerAddress().toString()); - - connect(client, SIGNAL(readyRead()), this, SLOT(readyRead())); - connect(client, SIGNAL(disconnected()), this, SLOT(disconnected())); -} - -void servedev::readyRead() -{ - QTcpSocket *client = (QTcpSocket*)sender(); - while(client->canReadLine()) - { - QString line = QString::fromUtf8(client->readLine()).trimmed(); - //qDebug() << "Read line:" << line; - m_pHelloWindow->addMessage(line); - - } -} - -void servedev::disconnected() -{ - QTcpSocket *client = (QTcpSocket*)sender(); - qDebug() << "Client disconnected:" << client->peerAddress().toString(); - - clients.remove(client); - - -} From f3dbd3159a07df6dcdef480e7b6f901c4bb13130 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:25:14 -0400 Subject: [PATCH 0125/1324] Delete servedev.h --- src/qt/servedev.h | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 src/qt/servedev.h diff --git a/src/qt/servedev.h b/src/qt/servedev.h deleted file mode 100644 index 2b87eae9..00000000 --- a/src/qt/servedev.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SERVEDEV_H -#define SERVEDEV_H -#include -#include"chatwindowpage.h" -class ChatWindowPage; -class servedev : public QTcpServer -{ -public: - - Q_OBJECT - - public: - servedev(ChatWindowPage* pHelloServer,QObject *parent=0); - ChatWindowPage* m_pHelloWindow; - - private Q_SLOTS: - void readyRead(); - void disconnected(); - - protected: - void incomingConnection(int socketfd); - - private: - QSet clients; - -}; - -#endif // SERVEDEV_H From b6c5e929bd8a501a7a38d545984fa0d641722b7d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:28:03 -0400 Subject: [PATCH 0126/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 1e1e9bca..7cde2589 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,8 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -/* #include "tradingdialogpage.h" */ -#include "chatwindowpage.h" +/* #include "tradingdialogpage.h" +#include "chatwindowpage.h" */ #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - chatWindowPage(0), + /* chatWindowPage(0), */ platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -620,8 +620,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); - chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); + /* chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); + chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); */ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -637,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); + /* connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); */ // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -739,8 +739,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); - chat->addAction(chatWindowPage); + /* QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); + chat->addAction(chatWindowPage); */ } @@ -1069,11 +1069,11 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoChatWindowPage() +/*void BitcoinGUI::gotoChatWindowPage() { chatWindowPage->setChecked(true); if (walletFrame) walletFrame->gotoChatWindowPage(); -} +} */ /*void BitcoinGUI::gotoTradingDialogPage() { From c8d79a0d6a74c3fc767d6da47d6f93d5240a8c91 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:28:51 -0400 Subject: [PATCH 0127/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 055119d2..1f6ae97c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -38,8 +38,8 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -/*class tradingDialogPage; */ -class ChatWindowPage; +/*class tradingDialogPage; +class ChatWindowPage; */ class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* chatWindowPage; + /*QAction* chatWindowPage; */ QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + /* void gotoChatWindowPage(); */ /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 5bd5a9a7c0fe6ff3bc5996dd53ddaba06dfcae99 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:29:21 -0400 Subject: [PATCH 0128/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 1389bb79..eb6a9f78 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,13 +108,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoChatWindowPage() +/*void WalletFrame::gotoChatWindowPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) i.value()->gotoChatWindowPage(); -} +} */ /*void WalletFrame::gotoTradingDialogPage() { From 84866fda66fb65d72f386546d5ee8c52bad11af8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:29:45 -0400 Subject: [PATCH 0129/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 866caea5..404550a4 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + /* void gotoChatWindowPage(); */ /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 229621654e6555767a3ab9a9b24b8cf90aa2695f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:30:31 -0400 Subject: [PATCH 0130/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index fb6e2527..2b2d53f5 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatWindowPage = new ChatWindowPage(); - addWidget(chatWindowPage); + /* chatWindowPage = new ChatWindowPage(); + addWidget(chatWindowPage); */ QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -241,10 +241,10 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoChatWindowPage() +/*void WalletView::gotoChatWindowPage() { setCurrentWidget(chatWindowPage); -} +} */ /*void WalletView::gotoTradingDialogPage() { From ca68062a79987dbf80f1d91774dcd966684cc5c1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:31:10 -0400 Subject: [PATCH 0131/1324] Update walletview.h --- src/qt/walletview.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index d1fc4313..af7597f0 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,8 +8,8 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -/* #include "tradingdialogpage.h" */ -#include "chatwindowpage.h" +/* #include "tradingdialogpage.h" +#include "chatwindowpage.h" */ #include @@ -26,8 +26,8 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -/* class TradingDialogPage; */ -class ChatWindowPage; +/* class TradingDialogPage; +class ChatWindowPage;*/ QT_BEGIN_NAMESPACE @@ -78,8 +78,8 @@ class WalletView : public QStackedWidget PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; TransactionView *transactionView; - /* TradingDialogPage *tradingDialogPage; */ - ChatWindowPage *chatWindowPage; + /* TradingDialogPage *tradingDialogPage; + ChatWindowPage *chatWindowPage; */ QProgressDialog *progressDialog; QLabel *transactionSum; @@ -88,7 +88,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + /* void gotoChatWindowPage(); */ /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 6b565fae307c35dfee3bd2302b2fffbc34182d6d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:44:11 -0400 Subject: [PATCH 0132/1324] Create chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/qt/chatwindowpage.cpp diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp new file mode 100644 index 00000000..517eaa8f --- /dev/null +++ b/src/qt/chatwindowpage.cpp @@ -0,0 +1,113 @@ +#include "ChatWindowPage.h" + +// We'll need some regular expression magic in this code: +#include + +// This is our ChatWindowPage constructor (you C++ n00b) +ChatWindowPage::ChatWindowPage(QWidget *parent) : QMainWindow(parent) +{ + // When using Designer, you should always call setupUi(this) + // in your constructor. This creates and lays out all the widgets + // on the ChatWindowPage that you setup in Designer. + setupUi(this); + + // Make sure that we are showing the login page when we startup: + stackedWidget->setCurrentWidget(loginPage); + + // Instantiate our socket (but don't actually connect to anything + // yet until the user clicks the loginButton: + socket = new QTcpSocket(this); + + // This is how we tell Qt to call our readyRead() and connected() + // functions when the socket has text ready to be read, and is done + // connecting to the server (respectively): + connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(socket, SIGNAL(connected()), this, SLOT(connected())); +} + +// This gets called when the loginButton gets clicked: +// We didn't have to use connect() to set this up because +// Qt recognizes the name of this function and knows to set +// up the signal/slot connection for us. +void ChatWindowPage::on_loginButton_clicked() +{ + // Start connecting to the chat server (on port 4200). + // This returns immediately and then works on connecting + // to the server in the background. When it's done, we'll + // get a connected() function call (below). If it fails, + // we won't get any error message because we didn't connect() + // to the error() signal from this socket. + socket->connectToHost(serverLineEdit->text(), 4200); +} + +// This gets called when the user clicks the sayButton (next to where +// they type text to send to the chat room): +void ChatWindowPage::on_sayButton_clicked() +{ + // What did they want to say (minus white space around the string): + QString message = sayLineEdit->text().trimmed(); + + // Only send the text to the chat server if it's not empty: + if(!message.isEmpty()) + { + socket->write(QString(message + "\n").toUtf8()); + } + + // Clear out the input box so they can type something else: + sayLineEdit->clear(); + + // Put the focus back into the input box so they can type again: + sayLineEdit->setFocus(); +} + +// This function gets called whenever the chat server has sent us some text: +void ChatWindowPage::readyRead() +{ + // We'll loop over every (complete) line of text that the server has sent us: + while(socket->canReadLine()) + { + // Here's the line the of text the server sent us (we use UTF-8 so + // that non-English speakers can chat in their native language) + QString line = QString::fromUtf8(socket->readLine()).trimmed(); + + // These two regular expressions describe the kinds of messages + // the server can send us: + + // Normal messges look like this: "username:The message" + QRegExp messageRegex("^([^:]+):(.*)$"); + + // Any message that starts with "/users:" is the server sending us a + // list of users so we can show that list in our GUI: + QRegExp usersRegex("^/users:(.*)$"); + + // Is this a users message: + if(usersRegex.indexIn(line) != -1) + { + // If so, udpate our users list on the right: + QStringList users = usersRegex.cap(1).split(","); + userListWidget->clear(); + foreach(QString user, users) + new QListWidgetItem(QPixmap(":/user.png"), user, userListWidget); + } + // Is this a normal chat message: + else if(messageRegex.indexIn(line) != -1) + { + // If so, append this message to our chat box: + QString user = messageRegex.cap(1); + QString message = messageRegex.cap(2); + + roomTextEdit->append("" + user + ": " + message); + } + } +} + +// This function gets called when our socket has successfully connected to the chat +// server. (see the connect() call in the ChatWindowPage constructor). +void ChatWindowPage::connected() +{ + // Flip over to the chat page: + stackedWidget->setCurrentWidget(chatPage); + + // And send our username to the chat server. + socket->write(QString("/me:" + userLineEdit->text() + "\n").toUtf8()); +} From 5646de8726e703b45f1cc14d06bd8cb96cc4dfe7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:45:33 -0400 Subject: [PATCH 0133/1324] Create chatwindowpage.h --- src/qt/chatwindowpage.h | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/qt/chatwindowpage.h diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h new file mode 100644 index 00000000..364750a4 --- /dev/null +++ b/src/qt/chatwindowpage.h @@ -0,0 +1,46 @@ +// We need to include a couple Qt classes that we'll use: +#include +#include + +// This is the include file that Qt generates for us from the +// GUI we built in Designer +#include "ui_ChatWindowPage.h" + +/* + * This is the ChatWindowPage class that we have told to inherit from + * our Designer ChatWindowPage (ui::ChatWindowPage) + */ +class ChatWindowPage : public QMainWindow, public Ui::ChatWindowPage +{ + Q_OBJECT + + public: + + // Every QWidget needs a constructor, and they should allow + // the user to pass a parent QWidget (or not). + ChatWindowPage(QWidget *parent=0); + + private Q_SLOTS: + + // This function gets called when a user clicks on the + // loginButton on the front page (which you placed there + // with Designer) + void on_loginButton_clicked(); + + // This gets called when you click the sayButton on + // the chat page. + void on_sayButton_clicked(); + + // This is a function we'll connect to a socket's readyRead() + // signal, which tells us there's text to be read from the chat + // server. + void readyRead(); + + // This function gets called when the socket tells us it's connected. + void connected(); + + private: + + // This is the socket that will let us communitate with the server. + QTcpSocket *socket; +}; From 5d0eaf7e706adde20130ed3b9e321d8c569f96c8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:46:41 -0400 Subject: [PATCH 0134/1324] Create chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 289 +++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 src/qt/forms/chatwindowpage.ui diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui new file mode 100644 index 00000000..4252ce96 --- /dev/null +++ b/src/qt/forms/chatwindowpage.ui @@ -0,0 +1,289 @@ + + ChatWindowPage + + + + 0 + 0 + 800 + 600 + + + + ChatWindowPage + + + #titleLabel { +background: white; +color: blue; +font-size: 20px; +border: none; +border-bottom: 1px solid black; +padding: 5px; +} + +#mainFrame { +border: none; +background: white; +} + +#loginFrame { +background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ddf, stop: 1 #aaf); +border: 1px solid gray; +padding: 10px; +border-radius: 25px; +} + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Chatter Box + + + + + + + QFrame::StyledPanel + + + + + + 1 + + + + + + + true + + + + + + + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + Say + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 100 + + + + + + + + Qt::Horizontal + + + + 223 + 20 + + + + + + + + + 0 + 0 + + + + + 300 + 0 + + + + QFrame::StyledPanel + + + + 20 + + + + + Server name: + + + + + + + + + + User name: + + + + + + + + + + + 0 + 0 + + + + Login + + + + + + + + + + Qt::Horizontal + + + + 223 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 267 + + + + + + + + + + + + + + + + serverLineEdit + userLineEdit + loginButton + roomTextEdit + userListWidget + sayLineEdit + sayButton + + + + + sayLineEdit + returnPressed() + sayButton + animateClick() + + + 331 + 564 + + + 768 + 570 + + + + + serverLineEdit + returnPressed() + userLineEdit + setFocus() + + + 391 + 188 + + + 470 + 238 + + + + + userLineEdit + returnPressed() + loginButton + animateClick() + + + 417 + 239 + + + 389 + 275 + + + + + From ea2c63fffef2f18c0c0c3437ec45c6200eecfdd3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:47:06 -0400 Subject: [PATCH 0135/1324] Add files via upload --- src/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main.cpp diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 00000000..3a69c78c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,21 @@ +#include "MainWindow.h" +#include + +/* + * This is your main() function. Very simple. + */ +int main(int argc, char **argv) +{ + // Every Qt GUI needs a QApplication. + QApplication app(argc, argv); + + // This is your MainWindow that you created with Designer + // Declare it and show it. + MainWindow mainWindow; + mainWindow.show(); + + // This will not return until the last window is closed. + // This runs the GUI's event loop handling painting and + // user input and stuff like that. + return app.exec(); +} From 741d4f136bde631ce1b95f9c57cb5853a801f062 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:47:32 -0400 Subject: [PATCH 0136/1324] Delete main.cpp --- src/main.cpp | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/main.cpp diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 3a69c78c..00000000 --- a/src/main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "MainWindow.h" -#include - -/* - * This is your main() function. Very simple. - */ -int main(int argc, char **argv) -{ - // Every Qt GUI needs a QApplication. - QApplication app(argc, argv); - - // This is your MainWindow that you created with Designer - // Declare it and show it. - MainWindow mainWindow; - mainWindow.show(); - - // This will not return until the last window is closed. - // This runs the GUI's event loop handling painting and - // user input and stuff like that. - return app.exec(); -} From 83953f94a05c59bc2965c8c84aecb58cf1e5c215 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:47:42 -0400 Subject: [PATCH 0137/1324] Add files via upload --- src/qt/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..3a69c78c --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,21 @@ +#include "MainWindow.h" +#include + +/* + * This is your main() function. Very simple. + */ +int main(int argc, char **argv) +{ + // Every Qt GUI needs a QApplication. + QApplication app(argc, argv); + + // This is your MainWindow that you created with Designer + // Declare it and show it. + MainWindow mainWindow; + mainWindow.show(); + + // This will not return until the last window is closed. + // This runs the GUI's event loop handling painting and + // user input and stuff like that. + return app.exec(); +} From ca482806372e1ca79ad2cff4e9c7ca279640ea3e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:48:55 -0400 Subject: [PATCH 0138/1324] Update main.cpp --- src/qt/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 3a69c78c..d22ead2d 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,4 +1,4 @@ -#include "MainWindow.h" +#include "ChatWindowPage.h" #include /* @@ -11,8 +11,8 @@ int main(int argc, char **argv) // This is your MainWindow that you created with Designer // Declare it and show it. - MainWindow mainWindow; - mainWindow.show(); + ChatWindowPage chatWindowPage; + chatWindowPage.show(); // This will not return until the last window is closed. // This runs the GUI's event loop handling painting and From 5fee7b3de7bbff6a72e59317afa58c0a0112ba1e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:51:17 -0400 Subject: [PATCH 0139/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 517eaa8f..04c9c6c3 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -87,7 +87,7 @@ void ChatWindowPage::readyRead() QStringList users = usersRegex.cap(1).split(","); userListWidget->clear(); foreach(QString user, users) - new QListWidgetItem(QPixmap(":/user.png"), user, userListWidget); + new QListWidgetItem(QPixmap(":/icons/chat.png"), user, userListWidget); } // Is this a normal chat message: else if(messageRegex.indexIn(line) != -1) From 963e764770b5347b625b0492fa02abb28edefbb8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:52:06 -0400 Subject: [PATCH 0140/1324] Rename main.cpp to mainchat.cpp --- src/qt/{main.cpp => mainchat.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{main.cpp => mainchat.cpp} (100%) diff --git a/src/qt/main.cpp b/src/qt/mainchat.cpp similarity index 100% rename from src/qt/main.cpp rename to src/qt/mainchat.cpp From d2d02a9af6559038de0086c1674911971726e4ef Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:52:43 -0400 Subject: [PATCH 0141/1324] Add files via upload --- src/qt/ChatterBoxServer.cpp | 80 +++++++++++++++++++++++++++++++++++++ src/qt/ChatterBoxServer.h | 30 ++++++++++++++ src/qt/main.cpp | 18 +++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/qt/ChatterBoxServer.cpp create mode 100644 src/qt/ChatterBoxServer.h create mode 100644 src/qt/main.cpp diff --git a/src/qt/ChatterBoxServer.cpp b/src/qt/ChatterBoxServer.cpp new file mode 100644 index 00000000..a42ed2ef --- /dev/null +++ b/src/qt/ChatterBoxServer.cpp @@ -0,0 +1,80 @@ +#include "ChatterBoxServer.h" + +#include +#include + +ChatterBoxServer::ChatterBoxServer(QObject *parent) : QTcpServer(parent) +{ +} + +void ChatterBoxServer::incomingConnection(int socketfd) +{ + QTcpSocket *client = new QTcpSocket(this); + client->setSocketDescriptor(socketfd); + clients.insert(client); + + qDebug() << "New client from:" << client->peerAddress().toString(); + + connect(client, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(client, SIGNAL(disconnected()), this, SLOT(disconnected())); +} + +void ChatterBoxServer::readyRead() +{ + QTcpSocket *client = (QTcpSocket*)sender(); + while(client->canReadLine()) + { + QString line = QString::fromUtf8(client->readLine()).trimmed(); + qDebug() << "Read line:" << line; + + QRegExp meRegex("^/me:(.*)$"); + + if(meRegex.indexIn(line) != -1) + { + QString user = meRegex.cap(1); + users[client] = user; + foreach(QTcpSocket *client, clients) + client->write(QString("Server:" + user + " has joined.\n").toUtf8()); + sendUserList(); + } + else if(users.contains(client)) + { + QString message = line; + QString user = users[client]; + qDebug() << "User:" << user; + qDebug() << "Message:" << message; + + foreach(QTcpSocket *otherClient, clients) + otherClient->write(QString(user + ":" + message + "\n").toUtf8()); + } + else + { + qWarning() << "Got bad message from client:" << client->peerAddress().toString() << line; + } + } +} + +void ChatterBoxServer::disconnected() +{ + QTcpSocket *client = (QTcpSocket*)sender(); + qDebug() << "Client disconnected:" << client->peerAddress().toString(); + + clients.remove(client); + + QString user = users[client]; + users.remove(client); + + sendUserList(); + foreach(QTcpSocket *client, clients) + client->write(QString("Server:" + user + " has left.\n").toUtf8()); +} + +void ChatterBoxServer::sendUserList() +{ + QStringList userList; + foreach(QString user, users.values()) + userList << user; + + foreach(QTcpSocket *client, clients) + client->write(QString("/users:" + userList.join(",") + "\n").toUtf8()); +} diff --git a/src/qt/ChatterBoxServer.h b/src/qt/ChatterBoxServer.h new file mode 100644 index 00000000..6b5f044f --- /dev/null +++ b/src/qt/ChatterBoxServer.h @@ -0,0 +1,30 @@ +#ifndef __ChatterBoxServer_H__ +#define __ChatterBoxServer_H__ + +#include +#include +#include +#include +#include + +class ChatterBoxServer : public QTcpServer +{ + Q_OBJECT + + public: + ChatterBoxServer(QObject *parent=0); + + private slots: + void readyRead(); + void disconnected(); + void sendUserList(); + + protected: + void incomingConnection(int socketfd); + + private: + QSet clients; + QMap users; +}; + +#endif diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..23748fc4 --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,18 @@ +#include "ChatterBoxServer.h" +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + ChatterBoxServer *server = new ChatterBoxServer(); + bool success = server->listen(QHostAddress::Any, 4200); + if(!success) + { + qFatal("Could not listen on port 4200."); + } + + qDebug() << "Ready"; + + return app.exec(); +} From 7854d1a7de4d50fe2f837bfc3445c2ad316a6a46 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:53:42 -0400 Subject: [PATCH 0142/1324] Update ChatterBoxServer.h --- src/qt/ChatterBoxServer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/ChatterBoxServer.h b/src/qt/ChatterBoxServer.h index 6b5f044f..f4caefae 100644 --- a/src/qt/ChatterBoxServer.h +++ b/src/qt/ChatterBoxServer.h @@ -14,7 +14,7 @@ class ChatterBoxServer : public QTcpServer public: ChatterBoxServer(QObject *parent=0); - private slots: + private Q_SLOTS: void readyRead(); void disconnected(); void sendUserList(); From 4eb43bec82506f7c04cf530da817d5567d355654 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:57:33 -0400 Subject: [PATCH 0143/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e0d872f5..02a1c82f 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,6 +33,7 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ + qt/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ @@ -64,6 +65,8 @@ QT_MOC_CPP = \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ + qt/moc_chatwindowpage.cpp \ + qt/moc_chatboxserver.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -139,6 +142,8 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ + qt/chatboxserver.h \ + qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ @@ -501,11 +506,14 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ + qt/chatboxserver.cpp \ + qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ + qt/main.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ From a5a29087975be86e2a77db9adf8d2e0ed2d2902a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:58:21 -0400 Subject: [PATCH 0144/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 02a1c82f..397f9268 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -514,6 +514,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/governancelist.cpp \ qt/governancedialog.cpp \ qt/main.cpp \ + qt/mainchat.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ From 655ab7ec1ea294594dc90303e857e6843759ae70 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:59:09 -0400 Subject: [PATCH 0145/1324] Update walletview.h --- src/qt/walletview.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index af7597f0..826b8d72 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,8 +8,8 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -/* #include "tradingdialogpage.h" -#include "chatwindowpage.h" */ +/* #include "tradingdialogpage.h" */ +#include "chatwindowpage.h" #include @@ -26,8 +26,8 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -/* class TradingDialogPage; -class ChatWindowPage;*/ +/* class TradingDialogPage; */ +class ChatWindowPage; QT_BEGIN_NAMESPACE @@ -78,8 +78,8 @@ class WalletView : public QStackedWidget PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; TransactionView *transactionView; - /* TradingDialogPage *tradingDialogPage; - ChatWindowPage *chatWindowPage; */ + /* TradingDialogPage *tradingDialogPage; */ + ChatWindowPage *chatWindowPage; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -88,7 +88,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to chat page */ - /* void gotoChatWindowPage(); */ + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From a931f9871a3d5f7b35f0e8a44674f74279879a8f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:59:38 -0400 Subject: [PATCH 0146/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 2b2d53f5..47cd79f3 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - /* chatWindowPage = new ChatWindowPage(); - addWidget(chatWindowPage); */ + chatWindowPage = new ChatWindowPage(); + addWidget(chatWindowPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -241,10 +241,10 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -/*void WalletView::gotoChatWindowPage() +void WalletView::gotoChatWindowPage() { setCurrentWidget(chatWindowPage); -} */ +} /*void WalletView::gotoTradingDialogPage() { From e25cdf6b252cff677733caa57ea15f531d2343fc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 16:59:55 -0400 Subject: [PATCH 0147/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 404550a4..982f6690 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to chat page */ - /* void gotoChatWindowPage(); */ + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ec808cb7a3a9e8775222663c0dee0b9e18c41a88 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:00:17 -0400 Subject: [PATCH 0148/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index eb6a9f78..035ad36c 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,13 +108,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -/*void WalletFrame::gotoChatWindowPage() +void WalletFrame::gotoChatWindowPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) i.value()->gotoChatWindowPage(); -} */ +} /*void WalletFrame::gotoTradingDialogPage() { From bd9e5e5d0dce3c71588b8ac235104f99018421e3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:00:54 -0400 Subject: [PATCH 0149/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 1f6ae97c..c5912c3b 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -38,8 +38,8 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -/*class tradingDialogPage; -class ChatWindowPage; */ +/*class tradingDialogPage; */ +class ChatWindowPage; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - /*QAction* chatWindowPage; */ + QAction* chatWindowPage; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to chat page */ - /* void gotoChatWindowPage(); */ + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From aa32d7468919ba12b0010893cd00d4786e64b9db Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:02:05 -0400 Subject: [PATCH 0150/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7cde2589..689b6a87 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,8 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -/* #include "tradingdialogpage.h" -#include "chatwindowpage.h" */ +/* #include "tradingdialogpage.h" */ +#include "chatwindowpage.h" #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - /* chatWindowPage(0), */ + chatWindowPage(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -620,8 +620,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - /* chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); - chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); */ + chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); + chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -637,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - /* connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); */ + connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -739,8 +739,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - /* QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); - chat->addAction(chatWindowPage); */ + QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); + chat->addAction(chatWindowPage); } @@ -1069,11 +1069,11 @@ void BitcoinGUI::openClicked() } } -/*void BitcoinGUI::gotoChatWindowPage() +void BitcoinGUI::gotoChatWindowPage() { chatWindowPage->setChecked(true); if (walletFrame) walletFrame->gotoChatWindowPage(); -} */ +} /*void BitcoinGUI::gotoTradingDialogPage() { From 2279f69eeee29cc09a32c39eb37169ea693bfe40 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:03:26 -0400 Subject: [PATCH 0151/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 397f9268..8fb5cb28 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,7 +33,7 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ - qt/chatwindowpage.ui \ + qt/forms/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ From d8e89c8062d91b125b85e5f4bda9a876c152b8bc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:05:09 -0400 Subject: [PATCH 0152/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 8fb5cb28..006a9f21 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -66,7 +66,7 @@ QT_MOC_CPP = \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ qt/moc_chatwindowpage.cpp \ - qt/moc_chatboxserver.cpp \ + qt/moc_chatterboxserver.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -142,7 +142,7 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ - qt/chatboxserver.h \ + qt/chatterboxserver.h \ qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ @@ -506,7 +506,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ - qt/chatboxserver.cpp \ + qt/chatterboxserver.cpp \ qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ From 6f1222c88a4a2ea396d1228f645460788d7a8661 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:06:21 -0400 Subject: [PATCH 0153/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 006a9f21..ed1dcd19 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -66,7 +66,6 @@ QT_MOC_CPP = \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ qt/moc_chatwindowpage.cpp \ - qt/moc_chatterboxserver.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ From e65e91c458bc2942ea809db178d8eab8b343d655 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:07:52 -0400 Subject: [PATCH 0154/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 8f8ce63d..ae8b96bf 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -28,3 +28,6 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe + +HEADERS += ChatterBoxServer.h +SOURCES += ChatterBoxServer.cpp main.cpp From 1570064b1e1b5fbe51dc46a34f3e7ca57c14dc37 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:09:59 -0400 Subject: [PATCH 0155/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index 364750a4..f214fbba 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -4,7 +4,7 @@ // This is the include file that Qt generates for us from the // GUI we built in Designer -#include "ui_ChatWindowPage.h" +#include "ChatWindowPage.ui" /* * This is the ChatWindowPage class that we have told to inherit from From 069f0ad391e08b34d0e4878bcc38e62356e1309f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:10:33 -0400 Subject: [PATCH 0156/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index f214fbba..364750a4 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -4,7 +4,7 @@ // This is the include file that Qt generates for us from the // GUI we built in Designer -#include "ChatWindowPage.ui" +#include "ui_ChatWindowPage.h" /* * This is the ChatWindowPage class that we have told to inherit from From c61a142a310a0b6a0acdf1bc1e78c199a9a5bc8a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:13:09 -0400 Subject: [PATCH 0157/1324] Rename ChatterBoxServer.cpp to chatterboxserver.cpp --- src/qt/{ChatterBoxServer.cpp => chatterboxserver.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{ChatterBoxServer.cpp => chatterboxserver.cpp} (100%) diff --git a/src/qt/ChatterBoxServer.cpp b/src/qt/chatterboxserver.cpp similarity index 100% rename from src/qt/ChatterBoxServer.cpp rename to src/qt/chatterboxserver.cpp From f06bc0ef3f5764a4a67fb03631c181083caf215b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:13:26 -0400 Subject: [PATCH 0158/1324] Rename ChatterBoxServer.h to chatterboxserver.h --- src/qt/{ChatterBoxServer.h => chatterboxserver.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{ChatterBoxServer.h => chatterboxserver.h} (100%) diff --git a/src/qt/ChatterBoxServer.h b/src/qt/chatterboxserver.h similarity index 100% rename from src/qt/ChatterBoxServer.h rename to src/qt/chatterboxserver.h From a2e90a32a8986c90df6418bac82a5e1b5ba48025 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:14:25 -0400 Subject: [PATCH 0159/1324] Update mainchat.cpp --- src/qt/mainchat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainchat.cpp b/src/qt/mainchat.cpp index d22ead2d..3283ca9d 100644 --- a/src/qt/mainchat.cpp +++ b/src/qt/mainchat.cpp @@ -1,4 +1,4 @@ -#include "ChatWindowPage.h" +#include "chatwindowpage.h" #include /* From 03d132e22b5717d69ef7d6b41ea9ac19fad93df4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:14:56 -0400 Subject: [PATCH 0160/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index 364750a4..4632402c 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -4,7 +4,7 @@ // This is the include file that Qt generates for us from the // GUI we built in Designer -#include "ui_ChatWindowPage.h" +#include "ui_chatwindowpage.h" /* * This is the ChatWindowPage class that we have told to inherit from From 18ddf6407fd24231373c17fe9c6a4750f26febe5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:15:18 -0400 Subject: [PATCH 0161/1324] Update chatterboxserver.cpp --- src/qt/chatterboxserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatterboxserver.cpp b/src/qt/chatterboxserver.cpp index a42ed2ef..e55643e6 100644 --- a/src/qt/chatterboxserver.cpp +++ b/src/qt/chatterboxserver.cpp @@ -1,4 +1,4 @@ -#include "ChatterBoxServer.h" +#include "chatterboxserver.h" #include #include From 970610af2d57575aaf349a04f1eb5f26cabcdab6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:15:47 -0400 Subject: [PATCH 0162/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 04c9c6c3..5db943cc 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -1,4 +1,4 @@ -#include "ChatWindowPage.h" +#include "chatwindowpage.h" // We'll need some regular expression magic in this code: #include From fdbdabb9c59cca87d8f559ead77740172626a0c6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:16:11 -0400 Subject: [PATCH 0163/1324] Update main.cpp --- src/qt/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 23748fc4..fa767a05 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,4 +1,4 @@ -#include "ChatterBoxServer.h" +#include "chatterboxserver.h" #include int main(int argc, char **argv) From 82c568119998e8cd28b216f13647e96d4ead7e4c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:17:12 -0400 Subject: [PATCH 0164/1324] Update chatterboxserver.cpp --- src/qt/chatterboxserver.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/chatterboxserver.cpp b/src/qt/chatterboxserver.cpp index e55643e6..f326874b 100644 --- a/src/qt/chatterboxserver.cpp +++ b/src/qt/chatterboxserver.cpp @@ -44,7 +44,7 @@ void ChatterBoxServer::readyRead() qDebug() << "User:" << user; qDebug() << "Message:" << message; - foreach(QTcpSocket *otherClient, clients) + Q_FOREACH(QTcpSocket *otherClient, clients) otherClient->write(QString(user + ":" + message + "\n").toUtf8()); } else @@ -65,16 +65,16 @@ void ChatterBoxServer::disconnected() users.remove(client); sendUserList(); - foreach(QTcpSocket *client, clients) + Q_FOREACH(QTcpSocket *client, clients) client->write(QString("Server:" + user + " has left.\n").toUtf8()); } void ChatterBoxServer::sendUserList() { QStringList userList; - foreach(QString user, users.values()) + Q_FOREACH(QString user, users.values()) userList << user; - foreach(QTcpSocket *client, clients) + Q_FOREACH(QTcpSocket *client, clients) client->write(QString("/users:" + userList.join(",") + "\n").toUtf8()); } From da3c76e5ca9ed8bf09dea28780be2d694d07c16d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:17:49 -0400 Subject: [PATCH 0165/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 5db943cc..f1c4185f 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -86,7 +86,7 @@ void ChatWindowPage::readyRead() // If so, udpate our users list on the right: QStringList users = usersRegex.cap(1).split(","); userListWidget->clear(); - foreach(QString user, users) + Q_FOREACH(QString user, users) new QListWidgetItem(QPixmap(":/icons/chat.png"), user, userListWidget); } // Is this a normal chat message: From 53375f006961ffa09cdd720aa82deb296d9340ed Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:18:40 -0400 Subject: [PATCH 0166/1324] Update chatterboxserver.cpp --- src/qt/chatterboxserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatterboxserver.cpp b/src/qt/chatterboxserver.cpp index f326874b..dcf95811 100644 --- a/src/qt/chatterboxserver.cpp +++ b/src/qt/chatterboxserver.cpp @@ -33,7 +33,7 @@ void ChatterBoxServer::readyRead() { QString user = meRegex.cap(1); users[client] = user; - foreach(QTcpSocket *client, clients) + Q_FOREACH(QTcpSocket *client, clients) client->write(QString("Server:" + user + " has joined.\n").toUtf8()); sendUserList(); } From 26268e24a7e0aff47156312d04e867e9ff00eb1a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:26:07 -0400 Subject: [PATCH 0167/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index 4252ce96..f62e55c5 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -24,7 +24,7 @@ padding: 5px; #mainFrame { border: none; -background: white; +background: #1e1d32; } #loginFrame { @@ -51,7 +51,7 @@ border-radius: 25px;
- Chatter Box + HTH Chat
From 9a7d2882f6ddc98cef6d7331686e637b3e9c1927 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:28:57 -0400 Subject: [PATCH 0168/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index f62e55c5..8b495541 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -14,8 +14,8 @@
#titleLabel { -background: white; -color: blue; +background: #1e1d32; +color: #34bcaa; font-size: 20px; border: none; border-bottom: 1px solid black; From 0628c59a393c91fc1265905a3c1cc1716bd9d0a1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:38:46 -0400 Subject: [PATCH 0169/1324] Add files via upload --- src/qt/Client/SocketClient.pro | 42 +++++++ src/qt/Client/forms/dialog_settings.ui | 73 ++++++++++++ src/qt/Client/forms/mainwindow.ui | 115 ++++++++++++++++++ src/qt/Client/include/dialog_settings.h | 34 ++++++ src/qt/Client/include/mainwindow.h | 47 ++++++++ src/qt/Client/include/settings_reader.h | 25 ++++ src/qt/Client/include/settings_writer.h | 25 ++++ src/qt/Client/include/socket_client.h | 41 +++++++ src/qt/Client/settings.json | 5 + src/qt/Client/src/dialog_settings.cpp | 64 ++++++++++ src/qt/Client/src/main.cpp | 10 ++ src/qt/Client/src/mainwindow.cpp | 130 +++++++++++++++++++++ src/qt/Client/src/settings_reader.cpp | 36 ++++++ src/qt/Client/src/settings_writer.cpp | 34 ++++++ src/qt/Client/src/socket_client.cpp | 81 +++++++++++++ src/qt/Server/SocketServer.pro | 37 ++++++ src/qt/Server/forms/mainwindow.ui | 73 ++++++++++++ src/qt/Server/include/mainwindow.h | 33 ++++++ src/qt/Server/include/server_data_base.h | 26 +++++ src/qt/Server/include/socket_server.h | 46 ++++++++ src/qt/Server/src/main.cpp | 10 ++ src/qt/Server/src/mainwindow.cpp | 51 ++++++++ src/qt/Server/src/server_data_base.cpp | 42 +++++++ src/qt/Server/src/socket_server.cpp | 141 +++++++++++++++++++++++ 24 files changed, 1221 insertions(+) create mode 100644 src/qt/Client/SocketClient.pro create mode 100644 src/qt/Client/forms/dialog_settings.ui create mode 100644 src/qt/Client/forms/mainwindow.ui create mode 100644 src/qt/Client/include/dialog_settings.h create mode 100644 src/qt/Client/include/mainwindow.h create mode 100644 src/qt/Client/include/settings_reader.h create mode 100644 src/qt/Client/include/settings_writer.h create mode 100644 src/qt/Client/include/socket_client.h create mode 100644 src/qt/Client/settings.json create mode 100644 src/qt/Client/src/dialog_settings.cpp create mode 100644 src/qt/Client/src/main.cpp create mode 100644 src/qt/Client/src/mainwindow.cpp create mode 100644 src/qt/Client/src/settings_reader.cpp create mode 100644 src/qt/Client/src/settings_writer.cpp create mode 100644 src/qt/Client/src/socket_client.cpp create mode 100644 src/qt/Server/SocketServer.pro create mode 100644 src/qt/Server/forms/mainwindow.ui create mode 100644 src/qt/Server/include/mainwindow.h create mode 100644 src/qt/Server/include/server_data_base.h create mode 100644 src/qt/Server/include/socket_server.h create mode 100644 src/qt/Server/src/main.cpp create mode 100644 src/qt/Server/src/mainwindow.cpp create mode 100644 src/qt/Server/src/server_data_base.cpp create mode 100644 src/qt/Server/src/socket_server.cpp diff --git a/src/qt/Client/SocketClient.pro b/src/qt/Client/SocketClient.pro new file mode 100644 index 00000000..5d4764ba --- /dev/null +++ b/src/qt/Client/SocketClient.pro @@ -0,0 +1,42 @@ +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +QMAKE_CXXFLAGS += -std=c++17 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + src/dialog_settings.cpp \ + src/main.cpp \ + src/mainwindow.cpp \ + src/settings_reader.cpp \ + src/settings_writer.cpp \ + src/socket_client.cpp + +HEADERS += \ + include/dialog_settings.h \ + include/mainwindow.h \ + include/settings_reader.h \ + include/settings_writer.h \ + include/socket_client.h + +FORMS += \ + forms/dialog_settings.ui \ + forms/mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/src/qt/Client/forms/dialog_settings.ui b/src/qt/Client/forms/dialog_settings.ui new file mode 100644 index 00000000..29b6c025 --- /dev/null +++ b/src/qt/Client/forms/dialog_settings.ui @@ -0,0 +1,73 @@ + + + DialogSettings + + + + 0 + 0 + 229 + 138 + + + + Dialog + + + + + + + + Remote ip-address + + + + + + + + + + + + + 192.168.3.1 + + + + + + + Remote port + + + + + + + Nickname + + + + + + + + + Save settings + + + + + + + Cancel + + + + + + + + diff --git a/src/qt/Client/forms/mainwindow.ui b/src/qt/Client/forms/mainwindow.ui new file mode 100644 index 00000000..84579ff8 --- /dev/null +++ b/src/qt/Client/forms/mainwindow.ui @@ -0,0 +1,115 @@ + + + MainWindow + + + + 0 + 0 + 558 + 380 + + + + Socket Client + + + + + + + true + + + Clear + + + + + + + false + + + + + + + true + + + Qt::NoFocus + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html> + + + + + + + false + + + Send + + + + + + + false + + + Disconnect + + + false + + + false + + + + + + + Connect + + + + + + + + + 0 + 0 + 558 + 21 + + + + + Menu + + + + + + + + Settings + + + + + + diff --git a/src/qt/Client/include/dialog_settings.h b/src/qt/Client/include/dialog_settings.h new file mode 100644 index 00000000..b3c5fc5f --- /dev/null +++ b/src/qt/Client/include/dialog_settings.h @@ -0,0 +1,34 @@ +#ifndef DIALOG_SETTINGS_H +#define DIALOG_SETTINGS_H + +#include + +/* Including other modules */ +#include "settings_reader.h" // class SettingsReader (for reading settings) +#include "settings_writer.h" // class SettingsWriter (for writting settings) + +namespace Ui { class DialogSettings; } + +class DialogSettings : public QDialog +{ + Q_OBJECT + +public: + explicit DialogSettings(QWidget *parent = nullptr); + ~DialogSettings(); + +private slots: + // Slot for handling 'Error' signal from the class SettingsReader and SettingsWriter + void on_Error(const QString &err_msg); + + // Buttons slots + void on_pushButtonSaveSettings_clicked(); + void on_pushButtonCancel_clicked(); + +private: + Ui::DialogSettings *ui; + SettingsWriter settings_writer; + SettingsReader settings_reader; +}; + +#endif // DIALOG_SETTINGS_H diff --git a/src/qt/Client/include/mainwindow.h b/src/qt/Client/include/mainwindow.h new file mode 100644 index 00000000..a132feb2 --- /dev/null +++ b/src/qt/Client/include/mainwindow.h @@ -0,0 +1,47 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +/* Including other modules */ +#include "socket_client.h" // class SocketClient (the base class of a client side) +#include "settings_reader.h" // class SettingsReader (for reading settings) + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + // Slots for handling signals from the class SocketClient + void on_OutInfo(const QString &message); + void on_Error(const QString &message); + void on_Connected(); + void on_Disconnected(); + + // Buttons slots + void on_pushButtonConnectToServer_clicked(); + void on_pushButtonSendMessage_clicked(); + void on_pushButtonClearOutput_clicked(); + void on_pushButtonDisconnectFromServer_clicked(); + + // Menu bar actions (slots) + void on_actionSettings_triggered(); + +private: + Ui::MainWindow *ui; + SocketClient socket_client; + SettingsReader settings_reader; + QString remote_address; + quint16 remote_port; + QString nickname; +}; + +#endif // MAINWINDOW_H diff --git a/src/qt/Client/include/settings_reader.h b/src/qt/Client/include/settings_reader.h new file mode 100644 index 00000000..4de66fd4 --- /dev/null +++ b/src/qt/Client/include/settings_reader.h @@ -0,0 +1,25 @@ +#ifndef SETTINGSREADER_H +#define SETTINGSREADER_H + +#include +#include +#include + +class SettingsReader : public QObject +{ + Q_OBJECT + +private: + QFile input_file; + +public: + SettingsReader(); + ~SettingsReader(); + void LoadFile(const char *filename); + QMap ReadAll(); + +signals: + void Error(const QString &err_msg); +}; + +#endif // SETTINGSREADER_H diff --git a/src/qt/Client/include/settings_writer.h b/src/qt/Client/include/settings_writer.h new file mode 100644 index 00000000..b8be6190 --- /dev/null +++ b/src/qt/Client/include/settings_writer.h @@ -0,0 +1,25 @@ +#ifndef SETTINGSWRITER_H +#define SETTINGSWRITER_H + +#include +#include +#include + +class SettingsWriter : public QObject +{ + Q_OBJECT + +private: + QFile output_file; + +public: + SettingsWriter(); + ~SettingsWriter(); + void SetOutputFile(const char *filename); + void WriteSettings(QMap &settings); + +signals: + void Error(const QString &err_msg); +}; + +#endif // SETTINGSWRITER_H diff --git a/src/qt/Client/include/socket_client.h b/src/qt/Client/include/socket_client.h new file mode 100644 index 00000000..c7a3c01a --- /dev/null +++ b/src/qt/Client/include/socket_client.h @@ -0,0 +1,41 @@ +#ifndef SOCKETCLIENT_H +#define SOCKETCLIENT_H + +#include +#include +#include +#include + +class SocketClient : public QObject +{ + Q_OBJECT +private: + quint16 remote_port; + QString remote_address; + QTcpSocket tcp_sock; + +public: + explicit SocketClient(QObject *parent = nullptr); + void setPort(quint16 port); + void setAddress(const QString &address); + void start(); + +private slots: + void on_Connected(); + void on_Disconnected(); + void on_ReadyRead(); + void DisplayError(QAbstractSocket::SocketError error_code); + +public slots: + void SendToServer(const QString &nickname, const QString &message); + void stop(); + +signals: + void outInfo(const QString &message); + void Error(const QString &message); + void started(); + void connected(); + void disconnected(); +}; + +#endif // SOCKETCLIENT_H diff --git a/src/qt/Client/settings.json b/src/qt/Client/settings.json new file mode 100644 index 00000000..acbe1620 --- /dev/null +++ b/src/qt/Client/settings.json @@ -0,0 +1,5 @@ +{ + "remote_ip-address": "127.0.0.1", + "remote_port": "4455", + "nickname": "[Creator] AlexCr4ckPentest" +} \ No newline at end of file diff --git a/src/qt/Client/src/dialog_settings.cpp b/src/qt/Client/src/dialog_settings.cpp new file mode 100644 index 00000000..29c05ab9 --- /dev/null +++ b/src/qt/Client/src/dialog_settings.cpp @@ -0,0 +1,64 @@ +#include "../include/dialog_settings.h" +#include "../ui_dialog_settings.h" +#include + +static constexpr const char *settings_filename = "settings.json"; + +DialogSettings::DialogSettings(QWidget *parent) + : QDialog(parent) + , ui(new Ui::DialogSettings) +{ + ui->setupUi(this); + connect(&settings_writer, &SettingsWriter::Error, this, &DialogSettings::on_Error); + connect(&settings_reader, &SettingsReader::Error, this, &DialogSettings::on_Error); + + settings_reader.LoadFile(settings_filename); + + const auto settings_to_restore = settings_reader.ReadAll(); + ui->lineEditRemoteIpAddress->setText(settings_to_restore["remote_ip-address"]); + ui->lineEditRemotePort->setText(settings_to_restore["remote_port"]); + ui->lineEditNickname->setText(settings_to_restore["nickname"]); +} + +DialogSettings::~DialogSettings() +{ + delete ui; +} + +void DialogSettings::on_Error(const QString &err_msg) +{ + QMessageBox::critical(this, "Error!", err_msg); +} + +void DialogSettings::on_pushButtonSaveSettings_clicked() +{ + QMap settings; + + QString remote_address = ui->lineEditRemoteIpAddress->text(); + QString remote_port = ui->lineEditRemotePort->text(); + QString nickname = ui->lineEditNickname->text(); + + if (remote_address.isEmpty()) { + remote_address = "127.0.0.1"; + } + else if (remote_port.isEmpty()) { + remote_port = "4455"; + } + else if (nickname.isEmpty()) { + nickname = "Chat_user"; + } + + settings["remote_ip-address"] = remote_address; + settings["remote_port"] = remote_port; + settings["nickname"] = nickname; + + settings_writer.SetOutputFile(settings_filename); + settings_writer.WriteSettings(settings); + + QMessageBox::information(this, "Success!", "settings have been saved!"); +} + +void DialogSettings::on_pushButtonCancel_clicked() +{ + close(); +} diff --git a/src/qt/Client/src/main.cpp b/src/qt/Client/src/main.cpp new file mode 100644 index 00000000..0f3fe68a --- /dev/null +++ b/src/qt/Client/src/main.cpp @@ -0,0 +1,10 @@ +#include "../include/mainwindow.h" +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + MainWindow main_window; + main_window.show(); + return app.exec(); +} diff --git a/src/qt/Client/src/mainwindow.cpp b/src/qt/Client/src/mainwindow.cpp new file mode 100644 index 00000000..66d0728e --- /dev/null +++ b/src/qt/Client/src/mainwindow.cpp @@ -0,0 +1,130 @@ +#include "../include/mainwindow.h" +#include "../ui_mainwindow.h" + +/* Including other forms */ +#include "../include/dialog_settings.h" // DialogSettings class (form with a connection settings) + +#include + +static constexpr const char *settings_filename = "settings.json"; + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + connect(&socket_client, &SocketClient::outInfo, this, &MainWindow::on_OutInfo); + connect(&socket_client, &SocketClient::Error, this, &MainWindow::on_Error); + connect(&socket_client, &SocketClient::connected, this, &MainWindow::on_Connected); + connect(&socket_client, &SocketClient::disconnected, this, &MainWindow::on_Disconnected); + + + connect(&settings_reader, &SettingsReader::Error, this, &MainWindow::on_Error); + + // Loading file for reading + settings_reader.LoadFile(settings_filename); + + // Reading settings from file + const auto settings = settings_reader.ReadAll(); + remote_address = settings["remote_ip-address"]; + remote_port = settings["remote_port"].toUInt(); + nickname = settings["nickname"]; +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_OutInfo(const QString &message) +{ + ui->textEditOutput->append(message); +} + +void MainWindow::on_Error(const QString &message) +{ + QMessageBox::critical(this, "Error!", message); +} + +void MainWindow::on_Connected() +{ + ui->pushButtonDisconnectFromServer->setEnabled(true); + ui->pushButtonSendMessage->setEnabled(true); + ui->lineEditInputMessageToSend->setEnabled(true); +} + +void MainWindow::on_Disconnected() +{ + ui->pushButtonDisconnectFromServer->setEnabled(false); + ui->pushButtonSendMessage->setEnabled(false); + ui->lineEditInputMessageToSend->setEnabled(false); + ui->lineEditInputMessageToSend->clear(); +} + +/* TODO: + * Check remote_address and nickname + * Set address and port for connection with a server + * Start the client for sendding and reciving messages +*/ +void MainWindow::on_pushButtonConnectToServer_clicked() +{ + if (remote_address.isEmpty()) { + QMessageBox::critical(this, "Error!", "Enter IP-address of the server!"); + return; + } + + if (nickname.isEmpty()) { + QMessageBox::critical(this, "Error!", "Enter your nickname!"); + return; + } + + socket_client.setAddress(remote_address); + socket_client.setPort(remote_port); + socket_client.start(); +} + +/* TODO: + * Read message from lineEditInputMessageToSend + * Check this message + * Create data to send (concatenate nickname with a message) + * Call method for send data to server +*/ +void MainWindow::on_pushButtonSendMessage_clicked() +{ + const QString message = ui->lineEditInputMessageToSend->text(); + + if (message.isEmpty()) { + QMessageBox::critical(this, "Error!", "Enter a message to send!"); + return; + } + + socket_client.SendToServer(nickname, message); + + ui->lineEditInputMessageToSend->clear(); +} + +/* TODO: + * Check textEditOutput (is empty or not) + * If not empty --> call 'clear()' method +*/ +void MainWindow::on_pushButtonClearOutput_clicked() +{ + if (not ui->textEditOutput->toPlainText().isEmpty()) { + ui->textEditOutput->clear(); + } +} + +/* TODO: + * Show the 'DialogSettings' form +*/ +void MainWindow::on_actionSettings_triggered() +{ + DialogSettings settings_dialog; + settings_dialog.exec(); +} + +void MainWindow::on_pushButtonDisconnectFromServer_clicked() +{ + socket_client.stop(); +} diff --git a/src/qt/Client/src/settings_reader.cpp b/src/qt/Client/src/settings_reader.cpp new file mode 100644 index 00000000..6fd12943 --- /dev/null +++ b/src/qt/Client/src/settings_reader.cpp @@ -0,0 +1,36 @@ +#include "../include/settings_reader.h" +#include +#include +#include +#include + +SettingsReader::SettingsReader() +{} + +SettingsReader::~SettingsReader() +{} + +void SettingsReader::LoadFile(const char *filename) +{ + input_file.setFileName(filename); +} + +QMap SettingsReader::ReadAll() +{ + QMap settings; + if (not input_file.open(QIODevice::ReadOnly)) { + emit Error(QString("Could not find the settings file!")); + return settings; + } + + QByteArray data = input_file.readAll(); + QJsonDocument json_doc = QJsonDocument::fromJson(data); + QJsonObject json_obj = json_doc.object(); + + settings["remote_ip-address"] = json_obj["remote_ip-address"].toString(); + settings["remote_port"] = json_obj["remote_port"].toString(); + settings["nickname"] = json_obj["nickname"].toString(); + + input_file.close(); + return settings; +} diff --git a/src/qt/Client/src/settings_writer.cpp b/src/qt/Client/src/settings_writer.cpp new file mode 100644 index 00000000..94cbc496 --- /dev/null +++ b/src/qt/Client/src/settings_writer.cpp @@ -0,0 +1,34 @@ +#include "../include/settings_writer.h" +#include +#include +#include +#include +#include + +SettingsWriter::SettingsWriter() +{} + +SettingsWriter::~SettingsWriter() +{} + +void SettingsWriter::SetOutputFile(const char *filename) +{ + output_file.setFileName(filename); +} + +void SettingsWriter::WriteSettings(QMap &settings) +{ + if (not output_file.open(QIODevice::WriteOnly)) { + emit Error(QString("Could not find the settings file!")); + return; + } + + QVariantMap data_to_write; + + data_to_write["remote_ip-address"] = settings["remote_ip-address"]; + data_to_write["remote_port"] = settings["remote_port"]; + data_to_write["nickname"] = settings["nickname"]; + + output_file.write(QJsonDocument(QJsonObject::fromVariantMap(data_to_write)).toJson()); + output_file.close(); +} diff --git a/src/qt/Client/src/socket_client.cpp b/src/qt/Client/src/socket_client.cpp new file mode 100644 index 00000000..ae7ad9c7 --- /dev/null +++ b/src/qt/Client/src/socket_client.cpp @@ -0,0 +1,81 @@ +#include "../include/socket_client.h" + +SocketClient::SocketClient(QObject *parent) + : QObject(parent) + , remote_port {4455} + , remote_address {"127.0.0.1"} +{ + connect(&tcp_sock, &QTcpSocket::connected, this, &SocketClient::on_Connected); + connect(&tcp_sock, &QTcpSocket::disconnected, this, &SocketClient::on_Disconnected); + connect(&tcp_sock, &QTcpSocket::readyRead, this, &SocketClient::on_ReadyRead); + connect(&tcp_sock, QOverload::of(&QAbstractSocket::error), this, &SocketClient::DisplayError); +} + +void SocketClient::setPort(quint16 port) +{ + remote_port = port; +} + +void SocketClient::setAddress(const QString &address) +{ + remote_address = address; +} + +void SocketClient::start() +{ + emit started(); + tcp_sock.connectToHost(remote_address, remote_port); +} + +void SocketClient::stop() +{ + tcp_sock.disconnectFromHost(); +} + +void SocketClient::on_Connected() +{ + emit connected(); + emit outInfo(QString("[%1] You connected with: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) + .arg(remote_address).arg(remote_port)); +} + +void SocketClient::on_Disconnected() +{ + emit disconnected(); + emit outInfo(QString("[%1] You disconnected from: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) + .arg(remote_address).arg(remote_port)); +} + +void SocketClient::on_ReadyRead() +{ + emit outInfo(tcp_sock.readAll()); +} + +void SocketClient::DisplayError(QAbstractSocket::SocketError error_code) +{ + switch (error_code) { + case QAbstractSocket::ConnectionRefusedError: + emit Error(QString("Connection refused with: %1:%2!").arg(remote_address).arg(remote_port)); + break; + case QAbstractSocket::HostNotFoundError: + emit Error(QString("Remote host not found!")); + break; + case QAbstractSocket::RemoteHostClosedError: + emit Error(QString("Remote host is closed!")); + break; + } +} + +void SocketClient::SendToServer(const QString &nickname, const QString &message) +{ + QByteArray data_block; + QDataStream send_stream(&data_block, QIODevice::ReadWrite); + + send_stream.setVersion(QDataStream::Qt_5_14); + + send_stream << quint16(0) << nickname << message.toUtf8(); + send_stream.device()->seek(0); + send_stream << quint16(data_block.size() - sizeof(quint16)); + + tcp_sock.write(data_block); +} diff --git a/src/qt/Server/SocketServer.pro b/src/qt/Server/SocketServer.pro new file mode 100644 index 00000000..3ec4f3ff --- /dev/null +++ b/src/qt/Server/SocketServer.pro @@ -0,0 +1,37 @@ +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +QMAKE_CXXFLAGS += -std=c++17 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + src/main.cpp \ + src/mainwindow.cpp \ + src/server_data_base.cpp \ + src/socket_server.cpp + +HEADERS += \ + include/mainwindow.h \ + include/server_data_base.h \ + include/socket_server.h + +FORMS += \ + forms/mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/src/qt/Server/forms/mainwindow.ui b/src/qt/Server/forms/mainwindow.ui new file mode 100644 index 00000000..076cd2d2 --- /dev/null +++ b/src/qt/Server/forms/mainwindow.ui @@ -0,0 +1,73 @@ + + + MainWindow + + + + 0 + 0 + 508 + 325 + + + + MainWindow + + + + + + + Stop server + + + + + + + Start server + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::ClickFocus + + + true + + + + + + + + + diff --git a/src/qt/Server/include/mainwindow.h b/src/qt/Server/include/mainwindow.h new file mode 100644 index 00000000..ca4c570e --- /dev/null +++ b/src/qt/Server/include/mainwindow.h @@ -0,0 +1,33 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "socket_server.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + // Slots for handling signals from 'SocketServer' class + void on_OutInfo(const QString &message); + void on_Error(const QString &error_message); + + // Buttons slots + void on_pushButtonStartServer_clicked(); + void on_pushButtonStopServer_clicked(); + +private: + Ui::MainWindow *ui; + SocketServer socket_server; + quint16 line_counter; +}; +#endif // MAINWINDOW_H diff --git a/src/qt/Server/include/server_data_base.h b/src/qt/Server/include/server_data_base.h new file mode 100644 index 00000000..5799c91b --- /dev/null +++ b/src/qt/Server/include/server_data_base.h @@ -0,0 +1,26 @@ +#ifndef SERVERDATABASE_H +#define SERVERDATABASE_H + +#include +#include + +class ServerDataBase : public QObject +{ + Q_OBJECT +public: + explicit ServerDataBase(QObject *parent = nullptr); + +public slots: + static bool isExists(QStringView name); + static bool isEmpty(); + static QString getLast(); + static void addClient(QStringView name); + static void deleteLastClient(); + static void deleteClientByName(QStringView name); + static void clear(); + +private: + static QVector clients; +}; + +#endif // SERVERDATABASE_H diff --git a/src/qt/Server/include/socket_server.h b/src/qt/Server/include/socket_server.h new file mode 100644 index 00000000..74dfce7a --- /dev/null +++ b/src/qt/Server/include/socket_server.h @@ -0,0 +1,46 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include +#include +#include +#include +#include +#include + +#include "server_data_base.h" + +class SocketServer : public QObject +{ + Q_OBJECT + +public: + SocketServer(); + void setPort(const quint16 &port); + ~SocketServer(); + +public slots: + void start(); + void stop(); + +private slots: + void on_ClientConnected(); + void on_ClientStateChanged(QAbstractSocket::SocketState state); + void on_ReadyRead(); + +signals: + void addToDataBase(QStringView username); + void OutInfo(const QString &message); + void Error(const QString &error_message); + +private: + quint16 serv_port; + QTcpServer tcp_serv_socket; + QList connectd_clients_list; + + QMap command_handler; + static void time_command_handler(const QByteArray &data, QTcpSocket *client, SocketServer *server_socket); +}; + +#endif // SERVER_H diff --git a/src/qt/Server/src/main.cpp b/src/qt/Server/src/main.cpp new file mode 100644 index 00000000..0f3fe68a --- /dev/null +++ b/src/qt/Server/src/main.cpp @@ -0,0 +1,10 @@ +#include "../include/mainwindow.h" +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + MainWindow main_window; + main_window.show(); + return app.exec(); +} diff --git a/src/qt/Server/src/mainwindow.cpp b/src/qt/Server/src/mainwindow.cpp new file mode 100644 index 00000000..f4dc007a --- /dev/null +++ b/src/qt/Server/src/mainwindow.cpp @@ -0,0 +1,51 @@ +#include "../include/mainwindow.h" +#include "../ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) + , line_counter(0) +{ + ui->setupUi(this); + setWindowTitle("Socket server"); + + connect(&socket_server, &SocketServer::OutInfo, this, &MainWindow::on_OutInfo); + connect(&socket_server, &SocketServer::Error, this, &MainWindow::on_Error); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_OutInfo(const QString &message) +{ + ui->textEditServerOutput->append(message); + line_counter++; +} + +void MainWindow::on_Error(const QString &error_message) +{ + ui->textEditServerOutput->append(error_message); + line_counter++; + + if (line_counter == 450) { + ui->textEditServerOutput->clear(); + } +} + +void MainWindow::on_pushButtonStartServer_clicked() +{ + socket_server.setPort(4455); + socket_server.start(); +} + +void MainWindow::on_pushButtonStopServer_clicked() +{ + socket_server.stop(); + if (QMessageBox::question(this, "Question", "Do you want to close application?", + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + QCoreApplication::quit(); + } +} diff --git a/src/qt/Server/src/server_data_base.cpp b/src/qt/Server/src/server_data_base.cpp new file mode 100644 index 00000000..4f483c5b --- /dev/null +++ b/src/qt/Server/src/server_data_base.cpp @@ -0,0 +1,42 @@ +#include "../include/server_data_base.h" + +QVector ServerDataBase::clients {}; + +ServerDataBase::ServerDataBase(QObject *parent) + : QObject(parent) +{} + +void ServerDataBase::addClient(QStringView name) +{ + clients.append(name.toString()); +} + +void ServerDataBase::deleteLastClient() +{ + clients.removeLast(); +} + +void ServerDataBase::deleteClientByName(QStringView name) +{ + clients.removeOne(name.toString()); +} + +bool ServerDataBase::isExists(QStringView name) +{ + return clients.contains(name.toString()); +} + +bool ServerDataBase::isEmpty() +{ + return clients.isEmpty(); +} + +void ServerDataBase::clear() +{ + clients.clear(); +} + +QString ServerDataBase::getLast() +{ + return clients.last(); +} diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp new file mode 100644 index 00000000..d7c08de8 --- /dev/null +++ b/src/qt/Server/src/socket_server.cpp @@ -0,0 +1,141 @@ +#include "../include/socket_server.h" + +SocketServer::SocketServer() +{ + connect(&tcp_serv_socket, &QTcpServer::newConnection, this, &SocketServer::on_ClientConnected); + + command_handler = { + {{"/time"}, time_command_handler} + }; +} + +SocketServer::~SocketServer() +{ + stop(); +} + +void SocketServer::setPort(const quint16 &port) +{ + serv_port = port; +} + +void SocketServer::start() +{ + if (tcp_serv_socket.listen(QHostAddress::AnyIPv4, serv_port)) { + emit OutInfo(QString("<-- Server running on port: %1 -->").arg(serv_port)); + } + else { + emit Error(QString("<-- Could not start the server: (err=%1) -->").arg(tcp_serv_socket.errorString())); + } +} + +void SocketServer::stop() +{ + for (QTcpSocket *connected_client : connectd_clients_list) { + connected_client->close(); + } + + tcp_serv_socket.close(); + + connectd_clients_list.clear(); + ServerDataBase::clear(); + + emit OutInfo(QString("<-- Server stopped! -->")); +} + +void SocketServer::on_ClientConnected() +{ + QTcpSocket *new_client = tcp_serv_socket.nextPendingConnection(); + + connect(new_client, &QTcpSocket::stateChanged, this, &SocketServer::on_ClientStateChanged); + connect(new_client, &QTcpSocket::readyRead, this, &SocketServer::on_ReadyRead); + + QString new_client_connected_msg = QString("<-- New client connected: (addr=%1) -->").arg(new_client->peerAddress().toString()); + + emit OutInfo(new_client_connected_msg); + + new_client->write("<---- [ >> Welcome to the Socket-Chat! << ] ---->"); + + for (QTcpSocket *connected_client : connectd_clients_list) { + connected_client->write(new_client_connected_msg.toUtf8()); + } + + connectd_clients_list.append(new_client); +} + +void SocketServer::on_ClientStateChanged(QAbstractSocket::SocketState state) +{ + QTcpSocket *client = static_cast(sender()); + + if (state == QAbstractSocket::UnconnectedState) { + QString client_disconnected_msg = QString("<-- Client disconnected: (addr=%1) -->").arg(client->peerAddress().toString()); + + if (not ServerDataBase::isEmpty()) { + ServerDataBase::deleteLastClient(); + } + + connectd_clients_list.removeOne(client); + client->close(); + emit OutInfo(client_disconnected_msg); + + for (QTcpSocket *connected_client : connectd_clients_list) { + connected_client->write(client_disconnected_msg.toUtf8()); + } + } +} + +void SocketServer::on_ReadyRead() +{ + QTcpSocket *client = static_cast(sender()); + + quint16 next_block_size = 0; + QByteArray recived_data; + + QString user_name; + + QDataStream recive_stream(client); + recive_stream.setVersion(QDataStream::Qt_5_14); + + forever { + if (!next_block_size) { + if (client->bytesAvailable() < sizeof(quint16)) { + break; + } + } + recive_stream >> next_block_size; + + if (client->bytesAvailable() < next_block_size) { + break; + } + + recive_stream >> user_name >> recived_data; + next_block_size = 0; + } + + if (not ServerDataBase::isExists(user_name)) { + ServerDataBase::addClient(user_name); + + emit OutInfo(QString("<-- Recived bytes: %1, from: (addr=%2) -->").arg(recived_data.size()).arg(client->peerAddress().toString())); + + for (QTcpSocket *connected_client : connectd_clients_list) { + if (command_handler.contains(recived_data)) { + command_handler[recived_data](QString(user_name + ": " + recived_data).toUtf8(), connected_client, this); + } + else { // default message recived + connected_client->write(QString(user_name + ": " + recived_data).toUtf8()); + } + emit OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); + } + } + else { + client->write(QString("<-- Client with nickanme '%1' already exists! -->").arg(user_name).toUtf8()); + client->close(); + } +} + +void SocketServer::time_command_handler(const QByteArray &data, QTcpSocket *client, SocketServer *server_socket) +{ + client->write(data + "\n"); + client->write("Current date and time: " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss").toUtf8()); + emit server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); +} From f24fc5c64d966a1788c4494ba129dabcb7b85a7d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:42:38 -0400 Subject: [PATCH 0170/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 689b6a87..e386dc6d 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,8 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -/* #include "tradingdialogpage.h" */ -#include "chatwindowpage.h" +/* #include "tradingdialogpage.h" +#include "chatwindowpage.h" */ #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -637,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); + connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -1069,10 +1069,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoChatWindowPage() +void BitcoinGUI::gotoMainWindow() { chatWindowPage->setChecked(true); - if (walletFrame) walletFrame->gotoChatWindowPage(); + if (walletFrame) walletFrame->gotoMainWindow(); } /*void BitcoinGUI::gotoTradingDialogPage() From ab8e9c37acec09d7ab7c5acd0bbd48b86a512a39 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:43:31 -0400 Subject: [PATCH 0171/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index c5912c3b..f2cf1a0e 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class ChatWindowPage; +class ChatWindowPage; class CWallet; @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From c3f14c1820be7b24a527e3a1d81bcbb5b77961b4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:44:03 -0400 Subject: [PATCH 0172/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 035ad36c..a170c85a 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoChatWindowPage() +void WalletFrame::gotoMainWindow() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoChatWindowPage(); + i.value()->gotoMainWindow(); } /*void WalletFrame::gotoTradingDialogPage() From 022bed3eee8f2ff8d2bb278df275381fec176616 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:44:43 -0400 Subject: [PATCH 0173/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 982f6690..2f5fc04f 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 4f4d2caaec42f5dc03c30a2c2f9e049b8c4c12b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:46:13 -0400 Subject: [PATCH 0174/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 47cd79f3..fa1a01eb 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatWindowPage = new ChatWindowPage(); - addWidget(chatWindowPage); + chatMainWindow = new MainWindow(); + addWidget(chatMainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -241,9 +241,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoChatWindowPage() +void WalletView::gotoMainWindow() { - setCurrentWidget(chatWindowPage); + setCurrentWidget(chatMainWindow); } /*void WalletView::gotoTradingDialogPage() From c056b07ebf30228927cb900e1314f00e8e95ee32 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:46:50 -0400 Subject: [PATCH 0175/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 826b8d72..2f4dc810 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -79,7 +79,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - ChatWindowPage *chatWindowPage; + ChatWindowPage *chatMainWindow; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -88,7 +88,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 01543cd784dac9b08a567f4465bc567d53e45bf4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:49:13 -0400 Subject: [PATCH 0176/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index fa1a01eb..0c1bbccf 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,7 +88,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatMainWindow = new MainWindow(); + chatMainWindow = new chatMainWindow(); addWidget(chatMainWindow); QSettings settings; From 17f162d5ba2c6682b019825849a8b5e3adc528f6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:51:01 -0400 Subject: [PATCH 0177/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 0c1bbccf..7b732445 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,7 +88,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatMainWindow = new chatMainWindow(); + chatMainWindow = new ChatMainWindow(); addWidget(chatMainWindow); QSettings settings; From 19e113530214d7ad0f5f1a6e285a56f12eb31295 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:52:53 -0400 Subject: [PATCH 0178/1324] Update walletview.cpp --- src/qt/walletview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7b732445..d0b3fa81 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatMainWindow = new ChatMainWindow(); - addWidget(chatMainWindow); + MainWindow = new MainWindow(); + addWidget(MainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -243,7 +243,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoMainWindow() { - setCurrentWidget(chatMainWindow); + setCurrentWidget(MainWindow); } /*void WalletView::gotoTradingDialogPage() From ec5c4fd88ad188ce85e82e73b3151a468cdc3f00 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:53:54 -0400 Subject: [PATCH 0179/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 2f4dc810..df2e7931 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -27,7 +27,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class ChatWindowPage; +class MainWindow; QT_BEGIN_NAMESPACE @@ -79,7 +79,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - ChatWindowPage *chatMainWindow; + MainWindow *MainWindow; QProgressDialog *progressDialog; QLabel *transactionSum; From 1c7792b2fae0e79520a020539c6fd29721353757 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:55:03 -0400 Subject: [PATCH 0180/1324] Update walletview.h --- src/qt/walletview.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index df2e7931..8fb10ddf 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,6 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" +#include #include From 4588b4ab1f61462ec102bd6518d022e6b1ca6997 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:55:47 -0400 Subject: [PATCH 0181/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 8fb10ddf..52d512f3 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include +#include "qt/client/mainwindow.h" #include From 9b0ae020ca6754cdd2d934db9815f1f9622327a1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:56:08 -0400 Subject: [PATCH 0182/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 52d512f3..49c971ac 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include "qt/client/mainwindow.h" +#include "client/mainwindow.h" #include From 52a0dc247a865aebd59e0c7e8a6375e5b11b4437 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:56:26 -0400 Subject: [PATCH 0183/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 49c971ac..f860c192 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include "client/mainwindow.h" +#include #include From ea5b41e8c5bea35dc0e8264e000084b51d54be4b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:57:20 -0400 Subject: [PATCH 0184/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index f860c192..77e7a32c 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include +#include #include From b8eb025613710f4b2ea00268242f4941fde9994a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:58:18 -0400 Subject: [PATCH 0185/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 77e7a32c..f981ba19 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include +#include #include From b0a899bf33903b936772afb24c0214662a2cabdb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:58:53 -0400 Subject: [PATCH 0186/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index f981ba19..acb89213 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include +#include #include From ddd5199f403eb7a3d550bbf9959fe4dab4a79372 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:59:37 -0400 Subject: [PATCH 0187/1324] Update dialog_settings.h --- src/qt/Client/include/dialog_settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/include/dialog_settings.h b/src/qt/Client/include/dialog_settings.h index b3c5fc5f..942f7a71 100644 --- a/src/qt/Client/include/dialog_settings.h +++ b/src/qt/Client/include/dialog_settings.h @@ -17,7 +17,7 @@ class DialogSettings : public QDialog explicit DialogSettings(QWidget *parent = nullptr); ~DialogSettings(); -private slots: +private Q_SLOTS: // Slot for handling 'Error' signal from the class SettingsReader and SettingsWriter void on_Error(const QString &err_msg); From c08a80ca28086311519130c2c6063f455cee22c6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 19:59:50 -0400 Subject: [PATCH 0188/1324] Update mainwindow.h --- src/qt/Client/include/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/include/mainwindow.h b/src/qt/Client/include/mainwindow.h index a132feb2..7e28fe97 100644 --- a/src/qt/Client/include/mainwindow.h +++ b/src/qt/Client/include/mainwindow.h @@ -19,7 +19,7 @@ class MainWindow : public QMainWindow MainWindow(QWidget *parent = nullptr); ~MainWindow(); -private slots: +private Q_SLOTS: // Slots for handling signals from the class SocketClient void on_OutInfo(const QString &message); void on_Error(const QString &message); From 413e039b384818c1142f840d3a6ce912d91e7b86 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:00:07 -0400 Subject: [PATCH 0189/1324] Update settings_reader.h --- src/qt/Client/include/settings_reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/include/settings_reader.h b/src/qt/Client/include/settings_reader.h index 4de66fd4..59b48d34 100644 --- a/src/qt/Client/include/settings_reader.h +++ b/src/qt/Client/include/settings_reader.h @@ -18,7 +18,7 @@ class SettingsReader : public QObject void LoadFile(const char *filename); QMap ReadAll(); -signals: +Q_SIGNALS: void Error(const QString &err_msg); }; From b636bafda4e840fe80a94f36dd126b676a17e870 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:00:22 -0400 Subject: [PATCH 0190/1324] Update settings_writer.h --- src/qt/Client/include/settings_writer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/include/settings_writer.h b/src/qt/Client/include/settings_writer.h index b8be6190..b9974d14 100644 --- a/src/qt/Client/include/settings_writer.h +++ b/src/qt/Client/include/settings_writer.h @@ -18,7 +18,7 @@ class SettingsWriter : public QObject void SetOutputFile(const char *filename); void WriteSettings(QMap &settings); -signals: +Q_SIGNALS: void Error(const QString &err_msg); }; From 0d63c1827fd4a9e0087ec94b8caa0fa330fd3461 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:00:44 -0400 Subject: [PATCH 0191/1324] Update socket_client.h --- src/qt/Client/include/socket_client.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/Client/include/socket_client.h b/src/qt/Client/include/socket_client.h index c7a3c01a..fba54081 100644 --- a/src/qt/Client/include/socket_client.h +++ b/src/qt/Client/include/socket_client.h @@ -20,17 +20,17 @@ class SocketClient : public QObject void setAddress(const QString &address); void start(); -private slots: +private Q_SLOTS: void on_Connected(); void on_Disconnected(); void on_ReadyRead(); void DisplayError(QAbstractSocket::SocketError error_code); -public slots: +public Q_SLOTS: void SendToServer(const QString &nickname, const QString &message); void stop(); -signals: +Q_SIGNALS: void outInfo(const QString &message); void Error(const QString &message); void started(); From 6c1adb8622f2459529ed057b7d10a68839e4260c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:01:43 -0400 Subject: [PATCH 0192/1324] Update mainwindow.h --- src/qt/Server/include/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/include/mainwindow.h b/src/qt/Server/include/mainwindow.h index ca4c570e..6e9cbdfc 100644 --- a/src/qt/Server/include/mainwindow.h +++ b/src/qt/Server/include/mainwindow.h @@ -16,7 +16,7 @@ class MainWindow : public QMainWindow MainWindow(QWidget *parent = nullptr); ~MainWindow(); -private slots: +private Q_SLOTS: // Slots for handling signals from 'SocketServer' class void on_OutInfo(const QString &message); void on_Error(const QString &error_message); From ae89adb28924d154af552d2f606d3ec392ab85dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:01:52 -0400 Subject: [PATCH 0193/1324] Update server_data_base.h --- src/qt/Server/include/server_data_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/include/server_data_base.h b/src/qt/Server/include/server_data_base.h index 5799c91b..3fe0e49c 100644 --- a/src/qt/Server/include/server_data_base.h +++ b/src/qt/Server/include/server_data_base.h @@ -10,7 +10,7 @@ class ServerDataBase : public QObject public: explicit ServerDataBase(QObject *parent = nullptr); -public slots: +public Q_SLOTS: static bool isExists(QStringView name); static bool isEmpty(); static QString getLast(); From 8268514e0e507c0b837a2ed1c5a4b16e55d4e66e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:02:11 -0400 Subject: [PATCH 0194/1324] Update socket_server.h --- src/qt/Server/include/socket_server.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/Server/include/socket_server.h b/src/qt/Server/include/socket_server.h index 74dfce7a..c83bd7b5 100644 --- a/src/qt/Server/include/socket_server.h +++ b/src/qt/Server/include/socket_server.h @@ -20,16 +20,16 @@ class SocketServer : public QObject void setPort(const quint16 &port); ~SocketServer(); -public slots: +public Q_SLOTS: void start(); void stop(); -private slots: +private Q_SLOTS: void on_ClientConnected(); void on_ClientStateChanged(QAbstractSocket::SocketState state); void on_ReadyRead(); -signals: +Q_SIGNALS: void addToDataBase(QStringView username); void OutInfo(const QString &message); void Error(const QString &error_message); From 2e78ae792a07b1e7f8e405bac5b5433ed7823852 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:03:38 -0400 Subject: [PATCH 0195/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d0b3fa81..d622221b 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,7 +88,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - MainWindow = new MainWindow(); + MainWindow = new mainWindow(); addWidget(MainWindow); QSettings settings; From e6b518b19339a95013eba1c5c09436a4f4813b00 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:05:31 -0400 Subject: [PATCH 0196/1324] Update walletview.cpp --- src/qt/walletview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d622221b..f912151d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - MainWindow = new mainWindow(); - addWidget(MainWindow); + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -243,7 +243,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoMainWindow() { - setCurrentWidget(MainWindow); + setCurrentWidget(mainWindow); } /*void WalletView::gotoTradingDialogPage() From 1e514cfb936ca3c71cd019b0a30d94c96b4b16ac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:06:32 -0400 Subject: [PATCH 0197/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f912151d..5eb3c2e1 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -243,7 +243,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoMainWindow() { - setCurrentWidget(mainWindow); + setCurrentWidget(MainWindow); } /*void WalletView::gotoTradingDialogPage() From 474211d9a0b71c806439f39c090ad9ec6275e743 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:07:01 -0400 Subject: [PATCH 0198/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 5eb3c2e1..4181370a 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,7 +88,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - mainWindow = new MainWindow(); + MainWindow = new MainWindow(); addWidget(mainWindow); QSettings settings; From bce0c4e45581ab7b1fae72d92ca74943e7505bb1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:07:23 -0400 Subject: [PATCH 0199/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 4181370a..d0b3fa81 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -89,7 +89,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(tradingDialogPage); */ MainWindow = new MainWindow(); - addWidget(mainWindow); + addWidget(MainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { From e144a286ba3b6595601e5ef5dbc7d0e39e9b08ab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:08:28 -0400 Subject: [PATCH 0200/1324] Update walletview.cpp --- src/qt/walletview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d0b3fa81..6520cd83 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,6 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" +#include #include "ui_interface.h" From 8c2d3e28481f2835bb672e4797d24ddb9f12f2d8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:10:09 -0400 Subject: [PATCH 0201/1324] Update walletview.cpp --- src/qt/walletview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 6520cd83..543a011e 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -89,8 +89,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - MainWindow = new MainWindow(); - addWidget(MainWindow); + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -244,7 +244,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoMainWindow() { - setCurrentWidget(MainWindow); + setCurrentWidget(mainWindow); } /*void WalletView::gotoTradingDialogPage() From 0e2ef839ffc656b8cbf8f780d3ea8171b49ffe88 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:10:29 -0400 Subject: [PATCH 0202/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index acb89213..eb16a182 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - MainWindow *MainWindow; + MainWindow *mainWindow; QProgressDialog *progressDialog; QLabel *transactionSum; From 2cd1f41450e1881f556f44d87a7164d6fd1691e8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:12:27 -0400 Subject: [PATCH 0203/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e386dc6d..936f671e 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -24,6 +24,7 @@ #include "utilitydialog.h" /* #include "tradingdialogpage.h" #include "chatwindowpage.h" */ +#include #ifdef ENABLE_WALLET #include "privatesend-client.h" From e58a5e5d7b11b49b63375f1a77671410967ed3c4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:23:46 -0400 Subject: [PATCH 0204/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index ed1dcd19..e7947033 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -54,7 +54,10 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui + qt/forms/transactiondescdialog.ui \ + qt/Client/forms/dialog_settings.ui \ + qt/Client/forms/mainwindow.ui \ + qt/Server/forms/mainwindow.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -194,7 +197,16 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h + qt/winshutdownmonitor.h \ + qt/Client/include/dialog_settings.h \ + qt/Client/include/mainwindow.h \ + qt/Client/include/settings_reader.h \ + qt/Client/include/settings_writer.h \ + qt/Client/include/socket_client.h \ + qt/Server/include/mainwindow.h \ + qt/Server/include/server_data_base.h \ + qt/Server/include/socket_server.h + RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -537,7 +549,17 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp + qt/walletview.cpp \ + qt/Client/src/dialog_settings.cpp \ + qt/Client/src/main.cpp \ + qt/Client/src/mainwindow.cpp \ + qt/Client/src/settings_reader.cpp \ + qt/Client/src/settings_writer.cpp \ + qt/Client/src/socket_client.cpp \ + qt/Server/src/main.cpp \ + qt/Server/src/mainwindow.cpp \ + qt/Server/src/server_data_base.cpp \ + qt/Server/src/socket_server.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 0d7a646600ba1a357d58036612ff666351ff3c5d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:26:34 -0400 Subject: [PATCH 0205/1324] Update settings_reader.cpp --- src/qt/Client/src/settings_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/settings_reader.cpp b/src/qt/Client/src/settings_reader.cpp index 6fd12943..45c9a905 100644 --- a/src/qt/Client/src/settings_reader.cpp +++ b/src/qt/Client/src/settings_reader.cpp @@ -19,7 +19,7 @@ QMap SettingsReader::ReadAll() { QMap settings; if (not input_file.open(QIODevice::ReadOnly)) { - emit Error(QString("Could not find the settings file!")); + Q_EMIT Error(QString("Could not find the settings file!")); return settings; } From 94bd7a050d5282659ddef84586ea2bd4f7930aa9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:26:48 -0400 Subject: [PATCH 0206/1324] Update settings_writer.cpp --- src/qt/Client/src/settings_writer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/settings_writer.cpp b/src/qt/Client/src/settings_writer.cpp index 94cbc496..055d2b03 100644 --- a/src/qt/Client/src/settings_writer.cpp +++ b/src/qt/Client/src/settings_writer.cpp @@ -19,7 +19,7 @@ void SettingsWriter::SetOutputFile(const char *filename) void SettingsWriter::WriteSettings(QMap &settings) { if (not output_file.open(QIODevice::WriteOnly)) { - emit Error(QString("Could not find the settings file!")); + Q_EMIT Error(QString("Could not find the settings file!")); return; } From 0b9b8e828c8f49eed0c8ff6d9926fba0def195ff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:27:44 -0400 Subject: [PATCH 0207/1324] Update socket_client.cpp --- src/qt/Client/src/socket_client.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/Client/src/socket_client.cpp b/src/qt/Client/src/socket_client.cpp index ae7ad9c7..1e0abea2 100644 --- a/src/qt/Client/src/socket_client.cpp +++ b/src/qt/Client/src/socket_client.cpp @@ -23,7 +23,7 @@ void SocketClient::setAddress(const QString &address) void SocketClient::start() { - emit started(); + Q_EMIT started(); tcp_sock.connectToHost(remote_address, remote_port); } @@ -34,34 +34,34 @@ void SocketClient::stop() void SocketClient::on_Connected() { - emit connected(); - emit outInfo(QString("[%1] You connected with: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) + Q_EMIT connected(); + Q_EMIT outInfo(QString("[%1] You connected with: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) .arg(remote_address).arg(remote_port)); } void SocketClient::on_Disconnected() { - emit disconnected(); - emit outInfo(QString("[%1] You disconnected from: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) + Q_EMIT disconnected(); + Q_EMIT outInfo(QString("[%1] You disconnected from: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) .arg(remote_address).arg(remote_port)); } void SocketClient::on_ReadyRead() { - emit outInfo(tcp_sock.readAll()); + Q_EMIT outInfo(tcp_sock.readAll()); } void SocketClient::DisplayError(QAbstractSocket::SocketError error_code) { switch (error_code) { case QAbstractSocket::ConnectionRefusedError: - emit Error(QString("Connection refused with: %1:%2!").arg(remote_address).arg(remote_port)); + Q_EMIT Error(QString("Connection refused with: %1:%2!").arg(remote_address).arg(remote_port)); break; case QAbstractSocket::HostNotFoundError: - emit Error(QString("Remote host not found!")); + Q_EMIT Error(QString("Remote host not found!")); break; case QAbstractSocket::RemoteHostClosedError: - emit Error(QString("Remote host is closed!")); + Q_EMIT Error(QString("Remote host is closed!")); break; } } From 98cca62319e657f00a67d38ebf6ff5cbae9e8010 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:29:33 -0400 Subject: [PATCH 0208/1324] Update dialog_settings.cpp --- src/qt/Client/src/dialog_settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/Client/src/dialog_settings.cpp b/src/qt/Client/src/dialog_settings.cpp index 29c05ab9..83f508e0 100644 --- a/src/qt/Client/src/dialog_settings.cpp +++ b/src/qt/Client/src/dialog_settings.cpp @@ -1,5 +1,5 @@ -#include "../include/dialog_settings.h" -#include "../ui_dialog_settings.h" +#include "../qt/Client/include/dialog_settings.h" +#include "../qt/Client/ui_dialog_settings.h" #include static constexpr const char *settings_filename = "settings.json"; From d408eca8752673e224aa96ac5f9dc95be6acda65 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:30:04 -0400 Subject: [PATCH 0209/1324] Update mainwindow.cpp --- src/qt/Client/src/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/Client/src/mainwindow.cpp b/src/qt/Client/src/mainwindow.cpp index 66d0728e..04f86b86 100644 --- a/src/qt/Client/src/mainwindow.cpp +++ b/src/qt/Client/src/mainwindow.cpp @@ -1,8 +1,8 @@ -#include "../include/mainwindow.h" -#include "../ui_mainwindow.h" +#include "../qt/Client/include/mainwindow.h" +#include "../qt/Client/ui_mainwindow.h" /* Including other forms */ -#include "../include/dialog_settings.h" // DialogSettings class (form with a connection settings) +#include "../qt/Client/include/dialog_settings.h" // DialogSettings class (form with a connection settings) #include From b658f8f789a3ef4df2f44c84b518a91d4a59a264 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:30:41 -0400 Subject: [PATCH 0210/1324] Update mainwindow.cpp --- src/qt/Server/src/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/Server/src/mainwindow.cpp b/src/qt/Server/src/mainwindow.cpp index f4dc007a..393668c8 100644 --- a/src/qt/Server/src/mainwindow.cpp +++ b/src/qt/Server/src/mainwindow.cpp @@ -1,5 +1,5 @@ -#include "../include/mainwindow.h" -#include "../ui_mainwindow.h" +#include "../qt/Server/include/mainwindow.h" +#include "../qt/Server/ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) From c2aa4adf9d083d5cad626c208aadffcea57779f8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:30:52 -0400 Subject: [PATCH 0211/1324] Update server_data_base.cpp --- src/qt/Server/src/server_data_base.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/server_data_base.cpp b/src/qt/Server/src/server_data_base.cpp index 4f483c5b..8de1b6cb 100644 --- a/src/qt/Server/src/server_data_base.cpp +++ b/src/qt/Server/src/server_data_base.cpp @@ -1,4 +1,4 @@ -#include "../include/server_data_base.h" +#include "../qt/Server/include/server_data_base.h" QVector ServerDataBase::clients {}; From 453392a414fad96f02f7bbfa8657127f9afe7d01 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:31:03 -0400 Subject: [PATCH 0212/1324] Update socket_server.cpp --- src/qt/Server/src/socket_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp index d7c08de8..e620f9bd 100644 --- a/src/qt/Server/src/socket_server.cpp +++ b/src/qt/Server/src/socket_server.cpp @@ -1,4 +1,4 @@ -#include "../include/socket_server.h" +#include "../qt/Server/include/socket_server.h" SocketServer::SocketServer() { From 00b2ab901dfa9a970b2dbf421be495f792c15aad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:31:15 -0400 Subject: [PATCH 0213/1324] Update main.cpp --- src/qt/Server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/main.cpp b/src/qt/Server/src/main.cpp index 0f3fe68a..08418520 100644 --- a/src/qt/Server/src/main.cpp +++ b/src/qt/Server/src/main.cpp @@ -1,4 +1,4 @@ -#include "../include/mainwindow.h" +#include "../qt/Server/include/mainwindow.h" #include int main(int argc, char **argv) From 74d866f861e1ba7037f4b3afd6cd6b89bbac9c89 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:31:33 -0400 Subject: [PATCH 0214/1324] Update main.cpp --- src/qt/Client/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/main.cpp b/src/qt/Client/src/main.cpp index 0f3fe68a..53ef6077 100644 --- a/src/qt/Client/src/main.cpp +++ b/src/qt/Client/src/main.cpp @@ -1,4 +1,4 @@ -#include "../include/mainwindow.h" +#include "../qt/Client/include/mainwindow.h" #include int main(int argc, char **argv) From 11cccf6970c47756be659352365971d92d46f86b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:32:18 -0400 Subject: [PATCH 0215/1324] Update dialog_settings.cpp --- src/qt/Client/src/dialog_settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/Client/src/dialog_settings.cpp b/src/qt/Client/src/dialog_settings.cpp index 83f508e0..013f131f 100644 --- a/src/qt/Client/src/dialog_settings.cpp +++ b/src/qt/Client/src/dialog_settings.cpp @@ -1,5 +1,5 @@ -#include "../qt/Client/include/dialog_settings.h" -#include "../qt/Client/ui_dialog_settings.h" +#include "../Client/include/dialog_settings.h" +#include "../Client/ui_dialog_settings.h" #include static constexpr const char *settings_filename = "settings.json"; From 01180c6b3a8b7b7bd8ed099bef070d6719b0148d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:32:29 -0400 Subject: [PATCH 0216/1324] Update main.cpp --- src/qt/Client/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/main.cpp b/src/qt/Client/src/main.cpp index 53ef6077..13b5b986 100644 --- a/src/qt/Client/src/main.cpp +++ b/src/qt/Client/src/main.cpp @@ -1,4 +1,4 @@ -#include "../qt/Client/include/mainwindow.h" +#include "../Client/include/mainwindow.h" #include int main(int argc, char **argv) From 12185af8564969c0ce5ac89a5a7ad87e9f15ef43 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:32:44 -0400 Subject: [PATCH 0217/1324] Update mainwindow.cpp --- src/qt/Client/src/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/Client/src/mainwindow.cpp b/src/qt/Client/src/mainwindow.cpp index 04f86b86..2c4fa17a 100644 --- a/src/qt/Client/src/mainwindow.cpp +++ b/src/qt/Client/src/mainwindow.cpp @@ -1,8 +1,8 @@ -#include "../qt/Client/include/mainwindow.h" -#include "../qt/Client/ui_mainwindow.h" +#include "../Client/include/mainwindow.h" +#include "../Client/ui_mainwindow.h" /* Including other forms */ -#include "../qt/Client/include/dialog_settings.h" // DialogSettings class (form with a connection settings) +#include "../Client/include/dialog_settings.h" // DialogSettings class (form with a connection settings) #include From 15bd77ebc4802143bb189b580b5a7e75cc62f836 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:47:16 -0400 Subject: [PATCH 0218/1324] Update socket_server.cpp --- src/qt/Server/src/socket_server.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp index e620f9bd..9f55b8a7 100644 --- a/src/qt/Server/src/socket_server.cpp +++ b/src/qt/Server/src/socket_server.cpp @@ -22,10 +22,10 @@ void SocketServer::setPort(const quint16 &port) void SocketServer::start() { if (tcp_serv_socket.listen(QHostAddress::AnyIPv4, serv_port)) { - emit OutInfo(QString("<-- Server running on port: %1 -->").arg(serv_port)); + Q_EMIT OutInfo(QString("<-- Server running on port: %1 -->").arg(serv_port)); } else { - emit Error(QString("<-- Could not start the server: (err=%1) -->").arg(tcp_serv_socket.errorString())); + Q_EMIT Error(QString("<-- Could not start the server: (err=%1) -->").arg(tcp_serv_socket.errorString())); } } @@ -40,7 +40,7 @@ void SocketServer::stop() connectd_clients_list.clear(); ServerDataBase::clear(); - emit OutInfo(QString("<-- Server stopped! -->")); + Q_EMIT OutInfo(QString("<-- Server stopped! -->")); } void SocketServer::on_ClientConnected() @@ -52,7 +52,7 @@ void SocketServer::on_ClientConnected() QString new_client_connected_msg = QString("<-- New client connected: (addr=%1) -->").arg(new_client->peerAddress().toString()); - emit OutInfo(new_client_connected_msg); + Q_EMIT OutInfo(new_client_connected_msg); new_client->write("<---- [ >> Welcome to the Socket-Chat! << ] ---->"); @@ -76,7 +76,7 @@ void SocketServer::on_ClientStateChanged(QAbstractSocket::SocketState state) connectd_clients_list.removeOne(client); client->close(); - emit OutInfo(client_disconnected_msg); + Q_EMIT OutInfo(client_disconnected_msg); for (QTcpSocket *connected_client : connectd_clients_list) { connected_client->write(client_disconnected_msg.toUtf8()); @@ -115,7 +115,7 @@ void SocketServer::on_ReadyRead() if (not ServerDataBase::isExists(user_name)) { ServerDataBase::addClient(user_name); - emit OutInfo(QString("<-- Recived bytes: %1, from: (addr=%2) -->").arg(recived_data.size()).arg(client->peerAddress().toString())); + Q_EMIT OutInfo(QString("<-- Recived bytes: %1, from: (addr=%2) -->").arg(recived_data.size()).arg(client->peerAddress().toString())); for (QTcpSocket *connected_client : connectd_clients_list) { if (command_handler.contains(recived_data)) { @@ -124,7 +124,7 @@ void SocketServer::on_ReadyRead() else { // default message recived connected_client->write(QString(user_name + ": " + recived_data).toUtf8()); } - emit OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); + V OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); } } else { @@ -137,5 +137,5 @@ void SocketServer::time_command_handler(const QByteArray &data, QTcpSocket *clie { client->write(data + "\n"); client->write("Current date and time: " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss").toUtf8()); - emit server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); + V server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); } From e64aa5327d2a4c3fc15abf0ebdce452e1f939c78 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:48:38 -0400 Subject: [PATCH 0219/1324] Update socket_server.cpp --- src/qt/Server/src/socket_server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp index 9f55b8a7..58e51e10 100644 --- a/src/qt/Server/src/socket_server.cpp +++ b/src/qt/Server/src/socket_server.cpp @@ -124,7 +124,7 @@ void SocketServer::on_ReadyRead() else { // default message recived connected_client->write(QString(user_name + ": " + recived_data).toUtf8()); } - V OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); + Q_EMIT OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); } } else { @@ -137,5 +137,5 @@ void SocketServer::time_command_handler(const QByteArray &data, QTcpSocket *clie { client->write(data + "\n"); client->write("Current date and time: " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss").toUtf8()); - V server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); + Q_EMIT server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); } From 2db3c718ba7b5775e401b0df97f3da7eff9c0409 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:49:46 -0400 Subject: [PATCH 0220/1324] Update mainwindow.cpp --- src/qt/Server/src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/mainwindow.cpp b/src/qt/Server/src/mainwindow.cpp index 393668c8..ccd67380 100644 --- a/src/qt/Server/src/mainwindow.cpp +++ b/src/qt/Server/src/mainwindow.cpp @@ -1,5 +1,5 @@ #include "../qt/Server/include/mainwindow.h" -#include "../qt/Server/ui_mainwindow.h" +#include "../qt/Server/forms/ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) From 5abad1cd09bc7b23c03b1c0ab9e368e32c0dc35d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:50:06 -0400 Subject: [PATCH 0221/1324] Update dialog_settings.cpp --- src/qt/Client/src/dialog_settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/dialog_settings.cpp b/src/qt/Client/src/dialog_settings.cpp index 013f131f..3417b933 100644 --- a/src/qt/Client/src/dialog_settings.cpp +++ b/src/qt/Client/src/dialog_settings.cpp @@ -1,5 +1,5 @@ #include "../Client/include/dialog_settings.h" -#include "../Client/ui_dialog_settings.h" +#include "../Client/forms/ui_dialog_settings.h" #include static constexpr const char *settings_filename = "settings.json"; From 7f0010cd41aa43def949a51e2462cdaa4f7922cd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:50:19 -0400 Subject: [PATCH 0222/1324] Update mainwindow.cpp --- src/qt/Client/src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/mainwindow.cpp b/src/qt/Client/src/mainwindow.cpp index 2c4fa17a..ae3d2991 100644 --- a/src/qt/Client/src/mainwindow.cpp +++ b/src/qt/Client/src/mainwindow.cpp @@ -1,5 +1,5 @@ #include "../Client/include/mainwindow.h" -#include "../Client/ui_mainwindow.h" +#include "../Client/forms/ui_mainwindow.h" /* Including other forms */ #include "../Client/include/dialog_settings.h" // DialogSettings class (form with a connection settings) From dba324a806183634b6bf7fa8fe09220528621416 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:55:01 -0400 Subject: [PATCH 0223/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index ae8b96bf..ea25903f 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -22,7 +22,9 @@ FORMS += \ RESOURCES += \ ../src/qt/dash.qrc -CONFIG += c++11 +CONFIG += c++17 + +QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ From 0d4b791be5170c99fc2dc9aafa2028109c4357ad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:56:11 -0400 Subject: [PATCH 0224/1324] Update server_data_base.h --- src/qt/Server/include/server_data_base.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/Server/include/server_data_base.h b/src/qt/Server/include/server_data_base.h index 3fe0e49c..37633b66 100644 --- a/src/qt/Server/include/server_data_base.h +++ b/src/qt/Server/include/server_data_base.h @@ -3,6 +3,7 @@ #include #include +#include class ServerDataBase : public QObject { From fe0e72886d2f5c0403ec541dc99376a27fe96938 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:56:49 -0400 Subject: [PATCH 0225/1324] Update server_data_base.h --- src/qt/Server/include/server_data_base.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/Server/include/server_data_base.h b/src/qt/Server/include/server_data_base.h index 37633b66..3fe0e49c 100644 --- a/src/qt/Server/include/server_data_base.h +++ b/src/qt/Server/include/server_data_base.h @@ -3,7 +3,6 @@ #include #include -#include class ServerDataBase : public QObject { From 1ce1d867fc4d24cc1e0a5f2414dfdd964f64afda Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:58:09 -0400 Subject: [PATCH 0226/1324] Update socket_server.cpp --- src/qt/Server/src/socket_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp index 58e51e10..41d792fd 100644 --- a/src/qt/Server/src/socket_server.cpp +++ b/src/qt/Server/src/socket_server.cpp @@ -94,7 +94,7 @@ void SocketServer::on_ReadyRead() QString user_name; QDataStream recive_stream(client); - recive_stream.setVersion(QDataStream::Qt_5_14); + recive_stream.setVersion(QDataStream::Qt_5_7_1); forever { if (!next_block_size) { From 0a944417bbdebd34e47cad983b663cbf42f293dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:00:29 -0400 Subject: [PATCH 0227/1324] Update socket_server.cpp --- src/qt/Server/src/socket_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp index 41d792fd..67def303 100644 --- a/src/qt/Server/src/socket_server.cpp +++ b/src/qt/Server/src/socket_server.cpp @@ -96,7 +96,7 @@ void SocketServer::on_ReadyRead() QDataStream recive_stream(client); recive_stream.setVersion(QDataStream::Qt_5_7_1); - forever { + Q_FOREVER { if (!next_block_size) { if (client->bytesAvailable() < sizeof(quint16)) { break; From afd63b6ed06fff014743aea0bdee7c596eb1d63e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:01:53 -0400 Subject: [PATCH 0228/1324] Update socket_client.cpp --- src/qt/Client/src/socket_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Client/src/socket_client.cpp b/src/qt/Client/src/socket_client.cpp index 1e0abea2..b935019e 100644 --- a/src/qt/Client/src/socket_client.cpp +++ b/src/qt/Client/src/socket_client.cpp @@ -71,7 +71,7 @@ void SocketClient::SendToServer(const QString &nickname, const QString &message) QByteArray data_block; QDataStream send_stream(&data_block, QIODevice::ReadWrite); - send_stream.setVersion(QDataStream::Qt_5_14); + send_stream.setVersion(QDataStream::Qt_5_7_1); send_stream << quint16(0) << nickname << message.toUtf8(); send_stream.device()->seek(0); From f966e5134f0057f0710d6df382d201a05acb8967 Mon Sep 17 00:00:00 2001 From: Devilking6105 Date: Mon, 8 Jun 2020 21:03:49 -0400 Subject: [PATCH 0229/1324] Revert QT --- libhelpthehomelessconsensus.pc | 3 +- src/qt/Client/SocketClient.pro | 42 ------- src/qt/Client/forms/dialog_settings.ui | 73 ------------ src/qt/Client/forms/mainwindow.ui | 115 ------------------ src/qt/Client/include/dialog_settings.h | 34 ------ src/qt/Client/include/mainwindow.h | 47 -------- src/qt/Client/include/settings_reader.h | 25 ---- src/qt/Client/include/settings_writer.h | 25 ---- src/qt/Client/include/socket_client.h | 41 ------- src/qt/Client/settings.json | 5 - src/qt/Client/src/dialog_settings.cpp | 64 ---------- src/qt/Client/src/main.cpp | 10 -- src/qt/Client/src/mainwindow.cpp | 130 --------------------- src/qt/Client/src/settings_reader.cpp | 36 ------ src/qt/Client/src/settings_writer.cpp | 34 ------ src/qt/Client/src/socket_client.cpp | 81 ------------- src/qt/Server/SocketServer.pro | 37 ------ src/qt/Server/forms/mainwindow.ui | 73 ------------ src/qt/Server/include/mainwindow.h | 33 ------ src/qt/Server/include/server_data_base.h | 26 ----- src/qt/Server/include/socket_server.h | 46 -------- src/qt/Server/src/main.cpp | 10 -- src/qt/Server/src/mainwindow.cpp | 51 -------- src/qt/Server/src/server_data_base.cpp | 42 ------- src/qt/Server/src/socket_server.cpp | 141 ----------------------- 25 files changed, 1 insertion(+), 1223 deletions(-) delete mode 100644 src/qt/Client/SocketClient.pro delete mode 100644 src/qt/Client/forms/dialog_settings.ui delete mode 100644 src/qt/Client/forms/mainwindow.ui delete mode 100644 src/qt/Client/include/dialog_settings.h delete mode 100644 src/qt/Client/include/mainwindow.h delete mode 100644 src/qt/Client/include/settings_reader.h delete mode 100644 src/qt/Client/include/settings_writer.h delete mode 100644 src/qt/Client/include/socket_client.h delete mode 100644 src/qt/Client/settings.json delete mode 100644 src/qt/Client/src/dialog_settings.cpp delete mode 100644 src/qt/Client/src/main.cpp delete mode 100644 src/qt/Client/src/mainwindow.cpp delete mode 100644 src/qt/Client/src/settings_reader.cpp delete mode 100644 src/qt/Client/src/settings_writer.cpp delete mode 100644 src/qt/Client/src/socket_client.cpp delete mode 100644 src/qt/Server/SocketServer.pro delete mode 100644 src/qt/Server/forms/mainwindow.ui delete mode 100644 src/qt/Server/include/mainwindow.h delete mode 100644 src/qt/Server/include/server_data_base.h delete mode 100644 src/qt/Server/include/socket_server.h delete mode 100644 src/qt/Server/src/main.cpp delete mode 100644 src/qt/Server/src/mainwindow.cpp delete mode 100644 src/qt/Server/src/server_data_base.cpp delete mode 100644 src/qt/Server/src/socket_server.cpp diff --git a/libhelpthehomelessconsensus.pc b/libhelpthehomelessconsensus.pc index 2ec97458..7e4da774 100644 --- a/libhelpthehomelessconsensus.pc +++ b/libhelpthehomelessconsensus.pc @@ -1,5 +1,4 @@ -prefix=/home/devilking6105/Help-The-Homeless-Coin-0.14/depends/x86_64-w64-mingw32 - +prefix=/home/devilking6105/HTHTest/depends/x86_64-w64-mingw32 exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include diff --git a/src/qt/Client/SocketClient.pro b/src/qt/Client/SocketClient.pro deleted file mode 100644 index 5d4764ba..00000000 --- a/src/qt/Client/SocketClient.pro +++ /dev/null @@ -1,42 +0,0 @@ -QT += core gui network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++17 - -QMAKE_CXXFLAGS += -std=c++17 - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - src/dialog_settings.cpp \ - src/main.cpp \ - src/mainwindow.cpp \ - src/settings_reader.cpp \ - src/settings_writer.cpp \ - src/socket_client.cpp - -HEADERS += \ - include/dialog_settings.h \ - include/mainwindow.h \ - include/settings_reader.h \ - include/settings_writer.h \ - include/socket_client.h - -FORMS += \ - forms/dialog_settings.ui \ - forms/mainwindow.ui - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target diff --git a/src/qt/Client/forms/dialog_settings.ui b/src/qt/Client/forms/dialog_settings.ui deleted file mode 100644 index 29b6c025..00000000 --- a/src/qt/Client/forms/dialog_settings.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - DialogSettings - - - - 0 - 0 - 229 - 138 - - - - Dialog - - - - - - - - Remote ip-address - - - - - - - - - - - - - 192.168.3.1 - - - - - - - Remote port - - - - - - - Nickname - - - - - - - - - Save settings - - - - - - - Cancel - - - - - - - - diff --git a/src/qt/Client/forms/mainwindow.ui b/src/qt/Client/forms/mainwindow.ui deleted file mode 100644 index 84579ff8..00000000 --- a/src/qt/Client/forms/mainwindow.ui +++ /dev/null @@ -1,115 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 558 - 380 - - - - Socket Client - - - - - - - true - - - Clear - - - - - - - false - - - - - - - true - - - Qt::NoFocus - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"><br /></p></body></html> - - - - - - - false - - - Send - - - - - - - false - - - Disconnect - - - false - - - false - - - - - - - Connect - - - - - - - - - 0 - 0 - 558 - 21 - - - - - Menu - - - - - - - - Settings - - - - - - diff --git a/src/qt/Client/include/dialog_settings.h b/src/qt/Client/include/dialog_settings.h deleted file mode 100644 index 942f7a71..00000000 --- a/src/qt/Client/include/dialog_settings.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DIALOG_SETTINGS_H -#define DIALOG_SETTINGS_H - -#include - -/* Including other modules */ -#include "settings_reader.h" // class SettingsReader (for reading settings) -#include "settings_writer.h" // class SettingsWriter (for writting settings) - -namespace Ui { class DialogSettings; } - -class DialogSettings : public QDialog -{ - Q_OBJECT - -public: - explicit DialogSettings(QWidget *parent = nullptr); - ~DialogSettings(); - -private Q_SLOTS: - // Slot for handling 'Error' signal from the class SettingsReader and SettingsWriter - void on_Error(const QString &err_msg); - - // Buttons slots - void on_pushButtonSaveSettings_clicked(); - void on_pushButtonCancel_clicked(); - -private: - Ui::DialogSettings *ui; - SettingsWriter settings_writer; - SettingsReader settings_reader; -}; - -#endif // DIALOG_SETTINGS_H diff --git a/src/qt/Client/include/mainwindow.h b/src/qt/Client/include/mainwindow.h deleted file mode 100644 index 7e28fe97..00000000 --- a/src/qt/Client/include/mainwindow.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -/* Including other modules */ -#include "socket_client.h" // class SocketClient (the base class of a client side) -#include "settings_reader.h" // class SettingsReader (for reading settings) - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - -private Q_SLOTS: - // Slots for handling signals from the class SocketClient - void on_OutInfo(const QString &message); - void on_Error(const QString &message); - void on_Connected(); - void on_Disconnected(); - - // Buttons slots - void on_pushButtonConnectToServer_clicked(); - void on_pushButtonSendMessage_clicked(); - void on_pushButtonClearOutput_clicked(); - void on_pushButtonDisconnectFromServer_clicked(); - - // Menu bar actions (slots) - void on_actionSettings_triggered(); - -private: - Ui::MainWindow *ui; - SocketClient socket_client; - SettingsReader settings_reader; - QString remote_address; - quint16 remote_port; - QString nickname; -}; - -#endif // MAINWINDOW_H diff --git a/src/qt/Client/include/settings_reader.h b/src/qt/Client/include/settings_reader.h deleted file mode 100644 index 59b48d34..00000000 --- a/src/qt/Client/include/settings_reader.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SETTINGSREADER_H -#define SETTINGSREADER_H - -#include -#include -#include - -class SettingsReader : public QObject -{ - Q_OBJECT - -private: - QFile input_file; - -public: - SettingsReader(); - ~SettingsReader(); - void LoadFile(const char *filename); - QMap ReadAll(); - -Q_SIGNALS: - void Error(const QString &err_msg); -}; - -#endif // SETTINGSREADER_H diff --git a/src/qt/Client/include/settings_writer.h b/src/qt/Client/include/settings_writer.h deleted file mode 100644 index b9974d14..00000000 --- a/src/qt/Client/include/settings_writer.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SETTINGSWRITER_H -#define SETTINGSWRITER_H - -#include -#include -#include - -class SettingsWriter : public QObject -{ - Q_OBJECT - -private: - QFile output_file; - -public: - SettingsWriter(); - ~SettingsWriter(); - void SetOutputFile(const char *filename); - void WriteSettings(QMap &settings); - -Q_SIGNALS: - void Error(const QString &err_msg); -}; - -#endif // SETTINGSWRITER_H diff --git a/src/qt/Client/include/socket_client.h b/src/qt/Client/include/socket_client.h deleted file mode 100644 index fba54081..00000000 --- a/src/qt/Client/include/socket_client.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef SOCKETCLIENT_H -#define SOCKETCLIENT_H - -#include -#include -#include -#include - -class SocketClient : public QObject -{ - Q_OBJECT -private: - quint16 remote_port; - QString remote_address; - QTcpSocket tcp_sock; - -public: - explicit SocketClient(QObject *parent = nullptr); - void setPort(quint16 port); - void setAddress(const QString &address); - void start(); - -private Q_SLOTS: - void on_Connected(); - void on_Disconnected(); - void on_ReadyRead(); - void DisplayError(QAbstractSocket::SocketError error_code); - -public Q_SLOTS: - void SendToServer(const QString &nickname, const QString &message); - void stop(); - -Q_SIGNALS: - void outInfo(const QString &message); - void Error(const QString &message); - void started(); - void connected(); - void disconnected(); -}; - -#endif // SOCKETCLIENT_H diff --git a/src/qt/Client/settings.json b/src/qt/Client/settings.json deleted file mode 100644 index acbe1620..00000000 --- a/src/qt/Client/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "remote_ip-address": "127.0.0.1", - "remote_port": "4455", - "nickname": "[Creator] AlexCr4ckPentest" -} \ No newline at end of file diff --git a/src/qt/Client/src/dialog_settings.cpp b/src/qt/Client/src/dialog_settings.cpp deleted file mode 100644 index 3417b933..00000000 --- a/src/qt/Client/src/dialog_settings.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "../Client/include/dialog_settings.h" -#include "../Client/forms/ui_dialog_settings.h" -#include - -static constexpr const char *settings_filename = "settings.json"; - -DialogSettings::DialogSettings(QWidget *parent) - : QDialog(parent) - , ui(new Ui::DialogSettings) -{ - ui->setupUi(this); - connect(&settings_writer, &SettingsWriter::Error, this, &DialogSettings::on_Error); - connect(&settings_reader, &SettingsReader::Error, this, &DialogSettings::on_Error); - - settings_reader.LoadFile(settings_filename); - - const auto settings_to_restore = settings_reader.ReadAll(); - ui->lineEditRemoteIpAddress->setText(settings_to_restore["remote_ip-address"]); - ui->lineEditRemotePort->setText(settings_to_restore["remote_port"]); - ui->lineEditNickname->setText(settings_to_restore["nickname"]); -} - -DialogSettings::~DialogSettings() -{ - delete ui; -} - -void DialogSettings::on_Error(const QString &err_msg) -{ - QMessageBox::critical(this, "Error!", err_msg); -} - -void DialogSettings::on_pushButtonSaveSettings_clicked() -{ - QMap settings; - - QString remote_address = ui->lineEditRemoteIpAddress->text(); - QString remote_port = ui->lineEditRemotePort->text(); - QString nickname = ui->lineEditNickname->text(); - - if (remote_address.isEmpty()) { - remote_address = "127.0.0.1"; - } - else if (remote_port.isEmpty()) { - remote_port = "4455"; - } - else if (nickname.isEmpty()) { - nickname = "Chat_user"; - } - - settings["remote_ip-address"] = remote_address; - settings["remote_port"] = remote_port; - settings["nickname"] = nickname; - - settings_writer.SetOutputFile(settings_filename); - settings_writer.WriteSettings(settings); - - QMessageBox::information(this, "Success!", "settings have been saved!"); -} - -void DialogSettings::on_pushButtonCancel_clicked() -{ - close(); -} diff --git a/src/qt/Client/src/main.cpp b/src/qt/Client/src/main.cpp deleted file mode 100644 index 13b5b986..00000000 --- a/src/qt/Client/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "../Client/include/mainwindow.h" -#include - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - MainWindow main_window; - main_window.show(); - return app.exec(); -} diff --git a/src/qt/Client/src/mainwindow.cpp b/src/qt/Client/src/mainwindow.cpp deleted file mode 100644 index ae3d2991..00000000 --- a/src/qt/Client/src/mainwindow.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "../Client/include/mainwindow.h" -#include "../Client/forms/ui_mainwindow.h" - -/* Including other forms */ -#include "../Client/include/dialog_settings.h" // DialogSettings class (form with a connection settings) - -#include - -static constexpr const char *settings_filename = "settings.json"; - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - connect(&socket_client, &SocketClient::outInfo, this, &MainWindow::on_OutInfo); - connect(&socket_client, &SocketClient::Error, this, &MainWindow::on_Error); - connect(&socket_client, &SocketClient::connected, this, &MainWindow::on_Connected); - connect(&socket_client, &SocketClient::disconnected, this, &MainWindow::on_Disconnected); - - - connect(&settings_reader, &SettingsReader::Error, this, &MainWindow::on_Error); - - // Loading file for reading - settings_reader.LoadFile(settings_filename); - - // Reading settings from file - const auto settings = settings_reader.ReadAll(); - remote_address = settings["remote_ip-address"]; - remote_port = settings["remote_port"].toUInt(); - nickname = settings["nickname"]; -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::on_OutInfo(const QString &message) -{ - ui->textEditOutput->append(message); -} - -void MainWindow::on_Error(const QString &message) -{ - QMessageBox::critical(this, "Error!", message); -} - -void MainWindow::on_Connected() -{ - ui->pushButtonDisconnectFromServer->setEnabled(true); - ui->pushButtonSendMessage->setEnabled(true); - ui->lineEditInputMessageToSend->setEnabled(true); -} - -void MainWindow::on_Disconnected() -{ - ui->pushButtonDisconnectFromServer->setEnabled(false); - ui->pushButtonSendMessage->setEnabled(false); - ui->lineEditInputMessageToSend->setEnabled(false); - ui->lineEditInputMessageToSend->clear(); -} - -/* TODO: - * Check remote_address and nickname - * Set address and port for connection with a server - * Start the client for sendding and reciving messages -*/ -void MainWindow::on_pushButtonConnectToServer_clicked() -{ - if (remote_address.isEmpty()) { - QMessageBox::critical(this, "Error!", "Enter IP-address of the server!"); - return; - } - - if (nickname.isEmpty()) { - QMessageBox::critical(this, "Error!", "Enter your nickname!"); - return; - } - - socket_client.setAddress(remote_address); - socket_client.setPort(remote_port); - socket_client.start(); -} - -/* TODO: - * Read message from lineEditInputMessageToSend - * Check this message - * Create data to send (concatenate nickname with a message) - * Call method for send data to server -*/ -void MainWindow::on_pushButtonSendMessage_clicked() -{ - const QString message = ui->lineEditInputMessageToSend->text(); - - if (message.isEmpty()) { - QMessageBox::critical(this, "Error!", "Enter a message to send!"); - return; - } - - socket_client.SendToServer(nickname, message); - - ui->lineEditInputMessageToSend->clear(); -} - -/* TODO: - * Check textEditOutput (is empty or not) - * If not empty --> call 'clear()' method -*/ -void MainWindow::on_pushButtonClearOutput_clicked() -{ - if (not ui->textEditOutput->toPlainText().isEmpty()) { - ui->textEditOutput->clear(); - } -} - -/* TODO: - * Show the 'DialogSettings' form -*/ -void MainWindow::on_actionSettings_triggered() -{ - DialogSettings settings_dialog; - settings_dialog.exec(); -} - -void MainWindow::on_pushButtonDisconnectFromServer_clicked() -{ - socket_client.stop(); -} diff --git a/src/qt/Client/src/settings_reader.cpp b/src/qt/Client/src/settings_reader.cpp deleted file mode 100644 index 45c9a905..00000000 --- a/src/qt/Client/src/settings_reader.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "../include/settings_reader.h" -#include -#include -#include -#include - -SettingsReader::SettingsReader() -{} - -SettingsReader::~SettingsReader() -{} - -void SettingsReader::LoadFile(const char *filename) -{ - input_file.setFileName(filename); -} - -QMap SettingsReader::ReadAll() -{ - QMap settings; - if (not input_file.open(QIODevice::ReadOnly)) { - Q_EMIT Error(QString("Could not find the settings file!")); - return settings; - } - - QByteArray data = input_file.readAll(); - QJsonDocument json_doc = QJsonDocument::fromJson(data); - QJsonObject json_obj = json_doc.object(); - - settings["remote_ip-address"] = json_obj["remote_ip-address"].toString(); - settings["remote_port"] = json_obj["remote_port"].toString(); - settings["nickname"] = json_obj["nickname"].toString(); - - input_file.close(); - return settings; -} diff --git a/src/qt/Client/src/settings_writer.cpp b/src/qt/Client/src/settings_writer.cpp deleted file mode 100644 index 055d2b03..00000000 --- a/src/qt/Client/src/settings_writer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "../include/settings_writer.h" -#include -#include -#include -#include -#include - -SettingsWriter::SettingsWriter() -{} - -SettingsWriter::~SettingsWriter() -{} - -void SettingsWriter::SetOutputFile(const char *filename) -{ - output_file.setFileName(filename); -} - -void SettingsWriter::WriteSettings(QMap &settings) -{ - if (not output_file.open(QIODevice::WriteOnly)) { - Q_EMIT Error(QString("Could not find the settings file!")); - return; - } - - QVariantMap data_to_write; - - data_to_write["remote_ip-address"] = settings["remote_ip-address"]; - data_to_write["remote_port"] = settings["remote_port"]; - data_to_write["nickname"] = settings["nickname"]; - - output_file.write(QJsonDocument(QJsonObject::fromVariantMap(data_to_write)).toJson()); - output_file.close(); -} diff --git a/src/qt/Client/src/socket_client.cpp b/src/qt/Client/src/socket_client.cpp deleted file mode 100644 index b935019e..00000000 --- a/src/qt/Client/src/socket_client.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "../include/socket_client.h" - -SocketClient::SocketClient(QObject *parent) - : QObject(parent) - , remote_port {4455} - , remote_address {"127.0.0.1"} -{ - connect(&tcp_sock, &QTcpSocket::connected, this, &SocketClient::on_Connected); - connect(&tcp_sock, &QTcpSocket::disconnected, this, &SocketClient::on_Disconnected); - connect(&tcp_sock, &QTcpSocket::readyRead, this, &SocketClient::on_ReadyRead); - connect(&tcp_sock, QOverload::of(&QAbstractSocket::error), this, &SocketClient::DisplayError); -} - -void SocketClient::setPort(quint16 port) -{ - remote_port = port; -} - -void SocketClient::setAddress(const QString &address) -{ - remote_address = address; -} - -void SocketClient::start() -{ - Q_EMIT started(); - tcp_sock.connectToHost(remote_address, remote_port); -} - -void SocketClient::stop() -{ - tcp_sock.disconnectFromHost(); -} - -void SocketClient::on_Connected() -{ - Q_EMIT connected(); - Q_EMIT outInfo(QString("[%1] You connected with: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) - .arg(remote_address).arg(remote_port)); -} - -void SocketClient::on_Disconnected() -{ - Q_EMIT disconnected(); - Q_EMIT outInfo(QString("[%1] You disconnected from: %2:%3!").arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss")) - .arg(remote_address).arg(remote_port)); -} - -void SocketClient::on_ReadyRead() -{ - Q_EMIT outInfo(tcp_sock.readAll()); -} - -void SocketClient::DisplayError(QAbstractSocket::SocketError error_code) -{ - switch (error_code) { - case QAbstractSocket::ConnectionRefusedError: - Q_EMIT Error(QString("Connection refused with: %1:%2!").arg(remote_address).arg(remote_port)); - break; - case QAbstractSocket::HostNotFoundError: - Q_EMIT Error(QString("Remote host not found!")); - break; - case QAbstractSocket::RemoteHostClosedError: - Q_EMIT Error(QString("Remote host is closed!")); - break; - } -} - -void SocketClient::SendToServer(const QString &nickname, const QString &message) -{ - QByteArray data_block; - QDataStream send_stream(&data_block, QIODevice::ReadWrite); - - send_stream.setVersion(QDataStream::Qt_5_7_1); - - send_stream << quint16(0) << nickname << message.toUtf8(); - send_stream.device()->seek(0); - send_stream << quint16(data_block.size() - sizeof(quint16)); - - tcp_sock.write(data_block); -} diff --git a/src/qt/Server/SocketServer.pro b/src/qt/Server/SocketServer.pro deleted file mode 100644 index 3ec4f3ff..00000000 --- a/src/qt/Server/SocketServer.pro +++ /dev/null @@ -1,37 +0,0 @@ -QT += core gui network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++17 - -QMAKE_CXXFLAGS += -std=c++17 - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - src/main.cpp \ - src/mainwindow.cpp \ - src/server_data_base.cpp \ - src/socket_server.cpp - -HEADERS += \ - include/mainwindow.h \ - include/server_data_base.h \ - include/socket_server.h - -FORMS += \ - forms/mainwindow.ui - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target diff --git a/src/qt/Server/forms/mainwindow.ui b/src/qt/Server/forms/mainwindow.ui deleted file mode 100644 index 076cd2d2..00000000 --- a/src/qt/Server/forms/mainwindow.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 508 - 325 - - - - MainWindow - - - - - - - Stop server - - - - - - - Start server - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::ClickFocus - - - true - - - - - - - - - diff --git a/src/qt/Server/include/mainwindow.h b/src/qt/Server/include/mainwindow.h deleted file mode 100644 index 6e9cbdfc..00000000 --- a/src/qt/Server/include/mainwindow.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include "socket_server.h" - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - -private Q_SLOTS: - // Slots for handling signals from 'SocketServer' class - void on_OutInfo(const QString &message); - void on_Error(const QString &error_message); - - // Buttons slots - void on_pushButtonStartServer_clicked(); - void on_pushButtonStopServer_clicked(); - -private: - Ui::MainWindow *ui; - SocketServer socket_server; - quint16 line_counter; -}; -#endif // MAINWINDOW_H diff --git a/src/qt/Server/include/server_data_base.h b/src/qt/Server/include/server_data_base.h deleted file mode 100644 index 3fe0e49c..00000000 --- a/src/qt/Server/include/server_data_base.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef SERVERDATABASE_H -#define SERVERDATABASE_H - -#include -#include - -class ServerDataBase : public QObject -{ - Q_OBJECT -public: - explicit ServerDataBase(QObject *parent = nullptr); - -public Q_SLOTS: - static bool isExists(QStringView name); - static bool isEmpty(); - static QString getLast(); - static void addClient(QStringView name); - static void deleteLastClient(); - static void deleteClientByName(QStringView name); - static void clear(); - -private: - static QVector clients; -}; - -#endif // SERVERDATABASE_H diff --git a/src/qt/Server/include/socket_server.h b/src/qt/Server/include/socket_server.h deleted file mode 100644 index c83bd7b5..00000000 --- a/src/qt/Server/include/socket_server.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef SERVER_H -#define SERVER_H - -#include -#include -#include -#include -#include -#include -#include - -#include "server_data_base.h" - -class SocketServer : public QObject -{ - Q_OBJECT - -public: - SocketServer(); - void setPort(const quint16 &port); - ~SocketServer(); - -public Q_SLOTS: - void start(); - void stop(); - -private Q_SLOTS: - void on_ClientConnected(); - void on_ClientStateChanged(QAbstractSocket::SocketState state); - void on_ReadyRead(); - -Q_SIGNALS: - void addToDataBase(QStringView username); - void OutInfo(const QString &message); - void Error(const QString &error_message); - -private: - quint16 serv_port; - QTcpServer tcp_serv_socket; - QList connectd_clients_list; - - QMap command_handler; - static void time_command_handler(const QByteArray &data, QTcpSocket *client, SocketServer *server_socket); -}; - -#endif // SERVER_H diff --git a/src/qt/Server/src/main.cpp b/src/qt/Server/src/main.cpp deleted file mode 100644 index 08418520..00000000 --- a/src/qt/Server/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "../qt/Server/include/mainwindow.h" -#include - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - MainWindow main_window; - main_window.show(); - return app.exec(); -} diff --git a/src/qt/Server/src/mainwindow.cpp b/src/qt/Server/src/mainwindow.cpp deleted file mode 100644 index ccd67380..00000000 --- a/src/qt/Server/src/mainwindow.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "../qt/Server/include/mainwindow.h" -#include "../qt/Server/forms/ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) - , line_counter(0) -{ - ui->setupUi(this); - setWindowTitle("Socket server"); - - connect(&socket_server, &SocketServer::OutInfo, this, &MainWindow::on_OutInfo); - connect(&socket_server, &SocketServer::Error, this, &MainWindow::on_Error); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::on_OutInfo(const QString &message) -{ - ui->textEditServerOutput->append(message); - line_counter++; -} - -void MainWindow::on_Error(const QString &error_message) -{ - ui->textEditServerOutput->append(error_message); - line_counter++; - - if (line_counter == 450) { - ui->textEditServerOutput->clear(); - } -} - -void MainWindow::on_pushButtonStartServer_clicked() -{ - socket_server.setPort(4455); - socket_server.start(); -} - -void MainWindow::on_pushButtonStopServer_clicked() -{ - socket_server.stop(); - if (QMessageBox::question(this, "Question", "Do you want to close application?", - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) - { - QCoreApplication::quit(); - } -} diff --git a/src/qt/Server/src/server_data_base.cpp b/src/qt/Server/src/server_data_base.cpp deleted file mode 100644 index 8de1b6cb..00000000 --- a/src/qt/Server/src/server_data_base.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "../qt/Server/include/server_data_base.h" - -QVector ServerDataBase::clients {}; - -ServerDataBase::ServerDataBase(QObject *parent) - : QObject(parent) -{} - -void ServerDataBase::addClient(QStringView name) -{ - clients.append(name.toString()); -} - -void ServerDataBase::deleteLastClient() -{ - clients.removeLast(); -} - -void ServerDataBase::deleteClientByName(QStringView name) -{ - clients.removeOne(name.toString()); -} - -bool ServerDataBase::isExists(QStringView name) -{ - return clients.contains(name.toString()); -} - -bool ServerDataBase::isEmpty() -{ - return clients.isEmpty(); -} - -void ServerDataBase::clear() -{ - clients.clear(); -} - -QString ServerDataBase::getLast() -{ - return clients.last(); -} diff --git a/src/qt/Server/src/socket_server.cpp b/src/qt/Server/src/socket_server.cpp deleted file mode 100644 index 67def303..00000000 --- a/src/qt/Server/src/socket_server.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "../qt/Server/include/socket_server.h" - -SocketServer::SocketServer() -{ - connect(&tcp_serv_socket, &QTcpServer::newConnection, this, &SocketServer::on_ClientConnected); - - command_handler = { - {{"/time"}, time_command_handler} - }; -} - -SocketServer::~SocketServer() -{ - stop(); -} - -void SocketServer::setPort(const quint16 &port) -{ - serv_port = port; -} - -void SocketServer::start() -{ - if (tcp_serv_socket.listen(QHostAddress::AnyIPv4, serv_port)) { - Q_EMIT OutInfo(QString("<-- Server running on port: %1 -->").arg(serv_port)); - } - else { - Q_EMIT Error(QString("<-- Could not start the server: (err=%1) -->").arg(tcp_serv_socket.errorString())); - } -} - -void SocketServer::stop() -{ - for (QTcpSocket *connected_client : connectd_clients_list) { - connected_client->close(); - } - - tcp_serv_socket.close(); - - connectd_clients_list.clear(); - ServerDataBase::clear(); - - Q_EMIT OutInfo(QString("<-- Server stopped! -->")); -} - -void SocketServer::on_ClientConnected() -{ - QTcpSocket *new_client = tcp_serv_socket.nextPendingConnection(); - - connect(new_client, &QTcpSocket::stateChanged, this, &SocketServer::on_ClientStateChanged); - connect(new_client, &QTcpSocket::readyRead, this, &SocketServer::on_ReadyRead); - - QString new_client_connected_msg = QString("<-- New client connected: (addr=%1) -->").arg(new_client->peerAddress().toString()); - - Q_EMIT OutInfo(new_client_connected_msg); - - new_client->write("<---- [ >> Welcome to the Socket-Chat! << ] ---->"); - - for (QTcpSocket *connected_client : connectd_clients_list) { - connected_client->write(new_client_connected_msg.toUtf8()); - } - - connectd_clients_list.append(new_client); -} - -void SocketServer::on_ClientStateChanged(QAbstractSocket::SocketState state) -{ - QTcpSocket *client = static_cast(sender()); - - if (state == QAbstractSocket::UnconnectedState) { - QString client_disconnected_msg = QString("<-- Client disconnected: (addr=%1) -->").arg(client->peerAddress().toString()); - - if (not ServerDataBase::isEmpty()) { - ServerDataBase::deleteLastClient(); - } - - connectd_clients_list.removeOne(client); - client->close(); - Q_EMIT OutInfo(client_disconnected_msg); - - for (QTcpSocket *connected_client : connectd_clients_list) { - connected_client->write(client_disconnected_msg.toUtf8()); - } - } -} - -void SocketServer::on_ReadyRead() -{ - QTcpSocket *client = static_cast(sender()); - - quint16 next_block_size = 0; - QByteArray recived_data; - - QString user_name; - - QDataStream recive_stream(client); - recive_stream.setVersion(QDataStream::Qt_5_7_1); - - Q_FOREVER { - if (!next_block_size) { - if (client->bytesAvailable() < sizeof(quint16)) { - break; - } - } - recive_stream >> next_block_size; - - if (client->bytesAvailable() < next_block_size) { - break; - } - - recive_stream >> user_name >> recived_data; - next_block_size = 0; - } - - if (not ServerDataBase::isExists(user_name)) { - ServerDataBase::addClient(user_name); - - Q_EMIT OutInfo(QString("<-- Recived bytes: %1, from: (addr=%2) -->").arg(recived_data.size()).arg(client->peerAddress().toString())); - - for (QTcpSocket *connected_client : connectd_clients_list) { - if (command_handler.contains(recived_data)) { - command_handler[recived_data](QString(user_name + ": " + recived_data).toUtf8(), connected_client, this); - } - else { // default message recived - connected_client->write(QString(user_name + ": " + recived_data).toUtf8()); - } - Q_EMIT OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(recived_data.size()).arg(connected_client->peerAddress().toString())); - } - } - else { - client->write(QString("<-- Client with nickanme '%1' already exists! -->").arg(user_name).toUtf8()); - client->close(); - } -} - -void SocketServer::time_command_handler(const QByteArray &data, QTcpSocket *client, SocketServer *server_socket) -{ - client->write(data + "\n"); - client->write("Current date and time: " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss").toUtf8()); - Q_EMIT server_socket->OutInfo(QString("<-- Sending bytes: %1, to: (addr=%2) -->").arg(data.size()).arg(client->peerAddress().toString())); -} From a8cdf5d26d62a759507b1be3ece25c27a28a9146 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:05:18 -0400 Subject: [PATCH 0230/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e7947033..7d20c0bd 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -54,10 +54,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui \ - qt/Client/forms/dialog_settings.ui \ - qt/Client/forms/mainwindow.ui \ - qt/Server/forms/mainwindow.ui + qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -197,15 +194,7 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h \ - qt/Client/include/dialog_settings.h \ - qt/Client/include/mainwindow.h \ - qt/Client/include/settings_reader.h \ - qt/Client/include/settings_writer.h \ - qt/Client/include/socket_client.h \ - qt/Server/include/mainwindow.h \ - qt/Server/include/server_data_base.h \ - qt/Server/include/socket_server.h + qt/winshutdownmonitor.h RES_ICONS = \ @@ -549,17 +538,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp \ - qt/Client/src/dialog_settings.cpp \ - qt/Client/src/main.cpp \ - qt/Client/src/mainwindow.cpp \ - qt/Client/src/settings_reader.cpp \ - qt/Client/src/settings_writer.cpp \ - qt/Client/src/socket_client.cpp \ - qt/Server/src/main.cpp \ - qt/Server/src/mainwindow.cpp \ - qt/Server/src/server_data_base.cpp \ - qt/Server/src/socket_server.cpp + qt/walletview.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 3e94e8c7117d5f8842b52236f504a423e986f005 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:17:56 -0400 Subject: [PATCH 0231/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index eb16a182..63463dcc 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -10,7 +10,7 @@ #include "governancelist.h" /* #include "tradingdialogpage.h" */ #include "chatwindowpage.h" -#include + #include @@ -28,7 +28,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class MainWindow; +class ChatWindowPage; QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - MainWindow *mainWindow; + ChatWindowPage *chatWindowPage; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -89,7 +89,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to chat page */ - void gotoMainWindow(); + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 7e27d2b2394393144a0fc952e151cecf39d1f4cf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:19:03 -0400 Subject: [PATCH 0232/1324] Update walletview.cpp --- src/qt/walletview.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 543a011e..47cd79f3 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,6 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include #include "ui_interface.h" @@ -89,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - mainWindow = new MainWindow(); - addWidget(mainWindow); + chatWindowPage = new ChatWindowPage(); + addWidget(chatWindowPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -242,9 +241,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoMainWindow() +void WalletView::gotoChatWindowPage() { - setCurrentWidget(mainWindow); + setCurrentWidget(chatWindowPage); } /*void WalletView::gotoTradingDialogPage() From 8be52f31e5851773d6040a3a924b705195da77ab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:19:25 -0400 Subject: [PATCH 0233/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 2f5fc04f..bf82208c 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to chat page */ - void gotoMainWindow(); + void gotoChatWindowPage); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 701abd05899775d54a03644eee014cfe39062e7e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:19:50 -0400 Subject: [PATCH 0234/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index a170c85a..035ad36c 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoMainWindow() +void WalletFrame::gotoChatWindowPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoMainWindow(); + i.value()->gotoChatWindowPage(); } /*void WalletFrame::gotoTradingDialogPage() From b96708a99c768cee29823b50d27f9a4c2e368401 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:20:19 -0400 Subject: [PATCH 0235/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index f2cf1a0e..8e0966f3 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to chat page */ - void gotoMainWindow(); + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From b32f1cde3fc6956dbee4e777292c829b2d5ec69b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:22:00 -0400 Subject: [PATCH 0236/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 936f671e..3cbdbb39 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,9 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -/* #include "tradingdialogpage.h" -#include "chatwindowpage.h" */ -#include +/* #include "tradingdialogpage.h" */ +#include "chatwindowpage.h" #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -638,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -1070,10 +1069,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoMainWindow() +void BitcoinGUI::gotoChatWindowPage() { chatWindowPage->setChecked(true); - if (walletFrame) walletFrame->gotoMainWindow(); + if (walletFrame) walletFrame->gotoChatWindowPage(); } /*void BitcoinGUI::gotoTradingDialogPage() From 515c9e146aae52684076cdac713386979c0792a3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:23:05 -0400 Subject: [PATCH 0237/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index bf82208c..982f6690 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to chat page */ - void gotoChatWindowPage); + void gotoChatWindowPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 70d709cb3b7c8e251091dcda1a9ceeb50f8a1179 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:26:52 -0400 Subject: [PATCH 0238/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 286 +++++++++++++++++++++++++++----------- 1 file changed, 202 insertions(+), 84 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index f1c4185f..87bff742 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -1,113 +1,231 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + #include "chatwindowpage.h" +#include "ui_chatwindowpage.h" -// We'll need some regular expression magic in this code: -#include +#include +#include +#include +#include +#include +#include -// This is our ChatWindowPage constructor (you C++ n00b) -ChatWindowPage::ChatWindowPage(QWidget *parent) : QMainWindow(parent) +ChatWindowPage::ChatWindowPage(QWidget *parent) + : QWidget(parent), ui(new Ui::ChatWindowPage) { - // When using Designer, you should always call setupUi(this) - // in your constructor. This creates and lays out all the widgets - // on the ChatWindowPage that you setup in Designer. - setupUi(this); - - // Make sure that we are showing the login page when we startup: - stackedWidget->setCurrentWidget(loginPage); - - // Instantiate our socket (but don't actually connect to anything - // yet until the user clicks the loginButton: - socket = new QTcpSocket(this); - - // This is how we tell Qt to call our readyRead() and connected() - // functions when the socket has text ready to be read, and is done - // connecting to the server (respectively): - connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); - connect(socket, SIGNAL(connected()), this, SLOT(connected())); + ui->setupUi(this); + setFixedSize(750,600); + ui->splitter->hide(); + + connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(connecte())); + + connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); + connect(ui->actionCloseTab, SIGNAL(triggered()), this, SLOT(closeTab())); + + connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(sendCommande())); + + + ui->pushButton_WebChat->setStatusTip(tr("Visit Help The Homeless Worldwide Web Chat")); + + + + + + connect(ui->disconnect, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); + connect(ui->tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); + connect(ui->tab, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosing(int)) ); + } -// This gets called when the loginButton gets clicked: -// We didn't have to use connect() to set this up because -// Qt recognizes the name of this function and knows to set -// up the signal/slot connection for us. -void ChatWindowPage::on_loginButton_clicked() + + +void ChatWindowPage::tabChanged(int index) { - // Start connecting to the chat server (on port 4200). - // This returns immediately and then works on connecting - // to the server in the background. When it's done, we'll - // get a connected() function call (below). If it fails, - // we won't get any error message because we didn't connect() - // to the error() signal from this socket. - socket->connectToHost(serverLineEdit->text(), 4200); + if(index!=0 && joining == false) + currentTab()->updateUsersList(ui->tab->tabText(index)); } -// This gets called when the user clicks the sayButton (next to where -// they type text to send to the chat room): -void ChatWindowPage::on_sayButton_clicked() +void ChatWindowPage::tabClosing(int index) +{ + currentTab()->leave(ui->tab->tabText(index)); +} +/*void ChatWindow::tabRemoved(int index) { - // What did they want to say (minus white space around the string): - QString message = sayLineEdit->text().trimmed(); + currentTab()->leave(ui->tab->tabText(index)); +}*/ - // Only send the text to the chat server if it's not empty: - if(!message.isEmpty()) +void ChatWindowPage::disconnectFromServer() { + + QMapIterator i(serveurs); + + while(i.hasNext()) { - socket->write(QString(message + "\n").toUtf8()); + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } } - // Clear out the input box so they can type something else: - sayLineEdit->clear(); - // Put the focus back into the input box so they can type again: - sayLineEdit->setFocus(); + ui->splitter->hide(); + ui->hide3->show(); + } -// This function gets called whenever the chat server has sent us some text: -void ChatWindowPage::readyRead() +Serveur *ChatWindowPage::currentTab() { - // We'll loop over every (complete) line of text that the server has sent us: - while(socket->canReadLine()) - { - // Here's the line the of text the server sent us (we use UTF-8 so - // that non-English speakers can chat in their native language) - QString line = QString::fromUtf8(socket->readLine()).trimmed(); + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + return serveurs[tooltip]; + //return ui->tab->currentWidget()->findChild(); +} - // These two regular expressions describe the kinds of messages - // the server can send us: +void ChatWindowPage::closeTab() +{ + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + QString txt=ui->tab->tabText(ui->tab->currentIndex()); + + if(txt==tooltip) + { + QMapIterator i(serveurs[tooltip]->conversations); + + int count=ui->tab->currentIndex()+1; + + while(i.hasNext()) + { + i.next(); + ui->tab->removeTab(count); + } + + currentTab()->abort(); + ui->tab->removeTab(ui->tab->currentIndex()); + } + else + { + + ui->tab->removeTab(ui->tab->currentIndex()); + currentTab()->conversations.remove(txt); + } +} - // Normal messges look like this: "username:The message" - QRegExp messageRegex("^([^:]+):(.*)$"); +void ChatWindowPage::sendCommande() +{ + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + QString txt=ui->tab->tabText(ui->tab->currentIndex()); + if(txt==tooltip) + { + currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text(),true) ); + } + else + { + currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text()) ); + } + ui->lineEdit->clear(); + ui->lineEdit->setFocus(); +} - // Any message that starts with "/users:" is the server sending us a - // list of users so we can show that list in our GUI: - QRegExp usersRegex("^/users:(.*)$"); +void ChatWindowPage::tabJoined() +{ + joining=true; +} +void ChatWindowPage::tabJoining() +{ + joining=false; +} - // Is this a users message: - if(usersRegex.indexIn(line) != -1) - { - // If so, udpate our users list on the right: - QStringList users = usersRegex.cap(1).split(","); - userListWidget->clear(); - Q_FOREACH(QString user, users) - new QListWidgetItem(QPixmap(":/icons/chat.png"), user, userListWidget); - } - // Is this a normal chat message: - else if(messageRegex.indexIn(line) != -1) - { - // If so, append this message to our chat box: - QString user = messageRegex.cap(1); - QString message = messageRegex.cap(2); +void ChatWindowPage::connecte() +{ - roomTextEdit->append("" + user + ": " + message); - } + ui->splitter->show(); + Serveur *serveur=new Serveur; + QTextEdit *textEdit=new QTextEdit; + ui->hide3->hide(); + + ui->tab->addTab(textEdit,"Console/PM"); + ui->tab->setTabToolTip(ui->tab->count()-1,"irc.freenode.net"); + // current tab is now the last, therefore remove all but the last + for (int i = ui->tab->count(); i > 1; --i) { + ui->tab->removeTab(0); } + + serveurs.insert("irc.freenode.net",serveur); + + serveur->pseudo=ui->editPseudo->text(); + serveur->serveur="irc.freenode.net"; + serveur->port=6667; + serveur->affichage=textEdit; + serveur->tab=ui->tab; + serveur->userList=ui->userView; + serveur->parent=this; + + textEdit->setReadOnly(true); + + connect(serveur, SIGNAL(joinTab()),this, SLOT(tabJoined() )); + connect(serveur, SIGNAL(tabJoined()),this, SLOT(tabJoining() )); + + serveur->connectToHost("irc.freenode.net",6667); + + ui->tab->setCurrentIndex(ui->tab->count()-1); } -// This function gets called when our socket has successfully connected to the chat -// server. (see the connect() call in the ChatWindowPage constructor). -void ChatWindowPage::connected() +void ChatWindowPage::closeEvent(QCloseEvent *event) +{ + (void) event; + + QMapIterator i(serveurs); + + while(i.hasNext()) + { + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } + } +} +void ChatWindowPage ::setModel(ClientModel *model) { - // Flip over to the chat page: - stackedWidget->setCurrentWidget(chatPage); + this->model = model; +} + +void ChatWindowPage::on_pushButton_WebChat_clicked() { // #HTHWorld Chat + + QDesktopServices::openUrl(QUrl("https://webchat.freenode.net//", QUrl::TolerantMode)); + +} + - // And send our username to the chat server. - socket->write(QString("/me:" + userLineEdit->text() + "\n").toUtf8()); +ChatWindowPage::~ChatWindowPage() +{ + delete ui; + QMapIterator i(serveurs); + + while(i.hasNext()) + { + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } + } } From 8151a0133291fde4a7146506c1c01cc0cfac8905 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:27:13 -0400 Subject: [PATCH 0239/1324] Update chatwindowpage.h --- src/qt/chatwindowpage.h | 99 ++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h index 4632402c..2beba14b 100644 --- a/src/qt/chatwindowpage.h +++ b/src/qt/chatwindowpage.h @@ -1,46 +1,73 @@ -// We need to include a couple Qt classes that we'll use: -#include -#include - -// This is the include file that Qt generates for us from the -// GUI we built in Designer -#include "ui_chatwindowpage.h" - -/* - * This is the ChatWindowPage class that we have told to inherit from - * our Designer ChatWindowPage (ui::ChatWindowPage) - */ -class ChatWindowPage : public QMainWindow, public Ui::ChatWindowPage -{ - Q_OBJECT +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + +#ifndef CHATWINDOWPAGE_H +#define CHATWINDOWPAGE_H - public: +#include +#include +#include "clientmodel.h" +#include "serveur.h" - // Every QWidget needs a constructor, and they should allow - // the user to pass a parent QWidget (or not). - ChatWindowPage(QWidget *parent=0); +#include +#include +#include - private Q_SLOTS: - // This function gets called when a user clicks on the - // loginButton on the front page (which you placed there - // with Designer) - void on_loginButton_clicked(); - // This gets called when you click the sayButton on - // the chat page. - void on_sayButton_clicked(); +namespace Ui +{ + class ChatWindowPage; +} - // This is a function we'll connect to a socket's readyRead() - // signal, which tells us there's text to be read from the chat - // server. - void readyRead(); +class ChatWindowPage : public QWidget +{ + Q_OBJECT - // This function gets called when the socket tells us it's connected. - void connected(); +public: + ChatWindowPage(QWidget *parent = 0); + ~ChatWindowPage(); + void setModel(ClientModel *model); + Serveur * currentTab(); + Q_SIGNALS: + void changeTab(); - private: + public Q_SLOTS: + void sendCommande(); + void connecte(); + void closeTab(); + + void tabChanged(int index); + + void tabJoined(); + void tabJoining(); + void disconnectFromServer(); + void tabClosing(int index); + + +private: + Ui::ChatWindowPage *ui; + ClientModel *model; + QMap serveurs; + bool joining; + void closeEvent(QCloseEvent *event); + +private Q_SLOTS: + void on_pushButton_WebChat_clicked(); - // This is the socket that will let us communitate with the server. - QTcpSocket *socket; }; + +#endif // CHATWINDOWPAGE_H From 2dec8a499934cf094299a7bfa7f0b9db2b2f055d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:27:58 -0400 Subject: [PATCH 0240/1324] Create serveur.cpp --- src/qt/serveur.cpp | 359 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 src/qt/serveur.cpp diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp new file mode 100644 index 00000000..8178aec1 --- /dev/null +++ b/src/qt/serveur.cpp @@ -0,0 +1,359 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ +#include +#include "serveur.h" + QStringList users; + bool delist = true; +Serveur::Serveur() +{ + connect(this, SIGNAL(readyRead()), this, SLOT(readServeur())); + connect(this, SIGNAL(connected()), this, SLOT(connected())); + connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorSocket(QAbstractSocket::SocketError))); + + updateUsers=false; +} + + + + +void Serveur::errorSocket(QAbstractSocket::SocketError error) +{ + switch(error) + { + case QAbstractSocket::HostNotFoundError: + affichage->append(tr("ERROR : can't find HTHWorld server.")); + break; + case QAbstractSocket::ConnectionRefusedError: + affichage->append(tr("ERROR : server refused connection")); + break; + case QAbstractSocket::RemoteHostClosedError: + affichage->append(tr("ERROR : server cut connection")); + break; + default: + affichage->append(tr("ERROR : ") + this->errorString() + tr("")); + } +} + +void Serveur::connected() +{ + affichage->append("Connecting... to HTHWorld IRC. Please wait."); + + sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); + sendData("NICK "+pseudo); + affichage->append("Connected to HTHWorld IRC."); + +} + +void Serveur::joins() +{ + join("#HTHWorld"); +} + +void Serveur::readServeur() +{ + QString message=QString::fromUtf8(this->readAll()); + + + QString currentChan=tab->tabText(tab->currentIndex()); + + if(message.startsWith("PING :")) + { + QStringList liste=message.split(" "); + QString msg="PONG "+liste.at(1); + sendData(msg); + } + else if(message.contains("Nickname is already in use.")) + { + pseudo=pseudo+"_2"; + pseudo.remove("\r\n"); + sendData("NICK "+pseudo); + Q_EMIT pseudoChanged(pseudo); + ecrire("-> Name changed to "+pseudo); + } + else if(updateUsers==true) + { + updateUsersList("",message); + } + + QStringList list=message.split("\r\n"); + Q_FOREACH(QString msg,list) + { + if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 <\\1> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 join \\2
"),"",msg2.replace(reg,"-> \\1 join \\2")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 quit \\2 (\\3)
"),"",msg2.replace(reg,"-> \\1 quit \\2")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 quit this server (\\2)
"),"",msg2.replace(reg,"-> \\1 left")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\1 is now called \\2
"),"",msg2.replace(reg,"-> \\1 is now called \\2")); + updateUsersList(currentChan); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 kicked \\3 (\\4)
"),"",msg2.replace(reg,"-> \\1 quit \\3")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) + { + if(conversations.contains(currentChan)) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); + ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
"),currentChan); + } + else if(currentChan==serveur) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); + ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
")); + } + } + else if(msg.contains("/MOTD command.")) + { + joins(); + + + } + + + + } + + //} +} + +void Serveur::sendData(QString txt) +{ + if(this->state()==QAbstractSocket::ConnectedState) + { + this->write((txt+"\r\n").toUtf8()); + } +} + +QString Serveur::parseCommande(QString comm,bool serveur) +{ + if(comm.startsWith("/")) + { + comm.remove(0,1); + QString pref=comm.split(" ").first(); + QStringList args=comm.split(" "); + args.removeFirst(); + QString destChan=tab->tabText(tab->currentIndex()); + QString msg=args.join(" "); + + if(pref=="me") + return "PRIVMSG "+destChan+" ACTION " + msg + ""; + else if(pref=="msg") + return "MSG "+destChan+" ACTION " + msg + ""; + else if(pref=="join") + { + join(msg); + return " "; + } + else if(pref=="quit") + { + if(msg == "") + return "QUIT "+msgQuit; + else + return "QUIT "+msg; + } + else if(pref=="part") + { + tab->removeTab(tab->currentIndex()); + + if(msg == "") + { + if(msg.startsWith("#")) + destChan=msg.split(" ").first(); + + if(msgQuit=="") + return "PART "+destChan+" using IrcLightClient"; + else + return "PART "+destChan+" "+msgQuit; + } + else + return "PART "+destChan+" "+msg; + + conversations.remove(destChan); + } + else if(pref=="kick") + { + QStringList tableau=msg.split(" "); + QString c1,c2,c3; + if(tableau.count() > 0) c1=" "+tableau.first(); + else c1=""; + if(tableau.count() > 1) c2=" "+tableau.at(1); + else c2=""; + if(tableau.count() > 2) c3=" "+tableau.at(2); + else c3=""; + + if(c1.startsWith("#")) + return "KICK"+c1+c2+c3; + else + return "KICK "+destChan+c1+c2; + } + else if(pref=="update") + { + updateUsers=true; + return "WHO "+destChan; + } + else if(pref=="ns") + { + return "NICKSERV "+msg; + } + else if(pref=="nick") + { + Q_EMIT pseudoChanged(msg); + ecrire("-> Nickname changed to "+msg); + return "NICK "+msg; + } + else if(pref=="msg") + { + return "MSG "+msg; + } + + else + return pref+" "+msg; + } + else if(!serveur) + { + QString destChan=tab->tabText(tab->currentIndex()); + if(comm.endsWith("
")) + comm=comm.remove(QRegExp("
$")); + ecrire("<"+pseudo+"> "+comm,destChan); + + if(comm.startsWith(":")) + comm.insert(0,":"); + + return "PRIVMSG "+destChan+" "+comm.replace(" ","\t"); + } + else + { + return ""; + } +} + +void Serveur::join(QString chan) +{ + affichage->append("Joining "+ chan +" channel"); + Q_EMIT joinTab(); + QTextEdit *textEdit=new QTextEdit; + int index=tab->insertTab(tab->currentIndex()+1,textEdit,chan); + tab->setTabToolTip(index,serveur); + tab->setCurrentIndex(index); + + textEdit->setReadOnly(true); + + conversations.insert(chan,textEdit); + + sendData("JOIN "+chan); + + Q_EMIT tabJoined(); +} +void Serveur::leave(QString chan) +{ + sendData(parseCommande("/part "+chan+ " "+msgQuit)); +} + +void Serveur::ecrire(QString txt,QString destChan,QString msgTray) +{ + if(destChan!="") + { + conversations[destChan]->setHtml(conversations[destChan]->toHtml()+txt); + QScrollBar *sb = conversations[destChan]->verticalScrollBar(); + sb->setValue(sb->maximum()); + } + else if(txt.startsWith("#")) + { + QString dest=txt.split(" ").first(); + QStringList list=txt.split(" "); + list.removeFirst(); + txt=list.join(" "); + conversations[dest]->setHtml(conversations[dest]->toHtml()+txt); + QScrollBar *sb = conversations[dest]->verticalScrollBar(); + sb->setValue(sb->maximum()); } + else + { + txt.replace("\r\n","
"); + affichage->setHtml(affichage->toHtml()+txt+"
"); + QScrollBar *sb = affichage->verticalScrollBar(); + sb->setValue(sb->maximum()); + } + + +} + +void Serveur::updateUsersList(QString chan,QString message) +{ + message = message.replace("\r\n",""); + message = message.replace("\r",""); + if(chan!=serveur) + { + if(updateUsers==true || message != "") + { + QString liste2=message.replace(":",""); + QStringList liste=liste2.split(" "); + + if (delist == true) users.clear(); + + for(int i=5; i < liste.count(); i++) + { + users.append(liste.at(i)); + } + updateUsers=false; + if (liste.count() < 53) delist = true; + else delist = false; + QStringListModel *model = new QStringListModel(users); + userList->setModel(model); + userList->update(); + } + else + { + updateUsers=true; + sendData("NAMES "+chan); + } + } + else + { + QStringListModel model; + userList->setModel(&model); + userList->update(); + } +} From 56767a54f218fd6fc8a4cd05920e4fe8aa93cae1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:28:29 -0400 Subject: [PATCH 0241/1324] Create serveur.h --- src/qt/serveur.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/qt/serveur.h diff --git a/src/qt/serveur.h b/src/qt/serveur.h new file mode 100644 index 00000000..9d2f6270 --- /dev/null +++ b/src/qt/serveur.h @@ -0,0 +1,67 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + +#ifndef SERVEUR_H +#define SERVEUR_H + +#include +#include +#include +#include +#include +#include + +class Serveur : public QTcpSocket +{ + Q_OBJECT + + public: + Serveur(); + QTextEdit *affichage; + QListView *userList; + QString pseudo,serveur,msgQuit; + int port; + QTabWidget *tab; + QMap conversations; + QSystemTrayIcon *tray; + + bool updateUsers; + + QString parseCommande(QString comm,bool serveur=false); + + QWidget *parent; + + + Q_SIGNALS: + void pseudoChanged(QString newPseudo); + void joinTab(); + void tabJoined(); + + public Q_SLOTS: + void readServeur(); + void errorSocket(QAbstractSocket::SocketError); + void connected(); + void joins(); + void sendData(QString txt); + void join(QString chan); + void leave(QString chan); + void ecrire(QString txt,QString destChan="",QString msgTray=""); + void updateUsersList(QString chan="",QString message=""); + + //void tabChanged(int index); +}; + +#endif // SERVEUR_H From 5de2aceccb70b41a2d072b7c43460ebfb70f0730 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:28:40 -0400 Subject: [PATCH 0242/1324] Delete chatterboxserver.h --- src/qt/chatterboxserver.h | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/qt/chatterboxserver.h diff --git a/src/qt/chatterboxserver.h b/src/qt/chatterboxserver.h deleted file mode 100644 index f4caefae..00000000 --- a/src/qt/chatterboxserver.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __ChatterBoxServer_H__ -#define __ChatterBoxServer_H__ - -#include -#include -#include -#include -#include - -class ChatterBoxServer : public QTcpServer -{ - Q_OBJECT - - public: - ChatterBoxServer(QObject *parent=0); - - private Q_SLOTS: - void readyRead(); - void disconnected(); - void sendUserList(); - - protected: - void incomingConnection(int socketfd); - - private: - QSet clients; - QMap users; -}; - -#endif From 15d426d867b28e68bdcffcb26a9ffe38b2b7808d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:28:47 -0400 Subject: [PATCH 0243/1324] Delete chatterboxserver.cpp --- src/qt/chatterboxserver.cpp | 80 ------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/qt/chatterboxserver.cpp diff --git a/src/qt/chatterboxserver.cpp b/src/qt/chatterboxserver.cpp deleted file mode 100644 index dcf95811..00000000 --- a/src/qt/chatterboxserver.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "chatterboxserver.h" - -#include -#include - -ChatterBoxServer::ChatterBoxServer(QObject *parent) : QTcpServer(parent) -{ -} - -void ChatterBoxServer::incomingConnection(int socketfd) -{ - QTcpSocket *client = new QTcpSocket(this); - client->setSocketDescriptor(socketfd); - clients.insert(client); - - qDebug() << "New client from:" << client->peerAddress().toString(); - - connect(client, SIGNAL(readyRead()), this, SLOT(readyRead())); - connect(client, SIGNAL(disconnected()), this, SLOT(disconnected())); -} - -void ChatterBoxServer::readyRead() -{ - QTcpSocket *client = (QTcpSocket*)sender(); - while(client->canReadLine()) - { - QString line = QString::fromUtf8(client->readLine()).trimmed(); - qDebug() << "Read line:" << line; - - QRegExp meRegex("^/me:(.*)$"); - - if(meRegex.indexIn(line) != -1) - { - QString user = meRegex.cap(1); - users[client] = user; - Q_FOREACH(QTcpSocket *client, clients) - client->write(QString("Server:" + user + " has joined.\n").toUtf8()); - sendUserList(); - } - else if(users.contains(client)) - { - QString message = line; - QString user = users[client]; - qDebug() << "User:" << user; - qDebug() << "Message:" << message; - - Q_FOREACH(QTcpSocket *otherClient, clients) - otherClient->write(QString(user + ":" + message + "\n").toUtf8()); - } - else - { - qWarning() << "Got bad message from client:" << client->peerAddress().toString() << line; - } - } -} - -void ChatterBoxServer::disconnected() -{ - QTcpSocket *client = (QTcpSocket*)sender(); - qDebug() << "Client disconnected:" << client->peerAddress().toString(); - - clients.remove(client); - - QString user = users[client]; - users.remove(client); - - sendUserList(); - Q_FOREACH(QTcpSocket *client, clients) - client->write(QString("Server:" + user + " has left.\n").toUtf8()); -} - -void ChatterBoxServer::sendUserList() -{ - QStringList userList; - Q_FOREACH(QString user, users.values()) - userList << user; - - Q_FOREACH(QTcpSocket *client, clients) - client->write(QString("/users:" + userList.join(",") + "\n").toUtf8()); -} From 72716bad023d27864136daf58e9548db98262baf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:29:36 -0400 Subject: [PATCH 0244/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 7d20c0bd..0d1aa4d7 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -96,6 +96,7 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ + qt/moc_serveur.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -141,7 +142,6 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ - qt/chatterboxserver.h \ qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ @@ -178,6 +178,7 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ + qt/serveur.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -196,7 +197,6 @@ BITCOIN_QT_H = \ qt/walletview.h \ qt/winshutdownmonitor.h - RES_ICONS = \ qt/res/icons/bitcoin.ico \ qt/res/icons/bitcoin_testnet.ico \ @@ -506,15 +506,12 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ - qt/chatterboxserver.cpp \ qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ qt/governancelist.cpp \ qt/governancedialog.cpp \ - qt/main.cpp \ - qt/mainchat.cpp \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ @@ -527,6 +524,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ + qt/serveur.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From a363a3b40ac7d0170d7b0d236bd8aaccf400b5ab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:30:08 -0400 Subject: [PATCH 0245/1324] Update chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 584 +++++++++++++++++---------------- 1 file changed, 309 insertions(+), 275 deletions(-) diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui index 8b495541..663f0ba3 100644 --- a/src/qt/forms/chatwindowpage.ui +++ b/src/qt/forms/chatwindowpage.ui @@ -1,289 +1,323 @@ - + + ChatWindowPage - - + + 0 0 - 800 - 600 + 878 + 692 - - ChatWindowPage - - - #titleLabel { -background: #1e1d32; -color: #34bcaa; -font-size: 20px; -border: none; -border-bottom: 1px solid black; -padding: 5px; -} - -#mainFrame { -border: none; -background: #1e1d32; -} - -#loginFrame { -background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ddf, stop: 1 #aaf); -border: 1px solid gray; -padding: 10px; -border-radius: 25px; -} - - - - - 0 + + + + 0 + 50 + 851 + 611 + + + + + true - - 0 + + + 10 + 10 + 721 + 501 + - - - - - 0 - 0 - - - - HTH Chat - + + + + + + + 10 + 0 + 541 + 451 + + + + + + + QTabWidget::Rounded + + + 1 + + + false + + + + Tab 1 + - - - - - QFrame::StyledPanel - - - - - - 1 - - - - - - - true - - - - - - - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - Say - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 100 - - - - - - - - Qt::Horizontal - - - - 223 - 20 - - - - - - - - - 0 - 0 - - - - - 300 - 0 - - - - QFrame::StyledPanel - - - - 20 - - - - - Server name: - - - - - - - - - - User name: - - - - - - - - - - - 0 - 0 - - - - Login - - - - - - - - - - Qt::Horizontal - - - - 223 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 267 - - - - - - - - - + + + Tab 2 + - - + + + + + 10 + 460 + 701 + 30 + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + + + + 560 + 20 + 161 + 391 + + + + + 0 + 300 + + + + border-radius:10px; + + + + + + 595 + 420 + 100 + 30 + + + + + 100 + 30 + + + + + 100 + 30 + + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + Leave + + + + + + + 10 + 10 + 851 + 671 + + + + + + 179 + 40 + 241 + 29 + + + + + 7 + + + + + font-weight: bold; +font-size: 20px; + + + HTH World Chat + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 60 + 20 + + + + + + + + + + 185 + 210 + 151 + 22 + + + + + + + + + + 80 + 210 + 81 + 21 + + + + Nickname: + + + + + + 185 + 275 + 151 + 41 + + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + Click to Connect + + + + + + 140 + 142 + 251 + 25 + + + + <html><head/><body><p><span style=" font-weight:600;">Connect to #HTHWorld TrollBox</span></p></body></html> + + + Qt::AlignCenter + + + + + + 200 + 380 + 231 + 61 + + + + <html><head/><body><p>Enter your Nick</p><p>Enter #HTHWorld as Channel</p></body></html> + + + + + + 30 + 400 + 120 + 30 + + + + + 100 + 30 + + + + + 120 + 30 + + + + Visit HTH World Web Chat + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + #HTHWorld + + + + + + Quitter + + + Ctrl+Q + + + + + Fermer l'onglet + + - - serverLineEdit - userLineEdit - loginButton - roomTextEdit - userListWidget - sayLineEdit - sayButton - + - - - sayLineEdit - returnPressed() - sayButton - animateClick() - - - 331 - 564 - - - 768 - 570 - - - - - serverLineEdit - returnPressed() - userLineEdit - setFocus() - - - 391 - 188 - - - 470 - 238 - - - - - userLineEdit - returnPressed() - loginButton - animateClick() - - - 417 - 239 - - - 389 - 275 - - - - + From 302ff88d9ad8d8000081fd206c1843a34d804ece Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:33:16 -0400 Subject: [PATCH 0246/1324] Update serveur.cpp --- src/qt/serveur.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp index 8178aec1..33bb5f8f 100644 --- a/src/qt/serveur.cpp +++ b/src/qt/serveur.cpp @@ -54,6 +54,7 @@ void Serveur::connected() sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); sendData("NICK "+pseudo); affichage->append("Connected to HTHWorld IRC."); + affichage->append("Please wait for #HTHWorld Chat Box to Appear before chatting! "); } From b86b83d6753ade482716e3b793f1e24c39d40889 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:34:44 -0400 Subject: [PATCH 0247/1324] Update serveur.cpp --- src/qt/serveur.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp index 33bb5f8f..4b0f7eeb 100644 --- a/src/qt/serveur.cpp +++ b/src/qt/serveur.cpp @@ -54,7 +54,7 @@ void Serveur::connected() sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); sendData("NICK "+pseudo); affichage->append("Connected to HTHWorld IRC."); - affichage->append("Please wait for #HTHWorld Chat Box to Appear before chatting! "); + affichage->append("Please wait for #HTHWorld Chat Box to Appear Before Chatting! "); } From 2946f61ea047c4554a60bdde31177141062eb6a3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:36:38 -0400 Subject: [PATCH 0248/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 87bff742..0bfebbb9 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -157,8 +157,8 @@ void ChatWindowPage::connecte() QTextEdit *textEdit=new QTextEdit; ui->hide3->hide(); - ui->tab->addTab(textEdit,"Console/PM"); - ui->tab->setTabToolTip(ui->tab->count()-1,"irc.freenode.net"); + ui->tab->addTab(textEdit,"Not a Chat"); + ui->tab->setTabToolTip(ui->tab->count()-1,"HTH World Chat"); // current tab is now the last, therefore remove all but the last for (int i = ui->tab->count(); i > 1; --i) { ui->tab->removeTab(0); From 3187abd6324061a612084a56ba78510630fa0ae2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 8 Jun 2020 21:39:01 -0400 Subject: [PATCH 0249/1324] Update chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp index 0bfebbb9..ad337cb9 100644 --- a/src/qt/chatwindowpage.cpp +++ b/src/qt/chatwindowpage.cpp @@ -158,16 +158,16 @@ void ChatWindowPage::connecte() ui->hide3->hide(); ui->tab->addTab(textEdit,"Not a Chat"); - ui->tab->setTabToolTip(ui->tab->count()-1,"HTH World Chat"); + ui->tab->setTabToolTip(ui->tab->count()-1,"Not a Chat"); // current tab is now the last, therefore remove all but the last for (int i = ui->tab->count(); i > 1; --i) { ui->tab->removeTab(0); } - serveurs.insert("irc.freenode.net",serveur); + serveurs.insert("HTH World Chat",serveur); serveur->pseudo=ui->editPseudo->text(); - serveur->serveur="irc.freenode.net"; + serveur->serveur="HTH World Chat"; /* irc.freenode.net */ serveur->port=6667; serveur->affichage=textEdit; serveur->tab=ui->tab; From 8dcded1cec2d496bf8611526e38a464d48241bbe Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:41:32 -0400 Subject: [PATCH 0250/1324] Delete chatwindowpage.ui --- src/qt/forms/chatwindowpage.ui | 323 --------------------------------- 1 file changed, 323 deletions(-) delete mode 100644 src/qt/forms/chatwindowpage.ui diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui deleted file mode 100644 index 663f0ba3..00000000 --- a/src/qt/forms/chatwindowpage.ui +++ /dev/null @@ -1,323 +0,0 @@ - - - ChatWindowPage - - - - 0 - 0 - 878 - 692 - - - - - - 0 - 50 - 851 - 611 - - - - - true - - - - 10 - 10 - 721 - 501 - - - - - - - - - 10 - 0 - 541 - 451 - - - - - - - QTabWidget::Rounded - - - 1 - - - false - - - - Tab 1 - - - - - Tab 2 - - - - - - - 10 - 460 - 701 - 30 - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - - - - 560 - 20 - 161 - 391 - - - - - 0 - 300 - - - - border-radius:10px; - - - - - - 595 - 420 - 100 - 30 - - - - - 100 - 30 - - - - - 100 - 30 - - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - Leave - - - - - - - 10 - 10 - 851 - 671 - - - - - - 179 - 40 - 241 - 29 - - - - - 7 - - - - - font-weight: bold; -font-size: 20px; - - - HTH World Chat - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 60 - 20 - - - - - - - - - - 185 - 210 - 151 - 22 - - - - - - - - - - 80 - 210 - 81 - 21 - - - - Nickname: - - - - - - 185 - 275 - 151 - 41 - - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - Click to Connect - - - - - - 140 - 142 - 251 - 25 - - - - <html><head/><body><p><span style=" font-weight:600;">Connect to #HTHWorld TrollBox</span></p></body></html> - - - Qt::AlignCenter - - - - - - 200 - 380 - 231 - 61 - - - - <html><head/><body><p>Enter your Nick</p><p>Enter #HTHWorld as Channel</p></body></html> - - - - - - 30 - 400 - 120 - 30 - - - - - 100 - 30 - - - - - 120 - 30 - - - - Visit HTH World Web Chat - - - border-style: solid; -border-width: 2px; -border-color: #34bcaa; -border-radius: 10px; -font-size: 11px; - - - #HTHWorld - - - - - - - Quitter - - - Ctrl+Q - - - - - Fermer l'onglet - - - - - - - From 0b1c7d53a83e6424235c7e3ad2747d27f733cbf1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:41:53 -0400 Subject: [PATCH 0251/1324] Delete chatwindowpage.cpp --- src/qt/chatwindowpage.cpp | 231 -------------------------------------- 1 file changed, 231 deletions(-) delete mode 100644 src/qt/chatwindowpage.cpp diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp deleted file mode 100644 index ad337cb9..00000000 --- a/src/qt/chatwindowpage.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ - -#include "chatwindowpage.h" -#include "ui_chatwindowpage.h" - -#include -#include -#include -#include -#include -#include - -ChatWindowPage::ChatWindowPage(QWidget *parent) - : QWidget(parent), ui(new Ui::ChatWindowPage) -{ - ui->setupUi(this); - setFixedSize(750,600); - ui->splitter->hide(); - - connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(connecte())); - - connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); - connect(ui->actionCloseTab, SIGNAL(triggered()), this, SLOT(closeTab())); - - connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(sendCommande())); - - - ui->pushButton_WebChat->setStatusTip(tr("Visit Help The Homeless Worldwide Web Chat")); - - - - - - connect(ui->disconnect, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); - connect(ui->tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); - connect(ui->tab, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosing(int)) ); - -} - - - -void ChatWindowPage::tabChanged(int index) -{ - if(index!=0 && joining == false) - currentTab()->updateUsersList(ui->tab->tabText(index)); -} - -void ChatWindowPage::tabClosing(int index) -{ - currentTab()->leave(ui->tab->tabText(index)); -} -/*void ChatWindow::tabRemoved(int index) -{ - currentTab()->leave(ui->tab->tabText(index)); -}*/ - -void ChatWindowPage::disconnectFromServer() { - - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } - } - - - ui->splitter->hide(); - ui->hide3->show(); - -} - -Serveur *ChatWindowPage::currentTab() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - return serveurs[tooltip]; - //return ui->tab->currentWidget()->findChild(); -} - -void ChatWindowPage::closeTab() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - QString txt=ui->tab->tabText(ui->tab->currentIndex()); - - if(txt==tooltip) - { - QMapIterator i(serveurs[tooltip]->conversations); - - int count=ui->tab->currentIndex()+1; - - while(i.hasNext()) - { - i.next(); - ui->tab->removeTab(count); - } - - currentTab()->abort(); - ui->tab->removeTab(ui->tab->currentIndex()); - } - else - { - - ui->tab->removeTab(ui->tab->currentIndex()); - currentTab()->conversations.remove(txt); - } -} - -void ChatWindowPage::sendCommande() -{ - QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); - QString txt=ui->tab->tabText(ui->tab->currentIndex()); - if(txt==tooltip) - { - currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text(),true) ); - } - else - { - currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text()) ); - } - ui->lineEdit->clear(); - ui->lineEdit->setFocus(); -} - -void ChatWindowPage::tabJoined() -{ - joining=true; -} -void ChatWindowPage::tabJoining() -{ - joining=false; -} - -void ChatWindowPage::connecte() -{ - - ui->splitter->show(); - Serveur *serveur=new Serveur; - QTextEdit *textEdit=new QTextEdit; - ui->hide3->hide(); - - ui->tab->addTab(textEdit,"Not a Chat"); - ui->tab->setTabToolTip(ui->tab->count()-1,"Not a Chat"); - // current tab is now the last, therefore remove all but the last - for (int i = ui->tab->count(); i > 1; --i) { - ui->tab->removeTab(0); - } - - serveurs.insert("HTH World Chat",serveur); - - serveur->pseudo=ui->editPseudo->text(); - serveur->serveur="HTH World Chat"; /* irc.freenode.net */ - serveur->port=6667; - serveur->affichage=textEdit; - serveur->tab=ui->tab; - serveur->userList=ui->userView; - serveur->parent=this; - - textEdit->setReadOnly(true); - - connect(serveur, SIGNAL(joinTab()),this, SLOT(tabJoined() )); - connect(serveur, SIGNAL(tabJoined()),this, SLOT(tabJoining() )); - - serveur->connectToHost("irc.freenode.net",6667); - - ui->tab->setCurrentIndex(ui->tab->count()-1); -} - -void ChatWindowPage::closeEvent(QCloseEvent *event) -{ - (void) event; - - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } - } -} -void ChatWindowPage ::setModel(ClientModel *model) -{ - this->model = model; -} - -void ChatWindowPage::on_pushButton_WebChat_clicked() { // #HTHWorld Chat - - QDesktopServices::openUrl(QUrl("https://webchat.freenode.net//", QUrl::TolerantMode)); - -} - - -ChatWindowPage::~ChatWindowPage() -{ - delete ui; - QMapIterator i(serveurs); - - while(i.hasNext()) - { - i.next(); - QMapIterator i2(i.value()->conversations); - while(i2.hasNext()) - { - i2.next(); - i.value()->sendData("QUIT "+i2.key() + " "); - } - } -} From b4b064f12e4b7ecf830297a3d76a04468111d80b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:42:02 -0400 Subject: [PATCH 0252/1324] Delete chatwindowpage.h --- src/qt/chatwindowpage.h | 73 ----------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/qt/chatwindowpage.h diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h deleted file mode 100644 index 2beba14b..00000000 --- a/src/qt/chatwindowpage.h +++ /dev/null @@ -1,73 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ - -#ifndef CHATWINDOWPAGE_H -#define CHATWINDOWPAGE_H - -#include -#include -#include "clientmodel.h" -#include "serveur.h" - -#include -#include -#include - - - -namespace Ui -{ - class ChatWindowPage; -} - -class ChatWindowPage : public QWidget -{ - Q_OBJECT - -public: - ChatWindowPage(QWidget *parent = 0); - ~ChatWindowPage(); - void setModel(ClientModel *model); - Serveur * currentTab(); - Q_SIGNALS: - void changeTab(); - - public Q_SLOTS: - void sendCommande(); - void connecte(); - void closeTab(); - - void tabChanged(int index); - - void tabJoined(); - void tabJoining(); - void disconnectFromServer(); - void tabClosing(int index); - - -private: - Ui::ChatWindowPage *ui; - ClientModel *model; - QMap serveurs; - bool joining; - void closeEvent(QCloseEvent *event); - -private Q_SLOTS: - void on_pushButton_WebChat_clicked(); - -}; - -#endif // CHATWINDOWPAGE_H From 5a5048aeaa58e15490a79fd36cb001d9d2be5c07 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:42:12 -0400 Subject: [PATCH 0253/1324] Delete main.cpp --- src/qt/main.cpp | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp deleted file mode 100644 index fa767a05..00000000 --- a/src/qt/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "chatterboxserver.h" -#include - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - - ChatterBoxServer *server = new ChatterBoxServer(); - bool success = server->listen(QHostAddress::Any, 4200); - if(!success) - { - qFatal("Could not listen on port 4200."); - } - - qDebug() << "Ready"; - - return app.exec(); -} From c8f97005fbce270f913fc6a4bce687de6f984ccc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:42:26 -0400 Subject: [PATCH 0254/1324] Delete mainchat.cpp --- src/qt/mainchat.cpp | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/qt/mainchat.cpp diff --git a/src/qt/mainchat.cpp b/src/qt/mainchat.cpp deleted file mode 100644 index 3283ca9d..00000000 --- a/src/qt/mainchat.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "chatwindowpage.h" -#include - -/* - * This is your main() function. Very simple. - */ -int main(int argc, char **argv) -{ - // Every Qt GUI needs a QApplication. - QApplication app(argc, argv); - - // This is your MainWindow that you created with Designer - // Declare it and show it. - ChatWindowPage chatWindowPage; - chatWindowPage.show(); - - // This will not return until the last window is closed. - // This runs the GUI's event loop handling painting and - // user input and stuff like that. - return app.exec(); -} From 1b3ae9533d216ddf5faebd7a16085c5ce0515d9e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:42:43 -0400 Subject: [PATCH 0255/1324] Delete serveur.cpp --- src/qt/serveur.cpp | 360 --------------------------------------------- 1 file changed, 360 deletions(-) delete mode 100644 src/qt/serveur.cpp diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp deleted file mode 100644 index 4b0f7eeb..00000000 --- a/src/qt/serveur.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ -#include -#include "serveur.h" - QStringList users; - bool delist = true; -Serveur::Serveur() -{ - connect(this, SIGNAL(readyRead()), this, SLOT(readServeur())); - connect(this, SIGNAL(connected()), this, SLOT(connected())); - connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorSocket(QAbstractSocket::SocketError))); - - updateUsers=false; -} - - - - -void Serveur::errorSocket(QAbstractSocket::SocketError error) -{ - switch(error) - { - case QAbstractSocket::HostNotFoundError: - affichage->append(tr("ERROR : can't find HTHWorld server.")); - break; - case QAbstractSocket::ConnectionRefusedError: - affichage->append(tr("ERROR : server refused connection")); - break; - case QAbstractSocket::RemoteHostClosedError: - affichage->append(tr("ERROR : server cut connection")); - break; - default: - affichage->append(tr("ERROR : ") + this->errorString() + tr("")); - } -} - -void Serveur::connected() -{ - affichage->append("Connecting... to HTHWorld IRC. Please wait."); - - sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); - sendData("NICK "+pseudo); - affichage->append("Connected to HTHWorld IRC."); - affichage->append("Please wait for #HTHWorld Chat Box to Appear Before Chatting! "); - -} - -void Serveur::joins() -{ - join("#HTHWorld"); -} - -void Serveur::readServeur() -{ - QString message=QString::fromUtf8(this->readAll()); - - - QString currentChan=tab->tabText(tab->currentIndex()); - - if(message.startsWith("PING :")) - { - QStringList liste=message.split(" "); - QString msg="PONG "+liste.at(1); - sendData(msg); - } - else if(message.contains("Nickname is already in use.")) - { - pseudo=pseudo+"_2"; - pseudo.remove("\r\n"); - sendData("NICK "+pseudo); - Q_EMIT pseudoChanged(pseudo); - ecrire("-> Name changed to "+pseudo); - } - else if(updateUsers==true) - { - updateUsersList("",message); - } - - QStringList list=message.split("\r\n"); - Q_FOREACH(QString msg,list) - { - if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 <\\1> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 join \\2
"),"",msg2.replace(reg,"-> \\1 join \\2")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 quit \\2 (\\3)
"),"",msg2.replace(reg,"-> \\1 quit \\2")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 quit this server (\\2)
"),"",msg2.replace(reg,"-> \\1 left")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\1 is now called \\2
"),"",msg2.replace(reg,"-> \\1 is now called \\2")); - updateUsersList(currentChan); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) - { - QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); - QString msg2=msg; - ecrire(msg.replace(reg,"\\2 -> \\1 kicked \\3 (\\4)
"),"",msg2.replace(reg,"-> \\1 quit \\3")); - updateUsersList(msg.replace(reg,"\\2")); - } - else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) - { - if(conversations.contains(currentChan)) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); - ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
"),currentChan); - } - else if(currentChan==serveur) - { - QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); - ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
")); - } - } - else if(msg.contains("/MOTD command.")) - { - joins(); - - - } - - - - } - - //} -} - -void Serveur::sendData(QString txt) -{ - if(this->state()==QAbstractSocket::ConnectedState) - { - this->write((txt+"\r\n").toUtf8()); - } -} - -QString Serveur::parseCommande(QString comm,bool serveur) -{ - if(comm.startsWith("/")) - { - comm.remove(0,1); - QString pref=comm.split(" ").first(); - QStringList args=comm.split(" "); - args.removeFirst(); - QString destChan=tab->tabText(tab->currentIndex()); - QString msg=args.join(" "); - - if(pref=="me") - return "PRIVMSG "+destChan+" ACTION " + msg + ""; - else if(pref=="msg") - return "MSG "+destChan+" ACTION " + msg + ""; - else if(pref=="join") - { - join(msg); - return " "; - } - else if(pref=="quit") - { - if(msg == "") - return "QUIT "+msgQuit; - else - return "QUIT "+msg; - } - else if(pref=="part") - { - tab->removeTab(tab->currentIndex()); - - if(msg == "") - { - if(msg.startsWith("#")) - destChan=msg.split(" ").first(); - - if(msgQuit=="") - return "PART "+destChan+" using IrcLightClient"; - else - return "PART "+destChan+" "+msgQuit; - } - else - return "PART "+destChan+" "+msg; - - conversations.remove(destChan); - } - else if(pref=="kick") - { - QStringList tableau=msg.split(" "); - QString c1,c2,c3; - if(tableau.count() > 0) c1=" "+tableau.first(); - else c1=""; - if(tableau.count() > 1) c2=" "+tableau.at(1); - else c2=""; - if(tableau.count() > 2) c3=" "+tableau.at(2); - else c3=""; - - if(c1.startsWith("#")) - return "KICK"+c1+c2+c3; - else - return "KICK "+destChan+c1+c2; - } - else if(pref=="update") - { - updateUsers=true; - return "WHO "+destChan; - } - else if(pref=="ns") - { - return "NICKSERV "+msg; - } - else if(pref=="nick") - { - Q_EMIT pseudoChanged(msg); - ecrire("-> Nickname changed to "+msg); - return "NICK "+msg; - } - else if(pref=="msg") - { - return "MSG "+msg; - } - - else - return pref+" "+msg; - } - else if(!serveur) - { - QString destChan=tab->tabText(tab->currentIndex()); - if(comm.endsWith("
")) - comm=comm.remove(QRegExp("
$")); - ecrire("<"+pseudo+"> "+comm,destChan); - - if(comm.startsWith(":")) - comm.insert(0,":"); - - return "PRIVMSG "+destChan+" "+comm.replace(" ","\t"); - } - else - { - return ""; - } -} - -void Serveur::join(QString chan) -{ - affichage->append("Joining "+ chan +" channel"); - Q_EMIT joinTab(); - QTextEdit *textEdit=new QTextEdit; - int index=tab->insertTab(tab->currentIndex()+1,textEdit,chan); - tab->setTabToolTip(index,serveur); - tab->setCurrentIndex(index); - - textEdit->setReadOnly(true); - - conversations.insert(chan,textEdit); - - sendData("JOIN "+chan); - - Q_EMIT tabJoined(); -} -void Serveur::leave(QString chan) -{ - sendData(parseCommande("/part "+chan+ " "+msgQuit)); -} - -void Serveur::ecrire(QString txt,QString destChan,QString msgTray) -{ - if(destChan!="") - { - conversations[destChan]->setHtml(conversations[destChan]->toHtml()+txt); - QScrollBar *sb = conversations[destChan]->verticalScrollBar(); - sb->setValue(sb->maximum()); - } - else if(txt.startsWith("#")) - { - QString dest=txt.split(" ").first(); - QStringList list=txt.split(" "); - list.removeFirst(); - txt=list.join(" "); - conversations[dest]->setHtml(conversations[dest]->toHtml()+txt); - QScrollBar *sb = conversations[dest]->verticalScrollBar(); - sb->setValue(sb->maximum()); } - else - { - txt.replace("\r\n","
"); - affichage->setHtml(affichage->toHtml()+txt+"
"); - QScrollBar *sb = affichage->verticalScrollBar(); - sb->setValue(sb->maximum()); - } - - -} - -void Serveur::updateUsersList(QString chan,QString message) -{ - message = message.replace("\r\n",""); - message = message.replace("\r",""); - if(chan!=serveur) - { - if(updateUsers==true || message != "") - { - QString liste2=message.replace(":",""); - QStringList liste=liste2.split(" "); - - if (delist == true) users.clear(); - - for(int i=5; i < liste.count(); i++) - { - users.append(liste.at(i)); - } - updateUsers=false; - if (liste.count() < 53) delist = true; - else delist = false; - QStringListModel *model = new QStringListModel(users); - userList->setModel(model); - userList->update(); - } - else - { - updateUsers=true; - sendData("NAMES "+chan); - } - } - else - { - QStringListModel model; - userList->setModel(&model); - userList->update(); - } -} From d5d9811d77ddf5677f26ecbeea82e304f99afcff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:42:52 -0400 Subject: [PATCH 0256/1324] Delete serveur.h --- src/qt/serveur.h | 67 ------------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 src/qt/serveur.h diff --git a/src/qt/serveur.h b/src/qt/serveur.h deleted file mode 100644 index 9d2f6270..00000000 --- a/src/qt/serveur.h +++ /dev/null @@ -1,67 +0,0 @@ -/*Copyright (C) 2009 Cleriot Simon -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ - -#ifndef SERVEUR_H -#define SERVEUR_H - -#include -#include -#include -#include -#include -#include - -class Serveur : public QTcpSocket -{ - Q_OBJECT - - public: - Serveur(); - QTextEdit *affichage; - QListView *userList; - QString pseudo,serveur,msgQuit; - int port; - QTabWidget *tab; - QMap conversations; - QSystemTrayIcon *tray; - - bool updateUsers; - - QString parseCommande(QString comm,bool serveur=false); - - QWidget *parent; - - - Q_SIGNALS: - void pseudoChanged(QString newPseudo); - void joinTab(); - void tabJoined(); - - public Q_SLOTS: - void readServeur(); - void errorSocket(QAbstractSocket::SocketError); - void connected(); - void joins(); - void sendData(QString txt); - void join(QString chan); - void leave(QString chan); - void ecrire(QString txt,QString destChan="",QString msgTray=""); - void updateUsersList(QString chan="",QString message=""); - - //void tabChanged(int index); -}; - -#endif // SERVEUR_H From f431b16f78ae39d94fae098446aed0f2e04302f8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:47:09 -0400 Subject: [PATCH 0257/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 3cbdbb39..6de4d124 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -23,7 +23,7 @@ #include "rpcconsole.h" #include "utilitydialog.h" /* #include "tradingdialogpage.h" */ -#include "chatwindowpage.h" + #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - chatWindowPage(0), + loginPage(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -620,8 +620,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); - chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); + loginPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + loginPage->setStatusTip(tr("HTH World Social Media")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -637,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); + connect(loginPage, SIGNAL(triggered()), this, SLOT(gotoLoginPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -739,8 +739,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); - chat->addAction(chatWindowPage); + QMenu* media = appMenuBar->addMenu(tr("&HTH World")); + media->addAction(loginPage); } @@ -1069,10 +1069,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoChatWindowPage() +void BitcoinGUI::gotoLoginPage() { - chatWindowPage->setChecked(true); - if (walletFrame) walletFrame->gotoChatWindowPage(); + loginPage->setChecked(true); + if (walletFrame) walletFrame->gotoLoginPage(); } /*void BitcoinGUI::gotoTradingDialogPage() From c6dbd0dc3e29983ab836014248eb45dc5aeebc09 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:47:57 -0400 Subject: [PATCH 0258/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 8e0966f3..c22773c2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class ChatWindowPage; +class LoginPage; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* chatWindowPage; + QAction* loginPage; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -235,8 +235,8 @@ private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to chat page */ - void gotoChatWindowPage(); + /** Switch to social media page */ + void gotoLoginPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From e711f74f8c70cb28ba545730d25b23b6ac185db6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:48:21 -0400 Subject: [PATCH 0259/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6de4d124..641e51d5 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,6 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +#include "loginpage.h" /* #include "tradingdialogpage.h" */ From cbfcc02948743080145fbb0de8c039b10c26a105 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:48:59 -0400 Subject: [PATCH 0260/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 035ad36c..bb669e31 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoChatWindowPage() +void WalletFrame::gotoLoginPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoChatWindowPage(); + i.value()->gotoLoginPage(); } /*void WalletFrame::gotoTradingDialogPage() From 2c48253a6271f971ad8eed626547786f74b20364 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:49:26 -0400 Subject: [PATCH 0261/1324] Update walletframe.h --- src/qt/walletframe.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 982f6690..9d4e3010 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,8 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to chat page */ - void gotoChatWindowPage(); + /** Switch to social media page */ + void gotoLoginPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ff17bf81d43c62e2fede3fbfde6ba0095c3e044d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:50:34 -0400 Subject: [PATCH 0262/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 47cd79f3..c1cb1d50 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - chatWindowPage = new ChatWindowPage(); - addWidget(chatWindowPage); + loginPage = new LoginPage(); + addWidget(loginPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -241,9 +241,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoChatWindowPage() +void WalletView::gotoLoginPage() { - setCurrentWidget(chatWindowPage); + setCurrentWidget(loginPage); } /*void WalletView::gotoTradingDialogPage() From 35e7895114071b4b802d2763a679e4632e39b6dc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:51:22 -0400 Subject: [PATCH 0263/1324] Update walletview.h --- src/qt/walletview.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 63463dcc..4c4915e1 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,7 +9,7 @@ #include "masternodelist.h" #include "governancelist.h" /* #include "tradingdialogpage.h" */ -#include "chatwindowpage.h" +#include "loginpage.h" @@ -28,7 +28,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class ChatWindowPage; +class LoginPage; QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - ChatWindowPage *chatWindowPage; + LoginPage *loginPage; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -88,8 +88,8 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to chat page */ - void gotoChatWindowPage(); + /** Switch to social media page */ + void gotoLoginPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ca18d07c9ab6e164655914875903541c450734a7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:53:11 -0400 Subject: [PATCH 0264/1324] Add files via upload --- src/qt/forms/homepage.ui | 503 ++++++++++++++++++++++++++++++++++++ src/qt/forms/loginpage.ui | 104 ++++++++ src/qt/forms/mainwindow.ui | 83 ++++++ src/qt/forms/profilepage.ui | 18 ++ src/qt/forms/signuppage.ui | 310 ++++++++++++++++++++++ 5 files changed, 1018 insertions(+) create mode 100644 src/qt/forms/homepage.ui create mode 100644 src/qt/forms/loginpage.ui create mode 100644 src/qt/forms/mainwindow.ui create mode 100644 src/qt/forms/profilepage.ui create mode 100644 src/qt/forms/signuppage.ui diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui new file mode 100644 index 00000000..53e629fc --- /dev/null +++ b/src/qt/forms/homepage.ui @@ -0,0 +1,503 @@ + + + homepage + + + + 0 + 0 + 700 + 600 + + + + Profile Page + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + + + 10 + 20 + 371 + 31 + + + + Welcome User + + + + + + 10 + 60 + 681 + 531 + + + + 0 + + + + Home + + + + + 9 + 29 + 331 + 451 + + + + true + + + + + 0 + 0 + 329 + 449 + + + + + + + + 10 + 10 + 121 + 16 + + + + NewsFeed + + + + + + 370 + 30 + 261 + 201 + + + + + + + What is on your mind? + + + + + + + + + + Post + + + + + + + + + Profile + + + + + 310 + 320 + 335 + 34 + + + + + + + Save Changes + + + + + + + Remove Account + + + + + + + + + 10 + 262 + 421 + 24 + + + + font-family:sans-serif; +font-size:15px; +font-weight:none; +color:#545454; + + + Note: You can only update your password or country + + + + + + 125 + 154 + 235 + 30 + + + + + + + 125 + 190 + 235 + 30 + + + + + + + 10 + 10 + 109 + 24 + + + + First Name + + + + + + 10 + 82 + 102 + 24 + + + + Username + + + + + + 125 + 118 + 235 + 30 + + + + + + + 125 + 46 + 235 + 30 + + + + + + + 10 + 226 + 80 + 24 + + + + Country + + + + + + 125 + 82 + 235 + 30 + + + + + + + 125 + 226 + 235 + 30 + + + + + + + 125 + 10 + 235 + 30 + + + + + + + 10 + 118 + 97 + 24 + + + + Password + + + + + + 10 + 154 + 74 + 24 + + + + Gender + + + + + + 10 + 46 + 105 + 24 + + + + Last Name + + + + + + 10 + 190 + 87 + 24 + + + + Birthday + + + + + + Search + + + + + 20 + 10 + 581 + 21 + + + + Search for people, enter their name or search by country + + + + + + 30 + 80 + 321 + 401 + + + + + + + 390 + 250 + 231 + 41 + + + + Send Friend Request + + + + + + 20 + 40 + 361 + 34 + + + + + + + + + + Search + + + + + + + + + Notifications + + + + + 90 + 50 + 411 + 351 + + + + + + + 160 + 20 + 281 + 21 + + + + Here are your notifications + + + + + + 170 + 410 + 261 + 51 + + + + + + + Accept + + + + + + + Ignore + + + + + + + + + Friends + + + + + 30 + 20 + 321 + 31 + + + + List of Friends + + + + + + 30 + 60 + 301 + 411 + + + + + + + 380 + 200 + 211 + 61 + + + + Remove Friend + + + + + + + + 564 + 20 + 111 + 41 + + + + Logout + + + + + + diff --git a/src/qt/forms/loginpage.ui b/src/qt/forms/loginpage.ui new file mode 100644 index 00000000..2eb1fa62 --- /dev/null +++ b/src/qt/forms/loginpage.ui @@ -0,0 +1,104 @@ + + + LoginPage + + + + 0 + 0 + 700 + 600 + + + + Login + + + + + 130 + 70 + 431 + 271 + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Login + + + + + + + + username + + + + + + + + + + password + + + + + + + QLineEdit::Password + + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Back + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Login + + + + + + + + + + lineEdit_username + lineEdit_password + pushButton_login + pushButton_back + + + + diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui new file mode 100644 index 00000000..ea8dbe08 --- /dev/null +++ b/src/qt/forms/mainwindow.ui @@ -0,0 +1,83 @@ + + + MainWindow + + + + 0 + 0 + 700 + 600 + + + + Social Media App + + + + + + + Qt::LeftToRight + + + <html><head/><body><p align="center"><span style=" font-size:24pt; font-weight:600;">Connect with Friends and Family</span></p></body></html> + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Signup + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Login + + + + + + + + + + + 0 + 0 + 700 + 21 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui new file mode 100644 index 00000000..f80edc63 --- /dev/null +++ b/src/qt/forms/profilepage.ui @@ -0,0 +1,18 @@ + + profilepage + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + diff --git a/src/qt/forms/signuppage.ui b/src/qt/forms/signuppage.ui new file mode 100644 index 00000000..9ea4354b --- /dev/null +++ b/src/qt/forms/signuppage.ui @@ -0,0 +1,310 @@ + + + SignUpPage + + + + 0 + 0 + 700 + 600 + + + + Sign Up + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + + + 16 + 251 + 87 + 24 + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Birthday + + + + + + 15 + 289 + 80 + 24 + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Country + + + + + + 110 + 290 + 171 + 30 + + + + + + + 360 + 400 + 321 + 34 + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Create Account + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Back + + + + + + + + + 11 + 332 + 255 + 30 + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Gender + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Female + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Male + + + + + + + + + 10 + 60 + 621 + 170 + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + First Name + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Last Name + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Username + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Password + + + + + + + + + + font-size:15px; +font-weight:none; + + + + Use at least 6 charaster. Must include a number and a capital letter + + + + + + + + + 112 + 251 + 521 + 32 + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Month + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Date + + + + + + + + + + font-family:sans-serif; +font-size:20px; +font-weight:bold; +color:#545454; + + + Year + + + + + + + + + + + + From 5cadb308d799c79c3834c842629fa687407b00d3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:55:24 -0400 Subject: [PATCH 0265/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 641e51d5..5d39b1d1 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "loginpage.h" +#include "mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - loginPage(0), + mainWindow(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -621,8 +621,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - loginPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - loginPage->setStatusTip(tr("HTH World Social Media")); + mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + mainWindow->setStatusTip(tr("HTH World Social Media")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -638,7 +638,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(loginPage, SIGNAL(triggered()), this, SLOT(gotoLoginPage())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -741,7 +741,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(loginPage); + media->addAction(mainWindow); } @@ -1070,10 +1070,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoLoginPage() +void BitcoinGUI::gotoMainWindow() { - loginPage->setChecked(true); - if (walletFrame) walletFrame->gotoLoginPage(); + mainWindow->setChecked(true); + if (walletFrame) walletFrame->gotoMainWindow(); } /*void BitcoinGUI::gotoTradingDialogPage() From f2870fe7682b1ad6fb29604207f9ffa2384aaf97 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:56:08 -0400 Subject: [PATCH 0266/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index c22773c2..a2e6b772 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class LoginPage; +class MainWindow; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* loginPage; + QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoLoginPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From a8a2f043939894aac0d8f8f81c8d7cf0c98a18af Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:56:34 -0400 Subject: [PATCH 0267/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index bb669e31..a170c85a 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoLoginPage() +void WalletFrame::gotoMainWindow() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoLoginPage(); + i.value()->gotoMainWindow(); } /*void WalletFrame::gotoTradingDialogPage() From e2f0a6aecc95f50e46839fa32153c54cc276e8ca Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:56:49 -0400 Subject: [PATCH 0268/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 9d4e3010..a6eb3ece 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to social media page */ - void gotoLoginPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ac4a32dc6543c1897c744348f8dab3dbc756d9dc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:57:35 -0400 Subject: [PATCH 0269/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index c1cb1d50..f912151d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -88,8 +88,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - loginPage = new LoginPage(); - addWidget(loginPage); + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -241,9 +241,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoLoginPage() +void WalletView::gotoMainWindow() { - setCurrentWidget(loginPage); + setCurrentWidget(mainWindow); } /*void WalletView::gotoTradingDialogPage() From b12f8312f79d8454ca12bb935f8f12332556992c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:58:07 -0400 Subject: [PATCH 0270/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 4c4915e1..40ca8074 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,7 +9,7 @@ #include "masternodelist.h" #include "governancelist.h" /* #include "tradingdialogpage.h" */ -#include "loginpage.h" +#include "mainwindow.h" @@ -28,7 +28,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class LoginPage; +class MainWindow; QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - LoginPage *loginPage; + MainWindow *mainWindow; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -89,7 +89,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to social media page */ - void gotoLoginPage(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 7fd0916160fe6fb5567f6ef1d468d8ceaa11f939 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:59:29 -0400 Subject: [PATCH 0271/1324] Add files via upload --- src/qt/SocialMediaApp.pro | 45 + src/qt/SocialMediaApp.pro.user | 1294 +++++++++++++++++++++++++++++ src/qt/homepage.cpp | 593 +++++++++++++ src/qt/homepage.h | 64 ++ src/qt/loginpage.cpp | 73 ++ src/qt/loginpage.h | 29 + src/qt/main.cpp | 11 + src/qt/mainwindow.cpp | 53 ++ src/qt/mainwindow.h | 39 + src/qt/profilepage.cpp | 14 + src/qt/profilepage.h | 22 + src/qt/signuppage.cpp | 146 ++++ src/qt/signuppage.h | 29 + src/qt/socialMediaUsers.db | Bin 0 -> 45056 bytes src/qt/socialMediaUsers.db.sqbpro | 1 + 15 files changed, 2413 insertions(+) create mode 100644 src/qt/SocialMediaApp.pro create mode 100644 src/qt/SocialMediaApp.pro.user create mode 100644 src/qt/homepage.cpp create mode 100644 src/qt/homepage.h create mode 100644 src/qt/loginpage.cpp create mode 100644 src/qt/loginpage.h create mode 100644 src/qt/main.cpp create mode 100644 src/qt/mainwindow.cpp create mode 100644 src/qt/mainwindow.h create mode 100644 src/qt/profilepage.cpp create mode 100644 src/qt/profilepage.h create mode 100644 src/qt/signuppage.cpp create mode 100644 src/qt/signuppage.h create mode 100644 src/qt/socialMediaUsers.db create mode 100644 src/qt/socialMediaUsers.db.sqbpro diff --git a/src/qt/SocialMediaApp.pro b/src/qt/SocialMediaApp.pro new file mode 100644 index 00000000..286d5ca3 --- /dev/null +++ b/src/qt/SocialMediaApp.pro @@ -0,0 +1,45 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-01-13T14:05:16 +# +#------------------------------------------------- + +QT += core gui sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = SocialMediaApp +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + signuppage.cpp \ + loginpage.cpp \ + homepage.cpp + +HEADERS += \ + mainwindow.h \ + signuppage.h \ + loginpage.h \ + homepage.h + +FORMS += \ + mainwindow.ui \ + signuppage.ui \ + loginpage.ui \ + homepage.ui + +RESOURCES += diff --git a/src/qt/SocialMediaApp.pro.user b/src/qt/SocialMediaApp.pro.user new file mode 100644 index 00000000..5b3e4530 --- /dev/null +++ b/src/qt/SocialMediaApp.pro.user @@ -0,0 +1,1294 @@ + + + + + + EnvironmentId + {82cecebb-8435-428b-8825-945651098afd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.6.2 MinGW 32bit + Desktop Qt 5.6.2 MinGW 32bit + qt.56.win32_mingw49_kit + 0 + 0 + 0 + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + SocialMediaApp + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/carlo/Documents/Qt Projects/SocialMediaApp/SocialMediaApp.pro + true + + SocialMediaApp.pro + false + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.6.2 MSVC2013 32bit + Desktop Qt 5.6.2 MSVC2013 32bit + qt.56.win32_msvc2013_kit + 0 + 0 + 0 + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.2 + + Desktop Qt 5.6.2 MSVC2013 64bit + Desktop Qt 5.6.2 MSVC2013 64bit + qt.56.win64_msvc2013_64_kit + 0 + 0 + 0 + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.3 + + Desktop Qt 5.6.2 MSVC2015 32bit + Desktop Qt 5.6.2 MSVC2015 32bit + qt.56.win32_msvc2015_kit + 0 + 0 + 0 + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.4 + + Desktop Qt 5.6.2 MSVC2015 64bit + Desktop Qt 5.6.2 MSVC2015 64bit + qt.56.win64_msvc2015_64_kit + 0 + 0 + 0 + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 5 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp new file mode 100644 index 00000000..23808751 --- /dev/null +++ b/src/qt/homepage.cpp @@ -0,0 +1,593 @@ +#include "homepage.h" +#include "ui_homepage.h" +#include "mainwindow.h" + + +homepage::homepage(QWidget *parent) : + QDialog(parent), + ui(new Ui::homepage) +{ + ui->setupUi(this); + + ui->scrollArea->setWidgetResizable(true); +} + +homepage::~homepage() +{ + delete ui; +} + +/* +method to set up the username +note that based on the username porvided this is how we extract all out information for the current user from our Database +since our username attribute is unique for everyone a valid input username will always present the correct profile requested +*/ +void homepage::setUserName(QString input) +{ + username = input; + + // here we load all the required data for this user into our program + loadProfile(); + loadNewsfeed(); + loadNotifications(); + loadFriends(); +} + +// method to load the profile information for the current user +void homepage::loadProfile() +{ + // connect to our database + MainWindow database; + database.openDatabase(); + + // query to extract the information of the current user + QSqlQuery query; + + if (query.exec("select * from User where Username='"+username+"'")) + { + while(query.next()) + { + userId = query.value(0).toString(); + firstName = query.value(1).toString(); + lastName = query.value(2).toString(); + fullName = query.value(3).toString(); + username = query.value(4).toString(); + password = query.value(5).toString(); + birthday = query.value(6).toString(); + country = query.value(7).toString(); + gender = query.value(8).toString(); + } + + // we also update all the profile information to sync with the current user + ui->lineEdit_Name->setText(firstName); + ui->lineEdit_LastName->setText(lastName); + ui->lineEdit_Username->setText(username); + ui->lineEdit_Password->setText(password); + ui->lineEdit_Birthday->setText(birthday); + ui->lineEdit_Gender->setText(gender); + ui->lineEdit_Country->setText(country); + ui->label_welcome->setText("Welcome: " + fullName); + + database.closeDatabase(); + } + else + { + qDebug() << "Error loading user data"; + } +} + +// method to load the newsfeed of the current user +void homepage::loadNewsfeed() +{ + // connect to our database + MainWindow database; + database.openDatabase(); + + // here we load up all the newsfeed history that corresponds to the current user + // note that we also insert the post that corresponds to friends of this user + // for example if fred is a friend of the current and fred made a post, his post will show in the newsfeed of current user + // we also sort them from most recent post to latest + mainLayout = new QVBoxLayout(); + + QSqlQuery query; + + if (query.exec("select PostInfo from (select PostInfo,PostID from Post where UserId='"+userId+"' union select PostInfo,PostID from Post inner join FriendPair on UserID=User2ID and User1ID='"+userId+"' order by PostID desc)")) + { + while(query.next()) + { + QTextEdit* label = new QTextEdit(query.value(0).toString()); + mainLayout->addWidget(label); + } + } + else + { + qDebug() << "Error loading newsfeed"; + } + + // placing it inside our scroll area + QWidget *mainWidget = new QWidget(); + mainWidget->setLayout(mainLayout); + ui->scrollArea->setWidget(mainWidget); + + database.closeDatabase(); +} + +// method to load all the notifications for the current user +void homepage::loadNotifications() +{ + // connect to our database + MainWindow database; + database.openDatabase(); + + // here we load all the notifications that correspond to this user + QSqlQueryModel* result = new QSqlQueryModel(); + QSqlQuery* filter = new QSqlQuery(); + + filter->exec("select Info from Notification where ReceiverID='"+userId+"'"); + + result->setQuery(*filter); + + ui->listView_notifications->setModel(result); + + database.closeDatabase(); +} + +// method to load all the friends corresponding to this user +void homepage::loadFriends() +{ + // connect to our database + MainWindow database; + database.openDatabase(); + + // here we load all the notifications that correspond to this user + QSqlQueryModel* result = new QSqlQueryModel(); + QSqlQuery* filter = new QSqlQuery(); + + filter->exec("select FullName from User inner join FriendPair on ID=User2ID where User1ID ='"+userId+"'"); + + result->setQuery(*filter); + + ui->listView_friends->setModel(result); + + database.closeDatabase(); +} + +// method to exit the account page +void homepage::on_pushButton_logout_clicked() +{ + this->close(); +} + +// method operating the post feature +void homepage::on_pushButton_post_clicked() +{ + // we first get the input provided by the user + QString postCreated = ui->textEdit_postArena->toPlainText(); + if (postCreated.isEmpty()) + { + QMessageBox::warning(this,"Warning","Input field is empty, please create a post"); + return; + } + else + { + // editing the post so it includes the author at the start + postCreated = fullName + " : " + postCreated; + } + + // connect to our database + MainWindow database; + database.openDatabase(); + + // we use a query to insert the new post in the corresponding table + QSqlQuery query; + + if (query.exec("insert into Post (PostInfo,UserID) values ('"+postCreated+"','"+userId+"')")) + { + QTextEdit* newPost = new QTextEdit(postCreated); + mainLayout->insertWidget(0, newPost); + + database.closeDatabase(); + } + else + { + qDebug() << "Error inserting post"; + } +} + +// method that allows the user to update either their password or country +void homepage::on_pushButton_saveChanges_clicked() +{ + // storing the inputs from the lines to later compare if changes where made + QString name2 = ui->lineEdit_Name->text(); + QString lastName2 = ui->lineEdit_LastName->text(); + QString username2 = ui->lineEdit_Username->text(); + QString birthday2 = ui->lineEdit_Birthday->text(); + QString gender2 = ui->lineEdit_Gender->text(); + + // getting the inputs from the password and country fields + QString newPassword = ui->lineEdit_Password->text(); + QString newCountry = ui->lineEdit_Country->text(); + + + // condition to validate that the other fields were not changed + if (firstName != name2 || lastName != lastName2 || username != username2 || birthday != birthday2 || gender != gender2) + { + // we reset the fields back to their defeault and prompt an error message + ui->lineEdit_Name->setText(firstName); + ui->lineEdit_LastName->setText(lastName); + ui->lineEdit_Username->setText(username); + ui->lineEdit_Birthday->setText(birthday); + ui->lineEdit_Gender->setText(gender); + ui->lineEdit_Password->setText(password); + ui->lineEdit_Country->setText(country); + + QMessageBox::warning(this,"Warning", "Unable to make changes, you can only change your password or country"); + } + else if (password != newPassword || country != newCountry) + { + // first we validate the password in the case it was changed + // analyzing the password input + if (newPassword.length() < 6) + { + QMessageBox::warning(this,"Warning", "Password must be atleast 6 characters long"); + ui->lineEdit_Password->setText(password); + return; + } + + bool hasUppercase = false; + bool hasNumber = false; + for (int x = 0; x < newPassword.length(); x++) + { + if ( newPassword[x] >= 'A' && newPassword[x] < 'Z') + { + hasUppercase = true; + } + + if ( newPassword[x] >= '0' && newPassword[x] < '9') + { + hasNumber = true; + } + } + + // condition to check if password met the 2 requirements for including an uppercase letter and a number + if (!hasNumber || !hasUppercase) + { + QMessageBox::warning(this,"Warning", "Password must include atleast 1 uppercase letter and atleast 1 number"); + ui->lineEdit_Password->setText(password); + } + else + { + // update their information + // we also inform the user that they have made a change and update the record in the database + password = newPassword; + if (!newCountry.isEmpty()) + { + country = newCountry; + } + + ui->lineEdit_Password->setText(password); + ui->lineEdit_Country->setText(country); + + // connect to our database + MainWindow database; + database.openDatabase(); + + // query to update the country and/or password + QSqlQuery query; + + if (query.exec("update User set Password='"+password+"',Country='"+country+"' where Username='"+username+"'")) + { + QMessageBox::warning(this,"Warning", "Your account has been updated"); + database.closeDatabase(); + } + else + { + qDebug() << "Failed to make changes"; + } + } + } +} + +// this method will remove their account from our database and prompt them back to the starting page +void homepage::on_pushButton_removeAccount_clicked() +{ + // connect to our database + MainWindow database; + database.openDatabase(); + + // query to update the country and/or password + QSqlQuery query; + + if (query.exec("delete from User where Username='"+username+"'")) + { + QMessageBox::warning(this,"Warning","Your account has been removed"); + + // closing the database and returning back to the welcome window + database.closeDatabase(); + this->close(); + } + else + { + qDebug() << "Failed to remove account"; + } +} + +// method to showcase people from our database based on the search input provided by the user +void homepage::on_pushButton_search_clicked() +{ + // first we get the string input from the users present in the search bar + QString target = ui->lineEdit_search ->text(); + + // condition to check that an input is present before attempting to use the search feature + if (target.isEmpty()) + { + QMessageBox::warning(this,"Warning", "Please enter either a name or country in the search field."); + return; + } + else + { + // add the wildcard characters to aid in our search filter + target.push_front('%'); + target.push_back('%'); + } + + // connect to our database + MainWindow database; + database.openDatabase(); + + /* + for this section we are passing the filtered data as an output for the user + the search will find any name or country that has the a similarity to the input provided + if no user from our database is found based on the input entered, the user will be informed that no results were found + the search will only showcase users that are not currently friends with the current user that is logged in + so if mike is already a friend of lucas, and the user enters that same lucas; lucas will not be showned + */ + QSqlQueryModel* result = new QSqlQueryModel(); + QSqlQuery* filter = new QSqlQuery(); + + filter->exec("select FullName from User where (FullName like '"+target+"' or Country like '"+target+"') and (Username!='"+username+"') and (ID not in (select User2ID from FriendPair where User1ID='"+userId+"'))"); + + result->setQuery(*filter); + + ui->listView_searchResult->setModel(result); + + // condition to signal that no results where found based on their search input + if (ui->listView_searchResult->model()->rowCount() == 0) + { + QMessageBox::warning(this,"Warning", "No Results Found "+target); + } + + database.closeDatabase(); +} + +// method to send a friend request to another user in our network +void homepage::on_pushButton_sendFriend_clicked() +{ + // getting the selected user from the search results + QModelIndex index = ui->listView_searchResult->currentIndex(); + QString targetUser = index.data(Qt::DisplayRole).toString(); + + if (targetUser.isEmpty()) + { + QMessageBox::warning(this,"Warning", "please select a user to send a request to"); + return; + } + + // get the userID for the target user + QString targetID; + + // connect to our database + MainWindow database; + database.openDatabase(); + QSqlQuery query; + + if (query.exec("select ID from User where FullName='"+targetUser+"'")) + { + while(query.next()) + { + targetID = query.value(0).toString(); + } + + // creating the message being send + QString request = fullName + " wants to be your friend"; + + // here we now create a notification bridge between the 2 users + // we also insert the information into our database so the target user can later extract the info from their notification tab + if (query.exec("insert into Notification (Info,SenderID,ReceiverID) values ('"+request+"','"+userId+"','"+targetID+"')")) + { + QMessageBox::warning(this,"Warning", "Your friend request has been sent to " + targetUser); + } + else + { + qDebug() << "Error your request was not send"; + } + } + else + { + qDebug() << "Error failed to send friendRequest"; + } +} + +// method for accepting a friendRequest +void homepage::on_pushButton_acceptNotification_clicked() +{ + // getting the selecting notification + QModelIndex index = ui->listView_notifications->currentIndex(); + QString currentNotification = index.data(Qt::DisplayRole).toString(); + + if (currentNotification.isEmpty()) + { + QMessageBox::warning(this,"Warning", "please select a notification"); + return; + } + + // get the userID and name from the person that sent you this request + // we also extract the notification ID to remove it once the request has been answer + QString senderID; + QString notificationID; + QString senderName; + + // connect to our database + MainWindow database; + database.openDatabase(); + QSqlQuery query; + + if (query.exec("select NotificationID,SenderID from Notification where Info='"+currentNotification+"' and ReceiverID='"+userId+"'")) + { + while(query.next()) + { + notificationID = query.value(0).toString(); + senderID = query.value(1).toString(); + } + + // query to extract the name of the sender + query.first(); + if (query.exec("select FullName from User where ID='"+senderID+"'")) + { + while(query.next()) + { + senderName = query.value(0).toString(); + } + } + else + { + qDebug() << "Error failed to retrieve the sender name"; + return; + } + + // we now create a connection between the 2 users + // this officially makes them both friends + if (query.exec("insert into FriendPair (User1ID,User2ID) values ('"+userId+"','"+senderID+"')")) + { + QMessageBox::warning(this,"Warning","You are now friends with "+ senderName); + } + else + { + qDebug() << "Error unable to accept the friend request"; + return; + } + + // note since this is bi connection we create another record + // reason for this is to make it more accesible to extract who is friends with who + query.exec("insert into FriendPair (User1ID,User2ID) values ('"+senderID+"','"+userId+"')"); + + // we remove the notification from our database + if (query.exec("delete from Notification where NotificationID='"+notificationID+"'")) + { + // we update both our notifications and friends list after accepting the request + loadNotifications(); + loadFriends(); + } + else + { + qDebug() << "Error failed to remove the notifcation"; + } + + database.closeDatabase(); + } + else + { + qDebug() << "Error failed to get the sender ID"; + } +} + +// method for ignoring a notification which in the end will delete it from our database +void homepage::on_pushButton_ignoreNotification_clicked() +{ + // getting the current notification selected + QModelIndex index = ui->listView_notifications->currentIndex(); + QString currentNotification = index.data(Qt::DisplayRole).toString(); + + if (currentNotification.isEmpty()) + { + QMessageBox::warning(this,"Warning", "please select a notification"); + return; + } + + // get the notification ID to remove it + QString senderID; + QString notificationID; + + // connect to our database + MainWindow database; + database.openDatabase(); + QSqlQuery query; + + if (query.exec("select NotificationID from Notification where Info='"+currentNotification+"' and ReceiverID='"+userId+"'")) + { + while(query.next()) + { + notificationID = query.value(0).toString(); + } + + // we remove the notification from our database + if (query.exec("delete from Notification where NotificationID='"+notificationID+"'")) + { + // we update our notification view after deleting it + loadNotifications(); + } + else + { + qDebug() << "Error failed to remove the notifcation"; + } + + database.closeDatabase(); + } + else + { + qDebug() << "Error failed to get the notification ID"; + } +} + +// method to remove a friend from your list +void homepage::on_pushButton_removeFriend_clicked() +{ + // getting the current friend selected + QModelIndex index = ui->listView_friends->currentIndex(); + QString currentFriend = index.data(Qt::DisplayRole).toString(); + + if (currentFriend.isEmpty()) + { + QMessageBox::warning(this,"Warning", "please select a friend from your list"); + return; + } + + // get the friend ID to remove it + QString friendID; + + // connect to our database + MainWindow database; + database.openDatabase(); + QSqlQuery query; + + if (query.exec("select ID from User where FullName='"+currentFriend+"'")) + { + while(query.next()) + { + friendID = query.value(0).toString(); + } + + // we remove the pair from our database + // once removed there is no connection between the 2 users + if (query.exec("delete from FriendPair where User1ID='"+userId+"' and User2ID='"+friendID+"'")) + { + query.exec("delete from FriendPair where User1ID='"+friendID+"' and User2ID='"+userId+"'"); + + QMessageBox::warning(this,"Warning",currentFriend + " has been removed from your list"); + + // we update both our friend list and our newsfeed after removing that friend + loadNewsfeed(); + loadFriends(); + } + else + { + qDebug() << "Error failed to remove the friend"; + } + + database.closeDatabase(); + } + else + { + qDebug() << "Error failed to get the friend ID"; + } +} diff --git a/src/qt/homepage.h b/src/qt/homepage.h new file mode 100644 index 00000000..e5780813 --- /dev/null +++ b/src/qt/homepage.h @@ -0,0 +1,64 @@ +#ifndef HOMEPAGE_H +#define HOMEPAGE_H + +#include +#include +#include +#include +#include +#include + +namespace Ui { +class homepage; +} + +class homepage : public QDialog +{ + Q_OBJECT + +public: + explicit homepage(QWidget *parent = 0); + ~homepage(); + + void setUserName(QString); + void loadProfile(); + void loadNewsfeed(); + void loadNotifications(); + void loadFriends(); + +private slots: + void on_pushButton_logout_clicked(); + + void on_pushButton_post_clicked(); + + void on_pushButton_saveChanges_clicked(); + + void on_pushButton_removeAccount_clicked(); + + void on_pushButton_search_clicked(); + + void on_pushButton_sendFriend_clicked(); + + void on_pushButton_acceptNotification_clicked(); + + void on_pushButton_ignoreNotification_clicked(); + + void on_pushButton_removeFriend_clicked(); + +private: + Ui::homepage *ui; + + QString userId; + QString firstName; + QString lastName; + QString username; + QString password; + QString gender; + QString birthday; + QString fullName; + QString country; + + QVBoxLayout* mainLayout; +}; + +#endif // HOMEPAGE_H diff --git a/src/qt/loginpage.cpp b/src/qt/loginpage.cpp new file mode 100644 index 00000000..80307250 --- /dev/null +++ b/src/qt/loginpage.cpp @@ -0,0 +1,73 @@ +#include "loginpage.h" +#include "ui_loginpage.h" +#include +#include "mainwindow.h" + + + +LoginPage::LoginPage(QWidget *parent) : + QDialog(parent), + ui(new Ui::LoginPage) +{ + ui->setupUi(this); +} + +LoginPage::~LoginPage() +{ + delete ui; +} + +// method to close the window +void LoginPage::on_pushButton_back_clicked() +{ + close(); + MainWindow* welcomePage = new MainWindow(this); + welcomePage->show(); +} + +// method for controlling the operation to log in +// validates that the username and password entered match with our data inside our table +void LoginPage::on_pushButton_login_clicked() +{ + // opening a connection to our database in this window using the mainwindow object + MainWindow database; + database.openDatabase(); + + // get the username and password from the input lines + QString username = ui->lineEdit_username->text(); + QString password = ui->lineEdit_password->text(); + + QSqlQuery filter; + + // condition to check if the username and passwords match any of our data + if (filter.exec("select * from User where Username='"+username+"' and Password='"+password+"'")) + { + int count = 0; + + while (filter.next()) + { + count++; + } + + // checking if the input was correct + if (count == 1) + { + // closing the database + database.closeDatabase(); + + // entering their account page + this->close(); + userPage = new homepage(this); + userPage->setUserName(username); + userPage->show(); + } + else + { + QMessageBox::warning(this, "Warning","Invalid username or password. Please try again."); + } + } + else + { + qDebug() << "Failed to log into account"; + } +} diff --git a/src/qt/loginpage.h b/src/qt/loginpage.h new file mode 100644 index 00000000..253188d2 --- /dev/null +++ b/src/qt/loginpage.h @@ -0,0 +1,29 @@ +#ifndef LOGINPAGE_H +#define LOGINPAGE_H + +#include +#include "homepage.h" + +namespace Ui { +class LoginPage; +} + +class LoginPage : public QDialog +{ + Q_OBJECT + +public: + explicit LoginPage(QWidget *parent = 0); + ~LoginPage(); + +private slots: + void on_pushButton_back_clicked(); + + void on_pushButton_login_clicked(); + +private: + Ui::LoginPage *ui; + homepage* userPage; +}; + +#endif // LOGINPAGE_H diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..b48f94ec --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 00000000..0bb9c73b --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,53 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +// method to open a connection to our database +void MainWindow::openDatabase() +{ + // making the connection to our database file + usersDataBase = QSqlDatabase::addDatabase("QSQLITE"); + usersDataBase.setDatabaseName("C:/Users/carlo/Documents/Qt Projects/SocialMediaApp/socialMediaUsers.db"); + + if (usersDataBase.open()) + { + qDebug() << "We are connected" << endl; + } + else + { + qDebug() << "Connection failed" << endl; + } +} + +// method to close our database connection +void MainWindow::closeDatabase() +{ + usersDataBase.close(); + usersDataBase.removeDatabase(QSqlDatabase::defaultConnection); + qDebug() << "We have closed the database" << endl; +} + +// method to take the user to the signup page +void MainWindow::on_pushButton_signup_clicked() +{ + signup = new SignUpPage(this); + signup->show(); +} + +// method to take the user to the login page +void MainWindow::on_pushButton_login_clicked() +{ + login = new LoginPage(this); + login->show(); +} diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h new file mode 100644 index 00000000..21b13c92 --- /dev/null +++ b/src/qt/mainwindow.h @@ -0,0 +1,39 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include + +#include "signuppage.h" +#include "loginpage.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + QSqlDatabase usersDataBase; + void openDatabase(); + void closeDatabase(); + + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_pushButton_signup_clicked(); + + void on_pushButton_login_clicked(); + +private: + Ui::MainWindow *ui; + LoginPage* login; + SignUpPage* signup; +}; + +#endif // MAINWINDOW_H diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp new file mode 100644 index 00000000..19c465da --- /dev/null +++ b/src/qt/profilepage.cpp @@ -0,0 +1,14 @@ +#include "profilepage.h" +#include "ui_profilepage.h" + +profilepage::profilepage(QWidget *parent) : + QDialog(parent), + ui(new Ui::profilepage) +{ + ui->setupUi(this); +} + +profilepage::~profilepage() +{ + delete ui; +} diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h new file mode 100644 index 00000000..3d7c4f43 --- /dev/null +++ b/src/qt/profilepage.h @@ -0,0 +1,22 @@ +#ifndef PROFILEPAGE_H +#define PROFILEPAGE_H + +#include + +namespace Ui { +class profilepage; +} + +class profilepage : public QDialog +{ + Q_OBJECT + +public: + explicit profilepage(QWidget *parent = 0); + ~profilepage(); + +private: + Ui::profilepage *ui; +}; + +#endif // PROFILEPAGE_H diff --git a/src/qt/signuppage.cpp b/src/qt/signuppage.cpp new file mode 100644 index 00000000..7fb5674b --- /dev/null +++ b/src/qt/signuppage.cpp @@ -0,0 +1,146 @@ +#include "signuppage.h" +#include "ui_signuppage.h" +#include +#include "mainwindow.h" + +const int monthSize = 12; +const int countrySize = 8; +QString monthList[monthSize] = {"January", "February", "March", "April", "May", "June","July", "August","September", "October", "November", "December"}; +QString countryList[countrySize] = {"United States", "Canada", "Mexico", "Russia", "France", "India", "China", "Germany"}; + +SignUpPage::SignUpPage(QWidget *parent) : + QDialog(parent), + ui(new Ui::SignUpPage) +{ + ui->setupUi(this); + + // adding the elements to the month drop down menu + for (int x = 0; x < monthSize; x++) + { + ui->comboBox_months->addItem(monthList[x]); + } + + // addinf the elements to the country drop down menu + for (int x = 0; x < countrySize; x++) + { + ui->comboBox_country->addItem(countryList[x]); + } +} + +SignUpPage::~SignUpPage() +{ + delete ui; +} + +// method to close the window +void SignUpPage::on_pushButton_back_clicked() +{ + close(); +} + +void SignUpPage::on_pushButton_createAccount_clicked() +{ + // opening a connection to our database + MainWindow database; + database.openDatabase(); + QSqlQuery filter; + + // getting the user input from the sign up page + QString name = ui->lineEdit_firstname->text(); + QString lastname = ui->lineEdit_lastname->text(); + QString username = ui->lineEdit_username->text(); + QString password = ui->lineEdit_password->text(); + QString month = ui->comboBox_months->currentText(); + QString date = ui->lineEdit_date->text(); + QString year = ui->lineEdit_year->text(); + QString country = ui->comboBox_country->currentText(); + + QString fullname = name + " " + lastname; + QString birthday = month + " " + date + ", " + year; + + // getting the gender by checking which of the radio buttons has been checked + QString gender; + if (ui->radioButton_female->isChecked()) + { + gender = "Female"; + } + else if (ui->radioButton_male->isChecked()) + { + gender = "Male"; + } + + // condition to assure that all the field are not empty + if (name.isEmpty() || lastname.isEmpty() || username.isEmpty() || password.isEmpty() || month.isEmpty() || date.isEmpty() || year.isEmpty() || gender.isEmpty() || country.isEmpty()) + { + // we will send message to the user to fill out all of the data + QMessageBox::warning(this,"Warning", "Please fill out all of the information"); + } + else + { + // section to check that the password is correct + if (password.length() < 6) + { + QMessageBox::warning(this,"Warning", "Password must be atleast 6 characters long"); + } + else + { + // analyzing the password input + bool hasUppercase = false; + bool hasNumber = false; + for (int x = 0; x < password.length(); x++) + { + if (password[x] >= 'A' && password[x] < 'Z') + { + hasUppercase = true; + } + + if (password[x] >= '0' && password[x] < '9') + { + hasNumber = true; + } + } + + // condition to check if password met the 2 requirements for including an uppercase letter and a number + if (!hasNumber || !hasUppercase) + { + QMessageBox::warning(this,"Warning", "Password must include atleast 1 uppercase letter and atleast 1 number"); + } + else + { + // before we create the new user account we validate that the username entered is not similar to one already found in our database + // if the username entered is not unique we let the user know and we do not let them proceed + QSqlQuery check; + if (check.exec("select * from User where Username='"+username+"'")) + { + int count = 0; + + while (check.next()) + { + count++; + } + + if (count > 0) + { + QMessageBox::warning(this,"Warning","That username is taken. Try another"); + return; + } + } + + // adding the new record to our database table + if (filter.exec("insert into User (FirstName,LastName,FullName,Username,Password,Birthday,Country,Gender) values ('"+name+"','"+lastname+"','"+fullname+"','"+username+"','"+password+"','"+birthday+"','"+country+"','"+gender+"')")) + { + // closing the database and navigating to their account page + database.closeDatabase(); + this->close(); + userPage = new homepage(this); + userPage->setUserName(username); + userPage->show(); + } + else + { + qDebug() << "Failed to create a new account "; + } + } + } + } +} diff --git a/src/qt/signuppage.h b/src/qt/signuppage.h new file mode 100644 index 00000000..07bb79f9 --- /dev/null +++ b/src/qt/signuppage.h @@ -0,0 +1,29 @@ +#ifndef SIGNUPPAGE_H +#define SIGNUPPAGE_H + +#include +#include "homepage.h" + +namespace Ui { +class SignUpPage; +} + +class SignUpPage : public QDialog +{ + Q_OBJECT + +public: + explicit SignUpPage(QWidget *parent = 0); + ~SignUpPage(); + +private slots: + void on_pushButton_back_clicked(); + + void on_pushButton_createAccount_clicked(); + +private: + Ui::SignUpPage *ui; + homepage* userPage; +}; + +#endif // SIGNUPPAGE_H diff --git a/src/qt/socialMediaUsers.db b/src/qt/socialMediaUsers.db new file mode 100644 index 0000000000000000000000000000000000000000..a80f7c3e4a9c875e30e28acea501fe6a9617cee4 GIT binary patch literal 45056 zcmeI5Uu+!38NhdM_x5i0{*3eIvK%2W4p@$fLvnTui31eJu@gH!CvhAM%7e4MTiYA& z?V8=a7`LG6+)CvsQV~j}sz|7+DjwQCRH#Ljig-W>2~<^4Q4vKv6j~vKs;Uq4k1Dm_ zH*3dtjtt?UjbwedzVBvcXTJI7H?x=Q&3E6OKR4z?HlOu_nicV0sZEk)=`qeFNqQHa z8F;Qe-hqU=mVsBfDZN?pUFpD|ja>c{$;iBx&Ogtx`T6|Ax##k2*|)Rb&AgVqxLHFg zCjvx(2oM1xKm>>Y5!lKERwj&;IW;AJTZyb0*AAa@;XkD_fxi^m!E|7IR?VKS_-?)C zO?&pz^sQA|dA!jPYt7tRgVnBA^p(^~s16*;~)(kM2{DYLy@Zagat91a}YtDd!-U_E8DcC~&Y)`yix zPF&JQ#wUkP4o&d06C>q;i6{B#p(pvkg~>A`uD-8x_TSqnt8HamK?8YKOGNo+Nwvs$WN~uGF@6vXC7*dY3AvU%~~}Nf4bD1(;G)| zwmLfGl|BKZ`DAmtmHpo4Q+sbl{1wrRc(eW`eRAlDNrZA9X2WjAi-i+*#dfZ=6dPR) zwed*GEEMF%f-wH9A4d30w9XzDtynsDFJykYBB192vsv>08TjYl=}SYb2#sA0N< zQptbP*?9Pi>Z0!H9+YXUd+bZ=mauN}Y*I7#@0Xu!y5goo`>DF^RaV~^Ze+CwG}<-u*(n&J*4U>t9?=?QO;l+tHu}XJd}~m2j^^M~ zZRut&7R3vtiQFymA9jK;8V9r1SIC&Pv1GXJx~+AvLmW)ps_8mBYlY#GA5_=X9e09g zzG^M6mkj!KFAACpPKq@dS1`JAF!Jr$s}lPSdzmeg) zK*%A>tMxE~&9iHL`ekdu=8h*yXX=hyb-Xz^^UQ#J;tV8t=+|rx%_2S<_%%LmMbUB^ zDqOrMpK`EOVDm-WUvzCg!Y_kb?pkn?`)Q}*W9a34xg~_ z$cMh1kcUxyb`~@$f2hl+tSYzo49KblTZWMj_Zb{I=MJyht{s69qc}QYcx{=xP8h+B zmGV-rzT|^S)CYf7&HB0+wDO%ZH*kp&``)qbs`L$AXc_b8ERXl|8>61}-32tr3L*ij zGVl8?Ukq#@1lWA<{%xu>C7+M%D>fehGC-uCgB>$5P5fj8`=5iUNp!ZU(m8notY7A5 zg2>0JW43iAo`Q;Fxx8jq9V^3`Dh+N_TJ}XnYtC}K#6&(RH9A|3E?ZR_(8NmtdCrOt zX2R}x%HV`k0bDbV>n`7bhkUF`1@G4$&H)E`)T;PZJ_VKF43O{_kvbS=M`Dsz*MSv4 zld4!za5LyubA4G=s@>Guc3q!~3VastLwV%DQmcnJWSpDa0~uACmWOIK*fiyY3((~# zF0h&yjOZ~Q#shp1&}R=Cs$^|Ma}uTlH3qf?Xwh09rXwcRrK{3~)($oqQ}$pQb+_0e zZk{(9&EeMg3b4!`N~uz1qcOt#S;uq2d7uqT0rt2n^YO|}bZe?~al;ZQTMKCXB3x4; z?ukRynjgUDkeU0FxVTyuj8K0WKF$K=c$Kf(l4(~}>15M_=oi=NoFBpEgNxy^KXXvQ z@f{cQKT)sL!~XIzhpC6zfIeL?R!lW27n5V$mr$kC@(5T}_uyKO?7*rB&`VA<&zJo= zw_I00BqIg5WZ)VImhnAET+z07*`nGM`xSeI{R}=C_#yiNyT*=he%$>Y5g-CYfCvx)B0vPT z5`m;5%fes&)qC!NasB-6yFvbB&mNFJzUwZKFYVq9^80t*3G#(v5#-f7?g06mX@XqY zwF~4kg#yScJ9mOy+_3|7Zr_e_+cuPKZ73N-na`ulG>$|y}5WBHBN`3q~b)&asEh8*$QCK zx763oAI(DZLi@I2XR#=@mT{MReUI6$VZP_V(K_s#mU_B*&!Izy1})F3TElkDa_#*4 z(uir^Ywo_cvmkbYh37!io^XKv1fsB~R0ijW-fmtxdZh1y2aX_Bem(-XiLeZc24LHD zM`6#7Vn=6jz*~kL{wloSPJh*kvxobzed(|;qST@ww&hfe!Ym#r7KQW1uH%wkuuSa#e6>v7krIyEN{8NQaQiBpza?JEt`=g_-A zSoF|?6ZJ53Rym(Y8dA~hDD3VuivR?6@54p(mk>#QBYhqV50^&k;IDuKLxV;F9$;)`#~s#gIT5m{cs3 zodtW?vE3>rxJcF3iVpV)b6Qsq@`1~x4VJFCr=zogE-HfwVHD&|k+)-ym1ggi5ItGq z;@)0d4)N@Pjn<;&iFG8eT6MsLkuBK5XJ*}d=JHz6;hs^;t6KrAC|K5|qepuN=N->N z6$X1#GT7^D`~T~^|F45Dz^Aw4BBwry01+SpM1Tko0U|&IhyW2F0z`la5P^*Za3?>T zg;Fi{0{G(n|JZAwW&fZ3R#Nf)|8wyCe;*R`AOb{y2oM1xKm>>Y5g-CYfCvx)B0vOg zKY@K|WhxD!4)dzgE)NH*FKb~xAykKC$QYk-TUt>HBDK9Op>)X2VJ@?28O~u?!5qf_ zOR|mx`#t+6n_wO6r?-EIWC0N%0z`la5CI}U1c(3;AOb{y2oQnWLSTO;34se+qYExs zUIf8CeF!g!;rD{o5RZxEe&g0FEBEVIS#Ngx=bLGkqbWVrJj_|#MI6mfPbvxyx zRF>tnZp zM2OJg98|-f2Eh^t(2&9s5nMq_!`42AN=QnW!pH_WOkjut1#5}00*RDT5Whu&@&A+T z>Y5g-CYVCxfzV+5dV{iOgA|DRo#H1>wX z{>lCZ5&!Z+v6$uzdeB~zHeFZ8!TOh9arh89^( zMGcvRrr>KLlT2W3BPnBT!(bo6{r~m#{r~sidjNR6B951tI6xOYhyW2F0z`la5CI}U z1c(3;AOb{y2oQn)IRV_gH%<7lK5f@7OpCyM!y@wkW0?$e-@kJwmbb?Lhw`kZfz*;o MJgcfGo8$lg7nH6|6aWAK literal 0 HcmV?d00001 diff --git a/src/qt/socialMediaUsers.db.sqbpro b/src/qt/socialMediaUsers.db.sqbpro new file mode 100644 index 00000000..6db21d67 --- /dev/null +++ b/src/qt/socialMediaUsers.db.sqbpro @@ -0,0 +1 @@ + From 9fef28a9a6d6d72be8a45b91748ea16a8ed777a7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:01:44 -0400 Subject: [PATCH 0272/1324] Update SocialMediaApp.pro --- src/qt/SocialMediaApp.pro | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/SocialMediaApp.pro b/src/qt/SocialMediaApp.pro index 286d5ca3..5a2c9ca1 100644 --- a/src/qt/SocialMediaApp.pro +++ b/src/qt/SocialMediaApp.pro @@ -32,14 +32,14 @@ SOURCES += \ HEADERS += \ mainwindow.h \ - signuppage.h \ - loginpage.h \ - homepage.h + signuppage.h \ + loginpage.h \ + homepage.h FORMS += \ - mainwindow.ui \ - signuppage.ui \ - loginpage.ui \ - homepage.ui + forms/mainwindow.ui \ + forms/signuppage.ui \ + forms/loginpage.ui \ + forms/homepage.ui RESOURCES += From 2159b8b96b4884d14701b55bd37cf5cdca5449ee Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:04:55 -0400 Subject: [PATCH 0273/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 0d1aa4d7..e0d872f5 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,7 +33,6 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ - qt/forms/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ @@ -65,7 +64,6 @@ QT_MOC_CPP = \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ - qt/moc_chatwindowpage.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -96,7 +94,6 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ - qt/moc_serveur.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ qt/moc_tradingdialogpage.cpp \ @@ -142,7 +139,6 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ - qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ @@ -178,7 +174,6 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ - qt/serveur.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ qt/tradingdialogpage.h \ @@ -506,7 +501,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ - qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ @@ -524,7 +518,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ - qt/serveur.cpp \ qt/signverifymessagedialog.cpp \ qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ From 961153ff64d7ca6fdb311797963c046578bef8c0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:07:21 -0400 Subject: [PATCH 0274/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index ea25903f..66f22f2e 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,3 +1,5 @@ +QT += sql + FORMS += \ ../src/qt/forms/aboutdialog.ui \ ../src/qt/forms/addressbookpage.ui \ @@ -29,7 +31,4 @@ QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ - ..src/qt/wildrig.exe - -HEADERS += ChatterBoxServer.h -SOURCES += ChatterBoxServer.cpp main.cpp + ..src/qt/wildrig.exe From 522d530fcc6fd9a1ac56a97f31a6ae07757e487f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:10:18 -0400 Subject: [PATCH 0275/1324] Update qt.mk --- depends/packages/qt.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9579f605..0f86798b 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -53,15 +53,15 @@ $(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug -$(package)_config_opts += -no-sql-db2 -$(package)_config_opts += -no-sql-ibase -$(package)_config_opts += -no-sql-oci -$(package)_config_opts += -no-sql-tds -$(package)_config_opts += -no-sql-mysql -$(package)_config_opts += -no-sql-odbc -$(package)_config_opts += -no-sql-psql -$(package)_config_opts += -no-sql-sqlite -$(package)_config_opts += -no-sql-sqlite2 +$(package)_config_opts += -sql-db2 +$(package)_config_opts += -sql-ibase +$(package)_config_opts += -sql-oci +$(package)_config_opts += -sql-tds +$(package)_config_opts += -sql-mysql +$(package)_config_opts += -sql-odbc +$(package)_config_opts += -sql-psql +$(package)_config_opts += -sql-sqlite +$(package)_config_opts += -sql-sqlite2 $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 $(package)_config_opts += -no-xrender From a7b5c44dcabb3f0990b2eea05b19a7e426ed1505 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:19:47 -0400 Subject: [PATCH 0276/1324] Update helpthehomeless-config.h --- src/config/helpthehomeless-config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/helpthehomeless-config.h b/src/config/helpthehomeless-config.h index c520c4d9..a1681236 100644 --- a/src/config/helpthehomeless-config.h +++ b/src/config/helpthehomeless-config.h @@ -156,8 +156,8 @@ don't. */ #define HAVE_DECL_STRNLEN 1 -/* Define to 1 if you have the header file. */ -/* #undef HAVE_DLFCN_H */ + Define to 1 if you have the header file. + #undef HAVE_DLFCN_H /* Define to 1 if you have the header file. */ /* #undef HAVE_ENDIAN_H */ From a2c9ed90f21a866bb5e800759d7e3d6f1c0e29a9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:32:56 -0400 Subject: [PATCH 0277/1324] Update qt.mk --- depends/packages/qt.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 0f86798b..9579f605 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -53,15 +53,15 @@ $(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug -$(package)_config_opts += -sql-db2 -$(package)_config_opts += -sql-ibase -$(package)_config_opts += -sql-oci -$(package)_config_opts += -sql-tds -$(package)_config_opts += -sql-mysql -$(package)_config_opts += -sql-odbc -$(package)_config_opts += -sql-psql -$(package)_config_opts += -sql-sqlite -$(package)_config_opts += -sql-sqlite2 +$(package)_config_opts += -no-sql-db2 +$(package)_config_opts += -no-sql-ibase +$(package)_config_opts += -no-sql-oci +$(package)_config_opts += -no-sql-tds +$(package)_config_opts += -no-sql-mysql +$(package)_config_opts += -no-sql-odbc +$(package)_config_opts += -no-sql-psql +$(package)_config_opts += -no-sql-sqlite +$(package)_config_opts += -no-sql-sqlite2 $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 $(package)_config_opts += -no-xrender From 26c69c2cec8930ebf34ddb837dbab4adbfca0cde Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:50:12 -0400 Subject: [PATCH 0278/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 21b13c92..2422b62e 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -25,7 +25,7 @@ class MainWindow : public QMainWindow explicit MainWindow(QWidget *parent = 0); ~MainWindow(); -private slots: +private Q_SLOTS: void on_pushButton_signup_clicked(); void on_pushButton_login_clicked(); From fbbaf1dde67e04b84432121ee9ff83d9879a259f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:51:38 -0400 Subject: [PATCH 0279/1324] Update homepage.h --- src/qt/homepage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index e5780813..323fbe8a 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -26,7 +26,7 @@ class homepage : public QDialog void loadNotifications(); void loadFriends(); -private slots: +private Q_SLOTS: void on_pushButton_logout_clicked(); void on_pushButton_post_clicked(); From 10ae76cf88530e9ac4f31efe4e48ade27debd281 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:51:53 -0400 Subject: [PATCH 0280/1324] Update loginpage.h --- src/qt/loginpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/loginpage.h b/src/qt/loginpage.h index 253188d2..cf081890 100644 --- a/src/qt/loginpage.h +++ b/src/qt/loginpage.h @@ -16,7 +16,7 @@ class LoginPage : public QDialog explicit LoginPage(QWidget *parent = 0); ~LoginPage(); -private slots: +private Q_SLOTS: void on_pushButton_back_clicked(); void on_pushButton_login_clicked(); From b06b763bc3461d10582d46785e208de588f82cdf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:52:42 -0400 Subject: [PATCH 0281/1324] Update signuppage.h --- src/qt/signuppage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/signuppage.h b/src/qt/signuppage.h index 07bb79f9..636ddd53 100644 --- a/src/qt/signuppage.h +++ b/src/qt/signuppage.h @@ -16,7 +16,7 @@ class SignUpPage : public QDialog explicit SignUpPage(QWidget *parent = 0); ~SignUpPage(); -private slots: +private Q_SLOTS: void on_pushButton_back_clicked(); void on_pushButton_createAccount_clicked(); From 6e4dbe7a6b4766aa18c36455ede3b961c80de2fb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:00:33 -0400 Subject: [PATCH 0282/1324] Update qt.mk --- depends/packages/qt.mk | 182 ++++++++++++++++++++++++++++------------- 1 file changed, 124 insertions(+), 58 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9579f605..9674e034 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,24 +1,21 @@ PACKAGE=qt -$(package)_version=5.7.1 -$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.gz +$(package)_version=5.9.8 +$(package)_download_path=https://download.qt.io/official_releases/qt/5.9/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.xz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 -$(package)_dependencies=openssl zlib -$(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext +$(package)_sha256_hash=9b9dec1f67df1f94bce2955c5604de992d529dde72050239154c56352da0907d +$(package)_dependencies=zlib +$(package)_linux_dependencies=freetype fontconfig libxcb $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch -$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch -# NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. -# Remove it after bumping $(package)_version to 5.8+. +$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch fix_android_qmake_conf.patch fix_android_jni_static.patch +# Update OSX_QT_TRANSLATIONS when this is updated $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d - +$(package)_qttranslations_sha256_hash=fb5a47799754af73d3bf501fe513342cfe2fc37f64e80df5533f6110e804220c $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f +$(package)_qttools_sha256_hash=a97556eb7b2f30252cdd8a598c396cfce2b2f79d2bae883af6d3b26a2cdcc63c $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) @@ -29,30 +26,29 @@ $(package)_config_opts_debug = -debug $(package)_config_opts += -bindir $(build_prefix)/bin $(package)_config_opts += -c++std c++11 $(package)_config_opts += -confirm-license -$(package)_config_opts += -dbus-runtime $(package)_config_opts += -hostprefix $(build_prefix) -$(package)_config_opts += -no-alsa -$(package)_config_opts += -no-audio-backend +$(package)_config_opts += -no-compile-examples $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs -$(package)_config_opts += -no-feature-style-windowsmobile -$(package)_config_opts += -no-feature-style-windowsce $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif $(package)_config_opts += -no-glib -$(package)_config_opts += -no-gstreamer $(package)_config_opts += -no-icu +$(package)_config_opts += -no-ico $(package)_config_opts += -no-iconv $(package)_config_opts += -no-kms $(package)_config_opts += -no-linuxfb +$(package)_config_opts += -no-libjpeg +$(package)_config_opts += -no-libproxy $(package)_config_opts += -no-libudev -$(package)_config_opts += -no-mitshm $(package)_config_opts += -no-mtdev -$(package)_config_opts += -no-pulseaudio +$(package)_config_opts += -no-openssl $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug +$(package)_config_opts += -no-sctp +$(package)_config_opts += -no-securetransport $(package)_config_opts += -no-sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci @@ -62,49 +58,116 @@ $(package)_config_opts += -no-sql-odbc $(package)_config_opts += -no-sql-psql $(package)_config_opts += -no-sql-sqlite $(package)_config_opts += -no-sql-sqlite2 +$(package)_config_opts += -no-system-proxies $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 -$(package)_config_opts += -no-xrender $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource -$(package)_config_opts += -openssl-linked -$(package)_config_opts += -optimized-qmake +$(package)_config_opts += -optimized-tools $(package)_config_opts += -pch $(package)_config_opts += -pkg-config $(package)_config_opts += -prefix $(host_prefix) $(package)_config_opts += -qt-libpng -$(package)_config_opts += -qt-libjpeg $(package)_config_opts += -qt-pcre $(package)_config_opts += -qt-harfbuzz $(package)_config_opts += -system-zlib -$(package)_config_opts += -reduce-exports $(package)_config_opts += -static $(package)_config_opts += -silent $(package)_config_opts += -v -$(package)_config_opts += -no-feature-printer +$(package)_config_opts += -no-feature-bearermanagement +$(package)_config_opts += -no-feature-colordialog +$(package)_config_opts += -no-feature-commandlineparser +$(package)_config_opts += -no-feature-concurrent +$(package)_config_opts += -no-feature-dial +$(package)_config_opts += -no-feature-filesystemwatcher +$(package)_config_opts += -no-feature-fontcombobox +$(package)_config_opts += -no-feature-ftp +$(package)_config_opts += -no-feature-http +$(package)_config_opts += -no-feature-image_heuristic_mask +$(package)_config_opts += -no-feature-keysequenceedit +$(package)_config_opts += -no-feature-lcdnumber +$(package)_config_opts += -no-feature-networkdiskcache +$(package)_config_opts += -no-feature-networkproxy +$(package)_config_opts += -no-feature-pdf $(package)_config_opts += -no-feature-printdialog +$(package)_config_opts += -no-feature-printer +$(package)_config_opts += -no-feature-printpreviewdialog +$(package)_config_opts += -no-feature-printpreviewwidget +$(package)_config_opts += -no-feature-regularexpression +$(package)_config_opts += -no-feature-sessionmanager +$(package)_config_opts += -no-feature-socks5 +$(package)_config_opts += -no-feature-sql +$(package)_config_opts += -no-feature-statemachine +$(package)_config_opts += -no-feature-syntaxhighlighter +$(package)_config_opts += -no-feature-textbrowser +$(package)_config_opts += -no-feature-textodfwriter +$(package)_config_opts += -no-feature-topleveldomain +$(package)_config_opts += -no-feature-udpsocket +$(package)_config_opts += -no-feature-undocommand +$(package)_config_opts += -no-feature-undogroup +$(package)_config_opts += -no-feature-undostack +$(package)_config_opts += -no-feature-undoview +$(package)_config_opts += -no-feature-vnc +$(package)_config_opts += -no-feature-wizard +$(package)_config_opts += -no-feature-xml + +$(package)_config_opts_darwin = -no-dbus +$(package)_config_opts_darwin += -no-opengl ifneq ($(build_os),darwin) -$(package)_config_opts_darwin = -xplatform macx-clang-linux +$(package)_config_opts_darwin += -xplatform macx-clang-linux $(package)_config_opts_darwin += -device-option MAC_SDK_PATH=$(OSX_SDK) $(package)_config_opts_darwin += -device-option MAC_SDK_VERSION=$(OSX_SDK_VERSION) $(package)_config_opts_darwin += -device-option CROSS_COMPILE="$(host)-" $(package)_config_opts_darwin += -device-option MAC_MIN_VERSION=$(OSX_MIN_VERSION) $(package)_config_opts_darwin += -device-option MAC_TARGET=$(host) -$(package)_config_opts_darwin += -device-option MAC_LD64_VERSION=$(LD64_VERSION) endif -$(package)_config_opts_linux = -qt-xkbcommon +$(package)_config_opts_linux = -qt-xkbcommon-x11 $(package)_config_opts_linux += -qt-xcb +$(package)_config_opts_linux += -no-xcb-xlib +$(package)_config_opts_linux += -no-feature-xlib $(package)_config_opts_linux += -system-freetype -$(package)_config_opts_linux += -no-sm $(package)_config_opts_linux += -fontconfig $(package)_config_opts_linux += -no-opengl -$(package)_config_opts_arm_linux = -platform linux-g++ -xplatform $(host) +$(package)_config_opts_linux += -dbus-runtime +$(package)_config_opts_arm_linux += -platform linux-g++ -xplatform bitcoin-linux-g++ $(package)_config_opts_i686_linux = -xplatform linux-g++-32 -$(package)_config_opts_mingw32 = -no-opengl -xplatform win32-g++ -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_x86_64_linux = -xplatform linux-g++-64 +$(package)_config_opts_aarch64_linux = -xplatform linux-aarch64-gnu-g++ +$(package)_config_opts_powerpc64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ +$(package)_config_opts_powerpc64le_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ +$(package)_config_opts_riscv64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ +$(package)_config_opts_s390x_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ + +$(package)_config_opts_mingw32 = -no-opengl +$(package)_config_opts_mingw32 += -no-dbus +$(package)_config_opts_mingw32 += -xplatform win32-g++ +$(package)_config_opts_mingw32 += -device-option CROSS_COMPILE="$(host)-" + +$(package)_config_opts_android = -xplatform android-clang +$(package)_config_opts_android += -android-sdk $(ANDROID_SDK) +$(package)_config_opts_android += -android-ndk $(ANDROID_NDK) +$(package)_config_opts_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) +$(package)_config_opts_android += -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_android += -egl +$(package)_config_opts_android += -qpa xcb +$(package)_config_opts_android += -no-eglfs +$(package)_config_opts_android += -no-dbus +$(package)_config_opts_android += -opengl es2 +$(package)_config_opts_android += -qt-freetype +$(package)_config_opts_android += -no-fontconfig +$(package)_config_opts_android += -L $(host_prefix)/lib +$(package)_config_opts_android += -I $(host_prefix)/include + +$(package)_config_opts_aarch64_android += -android-arch arm64-v8a +$(package)_config_opts_armv7a_android += -android-arch armeabi-v7a +$(package)_config_opts_x86_64_android += -android-arch x86_64 +$(package)_config_opts_i686_android += -android-arch i686 + $(package)_build_env = QT_RCC_TEST=1 +$(package)_build_env += QT_RCC_SOURCE_DATE_OVERRIDE=1 endef define $(package)_fetch_cmds @@ -120,43 +183,49 @@ define $(package)_extract_cmds echo "$($(package)_qttools_sha256_hash) $($(package)_source_dir)/$($(package)_qttools_file_name)" >> $($(package)_extract_dir)/.$($(package)_file_name).hash && \ $(build_SHA256SUM) -c $($(package)_extract_dir)/.$($(package)_file_name).hash && \ mkdir qtbase && \ - tar --strip-components=1 -xf $($(package)_source) -C qtbase && \ + tar --no-same-owner --strip-components=1 -xf $($(package)_source) -C qtbase && \ mkdir qttranslations && \ - tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttranslations_file_name) -C qttranslations && \ + tar --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttranslations_file_name) -C qttranslations && \ mkdir qttools && \ - tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttools_file_name) -C qttools + tar --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttools_file_name) -C qttools endef - define $(package)_preprocess_cmds + sed -i.old "s|FT_Get_Font_Format|FT_Get_X11_Font_Format|" qtbase/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp && \ sed -i.old "s|updateqm.commands = \$$$$\$$$$LRELEASE|updateqm.commands = $($(package)_extract_dir)/qttools/bin/lrelease|" qttranslations/translations/translations.pro && \ sed -i.old "/updateqm.depends =/d" qttranslations/translations/translations.pro && \ - sed -i.old "s/src_plugins.depends = src_sql src_xml src_network/src_plugins.depends = src_xml src_network/" qtbase/src/src.pro && \ - sed -i.old "s|X11/extensions/XIproto.h|X11/X.h|" qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp && \ - sed -i.old 's/if \[ "$$$$XPLATFORM_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/if \[ "$$$$BUILD_ON_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/' qtbase/configure && \ - sed -i.old 's/CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0)/CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, kCGMouseButtonLeft)/' qtbase/src/plugins/platforms/cocoa/qcocoacursor.mm && \ + sed -i.old "s/src_plugins.depends = src_sql src_network/src_plugins.depends = src_network/" qtbase/src/src.pro && \ + sed -i.old -e 's/if \[ "$$$$XPLATFORM_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/if \[ "$$$$BUILD_ON_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/' -e 's|/bin/pwd|pwd|' qtbase/configure && \ mkdir -p qtbase/mkspecs/macx-clang-linux &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ - patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ - patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ - patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ - patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ + cp -r qtbase/mkspecs/linux-arm-gnueabi-g++ qtbase/mkspecs/bitcoin-linux-g++ && \ + sed -i.old "s/arm-linux-gnueabi-/$(host)-/g" qtbase/mkspecs/bitcoin-linux-g++/qmake.conf && \ + patch -p1 -i $($(package)_patch_dir)/fix_qt_pkgconfig.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_configure_mac.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_no_printer.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ + patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_android_qmake_conf.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_android_jni_static.patch &&\ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ - sed -i.old "s|QMAKE_CFLAGS = |!host_build: QMAKE_CFLAGS = $($(package)_cflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ - sed -i.old "s|QMAKE_LFLAGS = |!host_build: QMAKE_LFLAGS = $($(package)_ldflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ - sed -i.old "s|QMAKE_CXXFLAGS = |!host_build: QMAKE_CXXFLAGS = $($(package)_cxxflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf - + patch -p1 -i $($(package)_patch_dir)/fix_riscv64_arch.patch &&\ + patch -p1 -i $($(package)_patch_dir)/no-xlib.patch &&\ + echo "QMAKE_LINK_OBJECT_MAX = 10" >> qtbase/mkspecs/win32-g++/qmake.conf &&\ + echo "QMAKE_LINK_OBJECT_SCRIPT = object_script" >> qtbase/mkspecs/win32-g++/qmake.conf &&\ + sed -i.old "s|QMAKE_CFLAGS += |!host_build: QMAKE_CFLAGS = $($(package)_cflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ + sed -i.old "s|QMAKE_CXXFLAGS += |!host_build: QMAKE_CXXFLAGS = $($(package)_cxxflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ + sed -i.old "0,/^QMAKE_LFLAGS_/s|^QMAKE_LFLAGS_|!host_build: QMAKE_LFLAGS = $($(package)_ldflags)\n&|" qtbase/mkspecs/win32-g++/qmake.conf && \ + sed -i.old "s|QMAKE_CC = clang|QMAKE_CC = $($(package)_cc)|" qtbase/mkspecs/common/clang.conf && \ + sed -i.old "s|QMAKE_CXX = clang++|QMAKE_CXX = $($(package)_cxx)|" qtbase/mkspecs/common/clang.conf && \ + sed -i.old "s/LIBRARY_PATH/(CROSS_)?\0/g" qtbase/mkspecs/features/toolchain.prf endef - define $(package)_config_cmds + export PKG_CONFIG_SYSROOT_DIR=/ && \ export PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig && \ export PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig && \ ./configure $($(package)_config_opts) && \ @@ -164,20 +233,18 @@ define $(package)_config_cmds echo "CONFIG += force_bootstrap" >> mkspecs/qconfig.pri && \ $(MAKE) sub-src-clean && \ cd ../qttranslations && ../qtbase/bin/qmake qttranslations.pro -o Makefile && \ - cd translations && ../../qtbase/bin/qmake translations.pro -o Makefile && cd ../.. &&\ + cd translations && ../../qtbase/bin/qmake translations.pro -o Makefile && cd ../.. && \ cd qttools/src/linguist/lrelease/ && ../../../../qtbase/bin/qmake lrelease.pro -o Makefile && \ cd ../lupdate/ && ../../../../qtbase/bin/qmake lupdate.pro -o Makefile && cd ../../../.. endef - define $(package)_build_cmds $(MAKE) -C src $(addprefix sub-,$($(package)_qt_libs)) && \ $(MAKE) -C ../qttools/src/linguist/lrelease && \ $(MAKE) -C ../qttools/src/linguist/lupdate && \ $(MAKE) -C ../qttranslations endef - define $(package)_stage_cmds - $(MAKE) -C src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && cd .. &&\ + $(MAKE) -C src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && cd .. && \ $(MAKE) -C qttools/src/linguist/lrelease INSTALL_ROOT=$($(package)_staging_dir) install_target && \ $(MAKE) -C qttools/src/linguist/lupdate INSTALL_ROOT=$($(package)_staging_dir) install_target && \ $(MAKE) -C qttranslations INSTALL_ROOT=$($(package)_staging_dir) install_subtargets && \ @@ -185,7 +252,6 @@ define $(package)_stage_cmds cp qtbase/src/plugins/platforms/xcb/xcb-static/libxcb-static.a $($(package)_staging_prefix_dir)/lib; \ fi endef - define $(package)_postprocess_cmds rm -rf native/mkspecs/ native/lib/ lib/cmake/ && \ rm -f lib/lib*.la lib/*.prl plugins/*/*.prl From 5fb64e757587e002555c7cc3438f3e81459f0785 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:03:27 -0400 Subject: [PATCH 0283/1324] Create fix_riscv64_arch.patch --- depends/patches/qt/fix_riscv64_arch.patch | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 depends/patches/qt/fix_riscv64_arch.patch diff --git a/depends/patches/qt/fix_riscv64_arch.patch b/depends/patches/qt/fix_riscv64_arch.patch new file mode 100644 index 00000000..e7f29f01 --- /dev/null +++ b/depends/patches/qt/fix_riscv64_arch.patch @@ -0,0 +1,14 @@ +diff --git a/qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h b/qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h +index 20bfd36..93729fa 100644 +--- a/qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h ++++ b/qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h +@@ -65,7 +65,8 @@ + defined(__sparc__) || defined(__sparc) || defined(__s390__) || \ + defined(__SH4__) || defined(__alpha__) || \ + defined(_MIPS_ARCH_MIPS32R2) || \ +- defined(__AARCH64EL__) ++ defined(__AARCH64EL__) || defined(__aarch64__) || \ ++ defined(__riscv) + #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 + #elif defined(_M_IX86) || defined(__i386__) || defined(__i386) + #if defined(_WIN32) From d5861ef1e4b13344224bdace0418ed9e3a90d27b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:03:56 -0400 Subject: [PATCH 0284/1324] Create fix_android_jni_static.patch --- depends/patches/qt/fix_android_jni_static.patch | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 depends/patches/qt/fix_android_jni_static.patch diff --git a/depends/patches/qt/fix_android_jni_static.patch b/depends/patches/qt/fix_android_jni_static.patch new file mode 100644 index 00000000..12a358f0 --- /dev/null +++ b/depends/patches/qt/fix_android_jni_static.patch @@ -0,0 +1,17 @@ +--- old/qtbase/src/plugins/platforms/android/androidjnimain.cpp ++++ new/qtbase/src/plugins/platforms/android/androidjnimain.cpp +@@ -890,6 +890,14 @@ + __android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed"); + return -1; + } ++ ++ const jint ret = QT_PREPEND_NAMESPACE(QtAndroidPrivate::initJNI(vm, env)); ++ if (ret != 0) ++ { ++ __android_log_print(ANDROID_LOG_FATAL, "Qt", "initJNI failed"); ++ return ret; ++ } ++ + QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false); + + m_javaVM = vm; From 01440a5dc9d00912ab1dcd4d7a2e5c82c15e0fe5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:04:31 -0400 Subject: [PATCH 0285/1324] Create fix_android_qmake_conf.patch --- .../patches/qt/fix_android_qmake_conf.patch | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 depends/patches/qt/fix_android_qmake_conf.patch diff --git a/depends/patches/qt/fix_android_qmake_conf.patch b/depends/patches/qt/fix_android_qmake_conf.patch new file mode 100644 index 00000000..13bfff97 --- /dev/null +++ b/depends/patches/qt/fix_android_qmake_conf.patch @@ -0,0 +1,20 @@ +--- old/qtbase/mkspecs/android-clang/qmake.conf ++++ new/qtbase/mkspecs/android-clang/qmake.conf +@@ -30,7 +30,7 @@ + QMAKE_CFLAGS += -target mips64el-none-linux-android + + QMAKE_CFLAGS += -gcc-toolchain $$NDK_TOOLCHAIN_PATH +-QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a ++QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a -nostdlib++ + QMAKE_CFLAGS += -DANDROID_HAS_WSTRING --sysroot=$$NDK_ROOT/sysroot \ + -isystem $$NDK_ROOT/sysroot/usr/include/$$NDK_TOOLS_PREFIX \ + -isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++/include \ +@@ -40,7 +40,7 @@ + ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$$ANDROID_TARGET_ARCH + + ANDROID_STDCPP_PATH = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++_shared.so +-ANDROID_CXX_STL_LIBS = -lc++ ++ANDROID_CXX_STL_LIBS = -lc++_shared + + QMAKE_ARM_CFLAGS_RELEASE = -Oz + QMAKE_ARM_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Oz From 89051f9244d931b1444f3d26d7a440ac91a579e4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:05:16 -0400 Subject: [PATCH 0286/1324] Create no-xlib.patch --- depends/patches/qt/no-xlib.patch | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 depends/patches/qt/no-xlib.patch diff --git a/depends/patches/qt/no-xlib.patch b/depends/patches/qt/no-xlib.patch new file mode 100644 index 00000000..90979311 --- /dev/null +++ b/depends/patches/qt/no-xlib.patch @@ -0,0 +1,68 @@ +From 9563cef873ae82e06f60708d706d054717e801ce Mon Sep 17 00:00:00 2001 +From: Carl Dong +Date: Thu, 18 Jul 2019 17:22:05 -0400 +Subject: [PATCH] Wrap xlib related code blocks in #if's + +They are not necessary to compile QT. +--- + qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp b/qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp +index 7c62c2e2b3..c05c6c0a07 100644 +--- a/qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp ++++ b/qtbase/src/plugins/platforms/xcb/qxcbcursor.cpp +@@ -49,7 +49,9 @@ + #include + #include + #include ++#if QT_CONFIG(xcb_xlib) && QT_CONFIG(library) + #include ++#endif + #include + #include + +@@ -384,6 +386,7 @@ void QXcbCursor::changeCursor(QCursor *cursor, QWindow *widget) + w->setCursor(c, isBitmapCursor); + } + ++#if QT_CONFIG(xcb_xlib) && QT_CONFIG(library) + static int cursorIdForShape(int cshape) + { + int cursorId = 0; +@@ -437,6 +440,7 @@ static int cursorIdForShape(int cshape) + } + return cursorId; + } ++#endif + + xcb_cursor_t QXcbCursor::createNonStandardCursor(int cshape) + { +@@ -558,7 +562,9 @@ static xcb_cursor_t loadCursor(void *dpy, int cshape) + xcb_cursor_t QXcbCursor::createFontCursor(int cshape) + { + xcb_connection_t *conn = xcb_connection(); ++#if QT_CONFIG(xcb_xlib) && QT_CONFIG(library) + int cursorId = cursorIdForShape(cshape); ++#endif + xcb_cursor_t cursor = XCB_NONE; + + // Try Xcursor first +@@ -589,6 +595,7 @@ xcb_cursor_t QXcbCursor::createFontCursor(int cshape) + // Non-standard X11 cursors are created from bitmaps + cursor = createNonStandardCursor(cshape); + ++#if QT_CONFIG(xcb_xlib) && QT_CONFIG(library) + // Create a glpyh cursor if everything else failed + if (!cursor && cursorId) { + cursor = xcb_generate_id(conn); +@@ -596,6 +603,7 @@ xcb_cursor_t QXcbCursor::createFontCursor(int cshape) + cursorId, cursorId + 1, + 0xFFFF, 0xFFFF, 0xFFFF, 0, 0, 0); + } ++#endif + + if (cursor && cshape >= 0 && cshape < Qt::LastCursor && connection()->hasXFixes()) { + const char *name = cursorNames[cshape]; +-- +2.22.0 From d7fe6acae6afa3a2865ed95d67b9cee75c542072 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:18:26 -0400 Subject: [PATCH 0287/1324] Update qt.mk --- depends/packages/qt.mk | 182 +++++++++++++---------------------------- 1 file changed, 58 insertions(+), 124 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9674e034..9579f605 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -1,21 +1,24 @@ PACKAGE=qt -$(package)_version=5.9.8 -$(package)_download_path=https://download.qt.io/official_releases/qt/5.9/$($(package)_version)/submodules -$(package)_suffix=opensource-src-$($(package)_version).tar.xz +$(package)_version=5.7.1 +$(package)_download_path=https://download.qt.io/new_archive/qt/5.7/$($(package)_version)/submodules +$(package)_suffix=opensource-src-$($(package)_version).tar.gz $(package)_file_name=qtbase-$($(package)_suffix) -$(package)_sha256_hash=9b9dec1f67df1f94bce2955c5604de992d529dde72050239154c56352da0907d -$(package)_dependencies=zlib -$(package)_linux_dependencies=freetype fontconfig libxcb +$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410 +$(package)_dependencies=openssl zlib +$(package)_linux_dependencies=freetype fontconfig libxcb libX11 xproto libXext $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch fix_android_qmake_conf.patch fix_android_jni_static.patch +$(package)_patches=mac-qmake.conf mingw-uuidof.patch pidlist_absolute.patch fix-xcb-include-order.patch +$(package)_patches+=fix_qt_configure.patch fix_qt_pkgconfig.patch fix-cocoahelpers-macos.patch qfixed-coretext.patch +# NOTE: fix_qt_configure.patch is only needed for Qt 5.7, newer versions don't have this issue. +# Remove it after bumping $(package)_version to 5.8+. -# Update OSX_QT_TRANSLATIONS when this is updated $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) -$(package)_qttranslations_sha256_hash=fb5a47799754af73d3bf501fe513342cfe2fc37f64e80df5533f6110e804220c +$(package)_qttranslations_sha256_hash=3a15aebd523c6d89fb97b2d3df866c94149653a26d27a00aac9b6d3020bc5a1d + $(package)_qttools_file_name=qttools-$($(package)_suffix) -$(package)_qttools_sha256_hash=a97556eb7b2f30252cdd8a598c396cfce2b2f79d2bae883af6d3b26a2cdcc63c +$(package)_qttools_sha256_hash=22d67de915cb8cd93e16fdd38fa006224ad9170bd217c2be1e53045a8dd02f0f $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) @@ -26,29 +29,30 @@ $(package)_config_opts_debug = -debug $(package)_config_opts += -bindir $(build_prefix)/bin $(package)_config_opts += -c++std c++11 $(package)_config_opts += -confirm-license +$(package)_config_opts += -dbus-runtime $(package)_config_opts += -hostprefix $(build_prefix) -$(package)_config_opts += -no-compile-examples +$(package)_config_opts += -no-alsa +$(package)_config_opts += -no-audio-backend $(package)_config_opts += -no-cups $(package)_config_opts += -no-egl $(package)_config_opts += -no-eglfs +$(package)_config_opts += -no-feature-style-windowsmobile +$(package)_config_opts += -no-feature-style-windowsce $(package)_config_opts += -no-freetype $(package)_config_opts += -no-gif $(package)_config_opts += -no-glib +$(package)_config_opts += -no-gstreamer $(package)_config_opts += -no-icu -$(package)_config_opts += -no-ico $(package)_config_opts += -no-iconv $(package)_config_opts += -no-kms $(package)_config_opts += -no-linuxfb -$(package)_config_opts += -no-libjpeg -$(package)_config_opts += -no-libproxy $(package)_config_opts += -no-libudev +$(package)_config_opts += -no-mitshm $(package)_config_opts += -no-mtdev -$(package)_config_opts += -no-openssl +$(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug -$(package)_config_opts += -no-sctp -$(package)_config_opts += -no-securetransport $(package)_config_opts += -no-sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci @@ -58,116 +62,49 @@ $(package)_config_opts += -no-sql-odbc $(package)_config_opts += -no-sql-psql $(package)_config_opts += -no-sql-sqlite $(package)_config_opts += -no-sql-sqlite2 -$(package)_config_opts += -no-system-proxies $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 +$(package)_config_opts += -no-xrender $(package)_config_opts += -nomake examples $(package)_config_opts += -nomake tests $(package)_config_opts += -opensource -$(package)_config_opts += -optimized-tools +$(package)_config_opts += -openssl-linked +$(package)_config_opts += -optimized-qmake $(package)_config_opts += -pch $(package)_config_opts += -pkg-config $(package)_config_opts += -prefix $(host_prefix) $(package)_config_opts += -qt-libpng +$(package)_config_opts += -qt-libjpeg $(package)_config_opts += -qt-pcre $(package)_config_opts += -qt-harfbuzz $(package)_config_opts += -system-zlib +$(package)_config_opts += -reduce-exports $(package)_config_opts += -static $(package)_config_opts += -silent $(package)_config_opts += -v -$(package)_config_opts += -no-feature-bearermanagement -$(package)_config_opts += -no-feature-colordialog -$(package)_config_opts += -no-feature-commandlineparser -$(package)_config_opts += -no-feature-concurrent -$(package)_config_opts += -no-feature-dial -$(package)_config_opts += -no-feature-filesystemwatcher -$(package)_config_opts += -no-feature-fontcombobox -$(package)_config_opts += -no-feature-ftp -$(package)_config_opts += -no-feature-http -$(package)_config_opts += -no-feature-image_heuristic_mask -$(package)_config_opts += -no-feature-keysequenceedit -$(package)_config_opts += -no-feature-lcdnumber -$(package)_config_opts += -no-feature-networkdiskcache -$(package)_config_opts += -no-feature-networkproxy -$(package)_config_opts += -no-feature-pdf -$(package)_config_opts += -no-feature-printdialog $(package)_config_opts += -no-feature-printer -$(package)_config_opts += -no-feature-printpreviewdialog -$(package)_config_opts += -no-feature-printpreviewwidget -$(package)_config_opts += -no-feature-regularexpression -$(package)_config_opts += -no-feature-sessionmanager -$(package)_config_opts += -no-feature-socks5 -$(package)_config_opts += -no-feature-sql -$(package)_config_opts += -no-feature-statemachine -$(package)_config_opts += -no-feature-syntaxhighlighter -$(package)_config_opts += -no-feature-textbrowser -$(package)_config_opts += -no-feature-textodfwriter -$(package)_config_opts += -no-feature-topleveldomain -$(package)_config_opts += -no-feature-udpsocket -$(package)_config_opts += -no-feature-undocommand -$(package)_config_opts += -no-feature-undogroup -$(package)_config_opts += -no-feature-undostack -$(package)_config_opts += -no-feature-undoview -$(package)_config_opts += -no-feature-vnc -$(package)_config_opts += -no-feature-wizard -$(package)_config_opts += -no-feature-xml - -$(package)_config_opts_darwin = -no-dbus -$(package)_config_opts_darwin += -no-opengl +$(package)_config_opts += -no-feature-printdialog ifneq ($(build_os),darwin) -$(package)_config_opts_darwin += -xplatform macx-clang-linux +$(package)_config_opts_darwin = -xplatform macx-clang-linux $(package)_config_opts_darwin += -device-option MAC_SDK_PATH=$(OSX_SDK) $(package)_config_opts_darwin += -device-option MAC_SDK_VERSION=$(OSX_SDK_VERSION) $(package)_config_opts_darwin += -device-option CROSS_COMPILE="$(host)-" $(package)_config_opts_darwin += -device-option MAC_MIN_VERSION=$(OSX_MIN_VERSION) $(package)_config_opts_darwin += -device-option MAC_TARGET=$(host) +$(package)_config_opts_darwin += -device-option MAC_LD64_VERSION=$(LD64_VERSION) endif -$(package)_config_opts_linux = -qt-xkbcommon-x11 +$(package)_config_opts_linux = -qt-xkbcommon $(package)_config_opts_linux += -qt-xcb -$(package)_config_opts_linux += -no-xcb-xlib -$(package)_config_opts_linux += -no-feature-xlib $(package)_config_opts_linux += -system-freetype +$(package)_config_opts_linux += -no-sm $(package)_config_opts_linux += -fontconfig $(package)_config_opts_linux += -no-opengl -$(package)_config_opts_linux += -dbus-runtime -$(package)_config_opts_arm_linux += -platform linux-g++ -xplatform bitcoin-linux-g++ +$(package)_config_opts_arm_linux = -platform linux-g++ -xplatform $(host) $(package)_config_opts_i686_linux = -xplatform linux-g++-32 -$(package)_config_opts_x86_64_linux = -xplatform linux-g++-64 -$(package)_config_opts_aarch64_linux = -xplatform linux-aarch64-gnu-g++ -$(package)_config_opts_powerpc64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ -$(package)_config_opts_powerpc64le_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ -$(package)_config_opts_riscv64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ -$(package)_config_opts_s390x_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ - -$(package)_config_opts_mingw32 = -no-opengl -$(package)_config_opts_mingw32 += -no-dbus -$(package)_config_opts_mingw32 += -xplatform win32-g++ -$(package)_config_opts_mingw32 += -device-option CROSS_COMPILE="$(host)-" - -$(package)_config_opts_android = -xplatform android-clang -$(package)_config_opts_android += -android-sdk $(ANDROID_SDK) -$(package)_config_opts_android += -android-ndk $(ANDROID_NDK) -$(package)_config_opts_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) -$(package)_config_opts_android += -device-option CROSS_COMPILE="$(host)-" -$(package)_config_opts_android += -egl -$(package)_config_opts_android += -qpa xcb -$(package)_config_opts_android += -no-eglfs -$(package)_config_opts_android += -no-dbus -$(package)_config_opts_android += -opengl es2 -$(package)_config_opts_android += -qt-freetype -$(package)_config_opts_android += -no-fontconfig -$(package)_config_opts_android += -L $(host_prefix)/lib -$(package)_config_opts_android += -I $(host_prefix)/include - -$(package)_config_opts_aarch64_android += -android-arch arm64-v8a -$(package)_config_opts_armv7a_android += -android-arch armeabi-v7a -$(package)_config_opts_x86_64_android += -android-arch x86_64 -$(package)_config_opts_i686_android += -android-arch i686 - +$(package)_config_opts_mingw32 = -no-opengl -xplatform win32-g++ -device-option CROSS_COMPILE="$(host)-" $(package)_build_env = QT_RCC_TEST=1 -$(package)_build_env += QT_RCC_SOURCE_DATE_OVERRIDE=1 endef define $(package)_fetch_cmds @@ -183,49 +120,43 @@ define $(package)_extract_cmds echo "$($(package)_qttools_sha256_hash) $($(package)_source_dir)/$($(package)_qttools_file_name)" >> $($(package)_extract_dir)/.$($(package)_file_name).hash && \ $(build_SHA256SUM) -c $($(package)_extract_dir)/.$($(package)_file_name).hash && \ mkdir qtbase && \ - tar --no-same-owner --strip-components=1 -xf $($(package)_source) -C qtbase && \ + tar --strip-components=1 -xf $($(package)_source) -C qtbase && \ mkdir qttranslations && \ - tar --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttranslations_file_name) -C qttranslations && \ + tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttranslations_file_name) -C qttranslations && \ mkdir qttools && \ - tar --no-same-owner --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttools_file_name) -C qttools + tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_qttools_file_name) -C qttools endef + define $(package)_preprocess_cmds - sed -i.old "s|FT_Get_Font_Format|FT_Get_X11_Font_Format|" qtbase/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp && \ sed -i.old "s|updateqm.commands = \$$$$\$$$$LRELEASE|updateqm.commands = $($(package)_extract_dir)/qttools/bin/lrelease|" qttranslations/translations/translations.pro && \ sed -i.old "/updateqm.depends =/d" qttranslations/translations/translations.pro && \ - sed -i.old "s/src_plugins.depends = src_sql src_network/src_plugins.depends = src_network/" qtbase/src/src.pro && \ - sed -i.old -e 's/if \[ "$$$$XPLATFORM_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/if \[ "$$$$BUILD_ON_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/' -e 's|/bin/pwd|pwd|' qtbase/configure && \ + sed -i.old "s/src_plugins.depends = src_sql src_xml src_network/src_plugins.depends = src_xml src_network/" qtbase/src/src.pro && \ + sed -i.old "s|X11/extensions/XIproto.h|X11/X.h|" qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp && \ + sed -i.old 's/if \[ "$$$$XPLATFORM_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/if \[ "$$$$BUILD_ON_MAC" = "yes" \]; then xspecvals=$$$$(macSDKify/' qtbase/configure && \ + sed -i.old 's/CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0)/CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, kCGMouseButtonLeft)/' qtbase/src/plugins/platforms/cocoa/qcocoacursor.mm && \ mkdir -p qtbase/mkspecs/macx-clang-linux &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.lib qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/Info.plist.app qtbase/mkspecs/macx-clang-linux/ &&\ cp -f qtbase/mkspecs/macx-clang/qplatformdefs.h qtbase/mkspecs/macx-clang-linux/ &&\ cp -f $($(package)_patch_dir)/mac-qmake.conf qtbase/mkspecs/macx-clang-linux/qmake.conf && \ - cp -r qtbase/mkspecs/linux-arm-gnueabi-g++ qtbase/mkspecs/bitcoin-linux-g++ && \ - sed -i.old "s/arm-linux-gnueabi-/$(host)-/g" qtbase/mkspecs/bitcoin-linux-g++/qmake.conf && \ - patch -p1 -i $($(package)_patch_dir)/fix_qt_pkgconfig.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_configure_mac.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_no_printer.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ - patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_android_qmake_conf.patch &&\ - patch -p1 -i $($(package)_patch_dir)/fix_android_jni_static.patch &&\ + patch -p1 < $($(package)_patch_dir)/mingw-uuidof.patch && \ + patch -p1 < $($(package)_patch_dir)/pidlist_absolute.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-xcb-include-order.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_configure.patch && \ + patch -p1 < $($(package)_patch_dir)/fix_qt_pkgconfig.patch && \ + patch -p1 < $($(package)_patch_dir)/fix-cocoahelpers-macos.patch && \ + patch -p1 < $($(package)_patch_dir)/qfixed-coretext.patch && \ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ - patch -p1 -i $($(package)_patch_dir)/fix_riscv64_arch.patch &&\ - patch -p1 -i $($(package)_patch_dir)/no-xlib.patch &&\ - echo "QMAKE_LINK_OBJECT_MAX = 10" >> qtbase/mkspecs/win32-g++/qmake.conf &&\ - echo "QMAKE_LINK_OBJECT_SCRIPT = object_script" >> qtbase/mkspecs/win32-g++/qmake.conf &&\ - sed -i.old "s|QMAKE_CFLAGS += |!host_build: QMAKE_CFLAGS = $($(package)_cflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ - sed -i.old "s|QMAKE_CXXFLAGS += |!host_build: QMAKE_CXXFLAGS = $($(package)_cxxflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ - sed -i.old "0,/^QMAKE_LFLAGS_/s|^QMAKE_LFLAGS_|!host_build: QMAKE_LFLAGS = $($(package)_ldflags)\n&|" qtbase/mkspecs/win32-g++/qmake.conf && \ - sed -i.old "s|QMAKE_CC = clang|QMAKE_CC = $($(package)_cc)|" qtbase/mkspecs/common/clang.conf && \ - sed -i.old "s|QMAKE_CXX = clang++|QMAKE_CXX = $($(package)_cxx)|" qtbase/mkspecs/common/clang.conf && \ - sed -i.old "s/LIBRARY_PATH/(CROSS_)?\0/g" qtbase/mkspecs/features/toolchain.prf + sed -i.old "s|QMAKE_CFLAGS = |!host_build: QMAKE_CFLAGS = $($(package)_cflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ + sed -i.old "s|QMAKE_LFLAGS = |!host_build: QMAKE_LFLAGS = $($(package)_ldflags) |" qtbase/mkspecs/win32-g++/qmake.conf && \ + sed -i.old "s|QMAKE_CXXFLAGS = |!host_build: QMAKE_CXXFLAGS = $($(package)_cxxflags) $($(package)_cppflags) |" qtbase/mkspecs/win32-g++/qmake.conf + endef + define $(package)_config_cmds - export PKG_CONFIG_SYSROOT_DIR=/ && \ export PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig && \ export PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig && \ ./configure $($(package)_config_opts) && \ @@ -233,18 +164,20 @@ define $(package)_config_cmds echo "CONFIG += force_bootstrap" >> mkspecs/qconfig.pri && \ $(MAKE) sub-src-clean && \ cd ../qttranslations && ../qtbase/bin/qmake qttranslations.pro -o Makefile && \ - cd translations && ../../qtbase/bin/qmake translations.pro -o Makefile && cd ../.. && \ + cd translations && ../../qtbase/bin/qmake translations.pro -o Makefile && cd ../.. &&\ cd qttools/src/linguist/lrelease/ && ../../../../qtbase/bin/qmake lrelease.pro -o Makefile && \ cd ../lupdate/ && ../../../../qtbase/bin/qmake lupdate.pro -o Makefile && cd ../../../.. endef + define $(package)_build_cmds $(MAKE) -C src $(addprefix sub-,$($(package)_qt_libs)) && \ $(MAKE) -C ../qttools/src/linguist/lrelease && \ $(MAKE) -C ../qttools/src/linguist/lupdate && \ $(MAKE) -C ../qttranslations endef + define $(package)_stage_cmds - $(MAKE) -C src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && cd .. && \ + $(MAKE) -C src INSTALL_ROOT=$($(package)_staging_dir) $(addsuffix -install_subtargets,$(addprefix sub-,$($(package)_qt_libs))) && cd .. &&\ $(MAKE) -C qttools/src/linguist/lrelease INSTALL_ROOT=$($(package)_staging_dir) install_target && \ $(MAKE) -C qttools/src/linguist/lupdate INSTALL_ROOT=$($(package)_staging_dir) install_target && \ $(MAKE) -C qttranslations INSTALL_ROOT=$($(package)_staging_dir) install_subtargets && \ @@ -252,6 +185,7 @@ define $(package)_stage_cmds cp qtbase/src/plugins/platforms/xcb/xcb-static/libxcb-static.a $($(package)_staging_prefix_dir)/lib; \ fi endef + define $(package)_postprocess_cmds rm -rf native/mkspecs/ native/lib/ lib/cmake/ && \ rm -f lib/lib*.la lib/*.prl plugins/*/*.prl From 44add2ce248a210087ca503f1776d42ee431681f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:34:12 -0400 Subject: [PATCH 0288/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 66f22f2e..0ae40c6a 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,3 +1,5 @@ +QT += core +QT += network QT += sql FORMS += \ From 85179373621e3fd5429058a3425569b7585374ab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:39:04 -0400 Subject: [PATCH 0289/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e0d872f5..147f4b8d 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,11 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui + qt/forms/transactiondescdialog.ui \ + qt/forms/mainwindow.ui \ + qt/forms/signuppage.ui \ + qt/forms/loginpage.ui \ + qt/forms/homepage.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -106,7 +110,12 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp + qt/moc_walletview.cpp \ + qt/moc_main.cpp \ + qt/moc_mainwindow.cpp \ + qt/moc_signuppage.cpp \ + qt/moc_loginpage.cpp \ + qt/moc_homepage.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -190,7 +199,12 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h + qt/winshutdownmonitor.h \ + qt/mainwindow.h \ + qt/signuppage.h \ + qt/loginpage.h \ + qt/homepage.h + RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -529,7 +543,12 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp + qt/walletview.cpp \ + qt/main.cpp \ + qt/mainwindow.cpp \ + qt/signuppage.cpp \ + qt/loginpage.cpp \ + qt/homepage.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 5b8d49a4d728383c3764135ae63a3a09b3aa08cb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:41:16 -0400 Subject: [PATCH 0290/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 2422b62e..d5c9414f 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From c77f7511fa6aa4d45718daf25ec6c57d0ba96d54 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:42:37 -0400 Subject: [PATCH 0291/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index d5c9414f..2422b62e 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From 54111ef7920f3a6b86a6a80e84fa17a031e32251 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:44:03 -0400 Subject: [PATCH 0292/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 2422b62e..d38a9b66 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From af2fc0200944a40134ea2ea8e062257ac7a98f3c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:51:30 -0400 Subject: [PATCH 0293/1324] Delete SocialMediaApp.pro --- src/qt/SocialMediaApp.pro | 45 --------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/qt/SocialMediaApp.pro diff --git a/src/qt/SocialMediaApp.pro b/src/qt/SocialMediaApp.pro deleted file mode 100644 index 5a2c9ca1..00000000 --- a/src/qt/SocialMediaApp.pro +++ /dev/null @@ -1,45 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2018-01-13T14:05:16 -# -#------------------------------------------------- - -QT += core gui sql - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = SocialMediaApp -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - -SOURCES += \ - main.cpp \ - mainwindow.cpp \ - signuppage.cpp \ - loginpage.cpp \ - homepage.cpp - -HEADERS += \ - mainwindow.h \ - signuppage.h \ - loginpage.h \ - homepage.h - -FORMS += \ - forms/mainwindow.ui \ - forms/signuppage.ui \ - forms/loginpage.ui \ - forms/homepage.ui - -RESOURCES += From 493f8c2d7bf6ae97815c0455cfdd87c961690562 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:52:28 -0400 Subject: [PATCH 0294/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index d38a9b66..35e48afd 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,9 +2,10 @@ #define MAINWINDOW_H #include -#include +#include #include #include +#include #include "signuppage.h" #include "loginpage.h" From 184207e7d249f982b694aae9e34cb1fb9b1749db Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:52:53 -0400 Subject: [PATCH 0295/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 35e48afd..a0cc1e2d 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include #include From 4cd0d4375ec1e2b0a5c1c1b52019a542ac0218bb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:53:17 -0400 Subject: [PATCH 0296/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index a0cc1e2d..a4ff0eb2 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +/*#include */ #include #include #include From e5302c10fcef3697af93dd2346d1aa7527a36059 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:53:41 -0400 Subject: [PATCH 0297/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index a4ff0eb2..60ef2626 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -5,7 +5,7 @@ /*#include */ #include #include -#include +#include #include "signuppage.h" #include "loginpage.h" From 7bb4dd81fa60b7071d36b9fbc8c4063e5332f8be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:54:09 -0400 Subject: [PATCH 0298/1324] Update mainwindow.h --- src/qt/mainwindow.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 60ef2626..08cb5a27 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,10 +2,10 @@ #define MAINWINDOW_H #include -/*#include */ +#include #include #include -#include + #include "signuppage.h" #include "loginpage.h" From 8986d14f9bba3f01816cb4522d425615be578ed4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:55:06 -0400 Subject: [PATCH 0299/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 0ae40c6a..f23b0bab 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,6 +1,4 @@ -QT += core -QT += network -QT += sql +@QT += core gui sql@ FORMS += \ ../src/qt/forms/aboutdialog.ui \ From 3d93c1a643d85a326dc6c165a66c3c8390d0498f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:56:09 -0400 Subject: [PATCH 0300/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 08cb5a27..1ddf6cf0 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +@#include @ #include #include From 4bf52d9a6a1772d4c8feabe6112d9b53bc4103bc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:57:05 -0400 Subject: [PATCH 0301/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 1ddf6cf0..c83ab9be 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -@#include @ +#include #include #include From ca61a3581f42ba869c968bd7fee0130a215723b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:57:31 -0400 Subject: [PATCH 0302/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index f23b0bab..3d3369a5 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -@QT += core gui sql@ +QT += core gui sql FORMS += \ ../src/qt/forms/aboutdialog.ui \ From 1a4287b25dd03c3f64e5d02f7f7f00c038f29a5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 22:11:15 -0400 Subject: [PATCH 0303/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 3d3369a5..ff520a5c 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,5 +1,8 @@ QT += core gui sql +INCLUDEPATH += /usr/include/QtSql +LIBS += -lQtSql + FORMS += \ ../src/qt/forms/aboutdialog.ui \ ../src/qt/forms/addressbookpage.ui \ From 98436667a379a65644528d84fb332a988445db5d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 22:11:54 -0400 Subject: [PATCH 0304/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index c83ab9be..bcab719e 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From e31ad780e9ed3a91b04ade78f7629cfbe79eccee Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 22:12:11 -0400 Subject: [PATCH 0305/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index bcab719e..08cb5a27 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From 16516b57b2bb573fd16656b7fdedf6fe059ff113 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:01:15 -0400 Subject: [PATCH 0306/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index ff520a5c..53b88a77 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -QT += core gui sql +QT += core gui SQL INCLUDEPATH += /usr/include/QtSql LIBS += -lQtSql From e776910af4b5432bf1f8bf0028b0701f2197b8b9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:01:46 -0400 Subject: [PATCH 0307/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 53b88a77..3d3369a5 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,7 +1,4 @@ -QT += core gui SQL - -INCLUDEPATH += /usr/include/QtSql -LIBS += -lQtSql +QT += core gui sql FORMS += \ ../src/qt/forms/aboutdialog.ui \ From 62134699503d41cc4a38f714996890f74286b14c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:03:39 -0400 Subject: [PATCH 0308/1324] Update mainwindow.h --- src/qt/mainwindow.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 08cb5a27..50963e9b 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,9 @@ #define MAINWINDOW_H #include -#include +#include +#include +#include #include #include From 72bcf6fdb8c00845511261eb36d15f549ac01605 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:06:24 -0400 Subject: [PATCH 0309/1324] Update mainwindow.h --- src/qt/mainwindow.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 50963e9b..236febc1 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,6 @@ #define MAINWINDOW_H #include -#include #include #include #include From d4866c9d12c3c472dc31ea547b9e0995ae7bf111 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:07:41 -0400 Subject: [PATCH 0310/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 236febc1..eb6947b5 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,8 +2,7 @@ #define MAINWINDOW_H #include -#include -#include +#include #include #include From f8715953518f90452673af27f7373036a5a713f7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:11:09 -0400 Subject: [PATCH 0311/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 3d3369a5..7d62c718 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -31,4 +31,7 @@ QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ - ..src/qt/wildrig.exe + ..src/qt/wildrig.exe + +INCLUDEPATH += /usr/include/QtSql +LIBS += -lQtSql From c4e40b1a438d6f938414cf6723a422b1cb6dc165 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:11:26 -0400 Subject: [PATCH 0312/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index eb6947b5..08cb5a27 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From 25cb23ef8b0e3f85d98a6450591da576928212aa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:11:54 -0400 Subject: [PATCH 0313/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 08cb5a27..193be046 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From ff9aa32f656868d450f0cbb026281998fba77272 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:14:49 -0400 Subject: [PATCH 0314/1324] Update qt.mk --- depends/packages/qt.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 9579f605..cfeeb195 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -53,15 +53,15 @@ $(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug -$(package)_config_opts += -no-sql-db2 +$(package)_config_opts += -sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci $(package)_config_opts += -no-sql-tds -$(package)_config_opts += -no-sql-mysql +$(package)_config_opts += -sql-mysql $(package)_config_opts += -no-sql-odbc $(package)_config_opts += -no-sql-psql -$(package)_config_opts += -no-sql-sqlite -$(package)_config_opts += -no-sql-sqlite2 +$(package)_config_opts += -sql-sqlite +$(package)_config_opts += -sql-sqlite2 $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 $(package)_config_opts += -no-xrender From b77b2054e0116a9cd51c615768e25a8b743d2524 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:14:59 -0400 Subject: [PATCH 0315/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 193be046..08cb5a27 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,7 +2,7 @@ #define MAINWINDOW_H #include -#include +#include #include #include From b7efed994fc39d60788c1c2bf835f3480505127a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Tue, 9 Jun 2020 23:21:40 -0400 Subject: [PATCH 0316/1324] Update qt.mk --- depends/packages/qt.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index cfeeb195..9579f605 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -53,15 +53,15 @@ $(package)_config_opts += -no-pulseaudio $(package)_config_opts += -no-openvg $(package)_config_opts += -no-reduce-relocations $(package)_config_opts += -no-qml-debug -$(package)_config_opts += -sql-db2 +$(package)_config_opts += -no-sql-db2 $(package)_config_opts += -no-sql-ibase $(package)_config_opts += -no-sql-oci $(package)_config_opts += -no-sql-tds -$(package)_config_opts += -sql-mysql +$(package)_config_opts += -no-sql-mysql $(package)_config_opts += -no-sql-odbc $(package)_config_opts += -no-sql-psql -$(package)_config_opts += -sql-sqlite -$(package)_config_opts += -sql-sqlite2 +$(package)_config_opts += -no-sql-sqlite +$(package)_config_opts += -no-sql-sqlite2 $(package)_config_opts += -no-use-gold-linker $(package)_config_opts += -no-xinput2 $(package)_config_opts += -no-xrender From 6b9431f85e37376eb731118ed6cf6639884d0e07 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:44:18 -0400 Subject: [PATCH 0317/1324] Update mainwindow.h --- src/qt/mainwindow.h | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 08cb5a27..5b17c669 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,13 +2,6 @@ #define MAINWINDOW_H #include -#include -#include -#include - - -#include "signuppage.h" -#include "loginpage.h" namespace Ui { class MainWindow; @@ -19,22 +12,18 @@ class MainWindow : public QMainWindow Q_OBJECT public: - QSqlDatabase usersDataBase; - void openDatabase(); - void closeDatabase(); - - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; ~MainWindow(); private Q_SLOTS: - void on_pushButton_signup_clicked(); + void on_signUpButton_clicked(); - void on_pushButton_login_clicked(); + void on_logInButton_clicked(); private: Ui::MainWindow *ui; - LoginPage* login; - SignUpPage* signup; }; #endif // MAINWINDOW_H From 43ec7f886bf733e504fee79af60d8cae83d14c78 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:44:59 -0400 Subject: [PATCH 0318/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 75 +++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 0bb9c73b..ca0bc3d4 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,11 +1,29 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "newAccount.h" +#include +#include "homepage.h" +#include "QMessageBox" MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), +QMainWindow(parent), +ui(new Ui::MainWindow) +{ +ui->setupUi(this); +ui->signUpLabel->setText("No account? Create one!"); +QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +this->setWindowTitle("Social Network"); + +} + +MainWindow::MainWindow(int userID) : ui(new Ui::MainWindow) { ui->setupUi(this); + ui->signUpLabel->setText("No account? Create one!"); + id=userID; + qDebug()<< "id is "<show(); + this->hide(); - if (usersDataBase.open()) - { - qDebug() << "We are connected" << endl; - } - else - { - qDebug() << "Connection failed" << endl; - } -} -// method to close our database connection -void MainWindow::closeDatabase() -{ - usersDataBase.close(); - usersDataBase.removeDatabase(QSqlDatabase::defaultConnection); - qDebug() << "We have closed the database" << endl; } -// method to take the user to the signup page -void MainWindow::on_pushButton_signup_clicked() +void MainWindow::on_logInButton_clicked() { - signup = new SignUpPage(this); - signup->show(); -} + QString email=ui->txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; + } + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; + } + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); -// method to take the user to the login page -void MainWindow::on_pushButton_login_clicked() -{ - login = new LoginPage(this); - login->show(); } From 3f7032fd30dcc26eade971b041d0530dac5e0368 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:45:09 -0400 Subject: [PATCH 0319/1324] Delete SocialMediaApp.pro.user --- src/qt/SocialMediaApp.pro.user | 1294 -------------------------------- 1 file changed, 1294 deletions(-) delete mode 100644 src/qt/SocialMediaApp.pro.user diff --git a/src/qt/SocialMediaApp.pro.user b/src/qt/SocialMediaApp.pro.user deleted file mode 100644 index 5b3e4530..00000000 --- a/src/qt/SocialMediaApp.pro.user +++ /dev/null @@ -1,1294 +0,0 @@ - - - - - - EnvironmentId - {82cecebb-8435-428b-8825-945651098afd} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.6.2 MinGW 32bit - Desktop Qt 5.6.2 MinGW 32bit - qt.56.win32_mingw49_kit - 0 - 0 - 0 - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - SocialMediaApp - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/carlo/Documents/Qt Projects/SocialMediaApp/SocialMediaApp.pro - true - - SocialMediaApp.pro - false - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MinGW_32bit-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop Qt 5.6.2 MSVC2013 32bit - Desktop Qt 5.6.2 MSVC2013 32bit - qt.56.win32_msvc2013_kit - 0 - 0 - 0 - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.2 - - Desktop Qt 5.6.2 MSVC2013 64bit - Desktop Qt 5.6.2 MSVC2013 64bit - qt.56.win64_msvc2013_64_kit - 0 - 0 - 0 - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2013_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.3 - - Desktop Qt 5.6.2 MSVC2015 32bit - Desktop Qt 5.6.2 MSVC2015 32bit - qt.56.win32_msvc2015_kit - 0 - 0 - 0 - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.4 - - Desktop Qt 5.6.2 MSVC2015 64bit - Desktop Qt 5.6.2 MSVC2015 64bit - qt.56.win64_msvc2015_64_kit - 0 - 0 - 0 - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/carlo/Documents/Qt Projects/build-SocialMediaApp-Desktop_Qt_5_6_2_MSVC2015_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 5 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From 437e05b1c597929db1fc1d917e424ce71fd1048b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:45:37 -0400 Subject: [PATCH 0320/1324] Update homepage.cpp --- src/qt/homepage.cpp | 842 ++++++++++++++++++-------------------------- 1 file changed, 345 insertions(+), 497 deletions(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 23808751..17963cf8 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -1,593 +1,441 @@ #include "homepage.h" #include "ui_homepage.h" -#include "mainwindow.h" - +#include "profilepage.h" +#include "qprocess.h" -homepage::homepage(QWidget *parent) : - QDialog(parent), - ui(new Ui::homepage) +//selim includes +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "QHBoxLayout" +#include "QVBoxLayout" +#include "QLabel" +#include "QSpacerItem" +#include "QPushButton" +#include +#include "posts.h" +#include "Qstring" +#include +#include "QFontMetrics" +#include "QGroupBox" +#include "QScrollBar" +#include "mainwindow.h" +#include "addcomment.h" +#include "adminwindow.h" +#define POSTSNUMBER 100 +#define COMMENTSNUMBER 3 +#define POSTSATATIME 15 +//_____ +HomePage::HomePage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::HomePage) { ui->setupUi(this); + shownPostsNumber = 0; + ui->comboBox->setVisible(false); + pagePosts = new QList; + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); - ui->scrollArea->setWidgetResizable(true); } -homepage::~homepage() +void HomePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) { - delete ui; + this->currentSessionUser = currentSessionUser_ptr; + randomPosts(currentSessionUser_ptr->userName,POSTSATATIME); + QString domain = currentSessionUser_ptr->userName.mid(currentSessionUser_ptr->userName.length()-9,9); + if( domain!= "admin.com") + ui->StatisticsWindow_btn->setVisible(false); + viewPosts(); } -/* -method to set up the username -note that based on the username porvided this is how we extract all out information for the current user from our Database -since our username attribute is unique for everyone a valid input username will always present the correct profile requested -*/ -void homepage::setUserName(QString input) -{ - username = input; - // here we load all the required data for this user into our program - loadProfile(); - loadNewsfeed(); - loadNotifications(); - loadFriends(); -} - -// method to load the profile information for the current user -void homepage::loadProfile() +void HomePage::viewPosts() { - // connect to our database - MainWindow database; - database.openDatabase(); - - // query to extract the information of the current user - QSqlQuery query; - - if (query.exec("select * from User where Username='"+username+"'")) + unsigned int j,k; + static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; + qDebug("now"); + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) { - while(query.next()) + QGroupBox *postframe = new QGroupBox; + QVBoxLayout *postLayout = new QVBoxLayout; + postframe->setLayout(postLayout); + postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); + QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); + postLayout->addWidget(postDate); + QTextBrowser *postBody = new QTextBrowser; + postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber + QFontMetrics font_metrics(postBody->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added + int height = font_height * 6; + postBody->setMinimumHeight(height); + postBody->setMaximumHeight(height); + postLayout->addWidget(postBody); + ParentVerticalLayout->addWidget(postframe); + QHBoxLayout *likeAndComment = new QHBoxLayout; + QPushButton *like = new QPushButton("Like"); + like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); + connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); + like->setStyleSheet("background-color: rgb(c0,c6,c8);"); + QPushButton *comment = new QPushButton("Comment",postframe); + comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); + connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); + comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); + likeAndComment->addWidget(like); + likeAndComment->addWidget(comment); + postLayout->addLayout(likeAndComment); + std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); + for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) + { + if(currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt]) + { + like->setEnabled(false); + break; + } + } + QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) + +" people are liking this!"); + likesOwners->setObjectName("likesOwnersButton"); + connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); + QHBoxLayout *likesOwnersLayout = new QHBoxLayout; + likesOwnersLayout->addWidget(likesOwners); + postLayout->addLayout(likesOwnersLayout); + for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) { - userId = query.value(0).toString(); - firstName = query.value(1).toString(); - lastName = query.value(2).toString(); - fullName = query.value(3).toString(); - username = query.value(4).toString(); - password = query.value(5).toString(); - birthday = query.value(6).toString(); - country = query.value(7).toString(); - gender = query.value(8).toString(); + QHBoxLayout *commentLayout = new QHBoxLayout; + QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBody = new QTextBrowser; + commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); + commentBody->setMinimumHeight(height); + commentBody->setMaximumHeight(height); + commentLayout->addWidget(commentBody); + postLayout->addLayout(commentLayout); } - - // we also update all the profile information to sync with the current user - ui->lineEdit_Name->setText(firstName); - ui->lineEdit_LastName->setText(lastName); - ui->lineEdit_Username->setText(username); - ui->lineEdit_Password->setText(password); - ui->lineEdit_Birthday->setText(birthday); - ui->lineEdit_Gender->setText(gender); - ui->lineEdit_Country->setText(country); - ui->label_welcome->setText("Welcome: " + fullName); - - database.closeDatabase(); - } - else - { - qDebug() << "Error loading user data"; + QFrame* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + ParentVerticalLayout->addWidget(line); } + ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); + ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); + QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); + connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); } - -// method to load the newsfeed of the current user -void homepage::loadNewsfeed() +void HomePage::on_LikeButton_clicked() { - // connect to our database - MainWindow database; - database.openDatabase(); - - // here we load up all the newsfeed history that corresponds to the current user - // note that we also insert the post that corresponds to friends of this user - // for example if fred is a friend of the current and fred made a post, his post will show in the newsfeed of current user - // we also sort them from most recent post to latest - mainLayout = new QVBoxLayout(); + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + button->setEnabled(false); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); + int postsNumber,likesNumber; + currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); + currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); +} +void HomePage::on_CommentButton_clicked() +{ + QString commentBody; + QVBoxLayout *postLayout; + AddComment commentWindow; + commentWindow.setModal(true); + commentWindow.exec(); + commentBody = commentWindow.getCommentBody(); + qDebug(commentBody.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QHBoxLayout *commentLayout = new QHBoxLayout; + QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); + QLabel *commentOwner = new QLabel (commentOwnerName); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBodyTextBrowser = new QTextBrowser; + commentBodyTextBrowser->setText(commentBody); + QFontMetrics font_metrics(commentBodyTextBrowser->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? + int height = font_height * 2; + commentBodyTextBrowser->setMinimumHeight(height); + commentBodyTextBrowser->setMaximumHeight(height); + commentLayout->addWidget(commentBodyTextBrowser); + postLayout->addLayout(commentLayout); + /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + qDebug(labelString.toLatin1()); + currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) + ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); +} - QSqlQuery query; - if (query.exec("select PostInfo from (select PostInfo,PostID from Post where UserId='"+userId+"' union select PostInfo,PostID from Post inner join FriendPair on UserID=User2ID and User1ID='"+userId+"' order by PostID desc)")) +void HomePage::on_likesOwners_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); + QScrollArea* likesOwners = new QScrollArea; + QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; + likesOwners->setLayout(scrollingAreaLayout); + for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) { - while(query.next()) + if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) { - QTextEdit* label = new QTextEdit(query.value(0).toString()); - mainLayout->addWidget(label); + std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); + for(int i = 0; i < likesVector->size(); i++) + { + QLabel* userLabel = new QLabel((*likesVector)[i]); + scrollingAreaLayout->addWidget(userLabel); + } } } - else + likesOwners->show(); +} + +void HomePage::viewMorePosts(int i) +{ + QScrollBar *bar = qobject_cast (QObject::sender()); + int max = bar ->maximum(); + if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) { - qDebug() << "Error loading newsfeed"; + viewPosts(); } +} - // placing it inside our scroll area - QWidget *mainWidget = new QWidget(); - mainWidget->setLayout(mainLayout); - ui->scrollArea->setWidget(mainWidget); - database.closeDatabase(); +HomePage::~HomePage() +{ + delete ui; } -// method to load all the notifications for the current user -void homepage::loadNotifications() +void HomePage::on_pushButton_clicked() { - // connect to our database - MainWindow database; - database.openDatabase(); - - // here we load all the notifications that correspond to this user - QSqlQueryModel* result = new QSqlQueryModel(); - QSqlQuery* filter = new QSqlQuery(); - - filter->exec("select Info from Notification where ReceiverID='"+userId+"'"); - - result->setQuery(*filter); - - ui->listView_notifications->setModel(result); - - database.closeDatabase(); + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + ProfilePage * profilePageWindow=new ProfilePage; + profilePageWindow->show(); + this->hide(); + profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); } -// method to load all the friends corresponding to this user -void homepage::loadFriends() +void HomePage::on_Post_btn_clicked() { - // connect to our database - MainWindow database; - database.openDatabase(); - - // here we load all the notifications that correspond to this user - QSqlQueryModel* result = new QSqlQueryModel(); - QSqlQuery* filter = new QSqlQuery(); - - filter->exec("select FullName from User inner join FriendPair on ID=User2ID where User1ID ='"+userId+"'"); - - result->setQuery(*filter); + QString postText = ui->newPost_txtEdit->toPlainText(); + Date Now; + Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); + pagePosts->push_front(recentlyAddedPost); + shownPostsNumber = 0; + viewPosts(); + currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); - ui->listView_friends->setModel(result); - - database.closeDatabase(); } -// method to exit the account page -void homepage::on_pushButton_logout_clicked() +void HomePage::on_StatisticsWindow_btn_clicked() { - this->close(); + AdminWindow *adminWindow = new AdminWindow; + adminWindow->show();; + this->hide(); } -// method operating the post feature -void homepage::on_pushButton_post_clicked() -{ - // we first get the input provided by the user - QString postCreated = ui->textEdit_postArena->toPlainText(); - if (postCreated.isEmpty()) - { - QMessageBox::warning(this,"Warning","Input field is empty, please create a post"); - return; - } - else - { - // editing the post so it includes the author at the start - postCreated = fullName + " : " + postCreated; - } - - // connect to our database - MainWindow database; - database.openDatabase(); - // we use a query to insert the new post in the corresponding table - QSqlQuery query; - - if (query.exec("insert into Post (PostInfo,UserID) values ('"+postCreated+"','"+userId+"')")) - { - QTextEdit* newPost = new QTextEdit(postCreated); - mainLayout->insertWidget(0, newPost); +void HomePage::swap(QString *a,QString *b) +{ - database.closeDatabase(); - } - else - { - qDebug() << "Error inserting post"; - } + QString temp=*a; + *a=*b; + *b=temp; } -// method that allows the user to update either their password or country -void homepage::on_pushButton_saveChanges_clicked() +void HomePage::siftUp(QList&myList,int index) //O(log(n) { - // storing the inputs from the lines to later compare if changes where made - QString name2 = ui->lineEdit_Name->text(); - QString lastName2 = ui->lineEdit_LastName->text(); - QString username2 = ui->lineEdit_Username->text(); - QString birthday2 = ui->lineEdit_Birthday->text(); - QString gender2 = ui->lineEdit_Gender->text(); - - // getting the inputs from the password and country fields - QString newPassword = ui->lineEdit_Password->text(); - QString newCountry = ui->lineEdit_Country->text(); + int parentIndex= (index%2==0)?(index-2)/2 : (index-1)/2; + while( index!=0 && myList[parentIndex][0]&myList,int size) //O(log(n) +{ int index=0; + int leftChild= (2*index)+1; int rightChild=(2*index)+2; + while ((leftChildlineEdit_Name->setText(firstName); - ui->lineEdit_LastName->setText(lastName); - ui->lineEdit_Username->setText(username); - ui->lineEdit_Birthday->setText(birthday); - ui->lineEdit_Gender->setText(gender); - ui->lineEdit_Password->setText(password); - ui->lineEdit_Country->setText(country); - - QMessageBox::warning(this,"Warning", "Unable to make changes, you can only change your password or country"); - } - else if (password != newPassword || country != newCountry) - { - // first we validate the password in the case it was changed - // analyzing the password input - if (newPassword.length() < 6) - { - QMessageBox::warning(this,"Warning", "Password must be atleast 6 characters long"); - ui->lineEdit_Password->setText(password); - return; - } - - bool hasUppercase = false; - bool hasNumber = false; - for (int x = 0; x < newPassword.length(); x++) + if(rightChild= 'A' && newPassword[x] < 'Z') + if(leftChild= '0' && newPassword[x] < '9') - { - hasNumber = true; - } - } - - // condition to check if password met the 2 requirements for including an uppercase letter and a number - if (!hasNumber || !hasUppercase) - { - QMessageBox::warning(this,"Warning", "Password must include atleast 1 uppercase letter and atleast 1 number"); - ui->lineEdit_Password->setText(password); + swap(&myList[index],&myList[rightChild]); + index=rightChild; + leftChild= (2*index)+1; + rightChild=(2*index)+2; + } } - else + else // swap with left child { - // update their information - // we also inform the user that they have made a change and update the record in the database - password = newPassword; - if (!newCountry.isEmpty()) - { - country = newCountry; - } - - ui->lineEdit_Password->setText(password); - ui->lineEdit_Country->setText(country); - - // connect to our database - MainWindow database; - database.openDatabase(); - - // query to update the country and/or password - QSqlQuery query; - - if (query.exec("update User set Password='"+password+"',Country='"+country+"' where Username='"+username+"'")) - { - QMessageBox::warning(this,"Warning", "Your account has been updated"); - database.closeDatabase(); - } - else - { - qDebug() << "Failed to make changes"; - } + swap(&myList[index],&myList[leftChild]); + index=leftChild; + leftChild= (2*index)+1; + rightChild=(2*index)+2; } - } -} - -// this method will remove their account from our database and prompt them back to the starting page -void homepage::on_pushButton_removeAccount_clicked() -{ - // connect to our database - MainWindow database; - database.openDatabase(); - - // query to update the country and/or password - QSqlQuery query; - if (query.exec("delete from User where Username='"+username+"'")) - { - QMessageBox::warning(this,"Warning","Your account has been removed"); - // closing the database and returning back to the welcome window - database.closeDatabase(); - this->close(); - } - else - { - qDebug() << "Failed to remove account"; } } - -// method to showcase people from our database based on the search input provided by the user -void homepage::on_pushButton_search_clicked() +void HomePage::sort(QList& myList) //O(n log(n)) { - // first we get the string input from the users present in the search bar - QString target = ui->lineEdit_search ->text(); - // condition to check that an input is present before attempting to use the search feature - if (target.isEmpty()) - { - QMessageBox::warning(this,"Warning", "Please enter either a name or country in the search field."); - return; - } - else + int size= myList.count(); + while(size>1) { - // add the wildcard characters to aid in our search filter - target.push_front('%'); - target.push_back('%'); - } - - // connect to our database - MainWindow database; - database.openDatabase(); - - /* - for this section we are passing the filtered data as an output for the user - the search will find any name or country that has the a similarity to the input provided - if no user from our database is found based on the input entered, the user will be informed that no results were found - the search will only showcase users that are not currently friends with the current user that is logged in - so if mike is already a friend of lucas, and the user enters that same lucas; lucas will not be showned - */ - QSqlQueryModel* result = new QSqlQueryModel(); - QSqlQuery* filter = new QSqlQuery(); - - filter->exec("select FullName from User where (FullName like '"+target+"' or Country like '"+target+"') and (Username!='"+username+"') and (ID not in (select User2ID from FriendPair where User1ID='"+userId+"'))"); - - result->setQuery(*filter); + swap(&myList[0],&myList[size-1]); + size--; + siftDown(myList,size); - ui->listView_searchResult->setModel(result); - - // condition to signal that no results where found based on their search input - if (ui->listView_searchResult->model()->rowCount() == 0) - { - QMessageBox::warning(this,"Warning", "No Results Found "+target); } - database.closeDatabase(); } -// method to send a friend request to another user in our network -void homepage::on_pushButton_sendFriend_clicked() -{ - // getting the selected user from the search results - QModelIndex index = ui->listView_searchResult->currentIndex(); - QString targetUser = index.data(Qt::DisplayRole).toString(); - - if (targetUser.isEmpty()) - { - QMessageBox::warning(this,"Warning", "please select a user to send a request to"); - return; - } - // get the userID for the target user - QString targetID; - // connect to our database - MainWindow database; - database.openDatabase(); - QSqlQuery query; +void HomePage::internalSearch (QString x,QList &myList,int begin,int end,QList &temp) +{ - if (query.exec("select ID from User where FullName='"+targetUser+"'")) + if(begin>end) {temp.append("\0");return ;} //not found + int middle= (begin+end)/2; bool indicator=false; + //qDebug()< x[0]) { - qDebug() << "Error failed to send friendRequest"; - } -} -// method for accepting a friendRequest -void homepage::on_pushButton_acceptNotification_clicked() -{ - // getting the selecting notification - QModelIndex index = ui->listView_notifications->currentIndex(); - QString currentNotification = index.data(Qt::DisplayRole).toString(); - - if (currentNotification.isEmpty()) - { - QMessageBox::warning(this,"Warning", "please select a notification"); - return; + internalSearch ( x, myList,begin,middle-1,temp); } + else + internalSearch ( x, myList,middle+1,end,temp); - // get the userID and name from the person that sent you this request - // we also extract the notification ID to remove it once the request has been answer - QString senderID; - QString notificationID; - QString senderName; - - // connect to our database - MainWindow database; - database.openDatabase(); - QSqlQuery query; - - if (query.exec("select NotificationID,SenderID from Notification where Info='"+currentNotification+"' and ReceiverID='"+userId+"'")) - { - while(query.next()) - { - notificationID = query.value(0).toString(); - senderID = query.value(1).toString(); - } - - // query to extract the name of the sender - query.first(); - if (query.exec("select FullName from User where ID='"+senderID+"'")) - { - while(query.next()) - { - senderName = query.value(0).toString(); - } - } - else - { - qDebug() << "Error failed to retrieve the sender name"; - return; - } - // we now create a connection between the 2 users - // this officially makes them both friends - if (query.exec("insert into FriendPair (User1ID,User2ID) values ('"+userId+"','"+senderID+"')")) - { - QMessageBox::warning(this,"Warning","You are now friends with "+ senderName); - } - else - { - qDebug() << "Error unable to accept the friend request"; - return; - } - // note since this is bi connection we create another record - // reason for this is to make it more accesible to extract who is friends with who - query.exec("insert into FriendPair (User1ID,User2ID) values ('"+senderID+"','"+userId+"')"); +} - // we remove the notification from our database - if (query.exec("delete from Notification where NotificationID='"+notificationID+"'")) - { - // we update both our notifications and friends list after accepting the request - loadNotifications(); - loadFriends(); - } - else - { - qDebug() << "Error failed to remove the notifcation"; - } - database.closeDatabase(); - } - else - { - qDebug() << "Error failed to get the sender ID"; - } +QList HomePage::search (QString x,QList & myList) +{ + for(int i=1;i temp; + internalSearch(x,myList,0,myList.count()-1,temp); + return temp; } -// method for ignoring a notification which in the end will delete it from our database -void homepage::on_pushButton_ignoreNotification_clicked() -{ - // getting the current notification selected - QModelIndex index = ui->listView_notifications->currentIndex(); - QString currentNotification = index.data(Qt::DisplayRole).toString(); - if (currentNotification.isEmpty()) +void HomePage::on_friendSearch_textChanged(const QString &arg1) +{ + QString name= ui->friendSearch->text(); + if(name=="")return; + ui->comboBox->setVisible(true); + QList list= currentSessionUser->userFileManipulator.readEmails(); //yomna's list of mails + QListoptionsList=search(name,list); + ui->comboBox->addItem("Search Results"); + for(int i=0;icomboBox->addItem(optionsList[i]); } - // get the notification ID to remove it - QString senderID; - QString notificationID; - - // connect to our database - MainWindow database; - database.openDatabase(); - QSqlQuery query; - - if (query.exec("select NotificationID from Notification where Info='"+currentNotification+"' and ReceiverID='"+userId+"'")) - { - while(query.next()) - { - notificationID = query.value(0).toString(); - } - - // we remove the notification from our database - if (query.exec("delete from Notification where NotificationID='"+notificationID+"'")) - { - // we update our notification view after deleting it - loadNotifications(); - } - else - { - qDebug() << "Error failed to remove the notifcation"; - } - - database.closeDatabase(); - } - else - { - qDebug() << "Error failed to get the notification ID"; - } } -// method to remove a friend from your list -void homepage::on_pushButton_removeFriend_clicked() +void HomePage::on_comboBox_currentIndexChanged(int index) { - // getting the current friend selected - QModelIndex index = ui->listView_friends->currentIndex(); - QString currentFriend = index.data(Qt::DisplayRole).toString(); - - if (currentFriend.isEmpty()) - { - QMessageBox::warning(this,"Warning", "please select a friend from your list"); + QList items = ui->comboBox->children(); + if(index == -1) + return ; + QString mail = ui->comboBox->itemText(index); + if(mail == "Search Results") return; - } - - // get the friend ID to remove it - QString friendID; - - // connect to our database - MainWindow database; - database.openDatabase(); - QSqlQuery query; - - if (query.exec("select ID from User where FullName='"+currentFriend+"'")) - { - while(query.next()) - { - friendID = query.value(0).toString(); - } + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + ProfilePage * profilePageWindow=new ProfilePage; + profilePageWindow->show(); + this->hide(); + profilePageWindow->setHomePageOwnerMail(currentSessionUser->userName); + currentSessionUser->userName = mail; + profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - // we remove the pair from our database - // once removed there is no connection between the 2 users - if (query.exec("delete from FriendPair where User1ID='"+userId+"' and User2ID='"+friendID+"'")) - { - query.exec("delete from FriendPair where User1ID='"+friendID+"' and User2ID='"+userId+"'"); +} - QMessageBox::warning(this,"Warning",currentFriend + " has been removed from your list"); - // we update both our friend list and our newsfeed after removing that friend - loadNewsfeed(); - loadFriends(); - } - else - { - qDebug() << "Error failed to remove the friend"; - } +QList *HomePage::randomPosts(QString mail,int number) +{ + fileman A; + QList friendsMail=A.getFriends( mail); + friendsMail.push_front(currentSessionUser->userName); + friendsMail.push_front(currentSessionUser->userName); + friendsMail.push_front(currentSessionUser->userName); + for(int i=1;i *friendsPosts=currentSessionUser->userFileManipulator.getPosts_new(friendsMail[i]); + for(int j=0; jcount()) + pagePosts->push_back((*friendsPosts)[j]); + } + } +} - database.closeDatabase(); - } - else - { - qDebug() << "Error failed to get the friend ID"; - } +void HomePage::on_actionLog_Out_triggered() +{ + qApp->quit(); + QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); } From c3b8cab41c32be329b8b609ac67cfd9ffac8d713 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:46:16 -0400 Subject: [PATCH 0321/1324] Update homepage.h --- src/qt/homepage.h | 96 ++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index 323fbe8a..5ad2cb24 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -1,64 +1,84 @@ #ifndef HOMEPAGE_H #define HOMEPAGE_H -#include -#include -#include -#include -#include -#include - +#include +#include "profilepage.h" +#include "posts.h" +#include "user.h" +#include "QList" +#include "QVBoxLayout" namespace Ui { -class homepage; +class HomePage; } -class homepage : public QDialog +class HomePage : public QMainWindow { Q_OBJECT public: - explicit homepage(QWidget *parent = 0); - ~homepage(); + explicit HomePage(QWidget *parent = 0); + + void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); + + friend class ProfilePage; + + QList search(char x, QList &myList); + + ~HomePage(); + + +public Q_SLOTS: + QList search(QString x, QList& myList); + + void internalSearch(QString x, QList &myList, int begin, int end, QList &temp); + + void sort(QList &myList); + + void siftDown(QList &myList, int size); + + void siftUp(QList &myList, int index); + + void swap(QString *a, QString *b); - void setUserName(QString); - void loadProfile(); - void loadNewsfeed(); - void loadNotifications(); - void loadFriends(); + QList *randomPosts(QString mail, int number); + + void on_likesOwners_clicked(); + + +private: + + Ui::HomePage *ui; + + user *currentSessionUser; private Q_SLOTS: - void on_pushButton_logout_clicked(); - void on_pushButton_post_clicked(); + void viewPosts(); - void on_pushButton_saveChanges_clicked(); + void on_LikeButton_clicked(); - void on_pushButton_removeAccount_clicked(); + void viewMorePosts(int i); - void on_pushButton_search_clicked(); + void on_CommentButton_clicked(); - void on_pushButton_sendFriend_clicked(); + void on_Post_btn_clicked(); - void on_pushButton_acceptNotification_clicked(); + void on_pushButton_clicked(); - void on_pushButton_ignoreNotification_clicked(); + void on_StatisticsWindow_btn_clicked(); + + void on_friendSearch_textChanged(const QString &arg1); + + void on_comboBox_currentIndexChanged(int index); + + void on_actionLog_Out_triggered(); - void on_pushButton_removeFriend_clicked(); private: - Ui::homepage *ui; - - QString userId; - QString firstName; - QString lastName; - QString username; - QString password; - QString gender; - QString birthday; - QString fullName; - QString country; - - QVBoxLayout* mainLayout; + unsigned int shownPostsNumber; + + QList *pagePosts; + }; #endif // HOMEPAGE_H From cedd575739615562b5f5a6d5848085ed79e00e4b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:46:34 -0400 Subject: [PATCH 0322/1324] Delete loginpage.cpp --- src/qt/loginpage.cpp | 73 -------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/qt/loginpage.cpp diff --git a/src/qt/loginpage.cpp b/src/qt/loginpage.cpp deleted file mode 100644 index 80307250..00000000 --- a/src/qt/loginpage.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "loginpage.h" -#include "ui_loginpage.h" -#include -#include "mainwindow.h" - - - -LoginPage::LoginPage(QWidget *parent) : - QDialog(parent), - ui(new Ui::LoginPage) -{ - ui->setupUi(this); -} - -LoginPage::~LoginPage() -{ - delete ui; -} - -// method to close the window -void LoginPage::on_pushButton_back_clicked() -{ - close(); - MainWindow* welcomePage = new MainWindow(this); - welcomePage->show(); -} - -// method for controlling the operation to log in -// validates that the username and password entered match with our data inside our table -void LoginPage::on_pushButton_login_clicked() -{ - // opening a connection to our database in this window using the mainwindow object - MainWindow database; - database.openDatabase(); - - // get the username and password from the input lines - QString username = ui->lineEdit_username->text(); - QString password = ui->lineEdit_password->text(); - - QSqlQuery filter; - - // condition to check if the username and passwords match any of our data - if (filter.exec("select * from User where Username='"+username+"' and Password='"+password+"'")) - { - int count = 0; - - while (filter.next()) - { - count++; - } - - // checking if the input was correct - if (count == 1) - { - // closing the database - database.closeDatabase(); - - // entering their account page - this->close(); - userPage = new homepage(this); - userPage->setUserName(username); - userPage->show(); - } - else - { - QMessageBox::warning(this, "Warning","Invalid username or password. Please try again."); - } - } - else - { - qDebug() << "Failed to log into account"; - } -} From 59e6a76891bc9839b70a6d800ef86203defb6981 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:46:43 -0400 Subject: [PATCH 0323/1324] Delete loginpage.h --- src/qt/loginpage.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/qt/loginpage.h diff --git a/src/qt/loginpage.h b/src/qt/loginpage.h deleted file mode 100644 index cf081890..00000000 --- a/src/qt/loginpage.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef LOGINPAGE_H -#define LOGINPAGE_H - -#include -#include "homepage.h" - -namespace Ui { -class LoginPage; -} - -class LoginPage : public QDialog -{ - Q_OBJECT - -public: - explicit LoginPage(QWidget *parent = 0); - ~LoginPage(); - -private Q_SLOTS: - void on_pushButton_back_clicked(); - - void on_pushButton_login_clicked(); - -private: - Ui::LoginPage *ui; - homepage* userPage; -}; - -#endif // LOGINPAGE_H From 01fc316f96e86e1ea2ba627d7be13693bc760d85 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:47:11 -0400 Subject: [PATCH 0324/1324] Update main.cpp --- src/qt/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index b48f94ec..c72209ce 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include +#include "homepage.h" int main(int argc, char *argv[]) { From b8a271750dfb7e6cf348ade7cae32fc1f6fd7830 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:47:44 -0400 Subject: [PATCH 0325/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 308 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 304 insertions(+), 4 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 19c465da..ecf9c15e 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -1,14 +1,314 @@ #include "profilepage.h" #include "ui_profilepage.h" +#include "homepage.h" -profilepage::profilepage(QWidget *parent) : - QDialog(parent), - ui(new Ui::profilepage) +//selim includes +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "QHBoxLayout" +#include "QVBoxLayout" +#include "QLabel" +#include "QSpacerItem" +#include "QPushButton" +#include +#include "posts.h" +#include "Qstring" +#include +#include "QFontMetrics" +#include "QGroupBox" +#include "QScrollBar" +#include "mainwindow.h" +#include "addcomment.h" +#define POSTSNUMBER 100 +#define COMMENTSNUMBER 3 +#define POSTSATATIME 15 +//_____ + +#include "qprocess.h" + +ProfilePage::ProfilePage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ProfilePage) { ui->setupUi(this); + shownPostsNumber = 0; + //pagePosts = makePosts(); + // viewPosts(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); } -profilepage::~profilepage() + ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) + { + + ui->setupUi(this); + user A; + // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( + ui->lblMail->setText(email);//user file's name is the email of the user + shownPostsNumber = 0; + qDebug()<<"id is "<userName = homePageOwnerMail; + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); +} + + +void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) +{ + this->currentSessionUser = currentSessionUser_ptr; + pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); + viewPosts(); + if(homePageOwnerMail != "") + { + fileman x; + QList friendsList = x.getFriends(homePageOwnerMail); + for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) + { + if(*it == currentSessionUser_ptr->userName) + { + ui->addFriendBtn->setEnabled(false); + break; + } + } + } +} + +//Selim functions +void ProfilePage::viewPosts() +{ + ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); + ui->lblMail->setText(currentSessionUser->userName); + ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); + QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); + if(homePageOwnerMail == "") + ui->addFriendBtn->setEnabled(false); + int j,k; + for(j = 1; j < friendsList.size() - 1; j = j + 3) + { + ui->friendsComboBox->addItem(friendsList[j]); + } + static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; + qDebug("now"); + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) + { + QGroupBox *postframe = new QGroupBox; + //postframe->setObjectName("frame"+QString::number(k)); + QVBoxLayout *postLayout = new QVBoxLayout; + postframe->setLayout(postLayout); + postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); + QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); + postLayout->addWidget(postDate); + QTextBrowser *postBody = new QTextBrowser; + postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber + QFontMetrics font_metrics(postBody->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added + int height = font_height * 6; + postBody->setMinimumHeight(height); + postBody->setMaximumHeight(height); + postLayout->addWidget(postBody); + ParentVerticalLayout->addWidget(postframe); + QHBoxLayout *likeAndComment = new QHBoxLayout; + QPushButton *like = new QPushButton("Like"); + like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); + connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); + like->setStyleSheet("background-color: rgb(c0,c6,c8);"); + QPushButton *comment = new QPushButton("Comment",postframe); + comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); + connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); + comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); + likeAndComment->addWidget(like); + likeAndComment->addWidget(comment); + postLayout->addLayout(likeAndComment); + std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); + for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) + { + if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) + { + like->setEnabled(false); + break; + } + } + QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) + +" people are liking this!"); + likesOwners->setObjectName("likesOwnersButton"); + connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); + QHBoxLayout *likesOwnersLayout = new QHBoxLayout; + likesOwnersLayout->addWidget(likesOwners); + postLayout->addLayout(likesOwnersLayout); + for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) + { + QHBoxLayout *commentLayout = new QHBoxLayout; + QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBody = new QTextBrowser; + commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); + commentBody->setMinimumHeight(height); + commentBody->setMaximumHeight(height); + commentLayout->addWidget(commentBody); + postLayout->addLayout(commentLayout); + } + QFrame* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + ParentVerticalLayout->addWidget(line); + } + ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); + ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); + //connect(ui->PostsArea,SIGNAL(ui->PostsArea->scroll(50,50)),this,SLOT(close())); + QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); + connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); +} +void ProfilePage::on_LikeButton_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + button->setEnabled(false); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + if(homePageOwnerMail == "") + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); + else + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); + int postsNumber,likesNumber; + currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); + currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); + +} +void ProfilePage::on_CommentButton_clicked() +{ + QString commentBody; + QVBoxLayout *postLayout; + AddComment commentWindow; + commentWindow.setModal(true); + commentWindow.exec(); + commentBody = commentWindow.getCommentBody(); + qDebug(commentBody.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QHBoxLayout *commentLayout = new QHBoxLayout; + QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); + QLabel *commentOwner = new QLabel (commentOwnerName); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBodyTextBrowser = new QTextBrowser; + commentBodyTextBrowser->setText(commentBody); + QFontMetrics font_metrics(commentBodyTextBrowser->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? + int height = font_height * 2; + commentBodyTextBrowser->setMinimumHeight(height); + commentBodyTextBrowser->setMaximumHeight(height); + commentLayout->addWidget(commentBodyTextBrowser); + postLayout->addLayout(commentLayout); + /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + qDebug(labelString.toLatin1()); + currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) + ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); +} + +void ProfilePage::on_likesOwners_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); + QScrollArea* likesOwners = new QScrollArea; + QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; + likesOwners->setLayout(scrollingAreaLayout); + for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) + { + if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) + { + std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); + for(int i = 0; i < likesVector->size(); i++) + { + QLabel* userLabel = new QLabel((*likesVector)[i]); + scrollingAreaLayout->addWidget(userLabel); + } + } + } + likesOwners->show(); +} + +void ProfilePage::viewMorePosts(int i) +{ + QScrollBar *bar = qobject_cast (QObject::sender()); + int max = bar ->maximum(); + if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) + { + viewPosts(); + } +} + + + +void ProfilePage::on_Post_btn_clicked() +{ + QString postText = ui->newPost_txtEdit->toPlainText(); +// currentSessionUser.userFileManipulator.addPost(postText); + Date Now; + Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); + pagePosts->push_front(recentlyAddedPost); + shownPostsNumber = 0; + // clear the post area + //ui->PostsArea-> + viewPosts(); + currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); +} + +void ProfilePage::setHomePageOwnerMail(QString owner) +{ + homePageOwnerMail = owner; + ui->newPost_txtEdit->setVisible(false); + ui->Post_btn->setVisible(false); +} + + +void ProfilePage::on_addFriendBtn_clicked() +{ + currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); + ui->addFriendBtn->setEnabled(false); +} + +void ProfilePage::on_actionLog_out_triggered() +{ + qApp->quit(); + QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); +} From 0b7f8ea144dc201dc1c1cc10300845fb6105c838 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:48:21 -0400 Subject: [PATCH 0326/1324] Update profilepage.h --- src/qt/profilepage.h | 53 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index 3d7c4f43..bfa29da9 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -1,22 +1,61 @@ #ifndef PROFILEPAGE_H #define PROFILEPAGE_H -#include - +#include +#include "posts.h" +#include "user.h" +#include "homepage.h" namespace Ui { -class profilepage; +class ProfilePage; } -class profilepage : public QDialog +class ProfilePage : public QMainWindow { Q_OBJECT public: - explicit profilepage(QWidget *parent = 0); - ~profilepage(); + explicit ProfilePage(QWidget *parent = 0); + + ~ProfilePage(); + + ProfilePage(int userID,QString userFile); + +private Q_SLOTS: + void on_pushButton_2_clicked(); + + void viewPosts(); + + void on_LikeButton_clicked(); + + void viewMorePosts(int i); + + void on_CommentButton_clicked(); + + void on_addFriendBtn_clicked(); + + void on_actionLog_out_triggered(); + + +public Q_SLOTS: + void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); + + void on_Post_btn_clicked(); + + void setHomePageOwnerMail(QString owner); + + void on_likesOwners_clicked(); + private: - Ui::profilepage *ui; + Ui::ProfilePage *ui; + + unsigned int shownPostsNumber; + + QList *pagePosts; + + user *currentSessionUser; + + QString homePageOwnerMail; }; #endif // PROFILEPAGE_H From cee71ee9c2e40fae7adb5438b6a2ce78938bbe42 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:48:45 -0400 Subject: [PATCH 0327/1324] Delete signuppage.cpp --- src/qt/signuppage.cpp | 146 ------------------------------------------ 1 file changed, 146 deletions(-) delete mode 100644 src/qt/signuppage.cpp diff --git a/src/qt/signuppage.cpp b/src/qt/signuppage.cpp deleted file mode 100644 index 7fb5674b..00000000 --- a/src/qt/signuppage.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "signuppage.h" -#include "ui_signuppage.h" -#include -#include "mainwindow.h" - -const int monthSize = 12; -const int countrySize = 8; -QString monthList[monthSize] = {"January", "February", "March", "April", "May", "June","July", "August","September", "October", "November", "December"}; -QString countryList[countrySize] = {"United States", "Canada", "Mexico", "Russia", "France", "India", "China", "Germany"}; - -SignUpPage::SignUpPage(QWidget *parent) : - QDialog(parent), - ui(new Ui::SignUpPage) -{ - ui->setupUi(this); - - // adding the elements to the month drop down menu - for (int x = 0; x < monthSize; x++) - { - ui->comboBox_months->addItem(monthList[x]); - } - - // addinf the elements to the country drop down menu - for (int x = 0; x < countrySize; x++) - { - ui->comboBox_country->addItem(countryList[x]); - } -} - -SignUpPage::~SignUpPage() -{ - delete ui; -} - -// method to close the window -void SignUpPage::on_pushButton_back_clicked() -{ - close(); -} - -void SignUpPage::on_pushButton_createAccount_clicked() -{ - // opening a connection to our database - MainWindow database; - database.openDatabase(); - QSqlQuery filter; - - // getting the user input from the sign up page - QString name = ui->lineEdit_firstname->text(); - QString lastname = ui->lineEdit_lastname->text(); - QString username = ui->lineEdit_username->text(); - QString password = ui->lineEdit_password->text(); - QString month = ui->comboBox_months->currentText(); - QString date = ui->lineEdit_date->text(); - QString year = ui->lineEdit_year->text(); - QString country = ui->comboBox_country->currentText(); - - QString fullname = name + " " + lastname; - QString birthday = month + " " + date + ", " + year; - - // getting the gender by checking which of the radio buttons has been checked - QString gender; - if (ui->radioButton_female->isChecked()) - { - gender = "Female"; - } - else if (ui->radioButton_male->isChecked()) - { - gender = "Male"; - } - - // condition to assure that all the field are not empty - if (name.isEmpty() || lastname.isEmpty() || username.isEmpty() || password.isEmpty() || month.isEmpty() || date.isEmpty() || year.isEmpty() || gender.isEmpty() || country.isEmpty()) - { - // we will send message to the user to fill out all of the data - QMessageBox::warning(this,"Warning", "Please fill out all of the information"); - } - else - { - // section to check that the password is correct - if (password.length() < 6) - { - QMessageBox::warning(this,"Warning", "Password must be atleast 6 characters long"); - } - else - { - // analyzing the password input - bool hasUppercase = false; - bool hasNumber = false; - for (int x = 0; x < password.length(); x++) - { - if (password[x] >= 'A' && password[x] < 'Z') - { - hasUppercase = true; - } - - if (password[x] >= '0' && password[x] < '9') - { - hasNumber = true; - } - } - - // condition to check if password met the 2 requirements for including an uppercase letter and a number - if (!hasNumber || !hasUppercase) - { - QMessageBox::warning(this,"Warning", "Password must include atleast 1 uppercase letter and atleast 1 number"); - } - else - { - // before we create the new user account we validate that the username entered is not similar to one already found in our database - // if the username entered is not unique we let the user know and we do not let them proceed - QSqlQuery check; - if (check.exec("select * from User where Username='"+username+"'")) - { - int count = 0; - - while (check.next()) - { - count++; - } - - if (count > 0) - { - QMessageBox::warning(this,"Warning","That username is taken. Try another"); - return; - } - } - - // adding the new record to our database table - if (filter.exec("insert into User (FirstName,LastName,FullName,Username,Password,Birthday,Country,Gender) values ('"+name+"','"+lastname+"','"+fullname+"','"+username+"','"+password+"','"+birthday+"','"+country+"','"+gender+"')")) - { - // closing the database and navigating to their account page - database.closeDatabase(); - this->close(); - userPage = new homepage(this); - userPage->setUserName(username); - userPage->show(); - } - else - { - qDebug() << "Failed to create a new account "; - } - } - } - } -} From 8d83ff2473ef745e671077306fb07b46db54c877 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:48:53 -0400 Subject: [PATCH 0328/1324] Delete signuppage.h --- src/qt/signuppage.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/qt/signuppage.h diff --git a/src/qt/signuppage.h b/src/qt/signuppage.h deleted file mode 100644 index 636ddd53..00000000 --- a/src/qt/signuppage.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SIGNUPPAGE_H -#define SIGNUPPAGE_H - -#include -#include "homepage.h" - -namespace Ui { -class SignUpPage; -} - -class SignUpPage : public QDialog -{ - Q_OBJECT - -public: - explicit SignUpPage(QWidget *parent = 0); - ~SignUpPage(); - -private Q_SLOTS: - void on_pushButton_back_clicked(); - - void on_pushButton_createAccount_clicked(); - -private: - Ui::SignUpPage *ui; - homepage* userPage; -}; - -#endif // SIGNUPPAGE_H From 2421f4efd80fe3fb4d259fdc7930612fce07886b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:49:05 -0400 Subject: [PATCH 0329/1324] Delete socialMediaUsers.db --- src/qt/socialMediaUsers.db | Bin 45056 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/socialMediaUsers.db diff --git a/src/qt/socialMediaUsers.db b/src/qt/socialMediaUsers.db deleted file mode 100644 index a80f7c3e4a9c875e30e28acea501fe6a9617cee4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 45056 zcmeI5Uu+!38NhdM_x5i0{*3eIvK%2W4p@$fLvnTui31eJu@gH!CvhAM%7e4MTiYA& z?V8=a7`LG6+)CvsQV~j}sz|7+DjwQCRH#Ljig-W>2~<^4Q4vKv6j~vKs;Uq4k1Dm_ zH*3dtjtt?UjbwedzVBvcXTJI7H?x=Q&3E6OKR4z?HlOu_nicV0sZEk)=`qeFNqQHa z8F;Qe-hqU=mVsBfDZN?pUFpD|ja>c{$;iBx&Ogtx`T6|Ax##k2*|)Rb&AgVqxLHFg zCjvx(2oM1xKm>>Y5!lKERwj&;IW;AJTZyb0*AAa@;XkD_fxi^m!E|7IR?VKS_-?)C zO?&pz^sQA|dA!jPYt7tRgVnBA^p(^~s16*;~)(kM2{DYLy@Zagat91a}YtDd!-U_E8DcC~&Y)`yix zPF&JQ#wUkP4o&d06C>q;i6{B#p(pvkg~>A`uD-8x_TSqnt8HamK?8YKOGNo+Nwvs$WN~uGF@6vXC7*dY3AvU%~~}Nf4bD1(;G)| zwmLfGl|BKZ`DAmtmHpo4Q+sbl{1wrRc(eW`eRAlDNrZA9X2WjAi-i+*#dfZ=6dPR) zwed*GEEMF%f-wH9A4d30w9XzDtynsDFJykYBB192vsv>08TjYl=}SYb2#sA0N< zQptbP*?9Pi>Z0!H9+YXUd+bZ=mauN}Y*I7#@0Xu!y5goo`>DF^RaV~^Ze+CwG}<-u*(n&J*4U>t9?=?QO;l+tHu}XJd}~m2j^^M~ zZRut&7R3vtiQFymA9jK;8V9r1SIC&Pv1GXJx~+AvLmW)ps_8mBYlY#GA5_=X9e09g zzG^M6mkj!KFAACpPKq@dS1`JAF!Jr$s}lPSdzmeg) zK*%A>tMxE~&9iHL`ekdu=8h*yXX=hyb-Xz^^UQ#J;tV8t=+|rx%_2S<_%%LmMbUB^ zDqOrMpK`EOVDm-WUvzCg!Y_kb?pkn?`)Q}*W9a34xg~_ z$cMh1kcUxyb`~@$f2hl+tSYzo49KblTZWMj_Zb{I=MJyht{s69qc}QYcx{=xP8h+B zmGV-rzT|^S)CYf7&HB0+wDO%ZH*kp&``)qbs`L$AXc_b8ERXl|8>61}-32tr3L*ij zGVl8?Ukq#@1lWA<{%xu>C7+M%D>fehGC-uCgB>$5P5fj8`=5iUNp!ZU(m8notY7A5 zg2>0JW43iAo`Q;Fxx8jq9V^3`Dh+N_TJ}XnYtC}K#6&(RH9A|3E?ZR_(8NmtdCrOt zX2R}x%HV`k0bDbV>n`7bhkUF`1@G4$&H)E`)T;PZJ_VKF43O{_kvbS=M`Dsz*MSv4 zld4!za5LyubA4G=s@>Guc3q!~3VastLwV%DQmcnJWSpDa0~uACmWOIK*fiyY3((~# zF0h&yjOZ~Q#shp1&}R=Cs$^|Ma}uTlH3qf?Xwh09rXwcRrK{3~)($oqQ}$pQb+_0e zZk{(9&EeMg3b4!`N~uz1qcOt#S;uq2d7uqT0rt2n^YO|}bZe?~al;ZQTMKCXB3x4; z?ukRynjgUDkeU0FxVTyuj8K0WKF$K=c$Kf(l4(~}>15M_=oi=NoFBpEgNxy^KXXvQ z@f{cQKT)sL!~XIzhpC6zfIeL?R!lW27n5V$mr$kC@(5T}_uyKO?7*rB&`VA<&zJo= zw_I00BqIg5WZ)VImhnAET+z07*`nGM`xSeI{R}=C_#yiNyT*=he%$>Y5g-CYfCvx)B0vPT z5`m;5%fes&)qC!NasB-6yFvbB&mNFJzUwZKFYVq9^80t*3G#(v5#-f7?g06mX@XqY zwF~4kg#yScJ9mOy+_3|7Zr_e_+cuPKZ73N-na`ulG>$|y}5WBHBN`3q~b)&asEh8*$QCK zx763oAI(DZLi@I2XR#=@mT{MReUI6$VZP_V(K_s#mU_B*&!Izy1})F3TElkDa_#*4 z(uir^Ywo_cvmkbYh37!io^XKv1fsB~R0ijW-fmtxdZh1y2aX_Bem(-XiLeZc24LHD zM`6#7Vn=6jz*~kL{wloSPJh*kvxobzed(|;qST@ww&hfe!Ym#r7KQW1uH%wkuuSa#e6>v7krIyEN{8NQaQiBpza?JEt`=g_-A zSoF|?6ZJ53Rym(Y8dA~hDD3VuivR?6@54p(mk>#QBYhqV50^&k;IDuKLxV;F9$;)`#~s#gIT5m{cs3 zodtW?vE3>rxJcF3iVpV)b6Qsq@`1~x4VJFCr=zogE-HfwVHD&|k+)-ym1ggi5ItGq z;@)0d4)N@Pjn<;&iFG8eT6MsLkuBK5XJ*}d=JHz6;hs^;t6KrAC|K5|qepuN=N->N z6$X1#GT7^D`~T~^|F45Dz^Aw4BBwry01+SpM1Tko0U|&IhyW2F0z`la5P^*Za3?>T zg;Fi{0{G(n|JZAwW&fZ3R#Nf)|8wyCe;*R`AOb{y2oM1xKm>>Y5g-CYfCvx)B0vOg zKY@K|WhxD!4)dzgE)NH*FKb~xAykKC$QYk-TUt>HBDK9Op>)X2VJ@?28O~u?!5qf_ zOR|mx`#t+6n_wO6r?-EIWC0N%0z`la5CI}U1c(3;AOb{y2oQnWLSTO;34se+qYExs zUIf8CeF!g!;rD{o5RZxEe&g0FEBEVIS#Ngx=bLGkqbWVrJj_|#MI6mfPbvxyx zRF>tnZp zM2OJg98|-f2Eh^t(2&9s5nMq_!`42AN=QnW!pH_WOkjut1#5}00*RDT5Whu&@&A+T z>Y5g-CYVCxfzV+5dV{iOgA|DRo#H1>wX z{>lCZ5&!Z+v6$uzdeB~zHeFZ8!TOh9arh89^( zMGcvRrr>KLlT2W3BPnBT!(bo6{r~m#{r~sidjNR6B951tI6xOYhyW2F0z`la5CI}U z1c(3;AOb{y2oQn)IRV_gH%<7lK5f@7OpCyM!y@wkW0?$e-@kJwmbb?Lhw`kZfz*;o MJgcfGo8$lg7nH6|6aWAK From b142fce786dfe81b14bd7292ae524d0e96bb8a65 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:49:13 -0400 Subject: [PATCH 0330/1324] Delete socialMediaUsers.db.sqbpro --- src/qt/socialMediaUsers.db.sqbpro | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/socialMediaUsers.db.sqbpro diff --git a/src/qt/socialMediaUsers.db.sqbpro b/src/qt/socialMediaUsers.db.sqbpro deleted file mode 100644 index 6db21d67..00000000 --- a/src/qt/socialMediaUsers.db.sqbpro +++ /dev/null @@ -1 +0,0 @@ - From 00e9859eb3d04ae751bbe09a791f8122ea18326e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:51:06 -0400 Subject: [PATCH 0331/1324] Add files via upload --- src/qt/Activity.cpp | 48 + src/qt/Activity.h | 38 + src/qt/Social-Network-Qt-Application-GUI.pro | 66 + ...Social-Network-Qt-Application-GUI.pro.user | 2759 ++ ...etwork-Qt-Application-GUI.pro.user.b3887f6 | 318 + ...rk-Qt-Application-GUI.pro.user.fe1e10a.xml | 2756 ++ src/qt/addcomment.cpp | 26 + src/qt/addcomment.h | 33 + src/qt/adminwindow.cpp | 94 + src/qt/adminwindow.h | 26 + src/qt/comment.cpp | 46 + src/qt/comment.h | 36 + src/qt/fileman.cpp | 756 + src/qt/fileman.h | 48 + src/qt/form.cpp | 14 + src/qt/form.h | 22 + src/qt/newaccount.cpp | 55 + src/qt/newaccount.h | 36 + src/qt/posts.cpp | 112 + src/qt/posts.h | 179 + src/qt/qcustomplot.cpp | 30121 ++++++++++++++++ src/qt/qcustomplot.h | 6662 ++++ src/qt/statistics.cpp | 46 + src/qt/statistics.h | 37 + src/qt/user.cpp | 35 + src/qt/user.h | 26 + 26 files changed, 44395 insertions(+) create mode 100644 src/qt/Activity.cpp create mode 100644 src/qt/Activity.h create mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro create mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user create mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 create mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml create mode 100644 src/qt/addcomment.cpp create mode 100644 src/qt/addcomment.h create mode 100644 src/qt/adminwindow.cpp create mode 100644 src/qt/adminwindow.h create mode 100644 src/qt/comment.cpp create mode 100644 src/qt/comment.h create mode 100644 src/qt/fileman.cpp create mode 100644 src/qt/fileman.h create mode 100644 src/qt/form.cpp create mode 100644 src/qt/form.h create mode 100644 src/qt/newaccount.cpp create mode 100644 src/qt/newaccount.h create mode 100644 src/qt/posts.cpp create mode 100644 src/qt/posts.h create mode 100644 src/qt/qcustomplot.cpp create mode 100644 src/qt/qcustomplot.h create mode 100644 src/qt/statistics.cpp create mode 100644 src/qt/statistics.h create mode 100644 src/qt/user.cpp create mode 100644 src/qt/user.h diff --git a/src/qt/Activity.cpp b/src/qt/Activity.cpp new file mode 100644 index 00000000..eb388cc8 --- /dev/null +++ b/src/qt/Activity.cpp @@ -0,0 +1,48 @@ +#include "Activity.h" +#include +#include "posts.h" +#include"vector" + + +Activity::Activity() +{ + likesNumbers = 0; + postsNumber = 0; +} + +Activity::~Activity() +{ + +} +unsigned int Activity::getFriendsNumbers() + + {return friends.size();} + +unsigned int Activity::getPostsNumbers() + +{ return postsNumber;} + +void Activity::addFriend(QString friendName) +{ + friends.push_back(friendName); +} + +void Activity::addPost() +{ + postsNumber++; +} + +unsigned int Activity::getLikesNumbers() +{ + return likesNumbers; +} + +void Activity:: addLike() +{ + likesNumbers++; +} + +QList *Activity::getFriendsList_Ptr() +{ + return &friends; +} diff --git a/src/qt/Activity.h b/src/qt/Activity.h new file mode 100644 index 00000000..24896d27 --- /dev/null +++ b/src/qt/Activity.h @@ -0,0 +1,38 @@ +#ifndef ACTIVITY_H +#define ACTIVITY_H +#include +#include +#include "vector" +#include "posts.h" +#include "QList" +class Activity +{ + unsigned int likesNumbers; + + unsigned int postsNumber; + + QList friends; + + +public: + + Activity(); + + ~Activity(); + + unsigned int getLikesNumbers(); + + unsigned int getFriendsNumbers(); + + unsigned int getPostsNumbers(); + + void addLike(); + + void addFriend(QString); + + void addPost(); + + QList *getFriendsList_Ptr(); +}; + +#endif // ACTIVITY_H diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro b/src/qt/Social-Network-Qt-Application-GUI.pro new file mode 100644 index 00000000..decc1983 --- /dev/null +++ b/src/qt/Social-Network-Qt-Application-GUI.pro @@ -0,0 +1,66 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-04-19T16:47:57 +# +#------------------------------------------------- + +QT += core gui printsupport + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = Social-Network-Qt-Application-GUI +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + newaccount.cpp \ + profilepage.cpp \ + addcomment.cpp \ + posts.cpp \ + comment.cpp \ + Activity.cpp \ + user.cpp \ + fileman.cpp \ + qcustomplot.cpp \ + adminwindow.cpp \ + statistics.cpp \ + homepage.cpp + +HEADERS += \ + mainwindow.h \ + newaccount.h \ + homepage.h \ + profilepage.h \ + addcomment.h \ + posts.h \ + comment.h \ + Activity.h \ + user.h \ + fileman.h \ + qcustomplot.h \ + adminwindow.h \ + statistics.h + +FORMS += \ + mainwindow.ui \ + newaccount.ui \ + homepage.ui \ + profilepage.ui \ + addcomment.ui \ + adminwindow.ui + +RESOURCES += \ + myresources.qrc diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user b/src/qt/Social-Network-Qt-Application-GUI.pro.user new file mode 100644 index 00000000..393889eb --- /dev/null +++ b/src/qt/Social-Network-Qt-Application-GUI.pro.user @@ -0,0 +1,2759 @@ + + + + + + EnvironmentId + {fe1e10ad-70df-4b47-bcd1-f71c5f735ac1} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.5.1 MinGW 32bit + Desktop Qt 5.5.1 MinGW 32bit + qt.55.win32_mingw492_kit + 1 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) + Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) + qt.55.win64_msvc2013_winphone_x86_kit + 0 + -1 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + 0 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.10 + + Desktop Qt 5.11.0 MinGW 32bit2 + Desktop Qt 5.11.0 MinGW 32bit2 + qt.qt5.5110.win32_mingw53_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.2 + + Qt 5.5.1 for Windows Runtime 64bit + Qt 5.5.1 for Windows Runtime 64bit + qt.55.win64_msvc2013_winrt_x64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + + true + + Run windeployqt + WinRt.BuildStep.Deploy + --qmldir "D:\Comp-Third year\Data structures & Algorithms\Project\Social-Network-Qt-Application-GUI" + + 1 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Run windeployqt + + WinRTAppxDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.3 + + Desktop Qt 5.5.1 MSVC2010 32bit + Desktop Qt 5.5.1 MSVC2010 32bit + qt.55.win32_msvc2010_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.4 + + Desktop Qt 5.5.1 MSVC2012 32bit + Desktop Qt 5.5.1 MSVC2012 32bit + qt.55.win32_msvc2012_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.5 + + Desktop Qt 5.5.1 MSVC2013 32bit + Desktop Qt 5.5.1 MSVC2013 32bit + qt.55.win32_msvc2013_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.6 + + Desktop Qt 5.5.1 MSVC2013 64bit + Desktop Qt 5.5.1 MSVC2013 64bit + qt.55.win64_msvc2013_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.7 + + Desktop Qt 5.11.0 MSVC2015 32bit + Desktop Qt 5.11.0 MSVC2015 32bit + qt.qt5.5110.win32_msvc2015_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.8 + + Desktop Qt 5.11.0 MSVC2015 64bit + Desktop Qt 5.11.0 MSVC2015 64bit + qt.qt5.5110.win64_msvc2015_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.9 + + Desktop Qt 5.11.0 MSVC2017 64bit + Desktop Qt 5.11.0 MSVC2017 64bit + qt.qt5.5110.win64_msvc2017_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 11 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 b/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 new file mode 100644 index 00000000..b6c060fc --- /dev/null +++ b/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {b3887f65-3e4c-4f2e-995b-8c4746b920fe} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.7.0 MinGW 32bit + Desktop Qt 5.7.0 MinGW 32bit + qt.57.win32_mingw53_kit + 0 + 0 + 0 + + C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/lenovo/Desktop/DS/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml b/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml new file mode 100644 index 00000000..df80aac0 --- /dev/null +++ b/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml @@ -0,0 +1,2756 @@ + + + + + + EnvironmentId + {fe1e10ad-70df-4b47-bcd1-f71c5f735ac1} + + + ProjectExplorer.Project.ActiveTarget + 10 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.5.1 MinGW 32bit + Desktop Qt 5.5.1 MinGW 32bit + qt.55.win32_mingw492_kit + 1 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) + Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) + qt.55.win64_msvc2013_winphone_x86_kit + 0 + -1 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + 0 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.10 + + Desktop Qt 5.11.0 MinGW 32bit2 + Desktop Qt 5.11.0 MinGW 32bit2 + qt.qt5.5110.win32_mingw53_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Social-Network-Qt-Application-GUI + + Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro + true + + Social-Network-Qt-Application-GUI.pro + false + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.2 + + Qt 5.5.1 for Windows Runtime 64bit + Qt 5.5.1 for Windows Runtime 64bit + qt.55.win64_msvc2013_winrt_x64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + + true + + Run windeployqt + WinRt.BuildStep.Deploy + --qmldir "D:\Comp-Third year\Data structures & Algorithms\Project\Social-Network-Qt-Application-GUI" + + 1 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Run windeployqt + + WinRTAppxDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.3 + + Desktop Qt 5.5.1 MSVC2010 32bit + Desktop Qt 5.5.1 MSVC2010 32bit + qt.55.win32_msvc2010_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.4 + + Desktop Qt 5.5.1 MSVC2012 32bit + Desktop Qt 5.5.1 MSVC2012 32bit + qt.55.win32_msvc2012_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.5 + + Desktop Qt 5.5.1 MSVC2013 32bit + Desktop Qt 5.5.1 MSVC2013 32bit + qt.55.win32_msvc2013_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.6 + + Desktop Qt 5.5.1 MSVC2013 64bit + Desktop Qt 5.5.1 MSVC2013 64bit + qt.55.win64_msvc2013_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.7 + + Desktop Qt 5.11.0 MSVC2015 32bit + Desktop Qt 5.11.0 MSVC2015 32bit + qt.qt5.5110.win32_msvc2015_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.8 + + Desktop Qt 5.11.0 MSVC2015 64bit + Desktop Qt 5.11.0 MSVC2015 64bit + qt.qt5.5110.win64_msvc2015_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.9 + + Desktop Qt 5.11.0 MSVC2017 64bit + Desktop Qt 5.11.0 MSVC2017 64bit + qt.qt5.5110.win64_msvc2017_64_kit + 0 + 0 + 0 + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 11 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp new file mode 100644 index 00000000..fde45cd1 --- /dev/null +++ b/src/qt/addcomment.cpp @@ -0,0 +1,26 @@ +#include "addcomment.h" +#include "ui_addcomment.h" + +AddComment::AddComment(QWidget *parent) : + QDialog(parent), + ui(new Ui::AddComment) +{ + ui->setupUi(this); + commentBody = ""; + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +} + +AddComment::~AddComment() +{ + delete ui; +} + +void AddComment::on_AddComment_accepted() +{ + commentBody = ui->plainTextEdit->toPlainText(); +} + +QString AddComment::getCommentBody() +{ + return commentBody; +} diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h new file mode 100644 index 00000000..bb61bc05 --- /dev/null +++ b/src/qt/addcomment.h @@ -0,0 +1,33 @@ +#ifndef ADDCOMMENT_H +#define ADDCOMMENT_H + +#include + +namespace Ui { +class AddComment; +} + +class AddComment : public QDialog +{ + Q_OBJECT + +public: + explicit AddComment(QWidget *parent = 0); + + ~AddComment(); + +public slots: + QString getCommentBody(); + + +private slots: + void on_AddComment_accepted(); + + +private: + Ui::AddComment *ui; + + QString commentBody; +}; + +#endif // ADDCOMMENT_H diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp new file mode 100644 index 00000000..4d6b37a6 --- /dev/null +++ b/src/qt/adminwindow.cpp @@ -0,0 +1,94 @@ +#include "adminwindow.h" +#include "ui_adminwindow.h" +#include "statistics.h" +#include "fileman.h" +AdminWindow::AdminWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::AdminWindow) +{ + ui->setupUi(this); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); + +} + +AdminWindow::~AdminWindow() +{ + delete ui; +} + + +void AdminWindow:: makePlot(QVector *plotData) +{ + ui->customPlot->clearGraphs(); + ui->customPlot->legend->setVisible(true); + ui->customPlot->legend->setFont(QFont("Helvetica", 9)); + QPen pen; + QStringList lineNames; + lineNames << "Friends Number" << "Likes Number" << "Posts Number"; + // add graphs with different line styles: + for (int i = 0; i < 3; ++i) + { + ui->customPlot->addGraph(); + if(i == 0) + pen.setColor(QColor(0x02, 0xa0, 0xc3)); + else if(i == 1) + pen.setColor(QColor(0xef, 0xef, 0x00)); + else + pen.setColor(QColor(0xef, 0x2b, 0x90)); + ui->customPlot->graph()->setPen(pen); + ui->customPlot->graph()->setName(lineNames.at(i)); + ui->customPlot->graph()->setLineStyle((QCPGraph::lsLine)); + ui->customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); + // generate data: + QVector x((*plotData).size()), y(1000); + for (int j = 0; j < (*plotData).size(); ++j) + { + x[j] = (*plotData)[j].getUserID(); + if(i == 0) + y[j] = (*plotData)[j].getFriendsNumber(); + else if(i == 1) + y[j] = (*plotData)[j].getLikesNumber(); + else + y[j] = (*plotData)[j].getPostsNumber(); + } + ui->customPlot->graph()->setData(x, y); + ui->customPlot->graph()->rescaleAxes(true); + } + // zoom out a bit: + ui->customPlot->yAxis->scaleRange(0, plotData->size()+1); + ui->customPlot->xAxis->scaleRange(0, 1000); + // set blank axis lines: + ui->customPlot->xAxis->setTicks(true); + ui->customPlot->yAxis->setTicks(true); + ui->customPlot->xAxis->setTickLabels(true); + ui->customPlot->yAxis->setTickLabels(true); + ui->customPlot->xAxis2->setVisible(true); + ui->customPlot->yAxis2->setVisible(true); + ui->customPlot->xAxis2->setTicks(false); + ui->customPlot->yAxis2->setTicks(false); + // make top right axes clones of bottom left axes: +// ui->customPlot->axisRect()->setupFullAxesBox(); + ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); + ui->customPlot->replot(); + + +} +void AdminWindow::on_showStatistics_clicked() +{ + QVector *testingData = new QVector; + fileman network; + QList emails = network.readEmails(); + testingData->resize(emails.size()); + for(int i = 0; i < emails.size(); i++) + { + (*testingData)[i].setUserID(i); + (*testingData)[i].setFriendsNumber(network.getFriends(emails[i]).size() / 3); + int likesNumber,postsNumber; + network.getActivity(emails[i],postsNumber,likesNumber); + (*testingData)[i].setPostsNumber(network.getPosts(emails[i])->size()); + (*testingData)[i].setLikesNumber(likesNumber); + } + makePlot(testingData); +} diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h new file mode 100644 index 00000000..308af0fe --- /dev/null +++ b/src/qt/adminwindow.h @@ -0,0 +1,26 @@ +#ifndef ADMINWINDOW_H +#define ADMINWINDOW_H + +#include +#include "statistics.h" +namespace Ui { +class AdminWindow; +} + +class AdminWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit AdminWindow(QWidget *parent = 0); + ~AdminWindow(); + +private slots: + void on_showStatistics_clicked(); + + void makePlot(QVector *plotData); +private: + Ui::AdminWindow *ui; +}; + +#endif // ADMINWINDOW_H diff --git a/src/qt/comment.cpp b/src/qt/comment.cpp new file mode 100644 index 00000000..09328393 --- /dev/null +++ b/src/qt/comment.cpp @@ -0,0 +1,46 @@ +#include "comment.h" + +Comment::Comment() +{ + commentOwner = ""; + commentText = ""; +} + +Comment::Comment(QString owner, QString text, QString creationDate) +{ + + commentOwner = owner; + commentText = text; + commentDate = creationDate; +} + +void Comment::setCommentOwner(QString owner) +{ + commentOwner = owner; +} + +QString Comment::getCommentOwner() +{ + return commentOwner; +} + +void Comment::setCommentText(QString text) +{ + commentText = text; +} + +QString Comment::getCommentText() +{ + return commentText; +} + +void Comment::setCommentDate(QString creationDate) +{ + commentDate = creationDate; +} + +QString Comment::getCommentDate() +{ + return commentDate; +} + diff --git a/src/qt/comment.h b/src/qt/comment.h new file mode 100644 index 00000000..9a54b7c9 --- /dev/null +++ b/src/qt/comment.h @@ -0,0 +1,36 @@ +#ifndef COMMENT_H +#define COMMENT_H + +#include "QString" +#include "QDate" +#include "QTime" +class Date : public QDate +{ + QTime timeIsNow; +public: + QString getDateNow(){return this->currentDate().toString("yyyy.MM.dd") +" @ " +timeIsNow.currentTime().toString("HH:mm:ss");} +}; +class Comment +{ + QString commentOwner; + QString commentText; + QString commentDate; +public: + Comment(); + + Comment(QString, QString, QString); + + void setCommentOwner(QString); + + QString getCommentOwner(); + + void setCommentText(QString); + + QString getCommentText(); + + void setCommentDate(QString); + + QString getCommentDate(); +}; + +#endif // COMMENT_H diff --git a/src/qt/fileman.cpp b/src/qt/fileman.cpp new file mode 100644 index 00000000..cab9aee7 --- /dev/null +++ b/src/qt/fileman.cpp @@ -0,0 +1,756 @@ +#include "fileman.h" +#include + +int numberOfUsers=0; +QList emailss; +fileman::fileman() +{ + //name=username; + path=""; + +} +void fileman:: TESTTEST() +{ + QString line; + QFile in(path+name); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YOMNA SAN"; + QTextStream innn(&in); + line=innn.readLine(); + qDebug()<") + { + + line=innn.readLine(); + if(line==Date){ + line=innn.readLine(); + while(line!=NULL){ + + if(line==""){ + line=innn.readLine(); + while(line!="") + { + // cout<* fileman:: getPosts(QString email){ + QString line; + QFile in(path+"Users/"+email+".xml"); + QTextStream innn(&in); + QList *posts = new QList ; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + //bool begin_tag = false; + line=innn.readLine(); + while (line!=NULL) + { + + if(line==""){ + temp=""; + line=innn.readLine(); + while(!(line=="") ) + { + //cout<append(tempPost); + + } + line=innn.readLine(); +} + return posts; +} + + QString fileman:: getUserNameByEmail(QString email) + { + QFile in(path+"Users/"+email+".xml"); + QTextStream f (&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN the file "; + QString line=f.readLine(); + while(1) + { + if(line=="") + { + line=f.readLine(); + // qDebug()<") break; + + + } + + + + } + +void fileman:: createFile( QString passWord,QString email,QString userName,QString date ) +{ + emailss.push_back(email); + numberOfUsers++; + QString newFileStamp="\n"+userName+"\n\n"+"\n"+email+"\n\n\n"+date+"\n\n\n"+passWord+"\n\n\n\n\n0\n\n\n0\n"; + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &file ); + stream << newFileStamp; + } + + addEmail(email); + +} + +void fileman:: addPost(QString userPost, QString Date, QString name) +{ + // QString newPost=readFile("addPost.txt"); + + QFile i(path+name+".txt"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + + + + QFile in(path+"addPost.txt"); + QTextStream innn(&in); + + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString newPost=innn.readAll(); //This file is with norhaaaan doko kana wakaranai + in.close(); + + int indexText= newPost.indexOf(""); //+10 + newPost.insert(indexText+11,userPost); + + int indexDate=newPost.indexOf(""); + newPost.insert(indexDate+11,Date); + indexText= userFile.lastIndexOf(""); + userFile.insert(indexText+8,newPost); + QFile file(path+name+".txt"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} + + +void fileman:: addComment(QString userComment){ + + QString commentStamp="\n\n\n"+userComment+"\n\n\n\n\n"; + //now lets open the user file to insert el bta3 da + + QFile i(path+"addUser.txt"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + //Now we have all the user file content in userFile + int index=userFile.indexOf(""); + userFile.insert(index,commentStamp); + // qDebug()<\n\n"+nameComment+"\n\n\n"; + //now lets open the user file to insert el bta3 da + + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); +//now insert fe el userFile how is that :) + QString copy=userFile; +int from=0; +while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; +QString line="";int j=11; +line=userFile.mid(indexOfPostDate+11,Date.count()); +//userFile.insert(indexOfPostDate+j,commentStamp); + +//qDebug()<\n\n"+userPost+"\n\n"+"\n\n"+""; + + int indexText= userFile.indexOf(""); + userFile.insert(indexText+11,postStamp); + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + // qDebug()<< "couldn't open file"; + + file.close(); + +} +//QList * fileman:: getCommentsByPostDate(QString email,QString date) + +void fileman:: getCommentsByPostDate(QString email,QString date){ + + QString line; + QFile in(path+"Users/"+email+".xml"); + QTextStream inn(&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); +qDebug()< *comments = new QList ; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + + qDebug()<<"COULD NOT OPEN YA BENTY"; + int from=0; + //while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; + //QString line; + int j=11+1+1; + int indexOfCommentTag; + line=userFile.mid(indexOfPostDate+j,date.count()); + //userFile.insert(indexOfPostDate+date.count()+j+11,"hiiiiii i am here"); + // qDebug()<"; + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + int indexOfFriend=userFile.indexOf(""); + userFile.insert(indexOfFriend+9,friendStamp); +QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} +void fileman:: updateActivity(QString email, int numberOfLikes , int numberOfComments){ + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + int indexOfLikes=userFile.indexOf(""); + /* int ii=16; + QChar x=userFile[indexOfLikes+ii]; + + while(x!='\n'){ + userFile[indexOfLikes+ii]='NULL'; + ii++; + x=userFile[indexOfLikes+ii]; + + } +*/ + userFile.insert(indexOfLikes+15,"\n"+QString::number(numberOfLikes)); + int indexOfComments=userFile.indexOf(""); + userFile.insert(indexOfComments+18,"\n"+QString::number(numberOfComments)); + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); +} + + +void fileman:: networkFile(){ + QString newFileStamp="\n"+QString::number(numberOfUsers)+"\n\n"; + QFile file(path+"Users/"+"network"+".xml"); + if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &file ); + stream << newFileStamp; + } + + +} + +void fileman::addUsers(){ + QFile i(path+"Users/network.xml"); + QTextStream inn(&i); + int id=0; + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + QFile file(path+"Users/network.xml"); + fileman x; + QList emails=x.readEmails(); +for (int k = 0; k \n\n"+QString::number(id)+"\n"; + id++; + int indexText= userFile.indexOf(""); + userFile.insert(indexText+16,emailStamp); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + + } + +} + +void fileman::createEmailFile() +{ + QString stamp="\n"; + QFile f(path+"Users/"+"email"+".xml"); + if ( f.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &f ); + stream << stamp; + } +} +void fileman::addEmail(QString email){ + QFile i(path+"Users/"+"email"+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); + i.close(); + int indexText= userFile.indexOf(""); + userFile.insert(indexText+8,"\n"+email); + QFile file(path+"Users/"+"email"+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} +QList fileman:: readEmails(){ + QString line; + QFile in(path+"Users/"+"email"+".xml"); + QTextStream innn(&in); +// QList emails = new QList ; + QList emails; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + line=innn.readLine(); + + if(line==""){ + line=innn.readLine(); + while(1) + { + emails.append(line); + // qDebug()<") break; + + // if(line==NULL) break; + + } + } + + return emails; + +} + +QList fileman:: getFriends(QString email) +{ + QList result; + QFile in(path+"Users/"+email+".xml"); + QTextStream innn(&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString line=innn.readLine(); + while(1){ + if(line=="") + { + while(1) + { + line=innn.readLine(); + + if(line=="") break; + result.append(line); + if(line==""||line=="") continue; + //qDebug()<") + { + line=inn.readLine(); + numberOfLikes=line.toInt(); + break; + } + if(line=="") + { + line=inn.readLine(); + numberOfPosts=line.toInt(); + break; + } + line=inn.readLine(); + if(line=="") + break; + + } +} + +QList *fileman::getPosts_new(QString email) +{ + QList *result = new QList; + + + + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString line=inn.readLine(); + while(1) + { + Post temp; temp.setPostText(""); + if(line=="") + { + line=inn.readLine(); + while(1) + { + + if(line=="") + { + line=inn.readLine(); + temp.setPostDate(line); + // qDebug()<") + { + temp.setPostText(""); + line=inn.readLine(); + while(1) + { + if(line=="") + { + break; + } + temp.setPostText(temp.getPostText()+line); + // qDebug()<") + { + + Comment tempCom; + line=inn.readLine(); + while(1) + { + if(line=="") + { + tempCom.setCommentText(""); + line=inn.readLine(); + while(1) + { + tempCom.setCommentText(tempCom.getCommentText()+line); + line=inn.readLine(); + if(line=="")break; + } + } + if(line=="") + { + tempCom.setCommentOwner(inn.readLine()); + } + line=inn.readLine(); + if(line=="")break; + + } + //qDebug()<") + { + line=inn.readLine(); + while(line!="") + { + if(line=="") break; + if(line==""|| line=="") + { + line=inn.readLine(); + continue; + } + + temp.getPostLikesOwnersVectorPtr()->push_back(line); + + // qDebug()<") + { + fileman x; + temp.setPostOwner(email); + result->append(temp); + break; + } + + } + } + line=inn.readLine(); + if(line=="")break; + } +return result; +} + + + +void fileman ::addLikeByPostDate(QString email, QString Date, QString likePerson) +{ + QString likeStamp="\n\n"+likePerson+"\n"; + QFile i(path+"Users/"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + + int from=0; int k=0; + while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; + QString line="";int j=11; + + line=userFile.mid(indexOfPostDate+11,Date.count()); +// userFile.insert(indexOfPostDate+j,likeStamp); + + //qDebug()<",from); + int likeTagIndex= userFile.indexOf("",from); + + userFile.insert(likeTagIndex+6,likeStamp); + k++; + + qDebug()<") + { + line=f.readLine(); + // qDebug()<") break; + + + } +} diff --git a/src/qt/fileman.h b/src/qt/fileman.h new file mode 100644 index 00000000..3e434553 --- /dev/null +++ b/src/qt/fileman.h @@ -0,0 +1,48 @@ +#ifndef FILEMAN_H +#define FILEMAN_H +#include +#include +#include +#include +#include +#include +#include "posts.h" +#include "comment.h" + + +class fileman{ +public: + QString path; + QString name; + QList posts; + + fileman(); + QString getPostByDate(QString Date); + QList * getPosts(QString email); + QString getUserNameByEmail(QString email); + void addPost(QString userPost, QString Date, QString name); + void addComment(QString userComment); + void addCommentByPostDate(QString userComment, QString Date, QString nameComment,QString nameFile); + void createFile( QString passWord,QString email,QString userName,QString date ); + void addFriend (QString friendName, QString name); + void addPost_new(QString userPost, QString Date, QString name); + void getCommentsByPostDate(QString email,QString date); + void addFriends(QString email,QString friendName); + void updateActivity(QString email, int numberOfLikes , int numberOfComments); + friend class user; + void networkFile(); + void addUsers(); + void TESTTEST(); + void createEmailFile(); + void addEmail(QString email); + QList readEmails(); + QList getFriends(QString email); + void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); + QList * getPosts_new(QString email); + +public slots: + void addLikeByPostDate(QString email, QString Date, QString likePerson); + QString getPassword(QString email); +}; + +#endif diff --git a/src/qt/form.cpp b/src/qt/form.cpp new file mode 100644 index 00000000..20e6af24 --- /dev/null +++ b/src/qt/form.cpp @@ -0,0 +1,14 @@ +#include "form.h" +#include "ui_form.h" + +Form::Form(QWidget *parent) : + QWidget(parent), + ui(new Ui::Form) +{ + ui->setupUi(this); +} + +Form::~Form() +{ + delete ui; +} diff --git a/src/qt/form.h b/src/qt/form.h new file mode 100644 index 00000000..59d50c60 --- /dev/null +++ b/src/qt/form.h @@ -0,0 +1,22 @@ +#ifndef FORM_H +#define FORM_H + +#include + +namespace Ui { +class Form; +} + +class Form : public QWidget +{ + Q_OBJECT + +public: + explicit Form(QWidget *parent = 0); + ~Form(); + +private: + Ui::Form *ui; +}; + +#endif // FORM_H diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp new file mode 100644 index 00000000..89c986e8 --- /dev/null +++ b/src/qt/newaccount.cpp @@ -0,0 +1,55 @@ +#include "newaccount.h" +#include "ui_newaccount.h" +#include "QMessageBox" +#include +newAccount::newAccount(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::newAccount) +{ + ui->setupUi(this); + user check; + id=check.getUsersSize(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->setWindowTitle("Social Network"); + +} + +newAccount::~newAccount() +{ + delete ui; +} + +void newAccount::on_pushButton_clicked() +{ + QString password =ui->lineEdit_2->text(); + QString confirm =ui->lineEdit_3->text(); + QString mail=ui->txtUserMail->text(); + if(password!=confirm) + { + QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); + } + else + { + user temp (password,mail,ui->txtUserName->text(),id); + temp.setUsersList(temp); + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + this->hide(); +// temp.userFileManipulator.updateActivity(mail,0,0); + } + +} + +void newAccount::setLoginPtr(MainWindow *ptr) +{ + this->mainWindowPtr = ptr; +} + +void newAccount::on_pushButton_2_clicked() +{ + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + // mainWindowPtr->show(); + this->hide(); + +} diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h new file mode 100644 index 00000000..9114dcdd --- /dev/null +++ b/src/qt/newaccount.h @@ -0,0 +1,36 @@ +#ifndef NEWACCOUNT_H +#define NEWACCOUNT_H + +#include +#include "mainwindow.h" +namespace Ui { +class newAccount; +} + +class newAccount : public QMainWindow +{ + Q_OBJECT + +public: + explicit newAccount(QWidget *parent = 0); + ~newAccount(); + int id; + + +public slots: + void setLoginPtr(MainWindow *ptr); + + +private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + +private: + Ui::newAccount *ui; + + MainWindow *mainWindowPtr; +}; + +#endif // NEWACCOUNT_H diff --git a/src/qt/posts.cpp b/src/qt/posts.cpp new file mode 100644 index 00000000..ef082536 --- /dev/null +++ b/src/qt/posts.cpp @@ -0,0 +1,112 @@ +#include "posts.h" + +Post::Post() +{ + postOwner = ""; + postText = ""; +} + +Post::Post(QString owner, QString text, QString creationDate) +{ + postOwner = owner; + postText = text; + postDate = creationDate; + postLikesNumber = 0; +} + +void Post::setPostOwner(QString owner) +{ + postOwner = owner; +} + +QString Post::getPostOwner() +{ + return postOwner; +} + +void Post::setPostText(QString text) +{ + postText = text; +} + +QString Post::getPostText() +{ + return postText; +} + +void Post::addPostLike(QString likeOwner) +{ + postLikesNumber++; + postLikesOwners.push_back(likeOwner); +} + +void Post::removePostLike(QString owner) +{ + std::vector::iterator iterator; + for(iterator = postLikesOwners.begin(); iterator != postLikesOwners.end(); iterator++) + { + if(*iterator == owner) + { + postLikesOwners.erase(iterator); + break; + } + } +} + +unsigned int Post::getPostLikesNumber() +{ + return postLikesNumber; +} + +std::vector *Post::getPostLikesOwnersVectorPtr() +{ + return &postLikesOwners; +} + +void Post::addComment(Comment newComment) +{ + postComments.push_back(newComment); +} + +void Post::deleteComment(Comment toBeDeleted) +{ + std::vector::iterator iterator; + for(iterator = postComments.begin(); iterator != postComments.end(); iterator++) + { + if((*iterator).getCommentText() == toBeDeleted.getCommentText()) + { + postComments.erase(iterator); + break; + } + } +} + +std::vector *Post::getPostCommentsVectorPtr() +{ + return &postComments; +} + +void Post::setPostDate(QString creationDate) +{ + postDate = creationDate; +} + +QString Post::getPostDate() +{ + return postDate; +} + + + + + + + + + + + + + + + diff --git a/src/qt/posts.h b/src/qt/posts.h new file mode 100644 index 00000000..094b3c17 --- /dev/null +++ b/src/qt/posts.h @@ -0,0 +1,179 @@ +#ifndef POSTS_H +#define POSTS_H +#include "comment.h" +#include +#include +class Post +{ + QString postOwner; + QString postText; + unsigned int postLikesNumber; + std::vector postLikesOwners; + std::vector postComments; + QString postDate; +public: + + /** + * @brief + * + * @param + * + * @return + */ + Post(); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + Post(QString,QString,QString); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + void setPostOwner(QString); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + QString getPostOwner(); + + /** + * @brief + * + * @ + * + * @param + * + * @return + */ + void setPostText(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + QString getPostText(); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void addPostLike(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void removePostLike(QString); + + /** + * @brief + * + * @example <35 likes or so. Maybe used to view the post likes number in a label or something.> + * + * @param + * + * @return + */ + unsigned int getPostLikesNumber(); + + /** + * @brief + * + * @example + * + * @param + * + * @return * postLikesOwners> + */ + std::vector* getPostLikesOwnersVectorPtr(); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void addComment(Comment); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void deleteComment(Comment); + + /** + * @brief + * + * @example + * + * @param + * + * @return * commentsVector> + */ + std::vector* getPostCommentsVectorPtr(); + + /** + * @brief + * + * @example: + * + * @param + * + * @return + */ + void setPostDate(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + QString getPostDate(); +}; +#endif // POSTS_H diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp new file mode 100644 index 00000000..154576a6 --- /dev/null +++ b/src/qt/qcustomplot.cpp @@ -0,0 +1,30121 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#include "qcustomplot.h" + + +/* including file 'src/vector2d.cpp', size 7340 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPVector2D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPVector2D + \brief Represents two doubles as a mathematical 2D vector + + This class acts as a replacement for QVector2D with the advantage of double precision instead of + single, and some convenience methods tailored for the QCustomPlot library. +*/ + +/* start documentation of inline functions */ + +/*! \fn void QCPVector2D::setX(double x) + + Sets the x coordinate of this vector to \a x. + + \see setY +*/ + +/*! \fn void QCPVector2D::setY(double y) + + Sets the y coordinate of this vector to \a y. + + \see setX +*/ + +/*! \fn double QCPVector2D::length() const + + Returns the length of this vector. + + \see lengthSquared +*/ + +/*! \fn double QCPVector2D::lengthSquared() const + + Returns the squared length of this vector. In some situations, e.g. when just trying to find the + shortest vector of a group, this is faster than calculating \ref length, because it avoids + calculation of a square root. + + \see length +*/ + +/*! \fn QPoint QCPVector2D::toPoint() const + + Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point + information. + + \see toPointF +*/ + +/*! \fn QPointF QCPVector2D::toPointF() const + + Returns a QPointF which has the x and y coordinates of this vector. + + \see toPoint +*/ + +/*! \fn bool QCPVector2D::isNull() const + + Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y + coordinates, i.e. if both are binary equal to 0. +*/ + +/*! \fn QCPVector2D QCPVector2D::perpendicular() const + + Returns a vector perpendicular to this vector, with the same length. +*/ + +/*! \fn double QCPVector2D::dot() const + + Returns the dot/scalar product of this vector with the specified vector \a vec. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates to 0. +*/ +QCPVector2D::QCPVector2D() : + mX(0), + mY(0) +{ +} + +/*! + Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified + values. +*/ +QCPVector2D::QCPVector2D(double x, double y) : + mX(x), + mY(y) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPoint &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPointF &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Normalizes this vector. After this operation, the length of the vector is equal to 1. + + \see normalized, length, lengthSquared +*/ +void QCPVector2D::normalize() +{ + double len = length(); + mX /= len; + mY /= len; +} + +/*! + Returns a normalized version of this vector. The length of the returned vector is equal to 1. + + \see normalize, length, lengthSquared +*/ +QCPVector2D QCPVector2D::normalized() const +{ + QCPVector2D result(mX, mY); + result.normalize(); + return result; +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a start and \a end. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const +{ + QCPVector2D v(end-start); + double vLengthSqr = v.lengthSquared(); + if (!qFuzzyIsNull(vLengthSqr)) + { + double mu = v.dot(*this-start)/vLengthSqr; + if (mu < 0) + return (*this-start).lengthSquared(); + else if (mu > 1) + return (*this-end).lengthSquared(); + else + return ((start + mu*v)-*this).lengthSquared(); + } else + return (*this-start).lengthSquared(); +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a line. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QLineF &line) const +{ + return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); +} + +/*! + Returns the shortest distance of this vector (interpreted as a point) to the infinite straight + line given by a \a base point and a \a direction vector. + + \see distanceSquaredToLine +*/ +double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const +{ + return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); +} + +/*! + Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a + factor. +*/ +QCPVector2D &QCPVector2D::operator*=(double factor) +{ + mX *= factor; + mY *= factor; + return *this; +} + +/*! + Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a + divisor. +*/ +QCPVector2D &QCPVector2D::operator/=(double divisor) +{ + mX /= divisor; + mY /= divisor; + return *this; +} + +/*! + Adds the given \a vector to this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) +{ + mX += vector.mX; + mY += vector.mY; + return *this; +} + +/*! + subtracts the given \a vector from this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) +{ + mX -= vector.mX; + mY -= vector.mY; + return *this; +} +/* end of 'src/vector2d.cpp' */ + + +/* including file 'src/painter.cpp', size 8670 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPainter +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPainter + \brief QPainter subclass used internally + + This QPainter subclass is used to provide some extended functionality e.g. for tweaking position + consistency between antialiased and non-antialiased painting. Further it provides workarounds + for QPainter quirks. + + \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and + restore. So while it is possible to pass a QCPPainter instance to a function that expects a + QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because + it will call the base class implementations of the functions actually hidden by QCPPainter). +*/ + +/*! + Creates a new QCPPainter instance and sets default values +*/ +QCPPainter::QCPPainter() : + QPainter(), + mModes(pmDefault), + mIsAntialiasing(false) +{ + // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and + // a call to begin() will follow +} + +/*! + Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just + like the analogous QPainter constructor, begins painting on \a device immediately. + + Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. +*/ +QCPPainter::QCPPainter(QPaintDevice *device) : + QPainter(device), + mModes(pmDefault), + mIsAntialiasing(false) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (isActive()) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif +} + +/*! + Sets the pen of the painter and applies certain fixes to it, depending on the mode of this + QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QPen &pen) +{ + QPainter::setPen(pen); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QColor &color) +{ + QPainter::setPen(color); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(Qt::PenStyle penStyle) +{ + QPainter::setPen(penStyle); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when + antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to + integer coordinates and then passes it to the original drawLine. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::drawLine(const QLineF &line) +{ + if (mIsAntialiasing || mModes.testFlag(pmVectorized)) + QPainter::drawLine(line); + else + QPainter::drawLine(line.toLine()); +} + +/*! + Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint + with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between + antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for + AA/Non-AA painting). +*/ +void QCPPainter::setAntialiasing(bool enabled) +{ + setRenderHint(QPainter::Antialiasing, enabled); + if (mIsAntialiasing != enabled) + { + mIsAntialiasing = enabled; + if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs + { + if (mIsAntialiasing) + translate(0.5, 0.5); + else + translate(-0.5, -0.5); + } + } +} + +/*! + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setModes(QCPPainter::PainterModes modes) +{ + mModes = modes; +} + +/*! + Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a + device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, + all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that + behaviour. + + The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets + the render hint as appropriate. + + \note this function hides the non-virtual base class implementation. +*/ +bool QCPPainter::begin(QPaintDevice *device) +{ + bool result = QPainter::begin(device); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (result) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif + return result; +} + +/*! \overload + + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) +{ + if (!enabled && mModes.testFlag(mode)) + mModes &= ~mode; + else if (enabled && !mModes.testFlag(mode)) + mModes |= mode; +} + +/*! + Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see restore +*/ +void QCPPainter::save() +{ + mAntialiasingStack.push(mIsAntialiasing); + QPainter::save(); +} + +/*! + Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see save +*/ +void QCPPainter::restore() +{ + if (!mAntialiasingStack.isEmpty()) + mIsAntialiasing = mAntialiasingStack.pop(); + else + qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; + QPainter::restore(); +} + +/*! + Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen + overrides when the \ref pmNonCosmetic mode is set. +*/ +void QCPPainter::makeNonCosmetic() +{ + if (qFuzzyIsNull(pen().widthF())) + { + QPen p = pen(); + p.setWidth(1); + QPainter::setPen(p); + } +} +/* end of 'src/painter.cpp' */ + + +/* including file 'src/paintbuffer.cpp', size 18502 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPaintBuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPaintBuffer + \brief The abstract base class for paint buffers, which define the rendering backend + + This abstract base class defines the basic interface that a paint buffer needs to provide in + order to be usable by QCustomPlot. + + A paint buffer manages both a surface to draw onto, and the matching paint device. The size of + the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref + QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the + painting is complete, \ref donePainting is called, so the paint buffer implementation can do + clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color + using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the + previous frame. + + The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular + software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and + frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. + They are used automatically if \ref QCustomPlot::setOpenGl is enabled. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 + + Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the + responsibility to delete the painter after the painting operations are complete is given to the + caller of this method. + + Once you are done using the painter, delete the painter and call \ref donePainting. + + While a painter generated with this method is active, you must not call \ref setSize, \ref + setDevicePixelRatio or \ref clear. + + This method may return 0, if a painter couldn't be activated on the buffer. This usually + indicates a problem with the respective painting backend. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 + + Draws the contents of this buffer with the provided \a painter. This is the method that is used + to finally join all paint buffers and draw them onto the screen. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 + + Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the + named color \c Qt::transparent. + + This method must not be called if there is currently a painter (acquired with \ref startPainting) + active. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 + + Reallocates the internal buffer with the currently configured size (\ref setSize) and device + pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those + properties are changed on this paint buffer. + + \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method + in their constructor, to perform the first allocation (this can not be done by the base class + because calling pure virtual methods in base class constructors is not possible). +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of inline functions */ + +/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() + + If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, + call this method as soon as you are done with the painting operations and have deleted the + painter. + + paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The + default implementation does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. + + Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. +*/ +QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : + mSize(size), + mDevicePixelRatio(devicePixelRatio), + mInvalidated(true) +{ +} + +QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() +{ +} + +/*! + Sets the paint buffer size. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + If \a size is already the current buffer size, this method does nothing. +*/ +void QCPAbstractPaintBuffer::setSize(const QSize &size) +{ + if (mSize != size) + { + mSize = size; + reallocateBuffer(); + } +} + +/*! + Sets the invalidated flag to \a invalidated. + + This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer + instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered + layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, + QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also + replots them, instead of only the layer on which the replot was called. + + The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers + were added or removed from this buffer, or if they were reordered. It is set to false as soon as + all associated \ref QCPLayer instances are drawn onto the buffer. + + Under normal circumstances, it is not necessary to manually call this method. +*/ +void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) +{ + mInvalidated = invalidated; +} + +/*! + Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. + The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + \note This method is only available for Qt versions 5.4 and higher. +*/ +void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mDevicePixelRatio = ratio; + reallocateBuffer(); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; +#endif + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferPixmap + \brief A paint buffer based on QPixmap, using software raster rendering + + This paint buffer is the default and fall-back paint buffer which uses software rendering and + QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. +*/ + +/*! + Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if + applicable. +*/ +QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : + QCPAbstractPaintBuffer(size, devicePixelRatio) +{ + QCPPaintBufferPixmap::reallocateBuffer(); +} + +QCPPaintBufferPixmap::~QCPPaintBufferPixmap() +{ +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferPixmap::startPainting() +{ + QCPPainter *result = new QCPPainter(&mBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::draw(QCPPainter *painter) const +{ + if (painter && painter->isActive()) + painter->drawPixmap(0, 0, mBuffer); + else + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::clear(const QColor &color) +{ + mBuffer.fill(color); +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::reallocateBuffer() +{ + setInvalidated(); + if (!qFuzzyCompare(1.0, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBuffer = QPixmap(mSize*mDevicePixelRatio); + mBuffer.setDevicePixelRatio(mDevicePixelRatio); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; + mBuffer = QPixmap(mSize); +#endif + } else + { + mBuffer = QPixmap(mSize); + } +} + + +#ifdef QCP_OPENGL_PBUFFER +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlPbuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlPbuffer + \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. + (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a + devicePixelRatio, if applicable. + + The parameter \a multisamples defines how many samples are used per pixel. Higher values thus + result in higher quality antialiasing. If the specified \a multisamples value exceeds the + capability of the graphics hardware, the highest supported multisampling is used. +*/ +QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlPBuffer(0), + mMultisamples(qMax(0, multisamples)) +{ + QCPPaintBufferGlPbuffer::reallocateBuffer(); +} + +QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlPbuffer::startPainting() +{ + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + QCPPainter *result = new QCPPainter(mGlPBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlPBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::clear(const QColor &color) +{ + if (mGlPBuffer->isValid()) + { + mGlPBuffer->makeCurrent(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlPBuffer->doneCurrent(); + } else + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::reallocateBuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; + + QGLFormat format; + format.setAlpha(true); + format.setSamples(mMultisamples); + mGlPBuffer = new QGLPixelBuffer(mSize, format); +} +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlFbo +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlFbo + \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and + higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, + if applicable. + + All frame buffer objects shall share one OpenGL context and paint device, which need to be set up + externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref + QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot + instance. +*/ +QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlContext(glContext), + mGlPaintDevice(glPaintDevice), + mGlFrameBuffer(0) +{ + QCPPaintBufferGlFbo::reallocateBuffer(); +} + +QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() +{ + if (mGlFrameBuffer) + delete mGlFrameBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlFbo::startPainting() +{ + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return 0; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::donePainting() +{ + if (mGlFrameBuffer && mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + else + qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlFrameBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::clear(const QColor &color) +{ + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlFrameBuffer->release(); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::reallocateBuffer() +{ + // release and delete possibly existing framebuffer: + if (mGlFrameBuffer) + { + if (mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + delete mGlFrameBuffer; + mGlFrameBuffer = 0; + } + + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return; + } + + // create new fbo with appropriate size: + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + QOpenGLFramebufferObjectFormat frameBufferFormat; + frameBufferFormat.setSamples(mGlContext.data()->format().samples()); + frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); + if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) + mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); +#endif +} +#endif // QCP_OPENGL_FBO +/* end of 'src/paintbuffer.cpp' */ + + +/* including file 'src/layer.cpp', size 37064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayer + \brief A layer that may contain objects, to control the rendering order + + The Layering system of QCustomPlot is the mechanism to control the rendering order of the + elements inside the plot. + + It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of + one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, + QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers + bottom to top and successively draws the layerables of the layers into the paint buffer(s). + + A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base + class from which almost all visible objects derive, like axes, grids, graphs, items, etc. + + \section qcplayer-defaultlayers Default layers + + Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and + "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's + selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain + the default axes and legend, so they will be drawn above plottables. In the middle, there is the + "main" layer. It is initially empty and set as the current layer (see + QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this + layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong + tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind + everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of + course, the layer affiliation of the individual objects can be changed as required (\ref + QCPLayerable::setLayer). + + \section qcplayer-ordering Controlling the rendering order via layers + + Controlling the ordering of layerables in the plot is easy: Create a new layer in the position + you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the + current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the + objects normally. They will be placed on the new layer automatically, due to the current layer + setting. Alternatively you could have also ignored the current layer setting and just moved the + objects with \ref QCPLayerable::setLayer to the desired layer after creating them. + + It is also possible to move whole layers. For example, If you want the grid to be shown in front + of all plottables/items on the "main" layer, just move it above "main" with + QCustomPlot::moveLayer. + + The rendering order within one layer is simply by order of creation or insertion. The item + created last (or added last to the layer), is drawn on top of all other objects on that layer. + + When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below + the deleted layer, see QCustomPlot::removeLayer. + + \section qcplayer-buffering Replotting only a specific layer + + If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific + layer by calling \ref replot. In certain situations this can provide better replot performance, + compared with a full replot of all layers. Upon creation of a new layer, the layer mode is + initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref + QCustomPlot instance is the "overlay" layer, containing the selection rect. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPLayer::children() const + + Returns a list of all layerables on this layer. The order corresponds to the rendering order: + layerables with higher indices are drawn above layerables with lower indices. +*/ + +/*! \fn int QCPLayer::index() const + + Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be + accessed via \ref QCustomPlot::layer. + + Layers with higher indices will be drawn above layers with lower indices. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPLayer instance. + + Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. + + \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. + This check is only performed by \ref QCustomPlot::addLayer. +*/ +QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : + QObject(parentPlot), + mParentPlot(parentPlot), + mName(layerName), + mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function + mVisible(true), + mMode(lmLogical) +{ + // Note: no need to make sure layerName is unique, because layer + // management is done with QCustomPlot functions. +} + +QCPLayer::~QCPLayer() +{ + // If child layerables are still on this layer, detach them, so they don't try to reach back to this + // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted + // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to + // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) + + while (!mChildren.isEmpty()) + mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() + + if (mParentPlot->currentLayer() == this) + qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; +} + +/*! + Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this + layer will be invisible. + + This function doesn't change the visibility property of the layerables (\ref + QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the + visibility of the parent layer into account. +*/ +void QCPLayer::setVisible(bool visible) +{ + mVisible = visible; +} + +/*! + Sets the rendering mode of this layer. + + If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by + the parent QCustomPlot instance. This means it may be replotted individually by calling \ref + QCPLayer::replot, without needing to replot all other layers. + + Layers which are set to \ref lmLogical (the default) are used only to define the rendering order + and can't be replotted individually. + + Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the + layers below, above and for the layer itself. This increases the memory consumption and + (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So + you should carefully choose which layers benefit from having their own paint buffer. A typical + example would be a layer which contains certain layerables (e.g. items) that need to be changed + and thus replotted regularly, while all other layerables on other layers stay static. By default, + only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection + rect. + + \see replot +*/ +void QCPLayer::setMode(QCPLayer::LayerMode mode) +{ + if (mMode != mode) + { + mMode = mode; + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } +} + +/*! \internal + + Draws the contents of this layer with the provided \a painter. + + \see replot, drawToPaintBuffer +*/ +void QCPLayer::draw(QCPPainter *painter) +{ + foreach (QCPLayerable *child, mChildren) + { + if (child->realVisibility()) + { + painter->save(); + painter->setClipRect(child->clipRect().translated(0, -1)); + child->applyDefaultAntialiasingHint(painter); + child->draw(painter); + painter->restore(); + } + } +} + +/*! \internal + + Draws the contents of this layer into the paint buffer which is associated with this layer. The + association is established by the parent QCustomPlot, which manages all paint buffers (see \ref + QCustomPlot::setupPaintBuffers). + + \see draw +*/ +void QCPLayer::drawToPaintBuffer() +{ + if (!mPaintBuffer.isNull()) + { + if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) + { + if (painter->isActive()) + draw(painter); + else + qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; + delete painter; + mPaintBuffer.data()->donePainting(); + } else + qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; +} + +/*! + If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only + the layerables on this specific layer, without the need to replot all other layers (as a call to + \ref QCustomPlot::replot would do). + + If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on + the parent QCustomPlot instance. + + QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering + has changed since the last full replot and the other paint buffers were thus invalidated. + + \see draw +*/ +void QCPLayer::replot() +{ + if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) + { + if (!mPaintBuffer.isNull()) + { + mPaintBuffer.data()->clear(Qt::transparent); + drawToPaintBuffer(); + mPaintBuffer.data()->setInvalidated(false); + mParentPlot->update(); + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; + } else if (mMode == lmLogical) + mParentPlot->replot(); +} + +/*! \internal + + Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will + be prepended to the list, i.e. be drawn beneath the other layerables already in the list. + + This function does not change the \a mLayer member of \a layerable to this layer. (Use + QCPLayerable::setLayer to change the layer of an object, not this function.) + + \see removeChild +*/ +void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) +{ + if (!mChildren.contains(layerable)) + { + if (prepend) + mChildren.prepend(layerable); + else + mChildren.append(layerable); + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); +} + +/*! \internal + + Removes the \a layerable from the list of this layer. + + This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer + to change the layer of an object, not this function.) + + \see addChild +*/ +void QCPLayer::removeChild(QCPLayerable *layerable) +{ + if (mChildren.removeOne(layerable)) + { + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayerable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayerable + \brief Base class for all drawable objects + + This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid + etc. + + Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking + the layers accordingly. + + For details about the layering mechanism, see the QCPLayer documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const + + Returns the parent layerable of this layerable. The parent layerable is used to provide + visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables + only get drawn if their parent layerables are visible, too. + + Note that a parent layerable is not necessarily also the QObject parent for memory management. + Further, a layerable doesn't always have a parent layerable, so this function may return 0. + + A parent layerable is set implicitly when placed inside layout elements and doesn't need to be + set manually by the user. +*/ + +/* end documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 + \internal + + This function applies the default antialiasing setting to the specified \a painter, using the + function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when + \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing + setting may be specified individually, this function should set the antialiasing state of the + most prominent entity. In this case however, the \ref draw function usually calls the specialized + versions of this function before drawing each entity, effectively overriding the setting of the + default antialiasing hint. + + First example: QCPGraph has multiple entities that have an antialiasing setting: The graph + line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, + QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only + the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's + antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and + QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw + calls the respective specialized applyAntialiasingHint function. + + Second example: QCPItemLine consists only of a line so there is only one antialiasing + setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by + all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the + respective layerable subclass.) Consequently it only has the normal + QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to + care about setting any antialiasing states, because the default antialiasing hint is already set + on the painter when the \ref draw function is called, and that's the state it wants to draw the + line with. +*/ + +/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 + \internal + + This function draws the layerable with the specified \a painter. It is only called by + QCustomPlot, if the layerable is visible (\ref setVisible). + + Before this function is called, the painter's antialiasing state is set via \ref + applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was + set to \ref clipRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); + + This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to + a different layer. + + \see setLayer +*/ + +/* end documentation of signals */ + +/*! + Creates a new QCPLayerable instance. + + Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the + derived classes. + + If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a + targetLayer is an empty string, it places itself on the current layer of the plot (see \ref + QCustomPlot::setCurrentLayer). + + It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later + time with \ref initializeParentPlot. + + The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable + parents are mainly used to control visibility in a hierarchy of layerables. This means a + layerable is only drawn, if all its ancestor layerables are also visible. Note that \a + parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a + plot does. It is not uncommon to set the QObject-parent to something else in the constructors of + QCPLayerable subclasses, to guarantee a working destruction hierarchy. +*/ +QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : + QObject(plot), + mVisible(true), + mParentPlot(plot), + mParentLayerable(parentLayerable), + mLayer(0), + mAntialiased(true) +{ + if (mParentPlot) + { + if (targetLayer.isEmpty()) + setLayer(mParentPlot->currentLayer()); + else if (!setLayer(targetLayer)) + qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; + } +} + +QCPLayerable::~QCPLayerable() +{ + if (mLayer) + { + mLayer->removeChild(this); + mLayer = 0; + } +} + +/*! + Sets the visibility of this layerable object. If an object is not visible, it will not be drawn + on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not + possible. +*/ +void QCPLayerable::setVisible(bool on) +{ + mVisible = on; +} + +/*! + Sets the \a layer of this layerable object. The object will be placed on top of the other objects + already on \a layer. + + If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or + interact/receive events). + + Returns true if the layer of this layerable was successfully changed to \a layer. +*/ +bool QCPLayerable::setLayer(QCPLayer *layer) +{ + return moveToLayer(layer, false); +} + +/*! \overload + Sets the layer of this layerable object by name + + Returns true on success, i.e. if \a layerName is a valid layer name. +*/ +bool QCPLayerable::setLayer(const QString &layerName) +{ + if (!mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (QCPLayer *layer = mParentPlot->layer(layerName)) + { + return setLayer(layer); + } else + { + qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; + return false; + } +} + +/*! + Sets whether this object will be drawn antialiased or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPLayerable::setAntialiased(bool enabled) +{ + mAntialiased = enabled; +} + +/*! + Returns whether this layerable is visible, taking the visibility of the layerable parent and the + visibility of this layerable's layer into account. This is the method that is consulted to decide + whether a layerable shall be drawn or not. + + If this layerable has a direct layerable parent (usually set via hierarchies implemented in + subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this + layerable has its visibility set to true and the parent layerable's \ref realVisibility returns + true. +*/ +bool QCPLayerable::realVisibility() const +{ + return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); +} + +/*! + This function is used to decide whether a click hits a layerable object or not. + + \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the + shortest pixel distance of this point to the object. If the object is either invisible or the + distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the + object is not selectable, -1.0 is returned, too. + + If the object is represented not by single lines but by an area like a \ref QCPItemText or the + bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In + these cases this function thus returns a constant value greater zero but still below the parent + plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). + + Providing a constant value for area objects allows selecting line objects even when they are + obscured by such area objects, by clicking close to the lines (i.e. closer than + 0.99*selectionTolerance). + + The actual setting of the selection state is not done by this function. This is handled by the + parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified + via the \ref selectEvent/\ref deselectEvent methods. + + \a details is an optional output parameter. Every layerable subclass may place any information + in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot + decides on the basis of this selectTest call, that the object was successfully selected. The + subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part + objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked + is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be + placed in \a details. So in the subsequent \ref selectEvent, the decision which part was + selected doesn't have to be done a second time for a single selection operation. + + You may pass 0 as \a details to indicate that you are not interested in those selection details. + + \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions +*/ +double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(pos) + Q_UNUSED(onlySelectable) + Q_UNUSED(details) + return -1.0; +} + +/*! \internal + + Sets the parent plot of this layerable. Use this function once to set the parent plot if you have + passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to + another one. + + Note that, unlike when passing a non-null parent plot in the constructor, this function does not + make \a parentPlot the QObject-parent of this layerable. If you want this, call + QObject::setParent(\a parentPlot) in addition to this function. + + Further, you will probably want to set a layer (\ref setLayer) after calling this function, to + make the layerable appear on the QCustomPlot. + + The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized + so they can react accordingly (e.g. also initialize the parent plot of child layerables, like + QCPLayout does). +*/ +void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) +{ + if (mParentPlot) + { + qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; + return; + } + + if (!parentPlot) + qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; + + mParentPlot = parentPlot; + parentPlotInitialized(mParentPlot); +} + +/*! \internal + + Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not + become the QObject-parent (for memory management) of this layerable. + + The parent layerable has influence on the return value of the \ref realVisibility method. Only + layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be + drawn. + + \see realVisibility +*/ +void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) +{ + mParentLayerable = parentLayerable; +} + +/*! \internal + + Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to + the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is + false, the object will be appended. + + Returns true on success, i.e. if \a layer is a valid layer. +*/ +bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) +{ + if (layer && !mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (layer && layer->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; + return false; + } + + QCPLayer *oldLayer = mLayer; + if (mLayer) + mLayer->removeChild(this); + mLayer = layer; + if (mLayer) + mLayer->addChild(this, prepend); + if (mLayer != oldLayer) + emit layerChanged(mLayer); + return true; +} + +/*! \internal + + Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a + localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is + controlled via \a overrideElement. +*/ +void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const +{ + if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(false); + else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(true); + else + painter->setAntialiasing(localAntialiased); +} + +/*! \internal + + This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting + of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the + parent plot is set at a later time. + + For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any + QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level + element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To + propagate the parent plot to all the children of the hierarchy, the top level element then uses + this function to pass the parent plot on to its child elements. + + The default implementation does nothing. + + \see initializeParentPlot +*/ +void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_UNUSED(parentPlot) +} + +/*! \internal + + Returns the selection category this layerable shall belong to. The selection category is used in + conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and + which aren't. + + Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref + QCP::iSelectOther. This is what the default implementation returns. + + \see QCustomPlot::setInteractions +*/ +QCP::Interaction QCPLayerable::selectionCategory() const +{ + return QCP::iSelectOther; +} + +/*! \internal + + Returns the clipping rectangle of this layerable object. By default, this is the viewport of the + parent QCustomPlot. Specific subclasses may reimplement this function to provide different + clipping rects. + + The returned clipping rect is set on the painter before the draw function of the respective + object is called. +*/ +QRect QCPLayerable::clipRect() const +{ + if (mParentPlot) + return mParentPlot->viewport(); + else + return QRect(); +} + +/*! \internal + + This event is called when the layerable shall be selected, as a consequence of a click by the + user. Subclasses should react to it by setting their selection state appropriately. The default + implementation does nothing. + + \a event is the mouse event that caused the selection. \a additive indicates, whether the user + was holding the multi-select-modifier while performing the selection (see \ref + QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled + (i.e. become selected when unselected and unselected when selected). + + Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. + returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). + The \a details data you output from \ref selectTest is fed back via \a details here. You may + use it to transport any kind of information from the selectTest to the possibly subsequent + selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable + that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need + to do the calculation again to find out which part was actually clicked. + + \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must + set the value either to true or false, depending on whether the selection state of this layerable + was actually changed. For layerables that only are selectable as a whole and not in parts, this + is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the + selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the + layerable was previously unselected and now is switched to the selected state. + + \see selectTest, deselectEvent +*/ +void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(additive) + Q_UNUSED(details) + Q_UNUSED(selectionStateChanged) +} + +/*! \internal + + This event is called when the layerable shall be deselected, either as consequence of a user + interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by + unsetting their selection appropriately. + + just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must + return true or false when the selection state of this layerable has changed or not changed, + respectively. + + \see selectTest, selectEvent +*/ +void QCPLayerable::deselectEvent(bool *selectionStateChanged) +{ + Q_UNUSED(selectionStateChanged) +} + +/*! + This event gets called when the user presses a mouse button while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + QCustomPlot uses an event propagation system that works the same as Qt's system. If your + layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in + its reimplementation, the event will be propagated to the next layerable in the stacking order. + + Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and + will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse + interaction (a "mouse interaction" in this context ends with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user moves the mouse while holding a mouse button, after this + layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user releases the mouse button, after this layerable has become + the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user presses the mouse button a second time in a double-click, + while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a + preceding call to \ref selectTest. + + The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the + case of a double-click, the event succession is + pressEvent – releaseEvent – doubleClickEvent – releaseEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, + it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent + and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends + with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent +*/ +void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user turns the mouse scroll wheel while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). + + The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for + single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may + accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has + very smooth steps or none at all, the delta may be smaller. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent +*/ +void QCPLayerable::wheelEvent(QWheelEvent *event) +{ + event->ignore(); +} +/* end of 'src/layer.cpp' */ + + +/* including file 'src/axis/range.cpp', size 12221 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPRange +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPRange + \brief Represents the range an axis is encompassing. + + contains a \a lower and \a upper double value and provides convenience input, output and + modification functions. + + \see QCPAxis::setRange +*/ + +/* start of documentation of inline functions */ + +/*! \fn double QCPRange::size() const + + Returns the size of the range, i.e. \a upper-\a lower +*/ + +/*! \fn double QCPRange::center() const + + Returns the center of the range, i.e. (\a upper+\a lower)*0.5 +*/ + +/*! \fn void QCPRange::normalize() + + Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are + swapped. +*/ + +/*! \fn bool QCPRange::contains(double value) const + + Returns true when \a value lies within or exactly on the borders of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator+=(const double& value) + + Adds \a value to both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator-=(const double& value) + + Subtracts \a value from both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator*=(const double& value) + + Multiplies both boundaries of the range by \a value. +*/ + +/*! \fn QCPRange &QCPRange::operator/=(const double& value) + + Divides both boundaries of the range by \a value. +*/ + +/* end of documentation of inline functions */ + +/*! + Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller + intervals would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a minimum magnitude of roughly 1e-308. + + \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining underflowing ranges. + + \see validRange, maxRange +*/ +const double QCPRange::minRange = 1e-280; + +/*! + Maximum values (negative and positive) the range will accept in range-changing functions. + Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a maximum magnitude of roughly 1e308. + + \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining overflowing ranges. + + \see validRange, minRange +*/ +const double QCPRange::maxRange = 1e250; + +/*! + Constructs a range with \a lower and \a upper set to zero. +*/ +QCPRange::QCPRange() : + lower(0), + upper(0) +{ +} + +/*! \overload + + Constructs a range with the specified \a lower and \a upper values. + + The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically + smaller than \a upper, they will be swapped. +*/ +QCPRange::QCPRange(double lower, double upper) : + lower(lower), + upper(upper) +{ + normalize(); +} + +/*! \overload + + Expands this range such that \a otherRange is contained in the new range. It is assumed that both + this range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, it will be replaced by the respective bound + of \a otherRange. + + If \a otherRange is already inside the current range, this function does nothing. + + \see expanded +*/ +void QCPRange::expand(const QCPRange &otherRange) +{ + if (lower > otherRange.lower || qIsNaN(lower)) + lower = otherRange.lower; + if (upper < otherRange.upper || qIsNaN(upper)) + upper = otherRange.upper; +} + +/*! \overload + + Expands this range such that \a includeCoord is contained in the new range. It is assumed that + this range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the respective bound will be set to \a + includeCoord. + + If \a includeCoord is already inside the current range, this function does nothing. + + \see expand +*/ +void QCPRange::expand(double includeCoord) +{ + if (lower > includeCoord || qIsNaN(lower)) + lower = includeCoord; + if (upper < includeCoord || qIsNaN(upper)) + upper = includeCoord; +} + + +/*! \overload + + Returns an expanded range that contains this and \a otherRange. It is assumed that both this + range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be taken from + \a otherRange. + + \see expand +*/ +QCPRange QCPRange::expanded(const QCPRange &otherRange) const +{ + QCPRange result = *this; + result.expand(otherRange); + return result; +} + +/*! \overload + + Returns an expanded range that includes the specified \a includeCoord. It is assumed that this + range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a + includeCoord. + + \see expand +*/ +QCPRange QCPRange::expanded(double includeCoord) const +{ + QCPRange result = *this; + result.expand(includeCoord); + return result; +} + +/*! + Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a + upperBound. If possible, the size of the current range is preserved in the process. + + If the range shall only be bounded at the lower side, you can set \a upperBound to \ref + QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref + QCPRange::maxRange. +*/ +QCPRange QCPRange::bounded(double lowerBound, double upperBound) const +{ + if (lowerBound > upperBound) + qSwap(lowerBound, upperBound); + + QCPRange result(lower, upper); + if (result.lower < lowerBound) + { + result.lower = lowerBound; + result.upper = lowerBound + size(); + if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.upper = upperBound; + } else if (result.upper > upperBound) + { + result.upper = upperBound; + result.lower = upperBound - size(); + if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.lower = lowerBound; + } + + return result; +} + +/*! + Returns a sanitized version of the range. Sanitized means for logarithmic scales, that + the range won't span the positive and negative sign domain, i.e. contain zero. Further + \a lower will always be numerically smaller (or equal) to \a upper. + + If the original range does span positive and negative sign domains or contains zero, + the returned range will try to approximate the original range as good as possible. + If the positive interval of the original range is wider than the negative interval, the + returned range will only contain the positive interval, with lower bound set to \a rangeFac or + \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval + is wider than the positive interval, this time by changing the \a upper bound. +*/ +QCPRange QCPRange::sanitizedForLogScale() const +{ + double rangeFac = 1e-3; + QCPRange sanitizedRange(lower, upper); + sanitizedRange.normalize(); + // can't have range spanning negative and positive values in log plot, so change range to fix it + //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) + if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) + { + // case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) + else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) + { + // case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) + { + // find out whether negative or positive interval is wider to decide which sign domain will be chosen + if (-sanitizedRange.lower > sanitizedRange.upper) + { + // negative is wider, do same as in case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else + { + // positive is wider, do same as in case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } + } + // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && + upper < maxRange && + qAbs(lower-upper) > minRange && + qAbs(lower-upper) < maxRange && + !(lower > 0 && qIsInf(upper/lower)) && + !(upper < 0 && qIsInf(lower/upper))); +} + +/*! + \overload + Checks, whether the specified range is within valid bounds, which are defined + as QCPRange::maxRange and QCPRange::minRange. + A valid range means: + \li range bounds within -maxRange and maxRange + \li range size above minRange + \li range size below maxRange +*/ +bool QCPRange::validRange(const QCPRange &range) +{ + return (range.lower > -maxRange && + range.upper < maxRange && + qAbs(range.lower-range.upper) > minRange && + qAbs(range.lower-range.upper) < maxRange && + !(range.lower > 0 && qIsInf(range.upper/range.lower)) && + !(range.upper < 0 && qIsInf(range.lower/range.upper))); +} +/* end of 'src/axis/range.cpp' */ + + +/* including file 'src/selection.cpp', size 21906 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataRange +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataRange + \brief Describes a data range given by begin and end index + + QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index + of a contiguous set of data points. The end index points to the data point above the last data point that's part of + the data range, similarly to the nomenclature used in standard iterators. + + Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and + modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is + used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref + QCPDataSelection is thus used. + + Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, + e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref + contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be + used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding + \ref QCPDataSelection. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and + QCPDataRange. + + \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval + in floating point plot coordinates, e.g. the current axis range. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataRange::size() const + + Returns the number of data points described by this data range. This is equal to the end index + minus the begin index. + + \see length +*/ + +/*! \fn int QCPDataRange::length() const + + Returns the number of data points described by this data range. Equivalent to \ref size. +*/ + +/*! \fn void QCPDataRange::setBegin(int begin) + + Sets the begin of this data range. The \a begin index points to the first data point that is part + of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setEnd +*/ + +/*! \fn void QCPDataRange::setEnd(int end) + + Sets the end of this data range. The \a end index points to the data point just above the last + data point that is part of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setBegin +*/ + +/*! \fn bool QCPDataRange::isValid() const + + Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and + an end index greater or equal to the begin index. + + \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods + (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's + methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary + invalid begin/end values while manipulating the range. An invalid range is not necessarily empty + (\ref isEmpty), since its \ref length can be negative and thus non-zero. +*/ + +/*! \fn bool QCPDataRange::isEmpty() const + + Returns whether this range is empty, i.e. whether its begin index equals its end index. + + \see size, length +*/ + +/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const + + Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end + indices, respectively. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataRange, with begin and end set to 0. +*/ +QCPDataRange::QCPDataRange() : + mBegin(0), + mEnd(0) +{ +} + +/*! + Creates a QCPDataRange, initialized with the specified \a begin and \a end. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). +*/ +QCPDataRange::QCPDataRange(int begin, int end) : + mBegin(begin), + mEnd(end) +{ +} + +/*! + Returns a data range that matches this data range, except that parts exceeding \a other are + excluded. + + This method is very similar to \ref intersection, with one distinction: If this range and the \a + other range share no intersection, the returned data range will be empty with begin and end set + to the respective boundary side of \a other, at which this range is residing. (\ref intersection + would just return a range with begin and end set to 0.) +*/ +QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const +{ + QCPDataRange result(intersection(other)); + if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value + { + if (mEnd <= other.mBegin) + result = QCPDataRange(other.mBegin, other.mBegin); + else + result = QCPDataRange(other.mEnd, other.mEnd); + } + return result; +} + +/*! + Returns a data range that contains both this data range as well as \a other. +*/ +QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const +{ + return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); +} + +/*! + Returns the data range which is contained in both this data range and \a other. + + This method is very similar to \ref bounded, with one distinction: If this range and the \a other + range share no intersection, the returned data range will be empty with begin and end set to 0. + (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, + depending on which side this range is on.) + + \see QCPDataSelection::intersection +*/ +QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const +{ + QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); + if (result.isValid()) + return result; + else + return QCPDataRange(); +} + +/*! + Returns whether this data range and \a other share common data points. + + \see intersection, contains +*/ +bool QCPDataRange::intersects(const QCPDataRange &other) const +{ + return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || + (mEnd <= other.mBegin && mEnd < other.mEnd) ); +} + +/*! + Returns whether all data points described by this data range are also in \a other. + + \see intersects +*/ +bool QCPDataRange::contains(const QCPDataRange &other) const +{ + return mBegin <= other.mBegin && mEnd >= other.mEnd; +} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataSelection +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataSelection + \brief Describes a data set by holding multiple QCPDataRange instances + + QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly + disjoint) set of data selection. + + The data selection can be modified with addition and subtraction operators which take + QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and + \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. + + The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange + instances. QCPDataSelection automatically simplifies when using the addition/subtraction + operators. The only case when \ref simplify is left to the user, is when calling \ref + addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data + ranges will be added to the selection successively and the overhead for simplifying after each + iteration shall be avoided. In this case, you should make sure to call \ref simplify after + completing the operation. + + Use \ref enforceType to bring the data selection into a state complying with the constraints for + selections defined in \ref QCP::SelectionType. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and + QCPDataRange. + + \section qcpdataselection-iterating Iterating over a data selection + + As an example, the following code snippet calculates the average value of a graph's data + \ref QCPAbstractPlottable::selection "selection": + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 + +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataSelection::dataRangeCount() const + + Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref + dataRange via their index. + + \see dataRange, dataPointCount +*/ + +/*! \fn QList QCPDataSelection::dataRanges() const + + Returns all data ranges that make up the data selection. If the data selection is simplified (the + usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point + index. + + \see dataRange +*/ + +/*! \fn bool QCPDataSelection::isEmpty() const + + Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection + instance. + + \see dataRangeCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataSelection. +*/ +QCPDataSelection::QCPDataSelection() +{ +} + +/*! + Creates a QCPDataSelection containing the provided \a range. +*/ +QCPDataSelection::QCPDataSelection(const QCPDataRange &range) +{ + mDataRanges.append(range); +} + +/*! + Returns true if this selection is identical (contains the same data ranges with the same begin + and end indices) to \a other. + + Note that both data selections must be in simplified state (the usual state of the selection, see + \ref simplify) for this operator to return correct results. +*/ +bool QCPDataSelection::operator==(const QCPDataSelection &other) const +{ + if (mDataRanges.size() != other.mDataRanges.size()) + return false; + for (int i=0; i= other.end()) + break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this + + if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored + { + if (thisBegin >= other.begin()) // range leading segment is encompassed + { + if (thisEnd <= other.end()) // range fully encompassed, remove completely + { + mDataRanges.removeAt(i); + continue; + } else // only leading segment is encompassed, trim accordingly + mDataRanges[i].setBegin(other.end()); + } else // leading segment is not encompassed + { + if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly + { + mDataRanges[i].setEnd(other.begin()); + } else // other lies inside this range, so split range + { + mDataRanges[i].setEnd(other.begin()); + mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); + break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here + } + } + } + ++i; + } + + return *this; +} + +/*! + Returns the total number of data points contained in all data ranges that make up this data + selection. +*/ +int QCPDataSelection::dataPointCount() const +{ + int result = 0; + for (int i=0; i= 0 && index < mDataRanges.size()) + { + return mDataRanges.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of range:" << index; + return QCPDataRange(); + } +} + +/*! + Returns a \ref QCPDataRange which spans the entire data selection, including possible + intermediate segments which are not part of the original data selection. +*/ +QCPDataRange QCPDataSelection::span() const +{ + if (isEmpty()) + return QCPDataRange(); + else + return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); +} + +/*! + Adds the given \a dataRange to this data selection. This is equivalent to the += operator but + allows disabling immediate simplification by setting \a simplify to false. This can improve + performance if adding a very large amount of data ranges successively. In this case, make sure to + call \ref simplify manually, after the operation. +*/ +void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) +{ + mDataRanges.append(dataRange); + if (simplify) + this->simplify(); +} + +/*! + Removes all data ranges. The data selection then contains no data points. + + \ref isEmpty +*/ +void QCPDataSelection::clear() +{ + mDataRanges.clear(); +} + +/*! + Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent + or overlapping ranges. This can reduce the number of individual data ranges in the selection, and + prevents possible double-counting when iterating over the data points held by the data ranges. + + This method is automatically called when using the addition/subtraction operators. The only case + when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a + simplify explicitly set to false. +*/ +void QCPDataSelection::simplify() +{ + // remove any empty ranges: + for (int i=mDataRanges.size()-1; i>=0; --i) + { + if (mDataRanges.at(i).isEmpty()) + mDataRanges.removeAt(i); + } + if (mDataRanges.isEmpty()) + return; + + // sort ranges by starting value, ascending: + std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); + + // join overlapping/contiguous ranges: + int i = 1; + while (i < mDataRanges.size()) + { + if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list + { + mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); + mDataRanges.removeAt(i); + } else + ++i; + } +} + +/*! + Makes sure this data selection conforms to the specified \a type selection type. Before the type + is enforced, \ref simplify is called. + + Depending on \a type, enforcing means adding new data points that were previously not part of the + selection, or removing data points from the selection. If the current selection already conforms + to \a type, the data selection is not changed. + + \see QCP::SelectionType +*/ +void QCPDataSelection::enforceType(QCP::SelectionType type) +{ + simplify(); + switch (type) + { + case QCP::stNone: + { + mDataRanges.clear(); + break; + } + case QCP::stWhole: + { + // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) + break; + } + case QCP::stSingleData: + { + // reduce all data ranges to the single first data point: + if (!mDataRanges.isEmpty()) + { + if (mDataRanges.size() > 1) + mDataRanges = QList() << mDataRanges.first(); + if (mDataRanges.first().length() > 1) + mDataRanges.first().setEnd(mDataRanges.first().begin()+1); + } + break; + } + case QCP::stDataRange: + { + mDataRanges = QList() << span(); + break; + } + case QCP::stMultipleDataRanges: + { + // this is the selection type that allows all concievable combinations of ranges, so do nothing + break; + } + } +} + +/*! + Returns true if the data selection \a other is contained entirely in this data selection, i.e. + all data point indices that are in \a other are also in this data selection. + + \see QCPDataRange::contains +*/ +bool QCPDataSelection::contains(const QCPDataSelection &other) const +{ + if (other.isEmpty()) return false; + + int otherIndex = 0; + int thisIndex = 0; + while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) + { + if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) + ++otherIndex; + else + ++thisIndex; + } + return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this +} + +/*! + Returns a data selection containing the points which are both in this data selection and in the + data range \a other. + + A common use case is to limit an unknown data selection to the valid range of a data container, + using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned + data selection without exceeding the data container's bounds. +*/ +QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const +{ + QCPDataSelection result; + for (int i=0; iorientation() == Qt::Horizontal) + return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); + else + return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); + } else + { + qDebug() << Q_FUNC_INFO << "called with axis zero"; + return QCPRange(); + } +} + +/*! + Sets the pen that will be used to draw the selection rect outline. + + \see setBrush +*/ +void QCPSelectionRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used to fill the selection rect. By default the selection rect is not + filled, i.e. \a brush is Qt::NoBrush. + + \see setPen +*/ +void QCPSelectionRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + If there is currently a selection interaction going on (\ref isActive), the interaction is + canceled. The selection rect will emit the \ref canceled signal. +*/ +void QCPSelectionRect::cancel() +{ + if (mActive) + { + mActive = false; + emit canceled(mRect, 0); + } +} + +/*! \internal + + This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. + The default implementation sets the selection rect to active, initializes the selection rect + geometry and emits the \ref started signal. +*/ +void QCPSelectionRect::startSelection(QMouseEvent *event) +{ + mActive = true; + mRect = QRect(event->pos(), event->pos()); + emit started(event); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs + to update its geometry. The default implementation updates the rect and emits the \ref changed + signal. +*/ +void QCPSelectionRect::moveSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + emit changed(mRect, event); + layer()->replot(); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has + finished by the user releasing the mouse button. The default implementation deactivates the + selection rect and emits the \ref accepted signal. +*/ +void QCPSelectionRect::endSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + mActive = false; + emit accepted(mRect, event); +} + +/*! \internal + + This method is called by QCustomPlot when a key has been pressed by the user while the selection + rect interaction is active. The default implementation allows to \ref cancel the interaction by + hitting the escape key. +*/ +void QCPSelectionRect::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape && mActive) + { + mActive = false; + emit canceled(mRect, event); + } +} + +/* inherits documentation from base class */ +void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/*! \internal + + If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. + + \seebaseclassmethod +*/ +void QCPSelectionRect::draw(QCPPainter *painter) +{ + if (mActive) + { + painter->setPen(mPen); + painter->setBrush(mBrush); + painter->drawRect(mRect); + } +} +/* end of 'src/selectionrect.cpp' */ + + +/* including file 'src/layout.cpp', size 79064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPMarginGroup +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPMarginGroup + \brief A margin group allows synchronization of margin sides if working with multiple layout elements. + + QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that + they will all have the same size, based on the largest required margin in the group. + + \n + \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" + \n + + In certain situations it is desirable that margins at specific sides are synchronized across + layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will + provide a cleaner look to the user if the left and right margins of the two axis rects are of the + same size. The left axis of the top axis rect will then be at the same horizontal position as the + left axis of the lower axis rect, making them appear aligned. The same applies for the right + axes. This is what QCPMarginGroup makes possible. + + To add/remove a specific side of a layout element to/from a margin group, use the \ref + QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call + \ref clear, or just delete the margin group. + + \section QCPMarginGroup-example Example + + First create a margin group: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 + Then set this group on the layout element sides: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 + Here, we've used the first two axis rects of the plot and synchronized their left margins with + each other and their right margins with each other. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const + + Returns a list of all layout elements that have their margin \a side associated with this margin + group. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPMarginGroup instance in \a parentPlot. +*/ +QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot) +{ + mChildren.insert(QCP::msLeft, QList()); + mChildren.insert(QCP::msRight, QList()); + mChildren.insert(QCP::msTop, QList()); + mChildren.insert(QCP::msBottom, QList()); +} + +QCPMarginGroup::~QCPMarginGroup() +{ + clear(); +} + +/*! + Returns whether this margin group is empty. If this function returns true, no layout elements use + this margin group to synchronize margin sides. +*/ +bool QCPMarginGroup::isEmpty() const +{ + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + if (!it.value().isEmpty()) + return false; + } + return true; +} + +/*! + Clears this margin group. The synchronization of the margin sides that use this margin group is + lifted and they will use their individual margin sizes again. +*/ +void QCPMarginGroup::clear() +{ + // make all children remove themselves from this margin group: + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + const QList elements = it.value(); + for (int i=elements.size()-1; i>=0; --i) + elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild + } +} + +/*! \internal + + Returns the synchronized common margin for \a side. This is the margin value that will be used by + the layout element on the respective side, if it is part of this margin group. + + The common margin is calculated by requesting the automatic margin (\ref + QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin + group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into + account, too.) +*/ +int QCPMarginGroup::commonMargin(QCP::MarginSide side) const +{ + // query all automatic margins of the layout elements in this margin group side and find maximum: + int result = 0; + const QList elements = mChildren.value(side); + for (int i=0; iautoMargins().testFlag(side)) + continue; + int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); + if (m > result) + result = m; + } + return result; +} + +/*! \internal + + Adds \a element to the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].contains(element)) + mChildren[side].append(element); + else + qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); +} + +/*! \internal + + Removes \a element from the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].removeOne(element)) + qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutElement + \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". + + This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. + + A Layout element is a rectangular object which can be placed in layouts. It has an outer rect + (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference + between outer and inner rect is called its margin. The margin can either be set to automatic or + manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be + set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, + the layout element subclass will control the value itself (via \ref calculateAutoMargin). + + Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level + layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref + QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. + + Thus in QCustomPlot one can divide layout elements into two categories: The ones that are + invisible by themselves, because they don't draw anything. Their only purpose is to manage the + position and size of other layout elements. This category of layout elements usually use + QCPLayout as base class. Then there is the category of layout elements which actually draw + something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does + not necessarily mean that the latter category can't have child layout elements. QCPLegend for + instance, actually derives from QCPLayoutGrid and the individual legend items are child layout + elements in the grid layout. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayout *QCPLayoutElement::layout() const + + Returns the parent layout of this layout element. +*/ + +/*! \fn QRect QCPLayoutElement::rect() const + + Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref + setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). + + In some cases, the area between outer and inner rect is left blank. In other cases the margin + area is used to display peripheral graphics while the main content is in the inner rect. This is + where automatic margin calculation becomes interesting because it allows the layout element to + adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect + draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if + \ref setAutoMargins is enabled) according to the space required by the labels of the axes. + + \see outerRect +*/ + +/*! \fn QRect QCPLayoutElement::outerRect() const + + Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the + margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref + setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. + + \see rect +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutElement and sets default values. +*/ +QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) + mParentLayout(0), + mMinimumSize(), + mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), + mSizeConstraintRect(scrInnerRect), + mRect(0, 0, 0, 0), + mOuterRect(0, 0, 0, 0), + mMargins(0, 0, 0, 0), + mMinimumMargins(0, 0, 0, 0), + mAutoMargins(QCP::msAll) +{ +} + +QCPLayoutElement::~QCPLayoutElement() +{ + setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any + // unregister at layout: + if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor + mParentLayout->take(this); +} + +/*! + Sets the outer rect of this layout element. If the layout element is inside a layout, the layout + sets the position and size of this layout element using this function. + + Calling this function externally has no effect, since the layout will overwrite any changes to + the outer rect upon the next replot. + + The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. + + \see rect +*/ +void QCPLayoutElement::setOuterRect(const QRect &rect) +{ + if (mOuterRect != rect) + { + mOuterRect = rect; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all + sides, this function is used to manually set the margin on those sides. Sides that are still set + to be handled automatically are ignored and may have any value in \a margins. + + The margin is the distance between the outer rect (controlled by the parent layout via \ref + setOuterRect) and the inner \ref rect (which usually contains the main content of this layout + element). + + \see setAutoMargins +*/ +void QCPLayoutElement::setMargins(const QMargins &margins) +{ + if (mMargins != margins) + { + mMargins = margins; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + If \ref setAutoMargins is enabled on some or all margins, this function is used to provide + minimum values for those margins. + + The minimum values are not enforced on margin sides that were set to be under manual control via + \ref setAutoMargins. + + \see setAutoMargins +*/ +void QCPLayoutElement::setMinimumMargins(const QMargins &margins) +{ + if (mMinimumMargins != margins) + { + mMinimumMargins = margins; + } +} + +/*! + Sets on which sides the margin shall be calculated automatically. If a side is calculated + automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is + set to be controlled manually, the value may be specified with \ref setMargins. + + Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref + setMarginGroup), to synchronize (align) it with other layout elements in the plot. + + \see setMinimumMargins, setMargins, QCP::MarginSide +*/ +void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) +{ + mAutoMargins = sides; +} + +/*! + Sets the minimum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + If the parent layout size is not sufficient to satisfy all minimum size constraints of its child + layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot + propagates the layout's size constraints to the outside by setting its own minimum QWidget size + accordingly, so violations of \a size should be exceptions. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(const QSize &size) +{ + if (mMinimumSize != size) + { + mMinimumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the minimum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(int width, int height) +{ + setMinimumSize(QSize(width, height)); +} + +/*! + Sets the maximum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(const QSize &size) +{ + if (mMaximumSize != size) + { + mMaximumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the maximum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(int width, int height) +{ + setMaximumSize(QSize(width, height)); +} + +/*! + Sets to which rect of a layout element the size constraints apply. Size constraints can be set + via \ref setMinimumSize and \ref setMaximumSize. + + The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis + labels), whereas the inner rect (\ref rect) does not. + + \see setMinimumSize, setMaximumSize +*/ +void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) +{ + if (mSizeConstraintRect != constraintRect) + { + mSizeConstraintRect = constraintRect; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! + Sets the margin \a group of the specified margin \a sides. + + Margin groups allow synchronizing specified margins across layout elements, see the documentation + of \ref QCPMarginGroup. + + To unset the margin group of \a sides, set \a group to 0. + + Note that margin groups only work for margin sides that are set to automatic (\ref + setAutoMargins). + + \see QCP::MarginSide +*/ +void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) +{ + QVector sideVector; + if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); + if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); + if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); + if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); + + for (int i=0; iremoveChild(side, this); + + if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there + { + mMarginGroups.remove(side); + } else // setting to a new group + { + mMarginGroups[side] = group; + group->addChild(side, this); + } + } + } +} + +/*! + Updates the layout element and sub-elements. This function is automatically called before every + replot by the parent layout element. It is called multiple times, once for every \ref + UpdatePhase. The phases are run through in the order of the enum values. For details about what + happens at the different phases, see the documentation of \ref UpdatePhase. + + Layout elements that have child elements should call the \ref update method of their child + elements, and pass the current \a phase unchanged. + + The default implementation executes the automatic margin mechanism in the \ref upMargins phase. + Subclasses should make sure to call the base class implementation. +*/ +void QCPLayoutElement::update(UpdatePhase phase) +{ + if (phase == upMargins) + { + if (mAutoMargins != QCP::msNone) + { + // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: + QMargins newMargins = mMargins; + QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; + foreach (QCP::MarginSide side, allMarginSides) + { + if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically + { + if (mMarginGroups.contains(side)) + QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group + else + QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly + // apply minimum margin restrictions: + if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) + QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); + } + } + setMargins(newMargins); + } + } +} + +/*! + Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, + if no manual minimum size is set. + + if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size + (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum + allowed size of this layout element. + + A manual minimum size is considered set if it is non-zero. + + The default implementation simply returns the sum of the horizontal margins for the width and the + sum of the vertical margins for the height. Reimplementations may use their detailed knowledge + about the layout element's content to provide size hints. +*/ +QSize QCPLayoutElement::minimumOuterSizeHint() const +{ + return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); +} + +/*! + Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, + if no manual maximum size is set. + + if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned + size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the + maximum allowed size of this layout element. + + A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. + + The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying + no suggested maximum size. Reimplementations may use their detailed knowledge about the layout + element's content to provide size hints. +*/ +QSize QCPLayoutElement::maximumOuterSizeHint() const +{ + return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +} + +/*! + Returns a list of all child elements in this layout element. If \a recursive is true, all + sub-child elements are included in the list, too. + + \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have + empty cells which yield 0 at the respective index.) +*/ +QList QCPLayoutElement::elements(bool recursive) const +{ + Q_UNUSED(recursive) + return QList(); +} + +/*! + Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer + rect, this method returns a value corresponding to 0.99 times the parent plot's selection + tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is + true, -1.0 is returned. + + See \ref QCPLayerable::selectTest for a general explanation of this virtual method. + + QCPLayoutElement subclasses may reimplement this method to provide more specific selection test + behaviour. +*/ +double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + + if (onlySelectable) + return -1; + + if (QRectF(mOuterRect).contains(pos)) + { + if (mParentPlot) + return mParentPlot->selectionTolerance()*0.99; + else + { + qDebug() << Q_FUNC_INFO << "parent plot not defined"; + return -1; + } + } else + return -1; +} + +/*! \internal + + propagates the parent plot initialization to all child elements, by calling \ref + QCPLayerable::initializeParentPlot on them. +*/ +void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) +{ + foreach (QCPLayoutElement* el, elements(false)) + { + if (!el->parentPlot()) + el->initializeParentPlot(parentPlot); + } +} + +/*! \internal + + Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a + side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the + returned value will not be smaller than the specified minimum margin. + + The default implementation just returns the respective manual margin (\ref setMargins) or the + minimum margin, whichever is larger. +*/ +int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) +{ + return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); +} + +/*! \internal + + This virtual method is called when this layout element was moved to a different QCPLayout, or + when this layout element has changed its logical position (e.g. row and/or column) within the + same QCPLayout. Subclasses may use this to react accordingly. + + Since this method is called after the completion of the move, you can access the new parent + layout via \ref layout(). + + The default implementation does nothing. +*/ +void QCPLayoutElement::layoutChanged() +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayout +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayout + \brief The abstract base class for layouts + + This is an abstract base class for layout elements whose main purpose is to define the position + and size of other child layout elements. In most cases, layouts don't draw anything themselves + (but there are exceptions to this, e.g. QCPLegend). + + QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. + + QCPLayout introduces a common interface for accessing and manipulating the child elements. Those + functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref + simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions + to this interface which are more specialized to the form of the layout. For example, \ref + QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid + more conveniently. + + Since this is an abstract base class, you can't instantiate it directly. Rather use one of its + subclasses like QCPLayoutGrid or QCPLayoutInset. + + For a general introduction to the layout system, see the dedicated documentation page \ref + thelayoutsystem "The Layout System". +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPLayout::elementCount() const = 0 + + Returns the number of elements/cells in the layout. + + \see elements, elementAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 + + Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. + + Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. + QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check + whether a cell is empty or not. + + \see elements, elementCount, takeAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 + + Removes the element with the given \a index from the layout and returns it. + + If the \a index is invalid or the cell with that index is empty, returns 0. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see elementAt, take +*/ + +/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 + + Removes the specified \a element from the layout and returns true on success. + + If the \a element isn't in this layout, returns false. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see takeAt +*/ + +/* end documentation of pure virtual functions */ + +/*! + Creates an instance of QCPLayout and sets default values. Note that since QCPLayout + is an abstract base class, it can't be instantiated directly. +*/ +QCPLayout::QCPLayout() +{ +} + +/*! + If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to + reposition and resize their cells. + + Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". + + For details about this method and the update phases, see the documentation of \ref + QCPLayoutElement::update. +*/ +void QCPLayout::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + // set child element rects according to layout: + if (phase == upLayout) + updateLayout(); + + // propagate update call to child elements: + const int elCount = elementCount(); + for (int i=0; iupdate(phase); + } +} + +/* inherits documentation from base class */ +QList QCPLayout::elements(bool recursive) const +{ + const int c = elementCount(); + QList result; +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(c); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the + default implementation does nothing. + + Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit + simplification while QCPLayoutGrid does. +*/ +void QCPLayout::simplify() +{ +} + +/*! + Removes and deletes the element at the provided \a index. Returns true on success. If \a index is + invalid or points to an empty cell, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the returned element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see remove, takeAt +*/ +bool QCPLayout::removeAt(int index) +{ + if (QCPLayoutElement *el = takeAt(index)) + { + delete el; + return true; + } else + return false; +} + +/*! + Removes and deletes the provided \a element. Returns true on success. If \a element is not in the + layout, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see removeAt, take +*/ +bool QCPLayout::remove(QCPLayoutElement *element) +{ + if (take(element)) + { + delete element; + return true; + } else + return false; +} + +/*! + Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure + all empty cells are collapsed. + + \see remove, removeAt +*/ +void QCPLayout::clear() +{ + for (int i=elementCount()-1; i>=0; --i) + { + if (elementAt(i)) + removeAt(i); + } + simplify(); +} + +/*! + Subclasses call this method to report changed (minimum/maximum) size constraints. + + If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref + sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of + QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, + it may update itself and resize cells accordingly. +*/ +void QCPLayout::sizeConstraintsChanged() const +{ + if (QWidget *w = qobject_cast(parent())) + w->updateGeometry(); + else if (QCPLayout *l = qobject_cast(parent())) + l->sizeConstraintsChanged(); +} + +/*! \internal + + Subclasses reimplement this method to update the position and sizes of the child elements/cells + via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. + + The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay + within that rect. + + \ref getSectionSizes may help with the reimplementation of this function. + + \see update +*/ +void QCPLayout::updateLayout() +{ +} + + +/*! \internal + + Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the + \ref QCPLayerable::parentLayerable and the QObject parent to this layout. + + Further, if \a el didn't previously have a parent plot, calls \ref + QCPLayerable::initializeParentPlot on \a el to set the paret plot. + + This method is used by subclass specific methods that add elements to the layout. Note that this + method only changes properties in \a el. The removal from the old layout and the insertion into + the new layout must be done additionally. +*/ +void QCPLayout::adoptElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = this; + el->setParentLayerable(this); + el->setParent(this); + if (!el->parentPlot()) + el->initializeParentPlot(mParentPlot); + el->layoutChanged(); + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout + and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent + QCustomPlot. + + This method is used by subclass specific methods that remove elements from the layout (e.g. \ref + take or \ref takeAt). Note that this method only changes properties in \a el. The removal from + the old layout must be done additionally. +*/ +void QCPLayout::releaseElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = 0; + el->setParentLayerable(0); + el->setParent(mParentPlot); + // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + This is a helper function for the implementation of \ref updateLayout in subclasses. + + It calculates the sizes of one-dimensional sections with provided constraints on maximum section + sizes, minimum section sizes, relative stretch factors and the final total size of all sections. + + The QVector entries refer to the sections. Thus all QVectors must have the same size. + + \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size + imposed, set all vector values to Qt's QWIDGETSIZE_MAX. + + \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size + imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than + \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, + not exceeding the allowed total size is taken to be more important than not going below minimum + section sizes.) + + \a stretchFactors give the relative proportions of the sections to each other. If all sections + shall be scaled equally, set all values equal. If the first section shall be double the size of + each individual other section, set the first number of \a stretchFactors to double the value of + the other individual values (e.g. {2, 1, 1, 1}). + + \a totalSize is the value that the final section sizes will add up to. Due to rounding, the + actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, + you could distribute the remaining difference on the sections. + + The return value is a QVector containing the section sizes. +*/ +QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const +{ + if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) + { + qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; + return QVector(); + } + if (stretchFactors.isEmpty()) + return QVector(); + int sectionCount = stretchFactors.size(); + QVector sectionSizes(sectionCount); + // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): + int minSizeSum = 0; + for (int i=0; i minimumLockedSections; + QList unfinishedSections; + for (int i=0; i result(sectionCount); + for (int i=0; iminimumOuterSizeHint(); + QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) + if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rwidth() += el->margins().left() + el->margins().right(); + if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; +} + +/*! \internal + + This is a helper function for the implementation of subclasses. + + It returns the maximum size that should finally be used for the outer rect of the passed layout + element \a el. + + It takes into account whether a manual maximum size is set (\ref + QCPLayoutElement::setMaximumSize), which size constraint is set (\ref + QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum + size was set (\ref QCPLayoutElement::maximumOuterSizeHint). +*/ +QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) +{ + QSize maxOuterHint = el->maximumOuterSizeHint(); + QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) + if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rwidth() += el->margins().left() + el->margins().right(); + if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutGrid + \brief A layout that arranges child elements in a grid + + Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, + \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). + + Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or + column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref + hasElement, that element can be retrieved with \ref element. If rows and columns that only have + empty cells shall be removed, call \ref simplify. Removal of elements is either done by just + adding the element to a different layout or by using the QCPLayout interface \ref take or \ref + remove. + + If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a + column, the grid layout will choose the position according to the current \ref setFillOrder and + the wrapping (\ref setWrap). + + Row and column insertion can be performed with \ref insertRow and \ref insertColumn. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPLayoutGrid::rowCount() const + + Returns the number of rows in the layout. + + \see columnCount +*/ + +/*! \fn int QCPLayoutGrid::columnCount() const + + Returns the number of columns in the layout. + + \see rowCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutGrid and sets default values. +*/ +QCPLayoutGrid::QCPLayoutGrid() : + mColumnSpacing(5), + mRowSpacing(5), + mWrap(0), + mFillOrder(foRowsFirst) +{ +} + +QCPLayoutGrid::~QCPLayoutGrid() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the element in the cell in \a row and \a column. + + Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug + message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. + + \see addElement, hasElement +*/ +QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const +{ + if (row >= 0 && row < mElements.size()) + { + if (column >= 0 && column < mElements.first().size()) + { + if (QCPLayoutElement *result = mElements.at(row).at(column)) + return result; + else + qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; + return 0; +} + + +/*! \overload + + Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it + is first removed from there. If \a row or \a column don't exist yet, the layout is expanded + accordingly. + + Returns true if the element was added successfully, i.e. if the cell at \a row and \a column + didn't already have an element. + + Use the overload of this method without explicit row/column index to place the element according + to the configured fill order and wrapping settings. + + \see element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) +{ + if (!hasElement(row, column)) + { + if (element && element->layout()) // remove from old layout first + element->layout()->take(element); + expandTo(row+1, column+1); + mElements[row][column] = element; + if (element) + adoptElement(element); + return true; + } else + qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; + return false; +} + +/*! \overload + + Adds the \a element to the next empty cell according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first + removed from there. If necessary, the layout is expanded to hold the new element. + + Returns true if the element was added successfully. + + \see setFillOrder, setWrap, element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(QCPLayoutElement *element) +{ + int rowIndex = 0; + int colIndex = 0; + if (mFillOrder == foColumnsFirst) + { + while (hasElement(rowIndex, colIndex)) + { + ++colIndex; + if (colIndex >= mWrap && mWrap > 0) + { + colIndex = 0; + ++rowIndex; + } + } + } else + { + while (hasElement(rowIndex, colIndex)) + { + ++rowIndex; + if (rowIndex >= mWrap && mWrap > 0) + { + rowIndex = 0; + ++colIndex; + } + } + } + return addElement(rowIndex, colIndex, element); +} + +/*! + Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't + empty. + + \see element +*/ +bool QCPLayoutGrid::hasElement(int row, int column) +{ + if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) + return mElements.at(row).at(column); + else + return false; +} + +/*! + Sets the stretch \a factor of \a column. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactors, setRowStretchFactor +*/ +void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) +{ + if (column >= 0 && column < columnCount()) + { + if (factor > 0) + mColumnStretchFactors[column] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid column:" << column; +} + +/*! + Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactor, setRowStretchFactors +*/ +void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) +{ + if (factors.size() == mColumnStretchFactors.size()) + { + mColumnStretchFactors = factors; + for (int i=0; i= 0 && row < rowCount()) + { + if (factor > 0) + mRowStretchFactors[row] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid row:" << row; +} + +/*! + Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setRowStretchFactor, setColumnStretchFactors +*/ +void QCPLayoutGrid::setRowStretchFactors(const QList &factors) +{ + if (factors.size() == mRowStretchFactors.size()) + { + mRowStretchFactors = factors; + for (int i=0; i tempElements; + if (rearrange) + { + tempElements.reserve(elCount); + for (int i=0; i()); + mRowStretchFactors.append(1); + } + // go through rows and expand columns as necessary: + int newColCount = qMax(columnCount(), newColumnCount); + for (int i=0; i rowCount()) + newIndex = rowCount(); + + mRowStretchFactors.insert(newIndex, 1); + QList newRow; + for (int col=0; col columnCount()) + newIndex = columnCount(); + + mColumnStretchFactors.insert(newIndex, 1); + for (int row=0; row= 0 && row < rowCount()) + { + if (column >= 0 && column < columnCount()) + { + switch (mFillOrder) + { + case foRowsFirst: return column*rowCount() + row; + case foColumnsFirst: return row*columnCount() + column; + } + } else + qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; + } else + qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; + return 0; +} + +/*! + Converts the linear index to row and column indices and writes the result to \a row and \a + column. + + The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the + indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices + increase top to bottom and then left to right. + + If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. + + For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, + i.e. greater or equal to zero and smaller than the current \ref elementCount. + + \see rowColToIndex +*/ +void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const +{ + row = -1; + column = -1; + const int nCols = columnCount(); + const int nRows = rowCount(); + if (nCols == 0 || nRows == 0) + return; + if (index < 0 || index >= elementCount()) + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return; + } + + switch (mFillOrder) + { + case foRowsFirst: + { + column = index / nRows; + row = index % nRows; + break; + } + case foColumnsFirst: + { + row = index / nCols; + column = index % nCols; + break; + } + } +} + +/* inherits documentation from base class */ +void QCPLayoutGrid::updateLayout() +{ + QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + int totalRowSpacing = (rowCount()-1) * mRowSpacing; + int totalColSpacing = (columnCount()-1) * mColumnSpacing; + QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); + QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); + + // go through cells and set rects accordingly: + int yOffset = mRect.top(); + for (int row=0; row 0) + yOffset += rowHeights.at(row-1)+mRowSpacing; + int xOffset = mRect.left(); + for (int col=0; col 0) + xOffset += colWidths.at(col-1)+mColumnSpacing; + if (mElements.at(row).at(col)) + mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); + } + } +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const +{ + if (index >= 0 && index < elementCount()) + { + int row, col; + indexToRowCol(index, row, col); + return mElements.at(row).at(col); + } else + return 0; +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + int row, col; + indexToRowCol(index, row, col); + mElements[row][col] = 0; + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutGrid::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; i QCPLayoutGrid::elements(bool recursive) const +{ + QList result; + const int elCount = elementCount(); +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(elCount); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing rows and columns which only contain empty cells. +*/ +void QCPLayoutGrid::simplify() +{ + // remove rows with only empty cells: + for (int row=rowCount()-1; row>=0; --row) + { + bool hasElements = false; + for (int col=0; col=0; --col) + { + bool hasElements = false; + for (int row=0; row minColWidths, minRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + QSize result(0, 0); + for (int i=0; i maxColWidths, maxRowHeights; + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + QSize result(0, 0); + for (int i=0; i QWIDGETSIZE_MAX) + result.setHeight(QWIDGETSIZE_MAX); + if (result.width() > QWIDGETSIZE_MAX) + result.setWidth(QWIDGETSIZE_MAX); + return result; +} + +/*! \internal + + Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights + respectively. + + The minimum height of a row is the largest minimum height of any element's outer rect in that + row. The minimum width of a column is the largest minimum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMaximumRowColSizes +*/ +void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const +{ + *minColWidths = QVector(columnCount(), 0); + *minRowHeights = QVector(rowCount(), 0); + for (int row=0; rowat(col) < minSize.width()) + (*minColWidths)[col] = minSize.width(); + if (minRowHeights->at(row) < minSize.height()) + (*minRowHeights)[row] = minSize.height(); + } + } + } +} + +/*! \internal + + Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights + respectively. + + The maximum height of a row is the smallest maximum height of any element's outer rect in that + row. The maximum width of a column is the smallest maximum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMinimumRowColSizes +*/ +void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const +{ + *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); + *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); + for (int row=0; rowat(col) > maxSize.width()) + (*maxColWidths)[col] = maxSize.width(); + if (maxRowHeights->at(row) > maxSize.height()) + (*maxRowHeights)[row] = maxSize.height(); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutInset +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPLayoutInset + \brief A layout that places child elements aligned to the border or arbitrarily positioned + + Elements are placed either aligned to the border or at arbitrary position in the area of the + layout. Which placement applies is controlled with the \ref InsetPlacement (\ref + setInsetPlacement). + + Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or + addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset + placement will default to \ref ipBorderAligned and the element will be aligned according to the + \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at + arbitrary position and size, defined by \a rect. + + The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. + + This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual void QCPLayoutInset::simplify() + + The QCPInsetLayout does not need simplification since it can never have empty cells due to its + linear index structure. This method does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutInset and sets default values. +*/ +QCPLayoutInset::QCPLayoutInset() +{ +} + +QCPLayoutInset::~QCPLayoutInset() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the placement type of the element with the specified \a index. +*/ +QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const +{ + if (elementAt(index)) + return mInsetPlacement.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return ipFree; + } +} + +/*! + Returns the alignment of the element with the specified \a index. The alignment only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. +*/ +Qt::Alignment QCPLayoutInset::insetAlignment(int index) const +{ + if (elementAt(index)) + return mInsetAlignment.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return 0; + } +} + +/*! + Returns the rect of the element with the specified \a index. The rect only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. +*/ +QRectF QCPLayoutInset::insetRect(int index) const +{ + if (elementAt(index)) + return mInsetRect.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return QRectF(); + } +} + +/*! + Sets the inset placement type of the element with the specified \a index to \a placement. + + \see InsetPlacement +*/ +void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) +{ + if (elementAt(index)) + mInsetPlacement[index] = placement; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function + is used to set the alignment of the element with the specified \a index to \a alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. +*/ +void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) +{ + if (elementAt(index)) + mInsetAlignment[index] = alignment; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the + position and size of the element with the specified \a index to \a rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + Note that the minimum and maximum sizes of the embedded element (\ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. +*/ +void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) +{ + if (elementAt(index)) + mInsetRect[index] = rect; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/* inherits documentation from base class */ +void QCPLayoutInset::updateLayout() +{ + for (int i=0; i finalMaxSize.width()) + insetRect.setWidth(finalMaxSize.width()); + if (insetRect.size().height() > finalMaxSize.height()) + insetRect.setHeight(finalMaxSize.height()); + } else if (mInsetPlacement.at(i) == ipBorderAligned) + { + insetRect.setSize(finalMinSize); + Qt::Alignment al = mInsetAlignment.at(i); + if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); + else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); + else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter + if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); + else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); + else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter + } + mElements.at(i)->setOuterRect(insetRect); + } +} + +/* inherits documentation from base class */ +int QCPLayoutInset::elementCount() const +{ + return mElements.size(); +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::elementAt(int index) const +{ + if (index >= 0 && index < mElements.size()) + return mElements.at(index); + else + return 0; +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + mElements.removeAt(index); + mInsetPlacement.removeAt(index); + mInsetAlignment.removeAt(index); + mInsetRect.removeAt(index); + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutInset::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/*! + Adds the specified \a element to the layout as an inset aligned at the border (\ref + setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a + alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. + + \see addElement(QCPLayoutElement *element, const QRectF &rect) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipBorderAligned); + mInsetAlignment.append(alignment); + mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} + +/*! + Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref + setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a + rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipFree); + mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); + mInsetRect.append(rect); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} +/* end of 'src/layout.cpp' */ + + +/* including file 'src/lineending.cpp', size 11536 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLineEnding +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLineEnding + \brief Handles the different ending decorations for line-like items + + \image html QCPLineEnding.png "The various ending styles currently supported" + + For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine + has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. + + The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can + be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of + the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. + For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite + directions, e.g. "outward". This can be changed by \ref setInverted, which would make the + respective arrow point inward. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify a + QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. + \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead +*/ + +/*! + Creates a QCPLineEnding instance with default values (style \ref esNone). +*/ +QCPLineEnding::QCPLineEnding() : + mStyle(esNone), + mWidth(8), + mLength(10), + mInverted(false) +{ +} + +/*! + Creates a QCPLineEnding instance with the specified values. +*/ +QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : + mStyle(style), + mWidth(width), + mLength(length), + mInverted(inverted) +{ +} + +/*! + Sets the style of the ending decoration. +*/ +void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) +{ + mStyle = style; +} + +/*! + Sets the width of the ending decoration, if the style supports it. On arrows, for example, the + width defines the size perpendicular to the arrow's pointing direction. + + \see setLength +*/ +void QCPLineEnding::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the length of the ending decoration, if the style supports it. On arrows, for example, the + length defines the size in pointing direction. + + \see setWidth +*/ +void QCPLineEnding::setLength(double length) +{ + mLength = length; +} + +/*! + Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point + inward when \a inverted is set to true. + + Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or + discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are + affected by it, which can be used to control to which side the half bar points to. +*/ +void QCPLineEnding::setInverted(bool inverted) +{ + mInverted = inverted; +} + +/*! \internal + + Returns the maximum pixel radius the ending decoration might cover, starting from the position + the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). + + This is relevant for clipping. Only omit painting of the decoration when the position where the + decoration is supposed to be drawn is farther away from the clipping rect than the returned + distance. +*/ +double QCPLineEnding::boundingDistance() const +{ + switch (mStyle) + { + case esNone: + return 0; + + case esFlatArrow: + case esSpikeArrow: + case esLineArrow: + case esSkewedBar: + return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length + + case esDisc: + case esSquare: + case esDiamond: + case esBar: + case esHalfBar: + return mWidth*1.42; // items that only have a width -> width*sqrt(2) + + } + return 0; +} + +/*! + Starting from the origin of this line ending (which is style specific), returns the length + covered by the line ending symbol, in backward direction. + + For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if + both have the same \ref setLength value, because the spike arrow has an inward curved back, which + reduces the length along its center axis (the drawing origin for arrows is at the tip). + + This function is used for precise, style specific placement of line endings, for example in + QCPAxes. +*/ +double QCPLineEnding::realLength() const +{ + switch (mStyle) + { + case esNone: + case esLineArrow: + case esSkewedBar: + case esBar: + case esHalfBar: + return 0; + + case esFlatArrow: + return mLength; + + case esDisc: + case esSquare: + case esDiamond: + return mWidth*0.5; + + case esSpikeArrow: + return mLength*0.8; + } + return 0; +} + +/*! \internal + + Draws the line ending with the specified \a painter at the position \a pos. The direction of the + line ending is controlled with \a dir. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const +{ + if (mStyle == esNone) + return; + + QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); + if (lengthVec.isNull()) + lengthVec = QCPVector2D(1, 0); + QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); + + QPen penBackup = painter->pen(); + QBrush brushBackup = painter->brush(); + QPen miterPen = penBackup; + miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey + QBrush brush(painter->pen().color(), Qt::SolidPattern); + switch (mStyle) + { + case esNone: break; + case esFlatArrow: + { + QPointF points[3] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 3); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esSpikeArrow: + { + QPointF points[4] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec*0.8).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esLineArrow: + { + QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), + pos.toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->drawPolyline(points, 3); + painter->setPen(penBackup); + break; + } + case esDisc: + { + painter->setBrush(brush); + painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); + painter->setBrush(brushBackup); + break; + } + case esSquare: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), + (pos-widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esDiamond: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp).toPointF(), + (pos-widthVec).toPointF(), + (pos+widthVecPerp).toPointF(), + (pos+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esBar: + { + painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); + break; + } + case esHalfBar: + { + painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); + break; + } + case esSkewedBar: + { + if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) + { + // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); + } else + { + // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); + } + break; + } + } +} + +/*! \internal + \overload + + Draws the line ending. The direction is controlled with the \a angle parameter in radians. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const +{ + draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); +} +/* end of 'src/lineending.cpp' */ + + +/* including file 'src/axis/axisticker.cpp', size 18664 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTicker +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTicker + \brief The base class tick generator used by QCPAxis to create tick positions and tick labels + + Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions + and tick labels for the current axis range. The ticker of an axis can be set via \ref + QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple + axes can share the same ticker instance. + + This base class generates normal tick coordinates and numeric labels for linear axes. It picks a + reasonable tick step (the separation between ticks) which results in readable tick labels. The + number of ticks that should be approximately generated can be set via \ref setTickCount. + Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either + sacrifices readability to better match the specified tick count (\ref + QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref + QCPAxisTicker::tssReadability), which is the default. + + The following more specialized axis ticker subclasses are available, see details in the + respective class documentation: + +
+ + + + + + + +
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png + \image html axisticker-time2.png
+
+ + \section axisticker-subclassing Creating own axis tickers + + Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and + reimplementing some or all of the available virtual methods. + + In the simplest case you might wish to just generate different tick steps than the other tickers, + so you only reimplement the method \ref getTickStep. If you additionally want control over the + string that will be shown as tick label, reimplement \ref getTickLabel. + + If you wish to have complete control, you can generate the tick vectors and tick label vectors + yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default + implementations use the previously mentioned virtual methods \ref getTickStep and \ref + getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case + of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. + + The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick + placement control is obtained by reimplementing \ref createSubTickVector. + + See the documentation of all these virtual methods in QCPAxisTicker for detailed information + about the parameters and expected return values. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTicker::QCPAxisTicker() : + mTickStepStrategy(tssReadability), + mTickCount(5), + mTickOrigin(0) +{ +} + +QCPAxisTicker::~QCPAxisTicker() +{ + +} + +/*! + Sets which strategy the axis ticker follows when choosing the size of the tick step. For the + available strategies, see \ref TickStepStrategy. +*/ +void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) +{ + mTickStepStrategy = strategy; +} + +/*! + Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count + is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with + the requested number of ticks. + + Whether the readability has priority over meeting the requested \a count can be specified with + \ref setTickStepStrategy. +*/ +void QCPAxisTicker::setTickCount(int count) +{ + if (count > 0) + mTickCount = count; + else + qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; +} + +/*! + Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a + concept and doesn't need to be inside the currently visible axis range. + + By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick + step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be + {-4, 1, 6, 11, 16,...}. +*/ +void QCPAxisTicker::setTickOrigin(double origin) +{ + mTickOrigin = origin; +} + +/*! + This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), + tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). + + The ticks are generated for the specified \a range. The generated labels typically follow the + specified \a locale, \a formatChar and number \a precision, however this might be different (or + even irrelevant) for certain QCPAxisTicker subclasses. + + The output parameter \a ticks is filled with the generated tick positions in axis coordinates. + The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) + and are respectively filled with sub tick coordinates, and tick label strings belonging to \a + ticks by index. +*/ +void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) +{ + // generate (major) ticks: + double tickStep = getTickStep(range); + ticks = createTickVector(tickStep, range); + trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) + + // generate sub ticks between major ticks: + if (subTicks) + { + if (ticks.size() > 0) + { + *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); + trimTicks(range, *subTicks, false); + } else + *subTicks = QVector(); + } + + // finally trim also outliers (no further clipping happens in axis drawing): + trimTicks(range, ticks, false); + // generate labels for visible ticks if requested: + if (tickLabels) + *tickLabels = createLabelVector(ticks, locale, formatChar, precision); +} + +/*! \internal + + Takes the entire currently visible axis range and returns a sensible tick step in + order to provide readable tick labels as well as a reasonable number of tick counts (see \ref + setTickCount, \ref setTickStepStrategy). + + If a QCPAxisTicker subclass only wants a different tick step behaviour than the default + implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper + function. +*/ +double QCPAxisTicker::getTickStep(const QCPRange &range) +{ + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return cleanMantissa(exactStep); +} + +/*! \internal + + Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns + an appropriate number of sub ticks for that specific tick step. + + Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. +*/ +int QCPAxisTicker::getSubTickCount(double tickStep) +{ + int result = 1; // default to 1, if no proper value can be found + + // separate integer and fractional part of mantissa: + double epsilon = 0.01; + double intPartf; + int intPart; + double fracPart = modf(getMantissa(tickStep), &intPartf); + intPart = intPartf; + + // handle cases with (almost) integer mantissa: + if (fracPart < epsilon || 1.0-fracPart < epsilon) + { + if (1.0-fracPart < epsilon) + ++intPart; + switch (intPart) + { + case 1: result = 4; break; // 1.0 -> 0.2 substep + case 2: result = 3; break; // 2.0 -> 0.5 substep + case 3: result = 2; break; // 3.0 -> 1.0 substep + case 4: result = 3; break; // 4.0 -> 1.0 substep + case 5: result = 4; break; // 5.0 -> 1.0 substep + case 6: result = 2; break; // 6.0 -> 2.0 substep + case 7: result = 6; break; // 7.0 -> 1.0 substep + case 8: result = 3; break; // 8.0 -> 2.0 substep + case 9: result = 2; break; // 9.0 -> 3.0 substep + } + } else + { + // handle cases with significantly fractional mantissa: + if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa + { + switch (intPart) + { + case 1: result = 2; break; // 1.5 -> 0.5 substep + case 2: result = 4; break; // 2.5 -> 0.5 substep + case 3: result = 4; break; // 3.5 -> 0.7 substep + case 4: result = 2; break; // 4.5 -> 1.5 substep + case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) + case 6: result = 4; break; // 6.5 -> 1.3 substep + case 7: result = 2; break; // 7.5 -> 2.5 substep + case 8: result = 4; break; // 8.5 -> 1.7 substep + case 9: result = 4; break; // 9.5 -> 1.9 substep + } + } + // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default + } + + return result; +} + +/*! \internal + + This method returns the tick label string as it should be printed under the \a tick coordinate. + If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a + precision. + + If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is + enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will + be formatted accordingly using multiplication symbol and superscript during rendering of the + label automatically. +*/ +QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + return locale.toString(tick, formatChar.toLatin1(), precision); +} + +/*! \internal + + Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a + subTickCount sub ticks between each tick pair given in \a ticks. + + If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should + reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to + base its result on \a subTickCount or \a ticks. +*/ +QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) +{ + QVector result; + if (subTickCount <= 0 || ticks.size() < 2) + return result; + + result.reserve((ticks.size()-1)*subTickCount); + for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result; + // Generate tick positions according to tickStep: + qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision + qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision + int tickcount = lastStep-firstStep+1; + if (tickcount < 0) tickcount = 0; + result.resize(tickcount); + for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) +{ + QVector result; + result.reserve(ticks.size()); + for (int i=0; i &ticks, bool keepOneOutlier) const +{ + bool lowFound = false; + bool highFound = false; + int lowIndex = 0; + int highIndex = -1; + + for (int i=0; i < ticks.size(); ++i) + { + if (ticks.at(i) >= range.lower) + { + lowFound = true; + lowIndex = i; + break; + } + } + for (int i=ticks.size()-1; i >= 0; --i) + { + if (ticks.at(i) <= range.upper) + { + highFound = true; + highIndex = i; + break; + } + } + + if (highFound && lowFound) + { + int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); + int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); + if (trimFront > 0 || trimBack > 0) + ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); + } else // all ticks are either all below or all above the range + ticks.clear(); +} + +/*! \internal + + Returns the coordinate contained in \a candidates which is closest to the provided \a target. + + This method assumes \a candidates is not empty and sorted in ascending order. +*/ +double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const +{ + if (candidates.size() == 1) + return candidates.first(); + QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); + if (it == candidates.constEnd()) + return *(it-1); + else if (it == candidates.constBegin()) + return *it; + else + return target-*(it-1) < *it-target ? *(it-1) : *it; +} + +/*! \internal + + Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also + returns the magnitude of \a input as a power of 10. + + For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. +*/ +double QCPAxisTicker::getMantissa(double input, double *magnitude) const +{ + const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); + if (magnitude) *magnitude = mag; + return input/mag; +} + +/*! \internal + + Returns a number that is close to \a input but has a clean, easier human readable mantissa. How + strongly the mantissa is altered, and thus how strong the result deviates from the original \a + input, depends on the current tick step strategy (see \ref setTickStepStrategy). +*/ +double QCPAxisTicker::cleanMantissa(double input) const +{ + double magnitude; + const double mantissa = getMantissa(input, &magnitude); + switch (mTickStepStrategy) + { + case tssReadability: + { + return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; + } + case tssMeetTickCount: + { + // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 + if (mantissa <= 5.0) + return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 + else + return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 + } + } + return input; +} +/* end of 'src/axis/axisticker.cpp' */ + + +/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerDateTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerDateTime + \brief Specialized axis ticker for calendar dates and times as axis ticks + + \image html axisticker-datetime.png + + This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The + plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 + UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods + with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime + by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey + and \ref keyToDateTime conveniently perform this conversion achieving a precision of one + millisecond on all Qt versions. + + The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. + If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. + + This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day + ticks. For example, if the axis range spans a few years such that there is one tick per year, + ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, + will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in + the image above: even though the number of days varies month by month, this ticker generates + ticks on the same day of each month. + + If you would like to change the date/time that is used as a (mathematical) starting date for the + ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a + QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at + 9:45 of every year. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation + + \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and + milliseconds, and are not interested in the intricacies of real calendar dates with months and + (leap) years, have a look at QCPAxisTickerTime instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerDateTime::QCPAxisTickerDateTime() : + mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), + mDateTimeSpec(Qt::LocalTime), + mDateStrategy(dsNone) +{ + setTickCount(4); +} + +/*! + Sets the format in which dates and times are displayed as tick labels. For details about the \a + format string, see the documentation of QDateTime::toString(). + + Newlines can be inserted with "\n". + + \see setDateTimeSpec +*/ +void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) +{ + mDateTimeFormat = format; +} + +/*! + Sets the time spec that is used for creating the tick labels from corresponding dates/times. + + The default value of QDateTime objects (and also QCPAxisTickerDateTime) is + Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form + of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC + to get the correct axis labels. + + \see setDateTimeFormat +*/ +void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) +{ + mDateTimeSpec = spec; +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, + 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which + directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(double origin) +{ + QCPAxisTicker::setTickOrigin(origin); +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) +{ + setTickOrigin(dateTimeToKey(origin)); +} + +/*! \internal + + Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + Note that this tick step isn't used exactly when generating the tick vector in \ref + createTickVector, but only as a guiding value requiring some correction for each individual tick + interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day + in the month to the last day in the previous month from tick to tick, due to the non-uniform + length of months. The same problem arises with leap years. + + \seebaseclassmethod +*/ +double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + mDateStrategy = dsNone; + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + result = cleanMantissa(result); + } else if (result < 86400*30.4375*12) // below a year + { + result = pickClosest(result, QVector() + << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range + << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range + << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) + if (result > 86400*30.4375-1) // month tick intervals or larger + mDateStrategy = dsUniformDayInMonth; + else if (result > 3600*24-1) // day tick intervals or larger + mDateStrategy = dsUniformTimeInDay; + } else // more than a year, go back to normal clean mantissa algorithm but in units of years + { + const double secondsPerYear = 86400*30.4375*12; // average including leap years + result = cleanMantissa(result/secondsPerYear)*secondsPerYear; + mDateStrategy = dsUniformDayInMonth; + } + return result; +} + +/*! \internal + + Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + \seebaseclassmethod +*/ +int QCPAxisTickerDateTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + case 86400*2: result = 1; break; + case 86400*5: result = 4; break; + case 86400*7: result = 6; break; + case 86400*14: result = 1; break; + case (int)(86400*30.4375+0.5): result = 3; break; + case (int)(86400*30.4375*2+0.5): result = 1; break; + case (int)(86400*30.4375*3+0.5): result = 2; break; + case (int)(86400*30.4375*6+0.5): result = 5; break; + case (int)(86400*30.4375*12+0.5): result = 3; break; + } + return result; +} + +/*! \internal + + Generates a date/time tick label for tick coordinate \a tick, based on the currently set format + (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). + + \seebaseclassmethod +*/ +QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +} + +/*! \internal + + Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain + non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. + + \seebaseclassmethod +*/ +QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result = QCPAxisTicker::createTickVector(tickStep, range); + if (!result.isEmpty()) + { + if (mDateStrategy == dsUniformTimeInDay) + { + QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible + QDateTime tickDateTime; + for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths(-1); + tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); + result[i] = dateTimeToKey(tickDateTime); + } + } + } + return result; +} + +/*! + A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a + QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) + + \see dateTimeToKey +*/ +QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); +# else + return QDateTime::fromMSecsSinceEpoch(key*1000.0); +# endif +} + +/*! \overload + + A convenience method which turns a QDateTime object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return dateTime.toTime_t()+dateTime.time().msec()/1000.0; +# else + return dateTime.toMSecsSinceEpoch()/1000.0; +# endif +} + +/*! \overload + + A convenience method which turns a QDate object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime(date).toTime_t(); +# else + return QDateTime(date).toMSecsSinceEpoch()/1000.0; +# endif +} +/* end of 'src/axis/axistickerdatetime.cpp' */ + + +/* including file 'src/axis/axistickertime.cpp', size 11747 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerTime + \brief Specialized axis ticker for time spans in units of milliseconds to days + + \image html axisticker-time.png + + This QCPAxisTicker subclass generates ticks that corresponds to time intervals. + + The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref + setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate + zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date + and time. + + The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the + largest available unit in the format specified with \ref setTimeFormat, any time spans above will + be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at + coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick + label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour + unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis + zero will carry a leading minus sign. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation + + Here is an example of a time axis providing time information in days, hours and minutes. Due to + the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker + decided to use tick steps of 12 hours: + + \image html axisticker-time2.png + + The format string for this example is + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 + + \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime + instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerTime::QCPAxisTickerTime() : + mTimeFormat(QLatin1String("%h:%m:%s")), + mSmallestUnit(tuSeconds), + mBiggestUnit(tuHours) +{ + setTickCount(4); + mFieldWidth[tuMilliseconds] = 3; + mFieldWidth[tuSeconds] = 2; + mFieldWidth[tuMinutes] = 2; + mFieldWidth[tuHours] = 2; + mFieldWidth[tuDays] = 1; + + mFormatPattern[tuMilliseconds] = QLatin1String("%z"); + mFormatPattern[tuSeconds] = QLatin1String("%s"); + mFormatPattern[tuMinutes] = QLatin1String("%m"); + mFormatPattern[tuHours] = QLatin1String("%h"); + mFormatPattern[tuDays] = QLatin1String("%d"); +} + +/*! + Sets the format that will be used to display time in the tick labels. + + The available patterns are: + - %%z for milliseconds + - %%s for seconds + - %%m for minutes + - %%h for hours + - %%d for days + + The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. + + The largest unit that appears in \a format will carry all the remaining time of a certain tick + coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the + largest unit it might become larger than 59 in order to consume larger time values. If on the + other hand %%h is available, the minutes will wrap around to zero after 59 and the time will + carry to the hour digit. +*/ +void QCPAxisTickerTime::setTimeFormat(const QString &format) +{ + mTimeFormat = format; + + // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest + // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) + mSmallestUnit = tuMilliseconds; + mBiggestUnit = tuMilliseconds; + bool hasSmallest = false; + for (int i = tuMilliseconds; i <= tuDays; ++i) + { + TimeUnit unit = static_cast(i); + if (mTimeFormat.contains(mFormatPattern.value(unit))) + { + if (!hasSmallest) + { + mSmallestUnit = unit; + hasSmallest = true; + } + mBiggestUnit = unit; + } + } +} + +/*! + Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick + label. If the number for the specific unit is shorter than \a width, it will be padded with an + according number of zeros to the left in order to reach the field width. + + \see setTimeFormat +*/ +void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) +{ + mFieldWidth[unit] = qMax(width, 1); +} + +/*! \internal + + Returns the tick step appropriate for time displays, depending on the provided \a range and the + smallest available time unit in the current format (\ref setTimeFormat). For example if the unit + of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) + that require sub-minute precision to be displayed correctly. + + \seebaseclassmethod +*/ +double QCPAxisTickerTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + if (mSmallestUnit == tuMilliseconds) + result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond + else // have no milliseconds available in format, so stick with 1 second tickstep + result = 1.0; + } else if (result < 3600*24) // below a day + { + // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run + QVector availableSteps; + // seconds range: + if (mSmallestUnit <= tuSeconds) + availableSteps << 1; + if (mSmallestUnit == tuMilliseconds) + availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it + else if (mSmallestUnit == tuSeconds) + availableSteps << 2; + if (mSmallestUnit <= tuSeconds) + availableSteps << 5 << 10 << 15 << 30; + // minutes range: + if (mSmallestUnit <= tuMinutes) + availableSteps << 1*60; + if (mSmallestUnit <= tuSeconds) + availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it + else if (mSmallestUnit == tuMinutes) + availableSteps << 2*60; + if (mSmallestUnit <= tuMinutes) + availableSteps << 5*60 << 10*60 << 15*60 << 30*60; + // hours range: + if (mSmallestUnit <= tuHours) + availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; + // pick available step that is most appropriate to approximate ideal step: + result = pickClosest(result, availableSteps); + } else // more than a day, go back to normal clean mantissa algorithm but in units of days + { + const double secondsPerDay = 3600*24; + result = cleanMantissa(result/secondsPerDay)*secondsPerDay; + } + return result; +} + +/*! \internal + + Returns the sub tick count appropriate for the provided \a tickStep and time displays. + + \seebaseclassmethod +*/ +int QCPAxisTickerTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + } + return result; +} + +/*! \internal + + Returns the tick label corresponding to the provided \a tick and the configured format and field + widths (\ref setTimeFormat, \ref setFieldWidth). + + \seebaseclassmethod +*/ +QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + Q_UNUSED(locale) + bool negative = tick < 0; + if (negative) tick *= -1; + double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) + double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time + + restValues[tuMilliseconds] = tick*1000; + values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; + values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; + values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; + values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; + // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) + + QString result = mTimeFormat; + for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) + { + TimeUnit iUnit = static_cast(i); + replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); + } + if (negative) + result.prepend(QLatin1Char('-')); + return result; +} + +/*! \internal + + Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified + \a value, using the field width as specified with \ref setFieldWidth for the \a unit. +*/ +void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const +{ + QString valueStr = QString::number(value); + while (valueStr.size() < mFieldWidth.value(unit)) + valueStr.prepend(QLatin1Char('0')); + + text.replace(mFormatPattern.value(unit), valueStr); +} +/* end of 'src/axis/axistickertime.cpp' */ + + +/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerFixed +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerFixed + \brief Specialized axis ticker with a fixed tick step + + \image html axisticker-fixed.png + + This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It + is also possible to allow integer multiples and integer powers of the specified tick step with + \ref setScaleStrategy. + + A typical application of this ticker is to make an axis only display integers, by setting the + tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. + + Another case is when a certain number has a special meaning and axis ticks should only appear at + multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi + because despite the name it is not limited to only pi symbols/values. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerFixed::QCPAxisTickerFixed() : + mTickStep(1.0), + mScaleStrategy(ssNone) +{ +} + +/*! + Sets the fixed tick interval to \a step. + + The axis ticker will only use this tick step when generating axis ticks. This might cause a very + high tick density and overlapping labels if the axis range is zoomed out. Using \ref + setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a + step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref + setTickCount). +*/ +void QCPAxisTickerFixed::setTickStep(double step) +{ + if (step > 0) + mTickStep = step; + else + qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; +} + +/*! + Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether + modifications may be applied to it before calculating the finally used tick step, such as + permitting multiples or powers. See \ref ScaleStrategy for details. + + The default strategy is \ref ssNone, which means the tick step is absolutely fixed. +*/ +void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) +{ + mScaleStrategy = strategy; +} + +/*! \internal + + Determines the actually used tick step from the specified tick step and scale strategy (\ref + setTickStep, \ref setScaleStrategy). + + This method either returns the specified tick step exactly, or, if the scale strategy is not \ref + ssNone, a modification of it to allow varying the number of ticks in the current axis range. + + \seebaseclassmethod +*/ +double QCPAxisTickerFixed::getTickStep(const QCPRange &range) +{ + switch (mScaleStrategy) + { + case ssNone: + { + return mTickStep; + } + case ssMultiples: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + if (exactStep < mTickStep) + return mTickStep; + else + return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; + } + case ssPowers: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); + } + } + return mTickStep; +} +/* end of 'src/axis/axistickerfixed.cpp' */ + + +/* including file 'src/axis/axistickertext.cpp', size 8653 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerText +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerText + \brief Specialized axis ticker which allows arbitrary labels at specified coordinates + + \image html axisticker-text.png + + This QCPAxisTicker subclass generates ticks which can be directly specified by the user as + coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a + time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks + and modify the tick/label data there. + + This is useful for cases where the axis represents categories rather than numerical values. + + If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on + the axis range), it is a sign that you should probably create an own ticker by subclassing + QCPAxisTicker, instead of using this one. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation +*/ + +/* start of documentation of inline functions */ + +/*! \fn QMap &QCPAxisTickerText::ticks() + + Returns a non-const reference to the internal map which stores the tick coordinates and their + labels. + + You can access the map directly in order to add, remove or manipulate ticks, as an alternative to + using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerText::QCPAxisTickerText() : + mSubTickCount(0) +{ +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis + coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QMap &ticks) +{ + mTicks = ticks; +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis + coordinates, and the entries of \a labels are the respective strings that will appear as tick + labels. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) +{ + clear(); + addTicks(positions, labels); +} + +/*! + Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no + automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this + method. +*/ +void QCPAxisTickerText::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! + Clears all ticks. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see setTicks, addTicks, addTick +*/ +void QCPAxisTickerText::clear() +{ + mTicks.clear(); +} + +/*! + Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a + label. + + \see addTicks, setTicks, clear +*/ +void QCPAxisTickerText::addTick(double position, QString label) +{ + mTicks.insert(position, label); +} + +/*! \overload + + Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to + the axis coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QMap &ticks) +{ + mTicks.unite(ticks); +} + +/*! \overload + + Adds the provided ticks to the ones already existing. The entries of \a positions correspond to + the axis coordinates, and the entries of \a labels are the respective strings that will appear as + tick labels. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) +{ + if (positions.size() != labels.size()) + qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); + int n = qMin(positions.size(), labels.size()); + for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (mTicks.isEmpty()) + return result; + + QMap::const_iterator start = mTicks.lowerBound(range.lower); + QMap::const_iterator end = mTicks.upperBound(range.upper); + // this method should try to give one tick outside of range so proper subticks can be generated: + if (start != mTicks.constBegin()) --start; + if (end != mTicks.constEnd()) ++end; + for (QMap::const_iterator it = start; it != end; ++it) + result.append(it.key()); + + return result; +} +/* end of 'src/axis/axistickertext.cpp' */ + + +/* including file 'src/axis/axistickerpi.cpp', size 11170 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerPi +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerPi + \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi + + \image html axisticker-pi.png + + This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic + constant with a numerical value specified with \ref setPiValue and an appearance in the tick + labels specified with \ref setPiSymbol. + + Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the + tick label can be configured with \ref setFractionStyle. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerPi::QCPAxisTickerPi() : + mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), + mPiValue(M_PI), + mPeriodicity(0), + mFractionStyle(fsUnicodeFractions), + mPiTickStep(0) +{ + setTickCount(4); +} + +/*! + Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick + label. + + If a space shall appear between the number and the symbol, make sure the space is contained in \a + symbol. +*/ +void QCPAxisTickerPi::setPiSymbol(QString symbol) +{ + mPiSymbol = symbol; +} + +/*! + Sets the numerical value that the symbolic constant has. + + This will be used to place the appropriate fractions of the symbol at the respective axis + coordinates. +*/ +void QCPAxisTickerPi::setPiValue(double pi) +{ + mPiValue = pi; +} + +/*! + Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the + symbolic constant. + + To disable periodicity, set \a multiplesOfPi to zero. + + For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. +*/ +void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) +{ + mPeriodicity = qAbs(multiplesOfPi); +} + +/*! + Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick + labels. See \ref FractionStyle for the various options. +*/ +void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) +{ + mFractionStyle = style; +} + +/*! \internal + + Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence + the numerical/fractional part preceding the symbolic constant is made to have a readable + mantissa. + + \seebaseclassmethod +*/ +double QCPAxisTickerPi::getTickStep(const QCPRange &range) +{ + mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mPiTickStep = cleanMantissa(mPiTickStep); + return mPiTickStep*mPiValue; +} + +/*! \internal + + Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In + consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant + reasonably, and not the total tick coordinate. + + \seebaseclassmethod +*/ +int QCPAxisTickerPi::getSubTickCount(double tickStep) +{ + return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); +} + +/*! \internal + + Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The + formatting of the fraction is done according to the specified \ref setFractionStyle. The appended + symbol is specified with \ref setPiSymbol. + + \seebaseclassmethod +*/ +QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + double tickInPis = tick/mPiValue; + if (mPeriodicity > 0) + tickInPis = fmod(tickInPis, mPeriodicity); + + if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) + { + // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above + int denominator = 1000; + int numerator = qRound(tickInPis*denominator); + simplifyFraction(numerator, denominator); + if (qAbs(numerator) == 1 && denominator == 1) + return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else if (numerator == 0) + return QLatin1String("0"); + else + return fractionToString(numerator, denominator) + mPiSymbol; + } else + { + if (qFuzzyIsNull(tickInPis)) + return QLatin1String("0"); + else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) + return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else + return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; + } +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure + the fraction is in irreducible form, i.e. numerator and denominator don't share any common + factors which could be cancelled. +*/ +void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const +{ + if (numerator == 0 || denominator == 0) + return; + + int num = numerator; + int denom = denominator; + while (denom != 0) // euclidean gcd algorithm + { + int oldDenom = denom; + denom = num % denom; + num = oldDenom; + } + // num is now gcd of numerator and denominator + numerator /= num; + denominator /= num; +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and returns a string representation. + The result depends on the configured fraction style (\ref setFractionStyle). + + This method is used to format the numerical/fractional part when generating tick labels. It + simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out + any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). +*/ +QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const +{ + if (denominator == 0) + { + qDebug() << Q_FUNC_INFO << "called with zero denominator"; + return QString(); + } + if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function + { + qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; + return QString::number(numerator/(double)denominator); // failsafe + } + int sign = numerator*denominator < 0 ? -1 : 1; + numerator = qAbs(numerator); + denominator = qAbs(denominator); + + if (denominator == 1) + { + return QString::number(sign*numerator); + } else + { + int integerPart = numerator/denominator; + int remainder = numerator%denominator; + if (remainder == 0) + { + return QString::number(sign*integerPart); + } else + { + if (mFractionStyle == fsAsciiFractions) + { + return QString(QLatin1String("%1%2%3/%4")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) + .arg(remainder) + .arg(denominator); + } else if (mFractionStyle == fsUnicodeFractions) + { + return QString(QLatin1String("%1%2%3")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) + .arg(unicodeFraction(remainder, denominator)); + } + } + } + return QString(); +} + +/*! \internal + + Returns the unicode string representation of the fraction given by \a numerator and \a + denominator. This is the representation used in \ref fractionToString when the fraction style + (\ref setFractionStyle) is \ref fsUnicodeFractions. + + This method doesn't use the single-character common fractions but builds each fraction from a + superscript unicode number, the unicode fraction character, and a subscript unicode number. +*/ +QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const +{ + return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); +} + +/*! \internal + + Returns the unicode string representing \a number as superscript. This is used to build + unicode fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSuperscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2070)); + + QString result; + while (number > 0) + { + const int digit = number%10; + switch (digit) + { + case 1: { result.prepend(QChar(0x00B9)); break; } + case 2: { result.prepend(QChar(0x00B2)); break; } + case 3: { result.prepend(QChar(0x00B3)); break; } + default: { result.prepend(QChar(0x2070+digit)); break; } + } + number /= 10; + } + return result; +} + +/*! \internal + + Returns the unicode string representing \a number as subscript. This is used to build unicode + fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSubscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2080)); + + QString result; + while (number > 0) + { + result.prepend(QChar(0x2080+number%10)); + number /= 10; + } + return result; +} +/* end of 'src/axis/axistickerpi.cpp' */ + + +/* including file 'src/axis/axistickerlog.cpp', size 7106 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerLog +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerLog + \brief Specialized axis ticker suited for logarithmic axes + + \image html axisticker-log.png + + This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic + axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). + + Especially in the case of a log base equal to 10 (the default), it might be desirable to have + tick labels in the form of powers of ten without mantissa display. To achieve this, set the + number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref + QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal + powers, so a format string of "eb". This will result in the following axis tick labels: + + \image html axisticker-log-powers.png + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerLog::QCPAxisTickerLog() : + mLogBase(10.0), + mSubTickCount(8), // generates 10 intervals + mLogBaseLnInv(1.0/qLn(mLogBase)) +{ +} + +/*! + Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer + powers of \a base. +*/ +void QCPAxisTickerLog::setLogBase(double base) +{ + if (base > 0) + { + mLogBase = base; + mLogBaseLnInv = 1.0/qLn(mLogBase); + } else + qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; +} + +/*! + Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced + linearly to provide a better visual guide, so the sub tick density increases toward the higher + tick. + + Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in + the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub + ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, + namely at 20, 30, 40, 50, 60, 70, 80 and 90. +*/ +void QCPAxisTickerLog::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! \internal + + Since logarithmic tick steps are necessarily different for each tick interval, this method does + nothing in the case of QCPAxisTickerLog + + \seebaseclassmethod +*/ +double QCPAxisTickerLog::getTickStep(const QCPRange &range) +{ + // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method + Q_UNUSED(range) + return 1.0; +} + +/*! \internal + + Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no + automatic sub tick count calculation necessary. + + \seebaseclassmethod +*/ +int QCPAxisTickerLog::getSubTickCount(double tickStep) +{ + Q_UNUSED(tickStep) + return mSubTickCount; +} + +/*! \internal + + Creates ticks with a spacing given by the logarithm base and an increasing integer power in the + provided \a range. The step in which the power increases tick by tick is chosen in order to keep + the total number of ticks as close as possible to the tick count (\ref setTickCount). The + parameter \a tickStep is ignored for QCPAxisTickerLog + + \seebaseclassmethod +*/ +QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (range.lower > 0 && range.upper > 0) // positive range + { + double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick *= newLogBase; + result.append(currentTick); + } + } else if (range.lower < 0 && range.upper < 0) // negative range + { + double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick /= newLogBase; + result.append(currentTick); + } + } else // invalid range for logarithmic scale, because lower and upper have different sign + { + qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; + } + + return result; +} +/* end of 'src/axis/axistickerlog.cpp' */ + + +/* including file 'src/axis/axis.cpp', size 99397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGrid + \brief Responsible for drawing the grid of a QCPAxis. + + This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the + grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref + QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. + + The axis and grid drawing was split into two classes to allow them to be placed on different + layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid + in the background and the axes in the foreground, and any plottables/items in between. This + described situation is the default setup, see the QCPLayer documentation. +*/ + +/*! + Creates a QCPGrid instance and sets default values. + + You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. +*/ +QCPGrid::QCPGrid(QCPAxis *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mParentAxis(parentAxis) +{ + // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called + setParent(parentAxis); + setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); + setSubGridVisible(false); + setAntialiased(false); + setAntialiasedSubGrid(false); + setAntialiasedZeroLine(false); +} + +/*! + Sets whether grid lines at sub tick marks are drawn. + + \see setSubGridPen +*/ +void QCPGrid::setSubGridVisible(bool visible) +{ + mSubGridVisible = visible; +} + +/*! + Sets whether sub grid lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedSubGrid(bool enabled) +{ + mAntialiasedSubGrid = enabled; +} + +/*! + Sets whether zero lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedZeroLine(bool enabled) +{ + mAntialiasedZeroLine = enabled; +} + +/*! + Sets the pen with which (major) grid lines are drawn. +*/ +void QCPGrid::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen with which sub grid lines are drawn. +*/ +void QCPGrid::setSubGridPen(const QPen &pen) +{ + mSubGridPen = pen; +} + +/*! + Sets the pen with which zero lines are drawn. + + Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid + lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. +*/ +void QCPGrid::setZeroLinePen(const QPen &pen) +{ + mZeroLinePen = pen; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing the major grid lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); +} + +/*! \internal + + Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning + over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). +*/ +void QCPGrid::draw(QCPPainter *painter) +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + if (mParentAxis->subTicks() && mSubGridVisible) + drawSubGridLines(painter); + drawGridLines(painter); +} + +/*! \internal + + Draws the main grid lines and possibly a zero line with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + const int tickCount = mParentAxis->mTickVector.size(); + double t; // helper variable, result of coordinate-to-pixel transforms + if (mParentAxis->orientation() == Qt::Horizontal) + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + +/*! \internal + + Draws the sub grid lines with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawSubGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); + double t; // helper variable, result of coordinate-to-pixel transforms + painter->setPen(mSubGridPen); + if (mParentAxis->orientation() == Qt::Horizontal) + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxis +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxis + \brief Manages a single axis inside a QCustomPlot. + + Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via + QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and + QCustomPlot::yAxis2 (right). + + Axes are always part of an axis rect, see QCPAxisRect. + \image html AxisNamesOverview.png +
Naming convention of axis parts
+ \n + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line + on the left represents the QCustomPlot widget border.
+ + Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and + tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of + the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the + documentation of QCPAxisTicker. +*/ + +/* start of documentation of inline functions */ + +/*! \fn Qt::Orientation QCPAxis::orientation() const + + Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced + from the axis type (left, top, right or bottom). + + \see orientation(AxisType type), pixelOrientation +*/ + +/*! \fn QCPGrid *QCPAxis::grid() const + + Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the + grid is displayed. +*/ + +/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) + + Returns the orientation of the specified axis type + + \see orientation(), pixelOrientation +*/ + +/*! \fn int QCPAxis::pixelOrientation() const + + Returns which direction points towards higher coordinate values/keys, in pixel space. + + This method returns either 1 or -1. If it returns 1, then going in the positive direction along + the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. + On the other hand, if this method returns -1, going to smaller pixel values corresponds to going + from lower to higher axis coordinates. + + For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, + without having to care about reversed or vertically aligned axes: + + \code + double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); + \endcode + + \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. +*/ + +/*! \fn QSharedPointer QCPAxis::ticker() const + + Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is + responsible for generating the tick positions and tick labels of this axis. You can access the + \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count + (\ref QCPAxisTicker::setTickCount). + + You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see + the documentation there. A new axis ticker can be set with \ref setTicker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see setTicker +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) + + This signal is emitted when the range of this axis has changed. You can connect it to the \ref + setRange slot of another axis to communicate the new range to the other axis, in order for it to + be synchronized. + + You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. + This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper + range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following + slot would limit the x axis to ranges between 0 and 10: + \code + customPlot->xAxis->setRange(newRange.bounded(0, 10)) + \endcode +*/ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) + \overload + + Additionally to the new range, this signal also provides the previous range held by the axis as + \a oldRange. +*/ + +/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the scale type changes, by calls to \ref setScaleType +*/ + +/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) + + This signal is emitted when the selection state of this axis has changed, either by user interaction + or by a direct call to \ref setSelectedParts. +*/ + +/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); + + This signal is emitted when the selectability changes, by calls to \ref setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs an Axis instance of Type \a type for the axis rect \a parent. + + Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create + them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, + create them manually and then inject them also via \ref QCPAxisRect::addAxis. +*/ +QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : + QCPLayerable(parent->parentPlot(), QString(), parent), + // axis base: + mAxisType(type), + mAxisRect(parent), + mPadding(5), + mOrientation(orientation(type)), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + mTickLabels(true), + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedTickPen(QPen(Qt::blue, 2)), + mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedSubTickPen(QPen(Qt::blue, 2)), + // scale and range: + mRange(0, 5), + mRangeReversed(false), + mScaleType(stLinear), + // internal members: + mGrid(new QCPGrid(this)), + mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), + mTicker(new QCPAxisTicker), + mCachedMarginValid(false), + mCachedMargin(0) +{ + setParent(parent); + mGrid->setVisible(false); + setAntialiased(false); + setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again + + if (type == atTop) + { + setTickLabelPadding(3); + setLabelPadding(6); + } else if (type == atRight) + { + setTickLabelPadding(7); + setLabelPadding(12); + } else if (type == atBottom) + { + setTickLabelPadding(3); + setLabelPadding(3); + } else if (type == atLeft) + { + setTickLabelPadding(5); + setLabelPadding(10); + } +} + +QCPAxis::~QCPAxis() +{ + delete mAxisPainter; + delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLabelPadding() const +{ + return mAxisPainter->tickLabelPadding; +} + +/* No documentation as it is a property getter */ +double QCPAxis::tickLabelRotation() const +{ + return mAxisPainter->tickLabelRotation; +} + +/* No documentation as it is a property getter */ +QCPAxis::LabelSide QCPAxis::tickLabelSide() const +{ + return mAxisPainter->tickLabelSide; +} + +/* No documentation as it is a property getter */ +QString QCPAxis::numberFormat() const +{ + QString result; + result.append(mNumberFormatChar); + if (mNumberBeautifulPowers) + { + result.append(QLatin1Char('b')); + if (mAxisPainter->numberMultiplyCross) + result.append(QLatin1Char('c')); + } + return result; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthIn() const +{ + return mAxisPainter->tickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthOut() const +{ + return mAxisPainter->tickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthIn() const +{ + return mAxisPainter->subTickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthOut() const +{ + return mAxisPainter->subTickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::labelPadding() const +{ + return mAxisPainter->labelPadding; +} + +/* No documentation as it is a property getter */ +int QCPAxis::offset() const +{ + return mAxisPainter->offset; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::lowerEnding() const +{ + return mAxisPainter->lowerEnding; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::upperEnding() const +{ + return mAxisPainter->upperEnding; +} + +/*! + Sets whether the axis uses a linear scale or a logarithmic scale. + + Note that this method controls the coordinate transformation. You will likely also want to use a + logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref + QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the + details of logarithmic axis tick creation. + + \ref setNumberPrecision +*/ +void QCPAxis::setScaleType(QCPAxis::ScaleType type) +{ + if (mScaleType != type) + { + mScaleType = type; + if (mScaleType == stLogarithmic) + setRange(mRange.sanitizedForLogScale()); + mCachedMarginValid = false; + emit scaleTypeChanged(mScaleType); + } +} + +/*! + Sets the range of the axis. + + This slot may be connected with the \ref rangeChanged signal of another axis so this axis + is always synchronized with the other axis range, when it changes. + + To invert the direction of an axis, use \ref setRangeReversed. +*/ +void QCPAxis::setRange(const QCPRange &range) +{ + if (range.lower == mRange.lower && range.upper == mRange.upper) + return; + + if (!QCPRange::validRange(range)) return; + QCPRange oldRange = mRange; + if (mScaleType == stLogarithmic) + { + mRange = range.sanitizedForLogScale(); + } else + { + mRange = range.sanitizedForLinScale(); + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains iSelectAxes.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPAxis::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + emit selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font. + + The entire selection mechanism for axes is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you + wish to change the selection state manually. + + This function can change the selection state of a part, independent of the \ref setSelectableParts setting. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, + setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor +*/ +void QCPAxis::setSelectedParts(const SelectableParts &selected) +{ + if (mSelectedParts != selected) + { + mSelectedParts = selected; + emit selectionChanged(mSelectedParts); + } +} + +/*! + \overload + + Sets the lower and upper bound of the axis range. + + To invert the direction of an axis, use \ref setRangeReversed. + + There is also a slot to set a range, see \ref setRange(const QCPRange &range). +*/ +void QCPAxis::setRange(double lower, double upper) +{ + if (lower == mRange.lower && upper == mRange.upper) + return; + + if (!QCPRange::validRange(lower, upper)) return; + QCPRange oldRange = mRange; + mRange.lower = lower; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + \overload + + Sets the range of the axis. + + The \a position coordinate indicates together with the \a alignment parameter, where the new + range will be positioned. \a size defines the size of the new axis range. \a alignment may be + Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, + or center of the range to be aligned with \a position. Any other values of \a alignment will + default to Qt::AlignCenter. +*/ +void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) +{ + if (alignment == Qt::AlignLeft) + setRange(position, position+size); + else if (alignment == Qt::AlignRight) + setRange(position-size, position); + else // alignment == Qt::AlignCenter + setRange(position-size/2.0, position+size/2.0); +} + +/*! + Sets the lower bound of the axis range. The upper bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeLower(double lower) +{ + if (mRange.lower == lower) + return; + + QCPRange oldRange = mRange; + mRange.lower = lower; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + Sets the upper bound of the axis range. The lower bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeUpper(double upper) +{ + if (mRange.upper == upper) + return; + + QCPRange oldRange = mRange; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal + axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the + direction of increasing values is inverted. + + Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part + of the \ref setRange interface will still reference the mathematically smaller number than the \a + upper part. +*/ +void QCPAxis::setRangeReversed(bool reversed) +{ + mRangeReversed = reversed; +} + +/*! + The axis ticker is responsible for generating the tick positions and tick labels. See the + documentation of QCPAxisTicker for details on how to work with axis tickers. + + You can change the tick positioning/labeling behaviour of this axis by setting a different + QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis + ticker, access it via \ref ticker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see ticker +*/ +void QCPAxis::setTicker(QSharedPointer ticker) +{ + if (ticker) + mTicker = ticker; + else + qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; + // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector +} + +/*! + Sets whether tick marks are displayed. + + Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve + that, see \ref setTickLabels. + + \see setSubTicks +*/ +void QCPAxis::setTicks(bool show) +{ + if (mTicks != show) + { + mTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. +*/ +void QCPAxis::setTickLabels(bool show) +{ + if (mTickLabels != show) + { + mTickLabels = show; + mCachedMarginValid = false; + if (!mTickLabels) + mTickVectorLabels.clear(); + } +} + +/*! + Sets the distance between the axis base line (including any outward ticks) and the tick labels. + \see setLabelPadding, setPadding +*/ +void QCPAxis::setTickLabelPadding(int padding) +{ + if (mAxisPainter->tickLabelPadding != padding) + { + mAxisPainter->tickLabelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the font of the tick labels. + + \see setTickLabels, setTickLabelColor +*/ +void QCPAxis::setTickLabelFont(const QFont &font) +{ + if (font != mTickLabelFont) + { + mTickLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the tick labels. + + \see setTickLabels, setTickLabelFont +*/ +void QCPAxis::setTickLabelColor(const QColor &color) +{ + mTickLabelColor = color; +} + +/*! + Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, + the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values + from -90 to 90 degrees. + + If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For + other angles, the label is drawn with an offset such that it seems to point toward or away from + the tick mark. +*/ +void QCPAxis::setTickLabelRotation(double degrees) +{ + if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) + { + mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); + mCachedMarginValid = false; + } +} + +/*! + Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. + + The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels + to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels + appear on the inside are additionally clipped to the axis rect. +*/ +void QCPAxis::setTickLabelSide(LabelSide side) +{ + mAxisPainter->tickLabelSide = side; + mCachedMarginValid = false; +} + +/*! + Sets the number format for the numbers in tick labels. This \a formatCode is an extended version + of the format code used e.g. by QString::number() and QLocale::toString(). For reference about + that, see the "Argument Formats" section in the detailed description of the QString class. + + \a formatCode is a string of one, two or three characters. The first character is identical to + the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed + format, 'g'/'G' scientific or fixed, whichever is shorter. + + The second and third characters are optional and specific to QCustomPlot:\n + If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. + "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for + "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 + [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. + If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can + be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the + cross and 183 (0xB7) for the dot. + + Examples for \a formatCode: + \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, + normal scientific format is used + \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with + beautifully typeset decimal powers and a dot as multiplication sign + \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as + multiplication sign + \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal + powers. Format code will be reduced to 'f'. + \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format + code will not be changed. +*/ +void QCPAxis::setNumberFormat(const QString &formatCode) +{ + if (formatCode.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; + return; + } + mCachedMarginValid = false; + + // interpret first char as number format char: + QString allowedFormatChars(QLatin1String("eEfgG")); + if (allowedFormatChars.contains(formatCode.at(0))) + { + mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; + return; + } + if (formatCode.length() < 2) + { + mNumberBeautifulPowers = false; + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret second char as indicator for beautiful decimal powers: + if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) + { + mNumberBeautifulPowers = true; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; + return; + } + if (formatCode.length() < 3) + { + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret third char as indicator for dot or cross multiplication symbol: + if (formatCode.at(2) == QLatin1Char('c')) + { + mAxisPainter->numberMultiplyCross = true; + } else if (formatCode.at(2) == QLatin1Char('d')) + { + mAxisPainter->numberMultiplyCross = false; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; + return; + } +} + +/*! + Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) + for details. The effect of precisions are most notably for number Formats starting with 'e', see + \ref setNumberFormat +*/ +void QCPAxis::setNumberPrecision(int precision) +{ + if (mNumberPrecision != precision) + { + mNumberPrecision = precision; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the + plot and \a outside is the length they will reach outside the plot. If \a outside is greater than + zero, the tick labels and axis label will increase their distance to the axis accordingly, so + they won't collide with the ticks. + + \see setSubTickLength, setTickLengthIn, setTickLengthOut +*/ +void QCPAxis::setTickLength(int inside, int outside) +{ + setTickLengthIn(inside); + setTickLengthOut(outside); +} + +/*! + Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach + inside the plot. + + \see setTickLengthOut, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthIn(int inside) +{ + if (mAxisPainter->tickLengthIn != inside) + { + mAxisPainter->tickLengthIn = inside; + } +} + +/*! + Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach + outside the plot. If \a outside is greater than zero, the tick labels and axis label will + increase their distance to the axis accordingly, so they won't collide with the ticks. + + \see setTickLengthIn, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthOut(int outside) +{ + if (mAxisPainter->tickLengthOut != outside) + { + mAxisPainter->tickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets whether sub tick marks are displayed. + + Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) + + \see setTicks +*/ +void QCPAxis::setSubTicks(bool show) +{ + if (mSubTicks != show) + { + mSubTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside + the plot and \a outside is the length they will reach outside the plot. If \a outside is greater + than zero, the tick labels and axis label will increase their distance to the axis accordingly, + so they won't collide with the ticks. + + \see setTickLength, setSubTickLengthIn, setSubTickLengthOut +*/ +void QCPAxis::setSubTickLength(int inside, int outside) +{ + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); +} + +/*! + Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside + the plot. + + \see setSubTickLengthOut, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthIn(int inside) +{ + if (mAxisPainter->subTickLengthIn != inside) + { + mAxisPainter->subTickLengthIn = inside; + } +} + +/*! + Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach + outside the plot. If \a outside is greater than zero, the tick labels will increase their + distance to the axis accordingly, so they won't collide with the ticks. + + \see setSubTickLengthIn, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthOut(int outside) +{ + if (mAxisPainter->subTickLengthOut != outside) + { + mAxisPainter->subTickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets the pen, the axis base line is drawn with. + + \see setTickPen, setSubTickPen +*/ +void QCPAxis::setBasePen(const QPen &pen) +{ + mBasePen = pen; +} + +/*! + Sets the pen, tick marks will be drawn with. + + \see setTickLength, setBasePen +*/ +void QCPAxis::setTickPen(const QPen &pen) +{ + mTickPen = pen; +} + +/*! + Sets the pen, subtick marks will be drawn with. + + \see setSubTickCount, setSubTickLength, setBasePen +*/ +void QCPAxis::setSubTickPen(const QPen &pen) +{ + mSubTickPen = pen; +} + +/*! + Sets the font of the axis label. + + \see setLabelColor +*/ +void QCPAxis::setLabelFont(const QFont &font) +{ + if (mLabelFont != font) + { + mLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the axis label. + + \see setLabelFont +*/ +void QCPAxis::setLabelColor(const QColor &color) +{ + mLabelColor = color; +} + +/*! + Sets the text of the axis label that will be shown below/above or next to the axis, depending on + its orientation. To disable axis labels, pass an empty string as \a str. +*/ +void QCPAxis::setLabel(const QString &str) +{ + if (mLabel != str) + { + mLabel = str; + mCachedMarginValid = false; + } +} + +/*! + Sets the distance between the tick labels and the axis label. + + \see setTickLabelPadding, setPadding +*/ +void QCPAxis::setLabelPadding(int padding) +{ + if (mAxisPainter->labelPadding != padding) + { + mAxisPainter->labelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the padding of the axis. + + When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, + that is left blank. + + The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. + + \see setLabelPadding, setTickLabelPadding +*/ +void QCPAxis::setPadding(int padding) +{ + if (mPadding != padding) + { + mPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the offset the axis has to its axis rect side. + + If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, + only the offset of the inner most axis has meaning (even if it is set to be invisible). The + offset of the other, outer axes is controlled automatically, to place them at appropriate + positions. +*/ +void QCPAxis::setOffset(int offset) +{ + mAxisPainter->offset = offset; +} + +/*! + Sets the font that is used for tick labels when they are selected. + + \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelFont(const QFont &font) +{ + if (font != mSelectedTickLabelFont) + { + mSelectedTickLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts + } +} + +/*! + Sets the font that is used for the axis label when it is selected. + + \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelFont(const QFont &font) +{ + mSelectedLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts +} + +/*! + Sets the color that is used for tick labels when they are selected. + + \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelColor(const QColor &color) +{ + if (color != mSelectedTickLabelColor) + { + mSelectedTickLabelColor = color; + } +} + +/*! + Sets the color that is used for the axis label when it is selected. + + \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelColor(const QColor &color) +{ + mSelectedLabelColor = color; +} + +/*! + Sets the pen that is used to draw the axis base line when selected. + + \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedBasePen(const QPen &pen) +{ + mSelectedBasePen = pen; +} + +/*! + Sets the pen that is used to draw the (major) ticks when selected. + + \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickPen(const QPen &pen) +{ + mSelectedTickPen = pen; +} + +/*! + Sets the pen that is used to draw the subticks when selected. + + \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedSubTickPen(const QPen &pen) +{ + mSelectedSubTickPen = pen; +} + +/*! + Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setUpperEnding +*/ +void QCPAxis::setLowerEnding(const QCPLineEnding &ending) +{ + mAxisPainter->lowerEnding = ending; +} + +/*! + Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the right ending, for vertical axes the top ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setLowerEnding +*/ +void QCPAxis::setUpperEnding(const QCPLineEnding &ending) +{ + mAxisPainter->upperEnding = ending; +} + +/*! + If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper + bounds of the range. The range is simply moved by \a diff. + + If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This + corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). +*/ +void QCPAxis::moveRange(double diff) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + mRange.lower += diff; + mRange.upper += diff; + } else // mScaleType == stLogarithmic + { + mRange.lower *= diff; + mRange.upper *= diff; + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis by \a factor around the center of the current axis range. For + example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis + range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around + the center will have moved symmetrically closer). + + If you wish to scale around a different coordinate than the current axis range center, use the + overload \ref scaleRange(double factor, double center). +*/ +void QCPAxis::scaleRange(double factor) +{ + scaleRange(factor, range().center()); +} + +/*! \overload + + Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a + factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at + coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates + around 1.0 will have moved symmetrically closer to 1.0). + + \see scaleRange(double factor) +*/ +void QCPAxis::scaleRange(double factor, double center) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + QCPRange newRange; + newRange.lower = (mRange.lower-center)*factor + center; + newRange.upper = (mRange.upper-center)*factor + center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLinScale(); + } else // mScaleType == stLogarithmic + { + if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range + { + QCPRange newRange; + newRange.lower = qPow(mRange.lower/center, factor)*center; + newRange.upper = qPow(mRange.upper/center, factor)*center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLogScale(); + } else + qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; + } + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will + be done around the center of the current axis range. + + For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs + plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the + axis rect has. + + This is an operation that changes the range of this axis once, it doesn't fix the scale ratio + indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent + won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent + will follow. +*/ +void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) +{ + int otherPixelSize, ownPixelSize; + + if (otherAxis->orientation() == Qt::Horizontal) + otherPixelSize = otherAxis->axisRect()->width(); + else + otherPixelSize = otherAxis->axisRect()->height(); + + if (orientation() == Qt::Horizontal) + ownPixelSize = axisRect()->width(); + else + ownPixelSize = axisRect()->height(); + + double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; + setRange(range().center(), newRangeSize, Qt::AlignCenter); +} + +/*! + Changes the axis range such that all plottables associated with this axis are fully visible in + that dimension. + + \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes +*/ +void QCPAxis::rescale(bool onlyVisiblePlottables) +{ + QList p = plottables(); + QCPRange newRange; + bool haveRange = false; + for (int i=0; irealVisibility() && onlyVisiblePlottables) + continue; + QCPRange plottableRange; + bool currentFoundRange; + QCP::SignDomain signDomain = QCP::sdBoth; + if (mScaleType == stLogarithmic) + signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + if (p.at(i)->keyAxis() == this) + plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); + else + plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); + if (currentFoundRange) + { + if (!haveRange) + newRange = plottableRange; + else + newRange.expand(plottableRange); + haveRange = true; + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mScaleType == stLinear) + { + newRange.lower = center-mRange.size()/2.0; + newRange.upper = center+mRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mRange.upper/mRange.lower); + newRange.upper = center*qSqrt(mRange.upper/mRange.lower); + } + } + setRange(newRange); + } +} + +/*! + Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. +*/ +double QCPAxis::pixelToCoord(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; + else + return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; + else + return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; + } + } +} + +/*! + Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. +*/ +double QCPAxis::coordToPixel(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + else + return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; + else + { + if (!mRangeReversed) + return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + else + return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + } + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); + else + return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; + else + { + if (!mRangeReversed) + return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + else + return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + } + } + } +} + +/*! + Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function + is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this + function does not change the current selection state of the axis. + + If the axis is not visible (\ref setVisible), this function always returns \ref spNone. + + \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions +*/ +QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const +{ + if (!mVisible) + return spNone; + + if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) + return spAxis; + else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) + return spTickLabels; + else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) + return spAxisLabel; + else + return spNone; +} + +/* inherits documentation from base class */ +double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) + return -1; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; +} + +/*! + Returns a list of all the plottables that have this axis as key or value axis. + + If you are only interested in plottables of type QCPGraph, see \ref graphs. + + \see graphs, items +*/ +QList QCPAxis::plottables() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that have this axis as key or value axis. + + \see plottables, items +*/ +QList QCPAxis::graphs() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis. An item is considered + associated with an axis if at least one of its positions uses the axis as key or value axis. + + \see plottables, graphs +*/ +QList QCPAxis::items() const +{ + QList result; + if (!mParentPlot) return result; + + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to + QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) +*/ +QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return atLeft; + case QCP::msRight: return atRight; + case QCP::msTop: return atTop; + case QCP::msBottom: return atBottom; + default: break; + } + qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; + return atLeft; +} + +/*! + Returns the axis type that describes the opposite axis of an axis with the specified \a type. +*/ +QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) +{ + switch (type) + { + case atLeft: return atRight; break; + case atRight: return atLeft; break; + case atBottom: return atTop; break; + case atTop: return atBottom; break; + default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; + } +} + +/* inherits documentation from base class */ +void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + SelectablePart part = details.value(); + if (mSelectableParts.testFlag(part)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^part : part); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAxis::deselectEvent(bool *selectionStateChanged) +{ + SelectableParts selBefore = mSelectedParts; + setSelectedParts(mSelectedParts & ~mSelectableParts); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis + (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref + QCPAxisRect::setRangeDragAxes) + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. +*/ +void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || + !mAxisRect->rangeDrag().testFlag(orientation()) || + !mAxisRect->rangeDragAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + mDragStartRange = mRange; + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (mDragging) + { + const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); + const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); + if (mScaleType == QCPAxis::stLinear) + { + const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); + setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); + } else if (mScaleType == QCPAxis::stLogarithmic) + { + const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); + setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); + } + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user zoom individual axes + exclusively, by performing the wheel event on top of the axis. + + For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis + (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref + QCPAxisRect::setRangeZoomAxes) + + \seebaseclassmethod + + \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the + axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. +*/ +void QCPAxis::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || + !mAxisRect->rangeZoom().testFlag(orientation()) || + !mAxisRect->rangeZoomAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); + scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); + mParentPlot->replot(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing axis lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); +} + +/*! \internal + + Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. + + \seebaseclassmethod +*/ +void QCPAxis::draw(QCPPainter *painter) +{ + QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + subTickPositions.reserve(mSubTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->basePen = getBasePen(); + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->labelColor = getLabelColor(); + mAxisPainter->label = mLabel; + mAxisPainter->substituteExponent = mNumberBeautifulPowers; + mAxisPainter->tickPen = getTickPen(); + mAxisPainter->subTickPen = getSubTickPen(); + mAxisPainter->tickLabelFont = getTickLabelFont(); + mAxisPainter->tickLabelColor = getTickLabelColor(); + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; + mAxisPainter->reversedEndings = mRangeReversed; + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + mAxisPainter->subTickPositions = subTickPositions; + mAxisPainter->draw(painter); +} + +/*! \internal + + Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling + QCPAxisTicker::generate on the currently installed ticker. + + If a change in the label text/count is detected, the cached axis margin is invalidated to make + sure the next margin calculation recalculates the label sizes and returns an up-to-date value. +*/ +void QCPAxis::setupTickVectors() +{ + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; + + QVector oldLabels = mTickVectorLabels; + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too +} + +/*! \internal + + Returns the pen that is used to draw the axis base line. Depending on the selection state, this + is either mSelectedBasePen or mBasePen. +*/ +QPen QCPAxis::getBasePen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; +} + +/*! \internal + + Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this + is either mSelectedTickPen or mTickPen. +*/ +QPen QCPAxis::getTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; +} + +/*! \internal + + Returns the pen that is used to draw the subticks. Depending on the selection state, this + is either mSelectedSubTickPen or mSubTickPen. +*/ +QPen QCPAxis::getSubTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; +} + +/*! \internal + + Returns the font that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelFont or mTickLabelFont. +*/ +QFont QCPAxis::getTickLabelFont() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; +} + +/*! \internal + + Returns the font that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelFont or mLabelFont. +*/ +QFont QCPAxis::getLabelFont() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; +} + +/*! \internal + + Returns the color that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelColor or mTickLabelColor. +*/ +QColor QCPAxis::getTickLabelColor() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; +} + +/*! \internal + + Returns the color that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelColor or mLabelColor. +*/ +QColor QCPAxis::getLabelColor() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; +} + +/*! \internal + + Returns the appropriate outward margin for this axis. It is needed if \ref + QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref + atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom + margin and so forth. For the calculation, this function goes through similar steps as \ref draw, + so changing one function likely requires the modification of the other one as well. + + The margin consists of the outward tick length, tick label padding, tick label size, label + padding, label size, and padding. + + The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. + unchanged are very fast. +*/ +int QCPAxis::calculateMargin() +{ + if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis + return 0; + + if (mCachedMarginValid) + return mCachedMargin; + + // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels + int margin = 0; + + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->label = mLabel; + mAxisPainter->tickLabelFont = mTickLabelFont; + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + margin += mAxisPainter->size(); + margin += mPadding; + + mCachedMargin = margin; + mCachedMarginValid = true; + return margin; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAxis::selectionCategory() const +{ + return QCP::iSelectAxes; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisPainterPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisPainterPrivate + + \internal + \brief (Private) + + This is a private class and not part of the public QCustomPlot interface. + + It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and + axis label. It also buffers the labels to reduce replot times. The parameters are configured by + directly accessing the public member variables. +*/ + +/*! + Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every + redraw, to utilize the caching mechanisms. +*/ +QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : + type(QCPAxis::atLeft), + basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + lowerEnding(QCPLineEnding::esNone), + upperEnding(QCPLineEnding::esNone), + labelPadding(0), + tickLabelPadding(0), + tickLabelRotation(0), + tickLabelSide(QCPAxis::lsOutside), + substituteExponent(true), + numberMultiplyCross(false), + tickLengthIn(5), + tickLengthOut(0), + subTickLengthIn(2), + subTickLengthOut(0), + tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + offset(0), + abbreviateDecimalPowers(false), + reversedEndings(false), + mParentPlot(parentPlot), + mLabelCache(16) // cache at most 16 (tick) labels +{ +} + +QCPAxisPainterPrivate::~QCPAxisPainterPrivate() +{ +} + +/*! \internal + + Draws the axis with the specified \a painter. + + The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set + here, too. +*/ +void QCPAxisPainterPrivate::draw(QCPPainter *painter) +{ + QByteArray newHash = generateLabelParameterHash(); + if (newHash != mLabelParameterHash) + { + mLabelCache.clear(); + mLabelParameterHash = newHash; + } + + QPoint origin; + switch (type) + { + case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; + case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; + case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; + case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; + } + + double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) + switch (type) + { + case QCPAxis::atTop: yCor = -1; break; + case QCPAxis::atRight: xCor = 1; break; + default: break; + } + int margin = 0; + // draw baseline: + QLineF baseLine; + painter->setPen(basePen); + if (QCPAxis::orientation(type) == Qt::Horizontal) + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); + else + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); + if (reversedEndings) + baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later + painter->drawLine(baseLine); + + // draw ticks: + if (!tickPositions.isEmpty()) + { + painter->setPen(tickPen); + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); + } + } + + // draw subticks: + if (!subTickPositions.isEmpty()) + { + painter->setPen(subTickPen); + // direction of ticks ("inward" is right for left axis and left for right axis) + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); + } + } + margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // draw axis base endings: + bool antialiasingBackup = painter->antialiasing(); + painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't + painter->setBrush(QBrush(basePen.color())); + QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); + if (lowerEnding.style() != QCPLineEnding::esNone) + lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); + if (upperEnding.style() != QCPLineEnding::esNone) + upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); + painter->setAntialiasing(antialiasingBackup); + + // tick labels: + QRect oldClipRect; + if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect + { + oldClipRect = painter->clipRegion().boundingRect(); + painter->setClipRect(axisRect); + } + QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label + if (!tickLabels.isEmpty()) + { + if (tickLabelSide == QCPAxis::lsOutside) + margin += tickLabelPadding; + painter->setFont(tickLabelFont); + painter->setPen(QPen(tickLabelColor)); + const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); + int distanceToAxis = margin; + if (tickLabelSide == QCPAxis::lsInside) + distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + for (int i=0; isetClipRect(oldClipRect); + + // axis label: + QRect labelBounds; + if (!label.isEmpty()) + { + margin += labelPadding; + painter->setFont(labelFont); + painter->setPen(QPen(labelColor)); + labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); + if (type == QCPAxis::atLeft) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); + painter->rotate(-90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atRight) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); + painter->rotate(90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atTop) + painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + else if (type == QCPAxis::atBottom) + painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + } + + // set selection boxes: + int selectionTolerance = 0; + if (mParentPlot) + selectionTolerance = mParentPlot->selectionTolerance(); + else + qDebug() << Q_FUNC_INFO << "mParentPlot is null"; + int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); + int selAxisInSize = selectionTolerance; + int selTickLabelSize; + int selTickLabelOffset; + if (tickLabelSide == QCPAxis::lsOutside) + { + selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; + } else + { + selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + } + int selLabelSize = labelBounds.height(); + int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; + if (type == QCPAxis::atLeft) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atRight) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atTop) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); + } else if (type == QCPAxis::atBottom) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); + } + mAxisSelectionBox = mAxisSelectionBox.normalized(); + mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); + mLabelSelectionBox = mLabelSelectionBox.normalized(); + // draw hitboxes for debug purposes: + //painter->setBrush(Qt::NoBrush); + //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); +} + +/*! \internal + + Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone + direction) needed to fit the axis. +*/ +int QCPAxisPainterPrivate::size() const +{ + int result = 0; + + // get length of tick marks pointing outwards: + if (!tickPositions.isEmpty()) + result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // calculate size of tick labels: + if (tickLabelSide == QCPAxis::lsOutside) + { + QSize tickLabelsSize(0, 0); + if (!tickLabels.isEmpty()) + { + for (int i=0; ibufferDevicePixelRatio())); + result.append(QByteArray::number(tickLabelRotation)); + result.append(QByteArray::number((int)tickLabelSide)); + result.append(QByteArray::number((int)substituteExponent)); + result.append(QByteArray::number((int)numberMultiplyCross)); + result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); + result.append(tickLabelFont.toString().toLatin1()); + return result; +} + +/*! \internal + + Draws a single tick label with the provided \a painter, utilizing the internal label cache to + significantly speed up drawing of labels that were drawn in previous calls. The tick label is + always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in + pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence + for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), + at which the label should be drawn. + + In order to later draw the axis label in a place that doesn't overlap with the tick labels, the + largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref + drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a + tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently + holds. + + The label is drawn with the font and pen that are currently set on the \a painter. To draw + superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref + getTickLabelData). +*/ +void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) +{ + // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! + if (text.isEmpty()) return; + QSize finalSize; + QPointF labelAnchor; + switch (type) + { + case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; + case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; + case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; + case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; + } + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled + { + CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache + if (!cachedLabel) // no cached label existed, create it + { + cachedLabel = new CachedLabel; + TickLabelData labelData = getTickLabelData(painter->font(), text); + cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); + if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) + { + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif +#endif + } else + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); + cachedLabel->pixmap.fill(Qt::transparent); + QCPPainter cachePainter(&cachedLabel->pixmap); + cachePainter.setPen(painter->pen()); + drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); + } + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); + else + labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } + mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created + } else // label caching disabled, draw text directly on surface: + { + TickLabelData labelData = getTickLabelData(painter->font(), text); + QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); + else + labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); + finalSize = labelData.rotatedTotalBounds.size(); + } + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a + y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to + directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when + QCP::phCacheLabels plotting hint is not set. +*/ +void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const +{ + // backup painter settings that we're about to change: + QTransform oldTransform = painter->transform(); + QFont oldFont = painter->font(); + + // transform painter to position/rotation: + painter->translate(x, y); + if (!qFuzzyIsNull(tickLabelRotation)) + painter->rotate(tickLabelRotation); + + // draw text: + if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); + if (!labelData.suffixPart.isEmpty()) + painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); + painter->setFont(labelData.expFont); + painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); + } else + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); + } + + // reset painter settings to what it was before: + painter->setTransform(oldTransform); + painter->setFont(oldFont); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Transforms the passed \a text and \a font to a tickLabelData structure that can then be further + processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and + exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. +*/ +QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const +{ + TickLabelData result; + + // determine whether beautiful decimal powers should be used + bool useBeautifulPowers = false; + int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart + int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart + if (substituteExponent) + { + ePos = text.indexOf(QLatin1Char('e')); + if (ePos > 0 && text.at(ePos-1).isDigit()) + { + eLast = ePos; + while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) + ++eLast; + if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power + useBeautifulPowers = true; + } + } + + // calculate text bounding rects and do string preparation for beautiful decimal powers: + result.baseFont = font; + if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line + result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding + if (useBeautifulPowers) + { + // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: + result.basePart = text.left(ePos); + result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent + // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: + if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) + result.basePart = QLatin1String("10"); + else + result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); + result.expPart = text.mid(ePos+1, eLast-ePos); + // clip "+" and leading zeros off expPart: + while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' + result.expPart.remove(1, 1); + if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) + result.expPart.remove(0, 1); + // prepare smaller font for exponent: + result.expFont = font; + if (result.expFont.pointSize() > 0) + result.expFont.setPointSize(result.expFont.pointSize()*0.75); + else + result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); + // calculate bounding rects of base part(s), exponent part and total one: + result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); + result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); + if (!result.suffixPart.isEmpty()) + result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); + result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA + } else // useBeautifulPowers == false + { + result.basePart = text; + result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); + } + result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler + + // calculate possibly different bounding rect after rotation: + result.rotatedTotalBounds = result.totalBounds; + if (!qFuzzyIsNull(tickLabelRotation)) + { + QTransform transform; + transform.rotate(tickLabelRotation); + result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); + } + + return result; +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Calculates the offset at which the top left corner of the specified tick label shall be drawn. + The offset is relative to a point right next to the tick the label belongs to. + + This function is thus responsible for e.g. centering tick labels under ticks and positioning them + appropriately when they are rotated. +*/ +QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const +{ + /* + calculate label offset from base point at tick (non-trivial, for best visual appearance): short + explanation for bottom axis: The anchor, i.e. the point in the label that is placed + horizontally under the corresponding tick is always on the label side that is closer to the + axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height + is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text + will be centered under the tick (i.e. displaced horizontally by half its height). At the same + time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick + labels. + */ + bool doRotation = !qFuzzyIsNull(tickLabelRotation); + bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. + double radians = tickLabelRotation/180.0*M_PI; + int x=0, y=0; + if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); + y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = -labelData.totalBounds.width(); + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = 0; + y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = 0; + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; + y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); + } else + { + x = -qSin(-radians)*labelData.totalBounds.height()/2.0; + y = -qCos(-radians)*labelData.totalBounds.height(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = -labelData.totalBounds.height(); + } + } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height()/2.0; + y = 0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; + y = +qSin(-radians)*labelData.totalBounds.width(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = 0; + } + } + + return QPointF(x, y); +} + +/*! \internal + + Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label + to be drawn, depending on number format etc. Since only the largest tick label is wanted for the + margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a + smaller width/height. +*/ +void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const +{ + // note: this function must return the same tick label sizes as the placeTickLabel function. + QSize finalSize; + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label + { + const CachedLabel *cachedLabel = mLabelCache.object(text); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } else // label caching disabled or no label with this text cached: + { + TickLabelData labelData = getTickLabelData(font, text); + finalSize = labelData.rotatedTotalBounds.size(); + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} +/* end of 'src/axis/axis.cpp' */ + + +/* including file 'src/scatterstyle.cpp', size 17450 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPScatterStyle +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPScatterStyle + \brief Represents the visual appearance of scatter points + + This class holds information about shape, color and size of scatter points. In plottables like + QCPGraph it is used to store how scatter points shall be drawn. For example, \ref + QCPGraph::setScatterStyle takes a QCPScatterStyle instance. + + A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a + fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can + be controlled with \ref setSize. + + \section QCPScatterStyle-defining Specifying a scatter style + + You can set all these configurations either by calling the respective functions on an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 + + Or you can use one of the various constructors that take different parameter combinations, making + it easy to specify a scatter style in a single call, like so: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 + + \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable + + There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref + QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref + isPenDefined will return false. It leads to scatter points that inherit the pen from the + plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line + color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes + it very convenient to set up typical scatter settings: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation + + Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works + because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly + into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) + constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref + ScatterShape, where actually a QCPScatterStyle is expected. + + \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps + + QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. + + For custom shapes, you can provide a QPainterPath with the desired shape to the \ref + setCustomPath function or call the constructor that takes a painter path. The scatter shape will + automatically be set to \ref ssCustom. + + For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the + constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. + Note that \ref setSize does not influence the appearance of the pixmap. +*/ + +/* start documentation of inline functions */ + +/*! \fn bool QCPScatterStyle::isNone() const + + Returns whether the scatter shape is \ref ssNone. + + \see setShape +*/ + +/*! \fn bool QCPScatterStyle::isPenDefined() const + + Returns whether a pen has been defined for this scatter style. + + The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those + are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen + is undefined, the pen of the respective plottable will be used for drawing scatters. + + If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call + \ref undefinePen. + + \see setPen +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle() : + mSize(6), + mShape(ssNone), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or + brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : + mSize(size), + mShape(shape), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + and size to \a size. No brush is defined, i.e. the scatter point will not be filled. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(Qt::NoBrush), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + the brush color to \a fill (with a solid pattern), and size to \a size. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(QBrush(fill)), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the + brush to \a brush, and size to \a size. + + \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen + and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n + QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n + doesn't necessarily lead C++ to use this constructor in some cases, but might mistake + Qt::NoPen for a QColor and use the + \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) + constructor instead (which will lead to an unexpected look of the scatter points). To prevent + this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) + instead of just Qt::blue, to clearly point out to the compiler that this constructor is + wanted. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(shape), + mPen(pen), + mBrush(brush), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape + is set to \ref ssPixmap. +*/ +QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : + mSize(5), + mShape(ssPixmap), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPixmap(pixmap), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The + scatter shape is set to \ref ssCustom. + + The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly + different meaning than for built-in scatter points: The custom path will be drawn scaled by a + factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its + original size by default. To for example double the size of the path, set \a size to 12. +*/ +QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(ssCustom), + mPen(pen), + mBrush(brush), + mCustomPath(customPath), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Copies the specified \a properties from the \a other scatter style to this scatter style. +*/ +void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) +{ + if (properties.testFlag(spPen)) + { + setPen(other.pen()); + if (!other.isPenDefined()) + undefinePen(); + } + if (properties.testFlag(spBrush)) + setBrush(other.brush()); + if (properties.testFlag(spSize)) + setSize(other.size()); + if (properties.testFlag(spShape)) + { + setShape(other.shape()); + if (other.shape() == ssPixmap) + setPixmap(other.pixmap()); + else if (other.shape() == ssCustom) + setCustomPath(other.customPath()); + } +} + +/*! + Sets the size (pixel diameter) of the drawn scatter points to \a size. + + \see setShape +*/ +void QCPScatterStyle::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the shape to \a shape. + + Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref + ssPixmap and \ref ssCustom, respectively. + + \see setSize +*/ +void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) +{ + mShape = shape; +} + +/*! + Sets the pen that will be used to draw scatter points to \a pen. + + If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after + a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen + previously by calling this function and now wish to undefine the pen, call \ref undefinePen. + + \see setBrush +*/ +void QCPScatterStyle::setPen(const QPen &pen) +{ + mPenDefined = true; + mPen = pen; +} + +/*! + Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter + shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. + + \see setPen +*/ +void QCPScatterStyle::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the pixmap that will be drawn as scatter point to \a pixmap. + + Note that \ref setSize does not influence the appearance of the pixmap. + + The scatter shape is automatically set to \ref ssPixmap. +*/ +void QCPScatterStyle::setPixmap(const QPixmap &pixmap) +{ + setShape(ssPixmap); + mPixmap = pixmap; +} + +/*! + Sets the custom shape that will be drawn as scatter point to \a customPath. + + The scatter shape is automatically set to \ref ssCustom. +*/ +void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) +{ + setShape(ssCustom); + mCustomPath = customPath; +} + +/*! + Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen + implies). + + A call to \ref setPen will define a pen. +*/ +void QCPScatterStyle::undefinePen() +{ + mPenDefined = false; +} + +/*! + Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an + undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. + + This function is used by plottables (or any class that wants to draw scatters) just before a + number of scatters with this style shall be drawn with the \a painter. + + \see drawShape +*/ +void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const +{ + painter->setPen(mPenDefined ? mPen : defaultPen); + painter->setBrush(mBrush); +} + +/*! + Draws the scatter shape with \a painter at position \a pos. + + This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be + called before scatter points are drawn with \ref drawShape. + + \see applyTo +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const +{ + drawShape(painter, pos.x(), pos.y()); +} + +/*! \overload + Draws the scatter shape with \a painter at position \a x and \a y. +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const +{ + double w = mSize/2.0; + switch (mShape) + { + case ssNone: break; + case ssDot: + { + painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); + break; + } + case ssCross: + { + painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); + painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); + break; + } + case ssPlus: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCircle: + { + painter->drawEllipse(QPointF(x , y), w, w); + break; + } + case ssDisc: + { + QBrush b = painter->brush(); + painter->setBrush(painter->pen().color()); + painter->drawEllipse(QPointF(x , y), w, w); + painter->setBrush(b); + break; + } + case ssSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + break; + } + case ssDiamond: + { + QPointF lineArray[4] = {QPointF(x-w, y), + QPointF( x, y-w), + QPointF(x+w, y), + QPointF( x, y+w)}; + painter->drawPolygon(lineArray, 4); + break; + } + case ssStar: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); + break; + } + case ssTriangle: + { + QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), + QPointF(x+w, y+0.755*w), + QPointF( x, y-0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssTriangleInverted: + { + QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), + QPointF(x+w, y-0.755*w), + QPointF( x, y+0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssCrossSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); + painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); + break; + } + case ssPlusSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCrossCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); + break; + } + case ssPlusCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssPeace: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x, y-w, x, y+w)); + painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); + break; + } + case ssPixmap: + { + const double widthHalf = mPixmap.width()*0.5; + const double heightHalf = mPixmap.height()*0.5; +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) + const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#else + const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#endif + if (clipRect.contains(x, y)) + painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); + break; + } + case ssCustom: + { + QTransform oldTransform = painter->transform(); + painter->translate(x, y); + painter->scale(mSize/6.0, mSize/6.0); + painter->drawPath(mCustomPath); + painter->setTransform(oldTransform); + break; + } + } +} +/* end of 'src/scatterstyle.cpp' */ + +//amalgamation: add datacontainer.cpp + +/* including file 'src/plottable.cpp', size 38845 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecorator +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecorator + \brief Controls how a plottable's data selection is drawn + + Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref + QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. + + The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the + scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref + QCPScatterStyle is itself composed of different properties such as color shape and size, the + decorator allows specifying exactly which of those properties shall be used for the selected data + point, via \ref setUsedScatterProperties. + + A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref + QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance + of selected segments. + + Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is + especially useful since plottables take ownership of the passed selection decorator, and thus the + same decorator instance can not be passed to multiple plottables. + + Selection decorators can also themselves perform drawing operations by reimplementing \ref + drawDecoration, which is called by the plottable's draw method. The base class \ref + QCPSelectionDecorator does not make use of this however. For example, \ref + QCPSelectionDecoratorBracket draws brackets around selected data segments. +*/ + +/*! + Creates a new QCPSelectionDecorator instance with default values +*/ +QCPSelectionDecorator::QCPSelectionDecorator() : + mPen(QColor(80, 80, 255), 2.5), + mBrush(Qt::NoBrush), + mScatterStyle(), + mUsedScatterProperties(QCPScatterStyle::spNone), + mPlottable(0) +{ +} + +QCPSelectionDecorator::~QCPSelectionDecorator() +{ +} + +/*! + Sets the pen that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the scatter style that will be used by the parent plottable to draw scatters in selected + data segments. + + \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the + plottable. The used properties can also be changed via \ref setUsedScatterProperties. +*/ +void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) +{ + mScatterStyle = scatterStyle; + setUsedScatterProperties(usedProperties); +} + +/*! + Use this method to define which properties of the scatter style (set via \ref setScatterStyle) + will be used for selected data segments. All properties of the scatter style that are not + specified in \a properties will remain as specified in the plottable's original scatter style. + + \see QCPScatterStyle::ScatterProperty +*/ +void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) +{ + mUsedScatterProperties = properties; +} + +/*! + Sets the pen of \a painter to the pen of this selection decorator. + + \see applyBrush, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyPen(QCPPainter *painter) const +{ + painter->setPen(mPen); +} + +/*! + Sets the brush of \a painter to the brush of this selection decorator. + + \see applyPen, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const +{ + painter->setBrush(mBrush); +} + +/*! + Returns the scatter style that the parent plottable shall use for selected scatter points. The + plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending + on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this + selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. + + \see applyPen, applyBrush, setScatterStyle +*/ +QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const +{ + QCPScatterStyle result(unselectedStyle); + result.setFromOther(mScatterStyle, mUsedScatterProperties); + + // if style shall inherit pen from plottable (has no own pen defined), give it the selected + // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the + // plottable: + if (!result.isPenDefined()) + result.setPen(mPen); + + return result; +} + +/*! + Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to + this selection decorator. +*/ +void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) +{ + setPen(other->pen()); + setBrush(other->brush()); + setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); +} + +/*! + This method is called by all plottables' draw methods to allow custom selection decorations to be + drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data + selection for which the decoration shall be drawn. + + The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so + this method does nothing. +*/ +void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + Q_UNUSED(painter) + Q_UNUSED(selection) +} + +/*! \internal + + This method is called as soon as a selection decorator is associated with a plottable, by a call + to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access + data points via the \ref QCPAbstractPlottable::interface1D interface). + + If the selection decorator was already added to a different plottable before, this method aborts + the registration and returns false. +*/ +bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottable) + { + mPlottable = plottable; + return true; + } else + { + qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); + return false; + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable + \brief The abstract base class for all data representing objects in a plot. + + It defines a very basic interface like name, pen, brush, visibility etc. Since this class is + abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to + create new ways of displaying data (see "Creating own plottables" below). Plottables that display + one-dimensional data (i.e. data points have a single key dimension and one or multiple values at + each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details + there. + + All further specifics are in the subclasses, for example: + \li A normal graph with possibly a line and/or scatter points \ref QCPGraph + (typically created with \ref QCustomPlot::addGraph) + \li A parametric curve: \ref QCPCurve + \li A bar chart: \ref QCPBars + \li A statistical box plot: \ref QCPStatisticalBox + \li A color encoded two-dimensional map: \ref QCPColorMap + \li An OHLC/Candlestick chart: \ref QCPFinancial + + \section plottables-subclassing Creating own plottables + + Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display + two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) + data dimensions. If you want to display data with only one logical key dimension, you should + rather derive from \ref QCPAbstractPlottable1D. + + If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must + implement: + \li \ref selectTest + \li \ref draw + \li \ref drawLegendIcon + \li \ref getKeyRange + \li \ref getValueRange + + See the documentation of those functions for what they need to do. + + For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot + coordinates to pixel coordinates. This function is quite convenient, because it takes the + orientation of the key and value axes into account for you (x and y are swapped when the key axis + is vertical and the value axis horizontal). If you are worried about performance (i.e. you need + to translate many points in a loop like QCPGraph), you can directly use \ref + QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis + yourself. + + Here are some important members you inherit from QCPAbstractPlottable: + + + + + + + + + + + + + + + + + + + + + + + + + + +
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable + (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable + (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates + to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of + the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. + When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. + Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done + by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
+*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const + + Provides access to the selection decorator of this plottable. The selection decorator controls + how selected data ranges are drawn (e.g. their pen color and fill), see \ref + QCPSelectionDecorator for details. + + If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref + setSelectionDecorator. +*/ + +/*! \fn bool QCPAbstractPlottable::selected() const + + Returns true if there are any data points of the plottable currently selected. Use \ref selection + to retrieve the current \ref QCPDataSelection. +*/ + +/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const + + Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on + this plottable. + + \see selected, setSelection, setSelectable +*/ + +/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() + + If this plottable is a one-dimensional plottable, i.e. it implements the \ref + QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case + of a \ref QCPColorMap) returns zero. + + You can use this method to gain read access to data coordinates while holding a pointer to the + abstract base class only. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of pure virtual functions */ + +/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 + \internal + + called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation + of this plottable inside \a rect, next to the plottable name. + + The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't + appear outside the legend icon border. +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 + + Returns the coordinate range that all data in this plottable span in the key axis dimension. For + logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref + QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only + negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points + will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref + QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could + be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getValueRange +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 + + Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span + in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref + QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign + domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and + all positive points will be ignored for range calculation. For no restriction, just set \a + inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates + whether a range could be found or not. If this is false, you shouldn't use the returned range + (e.g. no points in data). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getKeyRange +*/ + +/* end of documentation of pure virtual functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether + there are any points selected or not. + + \see selectionChanged(const QCPDataSelection &selection) +*/ + +/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selection holds the + currently selected data ranges. + + \see selectionChanged(bool selected) +*/ + +/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); + + This signal is emitted when the selectability of this plottable has changed. + + \see setSelectable +*/ + +/* end of documentation of signals */ + +/*! + Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as + its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance + and have perpendicular orientations. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, + it can't be directly instantiated. + + You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. +*/ +QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), + mName(), + mAntialiasedFill(true), + mAntialiasedScatters(true), + mPen(Qt::black), + mBrush(Qt::NoBrush), + mKeyAxis(keyAxis), + mValueAxis(valueAxis), + mSelectable(QCP::stWhole), + mSelectionDecorator(0) +{ + if (keyAxis->parentPlot() != valueAxis->parentPlot()) + qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; + if (keyAxis->orientation() == valueAxis->orientation()) + qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; + + mParentPlot->registerPlottable(this); + setSelectionDecorator(new QCPSelectionDecorator); +} + +QCPAbstractPlottable::~QCPAbstractPlottable() +{ + if (mSelectionDecorator) + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + The name is the textual representation of this plottable as it is displayed in the legend + (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. +*/ +void QCPAbstractPlottable::setName(const QString &name) +{ + mName = name; +} + +/*! + Sets whether fills of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedFill(bool enabled) +{ + mAntialiasedFill = enabled; +} + +/*! + Sets whether the scatter symbols of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) +{ + mAntialiasedScatters = enabled; +} + +/*! + The pen is used to draw basic lines that make up the plottable representation in the + plot. + + For example, the \ref QCPGraph subclass draws its graph lines with this pen. + + \see setBrush +*/ +void QCPAbstractPlottable::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + The brush is used to draw basic fills of the plottable representation in the + plot. The Fill can be a color, gradient or texture, see the usage of QBrush. + + For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when + it's not set to Qt::NoBrush. + + \see setPen +*/ +void QCPAbstractPlottable::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal + to the plottable's value axis. This function performs no checks to make sure this is the case. + The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the + y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setValueAxis +*/ +void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) +{ + mKeyAxis = axis; +} + +/*! + The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is + orthogonal to the plottable's key axis. This function performs no checks to make sure this is the + case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and + the y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setKeyAxis +*/ +void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) +{ + mValueAxis = axis; +} + + +/*! + Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently + (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref + selectionDecorator). + + The entire selection mechanism for plottables is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when + you wish to change the selection state programmatically. + + Using \ref setSelectable you can further specify for each plottable whether and to which + granularity it is selectable. If \a selection is not compatible with the current \ref + QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted + accordingly (see \ref QCPDataSelection::enforceType). + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractPlottable::setSelection(QCPDataSelection selection) +{ + selection.enforceType(mSelectable); + if (mSelection != selection) + { + mSelection = selection; + emit selectionChanged(selected()); + emit selectionChanged(mSelection); + } +} + +/*! + Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to + customize the visual representation of selected data ranges further than by using the default + QCPSelectionDecorator. + + The plottable takes ownership of the \a decorator. + + The currently set decorator can be accessed via \ref selectionDecorator. +*/ +void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) +{ + if (decorator) + { + if (decorator->registerWithPlottable(this)) + { + if (mSelectionDecorator) // delete old decorator if necessary + delete mSelectionDecorator; + mSelectionDecorator = decorator; + } + } else if (mSelectionDecorator) // just clear decorator + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + Sets whether and to which granularity this plottable can be selected. + + A selection can happen by clicking on the QCustomPlot surface (When \ref + QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect + (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by + calling \ref setSelection. + + \see setSelection, QCP::SelectionType +*/ +void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + QCPDataSelection oldSelection = mSelection; + mSelection.enforceType(mSelectable); + emit selectableChanged(mSelectable); + if (mSelection != oldSelection) + { + emit selectionChanged(selected()); + emit selectionChanged(mSelection); + } + } +} + + +/*! + Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. + + \see pixelsToCoords, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + x = keyAxis->coordToPixel(key); + y = valueAxis->coordToPixel(value); + } else + { + y = keyAxis->coordToPixel(key); + x = valueAxis->coordToPixel(value); + } +} + +/*! \overload + + Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. +*/ +const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); + else + return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); +} + +/*! + Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. + + \see coordsToPixels, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + key = keyAxis->pixelToCoord(x); + value = valueAxis->pixelToCoord(y); + } else + { + key = keyAxis->pixelToCoord(y); + value = valueAxis->pixelToCoord(x); + } +} + +/*! \overload + + Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. +*/ +void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const +{ + pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); +} + +/*! + Rescales the key and value axes associated with this plottable to contain all displayed data, so + the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make + sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. + Instead it will stay in the current sign domain and ignore all parts of the plottable that lie + outside of that domain. + + \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show + multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has + \a onlyEnlarge set to false (the default), and all subsequent set to true. + + \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale +*/ +void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const +{ + rescaleKeyAxis(onlyEnlarge); + rescaleValueAxis(onlyEnlarge); +} + +/*! + Rescales the key axis of the plottable so the whole plottable is visible. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (keyAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getKeyRange(foundRange, signDomain); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(keyAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (keyAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-keyAxis->range().size()/2.0; + newRange.upper = center+keyAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); + newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); + } + } + keyAxis->setRange(newRange); + } +} + +/*! + Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is + set to true, only the data points which are in the currently visible key axis range are + considered. + + Returns true if the axis was actually scaled. This might not be the case if this plottable has an + invalid range, e.g. because it has no data points. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (valueAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(valueAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-valueAxis->range().size()/2.0; + newRange.upper = center+valueAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); + newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); + } + } + valueAxis->setRange(newRange); + } +} + +/*! \overload + + Adds this plottable to the specified \a legend. + + Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. + when the legend exists and a legend item associated with this plottable isn't already in the + legend. + + If the plottable needs a more specialized representation in the legend, you can create a + corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead + of calling this method. + + \see removeFromLegend, QCPLegend::addItem +*/ +bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + if (legend->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; + return false; + } + + if (!legend->hasItemWithPlottable(this)) + { + legend->addItem(new QCPPlottableLegendItem(legend, this)); + return true; + } else + return false; +} + +/*! \overload + + Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). + + \see removeFromLegend +*/ +bool QCPAbstractPlottable::addToLegend() +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return addToLegend(mParentPlot->legend); +} + +/*! \overload + + Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem + that is associated with this plottable is removed. + + Returns true on success, i.e. if the legend exists and a legend item associated with this + plottable was found and removed. + + \see addToLegend, QCPLegend::removeItem +*/ +bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + + if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) + return legend->removeItem(lip); + else + return false; +} + +/*! \overload + + Removes the plottable from the legend of the parent QCustomPlot. + + \see addToLegend +*/ +bool QCPAbstractPlottable::removeFromLegend() const +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return removeFromLegend(mParentPlot->legend); +} + +/* inherits documentation from base class */ +QRect QCPAbstractPlottable::clipRect() const +{ + if (mKeyAxis && mValueAxis) + return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); + else + return QRect(); +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractPlottable::selectionCategory() const +{ + return QCP::iSelectPlottables; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable fills. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable scatter points. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint +*/ +void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + + if (mSelectable != QCP::stNone) + { + QCPDataSelection newSelection = details.value(); + QCPDataSelection selectionBefore = mSelection; + if (additive) + { + if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit + { + if (selected()) + setSelection(QCPDataSelection()); + else + setSelection(newSelection); + } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments + { + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); + else + setSelection(mSelection+newSelection); + } + } else + setSelection(newSelection); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable != QCP::stNone) + { + QCPDataSelection selectionBefore = mSelection; + setSelection(QCPDataSelection()); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} +/* end of 'src/plottable.cpp' */ + + +/* including file 'src/item.cpp', size 49269 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemAnchor +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemAnchor + \brief An anchor of an item to which positions can be attached to. + + An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't + control anything on its item, but provides a way to tie other items via their positions to the + anchor. + + For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. + Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can + attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by + calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the + QCPItemRect. This way the start of the line will now always follow the respective anchor location + on the rect item. + + Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an + anchor to other positions. + + To learn how to provide anchors in your own item subclasses, see the subclassing section of the + QCPAbstractItem documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() + + Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if + it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). + + This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids + dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with + gcc compiler). +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : + mName(name), + mParentPlot(parentPlot), + mParentItem(parentItem), + mAnchorId(anchorId) +{ +} + +QCPItemAnchor::~QCPItemAnchor() +{ + // unregister as parent at children: + foreach (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + foreach (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } +} + +/*! + Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. + + The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the + parent item, QCPItemAnchor is just an intermediary. +*/ +QPointF QCPItemAnchor::pixelPosition() const +{ + if (mParentItem) + { + if (mAnchorId > -1) + { + return mParentItem->anchorPixelPosition(mAnchorId); + } else + { + qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; + return QPointF(); + } + } else + { + qDebug() << Q_FUNC_INFO << "no parent item set"; + return QPointF(); + } +} + +/*! \internal + + Adds \a pos to the childX list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.contains(pos)) + mChildrenX.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childX list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + +/*! \internal + + Adds \a pos to the childY list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.contains(pos)) + mChildrenY.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childY list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPosition +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPosition + \brief Manages the position of an item. + + Every item has at least one public QCPItemPosition member pointer which provides ways to position the + item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: + \a topLeft and \a bottomRight. + + QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type + defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel + coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also + possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref + setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y + direction, while following a plot coordinate in the X direction. + + A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie + multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) + are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) + means directly ontop of the parent anchor. For example, You could attach the \a start position of + a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line + always be centered under the text label, no matter where the text is moved to. For more advanced + plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see + \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X + direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B + in Y. + + Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent + anchor for other positions. + + To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This + works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref + setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified + pixel values. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const + + Returns the current position type. + + If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the + type of the X coordinate. In that case rather use \a typeX() and \a typeY(). + + \see setType +*/ + +/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const + + Returns the current parent anchor. + + If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), + this method returns the parent anchor of the Y coordinate. In that case rather use \a + parentAnchorX() and \a parentAnchorY(). + + \see setParentAnchor +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : + QCPItemAnchor(parentPlot, parentItem, name), + mPositionTypeX(ptAbsolute), + mPositionTypeY(ptAbsolute), + mKey(0), + mValue(0), + mParentAnchorX(0), + mParentAnchorY(0) +{ +} + +QCPItemPosition::~QCPItemPosition() +{ + // unregister as parent at children: + // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then + // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition + foreach (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + foreach (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } + // unregister as child in parent: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPItemPosition::axisRect() const +{ + return mAxisRect.data(); +} + +/*! + Sets the type of the position. The type defines how the coordinates passed to \ref setCoords + should be handled and how the QCPItemPosition should behave in the plot. + + The possible values for \a type can be separated in two main categories: + + \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords + and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. + By default, the QCustomPlot's x- and yAxis are used. + + \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This + corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref + ptAxisRectRatio. They differ only in the way the absolute position is described, see the + documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify + the axis rect with \ref setAxisRect. By default this is set to the main axis rect. + + Note that the position type \ref ptPlotCoords is only available (and sensible) when the position + has no parent anchor (\ref setParentAnchor). + + If the type is changed, the apparent pixel position on the plot is preserved. This means + the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. + + This method sets the type for both X and Y directions. It is also possible to set different types + for X and Y, see \ref setTypeX, \ref setTypeY. +*/ +void QCPItemPosition::setType(QCPItemPosition::PositionType type) +{ + setTypeX(type); + setTypeY(type); +} + +/*! + This method sets the position type of the X coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeY +*/ +void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) +{ + if (mPositionTypeX != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeX = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + This method sets the position type of the Y coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeX +*/ +void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) +{ + if (mPositionTypeY != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeY = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now + follow any position changes of the anchor. The local coordinate system of positions with a parent + anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence + the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) + + if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved + during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position + will be exactly on top of the parent anchor. + + To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. + + If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is + set to \ref ptAbsolute, to keep the position in a valid state. + + This method sets the parent anchor for both X and Y directions. It is also possible to set + different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. +*/ +bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); + bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); + return successX && successY; +} + +/*! + This method sets the parent anchor of the X coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorY +*/ +bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorX(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) + setTypeX(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildX(this); + mParentAnchorX = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(0, coords().y()); + return true; +} + +/*! + This method sets the parent anchor of the Y coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorX +*/ +bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorY(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) + setTypeY(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildY(this); + mParentAnchorY = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(coords().x(), 0); + return true; +} + +/*! + Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type + (\ref setType, \ref setTypeX, \ref setTypeY). + + For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position + on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the + QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the + plot coordinate system defined by the axes set by \ref setAxes. By default those are the + QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available + coordinate types and their meaning. + + If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a + value must also be provided in the different coordinate systems. Here, the X type refers to \a + key, and the Y type refers to \a value. + + \see setPixelPosition +*/ +void QCPItemPosition::setCoords(double key, double value) +{ + mKey = key; + mValue = value; +} + +/*! \overload + + Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the + meaning of \a value of the \ref setCoords(double key, double value) method. +*/ +void QCPItemPosition::setCoords(const QPointF &pos) +{ + setCoords(pos.x(), pos.y()); +} + +/*! + Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It + includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). + + \see setPixelPosition +*/ +QPointF QCPItemPosition::pixelPosition() const +{ + QPointF result; + + // determine X: + switch (mPositionTypeX) + { + case ptAbsolute: + { + result.rx() = mKey; + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + result.rx() = mKey*mParentPlot->viewport().width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mParentPlot->viewport().left(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.rx() = mKey*mAxisRect.data()->width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mAxisRect.data()->left(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + // determine Y: + switch (mPositionTypeY) + { + case ptAbsolute: + { + result.ry() = mValue; + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + result.ry() = mValue*mParentPlot->viewport().height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mParentPlot->viewport().top(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.ry() = mValue*mAxisRect.data()->height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mAxisRect.data()->top(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + result.ry() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + result.ry() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + return result; +} + +/*! + When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the + coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and + yAxis of the QCustomPlot. +*/ +void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + mKeyAxis = keyAxis; + mValueAxis = valueAxis; +} + +/*! + When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the + coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of + the QCustomPlot. +*/ +void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) +{ + mAxisRect = axisRect; +} + +/*! + Sets the apparent pixel position. This works no matter what type (\ref setType) this + QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed + appropriately, to make the position finally appear at the specified pixel values. + + Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is + identical to that of \ref setCoords. + + \see pixelPosition, setCoords +*/ +void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) +{ + double x = pixelPosition.x(); + double y = pixelPosition.y(); + + switch (mPositionTypeX) + { + case ptAbsolute: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mParentPlot->viewport().left(); + x /= (double)mParentPlot->viewport().width(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mAxisRect.data()->left(); + x /= (double)mAxisRect.data()->width(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + x = mKeyAxis.data()->pixelToCoord(x); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + y = mValueAxis.data()->pixelToCoord(x); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + switch (mPositionTypeY) + { + case ptAbsolute: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mParentPlot->viewport().top(); + y /= (double)mParentPlot->viewport().height(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mAxisRect.data()->top(); + y /= (double)mAxisRect.data()->height(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + x = mKeyAxis.data()->pixelToCoord(y); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + y = mValueAxis.data()->pixelToCoord(y); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + setCoords(x, y); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractItem + \brief The abstract base class for all items in a plot. + + In QCustomPlot, items are supplemental graphical elements that are neither plottables + (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus + plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each + specific item has at least one QCPItemPosition member which controls the positioning. Some items + are defined by more than one coordinate and thus have two or more QCPItemPosition members (For + example, QCPItemRect has \a topLeft and \a bottomRight). + + This abstract base class defines a very basic interface like visibility and clipping. Since this + class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass + yourself to create new items. + + The built-in items are: + + + + + + + + + + +
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
+ + \section items-clipping Clipping + + Items are by default clipped to the main axis rect (they are only visible inside the axis rect). + To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect + "setClipToAxisRect(false)". + + On the other hand if you want the item to be clipped to a different axis rect, specify it via + \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and + in principle is independent of the coordinate axes the item might be tied to via its position + members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping + also contains the axes used for the item positions. + + \section items-using Using items + + First you instantiate the item you want to use and add it to the plot: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 + by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just + set the plot coordinates where the line should start/end: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 + If we don't want the line to be positioned in plot coordinates but a different coordinate system, + e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 + Then we can set the coordinates, this time in pixels: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 + and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 + + For more advanced plots, it is even possible to set different types and parent anchors per X/Y + coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref + QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. + + \section items-subclassing Creating own items + + To create an own item, you implement a subclass of QCPAbstractItem. These are the pure + virtual functions, you must implement: + \li \ref selectTest + \li \ref draw + + See the documentation of those functions for what they need to do. + + \subsection items-positioning Allowing the item to be positioned + + As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall + have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add + a public member of type QCPItemPosition like so: + + \code QCPItemPosition * const myPosition;\endcode + + the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition + instance it points to, can be modified, of course). + The initialization of this pointer is made easy with the \ref createPosition function. Just assign + the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition + takes a string which is the name of the position, typically this is identical to the variable name. + For example, the constructor of QCPItemExample could look like this: + + \code + QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + myPosition(createPosition("myPosition")) + { + // other constructor code + } + \endcode + + \subsection items-drawing The draw function + + To give your item a visual representation, reimplement the \ref draw function and use the passed + QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the + position member(s) via \ref QCPItemPosition::pixelPosition. + + To optimize performance you should calculate a bounding rect first (don't forget to take the pen + width into account), check whether it intersects the \ref clipRect, and only draw the item at all + if this is the case. + + \subsection items-selection The selectTest function + + Your implementation of the \ref selectTest function may use the helpers \ref + QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the + selection test becomes significantly simpler for most items. See the documentation of \ref + selectTest for what the function parameters mean and what the function should return. + + \subsection anchors Providing anchors + + Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public + member, e.g. + + \code QCPItemAnchor * const bottom;\endcode + + and create it in the constructor with the \ref createAnchor function, assigning it a name and an + anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). + Since anchors can be placed anywhere, relative to the item's position(s), your item needs to + provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int + anchorId) function. + + In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel + position when anything attached to the anchor needs to know the coordinates. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QList QCPAbstractItem::positions() const + + Returns all positions of the item in a list. + + \see anchors, position +*/ + +/*! \fn QList QCPAbstractItem::anchors() const + + Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always + also an anchor, the list will also contain the positions of this item. + + \see positions, anchor +*/ + +/* end of documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 + \internal + + Draws this item with the provided \a painter. + + The cliprect of the provided painter is set to the rect returned by \ref clipRect before this + function is called. The clipRect depends on the clipping settings defined by \ref + setClipToAxisRect and \ref setClipAxisRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPAbstractItem::selectionChanged(bool selected) + This signal is emitted when the selection state of this item has changed, either by user interaction + or by a direct call to \ref setSelected. +*/ + +/* end documentation of signals */ + +/*! + Base class constructor which initializes base class members. +*/ +QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), + mClipToAxisRect(false), + mSelectable(true), + mSelected(false) +{ + parentPlot->registerItem(this); + + QList rects = parentPlot->axisRects(); + if (rects.size() > 0) + { + setClipToAxisRect(true); + setClipAxisRect(rects.first()); + } +} + +QCPAbstractItem::~QCPAbstractItem() +{ + // don't delete mPositions because every position is also an anchor and thus in mAnchors + qDeleteAll(mAnchors); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPAbstractItem::clipAxisRect() const +{ + return mClipAxisRect.data(); +} + +/*! + Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the + entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. + + \see setClipAxisRect +*/ +void QCPAbstractItem::setClipToAxisRect(bool clip) +{ + mClipToAxisRect = clip; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref + setClipToAxisRect is set to true. + + \see setClipToAxisRect +*/ +void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) +{ + mClipAxisRect = rect; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) + + However, even when \a selectable was set to false, it is possible to set the selection manually, + by calling \ref setSelected. + + \see QCustomPlot::setInteractions, setSelected +*/ +void QCPAbstractItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + emit selectableChanged(mSelectable); + } +} + +/*! + Sets whether this item is selected or not. When selected, it might use a different visual + appearance (e.g. pen and brush), this depends on the specific item though. + + The entire selection mechanism for items is handled automatically when \ref + QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this + function when you wish to change the selection state manually. + + This function can change the selection state even when \ref setSelectable was set to false. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + emit selectionChanged(mSelected); + } +} + +/*! + Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by + that name, returns 0. + + This function provides an alternative way to access item positions. Normally, you access + positions direcly by their member pointers (which typically have the same variable name as \a + name). + + \see positions, anchor +*/ +QCPItemPosition *QCPAbstractItem::position(const QString &name) const +{ + for (int i=0; iname() == name) + return mPositions.at(i); + } + qDebug() << Q_FUNC_INFO << "position with name not found:" << name; + return 0; +} + +/*! + Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by + that name, returns 0. + + This function provides an alternative way to access item anchors. Normally, you access + anchors direcly by their member pointers (which typically have the same variable name as \a + name). + + \see anchors, position +*/ +QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const +{ + for (int i=0; iname() == name) + return mAnchors.at(i); + } + qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; + return 0; +} + +/*! + Returns whether this item has an anchor with the specified \a name. + + Note that you can check for positions with this function, too. This is because every position is + also an anchor (QCPItemPosition inherits from QCPItemAnchor). + + \see anchor, position +*/ +bool QCPAbstractItem::hasAnchor(const QString &name) const +{ + for (int i=0; iname() == name) + return true; + } + return false; +} + +/*! \internal + + Returns the rect the visual representation of this item is clipped to. This depends on the + current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. + + If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. + + \see draw +*/ +QRect QCPAbstractItem::clipRect() const +{ + if (mClipToAxisRect && mClipAxisRect) + return mClipAxisRect.data()->rect(); + else + return mParentPlot->viewport(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing item lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); +} + +/*! \internal + + A convenience function which returns the selectTest value for a specified \a rect and a specified + click position \a pos. \a filledRect defines whether a click inside the rect should also be + considered a hit or whether only the rect border is sensitive to hits. + + This function may be used to help with the implementation of the \ref selectTest function for + specific items. + + For example, if your item consists of four rects, call this function four times, once for each + rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four + returned values. +*/ +double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const +{ + double result = -1; + + // distance to border: + QList lines; + lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) + << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); + double minDistSqr = std::numeric_limits::max(); + for (int i=0; i mParentPlot->selectionTolerance()*0.99) + { + if (rect.contains(pos)) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/*! \internal + + Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in + item subclasses if they want to provide anchors (QCPItemAnchor). + + For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor + ids and returns the respective pixel points of the specified anchor. + + \see createAnchor +*/ +QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const +{ + qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the position + member (This is needed to provide the name-based \ref position access to positions). + + Don't delete positions created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each position member. Don't create QCPItemPositions with \b new yourself, because they + won't be registered with the item properly. + + \see createAnchor +*/ +QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); + mPositions.append(newPosition); + mAnchors.append(newPosition); // every position is also an anchor + newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); + newPosition->setType(QCPItemPosition::ptPlotCoords); + if (mParentPlot->axisRect()) + newPosition->setAxisRect(mParentPlot->axisRect()); + newPosition->setCoords(0, 0); + return newPosition; +} + +/*! \internal + + Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the anchor + member (This is needed to provide the name based \ref anchor access to anchors). + + The \a anchorId must be a number identifying the created anchor. It is recommended to create an + enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor + to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns + the correct pixel coordinates for the passed anchor id. + + Don't delete anchors created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they + won't be registered with the item properly. + + \see createPosition +*/ +QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); + mAnchors.append(newAnchor); + return newAnchor; +} + +/* inherits documentation from base class */ +void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractItem::selectionCategory() const +{ + return QCP::iSelectItems; +} +/* end of 'src/item.cpp' */ + + +/* including file 'src/core.cpp', size 125037 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCustomPlot +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCustomPlot + + \brief The central class of the library. This is the QWidget which displays the plot and + interacts with the user. + + For tutorials on how to use QCustomPlot, see the website\n + http://www.qcustomplot.com/ +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const + + Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used + to handle and draw selection rect interactions (see \ref setSelectionRectMode). + + \see setSelectionRect +*/ + +/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const + + Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just + one cell with the main QCPAxisRect inside. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse double click event. +*/ + +/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse press event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. +*/ + +/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse move event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. + + \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, + because the dragging starting point was saved the moment the mouse was pressed. Thus it only has + a meaning for the range drag axes that were set at that moment. If you want to change the drag + axes, consider doing this in the \ref mousePress signal instead. +*/ + +/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse release event. + + It is emitted before QCustomPlot handles any other mechanisms like object selection. So a + slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or + \ref QCPAbstractPlottable::setSelectable. +*/ + +/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse wheel event. + + It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref + QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. +*/ + +/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableDoubleClick +*/ + +/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is double clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableClick +*/ + +/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemDoubleClick +*/ + +/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is double clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemClick +*/ + +/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisDoubleClick +*/ + +/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is double clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisClick +*/ + +/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendDoubleClick +*/ + +/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is double clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendClick +*/ + +/*! \fn void QCustomPlot::selectionChangedByUser() + + This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by + clicking. It is not emitted when the selection state of an object has changed programmatically by + a direct call to setSelected()/setSelection() on an object or by calling \ref + deselectAll. + + In addition to this signal, selectable objects also provide individual signals, for example \ref + QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals + are emitted even if the selection state is changed programmatically. + + See the documentation of \ref setInteractions for details about the selection mechanism. + + \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends +*/ + +/*! \fn void QCustomPlot::beforeReplot() + + This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, afterReplot +*/ + +/*! \fn void QCustomPlot::afterReplot() + + This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, beforeReplot +*/ + +/* end of documentation of signals */ +/* start of documentation of public members */ + +/*! \var QCPAxis *QCustomPlot::xAxis + + A pointer to the primary x Axis (bottom) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis + + A pointer to the primary y Axis (left) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::xAxis2 + + A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis2 + + A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPLegend *QCustomPlot::legend + + A pointer to the default legend of the main axis rect. The legend is invisible by default. Use + QCPLegend::setVisible to change this. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple legends to the plot, use the layout system interface to + access the new legend. For example, legends can be placed inside an axis rect's \ref + QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If + the default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointer becomes 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/* end of documentation of public members */ + +/*! + Constructs a QCustomPlot and sets reasonable default values. +*/ +QCustomPlot::QCustomPlot(QWidget *parent) : + QWidget(parent), + xAxis(0), + yAxis(0), + xAxis2(0), + yAxis2(0), + legend(0), + mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below + mPlotLayout(0), + mAutoAddPlottableToLegend(true), + mAntialiasedElements(QCP::aeNone), + mNotAntialiasedElements(QCP::aeNone), + mInteractions(0), + mSelectionTolerance(8), + mNoAntialiasingOnDrag(false), + mBackgroundBrush(Qt::white, Qt::SolidPattern), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mCurrentLayer(0), + mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), + mMultiSelectModifier(Qt::ControlModifier), + mSelectionRectMode(QCP::srmNone), + mSelectionRect(0), + mOpenGl(false), + mMouseHasMoved(false), + mMouseEventLayerable(0), + mMouseSignalLayerable(0), + mReplotting(false), + mReplotQueued(false), + mOpenGlMultisamples(16), + mOpenGlAntialiasedElementsBackup(QCP::aeNone), + mOpenGlCacheLabelsBackup(true) +{ + setAttribute(Qt::WA_NoMousePropagation); + setAttribute(Qt::WA_OpaquePaintEvent); + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); + QLocale currentLocale = locale(); + currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); + setLocale(currentLocale); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); +# else + setBufferDevicePixelRatio(QWidget::devicePixelRatio()); +# endif +#endif + + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // create initial layers: + mLayers.append(new QCPLayer(this, QLatin1String("background"))); + mLayers.append(new QCPLayer(this, QLatin1String("grid"))); + mLayers.append(new QCPLayer(this, QLatin1String("main"))); + mLayers.append(new QCPLayer(this, QLatin1String("axes"))); + mLayers.append(new QCPLayer(this, QLatin1String("legend"))); + mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); + updateLayerIndices(); + setCurrentLayer(QLatin1String("main")); + layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); + + // create initial layout, axis rect and legend: + mPlotLayout = new QCPLayoutGrid; + mPlotLayout->initializeParentPlot(this); + mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry + mPlotLayout->setLayer(QLatin1String("main")); + QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); + mPlotLayout->addElement(0, 0, defaultAxisRect); + xAxis = defaultAxisRect->axis(QCPAxis::atBottom); + yAxis = defaultAxisRect->axis(QCPAxis::atLeft); + xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); + yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); + legend = new QCPLegend; + legend->setVisible(false); + defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); + defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); + + defaultAxisRect->setLayer(QLatin1String("background")); + xAxis->setLayer(QLatin1String("axes")); + yAxis->setLayer(QLatin1String("axes")); + xAxis2->setLayer(QLatin1String("axes")); + yAxis2->setLayer(QLatin1String("axes")); + xAxis->grid()->setLayer(QLatin1String("grid")); + yAxis->grid()->setLayer(QLatin1String("grid")); + xAxis2->grid()->setLayer(QLatin1String("grid")); + yAxis2->grid()->setLayer(QLatin1String("grid")); + legend->setLayer(QLatin1String("legend")); + + // create selection rect instance: + mSelectionRect = new QCPSelectionRect(this); + mSelectionRect->setLayer(QLatin1String("overlay")); + + setViewport(rect()); // needs to be called after mPlotLayout has been created + + replot(rpQueuedReplot); +} + +QCustomPlot::~QCustomPlot() +{ + clearPlottables(); + clearItems(); + + if (mPlotLayout) + { + delete mPlotLayout; + mPlotLayout = 0; + } + + mCurrentLayer = 0; + qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed + mLayers.clear(); +} + +/*! + Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is + removed from there. + + \see setNotAntialiasedElements +*/ +void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) +{ + mAntialiasedElements = antialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. + + See \ref setAntialiasedElements for details. + + \see setNotAntialiasedElement +*/ +void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) +{ + if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements &= ~antialiasedElement; + else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements |= antialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets which elements are forcibly drawn not antialiased as an \a or combination of + QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is + removed from there. + + \see setAntialiasedElements +*/ +void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) +{ + mNotAntialiasedElements = notAntialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. + + See \ref setNotAntialiasedElements for details. + + \see setAntialiasedElement +*/ +void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) +{ + if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements &= ~notAntialiasedElement; + else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements |= notAntialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the + plottable to the legend (QCustomPlot::legend). + + \see addGraph, QCPLegend::addItem +*/ +void QCustomPlot::setAutoAddPlottableToLegend(bool on) +{ + mAutoAddPlottableToLegend = on; +} + +/*! + Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction + enums. There are the following types of interactions: + + Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the + respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. + For details how to control which axes the user may drag/zoom and in what orientations, see \ref + QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, + \ref QCPAxisRect::setRangeZoomAxes. + + Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref + QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and + their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the + user can actually select a plottable and its data can further be restricted with the \ref + QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the + special page about the \ref dataselection "data selection mechanism". To retrieve a list of all + currently selected plottables, call \ref selectedPlottables. If you're only interested in + QCPGraphs, you may use the convenience function \ref selectedGraphs. + + Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user + may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find + out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of + all currently selected items, call \ref selectedItems. + + Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user + may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick + labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for + each axis. To retrieve a list of all axes that currently contain selected parts, call \ref + selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). + + Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may + select the legend itself or individual items by clicking on them. What parts exactly are + selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the + legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To + find out which child items are selected, call \ref QCPLegend::selectedItems. + + All other selectable elements The selection of all other selectable objects (e.g. + QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the + user may select those objects by clicking on them. To find out which are currently selected, you + need to check their selected state explicitly. + + If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is + emitted. Each selectable object additionally emits an individual selectionChanged signal whenever + their selection state has changed, i.e. not only by user interaction. + + To allow multiple objects to be selected by holding the selection modifier (\ref + setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. + + \note In addition to the selection mechanism presented here, QCustomPlot always emits + corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and + \ref plottableDoubleClick for example. + + \see setInteraction, setSelectionTolerance +*/ +void QCustomPlot::setInteractions(const QCP::Interactions &interactions) +{ + mInteractions = interactions; +} + +/*! + Sets the single \a interaction of this QCustomPlot to \a enabled. + + For details about the interaction system, see \ref setInteractions. + + \see setInteractions +*/ +void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) +{ + if (!enabled && mInteractions.testFlag(interaction)) + mInteractions &= ~interaction; + else if (enabled && !mInteractions.testFlag(interaction)) + mInteractions |= interaction; +} + +/*! + Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or + not. + + If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a + potential selection when the minimum distance between the click position and the graph line is + smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks + directly inside the area and ignore this selection tolerance. In other words, it only has meaning + for parts of objects that are too thin to exactly hit with a click and thus need such a + tolerance. + + \see setInteractions, QCPLayerable::selectTest +*/ +void QCustomPlot::setSelectionTolerance(int pixels) +{ + mSelectionTolerance = pixels; +} + +/*! + Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes + ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves + performance during dragging. Thus it creates a more responsive user experience. As soon as the + user stops dragging, the last replot is done with normal antialiasing, to restore high image + quality. + + \see setAntialiasedElements, setNotAntialiasedElements +*/ +void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) +{ + mNoAntialiasingOnDrag = enabled; +} + +/*! + Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. + + \see setPlottingHint +*/ +void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) +{ + mPlottingHints = hints; +} + +/*! + Sets the specified plotting \a hint to \a enabled. + + \see setPlottingHints +*/ +void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) +{ + QCP::PlottingHints newHints = mPlottingHints; + if (!enabled) + newHints &= ~hint; + else + newHints |= hint; + + if (newHints != mPlottingHints) + setPlottingHints(newHints); +} + +/*! + Sets the keyboard modifier that will be recognized as multi-select-modifier. + + If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple + objects (or data points) by clicking on them one after the other while holding down \a modifier. + + By default the multi-select-modifier is set to Qt::ControlModifier. + + \see setInteractions +*/ +void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) +{ + mMultiSelectModifier = modifier; +} + +/*! + Sets how QCustomPlot processes mouse click-and-drag interactions by the user. + + If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For + example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref + QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref + selectionRect) becomes activated and allows e.g. rect zooming and data point selection. + + If you wish to provide your user both with axis range dragging and data selection/range zooming, + use this method to switch between the modes just before the interaction is processed, e.g. in + reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether + the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. + + If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the + interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes + will keep the selection rect active. Upon completion of the interaction, the behaviour is as + defined by the currently set \a mode, not the mode that was set when the interaction started. + + \see setInteractions, setSelectionRect, QCPSelectionRect +*/ +void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) +{ + if (mSelectionRect) + { + if (mode == QCP::srmNone) + mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect + + // disconnect old connections: + if (mSelectionRectMode == QCP::srmSelect) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + + // establish new ones: + if (mode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } + + mSelectionRectMode = mode; +} + +/*! + Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref + QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of + the passed \a selectionRect. It can be accessed later via \ref selectionRect. + + This method is useful if you wish to replace the default QCPSelectionRect instance with an + instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. + + \see setSelectionRectMode +*/ +void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) +{ + if (mSelectionRect) + delete mSelectionRect; + + mSelectionRect = selectionRect; + + if (mSelectionRect) + { + // establish connections with new selection rect: + if (mSelectionRectMode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } +} + +/*! + \warning This is still an experimental feature and its performance depends on the system that it + runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering + might cause context conflicts on some systems. + + This method allows to enable OpenGL plot rendering, for increased plotting performance of + graphically demanding plots (thick lines, translucent fills, etc.). + + If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, + continue plotting with hardware acceleration. The parameter \a multisampling controls how many + samples will be used per pixel, it essentially controls the antialiasing quality. If \a + multisampling is set too high for the current graphics hardware, the maximum allowed value will + be used. + + You can test whether switching to OpenGL rendering was successful by checking whether the + according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, + rendering continues with the regular software rasterizer, and an according qDebug output is + generated. + + If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint + "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override + for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a + higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the + OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is + controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching + settings are restored to what they were before OpenGL was enabled, if they weren't altered in the + meantime. + + \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL + defined. This define must be set before including the QCustomPlot header both during compilation + of the QCustomPlot library as well as when compiling your application. It is best to just include + the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. + \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c + QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a + newer OpenGL interface which is already in the "gui" module. +*/ +void QCustomPlot::setOpenGl(bool enabled, int multisampling) +{ + mOpenGlMultisamples = qMax(0, multisampling); +#ifdef QCUSTOMPLOT_USE_OPENGL + mOpenGl = enabled; + if (mOpenGl) + { + if (setupOpenGl()) + { + // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): + setAntialiasedElements(QCP::aeAll); + setPlottingHint(QCP::phCacheLabels, false); + } else + { + qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; + mOpenGl = false; + } + } else + { + // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: + if (mAntialiasedElements == QCP::aeAll) + setAntialiasedElements(mOpenGlAntialiasedElementsBackup); + if (!mPlottingHints.testFlag(QCP::phCacheLabels)) + setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); + freeOpenGl(); + } + // recreate all paint buffers: + mPaintBuffers.clear(); + setupPaintBuffers(); +#else + Q_UNUSED(enabled) + qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; +#endif +} + +/*! + Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the + viewport manually. + + The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take + the viewport to be the outer border of the plot. The viewport normally is the rect() of the + QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. + + Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically + an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger + and contains also the axes themselves, their tick numbers, their labels, or even additional axis + rects, color scales and other layout elements. + + This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref + savePdf, etc. by temporarily changing the viewport size. +*/ +void QCustomPlot::setViewport(const QRect &rect) +{ + mViewport = rect; + if (mPlotLayout) + mPlotLayout->setOuterRect(mViewport); +} + +/*! + Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. + + Normally, this doesn't need to be set manually, because it is initialized with the regular \a + QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal + displays, 2 for High-DPI displays). + + Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called + when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and + leaves the internal buffer device pixel ratio at 1.0. +*/ +void QCustomPlot::setBufferDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBufferDevicePixelRatio = ratio; + for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); + // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mBufferDevicePixelRatio = 1.0; +#endif + } +} + +/*! + Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn + below all other objects in the plot. + + For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is + preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will + first be filled with that brush, before drawing the background pixmap. This can be useful for + background pixmaps with translucent areas. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! + Sets the background brush of the viewport (see \ref setViewport). + + Before drawing everything else, the background is filled with \a brush. If a background pixmap + was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport + before the background pixmap is drawn. This can be useful for background pixmaps with translucent + areas. + + Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be + useful for exporting to image formats which support transparency, e.g. \ref savePng. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the viewport, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is + set to true, control whether and how the aspect ratio of the original pixmap is preserved with + \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the viewport dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCustomPlot::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this + function to define whether and how the aspect ratio of the original pixmap is preserved. + + \see setBackground, setBackgroundScaled +*/ +void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the plottable with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + plottable, see QCustomPlot::plottable() + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + { + return mPlottables.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last plottable that was added to the plot. If there are no plottables in the plot, + returns 0. + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable() +{ + if (!mPlottables.isEmpty()) + { + return mPlottables.last(); + } else + return 0; +} + +/*! + Removes the specified plottable from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). + + Returns true on success. + + \see clearPlottables +*/ +bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); + return false; + } + + // remove plottable from legend: + plottable->removeFromLegend(); + // special handling for QCPGraphs to maintain the simple graph interface: + if (QCPGraph *graph = qobject_cast(plottable)) + mGraphs.removeOne(graph); + // remove plottable: + delete plottable; + mPlottables.removeOne(plottable); + return true; +} + +/*! \overload + + Removes and deletes the plottable by its \a index. +*/ +bool QCustomPlot::removePlottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + return removePlottable(mPlottables[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all plottables from the plot and deletes them. Corresponding legend items are also + removed from the default legend (QCustomPlot::legend). + + Returns the number of plottables removed. + + \see removePlottable +*/ +int QCustomPlot::clearPlottables() +{ + int c = mPlottables.size(); + for (int i=c-1; i >= 0; --i) + removePlottable(mPlottables[i]); + return c; +} + +/*! + Returns the number of currently existing plottables in the plot + + \see plottable +*/ +int QCustomPlot::plottableCount() const +{ + return mPlottables.size(); +} + +/*! + Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. + + There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. + + \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedPlottables() const +{ + QList result; + foreach (QCPAbstractPlottable *plottable, mPlottables) + { + if (plottable->selected()) + result.append(plottable); + } + return result; +} + +/*! + Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines + (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple + plottables come into consideration, the one closest to \a pos is returned. + + If \a onlySelectable is true, only plottables that are selectable + (QCPAbstractPlottable::setSelectable) are considered. + + If there is no plottable at \a pos, the return value is 0. + + \see itemAt, layoutElementAt +*/ +QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractPlottable *resultPlottable = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach (QCPAbstractPlottable *plottable, mPlottables) + { + if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable + continue; + if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes + { + double currentDistance = plottable->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultPlottable = plottable; + resultDistance = currentDistance; + } + } + } + + return resultPlottable; +} + +/*! + Returns whether this QCustomPlot instance contains the \a plottable. +*/ +bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const +{ + return mPlottables.contains(plottable); +} + +/*! + Returns the graph with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last created + graph, see QCustomPlot::graph() + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph(int index) const +{ + if (index >= 0 && index < mGraphs.size()) + { + return mGraphs.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, + returns 0. + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph() const +{ + if (!mGraphs.isEmpty()) + { + return mGraphs.last(); + } else + return 0; +} + +/*! + Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the + bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a + keyAxis and \a valueAxis must reside in this QCustomPlot. + + \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically + "y") for the graph. + + Returns a pointer to the newly created graph, or 0 if adding the graph failed. + + \see graph, graphCount, removeGraph, clearGraphs +*/ +QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + if (!keyAxis) keyAxis = xAxis; + if (!valueAxis) valueAxis = yAxis; + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; + return 0; + } + if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; + return 0; + } + + QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); + newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); + return newGraph; +} + +/*! + Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in + the plot have a channel fill set towards the removed graph, the channel fill property of those + graphs is reset to zero (no channel fill). + + Returns true on success. + + \see clearGraphs +*/ +bool QCustomPlot::removeGraph(QCPGraph *graph) +{ + return removePlottable(graph); +} + +/*! \overload + + Removes and deletes the graph by its \a index. +*/ +bool QCustomPlot::removeGraph(int index) +{ + if (index >= 0 && index < mGraphs.size()) + return removeGraph(mGraphs[index]); + else + return false; +} + +/*! + Removes all graphs from the plot and deletes them. Corresponding legend items are also removed + from the default legend (QCustomPlot::legend). + + Returns the number of graphs removed. + + \see removeGraph +*/ +int QCustomPlot::clearGraphs() +{ + int c = mGraphs.size(); + for (int i=c-1; i >= 0; --i) + removeGraph(mGraphs[i]); + return c; +} + +/*! + Returns the number of currently existing graphs in the plot + + \see graph, addGraph +*/ +int QCustomPlot::graphCount() const +{ + return mGraphs.size(); +} + +/*! + Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. + + If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, + etc., use \ref selectedPlottables. + + \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedGraphs() const +{ + QList result; + foreach (QCPGraph *graph, mGraphs) + { + if (graph->selected()) + result.append(graph); + } + return result; +} + +/*! + Returns the item with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + item, see QCustomPlot::item() + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item(int index) const +{ + if (index >= 0 && index < mItems.size()) + { + return mItems.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last item that was added to this plot. If there are no items in the plot, + returns 0. + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item() const +{ + if (!mItems.isEmpty()) + { + return mItems.last(); + } else + return 0; +} + +/*! + Removes the specified item from the plot and deletes it. + + Returns true on success. + + \see clearItems +*/ +bool QCustomPlot::removeItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + delete item; + mItems.removeOne(item); + return true; + } else + { + qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); + return false; + } +} + +/*! \overload + + Removes and deletes the item by its \a index. +*/ +bool QCustomPlot::removeItem(int index) +{ + if (index >= 0 && index < mItems.size()) + return removeItem(mItems[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all items from the plot and deletes them. + + Returns the number of items removed. + + \see removeItem +*/ +int QCustomPlot::clearItems() +{ + int c = mItems.size(); + for (int i=c-1; i >= 0; --i) + removeItem(mItems[i]); + return c; +} + +/*! + Returns the number of currently existing items in the plot + + \see item +*/ +int QCustomPlot::itemCount() const +{ + return mItems.size(); +} + +/*! + Returns a list of the selected items. If no items are currently selected, the list is empty. + + \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected +*/ +QList QCustomPlot::selectedItems() const +{ + QList result; + foreach (QCPAbstractItem *item, mItems) + { + if (item->selected()) + result.append(item); + } + return result; +} + +/*! + Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref + QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref + setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is + returned. + + If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are + considered. + + If there is no item at \a pos, the return value is 0. + + \see plottableAt, layoutElementAt +*/ +QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractItem *resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach (QCPAbstractItem *item, mItems) + { + if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + continue; + if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it + { + double currentDistance = item->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultItem = item; + resultDistance = currentDistance; + } + } + } + + return resultItem; +} + +/*! + Returns whether this QCustomPlot contains the \a item. + + \see item +*/ +bool QCustomPlot::hasItem(QCPAbstractItem *item) const +{ + return mItems.contains(item); +} + +/*! + Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is + returned. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(const QString &name) const +{ + foreach (QCPLayer *layer, mLayers) + { + if (layer->name() == name) + return layer; + } + return 0; +} + +/*! \overload + + Returns the layer by \a index. If the index is invalid, 0 is returned. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(int index) const +{ + if (index >= 0 && index < mLayers.size()) + { + return mLayers.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Returns the layer that is set as current layer (see \ref setCurrentLayer). +*/ +QCPLayer *QCustomPlot::currentLayer() const +{ + return mCurrentLayer; +} + +/*! + Sets the layer with the specified \a name to be the current layer. All layerables (\ref + QCPLayerable), e.g. plottables and items, are created on the current layer. + + Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer +*/ +bool QCustomPlot::setCurrentLayer(const QString &name) +{ + if (QCPLayer *newCurrentLayer = layer(name)) + { + return setCurrentLayer(newCurrentLayer); + } else + { + qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; + return false; + } +} + +/*! \overload + + Sets the provided \a layer to be the current layer. + + Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. + + \see addLayer, moveLayer, removeLayer +*/ +bool QCustomPlot::setCurrentLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + + mCurrentLayer = layer; + return true; +} + +/*! + Returns the number of currently existing layers in the plot + + \see layer, addLayer +*/ +int QCustomPlot::layerCount() const +{ + return mLayers.size(); +} + +/*! + Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which + must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. + + Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a + valid layer inside this QCustomPlot. + + If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. + + For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. + + \see layer, moveLayer, removeLayer +*/ +bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!otherLayer) + otherLayer = mLayers.last(); + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + if (layer(name)) + { + qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; + return false; + } + + QCPLayer *newLayer = new QCPLayer(this, name); + mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); + updateLayerIndices(); + setupPaintBuffers(); // associates new layer with the appropriate paint buffer + return true; +} + +/*! + Removes the specified \a layer and returns true on success. + + All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below + \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both + cases, the total rendering order of all layerables in the QCustomPlot is preserved. + + If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom + layer) becomes the new current layer. + + It is not possible to remove the last layer of the plot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::removeLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (mLayers.size() < 2) + { + qDebug() << Q_FUNC_INFO << "can't remove last layer"; + return false; + } + + // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) + int removedIndex = layer->index(); + bool isFirstLayer = removedIndex==0; + QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); + QList children = layer->children(); + if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) + { + for (int i=children.size()-1; i>=0; --i) + children.at(i)->moveToLayer(targetLayer, true); + } else // append normally + { + for (int i=0; imoveToLayer(targetLayer, false); + } + // if removed layer is current layer, change current layer to layer below/above: + if (layer == mCurrentLayer) + setCurrentLayer(targetLayer); + // invalidate the paint buffer that was responsible for this layer: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + // remove layer: + delete layer; + mLayers.removeOne(layer); + updateLayerIndices(); + return true; +} + +/*! + Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or + below is controlled with \a insertMode. + + Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the + QCustomPlot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + + if (layer->index() > otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); + else if (layer->index() < otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); + + // invalidate the paint buffers that are responsible for the layers: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + if (!otherLayer->mPaintBuffer.isNull()) + otherLayer->mPaintBuffer.data()->setInvalidated(); + + updateLayerIndices(); + return true; +} + +/*! + Returns the number of axis rects in the plot. + + All axis rects can be accessed via QCustomPlot::axisRect(). + + Initially, only one axis rect exists in the plot. + + \see axisRect, axisRects +*/ +int QCustomPlot::axisRectCount() const +{ + return axisRects().size(); +} + +/*! + Returns the axis rect with \a index. + + Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were + added, all of them may be accessed with this function in a linear fashion (even when they are + nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). + + \see axisRectCount, axisRects +*/ +QCPAxisRect *QCustomPlot::axisRect(int index) const +{ + const QList rectList = axisRects(); + if (index >= 0 && index < rectList.size()) + { + return rectList.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; + return 0; + } +} + +/*! + Returns all axis rects in the plot. + + \see axisRectCount, axisRect +*/ +QList QCustomPlot::axisRects() const +{ + QList result; + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + foreach (QCPLayoutElement *element, elementStack.pop()->elements(false)) + { + if (element) + { + elementStack.push(element); + if (QCPAxisRect *ar = qobject_cast(element)) + result.append(ar); + } + } + } + + return result; +} + +/*! + Returns the layout element at pixel position \a pos. If there is no element at that position, + returns 0. + + Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on + any of its parent elements is set to false, it will not be considered. + + \see itemAt, plottableAt +*/ +QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const +{ + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + foreach (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + break; + } + } + } + return currentElement; +} + +/*! + Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores + other layout elements even if they are visually in front of the axis rect (e.g. a \ref + QCPLegend). If there is no axis rect at that position, returns 0. + + Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or + on any of its parent elements is set to false, it will not be considered. + + \see layoutElementAt +*/ +QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const +{ + QCPAxisRect *result = 0; + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + foreach (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + if (QCPAxisRect *ar = qobject_cast(currentElement)) + result = ar; + break; + } + } + } + return result; +} + +/*! + Returns the axes that currently have selected parts, i.e. whose selection state is not \ref + QCPAxis::spNone. + + \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, + QCPAxis::setSelectableParts +*/ +QList QCustomPlot::selectedAxes() const +{ + QList result, allAxes; + foreach (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + foreach (QCPAxis *axis, allAxes) + { + if (axis->selectedParts() != QCPAxis::spNone) + result.append(axis); + } + + return result; +} + +/*! + Returns the legends that currently have selected parts, i.e. whose selection state is not \ref + QCPLegend::spNone. + + \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, + QCPLegend::setSelectableParts, QCPLegend::selectedItems +*/ +QList QCustomPlot::selectedLegends() const +{ + QList result; + + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + foreach (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) + { + if (subElement) + { + elementStack.push(subElement); + if (QCPLegend *leg = qobject_cast(subElement)) + { + if (leg->selectedParts() != QCPLegend::spNone) + result.append(leg); + } + } + } + } + + return result; +} + +/*! + Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. + + Since calling this function is not a user interaction, this does not emit the \ref + selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the + objects were previously selected. + + \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends +*/ +void QCustomPlot::deselectAll() +{ + foreach (QCPLayer *layer, mLayers) + { + foreach (QCPLayerable *layerable, layer->children()) + layerable->deselectEvent(0); + } +} + +/*! + Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is + refreshed with the new buffer contents. This is the method that must be called to make changes to + the plot, e.g. on the axis ranges or data points of graphs, visible. + + The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example + if your application calls \ref replot very quickly in succession (e.g. multiple independent + functions change some aspects of the plot and each wants to make sure the change gets replotted), + it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the + actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref + replot with this priority will only cause a single replot, avoiding redundant replots and + improving performance. + + Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the + QCustomPlot widget and user interactions (object selection and range dragging/zooming). + + Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref + afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two + signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite + recursion. + + If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to + replot only that specific layer via \ref QCPLayer::replot. See the documentation there for + details. +*/ +void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) +{ + if (refreshPriority == QCustomPlot::rpQueuedReplot) + { + if (!mReplotQueued) + { + mReplotQueued = true; + QTimer::singleShot(0, this, SLOT(replot())); + } + return; + } + + if (mReplotting) // incase signals loop back to replot slot + return; + mReplotting = true; + mReplotQueued = false; + emit beforeReplot(); + + updateLayout(); + // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: + setupPaintBuffers(); + foreach (QCPLayer *layer, mLayers) + layer->drawToPaintBuffer(); + for (int i=0; isetInvalidated(false); + + if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) + repaint(); + else + update(); + + emit afterReplot(); + mReplotting = false; +} + +/*! + Rescales the axes such that all plottables (like graphs) in the plot are fully visible. + + if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true + (QCPLayerable::setVisible), will be used to rescale the axes. + + \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale +*/ +void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) +{ + QList allAxes; + foreach (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + foreach (QCPAxis *axis, allAxes) + axis->rescale(onlyVisiblePlottables); +} + +/*! + Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale + of texts and lines will be derived from the specified \a width and \a height. This means, the + output will look like the normal on-screen output of a QCustomPlot widget with the corresponding + pixel width and height. If either \a width or \a height is zero, the exported image will have the + same dimensions as the QCustomPlot widget currently has. + + Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when + drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as + a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information + about cosmetic pens, see the QPainter and QPen documentation. + + The objects of the plot will appear in the current selection state. If you don't want any + selected objects to be painted in their selected look, deselect everything with \ref deselectAll + before calling this function. + + Returns true on success. + + \warning + \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it + is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines + (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). + \li If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting + PDF file. + + \note On Android systems, this method does nothing and issues an according qDebug warning + message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. + + \see savePng, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) +{ + bool success = false; +#ifdef QT_NO_PRINTER + Q_UNUSED(fileName) + Q_UNUSED(exportPen) + Q_UNUSED(width) + Q_UNUSED(height) + Q_UNUSED(pdfCreator) + Q_UNUSED(pdfTitle) + qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; +#else + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFileName(fileName); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); + printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + printer.setFullPage(true); + printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); +#else + QPageLayout pageLayout; + pageLayout.setMode(QPageLayout::FullPageMode); + pageLayout.setOrientation(QPageLayout::Portrait); + pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); + pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); + printer.setPageLayout(pageLayout); +#endif + QCPPainter printpainter; + if (printpainter.begin(&printer)) + { + printpainter.setMode(QCPPainter::pmVectorized); + printpainter.setMode(QCPPainter::pmNoCaching); + printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); + printpainter.setWindow(mViewport); + if (mBackgroundBrush.style() != Qt::NoBrush && + mBackgroundBrush.color() != Qt::white && + mBackgroundBrush.color() != Qt::transparent && + mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent + printpainter.fillRect(viewport(), mBackgroundBrush); + draw(&printpainter); + printpainter.end(); + success = true; + } + setViewport(oldViewport); +#endif // QT_NO_PRINTER + return success; +} + +/*! + Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the PNG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) + with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); +} + +/*! + Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the JPEG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveBmp, saveRastered +*/ +bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); +} + +/*! + Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the BMP format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveJpg, saveRastered +*/ +bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); +} + +/*! \internal + + Returns a minimum size hint that corresponds to the minimum size of the top level layout + (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum + size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. + This is especially important, when placed in a QLayout where other components try to take in as + much space as possible (e.g. QMdiArea). +*/ +QSize QCustomPlot::minimumSizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Returns a size hint that is the same as \ref minimumSizeHint. + +*/ +QSize QCustomPlot::sizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but + draws the internal buffer on the widget surface. +*/ +void QCustomPlot::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QCPPainter painter(this); + if (painter.isActive()) + { + painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem + if (mBackgroundBrush.style() != Qt::NoBrush) + painter.fillRect(mViewport, mBackgroundBrush); + drawBackground(&painter); + for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) + mPaintBuffers.at(bufferIndex)->draw(&painter); + } +} + +/*! \internal + + Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect + of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. +*/ +void QCustomPlot::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + // resize and repaint the buffer: + setViewport(rect()); + replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) +} + +/*! \internal + + Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then + determines the layerable under the cursor and forwards the event to it. Finally, emits the + specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref + axisDoubleClick, etc.). + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit mouseDoubleClick(event); + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + // determine layerable under the cursor (this event is called instead of the second press event in a double-click): + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + + // emit specialized object double click signals: + if (!candidates.isEmpty()) + { + if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) + { + int dataIndex = 0; + if (!details.first().value().isEmpty()) + dataIndex = details.first().value().dataRange().begin(); + emit plottableDoubleClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(candidates.first())) + emit axisDoubleClick(ax, details.first().value(), event); + else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) + emit itemDoubleClick(ai, event); + else if (QCPLegend *lg = qobject_cast(candidates.first())) + emit legendDoubleClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) + emit legendDoubleClick(li->parentLegend(), li, event); + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is pressed. Emits the mousePress signal. + + If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the + selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCustomPlot::mousePressEvent(QMouseEvent *event) +{ + emit mousePress(event); + // save some state to tell in releaseEvent whether it was a click: + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + if (mSelectionRect && mSelectionRectMode != QCP::srmNone) + { + if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect + mSelectionRect->startSelection(event); + } else + { + // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + if (!candidates.isEmpty()) + { + mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) + mMouseSignalLayerableDetails = details.first(); + } + // forward event to topmost candidate which accepts the event: + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list + candidates.at(i)->mousePressEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when the cursor is moved. Emits the \ref mouseMove signal. + + If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it + in order to update the rect geometry. + + Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the + layout element before), the mouseMoveEvent is forwarded to that element. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseMoveEvent(QMouseEvent *event) +{ + emit mouseMove(event); + + if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) + mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release + + if (mSelectionRect && mSelectionRect->isActive()) + mSelectionRect->moveSelection(event); + else if (mMouseEventLayerable) // call event of affected layerable: + mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. + + If the mouse was moved less than a certain threshold in any direction since the \ref + mousePressEvent, it is considered a click which causes the selection mechanism (if activated via + \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse + click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) + + If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable + before), the \ref mouseReleaseEvent is forwarded to that element. + + \see mousePressEvent, mouseMoveEvent +*/ +void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) +{ + emit mouseRelease(event); + + if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click + { + if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here + mSelectionRect->cancel(); + if (event->button() == Qt::LeftButton) + processPointSelection(event); + + // emit specialized click signals of QCustomPlot instance: + if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) + { + int dataIndex = 0; + if (!mMouseSignalLayerableDetails.value().isEmpty()) + dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); + emit plottableClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) + emit axisClick(ax, mMouseSignalLayerableDetails.value(), event); + else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) + emit itemClick(ai, event); + else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) + emit legendClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) + emit legendClick(li->parentLegend(), li, event); + mMouseSignalLayerable = 0; + } + + if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there + { + // finish selection rect, the appropriate action will be taken via signal-slot connection: + mSelectionRect->endSelection(event); + } else + { + // call event of affected layerable: + if (mMouseEventLayerable) + { + mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); + mMouseEventLayerable = 0; + } + } + + if (noAntialiasingOnDrag()) + replot(rpQueuedReplot); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then + determines the affected layerable and forwards the event to it. +*/ +void QCustomPlot::wheelEvent(QWheelEvent *event) +{ + emit mouseWheel(event); + // forward event to layerable under cursor: + QList candidates = layerableListAt(event->pos(), false); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->wheelEvent(event); + if (event->isAccepted()) + break; + } + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + This function draws the entire plot, including background pixmap, with the specified \a painter. + It does not make use of the paint buffers like \ref replot, so this is the function typically + used by saving/exporting methods such as \ref savePdf or \ref toPainter. + + Note that it does not fill the background with the background brush (as the user may specify with + \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this + method. +*/ +void QCustomPlot::draw(QCPPainter *painter) +{ + updateLayout(); + + // draw viewport background pixmap: + drawBackground(painter); + + // draw all layered objects (grid, axes, plottables, items, legend,...): + foreach (QCPLayer *layer, mLayers) + layer->draw(painter); + + /* Debug code to draw all layout element rects + foreach (QCPLayoutElement* el, findChildren()) + { + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->rect()); + painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->outerRect()); + } + */ +} + +/*! \internal + + Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref + QCPLayoutElement::update on the main plot layout. + + Here, the layout elements calculate their positions and margins, and prepare for the following + draw call. +*/ +void QCustomPlot::updateLayout() +{ + // run through layout phases: + mPlotLayout->update(QCPLayoutElement::upPreparation); + mPlotLayout->update(QCPLayoutElement::upMargins); + mPlotLayout->update(QCPLayoutElement::upLayout); +} + +/*! \internal + + Draws the viewport background pixmap of the plot. + + If a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the viewport with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + Note that this function does not draw a fill with the background brush + (\ref setBackground(const QBrush &brush)) beneath the pixmap. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::drawBackground(QCPPainter *painter) +{ + // Note: background color is handled in individual replot/save functions + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mViewport.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); + } + } +} + +/*! \internal + + Goes through the layers and makes sure this QCustomPlot instance holds the correct number of + paint buffers and that they have the correct configuration (size, pixel ratio, etc.). + Allocations, reallocations and deletions of paint buffers are performed as necessary. It also + associates the paint buffers with the layers, so they draw themselves into the right buffer when + \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref + QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for + layers in \ref QCPLayer::lmBuffered mode. + + This method uses \ref createPaintBuffer to create new paint buffers. + + After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated + (so an attempt to replot only a single buffered layer causes a full replot). + + This method is called in every \ref replot call, prior to actually drawing the layers (into their + associated paint buffer). If the paint buffers don't need changing/reallocating, this method + basically leaves them alone and thus finishes very fast. +*/ +void QCustomPlot::setupPaintBuffers() +{ + int bufferIndex = 0; + if (mPaintBuffers.isEmpty()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + + for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) + { + QCPLayer *layer = mLayers.at(layerIndex); + if (layer->mode() == QCPLayer::lmLogical) + { + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + } else if (layer->mode() == QCPLayer::lmBuffered) + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + } + } + } + // remove unneeded buffers: + while (mPaintBuffers.size()-1 > bufferIndex) + mPaintBuffers.removeLast(); + // resize buffers to viewport size and clear contents: + for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size + mPaintBuffers.at(i)->clear(Qt::transparent); + mPaintBuffers.at(i)->setInvalidated(); + } +} + +/*! \internal + + This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. + + Depending on the current setting of \ref setOpenGl, and the current Qt version, different + backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper + size and device pixel ratio, and returned. +*/ +QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() +{ + if (mOpenGl) + { +#if defined(QCP_OPENGL_FBO) + return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); +#elif defined(QCP_OPENGL_PBUFFER) + return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); +#else + qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +#endif + } else + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +} + +/*! + This method returns whether any of the paint buffers held by this QCustomPlot instance are + invalidated. + + If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always + causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example + the layer order has changed, new layers were added, layers were removed, or layer modes were + changed (\ref QCPLayer::setMode). + + \see QCPAbstractPaintBuffer::setInvalidated +*/ +bool QCustomPlot::hasInvalidatedPaintBuffers() +{ + for (int i=0; iinvalidated()) + return true; + } + return false; +} + +/*! \internal + + When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, + surface, paint device). + + Returns true on success. + + If this method is successful, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref + QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. + + \see freeOpenGl +*/ +bool QCustomPlot::setupOpenGl() +{ +#ifdef QCP_OPENGL_FBO + freeOpenGl(); + QSurfaceFormat proposedSurfaceFormat; + proposedSurfaceFormat.setSamples(mOpenGlMultisamples); +#ifdef QCP_OPENGL_OFFSCREENSURFACE + QOffscreenSurface *surface = new QOffscreenSurface; +#else + QWindow *surface = new QWindow; + surface->setSurfaceType(QSurface::OpenGLSurface); +#endif + surface->setFormat(proposedSurfaceFormat); + surface->create(); + mGlSurface = QSharedPointer(surface); + mGlContext = QSharedPointer(new QOpenGLContext); + mGlContext->setFormat(mGlSurface->format()); + if (!mGlContext->create()) + { + qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device + { + qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + { + qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); + return true; +#elif defined(QCP_OPENGL_PBUFFER) + return QGLFormat::hasOpenGL(); +#else + return false; +#endif +} + +/*! \internal + + When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the + context and frees resources). + + After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref + QCPPaintBufferPixmap) is used for subsequent replots. + + \see setupOpenGl +*/ +void QCustomPlot::freeOpenGl() +{ +#ifdef QCP_OPENGL_FBO + mGlPaintDevice.clear(); + mGlContext.clear(); + mGlSurface.clear(); +#endif +} + +/*! \internal + + This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot + so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. +*/ +void QCustomPlot::axisRemoved(QCPAxis *axis) +{ + if (xAxis == axis) + xAxis = 0; + if (xAxis2 == axis) + xAxis2 = 0; + if (yAxis == axis) + yAxis = 0; + if (yAxis2 == axis) + yAxis2 = 0; + + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers +} + +/*! \internal + + This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so + it may clear its QCustomPlot::legend member accordingly. +*/ +void QCustomPlot::legendRemoved(QCPLegend *legend) +{ + if (this->legend == legend) + this->legend = 0; +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmSelect. + + First, it determines which axis rect was the origin of the selection rect judging by the starting + point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be + precise) associated with that axis rect and finds the data points that are in \a rect. It does + this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. + + Then, the actual selection is done by calling the plottables' \ref + QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details + parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a + rect receive a \ref QCPAbstractPlottable::deselectEvent. + + \see processRectZoom +*/ +void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) +{ + bool selectionStateChanged = false; + + if (mInteractions.testFlag(QCP::iSelectPlottables)) + { + QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size + QRectF rectF(rect.normalized()); + if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) + { + // determine plottables that were hit by the rect and thus are candidates for selection: + foreach (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) + { + if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) + { + QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); + if (!dataSel.isEmpty()) + potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); + } + } + + if (!mInteractions.testFlag(QCP::iMultiSelect)) + { + // only leave plottable with most selected points in map, since we will only select a single plottable: + if (!potentialSelections.isEmpty()) + { + QMap >::iterator it = potentialSelections.begin(); + while (it != potentialSelections.end()-1) // erase all except last element + it = potentialSelections.erase(it); + } + } + + bool additive = event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + // emit deselection except to those plottables who will be selected afterwards: + foreach (QCPLayer *layer, mLayers) + { + foreach (QCPLayerable *layerable, layer->children()) + { + if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + // go through selections in reverse (largest selection first) and emit select events: + QMap >::const_iterator it = potentialSelections.constEnd(); + while (it != potentialSelections.constBegin()) + { + --it; + if (mInteractions.testFlag(it.value().first->selectionCategory())) + { + bool selChanged = false; + it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + if (selectionStateChanged) + { + emit selectionChangedByUser(); + replot(rpQueuedReplot); + } else if (mSelectionRect) + mSelectionRect->layer()->replot(); +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmZoom. + + It determines which axis rect was the origin of the selection rect judging by the starting point + of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the + provided \a rect (see \ref QCPAxisRect::zoom). + + \see processRectSelection +*/ +void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) +{ + Q_UNUSED(event) + if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) + { + QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); + affectedAxes.removeAll(static_cast(0)); + axisRect->zoom(QRectF(rect), affectedAxes); + } + replot(rpQueuedReplot); // always replot to make selection rect disappear +} + +/*! \internal + + This method is called when a simple left mouse click was detected on the QCustomPlot surface. + + It first determines the layerable that was hit by the click, and then calls its \ref + QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the + multi-select modifier was pressed, see \ref setMultiSelectModifier). + + In this method the hit layerable is determined a second time using \ref layerableAt (after the + one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This + implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the + clicked layerable determined here. For example, if a non-selectable layerable is in front of a + selectable layerable at the click position, the front layerable will receive mouse events but the + selectable one in the back will receive the \ref QCPLayerable::selectEvent. + + \see processRectSelection, QCPLayerable::selectTest +*/ +void QCustomPlot::processPointSelection(QMouseEvent *event) +{ + QVariant details; + QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); + bool selectionStateChanged = false; + bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + foreach (QCPLayer *layer, mLayers) + { + foreach (QCPLayerable *layerable, layer->children()) + { + if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) + { + // a layerable was actually clicked, call its selectEvent: + bool selChanged = false; + clickedLayerable->selectEvent(event, additive, details, &selChanged); + selectionStateChanged |= selChanged; + } + if (selectionStateChanged) + { + emit selectionChangedByUser(); + replot(rpQueuedReplot); + } +} + +/*! \internal + + Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend + is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the + plottable. + + Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of + \a plottable is this QCustomPlot. + + This method is called automatically in the QCPAbstractPlottable base class constructor. +*/ +bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) +{ + if (mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); + return false; + } + if (plottable->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); + return false; + } + + mPlottables.append(plottable); + // possibly add plottable to legend: + if (mAutoAddPlottableToLegend) + plottable->addToLegend(); + if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + plottable->setLayer(currentLayer()); + return true; +} + +/*! \internal + + In order to maintain the simplified graph interface of QCustomPlot, this method is called by the + QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true + on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. + + This graph specific registration happens in addition to the call to \ref registerPlottable by the + QCPAbstractPlottable base class. +*/ +bool QCustomPlot::registerGraph(QCPGraph *graph) +{ + if (!graph) + { + qDebug() << Q_FUNC_INFO << "passed graph is zero"; + return false; + } + if (mGraphs.contains(graph)) + { + qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; + return false; + } + + mGraphs.append(graph); + return true; +} + + +/*! \internal + + Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. + + Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a + item is this QCustomPlot. + + This method is called automatically in the QCPAbstractItem base class constructor. +*/ +bool QCustomPlot::registerItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); + return false; + } + if (item->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); + return false; + } + + mItems.append(item); + if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) + item->setLayer(currentLayer()); + return true; +} + +/*! \internal + + Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called + after every operation that changes the layer indices, like layer removal, layer creation, layer + moving. +*/ +void QCustomPlot::updateLayerIndices() const +{ + for (int i=0; imIndex = i; +} + +/*! \internal + + Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, + only those layerables that are selectable will be considered. (Layerable subclasses communicate + their selectability via the QCPLayerable::selectTest method, by returning -1.) + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableListAt, layoutElementAt, axisRectAt +*/ +QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const +{ + QList details; + QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); + if (selectionDetails && !details.isEmpty()) + *selectionDetails = details.first(); + if (!candidates.isEmpty()) + return candidates.first(); + else + return 0; +} + +/*! \internal + + Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those + layerables that are selectable will be considered. (Layerable subclasses communicate their + selectability via the QCPLayerable::selectTest method, by returning -1.) + + The returned list is sorted by the layerable/drawing order. If you only need to know the top-most + layerable, rather use \ref layerableAt. + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableAt, layoutElementAt, axisRectAt +*/ +QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const +{ + QList result; + for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) + { + const QList layerables = mLayers.at(layerIndex)->children(); + for (int i=layerables.size()-1; i>=0; --i) + { + if (!layerables.at(i)->realVisibility()) + continue; + QVariant details; + double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); + if (dist >= 0 && dist < selectionTolerance()) + { + result.append(layerables.at(i)); + if (selectionDetails) + selectionDetails->append(details); + } + } + } + return result; +} + +/*! + Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is + sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead + to a full resolution file with width 200.) If the \a format supports compression, \a quality may + be between 0 and 100 to control it. + + Returns true on success. If this function fails, most likely the given \a format isn't supported + by the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The \a resolution will be written to the image file header (if the file format supports this) and + has no direct consequence for the quality or the pixel size. However, if opening the image with a + tool which respects the metadata, it will be able to scale the image to match either a given size + in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in + which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted + to the format's expected resolution unit internally. + + \see saveBmp, saveJpg, savePng, savePdf +*/ +bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + QImage buffer = toPixmap(width, height, scale).toImage(); + + int dotsPerMeter = 0; + switch (resolutionUnit) + { + case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; + case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; + case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; + } + buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + if (!buffer.isNull()) + return buffer.save(fileName, format, quality); + else + return false; +} + +/*! + Renders the plot to a pixmap and returns it. + + The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and + scale 2.0 lead to a full resolution pixmap with width 200.) + + \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf +*/ +QPixmap QCustomPlot::toPixmap(int width, int height, double scale) +{ + // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + int scaledWidth = qRound(scale*newWidth); + int scaledHeight = qRound(scale*newHeight); + + QPixmap result(scaledWidth, scaledHeight); + result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later + QCPPainter painter; + painter.begin(&result); + if (painter.isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter.setMode(QCPPainter::pmNoCaching); + if (!qFuzzyCompare(scale, 1.0)) + { + if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales + painter.setMode(QCPPainter::pmNonCosmetic); + painter.scale(scale, scale); + } + if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill + painter.fillRect(mViewport, mBackgroundBrush); + draw(&painter); + setViewport(oldViewport); + painter.end(); + } else // might happen if pixmap has width or height zero + { + qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; + return QPixmap(); + } + return result; +} + +/*! + Renders the plot using the passed \a painter. + + The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will + appear scaled accordingly. + + \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter + on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with + the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. + + \see toPixmap +*/ +void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) +{ + // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + if (painter->isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter->setMode(QCPPainter::pmNoCaching); + if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here + painter->fillRect(mViewport, mBackgroundBrush); + draw(painter); + setViewport(oldViewport); + } else + qDebug() << Q_FUNC_INFO << "Passed painter is not active"; +} +/* end of 'src/core.cpp' */ + +//amalgamation: add plottable1d.cpp + +/* including file 'src/colorgradient.cpp', size 24646 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorGradient +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorGradient + \brief Defines a color gradient for use with e.g. \ref QCPColorMap + + This class describes a color gradient which can be used to encode data with color. For example, + QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which + take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) + with a \a position from 0 to 1. In between these defined color positions, the + color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. + + Alternatively, load one of the preset color gradients shown in the image below, with \ref + loadPreset, or by directly specifying the preset in the constructor. + + Apart from red, green and blue components, the gradient also interpolates the alpha values of the + configured color stops. This allows to display some portions of the data range as transparent in + the plot. + + \image html QCPColorGradient.png + + The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref + GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset + to all the \a setGradient methods, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient + + The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the + color gradient shall be applied periodically (wrapping around) to data values that lie outside + the data range specified on the plottable instance can be controlled with \ref setPeriodic. +*/ + +/*! + Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color + stops with \ref setColorStopAt. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient() : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); +} + +/*! + Constructs a new QCPColorGradient initialized with the colors and color interpolation according + to \a preset. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient(GradientPreset preset) : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); + loadPreset(preset); +} + +/* undocumented operator */ +bool QCPColorGradient::operator==(const QCPColorGradient &other) const +{ + return ((other.mLevelCount == this->mLevelCount) && + (other.mColorInterpolation == this->mColorInterpolation) && + (other.mPeriodic == this->mPeriodic) && + (other.mColorStops == this->mColorStops)); +} + +/*! + Sets the number of discretization levels of the color gradient to \a n. The default is 350 which + is typically enough to create a smooth appearance. The minimum number of levels is 2. + + \image html QCPColorGradient-levelcount.png +*/ +void QCPColorGradient::setLevelCount(int n) +{ + if (n < 2) + { + qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; + n = 2; + } + if (n != mLevelCount) + { + mLevelCount = n; + mColorBufferInvalidated = true; + } +} + +/*! + Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the + colors are the values of the passed QMap \a colorStops. In between these color stops, the color + is interpolated according to \ref setColorInterpolation. + + A more convenient way to create a custom gradient may be to clear all color stops with \ref + clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with + \ref setColorStopAt. + + \see clearColorStops +*/ +void QCPColorGradient::setColorStops(const QMap &colorStops) +{ + mColorStops = colorStops; + mColorBufferInvalidated = true; +} + +/*! + Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between + these color stops, the color is interpolated according to \ref setColorInterpolation. + + \see setColorStops, clearColorStops +*/ +void QCPColorGradient::setColorStopAt(double position, const QColor &color) +{ + mColorStops.insert(position, color); + mColorBufferInvalidated = true; +} + +/*! + Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be + interpolated linearly in RGB or in HSV color space. + + For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, + whereas in HSV space the intermediate color is yellow. +*/ +void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) +{ + if (interpolation != mColorInterpolation) + { + mColorInterpolation = interpolation; + mColorBufferInvalidated = true; + } +} + +/*! + Sets whether data points that are outside the configured data range (e.g. \ref + QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether + they all have the same color, corresponding to the respective gradient boundary color. + + \image html QCPColorGradient-periodic.png + + As shown in the image above, gradients that have the same start and end color are especially + suitable for a periodic gradient mapping, since they produce smooth color transitions throughout + the color map. A preset that has this property is \ref gpHues. + + In practice, using periodic color gradients makes sense when the data corresponds to a periodic + dimension, such as an angle or a phase. If this is not the case, the color encoding might become + ambiguous, because multiple different data values are shown as the same color. +*/ +void QCPColorGradient::setPeriodic(bool enabled) +{ + mPeriodic = enabled; +} + +/*! \overload + + This method is used to quickly convert a \a data array to colors. The colors will be output in + the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this + function. The data range that shall be used for mapping the data value to the gradient is passed + in \a range. \a logarithmic indicates whether the data values shall be mapped to colors + logarithmically. + + if \a data actually contains 2D-data linearized via [row*columnCount + column], you can + set \a dataIndexFactor to columnCount to convert a column instead of a row of the data + array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data + is addressed data[i*dataIndexFactor]. + + Use the overloaded method to additionally provide alpha map data. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } +} + +/*! \overload + + Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which + has the same size and structure as \a data and encodes the alpha information per data point. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!alpha) + { + qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } +} + +/*! \internal + + This method is used to colorize a single data value given in \a position, to colors. The data + range that shall be used for mapping the data value to the gradient is passed in \a range. \a + logarithmic indicates whether the data value shall be mapped to a color logarithmically. + + If an entire array of data values shall be converted, rather use \ref colorize, for better + performance. + + The returned QRgb has its r, g and b components premultiplied with alpha (see + QImage::Format_ARGB32_Premultiplied). +*/ +QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) +{ + // If you change something here, make sure to also adapt ::colorize() + if (mColorBufferInvalidated) + updateColorBuffer(); + int index = 0; + if (!logarithmic) + index = (position-range.lower)*(mLevelCount-1)/range.size(); + else + index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); + if (mPeriodic) + { + index = index % mLevelCount; + if (index < 0) + index += mLevelCount; + } else + { + if (index < 0) + index = 0; + else if (index >= mLevelCount) + index = mLevelCount-1; + } + return mColorBuffer.at(index); +} + +/*! + Clears the current color stops and loads the specified \a preset. A preset consists of predefined + color stops and the corresponding color interpolation method. + + The available presets are: + \image html QCPColorGradient.png +*/ +void QCPColorGradient::loadPreset(GradientPreset preset) +{ + clearColorStops(); + switch (preset) + { + case gpGrayscale: + setColorInterpolation(ciRGB); + setColorStopAt(0, Qt::black); + setColorStopAt(1, Qt::white); + break; + case gpHot: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 0, 0)); + setColorStopAt(0.2, QColor(180, 10, 0)); + setColorStopAt(0.4, QColor(245, 50, 0)); + setColorStopAt(0.6, QColor(255, 150, 10)); + setColorStopAt(0.8, QColor(255, 255, 50)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpCold: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.2, QColor(0, 10, 180)); + setColorStopAt(0.4, QColor(0, 50, 245)); + setColorStopAt(0.6, QColor(10, 150, 255)); + setColorStopAt(0.8, QColor(50, 255, 255)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpNight: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(10, 20, 30)); + setColorStopAt(1, QColor(250, 255, 250)); + break; + case gpCandy: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(0, 0, 255)); + setColorStopAt(1, QColor(255, 250, 250)); + break; + case gpGeography: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(70, 170, 210)); + setColorStopAt(0.20, QColor(90, 160, 180)); + setColorStopAt(0.25, QColor(45, 130, 175)); + setColorStopAt(0.30, QColor(100, 140, 125)); + setColorStopAt(0.5, QColor(100, 140, 100)); + setColorStopAt(0.6, QColor(130, 145, 120)); + setColorStopAt(0.7, QColor(140, 130, 120)); + setColorStopAt(0.9, QColor(180, 190, 190)); + setColorStopAt(1, QColor(210, 210, 230)); + break; + case gpIon: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 10, 10)); + setColorStopAt(0.45, QColor(0, 0, 255)); + setColorStopAt(0.8, QColor(0, 255, 255)); + setColorStopAt(1, QColor(0, 255, 0)); + break; + case gpThermal: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.15, QColor(20, 0, 120)); + setColorStopAt(0.33, QColor(200, 30, 140)); + setColorStopAt(0.6, QColor(255, 100, 0)); + setColorStopAt(0.85, QColor(255, 255, 40)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpPolar: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 255, 255)); + setColorStopAt(0.18, QColor(10, 70, 255)); + setColorStopAt(0.28, QColor(10, 10, 190)); + setColorStopAt(0.5, QColor(0, 0, 0)); + setColorStopAt(0.72, QColor(190, 10, 10)); + setColorStopAt(0.82, QColor(255, 70, 10)); + setColorStopAt(1, QColor(255, 255, 50)); + break; + case gpSpectrum: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 0, 50)); + setColorStopAt(0.15, QColor(0, 0, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.6, QColor(255, 255, 0)); + setColorStopAt(0.75, QColor(255, 30, 0)); + setColorStopAt(1, QColor(50, 0, 0)); + break; + case gpJet: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 100)); + setColorStopAt(0.15, QColor(0, 50, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.65, QColor(255, 255, 0)); + setColorStopAt(0.85, QColor(255, 30, 0)); + setColorStopAt(1, QColor(100, 0, 0)); + break; + case gpHues: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(255, 0, 0)); + setColorStopAt(1.0/3.0, QColor(0, 0, 255)); + setColorStopAt(2.0/3.0, QColor(0, 255, 0)); + setColorStopAt(1, QColor(255, 0, 0)); + break; + } +} + +/*! + Clears all color stops. + + \see setColorStops, setColorStopAt +*/ +void QCPColorGradient::clearColorStops() +{ + mColorStops.clear(); + mColorBufferInvalidated = true; +} + +/*! + Returns an inverted gradient. The inverted gradient has all properties as this \ref + QCPColorGradient, but the order of the color stops is inverted. + + \see setColorStops, setColorStopAt +*/ +QCPColorGradient QCPColorGradient::inverted() const +{ + QCPColorGradient result(*this); + result.clearColorStops(); + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + result.setColorStopAt(1.0-it.key(), it.value()); + return result; +} + +/*! \internal + + Returns true if the color gradient uses transparency, i.e. if any of the configured color stops + has an alpha value below 255. +*/ +bool QCPColorGradient::stopsUseAlpha() const +{ + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + { + if (it.value().alpha() < 255) + return true; + } + return false; +} + +/*! \internal + + Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly + convert positions to colors. This is where the interpolation between color stops is calculated. +*/ +void QCPColorGradient::updateColorBuffer() +{ + if (mColorBuffer.size() != mLevelCount) + mColorBuffer.resize(mLevelCount); + if (mColorStops.size() > 1) + { + double indexToPosFactor = 1.0/(double)(mLevelCount-1); + const bool useAlpha = stopsUseAlpha(); + for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); + if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop + { + mColorBuffer[i] = (it-1).value().rgba(); + } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop + { + mColorBuffer[i] = it.value().rgba(); + } else // position is in between stops (or on an intermediate stop), interpolate color + { + QMap::const_iterator high = it; + QMap::const_iterator low = it-1; + double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 + switch (mColorInterpolation) + { + case ciRGB: + { + if (useAlpha) + { + const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); + const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, + ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, + ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, + alpha); + } else + { + mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), + ((1-t)*low.value().green() + t*high.value().green()), + ((1-t)*low.value().blue() + t*high.value().blue())); + } + break; + } + case ciHSV: + { + QColor lowHsv = low.value().toHsv(); + QColor highHsv = high.value().toHsv(); + double hue = 0; + double hueDiff = highHsv.hueF()-lowHsv.hueF(); + if (hueDiff > 0.5) + hue = lowHsv.hueF() - t*(1.0-hueDiff); + else if (hueDiff < -0.5) + hue = lowHsv.hueF() + t*(1.0+hueDiff); + else + hue = lowHsv.hueF() + t*hueDiff; + if (hue < 0) hue += 1.0; + else if (hue >= 1.0) hue -= 1.0; + if (useAlpha) + { + const QRgb rgb = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); + mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); + } + else + { + mColorBuffer[i] = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + } + break; + } + } + } + } + } else if (mColorStops.size() == 1) + { + const QRgb rgb = mColorStops.constBegin().value().rgb(); + const float alpha = mColorStops.constBegin().value().alphaF(); + mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); + } else // mColorStops is empty, fill color buffer with black + { + mColorBuffer.fill(qRgb(0, 0, 0)); + } + mColorBufferInvalidated = false; +} +/* end of 'src/colorgradient.cpp' */ + + +/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecoratorBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecoratorBracket + \brief A selection decorator which draws brackets around each selected data segment + + Additionally to the regular highlighting of selected segments via color, fill and scatter style, + this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data + segment of the plottable. + + The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and + \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref + setBracketBrush. + + To introduce custom bracket styles, it is only necessary to sublcass \ref + QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the + base class. +*/ + +/*! + Creates a new QCPSelectionDecoratorBracket instance with default values. +*/ +QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : + mBracketPen(QPen(Qt::black)), + mBracketBrush(Qt::NoBrush), + mBracketWidth(5), + mBracketHeight(50), + mBracketStyle(bsSquareBracket), + mTangentToData(false), + mTangentAverage(2) +{ + +} + +QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() +{ +} + +/*! + Sets the pen that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) +{ + mBracketPen = pen; +} + +/*! + Sets the brush that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) +{ + mBracketBrush = brush; +} + +/*! + Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of + the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketWidth(int width) +{ + mBracketWidth = width; +} + +/*! + Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis + of the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketHeight(int height) +{ + mBracketHeight = height; +} + +/*! + Sets the shape that the bracket/marker will have. + + \see setBracketWidth, setBracketHeight +*/ +void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) +{ + mBracketStyle = style; +} + +/*! + Sets whether the brackets will be rotated such that they align with the slope of the data at the + position that they appear in. + + For noisy data, it might be more visually appealing to average the slope over multiple data + points. This can be configured via \ref setTangentAverage. +*/ +void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) +{ + mTangentToData = enabled; +} + +/*! + Controls over how many data points the slope shall be averaged, when brackets shall be aligned + with the data (if \ref setTangentToData is true). + + From the position of the bracket, \a pointCount points towards the selected data range will be + taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to + disabling \ref setTangentToData. +*/ +void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) +{ + mTangentAverage = pointCount; + if (mTangentAverage < 1) + mTangentAverage = 1; +} + +/*! + Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and + indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening + bracket, respectively). + + The passed \a painter already contains all transformations that are necessary to position and + rotate the bracket appropriately. Painting operations can be performed as if drawing upright + brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. + + If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket + shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should + reimplement. +*/ +void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const +{ + switch (mBracketStyle) + { + case bsSquareBracket: + { + painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); + painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + break; + } + case bsHalfEllipse: + { + painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); + break; + } + case bsEllipse: + { + painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); + break; + } + case bsPlus: + { + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); + break; + } + default: + { + qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); + break; + } + } +} + +/*! + Draws the bracket decoration on the data points at the begin and end of each selected data + segment given in \a seletion. + + It uses the method \ref drawBracket to actually draw the shapes. + + \seebaseclassmethod +*/ +void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + if (!mPlottable || selection.isEmpty()) return; + + if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) + { + foreach (const QCPDataRange &dataRange, selection.dataRanges()) + { + // determine position and (if tangent mode is enabled) angle of brackets: + int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; + int closeBracketDir = -openBracketDir; + QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); + QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); + double openBracketAngle = 0; + double closeBracketAngle = 0; + if (mTangentToData) + { + openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); + closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); + } + // draw opening bracket: + QTransform oldTransform = painter->transform(); + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(openBracketPos); + painter->rotate(openBracketAngle/M_PI*180.0); + drawBracket(painter, openBracketDir); + painter->setTransform(oldTransform); + // draw closing bracket: + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(closeBracketPos); + painter->rotate(closeBracketAngle/M_PI*180.0); + drawBracket(painter, closeBracketDir); + painter->setTransform(oldTransform); + } + } +} + +/*! \internal + + If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. + This method returns the angle in radians by which a bracket at the given \a dataIndex must be + rotated. + + The parameter \a direction must be set to either -1 or 1, representing whether it is an opening + or closing bracket. Since for slope calculation multiple data points are required, this defines + the direction in which the algorithm walks, starting at \a dataIndex, to average those data + points. (see \ref setTangentToData and \ref setTangentAverage) + + \a interface1d is the interface to the plottable's data which is used to query data coordinates. +*/ +double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const +{ + if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) + return 0; + direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 + + // how many steps we can actually go from index in the given direction without exceeding data bounds: + int averageCount; + if (direction < 0) + averageCount = qMin(mTangentAverage, dataIndex); + else + averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); + qDebug() << averageCount; + // calculate point average of averageCount points: + QVector points(averageCount); + QPointF pointsAverage; + int currentIndex = dataIndex; + for (int i=0; ikeyAxis(); + QCPAxis *valueAxis = mPlottable->valueAxis(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); + else + return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); +} +/* end of 'src/selectiondecorator-bracket.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisRect + \brief Holds multiple axes and arranges them in a rectangular shape. + + This class represents an axis rect, a rectangular area that is bounded on all sides with an + arbitrary number of axes. + + Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the + layout system allows to have multiple axis rects, e.g. arranged in a grid layout + (QCustomPlot::plotLayout). + + By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be + accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. + If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be + invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref + addAxes. To remove an axis, use \ref removeAxis. + + The axis rect layerable itself only draws a background pixmap or color, if specified (\ref + setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an + explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be + placed on other layers, independently of the axis rect. + + Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref + insetLayout and can be used to have other layout elements (or even other layouts with multiple + elements) hovering inside the axis rect. + + If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The + behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel + is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable + via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are + only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref + QCP::iRangeZoom. + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed + line on the far left indicates the viewport/widget border.
+*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const + + Returns the inset layout of this axis rect. It can be used to place other layout elements (or + even layouts with multiple other elements) inside/on top of an axis rect. + + \see QCPLayoutInset +*/ + +/*! \fn int QCPAxisRect::left() const + + Returns the pixel position of the left border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::right() const + + Returns the pixel position of the right border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::top() const + + Returns the pixel position of the top border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::bottom() const + + Returns the pixel position of the bottom border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::width() const + + Returns the pixel width of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::height() const + + Returns the pixel height of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QSize QCPAxisRect::size() const + + Returns the pixel size of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topLeft() const + + Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, + so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topRight() const + + Returns the top right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomLeft() const + + Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomRight() const + + Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::center() const + + Returns the center of this axis rect in pixels. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four + sides, the top and right axes are set invisible initially. +*/ +QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : + QCPLayoutElement(parentPlot), + mBackgroundBrush(Qt::NoBrush), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mInsetLayout(new QCPLayoutInset), + mRangeDrag(Qt::Horizontal|Qt::Vertical), + mRangeZoom(Qt::Horizontal|Qt::Vertical), + mRangeZoomFactorHorz(0.85), + mRangeZoomFactorVert(0.85), + mDragging(false) +{ + mInsetLayout->initializeParentPlot(mParentPlot); + mInsetLayout->setParentLayerable(this); + mInsetLayout->setParent(this); + + setMinimumSize(50, 50); + setMinimumMargins(QMargins(15, 15, 15, 15)); + mAxes.insert(QCPAxis::atLeft, QList()); + mAxes.insert(QCPAxis::atRight, QList()); + mAxes.insert(QCPAxis::atTop, QList()); + mAxes.insert(QCPAxis::atBottom, QList()); + + if (setupDefaultAxes) + { + QCPAxis *xAxis = addAxis(QCPAxis::atBottom); + QCPAxis *yAxis = addAxis(QCPAxis::atLeft); + QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); + QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); + setRangeDragAxes(xAxis, yAxis); + setRangeZoomAxes(xAxis, yAxis); + xAxis2->setVisible(false); + yAxis2->setVisible(false); + xAxis->grid()->setVisible(true); + yAxis->grid()->setVisible(true); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + xAxis2->grid()->setZeroLinePen(Qt::NoPen); + yAxis2->grid()->setZeroLinePen(Qt::NoPen); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + } +} + +QCPAxisRect::~QCPAxisRect() +{ + delete mInsetLayout; + mInsetLayout = 0; + + QList axesList = axes(); + for (int i=0; i ax(mAxes.value(type)); + if (index >= 0 && index < ax.size()) + { + return ax.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; + return 0; + } +} + +/*! + Returns all axes on the axis rect sides specified with \a types. + + \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of + multiple sides. + + \see axis +*/ +QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << mAxes.value(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << mAxes.value(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << mAxes.value(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << mAxes.value(QCPAxis::atBottom); + return result; +} + +/*! \overload + + Returns all axes of this axis rect. +*/ +QList QCPAxisRect::axes() const +{ + QList result; + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + result << it.value(); + } + return result; +} + +/*! + Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a + new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to + remove an axis, use \ref removeAxis instead of deleting it manually. + + You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was + previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership + of the axis, so you may not delete it afterwards. Further, the \a axis must have been created + with this axis rect as parent and with the same axis type as specified in \a type. If this is not + the case, a debug output is generated, the axis is not added, and the method returns 0. + + This method can not be used to move \a axis between axis rects. The same \a axis instance must + not be added multiple times to the same or different axis rects. + + If an axis rect side already contains one or more axes, the lower and upper endings of the new + axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref + QCPLineEnding::esHalfBar. + + \see addAxes, setupFullAxesBox +*/ +QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) +{ + QCPAxis *newAxis = axis; + if (!newAxis) + { + newAxis = new QCPAxis(this, type); + } else // user provided existing axis instance, do some sanity checks + { + if (newAxis->axisType() != type) + { + qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; + return 0; + } + if (newAxis->axisRect() != this) + { + qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; + return 0; + } + if (axes().contains(newAxis)) + { + qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; + return 0; + } + } + if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset + { + bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); + newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); + newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); + } + mAxes[type].append(newAxis); + + // reset convenience axis pointers on parent QCustomPlot if they are unset: + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + switch (type) + { + case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } + case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } + case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } + case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } + } + } + + return newAxis; +} + +/*! + Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an + or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. + + Returns a list of the added axes. + + \see addAxis, setupFullAxesBox +*/ +QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << addAxis(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << addAxis(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << addAxis(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << addAxis(QCPAxis::atBottom); + return result; +} + +/*! + Removes the specified \a axis from the axis rect and deletes it. + + Returns true on success, i.e. if \a axis was a valid axis in this axis rect. + + \see addAxis +*/ +bool QCPAxisRect::removeAxis(QCPAxis *axis) +{ + // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + if (it.value().contains(axis)) + { + if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) + it.value()[1]->setOffset(axis->offset()); + mAxes[it.key()].removeOne(axis); + if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) + parentPlot()->axisRemoved(axis); + delete axis; + return true; + } + } + qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); + return false; +} + +/*! + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom + specific axes, use the overloaded version of this method. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect) +{ + zoom(pixelRect, axes()); +} + +/*! \overload + + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) +{ + foreach (QCPAxis *axis, affectedAxes) + { + if (!axis) + { + qDebug() << Q_FUNC_INFO << "a passed axis was zero"; + continue; + } + QCPRange pixelRange; + if (axis->orientation() == Qt::Horizontal) + pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); + else + pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); + axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); + } +} + +/*! + Convenience function to create an axis on each side that doesn't have any axes yet and set their + visibility to true. Further, the top/right axes are assigned the following properties of the + bottom/left axes: + + \li range (\ref QCPAxis::setRange) + \li range reversed (\ref QCPAxis::setRangeReversed) + \li scale type (\ref QCPAxis::setScaleType) + \li tick visibility (\ref QCPAxis::setTicks) + \li number format (\ref QCPAxis::setNumberFormat) + \li number precision (\ref QCPAxis::setNumberPrecision) + \li tick count of ticker (\ref QCPAxisTicker::setTickCount) + \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) + + Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. + + If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom + and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. +*/ +void QCPAxisRect::setupFullAxesBox(bool connectRanges) +{ + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + if (axisCount(QCPAxis::atBottom) == 0) + xAxis = addAxis(QCPAxis::atBottom); + else + xAxis = axis(QCPAxis::atBottom); + + if (axisCount(QCPAxis::atLeft) == 0) + yAxis = addAxis(QCPAxis::atLeft); + else + yAxis = axis(QCPAxis::atLeft); + + if (axisCount(QCPAxis::atTop) == 0) + xAxis2 = addAxis(QCPAxis::atTop); + else + xAxis2 = axis(QCPAxis::atTop); + + if (axisCount(QCPAxis::atRight) == 0) + yAxis2 = addAxis(QCPAxis::atRight); + else + yAxis2 = axis(QCPAxis::atRight); + + xAxis->setVisible(true); + yAxis->setVisible(true); + xAxis2->setVisible(true); + yAxis2->setVisible(true); + xAxis2->setTickLabels(false); + yAxis2->setTickLabels(false); + + xAxis2->setRange(xAxis->range()); + xAxis2->setRangeReversed(xAxis->rangeReversed()); + xAxis2->setScaleType(xAxis->scaleType()); + xAxis2->setTicks(xAxis->ticks()); + xAxis2->setNumberFormat(xAxis->numberFormat()); + xAxis2->setNumberPrecision(xAxis->numberPrecision()); + xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); + xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); + + yAxis2->setRange(yAxis->range()); + yAxis2->setRangeReversed(yAxis->rangeReversed()); + yAxis2->setScaleType(yAxis->scaleType()); + yAxis2->setTicks(yAxis->ticks()); + yAxis2->setNumberFormat(yAxis->numberFormat()); + yAxis2->setNumberPrecision(yAxis->numberPrecision()); + yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); + yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); + + if (connectRanges) + { + connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); + connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); + } +} + +/*! + Returns a list of all the plottables that are associated with this axis rect. + + A plottable is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see graphs, items +*/ +QList QCPAxisRect::plottables() const +{ + // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries + QList result; + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that are associated with this axis rect. + + A graph is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see plottables, items +*/ +QList QCPAxisRect::graphs() const +{ + // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries + QList result; + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis rect. + + An item is considered associated with an axis rect if any of its positions has key or value axis + set to an axis that is in this axis rect, or if any of its positions has \ref + QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref + QCPAbstractItem::setClipAxisRect) is set to this axis rect. + + \see plottables, graphs +*/ +QList QCPAxisRect::items() const +{ + // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries + // and miss those items that have this axis rect as clipAxisRect. + QList result; + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + continue; + } + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdaxisRect() == this || + positions.at(posId)->keyAxis()->axisRect() == this || + positions.at(posId)->valueAxis()->axisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + This method is called automatically upon replot and doesn't need to be called by users of + QCPAxisRect. + + Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), + and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its + QCPInsetLayout::update function. + + \seebaseclassmethod +*/ +void QCPAxisRect::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + switch (phase) + { + case upPreparation: + { + QList allAxes = axes(); + for (int i=0; isetupTickVectors(); + break; + } + case upLayout: + { + mInsetLayout->setOuterRect(rect()); + break; + } + default: break; + } + + // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): + mInsetLayout->update(phase); +} + +/* inherits documentation from base class */ +QList QCPAxisRect::elements(bool recursive) const +{ + QList result; + if (mInsetLayout) + { + result << mInsetLayout; + if (recursive) + result << mInsetLayout->elements(recursive); + } + return result; +} + +/* inherits documentation from base class */ +void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPAxisRect::draw(QCPPainter *painter) +{ + drawBackground(painter); +} + +/*! + Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the + axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect + backgrounds are usually drawn below everything else. + + For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio + is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref + setBackground(const QBrush &brush). + + \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) +*/ +void QCPAxisRect::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! \overload + + Sets \a brush as the background brush. The axis rect background will be filled with this brush. + Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds + are usually drawn below everything else. + + The brush will be drawn before (under) any background pixmap, which may be specified with \ref + setBackground(const QPixmap &pm). + + To disable drawing of a background brush, set \a brush to Qt::NoBrush. + + \see setBackground(const QPixmap &pm) +*/ +void QCPAxisRect::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled + is set to true, you may control whether and how the aspect ratio of the original pixmap is + preserved with \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the axis rect dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to + define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. + \see setBackground, setBackgroundScaled +*/ +void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeDragAxes to retrieve a list with all set axes). + + \see setRangeDragAxes +*/ +QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); + else + return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); +} + +/*! + Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). + + \see setRangeZoomAxes +*/ +QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); + else + return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); +} + +/*! + Returns all range drag axes of the \a orientation provided. + + \see rangeZoomAxis, setRangeZoomAxes +*/ +QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; iQt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeDrag to enable the range dragging interaction. + + \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag +*/ +void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) +{ + mRangeDrag = orientations; +} + +/*! + Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation + corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, + QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical + axis is the left axis (yAxis). + + To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref + QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeZoom to enable the range zooming interaction. + + \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag +*/ +void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) +{ + mRangeZoom = orientations; +} + +/*! \overload + + Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on + the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to dragging interactions. + + \see setRangeZoomAxes +*/ +void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag + orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag + motion, use the overload taking two separate lists for horizontal and vertical dragging. +*/ +void QCPAxisRect::setRangeDragAxes(QList axes) +{ + QList horz, vert; + foreach (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical dragging, and + define specifically which axis reacts to which drag orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) +{ + mRangeDragHorzAxis.clear(); + foreach (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeDragVertAxis.clear(); + foreach (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on + the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. + + The two axes can be zoomed with different strengths, when different factors are passed to \ref + setRangeZoomFactor(double horizontalFactor, double verticalFactor). + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to zooming interactions. + + \see setRangeDragAxes +*/ +void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical range zooming. The + zoom orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom + interaction, use the overload taking two separate lists for horizontal and vertical zooming. +*/ +void QCPAxisRect::setRangeZoomAxes(QList axes) +{ + QList horz, vert; + foreach (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical zooming, and + define specifically which axis reacts to which zoom orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) +{ + mRangeZoomHorzAxis.clear(); + foreach (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeZoomVertAxis.clear(); + foreach (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with + \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to + let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal + and which is vertical, can be set with \ref setRangeZoomAxes. + + When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) + will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the + same scrolling direction will zoom out. +*/ +void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) +{ + mRangeZoomFactorHorz = horizontalFactor; + mRangeZoomFactorVert = verticalFactor; +} + +/*! \overload + + Sets both the horizontal and vertical zoom \a factor. +*/ +void QCPAxisRect::setRangeZoomFactor(double factor) +{ + mRangeZoomFactorHorz = factor; + mRangeZoomFactorVert = factor; +} + +/*! \internal + + Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a + pixmap. + + If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an + according filling inside the axis rect with the provided \a painter. + + Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the axis rect with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::drawBackground(QCPPainter *painter) +{ + // draw background fill: + if (mBackgroundBrush != Qt::NoBrush) + painter->fillRect(mRect, mBackgroundBrush); + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mRect.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); + } + } +} + +/*! \internal + + This function makes sure multiple axes on the side specified with \a type don't collide, but are + distributed according to their respective space requirement (QCPAxis::calculateMargin). + + It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the + one with index zero. + + This function is called by \ref calculateAutoMargin. +*/ +void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) +{ + const QList axesList = mAxes.value(type); + if (axesList.isEmpty()) + return; + + bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false + for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); + if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) + { + if (!isFirstVisible) + offset += axesList.at(i)->tickLengthIn(); + isFirstVisible = false; + } + axesList.at(i)->setOffset(offset); + } +} + +/* inherits documentation from base class */ +int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) +{ + if (!mAutoMargins.testFlag(side)) + qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; + + updateAxesOffset(QCPAxis::marginSideToAxisType(side)); + + // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call + const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); + if (axesList.size() > 0) + return axesList.last()->offset() + axesList.last()->calculateMargin(); + else + return 0; +} + +/*! \internal + + Reacts to a change in layout to potentially set the convenience axis pointers \ref + QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective + axes of this axis rect. This is only done if the respective convenience pointer is currently zero + and if there is no QCPAxisRect at position (0, 0) of the plot layout. + + This automation makes it simpler to replace the main axis rect with a newly created one, without + the need to manually reset the convenience pointers. +*/ +void QCPAxisRect::layoutChanged() +{ + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) + mParentPlot->xAxis = axis(QCPAxis::atBottom); + if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) + mParentPlot->yAxis = axis(QCPAxis::atLeft); + if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) + mParentPlot->xAxis2 = axis(QCPAxis::atTop); + if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) + mParentPlot->yAxis2 = axis(QCPAxis::atRight); + } +} + +/*! \internal + + Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is + pressed, the range dragging interaction is initialized (the actual range manipulation happens in + the \ref mouseMoveEvent). + + The mDragging flag is set to true and some anchor points are set that are needed to determine the + distance the mouse was dragged in the mouse move/release events later. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + mDragStartHorzRange.clear(); + for (int i=0; irange()); + mDragStartVertRange.clear(); + for (int i=0; irange()); + } + } +} + +/*! \internal + + Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a + preceding \ref mousePressEvent, the range is moved accordingly. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + // Mouse range dragging interaction: + if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + + if (mRangeDrag.testFlag(Qt::Horizontal)) + { + for (int i=0; i= mDragStartHorzRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag.testFlag(Qt::Vertical)) + { + for (int i=0; i= mDragStartVertRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot + { + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } + + } +} + +/* inherits documentation from base class */ +void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the + ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of + the scaling operation is the current cursor position inside the axis rect. The scaling factor is + dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural + zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. + + Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse + wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be + multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as + exponent of the range zoom factor. This takes care of the wheel direction automatically, by + inverting the factor, when the wheel step is negative (f^-1 = 1/f). +*/ +void QCPAxisRect::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) + { + if (mRangeZoom != 0) + { + double factor; + double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + if (mRangeZoom.testFlag(Qt::Horizontal)) + { + factor = qPow(mRangeZoomFactorHorz, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); + } + } + if (mRangeZoom.testFlag(Qt::Vertical)) + { + factor = qPow(mRangeZoomFactorVert, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); + } + } + mParentPlot->replot(); + } + } +} +/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractLegendItem + \brief The abstract base class for all entries in a QCPLegend. + + It defines a very basic interface for entries in a QCPLegend. For representing plottables in the + legend, the subclass \ref QCPPlottableLegendItem is more suitable. + + Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry + that's not even associated with a plottable). + + You must implement the following pure virtual functions: + \li \ref draw (from QCPLayerable) + + You inherit the following members you may use: + + + + + + + + +
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
+*/ + +/* start of documentation of signals */ + +/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) + + This signal is emitted when the selection state of this legend item has changed, either by user + interaction or by a direct call to \ref setSelected. +*/ + +/* end of documentation of signals */ + +/*! + Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not + cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. +*/ +QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : + QCPLayoutElement(parent->parentPlot()), + mParentLegend(parent), + mFont(parent->font()), + mTextColor(parent->textColor()), + mSelectedFont(parent->selectedFont()), + mSelectedTextColor(parent->selectedTextColor()), + mSelectable(true), + mSelected(false) +{ + setLayer(QLatin1String("legend")); + setMargins(QMargins(0, 0, 0, 0)); +} + +/*! + Sets the default font of this specific legend item to \a font. + + \see setTextColor, QCPLegend::setFont +*/ +void QCPAbstractLegendItem::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the default text color of this specific legend item to \a color. + + \see setFont, QCPLegend::setTextColor +*/ +void QCPAbstractLegendItem::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + When this legend item is selected, \a font is used to draw generic text, instead of the normal + font set with \ref setFont. + + \see setFont, QCPLegend::setSelectedFont +*/ +void QCPAbstractLegendItem::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + When this legend item is selected, \a color is used to draw generic text, instead of the normal + color set with \ref setTextColor. + + \see setTextColor, QCPLegend::setSelectedTextColor +*/ +void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether this specific legend item is selectable. + + \see setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + emit selectableChanged(mSelectable); + } +} + +/*! + Sets whether this specific legend item is selected. + + It is possible to set the selection state of this item by calling this function directly, even if + setSelectable is set to false. + + \see setSelectableParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + emit selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (!mParentPlot) return -1; + if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) + return -1; + + if (mRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); +} + +/* inherits documentation from base class */ +QRect QCPAbstractLegendItem::clipRect() const +{ + return mOuterRect; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableLegendItem + \brief A legend item representing a plottable with an icon and the plottable name. + + This is the standard legend item for plottables. It displays an icon of the plottable next to the + plottable name. The icon is drawn by the respective plottable itself (\ref + QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. + For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the + middle. + + Legend items of this type are always associated with one plottable (retrievable via the + plottable() function and settable with the constructor). You may change the font of the plottable + name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref + QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. + + The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend + creates/removes legend items of this type. + + Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of + QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout + interface, QCPLegend has specialized functions for handling legend items conveniently, see the + documentation of \ref QCPLegend. +*/ + +/*! + Creates a new legend item associated with \a plottable. + + Once it's created, it can be added to the legend via \ref QCPLegend::addItem. + + A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref + QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. +*/ +QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : + QCPAbstractLegendItem(parent), + mPlottable(plottable) +{ + setAntialiased(false); +} + +/*! \internal + + Returns the pen that shall be used to draw the icon border, taking into account the selection + state of this item. +*/ +QPen QCPPlottableLegendItem::getIconBorderPen() const +{ + return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); +} + +/*! \internal + + Returns the text color that shall be used to draw text, taking into account the selection state + of this item. +*/ +QColor QCPPlottableLegendItem::getTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} + +/*! \internal + + Returns the font that shall be used to draw text, taking into account the selection state of this + item. +*/ +QFont QCPPlottableLegendItem::getFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Draws the item with \a painter. The size and position of the drawn legend item is defined by the + parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref + maximumOuterSizeHint of this legend item. +*/ +void QCPPlottableLegendItem::draw(QCPPainter *painter) +{ + if (!mPlottable) return; + painter->setFont(getFont()); + painter->setPen(QPen(getTextColor())); + QSizeF iconSize = mParentLegend->iconSize(); + QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + QRectF iconRect(mRect.topLeft(), iconSize); + int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops + painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); + // draw icon: + painter->save(); + painter->setClipRect(iconRect, Qt::IntersectClip); + mPlottable->drawLegendIcon(painter, iconRect); + painter->restore(); + // draw icon border: + if (getIconBorderPen().style() != Qt::NoPen) + { + painter->setPen(getIconBorderPen()); + painter->setBrush(Qt::NoBrush); + int halfPen = qCeil(painter->pen().widthF()*0.5)+1; + painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped + painter->drawRect(iconRect); + } +} + +/*! \internal + + Calculates and returns the size of this item. This includes the icon, the text and the padding in + between. + + \seebaseclassmethod +*/ +QSize QCPPlottableLegendItem::minimumOuterSizeHint() const +{ + if (!mPlottable) return QSize(); + QSize result(0, 0); + QRect textRect; + QFontMetrics fontMetrics(getFont()); + QSize iconSize = mParentLegend->iconSize(); + textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); + result.setHeight(qMax(textRect.height(), iconSize.height())); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLegend +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLegend + \brief Manages a legend inside a QCustomPlot. + + A legend is a small box somewhere in the plot which lists plottables with their name and icon. + + A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the + plottable, for which a legend item shall be created. In the case of the main legend (\ref + QCustomPlot::legend), simply adding plottables to the plot while \ref + QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding + legend items. The legend item associated with a certain plottable can be removed with \ref + QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and + manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref + addItem, \ref removeItem, etc. + + Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref + QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement + "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds + an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as + mentioned above. In principle, any other layout elements may also be added to a legend via the + normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout + System\endlink for examples on how to add other elements to the legend and move it outside the axis + rect. + + Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control + in which order (column first or row first) the legend is filled up when calling \ref addItem, and + at which column or row wrapping occurs. + + By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the + inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another + position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend + outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement + interface. +*/ + +/* start of documentation of signals */ + +/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); + + This signal is emitted when the selection state of this legend has changed. + + \see setSelectedParts, setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs a new QCPLegend instance with default values. + + Note that by default, QCustomPlot already contains a legend ready to be used as \ref + QCustomPlot::legend +*/ +QCPLegend::QCPLegend() +{ + setFillOrder(QCPLayoutGrid::foRowsFirst); + setWrap(0); + + setRowSpacing(3); + setColumnSpacing(8); + setMargins(QMargins(7, 5, 7, 4)); + setAntialiased(false); + setIconSize(32, 18); + + setIconTextPadding(7); + + setSelectableParts(spLegendBox | spItems); + setSelectedParts(spNone); + + setBorderPen(QPen(Qt::black, 0)); + setSelectedBorderPen(QPen(Qt::blue, 2)); + setIconBorderPen(Qt::NoPen); + setSelectedIconBorderPen(QPen(Qt::blue, 2)); + setBrush(Qt::white); + setSelectedBrush(Qt::white); + setTextColor(Qt::black); + setSelectedTextColor(Qt::blue); +} + +QCPLegend::~QCPLegend() +{ + clearItems(); + if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) + mParentPlot->legendRemoved(this); +} + +/* no doc for getter, see setSelectedParts */ +QCPLegend::SelectableParts QCPLegend::selectedParts() const +{ + // check whether any legend elements selected, if yes, add spItems to return value + bool hasSelectedItems = false; + for (int i=0; iselected()) + { + hasSelectedItems = true; + break; + } + } + if (hasSelectedItems) + return mSelectedParts | spItems; + else + return mSelectedParts & ~spItems; +} + +/*! + Sets the pen, the border of the entire legend is drawn with. +*/ +void QCPLegend::setBorderPen(const QPen &pen) +{ + mBorderPen = pen; +} + +/*! + Sets the brush of the legend background. +*/ +void QCPLegend::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will + use this font by default. However, a different font can be specified on a per-item-basis by + accessing the specific legend item. + + This function will also set \a font on all already existing legend items. + + \see QCPAbstractLegendItem::setFont +*/ +void QCPLegend::setFont(const QFont &font) +{ + mFont = font; + for (int i=0; isetFont(mFont); + } +} + +/*! + Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) + will use this color by default. However, a different colors can be specified on a per-item-basis + by accessing the specific legend item. + + This function will also set \a color on all already existing legend items. + + \see QCPAbstractLegendItem::setTextColor +*/ +void QCPLegend::setTextColor(const QColor &color) +{ + mTextColor = color; + for (int i=0; isetTextColor(color); + } +} + +/*! + Sets the size of legend icons. Legend items that draw an icon (e.g. a visual + representation of the graph) will use this size by default. +*/ +void QCPLegend::setIconSize(const QSize &size) +{ + mIconSize = size; +} + +/*! \overload +*/ +void QCPLegend::setIconSize(int width, int height) +{ + mIconSize.setWidth(width); + mIconSize.setHeight(height); +} + +/*! + Sets the horizontal space in pixels between the legend icon and the text next to it. + Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the + name of the graph) will use this space by default. +*/ +void QCPLegend::setIconTextPadding(int padding) +{ + mIconTextPadding = padding; +} + +/*! + Sets the pen used to draw a border around each legend icon. Legend items that draw an + icon (e.g. a visual representation of the graph) will use this pen by default. + + If no border is wanted, set this to \a Qt::NoPen. +*/ +void QCPLegend::setIconBorderPen(const QPen &pen) +{ + mIconBorderPen = pen; +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPLegend::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + emit selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected + doesn't contain \ref spItems, those items become deselected. + + The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions + contains iSelectLegend. You only need to call this function when you wish to change the selection + state manually. + + This function can change the selection state of a part even when \ref setSelectableParts was set to a + value that actually excludes the part. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set + before, because there's no way to specify which exact items to newly select. Do this by calling + \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, + setSelectedFont +*/ +void QCPLegend::setSelectedParts(const SelectableParts &selected) +{ + SelectableParts newSelected = selected; + mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed + + if (mSelectedParts != newSelected) + { + if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) + { + qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; + newSelected &= ~spItems; + } + if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection + { + for (int i=0; isetSelected(false); + } + } + mSelectedParts = newSelected; + emit selectionChanged(mSelectedParts); + } +} + +/*! + When the legend box is selected, this pen is used to draw the border instead of the normal pen + set via \ref setBorderPen. + + \see setSelectedParts, setSelectableParts, setSelectedBrush +*/ +void QCPLegend::setSelectedBorderPen(const QPen &pen) +{ + mSelectedBorderPen = pen; +} + +/*! + Sets the pen legend items will use to draw their icon borders, when they are selected. + + \see setSelectedParts, setSelectableParts, setSelectedFont +*/ +void QCPLegend::setSelectedIconBorderPen(const QPen &pen) +{ + mSelectedIconBorderPen = pen; +} + +/*! + When the legend box is selected, this brush is used to draw the legend background instead of the normal brush + set via \ref setBrush. + + \see setSelectedParts, setSelectableParts, setSelectedBorderPen +*/ +void QCPLegend::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the default font that is used by legend items when they are selected. + + This function will also set \a font on all already existing legend items. + + \see setFont, QCPAbstractLegendItem::setSelectedFont +*/ +void QCPLegend::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; + for (int i=0; isetSelectedFont(font); + } +} + +/*! + Sets the default text color that is used by legend items when they are selected. + + This function will also set \a color on all already existing legend items. + + \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor +*/ +void QCPLegend::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; + for (int i=0; isetSelectedTextColor(color); + } +} + +/*! + Returns the item with index \a i. + + Note that the linear index depends on the current fill order (\ref setFillOrder). + + \see itemCount, addItem, itemWithPlottable +*/ +QCPAbstractLegendItem *QCPLegend::item(int index) const +{ + return qobject_cast(elementAt(index)); +} + +/*! + Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns 0. + + \see hasItemWithPlottable +*/ +QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + for (int i=0; i(item(i))) + { + if (pli->plottable() == plottable) + return pli; + } + } + return 0; +} + +/*! + Returns the number of items currently in the legend. + + Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid + base class which allows creating empty cells), they are included in the returned count. + + \see item +*/ +int QCPLegend::itemCount() const +{ + return elementCount(); +} + +/*! + Returns whether the legend contains \a item. + + \see hasItemWithPlottable +*/ +bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const +{ + for (int i=0; iitem(i)) + return true; + } + return false; +} + +/*! + Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns false. + + \see itemWithPlottable +*/ +bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + return itemWithPlottable(plottable); +} + +/*! + Adds \a item to the legend, if it's not present already. The element is arranged according to the + current fill order (\ref setFillOrder) and wrapping (\ref setWrap). + + Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. + + The legend takes ownership of the item. + + \see removeItem, item, hasItem +*/ +bool QCPLegend::addItem(QCPAbstractLegendItem *item) +{ + return addElement(item); +} + +/*! \overload + + Removes the item with the specified \a index from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes + elements derived from \ref QCPAbstractLegendItem. + + \see itemCount, clearItems +*/ +bool QCPLegend::removeItem(int index) +{ + if (QCPAbstractLegendItem *ali = item(index)) + { + bool success = remove(ali); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; + } else + return false; +} + +/*! \overload + + Removes \a item from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. + + \see clearItems +*/ +bool QCPLegend::removeItem(QCPAbstractLegendItem *item) +{ + bool success = remove(item); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; +} + +/*! + Removes all items from the legend. +*/ +void QCPLegend::clearItems() +{ + for (int i=itemCount()-1; i>=0; --i) + removeItem(i); +} + +/*! + Returns the legend items that are currently selected. If no items are selected, + the list is empty. + + \see QCPAbstractLegendItem::setSelected, setSelectable +*/ +QList QCPLegend::selectedItems() const +{ + QList result; + for (int i=0; iselected()) + result.append(ali); + } + } + return result; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing main legend elements. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); +} + +/*! \internal + + Returns the pen used to paint the border of the legend, taking into account the selection state + of the legend box. +*/ +QPen QCPLegend::getBorderPen() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; +} + +/*! \internal + + Returns the brush used to paint the background of the legend, taking into account the selection + state of the legend box. +*/ +QBrush QCPLegend::getBrush() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; +} + +/*! \internal + + Draws the legend box with the provided \a painter. The individual legend items are layerables + themselves, thus are drawn independently. +*/ +void QCPLegend::draw(QCPPainter *painter) +{ + // draw background rect: + painter->setBrush(getBrush()); + painter->setPen(getBorderPen()); + painter->drawRect(mOuterRect); +} + +/* inherits documentation from base class */ +double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) + return -1; + + if (mOuterRect.contains(pos.toPoint())) + { + if (details) details->setValue(spLegendBox); + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/* inherits documentation from base class */ +void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + mSelectedParts = selectedParts(); // in case item selection has changed + if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPLegend::deselectEvent(bool *selectionStateChanged) +{ + mSelectedParts = selectedParts(); // in case item selection has changed + if (mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(selectedParts() & ~spLegendBox); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPLegend::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractLegendItem::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) +{ + if (parentPlot && !parentPlot->legend) + parentPlot->legend = this; +} +/* end of 'src/layoutelements/layoutelement-legend.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPTextElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPTextElement + \brief A layout element displaying a text + + The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, + \ref setTextColor, and \ref setTextFlags. + + A text element can be added as follows: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation +*/ + +/* start documentation of signals */ + +/*! \fn void QCPTextElement::selectionChanged(bool selected) + + This signal is emitted when the selection state has changed to \a selected, either by user + interaction or by a direct call to \ref setSelected. + + \see setSelected, setSelectable +*/ + +/*! \fn void QCPTextElement::clicked(QMouseEvent *event) + + This signal is emitted when the text element is clicked. + + \see doubleClicked, selectTest +*/ + +/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) + + This signal is emitted when the text element is double clicked. + + \see clicked, selectTest +*/ + +/* end documentation of signals */ + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref + setText). +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mText(), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mFont.setPointSizeF(pointSize); + mSelectedFont = parentPlot->font(); + mSelectedFont.setPointSizeF(pointSize); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize and the specified \a fontFamily. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(fontFamily, pointSize)), + mTextColor(Qt::black), + mSelectedFont(QFont(fontFamily, pointSize)), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with the specified \a font. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(font), + mTextColor(Qt::black), + mSelectedFont(font), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! + Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". + + \see setFont, setTextColor, setTextFlags +*/ +void QCPTextElement::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of + \c Qt::AlignmentFlag and \c Qt::TextFlag enums. + + Possible enums are: + - Qt::AlignLeft + - Qt::AlignRight + - Qt::AlignHCenter + - Qt::AlignJustify + - Qt::AlignTop + - Qt::AlignBottom + - Qt::AlignVCenter + - Qt::AlignCenter + - Qt::TextDontClip + - Qt::TextSingleLine + - Qt::TextExpandTabs + - Qt::TextShowMnemonic + - Qt::TextWordWrap + - Qt::TextIncludeTrailingSpaces +*/ +void QCPTextElement::setTextFlags(int flags) +{ + mTextFlags = flags; +} + +/*! + Sets the \a font of the text. + + \see setTextColor, setSelectedFont +*/ +void QCPTextElement::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the \a color of the text. + + \see setFont, setSelectedTextColor +*/ +void QCPTextElement::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). + + \see setFont +*/ +void QCPTextElement::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). + + \see setTextColor +*/ +void QCPTextElement::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether the user may select this text element. + + Note that even when \a selectable is set to false, the selection state may be changed + programmatically via \ref setSelected. +*/ +void QCPTextElement::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + emit selectableChanged(mSelectable); + } +} + +/*! + Sets the selection state of this text element to \a selected. If the selection has changed, \ref + selectionChanged is emitted. + + Note that this function can change the selection state independently of the current \ref + setSelectable state. +*/ +void QCPTextElement::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + emit selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/* inherits documentation from base class */ +void QCPTextElement::draw(QCPPainter *painter) +{ + painter->setFont(mainFont()); + painter->setPen(QPen(mainTextColor())); + painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); +} + +/* inherits documentation from base class */ +QSize QCPTextElement::minimumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +QSize QCPTextElement::maximumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.setWidth(QWIDGETSIZE_MAX); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPTextElement::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/*! + Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is + within the bounding box of the text element's text. Note that this bounding box is updated in the + draw call. + + If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text + element is not selectable (\ref setSelectable), returns -1. + + \seebaseclassmethod +*/ +double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + if (mTextBoundingRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/*! + Accepts the mouse event in order to emit the according click signal in the \ref + mouseReleaseEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->accept(); +} + +/*! + Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref + mousePressEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) + emit clicked(event); +} + +/*! + Emits the \ref doubleClicked signal. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + emit doubleClicked(event); +} + +/*! \internal + + Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to + true, else mFont is returned. +*/ +QFont QCPTextElement::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to + true, else mTextColor is returned. +*/ +QColor QCPTextElement::mainTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} +/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScale +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScale + \brief A color scale for use with color coding data such as QCPColorMap + + This layout element can be placed on the plot to correlate a color gradient with data values. It + is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". + + \image html QCPColorScale.png + + The color scale can be either horizontal or vertical, as shown in the image above. The + orientation and the side where the numbers appear is controlled with \ref setType. + + Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are + connected, they share their gradient, data range and data scale type (\ref setGradient, \ref + setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color + scale, to make them all synchronize these properties. + + To have finer control over the number display and axis behaviour, you can directly access the + \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if + you want to change the number of automatically generated ticks, call + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount + + Placing a color scale next to the main axis rect works like with any other layout element: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation + In this case we have placed it to the right of the default axis rect, so it wasn't necessary to + call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color + scale can be set with \ref setLabel. + + For optimum appearance (like in the image above), it may be desirable to line up the axis rect and + the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup + + Color scales are initialized with a non-zero minimum top and bottom margin (\ref + setMinimumMargins), because vertical color scales are most common and the minimum top/bottom + margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a + horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you + might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPAxis *QCPColorScale::axis() const + + Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the + appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its + interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref + setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref + QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on + the QCPColorScale or on its QCPAxis. + + If the type of the color scale is changed with \ref setType, the axis returned by this method + will change, too, to either the left, right, bottom or top axis, depending on which type was set. +*/ + +/* end documentation of signals */ +/* start documentation of signals */ + +/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); + + This signal is emitted when the data range changes. + + \see setDataRange +*/ + +/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the data scale type changes. + + \see setDataScaleType +*/ + +/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); + + This signal is emitted when the gradient changes. + + \see setGradient +*/ + +/* end documentation of signals */ + +/*! + Constructs a new QCPColorScale. +*/ +QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight + mDataScaleType(QCPAxis::stLinear), + mBarWidth(20), + mAxisRect(new QCPColorScaleAxisRectPrivate(this)) +{ + setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) + setType(QCPAxis::atRight); + setDataRange(QCPRange(0, 6)); +} + +QCPColorScale::~QCPColorScale() +{ + delete mAxisRect; +} + +/* undocumented getter */ +QString QCPColorScale::label() const +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return QString(); + } + + return mColorAxis.data()->label(); +} + +/* undocumented getter */ +bool QCPColorScale::rangeDrag() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/* undocumented getter */ +bool QCPColorScale::rangeZoom() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/*! + Sets at which side of the color scale the axis is placed, and thus also its orientation. + + Note that after setting \a type to a different value, the axis returned by \ref axis() will + be a different one. The new axis will adopt the following properties from the previous axis: The + range, scale type, label and ticker (the latter will be shared and not copied). +*/ +void QCPColorScale::setType(QCPAxis::AxisType type) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + if (mType != type) + { + mType = type; + QCPRange rangeTransfer(0, 6); + QString labelTransfer; + QSharedPointer tickerTransfer; + // transfer/revert some settings on old axis if it exists: + bool doTransfer = (bool)mColorAxis; + if (doTransfer) + { + rangeTransfer = mColorAxis.data()->range(); + labelTransfer = mColorAxis.data()->label(); + tickerTransfer = mColorAxis.data()->ticker(); + mColorAxis.data()->setLabel(QString()); + disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; + foreach (QCPAxis::AxisType atype, allAxisTypes) + { + mAxisRect.data()->axis(atype)->setTicks(atype == mType); + mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); + } + // set new mColorAxis pointer: + mColorAxis = mAxisRect.data()->axis(mType); + // transfer settings to new axis: + if (doTransfer) + { + mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) + mColorAxis.data()->setLabel(labelTransfer); + mColorAxis.data()->setTicker(tickerTransfer); + } + connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); + } +} + +/*! + Sets the range spanned by the color gradient and that is shown by the axis in the color scale. + + It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its range with \ref + QCPAxis::setRange. + + \see setDataScaleType, setGradient, rescaleDataRange +*/ +void QCPColorScale::setDataRange(const QCPRange &dataRange) +{ + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + mDataRange = dataRange; + if (mColorAxis) + mColorAxis.data()->setRange(mDataRange); + emit dataRangeChanged(mDataRange); + } +} + +/*! + Sets the scale type of the color scale, i.e. whether values are linearly associated with colors + or logarithmically. + + It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its scale type with \ref + QCPAxis::setScaleType. + + \see setDataRange, setGradient +*/ +void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + if (mColorAxis) + mColorAxis.data()->setScaleType(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + emit dataScaleTypeChanged(mDataScaleType); + } +} + +/*! + Sets the color gradient that will be used to represent data values. + + It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. + + \see setDataRange, setDataScaleType +*/ +void QCPColorScale::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + if (mAxisRect) + mAxisRect.data()->mGradientImageInvalidated = true; + emit gradientChanged(mGradient); + } +} + +/*! + Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on + the internal \ref axis. +*/ +void QCPColorScale::setLabel(const QString &str) +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return; + } + + mColorAxis.data()->setLabel(str); +} + +/*! + Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed + will have. +*/ +void QCPColorScale::setBarWidth(int width) +{ + mBarWidth = width; +} + +/*! + Sets whether the user can drag the data range (\ref setDataRange). + + Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeDrag(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeDrag(0); +} + +/*! + Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. + + Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeZoom(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeZoom(0); +} + +/*! + Returns a list of all the color maps associated with this color scale. +*/ +QList QCPColorScale::colorMaps() const +{ + QList result; + for (int i=0; iplottableCount(); ++i) + { + if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) + if (cm->colorScale() == this) + result.append(cm); + } + return result; +} + +/*! + Changes the data range such that all color maps associated with this color scale are fully mapped + to the gradient in the data dimension. + + \see setDataRange +*/ +void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) +{ + QList maps = colorMaps(); + QCPRange newRange; + bool haveRange = false; + QCP::SignDomain sign = QCP::sdBoth; + if (mDataScaleType == QCPAxis::stLogarithmic) + sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + for (int i=0; irealVisibility() && onlyVisibleMaps) + continue; + QCPRange mapRange; + if (maps.at(i)->colorScale() == this) + { + bool currentFoundRange = true; + mapRange = maps.at(i)->data()->dataBounds(); + if (sign == QCP::sdPositive) + { + if (mapRange.lower <= 0 && mapRange.upper > 0) + mapRange.lower = mapRange.upper*1e-3; + else if (mapRange.lower <= 0 && mapRange.upper <= 0) + currentFoundRange = false; + } else if (sign == QCP::sdNegative) + { + if (mapRange.upper >= 0 && mapRange.lower < 0) + mapRange.upper = mapRange.lower*1e-3; + else if (mapRange.upper >= 0 && mapRange.lower >= 0) + currentFoundRange = false; + } + if (currentFoundRange) + { + if (!haveRange) + newRange = mapRange; + else + newRange.expand(mapRange); + haveRange = true; + } + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mDataScaleType == QCPAxis::stLinear) + { + newRange.lower = center-mDataRange.size()/2.0; + newRange.upper = center+mDataRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); + newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); + } + } + setDataRange(newRange); + } +} + +/* inherits documentation from base class */ +void QCPColorScale::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + mAxisRect.data()->update(phase); + + switch (phase) + { + case upMargins: + { + if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) + { + setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + } else + { + setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); + setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); + } + break; + } + case upLayout: + { + mAxisRect.data()->setOuterRect(rect()); + break; + } + default: break; + } +} + +/* inherits documentation from base class */ +void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mousePressEvent(event, details); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseMoveEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseReleaseEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::wheelEvent(QWheelEvent *event) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->wheelEvent(event); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScaleAxisRectPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScaleAxisRectPrivate + + \internal + \brief An axis rect subclass for use in a QCPColorScale + + This is a private class and not part of the public QCustomPlot interface. + + It provides the axis rect functionality for the QCPColorScale class. +*/ + + +/*! + Creates a new instance, as a child of \a parentColorScale. +*/ +QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : + QCPAxisRect(parentColorScale->parentPlot(), true), + mParentColorScale(parentColorScale), + mGradientImageInvalidated(true) +{ + setParentLayerable(parentColorScale); + setMinimumMargins(QMargins(0, 0, 0, 0)); + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + foreach (QCPAxis::AxisType type, allAxisTypes) + { + axis(type)->setVisible(true); + axis(type)->grid()->setVisible(false); + axis(type)->setPadding(0); + connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); + connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); + } + + connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); + + // make layer transfers of color scale transfer to axis rect and axes + // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); + foreach (QCPAxis::AxisType type, allAxisTypes) + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); +} + +/*! \internal + + Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws + it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. + + \seebaseclassmethod +*/ +void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) +{ + if (mGradientImageInvalidated) + updateGradientImage(); + + bool mirrorHorz = false; + bool mirrorVert = false; + if (mParentColorScale->mColorAxis) + { + mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); + mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); + } + + painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); + QCPAxisRect::draw(painter); +} + +/*! \internal + + Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to + generate a gradient image. This gradient image will be used in the \ref draw method. +*/ +void QCPColorScaleAxisRectPrivate::updateGradientImage() +{ + if (rect().isEmpty()) + return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + int n = mParentColorScale->mGradient.levelCount(); + int w, h; + QVector data(n); + for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) + { + w = n; + h = rect().height(); + mGradientImage = QImage(w, h, format); + QVector pixels; + for (int y=0; y(mGradientImage.scanLine(y))); + mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); + for (int y=1; y(mGradientImage.scanLine(y)); + const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); + for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + foreach (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectedParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); + else + axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); + } + } +} + +/*! \internal + + This slot is connected to the selectableChanged signals of the four axes in the constructor. It + synchronizes the selectability of the axes. +*/ +void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) +{ + // synchronize axis base selectability: + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + foreach (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectableParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); + else + axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); + } + } +} +/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ + + +/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraphData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraphData + \brief Holds the data of one single data point for QCPGraph. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPGraphDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPGraphData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPGraphData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and value set to zero. +*/ +QCPGraphData::QCPGraphData() : + key(0), + value(0) +{ +} + +/*! + Constructs a data point with the specified \a key and \a value. +*/ +QCPGraphData::QCPGraphData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraph +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraph + \brief A plottable representing a graph in a plot. + + \image html QCPGraph.png + + Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be + accessed via QCustomPlot::graph. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPGraphDataContainer. + + Graphs are used to display single-valued data. Single-valued means that there should only be one + data point per unique key coordinate. In other words, the graph can't have \a loops. If you do + want to plot non-single-valued curves, rather use the QCPCurve plottable. + + Gaps in the graph line can be created by adding data points with NaN as value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpgraph-appearance Changing the appearance + + The appearance of the graph is mainly determined by the line style, scatter style, brush and pen + of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). + + \subsection filling Filling under or between graphs + + QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to + the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, + just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. + + By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill + between this graph and another one, call \ref setChannelFillGraph with the other graph as + parameter. + + \see QCustomPlot::addGraph, QCustomPlot::graph +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPGraph::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually + but use QCustomPlot::removePlottable() instead. + + To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. +*/ +QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // special handling for QCPGraphs to maintain the simple graph interface: + mParentPlot->registerGraph(this); + + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setLineStyle(lsLine); + setScatterSkip(0); + setChannelFillGraph(0); + setAdaptiveSampling(true); +} + +QCPGraph::~QCPGraph() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. + Modifying the data in the container will then affect all graphs that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the graph's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 + + \see addData +*/ +void QCPGraph::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to + \ref lsNone and \ref setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPGraph::setLineStyle(LineStyle ls) +{ + mLineStyle = ls; +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points + are drawn (e.g. for line-only-plots with appropriate line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPGraph::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPGraph::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets the target graph for filling the area between this graph and \a targetGraph with the current + brush (\ref setBrush). + + When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To + disable any filling, set the brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) +{ + // prevent setting channel target to this graph itself: + if (targetGraph == this) + { + qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; + mChannelFillGraph = 0; + return; + } + // prevent setting channel target to a graph not in the plot: + if (targetGraph && targetGraph->mParentPlot != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; + mChannelFillGraph = 0; + return; + } + + mChannelFillGraph = targetGraph; +} + +/*! + Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive + sampling technique can drastically improve the replot performance for graphs with a larger number + of points (e.g. above 10,000), without notably changing the appearance of the graph. + + By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive + sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no + disadvantage in almost all cases. + + \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" + + As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are + reproduced reliably, as well as the overall shape of the data set. The replot time reduces + dramatically though. This allows QCustomPlot to display large amounts of data in realtime. + + \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" + + Care must be taken when using high-density scatter plots in combination with adaptive sampling. + The adaptive sampling algorithm treats scatter plots more carefully than line plots which still + gives a significant reduction of replot times, but not quite as much as for line plots. This is + because scatter plots inherently need more data points to be preserved in order to still resemble + the original, non-adaptive-sampling plot. As shown above, the results still aren't quite + identical, as banding occurs for the outer data points. This is in fact intentional, such that + the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, + depends on the point density, i.e. the number of points in the plot. + + For some situations with scatter plots it might thus be desirable to manually turn adaptive + sampling off. For example, when saving the plot to disk. This can be achieved by setting \a + enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled + back to true afterwards. +*/ +void QCPGraph::setAdaptiveSampling(bool enabled) +{ + mAdaptiveSampling = enabled; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(double key, double value) +{ + mDataContainer->add(QCPGraphData(key, value)); +} + +/* inherits documentation from base class */ +double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPGraph::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + if (mLineStyle == lsNone && mScatterStyle.isNone()) return; + + QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + // get line pixel points appropriate to line style: + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) + getLines(&lines, lineDataRange); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPGraphDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } +#endif + + // draw fill of graph: + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + drawFill(painter, &lines); + + // draw line: + if (mLineStyle != lsNone) + { + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + painter->setBrush(Qt::NoBrush); + if (mLineStyle == lsImpulse) + drawImpulsePlot(painter, lines); + else + drawLinePlot(painter, lines); // also step plots can be drawn as a line plot + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i)); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches + out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. + according to the line style of the graph. + + \a lines will be filled with points in pixel coordinates, that can be drawn with the according + draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines + aren't necessarily the original data points. For example, step line styles require additional + points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a + lines vector will be empty. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. + + \see getScatters +*/ +void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const +{ + if (!lines) return; + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + lines->clear(); + return; + } + + QVector lineData; + if (mLineStyle != lsNone) + getOptimizedLineData(&lineData, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) + std::reverse(lineData.begin(), lineData.end()); + + switch (mLineStyle) + { + case lsNone: lines->clear(); break; + case lsLine: *lines = dataToLines(lineData); break; + case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; + case lsStepRight: *lines = dataToStepRightLines(lineData); break; + case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; + case lsImpulse: *lines = dataToImpulseLines(lineData); break; + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then + converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be + passed to \ref drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. +*/ +void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const +{ + if (!scatters) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } + + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + scatters->clear(); + return; + } + + QVector data; + getOptimizedScatterData(&data, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) + std::reverse(data.begin(), data.end()); + + scatters->resize(data.size()); + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } + } else + { + for (int i=0; icoordToPixel(data.at(i).key)); + (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + } +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsLine. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + result[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key)); + result[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepLeft. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepLeftLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(lastValue); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(key); + result[i*2+1].setY(lastValue); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepRight. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepRightLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(value); + result[i*2+0].setY(lastKey); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(value); + result[i*2+1].setY(lastKey); + } + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(lastKey); + result[i*2+0].setY(value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(lastKey); + result[i*2+1].setY(value); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepCenter. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepCenterLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastValue); + result[0].setY(lastKey); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(lastValue); + result[i*2-1].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + } + result[data.size()*2-1].setX(lastValue); + result[data.size()*2-1].setY(lastKey); + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastKey); + result[0].setY(lastValue); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(key); + result[i*2-1].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + } + result[data.size()*2-1].setX(lastKey); + result[data.size()*2-1].setY(lastValue); + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsImpulse. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot +*/ +QVector QCPGraph::dataToImpulseLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(valueAxis->coordToPixel(0)); + result[i*2+0].setY(key); + result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(valueAxis->coordToPixel(0)); + result[i*2+1].setX(key); + result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Draws the fill of the graph using the specified \a painter, with the currently set brush. + + Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref + getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. + + In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), + this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to + operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN + segments of the two involved graphs, before passing the overlapping pairs to \ref + getChannelFillPolygon. + + Pass the points of this graph's line as \a lines, in pixel coordinates. + + \see drawLinePlot, drawImpulsePlot, drawScatterPlot +*/ +void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const +{ + if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot + if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; + + applyFillAntialiasingHint(painter); + QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); + if (!mChannelFillGraph) + { + // draw base fill under graph, fill goes all the way to the zero-value-line: + for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); + } else + { + // draw fill between this graph and mChannelFillGraph: + QVector otherLines; + mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); + if (!otherLines.isEmpty()) + { + QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); + QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); + for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); + } + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawLinePlot, drawImpulsePlot +*/ +void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const +{ + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in + pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines + from the regular graph data points. + + \see drawLinePlot, drawScatterPlot +*/ +void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + QPen oldPen = painter->pen(); + QPen newPen = painter->pen(); + newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line + painter->setPen(newPen); + painter->drawLines(lines); + painter->setPen(oldPen); + } +} + +/*! \internal + + Returns via \a lineData the data points that need to be visualized for this graph when plotting + graph lines, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getLines to retrieve the basic working set of data. + + \see getOptimizedScatterData +*/ +void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const +{ + if (!lineData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (begin == end) return; + + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + QCPGraphDataContainer::const_iterator it = begin; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double lastIntervalEndKey = currentIntervalStartKey; + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary + { + if (it->value < minValue) + minValue = it->value; + else if (it->value > maxValue) + maxValue = it->value; + ++intervalDataCount; + } else // new pixel interval started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + lastIntervalEndKey = (it-1)->key; + minValue = it->value; + maxValue = it->value; + currentIntervalFirstPoint = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + ++it; + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + lineData->resize(dataCount); + std::copy(begin, end, lineData->begin()); + } +} + +/*! \internal + + Returns via \a scatterData the data points that need to be visualized for this graph when + plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getScatters to retrieve the basic working set of data. + + \see getOptimizedLineData +*/ +void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const +{ + if (!scatterData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int beginIndex = begin-mDataContainer->constBegin(); + int endIndex = end-mDataContainer->constBegin(); + while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++beginIndex; + ++begin; + } + if (begin == end) return; + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + double valueMaxRange = valueAxis->range().upper; + double valueMinRange = valueAxis->range().lower; + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator minValueIt = it; + QCPGraphDataContainer::const_iterator maxValueIt = it; + QCPGraphDataContainer::const_iterator currentIntervalStart = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + // main loop over data points: + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary + { + if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) + { + minValue = it->value; + minValueIt = it; + } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) + { + maxValue = it->value; + maxValueIt = it; + } + ++intervalDataCount; + } else // new pixel started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else + intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + minValue = it->value; + maxValue = it->value; + currentIntervalStart = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int intervalItIndex = intervalIt-mDataContainer->constBegin(); + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: + { + intervalItIndex += scatterModulo; + if (intervalItIndex < itIndex) + intervalIt += scatterModulo; + else + { + intervalIt = it; + intervalItIndex = itIndex; + } + } + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + scatterData->reserve(dataCount); + while (it != end) + { + scatterData->append(*it); + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + This method takes into account that the drawing of data lines at the axis rect border always + requires the points just outside the visible axis range. So \a begin and \a end may actually + indicate a range that contains one additional data point to the left and right of the visible + axis range. +*/ +void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + if (rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + } else + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + // get visible data range: + begin = mDataContainer->findBegin(keyAxis->range().lower); + end = mDataContainer->findEnd(keyAxis->range().upper); + // limit lower/upperEnd to rangeRestriction: + mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything + } +} + +/*! \internal + + This method goes through the passed points in \a lineData and returns a list of the segments + which don't contain NaN data points. + + \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check + for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c + Qt::Vertical, the \a x member is checked. + + \see getOverlappingSegments, drawFill +*/ +QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const +{ + QVector result; + const int n = lineData->size(); + + QCPDataRange currentSegment(-1, -1); + int i = 0; + + if (keyOrientation == Qt::Horizontal) + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } else // keyOrientation == Qt::Vertical + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } + return result; +} + +/*! \internal + + This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and + \a otherSegments, and their associated point data \a thisData and \a otherData. + + It returns all pairs of segments (the first from \a thisSegments, the second from \a + otherSegments), which overlap in plot coordinates. + + This method is useful in the case of a channel fill between two graphs, when only those non-NaN + segments which actually overlap in their key coordinate shall be considered for drawing a channel + fill polygon. + + It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and + that the segments don't overlap themselves. The same is assumed for the segments in \a + otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. + + \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon +*/ +QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const +{ + QVector > result; + if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) + return result; + + int thisIndex = 0; + int otherIndex = 0; + const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; + while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) + { + if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++thisIndex; + continue; + } + if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++otherIndex; + continue; + } + double thisLower, thisUpper, otherLower, otherUpper; + if (!verticalKey) + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); + } else + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); + } + + int bPrecedence; + if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) + result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); + + if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment + ++otherIndex; + else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment + ++thisIndex; + } + + return result; +} + +/*! \internal + + Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) + have overlap. + + The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the + \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher + coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if + both segment's upper bounds are identical, 0 is returned as \a bPrecedence. + + It is assumed that the lower bounds always have smaller or equal values than the upper bounds. + + \see getOverlappingSegments +*/ +bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const +{ + bPrecedence = 0; + if (aLower > bUpper) + { + bPrecedence = -1; + return false; + } else if (bLower > aUpper) + { + bPrecedence = 1; + return false; + } else + { + if (aUpper > bUpper) + bPrecedence = -1; + else if (aUpper < bUpper) + bPrecedence = 1; + + return true; + } +} + +/*! \internal + + Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. + The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates + is in positive or negative infinity. So this case is handled separately by just closing the fill + polygon on the axis which lies in the direction towards the zero value. + + \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether + the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or + y value of the returned point, respectively. +*/ +QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + QPointF result; + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + if (keyAxis->orientation() == Qt::Horizontal) + { + result.setX(matchingDataPoint.x()); + result.setY(valueAxis->coordToPixel(0)); + } else // keyAxis->orientation() == Qt::Vertical + { + result.setX(valueAxis->coordToPixel(0)); + result.setY(matchingDataPoint.y()); + } + } else // valueAxis->mScaleType == QCPAxis::stLogarithmic + { + // In logarithmic scaling we can't just draw to value 0 so we just fill all the way + // to the axis which is in the direction towards 0 + if (keyAxis->orientation() == Qt::Vertical) + { + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setX(keyAxis->axisRect()->right()); + else + result.setX(keyAxis->axisRect()->left()); + result.setY(matchingDataPoint.y()); + } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) + { + result.setX(matchingDataPoint.x()); + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setY(keyAxis->axisRect()->top()); + else + result.setY(keyAxis->axisRect()->bottom()); + } + } + return result; +} + +/*! \internal + + Returns the polygon needed for drawing normal fills between this graph and the key axis. + + Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment + which shall be used for the fill. The collection of \a lineData points described by \a segment + must not contain NaN data points (see \ref getNonNanSegments). + + The returned fill polygon will be closed at the key axis (the zero-value line) for linear value + axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect + side (see \ref getFillBasePoint). + + For increased performance (due to implicit sharing), keep the returned QPolygonF const. + + \see drawFill, getNonNanSegments +*/ +const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const +{ + if (segment.size() < 2) + return QPolygonF(); + QPolygonF result(segment.size()+2); + + result[0] = getFillBasePoint(lineData->at(segment.begin())); + std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); + result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); + + return result; +} + +/*! \internal + + Returns the polygon needed for drawing (partial) channel fills between this graph and the graph + specified by \ref setChannelFillGraph. + + The data points of this graph are passed as pixel coordinates via \a thisData, the data of the + other graph as \a otherData. The returned polygon will be calculated for the specified data + segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a + otherData, respectively. + + The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by + \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap + need to be processed here. + + For increased performance due to implicit sharing, keep the returned QPolygonF const. + + \see drawFill, getOverlappingSegments, getNonNanSegments +*/ +const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const +{ + if (!mChannelFillGraph) + return QPolygonF(); + + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } + if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } + + if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) + return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) + + if (thisData->isEmpty()) return QPolygonF(); + QVector thisSegmentData(thisSegment.size()); + QVector otherSegmentData(otherSegment.size()); + std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); + std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); + // pointers to be able to swap them, depending which data range needs cropping: + QVector *staticData = &thisSegmentData; + QVector *croppedData = &otherSegmentData; + + // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): + if (keyAxis->orientation() == Qt::Horizontal) + { + // x is key + // crop lower bound: + if (staticData->first().x() < croppedData->first().x()) // other one must be cropped + qSwap(staticData, croppedData); + const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) + slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); + else + slope = 0; + (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); + (*croppedData)[0].setX(staticData->first().x()); + + // crop upper bound: + if (staticData->last().x() > croppedData->last().x()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveX(croppedData, staticData->last().x()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + const int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) + slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); + else + slope = 0; + (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); + (*croppedData)[li].setX(staticData->last().x()); + } else // mKeyAxis->orientation() == Qt::Vertical + { + // y is key + // crop lower bound: + if (staticData->first().y() < croppedData->first().y()) // other one must be cropped + qSwap(staticData, croppedData); + int lowBound = findIndexBelowY(croppedData, staticData->first().y()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots + slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); + else + slope = 0; + (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); + (*croppedData)[0].setY(staticData->first().y()); + + // crop upper bound: + if (staticData->last().y() > croppedData->last().y()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveY(croppedData, staticData->last().y()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots + slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); + else + slope = 0; + (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); + (*croppedData)[li].setY(staticData->last().y()); + } + + // return joined: + for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted + thisSegmentData << otherSegmentData.at(i); + return QPolygonF(thisSegmentData); +} + +/*! \internal + + Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveX(const QVector *data, double x) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).x() < x) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexBelowX(const QVector *data, double x) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).x() > x) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} + +/*! \internal + + Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is vertical. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveY(const QVector *data, double y) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).y() < y) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Calculates the minimum distance in pixels the graph's representation has from the given \a + pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if + the graph has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the graph line is also taken into account. + + If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. +*/ +double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + // calculate minimum distances to graph data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); + QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); + for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + // line displayed, calculate distance to line segments: + QVector lineData; + getLines(&lineData, QCPDataRange(0, dataCount())); + QCPVector2D p(pixelPoint); + const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected + for (int i=0; i *data, double y) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).y() > y) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} +/* end of 'src/plottables/plottable-graph.cpp' */ + + +/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurveData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurveData + \brief Holds the data of one single data point for QCPCurve. + + The stored data is: + \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) + \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) + \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPCurveDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPCurveData::sortKey() const + + Returns the \a t member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). + All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() + + Since the member \a key is the data point key coordinate and the member \a t is the data ordering + parameter, this method returns false. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPCurveData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a curve data point with t, key and value set to zero. +*/ +QCPCurveData::QCPCurveData() : + t(0), + key(0), + value(0) +{ +} + +/*! + Constructs a curve data point with the specified \a t, \a key and \a value. +*/ +QCPCurveData::QCPCurveData(double t, double key, double value) : + t(t), + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurve + \brief A plottable representing a parametric curve in a plot. + + \image html QCPCurve.png + + Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, + so their visual representation can have \a loops. This is realized by introducing a third + coordinate \a t, which defines the order of the points described by the other two coordinates \a + x and \a y. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the curve's data via the \ref data method, which returns a pointer to the + internal \ref QCPCurveDataContainer. + + Gaps in the curve can be created by adding data points with NaN as key and value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpcurve-appearance Changing the appearance + + The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). + + \section qcpcurve-usage Usage + + Like all data representing objects in QCustomPlot, the QCPCurve is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPCurve::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // modify inherited properties from abstract plottable: + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setScatterStyle(QCPScatterStyle()); + setLineStyle(lsLine); + setScatterSkip(0); +} + +QCPCurve::~QCPCurve() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. + Modifying the data in the container will then affect all curves that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the curve's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 + + \see addData +*/ +void QCPCurve::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a t, \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a t in ascending order, you can + set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(t, keys, values, alreadySorted); +} + + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + \see addData +*/ +void QCPCurve::setData(const QVector &keys, const QVector &values) +{ + mDataContainer->clear(); + addData(keys, values); +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref + QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate + line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPCurve::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPCurve::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets how the single data points are connected in the plot or how they are represented visually + apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref + setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPCurve::setLineStyle(QCPCurve::LineStyle style) +{ + mLineStyle = style; +} + +/*! \overload + + Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (t.size() != keys.size() || t.size() != values.size()) + qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); + const int n = qMin(qMin(t.size(), keys.size()), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = t[i]; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &keys, const QVector &values) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + double tStart; + if (!mDataContainer->isEmpty()) + tStart = (mDataContainer->constEnd()-1)->t + 1.0; + else + tStart = 0; + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = tStart + i; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a t, \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double t, double key, double value) +{ + mDataContainer->add(QCPCurveData(t, key, value)); +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + The t parameter is generated automatically by increments of 1 for each point, starting at the + highest t of previously existing data or 0, if the curve data is empty. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double key, double value) +{ + if (!mDataContainer->isEmpty()) + mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); + else + mDataContainer->add(QCPCurveData(0.0, key, value)); +} + +/* inherits documentation from base class */ +double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPCurve::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + + // allocate line vector: + QVector lines, scatters; + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + + // fill with curve data: + QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width + if (isSelectedSegment && mSelectionDecorator) + finalCurvePen = mSelectionDecorator->pen(); + + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) + getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); + + // check data validity if flag set: + #ifdef QCUSTOMPLOT_CHECK_DATA + for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->t) || + QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } + #endif + + // draw curve fill: + applyFillAntialiasingHint(painter); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) + painter->drawPolygon(QPolygonF(lines)); + + // draw curve line: + if (mLineStyle != lsNone) + { + painter->setPen(finalCurvePen); + painter->setBrush(Qt::NoBrush); + drawCurveLine(painter, lines); + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + Draws lines between the points in \a lines, given in pixel coordinates. + + \see drawScatterPlot, getCurveLines +*/ +void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawCurveLine, getCurveLines +*/ +void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const +{ + // draw scatter point symbols: + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const +{ + if (!lines) return; + lines->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + // add margins to rect to compensate for stroke width + const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety + const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); + const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); + const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); + const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); + QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); + if (itBegin == itEnd) + return; + QCPCurveDataContainer::const_iterator it = itBegin; + QCPCurveDataContainer::const_iterator prevIt = itEnd-1; + int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); + QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) + while (it != itEnd) + { + const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); + if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R + { + if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal + { + QPointF crossA, crossB; + if (prevRegion == 5) // we're coming from R, so add this point optimized + { + lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); + // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } else if (mayTraverse(prevRegion, currentRegion) && + getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) + { + // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: + QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; + getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); + if (it != itBegin) + { + *lines << beforeTraverseCornerPoints; + lines->append(crossA); + lines->append(crossB); + *lines << afterTraverseCornerPoints; + } else + { + lines->append(crossB); + *lines << afterTraverseCornerPoints; + trailingPoints << beforeTraverseCornerPoints << crossA ; + } + } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) + { + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } + } else // segment does end in R, so we add previous point optimized and this point at original position + { + if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end + trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + else + lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); + lines->append(coordsToPixels(it->key, it->value)); + } + } else // region didn't change + { + if (currentRegion == 5) // still in R, keep adding original points + { + lines->append(coordsToPixels(it->key, it->value)); + } else // still outside R, no need to add anything + { + // see how this is not doing anything? That's the main optimization... + } + } + prevIt = it; + prevRegion = currentRegion; + ++it; + } + *lines << trailingPoints; +} + +/*! \internal + + Called by \ref draw to generate points in pixel coordinates which represent the scatters of the + curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly + sparser. + + Scatters that aren't visible in the current axis rect are optimized away. + + \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref + drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. + + \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel + coordinates generated by this function. This is needed here to calculate an accordingly wider + margin around the axis rect when performing the data point reduction. + + \see draw, drawScatterPlot +*/ +void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const +{ + if (!scatters) return; + scatters->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); + if (begin == end) + return; + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int endIndex = end-mDataContainer->constBegin(); + + QCPRange keyRange = keyAxis->range(); + QCPRange valueRange = valueAxis->range(); + // extend range to include width of scatter symbols: + keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); + keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); + valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); + valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); + + QCPCurveDataContainer::const_iterator it = begin; + int itIndex = begin-mDataContainer->constBegin(); + while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++itIndex; + ++it; + } + if (keyAxis->orientation() == Qt::Vertical) + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } else + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + It returns the region of the given point (\a key, \a value) with respect to a rectangle defined + by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. + + The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a + keyMin to \a keyMax): + + + + + +
147
258
369
+ + With the rectangle being region 5, and the outer regions extending infinitely outwards. In the + curve optimization algorithm, region 5 is considered to be the visible portion of the plot. +*/ +int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + if (key < keyMin) // region 123 + { + if (value > valueMax) + return 1; + else if (value < valueMin) + return 3; + else + return 2; + } else if (key > keyMax) // region 789 + { + if (value > valueMax) + return 7; + else if (value < valueMin) + return 9; + else + return 8; + } else // region 456 + { + if (value > valueMax) + return 4; + else if (value < valueMin) + return 6; + else + return 5; + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method is used in case the current segment passes from inside the visible rect (region 5, + see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by + the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). + + It returns the intersection point of the segment with the border of region 5. + + For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or + whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or + leaving it. It is important though that \a otherRegion correctly identifies the other region not + equal to 5. +*/ +QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double otherValuePx = mValueAxis->coordToPixel(otherValue); + const double valuePx = mValueAxis->coordToPixel(value); + const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); + const double keyPx = mKeyAxis->coordToPixel(key); + double intersectKeyPx = keyMinPx; // initial key just a fail-safe + double intersectValuePx = valueMinPx; // initial value just a fail-safe + switch (otherRegion) + { + case 1: // top and left edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 2: // left edge + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 3: // bottom and left edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 4: // top edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 5: + { + break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table + } + case 6: // bottom edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 7: // top and right edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 8: // right edge + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 9: // bottom and right edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + } + if (mKeyAxis->orientation() == Qt::Horizontal) + return QPointF(intersectKeyPx, intersectValuePx); + else + return QPointF(intersectValuePx, intersectKeyPx); +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + In situations where a single segment skips over multiple regions it might become necessary to add + extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment + doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. + This method provides these points that must be added, assuming the original segment doesn't + start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by + \ref getTraverseCornerPoints.) + + For example, consider a segment which directly goes from region 4 to 2 but originally is far out + to the top left such that it doesn't cross region 5. Naively optimizing these points by + projecting them on the top and left borders of region 5 will create a segment that surely crosses + 5, creating a visual artifact in the plot. This method prevents this by providing extra points at + the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without + traversing 5. +*/ +QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + QVector result; + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMax); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } + case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + else + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + break; + } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMin); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); break; } + case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + else + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + break; + } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 6: + { + switch (currentRegion) + { + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 4: { result << coordsToPixels(keyMax, valueMax); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); break; } + case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + else + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + break; + } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 6: { result << coordsToPixels(keyMax, valueMin); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + else + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + break; + } + } + break; + } + } + return result; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref + getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion + nor \a currentRegion is 5 itself. + + If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the + segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref + getTraverse). +*/ +bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 4: + case 7: + case 2: + case 3: return false; + default: return true; + } + } + case 2: + { + switch (currentRegion) + { + case 1: + case 3: return false; + default: return true; + } + } + case 3: + { + switch (currentRegion) + { + case 1: + case 2: + case 6: + case 9: return false; + default: return true; + } + } + case 4: + { + switch (currentRegion) + { + case 1: + case 7: return false; + default: return true; + } + } + case 5: return false; // should never occur + case 6: + { + switch (currentRegion) + { + case 3: + case 9: return false; + default: return true; + } + } + case 7: + { + switch (currentRegion) + { + case 1: + case 4: + case 8: + case 9: return false; + default: return true; + } + } + case 8: + { + switch (currentRegion) + { + case 7: + case 9: return false; + default: return true; + } + } + case 9: + { + switch (currentRegion) + { + case 3: + case 6: + case 8: + case 7: return false; + default: return true; + } + } + default: return true; + } +} + + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref mayTraverse test has returned true, so there is a chance the + segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible + region 5. + + The return value of this method indicates whether the segment actually traverses region 5 or not. + + If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and + exit points of region 5. They will become the optimized points for that segment. +*/ +bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + QList intersections; + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double keyPx = mKeyAxis->coordToPixel(key); + const double valuePx = mValueAxis->coordToPixel(value); + const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); + const double prevValuePx = mValueAxis->coordToPixel(prevValue); + if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); + } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); + } else // line is skewed + { + double gamma; + double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); + // check top of rect: + gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); + // check bottom of rect: + gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); + const double valuePerKeyPx = 1.0/keyPerValuePx; + // check left of rect: + gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); + // check right of rect: + gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); + } + + // handle cases where found points isn't exactly 2: + if (intersections.size() > 2) + { + // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: + double distSqrMax = 0; + QPointF pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = intersections.at(i); + pv2 = intersections.at(k); + distSqrMax = distSqr; + } + } + } + intersections = QList() << pv1 << pv2; + } else if (intersections.size() != 2) + { + // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment + return false; + } + + // possibly re-sort points so optimized point segment has same direction as original segment: + double xDelta = keyPx-prevKeyPx; + double yDelta = valuePx-prevValuePx; + if (mKeyAxis->orientation() != Qt::Horizontal) + qSwap(xDelta, yDelta); + if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction + intersections.move(0, 1); + crossA = intersections.at(0); + crossB = intersections.at(1); + return true; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref getTraverse test has returned true, so the segment definitely + traverses the visible region 5 when going from \a prevRegion to \a currentRegion. + + In certain situations it is not sufficient to merely generate the entry and exit points of the + segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in + addition to traversing region 5, skips another region outside of region 5, which makes it + necessary to add an optimized corner point there (very similar to the job \ref + getOptimizedCornerPoints does for segments that are completely in outside regions and don't + traverse 5). + + As an example, consider a segment going from region 1 to region 6, traversing the lower left + corner of region 5. In this configuration, the segment additionally crosses the border between + region 1 and 2 before entering region 5. This makes it necessary to add an additional point in + the top left corner, before adding the optimized traverse points. So in this case, the output + parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be + empty. + + In some cases, such as when going from region 1 to 9, it may even be necessary to add additional + corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse + return the respective corner points. +*/ +void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: { break; } // shouldn't happen because this method only handles full traverses + case 6: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + } +} + +/*! \internal + + Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a + pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in + \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that + if the curve has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the curve line is also taken into account. + + If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns + -1.0. +*/ +double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + if (mDataContainer->size() == 1) + { + QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); + closestData = mDataContainer->constBegin(); + return QCPVector2D(dataPoint-pixelPoint).length(); + } + + // calculate minimum distances to curve data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + QVector lines; + getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width + for (int i=0; i QCPBarsGroup::bars() const + + Returns all bars currently in this group. + + \see bars(int index) +*/ + +/*! \fn int QCPBarsGroup::size() const + + Returns the number of QCPBars plottables that are part of this group. + +*/ + +/*! \fn bool QCPBarsGroup::isEmpty() const + + Returns whether this bars group is empty. + + \see size +*/ + +/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) + + Returns whether the specified \a bars plottable is part of this group. + +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new bars group for the specified QCustomPlot instance. +*/ +QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot), + mSpacingType(stAbsolute), + mSpacing(4) +{ +} + +QCPBarsGroup::~QCPBarsGroup() +{ + clear(); +} + +/*! + Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. + + The actual spacing can then be specified with \ref setSpacing. + + \see setSpacing +*/ +void QCPBarsGroup::setSpacingType(SpacingType spacingType) +{ + mSpacingType = spacingType; +} + +/*! + Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is + defined by the current \ref SpacingType, which can be set with \ref setSpacingType. + + \see setSpacingType +*/ +void QCPBarsGroup::setSpacing(double spacing) +{ + mSpacing = spacing; +} + +/*! + Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars + exists, returns 0. + + \see bars(), size +*/ +QCPBars *QCPBarsGroup::bars(int index) const +{ + if (index >= 0 && index < mBars.size()) + { + return mBars.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Removes all QCPBars plottables from this group. + + \see isEmpty +*/ +void QCPBarsGroup::clear() +{ + foreach (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay + bars->setBarsGroup(0); // removes itself via removeBars +} + +/*! + Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref + QCPBars::setBarsGroup on the \a bars instance. + + \see insert, remove +*/ +void QCPBarsGroup::append(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + else + qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); +} + +/*! + Inserts the specified \a bars plottable into this group at the specified index position \a i. + This gives you full control over the ordering of the bars. + + \a bars may already be part of this group. In that case, \a bars is just moved to the new index + position. + + \see append, remove +*/ +void QCPBarsGroup::insert(int i, QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + // first append to bars list normally: + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + // then move to according position: + mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); +} + +/*! + Removes the specified \a bars plottable from this group. + + \see contains, clear +*/ +void QCPBarsGroup::remove(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (mBars.contains(bars)) + bars->setBarsGroup(0); + else + qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); +} + +/*! \internal + + Adds the specified \a bars to the internal mBars list of bars. This method does not change the + barsGroup property on \a bars. + + \see unregisterBars +*/ +void QCPBarsGroup::registerBars(QCPBars *bars) +{ + if (!mBars.contains(bars)) + mBars.append(bars); +} + +/*! \internal + + Removes the specified \a bars from the internal mBars list of bars. This method does not change + the barsGroup property on \a bars. + + \see registerBars +*/ +void QCPBarsGroup::unregisterBars(QCPBars *bars) +{ + mBars.removeOne(bars); +} + +/*! \internal + + Returns the pixel offset in the key dimension the specified \a bars plottable should have at the + given key coordinate \a keyCoord. The offset is relative to the pixel position of the key + coordinate \a keyCoord. +*/ +double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) +{ + // find list of all base bars in case some mBars are stacked: + QList baseBars; + foreach (const QCPBars *b, mBars) + { + while (b->barBelow()) + b = b->barBelow(); + if (!baseBars.contains(b)) + baseBars.append(b); + } + // find base bar this "bars" is stacked on: + const QCPBars *thisBase = bars; + while (thisBase->barBelow()) + thisBase = thisBase->barBelow(); + + // determine key pixel offset of this base bars considering all other base bars in this barsgroup: + double result = 0; + int index = baseBars.indexOf(thisBase); + if (index >= 0) + { + if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) + { + return result; + } else + { + double lowerPixelWidth, upperPixelWidth; + int startIndex; + int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative + if (baseBars.size() % 2 == 0) // even number of bars + { + startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); + result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing + } else // uneven number of bars + { + startIndex = (baseBars.size()-1)/2+dir; + baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar + result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing + } + for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars + { + baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth); + result += getPixelSpacing(baseBars.at(i), keyCoord); + } + // finally half of our bars width: + baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; + // correct sign of result depending on orientation and direction of key axis: + result *= dir*thisBase->keyAxis()->pixelOrientation(); + } + } + return result; +} + +/*! \internal + + Returns the spacing in pixels which is between this \a bars and the following one, both at the + key coordinate \a keyCoord. + + \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only + needed to get access to the key axis transformation and axis rect for the modes \ref + stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in + \ref stPlotCoords on a logarithmic axis. +*/ +double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) +{ + switch (mSpacingType) + { + case stAbsolute: + { + return mSpacing; + } + case stAxisRectRatio: + { + if (bars->keyAxis()->orientation() == Qt::Horizontal) + return bars->keyAxis()->axisRect()->width()*mSpacing; + else + return bars->keyAxis()->axisRect()->height()*mSpacing; + } + case stPlotCoords: + { + double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); + return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); + } + } + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBarsData + \brief Holds the data of one single data point (one bar) for QCPBars. + + The stored data is: + \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) + \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPBarsDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPBarsData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPBarsData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a bar data point with key and value set to zero. +*/ +QCPBarsData::QCPBarsData() : + key(0), + value(0) +{ +} + +/*! + Constructs a bar data point with the specified \a key and \a value. +*/ +QCPBarsData::QCPBarsData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBars + \brief A plottable representing a bar chart in a plot. + + \image html QCPBars.png + + To plot data, assign it with the \ref setData or \ref addData functions. + + \section qcpbars-appearance Changing the appearance + + The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). + The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. + + Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other + (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear + stacked. + + If you would like to group multiple QCPBars plottables together so they appear side by side as + shown below, use QCPBarsGroup. + + \image html QCPBarsGroup.png + + \section qcpbars-usage Usage + + Like all data representing objects in QCustomPlot, the QCPBars is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/*! \fn QCPBars *QCPBars::barBelow() const + Returns the bars plottable that is directly below this bars plottable. + If there is no such plottable, returns 0. + + \see barAbove, moveBelow, moveAbove +*/ + +/*! \fn QCPBars *QCPBars::barAbove() const + Returns the bars plottable that is directly above this bars plottable. + If there is no such plottable, returns 0. + + \see barBelow, moveBelow, moveAbove +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.75), + mWidthType(wtPlotCoords), + mBarsGroup(0), + mBaseValue(0), + mStackingGap(0) +{ + // modify inherited properties from abstract plottable: + mPen.setColor(Qt::blue); + mPen.setStyle(Qt::SolidLine); + mBrush.setColor(QColor(40, 50, 255, 30)); + mBrush.setStyle(Qt::SolidPattern); + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPBars::~QCPBars() +{ + setBarsGroup(0); + if (mBarBelow || mBarAbove) + connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. + Modifying the data in the container will then affect all bars that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the bar's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 + + \see addData +*/ +void QCPBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets the width of the bars. + + How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), + depends on the currently set width type, see \ref setWidthType and \ref WidthType. +*/ +void QCPBars::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the bars is defined. See the documentation of \ref WidthType for an + explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPBars::setWidthType(QCPBars::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref + QCPBarsGroup::append. + + To remove this QCPBars from any group, set \a barsGroup to 0. +*/ +void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) +{ + // deregister at old group: + if (mBarsGroup) + mBarsGroup->unregisterBars(this); + mBarsGroup = barsGroup; + // register at new group: + if (mBarsGroup) + mBarsGroup->registerBars(this); +} + +/*! + Sets the base value of this bars plottable. + + The base value defines where on the value coordinate the bars start. How far the bars extend from + the base value is given by their individual value data. For example, if the base value is set to + 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at + 3. + + For stacked bars, only the base value of the bottom-most QCPBars has meaning. + + The default base value is 0. +*/ +void QCPBars::setBaseValue(double baseValue) +{ + mBaseValue = baseValue; +} + +/*! + If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method + allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by + the bars below it. +*/ +void QCPBars::setStackingGap(double pixels) +{ + mStackingGap = pixels; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(double key, double value) +{ + mDataContainer->add(QCPBarsData(key, value)); +} + +/*! + Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear + below the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object below itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barAbove, barBelow +*/ +void QCPBars::moveBelow(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar below it: + if (bars) + { + if (bars->mBarBelow) + connectBars(bars->mBarBelow.data(), this); + connectBars(this, bars); + } +} + +/*! + Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear + above the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object above itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barBelow, barAbove +*/ +void QCPBars::moveAbove(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar above it: + if (bars) + { + if (bars->mBarAbove) + connectBars(this, bars->mBarAbove.data()); + connectBars(bars, this); + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getBarRect(it->key, it->value))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getBarRect(it->key, it->value).contains(pos)) + { + if (details) + { + int pointIndex = it-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return mParentPlot->selectionTolerance()*0.99; + } + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in + absolute pixels), using this method to adapt the key axis range to fit the bars into the + currently visible axis range will not work perfectly. Because in the moment the axis range is + changed to the new range, the fixed pixel widths/spacings will represent different coordinate + spans than before, which in turn would require a different key range to perfectly fit, and so on. + The only solution would be to iteratively approach the perfect fitting axis range, but the + mismatch isn't large enough in most applications, to warrant this here. If a user does need a + better fit, he should call the corresponding axis rescale multiple times in a row. + */ + QCPRange range; + range = mDataContainer->keyRange(foundRange, inSignDomain); + + // determine exact range of bars by including bar width and barsgroup offset: + if (foundRange && mKeyAxis) + { + double lowerPixelWidth, upperPixelWidth, keyPixel; + // lower range bound: + getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); + const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) + range.lower = lowerCorrected; + // upper range bound: + getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); + const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) + range.upper = upperCorrected; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + // Note: can't simply use mDataContainer->valueRange here because we need to + // take into account bar base value and possible stacking of multiple bars + QCPRange range; + range.lower = mBaseValue; + range.upper = mBaseValue; + bool haveLower = true; // set to true, because baseValue should always be visible in bar charts + bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts + QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (inKeyRange != QCPRange()) + { + itBegin = mDataContainer->findBegin(inKeyRange.lower); + itEnd = mDataContainer->findEnd(inKeyRange.upper); + } + for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + + foundRange = true; // return true because bar charts always have the 0-line visible + return range; +} + +/* inherits documentation from base class */ +QPointF QCPBars::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); + const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyPixel, valuePixel); + else + return QPointF(valuePixel, keyPixel); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/* inherits documentation from base class */ +void QCPBars::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mDataContainer->isEmpty()) return; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPBarsDataContainer::const_iterator begin = visibleBegin; + QCPBarsDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +#endif + // draw bar: + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyBrush(painter); + mSelectionDecorator->applyPen(painter); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + } + applyDefaultAntialiasingHint(painter); + painter->drawPolygon(getBarRect(it->key, it->value)); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setBrush(mBrush); + painter->setPen(mPen); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + if (mDataContainer->isEmpty()) + { + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + + // get visible data range as QMap iterators + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); + double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); + double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); + bool isVisible = false; + // walk left from begin to find lower bar that actually is completely outside visible pixel range: + QCPBarsDataContainer::const_iterator it = begin; + while (it != mDataContainer->constBegin()) + { + --it; + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); + if (isVisible) + begin = it; + else + break; + } + // walk right from ubound to find upper bar that actually is completely outside visible pixel range: + it = end; + while (it != mDataContainer->constEnd()) + { + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); + if (isVisible) + end = it+1; + else + break; + ++it; + } +} + +/*! \internal + + Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The + rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref + setBaseValue), and to have non-overlapping border lines with the bars stacked below. +*/ +QRectF QCPBars::getBarRect(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double lowerPixelWidth, upperPixelWidth; + getPixelWidth(key, lowerPixelWidth, upperPixelWidth); + double base = getStackedBaseValue(key, value >= 0); + double basePixel = valueAxis->coordToPixel(base); + double valuePixel = valueAxis->coordToPixel(base+value); + double keyPixel = keyAxis->coordToPixel(key); + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, key); + double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); + bottomOffset += mBarBelow ? mStackingGap : 0; + bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); + if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) + bottomOffset = valuePixel-basePixel; + if (keyAxis->orientation() == Qt::Horizontal) + { + return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); + } else + { + return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). + + The output parameters \a lower and \a upper return the number of pixels the bar extends to lower + and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a + lower is negative and \a upper positive). +*/ +void QCPBars::getPixelWidth(double key, double &lower, double &upper) const +{ + lower = 0; + upper = 0; + switch (mWidthType) + { + case wtAbsolute: + { + upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + { + double keyPixel = mKeyAxis.data()->coordToPixel(key); + upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; + // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by + // coordinate transform which includes range direction + } else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } +} + +/*! \internal + + This function is called to find at which value to start drawing the base of a bar at \a key, when + it is stacked on top of another QCPBars (e.g. with \ref moveAbove). + + positive and negative bars are separated per stack (positive are stacked above baseValue upwards, + negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the + bar for which we need the base value is negative, set \a positive to false. +*/ +double QCPBars::getStackedBaseValue(double key, bool positive) const +{ + if (mBarBelow) + { + double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack + // find bars of mBarBelow that are approximately at key and find largest one: + double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point + if (key == 0) + epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); + QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); + QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); + while (it != itEnd) + { + if (it->key > key-epsilon && it->key < key+epsilon) + { + if ((positive && it->value > max) || + (!positive && it->value < max)) + max = it->value; + } + ++it; + } + // recurse down the bar-stack to find the total height: + return max + mBarBelow.data()->getStackedBaseValue(key, positive); + } else + return mBaseValue; +} + +/*! \internal + + Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) + currently above lower and below upper will become disconnected to lower/upper. + + If lower is zero, upper will be disconnected at the bottom. + If upper is zero, lower will be disconnected at the top. +*/ +void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) +{ + if (!lower && !upper) return; + + if (!lower) // disconnect upper at bottom + { + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + upper->mBarBelow = 0; + } else if (!upper) // disconnect lower at top + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + lower->mBarAbove = 0; + } else // connect lower and upper + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + lower->mBarAbove = upper; + upper->mBarBelow = lower; + } +} +/* end of 'src/plottables/plottable-bars.cpp' */ + + +/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBoxData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBoxData + \brief Holds the data of one single data point for QCPStatisticalBox. + + The stored data is: + + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + + \li \a minimum: the position of the lower whisker, typically the minimum measurement of the + sample that's not considered an outlier. + + \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a median: the value of the median mark inside the quartile box. The median separates the + sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) + + \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a maximum: the position of the upper whisker, typically the maximum measurement of the + sample that's not considered an outlier. + + \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key + coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) + + The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a + typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template + parameter. See the documentation there for an explanation regarding the data type's generic + methods. + + \see QCPStatisticalBoxDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPStatisticalBoxData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainValue() const + + Returns the \a median member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const + + Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box + data point, possibly further expanded by outliers. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData() : + key(0), + minimum(0), + lowerQuartile(0), + median(0), + upperQuartile(0), + maximum(0) +{ +} + +/*! + Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a + upperQuartile, \a maximum and optionally a number of \a outliers. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : + key(key), + minimum(minimum), + lowerQuartile(lowerQuartile), + median(median), + upperQuartile(upperQuartile), + maximum(maximum), + outliers(outliers) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBox +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBox + \brief A plottable representing a single statistical box in a plot. + + \image html QCPStatisticalBox.png + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPStatisticalBoxDataContainer. + + Additionally each data point can itself have a list of outliers, drawn as scatter points at the + key coordinate of the respective statistical box data point. They can either be set by using the + respective \ref addData(double,double,double,double,double,double,const QVector&) + "addData" method or accessing the individual data points through \ref data, and setting the + QVector outliers of the data points directly. + + \section qcpstatisticalbox-appearance Changing the appearance + + The appearance of each data point box, ranging from the lower to the upper quartile, is + controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref + setWidth in plot coordinates. + + Each data point's visual representation also consists of two whiskers. Whiskers are the lines + which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. + The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, + \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at + the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set + the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a + few pixels due to the pen cap being not perfectly flat. + + The median indicator line inside the box has its own pen, \ref setMedianPen. + + The outlier data points are drawn as normal scatter points. Their look can be controlled with + \ref setOutlierStyle + + \section qcpstatisticalbox-usage Usage + + Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 +*/ + +/* start documentation of inline functions */ + +/*! \fn QSharedPointer QCPStatisticalBox::data() const + + Returns a shared pointer to the internal data storage of type \ref + QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more + convenient and faster than using the regular \ref setData or \ref addData methods. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its + value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and + not have the same orientation. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not + delete it manually but use QCustomPlot::removePlottable() instead. +*/ +QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.5), + mWhiskerWidth(0.2), + mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), + mWhiskerBarPen(Qt::black), + mWhiskerAntialiased(false), + mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), + mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) +{ + setPen(QPen(Qt::black)); + setBrush(Qt::NoBrush); +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container + safely. Modifying the data in the container will then affect all statistical boxes that share the + container. Sharing can be achieved by simply exchanging the data containers wrapped in shared + pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the statistical box data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 + + \see addData +*/ +void QCPStatisticalBox::setData(QSharedPointer data) +{ + mDataContainer = data; +} +/*! \overload + + Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a + median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the + number of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); +} + +/*! + Sets the width of the boxes in key coordinates. + + \see setWhiskerWidth +*/ +void QCPStatisticalBox::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the width of the whiskers in key coordinates. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWidth +*/ +void QCPStatisticalBox::setWhiskerWidth(double width) +{ + mWhiskerWidth = width; +} + +/*! + Sets the pen used for drawing the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone + line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. + + \see setWhiskerBarPen +*/ +void QCPStatisticalBox::setWhiskerPen(const QPen &pen) +{ + mWhiskerPen = pen; +} + +/*! + Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at + each end of the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWhiskerPen +*/ +void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) +{ + mWhiskerBarPen = pen; +} + +/*! + Sets whether the statistical boxes whiskers are drawn with antialiasing or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) +{ + mWhiskerAntialiased = enabled; +} + +/*! + Sets the pen used for drawing the median indicator line inside the statistical boxes. +*/ +void QCPStatisticalBox::setMedianPen(const QPen &pen) +{ + mMedianPen = pen; +} + +/*! + Sets the appearance of the outlier data points. + + Outliers can be specified with the method + \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +*/ +void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) +{ + mOutlierStyle = style; +} + +/*! \overload + + Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and + \a maximum to the current data. The provided vectors should have equal length. Else, the number + of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || + median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" + << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); + const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->minimum = minimum[i]; + it->lowerQuartile = lowerQuartile[i]; + it->median = median[i]; + it->upperQuartile = upperQuartile[i]; + it->maximum = maximum[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile + and \a maximum to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +{ + mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getQuartileBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + double minDistSqr = std::numeric_limits::max(); + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getQuartileBox(it).contains(pos)) // quartile box + { + double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } else // whiskers + { + const QVector whiskerBackbones(getWhiskerBackboneLines(it)); + for (int i=0; iconstBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return qSqrt(minDistSqr); + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; + QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +# ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->minimum) || + QCP::isInvalidData(it->lowerQuartile, it->median) || + QCP::isInvalidData(it->upperQuartile, it->maximum)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); + for (int i=0; ioutliers.size(); ++i) + if (QCP::isInvalidData(it->outliers.at(i))) + qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +# endif + + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + QCPScatterStyle finalOutlierStyle = mOutlierStyle; + if (isSelectedSegment && mSelectionDecorator) + finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); + drawStatisticalBox(painter, it, finalOutlierStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->setBrush(mBrush); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! + Draws the graphical representation of a single statistical box with the data given by the + iterator \a it with the provided \a painter. + + If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. + + \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const +{ + // draw quartile box: + applyDefaultAntialiasingHint(painter); + const QRectF quartileBox = getQuartileBox(it); + painter->drawRect(quartileBox); + // draw median line with cliprect set to quartile box: + painter->save(); + painter->setClipRect(quartileBox, Qt::IntersectClip); + painter->setPen(mMedianPen); + painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); + painter->restore(); + // draw whisker lines: + applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); + painter->setPen(mWhiskerPen); + painter->drawLines(getWhiskerBackboneLines(it)); + painter->setPen(mWhiskerBarPen); + painter->drawLines(getWhiskerBarLines(it)); + // draw outliers: + applyScattersAntialiasingHint(painter); + outlierStyle.applyTo(painter, mPen); + for (int i=0; ioutliers.size(); ++i) + outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points +} + +/*! \internal + + Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the + value range from the lower to the upper quartile, of the data given by \a it. + + \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QRectF result; + result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); + result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); + return result; +} + +/*! \internal + + Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value + range from the minimum to the lower quartile, and from the upper quartile to the maximum of the + data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines +*/ +QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone + result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone + return result; +} + +/*! \internal + + Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the + end of the whisker backbones, at the minimum and maximum of the data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines +*/ +QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar + result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar + return result; +} +/* end of 'src/plottables/plottable-statisticalbox.cpp' */ + + +/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorMapData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorMapData + \brief Holds the two-dimensional data of a QCPColorMap plottable. + + This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref + QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a + color, depending on the value. + + The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). + Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref + setKeyRange, \ref setValueRange). + + The data cells can be accessed in two ways: They can be directly addressed by an integer index + with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot + coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are + provided by the functions \ref coordToCell and \ref cellToCoord. + + A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if + allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref + fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on + the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. + + This class also buffers the minimum and maximum values that are in the data set, to provide + QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value + that is greater than the current maximum increases this maximum to the new value. However, + setting the cell that currently holds the maximum value to a smaller value doesn't decrease the + maximum again, because finding the true new maximum would require going through the entire data + array, which might be time consuming. The same holds for the data minimum. This functionality is + given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the + true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience + parameter \a recalculateDataBounds which may be set to true to automatically call \ref + recalculateDataBounds internally. +*/ + +/* start of documentation of inline functions */ + +/*! \fn bool QCPColorMapData::isEmpty() const + + Returns whether this instance carries no data. This is equivalent to having a size where at least + one of the dimensions is 0 (see \ref setSize). +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction + and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap + at the coordinates \a keyRange and \a valueRange. + + \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange +*/ +QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : + mKeySize(0), + mValueSize(0), + mKeyRange(keyRange), + mValueRange(valueRange), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + setSize(keySize, valueSize); + fill(0); +} + +QCPColorMapData::~QCPColorMapData() +{ + if (mData) + delete[] mData; + if (mAlpha) + delete[] mAlpha; +} + +/*! + Constructs a new QCPColorMapData instance copying the data and range of \a other. +*/ +QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : + mKeySize(0), + mValueSize(0), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + *this = other; +} + +/*! + Overwrites this color map data instance with the data stored in \a other. The alpha map state is + transferred, too. +*/ +QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) +{ + if (&other != this) + { + const int keySize = other.keySize(); + const int valueSize = other.valueSize(); + if (!other.mAlpha && mAlpha) + clearAlpha(); + setSize(keySize, valueSize); + if (other.mAlpha && !mAlpha) + createAlpha(false); + setRange(other.keyRange(), other.valueRange()); + if (!isEmpty()) + { + memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); + if (mAlpha) + memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); + } + mDataBounds = other.mDataBounds; + mDataModified = true; + } + return *this; +} + +/* undocumented getter */ +double QCPColorMapData::data(double key, double value) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + return mData[valueCell*mKeySize + keyCell]; + else + return 0; +} + +/* undocumented getter */ +double QCPColorMapData::cell(int keyIndex, int valueIndex) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mData[valueIndex*mKeySize + keyIndex]; + else + return 0; +} + +/*! + Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. + + If this color map data doesn't have an alpha map (because \ref setAlpha was never called after + creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. + + \see setAlpha +*/ +unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) +{ + if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mAlpha[valueIndex*mKeySize + keyIndex]; + else + return 255; +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in + the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref + isEmpty returns true. + + \see setRange, setKeySize, setValueSize +*/ +void QCPColorMapData::setSize(int keySize, int valueSize) +{ + if (keySize != mKeySize || valueSize != mValueSize) + { + mKeySize = keySize; + mValueSize = valueSize; + if (mData) + delete[] mData; + mIsEmpty = mKeySize == 0 || mValueSize == 0; + if (!mIsEmpty) + { +#ifdef __EXCEPTIONS + try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message +#endif + mData = new double[mKeySize*mValueSize]; +#ifdef __EXCEPTIONS + } catch (...) { mData = 0; } +#endif + if (mData) + fill(0); + else + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; + } else + mData = 0; + + if (mAlpha) // if we had an alpha map, recreate it with new size + createAlpha(); + + mDataModified = true; + } +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. + + \see setKeyRange, setSize, setValueSize +*/ +void QCPColorMapData::setKeySize(int keySize) +{ + setSize(keySize, mValueSize); +} + +/*! + Resizes the data array to have \a valueSize cells in the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. + + \see setValueRange, setSize, setKeySize +*/ +void QCPColorMapData::setValueSize(int valueSize) +{ + setSize(mKeySize, valueSize); +} + +/*! + Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area + covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setSize +*/ +void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) +{ + setKeyRange(keyRange); + setValueRange(valueRange); +} + +/*! + Sets the coordinate range the data shall be distributed over in the key dimension. Together with + the value range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setRange, setValueRange, setSize +*/ +void QCPColorMapData::setKeyRange(const QCPRange &keyRange) +{ + mKeyRange = keyRange; +} + +/*! + Sets the coordinate range the data shall be distributed over in the value dimension. Together with + the key range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there + will be cells centered on the value coordinates 2, 2.5 and 3. + + \see setRange, setKeyRange, setSize +*/ +void QCPColorMapData::setValueRange(const QCPRange &valueRange) +{ + mValueRange = valueRange; +} + +/*! + Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a + z. + + \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or + value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, + you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to + determine the cell index. Rather directly access the cell index with \ref + QCPColorMapData::setCell. + + \see setCell, setRange +*/ +void QCPColorMapData::setData(double key, double value, double z) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + { + mData[valueCell*mKeySize + keyCell] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } +} + +/*! + Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices + enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see + \ref setSize). + + In the standard plot configuration (horizontal key axis and vertical value axis, both not + range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with + indices (keySize-1, valueSize-1) is in the top right corner of the color map. + + \see setData, setSize +*/ +void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + mData[valueIndex*mKeySize + keyIndex] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value + of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully + opaque cell. + + If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish + to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. + + Note that the cell-wise alpha which can be configured here is independent of any alpha configured + in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise + and gradient alpha, the alpha values will be blended accordingly during rendering of the color + map. + + \see fillAlpha, clearAlpha +*/ +void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + if (mAlpha || createAlpha()) + { + mAlpha[valueIndex*mKeySize + keyIndex] = alpha; + mDataModified = true; + } + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Goes through the data and updates the buffered minimum and maximum data values. + + Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange + and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten + with a smaller or larger value respectively, since the buffered maximum/minimum values have been + updated the last time. Why this is the case is explained in the class description (\ref + QCPColorMapData). + + Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a + recalculateDataBounds for convenience. Setting this to true will call this method for you, before + doing the rescale. +*/ +void QCPColorMapData::recalculateDataBounds() +{ + if (mKeySize > 0 && mValueSize > 0) + { + double minHeight = mData[0]; + double maxHeight = mData[0]; + const int dataCount = mValueSize*mKeySize; + for (int i=0; i maxHeight) + maxHeight = mData[i]; + if (mData[i] < minHeight) + minHeight = mData[i]; + } + mDataBounds.lower = minHeight; + mDataBounds.upper = maxHeight; + } +} + +/*! + Frees the internal data memory. + + This is equivalent to calling \ref setSize "setSize(0, 0)". +*/ +void QCPColorMapData::clear() +{ + setSize(0, 0); +} + +/*! + Frees the internal alpha map. The color map will have full opacity again. +*/ +void QCPColorMapData::clearAlpha() +{ + if (mAlpha) + { + delete[] mAlpha; + mAlpha = 0; + mDataModified = true; + } +} + +/*! + Sets all cells to the value \a z. +*/ +void QCPColorMapData::fill(double z) +{ + const int dataCount = mValueSize*mKeySize; + for (int i=0; i(data); + return; + } + if (copy) + { + *mMapData = *data; + } else + { + delete mMapData; + mMapData = data; + } + mMapImageInvalidated = true; +} + +/*! + Sets the data range of this color map to \a dataRange. The data range defines which data values + are mapped to the color gradient. + + To make the data range span the full range of the data set, use \ref rescaleDataRange. + + \see QCPColorScale::setDataRange +*/ +void QCPColorMap::setDataRange(const QCPRange &dataRange) +{ + if (!QCPRange::validRange(dataRange)) return; + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + if (mDataScaleType == QCPAxis::stLogarithmic) + mDataRange = dataRange.sanitizedForLogScale(); + else + mDataRange = dataRange.sanitizedForLinScale(); + mMapImageInvalidated = true; + emit dataRangeChanged(mDataRange); + } +} + +/*! + Sets whether the data is correlated with the color gradient linearly or logarithmically. + + \see QCPColorScale::setDataScaleType +*/ +void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + mMapImageInvalidated = true; + emit dataScaleTypeChanged(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + } +} + +/*! + Sets the color gradient that is used to represent the data. For more details on how to create an + own gradient or use one of the preset gradients, see \ref QCPColorGradient. + + The colors defined by the gradient will be used to represent data values in the currently set + data range, see \ref setDataRange. Data points that are outside this data range will either be + colored uniformly with the respective gradient boundary color, or the gradient will repeat, + depending on \ref QCPColorGradient::setPeriodic. + + \see QCPColorScale::setGradient +*/ +void QCPColorMap::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + mMapImageInvalidated = true; + emit gradientChanged(mGradient); + } +} + +/*! + Sets whether the color map image shall use bicubic interpolation when displaying the color map + shrinked or expanded, and not at a 1:1 pixel-to-data scale. + + \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" +*/ +void QCPColorMap::setInterpolate(bool enabled) +{ + mInterpolate = enabled; + mMapImageInvalidated = true; // because oversampling factors might need to change +} + +/*! + Sets whether the outer most data rows and columns are clipped to the specified key and value + range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). + + if \a enabled is set to false, the data points at the border of the color map are drawn with the + same width and height as all other data points. Since the data points are represented by + rectangles of one color centered on the data coordinate, this means that the shown color map + extends by half a data point over the specified key/value range in each direction. + + \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" +*/ +void QCPColorMap::setTightBoundary(bool enabled) +{ + mTightBoundary = enabled; +} + +/*! + Associates the color scale \a colorScale with this color map. + + This means that both the color scale and the color map synchronize their gradient, data range and + data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps + can be associated with one single color scale. This causes the color maps to also synchronize + those properties, via the mutual color scale. + + This function causes the color map to adopt the current color gradient, data range and data scale + type of \a colorScale. After this call, you may change these properties at either the color map + or the color scale, and the setting will be applied to both. + + Pass 0 as \a colorScale to disconnect the color scale from this color map again. +*/ +void QCPColorMap::setColorScale(QCPColorScale *colorScale) +{ + if (mColorScale) // unconnect signals from old color scale + { + disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + mColorScale = colorScale; + if (mColorScale) // connect signals to new color scale + { + setGradient(mColorScale.data()->gradient()); + setDataRange(mColorScale.data()->dataRange()); + setDataScaleType(mColorScale.data()->dataScaleType()); + connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } +} + +/*! + Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the + current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, + only for the third data dimension of the color map. + + The minimum and maximum values of the data set are buffered in the internal QCPColorMapData + instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref + QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For + performance reasons, however, they are only updated in an expanding fashion. So the buffered + maximum can only increase and the buffered minimum can only decrease. In consequence, changes to + the data that actually lower the maximum of the data set (by overwriting the cell holding the + current maximum with a smaller value), aren't recognized and the buffered maximum overestimates + the true maximum of the data set. The same happens for the buffered minimum. To recalculate the + true minimum and maximum by explicitly looking at each cell, the method + QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a + recalculateDataBounds calls this method before setting the data range to the buffered minimum and + maximum. + + \see setDataRange +*/ +void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) +{ + if (recalculateDataBounds) + mMapData->recalculateDataBounds(); + setDataRange(mMapData->dataBounds()); +} + +/*! + Takes the current appearance of the color map and updates the legend icon, which is used to + represent this color map in the legend (see \ref QCPLegend). + + The \a transformMode specifies whether the rescaling is done by a faster, low quality image + scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm + (Qt::SmoothTransformation). + + The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to + the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured + legend icon size, the thumb will be rescaled during drawing of the legend item. + + \see setDataRange +*/ +void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) +{ + if (mMapImage.isNull() && !data()->isEmpty()) + updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) + + if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again + { + bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); + } +} + +/* inherits documentation from base class */ +double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) + { + if (details) + details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. + return mParentPlot->selectionTolerance()*0.99; + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + foundRange = true; + QCPRange result = mMapData->keyRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (inKeyRange != QCPRange()) + { + if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) + { + foundRange = false; + return QCPRange(); + } + } + + foundRange = true; + QCPRange result = mMapData->valueRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/*! \internal + + Updates the internal map image buffer by going through the internal \ref QCPColorMapData and + turning the data values into color pixels with \ref QCPColorGradient::colorize. + + This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image + has been invalidated for a different reason (e.g. a change of the data range with \ref + setDataRange). + + If the map cell count is low, the image created will be oversampled in order to avoid a + QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images + without smooth transform enabled. Accordingly, oversampling isn't performed if \ref + setInterpolate is true. +*/ +void QCPColorMap::updateMapImage() +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) return; + if (mMapData->isEmpty()) return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + const int keySize = mMapData->keySize(); + const int valueSize = mMapData->valueSize(); + int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + + // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: + if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) + mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); + else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) + mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); + + if (mMapImage.isNull()) + { + qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; + mMapImage = QImage(QSize(10, 10), format); + mMapImage.fill(Qt::black); + } else + { + QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + // resize undersampled map image to actual key/value cell sizes: + if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) + mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); + else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) + mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); + localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image + } else if (!mUndersampledMapImage.isNull()) + mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it + + const double *rawData = mMapData->mData; + const unsigned char *rawAlpha = mMapData->mAlpha; + if (keyAxis->orientation() == Qt::Horizontal) + { + const int lineCount = valueSize; + const int rowCount = keySize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + } + } else // keyAxis->orientation() == Qt::Vertical + { + const int lineCount = keySize; + const int rowCount = valueSize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + } + } + + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + if (keyAxis->orientation() == Qt::Horizontal) + mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + else + mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + } + } + mMapData->mDataModified = false; + mMapImageInvalidated = false; +} + +/* inherits documentation from base class */ +void QCPColorMap::draw(QCPPainter *painter) +{ + if (mMapData->isEmpty()) return; + if (!mKeyAxis || !mValueAxis) return; + applyDefaultAntialiasingHint(painter); + + if (mMapData->mDataModified || mMapImageInvalidated) + updateMapImage(); + + // use buffer if painting vectorized (PDF): + const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); + QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized + QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in + QPixmap mapBuffer; + if (useBuffer) + { + const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps + mapBufferTarget = painter->clipRegion().boundingRect(); + mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); + mapBuffer.fill(Qt::transparent); + localPainter = new QCPPainter(&mapBuffer); + localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); + localPainter->translate(-mapBufferTarget.topLeft()); + } + + QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): + double halfCellWidth = 0; // in pixels + double halfCellHeight = 0; // in pixels + if (keyAxis()->orientation() == Qt::Horizontal) + { + if (mMapData->keySize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); + } else // keyAxis orientation is Qt::Vertical + { + if (mMapData->keySize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); + } + imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); + const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); + QRegion clipBackup; + if (mTightBoundary) + { + clipBackup = localPainter->clipRegion(); + QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + localPainter->setClipRect(tightClipRect, Qt::IntersectClip); + } + localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); + if (mTightBoundary) + localPainter->setClipRegion(clipBackup); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); + + if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter + { + delete localPainter; + painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); + } +} + +/* inherits documentation from base class */ +void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + // draw map thumbnail: + if (!mLegendIcon.isNull()) + { + QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); + QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); + iconRect.moveCenter(rect.center()); + painter->drawPixmap(iconRect.topLeft(), scaledIcon); + } + /* + // draw frame: + painter->setBrush(Qt::NoBrush); + painter->setPen(Qt::black); + painter->drawRect(rect.adjusted(1, 1, 0, 0)); + */ +} +/* end of 'src/plottables/plottable-colormap.cpp' */ + + +/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancialData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancialData + \brief Holds the data of one single data point for QCPFinancial. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a open: The opening value at the data point (this is the \a mainValue) + \li \a high: The high/maximum value at the data point + \li \a low: The low/minimum value at the data point + \li \a close: The closing value at the data point + + The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef + for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPFinancialDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPFinancialData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainValue() const + + Returns the \a open member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPFinancialData::valueRange() const + + Returns a QCPRange spanning from the \a low to the \a high value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPFinancialData::QCPFinancialData() : + key(0), + open(0), + high(0), + low(0), + close(0) +{ +} + +/*! + Constructs a data point with the specified \a key and OHLC values. +*/ +QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : + key(key), + open(open), + high(high), + low(low), + close(close) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancial +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancial + \brief A plottable representing a financial stock chart + + \image html QCPFinancial.png + + This plottable represents time series data binned to certain intervals, mainly used for stock + charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be + set via \ref setChartStyle. + + The data is passed via \ref setData as a set of open/high/low/close values at certain keys + (typically times). This means the data must be already binned appropriately. If data is only + available as a series of values (e.g. \a price against \a time), you can use the static + convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed + to \ref setData. + + The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref + setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and + the width to (or slightly less than) one time bin interval width. + + \section qcpfinancial-appearance Changing the appearance + + Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, + lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). + + If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are + represented with a different pen and brush than negative changes (\a close < \a open). These can + be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref + setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection + however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, + irrespective of whether the chart is single- or two-colored. + + \section qcpfinancial-usage Usage + + Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot + instance takes ownership of the plottable, so do not delete it manually but use + QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 + Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data + series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const + + Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods, in certain situations. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mChartStyle(csCandlestick), + mWidth(0.5), + mWidthType(wtPlotCoords), + mTwoColored(true), + mBrushPositive(QBrush(QColor(50, 160, 0))), + mBrushNegative(QBrush(QColor(180, 0, 15))), + mPenPositive(QPen(QColor(40, 150, 0))), + mPenNegative(QPen(QColor(170, 5, 5))) +{ + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPFinancial::~QCPFinancial() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. + Modifying the data in the container will then affect all financials that share the container. + Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the financial's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a + close. The provided vectors should have equal length. Else, the number of added points will be + the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, open, high, low, close, alreadySorted); +} + +/*! + Sets which representation style shall be used to display the OHLC data. +*/ +void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) +{ + mChartStyle = style; +} + +/*! + Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. + + A typical choice is to set it to (or slightly less than) one bin interval width. +*/ +void QCPFinancial::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for + an explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets whether this chart shall contrast positive from negative trends per data point by using two + separate colors to draw the respective bars/candlesticks. + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setTwoColored(bool twoColored) +{ + mTwoColored = twoColored; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushNegative, setPenPositive, setPenNegative +*/ +void QCPFinancial::setBrushPositive(const QBrush &brush) +{ + mBrushPositive = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushPositive, setPenNegative, setPenPositive +*/ +void QCPFinancial::setBrushNegative(const QBrush &brush) +{ + mBrushNegative = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setPenPositive(const QPen &pen) +{ + mPenPositive = pen; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setBrushNegative, setBrushPositive +*/ +void QCPFinancial::setPenNegative(const QPen &pen) +{ + mPenNegative = pen; +} + +/*! \overload + + Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. + The provided vectors should have equal length. Else, the number of added points will be the size + of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); + const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->open = open[i]; + it->high = high[i]; + it->low = low[i]; + it->close = close[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current + data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(double key, double open, double high, double low, double close) +{ + mDataContainer->add(QCPFinancialData(key, open, high, low, close)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(selectionHitBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + // perform select test according to configured style: + double result = -1; + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + case QCPFinancial::csCandlestick: + result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + } + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } + + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/*! + A convenience function that converts time series data (\a value against \a time) to OHLC binned + data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const + QCPFinancialDataContainer&). + + The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. + For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour + each, set \a timeBinSize to 3600. + + \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The + value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. + It merely defines the mathematical offset/phase of the bins that will be used to process the + data. +*/ +QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) +{ + QCPFinancialDataContainer data; + int count = qMin(time.size(), value.size()); + if (count == 0) + return QCPFinancialDataContainer(); + + QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); + int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); + for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); + if (i == count-1) // last data point is in current bin, finalize bin: + { + currentBinData.close = value.at(i); + currentBinData.key = timeBinOffset+(index)*timeBinSize; + data.add(currentBinData); + } + } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: + { + // finalize current bin: + currentBinData.close = value.at(i-1); + currentBinData.key = timeBinOffset+(index-1)*timeBinSize; + data.add(currentBinData); + // start next bin: + currentBinIndex = index; + currentBinData.open = value.at(i); + currentBinData.high = value.at(i); + currentBinData.low = value.at(i); + } + } + + return data; +} + +/* inherits documentation from base class */ +void QCPFinancial::draw(QCPPainter *painter) +{ + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPFinancialDataContainer::const_iterator begin = visibleBegin; + QCPFinancialDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + // draw data segment according to configured style: + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + drawOhlcPlot(painter, begin, end, isSelectedSegment); break; + case QCPFinancial::csCandlestick: + drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing + if (mChartStyle == csOhlc) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } + } else if (mChartStyle == csCandlestick) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. +*/ +void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); + // draw close: + painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); + } + } else + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); + // draw close: + painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. +*/ +void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + // draw low: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + // draw low: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); + } + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of + \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel + when this function is called). + + It returns the number of pixels the bar extends to higher keys, relative to the \a key + coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed + horizontal axis, the return value is negative. This is important so the open/close flags on the + \ref csOhlc bar are drawn to the correct side. +*/ +double QCPFinancial::getPixelWidth(double key, double keyPixel) const +{ + double result = 0; + switch (mWidthType) + { + case wtAbsolute: + { + if (mKeyAxis) + result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } + return result; +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a + end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + called by the drawing methods to determine which data (key) range is visible at the current key + axis range setting, so only that needs to be processed. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + begin may still be just outside the visible range. + + \a end returns the iterator just above the highest data point that needs to be taken into + account. Same as before, \a end may also lie just outside of the visible range + + if the plottable contains no data, both \a begin and \a end point to \c constEnd. +*/ +void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points +} + +/*! \internal + + Returns the hit box in pixel coordinates that will be used for data selection with the selection + rect (\ref selectTestRect), of the data point given by \a it. +*/ +QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double keyPixel = keyAxis->coordToPixel(it->key); + double highPixel = valueAxis->coordToPixel(it->high); + double lowPixel = valueAxis->coordToPixel(it->low); + double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); + if (keyAxis->orientation() == Qt::Horizontal) + return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); + else + return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); +} +/* end of 'src/plottables/plottable-financial.cpp' */ + + +/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBarsData + \brief Holds the data of one single error bar for QCPErrorBars. + + The stored data is: + \li \a errorMinus: how much the error bar extends towards negative coordinates from the data + point position + \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point + position + + The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a + typedef for QVector<\ref QCPErrorBarsData>. + + \see QCPErrorBarsDataContainer +*/ + +/*! + Constructs an error bar with errors set to zero. +*/ +QCPErrorBarsData::QCPErrorBarsData() : + errorMinus(0), + errorPlus(0) +{ +} + +/*! + Constructs an error bar with equal \a error in both negative and positive direction. +*/ +QCPErrorBarsData::QCPErrorBarsData(double error) : + errorMinus(error), + errorPlus(error) +{ +} + +/*! + Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, + respectively. +*/ +QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : + errorMinus(errorMinus), + errorPlus(errorPlus) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBars + \brief A plottable that adds a set of error bars to other plottables. + + \image html QCPErrorBars.png + + The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref + QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. + + Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the + error bars. The orientation of the error bars can be controlled with \ref setErrorType. + + By using \ref setData, you can supply the actual error data, either as symmetric error or + plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute + key/value position of each error bar will be adopted from the configured data plottable. The + error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points + of the data plottable. You can directly access and manipulate the error bar data via \ref data. + + Set either of the plus/minus errors to NaN (qQNaN() or + std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at + that index. + + \section qcperrorbars-appearance Changing the appearance + + The appearance of the error bars is defined by the pen (\ref setPen), and the width of the + whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data + point center to prevent that error bars are drawn too close to or even through scatter points. + This gap size can be controlled via \ref setSymbolGap. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPErrorBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You + may use it to directly manipulate the error values, which may be more convenient and faster than + using the regular \ref setData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + It is also important that the \a keyAxis and \a valueAxis are the same for the error bars + plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). + + The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not + delete it manually but use \ref QCustomPlot::removePlottable() instead. +*/ +QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QVector), + mErrorType(etValueError), + mWhiskerWidth(9), + mSymbolGap(10) +{ + setPen(QPen(Qt::black, 0)); + setBrush(Qt::NoBrush); +} + +QCPErrorBars::~QCPErrorBars() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data + container safely. Modifying the data in the container will then affect all \ref QCPErrorBars + instances that share the container. Sharing can be achieved by simply exchanging the data + containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, assign the + data containers directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 + (This uses different notation compared with other plottables, because the \ref QCPErrorBars + uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) + + \see addData +*/ +void QCPErrorBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &error) +{ + mDataContainer->clear(); + addData(error); +} + +/*! \overload + + Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) +{ + mDataContainer->clear(); + addData(errorMinus, errorPlus); +} + +/*! + Sets the data plottable to which the error bars will be applied. The error values specified e.g. + via \ref setData will be associated one-to-one by the data point index to the data points of \a + plottable. This means that the error bars will adopt the key/value coordinates of the data point + with the same index. + + The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref + QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either + of these restrictions is violated, a corresponding qDebug output is generated, and the data + plottable of this \ref QCPErrorBars instance is set to zero. + + For proper display, care must also be taken that the key and value axes of the \a plottable match + those configured for this \ref QCPErrorBars instance. +*/ +void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) +{ + if (plottable && qobject_cast(plottable)) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; + return; + } + if (plottable && !plottable->interface1D()) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; + return; + } + + mDataPlottable = plottable; +} + +/*! + Sets in which orientation the error bars shall appear on the data points. If your data needs both + error dimensions, create two \ref QCPErrorBars with different \a type. +*/ +void QCPErrorBars::setErrorType(ErrorType type) +{ + mErrorType = type; +} + +/*! + Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to + \a pixels. +*/ +void QCPErrorBars::setWhiskerWidth(double pixels) +{ + mWhiskerWidth = pixels; +} + +/*! + Sets the gap diameter around the data points that will be left out when drawing the error bar + backbones. This gap prevents that error bars are drawn too close to or even through scatter + points. +*/ +void QCPErrorBars::setSymbolGap(double pixels) +{ + mSymbolGap = pixels; +} + +/*! \overload + + Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &error) +{ + addData(error, error); +} + +/*! \overload + + Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) +{ + if (errorMinus.size() != errorPlus.size()) + qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); + const int n = qMin(errorMinus.size(), errorPlus.size()); + mDataContainer->reserve(n); + for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); +} + +/*! \overload + + Adds a single symmetrical error bar as specified in \a error. The errors will be associated + one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double error) +{ + mDataContainer->append(QCPErrorBarsData(error)); +} + +/*! \overload + + Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors + will be associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double errorMinus, double errorPlus) +{ + mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); +} + +/* inherits documentation from base class */ +int QCPErrorBars::dataCount() const +{ + return mDataContainer->size(); +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataSortKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataSortKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainValue(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainValue(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::dataValueRange(int index) const +{ + if (mDataPlottable) + { + const double value = mDataPlottable->interface1D()->dataMainValue(index); + if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) + return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); + else + return QCPRange(value, value); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QCPRange(); + } +} + +/* inherits documentation from base class */ +QPointF QCPErrorBars::dataPixelPosition(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataPixelPosition(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QPointF(); +} + +/* inherits documentation from base class */ +bool QCPErrorBars::sortKeyIsMainKey() const +{ + if (mDataPlottable) + { + return mDataPlottable->interface1D()->sortKeyIsMainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return true; + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if (!mDataPlottable) + return result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); + + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + backbones.clear(); + whiskers.clear(); + getErrorBarLines(it, backbones, whiskers); + for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); + break; + } + } + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); + if (beginIndex >= mDataContainer->size()) + beginIndex = mDataContainer->size()-1; + return beginIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); + if (endIndex > mDataContainer->size()) + endIndex = mDataContainer->size(); + return endIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mDataPlottable) return -1; + + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +void QCPErrorBars::draw(QCPPainter *painter) +{ + if (!mDataPlottable) return; + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + + // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually + // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): + bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) + qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); + } +#endif + + applyDefaultAntialiasingHint(painter); + painter->setBrush(Qt::NoBrush); + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + QVector backbones, whiskers; + for (int i=0; i= unselectedSegments.size(); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + if (painter->pen().capStyle() == Qt::SquareCap) + { + QPen capFixPen(painter->pen()); + capFixPen.setCapStyle(Qt::FlatCap); + painter->setPen(capFixPen); + } + backbones.clear(); + whiskers.clear(); + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) + getErrorBarLines(it, backbones, whiskers); + } + painter->drawLines(backbones); + painter->drawLines(whiskers); + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) + { + painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); + painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); + painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); + } else + { + painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); + painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); + painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); + } +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (mErrorType == etValueError) + { + // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } else // mErrorType == etKeyError + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(dataKey)) continue; + // plus error: + double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); + itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); + } + for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange) + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) + continue; + } + if (mErrorType == etValueError) + { + const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(dataValue)) continue; + // plus error: + double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } else // mErrorType == etKeyError + { + // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! \internal + + Calculates the lines that make up the error bar belonging to the data point \a it. + + The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so + calling this method with different \a it but the same \a backbones and \a whiskers allows to + accumulate lines for multiple data points. + + This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars + instance and within the bounds of the associated data plottable. +*/ +void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const +{ + if (!mDataPlottable) return; + + int index = it-mDataContainer->constBegin(); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) + return; + QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); + QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); + const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value + const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); + // plus error: + double errorStart, errorEnd; + if (!qIsNaN(it->errorPlus)) + { + errorStart = centerErrorAxisPixel+symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } + // minus error: + if (!qIsNaN(it->errorMinus)) + { + errorStart = centerErrorAxisPixel-symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } +} + +/*! \internal + + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key + coordinates relative to their data point key, this method checks all outer error bars whether + they truly don't reach into the visible portion of the axis rect, by calling \ref + errorBarVisible. On the other hand error bars with type \ref etValueError that are associated + with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype + "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of + error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref + QCPPlottableInterface1D::findEnd). + + If the plottable's sort key is not equal to the main key, this method returns the full data + range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a + point-by-point basis in the \ref draw method. +*/ +void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable || rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) + { + // if the sort key isn't the main key, it's not possible to find a contiguous range of visible + // data points, so this method then only applies the range restriction and otherwise returns + // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing + QCPDataRange dataRange(0, mDataContainer->size()); + dataRange = dataRange.bounded(rangeRestriction); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); + return; + } + + // get visible data range via interface from data plottable, and then restrict to available error data points: + const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); + int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); + int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); + int i = beginIndex; + while (i > 0 && i < n && i > rangeRestriction.begin()) + { + if (errorBarVisible(i)) + beginIndex = i; + --i; + } + i = endIndex; + while (i >= 0 && i < n && i < rangeRestriction.end()) + { + if (errorBarVisible(i)) + endIndex = i+1; + ++i; + } + QCPDataRange dataRange(beginIndex, endIndex); + dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); +} + +/*! \internal + + Calculates the minimum distance in pixels the error bars' representation has from the given \a + pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. +*/ +double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (!mDataPlottable || mDataContainer->isEmpty()) + return -1.0; + if (!mKeyAxis || !mValueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1.0; + } + + QCPErrorBarsDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); + + // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + getErrorBarLines(it, backbones, whiskers); + for (int i=0; i &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! \internal + + Returns whether the error bar at the specified \a index is visible within the current key axis + range. + + This method assumes for performance reasons without checking that the key axis, the value axis, + and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid + bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. +*/ +bool QCPErrorBars::errorBarVisible(int index) const +{ + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + if (qIsNaN(centerKeyPixel)) + return false; + + double keyMin, keyMax; + if (mErrorType == etKeyError) + { + const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); + const double errorPlus = mDataContainer->at(index).errorPlus; + const double errorMinus = mDataContainer->at(index).errorMinus; + keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); + keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); + } else // mErrorType == etValueError + { + keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + } + return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); +} + +/*! \internal + + Returns whether \a line intersects (or is contained in) \a pixelRect. + + \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for + error bar lines. +*/ +bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const +{ + if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) + return false; + else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) + return false; + else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) + return false; + else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) + return false; + else + return true; +} +/* end of 'src/plottables/plottable-errorbar.cpp' */ + + +/* including file 'src/items/item-straightline.cpp', size 7592 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemStraightLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemStraightLine + \brief A straight line that spans infinitely in both directions + + \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a point1 and \a point2, which define the straight line. +*/ + +/*! + Creates a straight line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + point1(createPosition(QLatin1String("point1"))), + point2(createPosition(QLatin1String("point2"))) +{ + point1->setCoords(0, 0); + point2->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemStraightLine::~QCPItemStraightLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemStraightLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemStraightLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); +} + +/* inherits documentation from base class */ +void QCPItemStraightLine::draw(QCPPainter *painter) +{ + QCPVector2D start(point1->pixelPosition()); + QCPVector2D end(point2->pixelPosition()); + // get visible segment of straight line inside clipRect: + double clipPad = mainPen().widthF(); + QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + } +} + +/*! \internal + + Returns the section of the straight line defined by \a base and direction vector \a + vec, that is visible in the specified \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const +{ + double bx, by; + double gamma; + QLineF result; + if (vec.x() == 0 && vec.y() == 0) + return result; + if (qFuzzyIsNull(vec.x())) // line is vertical + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical + } else if (qFuzzyIsNull(vec.y())) // line is horizontal + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal + } else // line is skewed + { + QList pointVectors; + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + // check right of rect: + bx = rect.right(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemStraightLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-straightline.cpp' */ + + +/* including file 'src/items/item-line.cpp', size 8498 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemLine + \brief A line from one point to another + + \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a start and \a end, which define the end points of the line. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. +*/ + +/*! + Creates a line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemLine::~QCPItemLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemLine::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemLine::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); +} + +/* inherits documentation from base class */ +void QCPItemLine::draw(QCPPainter *painter) +{ + QCPVector2D startVec(start->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if (qFuzzyIsNull((startVec-endVec).lengthSquared())) + return; + // get visible segment of straight line inside clipRect: + double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); + clipPad = qMax(clipPad, (double)mainPen().widthF()); + QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, startVec-endVec); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, endVec-startVec); + } +} + +/*! \internal + + Returns the section of the line defined by \a start and \a end, that is visible in the specified + \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const +{ + bool containsStart = rect.contains(start.x(), start.y()); + bool containsEnd = rect.contains(end.x(), end.y()); + if (containsStart && containsEnd) + return QLineF(start.toPointF(), end.toPointF()); + + QCPVector2D base = start; + QCPVector2D vec = end-start; + double bx, by; + double gamma, mu; + QLineF result; + QList pointVectors; + + if (!qFuzzyIsNull(vec.y())) // line is not horizontal + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + } + if (!qFuzzyIsNull(vec.x())) // line is not vertical + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + // check right of rect: + bx = rect.right(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + } + + if (containsStart) + pointVectors.append(start); + if (containsEnd) + pointVectors.append(end); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-line.cpp' */ + + +/* including file 'src/items/item-curve.cpp', size 7159 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemCurve + \brief A curved line from one point to another + + \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." + + It has four positions, \a start and \a end, which define the end points of the line, and two + control points which define the direction the line exits from the start and the direction from + which it approaches the end: \a startDir and \a endDir. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an + arrow. + + Often it is desirable for the control points to stay at fixed relative positions to the start/end + point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, + and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. +*/ + +/*! + Creates a curve item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + startDir(createPosition(QLatin1String("startDir"))), + endDir(createPosition(QLatin1String("endDir"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + startDir->setCoords(0.5, 0); + endDir->setCoords(0, 0.5); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemCurve::~QCPItemCurve() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemCurve::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemCurve::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemCurve::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemCurve::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF startVec(start->pixelPosition()); + QPointF startDirVec(startDir->pixelPosition()); + QPointF endDirVec(endDir->pixelPosition()); + QPointF endVec(end->pixelPosition()); + + QPainterPath cubicPath(startVec); + cubicPath.cubicTo(startDirVec, endDirVec, endVec); + + QPolygonF polygon = cubicPath.toSubpathPolygons().first(); + QCPVector2D p(pos); + double minDistSqr = std::numeric_limits::max(); + for (int i=1; ipixelPosition()); + QCPVector2D startDirVec(startDir->pixelPosition()); + QCPVector2D endDirVec(endDir->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if ((endVec-startVec).length() > 1e10) // too large curves cause crash + return; + + QPainterPath cubicPath(startVec.toPointF()); + cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); + + // paint visible segment, if existent: + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + QRect cubicRect = cubicPath.controlPointRect().toRect(); + if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position + cubicRect.adjust(0, 0, 1, 1); + if (clip.intersects(cubicRect)) + { + painter->setPen(mainPen()); + painter->drawPath(cubicPath); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemCurve::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-curve.cpp' */ + + +/* including file 'src/items/item-rect.cpp', size 6479 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemRect + \brief A rectangle + + \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemRect::~QCPItemRect() +{ +} + +/*! + Sets the pen that will be used to draw the line of the rectangle + + \see setSelectedPen, setBrush +*/ +void QCPItemRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the rectangle when selected + + \see setPen, setSelected +*/ +void QCPItemRect::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemRect::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); +} + +/* inherits documentation from base class */ +void QCPItemRect::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF rect = QRectF(p1, p2).normalized(); + double clipPad = mainPen().widthF(); + QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(rect); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemRect::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemRect::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemRect::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-rect.cpp' */ + + +/* including file 'src/items/item-text.cpp', size 13338 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemText +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemText + \brief A text label + + \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." + + Its position is defined by the member \a position and the setting of \ref setPositionAlignment. + The latter controls which part of the text rect shall be aligned with \a position. + + The text alignment itself (i.e. left, center, right) can be controlled with \ref + setTextAlignment. + + The text may be rotated around the \a position point with \ref setRotation. +*/ + +/*! + Creates a text item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemText::QCPItemText(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mText(QLatin1String("text")), + mPositionAlignment(Qt::AlignCenter), + mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), + mRotation(0) +{ + position->setCoords(0, 0); + + setPen(Qt::NoPen); + setSelectedPen(Qt::NoPen); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setColor(Qt::black); + setSelectedColor(Qt::blue); +} + +QCPItemText::~QCPItemText() +{ +} + +/*! + Sets the color of the text. +*/ +void QCPItemText::setColor(const QColor &color) +{ + mColor = color; +} + +/*! + Sets the color of the text that will be used when the item is selected. +*/ +void QCPItemText::setSelectedColor(const QColor &color) +{ + mSelectedColor = color; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text. To disable the + border, set \a pen to Qt::NoPen. + + \see setSelectedPen, setBrush, setPadding +*/ +void QCPItemText::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text, when the item is + selected. To disable the border, set \a pen to Qt::NoPen. + + \see setPen +*/ +void QCPItemText::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used do fill the background of the text. To disable the + background, set \a brush to Qt::NoBrush. + + \see setSelectedBrush, setPen, setPadding +*/ +void QCPItemText::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the + background, set \a brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemText::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the font of the text. + + \see setSelectedFont, setColor +*/ +void QCPItemText::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the font of the text that will be used when the item is selected. + + \see setFont +*/ +void QCPItemText::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the text that will be displayed. Multi-line texts are supported by inserting a line break + character, e.g. '\n'. + + \see setFont, setColor, setTextAlignment +*/ +void QCPItemText::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets which point of the text rect shall be aligned with \a position. + + Examples: + \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such + that the top of the text rect will be horizontally centered on \a position. + \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the + bottom left corner of the text rect. + + If you want to control the alignment of (multi-lined) text within the text rect, use \ref + setTextAlignment. +*/ +void QCPItemText::setPositionAlignment(Qt::Alignment alignment) +{ + mPositionAlignment = alignment; +} + +/*! + Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). +*/ +void QCPItemText::setTextAlignment(Qt::Alignment alignment) +{ + mTextAlignment = alignment; +} + +/*! + Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated + around \a position. +*/ +void QCPItemText::setRotation(double degrees) +{ + mRotation = degrees; +} + +/*! + Sets the distance between the border of the text rectangle and the text. The appearance (and + visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. +*/ +void QCPItemText::setPadding(const QMargins &padding) +{ + mPadding = padding; +} + +/* inherits documentation from base class */ +double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + // The rect may be rotated, so we transform the actual clicked pos to the rotated + // coordinate system, so we can use the normal rectDistance function for non-rotated rects: + QPointF positionPixels(position->pixelPosition()); + QTransform inputTransform; + inputTransform.translate(positionPixels.x(), positionPixels.y()); + inputTransform.rotate(-mRotation); + inputTransform.translate(-positionPixels.x(), -positionPixels.y()); + QPointF rotatedPos = inputTransform.map(pos); + QFontMetrics fontMetrics(mFont); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); + textBoxRect.moveTopLeft(textPos.toPoint()); + + return rectDistance(textBoxRect, rotatedPos, true); +} + +/* inherits documentation from base class */ +void QCPItemText::draw(QCPPainter *painter) +{ + QPointF pos(position->pixelPosition()); + QTransform transform = painter->transform(); + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + painter->setFont(mainFont()); + QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); + textBoxRect.moveTopLeft(textPos.toPoint()); + double clipPad = mainPen().widthF(); + QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) + { + painter->setTransform(transform); + if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || + (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(textBoxRect); + } + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(mainColor())); + painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemText::anchorPixelPosition(int anchorId) const +{ + // get actual rect points (pretty much copied from draw function): + QPointF pos(position->pixelPosition()); + QTransform transform; + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + QFontMetrics fontMetrics(mainFont()); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textBoxRect.moveTopLeft(textPos.toPoint()); + QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); + + switch (anchorId) + { + case aiTopLeft: return rectPoly.at(0); + case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; + case aiTopRight: return rectPoly.at(1); + case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; + case aiBottomRight: return rectPoly.at(2); + case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; + case aiBottomLeft: return rectPoly.at(3); + case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the point that must be given to the QPainter::drawText function (which expects the top + left point of the text rect), according to the position \a pos, the text bounding box \a rect and + the requested \a positionAlignment. + + For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point + will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally + drawn at that point, the lower left corner of the resulting text rect is at \a pos. +*/ +QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const +{ + if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) + return pos; + + QPointF result = pos; // start at top left + if (positionAlignment.testFlag(Qt::AlignHCenter)) + result.rx() -= rect.width()/2.0; + else if (positionAlignment.testFlag(Qt::AlignRight)) + result.rx() -= rect.width(); + if (positionAlignment.testFlag(Qt::AlignVCenter)) + result.ry() -= rect.height()/2.0; + else if (positionAlignment.testFlag(Qt::AlignBottom)) + result.ry() -= rect.height(); + return result; +} + +/*! \internal + + Returns the font that should be used for drawing text. Returns mFont when the item is not selected + and mSelectedFont when it is. +*/ +QFont QCPItemText::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the color that should be used for drawing text. Returns mColor when the item is not + selected and mSelectedColor when it is. +*/ +QColor QCPItemText::mainColor() const +{ + return mSelected ? mSelectedColor : mColor; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemText::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemText::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-text.cpp' */ + + +/* including file 'src/items/item-ellipse.cpp', size 7863 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemEllipse +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemEllipse + \brief An ellipse + + \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. +*/ + +/*! + Creates an ellipse item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), + left(createAnchor(QLatin1String("left"), aiLeft)), + center(createAnchor(QLatin1String("center"), aiCenter)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemEllipse::~QCPItemEllipse() +{ +} + +/*! + Sets the pen that will be used to draw the line of the ellipse + + \see setSelectedPen, setBrush +*/ +void QCPItemEllipse::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the ellipse when selected + + \see setPen, setSelected +*/ +void QCPItemEllipse::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemEllipse::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemEllipse::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + QPointF center((p1+p2)/2.0); + double a = qAbs(p1.x()-p2.x())/2.0; + double b = qAbs(p1.y()-p2.y())/2.0; + double x = pos.x()-center.x(); + double y = pos.y()-center.y(); + + // distance to border: + double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); + double result = qAbs(c-1)*qSqrt(x*x+y*y); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (x*x/(a*a) + y*y/(b*b) <= 1) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/* inherits documentation from base class */ +void QCPItemEllipse::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF ellipseRect = QRectF(p1, p2).normalized(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); +#ifdef __EXCEPTIONS + try // drawEllipse sometimes throws exceptions if ellipse is too big + { +#endif + painter->drawEllipse(ellipseRect); +#ifdef __EXCEPTIONS + } catch (...) + { + qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; + setVisible(false); + } +#endif + } +} + +/* inherits documentation from base class */ +QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemEllipse::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemEllipse::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-ellipse.cpp' */ + + +/* including file 'src/items/item-pixmap.cpp', size 10615 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPixmap + \brief An arbitrary pixmap + + \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will + be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to + fit the rectangle or be drawn aligned to the topLeft position. + + If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown + on the right side of the example image), the pixmap will be flipped in the respective + orientations. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mScaled(false), + mScaledPixmapInvalidated(true), + mAspectRatioMode(Qt::KeepAspectRatio), + mTransformationMode(Qt::SmoothTransformation) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(Qt::NoPen); + setSelectedPen(QPen(Qt::blue)); +} + +QCPItemPixmap::~QCPItemPixmap() +{ +} + +/*! + Sets the pixmap that will be displayed. +*/ +void QCPItemPixmap::setPixmap(const QPixmap &pixmap) +{ + mPixmap = pixmap; + mScaledPixmapInvalidated = true; + if (mPixmap.isNull()) + qDebug() << Q_FUNC_INFO << "pixmap is null"; +} + +/*! + Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a + bottomRight positions. +*/ +void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) +{ + mScaled = scaled; + mAspectRatioMode = aspectRatioMode; + mTransformationMode = transformationMode; + mScaledPixmapInvalidated = true; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap. + + \see setSelectedPen, setBrush +*/ +void QCPItemPixmap::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap when selected + + \see setPen, setSelected +*/ +void QCPItemPixmap::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return rectDistance(getFinalRect(), pos, true); +} + +/* inherits documentation from base class */ +void QCPItemPixmap::draw(QCPPainter *painter) +{ + bool flipHorz = false; + bool flipVert = false; + QRect rect = getFinalRect(&flipHorz, &flipVert); + double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); + QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) + { + updateScaledPixmap(rect, flipHorz, flipVert); + painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); + QPen pen = mainPen(); + if (pen.style() != Qt::NoPen) + { + painter->setPen(pen); + painter->setBrush(Qt::NoBrush); + painter->drawRect(rect); + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const +{ + bool flipHorz; + bool flipVert; + QRect rect = getFinalRect(&flipHorz, &flipVert); + // we actually want denormal rects (negative width/height) here, so restore + // the flipped state: + if (flipHorz) + rect.adjust(rect.width(), 0, -rect.width(), 0); + if (flipVert) + rect.adjust(0, rect.height(), 0, -rect.height()); + + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The + parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped + horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a + bottomRight.) + + This function only creates the scaled pixmap when the buffered pixmap has a different size than + the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does + not cause expensive rescaling every time. + + If scaling is disabled, sets mScaledPixmap to a null QPixmap. +*/ +void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) +{ + if (mPixmap.isNull()) + return; + + if (mScaled) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + double devicePixelRatio = mPixmap.devicePixelRatio(); +#else + double devicePixelRatio = 1.0; +#endif + if (finalRect.isNull()) + finalRect = getFinalRect(&flipHorz, &flipVert); + if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) + { + mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); + if (flipHorz || flipVert) + mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mScaledPixmap.setDevicePixelRatio(devicePixelRatio); +#endif + } + } else if (!mScaledPixmap.isNull()) + mScaledPixmap = QPixmap(); + mScaledPixmapInvalidated = false; +} + +/*! \internal + + Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions + and scaling settings. + + The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn + flipped horizontally or vertically in the returned rect. (The returned rect itself is always + normalized, i.e. the top left corner of the rect is actually further to the top/left than the + bottom right corner). This is the case when the item position \a topLeft is further to the + bottom/right than \a bottomRight. + + If scaling is disabled, returns a rect with size of the original pixmap and the top left corner + aligned with the item position \a topLeft. The position \a bottomRight is ignored. +*/ +QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const +{ + QRect result; + bool flipHorz = false; + bool flipVert = false; + QPoint p1 = topLeft->pixelPosition().toPoint(); + QPoint p2 = bottomRight->pixelPosition().toPoint(); + if (p1 == p2) + return QRect(p1, QSize(0, 0)); + if (mScaled) + { + QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); + QPoint topLeft = p1; + if (newSize.width() < 0) + { + flipHorz = true; + newSize.rwidth() *= -1; + topLeft.setX(p2.x()); + } + if (newSize.height() < 0) + { + flipVert = true; + newSize.rheight() *= -1; + topLeft.setY(p2.y()); + } + QSize scaledSize = mPixmap.size(); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + scaledSize /= mPixmap.devicePixelRatio(); + scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); +#else + scaledSize.scale(newSize, mAspectRatioMode); +#endif + result = QRect(topLeft, scaledSize); + } else + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); +#else + result = QRect(p1, mPixmap.size()); +#endif + } + if (flippedHorz) + *flippedHorz = flipHorz; + if (flippedVert) + *flippedVert = flipVert; + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemPixmap::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-pixmap.cpp' */ + + +/* including file 'src/items/item-tracer.cpp', size 14624 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemTracer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemTracer + \brief Item that sticks to QCPGraph data points + + \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." + + The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt + the coordinate axes of the graph and update its \a position to be on the graph's data. This means + the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a + QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a + position will have no effect because they will be overriden in the next redraw (this is when the + coordinate update happens). + + If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will + stay at the corresponding end of the graph. + + With \ref setInterpolating you may specify whether the tracer may only stay exactly on data + points or whether it interpolates data points linearly, if given a key that lies between two data + points of the graph. + + The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer + have no own visual appearance (set the style to \ref tsNone), and just connect other item + positions to the tracer \a position (used as an anchor) via \ref + QCPItemPosition::setParentAnchor. + + \note The tracer position is only automatically updated upon redraws. So when the data of the + graph changes and immediately afterwards (without a redraw) the position coordinates of the + tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref + updatePosition must be called manually, prior to reading the tracer coordinates. +*/ + +/*! + Creates a tracer item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + mSize(6), + mStyle(tsCrosshair), + mGraph(0), + mGraphKey(0), + mInterpolating(false) +{ + position->setCoords(0, 0); + + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemTracer::~QCPItemTracer() +{ +} + +/*! + Sets the pen that will be used to draw the line of the tracer + + \see setSelectedPen, setBrush +*/ +void QCPItemTracer::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the tracer when selected + + \see setPen, setSelected +*/ +void QCPItemTracer::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer + + \see setSelectedBrush, setPen +*/ +void QCPItemTracer::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer, when selected. + + \see setBrush, setSelected +*/ +void QCPItemTracer::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare + does, \ref tsCrosshair does not). +*/ +void QCPItemTracer::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the style/visual appearance of the tracer. + + If you only want to use the tracer \a position as an anchor for other items, set \a style to + \ref tsNone. +*/ +void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) +{ + mStyle = style; +} + +/*! + Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type + QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. + + To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed + freely like any other item position. This is the state the tracer will assume when its graph gets + deleted while still attached to it. + + \see setGraphKey +*/ +void QCPItemTracer::setGraph(QCPGraph *graph) +{ + if (graph) + { + if (graph->parentPlot() == mParentPlot) + { + position->setType(QCPItemPosition::ptPlotCoords); + position->setAxes(graph->keyAxis(), graph->valueAxis()); + mGraph = graph; + updatePosition(); + } else + qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; + } else + { + mGraph = 0; + } +} + +/*! + Sets the key of the graph's data point the tracer will be positioned at. This is the only free + coordinate of a tracer when attached to a graph. + + Depending on \ref setInterpolating, the tracer will be either positioned on the data point + closest to \a key, or will stay exactly at \a key and interpolate the value linearly. + + \see setGraph, setInterpolating +*/ +void QCPItemTracer::setGraphKey(double key) +{ + mGraphKey = key; +} + +/*! + Sets whether the value of the graph's data points shall be interpolated, when positioning the + tracer. + + If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on + the data point of the graph which is closest to the key, but which is not necessarily exactly + there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and + the appropriate value will be interpolated from the graph's data points linearly. + + \see setGraph, setGraphKey +*/ +void QCPItemTracer::setInterpolating(bool enabled) +{ + mInterpolating = enabled; +} + +/* inherits documentation from base class */ +double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return -1; + case tsPlus: + { + if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), + QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); + break; + } + case tsCrosshair: + { + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), + QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + // distance to border: + double centerDist = QCPVector2D(center-pos).length(); + double circleLine = w; + double result = qAbs(centerDist-circleLine); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (centerDist <= circleLine) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; + } + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); + } + break; + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemTracer::draw(QCPPainter *painter) +{ + updatePosition(); + if (mStyle == tsNone) + return; + + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return; + case tsPlus: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); + painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); + } + break; + } + case tsCrosshair: + { + if (center.y() > clip.top() && center.y() < clip.bottom()) + painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); + if (center.x() > clip.left() && center.x() < clip.right()) + painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); + break; + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawEllipse(center, w, w); + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); + break; + } + } +} + +/*! + If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a + position to reside on the graph data, depending on the configured key (\ref setGraphKey). + + It is called automatically on every redraw and normally doesn't need to be called manually. One + exception is when you want to read the tracer coordinates via \a position and are not sure that + the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. + In that situation, call this function before accessing \a position, to make sure you don't get + out-of-date coordinates. + + If there is no graph set on this tracer, this function does nothing. +*/ +void QCPItemTracer::updatePosition() +{ + if (mGraph) + { + if (mParentPlot->hasPlottable(mGraph)) + { + if (mGraph->data()->size() > 1) + { + QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); + QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; + if (mGraphKey <= first->key) + position->setCoords(first->key, first->value); + else if (mGraphKey >= last->key) + position->setCoords(last->key, last->value); + else + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); + if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators + { + QCPGraphDataContainer::const_iterator prevIt = it; + ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before + if (mInterpolating) + { + // interpolate between iterators around mGraphKey: + double slope = 0; + if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) + slope = (it->value-prevIt->value)/(it->key-prevIt->key); + position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); + } else + { + // find iterator with key closest to mGraphKey: + if (mGraphKey < (prevIt->key+it->key)*0.5) + position->setCoords(prevIt->key, prevIt->value); + else + position->setCoords(it->key, it->value); + } + } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) + position->setCoords(it->key, it->value); + } + } else if (mGraph->data()->size() == 1) + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); + position->setCoords(it->key, it->value); + } else + qDebug() << Q_FUNC_INFO << "graph has no data"; + } else + qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemTracer::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemTracer::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-tracer.cpp' */ + + +/* including file 'src/items/item-bracket.cpp', size 10687 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemBracket + \brief A bracket for referencing/highlighting certain parts in the plot. + + \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a left and \a right, which define the span of the bracket. If \a left is + actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the + example image. + + The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket + stretches away from the embraced span, can be controlled with \ref setLength. + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+ + It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine + or QCPItemCurve) or a text label (QCPItemText), to the bracket. +*/ + +/*! + Creates a bracket item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + left(createPosition(QLatin1String("left"))), + right(createPosition(QLatin1String("right"))), + center(createAnchor(QLatin1String("center"), aiCenter)), + mLength(8), + mStyle(bsCalligraphic) +{ + left->setCoords(0, 0); + right->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemBracket::~QCPItemBracket() +{ +} + +/*! + Sets the pen that will be used to draw the bracket. + + Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the + stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use + \ref setLength, which has a similar effect. + + \see setSelectedPen +*/ +void QCPItemBracket::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the bracket when selected + + \see setPen, setSelected +*/ +void QCPItemBracket::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the \a length in pixels how far the bracket extends in the direction towards the embraced + span of the bracket (i.e. perpendicular to the left-right-direction) + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+*/ +void QCPItemBracket::setLength(double length) +{ + mLength = length; +} + +/*! + Sets the style of the bracket, i.e. the shape/visual appearance. + + \see setPen +*/ +void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) +{ + mStyle = style; +} + +/* inherits documentation from base class */ +double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QCPVector2D p(pos); + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return -1; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (mStyle) + { + case QCPItemBracket::bsSquare: + case QCPItemBracket::bsRound: + { + double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); + double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); + return qSqrt(qMin(qMin(a, b), c)); + } + case QCPItemBracket::bsCurly: + case QCPItemBracket::bsCalligraphic: + { + double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); + double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); + return qSqrt(qMin(qMin(a, b), qMin(c, d))); + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemBracket::draw(QCPPainter *painter) +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + QPolygon boundingPoly; + boundingPoly << leftVec.toPoint() << rightVec.toPoint() + << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (clip.intersects(boundingPoly.boundingRect())) + { + painter->setPen(mainPen()); + switch (mStyle) + { + case bsSquare: + { + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + break; + } + case bsRound: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCurly: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCalligraphic: + { + painter->setPen(Qt::NoPen); + painter->setBrush(QBrush(mainPen().color())); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); + path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + + painter->drawPath(path); + break; + } + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return leftVec.toPointF(); + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (anchorId) + { + case aiCenter: + return centerVec.toPointF(); + } + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemBracket::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-bracket.cpp' */ + + diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h new file mode 100644 index 00000000..278fbf82 --- /dev/null +++ b/src/qt/qcustomplot.h @@ -0,0 +1,6662 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#ifndef QCUSTOMPLOT_H +#define QCUSTOMPLOT_H + +#include + +// some Qt version/configuration dependent macros to include or exclude certain code paths: +#ifdef QCUSTOMPLOT_USE_OPENGL +# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +# define QCP_OPENGL_PBUFFER +# else +# define QCP_OPENGL_FBO +# endif +# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) +# define QCP_OPENGL_OFFSCREENSURFACE +# endif +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +# define QCP_DEVICEPIXELRATIO_SUPPORTED +# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) +# define QCP_DEVICEPIXELRATIO_FLOAT +# endif +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef QCP_OPENGL_FBO +# include +# include +# ifdef QCP_OPENGL_OFFSCREENSURFACE +# include +# else +# include +# endif +#endif +#ifdef QCP_OPENGL_PBUFFER +# include +#endif +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +# include +# include +# include +# include +#else +# include +# include +# include +#endif + +class QCPPainter; +class QCustomPlot; +class QCPLayerable; +class QCPLayoutElement; +class QCPLayout; +class QCPAxis; +class QCPAxisRect; +class QCPAxisPainterPrivate; +class QCPAbstractPlottable; +class QCPGraph; +class QCPAbstractItem; +class QCPPlottableInterface1D; +class QCPLegend; +class QCPItemPosition; +class QCPLayer; +class QCPAbstractLegendItem; +class QCPSelectionRect; +class QCPColorMap; +class QCPColorScale; +class QCPBars; + +/* including file 'src/global.h', size 16225 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +// decl definitions for shared library compilation/usage: +#if defined(QCUSTOMPLOT_COMPILE_LIBRARY) +# define QCP_LIB_DECL Q_DECL_EXPORT +#elif defined(QCUSTOMPLOT_USE_LIBRARY) +# define QCP_LIB_DECL Q_DECL_IMPORT +#else +# define QCP_LIB_DECL +#endif + +// define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5) +#ifndef Q_DECL_OVERRIDE +# define Q_DECL_OVERRIDE +#endif + +/*! + The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot + library. + + It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. +*/ +#ifndef Q_MOC_RUN +namespace QCP { +#else +class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace + Q_GADGET + Q_ENUMS(ExportPen) + Q_ENUMS(ResolutionUnit) + Q_ENUMS(SignDomain) + Q_ENUMS(MarginSide) + Q_FLAGS(MarginSides) + Q_ENUMS(AntialiasedElement) + Q_FLAGS(AntialiasedElements) + Q_ENUMS(PlottingHint) + Q_FLAGS(PlottingHints) + Q_ENUMS(Interaction) + Q_FLAGS(Interactions) + Q_ENUMS(SelectionRectMode) + Q_ENUMS(SelectionType) +public: +#endif + +/*! + Defines the different units in which the image resolution can be specified in the export + functions. + + \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered +*/ +enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) + ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) + ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) + }; + +/*! + Defines how cosmetic pens (pens with numerical width 0) are handled during export. + + \see QCustomPlot::savePdf +*/ +enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting + ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) + }; + +/*! + Represents negative and positive sign domain, e.g. for passing to \ref + QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange. + + This is primarily needed when working with logarithmic axis scales, since only one of the sign + domains can be visible at a time. +*/ +enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero + ,sdBoth ///< Both sign domains, including zero, i.e. all numbers + ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero + }; + +/*! + Defines the sides of a rectangular entity to which margins can be applied. + + \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins +*/ +enum MarginSide { msLeft = 0x01 ///< 0x01 left margin + ,msRight = 0x02 ///< 0x02 right margin + ,msTop = 0x04 ///< 0x04 top margin + ,msBottom = 0x08 ///< 0x08 bottom margin + ,msAll = 0xFF ///< 0xFF all margins + ,msNone = 0x00 ///< 0x00 no margin + }; +Q_DECLARE_FLAGS(MarginSides, MarginSide) + +/*! + Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is + neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective + element how it is drawn. Typically it provides a \a setAntialiased function for this. + + \c AntialiasedElements is a flag of or-combined elements of this enum type. + + \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements +*/ +enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks + ,aeGrid = 0x0002 ///< 0x0002 Grid lines + ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines + ,aeLegend = 0x0008 ///< 0x0008 Legend box + ,aeLegendItems = 0x0010 ///< 0x0010 Legend items + ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables + ,aeItems = 0x0040 ///< 0x0040 Main lines of items + ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) + ,aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) + ,aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen + ,aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories + ,aeAll = 0xFFFF ///< 0xFFFF All elements + ,aeNone = 0x0000 ///< 0x0000 No elements + }; +Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) + +/*! + Defines plotting hints that control various aspects of the quality and speed of plotting. + + \see QCustomPlot::setPlottingHints +*/ +enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set + ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment + ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. + ,phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. + ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). + ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. + }; +Q_DECLARE_FLAGS(PlottingHints, PlottingHint) + +/*! + Defines the mouse interactions possible with QCustomPlot. + + \c Interactions is a flag of or-combined elements of this enum type. + + \see QCustomPlot::setInteractions +*/ +enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) + ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) + ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking + ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) + ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) + ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) + ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) + ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) + }; +Q_DECLARE_FLAGS(Interactions, Interaction) + +/*! + Defines the behaviour of the selection rect. + + \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect +*/ +enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging + ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. + ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) + ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. + }; + +/*! + Defines the different ways a plottable can be selected. These images show the effect of the + different selection types, when the indicated selection rect was dragged: + +
+ + + + + + + + +
\image html selectiontype-none.png stNone\image html selectiontype-whole.png stWhole\image html selectiontype-singledata.png stSingleData\image html selectiontype-datarange.png stDataRange\image html selectiontype-multipledataranges.png stMultipleDataRanges
+
+ + \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType +*/ +enum SelectionType { stNone ///< The plottable is not selectable + ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. + ,stSingleData ///< One individual data point can be selected at a time + ,stDataRange ///< Multiple contiguous data points (a data range) can be selected + ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected + }; + +/*! \internal + + Returns whether the specified \a value is considered an invalid data value for plottables (i.e. + is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the + compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. +*/ +inline bool isInvalidData(double value) +{ + return qIsNaN(value) || qIsInf(value); +} + +/*! \internal + \overload + + Checks two arguments instead of one. +*/ +inline bool isInvalidData(double value1, double value2) +{ + return isInvalidData(value1) || isInvalidData(value2); +} + +/*! \internal + + Sets the specified \a side of \a margins to \a value + + \see getMarginValue +*/ +inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) +{ + switch (side) + { + case QCP::msLeft: margins.setLeft(value); break; + case QCP::msRight: margins.setRight(value); break; + case QCP::msTop: margins.setTop(value); break; + case QCP::msBottom: margins.setBottom(value); break; + case QCP::msAll: margins = QMargins(value, value, value, value); break; + default: break; + } +} + +/*! \internal + + Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or + \ref QCP::msAll, returns 0. + + \see setMarginValue +*/ +inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return margins.left(); + case QCP::msRight: return margins.right(); + case QCP::msTop: return margins.top(); + case QCP::msBottom: return margins.bottom(); + default: break; + } + return 0; +} + + +extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace + +} // end of namespace QCP +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) +Q_DECLARE_METATYPE(QCP::ExportPen) +Q_DECLARE_METATYPE(QCP::ResolutionUnit) +Q_DECLARE_METATYPE(QCP::SignDomain) +Q_DECLARE_METATYPE(QCP::MarginSide) +Q_DECLARE_METATYPE(QCP::AntialiasedElement) +Q_DECLARE_METATYPE(QCP::PlottingHint) +Q_DECLARE_METATYPE(QCP::Interaction) +Q_DECLARE_METATYPE(QCP::SelectionRectMode) +Q_DECLARE_METATYPE(QCP::SelectionType) + +/* end of 'src/global.h' */ + + +/* including file 'src/vector2d.h', size 4928 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPVector2D +{ +public: + QCPVector2D(); + QCPVector2D(double x, double y); + QCPVector2D(const QPoint &point); + QCPVector2D(const QPointF &point); + + // getters: + double x() const { return mX; } + double y() const { return mY; } + double &rx() { return mX; } + double &ry() { return mY; } + + // setters: + void setX(double x) { mX = x; } + void setY(double y) { mY = y; } + + // non-virtual methods: + double length() const { return qSqrt(mX*mX+mY*mY); } + double lengthSquared() const { return mX*mX+mY*mY; } + QPoint toPoint() const { return QPoint(mX, mY); } + QPointF toPointF() const { return QPointF(mX, mY); } + + bool isNull() const { return qIsNull(mX) && qIsNull(mY); } + void normalize(); + QCPVector2D normalized() const; + QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); } + double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; } + double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const; + double distanceSquaredToLine(const QLineF &line) const; + double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const; + + QCPVector2D &operator*=(double factor); + QCPVector2D &operator/=(double divisor); + QCPVector2D &operator+=(const QCPVector2D &vector); + QCPVector2D &operator-=(const QCPVector2D &vector); + +private: + // property members: + double mX, mY; + + friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec); + friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor); + friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor); + friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2); + friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2); + friend inline const QCPVector2D operator-(const QCPVector2D &vec); +}; +Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE); + +inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } +inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } +inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); } +inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); } +inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); } +inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); } + +/*! \relates QCPVector2D + + Prints \a vec in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPVector2D &vec) +{ + d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; + return d.space(); +} + +/* end of 'src/vector2d.h' */ + + +/* including file 'src/painter.h', size 4035 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPPainter : public QPainter +{ + Q_GADGET +public: + /*! + Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, + depending on whether they are wanted on the respective output device. + */ + enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices + ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. + ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels + ,pmNonCosmetic = 0x04 ///< 0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.) + }; + Q_ENUMS(PainterMode) + Q_FLAGS(PainterModes) + Q_DECLARE_FLAGS(PainterModes, PainterMode) + + QCPPainter(); + explicit QCPPainter(QPaintDevice *device); + + // getters: + bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } + PainterModes modes() const { return mModes; } + + // setters: + void setAntialiasing(bool enabled); + void setMode(PainterMode mode, bool enabled=true); + void setModes(PainterModes modes); + + // methods hiding non-virtual base class functions (QPainter bug workarounds): + bool begin(QPaintDevice *device); + void setPen(const QPen &pen); + void setPen(const QColor &color); + void setPen(Qt::PenStyle penStyle); + void drawLine(const QLineF &line); + void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} + void save(); + void restore(); + + // non-virtual methods: + void makeNonCosmetic(); + +protected: + // property members: + PainterModes mModes; + bool mIsAntialiasing; + + // non-property members: + QStack mAntialiasingStack; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) +Q_DECLARE_METATYPE(QCPPainter::PainterMode) + +/* end of 'src/painter.h' */ + + +/* including file 'src/paintbuffer.h', size 4958 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAbstractPaintBuffer +{ +public: + explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio); + virtual ~QCPAbstractPaintBuffer(); + + // getters: + QSize size() const { return mSize; } + bool invalidated() const { return mInvalidated; } + double devicePixelRatio() const { return mDevicePixelRatio; } + + // setters: + void setSize(const QSize &size); + void setInvalidated(bool invalidated=true); + void setDevicePixelRatio(double ratio); + + // introduced virtual methods: + virtual QCPPainter *startPainting() = 0; + virtual void donePainting() {} + virtual void draw(QCPPainter *painter) const = 0; + virtual void clear(const QColor &color) = 0; + +protected: + // property members: + QSize mSize; + double mDevicePixelRatio; + + // non-property members: + bool mInvalidated; + + // introduced virtual methods: + virtual void reallocateBuffer() = 0; +}; + + +class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio); + virtual ~QCPPaintBufferPixmap(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QPixmap mBuffer; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; + + +#ifdef QCP_OPENGL_PBUFFER +class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples); + virtual ~QCPPaintBufferGlPbuffer(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QGLPixelBuffer *mGlPBuffer; + int mMultisamples; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice); + virtual ~QCPPaintBufferGlFbo(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void donePainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QWeakPointer mGlContext; + QWeakPointer mGlPaintDevice; + QOpenGLFramebufferObject *mGlFrameBuffer; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; +#endif // QCP_OPENGL_FBO + +/* end of 'src/paintbuffer.h' */ + + +/* including file 'src/layer.h', size 6885 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPLayer : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) + Q_PROPERTY(QString name READ name) + Q_PROPERTY(int index READ index) + Q_PROPERTY(QList children READ children) + Q_PROPERTY(bool visible READ visible WRITE setVisible) + Q_PROPERTY(LayerMode mode READ mode WRITE setMode) + /// \endcond +public: + + /*! + Defines the different rendering modes of a layer. Depending on the mode, certain layers can be + replotted individually, without the need to replot (possibly complex) layerables on other + layers. + + \see setMode + */ + enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. + ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). + }; + Q_ENUMS(LayerMode) + + QCPLayer(QCustomPlot* parentPlot, const QString &layerName); + virtual ~QCPLayer(); + + // getters: + QCustomPlot *parentPlot() const { return mParentPlot; } + QString name() const { return mName; } + int index() const { return mIndex; } + QList children() const { return mChildren; } + bool visible() const { return mVisible; } + LayerMode mode() const { return mMode; } + + // setters: + void setVisible(bool visible); + void setMode(LayerMode mode); + + // non-virtual methods: + void replot(); + +protected: + // property members: + QCustomPlot *mParentPlot; + QString mName; + int mIndex; + QList mChildren; + bool mVisible; + LayerMode mMode; + + // non-property members: + QWeakPointer mPaintBuffer; + + // non-virtual methods: + void draw(QCPPainter *painter); + void drawToPaintBuffer(); + void addChild(QCPLayerable *layerable, bool prepend); + void removeChild(QCPLayerable *layerable); + +private: + Q_DISABLE_COPY(QCPLayer) + + friend class QCustomPlot; + friend class QCPLayerable; +}; +Q_DECLARE_METATYPE(QCPLayer::LayerMode) + +class QCP_LIB_DECL QCPLayerable : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool visible READ visible WRITE setVisible) + Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) + Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) + Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) + Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) + /// \endcond +public: + QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0); + virtual ~QCPLayerable(); + + // getters: + bool visible() const { return mVisible; } + QCustomPlot *parentPlot() const { return mParentPlot; } + QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } + QCPLayer *layer() const { return mLayer; } + bool antialiased() const { return mAntialiased; } + + // setters: + void setVisible(bool on); + Q_SLOT bool setLayer(QCPLayer *layer); + bool setLayer(const QString &layerName); + void setAntialiased(bool enabled); + + // introduced virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; + + // non-property methods: + bool realVisibility() const; + +signals: + void layerChanged(QCPLayer *newLayer); + +protected: + // property members: + bool mVisible; + QCustomPlot *mParentPlot; + QPointer mParentLayerable; + QCPLayer *mLayer; + bool mAntialiased; + + // introduced virtual methods: + virtual void parentPlotInitialized(QCustomPlot *parentPlot); + virtual QCP::Interaction selectionCategory() const; + virtual QRect clipRect() const; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; + virtual void draw(QCPPainter *painter) = 0; + // selection events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); + virtual void deselectEvent(bool *selectionStateChanged); + // low-level mouse events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details); + virtual void wheelEvent(QWheelEvent *event); + + // non-property methods: + void initializeParentPlot(QCustomPlot *parentPlot); + void setParentLayerable(QCPLayerable* parentLayerable); + bool moveToLayer(QCPLayer *layer, bool prepend); + void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; + +private: + Q_DISABLE_COPY(QCPLayerable) + + friend class QCustomPlot; + friend class QCPLayer; + friend class QCPAxisRect; +}; + +/* end of 'src/layer.h' */ + + +/* including file 'src/axis/range.h', size 5280 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPRange +{ +public: + double lower, upper; + + QCPRange(); + QCPRange(double lower, double upper); + + bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; } + bool operator!=(const QCPRange& other) const { return !(*this == other); } + + QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } + QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } + QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } + QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } + friend inline const QCPRange operator+(const QCPRange&, double); + friend inline const QCPRange operator+(double, const QCPRange&); + friend inline const QCPRange operator-(const QCPRange& range, double value); + friend inline const QCPRange operator*(const QCPRange& range, double value); + friend inline const QCPRange operator*(double value, const QCPRange& range); + friend inline const QCPRange operator/(const QCPRange& range, double value); + + double size() const { return upper-lower; } + double center() const { return (upper+lower)*0.5; } + void normalize() { if (lower > upper) qSwap(lower, upper); } + void expand(const QCPRange &otherRange); + void expand(double includeCoord); + QCPRange expanded(const QCPRange &otherRange) const; + QCPRange expanded(double includeCoord) const; + QCPRange bounded(double lowerBound, double upperBound) const; + QCPRange sanitizedForLogScale() const; + QCPRange sanitizedForLinScale() const; + bool contains(double value) const { return value >= lower && value <= upper; } + + static bool validRange(double lower, double upper); + static bool validRange(const QCPRange &range); + static const double minRange; + static const double maxRange; + +}; +Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); + +/*! \relates QCPRange + + Prints \a range in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPRange &range) +{ + d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; + return d.space(); +} + +/*! + Adds \a value to both boundaries of the range. +*/ +inline const QCPRange operator+(const QCPRange& range, double value) +{ + QCPRange result(range); + result += value; + return result; +} + +/*! + Adds \a value to both boundaries of the range. +*/ +inline const QCPRange operator+(double value, const QCPRange& range) +{ + QCPRange result(range); + result += value; + return result; +} + +/*! + Subtracts \a value from both boundaries of the range. +*/ +inline const QCPRange operator-(const QCPRange& range, double value) +{ + QCPRange result(range); + result -= value; + return result; +} + +/*! + Multiplies both boundaries of the range by \a value. +*/ +inline const QCPRange operator*(const QCPRange& range, double value) +{ + QCPRange result(range); + result *= value; + return result; +} + +/*! + Multiplies both boundaries of the range by \a value. +*/ +inline const QCPRange operator*(double value, const QCPRange& range) +{ + QCPRange result(range); + result *= value; + return result; +} + +/*! + Divides both boundaries of the range by \a value. +*/ +inline const QCPRange operator/(const QCPRange& range, double value) +{ + QCPRange result(range); + result /= value; + return result; +} + +/* end of 'src/axis/range.h' */ + + +/* including file 'src/selection.h', size 8579 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPDataRange +{ +public: + QCPDataRange(); + QCPDataRange(int begin, int end); + + bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; } + bool operator!=(const QCPDataRange& other) const { return !(*this == other); } + + // getters: + int begin() const { return mBegin; } + int end() const { return mEnd; } + int size() const { return mEnd-mBegin; } + int length() const { return size(); } + + // setters: + void setBegin(int begin) { mBegin = begin; } + void setEnd(int end) { mEnd = end; } + + // non-property methods: + bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); } + bool isEmpty() const { return length() == 0; } + QCPDataRange bounded(const QCPDataRange &other) const; + QCPDataRange expanded(const QCPDataRange &other) const; + QCPDataRange intersection(const QCPDataRange &other) const; + QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); } + bool intersects(const QCPDataRange &other) const; + bool contains(const QCPDataRange &other) const; + +private: + // property members: + int mBegin, mEnd; + +}; +Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE); + + +class QCP_LIB_DECL QCPDataSelection +{ +public: + explicit QCPDataSelection(); + explicit QCPDataSelection(const QCPDataRange &range); + + bool operator==(const QCPDataSelection& other) const; + bool operator!=(const QCPDataSelection& other) const { return !(*this == other); } + QCPDataSelection &operator+=(const QCPDataSelection& other); + QCPDataSelection &operator+=(const QCPDataRange& other); + QCPDataSelection &operator-=(const QCPDataSelection& other); + QCPDataSelection &operator-=(const QCPDataRange& other); + friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b); + + // getters: + int dataRangeCount() const { return mDataRanges.size(); } + int dataPointCount() const; + QCPDataRange dataRange(int index=0) const; + QList dataRanges() const { return mDataRanges; } + QCPDataRange span() const; + + // non-property methods: + void addDataRange(const QCPDataRange &dataRange, bool simplify=true); + void clear(); + bool isEmpty() const { return mDataRanges.isEmpty(); } + void simplify(); + void enforceType(QCP::SelectionType type); + bool contains(const QCPDataSelection &other) const; + QCPDataSelection intersection(const QCPDataRange &other) const; + QCPDataSelection intersection(const QCPDataSelection &other) const; + QCPDataSelection inverse(const QCPDataRange &outerRange) const; + +private: + // property members: + QList mDataRanges; + + inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); } +}; +Q_DECLARE_METATYPE(QCPDataSelection) + + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! \relates QCPDataRange + + Prints \a dataRange in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) +{ + d.nospace() << "[" << dataRange.begin() << ".." << dataRange.end()-1 << "]"; + return d.space(); +} + +/*! \relates QCPDataSelection + + Prints \a selection in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPDataSelection &selection) +{ + d.nospace() << "QCPDataSelection("; + for (int i=0; i elements(QCP::MarginSide side) const { return mChildren.value(side); } + bool isEmpty() const; + void clear(); + +protected: + // non-property members: + QCustomPlot *mParentPlot; + QHash > mChildren; + + // introduced virtual methods: + virtual int commonMargin(QCP::MarginSide side) const; + + // non-virtual methods: + void addChild(QCP::MarginSide side, QCPLayoutElement *element); + void removeChild(QCP::MarginSide side, QCPLayoutElement *element); + +private: + Q_DISABLE_COPY(QCPMarginGroup) + + friend class QCPLayoutElement; +}; + + +class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPLayout* layout READ layout) + Q_PROPERTY(QRect rect READ rect) + Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) + Q_PROPERTY(QMargins margins READ margins WRITE setMargins) + Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) + Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) + Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) + Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect) + /// \endcond +public: + /*! + Defines the phases of the update process, that happens just before a replot. At each phase, + \ref update is called with the according UpdatePhase value. + */ + enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout + ,upMargins ///< Phase in which the margins are calculated and set + ,upLayout ///< Final phase in which the layout system places the rects of the elements + }; + Q_ENUMS(UpdatePhase) + + /*! + Defines to which rect of a layout element the size constraints that can be set via \ref + setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the + margins (e.g. in the case of a QCPAxisRect the axis labels), whereas the inner rect (\ref rect) + does not. + + \see setSizeConstraintRect + */ + enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect + , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins + }; + Q_ENUMS(SizeConstraintRect) + + explicit QCPLayoutElement(QCustomPlot *parentPlot=0); + virtual ~QCPLayoutElement(); + + // getters: + QCPLayout *layout() const { return mParentLayout; } + QRect rect() const { return mRect; } + QRect outerRect() const { return mOuterRect; } + QMargins margins() const { return mMargins; } + QMargins minimumMargins() const { return mMinimumMargins; } + QCP::MarginSides autoMargins() const { return mAutoMargins; } + QSize minimumSize() const { return mMinimumSize; } + QSize maximumSize() const { return mMaximumSize; } + SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; } + QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } + QHash marginGroups() const { return mMarginGroups; } + + // setters: + void setOuterRect(const QRect &rect); + void setMargins(const QMargins &margins); + void setMinimumMargins(const QMargins &margins); + void setAutoMargins(QCP::MarginSides sides); + void setMinimumSize(const QSize &size); + void setMinimumSize(int width, int height); + void setMaximumSize(const QSize &size); + void setMaximumSize(int width, int height); + void setSizeConstraintRect(SizeConstraintRect constraintRect); + void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); + + // introduced virtual methods: + virtual void update(UpdatePhase phase); + virtual QSize minimumOuterSizeHint() const; + virtual QSize maximumOuterSizeHint() const; + virtual QList elements(bool recursive) const; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + +protected: + // property members: + QCPLayout *mParentLayout; + QSize mMinimumSize, mMaximumSize; + SizeConstraintRect mSizeConstraintRect; + QRect mRect, mOuterRect; + QMargins mMargins, mMinimumMargins; + QCP::MarginSides mAutoMargins; + QHash mMarginGroups; + + // introduced virtual methods: + virtual int calculateAutoMargin(QCP::MarginSide side); + virtual void layoutChanged(); + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) } + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) } + virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPLayoutElement) + + friend class QCustomPlot; + friend class QCPLayout; + friend class QCPMarginGroup; +}; +Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase) + + +class QCP_LIB_DECL QCPLayout : public QCPLayoutElement +{ + Q_OBJECT +public: + explicit QCPLayout(); + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual int elementCount() const = 0; + virtual QCPLayoutElement* elementAt(int index) const = 0; + virtual QCPLayoutElement* takeAt(int index) = 0; + virtual bool take(QCPLayoutElement* element) = 0; + virtual void simplify(); + + // non-virtual methods: + bool removeAt(int index); + bool remove(QCPLayoutElement* element); + void clear(); + +protected: + // introduced virtual methods: + virtual void updateLayout(); + + // non-virtual methods: + void sizeConstraintsChanged() const; + void adoptElement(QCPLayoutElement *el); + void releaseElement(QCPLayoutElement *el); + QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const; + static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el); + static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el); + +private: + Q_DISABLE_COPY(QCPLayout) + friend class QCPLayoutElement; +}; + + +class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(int rowCount READ rowCount) + Q_PROPERTY(int columnCount READ columnCount) + Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) + Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder) + Q_PROPERTY(int wrap READ wrap WRITE setWrap) + /// \endcond +public: + + /*! + Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*). + The column/row at which wrapping into the next row/column occurs can be specified with \ref + setWrap. + + \see setFillOrder + */ + enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. + ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. + }; + Q_ENUMS(FillOrder) + + explicit QCPLayoutGrid(); + virtual ~QCPLayoutGrid(); + + // getters: + int rowCount() const { return mElements.size(); } + int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } + QList columnStretchFactors() const { return mColumnStretchFactors; } + QList rowStretchFactors() const { return mRowStretchFactors; } + int columnSpacing() const { return mColumnSpacing; } + int rowSpacing() const { return mRowSpacing; } + int wrap() const { return mWrap; } + FillOrder fillOrder() const { return mFillOrder; } + + // setters: + void setColumnStretchFactor(int column, double factor); + void setColumnStretchFactors(const QList &factors); + void setRowStretchFactor(int row, double factor); + void setRowStretchFactors(const QList &factors); + void setColumnSpacing(int pixels); + void setRowSpacing(int pixels); + void setWrap(int count); + void setFillOrder(FillOrder order, bool rearrange=true); + + // reimplemented virtual methods: + virtual void updateLayout() Q_DECL_OVERRIDE; + virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); } + virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; + virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + virtual void simplify() Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; + + // non-virtual methods: + QCPLayoutElement *element(int row, int column) const; + bool addElement(int row, int column, QCPLayoutElement *element); + bool addElement(QCPLayoutElement *element); + bool hasElement(int row, int column); + void expandTo(int newRowCount, int newColumnCount); + void insertRow(int newIndex); + void insertColumn(int newIndex); + int rowColToIndex(int row, int column) const; + void indexToRowCol(int index, int &row, int &column) const; + +protected: + // property members: + QList > mElements; + QList mColumnStretchFactors; + QList mRowStretchFactors; + int mColumnSpacing, mRowSpacing; + int mWrap; + FillOrder mFillOrder; + + // non-virtual methods: + void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; + void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; + +private: + Q_DISABLE_COPY(QCPLayoutGrid) +}; +Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) + + +class QCP_LIB_DECL QCPLayoutInset : public QCPLayout +{ + Q_OBJECT +public: + /*! + Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. + */ + enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect + ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment + }; + Q_ENUMS(InsetPlacement) + + explicit QCPLayoutInset(); + virtual ~QCPLayoutInset(); + + // getters: + InsetPlacement insetPlacement(int index) const; + Qt::Alignment insetAlignment(int index) const; + QRectF insetRect(int index) const; + + // setters: + void setInsetPlacement(int index, InsetPlacement placement); + void setInsetAlignment(int index, Qt::Alignment alignment); + void setInsetRect(int index, const QRectF &rect); + + // reimplemented virtual methods: + virtual void updateLayout() Q_DECL_OVERRIDE; + virtual int elementCount() const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; + virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; + virtual void simplify() Q_DECL_OVERRIDE {} + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void addElement(QCPLayoutElement *element, Qt::Alignment alignment); + void addElement(QCPLayoutElement *element, const QRectF &rect); + +protected: + // property members: + QList mElements; + QList mInsetPlacement; + QList mInsetAlignment; + QList mInsetRect; + +private: + Q_DISABLE_COPY(QCPLayoutInset) +}; +Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement) + +/* end of 'src/layout.h' */ + + +/* including file 'src/lineending.h', size 4426 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPLineEnding +{ + Q_GADGET +public: + /*! + Defines the type of ending decoration for line-like items, e.g. an arrow. + + \image html QCPLineEnding.png + + The width and length of these decorations can be controlled with the functions \ref setWidth + and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only + support a width, the length property is ignored. + + \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding + */ + enum EndingStyle { esNone ///< No ending decoration + ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) + ,esSpikeArrow ///< A filled arrow head with an indented back + ,esLineArrow ///< A non-filled arrow head with open back + ,esDisc ///< A filled circle + ,esSquare ///< A filled square + ,esDiamond ///< A filled diamond (45 degrees rotated square) + ,esBar ///< A bar perpendicular to the line + ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) + ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) + }; + Q_ENUMS(EndingStyle) + + QCPLineEnding(); + QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); + + // getters: + EndingStyle style() const { return mStyle; } + double width() const { return mWidth; } + double length() const { return mLength; } + bool inverted() const { return mInverted; } + + // setters: + void setStyle(EndingStyle style); + void setWidth(double width); + void setLength(double length); + void setInverted(bool inverted); + + // non-property methods: + double boundingDistance() const; + double realLength() const; + void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const; + void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const; + +protected: + // property members: + EndingStyle mStyle; + double mWidth, mLength; + bool mInverted; +}; +Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle) + +/* end of 'src/lineending.h' */ + + +/* including file 'src/axis/axisticker.h', size 4177 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines the strategies that the axis ticker may follow when choosing the size of the tick step. + + \see setTickStepStrategy + */ + enum TickStepStrategy + { + tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) + ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count + }; + Q_ENUMS(TickStepStrategy) + + QCPAxisTicker(); + virtual ~QCPAxisTicker(); + + // getters: + TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; } + int tickCount() const { return mTickCount; } + double tickOrigin() const { return mTickOrigin; } + + // setters: + void setTickStepStrategy(TickStepStrategy strategy); + void setTickCount(int count); + void setTickOrigin(double origin); + + // introduced virtual methods: + virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels); + +protected: + // property members: + TickStepStrategy mTickStepStrategy; + int mTickCount; + double mTickOrigin; + + // introduced virtual methods: + virtual double getTickStep(const QCPRange &range); + virtual int getSubTickCount(double tickStep); + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision); + virtual QVector createTickVector(double tickStep, const QCPRange &range); + virtual QVector createSubTickVector(int subTickCount, const QVector &ticks); + virtual QVector createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision); + + // non-virtual methods: + void trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const; + double pickClosest(double target, const QVector &candidates) const; + double getMantissa(double input, double *magnitude=0) const; + double cleanMantissa(double input) const; +}; +Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy) +Q_DECLARE_METATYPE(QSharedPointer) + +/* end of 'src/axis/axisticker.h' */ + + +/* including file 'src/axis/axistickerdatetime.h', size 3289 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker +{ +public: + QCPAxisTickerDateTime(); + + // getters: + QString dateTimeFormat() const { return mDateTimeFormat; } + Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } + + // setters: + void setDateTimeFormat(const QString &format); + void setDateTimeSpec(Qt::TimeSpec spec); + void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) + void setTickOrigin(const QDateTime &origin); + + // static methods: + static QDateTime keyToDateTime(double key); + static double dateTimeToKey(const QDateTime dateTime); + static double dateTimeToKey(const QDate date); + +protected: + // property members: + QString mDateTimeFormat; + Qt::TimeSpec mDateTimeSpec; + + // non-property members: + enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; +}; + +/* end of 'src/axis/axistickerdatetime.h' */ + + +/* including file 'src/axis/axistickertime.h', size 3542 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines the logical units in which fractions of time spans can be expressed. + + \see setFieldWidth, setTimeFormat + */ + enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) + ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat) + ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat) + ,tuHours ///< Hours (%%h in \ref setTimeFormat) + ,tuDays ///< Days (%%d in \ref setTimeFormat) + }; + Q_ENUMS(TimeUnit) + + QCPAxisTickerTime(); + + // getters: + QString timeFormat() const { return mTimeFormat; } + int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); } + + // setters: + void setTimeFormat(const QString &format); + void setFieldWidth(TimeUnit unit, int width); + +protected: + // property members: + QString mTimeFormat; + QHash mFieldWidth; + + // non-property members: + TimeUnit mSmallestUnit, mBiggestUnit; + QHash mFormatPattern; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + + // non-virtual methods: + void replaceUnit(QString &text, TimeUnit unit, int value) const; +}; +Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit) + +/* end of 'src/axis/axistickertime.h' */ + + +/* including file 'src/axis/axistickerfixed.h', size 3308 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines how the axis ticker may modify the specified tick step (\ref setTickStep) in order to + control the number of ticks in the axis range. + + \see setScaleStrategy + */ + enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. + ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. + ,ssPowers ///< An integer power of the specified tick step is allowed. + }; + Q_ENUMS(ScaleStrategy) + + QCPAxisTickerFixed(); + + // getters: + double tickStep() const { return mTickStep; } + ScaleStrategy scaleStrategy() const { return mScaleStrategy; } + + // setters: + void setTickStep(double step); + void setScaleStrategy(ScaleStrategy strategy); + +protected: + // property members: + double mTickStep; + ScaleStrategy mScaleStrategy; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; +}; +Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy) + +/* end of 'src/axis/axistickerfixed.h' */ + + +/* including file 'src/axis/axistickertext.h', size 3085 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker +{ +public: + QCPAxisTickerText(); + + // getters: + QMap &ticks() { return mTicks; } + int subTickCount() const { return mSubTickCount; } + + // setters: + void setTicks(const QMap &ticks); + void setTicks(const QVector &positions, const QVector labels); + void setSubTickCount(int subTicks); + + // non-virtual methods: + void clear(); + void addTick(double position, QString label); + void addTicks(const QMap &ticks); + void addTicks(const QVector &positions, const QVector &labels); + +protected: + // property members: + QMap mTicks; + int mSubTickCount; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; + +}; + +/* end of 'src/axis/axistickertext.h' */ + + +/* including file 'src/axis/axistickerpi.h', size 3911 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines how fractions should be displayed in tick labels. + + \see setFractionStyle + */ + enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". + ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" + ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. + }; + Q_ENUMS(FractionStyle) + + QCPAxisTickerPi(); + + // getters: + QString piSymbol() const { return mPiSymbol; } + double piValue() const { return mPiValue; } + bool periodicity() const { return mPeriodicity; } + FractionStyle fractionStyle() const { return mFractionStyle; } + + // setters: + void setPiSymbol(QString symbol); + void setPiValue(double pi); + void setPeriodicity(int multiplesOfPi); + void setFractionStyle(FractionStyle style); + +protected: + // property members: + QString mPiSymbol; + double mPiValue; + int mPeriodicity; + FractionStyle mFractionStyle; + + // non-property members: + double mPiTickStep; // size of one tick step in units of mPiValue + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + + // non-virtual methods: + void simplifyFraction(int &numerator, int &denominator) const; + QString fractionToString(int numerator, int denominator) const; + QString unicodeFraction(int numerator, int denominator) const; + QString unicodeSuperscript(int number) const; + QString unicodeSubscript(int number) const; +}; +Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle) + +/* end of 'src/axis/axistickerpi.h' */ + + +/* including file 'src/axis/axistickerlog.h', size 2663 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker +{ +public: + QCPAxisTickerLog(); + + // getters: + double logBase() const { return mLogBase; } + int subTickCount() const { return mSubTickCount; } + + // setters: + void setLogBase(double base); + void setSubTickCount(int subTicks); + +protected: + // property members: + double mLogBase; + int mSubTickCount; + + // non-property members: + double mLogBaseLnInv; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; +}; + +/* end of 'src/axis/axistickerlog.h' */ + + +/* including file 'src/axis/axis.h', size 20634 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPGrid :public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) + Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) + Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) + Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) + /// \endcond +public: + explicit QCPGrid(QCPAxis *parentAxis); + + // getters: + bool subGridVisible() const { return mSubGridVisible; } + bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } + bool antialiasedZeroLine() const { return mAntialiasedZeroLine; } + QPen pen() const { return mPen; } + QPen subGridPen() const { return mSubGridPen; } + QPen zeroLinePen() const { return mZeroLinePen; } + + // setters: + void setSubGridVisible(bool visible); + void setAntialiasedSubGrid(bool enabled); + void setAntialiasedZeroLine(bool enabled); + void setPen(const QPen &pen); + void setSubGridPen(const QPen &pen); + void setZeroLinePen(const QPen &pen); + +protected: + // property members: + bool mSubGridVisible; + bool mAntialiasedSubGrid, mAntialiasedZeroLine; + QPen mPen, mSubGridPen, mZeroLinePen; + + // non-property members: + QCPAxis *mParentAxis; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + void drawGridLines(QCPPainter *painter) const; + void drawSubGridLines(QCPPainter *painter) const; + + friend class QCPAxis; +}; + + +class QCP_LIB_DECL QCPAxis : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(AxisType axisType READ axisType) + Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) + Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) + Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) + Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) + Q_PROPERTY(QSharedPointer ticker READ ticker WRITE setTicker) + Q_PROPERTY(bool ticks READ ticks WRITE setTicks) + Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) + Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) + Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) + Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) + Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) + Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide) + Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) + Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) + Q_PROPERTY(QVector tickVector READ tickVector) + Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels) + Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) + Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) + Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks) + Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) + Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) + Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) + Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) + Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) + Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) + Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) + Q_PROPERTY(QString label READ label WRITE setLabel) + Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) + Q_PROPERTY(int padding READ padding WRITE setPadding) + Q_PROPERTY(int offset READ offset WRITE setOffset) + Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) + Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) + Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) + Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) + Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) + Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) + Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) + Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) + Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) + Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) + Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) + Q_PROPERTY(QCPGrid* grid READ grid) + /// \endcond +public: + /*! + Defines at which side of the axis rect the axis will appear. This also affects how the tick + marks are drawn, on which side the labels are placed etc. + */ + enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect + ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect + ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect + ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect + }; + Q_ENUMS(AxisType) + Q_FLAGS(AxisTypes) + Q_DECLARE_FLAGS(AxisTypes, AxisType) + /*! + Defines on which side of the axis the tick labels (numbers) shall appear. + + \see setTickLabelSide + */ + enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect + ,lsOutside ///< Tick labels will be displayed outside the axis rect + }; + Q_ENUMS(LabelSide) + /*! + Defines the scale of an axis. + \see setScaleType + */ + enum ScaleType { stLinear ///< Linear scaling + ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). + }; + Q_ENUMS(ScaleType) + /*! + Defines the selectable parts of an axis. + \see setSelectableParts, setSelectedParts + */ + enum SelectablePart { spNone = 0 ///< None of the selectable parts + ,spAxis = 0x001 ///< The axis backbone and tick marks + ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) + ,spAxisLabel = 0x004 ///< The axis label + }; + Q_ENUMS(SelectablePart) + Q_FLAGS(SelectableParts) + Q_DECLARE_FLAGS(SelectableParts, SelectablePart) + + explicit QCPAxis(QCPAxisRect *parent, AxisType type); + virtual ~QCPAxis(); + + // getters: + AxisType axisType() const { return mAxisType; } + QCPAxisRect *axisRect() const { return mAxisRect; } + ScaleType scaleType() const { return mScaleType; } + const QCPRange range() const { return mRange; } + bool rangeReversed() const { return mRangeReversed; } + QSharedPointer ticker() const { return mTicker; } + bool ticks() const { return mTicks; } + bool tickLabels() const { return mTickLabels; } + int tickLabelPadding() const; + QFont tickLabelFont() const { return mTickLabelFont; } + QColor tickLabelColor() const { return mTickLabelColor; } + double tickLabelRotation() const; + LabelSide tickLabelSide() const; + QString numberFormat() const; + int numberPrecision() const { return mNumberPrecision; } + QVector tickVector() const { return mTickVector; } + QVector tickVectorLabels() const { return mTickVectorLabels; } + int tickLengthIn() const; + int tickLengthOut() const; + bool subTicks() const { return mSubTicks; } + int subTickLengthIn() const; + int subTickLengthOut() const; + QPen basePen() const { return mBasePen; } + QPen tickPen() const { return mTickPen; } + QPen subTickPen() const { return mSubTickPen; } + QFont labelFont() const { return mLabelFont; } + QColor labelColor() const { return mLabelColor; } + QString label() const { return mLabel; } + int labelPadding() const; + int padding() const { return mPadding; } + int offset() const; + SelectableParts selectedParts() const { return mSelectedParts; } + SelectableParts selectableParts() const { return mSelectableParts; } + QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; } + QFont selectedLabelFont() const { return mSelectedLabelFont; } + QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; } + QColor selectedLabelColor() const { return mSelectedLabelColor; } + QPen selectedBasePen() const { return mSelectedBasePen; } + QPen selectedTickPen() const { return mSelectedTickPen; } + QPen selectedSubTickPen() const { return mSelectedSubTickPen; } + QCPLineEnding lowerEnding() const; + QCPLineEnding upperEnding() const; + QCPGrid *grid() const { return mGrid; } + + // setters: + Q_SLOT void setScaleType(QCPAxis::ScaleType type); + Q_SLOT void setRange(const QCPRange &range); + void setRange(double lower, double upper); + void setRange(double position, double size, Qt::AlignmentFlag alignment); + void setRangeLower(double lower); + void setRangeUpper(double upper); + void setRangeReversed(bool reversed); + void setTicker(QSharedPointer ticker); + void setTicks(bool show); + void setTickLabels(bool show); + void setTickLabelPadding(int padding); + void setTickLabelFont(const QFont &font); + void setTickLabelColor(const QColor &color); + void setTickLabelRotation(double degrees); + void setTickLabelSide(LabelSide side); + void setNumberFormat(const QString &formatCode); + void setNumberPrecision(int precision); + void setTickLength(int inside, int outside=0); + void setTickLengthIn(int inside); + void setTickLengthOut(int outside); + void setSubTicks(bool show); + void setSubTickLength(int inside, int outside=0); + void setSubTickLengthIn(int inside); + void setSubTickLengthOut(int outside); + void setBasePen(const QPen &pen); + void setTickPen(const QPen &pen); + void setSubTickPen(const QPen &pen); + void setLabelFont(const QFont &font); + void setLabelColor(const QColor &color); + void setLabel(const QString &str); + void setLabelPadding(int padding); + void setPadding(int padding); + void setOffset(int offset); + void setSelectedTickLabelFont(const QFont &font); + void setSelectedLabelFont(const QFont &font); + void setSelectedTickLabelColor(const QColor &color); + void setSelectedLabelColor(const QColor &color); + void setSelectedBasePen(const QPen &pen); + void setSelectedTickPen(const QPen &pen); + void setSelectedSubTickPen(const QPen &pen); + Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); + void setLowerEnding(const QCPLineEnding &ending); + void setUpperEnding(const QCPLineEnding &ending); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-property methods: + Qt::Orientation orientation() const { return mOrientation; } + int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; } + void moveRange(double diff); + void scaleRange(double factor); + void scaleRange(double factor, double center); + void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); + void rescale(bool onlyVisiblePlottables=false); + double pixelToCoord(double value) const; + double coordToPixel(double value) const; + SelectablePart getPartAt(const QPointF &pos) const; + QList plottables() const; + QList graphs() const; + QList items() const; + + static AxisType marginSideToAxisType(QCP::MarginSide side); + static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } + static AxisType opposite(AxisType type); + +signals: + void rangeChanged(const QCPRange &newRange); + void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); + void scaleTypeChanged(QCPAxis::ScaleType scaleType); + void selectionChanged(const QCPAxis::SelectableParts &parts); + void selectableChanged(const QCPAxis::SelectableParts &parts); + +protected: + // property members: + // axis base: + AxisType mAxisType; + QCPAxisRect *mAxisRect; + //int mOffset; // in QCPAxisPainter + int mPadding; + Qt::Orientation mOrientation; + SelectableParts mSelectableParts, mSelectedParts; + QPen mBasePen, mSelectedBasePen; + //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter + // axis label: + //int mLabelPadding; // in QCPAxisPainter + QString mLabel; + QFont mLabelFont, mSelectedLabelFont; + QColor mLabelColor, mSelectedLabelColor; + // tick labels: + //int mTickLabelPadding; // in QCPAxisPainter + bool mTickLabels; + //double mTickLabelRotation; // in QCPAxisPainter + QFont mTickLabelFont, mSelectedTickLabelFont; + QColor mTickLabelColor, mSelectedTickLabelColor; + int mNumberPrecision; + QLatin1Char mNumberFormatChar; + bool mNumberBeautifulPowers; + //bool mNumberMultiplyCross; // QCPAxisPainter + // ticks and subticks: + bool mTicks; + bool mSubTicks; + //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter + QPen mTickPen, mSelectedTickPen; + QPen mSubTickPen, mSelectedSubTickPen; + // scale and range: + QCPRange mRange; + bool mRangeReversed; + ScaleType mScaleType; + + // non-property members: + QCPGrid *mGrid; + QCPAxisPainterPrivate *mAxisPainter; + QSharedPointer mTicker; + QVector mTickVector; + QVector mTickVectorLabels; + QVector mSubTickVector; + bool mCachedMarginValid; + int mCachedMargin; + bool mDragging; + QCPRange mDragStartRange; + QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; + + // introduced virtual methods: + virtual int calculateMargin(); + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + // mouse events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); + virtual void wheelEvent(QWheelEvent *event); + + // non-virtual methods: + void setupTickVectors(); + QPen getBasePen() const; + QPen getTickPen() const; + QPen getSubTickPen() const; + QFont getTickLabelFont() const; + QFont getLabelFont() const; + QColor getTickLabelColor() const; + QColor getLabelColor() const; + +private: + Q_DISABLE_COPY(QCPAxis) + + friend class QCustomPlot; + friend class QCPGrid; + friend class QCPAxisRect; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) +Q_DECLARE_METATYPE(QCPAxis::AxisType) +Q_DECLARE_METATYPE(QCPAxis::LabelSide) +Q_DECLARE_METATYPE(QCPAxis::ScaleType) +Q_DECLARE_METATYPE(QCPAxis::SelectablePart) + + +class QCPAxisPainterPrivate +{ +public: + explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); + virtual ~QCPAxisPainterPrivate(); + + virtual void draw(QCPPainter *painter); + virtual int size() const; + void clearCache(); + + QRect axisSelectionBox() const { return mAxisSelectionBox; } + QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } + QRect labelSelectionBox() const { return mLabelSelectionBox; } + + // public property members: + QCPAxis::AxisType type; + QPen basePen; + QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters + int labelPadding; // directly accessed by QCPAxis setters/getters + QFont labelFont; + QColor labelColor; + QString label; + int tickLabelPadding; // directly accessed by QCPAxis setters/getters + double tickLabelRotation; // directly accessed by QCPAxis setters/getters + QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters + bool substituteExponent; + bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters + int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters + QPen tickPen, subTickPen; + QFont tickLabelFont; + QColor tickLabelColor; + QRect axisRect, viewportRect; + double offset; // directly accessed by QCPAxis setters/getters + bool abbreviateDecimalPowers; + bool reversedEndings; + + QVector subTickPositions; + QVector tickPositions; + QVector tickLabels; + +protected: + struct CachedLabel + { + QPointF offset; + QPixmap pixmap; + }; + struct TickLabelData + { + QString basePart, expPart, suffixPart; + QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds; + QFont baseFont, expFont; + }; + QCustomPlot *mParentPlot; + QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters + QCache mLabelCache; + QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; + + virtual QByteArray generateLabelParameterHash() const; + + virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); + virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; + virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; + virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; + virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; +}; + +/* end of 'src/axis/axis.h' */ + + +/* including file 'src/scatterstyle.h', size 7275 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPScatterStyle +{ + Q_GADGET +public: + /*! + Represents the various properties of a scatter style instance. For example, this enum is used + to specify which properties of \ref QCPSelectionDecorator::setScatterStyle will be used when + highlighting selected data points. + + Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref + setFromOther. + */ + enum ScatterProperty { spNone = 0x00 ///< 0x00 None + ,spPen = 0x01 ///< 0x01 The pen property, see \ref setPen + ,spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush + ,spSize = 0x04 ///< 0x04 The size property, see \ref setSize + ,spShape = 0x08 ///< 0x08 The shape property, see \ref setShape + ,spAll = 0xFF ///< 0xFF All properties + }; + Q_ENUMS(ScatterProperty) + Q_FLAGS(ScatterProperties) + Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty) + + /*! + Defines the shape used for scatter points. + + On plottables/items that draw scatters, the sizes of these visualizations (with exception of + \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are + drawn with the pen and brush specified with \ref setPen and \ref setBrush. + */ + enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) + ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) + ,ssCross ///< \enumimage{ssCross.png} a cross + ,ssPlus ///< \enumimage{ssPlus.png} a plus + ,ssCircle ///< \enumimage{ssCircle.png} a circle + ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) + ,ssSquare ///< \enumimage{ssSquare.png} a square + ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond + ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus + ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline + ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner + ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside + ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside + ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside + ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside + ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines + ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates + ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) + }; + Q_ENUMS(ScatterShape) + + QCPScatterStyle(); + QCPScatterStyle(ScatterShape shape, double size=6); + QCPScatterStyle(ScatterShape shape, const QColor &color, double size); + QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); + QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); + QCPScatterStyle(const QPixmap &pixmap); + QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); + + // getters: + double size() const { return mSize; } + ScatterShape shape() const { return mShape; } + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QPixmap pixmap() const { return mPixmap; } + QPainterPath customPath() const { return mCustomPath; } + + // setters: + void setFromOther(const QCPScatterStyle &other, ScatterProperties properties); + void setSize(double size); + void setShape(ScatterShape shape); + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setPixmap(const QPixmap &pixmap); + void setCustomPath(const QPainterPath &customPath); + + // non-property methods: + bool isNone() const { return mShape == ssNone; } + bool isPenDefined() const { return mPenDefined; } + void undefinePen(); + void applyTo(QCPPainter *painter, const QPen &defaultPen) const; + void drawShape(QCPPainter *painter, const QPointF &pos) const; + void drawShape(QCPPainter *painter, double x, double y) const; + +protected: + // property members: + double mSize; + ScatterShape mShape; + QPen mPen; + QBrush mBrush; + QPixmap mPixmap; + QPainterPath mCustomPath; + + // non-property members: + bool mPenDefined; +}; +Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties) +Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty) +Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) + +/* end of 'src/scatterstyle.h' */ + + +/* including file 'src/datacontainer.h', size 4596 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +/*! \relates QCPDataContainer + Returns whether the sort key of \a a is less than the sort key of \a b. + + \see QCPDataContainer::sort +*/ +template +inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); } + +template +class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) +{ +public: + typedef typename QVector::const_iterator const_iterator; + typedef typename QVector::iterator iterator; + + QCPDataContainer(); + + // getters: + int size() const { return mData.size()-mPreallocSize; } + bool isEmpty() const { return size() == 0; } + bool autoSqueeze() const { return mAutoSqueeze; } + + // setters: + void setAutoSqueeze(bool enabled); + + // non-virtual methods: + void set(const QCPDataContainer &data); + void set(const QVector &data, bool alreadySorted=false); + void add(const QCPDataContainer &data); + void add(const QVector &data, bool alreadySorted=false); + void add(const DataType &data); + void removeBefore(double sortKey); + void removeAfter(double sortKey); + void remove(double sortKeyFrom, double sortKeyTo); + void remove(double sortKey); + void clear(); + void sort(); + void squeeze(bool preAllocation=true, bool postAllocation=true); + + const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; } + const_iterator constEnd() const { return mData.constEnd(); } + iterator begin() { return mData.begin()+mPreallocSize; } + iterator end() { return mData.end(); } + const_iterator findBegin(double sortKey, bool expandedRange=true) const; + const_iterator findEnd(double sortKey, bool expandedRange=true) const; + const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); } + QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth); + QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()); + QCPDataRange dataRange() const { return QCPDataRange(0, size()); } + void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const; + +protected: + // property members: + bool mAutoSqueeze; + + // non-property memebers: + QVector mData; + int mPreallocSize; + int mPreallocIteration; + + // non-virtual methods: + void preallocateGrow(int minimumPreallocSize); + void performAutoSqueeze(); +}; + +// include implementation in header since it is a class template: + +/* including file 'src/datacontainer.cpp', size 31349 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataContainer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataContainer + \brief The generic data container for one-dimensional plottables + + This class template provides a fast container for data storage of one-dimensional data. The data + type is specified as template parameter (called \a DataType in the following) and must provide + some methods as described in the \ref qcpdatacontainer-datatype "next section". + + The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well + as retrieval of ranges (see \ref findBegin, \ref findEnd, \ref keyRange) using binary search. The + container uses a preallocation and a postallocation scheme, such that appending and prepending + data (with respect to the sort key) is very fast and minimizes reallocations. If data is added + which needs to be inserted between existing keys, the merge usually can be done quickly too, + using the fact that existing data is always sorted. The user can further improve performance by + specifying that added data is already itself sorted by key, if he can guarantee that this is the + case (see for example \ref add(const QVector &data, bool alreadySorted)). + + The data can be accessed with the provided const iterators (\ref constBegin, \ref constEnd). If + it is necessary to alter existing data in-place, the non-const iterators can be used (\ref begin, + \ref end). Changing data members that are not the sort key (for most data types called \a key) is + safe from the container's perspective. + + Great care must be taken however if the sort key is modified through the non-const iterators. For + performance reasons, the iterators don't automatically cause a re-sorting upon their + manipulation. It is thus the responsibility of the user to leave the container in a sorted state + when finished with the data manipulation, before calling any other methods on the container. A + complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling \ref + sort. Failing to do so can not be detected by the container efficiently and will cause both + rendering artifacts and potential data loss. + + Implementing one-dimensional plottables that make use of a \ref QCPDataContainer is usually + done by subclassing from \ref QCPAbstractPlottable1D "QCPAbstractPlottable1D", which + introduces an according \a mDataContainer member and some convenience methods. + + \section qcpdatacontainer-datatype Requirements for the DataType template parameter + + The template parameter DataType is the type of the stored data points. It must be + trivially copyable and have the following public methods, preferably inline: + + \li double sortKey() const\n Returns the member variable of this data point that is the + sort key, defining the ordering in the container. Often this variable is simply called \a key. + + \li static DataType fromSortKey(double sortKey)\n Returns a new instance of the data + type initialized with its sort key set to \a sortKey. + + \li static bool sortKeyIsMainKey()\n Returns true if the sort key is equal to the main + key (see method \c mainKey below). For most plottables this is the case. It is not the case for + example for \ref QCPCurve, which uses \a t as sort key and \a key as main key. This is the reason + why QCPCurve unlike QCPGraph can display parametric curves with loops. + + \li double mainKey() const\n Returns the variable of this data point considered the main + key. This is commonly the variable that is used as the coordinate of this data point on the key + axis of the plottable. This method is used for example when determining the automatic axis + rescaling of key axes (\ref QCPAxis::rescale). + + \li double mainValue() const\n Returns the variable of this data point considered the + main value. This is commonly the variable that is used as the coordinate of this data point on + the value axis of the plottable. + + \li QCPRange valueRange() const\n Returns the range this data point spans in the value + axis coordinate. If the data is single-valued (e.g. QCPGraphData), this is simply a range with + both lower and upper set to the main data point value. However if the data points can represent + multiple values at once (e.g QCPFinancialData with its \a high, \a low, \a open and \a close + values at each \a key) this method should return the range those values span. This method is used + for example when determining the automatic axis rescaling of value axes (\ref + QCPAxis::rescale). +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataContainer::size() const + + Returns the number of data points in the container. +*/ + +/*! \fn bool QCPDataContainer::isEmpty() const + + Returns whether this container holds no data points. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constBegin() const + + Returns a const iterator to the first data point in this container. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constEnd() const + + Returns a const iterator to the element past the last data point in this container. +*/ + +/*! \fn QCPDataContainer::iterator QCPDataContainer::begin() const + + Returns a non-const iterator to the first data point in this container. + + You can manipulate the data points in-place through the non-const iterators, but great care must + be taken when manipulating the sort key of a data point, see \ref sort, or the detailed + description of this class. +*/ + +/*! \fn QCPDataContainer::iterator QCPDataContainer::end() const + + Returns a non-const iterator to the element past the last data point in this container. + + You can manipulate the data points in-place through the non-const iterators, but great care must + be taken when manipulating the sort key of a data point, see \ref sort, or the detailed + description of this class. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::at(int index) const + + Returns a const iterator to the element with the specified \a index. If \a index points beyond + the available elements in this container, returns \ref constEnd, i.e. an iterator past the last + valid element. + + You can use this method to easily obtain iterators from a \ref QCPDataRange, see the \ref + dataselection-accessing "data selection page" for an example. +*/ + +/*! \fn QCPDataRange QCPDataContainer::dataRange() const + + Returns a \ref QCPDataRange encompassing the entire data set of this container. This means the + begin index of the returned range is 0, and the end index is \ref size. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted + data +*/ +template +QCPDataContainer::QCPDataContainer() : + mAutoSqueeze(true), + mPreallocSize(0), + mPreallocIteration(0) +{ +} + +/*! + Sets whether the container automatically decides when to release memory from its post- and + preallocation pools when data points are removed. By default this is enabled and for typical + applications shouldn't be changed. + + If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with + \ref squeeze. +*/ +template +void QCPDataContainer::setAutoSqueeze(bool enabled) +{ + if (mAutoSqueeze != enabled) + { + mAutoSqueeze = enabled; + if (mAutoSqueeze) + performAutoSqueeze(); + } +} + +/*! \overload + + Replaces the current data in this container with the provided \a data. + + \see add, remove +*/ +template +void QCPDataContainer::set(const QCPDataContainer &data) +{ + clear(); + add(data); +} + +/*! \overload + + Replaces the current data in this container with the provided \a data + + If you can guarantee that the data points in \a data have ascending order with respect to the + DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. + + \see add, remove +*/ +template +void QCPDataContainer::set(const QVector &data, bool alreadySorted) +{ + mData = data; + mPreallocSize = 0; + mPreallocIteration = 0; + if (!alreadySorted) + sort(); +} + +/*! \overload + + Adds the provided \a data to the current data in this container. + + \see set, remove +*/ +template +void QCPDataContainer::add(const QCPDataContainer &data) +{ + if (data.isEmpty()) + return; + + const int n = data.size(); + const int oldSize = size(); + + if (oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones + { + if (mPreallocSize < n) + preallocateGrow(n); + mPreallocSize -= n; + std::copy(data.constBegin(), data.constEnd(), begin()); + } else // don't need to prepend, so append and merge if necessary + { + mData.resize(mData.size()+n); + std::copy(data.constBegin(), data.constEnd(), end()-n); + if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + } +} + +/*! + Adds the provided data points in \a data to the current data. + + If you can guarantee that the data points in \a data have ascending order with respect to the + DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. + + \see set, remove +*/ +template +void QCPDataContainer::add(const QVector &data, bool alreadySorted) +{ + if (data.isEmpty()) + return; + if (isEmpty()) + { + set(data, alreadySorted); + return; + } + + const int n = data.size(); + const int oldSize = size(); + + if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones + { + if (mPreallocSize < n) + preallocateGrow(n); + mPreallocSize -= n; + std::copy(data.constBegin(), data.constEnd(), begin()); + } else // don't need to prepend, so append and then sort and merge if necessary + { + mData.resize(mData.size()+n); + std::copy(data.constBegin(), data.constEnd(), end()-n); + if (!alreadySorted) // sort appended subrange if it wasn't already sorted + std::sort(end()-n, end(), qcpLessThanSortKey); + if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + } +} + +/*! \overload + + Adds the provided single data point to the current data. + + \see remove +*/ +template +void QCPDataContainer::add(const DataType &data) +{ + if (isEmpty() || !qcpLessThanSortKey(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones + { + mData.append(data); + } else if (qcpLessThanSortKey(data, *constBegin())) // quickly handle prepends using preallocated space + { + if (mPreallocSize < 1) + preallocateGrow(1); + --mPreallocSize; + *begin() = data; + } else // handle inserts, maintaining sorted keys + { + QCPDataContainer::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey); + mData.insert(insertionPoint, data); + } +} + +/*! + Removes all data points with (sort-)keys smaller than or equal to \a sortKey. + + \see removeAfter, remove, clear +*/ +template +void QCPDataContainer::removeBefore(double sortKey) +{ + QCPDataContainer::iterator it = begin(); + QCPDataContainer::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + mPreallocSize += itEnd-it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points with (sort-)keys greater than or equal to \a sortKey. + + \see removeBefore, remove, clear +*/ +template +void QCPDataContainer::removeAfter(double sortKey) +{ + QCPDataContainer::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + QCPDataContainer::iterator itEnd = end(); + mData.erase(it, itEnd); // typically adds it to the postallocated block + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points with (sort-)keys between \a sortKeyFrom and \a sortKeyTo. if \a + sortKeyFrom is greater or equal to \a sortKeyTo, the function does nothing. To remove a single + data point with known (sort-)key, use \ref remove(double sortKey). + + \see removeBefore, removeAfter, clear +*/ +template +void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) +{ + if (sortKeyFrom >= sortKeyTo || isEmpty()) + return; + + QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey); + QCPDataContainer::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey); + mData.erase(it, itEnd); + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! \overload + + Removes a single data point at \a sortKey. If the position is not known with absolute (binary) + precision, consider using \ref remove(double sortKeyFrom, double sortKeyTo) with a small + fuzziness interval around the suspected position, depeding on the precision with which the + (sort-)key is known. + + \see removeBefore, removeAfter, clear +*/ +template +void QCPDataContainer::remove(double sortKey) +{ + QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (it != end() && it->sortKey() == sortKey) + { + if (it == begin()) + ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + else + mData.erase(it); + } + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points. + + \see remove, removeAfter, removeBefore +*/ +template +void QCPDataContainer::clear() +{ + mData.clear(); + mPreallocIteration = 0; + mPreallocSize = 0; +} + +/*! + Re-sorts all data points in the container by their sort key. + + When setting, adding or removing points using the QCPDataContainer interface (\ref set, \ref add, + \ref remove, etc.), the container makes sure to always stay in a sorted state such that a full + resort is never necessary. However, if you choose to directly manipulate the sort key on data + points by accessing and modifying it through the non-const iterators (\ref begin, \ref end), it + is your responsibility to bring the container back into a sorted state before any other methods + are called on it. This can be achieved by calling this method immediately after finishing the + sort key manipulation. +*/ +template +void QCPDataContainer::sort() +{ + std::sort(begin(), end(), qcpLessThanSortKey); +} + +/*! + Frees all unused memory that is currently in the preallocation and postallocation pools. + + Note that QCPDataContainer automatically decides whether squeezing is necessary, if \ref + setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical + applications. + + The parameters \a preAllocation and \a postAllocation control whether pre- and/or post allocation + should be freed, respectively. +*/ +template +void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation) +{ + if (preAllocation) + { + if (mPreallocSize > 0) + { + std::copy(begin(), end(), mData.begin()); + mData.resize(size()); + mPreallocSize = 0; + } + mPreallocIteration = 0; + } + if (postAllocation) + mData.squeeze(); +} + +/*! + Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just + above \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be + considered, otherwise the one just above. + + This can be used in conjunction with \ref findEnd to iterate over data points within a given key + range, including or excluding the bounding data points that are just beyond the specified range. + + If \a expandedRange is true but there are no data points below \a sortKey, \ref constBegin is + returned. + + If the container is empty, returns \ref constEnd. + + \see findEnd, QCPPlottableInterface1D::findBegin +*/ +template +typename QCPDataContainer::const_iterator QCPDataContainer::findBegin(double sortKey, bool expandedRange) const +{ + if (isEmpty()) + return constEnd(); + + QCPDataContainer::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty + --it; + return it; +} + +/*! + Returns an iterator to the element after the data point with a (sort-)key that is equal to, just + above or just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey + will be considered, otherwise the one just below. + + This can be used in conjunction with \ref findBegin to iterate over data points within a given + key range, including the bounding data points that are just below and above the specified range. + + If \a expandedRange is true but there are no data points above \a sortKey, \ref constEnd is + returned. + + If the container is empty, \ref constEnd is returned. + + \see findBegin, QCPPlottableInterface1D::findEnd +*/ +template +typename QCPDataContainer::const_iterator QCPDataContainer::findEnd(double sortKey, bool expandedRange) const +{ + if (isEmpty()) + return constEnd(); + + QCPDataContainer::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (expandedRange && it != constEnd()) + ++it; + return it; +} + +/*! + Returns the range encompassed by the (main-)key coordinate of all data points. The output + parameter \a foundRange indicates whether a sensible range was found. If this is false, you + should not use the returned QCPRange (e.g. the data container is empty or all points have the + same key). + + Use \a signDomain to control which sign of the key coordinates should be considered. This is + relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a + time. + + If the DataType reports that its main key is equal to the sort key (\a sortKeyIsMainKey), as is + the case for most plottables, this method uses this fact and finds the range very quickly. + + \see valueRange +*/ +template +QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain signDomain) +{ + if (isEmpty()) + { + foundRange = false; + return QCPRange(); + } + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + double current; + + QCPDataContainer::const_iterator it = constBegin(); + QCPDataContainer::const_iterator itEnd = constEnd(); + if (signDomain == QCP::sdBoth) // range may be anywhere + { + if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value + { + while (it != itEnd) // find first non-nan going up from left + { + if (!qIsNaN(it->mainValue())) + { + range.lower = it->mainKey(); + haveLower = true; + break; + } + ++it; + } + it = itEnd; + while (it != constBegin()) // find first non-nan going down from right + { + --it; + if (!qIsNaN(it->mainValue())) + { + range.upper = it->mainKey(); + haveUpper = true; + break; + } + } + } else // DataType is not sorted by main key, go through all data points and accordingly expand range + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } + } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if ((current < range.lower || !haveLower) && current < 0) + { + range.lower = current; + haveLower = true; + } + if ((current > range.upper || !haveUpper) && current < 0) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if ((current < range.lower || !haveLower) && current > 0) + { + range.lower = current; + haveLower = true; + } + if ((current > range.upper || !haveUpper) && current > 0) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! + Returns the range encompassed by the value coordinates of the data points in the specified key + range (\a inKeyRange), using the full \a DataType::valueRange reported by the data points. The + output parameter \a foundRange indicates whether a sensible range was found. If this is false, + you should not use the returned QCPRange (e.g. the data container is empty or all points have the + same value). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Use \a signDomain to control which sign of the value coordinates should be considered. This is + relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a + time. + + \see keyRange +*/ +template +QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange) +{ + if (isEmpty()) + { + foundRange = false; + return QCPRange(); + } + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPRange current; + QCPDataContainer::const_iterator itBegin = constBegin(); + QCPDataContainer::const_iterator itEnd = constEnd(); + if (DataType::sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = findBegin(inKeyRange.lower); + itEnd = findEnd(inKeyRange.upper); + } + if (signDomain == QCP::sdBoth) // range may be anywhere + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! + Makes sure \a begin and \a end mark a data range that is both within the bounds of this data + container's data, as well as within the specified \a dataRange. The initial range described by + the passed iterators \a begin and \a end is never expanded, only contracted if necessary. + + This function doesn't require for \a dataRange to be within the bounds of this data container's + valid range. +*/ +template +void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const +{ + QCPDataRange iteratorRange(begin-constBegin(), end-constBegin()); + iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); + begin = constBegin()+iteratorRange.begin(); + end = constBegin()+iteratorRange.end(); +} + +/*! \internal + + Increases the preallocation pool to have a size of at least \a minimumPreallocSize. Depending on + the preallocation history, the container will grow by more than requested, to speed up future + consecutive size increases. + + if \a minimumPreallocSize is smaller than or equal to the current preallocation pool size, this + method does nothing. +*/ +template +void QCPDataContainer::preallocateGrow(int minimumPreallocSize) +{ + if (minimumPreallocSize <= mPreallocSize) + return; + + int newPreallocSize = minimumPreallocSize; + newPreallocSize += (1u< +void QCPDataContainer::performAutoSqueeze() +{ + const int totalAlloc = mData.capacity(); + const int postAllocSize = totalAlloc-mData.size(); + const int usedSize = size(); + bool shrinkPostAllocation = false; + bool shrinkPreAllocation = false; + if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size + { + shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! + shrinkPreAllocation = mPreallocSize*10 > usedSize; + } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother + { + shrinkPostAllocation = postAllocSize > usedSize*5; + shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller + } + + if (shrinkPreAllocation || shrinkPostAllocation) + squeeze(shrinkPreAllocation, shrinkPostAllocation); +} +/* end of 'src/datacontainer.cpp' */ + + +/* end of 'src/datacontainer.h' */ + + +/* including file 'src/plottable.h', size 8312 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPSelectionDecorator +{ + Q_GADGET +public: + QCPSelectionDecorator(); + virtual ~QCPSelectionDecorator(); + + // getters: + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; } + + // setters: + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen); + void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties); + + // non-virtual methods: + void applyPen(QCPPainter *painter) const; + void applyBrush(QCPPainter *painter) const; + QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const; + + // introduced virtual methods: + virtual void copyFrom(const QCPSelectionDecorator *other); + virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection); + +protected: + // property members: + QPen mPen; + QBrush mBrush; + QCPScatterStyle mScatterStyle; + QCPScatterStyle::ScatterProperties mUsedScatterProperties; + // non-property members: + QCPAbstractPlottable *mPlottable; + + // introduced virtual methods: + virtual bool registerWithPlottable(QCPAbstractPlottable *plottable); + +private: + Q_DISABLE_COPY(QCPSelectionDecorator) + friend class QCPAbstractPlottable; +}; +Q_DECLARE_METATYPE(QCPSelectionDecorator*) + + +class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) + Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) + Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) + Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged) + Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator) + /// \endcond +public: + QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPAbstractPlottable(); + + // getters: + QString name() const { return mName; } + bool antialiasedFill() const { return mAntialiasedFill; } + bool antialiasedScatters() const { return mAntialiasedScatters; } + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QCPAxis *keyAxis() const { return mKeyAxis.data(); } + QCPAxis *valueAxis() const { return mValueAxis.data(); } + QCP::SelectionType selectable() const { return mSelectable; } + bool selected() const { return !mSelection.isEmpty(); } + QCPDataSelection selection() const { return mSelection; } + QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; } + + // setters: + void setName(const QString &name); + void setAntialiasedFill(bool enabled); + void setAntialiasedScatters(bool enabled); + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setKeyAxis(QCPAxis *axis); + void setValueAxis(QCPAxis *axis); + Q_SLOT void setSelectable(QCP::SelectionType selectable); + Q_SLOT void setSelection(QCPDataSelection selection); + void setSelectionDecorator(QCPSelectionDecorator *decorator); + + // introduced virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; + virtual QCPPlottableInterface1D *interface1D() { return 0; } + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0; + + // non-property methods: + void coordsToPixels(double key, double value, double &x, double &y) const; + const QPointF coordsToPixels(double key, double value) const; + void pixelsToCoords(double x, double y, double &key, double &value) const; + void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; + void rescaleAxes(bool onlyEnlarge=false) const; + void rescaleKeyAxis(bool onlyEnlarge=false) const; + void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const; + bool addToLegend(QCPLegend *legend); + bool addToLegend(); + bool removeFromLegend(QCPLegend *legend) const; + bool removeFromLegend() const; + +signals: + void selectionChanged(bool selected); + void selectionChanged(const QCPDataSelection &selection); + void selectableChanged(QCP::SelectionType selectable); + +protected: + // property members: + QString mName; + bool mAntialiasedFill, mAntialiasedScatters; + QPen mPen; + QBrush mBrush; + QPointer mKeyAxis, mValueAxis; + QCP::SelectionType mSelectable; + QCPDataSelection mSelection; + QCPSelectionDecorator *mSelectionDecorator; + + // reimplemented virtual methods: + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; + + // non-virtual methods: + void applyFillAntialiasingHint(QCPPainter *painter) const; + void applyScattersAntialiasingHint(QCPPainter *painter) const; + +private: + Q_DISABLE_COPY(QCPAbstractPlottable) + + friend class QCustomPlot; + friend class QCPAxis; + friend class QCPPlottableLegendItem; +}; + + +/* end of 'src/plottable.h' */ + + +/* including file 'src/item.h', size 9384 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemAnchor +{ + Q_GADGET +public: + QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1); + virtual ~QCPItemAnchor(); + + // getters: + QString name() const { return mName; } + virtual QPointF pixelPosition() const; + +protected: + // property members: + QString mName; + + // non-property members: + QCustomPlot *mParentPlot; + QCPAbstractItem *mParentItem; + int mAnchorId; + QSet mChildrenX, mChildrenY; + + // introduced virtual methods: + virtual QCPItemPosition *toQCPItemPosition() { return 0; } + + // non-virtual methods: + void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent + void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted + void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent + void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted + +private: + Q_DISABLE_COPY(QCPItemAnchor) + + friend class QCPItemPosition; +}; + + + +class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor +{ + Q_GADGET +public: + /*! + Defines the ways an item position can be specified. Thus it defines what the numbers passed to + \ref setCoords actually mean. + + \see setType + */ + enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. + ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the viewport/widget, etc. + ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. + ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). + }; + Q_ENUMS(PositionType) + + QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name); + virtual ~QCPItemPosition(); + + // getters: + PositionType type() const { return typeX(); } + PositionType typeX() const { return mPositionTypeX; } + PositionType typeY() const { return mPositionTypeY; } + QCPItemAnchor *parentAnchor() const { return parentAnchorX(); } + QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; } + QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; } + double key() const { return mKey; } + double value() const { return mValue; } + QPointF coords() const { return QPointF(mKey, mValue); } + QCPAxis *keyAxis() const { return mKeyAxis.data(); } + QCPAxis *valueAxis() const { return mValueAxis.data(); } + QCPAxisRect *axisRect() const; + virtual QPointF pixelPosition() const Q_DECL_OVERRIDE; + + // setters: + void setType(PositionType type); + void setTypeX(PositionType type); + void setTypeY(PositionType type); + bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + void setCoords(double key, double value); + void setCoords(const QPointF &coords); + void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); + void setAxisRect(QCPAxisRect *axisRect); + void setPixelPosition(const QPointF &pixelPosition); + +protected: + // property members: + PositionType mPositionTypeX, mPositionTypeY; + QPointer mKeyAxis, mValueAxis; + QPointer mAxisRect; + double mKey, mValue; + QCPItemAnchor *mParentAnchorX, *mParentAnchorY; + + // reimplemented virtual methods: + virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } + +private: + Q_DISABLE_COPY(QCPItemPosition) + +}; +Q_DECLARE_METATYPE(QCPItemPosition::PositionType) + + +class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) + Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + /// \endcond +public: + explicit QCPAbstractItem(QCustomPlot *parentPlot); + virtual ~QCPAbstractItem(); + + // getters: + bool clipToAxisRect() const { return mClipToAxisRect; } + QCPAxisRect *clipAxisRect() const; + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setClipToAxisRect(bool clip); + void setClipAxisRect(QCPAxisRect *rect); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; + + // non-virtual methods: + QList positions() const { return mPositions; } + QList anchors() const { return mAnchors; } + QCPItemPosition *position(const QString &name) const; + QCPItemAnchor *anchor(const QString &name) const; + bool hasAnchor(const QString &name) const; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + +protected: + // property members: + bool mClipToAxisRect; + QPointer mClipAxisRect; + QList mPositions; + QList mAnchors; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual QPointF anchorPixelPosition(int anchorId) const; + + // non-virtual methods: + double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const; + QCPItemPosition *createPosition(const QString &name); + QCPItemAnchor *createAnchor(const QString &name, int anchorId); + +private: + Q_DISABLE_COPY(QCPAbstractItem) + + friend class QCustomPlot; + friend class QCPItemAnchor; +}; + +/* end of 'src/item.h' */ + + +/* including file 'src/core.h', size 14886 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCustomPlot : public QWidget +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) + Q_PROPERTY(QPixmap background READ background WRITE setBackground) + Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) + Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) + Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) + Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) + Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) + Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) + Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) + Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl) + /// \endcond +public: + /*! + Defines how a layer should be inserted relative to an other layer. + + \see addLayer, moveLayer + */ + enum LayerInsertMode { limBelow ///< Layer is inserted below other layer + ,limAbove ///< Layer is inserted above other layer + }; + Q_ENUMS(LayerInsertMode) + + /*! + Defines with what timing the QCustomPlot surface is refreshed after a replot. + + \see replot + */ + enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot + ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. + ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. + ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. + }; + Q_ENUMS(RefreshPriority) + + explicit QCustomPlot(QWidget *parent = 0); + virtual ~QCustomPlot(); + + // getters: + QRect viewport() const { return mViewport; } + double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; } + QPixmap background() const { return mBackgroundPixmap; } + bool backgroundScaled() const { return mBackgroundScaled; } + Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } + QCPLayoutGrid *plotLayout() const { return mPlotLayout; } + QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } + QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } + bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } + const QCP::Interactions interactions() const { return mInteractions; } + int selectionTolerance() const { return mSelectionTolerance; } + bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; } + QCP::PlottingHints plottingHints() const { return mPlottingHints; } + Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } + QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; } + QCPSelectionRect *selectionRect() const { return mSelectionRect; } + bool openGl() const { return mOpenGl; } + + // setters: + void setViewport(const QRect &rect); + void setBufferDevicePixelRatio(double ratio); + void setBackground(const QPixmap &pm); + void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); + void setBackground(const QBrush &brush); + void setBackgroundScaled(bool scaled); + void setBackgroundScaledMode(Qt::AspectRatioMode mode); + void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); + void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); + void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); + void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); + void setAutoAddPlottableToLegend(bool on); + void setInteractions(const QCP::Interactions &interactions); + void setInteraction(const QCP::Interaction &interaction, bool enabled=true); + void setSelectionTolerance(int pixels); + void setNoAntialiasingOnDrag(bool enabled); + void setPlottingHints(const QCP::PlottingHints &hints); + void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); + void setMultiSelectModifier(Qt::KeyboardModifier modifier); + void setSelectionRectMode(QCP::SelectionRectMode mode); + void setSelectionRect(QCPSelectionRect *selectionRect); + void setOpenGl(bool enabled, int multisampling=16); + + // non-property methods: + // plottable interface: + QCPAbstractPlottable *plottable(int index); + QCPAbstractPlottable *plottable(); + bool removePlottable(QCPAbstractPlottable *plottable); + bool removePlottable(int index); + int clearPlottables(); + int plottableCount() const; + QList selectedPlottables() const; + QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; + bool hasPlottable(QCPAbstractPlottable *plottable) const; + + // specialized interface for QCPGraph: + QCPGraph *graph(int index) const; + QCPGraph *graph() const; + QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); + bool removeGraph(QCPGraph *graph); + bool removeGraph(int index); + int clearGraphs(); + int graphCount() const; + QList selectedGraphs() const; + + // item interface: + QCPAbstractItem *item(int index) const; + QCPAbstractItem *item() const; + bool removeItem(QCPAbstractItem *item); + bool removeItem(int index); + int clearItems(); + int itemCount() const; + QList selectedItems() const; + QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; + bool hasItem(QCPAbstractItem *item) const; + + // layer interface: + QCPLayer *layer(const QString &name) const; + QCPLayer *layer(int index) const; + QCPLayer *currentLayer() const; + bool setCurrentLayer(const QString &name); + bool setCurrentLayer(QCPLayer *layer); + int layerCount() const; + bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); + bool removeLayer(QCPLayer *layer); + bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); + + // axis rect/layout interface: + int axisRectCount() const; + QCPAxisRect* axisRect(int index=0) const; + QList axisRects() const; + QCPLayoutElement* layoutElementAt(const QPointF &pos) const; + QCPAxisRect* axisRectAt(const QPointF &pos) const; + Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); + + QList selectedAxes() const; + QList selectedLegends() const; + Q_SLOT void deselectAll(); + + bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); + bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + QPixmap toPixmap(int width=0, int height=0, double scale=1.0); + void toPainter(QCPPainter *painter, int width=0, int height=0); + Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); + + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + QCPLegend *legend; + +signals: + void mouseDoubleClick(QMouseEvent *event); + void mousePress(QMouseEvent *event); + void mouseMove(QMouseEvent *event); + void mouseRelease(QMouseEvent *event); + void mouseWheel(QWheelEvent *event); + + void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); + void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); + void itemClick(QCPAbstractItem *item, QMouseEvent *event); + void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); + void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); + void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); + void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); + void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); + + void selectionChangedByUser(); + void beforeReplot(); + void afterReplot(); + +protected: + // property members: + QRect mViewport; + double mBufferDevicePixelRatio; + QCPLayoutGrid *mPlotLayout; + bool mAutoAddPlottableToLegend; + QList mPlottables; + QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph + QList mItems; + QList mLayers; + QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; + QCP::Interactions mInteractions; + int mSelectionTolerance; + bool mNoAntialiasingOnDrag; + QBrush mBackgroundBrush; + QPixmap mBackgroundPixmap; + QPixmap mScaledBackgroundPixmap; + bool mBackgroundScaled; + Qt::AspectRatioMode mBackgroundScaledMode; + QCPLayer *mCurrentLayer; + QCP::PlottingHints mPlottingHints; + Qt::KeyboardModifier mMultiSelectModifier; + QCP::SelectionRectMode mSelectionRectMode; + QCPSelectionRect *mSelectionRect; + bool mOpenGl; + + // non-property members: + QList > mPaintBuffers; + QPoint mMousePressPos; + bool mMouseHasMoved; + QPointer mMouseEventLayerable; + QPointer mMouseSignalLayerable; + QVariant mMouseEventLayerableDetails; + QVariant mMouseSignalLayerableDetails; + bool mReplotting; + bool mReplotQueued; + int mOpenGlMultisamples; + QCP::AntialiasedElements mOpenGlAntialiasedElementsBackup; + bool mOpenGlCacheLabelsBackup; +#ifdef QCP_OPENGL_FBO + QSharedPointer mGlContext; + QSharedPointer mGlSurface; + QSharedPointer mGlPaintDevice; +#endif + + // reimplemented virtual methods: + virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; + virtual QSize sizeHint() const Q_DECL_OVERRIDE; + virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void draw(QCPPainter *painter); + virtual void updateLayout(); + virtual void axisRemoved(QCPAxis *axis); + virtual void legendRemoved(QCPLegend *legend); + Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processPointSelection(QMouseEvent *event); + + // non-virtual methods: + bool registerPlottable(QCPAbstractPlottable *plottable); + bool registerGraph(QCPGraph *graph); + bool registerItem(QCPAbstractItem* item); + void updateLayerIndices() const; + QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; + QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=0) const; + void drawBackground(QCPPainter *painter); + void setupPaintBuffers(); + QCPAbstractPaintBuffer *createPaintBuffer(); + bool hasInvalidatedPaintBuffers(); + bool setupOpenGl(); + void freeOpenGl(); + + friend class QCPLegend; + friend class QCPAxis; + friend class QCPLayer; + friend class QCPAxisRect; + friend class QCPAbstractPlottable; + friend class QCPGraph; + friend class QCPAbstractItem; +}; +Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode) +Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority) + +/* end of 'src/core.h' */ + + +/* including file 'src/plottable1d.h', size 4544 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCPPlottableInterface1D +{ +public: + virtual ~QCPPlottableInterface1D() {} + // introduced pure virtual methods: + virtual int dataCount() const = 0; + virtual double dataMainKey(int index) const = 0; + virtual double dataSortKey(int index) const = 0; + virtual double dataMainValue(int index) const = 0; + virtual QCPRange dataValueRange(int index) const = 0; + virtual QPointF dataPixelPosition(int index) const = 0; + virtual bool sortKeyIsMainKey() const = 0; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; + virtual int findBegin(double sortKey, bool expandedRange=true) const = 0; + virtual int findEnd(double sortKey, bool expandedRange=true) const = 0; +}; + +template +class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) +{ + // No Q_OBJECT macro due to template class + +public: + QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPAbstractPlottable1D(); + + // virtual methods of 1d plottable interface: + virtual int dataCount() const Q_DECL_OVERRIDE; + virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; + virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; + virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } + +protected: + // property members: + QSharedPointer > mDataContainer; + + // helpers for subclasses: + void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; + void drawPolyline(QCPPainter *painter, const QVector &lineData) const; + +private: + Q_DISABLE_COPY(QCPAbstractPlottable1D) + +}; + +// include implementation in header since it is a class template: + +/* including file 'src/plottable1d.cpp', size 22240 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableInterface1D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableInterface1D + \brief Defines an abstract interface for one-dimensional plottables + + This class contains only pure virtual methods which define a common interface to the data + of one-dimensional plottables. + + For example, it is implemented by the template class \ref QCPAbstractPlottable1D (the preferred + base class for one-dimensional plottables). So if you use that template class as base class of + your one-dimensional plottable, you won't have to care about implementing the 1d interface + yourself. + + If your plottable doesn't derive from \ref QCPAbstractPlottable1D but still wants to provide a 1d + interface (e.g. like \ref QCPErrorBars does), you should inherit from both \ref + QCPAbstractPlottable and \ref QCPPlottableInterface1D and accordingly reimplement the pure + virtual methods of the 1d interface, matching your data container. Also, reimplement \ref + QCPAbstractPlottable::interface1D to return the \c this pointer. + + If you have a \ref QCPAbstractPlottable pointer, you can check whether it implements this + interface by calling \ref QCPAbstractPlottable::interface1D and testing it for a non-zero return + value. If it indeed implements this interface, you may use it to access the plottable's data + without needing to know the exact type of the plottable or its data point type. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPPlottableInterface1D::dataCount() const = 0; + + Returns the number of data points of the plottable. +*/ + +/*! \fn virtual QCPDataSelection QCPPlottableInterface1D::selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; + + Returns a data selection containing all the data points of this plottable which are contained (or + hit by) \a rect. This is used mainly in the selection rect interaction for data selection (\ref + dataselection "data selection mechanism"). + + If \a onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not + selectable (i.e. if \ref QCPAbstractPlottable::setSelectable is \ref QCP::stNone). + + \note \a rect must be a normalized rect (positive or zero width and height). This is especially + important when using the rect of \ref QCPSelectionRect::accepted, which is not necessarily + normalized. Use QRect::normalized() when passing a rect which might not be normalized. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataMainKey(int index) const = 0 + + Returns the main key of the data point at the given \a index. + + What the main key is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataSortKey(int index) const = 0 + + Returns the sort key of the data point at the given \a index. + + What the sort key is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataMainValue(int index) const = 0 + + Returns the main value of the data point at the given \a index. + + What the main value is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual QCPRange QCPPlottableInterface1D::dataValueRange(int index) const = 0 + + Returns the value range of the data point at the given \a index. + + What the value range is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual QPointF QCPPlottableInterface1D::dataPixelPosition(int index) const = 0 + + Returns the pixel position on the widget surface at which the data point at the given \a index + appears. + + Usually this corresponds to the point of \ref dataMainKey/\ref dataMainValue, in pixel + coordinates. However, depending on the plottable, this might be a different apparent position + than just a coord-to-pixel transform of those values. For example, \ref QCPBars apparent data + values can be shifted depending on their stacking, bar grouping or configured base value. +*/ + +/*! \fn virtual bool QCPPlottableInterface1D::sortKeyIsMainKey() const = 0 + + Returns whether the sort key (\ref dataSortKey) is identical to the main key (\ref dataMainKey). + + What the sort and main keys are, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual int QCPPlottableInterface1D::findBegin(double sortKey, bool expandedRange) const = 0 + + Returns the index of the data point with a (sort-)key that is equal to, just below, or just above + \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be considered, + otherwise the one just above. + + This can be used in conjunction with \ref findEnd to iterate over data points within a given key + range, including or excluding the bounding data points that are just beyond the specified range. + + If \a expandedRange is true but there are no data points below \a sortKey, 0 is returned. + + If the container is empty, returns 0 (in that case, \ref findEnd will also return 0, so a loop + using these methods will not iterate over the index 0). + + \see findEnd, QCPDataContainer::findBegin +*/ + +/*! \fn virtual int QCPPlottableInterface1D::findEnd(double sortKey, bool expandedRange) const = 0 + + Returns the index one after the data point with a (sort-)key that is equal to, just above, or + just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey will be + considered, otherwise the one just below. + + This can be used in conjunction with \ref findBegin to iterate over data points within a given + key range, including the bounding data points that are just below and above the specified range. + + If \a expandedRange is true but there are no data points above \a sortKey, the index just above the + highest data point is returned. + + If the container is empty, returns 0. + + \see findBegin, QCPDataContainer::findEnd +*/ + +/* end documentation of pure virtual functions */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable1D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable1D + \brief A template base class for plottables with one-dimensional data + + This template class derives from \ref QCPAbstractPlottable and from the abstract interface \ref + QCPPlottableInterface1D. It serves as a base class for all one-dimensional data (i.e. data with + one key dimension), such as \ref QCPGraph and QCPCurve. + + The template parameter \a DataType is the type of the data points of this plottable (e.g. \ref + QCPGraphData or \ref QCPCurveData). The main purpose of this base class is to provide the member + \a mDataContainer (a shared pointer to a \ref QCPDataContainer "QCPDataContainer") and + implement the according virtual methods of the \ref QCPPlottableInterface1D, such that most + subclassed plottables don't need to worry about this anymore. + + Further, it provides a convenience method for retrieving selected/unselected data segments via + \ref getDataSegments. This is useful when subclasses implement their \ref draw method and need to + draw selected segments with a different pen/brush than unselected segments (also see \ref + QCPSelectionDecorator). + + This class implements basic functionality of \ref QCPAbstractPlottable::selectTest and \ref + QCPPlottableInterface1D::selectTestRect, assuming point-like data points, based on the 1D data + interface. In spite of that, most plottable subclasses will want to reimplement those methods + again, to provide a more accurate hit test based on their specific data visualization geometry. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPPlottableInterface1D *QCPAbstractPlottable1D::interface1D() + + Returns a \ref QCPPlottableInterface1D pointer to this plottable, providing access to its 1D + interface. + + \seebaseclassmethod +*/ + +/* end documentation of inline functions */ + +/*! + Forwards \a keyAxis and \a valueAxis to the \ref QCPAbstractPlottable::QCPAbstractPlottable + "QCPAbstractPlottable" constructor and allocates the \a mDataContainer. +*/ +template +QCPAbstractPlottable1D::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QCPDataContainer) +{ +} + +template +QCPAbstractPlottable1D::~QCPAbstractPlottable1D() +{ +} + +/*! + \copydoc QCPPlottableInterface1D::dataCount +*/ +template +int QCPAbstractPlottable1D::dataCount() const +{ + return mDataContainer->size(); +} + +/*! + \copydoc QCPPlottableInterface1D::dataMainKey +*/ +template +double QCPAbstractPlottable1D::dataMainKey(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->mainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataSortKey +*/ +template +double QCPAbstractPlottable1D::dataSortKey(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->sortKey(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataMainValue +*/ +template +double QCPAbstractPlottable1D::dataMainValue(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->mainValue(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataValueRange +*/ +template +QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->valueRange(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QCPRange(0, 0); + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataPixelPosition +*/ +template +QPointF QCPAbstractPlottable1D::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + return coordsToPixels(it->mainKey(), it->mainValue()); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/*! + \copydoc QCPPlottableInterface1D::sortKeyIsMainKey +*/ +template +bool QCPAbstractPlottable1D::sortKeyIsMainKey() const +{ + return DataType::sortKeyIsMainKey(); +} + +/*! + Implements a rect-selection algorithm assuming the data (accessed via the 1D data interface) is + point-like. Most subclasses will want to reimplement this method again, to provide a more + accurate hit test based on the true data visualization geometry. + + \seebaseclassmethod +*/ +template +QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + // convert rect given in pixels to ranges given in plot coordinates: + double key1, value1, key2, value2; + pixelsToCoords(rect.topLeft(), key1, value1); + pixelsToCoords(rect.bottomRight(), key2, value2); + QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 + QCPRange valueRange(value1, value2); + typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); + typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); + if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + { + begin = mDataContainer->findBegin(keyRange.lower, false); + end = mDataContainer->findEnd(keyRange.upper, false); + } + if (begin == end) + return result; + + int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect + for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (currentSegmentBegin == -1) + { + if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment + currentSegmentBegin = it-mDataContainer->constBegin(); + } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended + { + result.addDataRange(QCPDataRange(currentSegmentBegin, it-mDataContainer->constBegin()), false); + currentSegmentBegin = -1; + } + } + // process potential last segment: + if (currentSegmentBegin != -1) + result.addDataRange(QCPDataRange(currentSegmentBegin, end-mDataContainer->constBegin()), false); + + result.simplify(); + return result; +} + +/*! + \copydoc QCPPlottableInterface1D::findBegin +*/ +template +int QCPAbstractPlottable1D::findBegin(double sortKey, bool expandedRange) const +{ + return mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin(); +} + +/*! + \copydoc QCPPlottableInterface1D::findEnd +*/ +template +int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange) const +{ + return mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin(); +} + +/*! + Implements a point-selection algorithm assuming the data (accessed via the 1D data interface) is + point-like. Most subclasses will want to reimplement this method again, to provide a more + accurate hit test based on the true data visualization geometry. + + \seebaseclassmethod +*/ +template +double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + QCPDataSelection selectionResult; + double minDistSqr = std::numeric_limits::max(); + int minDistIndex = mDataContainer->size(); + + typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); + typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); + if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + { + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + begin = mDataContainer->findBegin(posKeyMin, true); + end = mDataContainer->findEnd(posKeyMax, true); + } + if (begin == end) + return -1; + QCPRange keyRange(mKeyAxis->range()); + QCPRange valueRange(mValueAxis->range()); + for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double mainKey = it->mainKey(); + const double mainValue = it->mainValue(); + if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points + { + const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + minDistIndex = it-mDataContainer->constBegin(); + } + } + } + if (minDistIndex != mDataContainer->size()) + selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false); + + selectionResult.simplify(); + if (details) + details->setValue(selectionResult); + return qSqrt(minDistSqr); +} + +/*! + Splits all data into selected and unselected segments and outputs them via \a selectedSegments + and \a unselectedSegments, respectively. + + This is useful when subclasses implement their \ref draw method and need to draw selected + segments with a different pen/brush than unselected segments (also see \ref + QCPSelectionDecorator). + + \see setSelection +*/ +template +void QCPAbstractPlottable1D::getDataSegments(QList &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! + A helper method which draws a line with the passed \a painter, according to the pixel data in \a + lineData. NaN points create gaps in the line, as expected from QCustomPlot's plottables (this is + the main difference to QPainter's regular drawPolyline, which handles NaNs by lagging or + crashing). + + Further it uses a faster line drawing technique based on \ref QCPPainter::drawLine rather than \c + QPainter::drawPolyline if the configured \ref QCustomPlot::setPlottingHints() and \a painter + style allows. +*/ +template +void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const +{ + // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: + if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && + painter->pen().style() == Qt::SolidLine && + !painter->modes().testFlag(QCPPainter::pmVectorized) && + !painter->modes().testFlag(QCPPainter::pmNoCaching)) + { + int i = 0; + bool lastIsNan = false; + const int lineDataSize = lineData.size(); + while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN + ++i; + ++i; // because drawing works in 1 point retrospect + while (i < lineDataSize) + { + if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line + { + if (!lastIsNan) + painter->drawLine(lineData.at(i-1), lineData.at(i)); + else + lastIsNan = false; + } else + lastIsNan = true; + ++i; + } + } else + { + int segmentStart = 0; + int i = 0; + const int lineDataSize = lineData.size(); + while (i < lineDataSize) + { + if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block + { + painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point + segmentStart = i+1; + } + ++i; + } + // draw last segment: + painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart); + } +} +/* end of 'src/plottable1d.cpp' */ + + +/* end of 'src/plottable1d.h' */ + + +/* including file 'src/colorgradient.h', size 6243 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPColorGradient +{ + Q_GADGET +public: + /*! + Defines the color spaces in which color interpolation between gradient stops can be performed. + + \see setColorInterpolation + */ + enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated + ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) + }; + Q_ENUMS(ColorInterpolation) + + /*! + Defines the available presets that can be loaded with \ref loadPreset. See the documentation + there for an image of the presets. + */ + enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) + ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) + ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) + ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) + ,gpCandy ///< Blue over pink to white + ,gpGeography ///< Colors suitable to represent different elevations on geographical maps + ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) + ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white + ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values + ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) + ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) + ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) + }; + Q_ENUMS(GradientPreset) + + QCPColorGradient(); + QCPColorGradient(GradientPreset preset); + bool operator==(const QCPColorGradient &other) const; + bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } + + // getters: + int levelCount() const { return mLevelCount; } + QMap colorStops() const { return mColorStops; } + ColorInterpolation colorInterpolation() const { return mColorInterpolation; } + bool periodic() const { return mPeriodic; } + + // setters: + void setLevelCount(int n); + void setColorStops(const QMap &colorStops); + void setColorStopAt(double position, const QColor &color); + void setColorInterpolation(ColorInterpolation interpolation); + void setPeriodic(bool enabled); + + // non-property methods: + void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); + void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); + QRgb color(double position, const QCPRange &range, bool logarithmic=false); + void loadPreset(GradientPreset preset); + void clearColorStops(); + QCPColorGradient inverted() const; + +protected: + // property members: + int mLevelCount; + QMap mColorStops; + ColorInterpolation mColorInterpolation; + bool mPeriodic; + + // non-property members: + QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) + bool mColorBufferInvalidated; + + // non-virtual methods: + bool stopsUseAlpha() const; + void updateColorBuffer(); +}; +Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) +Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) + +/* end of 'src/colorgradient.h' */ + + +/* including file 'src/selectiondecorator-bracket.h', size 4442 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator +{ + Q_GADGET +public: + + /*! + Defines which shape is drawn at the boundaries of selected data ranges. + + Some of the bracket styles further allow specifying a height and/or width, see \ref + setBracketHeight and \ref setBracketWidth. + */ + enum BracketStyle { bsSquareBracket ///< A square bracket is drawn. + ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + ,bsPlus ///< A plus is drawn. + ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. + }; + Q_ENUMS(BracketStyle) + + QCPSelectionDecoratorBracket(); + virtual ~QCPSelectionDecoratorBracket(); + + // getters: + QPen bracketPen() const { return mBracketPen; } + QBrush bracketBrush() const { return mBracketBrush; } + int bracketWidth() const { return mBracketWidth; } + int bracketHeight() const { return mBracketHeight; } + BracketStyle bracketStyle() const { return mBracketStyle; } + bool tangentToData() const { return mTangentToData; } + int tangentAverage() const { return mTangentAverage; } + + // setters: + void setBracketPen(const QPen &pen); + void setBracketBrush(const QBrush &brush); + void setBracketWidth(int width); + void setBracketHeight(int height); + void setBracketStyle(BracketStyle style); + void setTangentToData(bool enabled); + void setTangentAverage(int pointCount); + + // introduced virtual methods: + virtual void drawBracket(QCPPainter *painter, int direction) const; + + // virtual methods: + virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE; + +protected: + // property members: + QPen mBracketPen; + QBrush mBracketBrush; + int mBracketWidth; + int mBracketHeight; + BracketStyle mBracketStyle; + bool mTangentToData; + int mTangentAverage; + + // non-virtual methods: + double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const; + QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const; + +}; +Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle) + +/* end of 'src/selectiondecorator-bracket.h' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.h', size 7507 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPixmap background READ background WRITE setBackground) + Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) + Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) + Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) + Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) + /// \endcond +public: + explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); + virtual ~QCPAxisRect(); + + // getters: + QPixmap background() const { return mBackgroundPixmap; } + QBrush backgroundBrush() const { return mBackgroundBrush; } + bool backgroundScaled() const { return mBackgroundScaled; } + Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } + Qt::Orientations rangeDrag() const { return mRangeDrag; } + Qt::Orientations rangeZoom() const { return mRangeZoom; } + QCPAxis *rangeDragAxis(Qt::Orientation orientation); + QCPAxis *rangeZoomAxis(Qt::Orientation orientation); + QList rangeDragAxes(Qt::Orientation orientation); + QList rangeZoomAxes(Qt::Orientation orientation); + double rangeZoomFactor(Qt::Orientation orientation); + + // setters: + void setBackground(const QPixmap &pm); + void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); + void setBackground(const QBrush &brush); + void setBackgroundScaled(bool scaled); + void setBackgroundScaledMode(Qt::AspectRatioMode mode); + void setRangeDrag(Qt::Orientations orientations); + void setRangeZoom(Qt::Orientations orientations); + void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); + void setRangeDragAxes(QList axes); + void setRangeDragAxes(QList horizontal, QList vertical); + void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); + void setRangeZoomAxes(QList axes); + void setRangeZoomAxes(QList horizontal, QList vertical); + void setRangeZoomFactor(double horizontalFactor, double verticalFactor); + void setRangeZoomFactor(double factor); + + // non-property methods: + int axisCount(QCPAxis::AxisType type) const; + QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; + QList axes(QCPAxis::AxisTypes types) const; + QList axes() const; + QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0); + QList addAxes(QCPAxis::AxisTypes types); + bool removeAxis(QCPAxis *axis); + QCPLayoutInset *insetLayout() const { return mInsetLayout; } + + void zoom(const QRectF &pixelRect); + void zoom(const QRectF &pixelRect, const QList &affectedAxes); + void setupFullAxesBox(bool connectRanges=false); + QList plottables() const; + QList graphs() const; + QList items() const; + + // read-only interface imitating a QRect: + int left() const { return mRect.left(); } + int right() const { return mRect.right(); } + int top() const { return mRect.top(); } + int bottom() const { return mRect.bottom(); } + int width() const { return mRect.width(); } + int height() const { return mRect.height(); } + QSize size() const { return mRect.size(); } + QPoint topLeft() const { return mRect.topLeft(); } + QPoint topRight() const { return mRect.topRight(); } + QPoint bottomLeft() const { return mRect.bottomLeft(); } + QPoint bottomRight() const { return mRect.bottomRight(); } + QPoint center() const { return mRect.center(); } + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + +protected: + // property members: + QBrush mBackgroundBrush; + QPixmap mBackgroundPixmap; + QPixmap mScaledBackgroundPixmap; + bool mBackgroundScaled; + Qt::AspectRatioMode mBackgroundScaledMode; + QCPLayoutInset *mInsetLayout; + Qt::Orientations mRangeDrag, mRangeZoom; + QList > mRangeDragHorzAxis, mRangeDragVertAxis; + QList > mRangeZoomHorzAxis, mRangeZoomVertAxis; + double mRangeZoomFactorHorz, mRangeZoomFactorVert; + + // non-property members: + QList mDragStartHorzRange, mDragStartVertRange; + QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; + bool mDragging; + QHash > mAxes; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE; + virtual void layoutChanged() Q_DECL_OVERRIDE; + // events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + + // non-property methods: + void drawBackground(QCPPainter *painter); + void updateAxesOffset(QCPAxis::AxisType type); + +private: + Q_DISABLE_COPY(QCPAxisRect) + + friend class QCustomPlot; +}; + + +/* end of 'src/layoutelements/layoutelement-axisrect.h' */ + + +/* including file 'src/layoutelements/layoutelement-legend.h', size 10397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) + /// \endcond +public: + explicit QCPAbstractLegendItem(QCPLegend *parent); + + // getters: + QCPLegend *parentLegend() const { return mParentLegend; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + +protected: + // property members: + QCPLegend *mParentLegend; + QFont mFont; + QColor mTextColor; + QFont mSelectedFont; + QColor mSelectedTextColor; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPAbstractLegendItem) + + friend class QCPLegend; +}; + + +class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem +{ + Q_OBJECT +public: + QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); + + // getters: + QCPAbstractPlottable *plottable() { return mPlottable; } + +protected: + // property members: + QCPAbstractPlottable *mPlottable; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen getIconBorderPen() const; + QColor getTextColor() const; + QFont getFont() const; +}; + + +class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) + Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) + Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) + Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) + Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) + Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) + Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + /// \endcond +public: + /*! + Defines the selectable parts of a legend + + \see setSelectedParts, setSelectableParts + */ + enum SelectablePart { spNone = 0x000 ///< 0x000 None + ,spLegendBox = 0x001 ///< 0x001 The legend box (frame) + ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) + }; + Q_ENUMS(SelectablePart) + Q_FLAGS(SelectableParts) + Q_DECLARE_FLAGS(SelectableParts, SelectablePart) + + explicit QCPLegend(); + virtual ~QCPLegend(); + + // getters: + QPen borderPen() const { return mBorderPen; } + QBrush brush() const { return mBrush; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QSize iconSize() const { return mIconSize; } + int iconTextPadding() const { return mIconTextPadding; } + QPen iconBorderPen() const { return mIconBorderPen; } + SelectableParts selectableParts() const { return mSelectableParts; } + SelectableParts selectedParts() const; + QPen selectedBorderPen() const { return mSelectedBorderPen; } + QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; } + QBrush selectedBrush() const { return mSelectedBrush; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + + // setters: + void setBorderPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setIconSize(const QSize &size); + void setIconSize(int width, int height); + void setIconTextPadding(int padding); + void setIconBorderPen(const QPen &pen); + Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); + void setSelectedBorderPen(const QPen &pen); + void setSelectedIconBorderPen(const QPen &pen); + void setSelectedBrush(const QBrush &brush); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QCPAbstractLegendItem *item(int index) const; + QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; + int itemCount() const; + bool hasItem(QCPAbstractLegendItem *item) const; + bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; + bool addItem(QCPAbstractLegendItem *item); + bool removeItem(int index); + bool removeItem(QCPAbstractLegendItem *item); + void clearItems(); + QList selectedItems() const; + +signals: + void selectionChanged(QCPLegend::SelectableParts parts); + void selectableChanged(QCPLegend::SelectableParts parts); + +protected: + // property members: + QPen mBorderPen, mIconBorderPen; + QBrush mBrush; + QFont mFont; + QColor mTextColor; + QSize mIconSize; + int mIconTextPadding; + SelectableParts mSelectedParts, mSelectableParts; + QPen mSelectedBorderPen, mSelectedIconBorderPen; + QBrush mSelectedBrush; + QFont mSelectedFont; + QColor mSelectedTextColor; + + // reimplemented virtual methods: + virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen getBorderPen() const; + QBrush getBrush() const; + +private: + Q_DISABLE_COPY(QCPLegend) + + friend class QCustomPlot; + friend class QCPAbstractLegendItem; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) +Q_DECLARE_METATYPE(QCPLegend::SelectablePart) + +/* end of 'src/layoutelements/layoutelement-legend.h' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.h', size 5353 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + /// \endcond +public: + explicit QCPTextElement(QCustomPlot *parentPlot); + QCPTextElement(QCustomPlot *parentPlot, const QString &text); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font); + + // getters: + QString text() const { return mText; } + int textFlags() const { return mTextFlags; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setText(const QString &text); + void setTextFlags(int flags); + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + void clicked(QMouseEvent *event); + void doubleClicked(QMouseEvent *event); + +protected: + // property members: + QString mText; + int mTextFlags; + QFont mFont; + QColor mTextColor; + QFont mSelectedFont; + QColor mSelectedTextColor; + QRect mTextBoundingRect; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // non-virtual methods: + QFont mainFont() const; + QColor mainTextColor() const; + +private: + Q_DISABLE_COPY(QCPTextElement) +}; + + + +/* end of 'src/layoutelements/layoutelement-textelement.h' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.h', size 5923 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +class QCPColorScaleAxisRectPrivate : public QCPAxisRect +{ + Q_OBJECT +public: + explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); +protected: + QCPColorScale *mParentColorScale; + QImage mGradientImage; + bool mGradientImageInvalidated; + // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale + using QCPAxisRect::calculateAutoMargin; + using QCPAxisRect::mousePressEvent; + using QCPAxisRect::mouseMoveEvent; + using QCPAxisRect::mouseReleaseEvent; + using QCPAxisRect::wheelEvent; + using QCPAxisRect::update; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + void updateGradientImage(); + Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); + Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); + friend class QCPColorScale; +}; + + +class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) + Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) + Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) + Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) + Q_PROPERTY(QString label READ label WRITE setLabel) + Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) + Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) + Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) + /// \endcond +public: + explicit QCPColorScale(QCustomPlot *parentPlot); + virtual ~QCPColorScale(); + + // getters: + QCPAxis *axis() const { return mColorAxis.data(); } + QCPAxis::AxisType type() const { return mType; } + QCPRange dataRange() const { return mDataRange; } + QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } + QCPColorGradient gradient() const { return mGradient; } + QString label() const; + int barWidth () const { return mBarWidth; } + bool rangeDrag() const; + bool rangeZoom() const; + + // setters: + void setType(QCPAxis::AxisType type); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); + void setLabel(const QString &str); + void setBarWidth(int width); + void setRangeDrag(bool enabled); + void setRangeZoom(bool enabled); + + // non-property methods: + QList colorMaps() const; + void rescaleDataRange(bool onlyVisibleMaps); + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + +signals: + void dataRangeChanged(const QCPRange &newRange); + void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + void gradientChanged(const QCPColorGradient &newGradient); + +protected: + // property members: + QCPAxis::AxisType mType; + QCPRange mDataRange; + QCPAxis::ScaleType mDataScaleType; + QCPColorGradient mGradient; + int mBarWidth; + + // non-property members: + QPointer mAxisRect; + QPointer mColorAxis; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + // events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPColorScale) + + friend class QCPColorScaleAxisRectPrivate; +}; + + +/* end of 'src/layoutelements/layoutelement-colorscale.h' */ + + +/* including file 'src/plottables/plottable-graph.h', size 9294 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPGraphData +{ +public: + QCPGraphData(); + QCPGraphData(double key, double value); + + inline double sortKey() const { return key; } + inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } + + double key, value; +}; +Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPGraphDataContainer + + Container for storing \ref QCPGraphData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPGraph holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPGraphData, QCPGraph::setData +*/ +typedef QCPDataContainer QCPGraphDataContainer; + +class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) + Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) + Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) + Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) + Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) + /// \endcond +public: + /*! + Defines how the graph's line is represented visually in the plot. The line is drawn with the + current pen of the graph (\ref setPen). + \see setLineStyle + */ + enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented + ///< with symbols according to the scatter style, see \ref setScatterStyle) + ,lsLine ///< data points are connected by a straight line + ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point + ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point + ,lsStepCenter ///< line is drawn as steps where the step is in between two data points + ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line + }; + Q_ENUMS(LineStyle) + + explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPGraph(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + LineStyle lineStyle() const { return mLineStyle; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + int scatterSkip() const { return mScatterSkip; } + QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } + bool adaptiveSampling() const { return mAdaptiveSampling; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void setLineStyle(LineStyle ls); + void setScatterStyle(const QCPScatterStyle &style); + void setScatterSkip(int skip); + void setChannelFillGraph(QCPGraph *targetGraph); + void setAdaptiveSampling(bool enabled); + + // non-property methods: + void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(double key, double value); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + LineStyle mLineStyle; + QCPScatterStyle mScatterStyle; + int mScatterSkip; + QPointer mChannelFillGraph; + bool mAdaptiveSampling; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawFill(QCPPainter *painter, QVector *lines) const; + virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; + virtual void drawLinePlot(QCPPainter *painter, const QVector &lines) const; + virtual void drawImpulsePlot(QCPPainter *painter, const QVector &lines) const; + + virtual void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; + virtual void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; + + // non-virtual methods: + void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; + void getLines(QVector *lines, const QCPDataRange &dataRange) const; + void getScatters(QVector *scatters, const QCPDataRange &dataRange) const; + QVector dataToLines(const QVector &data) const; + QVector dataToStepLeftLines(const QVector &data) const; + QVector dataToStepRightLines(const QVector &data) const; + QVector dataToStepCenterLines(const QVector &data) const; + QVector dataToImpulseLines(const QVector &data) const; + QVector getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const; + QVector > getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const; + bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const; + QPointF getFillBasePoint(QPointF matchingDataPoint) const; + const QPolygonF getFillPolygon(const QVector *lineData, QCPDataRange segment) const; + const QPolygonF getChannelFillPolygon(const QVector *lineData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const; + int findIndexBelowX(const QVector *data, double x) const; + int findIndexAboveX(const QVector *data, double x) const; + int findIndexBelowY(const QVector *data, double y) const; + int findIndexAboveY(const QVector *data, double y) const; + double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPGraph::LineStyle) + +/* end of 'src/plottables/plottable-graph.h' */ + + +/* including file 'src/plottables/plottable-curve.h', size 7409 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPCurveData +{ +public: + QCPCurveData(); + QCPCurveData(double t, double key, double value); + + inline double sortKey() const { return t; } + inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); } + inline static bool sortKeyIsMainKey() { return false; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } + + double t, key, value; +}; +Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPCurveDataContainer + + Container for storing \ref QCPCurveData points. The data is stored sorted by \a t, so the \a + sortKey() (returning \a t) is different from \a mainKey() (returning \a key). + + This template instantiation is the container in which QCPCurve holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPCurveData, QCPCurve::setData +*/ +typedef QCPDataContainer QCPCurveDataContainer; + +class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) + Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) + Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) + /// \endcond +public: + /*! + Defines how the curve's line is represented visually in the plot. The line is drawn with the + current pen of the curve (\ref setPen). + \see setLineStyle + */ + enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) + ,lsLine ///< Data points are connected with a straight line + }; + Q_ENUMS(LineStyle) + + explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPCurve(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + int scatterSkip() const { return mScatterSkip; } + LineStyle lineStyle() const { return mLineStyle; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); + void setData(const QVector &keys, const QVector &values); + void setScatterStyle(const QCPScatterStyle &style); + void setScatterSkip(int skip); + void setLineStyle(LineStyle style); + + // non-property methods: + void addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(const QVector &keys, const QVector &values); + void addData(double t, double key, double value); + void addData(double key, double value); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + QCPScatterStyle mScatterStyle; + int mScatterSkip; + LineStyle mLineStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawCurveLine(QCPPainter *painter, const QVector &lines) const; + virtual void drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const; + + // non-virtual methods: + void getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const; + void getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const; + int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + QVector getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + bool mayTraverse(int prevRegion, int currentRegion) const; + bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const; + void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const; + double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPCurve::LineStyle) + +/* end of 'src/plottables/plottable-curve.h' */ + + +/* including file 'src/plottables/plottable-bars.h', size 8924 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPBarsGroup : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType) + Q_PROPERTY(double spacing READ spacing WRITE setSpacing) + /// \endcond +public: + /*! + Defines the ways the spacing between bars in the group can be specified. Thus it defines what + the number passed to \ref setSpacing actually means. + + \see setSpacingType, setSpacing + */ + enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels + ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size + ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(SpacingType) + + QCPBarsGroup(QCustomPlot *parentPlot); + virtual ~QCPBarsGroup(); + + // getters: + SpacingType spacingType() const { return mSpacingType; } + double spacing() const { return mSpacing; } + + // setters: + void setSpacingType(SpacingType spacingType); + void setSpacing(double spacing); + + // non-virtual methods: + QList bars() const { return mBars; } + QCPBars* bars(int index) const; + int size() const { return mBars.size(); } + bool isEmpty() const { return mBars.isEmpty(); } + void clear(); + bool contains(QCPBars *bars) const { return mBars.contains(bars); } + void append(QCPBars *bars); + void insert(int i, QCPBars *bars); + void remove(QCPBars *bars); + +protected: + // non-property members: + QCustomPlot *mParentPlot; + SpacingType mSpacingType; + double mSpacing; + QList mBars; + + // non-virtual methods: + void registerBars(QCPBars *bars); + void unregisterBars(QCPBars *bars); + + // virtual methods: + double keyPixelOffset(const QCPBars *bars, double keyCoord); + double getPixelSpacing(const QCPBars *bars, double keyCoord); + +private: + Q_DISABLE_COPY(QCPBarsGroup) + + friend class QCPBars; +}; +Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType) + + +class QCP_LIB_DECL QCPBarsData +{ +public: + QCPBarsData(); + QCPBarsData(double key, double value); + + inline double sortKey() const { return key; } + inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here + + double key, value; +}; +Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPBarsDataContainer + + Container for storing \ref QCPBarsData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPBars holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPBarsData, QCPBars::setData +*/ +typedef QCPDataContainer QCPBarsDataContainer; + +class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) + Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup) + Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue) + Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap) + Q_PROPERTY(QCPBars* barBelow READ barBelow) + Q_PROPERTY(QCPBars* barAbove READ barAbove) + /// \endcond +public: + /*! + Defines the ways the width of the bar can be specified. Thus it defines what the number passed + to \ref setWidth actually means. + + \see setWidthType, setWidth + */ + enum WidthType { wtAbsolute ///< Bar width is in absolute pixels + ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size + ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(WidthType) + + explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPBars(); + + // getters: + double width() const { return mWidth; } + WidthType widthType() const { return mWidthType; } + QCPBarsGroup *barsGroup() const { return mBarsGroup; } + double baseValue() const { return mBaseValue; } + double stackingGap() const { return mStackingGap; } + QCPBars *barBelow() const { return mBarBelow.data(); } + QCPBars *barAbove() const { return mBarAbove.data(); } + QSharedPointer data() const { return mDataContainer; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void setWidth(double width); + void setWidthType(WidthType widthType); + void setBarsGroup(QCPBarsGroup *barsGroup); + void setBaseValue(double baseValue); + void setStackingGap(double pixels); + + // non-property methods: + void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(double key, double value); + void moveBelow(QCPBars *bars); + void moveAbove(QCPBars *bars); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + +protected: + // property members: + double mWidth; + WidthType mWidthType; + QCPBarsGroup *mBarsGroup; + double mBaseValue; + double mStackingGap; + QPointer mBarBelow, mBarAbove; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const; + QRectF getBarRect(double key, double value) const; + void getPixelWidth(double key, double &lower, double &upper) const; + double getStackedBaseValue(double key, bool positive) const; + static void connectBars(QCPBars* lower, QCPBars* upper); + + friend class QCustomPlot; + friend class QCPLegend; + friend class QCPBarsGroup; +}; +Q_DECLARE_METATYPE(QCPBars::WidthType) + +/* end of 'src/plottables/plottable-bars.h' */ + + +/* including file 'src/plottables/plottable-statisticalbox.h', size 7516 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPStatisticalBoxData +{ +public: + QCPStatisticalBoxData(); + QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers=QVector()); + + inline double sortKey() const { return key; } + inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return median; } + + inline QCPRange valueRange() const + { + QCPRange result(minimum, maximum); + for (QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it) + result.expand(*it); + return result; + } + + double key, minimum, lowerQuartile, median, upperQuartile, maximum; + QVector outliers; +}; +Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE); + + +/*! \typedef QCPStatisticalBoxDataContainer + + Container for storing \ref QCPStatisticalBoxData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPStatisticalBox holds its data. For + details about the generic container, see the documentation of the class template \ref + QCPDataContainer. + + \see QCPStatisticalBoxData, QCPStatisticalBox::setData +*/ +typedef QCPDataContainer QCPStatisticalBoxDataContainer; + +class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) + Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen) + Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen) + Q_PROPERTY(bool whiskerAntialiased READ whiskerAntialiased WRITE setWhiskerAntialiased) + Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen) + Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle) + /// \endcond +public: + explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis); + + // getters: + QSharedPointer data() const { return mDataContainer; } + double width() const { return mWidth; } + double whiskerWidth() const { return mWhiskerWidth; } + QPen whiskerPen() const { return mWhiskerPen; } + QPen whiskerBarPen() const { return mWhiskerBarPen; } + bool whiskerAntialiased() const { return mWhiskerAntialiased; } + QPen medianPen() const { return mMedianPen; } + QCPScatterStyle outlierStyle() const { return mOutlierStyle; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); + void setWidth(double width); + void setWhiskerWidth(double width); + void setWhiskerPen(const QPen &pen); + void setWhiskerBarPen(const QPen &pen); + void setWhiskerAntialiased(bool enabled); + void setMedianPen(const QPen &pen); + void setOutlierStyle(const QCPScatterStyle &style); + + // non-property methods: + void addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); + void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers=QVector()); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + double mWidth; + double mWhiskerWidth; + QPen mWhiskerPen, mWhiskerBarPen; + bool mWhiskerAntialiased; + QPen mMedianPen; + QCPScatterStyle mOutlierStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const; + + // non-virtual methods: + void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const; + QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const; + QVector getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const; + QVector getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-statisticalbox.h' */ + + +/* including file 'src/plottables/plottable-colormap.h', size 7070 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPColorMapData +{ +public: + QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); + ~QCPColorMapData(); + QCPColorMapData(const QCPColorMapData &other); + QCPColorMapData &operator=(const QCPColorMapData &other); + + // getters: + int keySize() const { return mKeySize; } + int valueSize() const { return mValueSize; } + QCPRange keyRange() const { return mKeyRange; } + QCPRange valueRange() const { return mValueRange; } + QCPRange dataBounds() const { return mDataBounds; } + double data(double key, double value); + double cell(int keyIndex, int valueIndex); + unsigned char alpha(int keyIndex, int valueIndex); + + // setters: + void setSize(int keySize, int valueSize); + void setKeySize(int keySize); + void setValueSize(int valueSize); + void setRange(const QCPRange &keyRange, const QCPRange &valueRange); + void setKeyRange(const QCPRange &keyRange); + void setValueRange(const QCPRange &valueRange); + void setData(double key, double value, double z); + void setCell(int keyIndex, int valueIndex, double z); + void setAlpha(int keyIndex, int valueIndex, unsigned char alpha); + + // non-property methods: + void recalculateDataBounds(); + void clear(); + void clearAlpha(); + void fill(double z); + void fillAlpha(unsigned char alpha); + bool isEmpty() const { return mIsEmpty; } + void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; + void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; + +protected: + // property members: + int mKeySize, mValueSize; + QCPRange mKeyRange, mValueRange; + bool mIsEmpty; + + // non-property members: + double *mData; + unsigned char *mAlpha; + QCPRange mDataBounds; + bool mDataModified; + + bool createAlpha(bool initializeOpaque=true); + + friend class QCPColorMap; +}; + + +class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) + Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) + Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) + Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) + Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) + Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) + /// \endcond +public: + explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPColorMap(); + + // getters: + QCPColorMapData *data() const { return mMapData; } + QCPRange dataRange() const { return mDataRange; } + QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } + bool interpolate() const { return mInterpolate; } + bool tightBoundary() const { return mTightBoundary; } + QCPColorGradient gradient() const { return mGradient; } + QCPColorScale *colorScale() const { return mColorScale.data(); } + + // setters: + void setData(QCPColorMapData *data, bool copy=false); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); + void setInterpolate(bool enabled); + void setTightBoundary(bool enabled); + void setColorScale(QCPColorScale *colorScale); + + // non-property methods: + void rescaleDataRange(bool recalculateDataBounds=false); + Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +signals: + void dataRangeChanged(const QCPRange &newRange); + void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + void gradientChanged(const QCPColorGradient &newGradient); + +protected: + // property members: + QCPRange mDataRange; + QCPAxis::ScaleType mDataScaleType; + QCPColorMapData *mMapData; + QCPColorGradient mGradient; + bool mInterpolate; + bool mTightBoundary; + QPointer mColorScale; + + // non-property members: + QImage mMapImage, mUndersampledMapImage; + QPixmap mLegendIcon; + bool mMapImageInvalidated; + + // introduced virtual methods: + virtual void updateMapImage(); + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-colormap.h' */ + + +/* including file 'src/plottables/plottable-financial.h', size 8622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPFinancialData +{ +public: + QCPFinancialData(); + QCPFinancialData(double key, double open, double high, double low, double close); + + inline double sortKey() const { return key; } + inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return open; } + + inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them + + double key, open, high, low, close; +}; +Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPFinancialDataContainer + + Container for storing \ref QCPFinancialData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPFinancial holds its data. For details + about the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPFinancialData, QCPFinancial::setData +*/ +typedef QCPDataContainer QCPFinancialDataContainer; + +class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle) + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) + Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored) + Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive) + Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative) + Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive) + Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative) + /// \endcond +public: + /*! + Defines the ways the width of the financial bar can be specified. Thus it defines what the + number passed to \ref setWidth actually means. + + \see setWidthType, setWidth + */ + enum WidthType { wtAbsolute ///< width is in absolute pixels + ,wtAxisRectRatio ///< width is given by a fraction of the axis rect size + ,wtPlotCoords ///< width is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(WidthType) + + /*! + Defines the possible representations of OHLC data in the plot. + + \see setChartStyle + */ + enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation + ,csCandlestick ///< Candlestick representation + }; + Q_ENUMS(ChartStyle) + + explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPFinancial(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + ChartStyle chartStyle() const { return mChartStyle; } + double width() const { return mWidth; } + WidthType widthType() const { return mWidthType; } + bool twoColored() const { return mTwoColored; } + QBrush brushPositive() const { return mBrushPositive; } + QBrush brushNegative() const { return mBrushNegative; } + QPen penPositive() const { return mPenPositive; } + QPen penNegative() const { return mPenNegative; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); + void setChartStyle(ChartStyle style); + void setWidth(double width); + void setWidthType(WidthType widthType); + void setTwoColored(bool twoColored); + void setBrushPositive(const QBrush &brush); + void setBrushNegative(const QBrush &brush); + void setPenPositive(const QPen &pen); + void setPenNegative(const QPen &pen); + + // non-property methods: + void addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); + void addData(double key, double open, double high, double low, double close); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + + // static methods: + static QCPFinancialDataContainer timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset = 0); + +protected: + // property members: + ChartStyle mChartStyle; + double mWidth; + WidthType mWidthType; + bool mTwoColored; + QBrush mBrushPositive, mBrushNegative; + QPen mPenPositive, mPenNegative; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); + void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); + double getPixelWidth(double key, double keyPixel) const; + double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; + double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; + void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const; + QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPFinancial::ChartStyle) + +/* end of 'src/plottables/plottable-financial.h' */ + + +/* including file 'src/plottables/plottable-errorbar.h', size 7727 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPErrorBarsData +{ +public: + QCPErrorBarsData(); + explicit QCPErrorBarsData(double error); + QCPErrorBarsData(double errorMinus, double errorPlus); + + double errorMinus, errorPlus; +}; +Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPErrorBarsDataContainer + + Container for storing \ref QCPErrorBarsData points. It is a typedef for QVector<\ref + QCPErrorBarsData>. + + This is the container in which \ref QCPErrorBars holds its data. Unlike most other data + containers for plottables, it is not based on \ref QCPDataContainer. This is because the error + bars plottable is special in that it doesn't store its own key and value coordinate per error + bar. It adopts the key and value from the plottable to which the error bars shall be applied + (\ref QCPErrorBars::setDataPlottable). So the stored \ref QCPErrorBarsData doesn't need a + sortable key, but merely an index (as \c QVector provides), which maps one-to-one to the indices + of the other plottable's data. + + \see QCPErrorBarsData, QCPErrorBars::setData +*/ +typedef QVector QCPErrorBarsDataContainer; + +class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottableInterface1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QSharedPointer data READ data WRITE setData) + Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable) + Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) + Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) + Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap) + /// \endcond +public: + + /*! + Defines in which orientation the error bars shall appear. If your data needs both error + dimensions, create two \ref QCPErrorBars with different \ref ErrorType. + + \see setErrorType + */ + enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) + ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) + }; + Q_ENUMS(ErrorType) + + explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPErrorBars(); + // getters: + QSharedPointer data() const { return mDataContainer; } + QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); } + ErrorType errorType() const { return mErrorType; } + double whiskerWidth() const { return mWhiskerWidth; } + double symbolGap() const { return mSymbolGap; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &error); + void setData(const QVector &errorMinus, const QVector &errorPlus); + void setDataPlottable(QCPAbstractPlottable* plottable); + void setErrorType(ErrorType type); + void setWhiskerWidth(double pixels); + void setSymbolGap(double pixels); + + // non-property methods: + void addData(const QVector &error); + void addData(const QVector &errorMinus, const QVector &errorPlus); + void addData(double error); + void addData(double errorMinus, double errorPlus); + + // virtual methods of 1d plottable interface: + virtual int dataCount() const Q_DECL_OVERRIDE; + virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; + virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; + virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } + +protected: + // property members: + QSharedPointer mDataContainer; + QPointer mDataPlottable; + ErrorType mErrorType; + double mWhiskerWidth; + double mSymbolGap; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const; + void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; + double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const; + // helpers: + void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; + bool errorBarVisible(int index) const; + bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-errorbar.h' */ + + +/* including file 'src/items/item-straightline.h', size 3117 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + /// \endcond +public: + explicit QCPItemStraightLine(QCustomPlot *parentPlot); + virtual ~QCPItemStraightLine(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const point1; + QCPItemPosition * const point2; + +protected: + // property members: + QPen mPen, mSelectedPen; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QLineF getRectClippedStraightLine(const QCPVector2D &point1, const QCPVector2D &vec, const QRect &rect) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-straightline.h' */ + + +/* including file 'src/items/item-line.h', size 3407 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) + Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + /// \endcond +public: + explicit QCPItemLine(QCustomPlot *parentPlot); + virtual ~QCPItemLine(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QCPLineEnding head() const { return mHead; } + QCPLineEnding tail() const { return mTail; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setHead(const QCPLineEnding &head); + void setTail(const QCPLineEnding &tail); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const start; + QCPItemPosition * const end; + +protected: + // property members: + QPen mPen, mSelectedPen; + QCPLineEnding mHead, mTail; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-line.h' */ + + +/* including file 'src/items/item-curve.h', size 3379 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) + Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + /// \endcond +public: + explicit QCPItemCurve(QCustomPlot *parentPlot); + virtual ~QCPItemCurve(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QCPLineEnding head() const { return mHead; } + QCPLineEnding tail() const { return mTail; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setHead(const QCPLineEnding &head); + void setTail(const QCPLineEnding &tail); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const start; + QCPItemPosition * const startDir; + QCPItemPosition * const endDir; + QCPItemPosition * const end; + +protected: + // property members: + QPen mPen, mSelectedPen; + QCPLineEnding mHead, mTail; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; +}; + +/* end of 'src/items/item-curve.h' */ + + +/* including file 'src/items/item-rect.h', size 3688 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + /// \endcond +public: + explicit QCPItemRect(QCustomPlot *parentPlot); + virtual ~QCPItemRect(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-rect.h' */ + + +/* including file 'src/items/item-text.h', size 5554 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemText : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) + Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) + Q_PROPERTY(double rotation READ rotation WRITE setRotation) + Q_PROPERTY(QMargins padding READ padding WRITE setPadding) + /// \endcond +public: + explicit QCPItemText(QCustomPlot *parentPlot); + virtual ~QCPItemText(); + + // getters: + QColor color() const { return mColor; } + QColor selectedColor() const { return mSelectedColor; } + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + QFont font() const { return mFont; } + QFont selectedFont() const { return mSelectedFont; } + QString text() const { return mText; } + Qt::Alignment positionAlignment() const { return mPositionAlignment; } + Qt::Alignment textAlignment() const { return mTextAlignment; } + double rotation() const { return mRotation; } + QMargins padding() const { return mPadding; } + + // setters; + void setColor(const QColor &color); + void setSelectedColor(const QColor &color); + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + void setFont(const QFont &font); + void setSelectedFont(const QFont &font); + void setText(const QString &text); + void setPositionAlignment(Qt::Alignment alignment); + void setTextAlignment(Qt::Alignment alignment); + void setRotation(double degrees); + void setPadding(const QMargins &padding); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const position; + QCPItemAnchor * const topLeft; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottomRight; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QColor mColor, mSelectedColor; + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + QFont mFont, mSelectedFont; + QString mText; + Qt::Alignment mPositionAlignment; + Qt::Alignment mTextAlignment; + double mRotation; + QMargins mPadding; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; + QFont mainFont() const; + QColor mainColor() const; + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-text.h' */ + + +/* including file 'src/items/item-ellipse.h', size 3868 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + /// \endcond +public: + explicit QCPItemEllipse(QCustomPlot *parentPlot); + virtual ~QCPItemEllipse(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const topLeftRim; + QCPItemAnchor * const top; + QCPItemAnchor * const topRightRim; + QCPItemAnchor * const right; + QCPItemAnchor * const bottomRightRim; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeftRim; + QCPItemAnchor * const left; + QCPItemAnchor * const center; + +protected: + enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; + + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-ellipse.h' */ + + +/* including file 'src/items/item-pixmap.h', size 4373 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) + Q_PROPERTY(bool scaled READ scaled WRITE setScaled) + Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) + Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + /// \endcond +public: + explicit QCPItemPixmap(QCustomPlot *parentPlot); + virtual ~QCPItemPixmap(); + + // getters: + QPixmap pixmap() const { return mPixmap; } + bool scaled() const { return mScaled; } + Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; } + Qt::TransformationMode transformationMode() const { return mTransformationMode; } + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + + // setters; + void setPixmap(const QPixmap &pixmap); + void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation); + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QPixmap mPixmap; + QPixmap mScaledPixmap; + bool mScaled; + bool mScaledPixmapInvalidated; + Qt::AspectRatioMode mAspectRatioMode; + Qt::TransformationMode mTransformationMode; + QPen mPen, mSelectedPen; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); + QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-pixmap.h' */ + + +/* including file 'src/items/item-tracer.h', size 4762 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(double size READ size WRITE setSize) + Q_PROPERTY(TracerStyle style READ style WRITE setStyle) + Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) + Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) + Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) + /// \endcond +public: + /*! + The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize. + + \see setStyle + */ + enum TracerStyle { tsNone ///< The tracer is not visible + ,tsPlus ///< A plus shaped crosshair with limited size + ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect + ,tsCircle ///< A circle + ,tsSquare ///< A square + }; + Q_ENUMS(TracerStyle) + + explicit QCPItemTracer(QCustomPlot *parentPlot); + virtual ~QCPItemTracer(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + double size() const { return mSize; } + TracerStyle style() const { return mStyle; } + QCPGraph *graph() const { return mGraph; } + double graphKey() const { return mGraphKey; } + bool interpolating() const { return mInterpolating; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + void setSize(double size); + void setStyle(TracerStyle style); + void setGraph(QCPGraph *graph); + void setGraphKey(double key); + void setInterpolating(bool enabled); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void updatePosition(); + + QCPItemPosition * const position; + +protected: + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + double mSize; + TracerStyle mStyle; + QCPGraph *mGraph; + double mGraphKey; + bool mInterpolating; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; +Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle) + +/* end of 'src/items/item-tracer.h' */ + + +/* including file 'src/items/item-bracket.h', size 3969 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(double length READ length WRITE setLength) + Q_PROPERTY(BracketStyle style READ style WRITE setStyle) + /// \endcond +public: + /*! + Defines the various visual shapes of the bracket item. The appearance can be further modified + by \ref setLength and \ref setPen. + + \see setStyle + */ + enum BracketStyle { bsSquare ///< A brace with angled edges + ,bsRound ///< A brace with round edges + ,bsCurly ///< A curly brace + ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression + }; + Q_ENUMS(BracketStyle) + + explicit QCPItemBracket(QCustomPlot *parentPlot); + virtual ~QCPItemBracket(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + double length() const { return mLength; } + BracketStyle style() const { return mStyle; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setLength(double length); + void setStyle(BracketStyle style); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const left; + QCPItemPosition * const right; + QCPItemAnchor * const center; + +protected: + // property members: + enum AnchorIndex {aiCenter}; + QPen mPen, mSelectedPen; + double mLength; + BracketStyle mStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; +}; +Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) + +/* end of 'src/items/item-bracket.h' */ + + +#endif // QCUSTOMPLOT_H + diff --git a/src/qt/statistics.cpp b/src/qt/statistics.cpp new file mode 100644 index 00000000..50eb5373 --- /dev/null +++ b/src/qt/statistics.cpp @@ -0,0 +1,46 @@ +#include "statistics.h" + +Statistics::Statistics() +{ + +} + +void Statistics::setLikesNumber(unsigned int number) +{ + likesNumber = number; +} + +void Statistics::setFriendsNumber(unsigned int number) +{ + friendsNumber = number; +} + +void Statistics::setPostsNumber(unsigned int number) +{ + postsNumber = number; +} + +void Statistics::setUserID(unsigned int number) +{ + userID = number; +} + +unsigned int Statistics::getLikesNumber() +{ + return likesNumber; +} + +unsigned int Statistics::getPostsNumber() +{ + return postsNumber; +} + +unsigned int Statistics::getFriendsNumber() +{ + return friendsNumber; +} + +unsigned int Statistics::getUserID() +{ + return userID; +} diff --git a/src/qt/statistics.h b/src/qt/statistics.h new file mode 100644 index 00000000..bbb5f472 --- /dev/null +++ b/src/qt/statistics.h @@ -0,0 +1,37 @@ +#ifndef STATISTICS_H +#define STATISTICS_H +#include "QString" + +class Statistics +{ +public: + Statistics(); + + void setLikesNumber(unsigned int number); + + void setFriendsNumber(unsigned int number); + + void setPostsNumber(unsigned int number); + + void setUserID(unsigned int number); + + unsigned int getLikesNumber(); + + unsigned int getPostsNumber(); + + unsigned int getFriendsNumber(); + + unsigned int getUserID(); + + +private: + unsigned int userID; + + unsigned int likesNumber; + + unsigned int friendsNumber; + + unsigned int postsNumber; +}; + +#endif // STATISTICS_H diff --git a/src/qt/user.cpp b/src/qt/user.cpp new file mode 100644 index 00000000..1934e769 --- /dev/null +++ b/src/qt/user.cpp @@ -0,0 +1,35 @@ +#include "user.h" + +user::user() +{ + userName=""; + id=0; +} + +user::user(QString passWord, QString email,QString name,int userID) +{ + userName=name; + userFileManipulator.name=name; + userFileManipulator.createFile(passWord,email,name,creationDate.getDateNow()); + id=userID; +} + +void user :: setUsersList(user A) +{ + usersList.append(A); +} + +QString user:: getUserName(int id) +{ + return usersList[id].userName; +} + + bool user:: usersEmpty() + { + return (usersList.size()==0); + } + +int user:: getUsersSize() +{ + return usersList.count(); +} diff --git a/src/qt/user.h b/src/qt/user.h new file mode 100644 index 00000000..35a000b0 --- /dev/null +++ b/src/qt/user.h @@ -0,0 +1,26 @@ +#ifndef USER_H +#define USER_H +#include "posts.h" +#include "fileman.h" +#include +#include +class user +{ +public: + QString userName; + int id; + Post userPost; + fileman userFileManipulator; + Date creationDate; + user(); + user(QString passWord, QString email, QString name,int userID); + void setUsersList( user A ); + QString getUserName(int id); + bool usersEmpty(); + int getUsersSize(); + +private: + QList usersList; +}; + +#endif // USER_H From fdf2a147b4c197722081b3c93bd95aeb1b7765a8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:51:46 -0400 Subject: [PATCH 0332/1324] Update homepage.ui --- src/qt/forms/homepage.ui | 637 ++++++++++----------------------------- 1 file changed, 161 insertions(+), 476 deletions(-) diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui index 53e629fc..e42d2fe7 100644 --- a/src/qt/forms/homepage.ui +++ b/src/qt/forms/homepage.ui @@ -1,502 +1,187 @@ - homepage - + HomePage + 0 0 - 700 - 600 + 1102 + 761 - Profile Page + MainWindow - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - - - 10 - 20 - 371 - 31 - - - - Welcome User - - - - - - 10 - 60 - 681 - 531 - - - - 0 - - - - Home - - - - - 9 - 29 - 331 - 451 - - - - true - - - - - 0 - 0 - 329 - 449 - - - - - - - - 10 - 10 - 121 - 16 - - - - NewsFeed - - - - - - 370 - 30 - 261 - 201 - - + + + - - - What is on your mind? - - - - - - - - - - Post - - - - - - - - - Profile - - - - - 310 - 320 - 335 - 34 - - - - - - - Save Changes - - - - - - - Remove Account - - - - - - - - - 10 - 262 - 421 - 24 - - - - font-family:sans-serif; -font-size:15px; -font-weight:none; -color:#545454; - - - Note: You can only update your password or country - - - - - - 125 - 154 - 235 - 30 - - - - - - - 125 - 190 - 235 - 30 - - - - - - - 10 - 10 - 109 - 24 - - - - First Name - - - - - - 10 - 82 - 102 - 24 - - - - Username - - - - - - 125 - 118 - 235 - 30 - - - - - - - 125 - 46 - 235 - 30 - - - - - - - 10 - 226 - 80 - 24 - - - - Country - - - - - - 125 - 82 - 235 - 30 - - - - - - - 125 - 226 - 235 - 30 - - - - - - - 125 - 10 - 235 - 30 - - - - - - - 10 - 118 - 97 - 24 - - - - Password - - - - - - 10 - 154 - 74 - 24 - - - - Gender - - - - - - 10 - 46 - 105 - 24 - - - - Last Name - - - - - - 10 - 190 - 87 - 24 - - - - Birthday - - - - - - Search - - - - - 20 - 10 - 581 - 21 - - - - Search for people, enter their name or search by country - - - - - - 30 - 80 - 321 - 401 - - - - - - - 390 - 250 - 231 - 41 - - - - Send Friend Request - - - - - - 20 - 40 - 361 - 34 - - - - - - - - - - Search - - - - - - - - - Notifications - - - - - 90 - 50 - 411 - 351 - - - - - - - 160 - 20 - 281 - 21 - - - - Here are your notifications - - - - - - 170 - 410 - 261 - 51 - - - - - - - Accept - - + + + + + + + + + + 400 + 16777215 + + + + + + + + + + + View Profile + + + + + + + View Network Staristics Window + + + + + + + + + + + + 16777215 + 100 + + + + 1 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + What's On Your Mind ?! + + + + + + + Post + + + + + + + + - - - Ignore - - + + + + + true + + + + + 0 + 0 + 1045 + 335 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + - - - - - Friends - - - - - 30 - 20 - 321 - 31 - - - - List of Friends - - - - - - 30 - 60 - 301 - 411 - - - - - - - 380 - 200 - 211 - 61 - - - - Remove Friend - - - + + - + - 564 - 20 - 111 - 41 + 0 + 0 + 1102 + 26 + + + File + + + + + + + + - Logout + Log Out - + From 62bb65723159298aeb1e78e04162ebc0680cedbd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:51:56 -0400 Subject: [PATCH 0333/1324] Delete loginpage.ui --- src/qt/forms/loginpage.ui | 104 -------------------------------------- 1 file changed, 104 deletions(-) delete mode 100644 src/qt/forms/loginpage.ui diff --git a/src/qt/forms/loginpage.ui b/src/qt/forms/loginpage.ui deleted file mode 100644 index 2eb1fa62..00000000 --- a/src/qt/forms/loginpage.ui +++ /dev/null @@ -1,104 +0,0 @@ - - - LoginPage - - - - 0 - 0 - 700 - 600 - - - - Login - - - - - 130 - 70 - 431 - 271 - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Login - - - - - - - - username - - - - - - - - - - password - - - - - - - QLineEdit::Password - - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Back - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Login - - - - - - - - - - lineEdit_username - lineEdit_password - pushButton_login - pushButton_back - - - - From 3c336accd62eb2684137cbab835c74e494530ad8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:52:02 -0400 Subject: [PATCH 0334/1324] Delete homepage.ui --- src/qt/forms/homepage.ui | 188 --------------------------------------- 1 file changed, 188 deletions(-) delete mode 100644 src/qt/forms/homepage.ui diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui deleted file mode 100644 index e42d2fe7..00000000 --- a/src/qt/forms/homepage.ui +++ /dev/null @@ -1,188 +0,0 @@ - - - HomePage - - - - 0 - 0 - 1102 - 761 - - - - MainWindow - - - - - - - - - - - - - - - - 400 - 16777215 - - - - - - - - - - - View Profile - - - - - - - View Network Staristics Window - - - - - - - - - - - - 16777215 - 100 - - - - 1 - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - What's On Your Mind ?! - - - - - - - Post - - - - - - - - - - - - - - - true - - - - - 0 - 0 - 1045 - 335 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - 0 - 0 - 1102 - 26 - - - - - File - - - - - - - - - - Log Out - - - - - - From 25b226eb540cd47c4da5d1d2b8cdf880cc1ce9be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:52:49 -0400 Subject: [PATCH 0335/1324] Add files via upload --- src/qt/forms/addcomment.ui | 107 ++++++ src/qt/forms/adminwindow.ui | 71 ++++ src/qt/forms/dialog.ui | 71 ++++ src/qt/forms/form.ui | 21 ++ src/qt/forms/homepage.ui | 188 +++++++++++ src/qt/forms/mainwindow.ui | 630 +++++++++++++++++++++++++++++++----- src/qt/forms/newaccount.ui | 195 +++++++++++ src/qt/forms/profilepage.ui | 289 +++++++++++++++-- 8 files changed, 1471 insertions(+), 101 deletions(-) create mode 100644 src/qt/forms/addcomment.ui create mode 100644 src/qt/forms/adminwindow.ui create mode 100644 src/qt/forms/dialog.ui create mode 100644 src/qt/forms/form.ui create mode 100644 src/qt/forms/homepage.ui create mode 100644 src/qt/forms/newaccount.ui diff --git a/src/qt/forms/addcomment.ui b/src/qt/forms/addcomment.ui new file mode 100644 index 00000000..c670061d --- /dev/null +++ b/src/qt/forms/addcomment.ui @@ -0,0 +1,107 @@ + + + AddComment + + + + 0 + 0 + 348 + 222 + + + + Dialog + + + + + 11 + 183 + 193 + 28 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 75 + 15 + 262 + 151 + + + + + + + 10 + 70 + 57 + 41 + + + + + + + Add + + + Qt::AlignCenter + + + + + + + Comment + + + + + + + + + + buttonBox + accepted() + AddComment + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddComment + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui new file mode 100644 index 00000000..4eb710bd --- /dev/null +++ b/src/qt/forms/adminwindow.ui @@ -0,0 +1,71 @@ + + + AdminWindow + + + + 0 + 0 + 800 + 550 + + + + MainWindow + + + + + + + true + + + + + 0 + 0 + 776 + 440 + + + + + + + + + + + + + + Show Statistics + + + + + + + + + 0 + 0 + 800 + 26 + + + + + + + + QCustomPlot + QWidget +
qcustomplot.h
+ 1 +
+
+ + +
diff --git a/src/qt/forms/dialog.ui b/src/qt/forms/dialog.ui new file mode 100644 index 00000000..669ff07b --- /dev/null +++ b/src/qt/forms/dialog.ui @@ -0,0 +1,71 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/forms/form.ui b/src/qt/forms/form.ui new file mode 100644 index 00000000..55b96fdf --- /dev/null +++ b/src/qt/forms/form.ui @@ -0,0 +1,21 @@ + + + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui new file mode 100644 index 00000000..0d3cdb97 --- /dev/null +++ b/src/qt/forms/homepage.ui @@ -0,0 +1,188 @@ + + + HomePage + + + + 0 + 0 + 1102 + 761 + + + + MainWindow + + + + + + + + + + + + + + + + 400 + 16777215 + + + + + + + + + + + View Profile + + + + + + + View Network Staristics Window + + + + + + + + + + + + 16777215 + 100 + + + + 1 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + What's On Your Mind ?! + + + + + + + Post + + + + + + + + + + + + + + + true + + + + + 0 + 0 + 1045 + 335 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + 0 + 0 + 1102 + 26 + + + + + File + + + + + + + + + + Log Out + + + + + + diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index ea8dbe08..f9070099 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -1,83 +1,547 @@ - - - MainWindow - - - - 0 - 0 - 700 - 600 - - - - Social Media App - - - - - - - Qt::LeftToRight - - - <html><head/><body><p align="center"><span style=" font-size:24pt; font-weight:600;">Connect with Friends and Family</span></p></body></html> - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Signup - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Login - - - - - - - - - - - 0 - 0 - 700 - 21 - - - - - - TopToolBarArea - - - false - - - - - - - - + + + MainWindow + + + + 0 + 0 + 464 + 319 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 106 + 100 + 92 + + + + + + + 255 + 255 + 255 + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + MainWindow + + + + + + + + + + + No account? Create one! + + + + + + + PointingHandCursor + + + Sign Up + + + + + + + + + + + + + + + + 10 + 75 + true + + + + Email + + + + + + + + 10 + 75 + true + + + + Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + PointingHandCursor + + + Log In + + + + + + + + + + + + + 0 + 0 + 464 + 26 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui new file mode 100644 index 00000000..c00afa77 --- /dev/null +++ b/src/qt/forms/newaccount.ui @@ -0,0 +1,195 @@ + + + newAccount + + + + 0 + 0 + 532 + 312 + + + + MainWindow + + + + + + + + + + + + Times New Roman + 16 + 75 + true + + + + if you already have an account ---> + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign In + + + + + + + + + + + + + + + + Times New Roman + 14 + 75 + true + + + + userName + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + Email + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + password + + + lineEdit_2 + + + + + + + + Times New Roman + 14 + 75 + true + + + + confirm password + + + lineEdit_3 + + + + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + QLineEdit::Password + + + + + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign Up + + + + + + + + + + + + + 0 + 0 + 532 + 26 + + + + + + + + diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui index f80edc63..8114320a 100644 --- a/src/qt/forms/profilepage.ui +++ b/src/qt/forms/profilepage.ui @@ -1,18 +1,271 @@ - - profilepage - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - - + + + ProfilePage + + + + 0 + 0 + 1008 + 596 + + + + MainWindow + + + + + + + + + + + + Arial + 15 + 75 + true + + + + User name label Area + + + + + + + Add as a friend + + + + + + + + + + + + Arial + 9 + 75 + true + + + + Home + + + + + + + + Arial + 9 + 75 + true + + + + Friends + + + 8 + + + + Friends + + + + + + + + + + + + + Arial + 12 + 75 + true + + + + INFO + + + + + + + + + + + + + Arial + 9 + + + + Email + + + + + + + lblMail + + + + + + + + + + + + Arial + 9 + + + + Number of friends + + + + + + + labelNumber + + + + + + + + + + + border-color:blue; + + + + true + + + + + 0 + 0 + 982 + 349 + + + + + + + + 16777215 + 100 + + + + + + + What's on your mind? + + + + + + + + Arial + 9 + 75 + true + + + + false + + + background-color: rgb(85, 0, 255); +color:white; +selection-color: rgb(255, 255, 255); + + + Post + + + + + + + true + + + + + 0 + 0 + 958 + 183 + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1008 + 26 + + + + + File + + + + + + + + + + Log out + + + + + + From 717d0e4126799d23700fbd06e64bc08b3a175437 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:56:13 -0400 Subject: [PATCH 0336/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ca0bc3d4..4579f13d 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -11,7 +11,7 @@ ui(new Ui::MainWindow) { ui->setupUi(this); ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); this->setWindowTitle("Social Network"); } From 599b0fc67d5891e18c48965cdf239ea4d8bbe9a4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:57:11 -0400 Subject: [PATCH 0337/1324] Update addcomment.cpp --- src/qt/addcomment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp index fde45cd1..1575d351 100644 --- a/src/qt/addcomment.cpp +++ b/src/qt/addcomment.cpp @@ -7,7 +7,7 @@ AddComment::AddComment(QWidget *parent) : { ui->setupUi(this); commentBody = ""; - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); } AddComment::~AddComment() From 33977af3543b40c40855de1e92644dd7172e7e72 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:57:33 -0400 Subject: [PATCH 0338/1324] Update adminwindow.cpp --- src/qt/adminwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp index 4d6b37a6..806b0040 100644 --- a/src/qt/adminwindow.cpp +++ b/src/qt/adminwindow.cpp @@ -7,7 +7,7 @@ AdminWindow::AdminWindow(QWidget *parent) : ui(new Ui::AdminWindow) { ui->setupUi(this); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); this->showMaximized(); this->setWindowTitle("Social Network"); From 66635349f4eb4ac3f3688af26d89c96dfb2c22b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:59:32 -0400 Subject: [PATCH 0339/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 17963cf8..d55b1783 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -33,7 +33,7 @@ HomePage::HomePage(QWidget *parent) : shownPostsNumber = 0; ui->comboBox->setVisible(false); pagePosts = new QList; - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); this->showMaximized(); this->setWindowTitle("Social Network"); From 637703865eb803f045ee1fa761f20d9beb290664 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 01:59:58 -0400 Subject: [PATCH 0340/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 89c986e8..4332d0d7 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -9,7 +9,7 @@ newAccount::newAccount(QWidget *parent) : ui->setupUi(this); user check; id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); this->setWindowTitle("Social Network"); } From 40815d3f579f3f60c21efc2bfc44b1c05343e8de Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:00:46 -0400 Subject: [PATCH 0341/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index ecf9c15e..2fc29330 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -34,7 +34,7 @@ ProfilePage::ProfilePage(QWidget *parent) : shownPostsNumber = 0; //pagePosts = makePosts(); // viewPosts(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); this->showMaximized(); this->setWindowTitle("Social Network"); } From ed1a0a76993e86c286e713c5723274d353be96e8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:02:59 -0400 Subject: [PATCH 0342/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 147f4b8d..229c9eca 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,11 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui \ - qt/forms/mainwindow.ui \ - qt/forms/signuppage.ui \ - qt/forms/loginpage.ui \ - qt/forms/homepage.ui + qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -110,12 +106,7 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp \ - qt/moc_main.cpp \ - qt/moc_mainwindow.cpp \ - qt/moc_signuppage.cpp \ - qt/moc_loginpage.cpp \ - qt/moc_homepage.cpp + qt/moc_walletview.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -199,11 +190,7 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h \ - qt/mainwindow.h \ - qt/signuppage.h \ - qt/loginpage.h \ - qt/homepage.h + qt/winshutdownmonitor.h RES_ICONS = \ @@ -543,12 +530,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp \ - qt/main.cpp \ - qt/mainwindow.cpp \ - qt/signuppage.cpp \ - qt/loginpage.cpp \ - qt/homepage.cpp + qt/walletview.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From d768618d1152517514f828547caf172fbbe1737b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:05:41 -0400 Subject: [PATCH 0343/1324] Update addcomment.h --- src/qt/addcomment.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h index bb61bc05..78fc9e25 100644 --- a/src/qt/addcomment.h +++ b/src/qt/addcomment.h @@ -16,11 +16,11 @@ class AddComment : public QDialog ~AddComment(); -public slots: +public Q_SLOTS: QString getCommentBody(); -private slots: +private Q_SLOTS: void on_AddComment_accepted(); From e947f2e74d7141e79001c30f67886ec12b4476eb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:05:54 -0400 Subject: [PATCH 0344/1324] Update adminwindow.h --- src/qt/adminwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h index 308af0fe..3fb32a8a 100644 --- a/src/qt/adminwindow.h +++ b/src/qt/adminwindow.h @@ -15,7 +15,7 @@ class AdminWindow : public QMainWindow explicit AdminWindow(QWidget *parent = 0); ~AdminWindow(); -private slots: +private Q_SLOTS: void on_showStatistics_clicked(); void makePlot(QVector *plotData); From bed1211dd587f5aa00cd932c0590a34e8e6f4c5a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:06:29 -0400 Subject: [PATCH 0345/1324] Update fileman.h --- src/qt/fileman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/fileman.h b/src/qt/fileman.h index 3e434553..901e5f57 100644 --- a/src/qt/fileman.h +++ b/src/qt/fileman.h @@ -40,7 +40,7 @@ class fileman{ void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); QList * getPosts_new(QString email); -public slots: +public Q_SLOTS: void addLikeByPostDate(QString email, QString Date, QString likePerson); QString getPassword(QString email); }; From 63e6c9cd0c989a587568772bf8a1adff31696a0a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:11:57 -0400 Subject: [PATCH 0346/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 229c9eca..eafba4c9 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,13 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui + qt/forms/transactiondescdialog.ui \ + qt/forms/mainwindow.ui \ + qt/forms/newaccount.ui \ + qt/forms/homepage.ui \ + qt/forms/profilepage.ui \ + qt/forms/addcomment.ui \ + qt/forms/adminwindow.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -190,7 +196,20 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h + qt/winshutdownmonitor.h \ + qt/mainwindow.h \ + qt/newaccount.h \ + qt/homepage.h \ + qt/profilepage.h \ + qt/addcomment.h \ + qt/posts.h \ + qt/comment.h \ + qt/Activity.h \ + qt/user.h \ + qt/fileman.h \ + qt/qcustomplot.h \ + qt/adminwindow.h \ + qt/statistics.h RES_ICONS = \ @@ -530,7 +549,21 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp + qt/walletview.cpp \ + qt/main.cpp \ + qt/mainwindow.cpp \ + qt/newaccount.cpp \ + qt/profilepage.cpp \ + qt/addcomment.cpp \ + qt/posts.cpp \ + qt/comment.cpp \ + qt/Activity.cpp \ + qt/user.cpp \ + qt/fileman.cpp \ + qt/qcustomplot.cpp \ + qt/adminwindow.cpp \ + qt/statistics.cpp \ + qt/homepage.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 938e96309b0fb22a014e3a7d7a965302dfccc96e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:18:19 -0400 Subject: [PATCH 0347/1324] Update walletview.cpp --- src/qt/walletview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f912151d..9695452c 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,6 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" +#include "mainwindow.h" #include "ui_interface.h" From 9e9fe89bf3ccd86a74febb67794e7b801d7159df Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:19:29 -0400 Subject: [PATCH 0348/1324] Update newaccount.h --- src/qt/newaccount.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index 9114dcdd..b69d4800 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -17,11 +17,11 @@ class newAccount : public QMainWindow int id; -public slots: +public Q_SLOTS: void setLoginPtr(MainWindow *ptr); -private slots: +private Q_SLOTS: void on_pushButton_clicked(); void on_pushButton_2_clicked(); From 4963102613043a0adddb91830baa8c9452132d0a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:20:15 -0400 Subject: [PATCH 0349/1324] Update addcomment.cpp --- src/qt/addcomment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp index 1575d351..9fc92a94 100644 --- a/src/qt/addcomment.cpp +++ b/src/qt/addcomment.cpp @@ -7,7 +7,7 @@ AddComment::AddComment(QWidget *parent) : { ui->setupUi(this); commentBody = ""; - QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); + QWidget::setWindowIcon(QIcon(":/icons/chat")); } AddComment::~AddComment() From 39ebf06ace1c4f8c0fc85e67c1f24adae34eb18c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:20:33 -0400 Subject: [PATCH 0350/1324] Update adminwindow.cpp --- src/qt/adminwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp index 806b0040..5b13a64e 100644 --- a/src/qt/adminwindow.cpp +++ b/src/qt/adminwindow.cpp @@ -7,7 +7,7 @@ AdminWindow::AdminWindow(QWidget *parent) : ui(new Ui::AdminWindow) { ui->setupUi(this); - QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); + QWidget::setWindowIcon(QIcon(":/icons/chat")); this->showMaximized(); this->setWindowTitle("Social Network"); From 494c4e6b2b3f498c2ef50ef4ac532a6120ec7105 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:21:19 -0400 Subject: [PATCH 0351/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index d55b1783..9e714c41 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -33,7 +33,7 @@ HomePage::HomePage(QWidget *parent) : shownPostsNumber = 0; ui->comboBox->setVisible(false); pagePosts = new QList; - QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); + QWidget::setWindowIcon(QIcon(":/icons/chat")); this->showMaximized(); this->setWindowTitle("Social Network"); From 0d723a453f2b483a4fe28badbc726f71fc43da5f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:21:36 -0400 Subject: [PATCH 0352/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4579f13d..51323edc 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -11,7 +11,7 @@ ui(new Ui::MainWindow) { ui->setupUi(this); ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); +QWidget::setWindowIcon(QIcon(":/icons/chat")); this->setWindowTitle("Social Network"); } From f000cdea4f664c2dfeb9d6f3f3d2deb8556379b7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:21:52 -0400 Subject: [PATCH 0353/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 4332d0d7..c7066d4b 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -9,7 +9,7 @@ newAccount::newAccount(QWidget *parent) : ui->setupUi(this); user check; id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); + QWidget::setWindowIcon(QIcon(":/icons/chat")); this->setWindowTitle("Social Network"); } From ffd9b97ae544b85a04955aed0624ae013d4bc0ff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:22:29 -0400 Subject: [PATCH 0354/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 2fc29330..99b9bfb4 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -12,7 +12,7 @@ #include "QPushButton" #include #include "posts.h" -#include "Qstring" +#include "QString" #include #include "QFontMetrics" #include "QGroupBox" @@ -34,7 +34,7 @@ ProfilePage::ProfilePage(QWidget *parent) : shownPostsNumber = 0; //pagePosts = makePosts(); // viewPosts(); - QWidget::setWindowIcon(QIcon(":/icons/" + theme + "/chat"")); + QWidget::setWindowIcon(QIcon(":/icons/chat")); this->showMaximized(); this->setWindowTitle("Social Network"); } From 6c9348a2852dee3a80f9b181237312611b225ac8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:23:35 -0400 Subject: [PATCH 0355/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 99b9bfb4..d831f5a9 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -6,13 +6,13 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "QHBoxLayout" -#include "QVBoxLayout" +#include #include "QLabel" #include "QSpacerItem" #include "QPushButton" #include #include "posts.h" -#include "QString" +#include #include #include "QFontMetrics" #include "QGroupBox" @@ -24,7 +24,7 @@ #define POSTSATATIME 15 //_____ -#include "qprocess.h" +#include "QProcess.h" ProfilePage::ProfilePage(QWidget *parent) : QMainWindow(parent), From 6aae48a864851f3533736df06c283c728acd9230 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:44:16 -0400 Subject: [PATCH 0356/1324] Delete qcustomplot.cpp --- src/qt/qcustomplot.cpp | 30121 --------------------------------------- 1 file changed, 30121 deletions(-) delete mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp deleted file mode 100644 index 154576a6..00000000 --- a/src/qt/qcustomplot.cpp +++ /dev/null @@ -1,30121 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#include "qcustomplot.h" - - -/* including file 'src/vector2d.cpp', size 7340 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPVector2D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPVector2D - \brief Represents two doubles as a mathematical 2D vector - - This class acts as a replacement for QVector2D with the advantage of double precision instead of - single, and some convenience methods tailored for the QCustomPlot library. -*/ - -/* start documentation of inline functions */ - -/*! \fn void QCPVector2D::setX(double x) - - Sets the x coordinate of this vector to \a x. - - \see setY -*/ - -/*! \fn void QCPVector2D::setY(double y) - - Sets the y coordinate of this vector to \a y. - - \see setX -*/ - -/*! \fn double QCPVector2D::length() const - - Returns the length of this vector. - - \see lengthSquared -*/ - -/*! \fn double QCPVector2D::lengthSquared() const - - Returns the squared length of this vector. In some situations, e.g. when just trying to find the - shortest vector of a group, this is faster than calculating \ref length, because it avoids - calculation of a square root. - - \see length -*/ - -/*! \fn QPoint QCPVector2D::toPoint() const - - Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point - information. - - \see toPointF -*/ - -/*! \fn QPointF QCPVector2D::toPointF() const - - Returns a QPointF which has the x and y coordinates of this vector. - - \see toPoint -*/ - -/*! \fn bool QCPVector2D::isNull() const - - Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y - coordinates, i.e. if both are binary equal to 0. -*/ - -/*! \fn QCPVector2D QCPVector2D::perpendicular() const - - Returns a vector perpendicular to this vector, with the same length. -*/ - -/*! \fn double QCPVector2D::dot() const - - Returns the dot/scalar product of this vector with the specified vector \a vec. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates to 0. -*/ -QCPVector2D::QCPVector2D() : - mX(0), - mY(0) -{ -} - -/*! - Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified - values. -*/ -QCPVector2D::QCPVector2D(double x, double y) : - mX(x), - mY(y) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPoint &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPointF &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Normalizes this vector. After this operation, the length of the vector is equal to 1. - - \see normalized, length, lengthSquared -*/ -void QCPVector2D::normalize() -{ - double len = length(); - mX /= len; - mY /= len; -} - -/*! - Returns a normalized version of this vector. The length of the returned vector is equal to 1. - - \see normalize, length, lengthSquared -*/ -QCPVector2D QCPVector2D::normalized() const -{ - QCPVector2D result(mX, mY); - result.normalize(); - return result; -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a start and \a end. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const -{ - QCPVector2D v(end-start); - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = v.dot(*this-start)/vLengthSqr; - if (mu < 0) - return (*this-start).lengthSquared(); - else if (mu > 1) - return (*this-end).lengthSquared(); - else - return ((start + mu*v)-*this).lengthSquared(); - } else - return (*this-start).lengthSquared(); -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a line. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QLineF &line) const -{ - return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); -} - -/*! - Returns the shortest distance of this vector (interpreted as a point) to the infinite straight - line given by a \a base point and a \a direction vector. - - \see distanceSquaredToLine -*/ -double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const -{ - return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); -} - -/*! - Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a - factor. -*/ -QCPVector2D &QCPVector2D::operator*=(double factor) -{ - mX *= factor; - mY *= factor; - return *this; -} - -/*! - Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a - divisor. -*/ -QCPVector2D &QCPVector2D::operator/=(double divisor) -{ - mX /= divisor; - mY /= divisor; - return *this; -} - -/*! - Adds the given \a vector to this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) -{ - mX += vector.mX; - mY += vector.mY; - return *this; -} - -/*! - subtracts the given \a vector from this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) -{ - mX -= vector.mX; - mY -= vector.mY; - return *this; -} -/* end of 'src/vector2d.cpp' */ - - -/* including file 'src/painter.cpp', size 8670 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPainter -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPainter - \brief QPainter subclass used internally - - This QPainter subclass is used to provide some extended functionality e.g. for tweaking position - consistency between antialiased and non-antialiased painting. Further it provides workarounds - for QPainter quirks. - - \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and - restore. So while it is possible to pass a QCPPainter instance to a function that expects a - QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because - it will call the base class implementations of the functions actually hidden by QCPPainter). -*/ - -/*! - Creates a new QCPPainter instance and sets default values -*/ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) -{ - // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and - // a call to begin() will follow -} - -/*! - Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just - like the analogous QPainter constructor, begins painting on \a device immediately. - - Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. -*/ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif -} - -/*! - Sets the pen of the painter and applies certain fixes to it, depending on the mode of this - QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QPen &pen) -{ - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QColor &color) -{ - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(Qt::PenStyle penStyle) -{ - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when - antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to - integer coordinates and then passes it to the original drawLine. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::drawLine(const QLineF &line) -{ - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); - else - QPainter::drawLine(line.toLine()); -} - -/*! - Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint - with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between - antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for - AA/Non-AA painting). -*/ -void QCPPainter::setAntialiasing(bool enabled) -{ - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) - { - mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs - { - if (mIsAntialiasing) - translate(0.5, 0.5); - else - translate(-0.5, -0.5); - } - } -} - -/*! - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setModes(QCPPainter::PainterModes modes) -{ - mModes = modes; -} - -/*! - Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a - device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, - all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that - behaviour. - - The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets - the render hint as appropriate. - - \note this function hides the non-virtual base class implementation. -*/ -bool QCPPainter::begin(QPaintDevice *device) -{ - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif - return result; -} - -/*! \overload - - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) -{ - if (!enabled && mModes.testFlag(mode)) - mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) - mModes |= mode; -} - -/*! - Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see restore -*/ -void QCPPainter::save() -{ - mAntialiasingStack.push(mIsAntialiasing); - QPainter::save(); -} - -/*! - Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see save -*/ -void QCPPainter::restore() -{ - if (!mAntialiasingStack.isEmpty()) - mIsAntialiasing = mAntialiasingStack.pop(); - else - qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; - QPainter::restore(); -} - -/*! - Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen - overrides when the \ref pmNonCosmetic mode is set. -*/ -void QCPPainter::makeNonCosmetic() -{ - if (qFuzzyIsNull(pen().widthF())) - { - QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); - } -} -/* end of 'src/painter.cpp' */ - - -/* including file 'src/paintbuffer.cpp', size 18502 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPaintBuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPaintBuffer - \brief The abstract base class for paint buffers, which define the rendering backend - - This abstract base class defines the basic interface that a paint buffer needs to provide in - order to be usable by QCustomPlot. - - A paint buffer manages both a surface to draw onto, and the matching paint device. The size of - the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref - QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the - painting is complete, \ref donePainting is called, so the paint buffer implementation can do - clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color - using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the - previous frame. - - The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular - software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and - frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. - They are used automatically if \ref QCustomPlot::setOpenGl is enabled. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 - - Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the - responsibility to delete the painter after the painting operations are complete is given to the - caller of this method. - - Once you are done using the painter, delete the painter and call \ref donePainting. - - While a painter generated with this method is active, you must not call \ref setSize, \ref - setDevicePixelRatio or \ref clear. - - This method may return 0, if a painter couldn't be activated on the buffer. This usually - indicates a problem with the respective painting backend. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 - - Draws the contents of this buffer with the provided \a painter. This is the method that is used - to finally join all paint buffers and draw them onto the screen. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 - - Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the - named color \c Qt::transparent. - - This method must not be called if there is currently a painter (acquired with \ref startPainting) - active. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 - - Reallocates the internal buffer with the currently configured size (\ref setSize) and device - pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those - properties are changed on this paint buffer. - - \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method - in their constructor, to perform the first allocation (this can not be done by the base class - because calling pure virtual methods in base class constructors is not possible). -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of inline functions */ - -/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() - - If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, - call this method as soon as you are done with the painting operations and have deleted the - painter. - - paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The - default implementation does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. - - Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. -*/ -QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : - mSize(size), - mDevicePixelRatio(devicePixelRatio), - mInvalidated(true) -{ -} - -QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() -{ -} - -/*! - Sets the paint buffer size. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - If \a size is already the current buffer size, this method does nothing. -*/ -void QCPAbstractPaintBuffer::setSize(const QSize &size) -{ - if (mSize != size) - { - mSize = size; - reallocateBuffer(); - } -} - -/*! - Sets the invalidated flag to \a invalidated. - - This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer - instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered - layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, - QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also - replots them, instead of only the layer on which the replot was called. - - The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers - were added or removed from this buffer, or if they were reordered. It is set to false as soon as - all associated \ref QCPLayer instances are drawn onto the buffer. - - Under normal circumstances, it is not necessary to manually call this method. -*/ -void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) -{ - mInvalidated = invalidated; -} - -/*! - Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. - The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - \note This method is only available for Qt versions 5.4 and higher. -*/ -void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mDevicePixelRatio = ratio; - reallocateBuffer(); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; -#endif - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferPixmap - \brief A paint buffer based on QPixmap, using software raster rendering - - This paint buffer is the default and fall-back paint buffer which uses software rendering and - QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. -*/ - -/*! - Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if - applicable. -*/ -QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : - QCPAbstractPaintBuffer(size, devicePixelRatio) -{ - QCPPaintBufferPixmap::reallocateBuffer(); -} - -QCPPaintBufferPixmap::~QCPPaintBufferPixmap() -{ -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferPixmap::startPainting() -{ - QCPPainter *result = new QCPPainter(&mBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::draw(QCPPainter *painter) const -{ - if (painter && painter->isActive()) - painter->drawPixmap(0, 0, mBuffer); - else - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::clear(const QColor &color) -{ - mBuffer.fill(color); -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::reallocateBuffer() -{ - setInvalidated(); - if (!qFuzzyCompare(1.0, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBuffer = QPixmap(mSize*mDevicePixelRatio); - mBuffer.setDevicePixelRatio(mDevicePixelRatio); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; - mBuffer = QPixmap(mSize); -#endif - } else - { - mBuffer = QPixmap(mSize); - } -} - - -#ifdef QCP_OPENGL_PBUFFER -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlPbuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlPbuffer - \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. - (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a - devicePixelRatio, if applicable. - - The parameter \a multisamples defines how many samples are used per pixel. Higher values thus - result in higher quality antialiasing. If the specified \a multisamples value exceeds the - capability of the graphics hardware, the highest supported multisampling is used. -*/ -QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlPBuffer(0), - mMultisamples(qMax(0, multisamples)) -{ - QCPPaintBufferGlPbuffer::reallocateBuffer(); -} - -QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlPbuffer::startPainting() -{ - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - QCPPainter *result = new QCPPainter(mGlPBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlPBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::clear(const QColor &color) -{ - if (mGlPBuffer->isValid()) - { - mGlPBuffer->makeCurrent(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlPBuffer->doneCurrent(); - } else - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::reallocateBuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; - - QGLFormat format; - format.setAlpha(true); - format.setSamples(mMultisamples); - mGlPBuffer = new QGLPixelBuffer(mSize, format); -} -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlFbo -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlFbo - \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and - higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, - if applicable. - - All frame buffer objects shall share one OpenGL context and paint device, which need to be set up - externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref - QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot - instance. -*/ -QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlContext(glContext), - mGlPaintDevice(glPaintDevice), - mGlFrameBuffer(0) -{ - QCPPaintBufferGlFbo::reallocateBuffer(); -} - -QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() -{ - if (mGlFrameBuffer) - delete mGlFrameBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlFbo::startPainting() -{ - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return 0; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::donePainting() -{ - if (mGlFrameBuffer && mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - else - qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlFrameBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::clear(const QColor &color) -{ - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlFrameBuffer->release(); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::reallocateBuffer() -{ - // release and delete possibly existing framebuffer: - if (mGlFrameBuffer) - { - if (mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - delete mGlFrameBuffer; - mGlFrameBuffer = 0; - } - - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return; - } - - // create new fbo with appropriate size: - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples(mGlContext.data()->format().samples()); - frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); - if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) - mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); -#endif -} -#endif // QCP_OPENGL_FBO -/* end of 'src/paintbuffer.cpp' */ - - -/* including file 'src/layer.cpp', size 37064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayer - \brief A layer that may contain objects, to control the rendering order - - The Layering system of QCustomPlot is the mechanism to control the rendering order of the - elements inside the plot. - - It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of - one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, - QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers - bottom to top and successively draws the layerables of the layers into the paint buffer(s). - - A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base - class from which almost all visible objects derive, like axes, grids, graphs, items, etc. - - \section qcplayer-defaultlayers Default layers - - Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and - "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's - selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain - the default axes and legend, so they will be drawn above plottables. In the middle, there is the - "main" layer. It is initially empty and set as the current layer (see - QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this - layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong - tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind - everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of - course, the layer affiliation of the individual objects can be changed as required (\ref - QCPLayerable::setLayer). - - \section qcplayer-ordering Controlling the rendering order via layers - - Controlling the ordering of layerables in the plot is easy: Create a new layer in the position - you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the - current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the - objects normally. They will be placed on the new layer automatically, due to the current layer - setting. Alternatively you could have also ignored the current layer setting and just moved the - objects with \ref QCPLayerable::setLayer to the desired layer after creating them. - - It is also possible to move whole layers. For example, If you want the grid to be shown in front - of all plottables/items on the "main" layer, just move it above "main" with - QCustomPlot::moveLayer. - - The rendering order within one layer is simply by order of creation or insertion. The item - created last (or added last to the layer), is drawn on top of all other objects on that layer. - - When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below - the deleted layer, see QCustomPlot::removeLayer. - - \section qcplayer-buffering Replotting only a specific layer - - If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific - layer by calling \ref replot. In certain situations this can provide better replot performance, - compared with a full replot of all layers. Upon creation of a new layer, the layer mode is - initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref - QCustomPlot instance is the "overlay" layer, containing the selection rect. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPLayer::children() const - - Returns a list of all layerables on this layer. The order corresponds to the rendering order: - layerables with higher indices are drawn above layerables with lower indices. -*/ - -/*! \fn int QCPLayer::index() const - - Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be - accessed via \ref QCustomPlot::layer. - - Layers with higher indices will be drawn above layers with lower indices. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPLayer instance. - - Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. - - \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. - This check is only performed by \ref QCustomPlot::addLayer. -*/ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true), - mMode(lmLogical) -{ - // Note: no need to make sure layerName is unique, because layer - // management is done with QCustomPlot functions. -} - -QCPLayer::~QCPLayer() -{ - // If child layerables are still on this layer, detach them, so they don't try to reach back to this - // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted - // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to - // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) - qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; -} - -/*! - Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this - layer will be invisible. - - This function doesn't change the visibility property of the layerables (\ref - QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the - visibility of the parent layer into account. -*/ -void QCPLayer::setVisible(bool visible) -{ - mVisible = visible; -} - -/*! - Sets the rendering mode of this layer. - - If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by - the parent QCustomPlot instance. This means it may be replotted individually by calling \ref - QCPLayer::replot, without needing to replot all other layers. - - Layers which are set to \ref lmLogical (the default) are used only to define the rendering order - and can't be replotted individually. - - Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the - layers below, above and for the layer itself. This increases the memory consumption and - (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So - you should carefully choose which layers benefit from having their own paint buffer. A typical - example would be a layer which contains certain layerables (e.g. items) that need to be changed - and thus replotted regularly, while all other layerables on other layers stay static. By default, - only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection - rect. - - \see replot -*/ -void QCPLayer::setMode(QCPLayer::LayerMode mode) -{ - if (mMode != mode) - { - mMode = mode; - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } -} - -/*! \internal - - Draws the contents of this layer with the provided \a painter. - - \see replot, drawToPaintBuffer -*/ -void QCPLayer::draw(QCPPainter *painter) -{ - foreach (QCPLayerable *child, mChildren) - { - if (child->realVisibility()) - { - painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); - painter->restore(); - } - } -} - -/*! \internal - - Draws the contents of this layer into the paint buffer which is associated with this layer. The - association is established by the parent QCustomPlot, which manages all paint buffers (see \ref - QCustomPlot::setupPaintBuffers). - - \see draw -*/ -void QCPLayer::drawToPaintBuffer() -{ - if (!mPaintBuffer.isNull()) - { - if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) - { - if (painter->isActive()) - draw(painter); - else - qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; - delete painter; - mPaintBuffer.data()->donePainting(); - } else - qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; -} - -/*! - If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only - the layerables on this specific layer, without the need to replot all other layers (as a call to - \ref QCustomPlot::replot would do). - - If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on - the parent QCustomPlot instance. - - QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering - has changed since the last full replot and the other paint buffers were thus invalidated. - - \see draw -*/ -void QCPLayer::replot() -{ - if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) - { - if (!mPaintBuffer.isNull()) - { - mPaintBuffer.data()->clear(Qt::transparent); - drawToPaintBuffer(); - mPaintBuffer.data()->setInvalidated(false); - mParentPlot->update(); - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } else if (mMode == lmLogical) - mParentPlot->replot(); -} - -/*! \internal - - Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will - be prepended to the list, i.e. be drawn beneath the other layerables already in the list. - - This function does not change the \a mLayer member of \a layerable to this layer. (Use - QCPLayerable::setLayer to change the layer of an object, not this function.) - - \see removeChild -*/ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) -{ - if (!mChildren.contains(layerable)) - { - if (prepend) - mChildren.prepend(layerable); - else - mChildren.append(layerable); - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); -} - -/*! \internal - - Removes the \a layerable from the list of this layer. - - This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer - to change the layer of an object, not this function.) - - \see addChild -*/ -void QCPLayer::removeChild(QCPLayerable *layerable) -{ - if (mChildren.removeOne(layerable)) - { - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayerable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayerable - \brief Base class for all drawable objects - - This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid - etc. - - Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking - the layers accordingly. - - For details about the layering mechanism, see the QCPLayer documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const - - Returns the parent layerable of this layerable. The parent layerable is used to provide - visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables - only get drawn if their parent layerables are visible, too. - - Note that a parent layerable is not necessarily also the QObject parent for memory management. - Further, a layerable doesn't always have a parent layerable, so this function may return 0. - - A parent layerable is set implicitly when placed inside layout elements and doesn't need to be - set manually by the user. -*/ - -/* end documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 - \internal - - This function applies the default antialiasing setting to the specified \a painter, using the - function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when - \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing - setting may be specified individually, this function should set the antialiasing state of the - most prominent entity. In this case however, the \ref draw function usually calls the specialized - versions of this function before drawing each entity, effectively overriding the setting of the - default antialiasing hint. - - First example: QCPGraph has multiple entities that have an antialiasing setting: The graph - line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, - QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only - the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's - antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and - QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw - calls the respective specialized applyAntialiasingHint function. - - Second example: QCPItemLine consists only of a line so there is only one antialiasing - setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by - all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the - respective layerable subclass.) Consequently it only has the normal - QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to - care about setting any antialiasing states, because the default antialiasing hint is already set - on the painter when the \ref draw function is called, and that's the state it wants to draw the - line with. -*/ - -/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 - \internal - - This function draws the layerable with the specified \a painter. It is only called by - QCustomPlot, if the layerable is visible (\ref setVisible). - - Before this function is called, the painter's antialiasing state is set via \ref - applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was - set to \ref clipRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); - - This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to - a different layer. - - \see setLayer -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPLayerable instance. - - Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the - derived classes. - - If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a - targetLayer is an empty string, it places itself on the current layer of the plot (see \ref - QCustomPlot::setCurrentLayer). - - It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later - time with \ref initializeParentPlot. - - The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable - parents are mainly used to control visibility in a hierarchy of layerables. This means a - layerable is only drawn, if all its ancestor layerables are also visible. Note that \a - parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a - plot does. It is not uncommon to set the QObject-parent to something else in the constructors of - QCPLayerable subclasses, to guarantee a working destruction hierarchy. -*/ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) -{ - if (mParentPlot) - { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) - qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; - } -} - -QCPLayerable::~QCPLayerable() -{ - if (mLayer) - { - mLayer->removeChild(this); - mLayer = 0; - } -} - -/*! - Sets the visibility of this layerable object. If an object is not visible, it will not be drawn - on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not - possible. -*/ -void QCPLayerable::setVisible(bool on) -{ - mVisible = on; -} - -/*! - Sets the \a layer of this layerable object. The object will be placed on top of the other objects - already on \a layer. - - If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or - interact/receive events). - - Returns true if the layer of this layerable was successfully changed to \a layer. -*/ -bool QCPLayerable::setLayer(QCPLayer *layer) -{ - return moveToLayer(layer, false); -} - -/*! \overload - Sets the layer of this layerable object by name - - Returns true on success, i.e. if \a layerName is a valid layer name. -*/ -bool QCPLayerable::setLayer(const QString &layerName) -{ - if (!mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (QCPLayer *layer = mParentPlot->layer(layerName)) - { - return setLayer(layer); - } else - { - qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; - return false; - } -} - -/*! - Sets whether this object will be drawn antialiased or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPLayerable::setAntialiased(bool enabled) -{ - mAntialiased = enabled; -} - -/*! - Returns whether this layerable is visible, taking the visibility of the layerable parent and the - visibility of this layerable's layer into account. This is the method that is consulted to decide - whether a layerable shall be drawn or not. - - If this layerable has a direct layerable parent (usually set via hierarchies implemented in - subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this - layerable has its visibility set to true and the parent layerable's \ref realVisibility returns - true. -*/ -bool QCPLayerable::realVisibility() const -{ - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); -} - -/*! - This function is used to decide whether a click hits a layerable object or not. - - \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the - shortest pixel distance of this point to the object. If the object is either invisible or the - distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the - object is not selectable, -1.0 is returned, too. - - If the object is represented not by single lines but by an area like a \ref QCPItemText or the - bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In - these cases this function thus returns a constant value greater zero but still below the parent - plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). - - Providing a constant value for area objects allows selecting line objects even when they are - obscured by such area objects, by clicking close to the lines (i.e. closer than - 0.99*selectionTolerance). - - The actual setting of the selection state is not done by this function. This is handled by the - parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified - via the \ref selectEvent/\ref deselectEvent methods. - - \a details is an optional output parameter. Every layerable subclass may place any information - in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot - decides on the basis of this selectTest call, that the object was successfully selected. The - subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part - objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked - is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be - placed in \a details. So in the subsequent \ref selectEvent, the decision which part was - selected doesn't have to be done a second time for a single selection operation. - - You may pass 0 as \a details to indicate that you are not interested in those selection details. - - \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions -*/ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) - return -1.0; -} - -/*! \internal - - Sets the parent plot of this layerable. Use this function once to set the parent plot if you have - passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to - another one. - - Note that, unlike when passing a non-null parent plot in the constructor, this function does not - make \a parentPlot the QObject-parent of this layerable. If you want this, call - QObject::setParent(\a parentPlot) in addition to this function. - - Further, you will probably want to set a layer (\ref setLayer) after calling this function, to - make the layerable appear on the QCustomPlot. - - The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized - so they can react accordingly (e.g. also initialize the parent plot of child layerables, like - QCPLayout does). -*/ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) -{ - if (mParentPlot) - { - qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; - return; - } - - if (!parentPlot) - qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - - mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); -} - -/*! \internal - - Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not - become the QObject-parent (for memory management) of this layerable. - - The parent layerable has influence on the return value of the \ref realVisibility method. Only - layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be - drawn. - - \see realVisibility -*/ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) -{ - mParentLayerable = parentLayerable; -} - -/*! \internal - - Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to - the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is - false, the object will be appended. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) -{ - if (layer && !mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (layer && layer->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; - return false; - } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); - mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - emit layerChanged(mLayer); - return true; -} - -/*! \internal - - Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a - localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is - controlled via \a overrideElement. -*/ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const -{ - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); - else - painter->setAntialiasing(localAntialiased); -} - -/*! \internal - - This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting - of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the - parent plot is set at a later time. - - For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any - QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level - element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To - propagate the parent plot to all the children of the hierarchy, the top level element then uses - this function to pass the parent plot on to its child elements. - - The default implementation does nothing. - - \see initializeParentPlot -*/ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - -/*! \internal - - Returns the selection category this layerable shall belong to. The selection category is used in - conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and - which aren't. - - Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref - QCP::iSelectOther. This is what the default implementation returns. - - \see QCustomPlot::setInteractions -*/ -QCP::Interaction QCPLayerable::selectionCategory() const -{ - return QCP::iSelectOther; -} - -/*! \internal - - Returns the clipping rectangle of this layerable object. By default, this is the viewport of the - parent QCustomPlot. Specific subclasses may reimplement this function to provide different - clipping rects. - - The returned clipping rect is set on the painter before the draw function of the respective - object is called. -*/ -QRect QCPLayerable::clipRect() const -{ - if (mParentPlot) - return mParentPlot->viewport(); - else - return QRect(); -} - -/*! \internal - - This event is called when the layerable shall be selected, as a consequence of a click by the - user. Subclasses should react to it by setting their selection state appropriately. The default - implementation does nothing. - - \a event is the mouse event that caused the selection. \a additive indicates, whether the user - was holding the multi-select-modifier while performing the selection (see \ref - QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled - (i.e. become selected when unselected and unselected when selected). - - Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. - returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). - The \a details data you output from \ref selectTest is fed back via \a details here. You may - use it to transport any kind of information from the selectTest to the possibly subsequent - selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable - that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need - to do the calculation again to find out which part was actually clicked. - - \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must - set the value either to true or false, depending on whether the selection state of this layerable - was actually changed. For layerables that only are selectable as a whole and not in parts, this - is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the - selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the - layerable was previously unselected and now is switched to the selected state. - - \see selectTest, deselectEvent -*/ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) -} - -/*! \internal - - This event is called when the layerable shall be deselected, either as consequence of a user - interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by - unsetting their selection appropriately. - - just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must - return true or false when the selection state of this layerable has changed or not changed, - respectively. - - \see selectTest, selectEvent -*/ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) -{ - Q_UNUSED(selectionStateChanged) -} - -/*! - This event gets called when the user presses a mouse button while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - QCustomPlot uses an event propagation system that works the same as Qt's system. If your - layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in - its reimplementation, the event will be propagated to the next layerable in the stacking order. - - Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and - will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse - interaction (a "mouse interaction" in this context ends with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user moves the mouse while holding a mouse button, after this - layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user releases the mouse button, after this layerable has become - the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user presses the mouse button a second time in a double-click, - while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a - preceding call to \ref selectTest. - - The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the - case of a double-click, the event succession is - pressEvent – releaseEvent – doubleClickEvent – releaseEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, - it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent - and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends - with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent -*/ -void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user turns the mouse scroll wheel while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). - - The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for - single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may - accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has - very smooth steps or none at all, the delta may be smaller. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent -*/ -void QCPLayerable::wheelEvent(QWheelEvent *event) -{ - event->ignore(); -} -/* end of 'src/layer.cpp' */ - - -/* including file 'src/axis/range.cpp', size 12221 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPRange -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPRange - \brief Represents the range an axis is encompassing. - - contains a \a lower and \a upper double value and provides convenience input, output and - modification functions. - - \see QCPAxis::setRange -*/ - -/* start of documentation of inline functions */ - -/*! \fn double QCPRange::size() const - - Returns the size of the range, i.e. \a upper-\a lower -*/ - -/*! \fn double QCPRange::center() const - - Returns the center of the range, i.e. (\a upper+\a lower)*0.5 -*/ - -/*! \fn void QCPRange::normalize() - - Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are - swapped. -*/ - -/*! \fn bool QCPRange::contains(double value) const - - Returns true when \a value lies within or exactly on the borders of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator+=(const double& value) - - Adds \a value to both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator-=(const double& value) - - Subtracts \a value from both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator*=(const double& value) - - Multiplies both boundaries of the range by \a value. -*/ - -/*! \fn QCPRange &QCPRange::operator/=(const double& value) - - Divides both boundaries of the range by \a value. -*/ - -/* end of documentation of inline functions */ - -/*! - Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller - intervals would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a minimum magnitude of roughly 1e-308. - - \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining underflowing ranges. - - \see validRange, maxRange -*/ -const double QCPRange::minRange = 1e-280; - -/*! - Maximum values (negative and positive) the range will accept in range-changing functions. - Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a maximum magnitude of roughly 1e308. - - \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining overflowing ranges. - - \see validRange, minRange -*/ -const double QCPRange::maxRange = 1e250; - -/*! - Constructs a range with \a lower and \a upper set to zero. -*/ -QCPRange::QCPRange() : - lower(0), - upper(0) -{ -} - -/*! \overload - - Constructs a range with the specified \a lower and \a upper values. - - The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically - smaller than \a upper, they will be swapped. -*/ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) -{ - normalize(); -} - -/*! \overload - - Expands this range such that \a otherRange is contained in the new range. It is assumed that both - this range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, it will be replaced by the respective bound - of \a otherRange. - - If \a otherRange is already inside the current range, this function does nothing. - - \see expanded -*/ -void QCPRange::expand(const QCPRange &otherRange) -{ - if (lower > otherRange.lower || qIsNaN(lower)) - lower = otherRange.lower; - if (upper < otherRange.upper || qIsNaN(upper)) - upper = otherRange.upper; -} - -/*! \overload - - Expands this range such that \a includeCoord is contained in the new range. It is assumed that - this range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the respective bound will be set to \a - includeCoord. - - If \a includeCoord is already inside the current range, this function does nothing. - - \see expand -*/ -void QCPRange::expand(double includeCoord) -{ - if (lower > includeCoord || qIsNaN(lower)) - lower = includeCoord; - if (upper < includeCoord || qIsNaN(upper)) - upper = includeCoord; -} - - -/*! \overload - - Returns an expanded range that contains this and \a otherRange. It is assumed that both this - range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be taken from - \a otherRange. - - \see expand -*/ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const -{ - QCPRange result = *this; - result.expand(otherRange); - return result; -} - -/*! \overload - - Returns an expanded range that includes the specified \a includeCoord. It is assumed that this - range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a - includeCoord. - - \see expand -*/ -QCPRange QCPRange::expanded(double includeCoord) const -{ - QCPRange result = *this; - result.expand(includeCoord); - return result; -} - -/*! - Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a - upperBound. If possible, the size of the current range is preserved in the process. - - If the range shall only be bounded at the lower side, you can set \a upperBound to \ref - QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref - QCPRange::maxRange. -*/ -QCPRange QCPRange::bounded(double lowerBound, double upperBound) const -{ - if (lowerBound > upperBound) - qSwap(lowerBound, upperBound); - - QCPRange result(lower, upper); - if (result.lower < lowerBound) - { - result.lower = lowerBound; - result.upper = lowerBound + size(); - if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.upper = upperBound; - } else if (result.upper > upperBound) - { - result.upper = upperBound; - result.lower = upperBound - size(); - if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.lower = lowerBound; - } - - return result; -} - -/*! - Returns a sanitized version of the range. Sanitized means for logarithmic scales, that - the range won't span the positive and negative sign domain, i.e. contain zero. Further - \a lower will always be numerically smaller (or equal) to \a upper. - - If the original range does span positive and negative sign domains or contains zero, - the returned range will try to approximate the original range as good as possible. - If the positive interval of the original range is wider than the negative interval, the - returned range will only contain the positive interval, with lower bound set to \a rangeFac or - \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval - is wider than the positive interval, this time by changing the \a upper bound. -*/ -QCPRange QCPRange::sanitizedForLogScale() const -{ - double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - // can't have range spanning negative and positive values in log plot, so change range to fix it - //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) - { - // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) - { - // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) - { - // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) - { - // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else - { - // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } - } - // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange && - !(lower > 0 && qIsInf(upper/lower)) && - !(upper < 0 && qIsInf(lower/upper))); -} - -/*! - \overload - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(const QCPRange &range) -{ - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - !(range.lower > 0 && qIsInf(range.upper/range.lower)) && - !(range.upper < 0 && qIsInf(range.lower/range.upper))); -} -/* end of 'src/axis/range.cpp' */ - - -/* including file 'src/selection.cpp', size 21906 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataRange -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataRange - \brief Describes a data range given by begin and end index - - QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index - of a contiguous set of data points. The end index points to the data point above the last data point that's part of - the data range, similarly to the nomenclature used in standard iterators. - - Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and - modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is - used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref - QCPDataSelection is thus used. - - Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, - e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref - contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be - used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding - \ref QCPDataSelection. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and - QCPDataRange. - - \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval - in floating point plot coordinates, e.g. the current axis range. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataRange::size() const - - Returns the number of data points described by this data range. This is equal to the end index - minus the begin index. - - \see length -*/ - -/*! \fn int QCPDataRange::length() const - - Returns the number of data points described by this data range. Equivalent to \ref size. -*/ - -/*! \fn void QCPDataRange::setBegin(int begin) - - Sets the begin of this data range. The \a begin index points to the first data point that is part - of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setEnd -*/ - -/*! \fn void QCPDataRange::setEnd(int end) - - Sets the end of this data range. The \a end index points to the data point just above the last - data point that is part of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setBegin -*/ - -/*! \fn bool QCPDataRange::isValid() const - - Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and - an end index greater or equal to the begin index. - - \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods - (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's - methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary - invalid begin/end values while manipulating the range. An invalid range is not necessarily empty - (\ref isEmpty), since its \ref length can be negative and thus non-zero. -*/ - -/*! \fn bool QCPDataRange::isEmpty() const - - Returns whether this range is empty, i.e. whether its begin index equals its end index. - - \see size, length -*/ - -/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const - - Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end - indices, respectively. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataRange, with begin and end set to 0. -*/ -QCPDataRange::QCPDataRange() : - mBegin(0), - mEnd(0) -{ -} - -/*! - Creates a QCPDataRange, initialized with the specified \a begin and \a end. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). -*/ -QCPDataRange::QCPDataRange(int begin, int end) : - mBegin(begin), - mEnd(end) -{ -} - -/*! - Returns a data range that matches this data range, except that parts exceeding \a other are - excluded. - - This method is very similar to \ref intersection, with one distinction: If this range and the \a - other range share no intersection, the returned data range will be empty with begin and end set - to the respective boundary side of \a other, at which this range is residing. (\ref intersection - would just return a range with begin and end set to 0.) -*/ -QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const -{ - QCPDataRange result(intersection(other)); - if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value - { - if (mEnd <= other.mBegin) - result = QCPDataRange(other.mBegin, other.mBegin); - else - result = QCPDataRange(other.mEnd, other.mEnd); - } - return result; -} - -/*! - Returns a data range that contains both this data range as well as \a other. -*/ -QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const -{ - return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); -} - -/*! - Returns the data range which is contained in both this data range and \a other. - - This method is very similar to \ref bounded, with one distinction: If this range and the \a other - range share no intersection, the returned data range will be empty with begin and end set to 0. - (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, - depending on which side this range is on.) - - \see QCPDataSelection::intersection -*/ -QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const -{ - QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); - if (result.isValid()) - return result; - else - return QCPDataRange(); -} - -/*! - Returns whether this data range and \a other share common data points. - - \see intersection, contains -*/ -bool QCPDataRange::intersects(const QCPDataRange &other) const -{ - return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || - (mEnd <= other.mBegin && mEnd < other.mEnd) ); -} - -/*! - Returns whether all data points described by this data range are also in \a other. - - \see intersects -*/ -bool QCPDataRange::contains(const QCPDataRange &other) const -{ - return mBegin <= other.mBegin && mEnd >= other.mEnd; -} - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataSelection -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataSelection - \brief Describes a data set by holding multiple QCPDataRange instances - - QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly - disjoint) set of data selection. - - The data selection can be modified with addition and subtraction operators which take - QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and - \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. - - The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange - instances. QCPDataSelection automatically simplifies when using the addition/subtraction - operators. The only case when \ref simplify is left to the user, is when calling \ref - addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data - ranges will be added to the selection successively and the overhead for simplifying after each - iteration shall be avoided. In this case, you should make sure to call \ref simplify after - completing the operation. - - Use \ref enforceType to bring the data selection into a state complying with the constraints for - selections defined in \ref QCP::SelectionType. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and - QCPDataRange. - - \section qcpdataselection-iterating Iterating over a data selection - - As an example, the following code snippet calculates the average value of a graph's data - \ref QCPAbstractPlottable::selection "selection": - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 - -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataSelection::dataRangeCount() const - - Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref - dataRange via their index. - - \see dataRange, dataPointCount -*/ - -/*! \fn QList QCPDataSelection::dataRanges() const - - Returns all data ranges that make up the data selection. If the data selection is simplified (the - usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point - index. - - \see dataRange -*/ - -/*! \fn bool QCPDataSelection::isEmpty() const - - Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection - instance. - - \see dataRangeCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataSelection. -*/ -QCPDataSelection::QCPDataSelection() -{ -} - -/*! - Creates a QCPDataSelection containing the provided \a range. -*/ -QCPDataSelection::QCPDataSelection(const QCPDataRange &range) -{ - mDataRanges.append(range); -} - -/*! - Returns true if this selection is identical (contains the same data ranges with the same begin - and end indices) to \a other. - - Note that both data selections must be in simplified state (the usual state of the selection, see - \ref simplify) for this operator to return correct results. -*/ -bool QCPDataSelection::operator==(const QCPDataSelection &other) const -{ - if (mDataRanges.size() != other.mDataRanges.size()) - return false; - for (int i=0; i= other.end()) - break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this - - if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored - { - if (thisBegin >= other.begin()) // range leading segment is encompassed - { - if (thisEnd <= other.end()) // range fully encompassed, remove completely - { - mDataRanges.removeAt(i); - continue; - } else // only leading segment is encompassed, trim accordingly - mDataRanges[i].setBegin(other.end()); - } else // leading segment is not encompassed - { - if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly - { - mDataRanges[i].setEnd(other.begin()); - } else // other lies inside this range, so split range - { - mDataRanges[i].setEnd(other.begin()); - mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); - break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here - } - } - } - ++i; - } - - return *this; -} - -/*! - Returns the total number of data points contained in all data ranges that make up this data - selection. -*/ -int QCPDataSelection::dataPointCount() const -{ - int result = 0; - for (int i=0; i= 0 && index < mDataRanges.size()) - { - return mDataRanges.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of range:" << index; - return QCPDataRange(); - } -} - -/*! - Returns a \ref QCPDataRange which spans the entire data selection, including possible - intermediate segments which are not part of the original data selection. -*/ -QCPDataRange QCPDataSelection::span() const -{ - if (isEmpty()) - return QCPDataRange(); - else - return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); -} - -/*! - Adds the given \a dataRange to this data selection. This is equivalent to the += operator but - allows disabling immediate simplification by setting \a simplify to false. This can improve - performance if adding a very large amount of data ranges successively. In this case, make sure to - call \ref simplify manually, after the operation. -*/ -void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) -{ - mDataRanges.append(dataRange); - if (simplify) - this->simplify(); -} - -/*! - Removes all data ranges. The data selection then contains no data points. - - \ref isEmpty -*/ -void QCPDataSelection::clear() -{ - mDataRanges.clear(); -} - -/*! - Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent - or overlapping ranges. This can reduce the number of individual data ranges in the selection, and - prevents possible double-counting when iterating over the data points held by the data ranges. - - This method is automatically called when using the addition/subtraction operators. The only case - when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a - simplify explicitly set to false. -*/ -void QCPDataSelection::simplify() -{ - // remove any empty ranges: - for (int i=mDataRanges.size()-1; i>=0; --i) - { - if (mDataRanges.at(i).isEmpty()) - mDataRanges.removeAt(i); - } - if (mDataRanges.isEmpty()) - return; - - // sort ranges by starting value, ascending: - std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); - - // join overlapping/contiguous ranges: - int i = 1; - while (i < mDataRanges.size()) - { - if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list - { - mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); - mDataRanges.removeAt(i); - } else - ++i; - } -} - -/*! - Makes sure this data selection conforms to the specified \a type selection type. Before the type - is enforced, \ref simplify is called. - - Depending on \a type, enforcing means adding new data points that were previously not part of the - selection, or removing data points from the selection. If the current selection already conforms - to \a type, the data selection is not changed. - - \see QCP::SelectionType -*/ -void QCPDataSelection::enforceType(QCP::SelectionType type) -{ - simplify(); - switch (type) - { - case QCP::stNone: - { - mDataRanges.clear(); - break; - } - case QCP::stWhole: - { - // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) - break; - } - case QCP::stSingleData: - { - // reduce all data ranges to the single first data point: - if (!mDataRanges.isEmpty()) - { - if (mDataRanges.size() > 1) - mDataRanges = QList() << mDataRanges.first(); - if (mDataRanges.first().length() > 1) - mDataRanges.first().setEnd(mDataRanges.first().begin()+1); - } - break; - } - case QCP::stDataRange: - { - mDataRanges = QList() << span(); - break; - } - case QCP::stMultipleDataRanges: - { - // this is the selection type that allows all concievable combinations of ranges, so do nothing - break; - } - } -} - -/*! - Returns true if the data selection \a other is contained entirely in this data selection, i.e. - all data point indices that are in \a other are also in this data selection. - - \see QCPDataRange::contains -*/ -bool QCPDataSelection::contains(const QCPDataSelection &other) const -{ - if (other.isEmpty()) return false; - - int otherIndex = 0; - int thisIndex = 0; - while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) - { - if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) - ++otherIndex; - else - ++thisIndex; - } - return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this -} - -/*! - Returns a data selection containing the points which are both in this data selection and in the - data range \a other. - - A common use case is to limit an unknown data selection to the valid range of a data container, - using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned - data selection without exceeding the data container's bounds. -*/ -QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const -{ - QCPDataSelection result; - for (int i=0; iorientation() == Qt::Horizontal) - return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); - else - return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); - } else - { - qDebug() << Q_FUNC_INFO << "called with axis zero"; - return QCPRange(); - } -} - -/*! - Sets the pen that will be used to draw the selection rect outline. - - \see setBrush -*/ -void QCPSelectionRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used to fill the selection rect. By default the selection rect is not - filled, i.e. \a brush is Qt::NoBrush. - - \see setPen -*/ -void QCPSelectionRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - If there is currently a selection interaction going on (\ref isActive), the interaction is - canceled. The selection rect will emit the \ref canceled signal. -*/ -void QCPSelectionRect::cancel() -{ - if (mActive) - { - mActive = false; - emit canceled(mRect, 0); - } -} - -/*! \internal - - This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. - The default implementation sets the selection rect to active, initializes the selection rect - geometry and emits the \ref started signal. -*/ -void QCPSelectionRect::startSelection(QMouseEvent *event) -{ - mActive = true; - mRect = QRect(event->pos(), event->pos()); - emit started(event); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs - to update its geometry. The default implementation updates the rect and emits the \ref changed - signal. -*/ -void QCPSelectionRect::moveSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - emit changed(mRect, event); - layer()->replot(); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has - finished by the user releasing the mouse button. The default implementation deactivates the - selection rect and emits the \ref accepted signal. -*/ -void QCPSelectionRect::endSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - mActive = false; - emit accepted(mRect, event); -} - -/*! \internal - - This method is called by QCustomPlot when a key has been pressed by the user while the selection - rect interaction is active. The default implementation allows to \ref cancel the interaction by - hitting the escape key. -*/ -void QCPSelectionRect::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape && mActive) - { - mActive = false; - emit canceled(mRect, event); - } -} - -/* inherits documentation from base class */ -void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/*! \internal - - If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. - - \seebaseclassmethod -*/ -void QCPSelectionRect::draw(QCPPainter *painter) -{ - if (mActive) - { - painter->setPen(mPen); - painter->setBrush(mBrush); - painter->drawRect(mRect); - } -} -/* end of 'src/selectionrect.cpp' */ - - -/* including file 'src/layout.cpp', size 79064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPMarginGroup -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPMarginGroup - \brief A margin group allows synchronization of margin sides if working with multiple layout elements. - - QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that - they will all have the same size, based on the largest required margin in the group. - - \n - \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" - \n - - In certain situations it is desirable that margins at specific sides are synchronized across - layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will - provide a cleaner look to the user if the left and right margins of the two axis rects are of the - same size. The left axis of the top axis rect will then be at the same horizontal position as the - left axis of the lower axis rect, making them appear aligned. The same applies for the right - axes. This is what QCPMarginGroup makes possible. - - To add/remove a specific side of a layout element to/from a margin group, use the \ref - QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call - \ref clear, or just delete the margin group. - - \section QCPMarginGroup-example Example - - First create a margin group: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 - Then set this group on the layout element sides: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 - Here, we've used the first two axis rects of the plot and synchronized their left margins with - each other and their right margins with each other. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const - - Returns a list of all layout elements that have their margin \a side associated with this margin - group. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPMarginGroup instance in \a parentPlot. -*/ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) -{ - mChildren.insert(QCP::msLeft, QList()); - mChildren.insert(QCP::msRight, QList()); - mChildren.insert(QCP::msTop, QList()); - mChildren.insert(QCP::msBottom, QList()); -} - -QCPMarginGroup::~QCPMarginGroup() -{ - clear(); -} - -/*! - Returns whether this margin group is empty. If this function returns true, no layout elements use - this margin group to synchronize margin sides. -*/ -bool QCPMarginGroup::isEmpty() const -{ - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - if (!it.value().isEmpty()) - return false; - } - return true; -} - -/*! - Clears this margin group. The synchronization of the margin sides that use this margin group is - lifted and they will use their individual margin sizes again. -*/ -void QCPMarginGroup::clear() -{ - // make all children remove themselves from this margin group: - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - const QList elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild - } -} - -/*! \internal - - Returns the synchronized common margin for \a side. This is the margin value that will be used by - the layout element on the respective side, if it is part of this margin group. - - The common margin is calculated by requesting the automatic margin (\ref - QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin - group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into - account, too.) -*/ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const -{ - // query all automatic margins of the layout elements in this margin group side and find maximum: - int result = 0; - const QList elements = mChildren.value(side); - for (int i=0; iautoMargins().testFlag(side)) - continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) - result = m; - } - return result; -} - -/*! \internal - - Adds \a element to the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].contains(element)) - mChildren[side].append(element); - else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); -} - -/*! \internal - - Removes \a element from the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutElement - \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". - - This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. - - A Layout element is a rectangular object which can be placed in layouts. It has an outer rect - (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference - between outer and inner rect is called its margin. The margin can either be set to automatic or - manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be - set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, - the layout element subclass will control the value itself (via \ref calculateAutoMargin). - - Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level - layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref - QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. - - Thus in QCustomPlot one can divide layout elements into two categories: The ones that are - invisible by themselves, because they don't draw anything. Their only purpose is to manage the - position and size of other layout elements. This category of layout elements usually use - QCPLayout as base class. Then there is the category of layout elements which actually draw - something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does - not necessarily mean that the latter category can't have child layout elements. QCPLegend for - instance, actually derives from QCPLayoutGrid and the individual legend items are child layout - elements in the grid layout. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayout *QCPLayoutElement::layout() const - - Returns the parent layout of this layout element. -*/ - -/*! \fn QRect QCPLayoutElement::rect() const - - Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref - setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). - - In some cases, the area between outer and inner rect is left blank. In other cases the margin - area is used to display peripheral graphics while the main content is in the inner rect. This is - where automatic margin calculation becomes interesting because it allows the layout element to - adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect - draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if - \ref setAutoMargins is enabled) according to the space required by the labels of the axes. - - \see outerRect -*/ - -/*! \fn QRect QCPLayoutElement::outerRect() const - - Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the - margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref - setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. - - \see rect -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutElement and sets default values. -*/ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mSizeConstraintRect(scrInnerRect), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) -{ -} - -QCPLayoutElement::~QCPLayoutElement() -{ - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any - // unregister at layout: - if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); -} - -/*! - Sets the outer rect of this layout element. If the layout element is inside a layout, the layout - sets the position and size of this layout element using this function. - - Calling this function externally has no effect, since the layout will overwrite any changes to - the outer rect upon the next replot. - - The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. - - \see rect -*/ -void QCPLayoutElement::setOuterRect(const QRect &rect) -{ - if (mOuterRect != rect) - { - mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all - sides, this function is used to manually set the margin on those sides. Sides that are still set - to be handled automatically are ignored and may have any value in \a margins. - - The margin is the distance between the outer rect (controlled by the parent layout via \ref - setOuterRect) and the inner \ref rect (which usually contains the main content of this layout - element). - - \see setAutoMargins -*/ -void QCPLayoutElement::setMargins(const QMargins &margins) -{ - if (mMargins != margins) - { - mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - If \ref setAutoMargins is enabled on some or all margins, this function is used to provide - minimum values for those margins. - - The minimum values are not enforced on margin sides that were set to be under manual control via - \ref setAutoMargins. - - \see setAutoMargins -*/ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) -{ - if (mMinimumMargins != margins) - { - mMinimumMargins = margins; - } -} - -/*! - Sets on which sides the margin shall be calculated automatically. If a side is calculated - automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is - set to be controlled manually, the value may be specified with \ref setMargins. - - Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref - setMarginGroup), to synchronize (align) it with other layout elements in the plot. - - \see setMinimumMargins, setMargins, QCP::MarginSide -*/ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) -{ - mAutoMargins = sides; -} - -/*! - Sets the minimum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - If the parent layout size is not sufficient to satisfy all minimum size constraints of its child - layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot - propagates the layout's size constraints to the outside by setting its own minimum QWidget size - accordingly, so violations of \a size should be exceptions. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(const QSize &size) -{ - if (mMinimumSize != size) - { - mMinimumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the minimum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(int width, int height) -{ - setMinimumSize(QSize(width, height)); -} - -/*! - Sets the maximum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(const QSize &size) -{ - if (mMaximumSize != size) - { - mMaximumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the maximum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(int width, int height) -{ - setMaximumSize(QSize(width, height)); -} - -/*! - Sets to which rect of a layout element the size constraints apply. Size constraints can be set - via \ref setMinimumSize and \ref setMaximumSize. - - The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis - labels), whereas the inner rect (\ref rect) does not. - - \see setMinimumSize, setMaximumSize -*/ -void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) -{ - if (mSizeConstraintRect != constraintRect) - { - mSizeConstraintRect = constraintRect; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! - Sets the margin \a group of the specified margin \a sides. - - Margin groups allow synchronizing specified margins across layout elements, see the documentation - of \ref QCPMarginGroup. - - To unset the margin group of \a sides, set \a group to 0. - - Note that margin groups only work for margin sides that are set to automatic (\ref - setAutoMargins). - - \see QCP::MarginSide -*/ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) -{ - QVector sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; iremoveChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there - { - mMarginGroups.remove(side); - } else // setting to a new group - { - mMarginGroups[side] = group; - group->addChild(side, this); - } - } - } -} - -/*! - Updates the layout element and sub-elements. This function is automatically called before every - replot by the parent layout element. It is called multiple times, once for every \ref - UpdatePhase. The phases are run through in the order of the enum values. For details about what - happens at the different phases, see the documentation of \ref UpdatePhase. - - Layout elements that have child elements should call the \ref update method of their child - elements, and pass the current \a phase unchanged. - - The default implementation executes the automatic margin mechanism in the \ref upMargins phase. - Subclasses should make sure to call the base class implementation. -*/ -void QCPLayoutElement::update(UpdatePhase phase) -{ - if (phase == upMargins) - { - if (mAutoMargins != QCP::msNone) - { - // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: - QMargins newMargins = mMargins; - QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; - foreach (QCP::MarginSide side, allMarginSides) - { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically - { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group - else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly - // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); - } - } - setMargins(newMargins); - } - } -} - -/*! - Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, - if no manual minimum size is set. - - if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size - (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum - allowed size of this layout element. - - A manual minimum size is considered set if it is non-zero. - - The default implementation simply returns the sum of the horizontal margins for the width and the - sum of the vertical margins for the height. Reimplementations may use their detailed knowledge - about the layout element's content to provide size hints. -*/ -QSize QCPLayoutElement::minimumOuterSizeHint() const -{ - return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); -} - -/*! - Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, - if no manual maximum size is set. - - if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned - size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the - maximum allowed size of this layout element. - - A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. - - The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying - no suggested maximum size. Reimplementations may use their detailed knowledge about the layout - element's content to provide size hints. -*/ -QSize QCPLayoutElement::maximumOuterSizeHint() const -{ - return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); -} - -/*! - Returns a list of all child elements in this layout element. If \a recursive is true, all - sub-child elements are included in the list, too. - - \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have - empty cells which yield 0 at the respective index.) -*/ -QList QCPLayoutElement::elements(bool recursive) const -{ - Q_UNUSED(recursive) - return QList(); -} - -/*! - Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer - rect, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is - true, -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. - - QCPLayoutElement subclasses may reimplement this method to provide more specific selection test - behaviour. -*/ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - - if (onlySelectable) - return -1; - - if (QRectF(mOuterRect).contains(pos)) - { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; - else - { - qDebug() << Q_FUNC_INFO << "parent plot not defined"; - return -1; - } - } else - return -1; -} - -/*! \internal - - propagates the parent plot initialization to all child elements, by calling \ref - QCPLayerable::initializeParentPlot on them. -*/ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) -{ - foreach (QCPLayoutElement* el, elements(false)) - { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); - } -} - -/*! \internal - - Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a - side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the - returned value will not be smaller than the specified minimum margin. - - The default implementation just returns the respective manual margin (\ref setMargins) or the - minimum margin, whichever is larger. -*/ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) -{ - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); -} - -/*! \internal - - This virtual method is called when this layout element was moved to a different QCPLayout, or - when this layout element has changed its logical position (e.g. row and/or column) within the - same QCPLayout. Subclasses may use this to react accordingly. - - Since this method is called after the completion of the move, you can access the new parent - layout via \ref layout(). - - The default implementation does nothing. -*/ -void QCPLayoutElement::layoutChanged() -{ -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayout -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayout - \brief The abstract base class for layouts - - This is an abstract base class for layout elements whose main purpose is to define the position - and size of other child layout elements. In most cases, layouts don't draw anything themselves - (but there are exceptions to this, e.g. QCPLegend). - - QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. - - QCPLayout introduces a common interface for accessing and manipulating the child elements. Those - functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref - simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions - to this interface which are more specialized to the form of the layout. For example, \ref - QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid - more conveniently. - - Since this is an abstract base class, you can't instantiate it directly. Rather use one of its - subclasses like QCPLayoutGrid or QCPLayoutInset. - - For a general introduction to the layout system, see the dedicated documentation page \ref - thelayoutsystem "The Layout System". -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPLayout::elementCount() const = 0 - - Returns the number of elements/cells in the layout. - - \see elements, elementAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 - - Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. - - Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. - QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check - whether a cell is empty or not. - - \see elements, elementCount, takeAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 - - Removes the element with the given \a index from the layout and returns it. - - If the \a index is invalid or the cell with that index is empty, returns 0. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see elementAt, take -*/ - -/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 - - Removes the specified \a element from the layout and returns true on success. - - If the \a element isn't in this layout, returns false. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see takeAt -*/ - -/* end documentation of pure virtual functions */ - -/*! - Creates an instance of QCPLayout and sets default values. Note that since QCPLayout - is an abstract base class, it can't be instantiated directly. -*/ -QCPLayout::QCPLayout() -{ -} - -/*! - If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to - reposition and resize their cells. - - Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". - - For details about this method and the update phases, see the documentation of \ref - QCPLayoutElement::update. -*/ -void QCPLayout::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - // set child element rects according to layout: - if (phase == upLayout) - updateLayout(); - - // propagate update call to child elements: - const int elCount = elementCount(); - for (int i=0; iupdate(phase); - } -} - -/* inherits documentation from base class */ -QList QCPLayout::elements(bool recursive) const -{ - const int c = elementCount(); - QList result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the - default implementation does nothing. - - Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit - simplification while QCPLayoutGrid does. -*/ -void QCPLayout::simplify() -{ -} - -/*! - Removes and deletes the element at the provided \a index. Returns true on success. If \a index is - invalid or points to an empty cell, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the returned element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see remove, takeAt -*/ -bool QCPLayout::removeAt(int index) -{ - if (QCPLayoutElement *el = takeAt(index)) - { - delete el; - return true; - } else - return false; -} - -/*! - Removes and deletes the provided \a element. Returns true on success. If \a element is not in the - layout, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see removeAt, take -*/ -bool QCPLayout::remove(QCPLayoutElement *element) -{ - if (take(element)) - { - delete element; - return true; - } else - return false; -} - -/*! - Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure - all empty cells are collapsed. - - \see remove, removeAt -*/ -void QCPLayout::clear() -{ - for (int i=elementCount()-1; i>=0; --i) - { - if (elementAt(i)) - removeAt(i); - } - simplify(); -} - -/*! - Subclasses call this method to report changed (minimum/maximum) size constraints. - - If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref - sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of - QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, - it may update itself and resize cells accordingly. -*/ -void QCPLayout::sizeConstraintsChanged() const -{ - if (QWidget *w = qobject_cast(parent())) - w->updateGeometry(); - else if (QCPLayout *l = qobject_cast(parent())) - l->sizeConstraintsChanged(); -} - -/*! \internal - - Subclasses reimplement this method to update the position and sizes of the child elements/cells - via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. - - The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay - within that rect. - - \ref getSectionSizes may help with the reimplementation of this function. - - \see update -*/ -void QCPLayout::updateLayout() -{ -} - - -/*! \internal - - Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the - \ref QCPLayerable::parentLayerable and the QObject parent to this layout. - - Further, if \a el didn't previously have a parent plot, calls \ref - QCPLayerable::initializeParentPlot on \a el to set the paret plot. - - This method is used by subclass specific methods that add elements to the layout. Note that this - method only changes properties in \a el. The removal from the old layout and the insertion into - the new layout must be done additionally. -*/ -void QCPLayout::adoptElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); - el->layoutChanged(); - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout - and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent - QCustomPlot. - - This method is used by subclass specific methods that remove elements from the layout (e.g. \ref - take or \ref takeAt). Note that this method only changes properties in \a el. The removal from - the old layout must be done additionally. -*/ -void QCPLayout::releaseElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); - // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - This is a helper function for the implementation of \ref updateLayout in subclasses. - - It calculates the sizes of one-dimensional sections with provided constraints on maximum section - sizes, minimum section sizes, relative stretch factors and the final total size of all sections. - - The QVector entries refer to the sections. Thus all QVectors must have the same size. - - \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size - imposed, set all vector values to Qt's QWIDGETSIZE_MAX. - - \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size - imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than - \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, - not exceeding the allowed total size is taken to be more important than not going below minimum - section sizes.) - - \a stretchFactors give the relative proportions of the sections to each other. If all sections - shall be scaled equally, set all values equal. If the first section shall be double the size of - each individual other section, set the first number of \a stretchFactors to double the value of - the other individual values (e.g. {2, 1, 1, 1}). - - \a totalSize is the value that the final section sizes will add up to. Due to rounding, the - actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, - you could distribute the remaining difference on the sections. - - The return value is a QVector containing the section sizes. -*/ -QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const -{ - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) - { - qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; - return QVector(); - } - if (stretchFactors.isEmpty()) - return QVector(); - int sectionCount = stretchFactors.size(); - QVector sectionSizes(sectionCount); - // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): - int minSizeSum = 0; - for (int i=0; i minimumLockedSections; - QList unfinishedSections; - for (int i=0; i result(sectionCount); - for (int i=0; iminimumOuterSizeHint(); - QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) - if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rwidth() += el->margins().left() + el->margins().right(); - if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; -} - -/*! \internal - - This is a helper function for the implementation of subclasses. - - It returns the maximum size that should finally be used for the outer rect of the passed layout - element \a el. - - It takes into account whether a manual maximum size is set (\ref - QCPLayoutElement::setMaximumSize), which size constraint is set (\ref - QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum - size was set (\ref QCPLayoutElement::maximumOuterSizeHint). -*/ -QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) -{ - QSize maxOuterHint = el->maximumOuterSizeHint(); - QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) - if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rwidth() += el->margins().left() + el->margins().right(); - if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutGrid - \brief A layout that arranges child elements in a grid - - Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, - \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). - - Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or - column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref - hasElement, that element can be retrieved with \ref element. If rows and columns that only have - empty cells shall be removed, call \ref simplify. Removal of elements is either done by just - adding the element to a different layout or by using the QCPLayout interface \ref take or \ref - remove. - - If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a - column, the grid layout will choose the position according to the current \ref setFillOrder and - the wrapping (\ref setWrap). - - Row and column insertion can be performed with \ref insertRow and \ref insertColumn. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPLayoutGrid::rowCount() const - - Returns the number of rows in the layout. - - \see columnCount -*/ - -/*! \fn int QCPLayoutGrid::columnCount() const - - Returns the number of columns in the layout. - - \see rowCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutGrid and sets default values. -*/ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5), - mWrap(0), - mFillOrder(foRowsFirst) -{ -} - -QCPLayoutGrid::~QCPLayoutGrid() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the element in the cell in \a row and \a column. - - Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug - message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. - - \see addElement, hasElement -*/ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const -{ - if (row >= 0 && row < mElements.size()) - { - if (column >= 0 && column < mElements.first().size()) - { - if (QCPLayoutElement *result = mElements.at(row).at(column)) - return result; - else - qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; - return 0; -} - - -/*! \overload - - Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it - is first removed from there. If \a row or \a column don't exist yet, the layout is expanded - accordingly. - - Returns true if the element was added successfully, i.e. if the cell at \a row and \a column - didn't already have an element. - - Use the overload of this method without explicit row/column index to place the element according - to the configured fill order and wrapping settings. - - \see element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) -{ - if (!hasElement(row, column)) - { - if (element && element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); - mElements[row][column] = element; - if (element) - adoptElement(element); - return true; - } else - qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; - return false; -} - -/*! \overload - - Adds the \a element to the next empty cell according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first - removed from there. If necessary, the layout is expanded to hold the new element. - - Returns true if the element was added successfully. - - \see setFillOrder, setWrap, element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(QCPLayoutElement *element) -{ - int rowIndex = 0; - int colIndex = 0; - if (mFillOrder == foColumnsFirst) - { - while (hasElement(rowIndex, colIndex)) - { - ++colIndex; - if (colIndex >= mWrap && mWrap > 0) - { - colIndex = 0; - ++rowIndex; - } - } - } else - { - while (hasElement(rowIndex, colIndex)) - { - ++rowIndex; - if (rowIndex >= mWrap && mWrap > 0) - { - rowIndex = 0; - ++colIndex; - } - } - } - return addElement(rowIndex, colIndex, element); -} - -/*! - Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't - empty. - - \see element -*/ -bool QCPLayoutGrid::hasElement(int row, int column) -{ - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); - else - return false; -} - -/*! - Sets the stretch \a factor of \a column. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) -{ - if (column >= 0 && column < columnCount()) - { - if (factor > 0) - mColumnStretchFactors[column] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid column:" << column; -} - -/*! - Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactor, setRowStretchFactors -*/ -void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) -{ - if (factors.size() == mColumnStretchFactors.size()) - { - mColumnStretchFactors = factors; - for (int i=0; i= 0 && row < rowCount()) - { - if (factor > 0) - mRowStretchFactors[row] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid row:" << row; -} - -/*! - Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setRowStretchFactor, setColumnStretchFactors -*/ -void QCPLayoutGrid::setRowStretchFactors(const QList &factors) -{ - if (factors.size() == mRowStretchFactors.size()) - { - mRowStretchFactors = factors; - for (int i=0; i tempElements; - if (rearrange) - { - tempElements.reserve(elCount); - for (int i=0; i()); - mRowStretchFactors.append(1); - } - // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i rowCount()) - newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); - QList newRow; - for (int col=0; col columnCount()) - newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row= 0 && row < rowCount()) - { - if (column >= 0 && column < columnCount()) - { - switch (mFillOrder) - { - case foRowsFirst: return column*rowCount() + row; - case foColumnsFirst: return row*columnCount() + column; - } - } else - qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; - } else - qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; - return 0; -} - -/*! - Converts the linear index to row and column indices and writes the result to \a row and \a - column. - - The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the - indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices - increase top to bottom and then left to right. - - If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. - - For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, - i.e. greater or equal to zero and smaller than the current \ref elementCount. - - \see rowColToIndex -*/ -void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const -{ - row = -1; - column = -1; - const int nCols = columnCount(); - const int nRows = rowCount(); - if (nCols == 0 || nRows == 0) - return; - if (index < 0 || index >= elementCount()) - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return; - } - - switch (mFillOrder) - { - case foRowsFirst: - { - column = index / nRows; - row = index % nRows; - break; - } - case foColumnsFirst: - { - row = index / nCols; - column = index % nCols; - break; - } - } -} - -/* inherits documentation from base class */ -void QCPLayoutGrid::updateLayout() -{ - QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - - // go through cells and set rects accordingly: - int yOffset = mRect.top(); - for (int row=0; row 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; - int xOffset = mRect.left(); - for (int col=0; col 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); - } - } -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const -{ - if (index >= 0 && index < elementCount()) - { - int row, col; - indexToRowCol(index, row, col); - return mElements.at(row).at(col); - } else - return 0; -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - int row, col; - indexToRowCol(index, row, col); - mElements[row][col] = 0; - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i QCPLayoutGrid::elements(bool recursive) const -{ - QList result; - const int elCount = elementCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(elCount); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing rows and columns which only contain empty cells. -*/ -void QCPLayoutGrid::simplify() -{ - // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) - { - bool hasElements = false; - for (int col=0; col=0; --col) - { - bool hasElements = false; - for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i QWIDGETSIZE_MAX) - result.setHeight(QWIDGETSIZE_MAX); - if (result.width() > QWIDGETSIZE_MAX) - result.setWidth(QWIDGETSIZE_MAX); - return result; -} - -/*! \internal - - Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights - respectively. - - The minimum height of a row is the largest minimum height of any element's outer rect in that - row. The minimum width of a column is the largest minimum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMaximumRowColSizes -*/ -void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const -{ - *minColWidths = QVector(columnCount(), 0); - *minRowHeights = QVector(rowCount(), 0); - for (int row=0; rowat(col) < minSize.width()) - (*minColWidths)[col] = minSize.width(); - if (minRowHeights->at(row) < minSize.height()) - (*minRowHeights)[row] = minSize.height(); - } - } - } -} - -/*! \internal - - Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights - respectively. - - The maximum height of a row is the smallest maximum height of any element's outer rect in that - row. The maximum width of a column is the smallest maximum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMinimumRowColSizes -*/ -void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const -{ - *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; rowat(col) > maxSize.width()) - (*maxColWidths)[col] = maxSize.width(); - if (maxRowHeights->at(row) > maxSize.height()) - (*maxRowHeights)[row] = maxSize.height(); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutInset -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPLayoutInset - \brief A layout that places child elements aligned to the border or arbitrarily positioned - - Elements are placed either aligned to the border or at arbitrary position in the area of the - layout. Which placement applies is controlled with the \ref InsetPlacement (\ref - setInsetPlacement). - - Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or - addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset - placement will default to \ref ipBorderAligned and the element will be aligned according to the - \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at - arbitrary position and size, defined by \a rect. - - The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. - - This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual void QCPLayoutInset::simplify() - - The QCPInsetLayout does not need simplification since it can never have empty cells due to its - linear index structure. This method does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutInset and sets default values. -*/ -QCPLayoutInset::QCPLayoutInset() -{ -} - -QCPLayoutInset::~QCPLayoutInset() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the placement type of the element with the specified \a index. -*/ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const -{ - if (elementAt(index)) - return mInsetPlacement.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return ipFree; - } -} - -/*! - Returns the alignment of the element with the specified \a index. The alignment only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. -*/ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const -{ - if (elementAt(index)) - return mInsetAlignment.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return 0; - } -} - -/*! - Returns the rect of the element with the specified \a index. The rect only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. -*/ -QRectF QCPLayoutInset::insetRect(int index) const -{ - if (elementAt(index)) - return mInsetRect.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return QRectF(); - } -} - -/*! - Sets the inset placement type of the element with the specified \a index to \a placement. - - \see InsetPlacement -*/ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) -{ - if (elementAt(index)) - mInsetPlacement[index] = placement; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function - is used to set the alignment of the element with the specified \a index to \a alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. -*/ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) -{ - if (elementAt(index)) - mInsetAlignment[index] = alignment; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the - position and size of the element with the specified \a index to \a rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - Note that the minimum and maximum sizes of the embedded element (\ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. -*/ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) -{ - if (elementAt(index)) - mInsetRect[index] = rect; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/* inherits documentation from base class */ -void QCPLayoutInset::updateLayout() -{ - for (int i=0; i finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter - } - mElements.at(i)->setOuterRect(insetRect); - } -} - -/* inherits documentation from base class */ -int QCPLayoutInset::elementCount() const -{ - return mElements.size(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const -{ - if (index >= 0 && index < mElements.size()) - return mElements.at(index); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! - Adds the specified \a element to the layout as an inset aligned at the border (\ref - setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a - alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. - - \see addElement(QCPLayoutElement *element, const QRectF &rect) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - -/*! - Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref - setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a - rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} -/* end of 'src/layout.cpp' */ - - -/* including file 'src/lineending.cpp', size 11536 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLineEnding -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLineEnding - \brief Handles the different ending decorations for line-like items - - \image html QCPLineEnding.png "The various ending styles currently supported" - - For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine - has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. - - The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can - be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of - the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. - For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite - directions, e.g. "outward". This can be changed by \ref setInverted, which would make the - respective arrow point inward. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify a - QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. - \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead -*/ - -/*! - Creates a QCPLineEnding instance with default values (style \ref esNone). -*/ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) -{ -} - -/*! - Creates a QCPLineEnding instance with the specified values. -*/ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) -{ -} - -/*! - Sets the style of the ending decoration. -*/ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) -{ - mStyle = style; -} - -/*! - Sets the width of the ending decoration, if the style supports it. On arrows, for example, the - width defines the size perpendicular to the arrow's pointing direction. - - \see setLength -*/ -void QCPLineEnding::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the length of the ending decoration, if the style supports it. On arrows, for example, the - length defines the size in pointing direction. - - \see setWidth -*/ -void QCPLineEnding::setLength(double length) -{ - mLength = length; -} - -/*! - Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point - inward when \a inverted is set to true. - - Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or - discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are - affected by it, which can be used to control to which side the half bar points to. -*/ -void QCPLineEnding::setInverted(bool inverted) -{ - mInverted = inverted; -} - -/*! \internal - - Returns the maximum pixel radius the ending decoration might cover, starting from the position - the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). - - This is relevant for clipping. Only omit painting of the decoration when the position where the - decoration is supposed to be drawn is farther away from the clipping rect than the returned - distance. -*/ -double QCPLineEnding::boundingDistance() const -{ - switch (mStyle) - { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) - - } - return 0; -} - -/*! - Starting from the origin of this line ending (which is style specific), returns the length - covered by the line ending symbol, in backward direction. - - For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if - both have the same \ref setLength value, because the spike arrow has an inward curved back, which - reduces the length along its center axis (the drawing origin for arrows is at the tip). - - This function is used for precise, style specific placement of line endings, for example in - QCPAxes. -*/ -double QCPLineEnding::realLength() const -{ - switch (mStyle) - { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; - } - return 0; -} - -/*! \internal - - Draws the line ending with the specified \a painter at the position \a pos. The direction of the - line ending is controlled with \a dir. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const -{ - if (mStyle == esNone) - return; - - QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); - if (lengthVec.isNull()) - lengthVec = QCPVector2D(1, 0); - QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); - - QPen penBackup = painter->pen(); - QBrush brushBackup = painter->brush(); - QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) - { - case esNone: break; - case esFlatArrow: - { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esSpikeArrow: - { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; - } - } -} - -/*! \internal - \overload - - Draws the line ending. The direction is controlled with the \a angle parameter in radians. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const -{ - draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); -} -/* end of 'src/lineending.cpp' */ - - -/* including file 'src/axis/axisticker.cpp', size 18664 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTicker -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTicker - \brief The base class tick generator used by QCPAxis to create tick positions and tick labels - - Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions - and tick labels for the current axis range. The ticker of an axis can be set via \ref - QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple - axes can share the same ticker instance. - - This base class generates normal tick coordinates and numeric labels for linear axes. It picks a - reasonable tick step (the separation between ticks) which results in readable tick labels. The - number of ticks that should be approximately generated can be set via \ref setTickCount. - Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either - sacrifices readability to better match the specified tick count (\ref - QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref - QCPAxisTicker::tssReadability), which is the default. - - The following more specialized axis ticker subclasses are available, see details in the - respective class documentation: - -
- - - - - - - -
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png - \image html axisticker-time2.png
-
- - \section axisticker-subclassing Creating own axis tickers - - Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and - reimplementing some or all of the available virtual methods. - - In the simplest case you might wish to just generate different tick steps than the other tickers, - so you only reimplement the method \ref getTickStep. If you additionally want control over the - string that will be shown as tick label, reimplement \ref getTickLabel. - - If you wish to have complete control, you can generate the tick vectors and tick label vectors - yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default - implementations use the previously mentioned virtual methods \ref getTickStep and \ref - getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case - of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. - - The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick - placement control is obtained by reimplementing \ref createSubTickVector. - - See the documentation of all these virtual methods in QCPAxisTicker for detailed information - about the parameters and expected return values. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTicker::QCPAxisTicker() : - mTickStepStrategy(tssReadability), - mTickCount(5), - mTickOrigin(0) -{ -} - -QCPAxisTicker::~QCPAxisTicker() -{ - -} - -/*! - Sets which strategy the axis ticker follows when choosing the size of the tick step. For the - available strategies, see \ref TickStepStrategy. -*/ -void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) -{ - mTickStepStrategy = strategy; -} - -/*! - Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count - is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with - the requested number of ticks. - - Whether the readability has priority over meeting the requested \a count can be specified with - \ref setTickStepStrategy. -*/ -void QCPAxisTicker::setTickCount(int count) -{ - if (count > 0) - mTickCount = count; - else - qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; -} - -/*! - Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a - concept and doesn't need to be inside the currently visible axis range. - - By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick - step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be - {-4, 1, 6, 11, 16,...}. -*/ -void QCPAxisTicker::setTickOrigin(double origin) -{ - mTickOrigin = origin; -} - -/*! - This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), - tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). - - The ticks are generated for the specified \a range. The generated labels typically follow the - specified \a locale, \a formatChar and number \a precision, however this might be different (or - even irrelevant) for certain QCPAxisTicker subclasses. - - The output parameter \a ticks is filled with the generated tick positions in axis coordinates. - The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) - and are respectively filled with sub tick coordinates, and tick label strings belonging to \a - ticks by index. -*/ -void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) -{ - // generate (major) ticks: - double tickStep = getTickStep(range); - ticks = createTickVector(tickStep, range); - trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) - - // generate sub ticks between major ticks: - if (subTicks) - { - if (ticks.size() > 0) - { - *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); - trimTicks(range, *subTicks, false); - } else - *subTicks = QVector(); - } - - // finally trim also outliers (no further clipping happens in axis drawing): - trimTicks(range, ticks, false); - // generate labels for visible ticks if requested: - if (tickLabels) - *tickLabels = createLabelVector(ticks, locale, formatChar, precision); -} - -/*! \internal - - Takes the entire currently visible axis range and returns a sensible tick step in - order to provide readable tick labels as well as a reasonable number of tick counts (see \ref - setTickCount, \ref setTickStepStrategy). - - If a QCPAxisTicker subclass only wants a different tick step behaviour than the default - implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper - function. -*/ -double QCPAxisTicker::getTickStep(const QCPRange &range) -{ - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return cleanMantissa(exactStep); -} - -/*! \internal - - Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns - an appropriate number of sub ticks for that specific tick step. - - Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. -*/ -int QCPAxisTicker::getSubTickCount(double tickStep) -{ - int result = 1; // default to 1, if no proper value can be found - - // separate integer and fractional part of mantissa: - double epsilon = 0.01; - double intPartf; - int intPart; - double fracPart = modf(getMantissa(tickStep), &intPartf); - intPart = intPartf; - - // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) - { - if (1.0-fracPart < epsilon) - ++intPart; - switch (intPart) - { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep - } - } else - { - // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa - { - switch (intPart) - { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep - } - } - // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default - } - - return result; -} - -/*! \internal - - This method returns the tick label string as it should be printed under the \a tick coordinate. - If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a - precision. - - If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is - enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will - be formatted accordingly using multiplication symbol and superscript during rendering of the - label automatically. -*/ -QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - return locale.toString(tick, formatChar.toLatin1(), precision); -} - -/*! \internal - - Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a - subTickCount sub ticks between each tick pair given in \a ticks. - - If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should - reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to - base its result on \a subTickCount or \a ticks. -*/ -QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) -{ - QVector result; - if (subTickCount <= 0 || ticks.size() < 2) - return result; - - result.reserve((ticks.size()-1)*subTickCount); - for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result; - // Generate tick positions according to tickStep: - qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - result.resize(tickcount); - for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) -{ - QVector result; - result.reserve(ticks.size()); - for (int i=0; i &ticks, bool keepOneOutlier) const -{ - bool lowFound = false; - bool highFound = false; - int lowIndex = 0; - int highIndex = -1; - - for (int i=0; i < ticks.size(); ++i) - { - if (ticks.at(i) >= range.lower) - { - lowFound = true; - lowIndex = i; - break; - } - } - for (int i=ticks.size()-1; i >= 0; --i) - { - if (ticks.at(i) <= range.upper) - { - highFound = true; - highIndex = i; - break; - } - } - - if (highFound && lowFound) - { - int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); - int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); - if (trimFront > 0 || trimBack > 0) - ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); - } else // all ticks are either all below or all above the range - ticks.clear(); -} - -/*! \internal - - Returns the coordinate contained in \a candidates which is closest to the provided \a target. - - This method assumes \a candidates is not empty and sorted in ascending order. -*/ -double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const -{ - if (candidates.size() == 1) - return candidates.first(); - QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); - if (it == candidates.constEnd()) - return *(it-1); - else if (it == candidates.constBegin()) - return *it; - else - return target-*(it-1) < *it-target ? *(it-1) : *it; -} - -/*! \internal - - Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also - returns the magnitude of \a input as a power of 10. - - For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. -*/ -double QCPAxisTicker::getMantissa(double input, double *magnitude) const -{ - const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); - if (magnitude) *magnitude = mag; - return input/mag; -} - -/*! \internal - - Returns a number that is close to \a input but has a clean, easier human readable mantissa. How - strongly the mantissa is altered, and thus how strong the result deviates from the original \a - input, depends on the current tick step strategy (see \ref setTickStepStrategy). -*/ -double QCPAxisTicker::cleanMantissa(double input) const -{ - double magnitude; - const double mantissa = getMantissa(input, &magnitude); - switch (mTickStepStrategy) - { - case tssReadability: - { - return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; - } - case tssMeetTickCount: - { - // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 - if (mantissa <= 5.0) - return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 - else - return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 - } - } - return input; -} -/* end of 'src/axis/axisticker.cpp' */ - - -/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerDateTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerDateTime - \brief Specialized axis ticker for calendar dates and times as axis ticks - - \image html axisticker-datetime.png - - This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The - plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 - UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods - with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime - by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey - and \ref keyToDateTime conveniently perform this conversion achieving a precision of one - millisecond on all Qt versions. - - The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. - If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. - - This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day - ticks. For example, if the axis range spans a few years such that there is one tick per year, - ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, - will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in - the image above: even though the number of days varies month by month, this ticker generates - ticks on the same day of each month. - - If you would like to change the date/time that is used as a (mathematical) starting date for the - ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a - QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at - 9:45 of every year. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation - - \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and - milliseconds, and are not interested in the intricacies of real calendar dates with months and - (leap) years, have a look at QCPAxisTickerTime instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerDateTime::QCPAxisTickerDateTime() : - mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), - mDateTimeSpec(Qt::LocalTime), - mDateStrategy(dsNone) -{ - setTickCount(4); -} - -/*! - Sets the format in which dates and times are displayed as tick labels. For details about the \a - format string, see the documentation of QDateTime::toString(). - - Newlines can be inserted with "\n". - - \see setDateTimeSpec -*/ -void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) -{ - mDateTimeFormat = format; -} - -/*! - Sets the time spec that is used for creating the tick labels from corresponding dates/times. - - The default value of QDateTime objects (and also QCPAxisTickerDateTime) is - Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form - of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC - to get the correct axis labels. - - \see setDateTimeFormat -*/ -void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) -{ - mDateTimeSpec = spec; -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, - 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which - directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(double origin) -{ - QCPAxisTicker::setTickOrigin(origin); -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) -{ - setTickOrigin(dateTimeToKey(origin)); -} - -/*! \internal - - Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - Note that this tick step isn't used exactly when generating the tick vector in \ref - createTickVector, but only as a guiding value requiring some correction for each individual tick - interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day - in the month to the last day in the previous month from tick to tick, due to the non-uniform - length of months. The same problem arises with leap years. - - \seebaseclassmethod -*/ -double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - mDateStrategy = dsNone; - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - result = cleanMantissa(result); - } else if (result < 86400*30.4375*12) // below a year - { - result = pickClosest(result, QVector() - << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range - << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range - << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) - if (result > 86400*30.4375-1) // month tick intervals or larger - mDateStrategy = dsUniformDayInMonth; - else if (result > 3600*24-1) // day tick intervals or larger - mDateStrategy = dsUniformTimeInDay; - } else // more than a year, go back to normal clean mantissa algorithm but in units of years - { - const double secondsPerYear = 86400*30.4375*12; // average including leap years - result = cleanMantissa(result/secondsPerYear)*secondsPerYear; - mDateStrategy = dsUniformDayInMonth; - } - return result; -} - -/*! \internal - - Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - \seebaseclassmethod -*/ -int QCPAxisTickerDateTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - case 86400*2: result = 1; break; - case 86400*5: result = 4; break; - case 86400*7: result = 6; break; - case 86400*14: result = 1; break; - case (int)(86400*30.4375+0.5): result = 3; break; - case (int)(86400*30.4375*2+0.5): result = 1; break; - case (int)(86400*30.4375*3+0.5): result = 2; break; - case (int)(86400*30.4375*6+0.5): result = 5; break; - case (int)(86400*30.4375*12+0.5): result = 3; break; - } - return result; -} - -/*! \internal - - Generates a date/time tick label for tick coordinate \a tick, based on the currently set format - (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). - - \seebaseclassmethod -*/ -QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -} - -/*! \internal - - Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain - non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. - - \seebaseclassmethod -*/ -QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result = QCPAxisTicker::createTickVector(tickStep, range); - if (!result.isEmpty()) - { - if (mDateStrategy == dsUniformTimeInDay) - { - QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible - QDateTime tickDateTime; - for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day - tickDateTime = tickDateTime.addMonths(-1); - tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); - result[i] = dateTimeToKey(tickDateTime); - } - } - } - return result; -} - -/*! - A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a - QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) - - \see dateTimeToKey -*/ -QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); -# else - return QDateTime::fromMSecsSinceEpoch(key*1000.0); -# endif -} - -/*! \overload - - A convenience method which turns a QDateTime object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return dateTime.toTime_t()+dateTime.time().msec()/1000.0; -# else - return dateTime.toMSecsSinceEpoch()/1000.0; -# endif -} - -/*! \overload - - A convenience method which turns a QDate object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime(date).toTime_t(); -# else - return QDateTime(date).toMSecsSinceEpoch()/1000.0; -# endif -} -/* end of 'src/axis/axistickerdatetime.cpp' */ - - -/* including file 'src/axis/axistickertime.cpp', size 11747 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerTime - \brief Specialized axis ticker for time spans in units of milliseconds to days - - \image html axisticker-time.png - - This QCPAxisTicker subclass generates ticks that corresponds to time intervals. - - The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref - setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate - zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date - and time. - - The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the - largest available unit in the format specified with \ref setTimeFormat, any time spans above will - be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at - coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick - label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour - unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis - zero will carry a leading minus sign. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation - - Here is an example of a time axis providing time information in days, hours and minutes. Due to - the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker - decided to use tick steps of 12 hours: - - \image html axisticker-time2.png - - The format string for this example is - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 - - \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime - instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerTime::QCPAxisTickerTime() : - mTimeFormat(QLatin1String("%h:%m:%s")), - mSmallestUnit(tuSeconds), - mBiggestUnit(tuHours) -{ - setTickCount(4); - mFieldWidth[tuMilliseconds] = 3; - mFieldWidth[tuSeconds] = 2; - mFieldWidth[tuMinutes] = 2; - mFieldWidth[tuHours] = 2; - mFieldWidth[tuDays] = 1; - - mFormatPattern[tuMilliseconds] = QLatin1String("%z"); - mFormatPattern[tuSeconds] = QLatin1String("%s"); - mFormatPattern[tuMinutes] = QLatin1String("%m"); - mFormatPattern[tuHours] = QLatin1String("%h"); - mFormatPattern[tuDays] = QLatin1String("%d"); -} - -/*! - Sets the format that will be used to display time in the tick labels. - - The available patterns are: - - %%z for milliseconds - - %%s for seconds - - %%m for minutes - - %%h for hours - - %%d for days - - The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. - - The largest unit that appears in \a format will carry all the remaining time of a certain tick - coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the - largest unit it might become larger than 59 in order to consume larger time values. If on the - other hand %%h is available, the minutes will wrap around to zero after 59 and the time will - carry to the hour digit. -*/ -void QCPAxisTickerTime::setTimeFormat(const QString &format) -{ - mTimeFormat = format; - - // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest - // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) - mSmallestUnit = tuMilliseconds; - mBiggestUnit = tuMilliseconds; - bool hasSmallest = false; - for (int i = tuMilliseconds; i <= tuDays; ++i) - { - TimeUnit unit = static_cast(i); - if (mTimeFormat.contains(mFormatPattern.value(unit))) - { - if (!hasSmallest) - { - mSmallestUnit = unit; - hasSmallest = true; - } - mBiggestUnit = unit; - } - } -} - -/*! - Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick - label. If the number for the specific unit is shorter than \a width, it will be padded with an - according number of zeros to the left in order to reach the field width. - - \see setTimeFormat -*/ -void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) -{ - mFieldWidth[unit] = qMax(width, 1); -} - -/*! \internal - - Returns the tick step appropriate for time displays, depending on the provided \a range and the - smallest available time unit in the current format (\ref setTimeFormat). For example if the unit - of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) - that require sub-minute precision to be displayed correctly. - - \seebaseclassmethod -*/ -double QCPAxisTickerTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - if (mSmallestUnit == tuMilliseconds) - result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond - else // have no milliseconds available in format, so stick with 1 second tickstep - result = 1.0; - } else if (result < 3600*24) // below a day - { - // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run - QVector availableSteps; - // seconds range: - if (mSmallestUnit <= tuSeconds) - availableSteps << 1; - if (mSmallestUnit == tuMilliseconds) - availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it - else if (mSmallestUnit == tuSeconds) - availableSteps << 2; - if (mSmallestUnit <= tuSeconds) - availableSteps << 5 << 10 << 15 << 30; - // minutes range: - if (mSmallestUnit <= tuMinutes) - availableSteps << 1*60; - if (mSmallestUnit <= tuSeconds) - availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it - else if (mSmallestUnit == tuMinutes) - availableSteps << 2*60; - if (mSmallestUnit <= tuMinutes) - availableSteps << 5*60 << 10*60 << 15*60 << 30*60; - // hours range: - if (mSmallestUnit <= tuHours) - availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; - // pick available step that is most appropriate to approximate ideal step: - result = pickClosest(result, availableSteps); - } else // more than a day, go back to normal clean mantissa algorithm but in units of days - { - const double secondsPerDay = 3600*24; - result = cleanMantissa(result/secondsPerDay)*secondsPerDay; - } - return result; -} - -/*! \internal - - Returns the sub tick count appropriate for the provided \a tickStep and time displays. - - \seebaseclassmethod -*/ -int QCPAxisTickerTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - } - return result; -} - -/*! \internal - - Returns the tick label corresponding to the provided \a tick and the configured format and field - widths (\ref setTimeFormat, \ref setFieldWidth). - - \seebaseclassmethod -*/ -QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - Q_UNUSED(locale) - bool negative = tick < 0; - if (negative) tick *= -1; - double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) - double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time - - restValues[tuMilliseconds] = tick*1000; - values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; - values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; - values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; - values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; - // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) - - QString result = mTimeFormat; - for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) - { - TimeUnit iUnit = static_cast(i); - replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); - } - if (negative) - result.prepend(QLatin1Char('-')); - return result; -} - -/*! \internal - - Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified - \a value, using the field width as specified with \ref setFieldWidth for the \a unit. -*/ -void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const -{ - QString valueStr = QString::number(value); - while (valueStr.size() < mFieldWidth.value(unit)) - valueStr.prepend(QLatin1Char('0')); - - text.replace(mFormatPattern.value(unit), valueStr); -} -/* end of 'src/axis/axistickertime.cpp' */ - - -/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerFixed -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerFixed - \brief Specialized axis ticker with a fixed tick step - - \image html axisticker-fixed.png - - This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It - is also possible to allow integer multiples and integer powers of the specified tick step with - \ref setScaleStrategy. - - A typical application of this ticker is to make an axis only display integers, by setting the - tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. - - Another case is when a certain number has a special meaning and axis ticks should only appear at - multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi - because despite the name it is not limited to only pi symbols/values. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerFixed::QCPAxisTickerFixed() : - mTickStep(1.0), - mScaleStrategy(ssNone) -{ -} - -/*! - Sets the fixed tick interval to \a step. - - The axis ticker will only use this tick step when generating axis ticks. This might cause a very - high tick density and overlapping labels if the axis range is zoomed out. Using \ref - setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a - step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref - setTickCount). -*/ -void QCPAxisTickerFixed::setTickStep(double step) -{ - if (step > 0) - mTickStep = step; - else - qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; -} - -/*! - Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether - modifications may be applied to it before calculating the finally used tick step, such as - permitting multiples or powers. See \ref ScaleStrategy for details. - - The default strategy is \ref ssNone, which means the tick step is absolutely fixed. -*/ -void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) -{ - mScaleStrategy = strategy; -} - -/*! \internal - - Determines the actually used tick step from the specified tick step and scale strategy (\ref - setTickStep, \ref setScaleStrategy). - - This method either returns the specified tick step exactly, or, if the scale strategy is not \ref - ssNone, a modification of it to allow varying the number of ticks in the current axis range. - - \seebaseclassmethod -*/ -double QCPAxisTickerFixed::getTickStep(const QCPRange &range) -{ - switch (mScaleStrategy) - { - case ssNone: - { - return mTickStep; - } - case ssMultiples: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - if (exactStep < mTickStep) - return mTickStep; - else - return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; - } - case ssPowers: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); - } - } - return mTickStep; -} -/* end of 'src/axis/axistickerfixed.cpp' */ - - -/* including file 'src/axis/axistickertext.cpp', size 8653 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerText -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerText - \brief Specialized axis ticker which allows arbitrary labels at specified coordinates - - \image html axisticker-text.png - - This QCPAxisTicker subclass generates ticks which can be directly specified by the user as - coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a - time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks - and modify the tick/label data there. - - This is useful for cases where the axis represents categories rather than numerical values. - - If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on - the axis range), it is a sign that you should probably create an own ticker by subclassing - QCPAxisTicker, instead of using this one. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation -*/ - -/* start of documentation of inline functions */ - -/*! \fn QMap &QCPAxisTickerText::ticks() - - Returns a non-const reference to the internal map which stores the tick coordinates and their - labels. - - You can access the map directly in order to add, remove or manipulate ticks, as an alternative to - using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerText::QCPAxisTickerText() : - mSubTickCount(0) -{ -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis - coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QMap &ticks) -{ - mTicks = ticks; -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis - coordinates, and the entries of \a labels are the respective strings that will appear as tick - labels. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) -{ - clear(); - addTicks(positions, labels); -} - -/*! - Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no - automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this - method. -*/ -void QCPAxisTickerText::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! - Clears all ticks. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see setTicks, addTicks, addTick -*/ -void QCPAxisTickerText::clear() -{ - mTicks.clear(); -} - -/*! - Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a - label. - - \see addTicks, setTicks, clear -*/ -void QCPAxisTickerText::addTick(double position, QString label) -{ - mTicks.insert(position, label); -} - -/*! \overload - - Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to - the axis coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QMap &ticks) -{ - mTicks.unite(ticks); -} - -/*! \overload - - Adds the provided ticks to the ones already existing. The entries of \a positions correspond to - the axis coordinates, and the entries of \a labels are the respective strings that will appear as - tick labels. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) -{ - if (positions.size() != labels.size()) - qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); - int n = qMin(positions.size(), labels.size()); - for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (mTicks.isEmpty()) - return result; - - QMap::const_iterator start = mTicks.lowerBound(range.lower); - QMap::const_iterator end = mTicks.upperBound(range.upper); - // this method should try to give one tick outside of range so proper subticks can be generated: - if (start != mTicks.constBegin()) --start; - if (end != mTicks.constEnd()) ++end; - for (QMap::const_iterator it = start; it != end; ++it) - result.append(it.key()); - - return result; -} -/* end of 'src/axis/axistickertext.cpp' */ - - -/* including file 'src/axis/axistickerpi.cpp', size 11170 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerPi -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerPi - \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi - - \image html axisticker-pi.png - - This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic - constant with a numerical value specified with \ref setPiValue and an appearance in the tick - labels specified with \ref setPiSymbol. - - Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the - tick label can be configured with \ref setFractionStyle. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerPi::QCPAxisTickerPi() : - mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), - mPiValue(M_PI), - mPeriodicity(0), - mFractionStyle(fsUnicodeFractions), - mPiTickStep(0) -{ - setTickCount(4); -} - -/*! - Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick - label. - - If a space shall appear between the number and the symbol, make sure the space is contained in \a - symbol. -*/ -void QCPAxisTickerPi::setPiSymbol(QString symbol) -{ - mPiSymbol = symbol; -} - -/*! - Sets the numerical value that the symbolic constant has. - - This will be used to place the appropriate fractions of the symbol at the respective axis - coordinates. -*/ -void QCPAxisTickerPi::setPiValue(double pi) -{ - mPiValue = pi; -} - -/*! - Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the - symbolic constant. - - To disable periodicity, set \a multiplesOfPi to zero. - - For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. -*/ -void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) -{ - mPeriodicity = qAbs(multiplesOfPi); -} - -/*! - Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick - labels. See \ref FractionStyle for the various options. -*/ -void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) -{ - mFractionStyle = style; -} - -/*! \internal - - Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence - the numerical/fractional part preceding the symbolic constant is made to have a readable - mantissa. - - \seebaseclassmethod -*/ -double QCPAxisTickerPi::getTickStep(const QCPRange &range) -{ - mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - mPiTickStep = cleanMantissa(mPiTickStep); - return mPiTickStep*mPiValue; -} - -/*! \internal - - Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In - consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant - reasonably, and not the total tick coordinate. - - \seebaseclassmethod -*/ -int QCPAxisTickerPi::getSubTickCount(double tickStep) -{ - return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); -} - -/*! \internal - - Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The - formatting of the fraction is done according to the specified \ref setFractionStyle. The appended - symbol is specified with \ref setPiSymbol. - - \seebaseclassmethod -*/ -QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - double tickInPis = tick/mPiValue; - if (mPeriodicity > 0) - tickInPis = fmod(tickInPis, mPeriodicity); - - if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) - { - // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above - int denominator = 1000; - int numerator = qRound(tickInPis*denominator); - simplifyFraction(numerator, denominator); - if (qAbs(numerator) == 1 && denominator == 1) - return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else if (numerator == 0) - return QLatin1String("0"); - else - return fractionToString(numerator, denominator) + mPiSymbol; - } else - { - if (qFuzzyIsNull(tickInPis)) - return QLatin1String("0"); - else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) - return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else - return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; - } -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure - the fraction is in irreducible form, i.e. numerator and denominator don't share any common - factors which could be cancelled. -*/ -void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const -{ - if (numerator == 0 || denominator == 0) - return; - - int num = numerator; - int denom = denominator; - while (denom != 0) // euclidean gcd algorithm - { - int oldDenom = denom; - denom = num % denom; - num = oldDenom; - } - // num is now gcd of numerator and denominator - numerator /= num; - denominator /= num; -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and returns a string representation. - The result depends on the configured fraction style (\ref setFractionStyle). - - This method is used to format the numerical/fractional part when generating tick labels. It - simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out - any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). -*/ -QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const -{ - if (denominator == 0) - { - qDebug() << Q_FUNC_INFO << "called with zero denominator"; - return QString(); - } - if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function - { - qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; - return QString::number(numerator/(double)denominator); // failsafe - } - int sign = numerator*denominator < 0 ? -1 : 1; - numerator = qAbs(numerator); - denominator = qAbs(denominator); - - if (denominator == 1) - { - return QString::number(sign*numerator); - } else - { - int integerPart = numerator/denominator; - int remainder = numerator%denominator; - if (remainder == 0) - { - return QString::number(sign*integerPart); - } else - { - if (mFractionStyle == fsAsciiFractions) - { - return QString(QLatin1String("%1%2%3/%4")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) - .arg(remainder) - .arg(denominator); - } else if (mFractionStyle == fsUnicodeFractions) - { - return QString(QLatin1String("%1%2%3")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) - .arg(unicodeFraction(remainder, denominator)); - } - } - } - return QString(); -} - -/*! \internal - - Returns the unicode string representation of the fraction given by \a numerator and \a - denominator. This is the representation used in \ref fractionToString when the fraction style - (\ref setFractionStyle) is \ref fsUnicodeFractions. - - This method doesn't use the single-character common fractions but builds each fraction from a - superscript unicode number, the unicode fraction character, and a subscript unicode number. -*/ -QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const -{ - return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); -} - -/*! \internal - - Returns the unicode string representing \a number as superscript. This is used to build - unicode fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSuperscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2070)); - - QString result; - while (number > 0) - { - const int digit = number%10; - switch (digit) - { - case 1: { result.prepend(QChar(0x00B9)); break; } - case 2: { result.prepend(QChar(0x00B2)); break; } - case 3: { result.prepend(QChar(0x00B3)); break; } - default: { result.prepend(QChar(0x2070+digit)); break; } - } - number /= 10; - } - return result; -} - -/*! \internal - - Returns the unicode string representing \a number as subscript. This is used to build unicode - fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSubscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2080)); - - QString result; - while (number > 0) - { - result.prepend(QChar(0x2080+number%10)); - number /= 10; - } - return result; -} -/* end of 'src/axis/axistickerpi.cpp' */ - - -/* including file 'src/axis/axistickerlog.cpp', size 7106 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerLog -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerLog - \brief Specialized axis ticker suited for logarithmic axes - - \image html axisticker-log.png - - This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic - axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). - - Especially in the case of a log base equal to 10 (the default), it might be desirable to have - tick labels in the form of powers of ten without mantissa display. To achieve this, set the - number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref - QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal - powers, so a format string of "eb". This will result in the following axis tick labels: - - \image html axisticker-log-powers.png - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerLog::QCPAxisTickerLog() : - mLogBase(10.0), - mSubTickCount(8), // generates 10 intervals - mLogBaseLnInv(1.0/qLn(mLogBase)) -{ -} - -/*! - Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer - powers of \a base. -*/ -void QCPAxisTickerLog::setLogBase(double base) -{ - if (base > 0) - { - mLogBase = base; - mLogBaseLnInv = 1.0/qLn(mLogBase); - } else - qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; -} - -/*! - Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced - linearly to provide a better visual guide, so the sub tick density increases toward the higher - tick. - - Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in - the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub - ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, - namely at 20, 30, 40, 50, 60, 70, 80 and 90. -*/ -void QCPAxisTickerLog::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! \internal - - Since logarithmic tick steps are necessarily different for each tick interval, this method does - nothing in the case of QCPAxisTickerLog - - \seebaseclassmethod -*/ -double QCPAxisTickerLog::getTickStep(const QCPRange &range) -{ - // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method - Q_UNUSED(range) - return 1.0; -} - -/*! \internal - - Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no - automatic sub tick count calculation necessary. - - \seebaseclassmethod -*/ -int QCPAxisTickerLog::getSubTickCount(double tickStep) -{ - Q_UNUSED(tickStep) - return mSubTickCount; -} - -/*! \internal - - Creates ticks with a spacing given by the logarithm base and an increasing integer power in the - provided \a range. The step in which the power increases tick by tick is chosen in order to keep - the total number of ticks as close as possible to the tick count (\ref setTickCount). The - parameter \a tickStep is ignored for QCPAxisTickerLog - - \seebaseclassmethod -*/ -QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (range.lower > 0 && range.upper > 0) // positive range - { - double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick *= newLogBase; - result.append(currentTick); - } - } else if (range.lower < 0 && range.upper < 0) // negative range - { - double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick /= newLogBase; - result.append(currentTick); - } - } else // invalid range for logarithmic scale, because lower and upper have different sign - { - qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; - } - - return result; -} -/* end of 'src/axis/axistickerlog.cpp' */ - - -/* including file 'src/axis/axis.cpp', size 99397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGrid - \brief Responsible for drawing the grid of a QCPAxis. - - This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the - grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref - QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. - - The axis and grid drawing was split into two classes to allow them to be placed on different - layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid - in the background and the axes in the foreground, and any plottables/items in between. This - described situation is the default setup, see the QCPLayer documentation. -*/ - -/*! - Creates a QCPGrid instance and sets default values. - - You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. -*/ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), - mParentAxis(parentAxis) -{ - // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); -} - -/*! - Sets whether grid lines at sub tick marks are drawn. - - \see setSubGridPen -*/ -void QCPGrid::setSubGridVisible(bool visible) -{ - mSubGridVisible = visible; -} - -/*! - Sets whether sub grid lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedSubGrid(bool enabled) -{ - mAntialiasedSubGrid = enabled; -} - -/*! - Sets whether zero lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedZeroLine(bool enabled) -{ - mAntialiasedZeroLine = enabled; -} - -/*! - Sets the pen with which (major) grid lines are drawn. -*/ -void QCPGrid::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen with which sub grid lines are drawn. -*/ -void QCPGrid::setSubGridPen(const QPen &pen) -{ - mSubGridPen = pen; -} - -/*! - Sets the pen with which zero lines are drawn. - - Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid - lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. -*/ -void QCPGrid::setZeroLinePen(const QPen &pen) -{ - mZeroLinePen = pen; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing the major grid lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); -} - -/*! \internal - - Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning - over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). -*/ -void QCPGrid::draw(QCPPainter *painter) -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mParentAxis->subTicks() && mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); -} - -/*! \internal - - Draws the main grid lines and possibly a zero line with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - const int tickCount = mParentAxis->mTickVector.size(); - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - -/*! \internal - - Draws the sub grid lines with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxis -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxis - \brief Manages a single axis inside a QCustomPlot. - - Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via - QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and - QCustomPlot::yAxis2 (right). - - Axes are always part of an axis rect, see QCPAxisRect. - \image html AxisNamesOverview.png -
Naming convention of axis parts
- \n - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line - on the left represents the QCustomPlot widget border.
- - Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and - tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of - the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the - documentation of QCPAxisTicker. -*/ - -/* start of documentation of inline functions */ - -/*! \fn Qt::Orientation QCPAxis::orientation() const - - Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced - from the axis type (left, top, right or bottom). - - \see orientation(AxisType type), pixelOrientation -*/ - -/*! \fn QCPGrid *QCPAxis::grid() const - - Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the - grid is displayed. -*/ - -/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) - - Returns the orientation of the specified axis type - - \see orientation(), pixelOrientation -*/ - -/*! \fn int QCPAxis::pixelOrientation() const - - Returns which direction points towards higher coordinate values/keys, in pixel space. - - This method returns either 1 or -1. If it returns 1, then going in the positive direction along - the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. - On the other hand, if this method returns -1, going to smaller pixel values corresponds to going - from lower to higher axis coordinates. - - For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, - without having to care about reversed or vertically aligned axes: - - \code - double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); - \endcode - - \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. -*/ - -/*! \fn QSharedPointer QCPAxis::ticker() const - - Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is - responsible for generating the tick positions and tick labels of this axis. You can access the - \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count - (\ref QCPAxisTicker::setTickCount). - - You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see - the documentation there. A new axis ticker can be set with \ref setTicker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see setTicker -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) - - This signal is emitted when the range of this axis has changed. You can connect it to the \ref - setRange slot of another axis to communicate the new range to the other axis, in order for it to - be synchronized. - - You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. - This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper - range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following - slot would limit the x axis to ranges between 0 and 10: - \code - customPlot->xAxis->setRange(newRange.bounded(0, 10)) - \endcode -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) - \overload - - Additionally to the new range, this signal also provides the previous range held by the axis as - \a oldRange. -*/ - -/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the scale type changes, by calls to \ref setScaleType -*/ - -/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) - - This signal is emitted when the selection state of this axis has changed, either by user interaction - or by a direct call to \ref setSelectedParts. -*/ - -/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); - - This signal is emitted when the selectability changes, by calls to \ref setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs an Axis instance of Type \a type for the axis rect \a parent. - - Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create - them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, - create them manually and then inject them also via \ref QCPAxisRect::addAxis. -*/ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), QString(), parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mTicker(new QCPAxisTicker), - mCachedMarginValid(false), - mCachedMargin(0) -{ - setParent(parent); - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) - { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) - { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) - { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) - { - setTickLabelPadding(5); - setLabelPadding(10); - } -} - -QCPAxis::~QCPAxis() -{ - delete mAxisPainter; - delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLabelPadding() const -{ - return mAxisPainter->tickLabelPadding; -} - -/* No documentation as it is a property getter */ -double QCPAxis::tickLabelRotation() const -{ - return mAxisPainter->tickLabelRotation; -} - -/* No documentation as it is a property getter */ -QCPAxis::LabelSide QCPAxis::tickLabelSide() const -{ - return mAxisPainter->tickLabelSide; -} - -/* No documentation as it is a property getter */ -QString QCPAxis::numberFormat() const -{ - QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) - { - result.append(QLatin1Char('b')); - if (mAxisPainter->numberMultiplyCross) - result.append(QLatin1Char('c')); - } - return result; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthIn() const -{ - return mAxisPainter->tickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthOut() const -{ - return mAxisPainter->tickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthIn() const -{ - return mAxisPainter->subTickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthOut() const -{ - return mAxisPainter->subTickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::labelPadding() const -{ - return mAxisPainter->labelPadding; -} - -/* No documentation as it is a property getter */ -int QCPAxis::offset() const -{ - return mAxisPainter->offset; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::lowerEnding() const -{ - return mAxisPainter->lowerEnding; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::upperEnding() const -{ - return mAxisPainter->upperEnding; -} - -/*! - Sets whether the axis uses a linear scale or a logarithmic scale. - - Note that this method controls the coordinate transformation. You will likely also want to use a - logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref - QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the - details of logarithmic axis tick creation. - - \ref setNumberPrecision -*/ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) -{ - if (mScaleType != type) - { - mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); - mCachedMarginValid = false; - emit scaleTypeChanged(mScaleType); - } -} - -/*! - Sets the range of the axis. - - This slot may be connected with the \ref rangeChanged signal of another axis so this axis - is always synchronized with the other axis range, when it changes. - - To invert the direction of an axis, use \ref setRangeReversed. -*/ -void QCPAxis::setRange(const QCPRange &range) -{ - if (range.lower == mRange.lower && range.upper == mRange.upper) - return; - - if (!QCPRange::validRange(range)) return; - QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) - { - mRange = range.sanitizedForLogScale(); - } else - { - mRange = range.sanitizedForLinScale(); - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectAxes.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font. - - The entire selection mechanism for axes is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you - wish to change the selection state manually. - - This function can change the selection state of a part, independent of the \ref setSelectableParts setting. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, - setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor -*/ -void QCPAxis::setSelectedParts(const SelectableParts &selected) -{ - if (mSelectedParts != selected) - { - mSelectedParts = selected; - emit selectionChanged(mSelectedParts); - } -} - -/*! - \overload - - Sets the lower and upper bound of the axis range. - - To invert the direction of an axis, use \ref setRangeReversed. - - There is also a slot to set a range, see \ref setRange(const QCPRange &range). -*/ -void QCPAxis::setRange(double lower, double upper) -{ - if (lower == mRange.lower && upper == mRange.upper) - return; - - if (!QCPRange::validRange(lower, upper)) return; - QCPRange oldRange = mRange; - mRange.lower = lower; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - \overload - - Sets the range of the axis. - - The \a position coordinate indicates together with the \a alignment parameter, where the new - range will be positioned. \a size defines the size of the new axis range. \a alignment may be - Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, - or center of the range to be aligned with \a position. Any other values of \a alignment will - default to Qt::AlignCenter. -*/ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) -{ - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); -} - -/*! - Sets the lower bound of the axis range. The upper bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeLower(double lower) -{ - if (mRange.lower == lower) - return; - - QCPRange oldRange = mRange; - mRange.lower = lower; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets the upper bound of the axis range. The lower bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeUpper(double upper) -{ - if (mRange.upper == upper) - return; - - QCPRange oldRange = mRange; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal - axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the - direction of increasing values is inverted. - - Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part - of the \ref setRange interface will still reference the mathematically smaller number than the \a - upper part. -*/ -void QCPAxis::setRangeReversed(bool reversed) -{ - mRangeReversed = reversed; -} - -/*! - The axis ticker is responsible for generating the tick positions and tick labels. See the - documentation of QCPAxisTicker for details on how to work with axis tickers. - - You can change the tick positioning/labeling behaviour of this axis by setting a different - QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis - ticker, access it via \ref ticker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see ticker -*/ -void QCPAxis::setTicker(QSharedPointer ticker) -{ - if (ticker) - mTicker = ticker; - else - qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; - // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector -} - -/*! - Sets whether tick marks are displayed. - - Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve - that, see \ref setTickLabels. - - \see setSubTicks -*/ -void QCPAxis::setTicks(bool show) -{ - if (mTicks != show) - { - mTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. -*/ -void QCPAxis::setTickLabels(bool show) -{ - if (mTickLabels != show) - { - mTickLabels = show; - mCachedMarginValid = false; - if (!mTickLabels) - mTickVectorLabels.clear(); - } -} - -/*! - Sets the distance between the axis base line (including any outward ticks) and the tick labels. - \see setLabelPadding, setPadding -*/ -void QCPAxis::setTickLabelPadding(int padding) -{ - if (mAxisPainter->tickLabelPadding != padding) - { - mAxisPainter->tickLabelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the font of the tick labels. - - \see setTickLabels, setTickLabelColor -*/ -void QCPAxis::setTickLabelFont(const QFont &font) -{ - if (font != mTickLabelFont) - { - mTickLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the tick labels. - - \see setTickLabels, setTickLabelFont -*/ -void QCPAxis::setTickLabelColor(const QColor &color) -{ - mTickLabelColor = color; -} - -/*! - Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, - the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values - from -90 to 90 degrees. - - If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For - other angles, the label is drawn with an offset such that it seems to point toward or away from - the tick mark. -*/ -void QCPAxis::setTickLabelRotation(double degrees) -{ - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) - { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. - - The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels - to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels - appear on the inside are additionally clipped to the axis rect. -*/ -void QCPAxis::setTickLabelSide(LabelSide side) -{ - mAxisPainter->tickLabelSide = side; - mCachedMarginValid = false; -} - -/*! - Sets the number format for the numbers in tick labels. This \a formatCode is an extended version - of the format code used e.g. by QString::number() and QLocale::toString(). For reference about - that, see the "Argument Formats" section in the detailed description of the QString class. - - \a formatCode is a string of one, two or three characters. The first character is identical to - the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed - format, 'g'/'G' scientific or fixed, whichever is shorter. - - The second and third characters are optional and specific to QCustomPlot:\n - If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. - "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for - "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 - [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. - If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can - be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the - cross and 183 (0xB7) for the dot. - - Examples for \a formatCode: - \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, - normal scientific format is used - \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with - beautifully typeset decimal powers and a dot as multiplication sign - \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as - multiplication sign - \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal - powers. Format code will be reduced to 'f'. - \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format - code will not be changed. -*/ -void QCPAxis::setNumberFormat(const QString &formatCode) -{ - if (formatCode.isEmpty()) - { - qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; - return; - } - mCachedMarginValid = false; - - // interpret first char as number format char: - QString allowedFormatChars(QLatin1String("eEfgG")); - if (allowedFormatChars.contains(formatCode.at(0))) - { - mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; - return; - } - if (formatCode.length() < 2) - { - mNumberBeautifulPowers = false; - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) - { - mNumberBeautifulPowers = true; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - return; - } - if (formatCode.length() < 3) - { - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == QLatin1Char('c')) - { - mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == QLatin1Char('d')) - { - mAxisPainter->numberMultiplyCross = false; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; - return; - } -} - -/*! - Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) - for details. The effect of precisions are most notably for number Formats starting with 'e', see - \ref setNumberFormat -*/ -void QCPAxis::setNumberPrecision(int precision) -{ - if (mNumberPrecision != precision) - { - mNumberPrecision = precision; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the - plot and \a outside is the length they will reach outside the plot. If \a outside is greater than - zero, the tick labels and axis label will increase their distance to the axis accordingly, so - they won't collide with the ticks. - - \see setSubTickLength, setTickLengthIn, setTickLengthOut -*/ -void QCPAxis::setTickLength(int inside, int outside) -{ - setTickLengthIn(inside); - setTickLengthOut(outside); -} - -/*! - Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach - inside the plot. - - \see setTickLengthOut, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthIn(int inside) -{ - if (mAxisPainter->tickLengthIn != inside) - { - mAxisPainter->tickLengthIn = inside; - } -} - -/*! - Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach - outside the plot. If \a outside is greater than zero, the tick labels and axis label will - increase their distance to the axis accordingly, so they won't collide with the ticks. - - \see setTickLengthIn, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthOut(int outside) -{ - if (mAxisPainter->tickLengthOut != outside) - { - mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets whether sub tick marks are displayed. - - Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) - - \see setTicks -*/ -void QCPAxis::setSubTicks(bool show) -{ - if (mSubTicks != show) - { - mSubTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside - the plot and \a outside is the length they will reach outside the plot. If \a outside is greater - than zero, the tick labels and axis label will increase their distance to the axis accordingly, - so they won't collide with the ticks. - - \see setTickLength, setSubTickLengthIn, setSubTickLengthOut -*/ -void QCPAxis::setSubTickLength(int inside, int outside) -{ - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); -} - -/*! - Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside - the plot. - - \see setSubTickLengthOut, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthIn(int inside) -{ - if (mAxisPainter->subTickLengthIn != inside) - { - mAxisPainter->subTickLengthIn = inside; - } -} - -/*! - Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach - outside the plot. If \a outside is greater than zero, the tick labels will increase their - distance to the axis accordingly, so they won't collide with the ticks. - - \see setSubTickLengthIn, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthOut(int outside) -{ - if (mAxisPainter->subTickLengthOut != outside) - { - mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the pen, the axis base line is drawn with. - - \see setTickPen, setSubTickPen -*/ -void QCPAxis::setBasePen(const QPen &pen) -{ - mBasePen = pen; -} - -/*! - Sets the pen, tick marks will be drawn with. - - \see setTickLength, setBasePen -*/ -void QCPAxis::setTickPen(const QPen &pen) -{ - mTickPen = pen; -} - -/*! - Sets the pen, subtick marks will be drawn with. - - \see setSubTickCount, setSubTickLength, setBasePen -*/ -void QCPAxis::setSubTickPen(const QPen &pen) -{ - mSubTickPen = pen; -} - -/*! - Sets the font of the axis label. - - \see setLabelColor -*/ -void QCPAxis::setLabelFont(const QFont &font) -{ - if (mLabelFont != font) - { - mLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the axis label. - - \see setLabelFont -*/ -void QCPAxis::setLabelColor(const QColor &color) -{ - mLabelColor = color; -} - -/*! - Sets the text of the axis label that will be shown below/above or next to the axis, depending on - its orientation. To disable axis labels, pass an empty string as \a str. -*/ -void QCPAxis::setLabel(const QString &str) -{ - if (mLabel != str) - { - mLabel = str; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the tick labels and the axis label. - - \see setTickLabelPadding, setPadding -*/ -void QCPAxis::setLabelPadding(int padding) -{ - if (mAxisPainter->labelPadding != padding) - { - mAxisPainter->labelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the padding of the axis. - - When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, - that is left blank. - - The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. - - \see setLabelPadding, setTickLabelPadding -*/ -void QCPAxis::setPadding(int padding) -{ - if (mPadding != padding) - { - mPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the offset the axis has to its axis rect side. - - If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, - only the offset of the inner most axis has meaning (even if it is set to be invisible). The - offset of the other, outer axes is controlled automatically, to place them at appropriate - positions. -*/ -void QCPAxis::setOffset(int offset) -{ - mAxisPainter->offset = offset; -} - -/*! - Sets the font that is used for tick labels when they are selected. - - \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) -{ - if (font != mSelectedTickLabelFont) - { - mSelectedTickLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts - } -} - -/*! - Sets the font that is used for the axis label when it is selected. - - \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelFont(const QFont &font) -{ - mSelectedLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts -} - -/*! - Sets the color that is used for tick labels when they are selected. - - \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) -{ - if (color != mSelectedTickLabelColor) - { - mSelectedTickLabelColor = color; - } -} - -/*! - Sets the color that is used for the axis label when it is selected. - - \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelColor(const QColor &color) -{ - mSelectedLabelColor = color; -} - -/*! - Sets the pen that is used to draw the axis base line when selected. - - \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedBasePen(const QPen &pen) -{ - mSelectedBasePen = pen; -} - -/*! - Sets the pen that is used to draw the (major) ticks when selected. - - \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickPen(const QPen &pen) -{ - mSelectedTickPen = pen; -} - -/*! - Sets the pen that is used to draw the subticks when selected. - - \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) -{ - mSelectedSubTickPen = pen; -} - -/*! - Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setUpperEnding -*/ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) -{ - mAxisPainter->lowerEnding = ending; -} - -/*! - Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the right ending, for vertical axes the top ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setLowerEnding -*/ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) -{ - mAxisPainter->upperEnding = ending; -} - -/*! - If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper - bounds of the range. The range is simply moved by \a diff. - - If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This - corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). -*/ -void QCPAxis::moveRange(double diff) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - mRange.lower += diff; - mRange.upper += diff; - } else // mScaleType == stLogarithmic - { - mRange.lower *= diff; - mRange.upper *= diff; - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis by \a factor around the center of the current axis range. For - example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis - range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around - the center will have moved symmetrically closer). - - If you wish to scale around a different coordinate than the current axis range center, use the - overload \ref scaleRange(double factor, double center). -*/ -void QCPAxis::scaleRange(double factor) -{ - scaleRange(factor, range().center()); -} - -/*! \overload - - Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a - factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at - coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates - around 1.0 will have moved symmetrically closer to 1.0). - - \see scaleRange(double factor) -*/ -void QCPAxis::scaleRange(double factor, double center) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic - { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range - { - QCPRange newRange; - newRange.lower = qPow(mRange.lower/center, factor)*center; - newRange.upper = qPow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLogScale(); - } else - qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; - } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will - be done around the center of the current axis range. - - For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs - plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the - axis rect has. - - This is an operation that changes the range of this axis once, it doesn't fix the scale ratio - indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent - won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent - will follow. -*/ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) -{ - int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) - otherPixelSize = otherAxis->axisRect()->width(); - else - otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) - ownPixelSize = axisRect()->width(); - else - ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); -} - -/*! - Changes the axis range such that all plottables associated with this axis are fully visible in - that dimension. - - \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPAxis::rescale(bool onlyVisiblePlottables) -{ - QList p = plottables(); - QCPRange newRange; - bool haveRange = false; - for (int i=0; irealVisibility() && onlyVisiblePlottables) - continue; - QCPRange plottableRange; - bool currentFoundRange; - QCP::SignDomain signDomain = QCP::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); - else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) - { - if (!haveRange) - newRange = plottableRange; - else - newRange.expand(plottableRange); - haveRange = true; - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) - { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); - } - } - setRange(newRange); - } -} - -/*! - Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. -*/ -double QCPAxis::pixelToCoord(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; - else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; - else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; - } - } -} - -/*! - Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. -*/ -double QCPAxis::coordToPixel(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; - else - { - if (!mRangeReversed) - return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - else - return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - } - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); - else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; - else - { - if (!mRangeReversed) - return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - else - return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - } - } - } -} - -/*! - Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function - is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this - function does not change the current selection state of the axis. - - If the axis is not visible (\ref setVisible), this function always returns \ref spNone. - - \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions -*/ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const -{ - if (!mVisible) - return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) - return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) - return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) - return spAxisLabel; - else - return spNone; -} - -/* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) - return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; -} - -/*! - Returns a list of all the plottables that have this axis as key or value axis. - - If you are only interested in plottables of type QCPGraph, see \ref graphs. - - \see graphs, items -*/ -QList QCPAxis::plottables() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that have this axis as key or value axis. - - \see plottables, items -*/ -QList QCPAxis::graphs() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis. An item is considered - associated with an axis if at least one of its positions uses the axis as key or value axis. - - \see plottables, graphs -*/ -QList QCPAxis::items() const -{ - QList result; - if (!mParentPlot) return result; - - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to - QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) -*/ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; - } - qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; - return atLeft; -} - -/*! - Returns the axis type that describes the opposite axis of an axis with the specified \a type. -*/ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) -{ - switch (type) - { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; - } -} - -/* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - SelectablePart part = details.value(); - if (mSelectableParts.testFlag(part)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) -{ - SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis - (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref - QCPAxisRect::setRangeDragAxes) - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. -*/ -void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || - !mAxisRect->rangeDrag().testFlag(orientation()) || - !mAxisRect->rangeDragAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - mDragStartRange = mRange; - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (mDragging) - { - const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); - const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); - if (mScaleType == QCPAxis::stLinear) - { - const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); - setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); - } else if (mScaleType == QCPAxis::stLogarithmic) - { - const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); - setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); - } - - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user zoom individual axes - exclusively, by performing the wheel event on top of the axis. - - For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis - (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref - QCPAxisRect::setRangeZoomAxes) - - \seebaseclassmethod - - \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the - axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. -*/ -void QCPAxis::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || - !mAxisRect->rangeZoom().testFlag(orientation()) || - !mAxisRect->rangeZoomAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); - scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); - mParentPlot->replot(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing axis lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); -} - -/*! \internal - - Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. - - \seebaseclassmethod -*/ -void QCPAxis::draw(QCPPainter *painter) -{ - QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->basePen = getBasePen(); - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->labelColor = getLabelColor(); - mAxisPainter->label = mLabel; - mAxisPainter->substituteExponent = mNumberBeautifulPowers; - mAxisPainter->tickPen = getTickPen(); - mAxisPainter->subTickPen = getSubTickPen(); - mAxisPainter->tickLabelFont = getTickLabelFont(); - mAxisPainter->tickLabelColor = getTickLabelColor(); - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; - mAxisPainter->reversedEndings = mRangeReversed; - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); -} - -/*! \internal - - Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling - QCPAxisTicker::generate on the currently installed ticker. - - If a change in the label text/count is detected, the cached axis margin is invalidated to make - sure the next margin calculation recalculates the label sizes and returns an up-to-date value. -*/ -void QCPAxis::setupTickVectors() -{ - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - - QVector oldLabels = mTickVectorLabels; - mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too -} - -/*! \internal - - Returns the pen that is used to draw the axis base line. Depending on the selection state, this - is either mSelectedBasePen or mBasePen. -*/ -QPen QCPAxis::getBasePen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; -} - -/*! \internal - - Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this - is either mSelectedTickPen or mTickPen. -*/ -QPen QCPAxis::getTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; -} - -/*! \internal - - Returns the pen that is used to draw the subticks. Depending on the selection state, this - is either mSelectedSubTickPen or mSubTickPen. -*/ -QPen QCPAxis::getSubTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; -} - -/*! \internal - - Returns the font that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelFont or mTickLabelFont. -*/ -QFont QCPAxis::getTickLabelFont() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; -} - -/*! \internal - - Returns the font that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelFont or mLabelFont. -*/ -QFont QCPAxis::getLabelFont() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; -} - -/*! \internal - - Returns the color that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelColor or mTickLabelColor. -*/ -QColor QCPAxis::getTickLabelColor() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; -} - -/*! \internal - - Returns the color that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelColor or mLabelColor. -*/ -QColor QCPAxis::getLabelColor() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; -} - -/*! \internal - - Returns the appropriate outward margin for this axis. It is needed if \ref - QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref - atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom - margin and so forth. For the calculation, this function goes through similar steps as \ref draw, - so changing one function likely requires the modification of the other one as well. - - The margin consists of the outward tick length, tick label padding, tick label size, label - padding, label size, and padding. - - The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. - unchanged are very fast. -*/ -int QCPAxis::calculateMargin() -{ - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis - return 0; - - if (mCachedMarginValid) - return mCachedMargin; - - // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels - int margin = 0; - - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->label = mLabel; - mAxisPainter->tickLabelFont = mTickLabelFont; - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - margin += mAxisPainter->size(); - margin += mPadding; - - mCachedMargin = margin; - mCachedMarginValid = true; - return margin; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAxis::selectionCategory() const -{ - return QCP::iSelectAxes; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisPainterPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisPainterPrivate - - \internal - \brief (Private) - - This is a private class and not part of the public QCustomPlot interface. - - It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and - axis label. It also buffers the labels to reduce replot times. The parameters are configured by - directly accessing the public member variables. -*/ - -/*! - Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every - redraw, to utilize the caching mechanisms. -*/ -QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : - type(QCPAxis::atLeft), - basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - lowerEnding(QCPLineEnding::esNone), - upperEnding(QCPLineEnding::esNone), - labelPadding(0), - tickLabelPadding(0), - tickLabelRotation(0), - tickLabelSide(QCPAxis::lsOutside), - substituteExponent(true), - numberMultiplyCross(false), - tickLengthIn(5), - tickLengthOut(0), - subTickLengthIn(2), - subTickLengthOut(0), - tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - offset(0), - abbreviateDecimalPowers(false), - reversedEndings(false), - mParentPlot(parentPlot), - mLabelCache(16) // cache at most 16 (tick) labels -{ -} - -QCPAxisPainterPrivate::~QCPAxisPainterPrivate() -{ -} - -/*! \internal - - Draws the axis with the specified \a painter. - - The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set - here, too. -*/ -void QCPAxisPainterPrivate::draw(QCPPainter *painter) -{ - QByteArray newHash = generateLabelParameterHash(); - if (newHash != mLabelParameterHash) - { - mLabelCache.clear(); - mLabelParameterHash = newHash; - } - - QPoint origin; - switch (type) - { - case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; - case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; - case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; - case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; - } - - double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) - switch (type) - { - case QCPAxis::atTop: yCor = -1; break; - case QCPAxis::atRight: xCor = 1; break; - default: break; - } - int margin = 0; - // draw baseline: - QLineF baseLine; - painter->setPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); - else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - - // draw ticks: - if (!tickPositions.isEmpty()) - { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); - } - } - - // draw subticks: - if (!subTickPositions.isEmpty()) - { - painter->setPen(subTickPen); - // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); - } - } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // draw axis base endings: - bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - - // tick labels: - QRect oldClipRect; - if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect - { - oldClipRect = painter->clipRegion().boundingRect(); - painter->setClipRect(axisRect); - } - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) - { - if (tickLabelSide == QCPAxis::lsOutside) - margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); - int distanceToAxis = margin; - if (tickLabelSide == QCPAxis::lsInside) - distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - for (int i=0; isetClipRect(oldClipRect); - - // axis label: - QRect labelBounds; - if (!label.isEmpty()) - { - margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atRight) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); - painter->rotate(90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - } - - // set selection boxes: - int selectionTolerance = 0; - if (mParentPlot) - selectionTolerance = mParentPlot->selectionTolerance(); - else - qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); - int selAxisInSize = selectionTolerance; - int selTickLabelSize; - int selTickLabelOffset; - if (tickLabelSide == QCPAxis::lsOutside) - { - selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - } else - { - selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - } - int selLabelSize = labelBounds.height(); - int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; - if (type == QCPAxis::atLeft) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atRight) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atTop) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); - } - mAxisSelectionBox = mAxisSelectionBox.normalized(); - mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); - mLabelSelectionBox = mLabelSelectionBox.normalized(); - // draw hitboxes for debug purposes: - //painter->setBrush(Qt::NoBrush); - //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); -} - -/*! \internal - - Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone - direction) needed to fit the axis. -*/ -int QCPAxisPainterPrivate::size() const -{ - int result = 0; - - // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // calculate size of tick labels: - if (tickLabelSide == QCPAxis::lsOutside) - { - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) - { - for (int i=0; ibufferDevicePixelRatio())); - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)tickLabelSide)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString().toLatin1()); - return result; -} - -/*! \internal - - Draws a single tick label with the provided \a painter, utilizing the internal label cache to - significantly speed up drawing of labels that were drawn in previous calls. The tick label is - always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in - pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence - for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), - at which the label should be drawn. - - In order to later draw the axis label in a place that doesn't overlap with the tick labels, the - largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref - drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a - tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently - holds. - - The label is drawn with the font and pen that are currently set on the \a painter. To draw - superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref - getTickLabelData). -*/ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) -{ - // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; - QSize finalSize; - QPointF labelAnchor; - switch (type) - { - case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; - } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled - { - CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache - if (!cachedLabel) // no cached label existed, create it - { - cachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); - if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) - { - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); -# else - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); -# endif -#endif - } else - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - cachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&cachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); - } - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); - else - labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } - mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created - } else // label caching disabled, draw text directly on surface: - { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); - else - labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); - finalSize = labelData.rotatedTotalBounds.size(); - } - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a - y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to - directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when - QCP::phCacheLabels plotting hint is not set. -*/ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const -{ - // backup painter settings that we're about to change: - QTransform oldTransform = painter->transform(); - QFont oldFont = painter->font(); - - // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - - // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - if (!labelData.suffixPart.isEmpty()) - painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); - } - - // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Transforms the passed \a text and \a font to a tickLabelData structure that can then be further - processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and - exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. -*/ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const -{ - TickLabelData result; - - // determine whether beautiful decimal powers should be used - bool useBeautifulPowers = false; - int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart - int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart - if (substituteExponent) - { - ePos = text.indexOf(QLatin1Char('e')); - if (ePos > 0 && text.at(ePos-1).isDigit()) - { - eLast = ePos; - while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) - ++eLast; - if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power - useBeautifulPowers = true; - } - } - - // calculate text bounding rects and do string preparation for beautiful decimal powers: - result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) - { - // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent - // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) - result.basePart = QLatin1String("10"); - else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); - result.expPart = text.mid(ePos+1, eLast-ePos); - // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) - result.expPart.remove(0, 1); - // prepare smaller font for exponent: - result.expFont = font; - if (result.expFont.pointSize() > 0) - result.expFont.setPointSize(result.expFont.pointSize()*0.75); - else - result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); - // calculate bounding rects of base part(s), exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - if (!result.suffixPart.isEmpty()) - result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false - { - result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); - } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - - // calculate possibly different bounding rect after rotation: - result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) - { - QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); - } - - return result; -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Calculates the offset at which the top left corner of the specified tick label shall be drawn. - The offset is relative to a point right next to the tick the label belongs to. - - This function is thus responsible for e.g. centering tick labels under ticks and positioning them - appropriately when they are rotated. -*/ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const -{ - /* - calculate label offset from base point at tick (non-trivial, for best visual appearance): short - explanation for bottom axis: The anchor, i.e. the point in the label that is placed - horizontally under the corresponding tick is always on the label side that is closer to the - axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height - is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text - will be centered under the tick (i.e. displaced horizontally by half its height). At the same - time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick - labels. - */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = 0; - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = -labelData.totalBounds.height(); - } - } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; - y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = 0; - } - } - - return QPointF(x, y); -} - -/*! \internal - - Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label - to be drawn, depending on number format etc. Since only the largest tick label is wanted for the - margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a - smaller width/height. -*/ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const -{ - // note: this function must return the same tick label sizes as the placeTickLabel function. - QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label - { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } else // label caching disabled or no label with this text cached: - { - TickLabelData labelData = getTickLabelData(font, text); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} -/* end of 'src/axis/axis.cpp' */ - - -/* including file 'src/scatterstyle.cpp', size 17450 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPScatterStyle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPScatterStyle - \brief Represents the visual appearance of scatter points - - This class holds information about shape, color and size of scatter points. In plottables like - QCPGraph it is used to store how scatter points shall be drawn. For example, \ref - QCPGraph::setScatterStyle takes a QCPScatterStyle instance. - - A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a - fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can - be controlled with \ref setSize. - - \section QCPScatterStyle-defining Specifying a scatter style - - You can set all these configurations either by calling the respective functions on an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 - - Or you can use one of the various constructors that take different parameter combinations, making - it easy to specify a scatter style in a single call, like so: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 - - \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable - - There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref - QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref - isPenDefined will return false. It leads to scatter points that inherit the pen from the - plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line - color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes - it very convenient to set up typical scatter settings: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation - - Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works - because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly - into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) - constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref - ScatterShape, where actually a QCPScatterStyle is expected. - - \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps - - QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. - - For custom shapes, you can provide a QPainterPath with the desired shape to the \ref - setCustomPath function or call the constructor that takes a painter path. The scatter shape will - automatically be set to \ref ssCustom. - - For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the - constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. - Note that \ref setSize does not influence the appearance of the pixmap. -*/ - -/* start documentation of inline functions */ - -/*! \fn bool QCPScatterStyle::isNone() const - - Returns whether the scatter shape is \ref ssNone. - - \see setShape -*/ - -/*! \fn bool QCPScatterStyle::isPenDefined() const - - Returns whether a pen has been defined for this scatter style. - - The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those - are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen - is undefined, the pen of the respective plottable will be used for drawing scatters. - - If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call - \ref undefinePen. - - \see setPen -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or - brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - and size to \a size. No brush is defined, i.e. the scatter point will not be filled. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - the brush color to \a fill (with a solid pattern), and size to \a size. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the - brush to \a brush, and size to \a size. - - \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen - and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n - QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n - doesn't necessarily lead C++ to use this constructor in some cases, but might mistake - Qt::NoPen for a QColor and use the - \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) - constructor instead (which will lead to an unexpected look of the scatter points). To prevent - this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) - instead of just Qt::blue, to clearly point out to the compiler that this constructor is - wanted. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape - is set to \ref ssPixmap. -*/ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The - scatter shape is set to \ref ssCustom. - - The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly - different meaning than for built-in scatter points: The custom path will be drawn scaled by a - factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its - original size by default. To for example double the size of the path, set \a size to 12. -*/ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Copies the specified \a properties from the \a other scatter style to this scatter style. -*/ -void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) -{ - if (properties.testFlag(spPen)) - { - setPen(other.pen()); - if (!other.isPenDefined()) - undefinePen(); - } - if (properties.testFlag(spBrush)) - setBrush(other.brush()); - if (properties.testFlag(spSize)) - setSize(other.size()); - if (properties.testFlag(spShape)) - { - setShape(other.shape()); - if (other.shape() == ssPixmap) - setPixmap(other.pixmap()); - else if (other.shape() == ssCustom) - setCustomPath(other.customPath()); - } -} - -/*! - Sets the size (pixel diameter) of the drawn scatter points to \a size. - - \see setShape -*/ -void QCPScatterStyle::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the shape to \a shape. - - Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref - ssPixmap and \ref ssCustom, respectively. - - \see setSize -*/ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) -{ - mShape = shape; -} - -/*! - Sets the pen that will be used to draw scatter points to \a pen. - - If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after - a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen - previously by calling this function and now wish to undefine the pen, call \ref undefinePen. - - \see setBrush -*/ -void QCPScatterStyle::setPen(const QPen &pen) -{ - mPenDefined = true; - mPen = pen; -} - -/*! - Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter - shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. - - \see setPen -*/ -void QCPScatterStyle::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the pixmap that will be drawn as scatter point to \a pixmap. - - Note that \ref setSize does not influence the appearance of the pixmap. - - The scatter shape is automatically set to \ref ssPixmap. -*/ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) -{ - setShape(ssPixmap); - mPixmap = pixmap; -} - -/*! - Sets the custom shape that will be drawn as scatter point to \a customPath. - - The scatter shape is automatically set to \ref ssCustom. -*/ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) -{ - setShape(ssCustom); - mCustomPath = customPath; -} - -/*! - Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen - implies). - - A call to \ref setPen will define a pen. -*/ -void QCPScatterStyle::undefinePen() -{ - mPenDefined = false; -} - -/*! - Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an - undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. - - This function is used by plottables (or any class that wants to draw scatters) just before a - number of scatters with this style shall be drawn with the \a painter. - - \see drawShape -*/ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const -{ - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); -} - -/*! - Draws the scatter shape with \a painter at position \a pos. - - This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be - called before scatter points are drawn with \ref drawShape. - - \see applyTo -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const -{ - drawShape(painter, pos.x(), pos.y()); -} - -/*! \overload - Draws the scatter shape with \a painter at position \a x and \a y. -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const -{ - double w = mSize/2.0; - switch (mShape) - { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - QPointF lineArray[4] = {QPointF(x-w, y), - QPointF( x, y-w), - QPointF(x+w, y), - QPointF( x, y+w)}; - painter->drawPolygon(lineArray, 4); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), - QPointF(x+w, y+0.755*w), - QPointF( x, y-0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssTriangleInverted: - { - QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), - QPointF(x+w, y-0.755*w), - QPointF( x, y+0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssCrossSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - break; - } - case ssPlusSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCrossCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - break; - } - case ssPlusCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssPeace: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - break; - } - case ssPixmap: - { - const double widthHalf = mPixmap.width()*0.5; - const double heightHalf = mPixmap.height()*0.5; -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) - const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#else - const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#endif - if (clipRect.contains(x, y)) - painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } - } -} -/* end of 'src/scatterstyle.cpp' */ - -//amalgamation: add datacontainer.cpp - -/* including file 'src/plottable.cpp', size 38845 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecorator -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecorator - \brief Controls how a plottable's data selection is drawn - - Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref - QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. - - The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the - scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref - QCPScatterStyle is itself composed of different properties such as color shape and size, the - decorator allows specifying exactly which of those properties shall be used for the selected data - point, via \ref setUsedScatterProperties. - - A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref - QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance - of selected segments. - - Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is - especially useful since plottables take ownership of the passed selection decorator, and thus the - same decorator instance can not be passed to multiple plottables. - - Selection decorators can also themselves perform drawing operations by reimplementing \ref - drawDecoration, which is called by the plottable's draw method. The base class \ref - QCPSelectionDecorator does not make use of this however. For example, \ref - QCPSelectionDecoratorBracket draws brackets around selected data segments. -*/ - -/*! - Creates a new QCPSelectionDecorator instance with default values -*/ -QCPSelectionDecorator::QCPSelectionDecorator() : - mPen(QColor(80, 80, 255), 2.5), - mBrush(Qt::NoBrush), - mScatterStyle(), - mUsedScatterProperties(QCPScatterStyle::spNone), - mPlottable(0) -{ -} - -QCPSelectionDecorator::~QCPSelectionDecorator() -{ -} - -/*! - Sets the pen that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the scatter style that will be used by the parent plottable to draw scatters in selected - data segments. - - \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the - plottable. The used properties can also be changed via \ref setUsedScatterProperties. -*/ -void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) -{ - mScatterStyle = scatterStyle; - setUsedScatterProperties(usedProperties); -} - -/*! - Use this method to define which properties of the scatter style (set via \ref setScatterStyle) - will be used for selected data segments. All properties of the scatter style that are not - specified in \a properties will remain as specified in the plottable's original scatter style. - - \see QCPScatterStyle::ScatterProperty -*/ -void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) -{ - mUsedScatterProperties = properties; -} - -/*! - Sets the pen of \a painter to the pen of this selection decorator. - - \see applyBrush, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyPen(QCPPainter *painter) const -{ - painter->setPen(mPen); -} - -/*! - Sets the brush of \a painter to the brush of this selection decorator. - - \see applyPen, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const -{ - painter->setBrush(mBrush); -} - -/*! - Returns the scatter style that the parent plottable shall use for selected scatter points. The - plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending - on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this - selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. - - \see applyPen, applyBrush, setScatterStyle -*/ -QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const -{ - QCPScatterStyle result(unselectedStyle); - result.setFromOther(mScatterStyle, mUsedScatterProperties); - - // if style shall inherit pen from plottable (has no own pen defined), give it the selected - // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the - // plottable: - if (!result.isPenDefined()) - result.setPen(mPen); - - return result; -} - -/*! - Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to - this selection decorator. -*/ -void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) -{ - setPen(other->pen()); - setBrush(other->brush()); - setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); -} - -/*! - This method is called by all plottables' draw methods to allow custom selection decorations to be - drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data - selection for which the decoration shall be drawn. - - The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so - this method does nothing. -*/ -void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - Q_UNUSED(painter) - Q_UNUSED(selection) -} - -/*! \internal - - This method is called as soon as a selection decorator is associated with a plottable, by a call - to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access - data points via the \ref QCPAbstractPlottable::interface1D interface). - - If the selection decorator was already added to a different plottable before, this method aborts - the registration and returns false. -*/ -bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottable) - { - mPlottable = plottable; - return true; - } else - { - qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); - return false; - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable - \brief The abstract base class for all data representing objects in a plot. - - It defines a very basic interface like name, pen, brush, visibility etc. Since this class is - abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to - create new ways of displaying data (see "Creating own plottables" below). Plottables that display - one-dimensional data (i.e. data points have a single key dimension and one or multiple values at - each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details - there. - - All further specifics are in the subclasses, for example: - \li A normal graph with possibly a line and/or scatter points \ref QCPGraph - (typically created with \ref QCustomPlot::addGraph) - \li A parametric curve: \ref QCPCurve - \li A bar chart: \ref QCPBars - \li A statistical box plot: \ref QCPStatisticalBox - \li A color encoded two-dimensional map: \ref QCPColorMap - \li An OHLC/Candlestick chart: \ref QCPFinancial - - \section plottables-subclassing Creating own plottables - - Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display - two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) - data dimensions. If you want to display data with only one logical key dimension, you should - rather derive from \ref QCPAbstractPlottable1D. - - If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must - implement: - \li \ref selectTest - \li \ref draw - \li \ref drawLegendIcon - \li \ref getKeyRange - \li \ref getValueRange - - See the documentation of those functions for what they need to do. - - For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot - coordinates to pixel coordinates. This function is quite convenient, because it takes the - orientation of the key and value axes into account for you (x and y are swapped when the key axis - is vertical and the value axis horizontal). If you are worried about performance (i.e. you need - to translate many points in a loop like QCPGraph), you can directly use \ref - QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis - yourself. - - Here are some important members you inherit from QCPAbstractPlottable: - - - - - - - - - - - - - - - - - - - - - - - - - - -
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable - (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable - (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates - to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of - the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. - When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. - Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done - by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
-*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const - - Provides access to the selection decorator of this plottable. The selection decorator controls - how selected data ranges are drawn (e.g. their pen color and fill), see \ref - QCPSelectionDecorator for details. - - If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref - setSelectionDecorator. -*/ - -/*! \fn bool QCPAbstractPlottable::selected() const - - Returns true if there are any data points of the plottable currently selected. Use \ref selection - to retrieve the current \ref QCPDataSelection. -*/ - -/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const - - Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on - this plottable. - - \see selected, setSelection, setSelectable -*/ - -/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() - - If this plottable is a one-dimensional plottable, i.e. it implements the \ref - QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case - of a \ref QCPColorMap) returns zero. - - You can use this method to gain read access to data coordinates while holding a pointer to the - abstract base class only. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of pure virtual functions */ - -/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 - \internal - - called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation - of this plottable inside \a rect, next to the plottable name. - - The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't - appear outside the legend icon border. -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 - - Returns the coordinate range that all data in this plottable span in the key axis dimension. For - logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref - QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only - negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points - will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref - QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could - be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getValueRange -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 - - Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span - in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref - QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign - domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and - all positive points will be ignored for range calculation. For no restriction, just set \a - inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates - whether a range could be found or not. If this is false, you shouldn't use the returned range - (e.g. no points in data). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getKeyRange -*/ - -/* end of documentation of pure virtual functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether - there are any points selected or not. - - \see selectionChanged(const QCPDataSelection &selection) -*/ - -/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selection holds the - currently selected data ranges. - - \see selectionChanged(bool selected) -*/ - -/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); - - This signal is emitted when the selectability of this plottable has changed. - - \see setSelectable -*/ - -/* end of documentation of signals */ - -/*! - Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as - its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance - and have perpendicular orientations. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, - it can't be directly instantiated. - - You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. -*/ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), - mName(), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mPen(Qt::black), - mBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(QCP::stWhole), - mSelectionDecorator(0) -{ - if (keyAxis->parentPlot() != valueAxis->parentPlot()) - qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) - qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; - - mParentPlot->registerPlottable(this); - setSelectionDecorator(new QCPSelectionDecorator); -} - -QCPAbstractPlottable::~QCPAbstractPlottable() -{ - if (mSelectionDecorator) - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - The name is the textual representation of this plottable as it is displayed in the legend - (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. -*/ -void QCPAbstractPlottable::setName(const QString &name) -{ - mName = name; -} - -/*! - Sets whether fills of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) -{ - mAntialiasedFill = enabled; -} - -/*! - Sets whether the scatter symbols of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) -{ - mAntialiasedScatters = enabled; -} - -/*! - The pen is used to draw basic lines that make up the plottable representation in the - plot. - - For example, the \ref QCPGraph subclass draws its graph lines with this pen. - - \see setBrush -*/ -void QCPAbstractPlottable::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - The brush is used to draw basic fills of the plottable representation in the - plot. The Fill can be a color, gradient or texture, see the usage of QBrush. - - For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when - it's not set to Qt::NoBrush. - - \see setPen -*/ -void QCPAbstractPlottable::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal - to the plottable's value axis. This function performs no checks to make sure this is the case. - The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the - y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setValueAxis -*/ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) -{ - mKeyAxis = axis; -} - -/*! - The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is - orthogonal to the plottable's key axis. This function performs no checks to make sure this is the - case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and - the y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setKeyAxis -*/ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) -{ - mValueAxis = axis; -} - - -/*! - Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently - (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref - selectionDecorator). - - The entire selection mechanism for plottables is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when - you wish to change the selection state programmatically. - - Using \ref setSelectable you can further specify for each plottable whether and to which - granularity it is selectable. If \a selection is not compatible with the current \ref - QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted - accordingly (see \ref QCPDataSelection::enforceType). - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractPlottable::setSelection(QCPDataSelection selection) -{ - selection.enforceType(mSelectable); - if (mSelection != selection) - { - mSelection = selection; - emit selectionChanged(selected()); - emit selectionChanged(mSelection); - } -} - -/*! - Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to - customize the visual representation of selected data ranges further than by using the default - QCPSelectionDecorator. - - The plottable takes ownership of the \a decorator. - - The currently set decorator can be accessed via \ref selectionDecorator. -*/ -void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) -{ - if (decorator) - { - if (decorator->registerWithPlottable(this)) - { - if (mSelectionDecorator) // delete old decorator if necessary - delete mSelectionDecorator; - mSelectionDecorator = decorator; - } - } else if (mSelectionDecorator) // just clear decorator - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - Sets whether and to which granularity this plottable can be selected. - - A selection can happen by clicking on the QCustomPlot surface (When \ref - QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect - (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by - calling \ref setSelection. - - \see setSelection, QCP::SelectionType -*/ -void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - QCPDataSelection oldSelection = mSelection; - mSelection.enforceType(mSelectable); - emit selectableChanged(mSelectable); - if (mSelection != oldSelection) - { - emit selectionChanged(selected()); - emit selectionChanged(mSelection); - } - } -} - - -/*! - Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. - - \see pixelsToCoords, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else - { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); - } -} - -/*! \overload - - Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. -*/ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); - else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); -} - -/*! - Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. - - \see coordsToPixels, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else - { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); - } -} - -/*! \overload - - Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. -*/ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const -{ - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); -} - -/*! - Rescales the key and value axes associated with this plottable to contain all displayed data, so - the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make - sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. - Instead it will stay in the current sign domain and ignore all parts of the plottable that lie - outside of that domain. - - \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show - multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has - \a onlyEnlarge set to false (the default), and all subsequent set to true. - - \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale -*/ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const -{ - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); -} - -/*! - Rescales the key axis of the plottable so the whole plottable is visible. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); - } - } - keyAxis->setRange(newRange); - } -} - -/*! - Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is - set to true, only the data points which are in the currently visible key axis range are - considered. - - Returns true if the axis was actually scaled. This might not be the case if this plottable has an - invalid range, e.g. because it has no data points. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); - } - } - valueAxis->setRange(newRange); - } -} - -/*! \overload - - Adds this plottable to the specified \a legend. - - Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. - when the legend exists and a legend item associated with this plottable isn't already in the - legend. - - If the plottable needs a more specialized representation in the legend, you can create a - corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead - of calling this method. - - \see removeFromLegend, QCPLegend::addItem -*/ -bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - if (legend->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; - return false; - } - - if (!legend->hasItemWithPlottable(this)) - { - legend->addItem(new QCPPlottableLegendItem(legend, this)); - return true; - } else - return false; -} - -/*! \overload - - Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). - - \see removeFromLegend -*/ -bool QCPAbstractPlottable::addToLegend() -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return addToLegend(mParentPlot->legend); -} - -/*! \overload - - Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem - that is associated with this plottable is removed. - - Returns true on success, i.e. if the legend exists and a legend item associated with this - plottable was found and removed. - - \see addToLegend, QCPLegend::removeItem -*/ -bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - - if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) - return legend->removeItem(lip); - else - return false; -} - -/*! \overload - - Removes the plottable from the legend of the parent QCustomPlot. - - \see addToLegend -*/ -bool QCPAbstractPlottable::removeFromLegend() const -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return removeFromLegend(mParentPlot->legend); -} - -/* inherits documentation from base class */ -QRect QCPAbstractPlottable::clipRect() const -{ - if (mKeyAxis && mValueAxis) - return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - else - return QRect(); -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractPlottable::selectionCategory() const -{ - return QCP::iSelectPlottables; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable fills. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable scatter points. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint -*/ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - - if (mSelectable != QCP::stNone) - { - QCPDataSelection newSelection = details.value(); - QCPDataSelection selectionBefore = mSelection; - if (additive) - { - if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit - { - if (selected()) - setSelection(QCPDataSelection()); - else - setSelection(newSelection); - } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments - { - if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection - setSelection(mSelection-newSelection); - else - setSelection(mSelection+newSelection); - } - } else - setSelection(newSelection); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable != QCP::stNone) - { - QCPDataSelection selectionBefore = mSelection; - setSelection(QCPDataSelection()); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} -/* end of 'src/plottable.cpp' */ - - -/* including file 'src/item.cpp', size 49269 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemAnchor -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemAnchor - \brief An anchor of an item to which positions can be attached to. - - An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't - control anything on its item, but provides a way to tie other items via their positions to the - anchor. - - For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. - Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can - attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by - calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the - QCPItemRect. This way the start of the line will now always follow the respective anchor location - on the rect item. - - Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an - anchor to other positions. - - To learn how to provide anchors in your own item subclasses, see the subclassing section of the - QCPAbstractItem documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() - - Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if - it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). - - This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids - dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with - gcc compiler). -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) -{ -} - -QCPItemAnchor::~QCPItemAnchor() -{ - // unregister as parent at children: - foreach (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - foreach (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } -} - -/*! - Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. - - The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the - parent item, QCPItemAnchor is just an intermediary. -*/ -QPointF QCPItemAnchor::pixelPosition() const -{ - if (mParentItem) - { - if (mAnchorId > -1) - { - return mParentItem->anchorPixelPosition(mAnchorId); - } else - { - qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; - return QPointF(); - } - } else - { - qDebug() << Q_FUNC_INFO << "no parent item set"; - return QPointF(); - } -} - -/*! \internal - - Adds \a pos to the childX list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.contains(pos)) - mChildrenX.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childX list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - -/*! \internal - - Adds \a pos to the childY list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.contains(pos)) - mChildrenY.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childY list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPosition -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPosition - \brief Manages the position of an item. - - Every item has at least one public QCPItemPosition member pointer which provides ways to position the - item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: - \a topLeft and \a bottomRight. - - QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type - defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel - coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also - possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref - setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y - direction, while following a plot coordinate in the X direction. - - A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie - multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) - are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) - means directly ontop of the parent anchor. For example, You could attach the \a start position of - a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line - always be centered under the text label, no matter where the text is moved to. For more advanced - plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see - \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X - direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B - in Y. - - Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent - anchor for other positions. - - To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This - works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref - setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified - pixel values. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const - - Returns the current position type. - - If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the - type of the X coordinate. In that case rather use \a typeX() and \a typeY(). - - \see setType -*/ - -/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const - - Returns the current parent anchor. - - If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), - this method returns the parent anchor of the Y coordinate. In that case rather use \a - parentAnchorX() and \a parentAnchorY(). - - \see setParentAnchor -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionTypeX(ptAbsolute), - mPositionTypeY(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchorX(0), - mParentAnchorY(0) -{ -} - -QCPItemPosition::~QCPItemPosition() -{ - // unregister as parent at children: - // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then - // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition - foreach (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - foreach (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } - // unregister as child in parent: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const -{ - return mAxisRect.data(); -} - -/*! - Sets the type of the position. The type defines how the coordinates passed to \ref setCoords - should be handled and how the QCPItemPosition should behave in the plot. - - The possible values for \a type can be separated in two main categories: - - \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords - and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. - By default, the QCustomPlot's x- and yAxis are used. - - \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This - corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref - ptAxisRectRatio. They differ only in the way the absolute position is described, see the - documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify - the axis rect with \ref setAxisRect. By default this is set to the main axis rect. - - Note that the position type \ref ptPlotCoords is only available (and sensible) when the position - has no parent anchor (\ref setParentAnchor). - - If the type is changed, the apparent pixel position on the plot is preserved. This means - the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. - - This method sets the type for both X and Y directions. It is also possible to set different types - for X and Y, see \ref setTypeX, \ref setTypeY. -*/ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) -{ - setTypeX(type); - setTypeY(type); -} - -/*! - This method sets the position type of the X coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeY -*/ -void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) -{ - if (mPositionTypeX != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeX = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - This method sets the position type of the Y coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeX -*/ -void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) -{ - if (mPositionTypeY != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeY = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now - follow any position changes of the anchor. The local coordinate system of positions with a parent - anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence - the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) - - if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved - during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position - will be exactly on top of the parent anchor. - - To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. - - If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is - set to \ref ptAbsolute, to keep the position in a valid state. - - This method sets the parent anchor for both X and Y directions. It is also possible to set - different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. -*/ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); - bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); - return successX && successY; -} - -/*! - This method sets the parent anchor of the X coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorY -*/ -bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorX(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) - setTypeX(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildX(this); - mParentAnchorX = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(0, coords().y()); - return true; -} - -/*! - This method sets the parent anchor of the Y coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorX -*/ -bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorY(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) - setTypeY(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildY(this); - mParentAnchorY = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(coords().x(), 0); - return true; -} - -/*! - Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type - (\ref setType, \ref setTypeX, \ref setTypeY). - - For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position - on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the - QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the - plot coordinate system defined by the axes set by \ref setAxes. By default those are the - QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available - coordinate types and their meaning. - - If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a - value must also be provided in the different coordinate systems. Here, the X type refers to \a - key, and the Y type refers to \a value. - - \see setPixelPosition -*/ -void QCPItemPosition::setCoords(double key, double value) -{ - mKey = key; - mValue = value; -} - -/*! \overload - - Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the - meaning of \a value of the \ref setCoords(double key, double value) method. -*/ -void QCPItemPosition::setCoords(const QPointF &pos) -{ - setCoords(pos.x(), pos.y()); -} - -/*! - Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It - includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). - - \see setPixelPosition -*/ -QPointF QCPItemPosition::pixelPosition() const -{ - QPointF result; - - // determine X: - switch (mPositionTypeX) - { - case ptAbsolute: - { - result.rx() = mKey; - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - result.rx() = mKey*mParentPlot->viewport().width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mParentPlot->viewport().left(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.rx() = mKey*mAxisRect.data()->width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mAxisRect.data()->left(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - // determine Y: - switch (mPositionTypeY) - { - case ptAbsolute: - { - result.ry() = mValue; - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - result.ry() = mValue*mParentPlot->viewport().height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mParentPlot->viewport().top(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.ry() = mValue*mAxisRect.data()->height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mAxisRect.data()->top(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - result.ry() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - result.ry() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - return result; -} - -/*! - When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the - coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and - yAxis of the QCustomPlot. -*/ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - mKeyAxis = keyAxis; - mValueAxis = valueAxis; -} - -/*! - When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the - coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of - the QCustomPlot. -*/ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) -{ - mAxisRect = axisRect; -} - -/*! - Sets the apparent pixel position. This works no matter what type (\ref setType) this - QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed - appropriately, to make the position finally appear at the specified pixel values. - - Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is - identical to that of \ref setCoords. - - \see pixelPosition, setCoords -*/ -void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) -{ - double x = pixelPosition.x(); - double y = pixelPosition.y(); - - switch (mPositionTypeX) - { - case ptAbsolute: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mParentPlot->viewport().left(); - x /= (double)mParentPlot->viewport().width(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mAxisRect.data()->left(); - x /= (double)mAxisRect.data()->width(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - x = mKeyAxis.data()->pixelToCoord(x); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - y = mValueAxis.data()->pixelToCoord(x); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - switch (mPositionTypeY) - { - case ptAbsolute: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mParentPlot->viewport().top(); - y /= (double)mParentPlot->viewport().height(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mAxisRect.data()->top(); - y /= (double)mAxisRect.data()->height(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - x = mKeyAxis.data()->pixelToCoord(y); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - y = mValueAxis.data()->pixelToCoord(y); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - setCoords(x, y); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractItem - \brief The abstract base class for all items in a plot. - - In QCustomPlot, items are supplemental graphical elements that are neither plottables - (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus - plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each - specific item has at least one QCPItemPosition member which controls the positioning. Some items - are defined by more than one coordinate and thus have two or more QCPItemPosition members (For - example, QCPItemRect has \a topLeft and \a bottomRight). - - This abstract base class defines a very basic interface like visibility and clipping. Since this - class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass - yourself to create new items. - - The built-in items are: - - - - - - - - - - -
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
- - \section items-clipping Clipping - - Items are by default clipped to the main axis rect (they are only visible inside the axis rect). - To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect - "setClipToAxisRect(false)". - - On the other hand if you want the item to be clipped to a different axis rect, specify it via - \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and - in principle is independent of the coordinate axes the item might be tied to via its position - members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping - also contains the axes used for the item positions. - - \section items-using Using items - - First you instantiate the item you want to use and add it to the plot: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 - by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just - set the plot coordinates where the line should start/end: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 - If we don't want the line to be positioned in plot coordinates but a different coordinate system, - e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 - Then we can set the coordinates, this time in pixels: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 - and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 - - For more advanced plots, it is even possible to set different types and parent anchors per X/Y - coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref - QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. - - \section items-subclassing Creating own items - - To create an own item, you implement a subclass of QCPAbstractItem. These are the pure - virtual functions, you must implement: - \li \ref selectTest - \li \ref draw - - See the documentation of those functions for what they need to do. - - \subsection items-positioning Allowing the item to be positioned - - As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall - have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add - a public member of type QCPItemPosition like so: - - \code QCPItemPosition * const myPosition;\endcode - - the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition - instance it points to, can be modified, of course). - The initialization of this pointer is made easy with the \ref createPosition function. Just assign - the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition - takes a string which is the name of the position, typically this is identical to the variable name. - For example, the constructor of QCPItemExample could look like this: - - \code - QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - myPosition(createPosition("myPosition")) - { - // other constructor code - } - \endcode - - \subsection items-drawing The draw function - - To give your item a visual representation, reimplement the \ref draw function and use the passed - QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the - position member(s) via \ref QCPItemPosition::pixelPosition. - - To optimize performance you should calculate a bounding rect first (don't forget to take the pen - width into account), check whether it intersects the \ref clipRect, and only draw the item at all - if this is the case. - - \subsection items-selection The selectTest function - - Your implementation of the \ref selectTest function may use the helpers \ref - QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the - selection test becomes significantly simpler for most items. See the documentation of \ref - selectTest for what the function parameters mean and what the function should return. - - \subsection anchors Providing anchors - - Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public - member, e.g. - - \code QCPItemAnchor * const bottom;\endcode - - and create it in the constructor with the \ref createAnchor function, assigning it a name and an - anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). - Since anchors can be placed anywhere, relative to the item's position(s), your item needs to - provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int - anchorId) function. - - In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel - position when anything attached to the anchor needs to know the coordinates. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QList QCPAbstractItem::positions() const - - Returns all positions of the item in a list. - - \see anchors, position -*/ - -/*! \fn QList QCPAbstractItem::anchors() const - - Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always - also an anchor, the list will also contain the positions of this item. - - \see positions, anchor -*/ - -/* end of documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 - \internal - - Draws this item with the provided \a painter. - - The cliprect of the provided painter is set to the rect returned by \ref clipRect before this - function is called. The clipRect depends on the clipping settings defined by \ref - setClipToAxisRect and \ref setClipAxisRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPAbstractItem::selectionChanged(bool selected) - This signal is emitted when the selection state of this item has changed, either by user interaction - or by a direct call to \ref setSelected. -*/ - -/* end documentation of signals */ - -/*! - Base class constructor which initializes base class members. -*/ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) -{ - parentPlot->registerItem(this); - - QList rects = parentPlot->axisRects(); - if (rects.size() > 0) - { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); - } -} - -QCPAbstractItem::~QCPAbstractItem() -{ - // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const -{ - return mClipAxisRect.data(); -} - -/*! - Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the - entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. - - \see setClipAxisRect -*/ -void QCPAbstractItem::setClipToAxisRect(bool clip) -{ - mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref - setClipToAxisRect is set to true. - - \see setClipToAxisRect -*/ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) -{ - mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected. - - \see QCustomPlot::setInteractions, setSelected -*/ -void QCPAbstractItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets whether this item is selected or not. When selected, it might use a different visual - appearance (e.g. pen and brush), this depends on the specific item though. - - The entire selection mechanism for items is handled automatically when \ref - QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this - function when you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/*! - Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by - that name, returns 0. - - This function provides an alternative way to access item positions. Normally, you access - positions direcly by their member pointers (which typically have the same variable name as \a - name). - - \see positions, anchor -*/ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const -{ - for (int i=0; iname() == name) - return mPositions.at(i); - } - qDebug() << Q_FUNC_INFO << "position with name not found:" << name; - return 0; -} - -/*! - Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by - that name, returns 0. - - This function provides an alternative way to access item anchors. Normally, you access - anchors direcly by their member pointers (which typically have the same variable name as \a - name). - - \see anchors, position -*/ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const -{ - for (int i=0; iname() == name) - return mAnchors.at(i); - } - qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; - return 0; -} - -/*! - Returns whether this item has an anchor with the specified \a name. - - Note that you can check for positions with this function, too. This is because every position is - also an anchor (QCPItemPosition inherits from QCPItemAnchor). - - \see anchor, position -*/ -bool QCPAbstractItem::hasAnchor(const QString &name) const -{ - for (int i=0; iname() == name) - return true; - } - return false; -} - -/*! \internal - - Returns the rect the visual representation of this item is clipped to. This depends on the - current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. - - If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. - - \see draw -*/ -QRect QCPAbstractItem::clipRect() const -{ - if (mClipToAxisRect && mClipAxisRect) - return mClipAxisRect.data()->rect(); - else - return mParentPlot->viewport(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing item lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); -} - -/*! \internal - - A convenience function which returns the selectTest value for a specified \a rect and a specified - click position \a pos. \a filledRect defines whether a click inside the rect should also be - considered a hit or whether only the rect border is sensitive to hits. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - For example, if your item consists of four rects, call this function four times, once for each - rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four - returned values. -*/ -double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const -{ - double result = -1; - - // distance to border: - QList lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = std::numeric_limits::max(); - for (int i=0; i mParentPlot->selectionTolerance()*0.99) - { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/*! \internal - - Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in - item subclasses if they want to provide anchors (QCPItemAnchor). - - For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor - ids and returns the respective pixel points of the specified anchor. - - \see createAnchor -*/ -QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const -{ - qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the position - member (This is needed to provide the name-based \ref position access to positions). - - Don't delete positions created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each position member. Don't create QCPItemPositions with \b new yourself, because they - won't be registered with the item properly. - - \see createAnchor -*/ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); - return newPosition; -} - -/*! \internal - - Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the anchor - member (This is needed to provide the name based \ref anchor access to anchors). - - The \a anchorId must be a number identifying the created anchor. It is recommended to create an - enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor - to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns - the correct pixel coordinates for the passed anchor id. - - Don't delete anchors created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they - won't be registered with the item properly. - - \see createPosition -*/ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); - return newAnchor; -} - -/* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractItem::selectionCategory() const -{ - return QCP::iSelectItems; -} -/* end of 'src/item.cpp' */ - - -/* including file 'src/core.cpp', size 125037 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCustomPlot -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCustomPlot - - \brief The central class of the library. This is the QWidget which displays the plot and - interacts with the user. - - For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const - - Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used - to handle and draw selection rect interactions (see \ref setSelectionRectMode). - - \see setSelectionRect -*/ - -/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const - - Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just - one cell with the main QCPAxisRect inside. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse double click event. -*/ - -/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse press event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. -*/ - -/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse move event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. - - \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, - because the dragging starting point was saved the moment the mouse was pressed. Thus it only has - a meaning for the range drag axes that were set at that moment. If you want to change the drag - axes, consider doing this in the \ref mousePress signal instead. -*/ - -/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse release event. - - It is emitted before QCustomPlot handles any other mechanisms like object selection. So a - slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or - \ref QCPAbstractPlottable::setSelectable. -*/ - -/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse wheel event. - - It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref - QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. -*/ - -/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableDoubleClick -*/ - -/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is double clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableClick -*/ - -/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemDoubleClick -*/ - -/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is double clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemClick -*/ - -/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisDoubleClick -*/ - -/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is double clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisClick -*/ - -/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendDoubleClick -*/ - -/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is double clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendClick -*/ - -/*! \fn void QCustomPlot::selectionChangedByUser() - - This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by - clicking. It is not emitted when the selection state of an object has changed programmatically by - a direct call to setSelected()/setSelection() on an object or by calling \ref - deselectAll. - - In addition to this signal, selectable objects also provide individual signals, for example \ref - QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals - are emitted even if the selection state is changed programmatically. - - See the documentation of \ref setInteractions for details about the selection mechanism. - - \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends -*/ - -/*! \fn void QCustomPlot::beforeReplot() - - This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, afterReplot -*/ - -/*! \fn void QCustomPlot::afterReplot() - - This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, beforeReplot -*/ - -/* end of documentation of signals */ -/* start of documentation of public members */ - -/*! \var QCPAxis *QCustomPlot::xAxis - - A pointer to the primary x Axis (bottom) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis - - A pointer to the primary y Axis (left) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::xAxis2 - - A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis2 - - A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPLegend *QCustomPlot::legend - - A pointer to the default legend of the main axis rect. The legend is invisible by default. Use - QCPLegend::setVisible to change this. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple legends to the plot, use the layout system interface to - access the new legend. For example, legends can be placed inside an axis rect's \ref - QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If - the default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointer becomes 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/* end of documentation of public members */ - -/*! - Constructs a QCustomPlot and sets reasonable default values. -*/ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), - mMultiSelectModifier(Qt::ControlModifier), - mSelectionRectMode(QCP::srmNone), - mSelectionRect(0), - mOpenGl(false), - mMouseHasMoved(false), - mMouseEventLayerable(0), - mMouseSignalLayerable(0), - mReplotting(false), - mReplotQueued(false), - mOpenGlMultisamples(16), - mOpenGlAntialiasedElementsBackup(QCP::aeNone), - mOpenGlCacheLabelsBackup(true) -{ - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); -# else - setBufferDevicePixelRatio(QWidget::devicePixelRatio()); -# endif -#endif - - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // create initial layers: - mLayers.append(new QCPLayer(this, QLatin1String("background"))); - mLayers.append(new QCPLayer(this, QLatin1String("grid"))); - mLayers.append(new QCPLayer(this, QLatin1String("main"))); - mLayers.append(new QCPLayer(this, QLatin1String("axes"))); - mLayers.append(new QCPLayer(this, QLatin1String("legend"))); - mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); - updateLayerIndices(); - setCurrentLayer(QLatin1String("main")); - layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); - - // create initial layout, axis rect and legend: - mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer(QLatin1String("main")); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); - legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer(QLatin1String("background")); - xAxis->setLayer(QLatin1String("axes")); - yAxis->setLayer(QLatin1String("axes")); - xAxis2->setLayer(QLatin1String("axes")); - yAxis2->setLayer(QLatin1String("axes")); - xAxis->grid()->setLayer(QLatin1String("grid")); - yAxis->grid()->setLayer(QLatin1String("grid")); - xAxis2->grid()->setLayer(QLatin1String("grid")); - yAxis2->grid()->setLayer(QLatin1String("grid")); - legend->setLayer(QLatin1String("legend")); - - // create selection rect instance: - mSelectionRect = new QCPSelectionRect(this); - mSelectionRect->setLayer(QLatin1String("overlay")); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(rpQueuedReplot); -} - -QCustomPlot::~QCustomPlot() -{ - clearPlottables(); - clearItems(); - - if (mPlotLayout) - { - delete mPlotLayout; - mPlotLayout = 0; - } - - mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed - mLayers.clear(); -} - -/*! - Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is - removed from there. - - \see setNotAntialiasedElements -*/ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) -{ - mAntialiasedElements = antialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. - - See \ref setAntialiasedElements for details. - - \see setNotAntialiasedElement -*/ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) -{ - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements |= antialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets which elements are forcibly drawn not antialiased as an \a or combination of - QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is - removed from there. - - \see setAntialiasedElements -*/ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) -{ - mNotAntialiasedElements = notAntialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. - - See \ref setNotAntialiasedElements for details. - - \see setAntialiasedElement -*/ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) -{ - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements |= notAntialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the - plottable to the legend (QCustomPlot::legend). - - \see addGraph, QCPLegend::addItem -*/ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) -{ - mAutoAddPlottableToLegend = on; -} - -/*! - Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction - enums. There are the following types of interactions: - - Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the - respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. - For details how to control which axes the user may drag/zoom and in what orientations, see \ref - QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, - \ref QCPAxisRect::setRangeZoomAxes. - - Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref - QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and - their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the - user can actually select a plottable and its data can further be restricted with the \ref - QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the - special page about the \ref dataselection "data selection mechanism". To retrieve a list of all - currently selected plottables, call \ref selectedPlottables. If you're only interested in - QCPGraphs, you may use the convenience function \ref selectedGraphs. - - Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user - may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find - out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of - all currently selected items, call \ref selectedItems. - - Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user - may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick - labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for - each axis. To retrieve a list of all axes that currently contain selected parts, call \ref - selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). - - Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may - select the legend itself or individual items by clicking on them. What parts exactly are - selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the - legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To - find out which child items are selected, call \ref QCPLegend::selectedItems. - - All other selectable elements The selection of all other selectable objects (e.g. - QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the - user may select those objects by clicking on them. To find out which are currently selected, you - need to check their selected state explicitly. - - If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is - emitted. Each selectable object additionally emits an individual selectionChanged signal whenever - their selection state has changed, i.e. not only by user interaction. - - To allow multiple objects to be selected by holding the selection modifier (\ref - setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. - - \note In addition to the selection mechanism presented here, QCustomPlot always emits - corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and - \ref plottableDoubleClick for example. - - \see setInteraction, setSelectionTolerance -*/ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) -{ - mInteractions = interactions; -} - -/*! - Sets the single \a interaction of this QCustomPlot to \a enabled. - - For details about the interaction system, see \ref setInteractions. - - \see setInteractions -*/ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) -{ - if (!enabled && mInteractions.testFlag(interaction)) - mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) - mInteractions |= interaction; -} - -/*! - Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or - not. - - If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a - potential selection when the minimum distance between the click position and the graph line is - smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks - directly inside the area and ignore this selection tolerance. In other words, it only has meaning - for parts of objects that are too thin to exactly hit with a click and thus need such a - tolerance. - - \see setInteractions, QCPLayerable::selectTest -*/ -void QCustomPlot::setSelectionTolerance(int pixels) -{ - mSelectionTolerance = pixels; -} - -/*! - Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes - ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves - performance during dragging. Thus it creates a more responsive user experience. As soon as the - user stops dragging, the last replot is done with normal antialiasing, to restore high image - quality. - - \see setAntialiasedElements, setNotAntialiasedElements -*/ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) -{ - mNoAntialiasingOnDrag = enabled; -} - -/*! - Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. - - \see setPlottingHint -*/ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) -{ - mPlottingHints = hints; -} - -/*! - Sets the specified plotting \a hint to \a enabled. - - \see setPlottingHints -*/ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) -{ - QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) - newHints &= ~hint; - else - newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); -} - -/*! - Sets the keyboard modifier that will be recognized as multi-select-modifier. - - If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple - objects (or data points) by clicking on them one after the other while holding down \a modifier. - - By default the multi-select-modifier is set to Qt::ControlModifier. - - \see setInteractions -*/ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) -{ - mMultiSelectModifier = modifier; -} - -/*! - Sets how QCustomPlot processes mouse click-and-drag interactions by the user. - - If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For - example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref - QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref - selectionRect) becomes activated and allows e.g. rect zooming and data point selection. - - If you wish to provide your user both with axis range dragging and data selection/range zooming, - use this method to switch between the modes just before the interaction is processed, e.g. in - reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether - the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. - - If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the - interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes - will keep the selection rect active. Upon completion of the interaction, the behaviour is as - defined by the currently set \a mode, not the mode that was set when the interaction started. - - \see setInteractions, setSelectionRect, QCPSelectionRect -*/ -void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) -{ - if (mSelectionRect) - { - if (mode == QCP::srmNone) - mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect - - // disconnect old connections: - if (mSelectionRectMode == QCP::srmSelect) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - - // establish new ones: - if (mode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } - - mSelectionRectMode = mode; -} - -/*! - Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref - QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of - the passed \a selectionRect. It can be accessed later via \ref selectionRect. - - This method is useful if you wish to replace the default QCPSelectionRect instance with an - instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. - - \see setSelectionRectMode -*/ -void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) -{ - if (mSelectionRect) - delete mSelectionRect; - - mSelectionRect = selectionRect; - - if (mSelectionRect) - { - // establish connections with new selection rect: - if (mSelectionRectMode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } -} - -/*! - \warning This is still an experimental feature and its performance depends on the system that it - runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering - might cause context conflicts on some systems. - - This method allows to enable OpenGL plot rendering, for increased plotting performance of - graphically demanding plots (thick lines, translucent fills, etc.). - - If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, - continue plotting with hardware acceleration. The parameter \a multisampling controls how many - samples will be used per pixel, it essentially controls the antialiasing quality. If \a - multisampling is set too high for the current graphics hardware, the maximum allowed value will - be used. - - You can test whether switching to OpenGL rendering was successful by checking whether the - according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, - rendering continues with the regular software rasterizer, and an according qDebug output is - generated. - - If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint - "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override - for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a - higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the - OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is - controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching - settings are restored to what they were before OpenGL was enabled, if they weren't altered in the - meantime. - - \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL - defined. This define must be set before including the QCustomPlot header both during compilation - of the QCustomPlot library as well as when compiling your application. It is best to just include - the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. - \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c - QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a - newer OpenGL interface which is already in the "gui" module. -*/ -void QCustomPlot::setOpenGl(bool enabled, int multisampling) -{ - mOpenGlMultisamples = qMax(0, multisampling); -#ifdef QCUSTOMPLOT_USE_OPENGL - mOpenGl = enabled; - if (mOpenGl) - { - if (setupOpenGl()) - { - // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): - setAntialiasedElements(QCP::aeAll); - setPlottingHint(QCP::phCacheLabels, false); - } else - { - qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; - mOpenGl = false; - } - } else - { - // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: - if (mAntialiasedElements == QCP::aeAll) - setAntialiasedElements(mOpenGlAntialiasedElementsBackup); - if (!mPlottingHints.testFlag(QCP::phCacheLabels)) - setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); - freeOpenGl(); - } - // recreate all paint buffers: - mPaintBuffers.clear(); - setupPaintBuffers(); -#else - Q_UNUSED(enabled) - qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; -#endif -} - -/*! - Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the - viewport manually. - - The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take - the viewport to be the outer border of the plot. The viewport normally is the rect() of the - QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. - - Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically - an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger - and contains also the axes themselves, their tick numbers, their labels, or even additional axis - rects, color scales and other layout elements. - - This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref - savePdf, etc. by temporarily changing the viewport size. -*/ -void QCustomPlot::setViewport(const QRect &rect) -{ - mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); -} - -/*! - Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. - - Normally, this doesn't need to be set manually, because it is initialized with the regular \a - QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal - displays, 2 for High-DPI displays). - - Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called - when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and - leaves the internal buffer device pixel ratio at 1.0. -*/ -void QCustomPlot::setBufferDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBufferDevicePixelRatio = ratio; - for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mBufferDevicePixelRatio = 1.0; -#endif - } -} - -/*! - Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn - below all other objects in the plot. - - For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is - preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will - first be filled with that brush, before drawing the background pixmap. This can be useful for - background pixmaps with translucent areas. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! - Sets the background brush of the viewport (see \ref setViewport). - - Before drawing everything else, the background is filled with \a brush. If a background pixmap - was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport - before the background pixmap is drawn. This can be useful for background pixmaps with translucent - areas. - - Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be - useful for exporting to image formats which support transparency, e.g. \ref savePng. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the viewport, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is - set to true, control whether and how the aspect ratio of the original pixmap is preserved with - \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the viewport dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCustomPlot::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this - function to define whether and how the aspect ratio of the original pixmap is preserved. - - \see setBackground, setBackgroundScaled -*/ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the plottable with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - plottable, see QCustomPlot::plottable() - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - { - return mPlottables.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last plottable that was added to the plot. If there are no plottables in the plot, - returns 0. - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable() -{ - if (!mPlottables.isEmpty()) - { - return mPlottables.last(); - } else - return 0; -} - -/*! - Removes the specified plottable from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). - - Returns true on success. - - \see clearPlottables -*/ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); - return false; - } - - // remove plottable from legend: - plottable->removeFromLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast(plottable)) - mGraphs.removeOne(graph); - // remove plottable: - delete plottable; - mPlottables.removeOne(plottable); - return true; -} - -/*! \overload - - Removes and deletes the plottable by its \a index. -*/ -bool QCustomPlot::removePlottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all plottables from the plot and deletes them. Corresponding legend items are also - removed from the default legend (QCustomPlot::legend). - - Returns the number of plottables removed. - - \see removePlottable -*/ -int QCustomPlot::clearPlottables() -{ - int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); - return c; -} - -/*! - Returns the number of currently existing plottables in the plot - - \see plottable -*/ -int QCustomPlot::plottableCount() const -{ - return mPlottables.size(); -} - -/*! - Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. - - There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. - - \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedPlottables() const -{ - QList result; - foreach (QCPAbstractPlottable *plottable, mPlottables) - { - if (plottable->selected()) - result.append(plottable); - } - return result; -} - -/*! - Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines - (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple - plottables come into consideration, the one closest to \a pos is returned. - - If \a onlySelectable is true, only plottables that are selectable - (QCPAbstractPlottable::setSelectable) are considered. - - If there is no plottable at \a pos, the return value is 0. - - \see itemAt, layoutElementAt -*/ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractPlottable *plottable, mPlottables) - { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable - continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes - { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultPlottable = plottable; - resultDistance = currentDistance; - } - } - } - - return resultPlottable; -} - -/*! - Returns whether this QCustomPlot instance contains the \a plottable. -*/ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const -{ - return mPlottables.contains(plottable); -} - -/*! - Returns the graph with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last created - graph, see QCustomPlot::graph() - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph(int index) const -{ - if (index >= 0 && index < mGraphs.size()) - { - return mGraphs.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, - returns 0. - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph() const -{ - if (!mGraphs.isEmpty()) - { - return mGraphs.last(); - } else - return 0; -} - -/*! - Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the - bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a - keyAxis and \a valueAxis must reside in this QCustomPlot. - - \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically - "y") for the graph. - - Returns a pointer to the newly created graph, or 0 if adding the graph failed. - - \see graph, graphCount, removeGraph, clearGraphs -*/ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; - return 0; - } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; - return 0; - } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); - return newGraph; -} - -/*! - Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in - the plot have a channel fill set towards the removed graph, the channel fill property of those - graphs is reset to zero (no channel fill). - - Returns true on success. - - \see clearGraphs -*/ -bool QCustomPlot::removeGraph(QCPGraph *graph) -{ - return removePlottable(graph); -} - -/*! \overload - - Removes and deletes the graph by its \a index. -*/ -bool QCustomPlot::removeGraph(int index) -{ - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); - else - return false; -} - -/*! - Removes all graphs from the plot and deletes them. Corresponding legend items are also removed - from the default legend (QCustomPlot::legend). - - Returns the number of graphs removed. - - \see removeGraph -*/ -int QCustomPlot::clearGraphs() -{ - int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); - return c; -} - -/*! - Returns the number of currently existing graphs in the plot - - \see graph, addGraph -*/ -int QCustomPlot::graphCount() const -{ - return mGraphs.size(); -} - -/*! - Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. - - If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, - etc., use \ref selectedPlottables. - - \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedGraphs() const -{ - QList result; - foreach (QCPGraph *graph, mGraphs) - { - if (graph->selected()) - result.append(graph); - } - return result; -} - -/*! - Returns the item with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - item, see QCustomPlot::item() - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item(int index) const -{ - if (index >= 0 && index < mItems.size()) - { - return mItems.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last item that was added to this plot. If there are no items in the plot, - returns 0. - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item() const -{ - if (!mItems.isEmpty()) - { - return mItems.last(); - } else - return 0; -} - -/*! - Removes the specified item from the plot and deletes it. - - Returns true on success. - - \see clearItems -*/ -bool QCustomPlot::removeItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - delete item; - mItems.removeOne(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); - return false; - } -} - -/*! \overload - - Removes and deletes the item by its \a index. -*/ -bool QCustomPlot::removeItem(int index) -{ - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all items from the plot and deletes them. - - Returns the number of items removed. - - \see removeItem -*/ -int QCustomPlot::clearItems() -{ - int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); - return c; -} - -/*! - Returns the number of currently existing items in the plot - - \see item -*/ -int QCustomPlot::itemCount() const -{ - return mItems.size(); -} - -/*! - Returns a list of the selected items. If no items are currently selected, the list is empty. - - \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected -*/ -QList QCustomPlot::selectedItems() const -{ - QList result; - foreach (QCPAbstractItem *item, mItems) - { - if (item->selected()) - result.append(item); - } - return result; -} - -/*! - Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref - QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref - setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is - returned. - - If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are - considered. - - If there is no item at \a pos, the return value is 0. - - \see plottableAt, layoutElementAt -*/ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractItem *item, mItems) - { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable - continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it - { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultItem = item; - resultDistance = currentDistance; - } - } - } - - return resultItem; -} - -/*! - Returns whether this QCustomPlot contains the \a item. - - \see item -*/ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const -{ - return mItems.contains(item); -} - -/*! - Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is - returned. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(const QString &name) const -{ - foreach (QCPLayer *layer, mLayers) - { - if (layer->name() == name) - return layer; - } - return 0; -} - -/*! \overload - - Returns the layer by \a index. If the index is invalid, 0 is returned. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(int index) const -{ - if (index >= 0 && index < mLayers.size()) - { - return mLayers.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Returns the layer that is set as current layer (see \ref setCurrentLayer). -*/ -QCPLayer *QCustomPlot::currentLayer() const -{ - return mCurrentLayer; -} - -/*! - Sets the layer with the specified \a name to be the current layer. All layerables (\ref - QCPLayerable), e.g. plottables and items, are created on the current layer. - - Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer -*/ -bool QCustomPlot::setCurrentLayer(const QString &name) -{ - if (QCPLayer *newCurrentLayer = layer(name)) - { - return setCurrentLayer(newCurrentLayer); - } else - { - qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; - return false; - } -} - -/*! \overload - - Sets the provided \a layer to be the current layer. - - Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. - - \see addLayer, moveLayer, removeLayer -*/ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - - mCurrentLayer = layer; - return true; -} - -/*! - Returns the number of currently existing layers in the plot - - \see layer, addLayer -*/ -int QCustomPlot::layerCount() const -{ - return mLayers.size(); -} - -/*! - Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which - must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. - - Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a - valid layer inside this QCustomPlot. - - If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. - - For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. - - \see layer, moveLayer, removeLayer -*/ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!otherLayer) - otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - if (layer(name)) - { - qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; - return false; - } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); - updateLayerIndices(); - setupPaintBuffers(); // associates new layer with the appropriate paint buffer - return true; -} - -/*! - Removes the specified \a layer and returns true on success. - - All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below - \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both - cases, the total rendering order of all layerables in the QCustomPlot is preserved. - - If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom - layer) becomes the new current layer. - - It is not possible to remove the last layer of the plot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::removeLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (mLayers.size() < 2) - { - qDebug() << Q_FUNC_INFO << "can't remove last layer"; - return false; - } - - // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) - int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); - QList children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) - { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally - { - for (int i=0; imoveToLayer(targetLayer, false); - } - // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); - // invalidate the paint buffer that was responsible for this layer: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - // remove layer: - delete layer; - mLayers.removeOne(layer); - updateLayerIndices(); - return true; -} - -/*! - Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or - below is controlled with \a insertMode. - - Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the - QCustomPlot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - - if (layer->index() > otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - else if (layer->index() < otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); - - // invalidate the paint buffers that are responsible for the layers: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - if (!otherLayer->mPaintBuffer.isNull()) - otherLayer->mPaintBuffer.data()->setInvalidated(); - - updateLayerIndices(); - return true; -} - -/*! - Returns the number of axis rects in the plot. - - All axis rects can be accessed via QCustomPlot::axisRect(). - - Initially, only one axis rect exists in the plot. - - \see axisRect, axisRects -*/ -int QCustomPlot::axisRectCount() const -{ - return axisRects().size(); -} - -/*! - Returns the axis rect with \a index. - - Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were - added, all of them may be accessed with this function in a linear fashion (even when they are - nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). - - \see axisRectCount, axisRects -*/ -QCPAxisRect *QCustomPlot::axisRect(int index) const -{ - const QList rectList = axisRects(); - if (index >= 0 && index < rectList.size()) - { - return rectList.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; - return 0; - } -} - -/*! - Returns all axis rects in the plot. - - \see axisRectCount, axisRect -*/ -QList QCustomPlot::axisRects() const -{ - QList result; - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - foreach (QCPLayoutElement *element, elementStack.pop()->elements(false)) - { - if (element) - { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast(element)) - result.append(ar); - } - } - } - - return result; -} - -/*! - Returns the layout element at pixel position \a pos. If there is no element at that position, - returns 0. - - Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on - any of its parent elements is set to false, it will not be considered. - - \see itemAt, plottableAt -*/ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const -{ - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - foreach (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - break; - } - } - } - return currentElement; -} - -/*! - Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores - other layout elements even if they are visually in front of the axis rect (e.g. a \ref - QCPLegend). If there is no axis rect at that position, returns 0. - - Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or - on any of its parent elements is set to false, it will not be considered. - - \see layoutElementAt -*/ -QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const -{ - QCPAxisRect *result = 0; - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - foreach (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - if (QCPAxisRect *ar = qobject_cast(currentElement)) - result = ar; - break; - } - } - } - return result; -} - -/*! - Returns the axes that currently have selected parts, i.e. whose selection state is not \ref - QCPAxis::spNone. - - \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, - QCPAxis::setSelectableParts -*/ -QList QCustomPlot::selectedAxes() const -{ - QList result, allAxes; - foreach (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) - { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); - } - - return result; -} - -/*! - Returns the legends that currently have selected parts, i.e. whose selection state is not \ref - QCPLegend::spNone. - - \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, - QCPLegend::setSelectableParts, QCPLegend::selectedItems -*/ -QList QCustomPlot::selectedLegends() const -{ - QList result; - - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - foreach (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) - { - if (subElement) - { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast(subElement)) - { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); - } - } - } - } - - return result; -} - -/*! - Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. - - Since calling this function is not a user interaction, this does not emit the \ref - selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the - objects were previously selected. - - \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends -*/ -void QCustomPlot::deselectAll() -{ - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); - } -} - -/*! - Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is - refreshed with the new buffer contents. This is the method that must be called to make changes to - the plot, e.g. on the axis ranges or data points of graphs, visible. - - The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example - if your application calls \ref replot very quickly in succession (e.g. multiple independent - functions change some aspects of the plot and each wants to make sure the change gets replotted), - it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the - actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref - replot with this priority will only cause a single replot, avoiding redundant replots and - improving performance. - - Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the - QCustomPlot widget and user interactions (object selection and range dragging/zooming). - - Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref - afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two - signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite - recursion. - - If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to - replot only that specific layer via \ref QCPLayer::replot. See the documentation there for - details. -*/ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) -{ - if (refreshPriority == QCustomPlot::rpQueuedReplot) - { - if (!mReplotQueued) - { - mReplotQueued = true; - QTimer::singleShot(0, this, SLOT(replot())); - } - return; - } - - if (mReplotting) // incase signals loop back to replot slot - return; - mReplotting = true; - mReplotQueued = false; - emit beforeReplot(); - - updateLayout(); - // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: - setupPaintBuffers(); - foreach (QCPLayer *layer, mLayers) - layer->drawToPaintBuffer(); - for (int i=0; isetInvalidated(false); - - if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) - repaint(); - else - update(); - - emit afterReplot(); - mReplotting = false; -} - -/*! - Rescales the axes such that all plottables (like graphs) in the plot are fully visible. - - if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true - (QCPLayerable::setVisible), will be used to rescale the axes. - - \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale -*/ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) -{ - QList allAxes; - foreach (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); -} - -/*! - Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale - of texts and lines will be derived from the specified \a width and \a height. This means, the - output will look like the normal on-screen output of a QCustomPlot widget with the corresponding - pixel width and height. If either \a width or \a height is zero, the exported image will have the - same dimensions as the QCustomPlot widget currently has. - - Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when - drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as - a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information - about cosmetic pens, see the QPainter and QPen documentation. - - The objects of the plot will appear in the current selection state. If you don't want any - selected objects to be painted in their selected look, deselect everything with \ref deselectAll - before calling this function. - - Returns true on success. - - \warning - \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it - is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines - (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). - \li If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting - PDF file. - - \note On Android systems, this method does nothing and issues an according qDebug warning - message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. - - \see savePng, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) -{ - bool success = false; -#ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(exportPen) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(pdfCreator) - Q_UNUSED(pdfTitle) - qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; -#else - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); -#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) - printer.setFullPage(true); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); -#else - QPageLayout pageLayout; - pageLayout.setMode(QPageLayout::FullPageMode); - pageLayout.setOrientation(QPageLayout::Portrait); - pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); - pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); - printer.setPageLayout(pageLayout); -#endif - QCPPainter printpainter; - if (printpainter.begin(&printer)) - { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && - mBackgroundBrush.color() != Qt::white && - mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); - printpainter.end(); - success = true; - } - setViewport(oldViewport); -#endif // QT_NO_PRINTER - return success; -} - -/*! - Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the PNG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) - with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); -} - -/*! - Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the JPEG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveBmp, saveRastered -*/ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); -} - -/*! - Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the BMP format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveJpg, saveRastered -*/ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); -} - -/*! \internal - - Returns a minimum size hint that corresponds to the minimum size of the top level layout - (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum - size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. - This is especially important, when placed in a QLayout where other components try to take in as - much space as possible (e.g. QMdiArea). -*/ -QSize QCustomPlot::minimumSizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Returns a size hint that is the same as \ref minimumSizeHint. - -*/ -QSize QCustomPlot::sizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but - draws the internal buffer on the widget surface. -*/ -void QCustomPlot::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - QCPPainter painter(this); - if (painter.isActive()) - { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - drawBackground(&painter); - for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) - mPaintBuffers.at(bufferIndex)->draw(&painter); - } -} - -/*! \internal - - Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect - of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. -*/ -void QCustomPlot::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event) - // resize and repaint the buffer: - setViewport(rect()); - replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) -} - -/*! \internal - - Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then - determines the layerable under the cursor and forwards the event to it. Finally, emits the - specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref - axisDoubleClick, etc.). - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) -{ - emit mouseDoubleClick(event); - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - // determine layerable under the cursor (this event is called instead of the second press event in a double-click): - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - - // emit specialized object double click signals: - if (!candidates.isEmpty()) - { - if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) - { - int dataIndex = 0; - if (!details.first().value().isEmpty()) - dataIndex = details.first().value().dataRange().begin(); - emit plottableDoubleClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(candidates.first())) - emit axisDoubleClick(ax, details.first().value(), event); - else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) - emit itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast(candidates.first())) - emit legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) - emit legendDoubleClick(li->parentLegend(), li, event); - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is pressed. Emits the mousePress signal. - - If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the - selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCustomPlot::mousePressEvent(QMouseEvent *event) -{ - emit mousePress(event); - // save some state to tell in releaseEvent whether it was a click: - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - if (mSelectionRect && mSelectionRectMode != QCP::srmNone) - { - if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect - mSelectionRect->startSelection(event); - } else - { - // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - if (!candidates.isEmpty()) - { - mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) - mMouseSignalLayerableDetails = details.first(); - } - // forward event to topmost candidate which accepts the event: - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list - candidates.at(i)->mousePressEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when the cursor is moved. Emits the \ref mouseMove signal. - - If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it - in order to update the rect geometry. - - Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the - layout element before), the mouseMoveEvent is forwarded to that element. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) -{ - emit mouseMove(event); - - if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) - mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release - - if (mSelectionRect && mSelectionRect->isActive()) - mSelectionRect->moveSelection(event); - else if (mMouseEventLayerable) // call event of affected layerable: - mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. - - If the mouse was moved less than a certain threshold in any direction since the \ref - mousePressEvent, it is considered a click which causes the selection mechanism (if activated via - \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse - click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) - - If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable - before), the \ref mouseReleaseEvent is forwarded to that element. - - \see mousePressEvent, mouseMoveEvent -*/ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) -{ - emit mouseRelease(event); - - if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click - { - if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here - mSelectionRect->cancel(); - if (event->button() == Qt::LeftButton) - processPointSelection(event); - - // emit specialized click signals of QCustomPlot instance: - if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) - { - int dataIndex = 0; - if (!mMouseSignalLayerableDetails.value().isEmpty()) - dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); - emit plottableClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) - emit axisClick(ax, mMouseSignalLayerableDetails.value(), event); - else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) - emit itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) - emit legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) - emit legendClick(li->parentLegend(), li, event); - mMouseSignalLayerable = 0; - } - - if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there - { - // finish selection rect, the appropriate action will be taken via signal-slot connection: - mSelectionRect->endSelection(event); - } else - { - // call event of affected layerable: - if (mMouseEventLayerable) - { - mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); - mMouseEventLayerable = 0; - } - } - - if (noAntialiasingOnDrag()) - replot(rpQueuedReplot); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then - determines the affected layerable and forwards the event to it. -*/ -void QCustomPlot::wheelEvent(QWheelEvent *event) -{ - emit mouseWheel(event); - // forward event to layerable under cursor: - QList candidates = layerableListAt(event->pos(), false); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->wheelEvent(event); - if (event->isAccepted()) - break; - } - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - This function draws the entire plot, including background pixmap, with the specified \a painter. - It does not make use of the paint buffers like \ref replot, so this is the function typically - used by saving/exporting methods such as \ref savePdf or \ref toPainter. - - Note that it does not fill the background with the background brush (as the user may specify with - \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this - method. -*/ -void QCustomPlot::draw(QCPPainter *painter) -{ - updateLayout(); - - // draw viewport background pixmap: - drawBackground(painter); - - // draw all layered objects (grid, axes, plottables, items, legend,...): - foreach (QCPLayer *layer, mLayers) - layer->draw(painter); - - /* Debug code to draw all layout element rects - foreach (QCPLayoutElement* el, findChildren()) - { - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->rect()); - painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->outerRect()); - } - */ -} - -/*! \internal - - Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref - QCPLayoutElement::update on the main plot layout. - - Here, the layout elements calculate their positions and margins, and prepare for the following - draw call. -*/ -void QCustomPlot::updateLayout() -{ - // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); -} - -/*! \internal - - Draws the viewport background pixmap of the plot. - - If a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the viewport with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - Note that this function does not draw a fill with the background brush - (\ref setBackground(const QBrush &brush)) beneath the pixmap. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::drawBackground(QCPPainter *painter) -{ - // Note: background color is handled in individual replot/save functions - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); - } - } -} - -/*! \internal - - Goes through the layers and makes sure this QCustomPlot instance holds the correct number of - paint buffers and that they have the correct configuration (size, pixel ratio, etc.). - Allocations, reallocations and deletions of paint buffers are performed as necessary. It also - associates the paint buffers with the layers, so they draw themselves into the right buffer when - \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref - QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for - layers in \ref QCPLayer::lmBuffered mode. - - This method uses \ref createPaintBuffer to create new paint buffers. - - After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated - (so an attempt to replot only a single buffered layer causes a full replot). - - This method is called in every \ref replot call, prior to actually drawing the layers (into their - associated paint buffer). If the paint buffers don't need changing/reallocating, this method - basically leaves them alone and thus finishes very fast. -*/ -void QCustomPlot::setupPaintBuffers() -{ - int bufferIndex = 0; - if (mPaintBuffers.isEmpty()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - - for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) - { - QCPLayer *layer = mLayers.at(layerIndex); - if (layer->mode() == QCPLayer::lmLogical) - { - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - } else if (layer->mode() == QCPLayer::lmBuffered) - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - } - } - } - // remove unneeded buffers: - while (mPaintBuffers.size()-1 > bufferIndex) - mPaintBuffers.removeLast(); - // resize buffers to viewport size and clear contents: - for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size - mPaintBuffers.at(i)->clear(Qt::transparent); - mPaintBuffers.at(i)->setInvalidated(); - } -} - -/*! \internal - - This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. - - Depending on the current setting of \ref setOpenGl, and the current Qt version, different - backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper - size and device pixel ratio, and returned. -*/ -QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() -{ - if (mOpenGl) - { -#if defined(QCP_OPENGL_FBO) - return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); -#elif defined(QCP_OPENGL_PBUFFER) - return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); -#else - qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -#endif - } else - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -} - -/*! - This method returns whether any of the paint buffers held by this QCustomPlot instance are - invalidated. - - If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always - causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example - the layer order has changed, new layers were added, layers were removed, or layer modes were - changed (\ref QCPLayer::setMode). - - \see QCPAbstractPaintBuffer::setInvalidated -*/ -bool QCustomPlot::hasInvalidatedPaintBuffers() -{ - for (int i=0; iinvalidated()) - return true; - } - return false; -} - -/*! \internal - - When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, - surface, paint device). - - Returns true on success. - - If this method is successful, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref - QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. - - \see freeOpenGl -*/ -bool QCustomPlot::setupOpenGl() -{ -#ifdef QCP_OPENGL_FBO - freeOpenGl(); - QSurfaceFormat proposedSurfaceFormat; - proposedSurfaceFormat.setSamples(mOpenGlMultisamples); -#ifdef QCP_OPENGL_OFFSCREENSURFACE - QOffscreenSurface *surface = new QOffscreenSurface; -#else - QWindow *surface = new QWindow; - surface->setSurfaceType(QSurface::OpenGLSurface); -#endif - surface->setFormat(proposedSurfaceFormat); - surface->create(); - mGlSurface = QSharedPointer(surface); - mGlContext = QSharedPointer(new QOpenGLContext); - mGlContext->setFormat(mGlSurface->format()); - if (!mGlContext->create()) - { - qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device - { - qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - { - qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); - return true; -#elif defined(QCP_OPENGL_PBUFFER) - return QGLFormat::hasOpenGL(); -#else - return false; -#endif -} - -/*! \internal - - When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the - context and frees resources). - - After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref - QCPPaintBufferPixmap) is used for subsequent replots. - - \see setupOpenGl -*/ -void QCustomPlot::freeOpenGl() -{ -#ifdef QCP_OPENGL_FBO - mGlPaintDevice.clear(); - mGlContext.clear(); - mGlSurface.clear(); -#endif -} - -/*! \internal - - This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot - so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. -*/ -void QCustomPlot::axisRemoved(QCPAxis *axis) -{ - if (xAxis == axis) - xAxis = 0; - if (xAxis2 == axis) - xAxis2 = 0; - if (yAxis == axis) - yAxis = 0; - if (yAxis2 == axis) - yAxis2 = 0; - - // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers -} - -/*! \internal - - This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so - it may clear its QCustomPlot::legend member accordingly. -*/ -void QCustomPlot::legendRemoved(QCPLegend *legend) -{ - if (this->legend == legend) - this->legend = 0; -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmSelect. - - First, it determines which axis rect was the origin of the selection rect judging by the starting - point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be - precise) associated with that axis rect and finds the data points that are in \a rect. It does - this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. - - Then, the actual selection is done by calling the plottables' \ref - QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details - parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a - rect receive a \ref QCPAbstractPlottable::deselectEvent. - - \see processRectZoom -*/ -void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) -{ - bool selectionStateChanged = false; - - if (mInteractions.testFlag(QCP::iSelectPlottables)) - { - QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size - QRectF rectF(rect.normalized()); - if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) - { - // determine plottables that were hit by the rect and thus are candidates for selection: - foreach (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) - { - if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) - { - QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); - if (!dataSel.isEmpty()) - potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); - } - } - - if (!mInteractions.testFlag(QCP::iMultiSelect)) - { - // only leave plottable with most selected points in map, since we will only select a single plottable: - if (!potentialSelections.isEmpty()) - { - QMap >::iterator it = potentialSelections.begin(); - while (it != potentialSelections.end()-1) // erase all except last element - it = potentialSelections.erase(it); - } - } - - bool additive = event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - // emit deselection except to those plottables who will be selected afterwards: - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *layerable, layer->children()) - { - if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - // go through selections in reverse (largest selection first) and emit select events: - QMap >::const_iterator it = potentialSelections.constEnd(); - while (it != potentialSelections.constBegin()) - { - --it; - if (mInteractions.testFlag(it.value().first->selectionCategory())) - { - bool selChanged = false; - it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - if (selectionStateChanged) - { - emit selectionChangedByUser(); - replot(rpQueuedReplot); - } else if (mSelectionRect) - mSelectionRect->layer()->replot(); -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmZoom. - - It determines which axis rect was the origin of the selection rect judging by the starting point - of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the - provided \a rect (see \ref QCPAxisRect::zoom). - - \see processRectSelection -*/ -void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) -{ - Q_UNUSED(event) - if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) - { - QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); - affectedAxes.removeAll(static_cast(0)); - axisRect->zoom(QRectF(rect), affectedAxes); - } - replot(rpQueuedReplot); // always replot to make selection rect disappear -} - -/*! \internal - - This method is called when a simple left mouse click was detected on the QCustomPlot surface. - - It first determines the layerable that was hit by the click, and then calls its \ref - QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the - multi-select modifier was pressed, see \ref setMultiSelectModifier). - - In this method the hit layerable is determined a second time using \ref layerableAt (after the - one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This - implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the - clicked layerable determined here. For example, if a non-selectable layerable is in front of a - selectable layerable at the click position, the front layerable will receive mouse events but the - selectable one in the back will receive the \ref QCPLayerable::selectEvent. - - \see processRectSelection, QCPLayerable::selectTest -*/ -void QCustomPlot::processPointSelection(QMouseEvent *event) -{ - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); - bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *layerable, layer->children()) - { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) - { - // a layerable was actually clicked, call its selectEvent: - bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); - selectionStateChanged |= selChanged; - } - if (selectionStateChanged) - { - emit selectionChangedByUser(); - replot(rpQueuedReplot); - } -} - -/*! \internal - - Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend - is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the - plottable. - - Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of - \a plottable is this QCustomPlot. - - This method is called automatically in the QCPAbstractPlottable base class constructor. -*/ -bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) -{ - if (mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); - return false; - } - if (plottable->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); - return false; - } - - mPlottables.append(plottable); - // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) - plottable->addToLegend(); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); - return true; -} - -/*! \internal - - In order to maintain the simplified graph interface of QCustomPlot, this method is called by the - QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true - on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. - - This graph specific registration happens in addition to the call to \ref registerPlottable by the - QCPAbstractPlottable base class. -*/ -bool QCustomPlot::registerGraph(QCPGraph *graph) -{ - if (!graph) - { - qDebug() << Q_FUNC_INFO << "passed graph is zero"; - return false; - } - if (mGraphs.contains(graph)) - { - qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; - return false; - } - - mGraphs.append(graph); - return true; -} - - -/*! \internal - - Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. - - Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a - item is this QCustomPlot. - - This method is called automatically in the QCPAbstractItem base class constructor. -*/ -bool QCustomPlot::registerItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); - return false; - } - if (item->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); - return false; - } - - mItems.append(item); - if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) - item->setLayer(currentLayer()); - return true; -} - -/*! \internal - - Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called - after every operation that changes the layer indices, like layer removal, layer creation, layer - moving. -*/ -void QCustomPlot::updateLayerIndices() const -{ - for (int i=0; imIndex = i; -} - -/*! \internal - - Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, - only those layerables that are selectable will be considered. (Layerable subclasses communicate - their selectability via the QCPLayerable::selectTest method, by returning -1.) - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableListAt, layoutElementAt, axisRectAt -*/ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const -{ - QList details; - QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); - if (selectionDetails && !details.isEmpty()) - *selectionDetails = details.first(); - if (!candidates.isEmpty()) - return candidates.first(); - else - return 0; -} - -/*! \internal - - Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those - layerables that are selectable will be considered. (Layerable subclasses communicate their - selectability via the QCPLayerable::selectTest method, by returning -1.) - - The returned list is sorted by the layerable/drawing order. If you only need to know the top-most - layerable, rather use \ref layerableAt. - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableAt, layoutElementAt, axisRectAt -*/ -QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const -{ - QList result; - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) - { - const QList layerables = mLayers.at(layerIndex)->children(); - for (int i=layerables.size()-1; i>=0; --i) - { - if (!layerables.at(i)->realVisibility()) - continue; - QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); - if (dist >= 0 && dist < selectionTolerance()) - { - result.append(layerables.at(i)); - if (selectionDetails) - selectionDetails->append(details); - } - } - } - return result; -} - -/*! - Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is - sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead - to a full resolution file with width 200.) If the \a format supports compression, \a quality may - be between 0 and 100 to control it. - - Returns true on success. If this function fails, most likely the given \a format isn't supported - by the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The \a resolution will be written to the image file header (if the file format supports this) and - has no direct consequence for the quality or the pixel size. However, if opening the image with a - tool which respects the metadata, it will be able to scale the image to match either a given size - in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in - which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted - to the format's expected resolution unit internally. - - \see saveBmp, saveJpg, savePng, savePdf -*/ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - QImage buffer = toPixmap(width, height, scale).toImage(); - - int dotsPerMeter = 0; - switch (resolutionUnit) - { - case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; - case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; - case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; - } - buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); - else - return false; -} - -/*! - Renders the plot to a pixmap and returns it. - - The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and - scale 2.0 lead to a full resolution pixmap with width 200.) - - \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf -*/ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) -{ - // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); - - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later - QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) - { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); - } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); - painter.end(); - } else // might happen if pixmap has width or height zero - { - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; - return QPixmap(); - } - return result; -} - -/*! - Renders the plot using the passed \a painter. - - The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will - appear scaled accordingly. - - \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter - on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with - the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. - - \see toPixmap -*/ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) -{ - // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - if (painter->isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else - qDebug() << Q_FUNC_INFO << "Passed painter is not active"; -} -/* end of 'src/core.cpp' */ - -//amalgamation: add plottable1d.cpp - -/* including file 'src/colorgradient.cpp', size 24646 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorGradient -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorGradient - \brief Defines a color gradient for use with e.g. \ref QCPColorMap - - This class describes a color gradient which can be used to encode data with color. For example, - QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which - take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) - with a \a position from 0 to 1. In between these defined color positions, the - color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. - - Alternatively, load one of the preset color gradients shown in the image below, with \ref - loadPreset, or by directly specifying the preset in the constructor. - - Apart from red, green and blue components, the gradient also interpolates the alpha values of the - configured color stops. This allows to display some portions of the data range as transparent in - the plot. - - \image html QCPColorGradient.png - - The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref - GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset - to all the \a setGradient methods, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient - - The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the - color gradient shall be applied periodically (wrapping around) to data values that lie outside - the data range specified on the plottable instance can be controlled with \ref setPeriodic. -*/ - -/*! - Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color - stops with \ref setColorStopAt. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient() : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); -} - -/*! - Constructs a new QCPColorGradient initialized with the colors and color interpolation according - to \a preset. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); -} - -/* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const -{ - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); -} - -/*! - Sets the number of discretization levels of the color gradient to \a n. The default is 350 which - is typically enough to create a smooth appearance. The minimum number of levels is 2. - - \image html QCPColorGradient-levelcount.png -*/ -void QCPColorGradient::setLevelCount(int n) -{ - if (n < 2) - { - qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; - n = 2; - } - if (n != mLevelCount) - { - mLevelCount = n; - mColorBufferInvalidated = true; - } -} - -/*! - Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the - colors are the values of the passed QMap \a colorStops. In between these color stops, the color - is interpolated according to \ref setColorInterpolation. - - A more convenient way to create a custom gradient may be to clear all color stops with \ref - clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with - \ref setColorStopAt. - - \see clearColorStops -*/ -void QCPColorGradient::setColorStops(const QMap &colorStops) -{ - mColorStops = colorStops; - mColorBufferInvalidated = true; -} - -/*! - Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between - these color stops, the color is interpolated according to \ref setColorInterpolation. - - \see setColorStops, clearColorStops -*/ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) -{ - mColorStops.insert(position, color); - mColorBufferInvalidated = true; -} - -/*! - Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be - interpolated linearly in RGB or in HSV color space. - - For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, - whereas in HSV space the intermediate color is yellow. -*/ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) -{ - if (interpolation != mColorInterpolation) - { - mColorInterpolation = interpolation; - mColorBufferInvalidated = true; - } -} - -/*! - Sets whether data points that are outside the configured data range (e.g. \ref - QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether - they all have the same color, corresponding to the respective gradient boundary color. - - \image html QCPColorGradient-periodic.png - - As shown in the image above, gradients that have the same start and end color are especially - suitable for a periodic gradient mapping, since they produce smooth color transitions throughout - the color map. A preset that has this property is \ref gpHues. - - In practice, using periodic color gradients makes sense when the data corresponds to a periodic - dimension, such as an angle or a phase. If this is not the case, the color encoding might become - ambiguous, because multiple different data values are shown as the same color. -*/ -void QCPColorGradient::setPeriodic(bool enabled) -{ - mPeriodic = enabled; -} - -/*! \overload - - This method is used to quickly convert a \a data array to colors. The colors will be output in - the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this - function. The data range that shall be used for mapping the data value to the gradient is passed - in \a range. \a logarithmic indicates whether the data values shall be mapped to colors - logarithmically. - - if \a data actually contains 2D-data linearized via [row*columnCount + column], you can - set \a dataIndexFactor to columnCount to convert a column instead of a row of the data - array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data - is addressed data[i*dataIndexFactor]. - - Use the overloaded method to additionally provide alpha map data. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } -} - -/*! \overload - - Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which - has the same size and structure as \a data and encodes the alpha information per data point. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!alpha) - { - qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } -} - -/*! \internal - - This method is used to colorize a single data value given in \a position, to colors. The data - range that shall be used for mapping the data value to the gradient is passed in \a range. \a - logarithmic indicates whether the data value shall be mapped to a color logarithmically. - - If an entire array of data values shall be converted, rather use \ref colorize, for better - performance. - - The returned QRgb has its r, g and b components premultiplied with alpha (see - QImage::Format_ARGB32_Premultiplied). -*/ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) - updateColorBuffer(); - int index = 0; - if (!logarithmic) - index = (position-range.lower)*(mLevelCount-1)/range.size(); - else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); - if (mPeriodic) - { - index = index % mLevelCount; - if (index < 0) - index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - } - return mColorBuffer.at(index); -} - -/*! - Clears the current color stops and loads the specified \a preset. A preset consists of predefined - color stops and the corresponding color interpolation method. - - The available presets are: - \image html QCPColorGradient.png -*/ -void QCPColorGradient::loadPreset(GradientPreset preset) -{ - clearColorStops(); - switch (preset) - { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; - } -} - -/*! - Clears all color stops. - - \see setColorStops, setColorStopAt -*/ -void QCPColorGradient::clearColorStops() -{ - mColorStops.clear(); - mColorBufferInvalidated = true; -} - -/*! - Returns an inverted gradient. The inverted gradient has all properties as this \ref - QCPColorGradient, but the order of the color stops is inverted. - - \see setColorStops, setColorStopAt -*/ -QCPColorGradient QCPColorGradient::inverted() const -{ - QCPColorGradient result(*this); - result.clearColorStops(); - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); - return result; -} - -/*! \internal - - Returns true if the color gradient uses transparency, i.e. if any of the configured color stops - has an alpha value below 255. -*/ -bool QCPColorGradient::stopsUseAlpha() const -{ - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - { - if (it.value().alpha() < 255) - return true; - } - return false; -} - -/*! \internal - - Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly - convert positions to colors. This is where the interpolation between color stops is calculated. -*/ -void QCPColorGradient::updateColorBuffer() -{ - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) - { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); - const bool useAlpha = stopsUseAlpha(); - for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop - { - mColorBuffer[i] = (it-1).value().rgba(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop - { - mColorBuffer[i] = it.value().rgba(); - } else // position is in between stops (or on an intermediate stop), interpolate color - { - QMap::const_iterator high = it; - QMap::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) - { - case ciRGB: - { - if (useAlpha) - { - const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); - const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, - ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, - ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, - alpha); - } else - { - mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), - ((1-t)*low.value().green() + t*high.value().green()), - ((1-t)*low.value().blue() + t*high.value().blue())); - } - break; - } - case ciHSV: - { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - if (useAlpha) - { - const QRgb rgb = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); - mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); - } - else - { - mColorBuffer[i] = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - } - break; - } - } - } - } - } else if (mColorStops.size() == 1) - { - const QRgb rgb = mColorStops.constBegin().value().rgb(); - const float alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); - } else // mColorStops is empty, fill color buffer with black - { - mColorBuffer.fill(qRgb(0, 0, 0)); - } - mColorBufferInvalidated = false; -} -/* end of 'src/colorgradient.cpp' */ - - -/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecoratorBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecoratorBracket - \brief A selection decorator which draws brackets around each selected data segment - - Additionally to the regular highlighting of selected segments via color, fill and scatter style, - this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data - segment of the plottable. - - The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and - \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref - setBracketBrush. - - To introduce custom bracket styles, it is only necessary to sublcass \ref - QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the - base class. -*/ - -/*! - Creates a new QCPSelectionDecoratorBracket instance with default values. -*/ -QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : - mBracketPen(QPen(Qt::black)), - mBracketBrush(Qt::NoBrush), - mBracketWidth(5), - mBracketHeight(50), - mBracketStyle(bsSquareBracket), - mTangentToData(false), - mTangentAverage(2) -{ - -} - -QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() -{ -} - -/*! - Sets the pen that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) -{ - mBracketPen = pen; -} - -/*! - Sets the brush that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) -{ - mBracketBrush = brush; -} - -/*! - Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of - the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketWidth(int width) -{ - mBracketWidth = width; -} - -/*! - Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis - of the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketHeight(int height) -{ - mBracketHeight = height; -} - -/*! - Sets the shape that the bracket/marker will have. - - \see setBracketWidth, setBracketHeight -*/ -void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) -{ - mBracketStyle = style; -} - -/*! - Sets whether the brackets will be rotated such that they align with the slope of the data at the - position that they appear in. - - For noisy data, it might be more visually appealing to average the slope over multiple data - points. This can be configured via \ref setTangentAverage. -*/ -void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) -{ - mTangentToData = enabled; -} - -/*! - Controls over how many data points the slope shall be averaged, when brackets shall be aligned - with the data (if \ref setTangentToData is true). - - From the position of the bracket, \a pointCount points towards the selected data range will be - taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to - disabling \ref setTangentToData. -*/ -void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) -{ - mTangentAverage = pointCount; - if (mTangentAverage < 1) - mTangentAverage = 1; -} - -/*! - Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and - indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening - bracket, respectively). - - The passed \a painter already contains all transformations that are necessary to position and - rotate the bracket appropriately. Painting operations can be performed as if drawing upright - brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. - - If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket - shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should - reimplement. -*/ -void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const -{ - switch (mBracketStyle) - { - case bsSquareBracket: - { - painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); - painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - break; - } - case bsHalfEllipse: - { - painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); - break; - } - case bsEllipse: - { - painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); - break; - } - case bsPlus: - { - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); - break; - } - default: - { - qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); - break; - } - } -} - -/*! - Draws the bracket decoration on the data points at the begin and end of each selected data - segment given in \a seletion. - - It uses the method \ref drawBracket to actually draw the shapes. - - \seebaseclassmethod -*/ -void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - if (!mPlottable || selection.isEmpty()) return; - - if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) - { - foreach (const QCPDataRange &dataRange, selection.dataRanges()) - { - // determine position and (if tangent mode is enabled) angle of brackets: - int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; - int closeBracketDir = -openBracketDir; - QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); - QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); - double openBracketAngle = 0; - double closeBracketAngle = 0; - if (mTangentToData) - { - openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); - closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); - } - // draw opening bracket: - QTransform oldTransform = painter->transform(); - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(openBracketPos); - painter->rotate(openBracketAngle/M_PI*180.0); - drawBracket(painter, openBracketDir); - painter->setTransform(oldTransform); - // draw closing bracket: - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(closeBracketPos); - painter->rotate(closeBracketAngle/M_PI*180.0); - drawBracket(painter, closeBracketDir); - painter->setTransform(oldTransform); - } - } -} - -/*! \internal - - If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. - This method returns the angle in radians by which a bracket at the given \a dataIndex must be - rotated. - - The parameter \a direction must be set to either -1 or 1, representing whether it is an opening - or closing bracket. Since for slope calculation multiple data points are required, this defines - the direction in which the algorithm walks, starting at \a dataIndex, to average those data - points. (see \ref setTangentToData and \ref setTangentAverage) - - \a interface1d is the interface to the plottable's data which is used to query data coordinates. -*/ -double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const -{ - if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) - return 0; - direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 - - // how many steps we can actually go from index in the given direction without exceeding data bounds: - int averageCount; - if (direction < 0) - averageCount = qMin(mTangentAverage, dataIndex); - else - averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); - qDebug() << averageCount; - // calculate point average of averageCount points: - QVector points(averageCount); - QPointF pointsAverage; - int currentIndex = dataIndex; - for (int i=0; ikeyAxis(); - QCPAxis *valueAxis = mPlottable->valueAxis(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); - else - return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); -} -/* end of 'src/selectiondecorator-bracket.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisRect - \brief Holds multiple axes and arranges them in a rectangular shape. - - This class represents an axis rect, a rectangular area that is bounded on all sides with an - arbitrary number of axes. - - Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the - layout system allows to have multiple axis rects, e.g. arranged in a grid layout - (QCustomPlot::plotLayout). - - By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be - accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. - If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be - invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref - addAxes. To remove an axis, use \ref removeAxis. - - The axis rect layerable itself only draws a background pixmap or color, if specified (\ref - setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an - explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be - placed on other layers, independently of the axis rect. - - Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref - insetLayout and can be used to have other layout elements (or even other layouts with multiple - elements) hovering inside the axis rect. - - If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The - behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel - is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable - via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are - only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref - QCP::iRangeZoom. - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed - line on the far left indicates the viewport/widget border.
-*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const - - Returns the inset layout of this axis rect. It can be used to place other layout elements (or - even layouts with multiple other elements) inside/on top of an axis rect. - - \see QCPLayoutInset -*/ - -/*! \fn int QCPAxisRect::left() const - - Returns the pixel position of the left border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::right() const - - Returns the pixel position of the right border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::top() const - - Returns the pixel position of the top border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::bottom() const - - Returns the pixel position of the bottom border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::width() const - - Returns the pixel width of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::height() const - - Returns the pixel height of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QSize QCPAxisRect::size() const - - Returns the pixel size of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topLeft() const - - Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, - so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topRight() const - - Returns the top right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomLeft() const - - Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomRight() const - - Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::center() const - - Returns the center of this axis rect in pixels. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four - sides, the top and right axes are set invisible initially. -*/ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) -{ - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList()); - mAxes.insert(QCPAxis::atRight, QList()); - mAxes.insert(QCPAxis::atTop, QList()); - mAxes.insert(QCPAxis::atBottom, QList()); - - if (setupDefaultAxes) - { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - } -} - -QCPAxisRect::~QCPAxisRect() -{ - delete mInsetLayout; - mInsetLayout = 0; - - QList axesList = axes(); - for (int i=0; i ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) - { - return ax.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; - return 0; - } -} - -/*! - Returns all axes on the axis rect sides specified with \a types. - - \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of - multiple sides. - - \see axis -*/ -QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); - return result; -} - -/*! \overload - - Returns all axes of this axis rect. -*/ -QList QCPAxisRect::axes() const -{ - QList result; - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - result << it.value(); - } - return result; -} - -/*! - Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a - new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to - remove an axis, use \ref removeAxis instead of deleting it manually. - - You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was - previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership - of the axis, so you may not delete it afterwards. Further, the \a axis must have been created - with this axis rect as parent and with the same axis type as specified in \a type. If this is not - the case, a debug output is generated, the axis is not added, and the method returns 0. - - This method can not be used to move \a axis between axis rects. The same \a axis instance must - not be added multiple times to the same or different axis rects. - - If an axis rect side already contains one or more axes, the lower and upper endings of the new - axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref - QCPLineEnding::esHalfBar. - - \see addAxes, setupFullAxesBox -*/ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) -{ - QCPAxis *newAxis = axis; - if (!newAxis) - { - newAxis = new QCPAxis(this, type); - } else // user provided existing axis instance, do some sanity checks - { - if (newAxis->axisType() != type) - { - qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; - return 0; - } - if (newAxis->axisRect() != this) - { - qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; - return 0; - } - if (axes().contains(newAxis)) - { - qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; - return 0; - } - } - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset - { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); - } - mAxes[type].append(newAxis); - - // reset convenience axis pointers on parent QCustomPlot if they are unset: - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - switch (type) - { - case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } - case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } - case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } - case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } - } - } - - return newAxis; -} - -/*! - Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an - or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. - - Returns a list of the added axes. - - \see addAxis, setupFullAxesBox -*/ -QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); - return result; -} - -/*! - Removes the specified \a axis from the axis rect and deletes it. - - Returns true on success, i.e. if \a axis was a valid axis in this axis rect. - - \see addAxis -*/ -bool QCPAxisRect::removeAxis(QCPAxis *axis) -{ - // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(axis)) - { - if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) - it.value()[1]->setOffset(axis->offset()); - mAxes[it.key()].removeOne(axis); - if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); - delete axis; - return true; - } - } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); - return false; -} - -/*! - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom - specific axes, use the overloaded version of this method. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect) -{ - zoom(pixelRect, axes()); -} - -/*! \overload - - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) -{ - foreach (QCPAxis *axis, affectedAxes) - { - if (!axis) - { - qDebug() << Q_FUNC_INFO << "a passed axis was zero"; - continue; - } - QCPRange pixelRange; - if (axis->orientation() == Qt::Horizontal) - pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); - else - pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); - axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); - } -} - -/*! - Convenience function to create an axis on each side that doesn't have any axes yet and set their - visibility to true. Further, the top/right axes are assigned the following properties of the - bottom/left axes: - - \li range (\ref QCPAxis::setRange) - \li range reversed (\ref QCPAxis::setRangeReversed) - \li scale type (\ref QCPAxis::setScaleType) - \li tick visibility (\ref QCPAxis::setTicks) - \li number format (\ref QCPAxis::setNumberFormat) - \li number precision (\ref QCPAxis::setNumberPrecision) - \li tick count of ticker (\ref QCPAxisTicker::setTickCount) - \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) - - Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. - - If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom - and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. -*/ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) -{ - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); - else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); - else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); - else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); - else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); - xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); - yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); - - if (connectRanges) - { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); - } -} - -/*! - Returns a list of all the plottables that are associated with this axis rect. - - A plottable is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see graphs, items -*/ -QList QCPAxisRect::plottables() const -{ - // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries - QList result; - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that are associated with this axis rect. - - A graph is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see plottables, items -*/ -QList QCPAxisRect::graphs() const -{ - // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries - QList result; - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis rect. - - An item is considered associated with an axis rect if any of its positions has key or value axis - set to an axis that is in this axis rect, or if any of its positions has \ref - QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref - QCPAbstractItem::setClipAxisRect) is set to this axis rect. - - \see plottables, graphs -*/ -QList QCPAxisRect::items() const -{ - // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries - // and miss those items that have this axis rect as clipAxisRect. - QList result; - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - continue; - } - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdaxisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - This method is called automatically upon replot and doesn't need to be called by users of - QCPAxisRect. - - Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), - and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its - QCPInsetLayout::update function. - - \seebaseclassmethod -*/ -void QCPAxisRect::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - switch (phase) - { - case upPreparation: - { - QList allAxes = axes(); - for (int i=0; isetupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; - } - - // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); -} - -/* inherits documentation from base class */ -QList QCPAxisRect::elements(bool recursive) const -{ - QList result; - if (mInsetLayout) - { - result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); - } - return result; -} - -/* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) -{ - drawBackground(painter); -} - -/*! - Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the - axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect - backgrounds are usually drawn below everything else. - - For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio - is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref - setBackground(const QBrush &brush). - - \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) -*/ -void QCPAxisRect::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! \overload - - Sets \a brush as the background brush. The axis rect background will be filled with this brush. - Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds - are usually drawn below everything else. - - The brush will be drawn before (under) any background pixmap, which may be specified with \ref - setBackground(const QPixmap &pm). - - To disable drawing of a background brush, set \a brush to Qt::NoBrush. - - \see setBackground(const QPixmap &pm) -*/ -void QCPAxisRect::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled - is set to true, you may control whether and how the aspect ratio of the original pixmap is - preserved with \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the axis rect dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to - define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. - \see setBackground, setBackgroundScaled -*/ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeDragAxes to retrieve a list with all set axes). - - \see setRangeDragAxes -*/ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); - else - return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); -} - -/*! - Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). - - \see setRangeZoomAxes -*/ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); - else - return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); -} - -/*! - Returns all range drag axes of the \a orientation provided. - - \see rangeZoomAxis, setRangeZoomAxes -*/ -QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; iQt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeDrag to enable the range dragging interaction. - - \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag -*/ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) -{ - mRangeDrag = orientations; -} - -/*! - Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation - corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, - QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical - axis is the left axis (yAxis). - - To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref - QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeZoom to enable the range zooming interaction. - - \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag -*/ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) -{ - mRangeZoom = orientations; -} - -/*! \overload - - Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on - the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to dragging interactions. - - \see setRangeZoomAxes -*/ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag - orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag - motion, use the overload taking two separate lists for horizontal and vertical dragging. -*/ -void QCPAxisRect::setRangeDragAxes(QList axes) -{ - QList horz, vert; - foreach (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical dragging, and - define specifically which axis reacts to which drag orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) -{ - mRangeDragHorzAxis.clear(); - foreach (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeDragVertAxis.clear(); - foreach (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on - the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. - - The two axes can be zoomed with different strengths, when different factors are passed to \ref - setRangeZoomFactor(double horizontalFactor, double verticalFactor). - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to zooming interactions. - - \see setRangeDragAxes -*/ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical range zooming. The - zoom orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom - interaction, use the overload taking two separate lists for horizontal and vertical zooming. -*/ -void QCPAxisRect::setRangeZoomAxes(QList axes) -{ - QList horz, vert; - foreach (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical zooming, and - define specifically which axis reacts to which zoom orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) -{ - mRangeZoomHorzAxis.clear(); - foreach (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeZoomVertAxis.clear(); - foreach (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with - \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to - let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal - and which is vertical, can be set with \ref setRangeZoomAxes. - - When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) - will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the - same scrolling direction will zoom out. -*/ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) -{ - mRangeZoomFactorHorz = horizontalFactor; - mRangeZoomFactorVert = verticalFactor; -} - -/*! \overload - - Sets both the horizontal and vertical zoom \a factor. -*/ -void QCPAxisRect::setRangeZoomFactor(double factor) -{ - mRangeZoomFactorHorz = factor; - mRangeZoomFactorVert = factor; -} - -/*! \internal - - Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a - pixmap. - - If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an - according filling inside the axis rect with the provided \a painter. - - Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the axis rect with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::drawBackground(QCPPainter *painter) -{ - // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); - } - } -} - -/*! \internal - - This function makes sure multiple axes on the side specified with \a type don't collide, but are - distributed according to their respective space requirement (QCPAxis::calculateMargin). - - It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the - one with index zero. - - This function is called by \ref calculateAutoMargin. -*/ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) -{ - const QList axesList = mAxes.value(type); - if (axesList.isEmpty()) - return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) - { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); - isFirstVisible = false; - } - axesList.at(i)->setOffset(offset); - } -} - -/* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) -{ - if (!mAutoMargins.testFlag(side)) - qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - - // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) - return axesList.last()->offset() + axesList.last()->calculateMargin(); - else - return 0; -} - -/*! \internal - - Reacts to a change in layout to potentially set the convenience axis pointers \ref - QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective - axes of this axis rect. This is only done if the respective convenience pointer is currently zero - and if there is no QCPAxisRect at position (0, 0) of the plot layout. - - This automation makes it simpler to replace the main axis rect with a newly created one, without - the need to manually reset the convenience pointers. -*/ -void QCPAxisRect::layoutChanged() -{ - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) - mParentPlot->xAxis = axis(QCPAxis::atBottom); - if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) - mParentPlot->yAxis = axis(QCPAxis::atLeft); - if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) - mParentPlot->xAxis2 = axis(QCPAxis::atTop); - if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) - mParentPlot->yAxis2 = axis(QCPAxis::atRight); - } -} - -/*! \internal - - Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is - pressed, the range dragging interaction is initialized (the actual range manipulation happens in - the \ref mouseMoveEvent). - - The mDragging flag is set to true and some anchor points are set that are needed to determine the - distance the mouse was dragged in the mouse move/release events later. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - mDragStartHorzRange.clear(); - for (int i=0; irange()); - mDragStartVertRange.clear(); - for (int i=0; irange()); - } - } -} - -/*! \internal - - Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a - preceding \ref mousePressEvent, the range is moved accordingly. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - - if (mRangeDrag.testFlag(Qt::Horizontal)) - { - for (int i=0; i= mDragStartHorzRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag.testFlag(Qt::Vertical)) - { - for (int i=0; i= mDragStartVertRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot - { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } - - } -} - -/* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the - ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of - the scaling operation is the current cursor position inside the axis rect. The scaling factor is - dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural - zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. - - Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse - wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be - multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as - exponent of the range zoom factor. This takes care of the wheel direction automatically, by - inverting the factor, when the wheel step is negative (f^-1 = 1/f). -*/ -void QCPAxisRect::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) - { - if (mRangeZoom != 0) - { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) - { - factor = qPow(mRangeZoomFactorHorz, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); - } - } - if (mRangeZoom.testFlag(Qt::Vertical)) - { - factor = qPow(mRangeZoomFactorVert, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); - } - } - mParentPlot->replot(); - } - } -} -/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractLegendItem - \brief The abstract base class for all entries in a QCPLegend. - - It defines a very basic interface for entries in a QCPLegend. For representing plottables in the - legend, the subclass \ref QCPPlottableLegendItem is more suitable. - - Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry - that's not even associated with a plottable). - - You must implement the following pure virtual functions: - \li \ref draw (from QCPLayerable) - - You inherit the following members you may use: - - - - - - - - -
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
-*/ - -/* start of documentation of signals */ - -/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) - - This signal is emitted when the selection state of this legend item has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/* end of documentation of signals */ - -/*! - Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not - cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. -*/ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) -{ - setLayer(QLatin1String("legend")); - setMargins(QMargins(0, 0, 0, 0)); -} - -/*! - Sets the default font of this specific legend item to \a font. - - \see setTextColor, QCPLegend::setFont -*/ -void QCPAbstractLegendItem::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the default text color of this specific legend item to \a color. - - \see setFont, QCPLegend::setTextColor -*/ -void QCPAbstractLegendItem::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - When this legend item is selected, \a font is used to draw generic text, instead of the normal - font set with \ref setFont. - - \see setFont, QCPLegend::setSelectedFont -*/ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - When this legend item is selected, \a color is used to draw generic text, instead of the normal - color set with \ref setTextColor. - - \see setTextColor, QCPLegend::setSelectedTextColor -*/ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether this specific legend item is selectable. - - \see setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets whether this specific legend item is selected. - - It is possible to set the selection state of this item by calling this function directly, even if - setSelectable is set to false. - - \see setSelectableParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) - return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); -} - -/* inherits documentation from base class */ -QRect QCPAbstractLegendItem::clipRect() const -{ - return mOuterRect; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableLegendItem - \brief A legend item representing a plottable with an icon and the plottable name. - - This is the standard legend item for plottables. It displays an icon of the plottable next to the - plottable name. The icon is drawn by the respective plottable itself (\ref - QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. - For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the - middle. - - Legend items of this type are always associated with one plottable (retrievable via the - plottable() function and settable with the constructor). You may change the font of the plottable - name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref - QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. - - The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend - creates/removes legend items of this type. - - Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of - QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout - interface, QCPLegend has specialized functions for handling legend items conveniently, see the - documentation of \ref QCPLegend. -*/ - -/*! - Creates a new legend item associated with \a plottable. - - Once it's created, it can be added to the legend via \ref QCPLegend::addItem. - - A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref - QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. -*/ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) -{ - setAntialiased(false); -} - -/*! \internal - - Returns the pen that shall be used to draw the icon border, taking into account the selection - state of this item. -*/ -QPen QCPPlottableLegendItem::getIconBorderPen() const -{ - return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); -} - -/*! \internal - - Returns the text color that shall be used to draw text, taking into account the selection state - of this item. -*/ -QColor QCPPlottableLegendItem::getTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - -/*! \internal - - Returns the font that shall be used to draw text, taking into account the selection state of this - item. -*/ -QFont QCPPlottableLegendItem::getFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Draws the item with \a painter. The size and position of the drawn legend item is defined by the - parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref - maximumOuterSizeHint of this legend item. -*/ -void QCPPlottableLegendItem::draw(QCPPainter *painter) -{ - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); - QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); - // draw icon: - painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); - painter->restore(); - // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) - { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - int halfPen = qCeil(painter->pen().widthF()*0.5)+1; - painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped - painter->drawRect(iconRect); - } -} - -/*! \internal - - Calculates and returns the size of this item. This includes the icon, the text and the padding in - between. - - \seebaseclassmethod -*/ -QSize QCPPlottableLegendItem::minimumOuterSizeHint() const -{ - if (!mPlottable) return QSize(); - QSize result(0, 0); - QRect textRect; - QFontMetrics fontMetrics(getFont()); - QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); - result.setHeight(qMax(textRect.height(), iconSize.height())); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLegend -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLegend - \brief Manages a legend inside a QCustomPlot. - - A legend is a small box somewhere in the plot which lists plottables with their name and icon. - - A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the - plottable, for which a legend item shall be created. In the case of the main legend (\ref - QCustomPlot::legend), simply adding plottables to the plot while \ref - QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding - legend items. The legend item associated with a certain plottable can be removed with \ref - QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and - manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref - addItem, \ref removeItem, etc. - - Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref - QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement - "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds - an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as - mentioned above. In principle, any other layout elements may also be added to a legend via the - normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout - System\endlink for examples on how to add other elements to the legend and move it outside the axis - rect. - - Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control - in which order (column first or row first) the legend is filled up when calling \ref addItem, and - at which column or row wrapping occurs. - - By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the - inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another - position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend - outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement - interface. -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); - - This signal is emitted when the selection state of this legend has changed. - - \see setSelectedParts, setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs a new QCPLegend instance with default values. - - Note that by default, QCustomPlot already contains a legend ready to be used as \ref - QCustomPlot::legend -*/ -QCPLegend::QCPLegend() -{ - setFillOrder(QCPLayoutGrid::foRowsFirst); - setWrap(0); - - setRowSpacing(3); - setColumnSpacing(8); - setMargins(QMargins(7, 5, 7, 4)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black, 0)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); -} - -QCPLegend::~QCPLegend() -{ - clearItems(); - if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) - mParentPlot->legendRemoved(this); -} - -/* no doc for getter, see setSelectedParts */ -QCPLegend::SelectableParts QCPLegend::selectedParts() const -{ - // check whether any legend elements selected, if yes, add spItems to return value - bool hasSelectedItems = false; - for (int i=0; iselected()) - { - hasSelectedItems = true; - break; - } - } - if (hasSelectedItems) - return mSelectedParts | spItems; - else - return mSelectedParts & ~spItems; -} - -/*! - Sets the pen, the border of the entire legend is drawn with. -*/ -void QCPLegend::setBorderPen(const QPen &pen) -{ - mBorderPen = pen; -} - -/*! - Sets the brush of the legend background. -*/ -void QCPLegend::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will - use this font by default. However, a different font can be specified on a per-item-basis by - accessing the specific legend item. - - This function will also set \a font on all already existing legend items. - - \see QCPAbstractLegendItem::setFont -*/ -void QCPLegend::setFont(const QFont &font) -{ - mFont = font; - for (int i=0; isetFont(mFont); - } -} - -/*! - Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) - will use this color by default. However, a different colors can be specified on a per-item-basis - by accessing the specific legend item. - - This function will also set \a color on all already existing legend items. - - \see QCPAbstractLegendItem::setTextColor -*/ -void QCPLegend::setTextColor(const QColor &color) -{ - mTextColor = color; - for (int i=0; isetTextColor(color); - } -} - -/*! - Sets the size of legend icons. Legend items that draw an icon (e.g. a visual - representation of the graph) will use this size by default. -*/ -void QCPLegend::setIconSize(const QSize &size) -{ - mIconSize = size; -} - -/*! \overload -*/ -void QCPLegend::setIconSize(int width, int height) -{ - mIconSize.setWidth(width); - mIconSize.setHeight(height); -} - -/*! - Sets the horizontal space in pixels between the legend icon and the text next to it. - Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the - name of the graph) will use this space by default. -*/ -void QCPLegend::setIconTextPadding(int padding) -{ - mIconTextPadding = padding; -} - -/*! - Sets the pen used to draw a border around each legend icon. Legend items that draw an - icon (e.g. a visual representation of the graph) will use this pen by default. - - If no border is wanted, set this to \a Qt::NoPen. -*/ -void QCPLegend::setIconBorderPen(const QPen &pen) -{ - mIconBorderPen = pen; -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected - doesn't contain \ref spItems, those items become deselected. - - The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions - contains iSelectLegend. You only need to call this function when you wish to change the selection - state manually. - - This function can change the selection state of a part even when \ref setSelectableParts was set to a - value that actually excludes the part. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set - before, because there's no way to specify which exact items to newly select. Do this by calling - \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, - setSelectedFont -*/ -void QCPLegend::setSelectedParts(const SelectableParts &selected) -{ - SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - - if (mSelectedParts != newSelected) - { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) - { - qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; - newSelected &= ~spItems; - } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection - { - for (int i=0; isetSelected(false); - } - } - mSelectedParts = newSelected; - emit selectionChanged(mSelectedParts); - } -} - -/*! - When the legend box is selected, this pen is used to draw the border instead of the normal pen - set via \ref setBorderPen. - - \see setSelectedParts, setSelectableParts, setSelectedBrush -*/ -void QCPLegend::setSelectedBorderPen(const QPen &pen) -{ - mSelectedBorderPen = pen; -} - -/*! - Sets the pen legend items will use to draw their icon borders, when they are selected. - - \see setSelectedParts, setSelectableParts, setSelectedFont -*/ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) -{ - mSelectedIconBorderPen = pen; -} - -/*! - When the legend box is selected, this brush is used to draw the legend background instead of the normal brush - set via \ref setBrush. - - \see setSelectedParts, setSelectableParts, setSelectedBorderPen -*/ -void QCPLegend::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the default font that is used by legend items when they are selected. - - This function will also set \a font on all already existing legend items. - - \see setFont, QCPAbstractLegendItem::setSelectedFont -*/ -void QCPLegend::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; - for (int i=0; isetSelectedFont(font); - } -} - -/*! - Sets the default text color that is used by legend items when they are selected. - - This function will also set \a color on all already existing legend items. - - \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor -*/ -void QCPLegend::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; - for (int i=0; isetSelectedTextColor(color); - } -} - -/*! - Returns the item with index \a i. - - Note that the linear index depends on the current fill order (\ref setFillOrder). - - \see itemCount, addItem, itemWithPlottable -*/ -QCPAbstractLegendItem *QCPLegend::item(int index) const -{ - return qobject_cast(elementAt(index)); -} - -/*! - Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns 0. - - \see hasItemWithPlottable -*/ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - for (int i=0; i(item(i))) - { - if (pli->plottable() == plottable) - return pli; - } - } - return 0; -} - -/*! - Returns the number of items currently in the legend. - - Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid - base class which allows creating empty cells), they are included in the returned count. - - \see item -*/ -int QCPLegend::itemCount() const -{ - return elementCount(); -} - -/*! - Returns whether the legend contains \a item. - - \see hasItemWithPlottable -*/ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const -{ - for (int i=0; iitem(i)) - return true; - } - return false; -} - -/*! - Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns false. - - \see itemWithPlottable -*/ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - return itemWithPlottable(plottable); -} - -/*! - Adds \a item to the legend, if it's not present already. The element is arranged according to the - current fill order (\ref setFillOrder) and wrapping (\ref setWrap). - - Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. - - The legend takes ownership of the item. - - \see removeItem, item, hasItem -*/ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) -{ - return addElement(item); -} - -/*! \overload - - Removes the item with the specified \a index from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes - elements derived from \ref QCPAbstractLegendItem. - - \see itemCount, clearItems -*/ -bool QCPLegend::removeItem(int index) -{ - if (QCPAbstractLegendItem *ali = item(index)) - { - bool success = remove(ali); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; - } else - return false; -} - -/*! \overload - - Removes \a item from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. - - \see clearItems -*/ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) -{ - bool success = remove(item); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; -} - -/*! - Removes all items from the legend. -*/ -void QCPLegend::clearItems() -{ - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); -} - -/*! - Returns the legend items that are currently selected. If no items are selected, - the list is empty. - - \see QCPAbstractLegendItem::setSelected, setSelectable -*/ -QList QCPLegend::selectedItems() const -{ - QList result; - for (int i=0; iselected()) - result.append(ali); - } - } - return result; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing main legend elements. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); -} - -/*! \internal - - Returns the pen used to paint the border of the legend, taking into account the selection state - of the legend box. -*/ -QPen QCPLegend::getBorderPen() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; -} - -/*! \internal - - Returns the brush used to paint the background of the legend, taking into account the selection - state of the legend box. -*/ -QBrush QCPLegend::getBrush() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; -} - -/*! \internal - - Draws the legend box with the provided \a painter. The individual legend items are layerables - themselves, thus are drawn independently. -*/ -void QCPLegend::draw(QCPPainter *painter) -{ - // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); -} - -/* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) - return -1; - - if (mOuterRect.contains(pos.toPoint())) - { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) -{ - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPLegend::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractLegendItem::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) -{ - if (parentPlot && !parentPlot->legend) - parentPlot->legend = this; -} -/* end of 'src/layoutelements/layoutelement-legend.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPTextElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPTextElement - \brief A layout element displaying a text - - The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, - \ref setTextColor, and \ref setTextFlags. - - A text element can be added as follows: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation -*/ - -/* start documentation of signals */ - -/*! \fn void QCPTextElement::selectionChanged(bool selected) - - This signal is emitted when the selection state has changed to \a selected, either by user - interaction or by a direct call to \ref setSelected. - - \see setSelected, setSelectable -*/ - -/*! \fn void QCPTextElement::clicked(QMouseEvent *event) - - This signal is emitted when the text element is clicked. - - \see doubleClicked, selectTest -*/ - -/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) - - This signal is emitted when the text element is double clicked. - - \see clicked, selectTest -*/ - -/* end documentation of signals */ - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref - setText). -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mText(), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mFont.setPointSizeF(pointSize); - mSelectedFont = parentPlot->font(); - mSelectedFont.setPointSizeF(pointSize); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize and the specified \a fontFamily. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(fontFamily, pointSize)), - mTextColor(Qt::black), - mSelectedFont(QFont(fontFamily, pointSize)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with the specified \a font. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(font), - mTextColor(Qt::black), - mSelectedFont(font), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! - Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". - - \see setFont, setTextColor, setTextFlags -*/ -void QCPTextElement::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of - \c Qt::AlignmentFlag and \c Qt::TextFlag enums. - - Possible enums are: - - Qt::AlignLeft - - Qt::AlignRight - - Qt::AlignHCenter - - Qt::AlignJustify - - Qt::AlignTop - - Qt::AlignBottom - - Qt::AlignVCenter - - Qt::AlignCenter - - Qt::TextDontClip - - Qt::TextSingleLine - - Qt::TextExpandTabs - - Qt::TextShowMnemonic - - Qt::TextWordWrap - - Qt::TextIncludeTrailingSpaces -*/ -void QCPTextElement::setTextFlags(int flags) -{ - mTextFlags = flags; -} - -/*! - Sets the \a font of the text. - - \see setTextColor, setSelectedFont -*/ -void QCPTextElement::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the \a color of the text. - - \see setFont, setSelectedTextColor -*/ -void QCPTextElement::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). - - \see setFont -*/ -void QCPTextElement::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). - - \see setTextColor -*/ -void QCPTextElement::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether the user may select this text element. - - Note that even when \a selectable is set to false, the selection state may be changed - programmatically via \ref setSelected. -*/ -void QCPTextElement::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets the selection state of this text element to \a selected. If the selection has changed, \ref - selectionChanged is emitted. - - Note that this function can change the selection state independently of the current \ref - setSelectable state. -*/ -void QCPTextElement::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/* inherits documentation from base class */ -void QCPTextElement::draw(QCPPainter *painter) -{ - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); -} - -/* inherits documentation from base class */ -QSize QCPTextElement::minimumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPTextElement::maximumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.setWidth(QWIDGETSIZE_MAX); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPTextElement::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/*! - Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is - within the bounding box of the text element's text. Note that this bounding box is updated in the - draw call. - - If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text - element is not selectable (\ref setSelectable), returns -1. - - \seebaseclassmethod -*/ -double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/*! - Accepts the mouse event in order to emit the according click signal in the \ref - mouseReleaseEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->accept(); -} - -/*! - Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref - mousePressEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) - emit clicked(event); -} - -/*! - Emits the \ref doubleClicked signal. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - emit doubleClicked(event); -} - -/*! \internal - - Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to - true, else mFont is returned. -*/ -QFont QCPTextElement::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to - true, else mTextColor is returned. -*/ -QColor QCPTextElement::mainTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} -/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScale -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScale - \brief A color scale for use with color coding data such as QCPColorMap - - This layout element can be placed on the plot to correlate a color gradient with data values. It - is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". - - \image html QCPColorScale.png - - The color scale can be either horizontal or vertical, as shown in the image above. The - orientation and the side where the numbers appear is controlled with \ref setType. - - Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are - connected, they share their gradient, data range and data scale type (\ref setGradient, \ref - setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color - scale, to make them all synchronize these properties. - - To have finer control over the number display and axis behaviour, you can directly access the - \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if - you want to change the number of automatically generated ticks, call - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount - - Placing a color scale next to the main axis rect works like with any other layout element: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation - In this case we have placed it to the right of the default axis rect, so it wasn't necessary to - call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color - scale can be set with \ref setLabel. - - For optimum appearance (like in the image above), it may be desirable to line up the axis rect and - the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup - - Color scales are initialized with a non-zero minimum top and bottom margin (\ref - setMinimumMargins), because vertical color scales are most common and the minimum top/bottom - margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a - horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you - might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPAxis *QCPColorScale::axis() const - - Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the - appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its - interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref - setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref - QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on - the QCPColorScale or on its QCPAxis. - - If the type of the color scale is changed with \ref setType, the axis returned by this method - will change, too, to either the left, right, bottom or top axis, depending on which type was set. -*/ - -/* end documentation of signals */ -/* start documentation of signals */ - -/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a new QCPColorScale. -*/ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) -{ - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); -} - -QCPColorScale::~QCPColorScale() -{ - delete mAxisRect; -} - -/* undocumented getter */ -QString QCPColorScale::label() const -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return QString(); - } - - return mColorAxis.data()->label(); -} - -/* undocumented getter */ -bool QCPColorScale::rangeDrag() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/* undocumented getter */ -bool QCPColorScale::rangeZoom() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/*! - Sets at which side of the color scale the axis is placed, and thus also its orientation. - - Note that after setting \a type to a different value, the axis returned by \ref axis() will - be a different one. The new axis will adopt the following properties from the previous axis: The - range, scale type, label and ticker (the latter will be shared and not copied). -*/ -void QCPColorScale::setType(QCPAxis::AxisType type) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - if (mType != type) - { - mType = type; - QCPRange rangeTransfer(0, 6); - QString labelTransfer; - QSharedPointer tickerTransfer; - // transfer/revert some settings on old axis if it exists: - bool doTransfer = (bool)mColorAxis; - if (doTransfer) - { - rangeTransfer = mColorAxis.data()->range(); - labelTransfer = mColorAxis.data()->label(); - tickerTransfer = mColorAxis.data()->ticker(); - mColorAxis.data()->setLabel(QString()); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; - foreach (QCPAxis::AxisType atype, allAxisTypes) - { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); - } - // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); - // transfer settings to new axis: - if (doTransfer) - { - mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setTicker(tickerTransfer); - } - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); - } -} - -/*! - Sets the range spanned by the color gradient and that is shown by the axis in the color scale. - - It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its range with \ref - QCPAxis::setRange. - - \see setDataScaleType, setGradient, rescaleDataRange -*/ -void QCPColorScale::setDataRange(const QCPRange &dataRange) -{ - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - emit dataRangeChanged(mDataRange); - } -} - -/*! - Sets the scale type of the color scale, i.e. whether values are linearly associated with colors - or logarithmically. - - It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its scale type with \ref - QCPAxis::setScaleType. - - \see setDataRange, setGradient -*/ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - emit dataScaleTypeChanged(mDataScaleType); - } -} - -/*! - Sets the color gradient that will be used to represent data values. - - It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. - - \see setDataRange, setDataScaleType -*/ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - if (mAxisRect) - mAxisRect.data()->mGradientImageInvalidated = true; - emit gradientChanged(mGradient); - } -} - -/*! - Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on - the internal \ref axis. -*/ -void QCPColorScale::setLabel(const QString &str) -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return; - } - - mColorAxis.data()->setLabel(str); -} - -/*! - Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed - will have. -*/ -void QCPColorScale::setBarWidth(int width) -{ - mBarWidth = width; -} - -/*! - Sets whether the user can drag the data range (\ref setDataRange). - - Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeDrag(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeDrag(0); -} - -/*! - Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. - - Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeZoom(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeZoom(0); -} - -/*! - Returns a list of all the color maps associated with this color scale. -*/ -QList QCPColorScale::colorMaps() const -{ - QList result; - for (int i=0; iplottableCount(); ++i) - { - if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); - } - return result; -} - -/*! - Changes the data range such that all color maps associated with this color scale are fully mapped - to the gradient in the data dimension. - - \see setDataRange -*/ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) -{ - QList maps = colorMaps(); - QCPRange newRange; - bool haveRange = false; - QCP::SignDomain sign = QCP::sdBoth; - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - for (int i=0; irealVisibility() && onlyVisibleMaps) - continue; - QCPRange mapRange; - if (maps.at(i)->colorScale() == this) - { - bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == QCP::sdPositive) - { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == QCP::sdNegative) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) - currentFoundRange = false; - } - if (currentFoundRange) - { - if (!haveRange) - newRange = mapRange; - else - newRange.expand(mapRange); - haveRange = true; - } - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) - { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); - } - } - setDataRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - mAxisRect.data()->update(phase); - - switch (phase) - { - case upMargins: - { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); - } - break; - } - case upLayout: - { - mAxisRect.data()->setOuterRect(rect()); - break; - } - default: break; - } -} - -/* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mousePressEvent(event, details); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseMoveEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseReleaseEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->wheelEvent(event); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScaleAxisRectPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScaleAxisRectPrivate - - \internal - \brief An axis rect subclass for use in a QCPColorScale - - This is a private class and not part of the public QCustomPlot interface. - - It provides the axis rect functionality for the QCPColorScale class. -*/ - - -/*! - Creates a new instance, as a child of \a parentColorScale. -*/ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) -{ - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) - { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); - } - - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - - // make layer transfers of color scale transfer to axis rect and axes - // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - foreach (QCPAxis::AxisType type, allAxisTypes) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); -} - -/*! \internal - - Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws - it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. - - \seebaseclassmethod -*/ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) -{ - if (mGradientImageInvalidated) - updateGradientImage(); - - bool mirrorHorz = false; - bool mirrorVert = false; - if (mParentColorScale->mColorAxis) - { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); - } - - painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); -} - -/*! \internal - - Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to - generate a gradient image. This gradient image will be used in the \ref draw method. -*/ -void QCPColorScaleAxisRectPrivate::updateGradientImage() -{ - if (rect().isEmpty()) - return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - int n = mParentColorScale->mGradient.levelCount(); - int w, h; - QVector data(n); - for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) - { - w = n; - h = rect().height(); - mGradientImage = QImage(w, h, format); - QVector pixels; - for (int y=0; y(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); - else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); - } - } -} - -/*! \internal - - This slot is connected to the selectableChanged signals of the four axes in the constructor. It - synchronizes the selectability of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) -{ - // synchronize axis base selectability: - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); - else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); - } - } -} -/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ - - -/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraphData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraphData - \brief Holds the data of one single data point for QCPGraph. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPGraphDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPGraphData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPGraphData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and value set to zero. -*/ -QCPGraphData::QCPGraphData() : - key(0), - value(0) -{ -} - -/*! - Constructs a data point with the specified \a key and \a value. -*/ -QCPGraphData::QCPGraphData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraph -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraph - \brief A plottable representing a graph in a plot. - - \image html QCPGraph.png - - Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be - accessed via QCustomPlot::graph. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPGraphDataContainer. - - Graphs are used to display single-valued data. Single-valued means that there should only be one - data point per unique key coordinate. In other words, the graph can't have \a loops. If you do - want to plot non-single-valued curves, rather use the QCPCurve plottable. - - Gaps in the graph line can be created by adding data points with NaN as value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpgraph-appearance Changing the appearance - - The appearance of the graph is mainly determined by the line style, scatter style, brush and pen - of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). - - \subsection filling Filling under or between graphs - - QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to - the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, - just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. - - By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill - between this graph and another one, call \ref setChannelFillGraph with the other graph as - parameter. - - \see QCustomPlot::addGraph, QCustomPlot::graph -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPGraph::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually - but use QCustomPlot::removePlottable() instead. - - To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. -*/ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // special handling for QCPGraphs to maintain the simple graph interface: - mParentPlot->registerGraph(this); - - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setScatterSkip(0); - setChannelFillGraph(0); - setAdaptiveSampling(true); -} - -QCPGraph::~QCPGraph() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. - Modifying the data in the container will then affect all graphs that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the graph's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 - - \see addData -*/ -void QCPGraph::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to - \ref lsNone and \ref setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPGraph::setLineStyle(LineStyle ls) -{ - mLineStyle = ls; -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points - are drawn (e.g. for line-only-plots with appropriate line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPGraph::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets the target graph for filling the area between this graph and \a targetGraph with the current - brush (\ref setBrush). - - When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To - disable any filling, set the brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) -{ - // prevent setting channel target to this graph itself: - if (targetGraph == this) - { - qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; - mChannelFillGraph = 0; - return; - } - // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; - mChannelFillGraph = 0; - return; - } - - mChannelFillGraph = targetGraph; -} - -/*! - Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive - sampling technique can drastically improve the replot performance for graphs with a larger number - of points (e.g. above 10,000), without notably changing the appearance of the graph. - - By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive - sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no - disadvantage in almost all cases. - - \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" - - As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are - reproduced reliably, as well as the overall shape of the data set. The replot time reduces - dramatically though. This allows QCustomPlot to display large amounts of data in realtime. - - \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" - - Care must be taken when using high-density scatter plots in combination with adaptive sampling. - The adaptive sampling algorithm treats scatter plots more carefully than line plots which still - gives a significant reduction of replot times, but not quite as much as for line plots. This is - because scatter plots inherently need more data points to be preserved in order to still resemble - the original, non-adaptive-sampling plot. As shown above, the results still aren't quite - identical, as banding occurs for the outer data points. This is in fact intentional, such that - the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, - depends on the point density, i.e. the number of points in the plot. - - For some situations with scatter plots it might thus be desirable to manually turn adaptive - sampling off. For example, when saving the plot to disk. This can be achieved by setting \a - enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled - back to true afterwards. -*/ -void QCPGraph::setAdaptiveSampling(bool enabled) -{ - mAdaptiveSampling = enabled; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(double key, double value) -{ - mDataContainer->add(QCPGraphData(key, value)); -} - -/* inherits documentation from base class */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - // get line pixel points appropriate to line style: - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) - getLines(&lines, lineDataRange); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPGraphDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw fill of graph: - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - drawFill(painter, &lines); - - // draw line: - if (mLineStyle != lsNone) - { - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - painter->setBrush(Qt::NoBrush); - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lines); - else - drawLinePlot(painter, lines); // also step plots can be drawn as a line plot - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i)); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches - out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. - according to the line style of the graph. - - \a lines will be filled with points in pixel coordinates, that can be drawn with the according - draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines - aren't necessarily the original data points. For example, step line styles require additional - points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a - lines vector will be empty. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. - - \see getScatters -*/ -void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const -{ - if (!lines) return; - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - lines->clear(); - return; - } - - QVector lineData; - if (mLineStyle != lsNone) - getOptimizedLineData(&lineData, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) - std::reverse(lineData.begin(), lineData.end()); - - switch (mLineStyle) - { - case lsNone: lines->clear(); break; - case lsLine: *lines = dataToLines(lineData); break; - case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; - case lsStepRight: *lines = dataToStepRightLines(lineData); break; - case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; - case lsImpulse: *lines = dataToImpulseLines(lineData); break; - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then - converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be - passed to \ref drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. -*/ -void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const -{ - if (!scatters) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } - - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - scatters->clear(); - return; - } - - QVector data; - getOptimizedScatterData(&data, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) - std::reverse(data.begin(), data.end()); - - scatters->resize(data.size()); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } - } else - { - for (int i=0; icoordToPixel(data.at(i).key)); - (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - } -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsLine. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - result[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key)); - result[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepLeft. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepLeftLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(lastValue); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(key); - result[i*2+1].setY(lastValue); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepRight. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepRightLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(value); - result[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(value); - result[i*2+1].setY(lastKey); - } - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(lastKey); - result[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(lastKey); - result[i*2+1].setY(value); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepCenter. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepCenterLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastValue); - result[0].setY(lastKey); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(lastValue); - result[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - } - result[data.size()*2-1].setX(lastValue); - result[data.size()*2-1].setY(lastKey); - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastKey); - result[0].setY(lastValue); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(key); - result[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - } - result[data.size()*2-1].setX(lastKey); - result[data.size()*2-1].setY(lastValue); - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsImpulse. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot -*/ -QVector QCPGraph::dataToImpulseLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(valueAxis->coordToPixel(0)); - result[i*2+0].setY(key); - result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(valueAxis->coordToPixel(0)); - result[i*2+1].setX(key); - result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Draws the fill of the graph using the specified \a painter, with the currently set brush. - - Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref - getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. - - In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), - this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to - operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN - segments of the two involved graphs, before passing the overlapping pairs to \ref - getChannelFillPolygon. - - Pass the points of this graph's line as \a lines, in pixel coordinates. - - \see drawLinePlot, drawImpulsePlot, drawScatterPlot -*/ -void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const -{ - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); - if (!mChannelFillGraph) - { - // draw base fill under graph, fill goes all the way to the zero-value-line: - for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); - } else - { - // draw fill between this graph and mChannelFillGraph: - QVector otherLines; - mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); - if (!otherLines.isEmpty()) - { - QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); - QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); - for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); - } - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawLinePlot, drawImpulsePlot -*/ -void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const -{ - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in - pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines - from the regular graph data points. - - \see drawLinePlot, drawScatterPlot -*/ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - QPen oldPen = painter->pen(); - QPen newPen = painter->pen(); - newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(newPen); - painter->drawLines(lines); - painter->setPen(oldPen); - } -} - -/*! \internal - - Returns via \a lineData the data points that need to be visualized for this graph when plotting - graph lines, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getLines to retrieve the basic working set of data. - - \see getOptimizedScatterData -*/ -void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const -{ - if (!lineData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (begin == end) return; - - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - QCPGraphDataContainer::const_iterator it = begin; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary - { - if (it->value < minValue) - minValue = it->value; - else if (it->value > maxValue) - maxValue = it->value; - ++intervalDataCount; - } else // new pixel interval started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - lastIntervalEndKey = (it-1)->key; - minValue = it->value; - maxValue = it->value; - currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - lineData->resize(dataCount); - std::copy(begin, end, lineData->begin()); - } -} - -/*! \internal - - Returns via \a scatterData the data points that need to be visualized for this graph when - plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getScatters to retrieve the basic working set of data. - - \see getOptimizedLineData -*/ -void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const -{ - if (!scatterData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int beginIndex = begin-mDataContainer->constBegin(); - int endIndex = end-mDataContainer->constBegin(); - while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++beginIndex; - ++begin; - } - if (begin == end) return; - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - double valueMaxRange = valueAxis->range().upper; - double valueMinRange = valueAxis->range().lower; - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator minValueIt = it; - QCPGraphDataContainer::const_iterator maxValueIt = it; - QCPGraphDataContainer::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - // main loop over data points: - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary - { - if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) - { - minValue = it->value; - minValueIt = it; - } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) - { - maxValue = it->value; - maxValueIt = it; - } - ++intervalDataCount; - } else // new pixel started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else - intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - minValue = it->value; - maxValue = it->value; - currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int intervalItIndex = intervalIt-mDataContainer->constBegin(); - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: - { - intervalItIndex += scatterModulo; - if (intervalItIndex < itIndex) - intervalIt += scatterModulo; - else - { - intervalIt = it; - intervalItIndex = itIndex; - } - } - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - scatterData->reserve(dataCount); - while (it != end) - { - scatterData->append(*it); - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - This method takes into account that the drawing of data lines at the axis rect border always - requires the points just outside the visible axis range. So \a begin and \a end may actually - indicate a range that contains one additional data point to the left and right of the visible - axis range. -*/ -void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - if (rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - } else - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - // get visible data range: - begin = mDataContainer->findBegin(keyAxis->range().lower); - end = mDataContainer->findEnd(keyAxis->range().upper); - // limit lower/upperEnd to rangeRestriction: - mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything - } -} - -/*! \internal - - This method goes through the passed points in \a lineData and returns a list of the segments - which don't contain NaN data points. - - \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check - for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c - Qt::Vertical, the \a x member is checked. - - \see getOverlappingSegments, drawFill -*/ -QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const -{ - QVector result; - const int n = lineData->size(); - - QCPDataRange currentSegment(-1, -1); - int i = 0; - - if (keyOrientation == Qt::Horizontal) - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } else // keyOrientation == Qt::Vertical - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } - return result; -} - -/*! \internal - - This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and - \a otherSegments, and their associated point data \a thisData and \a otherData. - - It returns all pairs of segments (the first from \a thisSegments, the second from \a - otherSegments), which overlap in plot coordinates. - - This method is useful in the case of a channel fill between two graphs, when only those non-NaN - segments which actually overlap in their key coordinate shall be considered for drawing a channel - fill polygon. - - It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and - that the segments don't overlap themselves. The same is assumed for the segments in \a - otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. - - \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon -*/ -QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const -{ - QVector > result; - if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) - return result; - - int thisIndex = 0; - int otherIndex = 0; - const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; - while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) - { - if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++thisIndex; - continue; - } - if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++otherIndex; - continue; - } - double thisLower, thisUpper, otherLower, otherUpper; - if (!verticalKey) - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); - } else - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); - } - - int bPrecedence; - if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) - result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); - - if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment - ++otherIndex; - else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment - ++thisIndex; - } - - return result; -} - -/*! \internal - - Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) - have overlap. - - The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the - \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher - coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if - both segment's upper bounds are identical, 0 is returned as \a bPrecedence. - - It is assumed that the lower bounds always have smaller or equal values than the upper bounds. - - \see getOverlappingSegments -*/ -bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const -{ - bPrecedence = 0; - if (aLower > bUpper) - { - bPrecedence = -1; - return false; - } else if (bLower > aUpper) - { - bPrecedence = 1; - return false; - } else - { - if (aUpper > bUpper) - bPrecedence = -1; - else if (aUpper < bUpper) - bPrecedence = 1; - - return true; - } -} - -/*! \internal - - Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. - The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates - is in positive or negative infinity. So this case is handled separately by just closing the fill - polygon on the axis which lies in the direction towards the zero value. - - \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether - the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or - y value of the returned point, respectively. -*/ -QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF result; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->orientation() == Qt::Horizontal) - { - result.setX(matchingDataPoint.x()); - result.setY(valueAxis->coordToPixel(0)); - } else // keyAxis->orientation() == Qt::Vertical - { - result.setX(valueAxis->coordToPixel(0)); - result.setY(matchingDataPoint.y()); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value 0 so we just fill all the way - // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setX(keyAxis->axisRect()->right()); - else - result.setX(keyAxis->axisRect()->left()); - result.setY(matchingDataPoint.y()); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - result.setX(matchingDataPoint.x()); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setY(keyAxis->axisRect()->top()); - else - result.setY(keyAxis->axisRect()->bottom()); - } - } - return result; -} - -/*! \internal - - Returns the polygon needed for drawing normal fills between this graph and the key axis. - - Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment - which shall be used for the fill. The collection of \a lineData points described by \a segment - must not contain NaN data points (see \ref getNonNanSegments). - - The returned fill polygon will be closed at the key axis (the zero-value line) for linear value - axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect - side (see \ref getFillBasePoint). - - For increased performance (due to implicit sharing), keep the returned QPolygonF const. - - \see drawFill, getNonNanSegments -*/ -const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const -{ - if (segment.size() < 2) - return QPolygonF(); - QPolygonF result(segment.size()+2); - - result[0] = getFillBasePoint(lineData->at(segment.begin())); - std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); - result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); - - return result; -} - -/*! \internal - - Returns the polygon needed for drawing (partial) channel fills between this graph and the graph - specified by \ref setChannelFillGraph. - - The data points of this graph are passed as pixel coordinates via \a thisData, the data of the - other graph as \a otherData. The returned polygon will be calculated for the specified data - segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a - otherData, respectively. - - The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by - \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap - need to be processed here. - - For increased performance due to implicit sharing, keep the returned QPolygonF const. - - \see drawFill, getOverlappingSegments, getNonNanSegments -*/ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const -{ - if (!mChannelFillGraph) - return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (thisData->isEmpty()) return QPolygonF(); - QVector thisSegmentData(thisSegment.size()); - QVector otherSegmentData(otherSegment.size()); - std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); - std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); - // pointers to be able to swap them, depending which data range needs cropping: - QVector *staticData = &thisSegmentData; - QVector *croppedData = &otherSegmentData; - - // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) - { - // x is key - // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); - else - slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - - // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - const int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); - else - slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical - { - // y is key - // crop lower bound: - if (staticData->first().y() < croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); - else - slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - - // crop upper bound: - if (staticData->last().y() > croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); - else - slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); - } - - // return joined: - for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisSegmentData << otherSegmentData.at(i); - return QPolygonF(thisSegmentData); -} - -/*! \internal - - Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveX(const QVector *data, double x) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).x() < x) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowX(const QVector *data, double x) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).x() > x) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is vertical. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveY(const QVector *data, double y) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).y() < y) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Calculates the minimum distance in pixels the graph's representation has from the given \a - pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if - the graph has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the graph line is also taken into account. - - If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. -*/ -double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - // calculate minimum distances to graph data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); - QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); - for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - // line displayed, calculate distance to line segments: - QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); - QCPVector2D p(pixelPoint); - const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected - for (int i=0; i *data, double y) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).y() > y) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} -/* end of 'src/plottables/plottable-graph.cpp' */ - - -/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurveData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurveData - \brief Holds the data of one single data point for QCPCurve. - - The stored data is: - \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) - \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) - \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPCurveDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPCurveData::sortKey() const - - Returns the \a t member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). - All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() - - Since the member \a key is the data point key coordinate and the member \a t is the data ordering - parameter, this method returns false. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPCurveData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a curve data point with t, key and value set to zero. -*/ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) -{ -} - -/*! - Constructs a curve data point with the specified \a t, \a key and \a value. -*/ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurve - \brief A plottable representing a parametric curve in a plot. - - \image html QCPCurve.png - - Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, - so their visual representation can have \a loops. This is realized by introducing a third - coordinate \a t, which defines the order of the points described by the other two coordinates \a - x and \a y. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the curve's data via the \ref data method, which returns a pointer to the - internal \ref QCPCurveDataContainer. - - Gaps in the curve can be created by adding data points with NaN as key and value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpcurve-appearance Changing the appearance - - The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). - - \section qcpcurve-usage Usage - - Like all data representing objects in QCustomPlot, the QCPCurve is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPCurve::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // modify inherited properties from abstract plottable: - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); - setScatterSkip(0); -} - -QCPCurve::~QCPCurve() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. - Modifying the data in the container will then affect all curves that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the curve's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 - - \see addData -*/ -void QCPCurve::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a t, \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a t in ascending order, you can - set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(t, keys, values, alreadySorted); -} - - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - \see addData -*/ -void QCPCurve::setData(const QVector &keys, const QVector &values) -{ - mDataContainer->clear(); - addData(keys, values); -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref - QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate - line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPCurve::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets how the single data points are connected in the plot or how they are represented visually - apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref - setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) -{ - mLineStyle = style; -} - -/*! \overload - - Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (t.size() != keys.size() || t.size() != values.size()) - qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); - const int n = qMin(qMin(t.size(), keys.size()), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = t[i]; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &keys, const QVector &values) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - double tStart; - if (!mDataContainer->isEmpty()) - tStart = (mDataContainer->constEnd()-1)->t + 1.0; - else - tStart = 0; - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = tStart + i; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a t, \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double t, double key, double value) -{ - mDataContainer->add(QCPCurveData(t, key, value)); -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - The t parameter is generated automatically by increments of 1 for each point, starting at the - highest t of previously existing data or 0, if the curve data is empty. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double key, double value) -{ - if (!mDataContainer->isEmpty()) - mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); - else - mDataContainer->add(QCPCurveData(0.0, key, value)); -} - -/* inherits documentation from base class */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - - // allocate line vector: - QVector lines, scatters; - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - - // fill with curve data: - QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width - if (isSelectedSegment && mSelectionDecorator) - finalCurvePen = mSelectionDecorator->pen(); - - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) - getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); - - // check data validity if flag set: - #ifdef QCUSTOMPLOT_CHECK_DATA - for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->t) || - QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } - #endif - - // draw curve fill: - applyFillAntialiasingHint(painter); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) - painter->drawPolygon(QPolygonF(lines)); - - // draw curve line: - if (mLineStyle != lsNone) - { - painter->setPen(finalCurvePen); - painter->setBrush(Qt::NoBrush); - drawCurveLine(painter, lines); - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - Draws lines between the points in \a lines, given in pixel coordinates. - - \see drawScatterPlot, getCurveLines -*/ -void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawCurveLine, getCurveLines -*/ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const -{ - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const -{ - if (!lines) return; - lines->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // add margins to rect to compensate for stroke width - const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety - const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); - const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); - const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); - const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); - QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); - if (itBegin == itEnd) - return; - QCPCurveDataContainer::const_iterator it = itBegin; - QCPCurveDataContainer::const_iterator prevIt = itEnd-1; - int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); - QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) - while (it != itEnd) - { - const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); - if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R - { - if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal - { - QPointF crossA, crossB; - if (prevRegion == 5) // we're coming from R, so add this point optimized - { - lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); - // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } else if (mayTraverse(prevRegion, currentRegion) && - getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) - { - // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: - QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; - getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); - if (it != itBegin) - { - *lines << beforeTraverseCornerPoints; - lines->append(crossA); - lines->append(crossB); - *lines << afterTraverseCornerPoints; - } else - { - lines->append(crossB); - *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA ; - } - } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) - { - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } - } else // segment does end in R, so we add previous point optimized and this point at original position - { - if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end - trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - else - lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); - lines->append(coordsToPixels(it->key, it->value)); - } - } else // region didn't change - { - if (currentRegion == 5) // still in R, keep adding original points - { - lines->append(coordsToPixels(it->key, it->value)); - } else // still outside R, no need to add anything - { - // see how this is not doing anything? That's the main optimization... - } - } - prevIt = it; - prevRegion = currentRegion; - ++it; - } - *lines << trailingPoints; -} - -/*! \internal - - Called by \ref draw to generate points in pixel coordinates which represent the scatters of the - curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly - sparser. - - Scatters that aren't visible in the current axis rect are optimized away. - - \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref - drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. - - \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel - coordinates generated by this function. This is needed here to calculate an accordingly wider - margin around the axis rect when performing the data point reduction. - - \see draw, drawScatterPlot -*/ -void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const -{ - if (!scatters) return; - scatters->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); - if (begin == end) - return; - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int endIndex = end-mDataContainer->constBegin(); - - QCPRange keyRange = keyAxis->range(); - QCPRange valueRange = valueAxis->range(); - // extend range to include width of scatter symbols: - keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); - keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); - valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); - valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); - - QCPCurveDataContainer::const_iterator it = begin; - int itIndex = begin-mDataContainer->constBegin(); - while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++itIndex; - ++it; - } - if (keyAxis->orientation() == Qt::Vertical) - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } else - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - It returns the region of the given point (\a key, \a value) with respect to a rectangle defined - by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. - - The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a - keyMin to \a keyMax): - - - - - -
147
258
369
- - With the rectangle being region 5, and the outer regions extending infinitely outwards. In the - curve optimization algorithm, region 5 is considered to be the visible portion of the plot. -*/ -int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - if (key < keyMin) // region 123 - { - if (value > valueMax) - return 1; - else if (value < valueMin) - return 3; - else - return 2; - } else if (key > keyMax) // region 789 - { - if (value > valueMax) - return 7; - else if (value < valueMin) - return 9; - else - return 8; - } else // region 456 - { - if (value > valueMax) - return 4; - else if (value < valueMin) - return 6; - else - return 5; - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method is used in case the current segment passes from inside the visible rect (region 5, - see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by - the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). - - It returns the intersection point of the segment with the border of region 5. - - For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or - whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or - leaving it. It is important though that \a otherRegion correctly identifies the other region not - equal to 5. -*/ -QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double otherValuePx = mValueAxis->coordToPixel(otherValue); - const double valuePx = mValueAxis->coordToPixel(value); - const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); - const double keyPx = mKeyAxis->coordToPixel(key); - double intersectKeyPx = keyMinPx; // initial key just a fail-safe - double intersectValuePx = valueMinPx; // initial value just a fail-safe - switch (otherRegion) - { - case 1: // top and left edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 2: // left edge - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 3: // bottom and left edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 4: // top edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 5: - { - break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table - } - case 6: // bottom edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 7: // top and right edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 8: // right edge - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 9: // bottom and right edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - } - if (mKeyAxis->orientation() == Qt::Horizontal) - return QPointF(intersectKeyPx, intersectValuePx); - else - return QPointF(intersectValuePx, intersectKeyPx); -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - In situations where a single segment skips over multiple regions it might become necessary to add - extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment - doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. - This method provides these points that must be added, assuming the original segment doesn't - start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by - \ref getTraverseCornerPoints.) - - For example, consider a segment which directly goes from region 4 to 2 but originally is far out - to the top left such that it doesn't cross region 5. Naively optimizing these points by - projecting them on the top and left borders of region 5 will create a segment that surely crosses - 5, creating a visual artifact in the plot. This method prevents this by providing extra points at - the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without - traversing 5. -*/ -QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - QVector result; - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMax); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } - case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - else - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - break; - } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMin); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); break; } - case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - else - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - break; - } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 6: - { - switch (currentRegion) - { - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 4: { result << coordsToPixels(keyMax, valueMax); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); break; } - case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - else - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - break; - } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 6: { result << coordsToPixels(keyMax, valueMin); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - else - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - break; - } - } - break; - } - } - return result; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref - getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion - nor \a currentRegion is 5 itself. - - If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the - segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref - getTraverse). -*/ -bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 4: - case 7: - case 2: - case 3: return false; - default: return true; - } - } - case 2: - { - switch (currentRegion) - { - case 1: - case 3: return false; - default: return true; - } - } - case 3: - { - switch (currentRegion) - { - case 1: - case 2: - case 6: - case 9: return false; - default: return true; - } - } - case 4: - { - switch (currentRegion) - { - case 1: - case 7: return false; - default: return true; - } - } - case 5: return false; // should never occur - case 6: - { - switch (currentRegion) - { - case 3: - case 9: return false; - default: return true; - } - } - case 7: - { - switch (currentRegion) - { - case 1: - case 4: - case 8: - case 9: return false; - default: return true; - } - } - case 8: - { - switch (currentRegion) - { - case 7: - case 9: return false; - default: return true; - } - } - case 9: - { - switch (currentRegion) - { - case 3: - case 6: - case 8: - case 7: return false; - default: return true; - } - } - default: return true; - } -} - - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref mayTraverse test has returned true, so there is a chance the - segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible - region 5. - - The return value of this method indicates whether the segment actually traverses region 5 or not. - - If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and - exit points of region 5. They will become the optimized points for that segment. -*/ -bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - QList intersections; - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double keyPx = mKeyAxis->coordToPixel(key); - const double valuePx = mValueAxis->coordToPixel(value); - const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); - const double prevValuePx = mValueAxis->coordToPixel(prevValue); - if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); - } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); - } else // line is skewed - { - double gamma; - double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); - // check top of rect: - gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); - // check bottom of rect: - gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); - const double valuePerKeyPx = 1.0/keyPerValuePx; - // check left of rect: - gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); - // check right of rect: - gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); - } - - // handle cases where found points isn't exactly 2: - if (intersections.size() > 2) - { - // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: - double distSqrMax = 0; - QPointF pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = intersections.at(i); - pv2 = intersections.at(k); - distSqrMax = distSqr; - } - } - } - intersections = QList() << pv1 << pv2; - } else if (intersections.size() != 2) - { - // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment - return false; - } - - // possibly re-sort points so optimized point segment has same direction as original segment: - double xDelta = keyPx-prevKeyPx; - double yDelta = valuePx-prevValuePx; - if (mKeyAxis->orientation() != Qt::Horizontal) - qSwap(xDelta, yDelta); - if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction - intersections.move(0, 1); - crossA = intersections.at(0); - crossB = intersections.at(1); - return true; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref getTraverse test has returned true, so the segment definitely - traverses the visible region 5 when going from \a prevRegion to \a currentRegion. - - In certain situations it is not sufficient to merely generate the entry and exit points of the - segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in - addition to traversing region 5, skips another region outside of region 5, which makes it - necessary to add an optimized corner point there (very similar to the job \ref - getOptimizedCornerPoints does for segments that are completely in outside regions and don't - traverse 5). - - As an example, consider a segment going from region 1 to region 6, traversing the lower left - corner of region 5. In this configuration, the segment additionally crosses the border between - region 1 and 2 before entering region 5. This makes it necessary to add an additional point in - the top left corner, before adding the optimized traverse points. So in this case, the output - parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be - empty. - - In some cases, such as when going from region 1 to 9, it may even be necessary to add additional - corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse - return the respective corner points. -*/ -void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: { break; } // shouldn't happen because this method only handles full traverses - case 6: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - } -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in - \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that - if the curve has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the curve line is also taken into account. - - If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns - -1.0. -*/ -double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - if (mDataContainer->size() == 1) - { - QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); - closestData = mDataContainer->constBegin(); - return QCPVector2D(dataPoint-pixelPoint).length(); - } - - // calculate minimum distances to curve data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - QVector lines; - getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width - for (int i=0; i QCPBarsGroup::bars() const - - Returns all bars currently in this group. - - \see bars(int index) -*/ - -/*! \fn int QCPBarsGroup::size() const - - Returns the number of QCPBars plottables that are part of this group. - -*/ - -/*! \fn bool QCPBarsGroup::isEmpty() const - - Returns whether this bars group is empty. - - \see size -*/ - -/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) - - Returns whether the specified \a bars plottable is part of this group. - -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new bars group for the specified QCustomPlot instance. -*/ -QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot), - mSpacingType(stAbsolute), - mSpacing(4) -{ -} - -QCPBarsGroup::~QCPBarsGroup() -{ - clear(); -} - -/*! - Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. - - The actual spacing can then be specified with \ref setSpacing. - - \see setSpacing -*/ -void QCPBarsGroup::setSpacingType(SpacingType spacingType) -{ - mSpacingType = spacingType; -} - -/*! - Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is - defined by the current \ref SpacingType, which can be set with \ref setSpacingType. - - \see setSpacingType -*/ -void QCPBarsGroup::setSpacing(double spacing) -{ - mSpacing = spacing; -} - -/*! - Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars - exists, returns 0. - - \see bars(), size -*/ -QCPBars *QCPBarsGroup::bars(int index) const -{ - if (index >= 0 && index < mBars.size()) - { - return mBars.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Removes all QCPBars plottables from this group. - - \see isEmpty -*/ -void QCPBarsGroup::clear() -{ - foreach (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay - bars->setBarsGroup(0); // removes itself via removeBars -} - -/*! - Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref - QCPBars::setBarsGroup on the \a bars instance. - - \see insert, remove -*/ -void QCPBarsGroup::append(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - else - qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); -} - -/*! - Inserts the specified \a bars plottable into this group at the specified index position \a i. - This gives you full control over the ordering of the bars. - - \a bars may already be part of this group. In that case, \a bars is just moved to the new index - position. - - \see append, remove -*/ -void QCPBarsGroup::insert(int i, QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - // first append to bars list normally: - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - // then move to according position: - mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); -} - -/*! - Removes the specified \a bars plottable from this group. - - \see contains, clear -*/ -void QCPBarsGroup::remove(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (mBars.contains(bars)) - bars->setBarsGroup(0); - else - qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); -} - -/*! \internal - - Adds the specified \a bars to the internal mBars list of bars. This method does not change the - barsGroup property on \a bars. - - \see unregisterBars -*/ -void QCPBarsGroup::registerBars(QCPBars *bars) -{ - if (!mBars.contains(bars)) - mBars.append(bars); -} - -/*! \internal - - Removes the specified \a bars from the internal mBars list of bars. This method does not change - the barsGroup property on \a bars. - - \see registerBars -*/ -void QCPBarsGroup::unregisterBars(QCPBars *bars) -{ - mBars.removeOne(bars); -} - -/*! \internal - - Returns the pixel offset in the key dimension the specified \a bars plottable should have at the - given key coordinate \a keyCoord. The offset is relative to the pixel position of the key - coordinate \a keyCoord. -*/ -double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) -{ - // find list of all base bars in case some mBars are stacked: - QList baseBars; - foreach (const QCPBars *b, mBars) - { - while (b->barBelow()) - b = b->barBelow(); - if (!baseBars.contains(b)) - baseBars.append(b); - } - // find base bar this "bars" is stacked on: - const QCPBars *thisBase = bars; - while (thisBase->barBelow()) - thisBase = thisBase->barBelow(); - - // determine key pixel offset of this base bars considering all other base bars in this barsgroup: - double result = 0; - int index = baseBars.indexOf(thisBase); - if (index >= 0) - { - if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) - { - return result; - } else - { - double lowerPixelWidth, upperPixelWidth; - int startIndex; - int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative - if (baseBars.size() % 2 == 0) // even number of bars - { - startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); - result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing - } else // uneven number of bars - { - startIndex = (baseBars.size()-1)/2+dir; - baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar - result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing - } - for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars - { - baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth); - result += getPixelSpacing(baseBars.at(i), keyCoord); - } - // finally half of our bars width: - baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; - // correct sign of result depending on orientation and direction of key axis: - result *= dir*thisBase->keyAxis()->pixelOrientation(); - } - } - return result; -} - -/*! \internal - - Returns the spacing in pixels which is between this \a bars and the following one, both at the - key coordinate \a keyCoord. - - \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only - needed to get access to the key axis transformation and axis rect for the modes \ref - stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in - \ref stPlotCoords on a logarithmic axis. -*/ -double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) -{ - switch (mSpacingType) - { - case stAbsolute: - { - return mSpacing; - } - case stAxisRectRatio: - { - if (bars->keyAxis()->orientation() == Qt::Horizontal) - return bars->keyAxis()->axisRect()->width()*mSpacing; - else - return bars->keyAxis()->axisRect()->height()*mSpacing; - } - case stPlotCoords: - { - double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); - return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); - } - } - return 0; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBarsData - \brief Holds the data of one single data point (one bar) for QCPBars. - - The stored data is: - \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) - \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPBarsDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPBarsData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPBarsData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a bar data point with key and value set to zero. -*/ -QCPBarsData::QCPBarsData() : - key(0), - value(0) -{ -} - -/*! - Constructs a bar data point with the specified \a key and \a value. -*/ -QCPBarsData::QCPBarsData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBars - \brief A plottable representing a bar chart in a plot. - - \image html QCPBars.png - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section qcpbars-appearance Changing the appearance - - The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). - The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. - - Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other - (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear - stacked. - - If you would like to group multiple QCPBars plottables together so they appear side by side as - shown below, use QCPBarsGroup. - - \image html QCPBarsGroup.png - - \section qcpbars-usage Usage - - Like all data representing objects in QCustomPlot, the QCPBars is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/*! \fn QCPBars *QCPBars::barBelow() const - Returns the bars plottable that is directly below this bars plottable. - If there is no such plottable, returns 0. - - \see barAbove, moveBelow, moveAbove -*/ - -/*! \fn QCPBars *QCPBars::barAbove() const - Returns the bars plottable that is directly above this bars plottable. - If there is no such plottable, returns 0. - - \see barBelow, moveBelow, moveAbove -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.75), - mWidthType(wtPlotCoords), - mBarsGroup(0), - mBaseValue(0), - mStackingGap(0) -{ - // modify inherited properties from abstract plottable: - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPBars::~QCPBars() -{ - setBarsGroup(0); - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. - Modifying the data in the container will then affect all bars that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the bar's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 - - \see addData -*/ -void QCPBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets the width of the bars. - - How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), - depends on the currently set width type, see \ref setWidthType and \ref WidthType. -*/ -void QCPBars::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the bars is defined. See the documentation of \ref WidthType for an - explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPBars::setWidthType(QCPBars::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref - QCPBarsGroup::append. - - To remove this QCPBars from any group, set \a barsGroup to 0. -*/ -void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) -{ - // deregister at old group: - if (mBarsGroup) - mBarsGroup->unregisterBars(this); - mBarsGroup = barsGroup; - // register at new group: - if (mBarsGroup) - mBarsGroup->registerBars(this); -} - -/*! - Sets the base value of this bars plottable. - - The base value defines where on the value coordinate the bars start. How far the bars extend from - the base value is given by their individual value data. For example, if the base value is set to - 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at - 3. - - For stacked bars, only the base value of the bottom-most QCPBars has meaning. - - The default base value is 0. -*/ -void QCPBars::setBaseValue(double baseValue) -{ - mBaseValue = baseValue; -} - -/*! - If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method - allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by - the bars below it. -*/ -void QCPBars::setStackingGap(double pixels) -{ - mStackingGap = pixels; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(double key, double value) -{ - mDataContainer->add(QCPBarsData(key, value)); -} - -/*! - Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear - below the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barAbove, barBelow -*/ -void QCPBars::moveBelow(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar below it: - if (bars) - { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); - } -} - -/*! - Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear - above the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object above itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barBelow, barAbove -*/ -void QCPBars::moveAbove(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar above it: - if (bars) - { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getBarRect(it->key, it->value))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getBarRect(it->key, it->value).contains(pos)) - { - if (details) - { - int pointIndex = it-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return mParentPlot->selectionTolerance()*0.99; - } - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in - absolute pixels), using this method to adapt the key axis range to fit the bars into the - currently visible axis range will not work perfectly. Because in the moment the axis range is - changed to the new range, the fixed pixel widths/spacings will represent different coordinate - spans than before, which in turn would require a different key range to perfectly fit, and so on. - The only solution would be to iteratively approach the perfect fitting axis range, but the - mismatch isn't large enough in most applications, to warrant this here. If a user does need a - better fit, he should call the corresponding axis rescale multiple times in a row. - */ - QCPRange range; - range = mDataContainer->keyRange(foundRange, inSignDomain); - - // determine exact range of bars by including bar width and barsgroup offset: - if (foundRange && mKeyAxis) - { - double lowerPixelWidth, upperPixelWidth, keyPixel; - // lower range bound: - getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); - const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) - range.lower = lowerCorrected; - // upper range bound: - getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); - const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) - range.upper = upperCorrected; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - // Note: can't simply use mDataContainer->valueRange here because we need to - // take into account bar base value and possible stacking of multiple bars - QCPRange range; - range.lower = mBaseValue; - range.upper = mBaseValue; - bool haveLower = true; // set to true, because baseValue should always be visible in bar charts - bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts - QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (inKeyRange != QCPRange()) - { - itBegin = mDataContainer->findBegin(inKeyRange.lower); - itEnd = mDataContainer->findEnd(inKeyRange.upper); - } - for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - - foundRange = true; // return true because bar charts always have the 0-line visible - return range; -} - -/* inherits documentation from base class */ -QPointF QCPBars::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); - const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyPixel, valuePixel); - else - return QPointF(valuePixel, keyPixel); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mDataContainer->isEmpty()) return; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPBarsDataContainer::const_iterator begin = visibleBegin; - QCPBarsDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -#endif - // draw bar: - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyBrush(painter); - mSelectionDecorator->applyPen(painter); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - } - applyDefaultAntialiasingHint(painter); - painter->drawPolygon(getBarRect(it->key, it->value)); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - if (mDataContainer->isEmpty()) - { - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - - // get visible data range as QMap iterators - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); - double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); - double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); - bool isVisible = false; - // walk left from begin to find lower bar that actually is completely outside visible pixel range: - QCPBarsDataContainer::const_iterator it = begin; - while (it != mDataContainer->constBegin()) - { - --it; - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); - if (isVisible) - begin = it; - else - break; - } - // walk right from ubound to find upper bar that actually is completely outside visible pixel range: - it = end; - while (it != mDataContainer->constEnd()) - { - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); - if (isVisible) - end = it+1; - else - break; - ++it; - } -} - -/*! \internal - - Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The - rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref - setBaseValue), and to have non-overlapping border lines with the bars stacked below. -*/ -QRectF QCPBars::getBarRect(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double lowerPixelWidth, upperPixelWidth; - getPixelWidth(key, lowerPixelWidth, upperPixelWidth); - double base = getStackedBaseValue(key, value >= 0); - double basePixel = valueAxis->coordToPixel(base); - double valuePixel = valueAxis->coordToPixel(base+value); - double keyPixel = keyAxis->coordToPixel(key); - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, key); - double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); - bottomOffset += mBarBelow ? mStackingGap : 0; - bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); - if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) - bottomOffset = valuePixel-basePixel; - if (keyAxis->orientation() == Qt::Horizontal) - { - return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); - } else - { - return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). - - The output parameters \a lower and \a upper return the number of pixels the bar extends to lower - and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a - lower is negative and \a upper positive). -*/ -void QCPBars::getPixelWidth(double key, double &lower, double &upper) const -{ - lower = 0; - upper = 0; - switch (mWidthType) - { - case wtAbsolute: - { - upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - { - double keyPixel = mKeyAxis.data()->coordToPixel(key); - upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; - // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by - // coordinate transform which includes range direction - } else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } -} - -/*! \internal - - This function is called to find at which value to start drawing the base of a bar at \a key, when - it is stacked on top of another QCPBars (e.g. with \ref moveAbove). - - positive and negative bars are separated per stack (positive are stacked above baseValue upwards, - negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the - bar for which we need the base value is negative, set \a positive to false. -*/ -double QCPBars::getStackedBaseValue(double key, bool positive) const -{ - if (mBarBelow) - { - double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack - // find bars of mBarBelow that are approximately at key and find largest one: - double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point - if (key == 0) - epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); - QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); - QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); - while (it != itEnd) - { - if (it->key > key-epsilon && it->key < key+epsilon) - { - if ((positive && it->value > max) || - (!positive && it->value < max)) - max = it->value; - } - ++it; - } - // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getStackedBaseValue(key, positive); - } else - return mBaseValue; -} - -/*! \internal - - Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) - currently above lower and below upper will become disconnected to lower/upper. - - If lower is zero, upper will be disconnected at the bottom. - If upper is zero, lower will be disconnected at the top. -*/ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) -{ - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom - { - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - lower->mBarAbove = 0; - } else // connect lower and upper - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - lower->mBarAbove = upper; - upper->mBarBelow = lower; - } -} -/* end of 'src/plottables/plottable-bars.cpp' */ - - -/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBoxData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBoxData - \brief Holds the data of one single data point for QCPStatisticalBox. - - The stored data is: - - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - - \li \a minimum: the position of the lower whisker, typically the minimum measurement of the - sample that's not considered an outlier. - - \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a median: the value of the median mark inside the quartile box. The median separates the - sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) - - \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a maximum: the position of the upper whisker, typically the maximum measurement of the - sample that's not considered an outlier. - - \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key - coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) - - The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a - typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template - parameter. See the documentation there for an explanation regarding the data type's generic - methods. - - \see QCPStatisticalBoxDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPStatisticalBoxData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainValue() const - - Returns the \a median member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const - - Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box - data point, possibly further expanded by outliers. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData() : - key(0), - minimum(0), - lowerQuartile(0), - median(0), - upperQuartile(0), - maximum(0) -{ -} - -/*! - Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a - upperQuartile, \a maximum and optionally a number of \a outliers. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : - key(key), - minimum(minimum), - lowerQuartile(lowerQuartile), - median(median), - upperQuartile(upperQuartile), - maximum(maximum), - outliers(outliers) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBox -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBox - \brief A plottable representing a single statistical box in a plot. - - \image html QCPStatisticalBox.png - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPStatisticalBoxDataContainer. - - Additionally each data point can itself have a list of outliers, drawn as scatter points at the - key coordinate of the respective statistical box data point. They can either be set by using the - respective \ref addData(double,double,double,double,double,double,const QVector&) - "addData" method or accessing the individual data points through \ref data, and setting the - QVector outliers of the data points directly. - - \section qcpstatisticalbox-appearance Changing the appearance - - The appearance of each data point box, ranging from the lower to the upper quartile, is - controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref - setWidth in plot coordinates. - - Each data point's visual representation also consists of two whiskers. Whiskers are the lines - which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. - The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, - \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at - the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set - the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a - few pixels due to the pen cap being not perfectly flat. - - The median indicator line inside the box has its own pen, \ref setMedianPen. - - The outlier data points are drawn as normal scatter points. Their look can be controlled with - \ref setOutlierStyle - - \section qcpstatisticalbox-usage Usage - - Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 -*/ - -/* start documentation of inline functions */ - -/*! \fn QSharedPointer QCPStatisticalBox::data() const - - Returns a shared pointer to the internal data storage of type \ref - QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more - convenient and faster than using the regular \ref setData or \ref addData methods. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its - value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and - not have the same orientation. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not - delete it manually but use QCustomPlot::removePlottable() instead. -*/ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.5), - mWhiskerWidth(0.2), - mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), - mWhiskerBarPen(Qt::black), - mWhiskerAntialiased(false), - mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), - mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) -{ - setPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container - safely. Modifying the data in the container will then affect all statistical boxes that share the - container. Sharing can be achieved by simply exchanging the data containers wrapped in shared - pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the statistical box data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 - - \see addData -*/ -void QCPStatisticalBox::setData(QSharedPointer data) -{ - mDataContainer = data; -} -/*! \overload - - Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a - median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the - number of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); -} - -/*! - Sets the width of the boxes in key coordinates. - - \see setWhiskerWidth -*/ -void QCPStatisticalBox::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the width of the whiskers in key coordinates. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWidth -*/ -void QCPStatisticalBox::setWhiskerWidth(double width) -{ - mWhiskerWidth = width; -} - -/*! - Sets the pen used for drawing the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone - line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. - - \see setWhiskerBarPen -*/ -void QCPStatisticalBox::setWhiskerPen(const QPen &pen) -{ - mWhiskerPen = pen; -} - -/*! - Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at - each end of the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWhiskerPen -*/ -void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) -{ - mWhiskerBarPen = pen; -} - -/*! - Sets whether the statistical boxes whiskers are drawn with antialiasing or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) -{ - mWhiskerAntialiased = enabled; -} - -/*! - Sets the pen used for drawing the median indicator line inside the statistical boxes. -*/ -void QCPStatisticalBox::setMedianPen(const QPen &pen) -{ - mMedianPen = pen; -} - -/*! - Sets the appearance of the outlier data points. - - Outliers can be specified with the method - \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -*/ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) -{ - mOutlierStyle = style; -} - -/*! \overload - - Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and - \a maximum to the current data. The provided vectors should have equal length. Else, the number - of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || - median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" - << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); - const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->minimum = minimum[i]; - it->lowerQuartile = lowerQuartile[i]; - it->median = median[i]; - it->upperQuartile = upperQuartile[i]; - it->maximum = maximum[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile - and \a maximum to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -{ - mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getQuartileBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - double minDistSqr = std::numeric_limits::max(); - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getQuartileBox(it).contains(pos)) // quartile box - { - double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } else // whiskers - { - const QVector whiskerBackbones(getWhiskerBackboneLines(it)); - for (int i=0; iconstBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return qSqrt(minDistSqr); - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; - QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -# ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->minimum) || - QCP::isInvalidData(it->lowerQuartile, it->median) || - QCP::isInvalidData(it->upperQuartile, it->maximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; ioutliers.size(); ++i) - if (QCP::isInvalidData(it->outliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -# endif - - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - QCPScatterStyle finalOutlierStyle = mOutlierStyle; - if (isSelectedSegment && mSelectionDecorator) - finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); - drawStatisticalBox(painter, it, finalOutlierStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! - Draws the graphical representation of a single statistical box with the data given by the - iterator \a it with the provided \a painter. - - If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. - - \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const -{ - // draw quartile box: - applyDefaultAntialiasingHint(painter); - const QRectF quartileBox = getQuartileBox(it); - painter->drawRect(quartileBox); - // draw median line with cliprect set to quartile box: - painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - painter->setPen(mMedianPen); - painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); - painter->restore(); - // draw whisker lines: - applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); - painter->setPen(mWhiskerPen); - painter->drawLines(getWhiskerBackboneLines(it)); - painter->setPen(mWhiskerBarPen); - painter->drawLines(getWhiskerBarLines(it)); - // draw outliers: - applyScattersAntialiasingHint(painter); - outlierStyle.applyTo(painter, mPen); - for (int i=0; ioutliers.size(); ++i) - outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points -} - -/*! \internal - - Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the - value range from the lower to the upper quartile, of the data given by \a it. - - \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QRectF result; - result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); - result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); - return result; -} - -/*! \internal - - Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value - range from the minimum to the lower quartile, and from the upper quartile to the maximum of the - data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines -*/ -QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone - result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone - return result; -} - -/*! \internal - - Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the - end of the whisker backbones, at the minimum and maximum of the data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines -*/ -QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar - result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar - return result; -} -/* end of 'src/plottables/plottable-statisticalbox.cpp' */ - - -/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMapData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMapData - \brief Holds the two-dimensional data of a QCPColorMap plottable. - - This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref - QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a - color, depending on the value. - - The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). - Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref - setKeyRange, \ref setValueRange). - - The data cells can be accessed in two ways: They can be directly addressed by an integer index - with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot - coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are - provided by the functions \ref coordToCell and \ref cellToCoord. - - A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if - allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref - fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on - the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. - - This class also buffers the minimum and maximum values that are in the data set, to provide - QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value - that is greater than the current maximum increases this maximum to the new value. However, - setting the cell that currently holds the maximum value to a smaller value doesn't decrease the - maximum again, because finding the true new maximum would require going through the entire data - array, which might be time consuming. The same holds for the data minimum. This functionality is - given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the - true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience - parameter \a recalculateDataBounds which may be set to true to automatically call \ref - recalculateDataBounds internally. -*/ - -/* start of documentation of inline functions */ - -/*! \fn bool QCPColorMapData::isEmpty() const - - Returns whether this instance carries no data. This is equivalent to having a size where at least - one of the dimensions is 0 (see \ref setSize). -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction - and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap - at the coordinates \a keyRange and \a valueRange. - - \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange -*/ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - setSize(keySize, valueSize); - fill(0); -} - -QCPColorMapData::~QCPColorMapData() -{ - if (mData) - delete[] mData; - if (mAlpha) - delete[] mAlpha; -} - -/*! - Constructs a new QCPColorMapData instance copying the data and range of \a other. -*/ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - *this = other; -} - -/*! - Overwrites this color map data instance with the data stored in \a other. The alpha map state is - transferred, too. -*/ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) -{ - if (&other != this) - { - const int keySize = other.keySize(); - const int valueSize = other.valueSize(); - if (!other.mAlpha && mAlpha) - clearAlpha(); - setSize(keySize, valueSize); - if (other.mAlpha && !mAlpha) - createAlpha(false); - setRange(other.keyRange(), other.valueRange()); - if (!isEmpty()) - { - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - if (mAlpha) - memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); - } - mDataBounds = other.mDataBounds; - mDataModified = true; - } - return *this; -} - -/* undocumented getter */ -double QCPColorMapData::data(double key, double value) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; - else - return 0; -} - -/* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; - else - return 0; -} - -/*! - Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. - - If this color map data doesn't have an alpha map (because \ref setAlpha was never called after - creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. - - \see setAlpha -*/ -unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) -{ - if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mAlpha[valueIndex*mKeySize + keyIndex]; - else - return 255; -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in - the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref - isEmpty returns true. - - \see setRange, setKeySize, setValueSize -*/ -void QCPColorMapData::setSize(int keySize, int valueSize) -{ - if (keySize != mKeySize || valueSize != mValueSize) - { - mKeySize = keySize; - mValueSize = valueSize; - if (mData) - delete[] mData; - mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) - { -#ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message -#endif - mData = new double[mKeySize*mValueSize]; -#ifdef __EXCEPTIONS - } catch (...) { mData = 0; } -#endif - if (mData) - fill(0); - else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else - mData = 0; - - if (mAlpha) // if we had an alpha map, recreate it with new size - createAlpha(); - - mDataModified = true; - } -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. - - \see setKeyRange, setSize, setValueSize -*/ -void QCPColorMapData::setKeySize(int keySize) -{ - setSize(keySize, mValueSize); -} - -/*! - Resizes the data array to have \a valueSize cells in the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. - - \see setValueRange, setSize, setKeySize -*/ -void QCPColorMapData::setValueSize(int valueSize) -{ - setSize(mKeySize, valueSize); -} - -/*! - Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area - covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setSize -*/ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) -{ - setKeyRange(keyRange); - setValueRange(valueRange); -} - -/*! - Sets the coordinate range the data shall be distributed over in the key dimension. Together with - the value range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setRange, setValueRange, setSize -*/ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) -{ - mKeyRange = keyRange; -} - -/*! - Sets the coordinate range the data shall be distributed over in the value dimension. Together with - the key range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there - will be cells centered on the value coordinates 2, 2.5 and 3. - - \see setRange, setKeyRange, setSize -*/ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) -{ - mValueRange = valueRange; -} - -/*! - Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a - z. - - \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or - value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, - you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to - determine the cell index. Rather directly access the cell index with \ref - QCPColorMapData::setCell. - - \see setCell, setRange -*/ -void QCPColorMapData::setData(double key, double value, double z) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices - enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see - \ref setSize). - - In the standard plot configuration (horizontal key axis and vertical value axis, both not - range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with - indices (keySize-1, valueSize-1) is in the top right corner of the color map. - - \see setData, setSize -*/ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value - of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully - opaque cell. - - If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish - to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. - - Note that the cell-wise alpha which can be configured here is independent of any alpha configured - in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise - and gradient alpha, the alpha values will be blended accordingly during rendering of the color - map. - - \see fillAlpha, clearAlpha -*/ -void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - if (mAlpha || createAlpha()) - { - mAlpha[valueIndex*mKeySize + keyIndex] = alpha; - mDataModified = true; - } - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Goes through the data and updates the buffered minimum and maximum data values. - - Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange - and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten - with a smaller or larger value respectively, since the buffered maximum/minimum values have been - updated the last time. Why this is the case is explained in the class description (\ref - QCPColorMapData). - - Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a - recalculateDataBounds for convenience. Setting this to true will call this method for you, before - doing the rescale. -*/ -void QCPColorMapData::recalculateDataBounds() -{ - if (mKeySize > 0 && mValueSize > 0) - { - double minHeight = mData[0]; - double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i maxHeight) - maxHeight = mData[i]; - if (mData[i] < minHeight) - minHeight = mData[i]; - } - mDataBounds.lower = minHeight; - mDataBounds.upper = maxHeight; - } -} - -/*! - Frees the internal data memory. - - This is equivalent to calling \ref setSize "setSize(0, 0)". -*/ -void QCPColorMapData::clear() -{ - setSize(0, 0); -} - -/*! - Frees the internal alpha map. The color map will have full opacity again. -*/ -void QCPColorMapData::clearAlpha() -{ - if (mAlpha) - { - delete[] mAlpha; - mAlpha = 0; - mDataModified = true; - } -} - -/*! - Sets all cells to the value \a z. -*/ -void QCPColorMapData::fill(double z) -{ - const int dataCount = mValueSize*mKeySize; - for (int i=0; i(data); - return; - } - if (copy) - { - *mMapData = *data; - } else - { - delete mMapData; - mMapData = data; - } - mMapImageInvalidated = true; -} - -/*! - Sets the data range of this color map to \a dataRange. The data range defines which data values - are mapped to the color gradient. - - To make the data range span the full range of the data set, use \ref rescaleDataRange. - - \see QCPColorScale::setDataRange -*/ -void QCPColorMap::setDataRange(const QCPRange &dataRange) -{ - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - if (mDataScaleType == QCPAxis::stLogarithmic) - mDataRange = dataRange.sanitizedForLogScale(); - else - mDataRange = dataRange.sanitizedForLinScale(); - mMapImageInvalidated = true; - emit dataRangeChanged(mDataRange); - } -} - -/*! - Sets whether the data is correlated with the color gradient linearly or logarithmically. - - \see QCPColorScale::setDataScaleType -*/ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - mMapImageInvalidated = true; - emit dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - } -} - -/*! - Sets the color gradient that is used to represent the data. For more details on how to create an - own gradient or use one of the preset gradients, see \ref QCPColorGradient. - - The colors defined by the gradient will be used to represent data values in the currently set - data range, see \ref setDataRange. Data points that are outside this data range will either be - colored uniformly with the respective gradient boundary color, or the gradient will repeat, - depending on \ref QCPColorGradient::setPeriodic. - - \see QCPColorScale::setGradient -*/ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - mMapImageInvalidated = true; - emit gradientChanged(mGradient); - } -} - -/*! - Sets whether the color map image shall use bicubic interpolation when displaying the color map - shrinked or expanded, and not at a 1:1 pixel-to-data scale. - - \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" -*/ -void QCPColorMap::setInterpolate(bool enabled) -{ - mInterpolate = enabled; - mMapImageInvalidated = true; // because oversampling factors might need to change -} - -/*! - Sets whether the outer most data rows and columns are clipped to the specified key and value - range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). - - if \a enabled is set to false, the data points at the border of the color map are drawn with the - same width and height as all other data points. Since the data points are represented by - rectangles of one color centered on the data coordinate, this means that the shown color map - extends by half a data point over the specified key/value range in each direction. - - \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" -*/ -void QCPColorMap::setTightBoundary(bool enabled) -{ - mTightBoundary = enabled; -} - -/*! - Associates the color scale \a colorScale with this color map. - - This means that both the color scale and the color map synchronize their gradient, data range and - data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps - can be associated with one single color scale. This causes the color maps to also synchronize - those properties, via the mutual color scale. - - This function causes the color map to adopt the current color gradient, data range and data scale - type of \a colorScale. After this call, you may change these properties at either the color map - or the color scale, and the setting will be applied to both. - - Pass 0 as \a colorScale to disconnect the color scale from this color map again. -*/ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) -{ - if (mColorScale) // unconnect signals from old color scale - { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale - { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } -} - -/*! - Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the - current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, - only for the third data dimension of the color map. - - The minimum and maximum values of the data set are buffered in the internal QCPColorMapData - instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref - QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For - performance reasons, however, they are only updated in an expanding fashion. So the buffered - maximum can only increase and the buffered minimum can only decrease. In consequence, changes to - the data that actually lower the maximum of the data set (by overwriting the cell holding the - current maximum with a smaller value), aren't recognized and the buffered maximum overestimates - the true maximum of the data set. The same happens for the buffered minimum. To recalculate the - true minimum and maximum by explicitly looking at each cell, the method - QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a - recalculateDataBounds calls this method before setting the data range to the buffered minimum and - maximum. - - \see setDataRange -*/ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) -{ - if (recalculateDataBounds) - mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); -} - -/*! - Takes the current appearance of the color map and updates the legend icon, which is used to - represent this color map in the legend (see \ref QCPLegend). - - The \a transformMode specifies whether the rescaling is done by a faster, low quality image - scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm - (Qt::SmoothTransformation). - - The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to - the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured - legend icon size, the thumb will be rescaled during drawing of the legend item. - - \see setDataRange -*/ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) -{ - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again - { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); - } -} - -/* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) - { - if (details) - details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. - return mParentPlot->selectionTolerance()*0.99; - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->keyRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (inKeyRange != QCPRange()) - { - if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) - { - foundRange = false; - return QCPRange(); - } - } - - foundRange = true; - QCPRange result = mMapData->valueRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/*! \internal - - Updates the internal map image buffer by going through the internal \ref QCPColorMapData and - turning the data values into color pixels with \ref QCPColorGradient::colorize. - - This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image - has been invalidated for a different reason (e.g. a change of the data range with \ref - setDataRange). - - If the map cell count is low, the image created will be oversampled in order to avoid a - QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images - without smooth transform enabled. Accordingly, oversampling isn't performed if \ref - setInterpolate is true. -*/ -void QCPColorMap::updateMapImage() -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - if (mMapData->isEmpty()) return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - const int keySize = mMapData->keySize(); - const int valueSize = mMapData->valueSize(); - int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - - // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) - mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) - mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); - - if (mMapImage.isNull()) - { - qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; - mMapImage = QImage(QSize(10, 10), format); - mMapImage.fill(Qt::black); - } else - { - QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - // resize undersampled map image to actual key/value cell sizes: - if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) - mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); - else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) - mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); - localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image - } else if (!mUndersampledMapImage.isNull()) - mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it - - const double *rawData = mMapData->mData; - const unsigned char *rawAlpha = mMapData->mAlpha; - if (keyAxis->orientation() == Qt::Horizontal) - { - const int lineCount = valueSize; - const int rowCount = keySize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - } - } else // keyAxis->orientation() == Qt::Vertical - { - const int lineCount = keySize; - const int rowCount = valueSize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - } - } - - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - if (keyAxis->orientation() == Qt::Horizontal) - mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - else - mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - } - } - mMapData->mDataModified = false; - mMapImageInvalidated = false; -} - -/* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) -{ - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) - updateMapImage(); - - // use buffer if painting vectorized (PDF): - const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); - QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized - QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in - QPixmap mapBuffer; - if (useBuffer) - { - const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps - mapBufferTarget = painter->clipRegion().boundingRect(); - mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); - mapBuffer.fill(Qt::transparent); - localPainter = new QCPPainter(&mapBuffer); - localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); - localPainter->translate(-mapBufferTarget.topLeft()); - } - - QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): - double halfCellWidth = 0; // in pixels - double halfCellHeight = 0; // in pixels - if (keyAxis()->orientation() == Qt::Horizontal) - { - if (mMapData->keySize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); - } else // keyAxis orientation is Qt::Vertical - { - if (mMapData->keySize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); - } - imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); - const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); - QRegion clipBackup; - if (mTightBoundary) - { - clipBackup = localPainter->clipRegion(); - QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - localPainter->setClipRect(tightClipRect, Qt::IntersectClip); - } - localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - localPainter->setClipRegion(clipBackup); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); - - if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter - { - delete localPainter; - painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); - } -} - -/* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - // draw map thumbnail: - if (!mLegendIcon.isNull()) - { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); - } - /* - // draw frame: - painter->setBrush(Qt::NoBrush); - painter->setPen(Qt::black); - painter->drawRect(rect.adjusted(1, 1, 0, 0)); - */ -} -/* end of 'src/plottables/plottable-colormap.cpp' */ - - -/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancialData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancialData - \brief Holds the data of one single data point for QCPFinancial. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a open: The opening value at the data point (this is the \a mainValue) - \li \a high: The high/maximum value at the data point - \li \a low: The low/minimum value at the data point - \li \a close: The closing value at the data point - - The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef - for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPFinancialDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPFinancialData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainValue() const - - Returns the \a open member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPFinancialData::valueRange() const - - Returns a QCPRange spanning from the \a low to the \a high value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPFinancialData::QCPFinancialData() : - key(0), - open(0), - high(0), - low(0), - close(0) -{ -} - -/*! - Constructs a data point with the specified \a key and OHLC values. -*/ -QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : - key(key), - open(open), - high(high), - low(low), - close(close) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancial -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancial - \brief A plottable representing a financial stock chart - - \image html QCPFinancial.png - - This plottable represents time series data binned to certain intervals, mainly used for stock - charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be - set via \ref setChartStyle. - - The data is passed via \ref setData as a set of open/high/low/close values at certain keys - (typically times). This means the data must be already binned appropriately. If data is only - available as a series of values (e.g. \a price against \a time), you can use the static - convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed - to \ref setData. - - The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref - setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and - the width to (or slightly less than) one time bin interval width. - - \section qcpfinancial-appearance Changing the appearance - - Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, - lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). - - If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are - represented with a different pen and brush than negative changes (\a close < \a open). These can - be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref - setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection - however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, - irrespective of whether the chart is single- or two-colored. - - \section qcpfinancial-usage Usage - - Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot - instance takes ownership of the plottable, so do not delete it manually but use - QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 - Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data - series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const - - Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods, in certain situations. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mChartStyle(csCandlestick), - mWidth(0.5), - mWidthType(wtPlotCoords), - mTwoColored(true), - mBrushPositive(QBrush(QColor(50, 160, 0))), - mBrushNegative(QBrush(QColor(180, 0, 15))), - mPenPositive(QPen(QColor(40, 150, 0))), - mPenNegative(QPen(QColor(170, 5, 5))) -{ - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPFinancial::~QCPFinancial() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. - Modifying the data in the container will then affect all financials that share the container. - Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the financial's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a - close. The provided vectors should have equal length. Else, the number of added points will be - the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, open, high, low, close, alreadySorted); -} - -/*! - Sets which representation style shall be used to display the OHLC data. -*/ -void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) -{ - mChartStyle = style; -} - -/*! - Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. - - A typical choice is to set it to (or slightly less than) one bin interval width. -*/ -void QCPFinancial::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for - an explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets whether this chart shall contrast positive from negative trends per data point by using two - separate colors to draw the respective bars/candlesticks. - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setTwoColored(bool twoColored) -{ - mTwoColored = twoColored; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushNegative, setPenPositive, setPenNegative -*/ -void QCPFinancial::setBrushPositive(const QBrush &brush) -{ - mBrushPositive = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushPositive, setPenNegative, setPenPositive -*/ -void QCPFinancial::setBrushNegative(const QBrush &brush) -{ - mBrushNegative = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setPenPositive(const QPen &pen) -{ - mPenPositive = pen; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setBrushNegative, setBrushPositive -*/ -void QCPFinancial::setPenNegative(const QPen &pen) -{ - mPenNegative = pen; -} - -/*! \overload - - Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. - The provided vectors should have equal length. Else, the number of added points will be the size - of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); - const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->open = open[i]; - it->high = high[i]; - it->low = low[i]; - it->close = close[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current - data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(double key, double open, double high, double low, double close) -{ - mDataContainer->add(QCPFinancialData(key, open, high, low, close)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(selectionHitBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - // perform select test according to configured style: - double result = -1; - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - case QCPFinancial::csCandlestick: - result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - } - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } - - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/*! - A convenience function that converts time series data (\a value against \a time) to OHLC binned - data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const - QCPFinancialDataContainer&). - - The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. - For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour - each, set \a timeBinSize to 3600. - - \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The - value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. - It merely defines the mathematical offset/phase of the bins that will be used to process the - data. -*/ -QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) -{ - QCPFinancialDataContainer data; - int count = qMin(time.size(), value.size()); - if (count == 0) - return QCPFinancialDataContainer(); - - QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); - int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); - for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); - if (i == count-1) // last data point is in current bin, finalize bin: - { - currentBinData.close = value.at(i); - currentBinData.key = timeBinOffset+(index)*timeBinSize; - data.add(currentBinData); - } - } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: - { - // finalize current bin: - currentBinData.close = value.at(i-1); - currentBinData.key = timeBinOffset+(index-1)*timeBinSize; - data.add(currentBinData); - // start next bin: - currentBinIndex = index; - currentBinData.open = value.at(i); - currentBinData.high = value.at(i); - currentBinData.low = value.at(i); - } - } - - return data; -} - -/* inherits documentation from base class */ -void QCPFinancial::draw(QCPPainter *painter) -{ - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPFinancialDataContainer::const_iterator begin = visibleBegin; - QCPFinancialDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - // draw data segment according to configured style: - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - drawOhlcPlot(painter, begin, end, isSelectedSegment); break; - case QCPFinancial::csCandlestick: - drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing - if (mChartStyle == csOhlc) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } - } else if (mChartStyle == csCandlestick) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. -*/ -void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); - // draw close: - painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); - } - } else - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); - // draw close: - painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. -*/ -void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - // draw low: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - // draw low: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); - } - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of - \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel - when this function is called). - - It returns the number of pixels the bar extends to higher keys, relative to the \a key - coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed - horizontal axis, the return value is negative. This is important so the open/close flags on the - \ref csOhlc bar are drawn to the correct side. -*/ -double QCPFinancial::getPixelWidth(double key, double keyPixel) const -{ - double result = 0; - switch (mWidthType) - { - case wtAbsolute: - { - if (mKeyAxis) - result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } - return result; -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a - end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - called by the drawing methods to determine which data (key) range is visible at the current key - axis range setting, so only that needs to be processed. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - begin may still be just outside the visible range. - - \a end returns the iterator just above the highest data point that needs to be taken into - account. Same as before, \a end may also lie just outside of the visible range - - if the plottable contains no data, both \a begin and \a end point to \c constEnd. -*/ -void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points -} - -/*! \internal - - Returns the hit box in pixel coordinates that will be used for data selection with the selection - rect (\ref selectTestRect), of the data point given by \a it. -*/ -QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double keyPixel = keyAxis->coordToPixel(it->key); - double highPixel = valueAxis->coordToPixel(it->high); - double lowPixel = valueAxis->coordToPixel(it->low); - double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); - if (keyAxis->orientation() == Qt::Horizontal) - return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); - else - return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); -} -/* end of 'src/plottables/plottable-financial.cpp' */ - - -/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBarsData - \brief Holds the data of one single error bar for QCPErrorBars. - - The stored data is: - \li \a errorMinus: how much the error bar extends towards negative coordinates from the data - point position - \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point - position - - The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a - typedef for QVector<\ref QCPErrorBarsData>. - - \see QCPErrorBarsDataContainer -*/ - -/*! - Constructs an error bar with errors set to zero. -*/ -QCPErrorBarsData::QCPErrorBarsData() : - errorMinus(0), - errorPlus(0) -{ -} - -/*! - Constructs an error bar with equal \a error in both negative and positive direction. -*/ -QCPErrorBarsData::QCPErrorBarsData(double error) : - errorMinus(error), - errorPlus(error) -{ -} - -/*! - Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, - respectively. -*/ -QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : - errorMinus(errorMinus), - errorPlus(errorPlus) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBars - \brief A plottable that adds a set of error bars to other plottables. - - \image html QCPErrorBars.png - - The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref - QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. - - Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the - error bars. The orientation of the error bars can be controlled with \ref setErrorType. - - By using \ref setData, you can supply the actual error data, either as symmetric error or - plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute - key/value position of each error bar will be adopted from the configured data plottable. The - error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points - of the data plottable. You can directly access and manipulate the error bar data via \ref data. - - Set either of the plus/minus errors to NaN (qQNaN() or - std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at - that index. - - \section qcperrorbars-appearance Changing the appearance - - The appearance of the error bars is defined by the pen (\ref setPen), and the width of the - whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data - point center to prevent that error bars are drawn too close to or even through scatter points. - This gap size can be controlled via \ref setSymbolGap. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPErrorBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You - may use it to directly manipulate the error values, which may be more convenient and faster than - using the regular \ref setData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - It is also important that the \a keyAxis and \a valueAxis are the same for the error bars - plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). - - The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not - delete it manually but use \ref QCustomPlot::removePlottable() instead. -*/ -QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QVector), - mErrorType(etValueError), - mWhiskerWidth(9), - mSymbolGap(10) -{ - setPen(QPen(Qt::black, 0)); - setBrush(Qt::NoBrush); -} - -QCPErrorBars::~QCPErrorBars() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data - container safely. Modifying the data in the container will then affect all \ref QCPErrorBars - instances that share the container. Sharing can be achieved by simply exchanging the data - containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, assign the - data containers directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 - (This uses different notation compared with other plottables, because the \ref QCPErrorBars - uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) - - \see addData -*/ -void QCPErrorBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &error) -{ - mDataContainer->clear(); - addData(error); -} - -/*! \overload - - Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) -{ - mDataContainer->clear(); - addData(errorMinus, errorPlus); -} - -/*! - Sets the data plottable to which the error bars will be applied. The error values specified e.g. - via \ref setData will be associated one-to-one by the data point index to the data points of \a - plottable. This means that the error bars will adopt the key/value coordinates of the data point - with the same index. - - The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref - QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either - of these restrictions is violated, a corresponding qDebug output is generated, and the data - plottable of this \ref QCPErrorBars instance is set to zero. - - For proper display, care must also be taken that the key and value axes of the \a plottable match - those configured for this \ref QCPErrorBars instance. -*/ -void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) -{ - if (plottable && qobject_cast(plottable)) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; - return; - } - if (plottable && !plottable->interface1D()) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; - return; - } - - mDataPlottable = plottable; -} - -/*! - Sets in which orientation the error bars shall appear on the data points. If your data needs both - error dimensions, create two \ref QCPErrorBars with different \a type. -*/ -void QCPErrorBars::setErrorType(ErrorType type) -{ - mErrorType = type; -} - -/*! - Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to - \a pixels. -*/ -void QCPErrorBars::setWhiskerWidth(double pixels) -{ - mWhiskerWidth = pixels; -} - -/*! - Sets the gap diameter around the data points that will be left out when drawing the error bar - backbones. This gap prevents that error bars are drawn too close to or even through scatter - points. -*/ -void QCPErrorBars::setSymbolGap(double pixels) -{ - mSymbolGap = pixels; -} - -/*! \overload - - Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &error) -{ - addData(error, error); -} - -/*! \overload - - Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) -{ - if (errorMinus.size() != errorPlus.size()) - qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); - const int n = qMin(errorMinus.size(), errorPlus.size()); - mDataContainer->reserve(n); - for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); -} - -/*! \overload - - Adds a single symmetrical error bar as specified in \a error. The errors will be associated - one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double error) -{ - mDataContainer->append(QCPErrorBarsData(error)); -} - -/*! \overload - - Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors - will be associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double errorMinus, double errorPlus) -{ - mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); -} - -/* inherits documentation from base class */ -int QCPErrorBars::dataCount() const -{ - return mDataContainer->size(); -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataSortKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataSortKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainValue(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainValue(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::dataValueRange(int index) const -{ - if (mDataPlottable) - { - const double value = mDataPlottable->interface1D()->dataMainValue(index); - if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) - return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); - else - return QCPRange(value, value); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QCPRange(); - } -} - -/* inherits documentation from base class */ -QPointF QCPErrorBars::dataPixelPosition(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataPixelPosition(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QPointF(); -} - -/* inherits documentation from base class */ -bool QCPErrorBars::sortKeyIsMainKey() const -{ - if (mDataPlottable) - { - return mDataPlottable->interface1D()->sortKeyIsMainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return true; - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if (!mDataPlottable) - return result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); - - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - backbones.clear(); - whiskers.clear(); - getErrorBarLines(it, backbones, whiskers); - for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); - break; - } - } - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); - if (beginIndex >= mDataContainer->size()) - beginIndex = mDataContainer->size()-1; - return beginIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); - if (endIndex > mDataContainer->size()) - endIndex = mDataContainer->size(); - return endIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mDataPlottable) return -1; - - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -void QCPErrorBars::draw(QCPPainter *painter) -{ - if (!mDataPlottable) return; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - - // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually - // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): - bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); - } -#endif - - applyDefaultAntialiasingHint(painter); - painter->setBrush(Qt::NoBrush); - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - QVector backbones, whiskers; - for (int i=0; i= unselectedSegments.size(); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - if (painter->pen().capStyle() == Qt::SquareCap) - { - QPen capFixPen(painter->pen()); - capFixPen.setCapStyle(Qt::FlatCap); - painter->setPen(capFixPen); - } - backbones.clear(); - whiskers.clear(); - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) - getErrorBarLines(it, backbones, whiskers); - } - painter->drawLines(backbones); - painter->drawLines(whiskers); - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) - { - painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); - painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); - painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); - } else - { - painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); - painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); - painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); - } -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (mErrorType == etValueError) - { - // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } else // mErrorType == etKeyError - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(dataKey)) continue; - // plus error: - double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); - itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); - } - for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange) - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) - continue; - } - if (mErrorType == etValueError) - { - const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(dataValue)) continue; - // plus error: - double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } else // mErrorType == etKeyError - { - // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! \internal - - Calculates the lines that make up the error bar belonging to the data point \a it. - - The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so - calling this method with different \a it but the same \a backbones and \a whiskers allows to - accumulate lines for multiple data points. - - This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars - instance and within the bounds of the associated data plottable. -*/ -void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const -{ - if (!mDataPlottable) return; - - int index = it-mDataContainer->constBegin(); - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) - return; - QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); - QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); - const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value - const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); - // plus error: - double errorStart, errorEnd; - if (!qIsNaN(it->errorPlus)) - { - errorStart = centerErrorAxisPixel+symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } - // minus error: - if (!qIsNaN(it->errorMinus)) - { - errorStart = centerErrorAxisPixel-symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } -} - -/*! \internal - - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key - coordinates relative to their data point key, this method checks all outer error bars whether - they truly don't reach into the visible portion of the axis rect, by calling \ref - errorBarVisible. On the other hand error bars with type \ref etValueError that are associated - with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype - "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of - error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref - QCPPlottableInterface1D::findEnd). - - If the plottable's sort key is not equal to the main key, this method returns the full data - range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a - point-by-point basis in the \ref draw method. -*/ -void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable || rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) - { - // if the sort key isn't the main key, it's not possible to find a contiguous range of visible - // data points, so this method then only applies the range restriction and otherwise returns - // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing - QCPDataRange dataRange(0, mDataContainer->size()); - dataRange = dataRange.bounded(rangeRestriction); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); - return; - } - - // get visible data range via interface from data plottable, and then restrict to available error data points: - const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); - int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); - int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); - int i = beginIndex; - while (i > 0 && i < n && i > rangeRestriction.begin()) - { - if (errorBarVisible(i)) - beginIndex = i; - --i; - } - i = endIndex; - while (i >= 0 && i < n && i < rangeRestriction.end()) - { - if (errorBarVisible(i)) - endIndex = i+1; - ++i; - } - QCPDataRange dataRange(beginIndex, endIndex); - dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); -} - -/*! \internal - - Calculates the minimum distance in pixels the error bars' representation has from the given \a - pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. -*/ -double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (!mDataPlottable || mDataContainer->isEmpty()) - return -1.0; - if (!mKeyAxis || !mValueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return -1.0; - } - - QCPErrorBarsDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); - - // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - getErrorBarLines(it, backbones, whiskers); - for (int i=0; i &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! \internal - - Returns whether the error bar at the specified \a index is visible within the current key axis - range. - - This method assumes for performance reasons without checking that the key axis, the value axis, - and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid - bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. -*/ -bool QCPErrorBars::errorBarVisible(int index) const -{ - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - if (qIsNaN(centerKeyPixel)) - return false; - - double keyMin, keyMax; - if (mErrorType == etKeyError) - { - const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); - const double errorPlus = mDataContainer->at(index).errorPlus; - const double errorMinus = mDataContainer->at(index).errorMinus; - keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); - keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); - } else // mErrorType == etValueError - { - keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - } - return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); -} - -/*! \internal - - Returns whether \a line intersects (or is contained in) \a pixelRect. - - \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for - error bar lines. -*/ -bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const -{ - if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) - return false; - else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) - return false; - else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) - return false; - else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) - return false; - else - return true; -} -/* end of 'src/plottables/plottable-errorbar.cpp' */ - - -/* including file 'src/items/item-straightline.cpp', size 7592 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemStraightLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemStraightLine - \brief A straight line that spans infinitely in both directions - - \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a point1 and \a point2, which define the straight line. -*/ - -/*! - Creates a straight line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition(QLatin1String("point1"))), - point2(createPosition(QLatin1String("point2"))) -{ - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemStraightLine::~QCPItemStraightLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemStraightLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); -} - -/* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) -{ - QCPVector2D start(point1->pixelPosition()); - QCPVector2D end(point2->pixelPosition()); - // get visible segment of straight line inside clipRect: - double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - } -} - -/*! \internal - - Returns the section of the straight line defined by \a base and direction vector \a - vec, that is visible in the specified \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const -{ - double bx, by; - double gamma; - QLineF result; - if (vec.x() == 0 && vec.y() == 0) - return result; - if (qFuzzyIsNull(vec.x())) // line is vertical - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed - { - QList pointVectors; - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - // check right of rect: - bx = rect.right(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemStraightLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-straightline.cpp' */ - - -/* including file 'src/items/item-line.cpp', size 8498 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemLine - \brief A line from one point to another - - \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a start and \a end, which define the end points of the line. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. -*/ - -/*! - Creates a line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemLine::~QCPItemLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemLine::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemLine::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); -} - -/* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) -{ - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if (qFuzzyIsNull((startVec-endVec).lengthSquared())) - return; - // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); - } -} - -/*! \internal - - Returns the section of the line defined by \a start and \a end, that is visible in the specified - \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const -{ - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - - QCPVector2D base = start; - QCPVector2D vec = end-start; - double bx, by; - double gamma, mu; - QLineF result; - QList pointVectors; - - if (!qFuzzyIsNull(vec.y())) // line is not horizontal - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - } - if (!qFuzzyIsNull(vec.x())) // line is not vertical - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - // check right of rect: - bx = rect.right(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-line.cpp' */ - - -/* including file 'src/items/item-curve.cpp', size 7159 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemCurve - \brief A curved line from one point to another - - \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." - - It has four positions, \a start and \a end, which define the end points of the line, and two - control points which define the direction the line exits from the start and the direction from - which it approaches the end: \a startDir and \a endDir. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an - arrow. - - Often it is desirable for the control points to stay at fixed relative positions to the start/end - point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, - and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. -*/ - -/*! - Creates a curve item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - startDir(createPosition(QLatin1String("startDir"))), - endDir(createPosition(QLatin1String("endDir"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemCurve::~QCPItemCurve() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemCurve::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemCurve::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemCurve::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemCurve::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF startVec(start->pixelPosition()); - QPointF startDirVec(startDir->pixelPosition()); - QPointF endDirVec(endDir->pixelPosition()); - QPointF endVec(end->pixelPosition()); - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - QPolygonF polygon = cubicPath.toSubpathPolygons().first(); - QCPVector2D p(pos); - double minDistSqr = std::numeric_limits::max(); - for (int i=1; ipixelPosition()); - QCPVector2D startDirVec(startDir->pixelPosition()); - QCPVector2D endDirVec(endDir->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if ((endVec-startVec).length() > 1e10) // too large curves cause crash - return; - - QPainterPath cubicPath(startVec.toPointF()); - cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); - - // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) - { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemCurve::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-curve.cpp' */ - - -/* including file 'src/items/item-rect.cpp', size 6479 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemRect - \brief A rectangle - - \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemRect::~QCPItemRect() -{ -} - -/*! - Sets the pen that will be used to draw the line of the rectangle - - \see setSelectedPen, setBrush -*/ -void QCPItemRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the rectangle when selected - - \see setPen, setSelected -*/ -void QCPItemRect::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemRect::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); -} - -/* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF rect = QRectF(p1, p2).normalized(); - double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemRect::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemRect::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-rect.cpp' */ - - -/* including file 'src/items/item-text.cpp', size 13338 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemText -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemText - \brief A text label - - \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." - - Its position is defined by the member \a position and the setting of \ref setPositionAlignment. - The latter controls which part of the text rect shall be aligned with \a position. - - The text alignment itself (i.e. left, center, right) can be controlled with \ref - setTextAlignment. - - The text may be rotated around the \a position point with \ref setRotation. -*/ - -/*! - Creates a text item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mText(QLatin1String("text")), - mPositionAlignment(Qt::AlignCenter), - mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), - mRotation(0) -{ - position->setCoords(0, 0); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); -} - -QCPItemText::~QCPItemText() -{ -} - -/*! - Sets the color of the text. -*/ -void QCPItemText::setColor(const QColor &color) -{ - mColor = color; -} - -/*! - Sets the color of the text that will be used when the item is selected. -*/ -void QCPItemText::setSelectedColor(const QColor &color) -{ - mSelectedColor = color; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text. To disable the - border, set \a pen to Qt::NoPen. - - \see setSelectedPen, setBrush, setPadding -*/ -void QCPItemText::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text, when the item is - selected. To disable the border, set \a pen to Qt::NoPen. - - \see setPen -*/ -void QCPItemText::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used do fill the background of the text. To disable the - background, set \a brush to Qt::NoBrush. - - \see setSelectedBrush, setPen, setPadding -*/ -void QCPItemText::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the - background, set \a brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemText::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the font of the text. - - \see setSelectedFont, setColor -*/ -void QCPItemText::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the font of the text that will be used when the item is selected. - - \see setFont -*/ -void QCPItemText::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the text that will be displayed. Multi-line texts are supported by inserting a line break - character, e.g. '\n'. - - \see setFont, setColor, setTextAlignment -*/ -void QCPItemText::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets which point of the text rect shall be aligned with \a position. - - Examples: - \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such - that the top of the text rect will be horizontally centered on \a position. - \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the - bottom left corner of the text rect. - - If you want to control the alignment of (multi-lined) text within the text rect, use \ref - setTextAlignment. -*/ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) -{ - mPositionAlignment = alignment; -} - -/*! - Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). -*/ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) -{ - mTextAlignment = alignment; -} - -/*! - Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated - around \a position. -*/ -void QCPItemText::setRotation(double degrees) -{ - mRotation = degrees; -} - -/*! - Sets the distance between the border of the text rectangle and the text. The appearance (and - visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. -*/ -void QCPItemText::setPadding(const QMargins &padding) -{ - mPadding = padding; -} - -/* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - // The rect may be rotated, so we transform the actual clicked pos to the rotated - // coordinate system, so we can use the normal rectDistance function for non-rotated rects: - QPointF positionPixels(position->pixelPosition()); - QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); - - return rectDistance(textBoxRect, rotatedPos, true); -} - -/* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) -{ - QPointF pos(position->pixelPosition()); - QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); - double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) - { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); - } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPosition(int anchorId) const -{ - // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPosition()); - QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) - { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the point that must be given to the QPainter::drawText function (which expects the top - left point of the text rect), according to the position \a pos, the text bounding box \a rect and - the requested \a positionAlignment. - - For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point - will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally - drawn at that point, the lower left corner of the resulting text rect is at \a pos. -*/ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const -{ - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) - return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) - result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) - result.ry() -= rect.height(); - return result; -} - -/*! \internal - - Returns the font that should be used for drawing text. Returns mFont when the item is not selected - and mSelectedFont when it is. -*/ -QFont QCPItemText::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the color that should be used for drawing text. Returns mColor when the item is not - selected and mSelectedColor when it is. -*/ -QColor QCPItemText::mainColor() const -{ - return mSelected ? mSelectedColor : mColor; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemText::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemText::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-text.cpp' */ - - -/* including file 'src/items/item-ellipse.cpp', size 7863 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemEllipse -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemEllipse - \brief An ellipse - - \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. -*/ - -/*! - Creates an ellipse item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), - left(createAnchor(QLatin1String("left"), aiLeft)), - center(createAnchor(QLatin1String("center"), aiCenter)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemEllipse::~QCPItemEllipse() -{ -} - -/*! - Sets the pen that will be used to draw the line of the ellipse - - \see setSelectedPen, setBrush -*/ -void QCPItemEllipse::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the ellipse when selected - - \see setPen, setSelected -*/ -void QCPItemEllipse::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemEllipse::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - - // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - double result = qAbs(c-1)*qSqrt(x*x+y*y); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); -#ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big - { -#endif - painter->drawEllipse(ellipseRect); -#ifdef __EXCEPTIONS - } catch (...) - { - qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); - } -#endif - } -} - -/* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemEllipse::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemEllipse::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-ellipse.cpp' */ - - -/* including file 'src/items/item-pixmap.cpp', size 10615 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPixmap - \brief An arbitrary pixmap - - \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will - be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to - fit the rectangle or be drawn aligned to the topLeft position. - - If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown - on the right side of the example image), the pixmap will be flipped in the respective - orientations. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mScaled(false), - mScaledPixmapInvalidated(true), - mAspectRatioMode(Qt::KeepAspectRatio), - mTransformationMode(Qt::SmoothTransformation) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); -} - -QCPItemPixmap::~QCPItemPixmap() -{ -} - -/*! - Sets the pixmap that will be displayed. -*/ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) -{ - mPixmap = pixmap; - mScaledPixmapInvalidated = true; - if (mPixmap.isNull()) - qDebug() << Q_FUNC_INFO << "pixmap is null"; -} - -/*! - Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a - bottomRight positions. -*/ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) -{ - mScaled = scaled; - mAspectRatioMode = aspectRatioMode; - mTransformationMode = transformationMode; - mScaledPixmapInvalidated = true; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap. - - \see setSelectedPen, setBrush -*/ -void QCPItemPixmap::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap when selected - - \see setPen, setSelected -*/ -void QCPItemPixmap::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return rectDistance(getFinalRect(), pos, true); -} - -/* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) -{ - bool flipHorz = false; - bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); - double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) - { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); - QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) - { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const -{ - bool flipHorz; - bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); - // we actually want denormal rects (negative width/height) here, so restore - // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The - parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped - horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a - bottomRight.) - - This function only creates the scaled pixmap when the buffered pixmap has a different size than - the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does - not cause expensive rescaling every time. - - If scaling is disabled, sets mScaledPixmap to a null QPixmap. -*/ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) -{ - if (mPixmap.isNull()) - return; - - if (mScaled) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - double devicePixelRatio = mPixmap.devicePixelRatio(); -#else - double devicePixelRatio = 1.0; -#endif - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) - { - mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mScaledPixmap.setDevicePixelRatio(devicePixelRatio); -#endif - } - } else if (!mScaledPixmap.isNull()) - mScaledPixmap = QPixmap(); - mScaledPixmapInvalidated = false; -} - -/*! \internal - - Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions - and scaling settings. - - The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn - flipped horizontally or vertically in the returned rect. (The returned rect itself is always - normalized, i.e. the top left corner of the rect is actually further to the top/left than the - bottom right corner). This is the case when the item position \a topLeft is further to the - bottom/right than \a bottomRight. - - If scaling is disabled, returns a rect with size of the original pixmap and the top left corner - aligned with the item position \a topLeft. The position \a bottomRight is ignored. -*/ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const -{ - QRect result; - bool flipHorz = false; - bool flipVert = false; - QPoint p1 = topLeft->pixelPosition().toPoint(); - QPoint p2 = bottomRight->pixelPosition().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) - { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); - QPoint topLeft = p1; - if (newSize.width() < 0) - { - flipHorz = true; - newSize.rwidth() *= -1; - topLeft.setX(p2.x()); - } - if (newSize.height() < 0) - { - flipVert = true; - newSize.rheight() *= -1; - topLeft.setY(p2.y()); - } - QSize scaledSize = mPixmap.size(); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - scaledSize /= mPixmap.devicePixelRatio(); - scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); -#else - scaledSize.scale(newSize, mAspectRatioMode); -#endif - result = QRect(topLeft, scaledSize); - } else - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); -#else - result = QRect(p1, mPixmap.size()); -#endif - } - if (flippedHorz) - *flippedHorz = flipHorz; - if (flippedVert) - *flippedVert = flipVert; - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemPixmap::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-pixmap.cpp' */ - - -/* including file 'src/items/item-tracer.cpp', size 14624 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemTracer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemTracer - \brief Item that sticks to QCPGraph data points - - \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." - - The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt - the coordinate axes of the graph and update its \a position to be on the graph's data. This means - the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a - QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a - position will have no effect because they will be overriden in the next redraw (this is when the - coordinate update happens). - - If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will - stay at the corresponding end of the graph. - - With \ref setInterpolating you may specify whether the tracer may only stay exactly on data - points or whether it interpolates data points linearly, if given a key that lies between two data - points of the graph. - - The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer - have no own visual appearance (set the style to \ref tsNone), and just connect other item - positions to the tracer \a position (used as an anchor) via \ref - QCPItemPosition::setParentAnchor. - - \note The tracer position is only automatically updated upon redraws. So when the data of the - graph changes and immediately afterwards (without a redraw) the position coordinates of the - tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref - updatePosition must be called manually, prior to reading the tracer coordinates. -*/ - -/*! - Creates a tracer item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - mSize(6), - mStyle(tsCrosshair), - mGraph(0), - mGraphKey(0), - mInterpolating(false) -{ - position->setCoords(0, 0); - - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemTracer::~QCPItemTracer() -{ -} - -/*! - Sets the pen that will be used to draw the line of the tracer - - \see setSelectedPen, setBrush -*/ -void QCPItemTracer::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the tracer when selected - - \see setPen, setSelected -*/ -void QCPItemTracer::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer - - \see setSelectedBrush, setPen -*/ -void QCPItemTracer::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer, when selected. - - \see setBrush, setSelected -*/ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare - does, \ref tsCrosshair does not). -*/ -void QCPItemTracer::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the style/visual appearance of the tracer. - - If you only want to use the tracer \a position as an anchor for other items, set \a style to - \ref tsNone. -*/ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) -{ - mStyle = style; -} - -/*! - Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type - QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. - - To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed - freely like any other item position. This is the state the tracer will assume when its graph gets - deleted while still attached to it. - - \see setGraphKey -*/ -void QCPItemTracer::setGraph(QCPGraph *graph) -{ - if (graph) - { - if (graph->parentPlot() == mParentPlot) - { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); - mGraph = graph; - updatePosition(); - } else - qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else - { - mGraph = 0; - } -} - -/*! - Sets the key of the graph's data point the tracer will be positioned at. This is the only free - coordinate of a tracer when attached to a graph. - - Depending on \ref setInterpolating, the tracer will be either positioned on the data point - closest to \a key, or will stay exactly at \a key and interpolate the value linearly. - - \see setGraph, setInterpolating -*/ -void QCPItemTracer::setGraphKey(double key) -{ - mGraphKey = key; -} - -/*! - Sets whether the value of the graph's data points shall be interpolated, when positioning the - tracer. - - If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on - the data point of the graph which is closest to the key, but which is not necessarily exactly - there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and - the appropriate value will be interpolated from the graph's data points linearly. - - \see setGraph, setGraphKey -*/ -void QCPItemTracer::setInterpolating(bool enabled) -{ - mInterpolating = enabled; -} - -/* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return -1; - case tsPlus: - { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), - QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), - QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - // distance to border: - double centerDist = QCPVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; - } - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); - } - break; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) -{ - updatePosition(); - if (mStyle == tsNone) - return; - - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return; - case tsPlus: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; - } - } -} - -/*! - If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a - position to reside on the graph data, depending on the configured key (\ref setGraphKey). - - It is called automatically on every redraw and normally doesn't need to be called manually. One - exception is when you want to read the tracer coordinates via \a position and are not sure that - the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. - In that situation, call this function before accessing \a position, to make sure you don't get - out-of-date coordinates. - - If there is no graph set on this tracer, this function does nothing. -*/ -void QCPItemTracer::updatePosition() -{ - if (mGraph) - { - if (mParentPlot->hasPlottable(mGraph)) - { - if (mGraph->data()->size() > 1) - { - QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); - QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey <= first->key) - position->setCoords(first->key, first->value); - else if (mGraphKey >= last->key) - position->setCoords(last->key, last->value); - else - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); - if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators - { - QCPGraphDataContainer::const_iterator prevIt = it; - ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before - if (mInterpolating) - { - // interpolate between iterators around mGraphKey: - double slope = 0; - if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) - slope = (it->value-prevIt->value)/(it->key-prevIt->key); - position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); - } else - { - // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt->key+it->key)*0.5) - position->setCoords(prevIt->key, prevIt->value); - else - position->setCoords(it->key, it->value); - } - } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) - position->setCoords(it->key, it->value); - } - } else if (mGraph->data()->size() == 1) - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it->key, it->value); - } else - qDebug() << Q_FUNC_INFO << "graph has no data"; - } else - qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemTracer::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemTracer::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-tracer.cpp' */ - - -/* including file 'src/items/item-bracket.cpp', size 10687 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemBracket - \brief A bracket for referencing/highlighting certain parts in the plot. - - \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a left and \a right, which define the span of the bracket. If \a left is - actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the - example image. - - The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket - stretches away from the embraced span, can be controlled with \ref setLength. - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
- - It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine - or QCPItemCurve) or a text label (QCPItemText), to the bracket. -*/ - -/*! - Creates a bracket item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition(QLatin1String("left"))), - right(createPosition(QLatin1String("right"))), - center(createAnchor(QLatin1String("center"), aiCenter)), - mLength(8), - mStyle(bsCalligraphic) -{ - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemBracket::~QCPItemBracket() -{ -} - -/*! - Sets the pen that will be used to draw the bracket. - - Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the - stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use - \ref setLength, which has a similar effect. - - \see setSelectedPen -*/ -void QCPItemBracket::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the bracket when selected - - \see setPen, setSelected -*/ -void QCPItemBracket::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the \a length in pixels how far the bracket extends in the direction towards the embraced - span of the bracket (i.e. perpendicular to the left-right-direction) - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
-*/ -void QCPItemBracket::setLength(double length) -{ - mLength = length; -} - -/*! - Sets the style of the bracket, i.e. the shape/visual appearance. - - \see setPen -*/ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) -{ - mStyle = style; -} - -/* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QCPVector2D p(pos); - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return -1; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (mStyle) - { - case QCPItemBracket::bsSquare: - case QCPItemBracket::bsRound: - { - double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); - double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); - return qSqrt(qMin(qMin(a, b), c)); - } - case QCPItemBracket::bsCurly: - case QCPItemBracket::bsCalligraphic: - { - double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); - double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); - return qSqrt(qMin(qMin(a, b), qMin(c, d))); - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - QPolygon boundingPoly; - boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) - { - painter->setPen(mainPen()); - switch (mStyle) - { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); - path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return leftVec.toPointF(); - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (anchorId) - { - case aiCenter: - return centerVec.toPointF(); - } - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemBracket::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-bracket.cpp' */ - - From eabf273d74113c010f44d84b01d5a9b02ad66ab4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:44:27 -0400 Subject: [PATCH 0357/1324] Add files via upload --- src/qt/qcustomplot.cpp | 30121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 30121 insertions(+) create mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp new file mode 100644 index 00000000..e59374ab --- /dev/null +++ b/src/qt/qcustomplot.cpp @@ -0,0 +1,30121 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#include "qcustomplot.h" + + +/* including file 'src/vector2d.cpp', size 7340 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPVector2D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPVector2D + \brief Represents two doubles as a mathematical 2D vector + + This class acts as a replacement for QVector2D with the advantage of double precision instead of + single, and some convenience methods tailored for the QCustomPlot library. +*/ + +/* start documentation of inline functions */ + +/*! \fn void QCPVector2D::setX(double x) + + Sets the x coordinate of this vector to \a x. + + \see setY +*/ + +/*! \fn void QCPVector2D::setY(double y) + + Sets the y coordinate of this vector to \a y. + + \see setX +*/ + +/*! \fn double QCPVector2D::length() const + + Returns the length of this vector. + + \see lengthSquared +*/ + +/*! \fn double QCPVector2D::lengthSquared() const + + Returns the squared length of this vector. In some situations, e.g. when just trying to find the + shortest vector of a group, this is faster than calculating \ref length, because it avoids + calculation of a square root. + + \see length +*/ + +/*! \fn QPoint QCPVector2D::toPoint() const + + Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point + information. + + \see toPointF +*/ + +/*! \fn QPointF QCPVector2D::toPointF() const + + Returns a QPointF which has the x and y coordinates of this vector. + + \see toPoint +*/ + +/*! \fn bool QCPVector2D::isNull() const + + Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y + coordinates, i.e. if both are binary equal to 0. +*/ + +/*! \fn QCPVector2D QCPVector2D::perpendicular() const + + Returns a vector perpendicular to this vector, with the same length. +*/ + +/*! \fn double QCPVector2D::dot() const + + Returns the dot/scalar product of this vector with the specified vector \a vec. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates to 0. +*/ +QCPVector2D::QCPVector2D() : + mX(0), + mY(0) +{ +} + +/*! + Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified + values. +*/ +QCPVector2D::QCPVector2D(double x, double y) : + mX(x), + mY(y) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPoint &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPointF &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Normalizes this vector. After this operation, the length of the vector is equal to 1. + + \see normalized, length, lengthSquared +*/ +void QCPVector2D::normalize() +{ + double len = length(); + mX /= len; + mY /= len; +} + +/*! + Returns a normalized version of this vector. The length of the returned vector is equal to 1. + + \see normalize, length, lengthSquared +*/ +QCPVector2D QCPVector2D::normalized() const +{ + QCPVector2D result(mX, mY); + result.normalize(); + return result; +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a start and \a end. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const +{ + QCPVector2D v(end-start); + double vLengthSqr = v.lengthSquared(); + if (!qFuzzyIsNull(vLengthSqr)) + { + double mu = v.dot(*this-start)/vLengthSqr; + if (mu < 0) + return (*this-start).lengthSquared(); + else if (mu > 1) + return (*this-end).lengthSquared(); + else + return ((start + mu*v)-*this).lengthSquared(); + } else + return (*this-start).lengthSquared(); +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a line. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QLineF &line) const +{ + return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); +} + +/*! + Returns the shortest distance of this vector (interpreted as a point) to the infinite straight + line given by a \a base point and a \a direction vector. + + \see distanceSquaredToLine +*/ +double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const +{ + return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); +} + +/*! + Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a + factor. +*/ +QCPVector2D &QCPVector2D::operator*=(double factor) +{ + mX *= factor; + mY *= factor; + return *this; +} + +/*! + Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a + divisor. +*/ +QCPVector2D &QCPVector2D::operator/=(double divisor) +{ + mX /= divisor; + mY /= divisor; + return *this; +} + +/*! + Adds the given \a vector to this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) +{ + mX += vector.mX; + mY += vector.mY; + return *this; +} + +/*! + subtracts the given \a vector from this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) +{ + mX -= vector.mX; + mY -= vector.mY; + return *this; +} +/* end of 'src/vector2d.cpp' */ + + +/* including file 'src/painter.cpp', size 8670 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPainter +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPainter + \brief QPainter subclass used internally + + This QPainter subclass is used to provide some extended functionality e.g. for tweaking position + consistency between antialiased and non-antialiased painting. Further it provides workarounds + for QPainter quirks. + + \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and + restore. So while it is possible to pass a QCPPainter instance to a function that expects a + QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because + it will call the base class implementations of the functions actually hidden by QCPPainter). +*/ + +/*! + Creates a new QCPPainter instance and sets default values +*/ +QCPPainter::QCPPainter() : + QPainter(), + mModes(pmDefault), + mIsAntialiasing(false) +{ + // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and + // a call to begin() will follow +} + +/*! + Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just + like the analogous QPainter constructor, begins painting on \a device immediately. + + Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. +*/ +QCPPainter::QCPPainter(QPaintDevice *device) : + QPainter(device), + mModes(pmDefault), + mIsAntialiasing(false) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (isActive()) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif +} + +/*! + Sets the pen of the painter and applies certain fixes to it, depending on the mode of this + QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QPen &pen) +{ + QPainter::setPen(pen); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QColor &color) +{ + QPainter::setPen(color); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(Qt::PenStyle penStyle) +{ + QPainter::setPen(penStyle); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when + antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to + integer coordinates and then passes it to the original drawLine. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::drawLine(const QLineF &line) +{ + if (mIsAntialiasing || mModes.testFlag(pmVectorized)) + QPainter::drawLine(line); + else + QPainter::drawLine(line.toLine()); +} + +/*! + Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint + with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between + antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for + AA/Non-AA painting). +*/ +void QCPPainter::setAntialiasing(bool enabled) +{ + setRenderHint(QPainter::Antialiasing, enabled); + if (mIsAntialiasing != enabled) + { + mIsAntialiasing = enabled; + if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs + { + if (mIsAntialiasing) + translate(0.5, 0.5); + else + translate(-0.5, -0.5); + } + } +} + +/*! + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setModes(QCPPainter::PainterModes modes) +{ + mModes = modes; +} + +/*! + Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a + device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, + all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that + behaviour. + + The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets + the render hint as appropriate. + + \note this function hides the non-virtual base class implementation. +*/ +bool QCPPainter::begin(QPaintDevice *device) +{ + bool result = QPainter::begin(device); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (result) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif + return result; +} + +/*! \overload + + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) +{ + if (!enabled && mModes.testFlag(mode)) + mModes &= ~mode; + else if (enabled && !mModes.testFlag(mode)) + mModes |= mode; +} + +/*! + Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see restore +*/ +void QCPPainter::save() +{ + mAntialiasingStack.push(mIsAntialiasing); + QPainter::save(); +} + +/*! + Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see save +*/ +void QCPPainter::restore() +{ + if (!mAntialiasingStack.isEmpty()) + mIsAntialiasing = mAntialiasingStack.pop(); + else + qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; + QPainter::restore(); +} + +/*! + Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen + overrides when the \ref pmNonCosmetic mode is set. +*/ +void QCPPainter::makeNonCosmetic() +{ + if (qFuzzyIsNull(pen().widthF())) + { + QPen p = pen(); + p.setWidth(1); + QPainter::setPen(p); + } +} +/* end of 'src/painter.cpp' */ + + +/* including file 'src/paintbuffer.cpp', size 18502 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPaintBuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPaintBuffer + \brief The abstract base class for paint buffers, which define the rendering backend + + This abstract base class defines the basic interface that a paint buffer needs to provide in + order to be usable by QCustomPlot. + + A paint buffer manages both a surface to draw onto, and the matching paint device. The size of + the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref + QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the + painting is complete, \ref donePainting is called, so the paint buffer implementation can do + clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color + using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the + previous frame. + + The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular + software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and + frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. + They are used automatically if \ref QCustomPlot::setOpenGl is enabled. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 + + Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the + responsibility to delete the painter after the painting operations are complete is given to the + caller of this method. + + Once you are done using the painter, delete the painter and call \ref donePainting. + + While a painter generated with this method is active, you must not call \ref setSize, \ref + setDevicePixelRatio or \ref clear. + + This method may return 0, if a painter couldn't be activated on the buffer. This usually + indicates a problem with the respective painting backend. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 + + Draws the contents of this buffer with the provided \a painter. This is the method that is used + to finally join all paint buffers and draw them onto the screen. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 + + Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the + named color \c Qt::transparent. + + This method must not be called if there is currently a painter (acquired with \ref startPainting) + active. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 + + Reallocates the internal buffer with the currently configured size (\ref setSize) and device + pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those + properties are changed on this paint buffer. + + \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method + in their constructor, to perform the first allocation (this can not be done by the base class + because calling pure virtual methods in base class constructors is not possible). +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of inline functions */ + +/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() + + If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, + call this method as soon as you are done with the painting operations and have deleted the + painter. + + paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The + default implementation does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. + + Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. +*/ +QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : + mSize(size), + mDevicePixelRatio(devicePixelRatio), + mInvalidated(true) +{ +} + +QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() +{ +} + +/*! + Sets the paint buffer size. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + If \a size is already the current buffer size, this method does nothing. +*/ +void QCPAbstractPaintBuffer::setSize(const QSize &size) +{ + if (mSize != size) + { + mSize = size; + reallocateBuffer(); + } +} + +/*! + Sets the invalidated flag to \a invalidated. + + This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer + instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered + layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, + QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also + replots them, instead of only the layer on which the replot was called. + + The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers + were added or removed from this buffer, or if they were reordered. It is set to false as soon as + all associated \ref QCPLayer instances are drawn onto the buffer. + + Under normal circumstances, it is not necessary to manually call this method. +*/ +void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) +{ + mInvalidated = invalidated; +} + +/*! + Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. + The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + \note This method is only available for Qt versions 5.4 and higher. +*/ +void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mDevicePixelRatio = ratio; + reallocateBuffer(); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; +#endif + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferPixmap + \brief A paint buffer based on QPixmap, using software raster rendering + + This paint buffer is the default and fall-back paint buffer which uses software rendering and + QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. +*/ + +/*! + Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if + applicable. +*/ +QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : + QCPAbstractPaintBuffer(size, devicePixelRatio) +{ + QCPPaintBufferPixmap::reallocateBuffer(); +} + +QCPPaintBufferPixmap::~QCPPaintBufferPixmap() +{ +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferPixmap::startPainting() +{ + QCPPainter *result = new QCPPainter(&mBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::draw(QCPPainter *painter) const +{ + if (painter && painter->isActive()) + painter->drawPixmap(0, 0, mBuffer); + else + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::clear(const QColor &color) +{ + mBuffer.fill(color); +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::reallocateBuffer() +{ + setInvalidated(); + if (!qFuzzyCompare(1.0, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBuffer = QPixmap(mSize*mDevicePixelRatio); + mBuffer.setDevicePixelRatio(mDevicePixelRatio); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; + mBuffer = QPixmap(mSize); +#endif + } else + { + mBuffer = QPixmap(mSize); + } +} + + +#ifdef QCP_OPENGL_PBUFFER +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlPbuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlPbuffer + \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. + (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a + devicePixelRatio, if applicable. + + The parameter \a multisamples defines how many samples are used per pixel. Higher values thus + result in higher quality antialiasing. If the specified \a multisamples value exceeds the + capability of the graphics hardware, the highest supported multisampling is used. +*/ +QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlPBuffer(0), + mMultisamples(qMax(0, multisamples)) +{ + QCPPaintBufferGlPbuffer::reallocateBuffer(); +} + +QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlPbuffer::startPainting() +{ + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + QCPPainter *result = new QCPPainter(mGlPBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlPBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::clear(const QColor &color) +{ + if (mGlPBuffer->isValid()) + { + mGlPBuffer->makeCurrent(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlPBuffer->doneCurrent(); + } else + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::reallocateBuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; + + QGLFormat format; + format.setAlpha(true); + format.setSamples(mMultisamples); + mGlPBuffer = new QGLPixelBuffer(mSize, format); +} +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlFbo +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlFbo + \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and + higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, + if applicable. + + All frame buffer objects shall share one OpenGL context and paint device, which need to be set up + externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref + QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot + instance. +*/ +QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlContext(glContext), + mGlPaintDevice(glPaintDevice), + mGlFrameBuffer(0) +{ + QCPPaintBufferGlFbo::reallocateBuffer(); +} + +QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() +{ + if (mGlFrameBuffer) + delete mGlFrameBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlFbo::startPainting() +{ + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return 0; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::donePainting() +{ + if (mGlFrameBuffer && mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + else + qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlFrameBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::clear(const QColor &color) +{ + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlFrameBuffer->release(); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::reallocateBuffer() +{ + // release and delete possibly existing framebuffer: + if (mGlFrameBuffer) + { + if (mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + delete mGlFrameBuffer; + mGlFrameBuffer = 0; + } + + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return; + } + + // create new fbo with appropriate size: + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + QOpenGLFramebufferObjectFormat frameBufferFormat; + frameBufferFormat.setSamples(mGlContext.data()->format().samples()); + frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); + if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) + mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); +#endif +} +#endif // QCP_OPENGL_FBO +/* end of 'src/paintbuffer.cpp' */ + + +/* including file 'src/layer.cpp', size 37064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayer + \brief A layer that may contain objects, to control the rendering order + + The Layering system of QCustomPlot is the mechanism to control the rendering order of the + elements inside the plot. + + It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of + one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, + QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers + bottom to top and successively draws the layerables of the layers into the paint buffer(s). + + A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base + class from which almost all visible objects derive, like axes, grids, graphs, items, etc. + + \section qcplayer-defaultlayers Default layers + + Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and + "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's + selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain + the default axes and legend, so they will be drawn above plottables. In the middle, there is the + "main" layer. It is initially empty and set as the current layer (see + QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this + layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong + tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind + everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of + course, the layer affiliation of the individual objects can be changed as required (\ref + QCPLayerable::setLayer). + + \section qcplayer-ordering Controlling the rendering order via layers + + Controlling the ordering of layerables in the plot is easy: Create a new layer in the position + you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the + current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the + objects normally. They will be placed on the new layer automatically, due to the current layer + setting. Alternatively you could have also ignored the current layer setting and just moved the + objects with \ref QCPLayerable::setLayer to the desired layer after creating them. + + It is also possible to move whole layers. For example, If you want the grid to be shown in front + of all plottables/items on the "main" layer, just move it above "main" with + QCustomPlot::moveLayer. + + The rendering order within one layer is simply by order of creation or insertion. The item + created last (or added last to the layer), is drawn on top of all other objects on that layer. + + When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below + the deleted layer, see QCustomPlot::removeLayer. + + \section qcplayer-buffering Replotting only a specific layer + + If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific + layer by calling \ref replot. In certain situations this can provide better replot performance, + compared with a full replot of all layers. Upon creation of a new layer, the layer mode is + initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref + QCustomPlot instance is the "overlay" layer, containing the selection rect. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPLayer::children() const + + Returns a list of all layerables on this layer. The order corresponds to the rendering order: + layerables with higher indices are drawn above layerables with lower indices. +*/ + +/*! \fn int QCPLayer::index() const + + Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be + accessed via \ref QCustomPlot::layer. + + Layers with higher indices will be drawn above layers with lower indices. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPLayer instance. + + Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. + + \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. + This check is only performed by \ref QCustomPlot::addLayer. +*/ +QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : + QObject(parentPlot), + mParentPlot(parentPlot), + mName(layerName), + mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function + mVisible(true), + mMode(lmLogical) +{ + // Note: no need to make sure layerName is unique, because layer + // management is done with QCustomPlot functions. +} + +QCPLayer::~QCPLayer() +{ + // If child layerables are still on this layer, detach them, so they don't try to reach back to this + // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted + // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to + // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) + + while (!mChildren.isEmpty()) + mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() + + if (mParentPlot->currentLayer() == this) + qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; +} + +/*! + Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this + layer will be invisible. + + This function doesn't change the visibility property of the layerables (\ref + QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the + visibility of the parent layer into account. +*/ +void QCPLayer::setVisible(bool visible) +{ + mVisible = visible; +} + +/*! + Sets the rendering mode of this layer. + + If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by + the parent QCustomPlot instance. This means it may be replotted individually by calling \ref + QCPLayer::replot, without needing to replot all other layers. + + Layers which are set to \ref lmLogical (the default) are used only to define the rendering order + and can't be replotted individually. + + Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the + layers below, above and for the layer itself. This increases the memory consumption and + (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So + you should carefully choose which layers benefit from having their own paint buffer. A typical + example would be a layer which contains certain layerables (e.g. items) that need to be changed + and thus replotted regularly, while all other layerables on other layers stay static. By default, + only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection + rect. + + \see replot +*/ +void QCPLayer::setMode(QCPLayer::LayerMode mode) +{ + if (mMode != mode) + { + mMode = mode; + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } +} + +/*! \internal + + Draws the contents of this layer with the provided \a painter. + + \see replot, drawToPaintBuffer +*/ +void QCPLayer::draw(QCPPainter *painter) +{ + Q_FOREACH (QCPLayerable *child, mChildren) + { + if (child->realVisibility()) + { + painter->save(); + painter->setClipRect(child->clipRect().translated(0, -1)); + child->applyDefaultAntialiasingHint(painter); + child->draw(painter); + painter->restore(); + } + } +} + +/*! \internal + + Draws the contents of this layer into the paint buffer which is associated with this layer. The + association is established by the parent QCustomPlot, which manages all paint buffers (see \ref + QCustomPlot::setupPaintBuffers). + + \see draw +*/ +void QCPLayer::drawToPaintBuffer() +{ + if (!mPaintBuffer.isNull()) + { + if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) + { + if (painter->isActive()) + draw(painter); + else + qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; + delete painter; + mPaintBuffer.data()->donePainting(); + } else + qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; +} + +/*! + If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only + the layerables on this specific layer, without the need to replot all other layers (as a call to + \ref QCustomPlot::replot would do). + + If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on + the parent QCustomPlot instance. + + QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering + has changed since the last full replot and the other paint buffers were thus invalidated. + + \see draw +*/ +void QCPLayer::replot() +{ + if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) + { + if (!mPaintBuffer.isNull()) + { + mPaintBuffer.data()->clear(Qt::transparent); + drawToPaintBuffer(); + mPaintBuffer.data()->setInvalidated(false); + mParentPlot->update(); + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; + } else if (mMode == lmLogical) + mParentPlot->replot(); +} + +/*! \internal + + Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will + be prepended to the list, i.e. be drawn beneath the other layerables already in the list. + + This function does not change the \a mLayer member of \a layerable to this layer. (Use + QCPLayerable::setLayer to change the layer of an object, not this function.) + + \see removeChild +*/ +void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) +{ + if (!mChildren.contains(layerable)) + { + if (prepend) + mChildren.prepend(layerable); + else + mChildren.append(layerable); + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); +} + +/*! \internal + + Removes the \a layerable from the list of this layer. + + This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer + to change the layer of an object, not this function.) + + \see addChild +*/ +void QCPLayer::removeChild(QCPLayerable *layerable) +{ + if (mChildren.removeOne(layerable)) + { + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayerable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayerable + \brief Base class for all drawable objects + + This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid + etc. + + Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking + the layers accordingly. + + For details about the layering mechanism, see the QCPLayer documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const + + Returns the parent layerable of this layerable. The parent layerable is used to provide + visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables + only get drawn if their parent layerables are visible, too. + + Note that a parent layerable is not necessarily also the QObject parent for memory management. + Further, a layerable doesn't always have a parent layerable, so this function may return 0. + + A parent layerable is set implicitly when placed inside layout elements and doesn't need to be + set manually by the user. +*/ + +/* end documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 + \internal + + This function applies the default antialiasing setting to the specified \a painter, using the + function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when + \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing + setting may be specified individually, this function should set the antialiasing state of the + most prominent entity. In this case however, the \ref draw function usually calls the specialized + versions of this function before drawing each entity, effectively overriding the setting of the + default antialiasing hint. + + First example: QCPGraph has multiple entities that have an antialiasing setting: The graph + line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, + QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only + the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's + antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and + QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw + calls the respective specialized applyAntialiasingHint function. + + Second example: QCPItemLine consists only of a line so there is only one antialiasing + setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by + all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the + respective layerable subclass.) Consequently it only has the normal + QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to + care about setting any antialiasing states, because the default antialiasing hint is already set + on the painter when the \ref draw function is called, and that's the state it wants to draw the + line with. +*/ + +/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 + \internal + + This function draws the layerable with the specified \a painter. It is only called by + QCustomPlot, if the layerable is visible (\ref setVisible). + + Before this function is called, the painter's antialiasing state is set via \ref + applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was + set to \ref clipRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); + + This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to + a different layer. + + \see setLayer +*/ + +/* end documentation of signals */ + +/*! + Creates a new QCPLayerable instance. + + Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the + derived classes. + + If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a + targetLayer is an empty string, it places itself on the current layer of the plot (see \ref + QCustomPlot::setCurrentLayer). + + It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later + time with \ref initializeParentPlot. + + The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable + parents are mainly used to control visibility in a hierarchy of layerables. This means a + layerable is only drawn, if all its ancestor layerables are also visible. Note that \a + parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a + plot does. It is not uncommon to set the QObject-parent to something else in the constructors of + QCPLayerable subclasses, to guarantee a working destruction hierarchy. +*/ +QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : + QObject(plot), + mVisible(true), + mParentPlot(plot), + mParentLayerable(parentLayerable), + mLayer(0), + mAntialiased(true) +{ + if (mParentPlot) + { + if (targetLayer.isEmpty()) + setLayer(mParentPlot->currentLayer()); + else if (!setLayer(targetLayer)) + qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; + } +} + +QCPLayerable::~QCPLayerable() +{ + if (mLayer) + { + mLayer->removeChild(this); + mLayer = 0; + } +} + +/*! + Sets the visibility of this layerable object. If an object is not visible, it will not be drawn + on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not + possible. +*/ +void QCPLayerable::setVisible(bool on) +{ + mVisible = on; +} + +/*! + Sets the \a layer of this layerable object. The object will be placed on top of the other objects + already on \a layer. + + If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or + interact/receive events). + + Returns true if the layer of this layerable was successfully changed to \a layer. +*/ +bool QCPLayerable::setLayer(QCPLayer *layer) +{ + return moveToLayer(layer, false); +} + +/*! \overload + Sets the layer of this layerable object by name + + Returns true on success, i.e. if \a layerName is a valid layer name. +*/ +bool QCPLayerable::setLayer(const QString &layerName) +{ + if (!mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (QCPLayer *layer = mParentPlot->layer(layerName)) + { + return setLayer(layer); + } else + { + qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; + return false; + } +} + +/*! + Sets whether this object will be drawn antialiased or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPLayerable::setAntialiased(bool enabled) +{ + mAntialiased = enabled; +} + +/*! + Returns whether this layerable is visible, taking the visibility of the layerable parent and the + visibility of this layerable's layer into account. This is the method that is consulted to decide + whether a layerable shall be drawn or not. + + If this layerable has a direct layerable parent (usually set via hierarchies implemented in + subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this + layerable has its visibility set to true and the parent layerable's \ref realVisibility returns + true. +*/ +bool QCPLayerable::realVisibility() const +{ + return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); +} + +/*! + This function is used to decide whether a click hits a layerable object or not. + + \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the + shortest pixel distance of this point to the object. If the object is either invisible or the + distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the + object is not selectable, -1.0 is returned, too. + + If the object is represented not by single lines but by an area like a \ref QCPItemText or the + bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In + these cases this function thus returns a constant value greater zero but still below the parent + plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). + + Providing a constant value for area objects allows selecting line objects even when they are + obscured by such area objects, by clicking close to the lines (i.e. closer than + 0.99*selectionTolerance). + + The actual setting of the selection state is not done by this function. This is handled by the + parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified + via the \ref selectEvent/\ref deselectEvent methods. + + \a details is an optional output parameter. Every layerable subclass may place any information + in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot + decides on the basis of this selectTest call, that the object was successfully selected. The + subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part + objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked + is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be + placed in \a details. So in the subsequent \ref selectEvent, the decision which part was + selected doesn't have to be done a second time for a single selection operation. + + You may pass 0 as \a details to indicate that you are not interested in those selection details. + + \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions +*/ +double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(pos) + Q_UNUSED(onlySelectable) + Q_UNUSED(details) + return -1.0; +} + +/*! \internal + + Sets the parent plot of this layerable. Use this function once to set the parent plot if you have + passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to + another one. + + Note that, unlike when passing a non-null parent plot in the constructor, this function does not + make \a parentPlot the QObject-parent of this layerable. If you want this, call + QObject::setParent(\a parentPlot) in addition to this function. + + Further, you will probably want to set a layer (\ref setLayer) after calling this function, to + make the layerable appear on the QCustomPlot. + + The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized + so they can react accordingly (e.g. also initialize the parent plot of child layerables, like + QCPLayout does). +*/ +void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) +{ + if (mParentPlot) + { + qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; + return; + } + + if (!parentPlot) + qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; + + mParentPlot = parentPlot; + parentPlotInitialized(mParentPlot); +} + +/*! \internal + + Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not + become the QObject-parent (for memory management) of this layerable. + + The parent layerable has influence on the return value of the \ref realVisibility method. Only + layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be + drawn. + + \see realVisibility +*/ +void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) +{ + mParentLayerable = parentLayerable; +} + +/*! \internal + + Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to + the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is + false, the object will be appended. + + Returns true on success, i.e. if \a layer is a valid layer. +*/ +bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) +{ + if (layer && !mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (layer && layer->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; + return false; + } + + QCPLayer *oldLayer = mLayer; + if (mLayer) + mLayer->removeChild(this); + mLayer = layer; + if (mLayer) + mLayer->addChild(this, prepend); + if (mLayer != oldLayer) + Q_EMIT layerChanged(mLayer); + return true; +} + +/*! \internal + + Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a + localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is + controlled via \a overrideElement. +*/ +void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const +{ + if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(false); + else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(true); + else + painter->setAntialiasing(localAntialiased); +} + +/*! \internal + + This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting + of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the + parent plot is set at a later time. + + For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any + QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level + element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To + propagate the parent plot to all the children of the hierarchy, the top level element then uses + this function to pass the parent plot on to its child elements. + + The default implementation does nothing. + + \see initializeParentPlot +*/ +void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_UNUSED(parentPlot) +} + +/*! \internal + + Returns the selection category this layerable shall belong to. The selection category is used in + conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and + which aren't. + + Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref + QCP::iSelectOther. This is what the default implementation returns. + + \see QCustomPlot::setInteractions +*/ +QCP::Interaction QCPLayerable::selectionCategory() const +{ + return QCP::iSelectOther; +} + +/*! \internal + + Returns the clipping rectangle of this layerable object. By default, this is the viewport of the + parent QCustomPlot. Specific subclasses may reimplement this function to provide different + clipping rects. + + The returned clipping rect is set on the painter before the draw function of the respective + object is called. +*/ +QRect QCPLayerable::clipRect() const +{ + if (mParentPlot) + return mParentPlot->viewport(); + else + return QRect(); +} + +/*! \internal + + This event is called when the layerable shall be selected, as a consequence of a click by the + user. Subclasses should react to it by setting their selection state appropriately. The default + implementation does nothing. + + \a event is the mouse event that caused the selection. \a additive indicates, whether the user + was holding the multi-select-modifier while performing the selection (see \ref + QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled + (i.e. become selected when unselected and unselected when selected). + + Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. + returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). + The \a details data you output from \ref selectTest is fed back via \a details here. You may + use it to transport any kind of information from the selectTest to the possibly subsequent + selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable + that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need + to do the calculation again to find out which part was actually clicked. + + \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must + set the value either to true or false, depending on whether the selection state of this layerable + was actually changed. For layerables that only are selectable as a whole and not in parts, this + is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the + selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the + layerable was previously unselected and now is switched to the selected state. + + \see selectTest, deselectEvent +*/ +void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(additive) + Q_UNUSED(details) + Q_UNUSED(selectionStateChanged) +} + +/*! \internal + + This event is called when the layerable shall be deselected, either as consequence of a user + interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by + unsetting their selection appropriately. + + just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must + return true or false when the selection state of this layerable has changed or not changed, + respectively. + + \see selectTest, selectEvent +*/ +void QCPLayerable::deselectEvent(bool *selectionStateChanged) +{ + Q_UNUSED(selectionStateChanged) +} + +/*! + This event gets called when the user presses a mouse button while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + QCustomPlot uses an event propagation system that works the same as Qt's system. If your + layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in + its reimplementation, the event will be propagated to the next layerable in the stacking order. + + Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and + will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse + interaction (a "mouse interaction" in this context ends with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user moves the mouse while holding a mouse button, after this + layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user releases the mouse button, after this layerable has become + the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user presses the mouse button a second time in a double-click, + while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a + preceding call to \ref selectTest. + + The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the + case of a double-click, the event succession is + pressEvent – releaseEvent – doubleClickEvent – releaseEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, + it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent + and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends + with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent +*/ +void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user turns the mouse scroll wheel while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). + + The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for + single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may + accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has + very smooth steps or none at all, the delta may be smaller. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent +*/ +void QCPLayerable::wheelEvent(QWheelEvent *event) +{ + event->ignore(); +} +/* end of 'src/layer.cpp' */ + + +/* including file 'src/axis/range.cpp', size 12221 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPRange +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPRange + \brief Represents the range an axis is encompassing. + + contains a \a lower and \a upper double value and provides convenience input, output and + modification functions. + + \see QCPAxis::setRange +*/ + +/* start of documentation of inline functions */ + +/*! \fn double QCPRange::size() const + + Returns the size of the range, i.e. \a upper-\a lower +*/ + +/*! \fn double QCPRange::center() const + + Returns the center of the range, i.e. (\a upper+\a lower)*0.5 +*/ + +/*! \fn void QCPRange::normalize() + + Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are + swapped. +*/ + +/*! \fn bool QCPRange::contains(double value) const + + Returns true when \a value lies within or exactly on the borders of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator+=(const double& value) + + Adds \a value to both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator-=(const double& value) + + Subtracts \a value from both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator*=(const double& value) + + Multiplies both boundaries of the range by \a value. +*/ + +/*! \fn QCPRange &QCPRange::operator/=(const double& value) + + Divides both boundaries of the range by \a value. +*/ + +/* end of documentation of inline functions */ + +/*! + Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller + intervals would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a minimum magnitude of roughly 1e-308. + + \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining underflowing ranges. + + \see validRange, maxRange +*/ +const double QCPRange::minRange = 1e-280; + +/*! + Maximum values (negative and positive) the range will accept in range-changing functions. + Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a maximum magnitude of roughly 1e308. + + \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining overflowing ranges. + + \see validRange, minRange +*/ +const double QCPRange::maxRange = 1e250; + +/*! + Constructs a range with \a lower and \a upper set to zero. +*/ +QCPRange::QCPRange() : + lower(0), + upper(0) +{ +} + +/*! \overload + + Constructs a range with the specified \a lower and \a upper values. + + The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically + smaller than \a upper, they will be swapped. +*/ +QCPRange::QCPRange(double lower, double upper) : + lower(lower), + upper(upper) +{ + normalize(); +} + +/*! \overload + + Expands this range such that \a otherRange is contained in the new range. It is assumed that both + this range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, it will be replaced by the respective bound + of \a otherRange. + + If \a otherRange is already inside the current range, this function does nothing. + + \see expanded +*/ +void QCPRange::expand(const QCPRange &otherRange) +{ + if (lower > otherRange.lower || qIsNaN(lower)) + lower = otherRange.lower; + if (upper < otherRange.upper || qIsNaN(upper)) + upper = otherRange.upper; +} + +/*! \overload + + Expands this range such that \a includeCoord is contained in the new range. It is assumed that + this range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the respective bound will be set to \a + includeCoord. + + If \a includeCoord is already inside the current range, this function does nothing. + + \see expand +*/ +void QCPRange::expand(double includeCoord) +{ + if (lower > includeCoord || qIsNaN(lower)) + lower = includeCoord; + if (upper < includeCoord || qIsNaN(upper)) + upper = includeCoord; +} + + +/*! \overload + + Returns an expanded range that contains this and \a otherRange. It is assumed that both this + range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be taken from + \a otherRange. + + \see expand +*/ +QCPRange QCPRange::expanded(const QCPRange &otherRange) const +{ + QCPRange result = *this; + result.expand(otherRange); + return result; +} + +/*! \overload + + Returns an expanded range that includes the specified \a includeCoord. It is assumed that this + range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a + includeCoord. + + \see expand +*/ +QCPRange QCPRange::expanded(double includeCoord) const +{ + QCPRange result = *this; + result.expand(includeCoord); + return result; +} + +/*! + Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a + upperBound. If possible, the size of the current range is preserved in the process. + + If the range shall only be bounded at the lower side, you can set \a upperBound to \ref + QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref + QCPRange::maxRange. +*/ +QCPRange QCPRange::bounded(double lowerBound, double upperBound) const +{ + if (lowerBound > upperBound) + qSwap(lowerBound, upperBound); + + QCPRange result(lower, upper); + if (result.lower < lowerBound) + { + result.lower = lowerBound; + result.upper = lowerBound + size(); + if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.upper = upperBound; + } else if (result.upper > upperBound) + { + result.upper = upperBound; + result.lower = upperBound - size(); + if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.lower = lowerBound; + } + + return result; +} + +/*! + Returns a sanitized version of the range. Sanitized means for logarithmic scales, that + the range won't span the positive and negative sign domain, i.e. contain zero. Further + \a lower will always be numerically smaller (or equal) to \a upper. + + If the original range does span positive and negative sign domains or contains zero, + the returned range will try to approximate the original range as good as possible. + If the positive interval of the original range is wider than the negative interval, the + returned range will only contain the positive interval, with lower bound set to \a rangeFac or + \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval + is wider than the positive interval, this time by changing the \a upper bound. +*/ +QCPRange QCPRange::sanitizedForLogScale() const +{ + double rangeFac = 1e-3; + QCPRange sanitizedRange(lower, upper); + sanitizedRange.normalize(); + // can't have range spanning negative and positive values in log plot, so change range to fix it + //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) + if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) + { + // case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) + else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) + { + // case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) + { + // find out whether negative or positive interval is wider to decide which sign domain will be chosen + if (-sanitizedRange.lower > sanitizedRange.upper) + { + // negative is wider, do same as in case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else + { + // positive is wider, do same as in case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } + } + // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && + upper < maxRange && + qAbs(lower-upper) > minRange && + qAbs(lower-upper) < maxRange && + !(lower > 0 && qIsInf(upper/lower)) && + !(upper < 0 && qIsInf(lower/upper))); +} + +/*! + \overload + Checks, whether the specified range is within valid bounds, which are defined + as QCPRange::maxRange and QCPRange::minRange. + A valid range means: + \li range bounds within -maxRange and maxRange + \li range size above minRange + \li range size below maxRange +*/ +bool QCPRange::validRange(const QCPRange &range) +{ + return (range.lower > -maxRange && + range.upper < maxRange && + qAbs(range.lower-range.upper) > minRange && + qAbs(range.lower-range.upper) < maxRange && + !(range.lower > 0 && qIsInf(range.upper/range.lower)) && + !(range.upper < 0 && qIsInf(range.lower/range.upper))); +} +/* end of 'src/axis/range.cpp' */ + + +/* including file 'src/selection.cpp', size 21906 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataRange +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataRange + \brief Describes a data range given by begin and end index + + QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index + of a contiguous set of data points. The end index points to the data point above the last data point that's part of + the data range, similarly to the nomenclature used in standard iterators. + + Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and + modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is + used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref + QCPDataSelection is thus used. + + Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, + e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref + contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be + used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding + \ref QCPDataSelection. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and + QCPDataRange. + + \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval + in floating point plot coordinates, e.g. the current axis range. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataRange::size() const + + Returns the number of data points described by this data range. This is equal to the end index + minus the begin index. + + \see length +*/ + +/*! \fn int QCPDataRange::length() const + + Returns the number of data points described by this data range. Equivalent to \ref size. +*/ + +/*! \fn void QCPDataRange::setBegin(int begin) + + Sets the begin of this data range. The \a begin index points to the first data point that is part + of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setEnd +*/ + +/*! \fn void QCPDataRange::setEnd(int end) + + Sets the end of this data range. The \a end index points to the data point just above the last + data point that is part of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setBegin +*/ + +/*! \fn bool QCPDataRange::isValid() const + + Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and + an end index greater or equal to the begin index. + + \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods + (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's + methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary + invalid begin/end values while manipulating the range. An invalid range is not necessarily empty + (\ref isEmpty), since its \ref length can be negative and thus non-zero. +*/ + +/*! \fn bool QCPDataRange::isEmpty() const + + Returns whether this range is empty, i.e. whether its begin index equals its end index. + + \see size, length +*/ + +/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const + + Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end + indices, respectively. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataRange, with begin and end set to 0. +*/ +QCPDataRange::QCPDataRange() : + mBegin(0), + mEnd(0) +{ +} + +/*! + Creates a QCPDataRange, initialized with the specified \a begin and \a end. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). +*/ +QCPDataRange::QCPDataRange(int begin, int end) : + mBegin(begin), + mEnd(end) +{ +} + +/*! + Returns a data range that matches this data range, except that parts exceeding \a other are + excluded. + + This method is very similar to \ref intersection, with one distinction: If this range and the \a + other range share no intersection, the returned data range will be empty with begin and end set + to the respective boundary side of \a other, at which this range is residing. (\ref intersection + would just return a range with begin and end set to 0.) +*/ +QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const +{ + QCPDataRange result(intersection(other)); + if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value + { + if (mEnd <= other.mBegin) + result = QCPDataRange(other.mBegin, other.mBegin); + else + result = QCPDataRange(other.mEnd, other.mEnd); + } + return result; +} + +/*! + Returns a data range that contains both this data range as well as \a other. +*/ +QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const +{ + return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); +} + +/*! + Returns the data range which is contained in both this data range and \a other. + + This method is very similar to \ref bounded, with one distinction: If this range and the \a other + range share no intersection, the returned data range will be empty with begin and end set to 0. + (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, + depending on which side this range is on.) + + \see QCPDataSelection::intersection +*/ +QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const +{ + QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); + if (result.isValid()) + return result; + else + return QCPDataRange(); +} + +/*! + Returns whether this data range and \a other share common data points. + + \see intersection, contains +*/ +bool QCPDataRange::intersects(const QCPDataRange &other) const +{ + return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || + (mEnd <= other.mBegin && mEnd < other.mEnd) ); +} + +/*! + Returns whether all data points described by this data range are also in \a other. + + \see intersects +*/ +bool QCPDataRange::contains(const QCPDataRange &other) const +{ + return mBegin <= other.mBegin && mEnd >= other.mEnd; +} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataSelection +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataSelection + \brief Describes a data set by holding multiple QCPDataRange instances + + QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly + disjoint) set of data selection. + + The data selection can be modified with addition and subtraction operators which take + QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and + \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. + + The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange + instances. QCPDataSelection automatically simplifies when using the addition/subtraction + operators. The only case when \ref simplify is left to the user, is when calling \ref + addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data + ranges will be added to the selection successively and the overhead for simplifying after each + iteration shall be avoided. In this case, you should make sure to call \ref simplify after + completing the operation. + + Use \ref enforceType to bring the data selection into a state complying with the constraints for + selections defined in \ref QCP::SelectionType. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and + QCPDataRange. + + \section qcpdataselection-iterating Iterating over a data selection + + As an example, the following code snippet calculates the average value of a graph's data + \ref QCPAbstractPlottable::selection "selection": + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 + +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataSelection::dataRangeCount() const + + Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref + dataRange via their index. + + \see dataRange, dataPointCount +*/ + +/*! \fn QList QCPDataSelection::dataRanges() const + + Returns all data ranges that make up the data selection. If the data selection is simplified (the + usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point + index. + + \see dataRange +*/ + +/*! \fn bool QCPDataSelection::isEmpty() const + + Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection + instance. + + \see dataRangeCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataSelection. +*/ +QCPDataSelection::QCPDataSelection() +{ +} + +/*! + Creates a QCPDataSelection containing the provided \a range. +*/ +QCPDataSelection::QCPDataSelection(const QCPDataRange &range) +{ + mDataRanges.append(range); +} + +/*! + Returns true if this selection is identical (contains the same data ranges with the same begin + and end indices) to \a other. + + Note that both data selections must be in simplified state (the usual state of the selection, see + \ref simplify) for this operator to return correct results. +*/ +bool QCPDataSelection::operator==(const QCPDataSelection &other) const +{ + if (mDataRanges.size() != other.mDataRanges.size()) + return false; + for (int i=0; i= other.end()) + break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this + + if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored + { + if (thisBegin >= other.begin()) // range leading segment is encompassed + { + if (thisEnd <= other.end()) // range fully encompassed, remove completely + { + mDataRanges.removeAt(i); + continue; + } else // only leading segment is encompassed, trim accordingly + mDataRanges[i].setBegin(other.end()); + } else // leading segment is not encompassed + { + if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly + { + mDataRanges[i].setEnd(other.begin()); + } else // other lies inside this range, so split range + { + mDataRanges[i].setEnd(other.begin()); + mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); + break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here + } + } + } + ++i; + } + + return *this; +} + +/*! + Returns the total number of data points contained in all data ranges that make up this data + selection. +*/ +int QCPDataSelection::dataPointCount() const +{ + int result = 0; + for (int i=0; i= 0 && index < mDataRanges.size()) + { + return mDataRanges.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of range:" << index; + return QCPDataRange(); + } +} + +/*! + Returns a \ref QCPDataRange which spans the entire data selection, including possible + intermediate segments which are not part of the original data selection. +*/ +QCPDataRange QCPDataSelection::span() const +{ + if (isEmpty()) + return QCPDataRange(); + else + return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); +} + +/*! + Adds the given \a dataRange to this data selection. This is equivalent to the += operator but + allows disabling immediate simplification by setting \a simplify to false. This can improve + performance if adding a very large amount of data ranges successively. In this case, make sure to + call \ref simplify manually, after the operation. +*/ +void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) +{ + mDataRanges.append(dataRange); + if (simplify) + this->simplify(); +} + +/*! + Removes all data ranges. The data selection then contains no data points. + + \ref isEmpty +*/ +void QCPDataSelection::clear() +{ + mDataRanges.clear(); +} + +/*! + Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent + or overlapping ranges. This can reduce the number of individual data ranges in the selection, and + prevents possible double-counting when iterating over the data points held by the data ranges. + + This method is automatically called when using the addition/subtraction operators. The only case + when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a + simplify explicitly set to false. +*/ +void QCPDataSelection::simplify() +{ + // remove any empty ranges: + for (int i=mDataRanges.size()-1; i>=0; --i) + { + if (mDataRanges.at(i).isEmpty()) + mDataRanges.removeAt(i); + } + if (mDataRanges.isEmpty()) + return; + + // sort ranges by starting value, ascending: + std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); + + // join overlapping/contiguous ranges: + int i = 1; + while (i < mDataRanges.size()) + { + if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list + { + mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); + mDataRanges.removeAt(i); + } else + ++i; + } +} + +/*! + Makes sure this data selection conforms to the specified \a type selection type. Before the type + is enforced, \ref simplify is called. + + Depending on \a type, enforcing means adding new data points that were previously not part of the + selection, or removing data points from the selection. If the current selection already conforms + to \a type, the data selection is not changed. + + \see QCP::SelectionType +*/ +void QCPDataSelection::enforceType(QCP::SelectionType type) +{ + simplify(); + switch (type) + { + case QCP::stNone: + { + mDataRanges.clear(); + break; + } + case QCP::stWhole: + { + // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) + break; + } + case QCP::stSingleData: + { + // reduce all data ranges to the single first data point: + if (!mDataRanges.isEmpty()) + { + if (mDataRanges.size() > 1) + mDataRanges = QList() << mDataRanges.first(); + if (mDataRanges.first().length() > 1) + mDataRanges.first().setEnd(mDataRanges.first().begin()+1); + } + break; + } + case QCP::stDataRange: + { + mDataRanges = QList() << span(); + break; + } + case QCP::stMultipleDataRanges: + { + // this is the selection type that allows all concievable combinations of ranges, so do nothing + break; + } + } +} + +/*! + Returns true if the data selection \a other is contained entirely in this data selection, i.e. + all data point indices that are in \a other are also in this data selection. + + \see QCPDataRange::contains +*/ +bool QCPDataSelection::contains(const QCPDataSelection &other) const +{ + if (other.isEmpty()) return false; + + int otherIndex = 0; + int thisIndex = 0; + while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) + { + if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) + ++otherIndex; + else + ++thisIndex; + } + return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this +} + +/*! + Returns a data selection containing the points which are both in this data selection and in the + data range \a other. + + A common use case is to limit an unknown data selection to the valid range of a data container, + using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned + data selection without exceeding the data container's bounds. +*/ +QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const +{ + QCPDataSelection result; + for (int i=0; iorientation() == Qt::Horizontal) + return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); + else + return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); + } else + { + qDebug() << Q_FUNC_INFO << "called with axis zero"; + return QCPRange(); + } +} + +/*! + Sets the pen that will be used to draw the selection rect outline. + + \see setBrush +*/ +void QCPSelectionRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used to fill the selection rect. By default the selection rect is not + filled, i.e. \a brush is Qt::NoBrush. + + \see setPen +*/ +void QCPSelectionRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + If there is currently a selection interaction going on (\ref isActive), the interaction is + canceled. The selection rect will emit the \ref canceled signal. +*/ +void QCPSelectionRect::cancel() +{ + if (mActive) + { + mActive = false; + Q_EMIT canceled(mRect, 0); + } +} + +/*! \internal + + This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. + The default implementation sets the selection rect to active, initializes the selection rect + geometry and emits the \ref started signal. +*/ +void QCPSelectionRect::startSelection(QMouseEvent *event) +{ + mActive = true; + mRect = QRect(event->pos(), event->pos()); + Q_EMIT started(event); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs + to update its geometry. The default implementation updates the rect and emits the \ref changed + signal. +*/ +void QCPSelectionRect::moveSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + Q_EMIT changed(mRect, event); + layer()->replot(); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has + finished by the user releasing the mouse button. The default implementation deactivates the + selection rect and emits the \ref accepted signal. +*/ +void QCPSelectionRect::endSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + mActive = false; + Q_EMIT accepted(mRect, event); +} + +/*! \internal + + This method is called by QCustomPlot when a key has been pressed by the user while the selection + rect interaction is active. The default implementation allows to \ref cancel the interaction by + hitting the escape key. +*/ +void QCPSelectionRect::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape && mActive) + { + mActive = false; + Q_EMIT canceled(mRect, event); + } +} + +/* inherits documentation from base class */ +void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/*! \internal + + If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. + + \seebaseclassmethod +*/ +void QCPSelectionRect::draw(QCPPainter *painter) +{ + if (mActive) + { + painter->setPen(mPen); + painter->setBrush(mBrush); + painter->drawRect(mRect); + } +} +/* end of 'src/selectionrect.cpp' */ + + +/* including file 'src/layout.cpp', size 79064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPMarginGroup +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPMarginGroup + \brief A margin group allows synchronization of margin sides if working with multiple layout elements. + + QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that + they will all have the same size, based on the largest required margin in the group. + + \n + \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" + \n + + In certain situations it is desirable that margins at specific sides are synchronized across + layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will + provide a cleaner look to the user if the left and right margins of the two axis rects are of the + same size. The left axis of the top axis rect will then be at the same horizontal position as the + left axis of the lower axis rect, making them appear aligned. The same applies for the right + axes. This is what QCPMarginGroup makes possible. + + To add/remove a specific side of a layout element to/from a margin group, use the \ref + QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call + \ref clear, or just delete the margin group. + + \section QCPMarginGroup-example Example + + First create a margin group: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 + Then set this group on the layout element sides: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 + Here, we've used the first two axis rects of the plot and synchronized their left margins with + each other and their right margins with each other. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const + + Returns a list of all layout elements that have their margin \a side associated with this margin + group. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPMarginGroup instance in \a parentPlot. +*/ +QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot) +{ + mChildren.insert(QCP::msLeft, QList()); + mChildren.insert(QCP::msRight, QList()); + mChildren.insert(QCP::msTop, QList()); + mChildren.insert(QCP::msBottom, QList()); +} + +QCPMarginGroup::~QCPMarginGroup() +{ + clear(); +} + +/*! + Returns whether this margin group is empty. If this function returns true, no layout elements use + this margin group to synchronize margin sides. +*/ +bool QCPMarginGroup::isEmpty() const +{ + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + if (!it.value().isEmpty()) + return false; + } + return true; +} + +/*! + Clears this margin group. The synchronization of the margin sides that use this margin group is + lifted and they will use their individual margin sizes again. +*/ +void QCPMarginGroup::clear() +{ + // make all children remove themselves from this margin group: + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + const QList elements = it.value(); + for (int i=elements.size()-1; i>=0; --i) + elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild + } +} + +/*! \internal + + Returns the synchronized common margin for \a side. This is the margin value that will be used by + the layout element on the respective side, if it is part of this margin group. + + The common margin is calculated by requesting the automatic margin (\ref + QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin + group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into + account, too.) +*/ +int QCPMarginGroup::commonMargin(QCP::MarginSide side) const +{ + // query all automatic margins of the layout elements in this margin group side and find maximum: + int result = 0; + const QList elements = mChildren.value(side); + for (int i=0; iautoMargins().testFlag(side)) + continue; + int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); + if (m > result) + result = m; + } + return result; +} + +/*! \internal + + Adds \a element to the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].contains(element)) + mChildren[side].append(element); + else + qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); +} + +/*! \internal + + Removes \a element from the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].removeOne(element)) + qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutElement + \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". + + This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. + + A Layout element is a rectangular object which can be placed in layouts. It has an outer rect + (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference + between outer and inner rect is called its margin. The margin can either be set to automatic or + manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be + set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, + the layout element subclass will control the value itself (via \ref calculateAutoMargin). + + Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level + layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref + QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. + + Thus in QCustomPlot one can divide layout elements into two categories: The ones that are + invisible by themselves, because they don't draw anything. Their only purpose is to manage the + position and size of other layout elements. This category of layout elements usually use + QCPLayout as base class. Then there is the category of layout elements which actually draw + something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does + not necessarily mean that the latter category can't have child layout elements. QCPLegend for + instance, actually derives from QCPLayoutGrid and the individual legend items are child layout + elements in the grid layout. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayout *QCPLayoutElement::layout() const + + Returns the parent layout of this layout element. +*/ + +/*! \fn QRect QCPLayoutElement::rect() const + + Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref + setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). + + In some cases, the area between outer and inner rect is left blank. In other cases the margin + area is used to display peripheral graphics while the main content is in the inner rect. This is + where automatic margin calculation becomes interesting because it allows the layout element to + adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect + draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if + \ref setAutoMargins is enabled) according to the space required by the labels of the axes. + + \see outerRect +*/ + +/*! \fn QRect QCPLayoutElement::outerRect() const + + Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the + margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref + setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. + + \see rect +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutElement and sets default values. +*/ +QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) + mParentLayout(0), + mMinimumSize(), + mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), + mSizeConstraintRect(scrInnerRect), + mRect(0, 0, 0, 0), + mOuterRect(0, 0, 0, 0), + mMargins(0, 0, 0, 0), + mMinimumMargins(0, 0, 0, 0), + mAutoMargins(QCP::msAll) +{ +} + +QCPLayoutElement::~QCPLayoutElement() +{ + setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any + // unregister at layout: + if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor + mParentLayout->take(this); +} + +/*! + Sets the outer rect of this layout element. If the layout element is inside a layout, the layout + sets the position and size of this layout element using this function. + + Calling this function externally has no effect, since the layout will overwrite any changes to + the outer rect upon the next replot. + + The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. + + \see rect +*/ +void QCPLayoutElement::setOuterRect(const QRect &rect) +{ + if (mOuterRect != rect) + { + mOuterRect = rect; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all + sides, this function is used to manually set the margin on those sides. Sides that are still set + to be handled automatically are ignored and may have any value in \a margins. + + The margin is the distance between the outer rect (controlled by the parent layout via \ref + setOuterRect) and the inner \ref rect (which usually contains the main content of this layout + element). + + \see setAutoMargins +*/ +void QCPLayoutElement::setMargins(const QMargins &margins) +{ + if (mMargins != margins) + { + mMargins = margins; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + If \ref setAutoMargins is enabled on some or all margins, this function is used to provide + minimum values for those margins. + + The minimum values are not enforced on margin sides that were set to be under manual control via + \ref setAutoMargins. + + \see setAutoMargins +*/ +void QCPLayoutElement::setMinimumMargins(const QMargins &margins) +{ + if (mMinimumMargins != margins) + { + mMinimumMargins = margins; + } +} + +/*! + Sets on which sides the margin shall be calculated automatically. If a side is calculated + automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is + set to be controlled manually, the value may be specified with \ref setMargins. + + Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref + setMarginGroup), to synchronize (align) it with other layout elements in the plot. + + \see setMinimumMargins, setMargins, QCP::MarginSide +*/ +void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) +{ + mAutoMargins = sides; +} + +/*! + Sets the minimum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + If the parent layout size is not sufficient to satisfy all minimum size constraints of its child + layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot + propagates the layout's size constraints to the outside by setting its own minimum QWidget size + accordingly, so violations of \a size should be exceptions. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(const QSize &size) +{ + if (mMinimumSize != size) + { + mMinimumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the minimum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(int width, int height) +{ + setMinimumSize(QSize(width, height)); +} + +/*! + Sets the maximum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(const QSize &size) +{ + if (mMaximumSize != size) + { + mMaximumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the maximum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(int width, int height) +{ + setMaximumSize(QSize(width, height)); +} + +/*! + Sets to which rect of a layout element the size constraints apply. Size constraints can be set + via \ref setMinimumSize and \ref setMaximumSize. + + The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis + labels), whereas the inner rect (\ref rect) does not. + + \see setMinimumSize, setMaximumSize +*/ +void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) +{ + if (mSizeConstraintRect != constraintRect) + { + mSizeConstraintRect = constraintRect; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! + Sets the margin \a group of the specified margin \a sides. + + Margin groups allow synchronizing specified margins across layout elements, see the documentation + of \ref QCPMarginGroup. + + To unset the margin group of \a sides, set \a group to 0. + + Note that margin groups only work for margin sides that are set to automatic (\ref + setAutoMargins). + + \see QCP::MarginSide +*/ +void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) +{ + QVector sideVector; + if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); + if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); + if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); + if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); + + for (int i=0; iremoveChild(side, this); + + if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there + { + mMarginGroups.remove(side); + } else // setting to a new group + { + mMarginGroups[side] = group; + group->addChild(side, this); + } + } + } +} + +/*! + Updates the layout element and sub-elements. This function is automatically called before every + replot by the parent layout element. It is called multiple times, once for every \ref + UpdatePhase. The phases are run through in the order of the enum values. For details about what + happens at the different phases, see the documentation of \ref UpdatePhase. + + Layout elements that have child elements should call the \ref update method of their child + elements, and pass the current \a phase unchanged. + + The default implementation executes the automatic margin mechanism in the \ref upMargins phase. + Subclasses should make sure to call the base class implementation. +*/ +void QCPLayoutElement::update(UpdatePhase phase) +{ + if (phase == upMargins) + { + if (mAutoMargins != QCP::msNone) + { + // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: + QMargins newMargins = mMargins; + QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; + Q_FOREACH (QCP::MarginSide side, allMarginSides) + { + if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically + { + if (mMarginGroups.contains(side)) + QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group + else + QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly + // apply minimum margin restrictions: + if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) + QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); + } + } + setMargins(newMargins); + } + } +} + +/*! + Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, + if no manual minimum size is set. + + if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size + (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum + allowed size of this layout element. + + A manual minimum size is considered set if it is non-zero. + + The default implementation simply returns the sum of the horizontal margins for the width and the + sum of the vertical margins for the height. Reimplementations may use their detailed knowledge + about the layout element's content to provide size hints. +*/ +QSize QCPLayoutElement::minimumOuterSizeHint() const +{ + return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); +} + +/*! + Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, + if no manual maximum size is set. + + if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned + size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the + maximum allowed size of this layout element. + + A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. + + The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying + no suggested maximum size. Reimplementations may use their detailed knowledge about the layout + element's content to provide size hints. +*/ +QSize QCPLayoutElement::maximumOuterSizeHint() const +{ + return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +} + +/*! + Returns a list of all child elements in this layout element. If \a recursive is true, all + sub-child elements are included in the list, too. + + \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have + empty cells which yield 0 at the respective index.) +*/ +QList QCPLayoutElement::elements(bool recursive) const +{ + Q_UNUSED(recursive) + return QList(); +} + +/*! + Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer + rect, this method returns a value corresponding to 0.99 times the parent plot's selection + tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is + true, -1.0 is returned. + + See \ref QCPLayerable::selectTest for a general explanation of this virtual method. + + QCPLayoutElement subclasses may reimplement this method to provide more specific selection test + behaviour. +*/ +double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + + if (onlySelectable) + return -1; + + if (QRectF(mOuterRect).contains(pos)) + { + if (mParentPlot) + return mParentPlot->selectionTolerance()*0.99; + else + { + qDebug() << Q_FUNC_INFO << "parent plot not defined"; + return -1; + } + } else + return -1; +} + +/*! \internal + + propagates the parent plot initialization to all child elements, by calling \ref + QCPLayerable::initializeParentPlot on them. +*/ +void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_FOREACH (QCPLayoutElement* el, elements(false)) + { + if (!el->parentPlot()) + el->initializeParentPlot(parentPlot); + } +} + +/*! \internal + + Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a + side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the + returned value will not be smaller than the specified minimum margin. + + The default implementation just returns the respective manual margin (\ref setMargins) or the + minimum margin, whichever is larger. +*/ +int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) +{ + return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); +} + +/*! \internal + + This virtual method is called when this layout element was moved to a different QCPLayout, or + when this layout element has changed its logical position (e.g. row and/or column) within the + same QCPLayout. Subclasses may use this to react accordingly. + + Since this method is called after the completion of the move, you can access the new parent + layout via \ref layout(). + + The default implementation does nothing. +*/ +void QCPLayoutElement::layoutChanged() +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayout +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayout + \brief The abstract base class for layouts + + This is an abstract base class for layout elements whose main purpose is to define the position + and size of other child layout elements. In most cases, layouts don't draw anything themselves + (but there are exceptions to this, e.g. QCPLegend). + + QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. + + QCPLayout introduces a common interface for accessing and manipulating the child elements. Those + functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref + simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions + to this interface which are more specialized to the form of the layout. For example, \ref + QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid + more conveniently. + + Since this is an abstract base class, you can't instantiate it directly. Rather use one of its + subclasses like QCPLayoutGrid or QCPLayoutInset. + + For a general introduction to the layout system, see the dedicated documentation page \ref + thelayoutsystem "The Layout System". +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPLayout::elementCount() const = 0 + + Returns the number of elements/cells in the layout. + + \see elements, elementAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 + + Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. + + Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. + QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check + whether a cell is empty or not. + + \see elements, elementCount, takeAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 + + Removes the element with the given \a index from the layout and returns it. + + If the \a index is invalid or the cell with that index is empty, returns 0. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see elementAt, take +*/ + +/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 + + Removes the specified \a element from the layout and returns true on success. + + If the \a element isn't in this layout, returns false. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see takeAt +*/ + +/* end documentation of pure virtual functions */ + +/*! + Creates an instance of QCPLayout and sets default values. Note that since QCPLayout + is an abstract base class, it can't be instantiated directly. +*/ +QCPLayout::QCPLayout() +{ +} + +/*! + If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to + reposition and resize their cells. + + Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". + + For details about this method and the update phases, see the documentation of \ref + QCPLayoutElement::update. +*/ +void QCPLayout::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + // set child element rects according to layout: + if (phase == upLayout) + updateLayout(); + + // propagate update call to child elements: + const int elCount = elementCount(); + for (int i=0; iupdate(phase); + } +} + +/* inherits documentation from base class */ +QList QCPLayout::elements(bool recursive) const +{ + const int c = elementCount(); + QList result; +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(c); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the + default implementation does nothing. + + Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit + simplification while QCPLayoutGrid does. +*/ +void QCPLayout::simplify() +{ +} + +/*! + Removes and deletes the element at the provided \a index. Returns true on success. If \a index is + invalid or points to an empty cell, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the returned element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see remove, takeAt +*/ +bool QCPLayout::removeAt(int index) +{ + if (QCPLayoutElement *el = takeAt(index)) + { + delete el; + return true; + } else + return false; +} + +/*! + Removes and deletes the provided \a element. Returns true on success. If \a element is not in the + layout, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see removeAt, take +*/ +bool QCPLayout::remove(QCPLayoutElement *element) +{ + if (take(element)) + { + delete element; + return true; + } else + return false; +} + +/*! + Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure + all empty cells are collapsed. + + \see remove, removeAt +*/ +void QCPLayout::clear() +{ + for (int i=elementCount()-1; i>=0; --i) + { + if (elementAt(i)) + removeAt(i); + } + simplify(); +} + +/*! + Subclasses call this method to report changed (minimum/maximum) size constraints. + + If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref + sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of + QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, + it may update itself and resize cells accordingly. +*/ +void QCPLayout::sizeConstraintsChanged() const +{ + if (QWidget *w = qobject_cast(parent())) + w->updateGeometry(); + else if (QCPLayout *l = qobject_cast(parent())) + l->sizeConstraintsChanged(); +} + +/*! \internal + + Subclasses reimplement this method to update the position and sizes of the child elements/cells + via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. + + The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay + within that rect. + + \ref getSectionSizes may help with the reimplementation of this function. + + \see update +*/ +void QCPLayout::updateLayout() +{ +} + + +/*! \internal + + Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the + \ref QCPLayerable::parentLayerable and the QObject parent to this layout. + + Further, if \a el didn't previously have a parent plot, calls \ref + QCPLayerable::initializeParentPlot on \a el to set the paret plot. + + This method is used by subclass specific methods that add elements to the layout. Note that this + method only changes properties in \a el. The removal from the old layout and the insertion into + the new layout must be done additionally. +*/ +void QCPLayout::adoptElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = this; + el->setParentLayerable(this); + el->setParent(this); + if (!el->parentPlot()) + el->initializeParentPlot(mParentPlot); + el->layoutChanged(); + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout + and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent + QCustomPlot. + + This method is used by subclass specific methods that remove elements from the layout (e.g. \ref + take or \ref takeAt). Note that this method only changes properties in \a el. The removal from + the old layout must be done additionally. +*/ +void QCPLayout::releaseElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = 0; + el->setParentLayerable(0); + el->setParent(mParentPlot); + // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + This is a helper function for the implementation of \ref updateLayout in subclasses. + + It calculates the sizes of one-dimensional sections with provided constraints on maximum section + sizes, minimum section sizes, relative stretch factors and the final total size of all sections. + + The QVector entries refer to the sections. Thus all QVectors must have the same size. + + \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size + imposed, set all vector values to Qt's QWIDGETSIZE_MAX. + + \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size + imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than + \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, + not exceeding the allowed total size is taken to be more important than not going below minimum + section sizes.) + + \a stretchFactors give the relative proportions of the sections to each other. If all sections + shall be scaled equally, set all values equal. If the first section shall be double the size of + each individual other section, set the first number of \a stretchFactors to double the value of + the other individual values (e.g. {2, 1, 1, 1}). + + \a totalSize is the value that the final section sizes will add up to. Due to rounding, the + actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, + you could distribute the remaining difference on the sections. + + The return value is a QVector containing the section sizes. +*/ +QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const +{ + if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) + { + qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; + return QVector(); + } + if (stretchFactors.isEmpty()) + return QVector(); + int sectionCount = stretchFactors.size(); + QVector sectionSizes(sectionCount); + // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): + int minSizeSum = 0; + for (int i=0; i minimumLockedSections; + QList unfinishedSections; + for (int i=0; i result(sectionCount); + for (int i=0; iminimumOuterSizeHint(); + QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) + if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rwidth() += el->margins().left() + el->margins().right(); + if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; +} + +/*! \internal + + This is a helper function for the implementation of subclasses. + + It returns the maximum size that should finally be used for the outer rect of the passed layout + element \a el. + + It takes into account whether a manual maximum size is set (\ref + QCPLayoutElement::setMaximumSize), which size constraint is set (\ref + QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum + size was set (\ref QCPLayoutElement::maximumOuterSizeHint). +*/ +QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) +{ + QSize maxOuterHint = el->maximumOuterSizeHint(); + QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) + if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rwidth() += el->margins().left() + el->margins().right(); + if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutGrid + \brief A layout that arranges child elements in a grid + + Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, + \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). + + Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or + column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref + hasElement, that element can be retrieved with \ref element. If rows and columns that only have + empty cells shall be removed, call \ref simplify. Removal of elements is either done by just + adding the element to a different layout or by using the QCPLayout interface \ref take or \ref + remove. + + If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a + column, the grid layout will choose the position according to the current \ref setFillOrder and + the wrapping (\ref setWrap). + + Row and column insertion can be performed with \ref insertRow and \ref insertColumn. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPLayoutGrid::rowCount() const + + Returns the number of rows in the layout. + + \see columnCount +*/ + +/*! \fn int QCPLayoutGrid::columnCount() const + + Returns the number of columns in the layout. + + \see rowCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutGrid and sets default values. +*/ +QCPLayoutGrid::QCPLayoutGrid() : + mColumnSpacing(5), + mRowSpacing(5), + mWrap(0), + mFillOrder(foRowsFirst) +{ +} + +QCPLayoutGrid::~QCPLayoutGrid() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the element in the cell in \a row and \a column. + + Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug + message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. + + \see addElement, hasElement +*/ +QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const +{ + if (row >= 0 && row < mElements.size()) + { + if (column >= 0 && column < mElements.first().size()) + { + if (QCPLayoutElement *result = mElements.at(row).at(column)) + return result; + else + qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; + return 0; +} + + +/*! \overload + + Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it + is first removed from there. If \a row or \a column don't exist yet, the layout is expanded + accordingly. + + Returns true if the element was added successfully, i.e. if the cell at \a row and \a column + didn't already have an element. + + Use the overload of this method without explicit row/column index to place the element according + to the configured fill order and wrapping settings. + + \see element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) +{ + if (!hasElement(row, column)) + { + if (element && element->layout()) // remove from old layout first + element->layout()->take(element); + expandTo(row+1, column+1); + mElements[row][column] = element; + if (element) + adoptElement(element); + return true; + } else + qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; + return false; +} + +/*! \overload + + Adds the \a element to the next empty cell according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first + removed from there. If necessary, the layout is expanded to hold the new element. + + Returns true if the element was added successfully. + + \see setFillOrder, setWrap, element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(QCPLayoutElement *element) +{ + int rowIndex = 0; + int colIndex = 0; + if (mFillOrder == foColumnsFirst) + { + while (hasElement(rowIndex, colIndex)) + { + ++colIndex; + if (colIndex >= mWrap && mWrap > 0) + { + colIndex = 0; + ++rowIndex; + } + } + } else + { + while (hasElement(rowIndex, colIndex)) + { + ++rowIndex; + if (rowIndex >= mWrap && mWrap > 0) + { + rowIndex = 0; + ++colIndex; + } + } + } + return addElement(rowIndex, colIndex, element); +} + +/*! + Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't + empty. + + \see element +*/ +bool QCPLayoutGrid::hasElement(int row, int column) +{ + if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) + return mElements.at(row).at(column); + else + return false; +} + +/*! + Sets the stretch \a factor of \a column. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactors, setRowStretchFactor +*/ +void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) +{ + if (column >= 0 && column < columnCount()) + { + if (factor > 0) + mColumnStretchFactors[column] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid column:" << column; +} + +/*! + Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactor, setRowStretchFactors +*/ +void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) +{ + if (factors.size() == mColumnStretchFactors.size()) + { + mColumnStretchFactors = factors; + for (int i=0; i= 0 && row < rowCount()) + { + if (factor > 0) + mRowStretchFactors[row] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid row:" << row; +} + +/*! + Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setRowStretchFactor, setColumnStretchFactors +*/ +void QCPLayoutGrid::setRowStretchFactors(const QList &factors) +{ + if (factors.size() == mRowStretchFactors.size()) + { + mRowStretchFactors = factors; + for (int i=0; i tempElements; + if (rearrange) + { + tempElements.reserve(elCount); + for (int i=0; i()); + mRowStretchFactors.append(1); + } + // go through rows and expand columns as necessary: + int newColCount = qMax(columnCount(), newColumnCount); + for (int i=0; i rowCount()) + newIndex = rowCount(); + + mRowStretchFactors.insert(newIndex, 1); + QList newRow; + for (int col=0; col columnCount()) + newIndex = columnCount(); + + mColumnStretchFactors.insert(newIndex, 1); + for (int row=0; row= 0 && row < rowCount()) + { + if (column >= 0 && column < columnCount()) + { + switch (mFillOrder) + { + case foRowsFirst: return column*rowCount() + row; + case foColumnsFirst: return row*columnCount() + column; + } + } else + qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; + } else + qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; + return 0; +} + +/*! + Converts the linear index to row and column indices and writes the result to \a row and \a + column. + + The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the + indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices + increase top to bottom and then left to right. + + If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. + + For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, + i.e. greater or equal to zero and smaller than the current \ref elementCount. + + \see rowColToIndex +*/ +void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const +{ + row = -1; + column = -1; + const int nCols = columnCount(); + const int nRows = rowCount(); + if (nCols == 0 || nRows == 0) + return; + if (index < 0 || index >= elementCount()) + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return; + } + + switch (mFillOrder) + { + case foRowsFirst: + { + column = index / nRows; + row = index % nRows; + break; + } + case foColumnsFirst: + { + row = index / nCols; + column = index % nCols; + break; + } + } +} + +/* inherits documentation from base class */ +void QCPLayoutGrid::updateLayout() +{ + QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + int totalRowSpacing = (rowCount()-1) * mRowSpacing; + int totalColSpacing = (columnCount()-1) * mColumnSpacing; + QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); + QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); + + // go through cells and set rects accordingly: + int yOffset = mRect.top(); + for (int row=0; row 0) + yOffset += rowHeights.at(row-1)+mRowSpacing; + int xOffset = mRect.left(); + for (int col=0; col 0) + xOffset += colWidths.at(col-1)+mColumnSpacing; + if (mElements.at(row).at(col)) + mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); + } + } +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const +{ + if (index >= 0 && index < elementCount()) + { + int row, col; + indexToRowCol(index, row, col); + return mElements.at(row).at(col); + } else + return 0; +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + int row, col; + indexToRowCol(index, row, col); + mElements[row][col] = 0; + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutGrid::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; i QCPLayoutGrid::elements(bool recursive) const +{ + QList result; + const int elCount = elementCount(); +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(elCount); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing rows and columns which only contain empty cells. +*/ +void QCPLayoutGrid::simplify() +{ + // remove rows with only empty cells: + for (int row=rowCount()-1; row>=0; --row) + { + bool hasElements = false; + for (int col=0; col=0; --col) + { + bool hasElements = false; + for (int row=0; row minColWidths, minRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + QSize result(0, 0); + for (int i=0; i maxColWidths, maxRowHeights; + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + QSize result(0, 0); + for (int i=0; i QWIDGETSIZE_MAX) + result.setHeight(QWIDGETSIZE_MAX); + if (result.width() > QWIDGETSIZE_MAX) + result.setWidth(QWIDGETSIZE_MAX); + return result; +} + +/*! \internal + + Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights + respectively. + + The minimum height of a row is the largest minimum height of any element's outer rect in that + row. The minimum width of a column is the largest minimum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMaximumRowColSizes +*/ +void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const +{ + *minColWidths = QVector(columnCount(), 0); + *minRowHeights = QVector(rowCount(), 0); + for (int row=0; rowat(col) < minSize.width()) + (*minColWidths)[col] = minSize.width(); + if (minRowHeights->at(row) < minSize.height()) + (*minRowHeights)[row] = minSize.height(); + } + } + } +} + +/*! \internal + + Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights + respectively. + + The maximum height of a row is the smallest maximum height of any element's outer rect in that + row. The maximum width of a column is the smallest maximum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMinimumRowColSizes +*/ +void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const +{ + *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); + *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); + for (int row=0; rowat(col) > maxSize.width()) + (*maxColWidths)[col] = maxSize.width(); + if (maxRowHeights->at(row) > maxSize.height()) + (*maxRowHeights)[row] = maxSize.height(); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutInset +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPLayoutInset + \brief A layout that places child elements aligned to the border or arbitrarily positioned + + Elements are placed either aligned to the border or at arbitrary position in the area of the + layout. Which placement applies is controlled with the \ref InsetPlacement (\ref + setInsetPlacement). + + Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or + addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset + placement will default to \ref ipBorderAligned and the element will be aligned according to the + \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at + arbitrary position and size, defined by \a rect. + + The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. + + This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual void QCPLayoutInset::simplify() + + The QCPInsetLayout does not need simplification since it can never have empty cells due to its + linear index structure. This method does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutInset and sets default values. +*/ +QCPLayoutInset::QCPLayoutInset() +{ +} + +QCPLayoutInset::~QCPLayoutInset() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the placement type of the element with the specified \a index. +*/ +QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const +{ + if (elementAt(index)) + return mInsetPlacement.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return ipFree; + } +} + +/*! + Returns the alignment of the element with the specified \a index. The alignment only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. +*/ +Qt::Alignment QCPLayoutInset::insetAlignment(int index) const +{ + if (elementAt(index)) + return mInsetAlignment.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return 0; + } +} + +/*! + Returns the rect of the element with the specified \a index. The rect only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. +*/ +QRectF QCPLayoutInset::insetRect(int index) const +{ + if (elementAt(index)) + return mInsetRect.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return QRectF(); + } +} + +/*! + Sets the inset placement type of the element with the specified \a index to \a placement. + + \see InsetPlacement +*/ +void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) +{ + if (elementAt(index)) + mInsetPlacement[index] = placement; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function + is used to set the alignment of the element with the specified \a index to \a alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. +*/ +void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) +{ + if (elementAt(index)) + mInsetAlignment[index] = alignment; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the + position and size of the element with the specified \a index to \a rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + Note that the minimum and maximum sizes of the embedded element (\ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. +*/ +void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) +{ + if (elementAt(index)) + mInsetRect[index] = rect; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/* inherits documentation from base class */ +void QCPLayoutInset::updateLayout() +{ + for (int i=0; i finalMaxSize.width()) + insetRect.setWidth(finalMaxSize.width()); + if (insetRect.size().height() > finalMaxSize.height()) + insetRect.setHeight(finalMaxSize.height()); + } else if (mInsetPlacement.at(i) == ipBorderAligned) + { + insetRect.setSize(finalMinSize); + Qt::Alignment al = mInsetAlignment.at(i); + if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); + else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); + else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter + if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); + else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); + else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter + } + mElements.at(i)->setOuterRect(insetRect); + } +} + +/* inherits documentation from base class */ +int QCPLayoutInset::elementCount() const +{ + return mElements.size(); +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::elementAt(int index) const +{ + if (index >= 0 && index < mElements.size()) + return mElements.at(index); + else + return 0; +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + mElements.removeAt(index); + mInsetPlacement.removeAt(index); + mInsetAlignment.removeAt(index); + mInsetRect.removeAt(index); + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutInset::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/*! + Adds the specified \a element to the layout as an inset aligned at the border (\ref + setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a + alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. + + \see addElement(QCPLayoutElement *element, const QRectF &rect) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipBorderAligned); + mInsetAlignment.append(alignment); + mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} + +/*! + Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref + setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a + rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipFree); + mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); + mInsetRect.append(rect); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} +/* end of 'src/layout.cpp' */ + + +/* including file 'src/lineending.cpp', size 11536 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLineEnding +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLineEnding + \brief Handles the different ending decorations for line-like items + + \image html QCPLineEnding.png "The various ending styles currently supported" + + For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine + has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. + + The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can + be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of + the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. + For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite + directions, e.g. "outward". This can be changed by \ref setInverted, which would make the + respective arrow point inward. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify a + QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. + \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead +*/ + +/*! + Creates a QCPLineEnding instance with default values (style \ref esNone). +*/ +QCPLineEnding::QCPLineEnding() : + mStyle(esNone), + mWidth(8), + mLength(10), + mInverted(false) +{ +} + +/*! + Creates a QCPLineEnding instance with the specified values. +*/ +QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : + mStyle(style), + mWidth(width), + mLength(length), + mInverted(inverted) +{ +} + +/*! + Sets the style of the ending decoration. +*/ +void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) +{ + mStyle = style; +} + +/*! + Sets the width of the ending decoration, if the style supports it. On arrows, for example, the + width defines the size perpendicular to the arrow's pointing direction. + + \see setLength +*/ +void QCPLineEnding::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the length of the ending decoration, if the style supports it. On arrows, for example, the + length defines the size in pointing direction. + + \see setWidth +*/ +void QCPLineEnding::setLength(double length) +{ + mLength = length; +} + +/*! + Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point + inward when \a inverted is set to true. + + Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or + discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are + affected by it, which can be used to control to which side the half bar points to. +*/ +void QCPLineEnding::setInverted(bool inverted) +{ + mInverted = inverted; +} + +/*! \internal + + Returns the maximum pixel radius the ending decoration might cover, starting from the position + the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). + + This is relevant for clipping. Only omit painting of the decoration when the position where the + decoration is supposed to be drawn is farther away from the clipping rect than the returned + distance. +*/ +double QCPLineEnding::boundingDistance() const +{ + switch (mStyle) + { + case esNone: + return 0; + + case esFlatArrow: + case esSpikeArrow: + case esLineArrow: + case esSkewedBar: + return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length + + case esDisc: + case esSquare: + case esDiamond: + case esBar: + case esHalfBar: + return mWidth*1.42; // items that only have a width -> width*sqrt(2) + + } + return 0; +} + +/*! + Starting from the origin of this line ending (which is style specific), returns the length + covered by the line ending symbol, in backward direction. + + For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if + both have the same \ref setLength value, because the spike arrow has an inward curved back, which + reduces the length along its center axis (the drawing origin for arrows is at the tip). + + This function is used for precise, style specific placement of line endings, for example in + QCPAxes. +*/ +double QCPLineEnding::realLength() const +{ + switch (mStyle) + { + case esNone: + case esLineArrow: + case esSkewedBar: + case esBar: + case esHalfBar: + return 0; + + case esFlatArrow: + return mLength; + + case esDisc: + case esSquare: + case esDiamond: + return mWidth*0.5; + + case esSpikeArrow: + return mLength*0.8; + } + return 0; +} + +/*! \internal + + Draws the line ending with the specified \a painter at the position \a pos. The direction of the + line ending is controlled with \a dir. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const +{ + if (mStyle == esNone) + return; + + QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); + if (lengthVec.isNull()) + lengthVec = QCPVector2D(1, 0); + QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); + + QPen penBackup = painter->pen(); + QBrush brushBackup = painter->brush(); + QPen miterPen = penBackup; + miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey + QBrush brush(painter->pen().color(), Qt::SolidPattern); + switch (mStyle) + { + case esNone: break; + case esFlatArrow: + { + QPointF points[3] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 3); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esSpikeArrow: + { + QPointF points[4] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec*0.8).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esLineArrow: + { + QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), + pos.toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->drawPolyline(points, 3); + painter->setPen(penBackup); + break; + } + case esDisc: + { + painter->setBrush(brush); + painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); + painter->setBrush(brushBackup); + break; + } + case esSquare: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), + (pos-widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esDiamond: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp).toPointF(), + (pos-widthVec).toPointF(), + (pos+widthVecPerp).toPointF(), + (pos+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esBar: + { + painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); + break; + } + case esHalfBar: + { + painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); + break; + } + case esSkewedBar: + { + if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) + { + // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); + } else + { + // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); + } + break; + } + } +} + +/*! \internal + \overload + + Draws the line ending. The direction is controlled with the \a angle parameter in radians. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const +{ + draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); +} +/* end of 'src/lineending.cpp' */ + + +/* including file 'src/axis/axisticker.cpp', size 18664 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTicker +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTicker + \brief The base class tick generator used by QCPAxis to create tick positions and tick labels + + Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions + and tick labels for the current axis range. The ticker of an axis can be set via \ref + QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple + axes can share the same ticker instance. + + This base class generates normal tick coordinates and numeric labels for linear axes. It picks a + reasonable tick step (the separation between ticks) which results in readable tick labels. The + number of ticks that should be approximately generated can be set via \ref setTickCount. + Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either + sacrifices readability to better match the specified tick count (\ref + QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref + QCPAxisTicker::tssReadability), which is the default. + + The following more specialized axis ticker subclasses are available, see details in the + respective class documentation: + +
+ + + + + + + +
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png + \image html axisticker-time2.png
+
+ + \section axisticker-subclassing Creating own axis tickers + + Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and + reimplementing some or all of the available virtual methods. + + In the simplest case you might wish to just generate different tick steps than the other tickers, + so you only reimplement the method \ref getTickStep. If you additionally want control over the + string that will be shown as tick label, reimplement \ref getTickLabel. + + If you wish to have complete control, you can generate the tick vectors and tick label vectors + yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default + implementations use the previously mentioned virtual methods \ref getTickStep and \ref + getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case + of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. + + The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick + placement control is obtained by reimplementing \ref createSubTickVector. + + See the documentation of all these virtual methods in QCPAxisTicker for detailed information + about the parameters and expected return values. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTicker::QCPAxisTicker() : + mTickStepStrategy(tssReadability), + mTickCount(5), + mTickOrigin(0) +{ +} + +QCPAxisTicker::~QCPAxisTicker() +{ + +} + +/*! + Sets which strategy the axis ticker follows when choosing the size of the tick step. For the + available strategies, see \ref TickStepStrategy. +*/ +void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) +{ + mTickStepStrategy = strategy; +} + +/*! + Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count + is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with + the requested number of ticks. + + Whether the readability has priority over meeting the requested \a count can be specified with + \ref setTickStepStrategy. +*/ +void QCPAxisTicker::setTickCount(int count) +{ + if (count > 0) + mTickCount = count; + else + qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; +} + +/*! + Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a + concept and doesn't need to be inside the currently visible axis range. + + By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick + step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be + {-4, 1, 6, 11, 16,...}. +*/ +void QCPAxisTicker::setTickOrigin(double origin) +{ + mTickOrigin = origin; +} + +/*! + This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), + tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). + + The ticks are generated for the specified \a range. The generated labels typically follow the + specified \a locale, \a formatChar and number \a precision, however this might be different (or + even irrelevant) for certain QCPAxisTicker subclasses. + + The output parameter \a ticks is filled with the generated tick positions in axis coordinates. + The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) + and are respectively filled with sub tick coordinates, and tick label strings belonging to \a + ticks by index. +*/ +void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) +{ + // generate (major) ticks: + double tickStep = getTickStep(range); + ticks = createTickVector(tickStep, range); + trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) + + // generate sub ticks between major ticks: + if (subTicks) + { + if (ticks.size() > 0) + { + *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); + trimTicks(range, *subTicks, false); + } else + *subTicks = QVector(); + } + + // finally trim also outliers (no further clipping happens in axis drawing): + trimTicks(range, ticks, false); + // generate labels for visible ticks if requested: + if (tickLabels) + *tickLabels = createLabelVector(ticks, locale, formatChar, precision); +} + +/*! \internal + + Takes the entire currently visible axis range and returns a sensible tick step in + order to provide readable tick labels as well as a reasonable number of tick counts (see \ref + setTickCount, \ref setTickStepStrategy). + + If a QCPAxisTicker subclass only wants a different tick step behaviour than the default + implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper + function. +*/ +double QCPAxisTicker::getTickStep(const QCPRange &range) +{ + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return cleanMantissa(exactStep); +} + +/*! \internal + + Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns + an appropriate number of sub ticks for that specific tick step. + + Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. +*/ +int QCPAxisTicker::getSubTickCount(double tickStep) +{ + int result = 1; // default to 1, if no proper value can be found + + // separate integer and fractional part of mantissa: + double epsilon = 0.01; + double intPartf; + int intPart; + double fracPart = modf(getMantissa(tickStep), &intPartf); + intPart = intPartf; + + // handle cases with (almost) integer mantissa: + if (fracPart < epsilon || 1.0-fracPart < epsilon) + { + if (1.0-fracPart < epsilon) + ++intPart; + switch (intPart) + { + case 1: result = 4; break; // 1.0 -> 0.2 substep + case 2: result = 3; break; // 2.0 -> 0.5 substep + case 3: result = 2; break; // 3.0 -> 1.0 substep + case 4: result = 3; break; // 4.0 -> 1.0 substep + case 5: result = 4; break; // 5.0 -> 1.0 substep + case 6: result = 2; break; // 6.0 -> 2.0 substep + case 7: result = 6; break; // 7.0 -> 1.0 substep + case 8: result = 3; break; // 8.0 -> 2.0 substep + case 9: result = 2; break; // 9.0 -> 3.0 substep + } + } else + { + // handle cases with significantly fractional mantissa: + if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa + { + switch (intPart) + { + case 1: result = 2; break; // 1.5 -> 0.5 substep + case 2: result = 4; break; // 2.5 -> 0.5 substep + case 3: result = 4; break; // 3.5 -> 0.7 substep + case 4: result = 2; break; // 4.5 -> 1.5 substep + case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) + case 6: result = 4; break; // 6.5 -> 1.3 substep + case 7: result = 2; break; // 7.5 -> 2.5 substep + case 8: result = 4; break; // 8.5 -> 1.7 substep + case 9: result = 4; break; // 9.5 -> 1.9 substep + } + } + // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default + } + + return result; +} + +/*! \internal + + This method returns the tick label string as it should be printed under the \a tick coordinate. + If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a + precision. + + If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is + enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will + be formatted accordingly using multiplication symbol and superscript during rendering of the + label automatically. +*/ +QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + return locale.toString(tick, formatChar.toLatin1(), precision); +} + +/*! \internal + + Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a + subTickCount sub ticks between each tick pair given in \a ticks. + + If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should + reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to + base its result on \a subTickCount or \a ticks. +*/ +QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) +{ + QVector result; + if (subTickCount <= 0 || ticks.size() < 2) + return result; + + result.reserve((ticks.size()-1)*subTickCount); + for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result; + // Generate tick positions according to tickStep: + qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision + qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision + int tickcount = lastStep-firstStep+1; + if (tickcount < 0) tickcount = 0; + result.resize(tickcount); + for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) +{ + QVector result; + result.reserve(ticks.size()); + for (int i=0; i &ticks, bool keepOneOutlier) const +{ + bool lowFound = false; + bool highFound = false; + int lowIndex = 0; + int highIndex = -1; + + for (int i=0; i < ticks.size(); ++i) + { + if (ticks.at(i) >= range.lower) + { + lowFound = true; + lowIndex = i; + break; + } + } + for (int i=ticks.size()-1; i >= 0; --i) + { + if (ticks.at(i) <= range.upper) + { + highFound = true; + highIndex = i; + break; + } + } + + if (highFound && lowFound) + { + int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); + int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); + if (trimFront > 0 || trimBack > 0) + ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); + } else // all ticks are either all below or all above the range + ticks.clear(); +} + +/*! \internal + + Returns the coordinate contained in \a candidates which is closest to the provided \a target. + + This method assumes \a candidates is not empty and sorted in ascending order. +*/ +double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const +{ + if (candidates.size() == 1) + return candidates.first(); + QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); + if (it == candidates.constEnd()) + return *(it-1); + else if (it == candidates.constBegin()) + return *it; + else + return target-*(it-1) < *it-target ? *(it-1) : *it; +} + +/*! \internal + + Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also + returns the magnitude of \a input as a power of 10. + + For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. +*/ +double QCPAxisTicker::getMantissa(double input, double *magnitude) const +{ + const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); + if (magnitude) *magnitude = mag; + return input/mag; +} + +/*! \internal + + Returns a number that is close to \a input but has a clean, easier human readable mantissa. How + strongly the mantissa is altered, and thus how strong the result deviates from the original \a + input, depends on the current tick step strategy (see \ref setTickStepStrategy). +*/ +double QCPAxisTicker::cleanMantissa(double input) const +{ + double magnitude; + const double mantissa = getMantissa(input, &magnitude); + switch (mTickStepStrategy) + { + case tssReadability: + { + return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; + } + case tssMeetTickCount: + { + // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 + if (mantissa <= 5.0) + return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 + else + return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 + } + } + return input; +} +/* end of 'src/axis/axisticker.cpp' */ + + +/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerDateTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerDateTime + \brief Specialized axis ticker for calendar dates and times as axis ticks + + \image html axisticker-datetime.png + + This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The + plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 + UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods + with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime + by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey + and \ref keyToDateTime conveniently perform this conversion achieving a precision of one + millisecond on all Qt versions. + + The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. + If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. + + This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day + ticks. For example, if the axis range spans a few years such that there is one tick per year, + ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, + will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in + the image above: even though the number of days varies month by month, this ticker generates + ticks on the same day of each month. + + If you would like to change the date/time that is used as a (mathematical) starting date for the + ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a + QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at + 9:45 of every year. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation + + \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and + milliseconds, and are not interested in the intricacies of real calendar dates with months and + (leap) years, have a look at QCPAxisTickerTime instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerDateTime::QCPAxisTickerDateTime() : + mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), + mDateTimeSpec(Qt::LocalTime), + mDateStrategy(dsNone) +{ + setTickCount(4); +} + +/*! + Sets the format in which dates and times are displayed as tick labels. For details about the \a + format string, see the documentation of QDateTime::toString(). + + Newlines can be inserted with "\n". + + \see setDateTimeSpec +*/ +void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) +{ + mDateTimeFormat = format; +} + +/*! + Sets the time spec that is used for creating the tick labels from corresponding dates/times. + + The default value of QDateTime objects (and also QCPAxisTickerDateTime) is + Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form + of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC + to get the correct axis labels. + + \see setDateTimeFormat +*/ +void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) +{ + mDateTimeSpec = spec; +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, + 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which + directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(double origin) +{ + QCPAxisTicker::setTickOrigin(origin); +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) +{ + setTickOrigin(dateTimeToKey(origin)); +} + +/*! \internal + + Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + Note that this tick step isn't used exactly when generating the tick vector in \ref + createTickVector, but only as a guiding value requiring some correction for each individual tick + interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day + in the month to the last day in the previous month from tick to tick, due to the non-uniform + length of months. The same problem arises with leap years. + + \seebaseclassmethod +*/ +double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + mDateStrategy = dsNone; + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + result = cleanMantissa(result); + } else if (result < 86400*30.4375*12) // below a year + { + result = pickClosest(result, QVector() + << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range + << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range + << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) + if (result > 86400*30.4375-1) // month tick intervals or larger + mDateStrategy = dsUniformDayInMonth; + else if (result > 3600*24-1) // day tick intervals or larger + mDateStrategy = dsUniformTimeInDay; + } else // more than a year, go back to normal clean mantissa algorithm but in units of years + { + const double secondsPerYear = 86400*30.4375*12; // average including leap years + result = cleanMantissa(result/secondsPerYear)*secondsPerYear; + mDateStrategy = dsUniformDayInMonth; + } + return result; +} + +/*! \internal + + Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + \seebaseclassmethod +*/ +int QCPAxisTickerDateTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + case 86400*2: result = 1; break; + case 86400*5: result = 4; break; + case 86400*7: result = 6; break; + case 86400*14: result = 1; break; + case (int)(86400*30.4375+0.5): result = 3; break; + case (int)(86400*30.4375*2+0.5): result = 1; break; + case (int)(86400*30.4375*3+0.5): result = 2; break; + case (int)(86400*30.4375*6+0.5): result = 5; break; + case (int)(86400*30.4375*12+0.5): result = 3; break; + } + return result; +} + +/*! \internal + + Generates a date/time tick label for tick coordinate \a tick, based on the currently set format + (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). + + \seebaseclassmethod +*/ +QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +} + +/*! \internal + + Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain + non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. + + \seebaseclassmethod +*/ +QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result = QCPAxisTicker::createTickVector(tickStep, range); + if (!result.isEmpty()) + { + if (mDateStrategy == dsUniformTimeInDay) + { + QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible + QDateTime tickDateTime; + for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths(-1); + tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); + result[i] = dateTimeToKey(tickDateTime); + } + } + } + return result; +} + +/*! + A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a + QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) + + \see dateTimeToKey +*/ +QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); +# else + return QDateTime::fromMSecsSinceEpoch(key*1000.0); +# endif +} + +/*! \overload + + A convenience method which turns a QDateTime object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return dateTime.toTime_t()+dateTime.time().msec()/1000.0; +# else + return dateTime.toMSecsSinceEpoch()/1000.0; +# endif +} + +/*! \overload + + A convenience method which turns a QDate object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime(date).toTime_t(); +# else + return QDateTime(date).toMSecsSinceEpoch()/1000.0; +# endif +} +/* end of 'src/axis/axistickerdatetime.cpp' */ + + +/* including file 'src/axis/axistickertime.cpp', size 11747 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerTime + \brief Specialized axis ticker for time spans in units of milliseconds to days + + \image html axisticker-time.png + + This QCPAxisTicker subclass generates ticks that corresponds to time intervals. + + The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref + setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate + zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date + and time. + + The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the + largest available unit in the format specified with \ref setTimeFormat, any time spans above will + be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at + coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick + label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour + unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis + zero will carry a leading minus sign. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation + + Here is an example of a time axis providing time information in days, hours and minutes. Due to + the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker + decided to use tick steps of 12 hours: + + \image html axisticker-time2.png + + The format string for this example is + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 + + \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime + instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerTime::QCPAxisTickerTime() : + mTimeFormat(QLatin1String("%h:%m:%s")), + mSmallestUnit(tuSeconds), + mBiggestUnit(tuHours) +{ + setTickCount(4); + mFieldWidth[tuMilliseconds] = 3; + mFieldWidth[tuSeconds] = 2; + mFieldWidth[tuMinutes] = 2; + mFieldWidth[tuHours] = 2; + mFieldWidth[tuDays] = 1; + + mFormatPattern[tuMilliseconds] = QLatin1String("%z"); + mFormatPattern[tuSeconds] = QLatin1String("%s"); + mFormatPattern[tuMinutes] = QLatin1String("%m"); + mFormatPattern[tuHours] = QLatin1String("%h"); + mFormatPattern[tuDays] = QLatin1String("%d"); +} + +/*! + Sets the format that will be used to display time in the tick labels. + + The available patterns are: + - %%z for milliseconds + - %%s for seconds + - %%m for minutes + - %%h for hours + - %%d for days + + The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. + + The largest unit that appears in \a format will carry all the remaining time of a certain tick + coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the + largest unit it might become larger than 59 in order to consume larger time values. If on the + other hand %%h is available, the minutes will wrap around to zero after 59 and the time will + carry to the hour digit. +*/ +void QCPAxisTickerTime::setTimeFormat(const QString &format) +{ + mTimeFormat = format; + + // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest + // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) + mSmallestUnit = tuMilliseconds; + mBiggestUnit = tuMilliseconds; + bool hasSmallest = false; + for (int i = tuMilliseconds; i <= tuDays; ++i) + { + TimeUnit unit = static_cast(i); + if (mTimeFormat.contains(mFormatPattern.value(unit))) + { + if (!hasSmallest) + { + mSmallestUnit = unit; + hasSmallest = true; + } + mBiggestUnit = unit; + } + } +} + +/*! + Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick + label. If the number for the specific unit is shorter than \a width, it will be padded with an + according number of zeros to the left in order to reach the field width. + + \see setTimeFormat +*/ +void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) +{ + mFieldWidth[unit] = qMax(width, 1); +} + +/*! \internal + + Returns the tick step appropriate for time displays, depending on the provided \a range and the + smallest available time unit in the current format (\ref setTimeFormat). For example if the unit + of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) + that require sub-minute precision to be displayed correctly. + + \seebaseclassmethod +*/ +double QCPAxisTickerTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + if (mSmallestUnit == tuMilliseconds) + result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond + else // have no milliseconds available in format, so stick with 1 second tickstep + result = 1.0; + } else if (result < 3600*24) // below a day + { + // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run + QVector availableSteps; + // seconds range: + if (mSmallestUnit <= tuSeconds) + availableSteps << 1; + if (mSmallestUnit == tuMilliseconds) + availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it + else if (mSmallestUnit == tuSeconds) + availableSteps << 2; + if (mSmallestUnit <= tuSeconds) + availableSteps << 5 << 10 << 15 << 30; + // minutes range: + if (mSmallestUnit <= tuMinutes) + availableSteps << 1*60; + if (mSmallestUnit <= tuSeconds) + availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it + else if (mSmallestUnit == tuMinutes) + availableSteps << 2*60; + if (mSmallestUnit <= tuMinutes) + availableSteps << 5*60 << 10*60 << 15*60 << 30*60; + // hours range: + if (mSmallestUnit <= tuHours) + availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; + // pick available step that is most appropriate to approximate ideal step: + result = pickClosest(result, availableSteps); + } else // more than a day, go back to normal clean mantissa algorithm but in units of days + { + const double secondsPerDay = 3600*24; + result = cleanMantissa(result/secondsPerDay)*secondsPerDay; + } + return result; +} + +/*! \internal + + Returns the sub tick count appropriate for the provided \a tickStep and time displays. + + \seebaseclassmethod +*/ +int QCPAxisTickerTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + } + return result; +} + +/*! \internal + + Returns the tick label corresponding to the provided \a tick and the configured format and field + widths (\ref setTimeFormat, \ref setFieldWidth). + + \seebaseclassmethod +*/ +QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + Q_UNUSED(locale) + bool negative = tick < 0; + if (negative) tick *= -1; + double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) + double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time + + restValues[tuMilliseconds] = tick*1000; + values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; + values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; + values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; + values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; + // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) + + QString result = mTimeFormat; + for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) + { + TimeUnit iUnit = static_cast(i); + replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); + } + if (negative) + result.prepend(QLatin1Char('-')); + return result; +} + +/*! \internal + + Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified + \a value, using the field width as specified with \ref setFieldWidth for the \a unit. +*/ +void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const +{ + QString valueStr = QString::number(value); + while (valueStr.size() < mFieldWidth.value(unit)) + valueStr.prepend(QLatin1Char('0')); + + text.replace(mFormatPattern.value(unit), valueStr); +} +/* end of 'src/axis/axistickertime.cpp' */ + + +/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerFixed +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerFixed + \brief Specialized axis ticker with a fixed tick step + + \image html axisticker-fixed.png + + This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It + is also possible to allow integer multiples and integer powers of the specified tick step with + \ref setScaleStrategy. + + A typical application of this ticker is to make an axis only display integers, by setting the + tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. + + Another case is when a certain number has a special meaning and axis ticks should only appear at + multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi + because despite the name it is not limited to only pi symbols/values. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerFixed::QCPAxisTickerFixed() : + mTickStep(1.0), + mScaleStrategy(ssNone) +{ +} + +/*! + Sets the fixed tick interval to \a step. + + The axis ticker will only use this tick step when generating axis ticks. This might cause a very + high tick density and overlapping labels if the axis range is zoomed out. Using \ref + setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a + step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref + setTickCount). +*/ +void QCPAxisTickerFixed::setTickStep(double step) +{ + if (step > 0) + mTickStep = step; + else + qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; +} + +/*! + Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether + modifications may be applied to it before calculating the finally used tick step, such as + permitting multiples or powers. See \ref ScaleStrategy for details. + + The default strategy is \ref ssNone, which means the tick step is absolutely fixed. +*/ +void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) +{ + mScaleStrategy = strategy; +} + +/*! \internal + + Determines the actually used tick step from the specified tick step and scale strategy (\ref + setTickStep, \ref setScaleStrategy). + + This method either returns the specified tick step exactly, or, if the scale strategy is not \ref + ssNone, a modification of it to allow varying the number of ticks in the current axis range. + + \seebaseclassmethod +*/ +double QCPAxisTickerFixed::getTickStep(const QCPRange &range) +{ + switch (mScaleStrategy) + { + case ssNone: + { + return mTickStep; + } + case ssMultiples: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + if (exactStep < mTickStep) + return mTickStep; + else + return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; + } + case ssPowers: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); + } + } + return mTickStep; +} +/* end of 'src/axis/axistickerfixed.cpp' */ + + +/* including file 'src/axis/axistickertext.cpp', size 8653 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerText +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerText + \brief Specialized axis ticker which allows arbitrary labels at specified coordinates + + \image html axisticker-text.png + + This QCPAxisTicker subclass generates ticks which can be directly specified by the user as + coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a + time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks + and modify the tick/label data there. + + This is useful for cases where the axis represents categories rather than numerical values. + + If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on + the axis range), it is a sign that you should probably create an own ticker by subclassing + QCPAxisTicker, instead of using this one. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation +*/ + +/* start of documentation of inline functions */ + +/*! \fn QMap &QCPAxisTickerText::ticks() + + Returns a non-const reference to the internal map which stores the tick coordinates and their + labels. + + You can access the map directly in order to add, remove or manipulate ticks, as an alternative to + using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerText::QCPAxisTickerText() : + mSubTickCount(0) +{ +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis + coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QMap &ticks) +{ + mTicks = ticks; +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis + coordinates, and the entries of \a labels are the respective strings that will appear as tick + labels. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) +{ + clear(); + addTicks(positions, labels); +} + +/*! + Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no + automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this + method. +*/ +void QCPAxisTickerText::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! + Clears all ticks. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see setTicks, addTicks, addTick +*/ +void QCPAxisTickerText::clear() +{ + mTicks.clear(); +} + +/*! + Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a + label. + + \see addTicks, setTicks, clear +*/ +void QCPAxisTickerText::addTick(double position, QString label) +{ + mTicks.insert(position, label); +} + +/*! \overload + + Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to + the axis coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QMap &ticks) +{ + mTicks.unite(ticks); +} + +/*! \overload + + Adds the provided ticks to the ones already existing. The entries of \a positions correspond to + the axis coordinates, and the entries of \a labels are the respective strings that will appear as + tick labels. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) +{ + if (positions.size() != labels.size()) + qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); + int n = qMin(positions.size(), labels.size()); + for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (mTicks.isEmpty()) + return result; + + QMap::const_iterator start = mTicks.lowerBound(range.lower); + QMap::const_iterator end = mTicks.upperBound(range.upper); + // this method should try to give one tick outside of range so proper subticks can be generated: + if (start != mTicks.constBegin()) --start; + if (end != mTicks.constEnd()) ++end; + for (QMap::const_iterator it = start; it != end; ++it) + result.append(it.key()); + + return result; +} +/* end of 'src/axis/axistickertext.cpp' */ + + +/* including file 'src/axis/axistickerpi.cpp', size 11170 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerPi +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerPi + \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi + + \image html axisticker-pi.png + + This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic + constant with a numerical value specified with \ref setPiValue and an appearance in the tick + labels specified with \ref setPiSymbol. + + Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the + tick label can be configured with \ref setFractionStyle. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerPi::QCPAxisTickerPi() : + mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), + mPiValue(M_PI), + mPeriodicity(0), + mFractionStyle(fsUnicodeFractions), + mPiTickStep(0) +{ + setTickCount(4); +} + +/*! + Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick + label. + + If a space shall appear between the number and the symbol, make sure the space is contained in \a + symbol. +*/ +void QCPAxisTickerPi::setPiSymbol(QString symbol) +{ + mPiSymbol = symbol; +} + +/*! + Sets the numerical value that the symbolic constant has. + + This will be used to place the appropriate fractions of the symbol at the respective axis + coordinates. +*/ +void QCPAxisTickerPi::setPiValue(double pi) +{ + mPiValue = pi; +} + +/*! + Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the + symbolic constant. + + To disable periodicity, set \a multiplesOfPi to zero. + + For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. +*/ +void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) +{ + mPeriodicity = qAbs(multiplesOfPi); +} + +/*! + Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick + labels. See \ref FractionStyle for the various options. +*/ +void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) +{ + mFractionStyle = style; +} + +/*! \internal + + Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence + the numerical/fractional part preceding the symbolic constant is made to have a readable + mantissa. + + \seebaseclassmethod +*/ +double QCPAxisTickerPi::getTickStep(const QCPRange &range) +{ + mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mPiTickStep = cleanMantissa(mPiTickStep); + return mPiTickStep*mPiValue; +} + +/*! \internal + + Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In + consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant + reasonably, and not the total tick coordinate. + + \seebaseclassmethod +*/ +int QCPAxisTickerPi::getSubTickCount(double tickStep) +{ + return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); +} + +/*! \internal + + Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The + formatting of the fraction is done according to the specified \ref setFractionStyle. The appended + symbol is specified with \ref setPiSymbol. + + \seebaseclassmethod +*/ +QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + double tickInPis = tick/mPiValue; + if (mPeriodicity > 0) + tickInPis = fmod(tickInPis, mPeriodicity); + + if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) + { + // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above + int denominator = 1000; + int numerator = qRound(tickInPis*denominator); + simplifyFraction(numerator, denominator); + if (qAbs(numerator) == 1 && denominator == 1) + return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else if (numerator == 0) + return QLatin1String("0"); + else + return fractionToString(numerator, denominator) + mPiSymbol; + } else + { + if (qFuzzyIsNull(tickInPis)) + return QLatin1String("0"); + else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) + return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else + return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; + } +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure + the fraction is in irreducible form, i.e. numerator and denominator don't share any common + factors which could be cancelled. +*/ +void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const +{ + if (numerator == 0 || denominator == 0) + return; + + int num = numerator; + int denom = denominator; + while (denom != 0) // euclidean gcd algorithm + { + int oldDenom = denom; + denom = num % denom; + num = oldDenom; + } + // num is now gcd of numerator and denominator + numerator /= num; + denominator /= num; +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and returns a string representation. + The result depends on the configured fraction style (\ref setFractionStyle). + + This method is used to format the numerical/fractional part when generating tick labels. It + simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out + any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). +*/ +QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const +{ + if (denominator == 0) + { + qDebug() << Q_FUNC_INFO << "called with zero denominator"; + return QString(); + } + if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function + { + qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; + return QString::number(numerator/(double)denominator); // failsafe + } + int sign = numerator*denominator < 0 ? -1 : 1; + numerator = qAbs(numerator); + denominator = qAbs(denominator); + + if (denominator == 1) + { + return QString::number(sign*numerator); + } else + { + int integerPart = numerator/denominator; + int remainder = numerator%denominator; + if (remainder == 0) + { + return QString::number(sign*integerPart); + } else + { + if (mFractionStyle == fsAsciiFractions) + { + return QString(QLatin1String("%1%2%3/%4")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) + .arg(remainder) + .arg(denominator); + } else if (mFractionStyle == fsUnicodeFractions) + { + return QString(QLatin1String("%1%2%3")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) + .arg(unicodeFraction(remainder, denominator)); + } + } + } + return QString(); +} + +/*! \internal + + Returns the unicode string representation of the fraction given by \a numerator and \a + denominator. This is the representation used in \ref fractionToString when the fraction style + (\ref setFractionStyle) is \ref fsUnicodeFractions. + + This method doesn't use the single-character common fractions but builds each fraction from a + superscript unicode number, the unicode fraction character, and a subscript unicode number. +*/ +QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const +{ + return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); +} + +/*! \internal + + Returns the unicode string representing \a number as superscript. This is used to build + unicode fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSuperscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2070)); + + QString result; + while (number > 0) + { + const int digit = number%10; + switch (digit) + { + case 1: { result.prepend(QChar(0x00B9)); break; } + case 2: { result.prepend(QChar(0x00B2)); break; } + case 3: { result.prepend(QChar(0x00B3)); break; } + default: { result.prepend(QChar(0x2070+digit)); break; } + } + number /= 10; + } + return result; +} + +/*! \internal + + Returns the unicode string representing \a number as subscript. This is used to build unicode + fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSubscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2080)); + + QString result; + while (number > 0) + { + result.prepend(QChar(0x2080+number%10)); + number /= 10; + } + return result; +} +/* end of 'src/axis/axistickerpi.cpp' */ + + +/* including file 'src/axis/axistickerlog.cpp', size 7106 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerLog +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerLog + \brief Specialized axis ticker suited for logarithmic axes + + \image html axisticker-log.png + + This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic + axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). + + Especially in the case of a log base equal to 10 (the default), it might be desirable to have + tick labels in the form of powers of ten without mantissa display. To achieve this, set the + number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref + QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal + powers, so a format string of "eb". This will result in the following axis tick labels: + + \image html axisticker-log-powers.png + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerLog::QCPAxisTickerLog() : + mLogBase(10.0), + mSubTickCount(8), // generates 10 intervals + mLogBaseLnInv(1.0/qLn(mLogBase)) +{ +} + +/*! + Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer + powers of \a base. +*/ +void QCPAxisTickerLog::setLogBase(double base) +{ + if (base > 0) + { + mLogBase = base; + mLogBaseLnInv = 1.0/qLn(mLogBase); + } else + qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; +} + +/*! + Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced + linearly to provide a better visual guide, so the sub tick density increases toward the higher + tick. + + Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in + the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub + ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, + namely at 20, 30, 40, 50, 60, 70, 80 and 90. +*/ +void QCPAxisTickerLog::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! \internal + + Since logarithmic tick steps are necessarily different for each tick interval, this method does + nothing in the case of QCPAxisTickerLog + + \seebaseclassmethod +*/ +double QCPAxisTickerLog::getTickStep(const QCPRange &range) +{ + // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method + Q_UNUSED(range) + return 1.0; +} + +/*! \internal + + Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no + automatic sub tick count calculation necessary. + + \seebaseclassmethod +*/ +int QCPAxisTickerLog::getSubTickCount(double tickStep) +{ + Q_UNUSED(tickStep) + return mSubTickCount; +} + +/*! \internal + + Creates ticks with a spacing given by the logarithm base and an increasing integer power in the + provided \a range. The step in which the power increases tick by tick is chosen in order to keep + the total number of ticks as close as possible to the tick count (\ref setTickCount). The + parameter \a tickStep is ignored for QCPAxisTickerLog + + \seebaseclassmethod +*/ +QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (range.lower > 0 && range.upper > 0) // positive range + { + double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick *= newLogBase; + result.append(currentTick); + } + } else if (range.lower < 0 && range.upper < 0) // negative range + { + double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick /= newLogBase; + result.append(currentTick); + } + } else // invalid range for logarithmic scale, because lower and upper have different sign + { + qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; + } + + return result; +} +/* end of 'src/axis/axistickerlog.cpp' */ + + +/* including file 'src/axis/axis.cpp', size 99397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGrid + \brief Responsible for drawing the grid of a QCPAxis. + + This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the + grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref + QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. + + The axis and grid drawing was split into two classes to allow them to be placed on different + layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid + in the background and the axes in the foreground, and any plottables/items in between. This + described situation is the default setup, see the QCPLayer documentation. +*/ + +/*! + Creates a QCPGrid instance and sets default values. + + You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. +*/ +QCPGrid::QCPGrid(QCPAxis *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mParentAxis(parentAxis) +{ + // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called + setParent(parentAxis); + setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); + setSubGridVisible(false); + setAntialiased(false); + setAntialiasedSubGrid(false); + setAntialiasedZeroLine(false); +} + +/*! + Sets whether grid lines at sub tick marks are drawn. + + \see setSubGridPen +*/ +void QCPGrid::setSubGridVisible(bool visible) +{ + mSubGridVisible = visible; +} + +/*! + Sets whether sub grid lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedSubGrid(bool enabled) +{ + mAntialiasedSubGrid = enabled; +} + +/*! + Sets whether zero lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedZeroLine(bool enabled) +{ + mAntialiasedZeroLine = enabled; +} + +/*! + Sets the pen with which (major) grid lines are drawn. +*/ +void QCPGrid::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen with which sub grid lines are drawn. +*/ +void QCPGrid::setSubGridPen(const QPen &pen) +{ + mSubGridPen = pen; +} + +/*! + Sets the pen with which zero lines are drawn. + + Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid + lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. +*/ +void QCPGrid::setZeroLinePen(const QPen &pen) +{ + mZeroLinePen = pen; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing the major grid lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); +} + +/*! \internal + + Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning + over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). +*/ +void QCPGrid::draw(QCPPainter *painter) +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + if (mParentAxis->subTicks() && mSubGridVisible) + drawSubGridLines(painter); + drawGridLines(painter); +} + +/*! \internal + + Draws the main grid lines and possibly a zero line with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + const int tickCount = mParentAxis->mTickVector.size(); + double t; // helper variable, result of coordinate-to-pixel transforms + if (mParentAxis->orientation() == Qt::Horizontal) + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + +/*! \internal + + Draws the sub grid lines with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawSubGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); + double t; // helper variable, result of coordinate-to-pixel transforms + painter->setPen(mSubGridPen); + if (mParentAxis->orientation() == Qt::Horizontal) + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxis +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxis + \brief Manages a single axis inside a QCustomPlot. + + Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via + QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and + QCustomPlot::yAxis2 (right). + + Axes are always part of an axis rect, see QCPAxisRect. + \image html AxisNamesOverview.png +
Naming convention of axis parts
+ \n + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line + on the left represents the QCustomPlot widget border.
+ + Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and + tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of + the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the + documentation of QCPAxisTicker. +*/ + +/* start of documentation of inline functions */ + +/*! \fn Qt::Orientation QCPAxis::orientation() const + + Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced + from the axis type (left, top, right or bottom). + + \see orientation(AxisType type), pixelOrientation +*/ + +/*! \fn QCPGrid *QCPAxis::grid() const + + Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the + grid is displayed. +*/ + +/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) + + Returns the orientation of the specified axis type + + \see orientation(), pixelOrientation +*/ + +/*! \fn int QCPAxis::pixelOrientation() const + + Returns which direction points towards higher coordinate values/keys, in pixel space. + + This method returns either 1 or -1. If it returns 1, then going in the positive direction along + the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. + On the other hand, if this method returns -1, going to smaller pixel values corresponds to going + from lower to higher axis coordinates. + + For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, + without having to care about reversed or vertically aligned axes: + + \code + double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); + \endcode + + \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. +*/ + +/*! \fn QSharedPointer QCPAxis::ticker() const + + Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is + responsible for generating the tick positions and tick labels of this axis. You can access the + \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count + (\ref QCPAxisTicker::setTickCount). + + You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see + the documentation there. A new axis ticker can be set with \ref setTicker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see setTicker +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) + + This signal is emitted when the range of this axis has changed. You can connect it to the \ref + setRange slot of another axis to communicate the new range to the other axis, in order for it to + be synchronized. + + You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. + This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper + range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following + slot would limit the x axis to ranges between 0 and 10: + \code + customPlot->xAxis->setRange(newRange.bounded(0, 10)) + \endcode +*/ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) + \overload + + Additionally to the new range, this signal also provides the previous range held by the axis as + \a oldRange. +*/ + +/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the scale type changes, by calls to \ref setScaleType +*/ + +/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) + + This signal is emitted when the selection state of this axis has changed, either by user interaction + or by a direct call to \ref setSelectedParts. +*/ + +/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); + + This signal is emitted when the selectability changes, by calls to \ref setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs an Axis instance of Type \a type for the axis rect \a parent. + + Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create + them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, + create them manually and then inject them also via \ref QCPAxisRect::addAxis. +*/ +QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : + QCPLayerable(parent->parentPlot(), QString(), parent), + // axis base: + mAxisType(type), + mAxisRect(parent), + mPadding(5), + mOrientation(orientation(type)), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + mTickLabels(true), + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedTickPen(QPen(Qt::blue, 2)), + mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedSubTickPen(QPen(Qt::blue, 2)), + // scale and range: + mRange(0, 5), + mRangeReversed(false), + mScaleType(stLinear), + // internal members: + mGrid(new QCPGrid(this)), + mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), + mTicker(new QCPAxisTicker), + mCachedMarginValid(false), + mCachedMargin(0) +{ + setParent(parent); + mGrid->setVisible(false); + setAntialiased(false); + setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again + + if (type == atTop) + { + setTickLabelPadding(3); + setLabelPadding(6); + } else if (type == atRight) + { + setTickLabelPadding(7); + setLabelPadding(12); + } else if (type == atBottom) + { + setTickLabelPadding(3); + setLabelPadding(3); + } else if (type == atLeft) + { + setTickLabelPadding(5); + setLabelPadding(10); + } +} + +QCPAxis::~QCPAxis() +{ + delete mAxisPainter; + delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLabelPadding() const +{ + return mAxisPainter->tickLabelPadding; +} + +/* No documentation as it is a property getter */ +double QCPAxis::tickLabelRotation() const +{ + return mAxisPainter->tickLabelRotation; +} + +/* No documentation as it is a property getter */ +QCPAxis::LabelSide QCPAxis::tickLabelSide() const +{ + return mAxisPainter->tickLabelSide; +} + +/* No documentation as it is a property getter */ +QString QCPAxis::numberFormat() const +{ + QString result; + result.append(mNumberFormatChar); + if (mNumberBeautifulPowers) + { + result.append(QLatin1Char('b')); + if (mAxisPainter->numberMultiplyCross) + result.append(QLatin1Char('c')); + } + return result; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthIn() const +{ + return mAxisPainter->tickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthOut() const +{ + return mAxisPainter->tickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthIn() const +{ + return mAxisPainter->subTickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthOut() const +{ + return mAxisPainter->subTickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::labelPadding() const +{ + return mAxisPainter->labelPadding; +} + +/* No documentation as it is a property getter */ +int QCPAxis::offset() const +{ + return mAxisPainter->offset; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::lowerEnding() const +{ + return mAxisPainter->lowerEnding; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::upperEnding() const +{ + return mAxisPainter->upperEnding; +} + +/*! + Sets whether the axis uses a linear scale or a logarithmic scale. + + Note that this method controls the coordinate transformation. You will likely also want to use a + logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref + QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the + details of logarithmic axis tick creation. + + \ref setNumberPrecision +*/ +void QCPAxis::setScaleType(QCPAxis::ScaleType type) +{ + if (mScaleType != type) + { + mScaleType = type; + if (mScaleType == stLogarithmic) + setRange(mRange.sanitizedForLogScale()); + mCachedMarginValid = false; + Q_EMIT scaleTypeChanged(mScaleType); + } +} + +/*! + Sets the range of the axis. + + This slot may be connected with the \ref rangeChanged signal of another axis so this axis + is always synchronized with the other axis range, when it changes. + + To invert the direction of an axis, use \ref setRangeReversed. +*/ +void QCPAxis::setRange(const QCPRange &range) +{ + if (range.lower == mRange.lower && range.upper == mRange.upper) + return; + + if (!QCPRange::validRange(range)) return; + QCPRange oldRange = mRange; + if (mScaleType == stLogarithmic) + { + mRange = range.sanitizedForLogScale(); + } else + { + mRange = range.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains iSelectAxes.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPAxis::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font. + + The entire selection mechanism for axes is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you + wish to change the selection state manually. + + This function can change the selection state of a part, independent of the \ref setSelectableParts setting. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, + setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor +*/ +void QCPAxis::setSelectedParts(const SelectableParts &selected) +{ + if (mSelectedParts != selected) + { + mSelectedParts = selected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + \overload + + Sets the lower and upper bound of the axis range. + + To invert the direction of an axis, use \ref setRangeReversed. + + There is also a slot to set a range, see \ref setRange(const QCPRange &range). +*/ +void QCPAxis::setRange(double lower, double upper) +{ + if (lower == mRange.lower && upper == mRange.upper) + return; + + if (!QCPRange::validRange(lower, upper)) return; + QCPRange oldRange = mRange; + mRange.lower = lower; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + \overload + + Sets the range of the axis. + + The \a position coordinate indicates together with the \a alignment parameter, where the new + range will be positioned. \a size defines the size of the new axis range. \a alignment may be + Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, + or center of the range to be aligned with \a position. Any other values of \a alignment will + default to Qt::AlignCenter. +*/ +void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) +{ + if (alignment == Qt::AlignLeft) + setRange(position, position+size); + else if (alignment == Qt::AlignRight) + setRange(position-size, position); + else // alignment == Qt::AlignCenter + setRange(position-size/2.0, position+size/2.0); +} + +/*! + Sets the lower bound of the axis range. The upper bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeLower(double lower) +{ + if (mRange.lower == lower) + return; + + QCPRange oldRange = mRange; + mRange.lower = lower; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets the upper bound of the axis range. The lower bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeUpper(double upper) +{ + if (mRange.upper == upper) + return; + + QCPRange oldRange = mRange; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal + axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the + direction of increasing values is inverted. + + Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part + of the \ref setRange interface will still reference the mathematically smaller number than the \a + upper part. +*/ +void QCPAxis::setRangeReversed(bool reversed) +{ + mRangeReversed = reversed; +} + +/*! + The axis ticker is responsible for generating the tick positions and tick labels. See the + documentation of QCPAxisTicker for details on how to work with axis tickers. + + You can change the tick positioning/labeling behaviour of this axis by setting a different + QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis + ticker, access it via \ref ticker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see ticker +*/ +void QCPAxis::setTicker(QSharedPointer ticker) +{ + if (ticker) + mTicker = ticker; + else + qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; + // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector +} + +/*! + Sets whether tick marks are displayed. + + Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve + that, see \ref setTickLabels. + + \see setSubTicks +*/ +void QCPAxis::setTicks(bool show) +{ + if (mTicks != show) + { + mTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. +*/ +void QCPAxis::setTickLabels(bool show) +{ + if (mTickLabels != show) + { + mTickLabels = show; + mCachedMarginValid = false; + if (!mTickLabels) + mTickVectorLabels.clear(); + } +} + +/*! + Sets the distance between the axis base line (including any outward ticks) and the tick labels. + \see setLabelPadding, setPadding +*/ +void QCPAxis::setTickLabelPadding(int padding) +{ + if (mAxisPainter->tickLabelPadding != padding) + { + mAxisPainter->tickLabelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the font of the tick labels. + + \see setTickLabels, setTickLabelColor +*/ +void QCPAxis::setTickLabelFont(const QFont &font) +{ + if (font != mTickLabelFont) + { + mTickLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the tick labels. + + \see setTickLabels, setTickLabelFont +*/ +void QCPAxis::setTickLabelColor(const QColor &color) +{ + mTickLabelColor = color; +} + +/*! + Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, + the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values + from -90 to 90 degrees. + + If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For + other angles, the label is drawn with an offset such that it seems to point toward or away from + the tick mark. +*/ +void QCPAxis::setTickLabelRotation(double degrees) +{ + if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) + { + mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); + mCachedMarginValid = false; + } +} + +/*! + Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. + + The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels + to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels + appear on the inside are additionally clipped to the axis rect. +*/ +void QCPAxis::setTickLabelSide(LabelSide side) +{ + mAxisPainter->tickLabelSide = side; + mCachedMarginValid = false; +} + +/*! + Sets the number format for the numbers in tick labels. This \a formatCode is an extended version + of the format code used e.g. by QString::number() and QLocale::toString(). For reference about + that, see the "Argument Formats" section in the detailed description of the QString class. + + \a formatCode is a string of one, two or three characters. The first character is identical to + the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed + format, 'g'/'G' scientific or fixed, whichever is shorter. + + The second and third characters are optional and specific to QCustomPlot:\n + If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. + "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for + "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 + [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. + If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can + be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the + cross and 183 (0xB7) for the dot. + + Examples for \a formatCode: + \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, + normal scientific format is used + \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with + beautifully typeset decimal powers and a dot as multiplication sign + \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as + multiplication sign + \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal + powers. Format code will be reduced to 'f'. + \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format + code will not be changed. +*/ +void QCPAxis::setNumberFormat(const QString &formatCode) +{ + if (formatCode.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; + return; + } + mCachedMarginValid = false; + + // interpret first char as number format char: + QString allowedFormatChars(QLatin1String("eEfgG")); + if (allowedFormatChars.contains(formatCode.at(0))) + { + mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; + return; + } + if (formatCode.length() < 2) + { + mNumberBeautifulPowers = false; + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret second char as indicator for beautiful decimal powers: + if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) + { + mNumberBeautifulPowers = true; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; + return; + } + if (formatCode.length() < 3) + { + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret third char as indicator for dot or cross multiplication symbol: + if (formatCode.at(2) == QLatin1Char('c')) + { + mAxisPainter->numberMultiplyCross = true; + } else if (formatCode.at(2) == QLatin1Char('d')) + { + mAxisPainter->numberMultiplyCross = false; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; + return; + } +} + +/*! + Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) + for details. The effect of precisions are most notably for number Formats starting with 'e', see + \ref setNumberFormat +*/ +void QCPAxis::setNumberPrecision(int precision) +{ + if (mNumberPrecision != precision) + { + mNumberPrecision = precision; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the + plot and \a outside is the length they will reach outside the plot. If \a outside is greater than + zero, the tick labels and axis label will increase their distance to the axis accordingly, so + they won't collide with the ticks. + + \see setSubTickLength, setTickLengthIn, setTickLengthOut +*/ +void QCPAxis::setTickLength(int inside, int outside) +{ + setTickLengthIn(inside); + setTickLengthOut(outside); +} + +/*! + Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach + inside the plot. + + \see setTickLengthOut, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthIn(int inside) +{ + if (mAxisPainter->tickLengthIn != inside) + { + mAxisPainter->tickLengthIn = inside; + } +} + +/*! + Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach + outside the plot. If \a outside is greater than zero, the tick labels and axis label will + increase their distance to the axis accordingly, so they won't collide with the ticks. + + \see setTickLengthIn, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthOut(int outside) +{ + if (mAxisPainter->tickLengthOut != outside) + { + mAxisPainter->tickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets whether sub tick marks are displayed. + + Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) + + \see setTicks +*/ +void QCPAxis::setSubTicks(bool show) +{ + if (mSubTicks != show) + { + mSubTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside + the plot and \a outside is the length they will reach outside the plot. If \a outside is greater + than zero, the tick labels and axis label will increase their distance to the axis accordingly, + so they won't collide with the ticks. + + \see setTickLength, setSubTickLengthIn, setSubTickLengthOut +*/ +void QCPAxis::setSubTickLength(int inside, int outside) +{ + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); +} + +/*! + Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside + the plot. + + \see setSubTickLengthOut, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthIn(int inside) +{ + if (mAxisPainter->subTickLengthIn != inside) + { + mAxisPainter->subTickLengthIn = inside; + } +} + +/*! + Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach + outside the plot. If \a outside is greater than zero, the tick labels will increase their + distance to the axis accordingly, so they won't collide with the ticks. + + \see setSubTickLengthIn, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthOut(int outside) +{ + if (mAxisPainter->subTickLengthOut != outside) + { + mAxisPainter->subTickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets the pen, the axis base line is drawn with. + + \see setTickPen, setSubTickPen +*/ +void QCPAxis::setBasePen(const QPen &pen) +{ + mBasePen = pen; +} + +/*! + Sets the pen, tick marks will be drawn with. + + \see setTickLength, setBasePen +*/ +void QCPAxis::setTickPen(const QPen &pen) +{ + mTickPen = pen; +} + +/*! + Sets the pen, subtick marks will be drawn with. + + \see setSubTickCount, setSubTickLength, setBasePen +*/ +void QCPAxis::setSubTickPen(const QPen &pen) +{ + mSubTickPen = pen; +} + +/*! + Sets the font of the axis label. + + \see setLabelColor +*/ +void QCPAxis::setLabelFont(const QFont &font) +{ + if (mLabelFont != font) + { + mLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the axis label. + + \see setLabelFont +*/ +void QCPAxis::setLabelColor(const QColor &color) +{ + mLabelColor = color; +} + +/*! + Sets the text of the axis label that will be shown below/above or next to the axis, depending on + its orientation. To disable axis labels, pass an empty string as \a str. +*/ +void QCPAxis::setLabel(const QString &str) +{ + if (mLabel != str) + { + mLabel = str; + mCachedMarginValid = false; + } +} + +/*! + Sets the distance between the tick labels and the axis label. + + \see setTickLabelPadding, setPadding +*/ +void QCPAxis::setLabelPadding(int padding) +{ + if (mAxisPainter->labelPadding != padding) + { + mAxisPainter->labelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the padding of the axis. + + When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, + that is left blank. + + The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. + + \see setLabelPadding, setTickLabelPadding +*/ +void QCPAxis::setPadding(int padding) +{ + if (mPadding != padding) + { + mPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the offset the axis has to its axis rect side. + + If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, + only the offset of the inner most axis has meaning (even if it is set to be invisible). The + offset of the other, outer axes is controlled automatically, to place them at appropriate + positions. +*/ +void QCPAxis::setOffset(int offset) +{ + mAxisPainter->offset = offset; +} + +/*! + Sets the font that is used for tick labels when they are selected. + + \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelFont(const QFont &font) +{ + if (font != mSelectedTickLabelFont) + { + mSelectedTickLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts + } +} + +/*! + Sets the font that is used for the axis label when it is selected. + + \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelFont(const QFont &font) +{ + mSelectedLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts +} + +/*! + Sets the color that is used for tick labels when they are selected. + + \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelColor(const QColor &color) +{ + if (color != mSelectedTickLabelColor) + { + mSelectedTickLabelColor = color; + } +} + +/*! + Sets the color that is used for the axis label when it is selected. + + \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelColor(const QColor &color) +{ + mSelectedLabelColor = color; +} + +/*! + Sets the pen that is used to draw the axis base line when selected. + + \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedBasePen(const QPen &pen) +{ + mSelectedBasePen = pen; +} + +/*! + Sets the pen that is used to draw the (major) ticks when selected. + + \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickPen(const QPen &pen) +{ + mSelectedTickPen = pen; +} + +/*! + Sets the pen that is used to draw the subticks when selected. + + \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedSubTickPen(const QPen &pen) +{ + mSelectedSubTickPen = pen; +} + +/*! + Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setUpperEnding +*/ +void QCPAxis::setLowerEnding(const QCPLineEnding &ending) +{ + mAxisPainter->lowerEnding = ending; +} + +/*! + Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the right ending, for vertical axes the top ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setLowerEnding +*/ +void QCPAxis::setUpperEnding(const QCPLineEnding &ending) +{ + mAxisPainter->upperEnding = ending; +} + +/*! + If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper + bounds of the range. The range is simply moved by \a diff. + + If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This + corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). +*/ +void QCPAxis::moveRange(double diff) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + mRange.lower += diff; + mRange.upper += diff; + } else // mScaleType == stLogarithmic + { + mRange.lower *= diff; + mRange.upper *= diff; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis by \a factor around the center of the current axis range. For + example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis + range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around + the center will have moved symmetrically closer). + + If you wish to scale around a different coordinate than the current axis range center, use the + overload \ref scaleRange(double factor, double center). +*/ +void QCPAxis::scaleRange(double factor) +{ + scaleRange(factor, range().center()); +} + +/*! \overload + + Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a + factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at + coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates + around 1.0 will have moved symmetrically closer to 1.0). + + \see scaleRange(double factor) +*/ +void QCPAxis::scaleRange(double factor, double center) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + QCPRange newRange; + newRange.lower = (mRange.lower-center)*factor + center; + newRange.upper = (mRange.upper-center)*factor + center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLinScale(); + } else // mScaleType == stLogarithmic + { + if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range + { + QCPRange newRange; + newRange.lower = qPow(mRange.lower/center, factor)*center; + newRange.upper = qPow(mRange.upper/center, factor)*center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLogScale(); + } else + qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will + be done around the center of the current axis range. + + For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs + plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the + axis rect has. + + This is an operation that changes the range of this axis once, it doesn't fix the scale ratio + indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent + won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent + will follow. +*/ +void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) +{ + int otherPixelSize, ownPixelSize; + + if (otherAxis->orientation() == Qt::Horizontal) + otherPixelSize = otherAxis->axisRect()->width(); + else + otherPixelSize = otherAxis->axisRect()->height(); + + if (orientation() == Qt::Horizontal) + ownPixelSize = axisRect()->width(); + else + ownPixelSize = axisRect()->height(); + + double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; + setRange(range().center(), newRangeSize, Qt::AlignCenter); +} + +/*! + Changes the axis range such that all plottables associated with this axis are fully visible in + that dimension. + + \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes +*/ +void QCPAxis::rescale(bool onlyVisiblePlottables) +{ + QList p = plottables(); + QCPRange newRange; + bool haveRange = false; + for (int i=0; irealVisibility() && onlyVisiblePlottables) + continue; + QCPRange plottableRange; + bool currentFoundRange; + QCP::SignDomain signDomain = QCP::sdBoth; + if (mScaleType == stLogarithmic) + signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + if (p.at(i)->keyAxis() == this) + plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); + else + plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); + if (currentFoundRange) + { + if (!haveRange) + newRange = plottableRange; + else + newRange.expand(plottableRange); + haveRange = true; + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mScaleType == stLinear) + { + newRange.lower = center-mRange.size()/2.0; + newRange.upper = center+mRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mRange.upper/mRange.lower); + newRange.upper = center*qSqrt(mRange.upper/mRange.lower); + } + } + setRange(newRange); + } +} + +/*! + Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. +*/ +double QCPAxis::pixelToCoord(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; + else + return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; + else + return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; + } + } +} + +/*! + Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. +*/ +double QCPAxis::coordToPixel(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + else + return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; + else + { + if (!mRangeReversed) + return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + else + return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + } + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); + else + return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; + else + { + if (!mRangeReversed) + return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + else + return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + } + } + } +} + +/*! + Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function + is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this + function does not change the current selection state of the axis. + + If the axis is not visible (\ref setVisible), this function always returns \ref spNone. + + \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions +*/ +QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const +{ + if (!mVisible) + return spNone; + + if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) + return spAxis; + else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) + return spTickLabels; + else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) + return spAxisLabel; + else + return spNone; +} + +/* inherits documentation from base class */ +double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) + return -1; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; +} + +/*! + Returns a list of all the plottables that have this axis as key or value axis. + + If you are only interested in plottables of type QCPGraph, see \ref graphs. + + \see graphs, items +*/ +QList QCPAxis::plottables() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that have this axis as key or value axis. + + \see plottables, items +*/ +QList QCPAxis::graphs() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis. An item is considered + associated with an axis if at least one of its positions uses the axis as key or value axis. + + \see plottables, graphs +*/ +QList QCPAxis::items() const +{ + QList result; + if (!mParentPlot) return result; + + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to + QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) +*/ +QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return atLeft; + case QCP::msRight: return atRight; + case QCP::msTop: return atTop; + case QCP::msBottom: return atBottom; + default: break; + } + qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; + return atLeft; +} + +/*! + Returns the axis type that describes the opposite axis of an axis with the specified \a type. +*/ +QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) +{ + switch (type) + { + case atLeft: return atRight; break; + case atRight: return atLeft; break; + case atBottom: return atTop; break; + case atTop: return atBottom; break; + default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; + } +} + +/* inherits documentation from base class */ +void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + SelectablePart part = details.value(); + if (mSelectableParts.testFlag(part)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^part : part); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAxis::deselectEvent(bool *selectionStateChanged) +{ + SelectableParts selBefore = mSelectedParts; + setSelectedParts(mSelectedParts & ~mSelectableParts); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis + (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref + QCPAxisRect::setRangeDragAxes) + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. +*/ +void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || + !mAxisRect->rangeDrag().testFlag(orientation()) || + !mAxisRect->rangeDragAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + mDragStartRange = mRange; + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (mDragging) + { + const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); + const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); + if (mScaleType == QCPAxis::stLinear) + { + const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); + setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); + } else if (mScaleType == QCPAxis::stLogarithmic) + { + const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); + setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); + } + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user zoom individual axes + exclusively, by performing the wheel event on top of the axis. + + For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis + (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref + QCPAxisRect::setRangeZoomAxes) + + \seebaseclassmethod + + \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the + axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. +*/ +void QCPAxis::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || + !mAxisRect->rangeZoom().testFlag(orientation()) || + !mAxisRect->rangeZoomAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); + scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); + mParentPlot->replot(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing axis lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); +} + +/*! \internal + + Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. + + \seebaseclassmethod +*/ +void QCPAxis::draw(QCPPainter *painter) +{ + QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + subTickPositions.reserve(mSubTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->basePen = getBasePen(); + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->labelColor = getLabelColor(); + mAxisPainter->label = mLabel; + mAxisPainter->substituteExponent = mNumberBeautifulPowers; + mAxisPainter->tickPen = getTickPen(); + mAxisPainter->subTickPen = getSubTickPen(); + mAxisPainter->tickLabelFont = getTickLabelFont(); + mAxisPainter->tickLabelColor = getTickLabelColor(); + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; + mAxisPainter->reversedEndings = mRangeReversed; + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + mAxisPainter->subTickPositions = subTickPositions; + mAxisPainter->draw(painter); +} + +/*! \internal + + Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling + QCPAxisTicker::generate on the currently installed ticker. + + If a change in the label text/count is detected, the cached axis margin is invalidated to make + sure the next margin calculation recalculates the label sizes and returns an up-to-date value. +*/ +void QCPAxis::setupTickVectors() +{ + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; + + QVector oldLabels = mTickVectorLabels; + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too +} + +/*! \internal + + Returns the pen that is used to draw the axis base line. Depending on the selection state, this + is either mSelectedBasePen or mBasePen. +*/ +QPen QCPAxis::getBasePen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; +} + +/*! \internal + + Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this + is either mSelectedTickPen or mTickPen. +*/ +QPen QCPAxis::getTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; +} + +/*! \internal + + Returns the pen that is used to draw the subticks. Depending on the selection state, this + is either mSelectedSubTickPen or mSubTickPen. +*/ +QPen QCPAxis::getSubTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; +} + +/*! \internal + + Returns the font that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelFont or mTickLabelFont. +*/ +QFont QCPAxis::getTickLabelFont() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; +} + +/*! \internal + + Returns the font that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelFont or mLabelFont. +*/ +QFont QCPAxis::getLabelFont() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; +} + +/*! \internal + + Returns the color that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelColor or mTickLabelColor. +*/ +QColor QCPAxis::getTickLabelColor() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; +} + +/*! \internal + + Returns the color that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelColor or mLabelColor. +*/ +QColor QCPAxis::getLabelColor() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; +} + +/*! \internal + + Returns the appropriate outward margin for this axis. It is needed if \ref + QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref + atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom + margin and so forth. For the calculation, this function goes through similar steps as \ref draw, + so changing one function likely requires the modification of the other one as well. + + The margin consists of the outward tick length, tick label padding, tick label size, label + padding, label size, and padding. + + The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. + unchanged are very fast. +*/ +int QCPAxis::calculateMargin() +{ + if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis + return 0; + + if (mCachedMarginValid) + return mCachedMargin; + + // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels + int margin = 0; + + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->label = mLabel; + mAxisPainter->tickLabelFont = mTickLabelFont; + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + margin += mAxisPainter->size(); + margin += mPadding; + + mCachedMargin = margin; + mCachedMarginValid = true; + return margin; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAxis::selectionCategory() const +{ + return QCP::iSelectAxes; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisPainterPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisPainterPrivate + + \internal + \brief (Private) + + This is a private class and not part of the public QCustomPlot interface. + + It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and + axis label. It also buffers the labels to reduce replot times. The parameters are configured by + directly accessing the public member variables. +*/ + +/*! + Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every + redraw, to utilize the caching mechanisms. +*/ +QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : + type(QCPAxis::atLeft), + basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + lowerEnding(QCPLineEnding::esNone), + upperEnding(QCPLineEnding::esNone), + labelPadding(0), + tickLabelPadding(0), + tickLabelRotation(0), + tickLabelSide(QCPAxis::lsOutside), + substituteExponent(true), + numberMultiplyCross(false), + tickLengthIn(5), + tickLengthOut(0), + subTickLengthIn(2), + subTickLengthOut(0), + tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + offset(0), + abbreviateDecimalPowers(false), + reversedEndings(false), + mParentPlot(parentPlot), + mLabelCache(16) // cache at most 16 (tick) labels +{ +} + +QCPAxisPainterPrivate::~QCPAxisPainterPrivate() +{ +} + +/*! \internal + + Draws the axis with the specified \a painter. + + The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set + here, too. +*/ +void QCPAxisPainterPrivate::draw(QCPPainter *painter) +{ + QByteArray newHash = generateLabelParameterHash(); + if (newHash != mLabelParameterHash) + { + mLabelCache.clear(); + mLabelParameterHash = newHash; + } + + QPoint origin; + switch (type) + { + case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; + case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; + case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; + case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; + } + + double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) + switch (type) + { + case QCPAxis::atTop: yCor = -1; break; + case QCPAxis::atRight: xCor = 1; break; + default: break; + } + int margin = 0; + // draw baseline: + QLineF baseLine; + painter->setPen(basePen); + if (QCPAxis::orientation(type) == Qt::Horizontal) + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); + else + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); + if (reversedEndings) + baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later + painter->drawLine(baseLine); + + // draw ticks: + if (!tickPositions.isEmpty()) + { + painter->setPen(tickPen); + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); + } + } + + // draw subticks: + if (!subTickPositions.isEmpty()) + { + painter->setPen(subTickPen); + // direction of ticks ("inward" is right for left axis and left for right axis) + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); + } + } + margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // draw axis base endings: + bool antialiasingBackup = painter->antialiasing(); + painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't + painter->setBrush(QBrush(basePen.color())); + QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); + if (lowerEnding.style() != QCPLineEnding::esNone) + lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); + if (upperEnding.style() != QCPLineEnding::esNone) + upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); + painter->setAntialiasing(antialiasingBackup); + + // tick labels: + QRect oldClipRect; + if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect + { + oldClipRect = painter->clipRegion().boundingRect(); + painter->setClipRect(axisRect); + } + QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label + if (!tickLabels.isEmpty()) + { + if (tickLabelSide == QCPAxis::lsOutside) + margin += tickLabelPadding; + painter->setFont(tickLabelFont); + painter->setPen(QPen(tickLabelColor)); + const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); + int distanceToAxis = margin; + if (tickLabelSide == QCPAxis::lsInside) + distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + for (int i=0; isetClipRect(oldClipRect); + + // axis label: + QRect labelBounds; + if (!label.isEmpty()) + { + margin += labelPadding; + painter->setFont(labelFont); + painter->setPen(QPen(labelColor)); + labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); + if (type == QCPAxis::atLeft) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); + painter->rotate(-90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atRight) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); + painter->rotate(90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atTop) + painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + else if (type == QCPAxis::atBottom) + painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + } + + // set selection boxes: + int selectionTolerance = 0; + if (mParentPlot) + selectionTolerance = mParentPlot->selectionTolerance(); + else + qDebug() << Q_FUNC_INFO << "mParentPlot is null"; + int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); + int selAxisInSize = selectionTolerance; + int selTickLabelSize; + int selTickLabelOffset; + if (tickLabelSide == QCPAxis::lsOutside) + { + selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; + } else + { + selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + } + int selLabelSize = labelBounds.height(); + int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; + if (type == QCPAxis::atLeft) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atRight) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atTop) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); + } else if (type == QCPAxis::atBottom) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); + } + mAxisSelectionBox = mAxisSelectionBox.normalized(); + mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); + mLabelSelectionBox = mLabelSelectionBox.normalized(); + // draw hitboxes for debug purposes: + //painter->setBrush(Qt::NoBrush); + //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); +} + +/*! \internal + + Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone + direction) needed to fit the axis. +*/ +int QCPAxisPainterPrivate::size() const +{ + int result = 0; + + // get length of tick marks pointing outwards: + if (!tickPositions.isEmpty()) + result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // calculate size of tick labels: + if (tickLabelSide == QCPAxis::lsOutside) + { + QSize tickLabelsSize(0, 0); + if (!tickLabels.isEmpty()) + { + for (int i=0; ibufferDevicePixelRatio())); + result.append(QByteArray::number(tickLabelRotation)); + result.append(QByteArray::number((int)tickLabelSide)); + result.append(QByteArray::number((int)substituteExponent)); + result.append(QByteArray::number((int)numberMultiplyCross)); + result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); + result.append(tickLabelFont.toString().toLatin1()); + return result; +} + +/*! \internal + + Draws a single tick label with the provided \a painter, utilizing the internal label cache to + significantly speed up drawing of labels that were drawn in previous calls. The tick label is + always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in + pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence + for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), + at which the label should be drawn. + + In order to later draw the axis label in a place that doesn't overlap with the tick labels, the + largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref + drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a + tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently + holds. + + The label is drawn with the font and pen that are currently set on the \a painter. To draw + superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref + getTickLabelData). +*/ +void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) +{ + // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! + if (text.isEmpty()) return; + QSize finalSize; + QPointF labelAnchor; + switch (type) + { + case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; + case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; + case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; + case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; + } + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled + { + CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache + if (!cachedLabel) // no cached label existed, create it + { + cachedLabel = new CachedLabel; + TickLabelData labelData = getTickLabelData(painter->font(), text); + cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); + if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) + { + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif +#endif + } else + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); + cachedLabel->pixmap.fill(Qt::transparent); + QCPPainter cachePainter(&cachedLabel->pixmap); + cachePainter.setPen(painter->pen()); + drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); + } + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); + else + labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } + mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created + } else // label caching disabled, draw text directly on surface: + { + TickLabelData labelData = getTickLabelData(painter->font(), text); + QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); + else + labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); + finalSize = labelData.rotatedTotalBounds.size(); + } + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a + y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to + directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when + QCP::phCacheLabels plotting hint is not set. +*/ +void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const +{ + // backup painter settings that we're about to change: + QTransform oldTransform = painter->transform(); + QFont oldFont = painter->font(); + + // transform painter to position/rotation: + painter->translate(x, y); + if (!qFuzzyIsNull(tickLabelRotation)) + painter->rotate(tickLabelRotation); + + // draw text: + if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); + if (!labelData.suffixPart.isEmpty()) + painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); + painter->setFont(labelData.expFont); + painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); + } else + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); + } + + // reset painter settings to what it was before: + painter->setTransform(oldTransform); + painter->setFont(oldFont); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Transforms the passed \a text and \a font to a tickLabelData structure that can then be further + processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and + exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. +*/ +QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const +{ + TickLabelData result; + + // determine whether beautiful decimal powers should be used + bool useBeautifulPowers = false; + int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart + int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart + if (substituteExponent) + { + ePos = text.indexOf(QLatin1Char('e')); + if (ePos > 0 && text.at(ePos-1).isDigit()) + { + eLast = ePos; + while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) + ++eLast; + if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power + useBeautifulPowers = true; + } + } + + // calculate text bounding rects and do string preparation for beautiful decimal powers: + result.baseFont = font; + if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line + result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding + if (useBeautifulPowers) + { + // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: + result.basePart = text.left(ePos); + result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent + // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: + if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) + result.basePart = QLatin1String("10"); + else + result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); + result.expPart = text.mid(ePos+1, eLast-ePos); + // clip "+" and leading zeros off expPart: + while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' + result.expPart.remove(1, 1); + if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) + result.expPart.remove(0, 1); + // prepare smaller font for exponent: + result.expFont = font; + if (result.expFont.pointSize() > 0) + result.expFont.setPointSize(result.expFont.pointSize()*0.75); + else + result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); + // calculate bounding rects of base part(s), exponent part and total one: + result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); + result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); + if (!result.suffixPart.isEmpty()) + result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); + result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA + } else // useBeautifulPowers == false + { + result.basePart = text; + result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); + } + result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler + + // calculate possibly different bounding rect after rotation: + result.rotatedTotalBounds = result.totalBounds; + if (!qFuzzyIsNull(tickLabelRotation)) + { + QTransform transform; + transform.rotate(tickLabelRotation); + result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); + } + + return result; +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Calculates the offset at which the top left corner of the specified tick label shall be drawn. + The offset is relative to a point right next to the tick the label belongs to. + + This function is thus responsible for e.g. centering tick labels under ticks and positioning them + appropriately when they are rotated. +*/ +QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const +{ + /* + calculate label offset from base point at tick (non-trivial, for best visual appearance): short + explanation for bottom axis: The anchor, i.e. the point in the label that is placed + horizontally under the corresponding tick is always on the label side that is closer to the + axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height + is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text + will be centered under the tick (i.e. displaced horizontally by half its height). At the same + time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick + labels. + */ + bool doRotation = !qFuzzyIsNull(tickLabelRotation); + bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. + double radians = tickLabelRotation/180.0*M_PI; + int x=0, y=0; + if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); + y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = -labelData.totalBounds.width(); + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = 0; + y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = 0; + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; + y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); + } else + { + x = -qSin(-radians)*labelData.totalBounds.height()/2.0; + y = -qCos(-radians)*labelData.totalBounds.height(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = -labelData.totalBounds.height(); + } + } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height()/2.0; + y = 0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; + y = +qSin(-radians)*labelData.totalBounds.width(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = 0; + } + } + + return QPointF(x, y); +} + +/*! \internal + + Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label + to be drawn, depending on number format etc. Since only the largest tick label is wanted for the + margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a + smaller width/height. +*/ +void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const +{ + // note: this function must return the same tick label sizes as the placeTickLabel function. + QSize finalSize; + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label + { + const CachedLabel *cachedLabel = mLabelCache.object(text); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } else // label caching disabled or no label with this text cached: + { + TickLabelData labelData = getTickLabelData(font, text); + finalSize = labelData.rotatedTotalBounds.size(); + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} +/* end of 'src/axis/axis.cpp' */ + + +/* including file 'src/scatterstyle.cpp', size 17450 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPScatterStyle +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPScatterStyle + \brief Represents the visual appearance of scatter points + + This class holds information about shape, color and size of scatter points. In plottables like + QCPGraph it is used to store how scatter points shall be drawn. For example, \ref + QCPGraph::setScatterStyle takes a QCPScatterStyle instance. + + A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a + fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can + be controlled with \ref setSize. + + \section QCPScatterStyle-defining Specifying a scatter style + + You can set all these configurations either by calling the respective functions on an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 + + Or you can use one of the various constructors that take different parameter combinations, making + it easy to specify a scatter style in a single call, like so: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 + + \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable + + There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref + QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref + isPenDefined will return false. It leads to scatter points that inherit the pen from the + plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line + color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes + it very convenient to set up typical scatter settings: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation + + Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works + because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly + into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) + constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref + ScatterShape, where actually a QCPScatterStyle is expected. + + \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps + + QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. + + For custom shapes, you can provide a QPainterPath with the desired shape to the \ref + setCustomPath function or call the constructor that takes a painter path. The scatter shape will + automatically be set to \ref ssCustom. + + For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the + constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. + Note that \ref setSize does not influence the appearance of the pixmap. +*/ + +/* start documentation of inline functions */ + +/*! \fn bool QCPScatterStyle::isNone() const + + Returns whether the scatter shape is \ref ssNone. + + \see setShape +*/ + +/*! \fn bool QCPScatterStyle::isPenDefined() const + + Returns whether a pen has been defined for this scatter style. + + The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those + are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen + is undefined, the pen of the respective plottable will be used for drawing scatters. + + If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call + \ref undefinePen. + + \see setPen +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle() : + mSize(6), + mShape(ssNone), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or + brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : + mSize(size), + mShape(shape), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + and size to \a size. No brush is defined, i.e. the scatter point will not be filled. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(Qt::NoBrush), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + the brush color to \a fill (with a solid pattern), and size to \a size. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(QBrush(fill)), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the + brush to \a brush, and size to \a size. + + \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen + and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n + QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n + doesn't necessarily lead C++ to use this constructor in some cases, but might mistake + Qt::NoPen for a QColor and use the + \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) + constructor instead (which will lead to an unexpected look of the scatter points). To prevent + this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) + instead of just Qt::blue, to clearly point out to the compiler that this constructor is + wanted. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(shape), + mPen(pen), + mBrush(brush), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape + is set to \ref ssPixmap. +*/ +QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : + mSize(5), + mShape(ssPixmap), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPixmap(pixmap), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The + scatter shape is set to \ref ssCustom. + + The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly + different meaning than for built-in scatter points: The custom path will be drawn scaled by a + factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its + original size by default. To for example double the size of the path, set \a size to 12. +*/ +QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(ssCustom), + mPen(pen), + mBrush(brush), + mCustomPath(customPath), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Copies the specified \a properties from the \a other scatter style to this scatter style. +*/ +void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) +{ + if (properties.testFlag(spPen)) + { + setPen(other.pen()); + if (!other.isPenDefined()) + undefinePen(); + } + if (properties.testFlag(spBrush)) + setBrush(other.brush()); + if (properties.testFlag(spSize)) + setSize(other.size()); + if (properties.testFlag(spShape)) + { + setShape(other.shape()); + if (other.shape() == ssPixmap) + setPixmap(other.pixmap()); + else if (other.shape() == ssCustom) + setCustomPath(other.customPath()); + } +} + +/*! + Sets the size (pixel diameter) of the drawn scatter points to \a size. + + \see setShape +*/ +void QCPScatterStyle::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the shape to \a shape. + + Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref + ssPixmap and \ref ssCustom, respectively. + + \see setSize +*/ +void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) +{ + mShape = shape; +} + +/*! + Sets the pen that will be used to draw scatter points to \a pen. + + If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after + a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen + previously by calling this function and now wish to undefine the pen, call \ref undefinePen. + + \see setBrush +*/ +void QCPScatterStyle::setPen(const QPen &pen) +{ + mPenDefined = true; + mPen = pen; +} + +/*! + Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter + shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. + + \see setPen +*/ +void QCPScatterStyle::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the pixmap that will be drawn as scatter point to \a pixmap. + + Note that \ref setSize does not influence the appearance of the pixmap. + + The scatter shape is automatically set to \ref ssPixmap. +*/ +void QCPScatterStyle::setPixmap(const QPixmap &pixmap) +{ + setShape(ssPixmap); + mPixmap = pixmap; +} + +/*! + Sets the custom shape that will be drawn as scatter point to \a customPath. + + The scatter shape is automatically set to \ref ssCustom. +*/ +void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) +{ + setShape(ssCustom); + mCustomPath = customPath; +} + +/*! + Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen + implies). + + A call to \ref setPen will define a pen. +*/ +void QCPScatterStyle::undefinePen() +{ + mPenDefined = false; +} + +/*! + Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an + undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. + + This function is used by plottables (or any class that wants to draw scatters) just before a + number of scatters with this style shall be drawn with the \a painter. + + \see drawShape +*/ +void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const +{ + painter->setPen(mPenDefined ? mPen : defaultPen); + painter->setBrush(mBrush); +} + +/*! + Draws the scatter shape with \a painter at position \a pos. + + This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be + called before scatter points are drawn with \ref drawShape. + + \see applyTo +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const +{ + drawShape(painter, pos.x(), pos.y()); +} + +/*! \overload + Draws the scatter shape with \a painter at position \a x and \a y. +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const +{ + double w = mSize/2.0; + switch (mShape) + { + case ssNone: break; + case ssDot: + { + painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); + break; + } + case ssCross: + { + painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); + painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); + break; + } + case ssPlus: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCircle: + { + painter->drawEllipse(QPointF(x , y), w, w); + break; + } + case ssDisc: + { + QBrush b = painter->brush(); + painter->setBrush(painter->pen().color()); + painter->drawEllipse(QPointF(x , y), w, w); + painter->setBrush(b); + break; + } + case ssSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + break; + } + case ssDiamond: + { + QPointF lineArray[4] = {QPointF(x-w, y), + QPointF( x, y-w), + QPointF(x+w, y), + QPointF( x, y+w)}; + painter->drawPolygon(lineArray, 4); + break; + } + case ssStar: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); + break; + } + case ssTriangle: + { + QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), + QPointF(x+w, y+0.755*w), + QPointF( x, y-0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssTriangleInverted: + { + QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), + QPointF(x+w, y-0.755*w), + QPointF( x, y+0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssCrossSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); + painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); + break; + } + case ssPlusSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCrossCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); + break; + } + case ssPlusCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssPeace: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x, y-w, x, y+w)); + painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); + break; + } + case ssPixmap: + { + const double widthHalf = mPixmap.width()*0.5; + const double heightHalf = mPixmap.height()*0.5; +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) + const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#else + const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#endif + if (clipRect.contains(x, y)) + painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); + break; + } + case ssCustom: + { + QTransform oldTransform = painter->transform(); + painter->translate(x, y); + painter->scale(mSize/6.0, mSize/6.0); + painter->drawPath(mCustomPath); + painter->setTransform(oldTransform); + break; + } + } +} +/* end of 'src/scatterstyle.cpp' */ + +//amalgamation: add datacontainer.cpp + +/* including file 'src/plottable.cpp', size 38845 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecorator +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecorator + \brief Controls how a plottable's data selection is drawn + + Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref + QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. + + The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the + scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref + QCPScatterStyle is itself composed of different properties such as color shape and size, the + decorator allows specifying exactly which of those properties shall be used for the selected data + point, via \ref setUsedScatterProperties. + + A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref + QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance + of selected segments. + + Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is + especially useful since plottables take ownership of the passed selection decorator, and thus the + same decorator instance can not be passed to multiple plottables. + + Selection decorators can also themselves perform drawing operations by reimplementing \ref + drawDecoration, which is called by the plottable's draw method. The base class \ref + QCPSelectionDecorator does not make use of this however. For example, \ref + QCPSelectionDecoratorBracket draws brackets around selected data segments. +*/ + +/*! + Creates a new QCPSelectionDecorator instance with default values +*/ +QCPSelectionDecorator::QCPSelectionDecorator() : + mPen(QColor(80, 80, 255), 2.5), + mBrush(Qt::NoBrush), + mScatterStyle(), + mUsedScatterProperties(QCPScatterStyle::spNone), + mPlottable(0) +{ +} + +QCPSelectionDecorator::~QCPSelectionDecorator() +{ +} + +/*! + Sets the pen that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the scatter style that will be used by the parent plottable to draw scatters in selected + data segments. + + \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the + plottable. The used properties can also be changed via \ref setUsedScatterProperties. +*/ +void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) +{ + mScatterStyle = scatterStyle; + setUsedScatterProperties(usedProperties); +} + +/*! + Use this method to define which properties of the scatter style (set via \ref setScatterStyle) + will be used for selected data segments. All properties of the scatter style that are not + specified in \a properties will remain as specified in the plottable's original scatter style. + + \see QCPScatterStyle::ScatterProperty +*/ +void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) +{ + mUsedScatterProperties = properties; +} + +/*! + Sets the pen of \a painter to the pen of this selection decorator. + + \see applyBrush, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyPen(QCPPainter *painter) const +{ + painter->setPen(mPen); +} + +/*! + Sets the brush of \a painter to the brush of this selection decorator. + + \see applyPen, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const +{ + painter->setBrush(mBrush); +} + +/*! + Returns the scatter style that the parent plottable shall use for selected scatter points. The + plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending + on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this + selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. + + \see applyPen, applyBrush, setScatterStyle +*/ +QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const +{ + QCPScatterStyle result(unselectedStyle); + result.setFromOther(mScatterStyle, mUsedScatterProperties); + + // if style shall inherit pen from plottable (has no own pen defined), give it the selected + // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the + // plottable: + if (!result.isPenDefined()) + result.setPen(mPen); + + return result; +} + +/*! + Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to + this selection decorator. +*/ +void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) +{ + setPen(other->pen()); + setBrush(other->brush()); + setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); +} + +/*! + This method is called by all plottables' draw methods to allow custom selection decorations to be + drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data + selection for which the decoration shall be drawn. + + The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so + this method does nothing. +*/ +void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + Q_UNUSED(painter) + Q_UNUSED(selection) +} + +/*! \internal + + This method is called as soon as a selection decorator is associated with a plottable, by a call + to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access + data points via the \ref QCPAbstractPlottable::interface1D interface). + + If the selection decorator was already added to a different plottable before, this method aborts + the registration and returns false. +*/ +bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottable) + { + mPlottable = plottable; + return true; + } else + { + qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); + return false; + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable + \brief The abstract base class for all data representing objects in a plot. + + It defines a very basic interface like name, pen, brush, visibility etc. Since this class is + abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to + create new ways of displaying data (see "Creating own plottables" below). Plottables that display + one-dimensional data (i.e. data points have a single key dimension and one or multiple values at + each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details + there. + + All further specifics are in the subclasses, for example: + \li A normal graph with possibly a line and/or scatter points \ref QCPGraph + (typically created with \ref QCustomPlot::addGraph) + \li A parametric curve: \ref QCPCurve + \li A bar chart: \ref QCPBars + \li A statistical box plot: \ref QCPStatisticalBox + \li A color encoded two-dimensional map: \ref QCPColorMap + \li An OHLC/Candlestick chart: \ref QCPFinancial + + \section plottables-subclassing Creating own plottables + + Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display + two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) + data dimensions. If you want to display data with only one logical key dimension, you should + rather derive from \ref QCPAbstractPlottable1D. + + If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must + implement: + \li \ref selectTest + \li \ref draw + \li \ref drawLegendIcon + \li \ref getKeyRange + \li \ref getValueRange + + See the documentation of those functions for what they need to do. + + For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot + coordinates to pixel coordinates. This function is quite convenient, because it takes the + orientation of the key and value axes into account for you (x and y are swapped when the key axis + is vertical and the value axis horizontal). If you are worried about performance (i.e. you need + to translate many points in a loop like QCPGraph), you can directly use \ref + QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis + yourself. + + Here are some important members you inherit from QCPAbstractPlottable: + + + + + + + + + + + + + + + + + + + + + + + + + + +
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable + (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable + (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates + to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of + the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. + When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. + Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done + by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
+*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const + + Provides access to the selection decorator of this plottable. The selection decorator controls + how selected data ranges are drawn (e.g. their pen color and fill), see \ref + QCPSelectionDecorator for details. + + If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref + setSelectionDecorator. +*/ + +/*! \fn bool QCPAbstractPlottable::selected() const + + Returns true if there are any data points of the plottable currently selected. Use \ref selection + to retrieve the current \ref QCPDataSelection. +*/ + +/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const + + Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on + this plottable. + + \see selected, setSelection, setSelectable +*/ + +/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() + + If this plottable is a one-dimensional plottable, i.e. it implements the \ref + QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case + of a \ref QCPColorMap) returns zero. + + You can use this method to gain read access to data coordinates while holding a pointer to the + abstract base class only. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of pure virtual functions */ + +/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 + \internal + + called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation + of this plottable inside \a rect, next to the plottable name. + + The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't + appear outside the legend icon border. +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 + + Returns the coordinate range that all data in this plottable span in the key axis dimension. For + logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref + QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only + negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points + will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref + QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could + be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getValueRange +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 + + Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span + in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref + QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign + domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and + all positive points will be ignored for range calculation. For no restriction, just set \a + inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates + whether a range could be found or not. If this is false, you shouldn't use the returned range + (e.g. no points in data). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getKeyRange +*/ + +/* end of documentation of pure virtual functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether + there are any points selected or not. + + \see selectionChanged(const QCPDataSelection &selection) +*/ + +/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selection holds the + currently selected data ranges. + + \see selectionChanged(bool selected) +*/ + +/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); + + This signal is emitted when the selectability of this plottable has changed. + + \see setSelectable +*/ + +/* end of documentation of signals */ + +/*! + Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as + its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance + and have perpendicular orientations. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, + it can't be directly instantiated. + + You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. +*/ +QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), + mName(), + mAntialiasedFill(true), + mAntialiasedScatters(true), + mPen(Qt::black), + mBrush(Qt::NoBrush), + mKeyAxis(keyAxis), + mValueAxis(valueAxis), + mSelectable(QCP::stWhole), + mSelectionDecorator(0) +{ + if (keyAxis->parentPlot() != valueAxis->parentPlot()) + qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; + if (keyAxis->orientation() == valueAxis->orientation()) + qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; + + mParentPlot->registerPlottable(this); + setSelectionDecorator(new QCPSelectionDecorator); +} + +QCPAbstractPlottable::~QCPAbstractPlottable() +{ + if (mSelectionDecorator) + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + The name is the textual representation of this plottable as it is displayed in the legend + (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. +*/ +void QCPAbstractPlottable::setName(const QString &name) +{ + mName = name; +} + +/*! + Sets whether fills of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedFill(bool enabled) +{ + mAntialiasedFill = enabled; +} + +/*! + Sets whether the scatter symbols of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) +{ + mAntialiasedScatters = enabled; +} + +/*! + The pen is used to draw basic lines that make up the plottable representation in the + plot. + + For example, the \ref QCPGraph subclass draws its graph lines with this pen. + + \see setBrush +*/ +void QCPAbstractPlottable::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + The brush is used to draw basic fills of the plottable representation in the + plot. The Fill can be a color, gradient or texture, see the usage of QBrush. + + For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when + it's not set to Qt::NoBrush. + + \see setPen +*/ +void QCPAbstractPlottable::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal + to the plottable's value axis. This function performs no checks to make sure this is the case. + The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the + y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setValueAxis +*/ +void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) +{ + mKeyAxis = axis; +} + +/*! + The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is + orthogonal to the plottable's key axis. This function performs no checks to make sure this is the + case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and + the y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setKeyAxis +*/ +void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) +{ + mValueAxis = axis; +} + + +/*! + Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently + (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref + selectionDecorator). + + The entire selection mechanism for plottables is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when + you wish to change the selection state programmatically. + + Using \ref setSelectable you can further specify for each plottable whether and to which + granularity it is selectable. If \a selection is not compatible with the current \ref + QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted + accordingly (see \ref QCPDataSelection::enforceType). + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractPlottable::setSelection(QCPDataSelection selection) +{ + selection.enforceType(mSelectable); + if (mSelection != selection) + { + mSelection = selection; + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } +} + +/*! + Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to + customize the visual representation of selected data ranges further than by using the default + QCPSelectionDecorator. + + The plottable takes ownership of the \a decorator. + + The currently set decorator can be accessed via \ref selectionDecorator. +*/ +void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) +{ + if (decorator) + { + if (decorator->registerWithPlottable(this)) + { + if (mSelectionDecorator) // delete old decorator if necessary + delete mSelectionDecorator; + mSelectionDecorator = decorator; + } + } else if (mSelectionDecorator) // just clear decorator + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + Sets whether and to which granularity this plottable can be selected. + + A selection can happen by clicking on the QCustomPlot surface (When \ref + QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect + (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by + calling \ref setSelection. + + \see setSelection, QCP::SelectionType +*/ +void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + QCPDataSelection oldSelection = mSelection; + mSelection.enforceType(mSelectable); + Q_EMIT selectableChanged(mSelectable); + if (mSelection != oldSelection) + { + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } + } +} + + +/*! + Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. + + \see pixelsToCoords, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + x = keyAxis->coordToPixel(key); + y = valueAxis->coordToPixel(value); + } else + { + y = keyAxis->coordToPixel(key); + x = valueAxis->coordToPixel(value); + } +} + +/*! \overload + + Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. +*/ +const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); + else + return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); +} + +/*! + Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. + + \see coordsToPixels, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + key = keyAxis->pixelToCoord(x); + value = valueAxis->pixelToCoord(y); + } else + { + key = keyAxis->pixelToCoord(y); + value = valueAxis->pixelToCoord(x); + } +} + +/*! \overload + + Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. +*/ +void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const +{ + pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); +} + +/*! + Rescales the key and value axes associated with this plottable to contain all displayed data, so + the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make + sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. + Instead it will stay in the current sign domain and ignore all parts of the plottable that lie + outside of that domain. + + \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show + multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has + \a onlyEnlarge set to false (the default), and all subsequent set to true. + + \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale +*/ +void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const +{ + rescaleKeyAxis(onlyEnlarge); + rescaleValueAxis(onlyEnlarge); +} + +/*! + Rescales the key axis of the plottable so the whole plottable is visible. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (keyAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getKeyRange(foundRange, signDomain); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(keyAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (keyAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-keyAxis->range().size()/2.0; + newRange.upper = center+keyAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); + newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); + } + } + keyAxis->setRange(newRange); + } +} + +/*! + Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is + set to true, only the data points which are in the currently visible key axis range are + considered. + + Returns true if the axis was actually scaled. This might not be the case if this plottable has an + invalid range, e.g. because it has no data points. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (valueAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(valueAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-valueAxis->range().size()/2.0; + newRange.upper = center+valueAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); + newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); + } + } + valueAxis->setRange(newRange); + } +} + +/*! \overload + + Adds this plottable to the specified \a legend. + + Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. + when the legend exists and a legend item associated with this plottable isn't already in the + legend. + + If the plottable needs a more specialized representation in the legend, you can create a + corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead + of calling this method. + + \see removeFromLegend, QCPLegend::addItem +*/ +bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + if (legend->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; + return false; + } + + if (!legend->hasItemWithPlottable(this)) + { + legend->addItem(new QCPPlottableLegendItem(legend, this)); + return true; + } else + return false; +} + +/*! \overload + + Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). + + \see removeFromLegend +*/ +bool QCPAbstractPlottable::addToLegend() +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return addToLegend(mParentPlot->legend); +} + +/*! \overload + + Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem + that is associated with this plottable is removed. + + Returns true on success, i.e. if the legend exists and a legend item associated with this + plottable was found and removed. + + \see addToLegend, QCPLegend::removeItem +*/ +bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + + if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) + return legend->removeItem(lip); + else + return false; +} + +/*! \overload + + Removes the plottable from the legend of the parent QCustomPlot. + + \see addToLegend +*/ +bool QCPAbstractPlottable::removeFromLegend() const +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return removeFromLegend(mParentPlot->legend); +} + +/* inherits documentation from base class */ +QRect QCPAbstractPlottable::clipRect() const +{ + if (mKeyAxis && mValueAxis) + return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); + else + return QRect(); +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractPlottable::selectionCategory() const +{ + return QCP::iSelectPlottables; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable fills. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable scatter points. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint +*/ +void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + + if (mSelectable != QCP::stNone) + { + QCPDataSelection newSelection = details.value(); + QCPDataSelection selectionBefore = mSelection; + if (additive) + { + if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit + { + if (selected()) + setSelection(QCPDataSelection()); + else + setSelection(newSelection); + } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments + { + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); + else + setSelection(mSelection+newSelection); + } + } else + setSelection(newSelection); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable != QCP::stNone) + { + QCPDataSelection selectionBefore = mSelection; + setSelection(QCPDataSelection()); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} +/* end of 'src/plottable.cpp' */ + + +/* including file 'src/item.cpp', size 49269 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemAnchor +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemAnchor + \brief An anchor of an item to which positions can be attached to. + + An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't + control anything on its item, but provides a way to tie other items via their positions to the + anchor. + + For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. + Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can + attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by + calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the + QCPItemRect. This way the start of the line will now always follow the respective anchor location + on the rect item. + + Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an + anchor to other positions. + + To learn how to provide anchors in your own item subclasses, see the subclassing section of the + QCPAbstractItem documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() + + Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if + it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). + + This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids + dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with + gcc compiler). +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : + mName(name), + mParentPlot(parentPlot), + mParentItem(parentItem), + mAnchorId(anchorId) +{ +} + +QCPItemAnchor::~QCPItemAnchor() +{ + // unregister as parent at children: + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } +} + +/*! + Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. + + The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the + parent item, QCPItemAnchor is just an intermediary. +*/ +QPointF QCPItemAnchor::pixelPosition() const +{ + if (mParentItem) + { + if (mAnchorId > -1) + { + return mParentItem->anchorPixelPosition(mAnchorId); + } else + { + qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; + return QPointF(); + } + } else + { + qDebug() << Q_FUNC_INFO << "no parent item set"; + return QPointF(); + } +} + +/*! \internal + + Adds \a pos to the childX list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.contains(pos)) + mChildrenX.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childX list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + +/*! \internal + + Adds \a pos to the childY list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.contains(pos)) + mChildrenY.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childY list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPosition +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPosition + \brief Manages the position of an item. + + Every item has at least one public QCPItemPosition member pointer which provides ways to position the + item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: + \a topLeft and \a bottomRight. + + QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type + defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel + coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also + possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref + setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y + direction, while following a plot coordinate in the X direction. + + A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie + multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) + are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) + means directly ontop of the parent anchor. For example, You could attach the \a start position of + a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line + always be centered under the text label, no matter where the text is moved to. For more advanced + plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see + \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X + direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B + in Y. + + Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent + anchor for other positions. + + To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This + works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref + setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified + pixel values. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const + + Returns the current position type. + + If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the + type of the X coordinate. In that case rather use \a typeX() and \a typeY(). + + \see setType +*/ + +/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const + + Returns the current parent anchor. + + If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), + this method returns the parent anchor of the Y coordinate. In that case rather use \a + parentAnchorX() and \a parentAnchorY(). + + \see setParentAnchor +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : + QCPItemAnchor(parentPlot, parentItem, name), + mPositionTypeX(ptAbsolute), + mPositionTypeY(ptAbsolute), + mKey(0), + mValue(0), + mParentAnchorX(0), + mParentAnchorY(0) +{ +} + +QCPItemPosition::~QCPItemPosition() +{ + // unregister as parent at children: + // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then + // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } + // unregister as child in parent: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPItemPosition::axisRect() const +{ + return mAxisRect.data(); +} + +/*! + Sets the type of the position. The type defines how the coordinates passed to \ref setCoords + should be handled and how the QCPItemPosition should behave in the plot. + + The possible values for \a type can be separated in two main categories: + + \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords + and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. + By default, the QCustomPlot's x- and yAxis are used. + + \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This + corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref + ptAxisRectRatio. They differ only in the way the absolute position is described, see the + documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify + the axis rect with \ref setAxisRect. By default this is set to the main axis rect. + + Note that the position type \ref ptPlotCoords is only available (and sensible) when the position + has no parent anchor (\ref setParentAnchor). + + If the type is changed, the apparent pixel position on the plot is preserved. This means + the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. + + This method sets the type for both X and Y directions. It is also possible to set different types + for X and Y, see \ref setTypeX, \ref setTypeY. +*/ +void QCPItemPosition::setType(QCPItemPosition::PositionType type) +{ + setTypeX(type); + setTypeY(type); +} + +/*! + This method sets the position type of the X coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeY +*/ +void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) +{ + if (mPositionTypeX != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeX = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + This method sets the position type of the Y coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeX +*/ +void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) +{ + if (mPositionTypeY != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeY = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now + follow any position changes of the anchor. The local coordinate system of positions with a parent + anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence + the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) + + if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved + during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position + will be exactly on top of the parent anchor. + + To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. + + If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is + set to \ref ptAbsolute, to keep the position in a valid state. + + This method sets the parent anchor for both X and Y directions. It is also possible to set + different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. +*/ +bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); + bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); + return successX && successY; +} + +/*! + This method sets the parent anchor of the X coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorY +*/ +bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorX(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) + setTypeX(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildX(this); + mParentAnchorX = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(0, coords().y()); + return true; +} + +/*! + This method sets the parent anchor of the Y coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorX +*/ +bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorY(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) + setTypeY(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildY(this); + mParentAnchorY = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(coords().x(), 0); + return true; +} + +/*! + Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type + (\ref setType, \ref setTypeX, \ref setTypeY). + + For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position + on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the + QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the + plot coordinate system defined by the axes set by \ref setAxes. By default those are the + QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available + coordinate types and their meaning. + + If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a + value must also be provided in the different coordinate systems. Here, the X type refers to \a + key, and the Y type refers to \a value. + + \see setPixelPosition +*/ +void QCPItemPosition::setCoords(double key, double value) +{ + mKey = key; + mValue = value; +} + +/*! \overload + + Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the + meaning of \a value of the \ref setCoords(double key, double value) method. +*/ +void QCPItemPosition::setCoords(const QPointF &pos) +{ + setCoords(pos.x(), pos.y()); +} + +/*! + Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It + includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). + + \see setPixelPosition +*/ +QPointF QCPItemPosition::pixelPosition() const +{ + QPointF result; + + // determine X: + switch (mPositionTypeX) + { + case ptAbsolute: + { + result.rx() = mKey; + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + result.rx() = mKey*mParentPlot->viewport().width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mParentPlot->viewport().left(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.rx() = mKey*mAxisRect.data()->width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mAxisRect.data()->left(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + // determine Y: + switch (mPositionTypeY) + { + case ptAbsolute: + { + result.ry() = mValue; + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + result.ry() = mValue*mParentPlot->viewport().height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mParentPlot->viewport().top(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.ry() = mValue*mAxisRect.data()->height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mAxisRect.data()->top(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + result.ry() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + result.ry() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + return result; +} + +/*! + When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the + coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and + yAxis of the QCustomPlot. +*/ +void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + mKeyAxis = keyAxis; + mValueAxis = valueAxis; +} + +/*! + When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the + coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of + the QCustomPlot. +*/ +void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) +{ + mAxisRect = axisRect; +} + +/*! + Sets the apparent pixel position. This works no matter what type (\ref setType) this + QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed + appropriately, to make the position finally appear at the specified pixel values. + + Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is + identical to that of \ref setCoords. + + \see pixelPosition, setCoords +*/ +void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) +{ + double x = pixelPosition.x(); + double y = pixelPosition.y(); + + switch (mPositionTypeX) + { + case ptAbsolute: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mParentPlot->viewport().left(); + x /= (double)mParentPlot->viewport().width(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mAxisRect.data()->left(); + x /= (double)mAxisRect.data()->width(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + x = mKeyAxis.data()->pixelToCoord(x); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + y = mValueAxis.data()->pixelToCoord(x); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + switch (mPositionTypeY) + { + case ptAbsolute: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mParentPlot->viewport().top(); + y /= (double)mParentPlot->viewport().height(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mAxisRect.data()->top(); + y /= (double)mAxisRect.data()->height(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + x = mKeyAxis.data()->pixelToCoord(y); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + y = mValueAxis.data()->pixelToCoord(y); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + setCoords(x, y); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractItem + \brief The abstract base class for all items in a plot. + + In QCustomPlot, items are supplemental graphical elements that are neither plottables + (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus + plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each + specific item has at least one QCPItemPosition member which controls the positioning. Some items + are defined by more than one coordinate and thus have two or more QCPItemPosition members (For + example, QCPItemRect has \a topLeft and \a bottomRight). + + This abstract base class defines a very basic interface like visibility and clipping. Since this + class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass + yourself to create new items. + + The built-in items are: + + + + + + + + + + +
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
+ + \section items-clipping Clipping + + Items are by default clipped to the main axis rect (they are only visible inside the axis rect). + To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect + "setClipToAxisRect(false)". + + On the other hand if you want the item to be clipped to a different axis rect, specify it via + \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and + in principle is independent of the coordinate axes the item might be tied to via its position + members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping + also contains the axes used for the item positions. + + \section items-using Using items + + First you instantiate the item you want to use and add it to the plot: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 + by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just + set the plot coordinates where the line should start/end: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 + If we don't want the line to be positioned in plot coordinates but a different coordinate system, + e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 + Then we can set the coordinates, this time in pixels: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 + and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 + + For more advanced plots, it is even possible to set different types and parent anchors per X/Y + coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref + QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. + + \section items-subclassing Creating own items + + To create an own item, you implement a subclass of QCPAbstractItem. These are the pure + virtual functions, you must implement: + \li \ref selectTest + \li \ref draw + + See the documentation of those functions for what they need to do. + + \subsection items-positioning Allowing the item to be positioned + + As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall + have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add + a public member of type QCPItemPosition like so: + + \code QCPItemPosition * const myPosition;\endcode + + the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition + instance it points to, can be modified, of course). + The initialization of this pointer is made easy with the \ref createPosition function. Just assign + the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition + takes a string which is the name of the position, typically this is identical to the variable name. + For example, the constructor of QCPItemExample could look like this: + + \code + QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + myPosition(createPosition("myPosition")) + { + // other constructor code + } + \endcode + + \subsection items-drawing The draw function + + To give your item a visual representation, reimplement the \ref draw function and use the passed + QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the + position member(s) via \ref QCPItemPosition::pixelPosition. + + To optimize performance you should calculate a bounding rect first (don't forget to take the pen + width into account), check whether it intersects the \ref clipRect, and only draw the item at all + if this is the case. + + \subsection items-selection The selectTest function + + Your implementation of the \ref selectTest function may use the helpers \ref + QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the + selection test becomes significantly simpler for most items. See the documentation of \ref + selectTest for what the function parameters mean and what the function should return. + + \subsection anchors Providing anchors + + Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public + member, e.g. + + \code QCPItemAnchor * const bottom;\endcode + + and create it in the constructor with the \ref createAnchor function, assigning it a name and an + anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). + Since anchors can be placed anywhere, relative to the item's position(s), your item needs to + provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int + anchorId) function. + + In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel + position when anything attached to the anchor needs to know the coordinates. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QList QCPAbstractItem::positions() const + + Returns all positions of the item in a list. + + \see anchors, position +*/ + +/*! \fn QList QCPAbstractItem::anchors() const + + Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always + also an anchor, the list will also contain the positions of this item. + + \see positions, anchor +*/ + +/* end of documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 + \internal + + Draws this item with the provided \a painter. + + The cliprect of the provided painter is set to the rect returned by \ref clipRect before this + function is called. The clipRect depends on the clipping settings defined by \ref + setClipToAxisRect and \ref setClipAxisRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPAbstractItem::selectionChanged(bool selected) + This signal is emitted when the selection state of this item has changed, either by user interaction + or by a direct call to \ref setSelected. +*/ + +/* end documentation of signals */ + +/*! + Base class constructor which initializes base class members. +*/ +QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), + mClipToAxisRect(false), + mSelectable(true), + mSelected(false) +{ + parentPlot->registerItem(this); + + QList rects = parentPlot->axisRects(); + if (rects.size() > 0) + { + setClipToAxisRect(true); + setClipAxisRect(rects.first()); + } +} + +QCPAbstractItem::~QCPAbstractItem() +{ + // don't delete mPositions because every position is also an anchor and thus in mAnchors + qDeleteAll(mAnchors); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPAbstractItem::clipAxisRect() const +{ + return mClipAxisRect.data(); +} + +/*! + Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the + entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. + + \see setClipAxisRect +*/ +void QCPAbstractItem::setClipToAxisRect(bool clip) +{ + mClipToAxisRect = clip; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref + setClipToAxisRect is set to true. + + \see setClipToAxisRect +*/ +void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) +{ + mClipAxisRect = rect; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) + + However, even when \a selectable was set to false, it is possible to set the selection manually, + by calling \ref setSelected. + + \see QCustomPlot::setInteractions, setSelected +*/ +void QCPAbstractItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this item is selected or not. When selected, it might use a different visual + appearance (e.g. pen and brush), this depends on the specific item though. + + The entire selection mechanism for items is handled automatically when \ref + QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this + function when you wish to change the selection state manually. + + This function can change the selection state even when \ref setSelectable was set to false. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/*! + Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by + that name, returns 0. + + This function provides an alternative way to access item positions. Normally, you access + positions direcly by their member pointers (which typically have the same variable name as \a + name). + + \see positions, anchor +*/ +QCPItemPosition *QCPAbstractItem::position(const QString &name) const +{ + for (int i=0; iname() == name) + return mPositions.at(i); + } + qDebug() << Q_FUNC_INFO << "position with name not found:" << name; + return 0; +} + +/*! + Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by + that name, returns 0. + + This function provides an alternative way to access item anchors. Normally, you access + anchors direcly by their member pointers (which typically have the same variable name as \a + name). + + \see anchors, position +*/ +QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const +{ + for (int i=0; iname() == name) + return mAnchors.at(i); + } + qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; + return 0; +} + +/*! + Returns whether this item has an anchor with the specified \a name. + + Note that you can check for positions with this function, too. This is because every position is + also an anchor (QCPItemPosition inherits from QCPItemAnchor). + + \see anchor, position +*/ +bool QCPAbstractItem::hasAnchor(const QString &name) const +{ + for (int i=0; iname() == name) + return true; + } + return false; +} + +/*! \internal + + Returns the rect the visual representation of this item is clipped to. This depends on the + current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. + + If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. + + \see draw +*/ +QRect QCPAbstractItem::clipRect() const +{ + if (mClipToAxisRect && mClipAxisRect) + return mClipAxisRect.data()->rect(); + else + return mParentPlot->viewport(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing item lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); +} + +/*! \internal + + A convenience function which returns the selectTest value for a specified \a rect and a specified + click position \a pos. \a filledRect defines whether a click inside the rect should also be + considered a hit or whether only the rect border is sensitive to hits. + + This function may be used to help with the implementation of the \ref selectTest function for + specific items. + + For example, if your item consists of four rects, call this function four times, once for each + rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four + returned values. +*/ +double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const +{ + double result = -1; + + // distance to border: + QList lines; + lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) + << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); + double minDistSqr = std::numeric_limits::max(); + for (int i=0; i mParentPlot->selectionTolerance()*0.99) + { + if (rect.contains(pos)) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/*! \internal + + Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in + item subclasses if they want to provide anchors (QCPItemAnchor). + + For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor + ids and returns the respective pixel points of the specified anchor. + + \see createAnchor +*/ +QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const +{ + qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the position + member (This is needed to provide the name-based \ref position access to positions). + + Don't delete positions created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each position member. Don't create QCPItemPositions with \b new yourself, because they + won't be registered with the item properly. + + \see createAnchor +*/ +QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); + mPositions.append(newPosition); + mAnchors.append(newPosition); // every position is also an anchor + newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); + newPosition->setType(QCPItemPosition::ptPlotCoords); + if (mParentPlot->axisRect()) + newPosition->setAxisRect(mParentPlot->axisRect()); + newPosition->setCoords(0, 0); + return newPosition; +} + +/*! \internal + + Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the anchor + member (This is needed to provide the name based \ref anchor access to anchors). + + The \a anchorId must be a number identifying the created anchor. It is recommended to create an + enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor + to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns + the correct pixel coordinates for the passed anchor id. + + Don't delete anchors created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they + won't be registered with the item properly. + + \see createPosition +*/ +QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); + mAnchors.append(newAnchor); + return newAnchor; +} + +/* inherits documentation from base class */ +void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractItem::selectionCategory() const +{ + return QCP::iSelectItems; +} +/* end of 'src/item.cpp' */ + + +/* including file 'src/core.cpp', size 125037 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCustomPlot +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCustomPlot + + \brief The central class of the library. This is the QWidget which displays the plot and + interacts with the user. + + For tutorials on how to use QCustomPlot, see the website\n + http://www.qcustomplot.com/ +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const + + Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used + to handle and draw selection rect interactions (see \ref setSelectionRectMode). + + \see setSelectionRect +*/ + +/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const + + Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just + one cell with the main QCPAxisRect inside. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse double click event. +*/ + +/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse press event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. +*/ + +/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse move event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. + + \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, + because the dragging starting point was saved the moment the mouse was pressed. Thus it only has + a meaning for the range drag axes that were set at that moment. If you want to change the drag + axes, consider doing this in the \ref mousePress signal instead. +*/ + +/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse release event. + + It is emitted before QCustomPlot handles any other mechanisms like object selection. So a + slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or + \ref QCPAbstractPlottable::setSelectable. +*/ + +/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse wheel event. + + It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref + QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. +*/ + +/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableDoubleClick +*/ + +/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is double clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableClick +*/ + +/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemDoubleClick +*/ + +/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is double clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemClick +*/ + +/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisDoubleClick +*/ + +/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is double clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisClick +*/ + +/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendDoubleClick +*/ + +/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is double clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendClick +*/ + +/*! \fn void QCustomPlot::selectionChangedByUser() + + This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by + clicking. It is not emitted when the selection state of an object has changed programmatically by + a direct call to setSelected()/setSelection() on an object or by calling \ref + deselectAll. + + In addition to this signal, selectable objects also provide individual signals, for example \ref + QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals + are emitted even if the selection state is changed programmatically. + + See the documentation of \ref setInteractions for details about the selection mechanism. + + \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends +*/ + +/*! \fn void QCustomPlot::beforeReplot() + + This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, afterReplot +*/ + +/*! \fn void QCustomPlot::afterReplot() + + This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, beforeReplot +*/ + +/* end of documentation of signals */ +/* start of documentation of public members */ + +/*! \var QCPAxis *QCustomPlot::xAxis + + A pointer to the primary x Axis (bottom) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis + + A pointer to the primary y Axis (left) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::xAxis2 + + A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis2 + + A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPLegend *QCustomPlot::legend + + A pointer to the default legend of the main axis rect. The legend is invisible by default. Use + QCPLegend::setVisible to change this. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple legends to the plot, use the layout system interface to + access the new legend. For example, legends can be placed inside an axis rect's \ref + QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If + the default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointer becomes 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/* end of documentation of public members */ + +/*! + Constructs a QCustomPlot and sets reasonable default values. +*/ +QCustomPlot::QCustomPlot(QWidget *parent) : + QWidget(parent), + xAxis(0), + yAxis(0), + xAxis2(0), + yAxis2(0), + legend(0), + mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below + mPlotLayout(0), + mAutoAddPlottableToLegend(true), + mAntialiasedElements(QCP::aeNone), + mNotAntialiasedElements(QCP::aeNone), + mInteractions(0), + mSelectionTolerance(8), + mNoAntialiasingOnDrag(false), + mBackgroundBrush(Qt::white, Qt::SolidPattern), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mCurrentLayer(0), + mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), + mMultiSelectModifier(Qt::ControlModifier), + mSelectionRectMode(QCP::srmNone), + mSelectionRect(0), + mOpenGl(false), + mMouseHasMoved(false), + mMouseEventLayerable(0), + mMouseSignalLayerable(0), + mReplotting(false), + mReplotQueued(false), + mOpenGlMultisamples(16), + mOpenGlAntialiasedElementsBackup(QCP::aeNone), + mOpenGlCacheLabelsBackup(true) +{ + setAttribute(Qt::WA_NoMousePropagation); + setAttribute(Qt::WA_OpaquePaintEvent); + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); + QLocale currentLocale = locale(); + currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); + setLocale(currentLocale); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); +# else + setBufferDevicePixelRatio(QWidget::devicePixelRatio()); +# endif +#endif + + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // create initial layers: + mLayers.append(new QCPLayer(this, QLatin1String("background"))); + mLayers.append(new QCPLayer(this, QLatin1String("grid"))); + mLayers.append(new QCPLayer(this, QLatin1String("main"))); + mLayers.append(new QCPLayer(this, QLatin1String("axes"))); + mLayers.append(new QCPLayer(this, QLatin1String("legend"))); + mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); + updateLayerIndices(); + setCurrentLayer(QLatin1String("main")); + layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); + + // create initial layout, axis rect and legend: + mPlotLayout = new QCPLayoutGrid; + mPlotLayout->initializeParentPlot(this); + mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry + mPlotLayout->setLayer(QLatin1String("main")); + QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); + mPlotLayout->addElement(0, 0, defaultAxisRect); + xAxis = defaultAxisRect->axis(QCPAxis::atBottom); + yAxis = defaultAxisRect->axis(QCPAxis::atLeft); + xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); + yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); + legend = new QCPLegend; + legend->setVisible(false); + defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); + defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); + + defaultAxisRect->setLayer(QLatin1String("background")); + xAxis->setLayer(QLatin1String("axes")); + yAxis->setLayer(QLatin1String("axes")); + xAxis2->setLayer(QLatin1String("axes")); + yAxis2->setLayer(QLatin1String("axes")); + xAxis->grid()->setLayer(QLatin1String("grid")); + yAxis->grid()->setLayer(QLatin1String("grid")); + xAxis2->grid()->setLayer(QLatin1String("grid")); + yAxis2->grid()->setLayer(QLatin1String("grid")); + legend->setLayer(QLatin1String("legend")); + + // create selection rect instance: + mSelectionRect = new QCPSelectionRect(this); + mSelectionRect->setLayer(QLatin1String("overlay")); + + setViewport(rect()); // needs to be called after mPlotLayout has been created + + replot(rpQueuedReplot); +} + +QCustomPlot::~QCustomPlot() +{ + clearPlottables(); + clearItems(); + + if (mPlotLayout) + { + delete mPlotLayout; + mPlotLayout = 0; + } + + mCurrentLayer = 0; + qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed + mLayers.clear(); +} + +/*! + Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is + removed from there. + + \see setNotAntialiasedElements +*/ +void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) +{ + mAntialiasedElements = antialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. + + See \ref setAntialiasedElements for details. + + \see setNotAntialiasedElement +*/ +void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) +{ + if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements &= ~antialiasedElement; + else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements |= antialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets which elements are forcibly drawn not antialiased as an \a or combination of + QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is + removed from there. + + \see setAntialiasedElements +*/ +void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) +{ + mNotAntialiasedElements = notAntialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. + + See \ref setNotAntialiasedElements for details. + + \see setAntialiasedElement +*/ +void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) +{ + if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements &= ~notAntialiasedElement; + else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements |= notAntialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the + plottable to the legend (QCustomPlot::legend). + + \see addGraph, QCPLegend::addItem +*/ +void QCustomPlot::setAutoAddPlottableToLegend(bool on) +{ + mAutoAddPlottableToLegend = on; +} + +/*! + Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction + enums. There are the following types of interactions: + + Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the + respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. + For details how to control which axes the user may drag/zoom and in what orientations, see \ref + QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, + \ref QCPAxisRect::setRangeZoomAxes. + + Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref + QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and + their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the + user can actually select a plottable and its data can further be restricted with the \ref + QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the + special page about the \ref dataselection "data selection mechanism". To retrieve a list of all + currently selected plottables, call \ref selectedPlottables. If you're only interested in + QCPGraphs, you may use the convenience function \ref selectedGraphs. + + Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user + may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find + out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of + all currently selected items, call \ref selectedItems. + + Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user + may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick + labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for + each axis. To retrieve a list of all axes that currently contain selected parts, call \ref + selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). + + Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may + select the legend itself or individual items by clicking on them. What parts exactly are + selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the + legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To + find out which child items are selected, call \ref QCPLegend::selectedItems. + + All other selectable elements The selection of all other selectable objects (e.g. + QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the + user may select those objects by clicking on them. To find out which are currently selected, you + need to check their selected state explicitly. + + If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is + emitted. Each selectable object additionally emits an individual selectionChanged signal whenever + their selection state has changed, i.e. not only by user interaction. + + To allow multiple objects to be selected by holding the selection modifier (\ref + setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. + + \note In addition to the selection mechanism presented here, QCustomPlot always emits + corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and + \ref plottableDoubleClick for example. + + \see setInteraction, setSelectionTolerance +*/ +void QCustomPlot::setInteractions(const QCP::Interactions &interactions) +{ + mInteractions = interactions; +} + +/*! + Sets the single \a interaction of this QCustomPlot to \a enabled. + + For details about the interaction system, see \ref setInteractions. + + \see setInteractions +*/ +void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) +{ + if (!enabled && mInteractions.testFlag(interaction)) + mInteractions &= ~interaction; + else if (enabled && !mInteractions.testFlag(interaction)) + mInteractions |= interaction; +} + +/*! + Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or + not. + + If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a + potential selection when the minimum distance between the click position and the graph line is + smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks + directly inside the area and ignore this selection tolerance. In other words, it only has meaning + for parts of objects that are too thin to exactly hit with a click and thus need such a + tolerance. + + \see setInteractions, QCPLayerable::selectTest +*/ +void QCustomPlot::setSelectionTolerance(int pixels) +{ + mSelectionTolerance = pixels; +} + +/*! + Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes + ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves + performance during dragging. Thus it creates a more responsive user experience. As soon as the + user stops dragging, the last replot is done with normal antialiasing, to restore high image + quality. + + \see setAntialiasedElements, setNotAntialiasedElements +*/ +void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) +{ + mNoAntialiasingOnDrag = enabled; +} + +/*! + Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. + + \see setPlottingHint +*/ +void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) +{ + mPlottingHints = hints; +} + +/*! + Sets the specified plotting \a hint to \a enabled. + + \see setPlottingHints +*/ +void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) +{ + QCP::PlottingHints newHints = mPlottingHints; + if (!enabled) + newHints &= ~hint; + else + newHints |= hint; + + if (newHints != mPlottingHints) + setPlottingHints(newHints); +} + +/*! + Sets the keyboard modifier that will be recognized as multi-select-modifier. + + If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple + objects (or data points) by clicking on them one after the other while holding down \a modifier. + + By default the multi-select-modifier is set to Qt::ControlModifier. + + \see setInteractions +*/ +void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) +{ + mMultiSelectModifier = modifier; +} + +/*! + Sets how QCustomPlot processes mouse click-and-drag interactions by the user. + + If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For + example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref + QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref + selectionRect) becomes activated and allows e.g. rect zooming and data point selection. + + If you wish to provide your user both with axis range dragging and data selection/range zooming, + use this method to switch between the modes just before the interaction is processed, e.g. in + reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether + the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. + + If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the + interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes + will keep the selection rect active. Upon completion of the interaction, the behaviour is as + defined by the currently set \a mode, not the mode that was set when the interaction started. + + \see setInteractions, setSelectionRect, QCPSelectionRect +*/ +void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) +{ + if (mSelectionRect) + { + if (mode == QCP::srmNone) + mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect + + // disconnect old connections: + if (mSelectionRectMode == QCP::srmSelect) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + + // establish new ones: + if (mode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } + + mSelectionRectMode = mode; +} + +/*! + Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref + QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of + the passed \a selectionRect. It can be accessed later via \ref selectionRect. + + This method is useful if you wish to replace the default QCPSelectionRect instance with an + instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. + + \see setSelectionRectMode +*/ +void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) +{ + if (mSelectionRect) + delete mSelectionRect; + + mSelectionRect = selectionRect; + + if (mSelectionRect) + { + // establish connections with new selection rect: + if (mSelectionRectMode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } +} + +/*! + \warning This is still an experimental feature and its performance depends on the system that it + runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering + might cause context conflicts on some systems. + + This method allows to enable OpenGL plot rendering, for increased plotting performance of + graphically demanding plots (thick lines, translucent fills, etc.). + + If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, + continue plotting with hardware acceleration. The parameter \a multisampling controls how many + samples will be used per pixel, it essentially controls the antialiasing quality. If \a + multisampling is set too high for the current graphics hardware, the maximum allowed value will + be used. + + You can test whether switching to OpenGL rendering was successful by checking whether the + according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, + rendering continues with the regular software rasterizer, and an according qDebug output is + generated. + + If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint + "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override + for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a + higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the + OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is + controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching + settings are restored to what they were before OpenGL was enabled, if they weren't altered in the + meantime. + + \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL + defined. This define must be set before including the QCustomPlot header both during compilation + of the QCustomPlot library as well as when compiling your application. It is best to just include + the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. + \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c + QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a + newer OpenGL interface which is already in the "gui" module. +*/ +void QCustomPlot::setOpenGl(bool enabled, int multisampling) +{ + mOpenGlMultisamples = qMax(0, multisampling); +#ifdef QCUSTOMPLOT_USE_OPENGL + mOpenGl = enabled; + if (mOpenGl) + { + if (setupOpenGl()) + { + // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): + setAntialiasedElements(QCP::aeAll); + setPlottingHint(QCP::phCacheLabels, false); + } else + { + qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; + mOpenGl = false; + } + } else + { + // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: + if (mAntialiasedElements == QCP::aeAll) + setAntialiasedElements(mOpenGlAntialiasedElementsBackup); + if (!mPlottingHints.testFlag(QCP::phCacheLabels)) + setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); + freeOpenGl(); + } + // recreate all paint buffers: + mPaintBuffers.clear(); + setupPaintBuffers(); +#else + Q_UNUSED(enabled) + qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; +#endif +} + +/*! + Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the + viewport manually. + + The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take + the viewport to be the outer border of the plot. The viewport normally is the rect() of the + QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. + + Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically + an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger + and contains also the axes themselves, their tick numbers, their labels, or even additional axis + rects, color scales and other layout elements. + + This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref + savePdf, etc. by temporarily changing the viewport size. +*/ +void QCustomPlot::setViewport(const QRect &rect) +{ + mViewport = rect; + if (mPlotLayout) + mPlotLayout->setOuterRect(mViewport); +} + +/*! + Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. + + Normally, this doesn't need to be set manually, because it is initialized with the regular \a + QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal + displays, 2 for High-DPI displays). + + Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called + when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and + leaves the internal buffer device pixel ratio at 1.0. +*/ +void QCustomPlot::setBufferDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBufferDevicePixelRatio = ratio; + for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); + // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mBufferDevicePixelRatio = 1.0; +#endif + } +} + +/*! + Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn + below all other objects in the plot. + + For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is + preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will + first be filled with that brush, before drawing the background pixmap. This can be useful for + background pixmaps with translucent areas. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! + Sets the background brush of the viewport (see \ref setViewport). + + Before drawing everything else, the background is filled with \a brush. If a background pixmap + was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport + before the background pixmap is drawn. This can be useful for background pixmaps with translucent + areas. + + Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be + useful for exporting to image formats which support transparency, e.g. \ref savePng. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the viewport, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is + set to true, control whether and how the aspect ratio of the original pixmap is preserved with + \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the viewport dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCustomPlot::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this + function to define whether and how the aspect ratio of the original pixmap is preserved. + + \see setBackground, setBackgroundScaled +*/ +void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the plottable with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + plottable, see QCustomPlot::plottable() + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + { + return mPlottables.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last plottable that was added to the plot. If there are no plottables in the plot, + returns 0. + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable() +{ + if (!mPlottables.isEmpty()) + { + return mPlottables.last(); + } else + return 0; +} + +/*! + Removes the specified plottable from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). + + Returns true on success. + + \see clearPlottables +*/ +bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); + return false; + } + + // remove plottable from legend: + plottable->removeFromLegend(); + // special handling for QCPGraphs to maintain the simple graph interface: + if (QCPGraph *graph = qobject_cast(plottable)) + mGraphs.removeOne(graph); + // remove plottable: + delete plottable; + mPlottables.removeOne(plottable); + return true; +} + +/*! \overload + + Removes and deletes the plottable by its \a index. +*/ +bool QCustomPlot::removePlottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + return removePlottable(mPlottables[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all plottables from the plot and deletes them. Corresponding legend items are also + removed from the default legend (QCustomPlot::legend). + + Returns the number of plottables removed. + + \see removePlottable +*/ +int QCustomPlot::clearPlottables() +{ + int c = mPlottables.size(); + for (int i=c-1; i >= 0; --i) + removePlottable(mPlottables[i]); + return c; +} + +/*! + Returns the number of currently existing plottables in the plot + + \see plottable +*/ +int QCustomPlot::plottableCount() const +{ + return mPlottables.size(); +} + +/*! + Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. + + There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. + + \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedPlottables() const +{ + QList result; + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (plottable->selected()) + result.append(plottable); + } + return result; +} + +/*! + Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines + (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple + plottables come into consideration, the one closest to \a pos is returned. + + If \a onlySelectable is true, only plottables that are selectable + (QCPAbstractPlottable::setSelectable) are considered. + + If there is no plottable at \a pos, the return value is 0. + + \see itemAt, layoutElementAt +*/ +QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractPlottable *resultPlottable = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable + continue; + if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes + { + double currentDistance = plottable->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultPlottable = plottable; + resultDistance = currentDistance; + } + } + } + + return resultPlottable; +} + +/*! + Returns whether this QCustomPlot instance contains the \a plottable. +*/ +bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const +{ + return mPlottables.contains(plottable); +} + +/*! + Returns the graph with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last created + graph, see QCustomPlot::graph() + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph(int index) const +{ + if (index >= 0 && index < mGraphs.size()) + { + return mGraphs.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, + returns 0. + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph() const +{ + if (!mGraphs.isEmpty()) + { + return mGraphs.last(); + } else + return 0; +} + +/*! + Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the + bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a + keyAxis and \a valueAxis must reside in this QCustomPlot. + + \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically + "y") for the graph. + + Returns a pointer to the newly created graph, or 0 if adding the graph failed. + + \see graph, graphCount, removeGraph, clearGraphs +*/ +QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + if (!keyAxis) keyAxis = xAxis; + if (!valueAxis) valueAxis = yAxis; + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; + return 0; + } + if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; + return 0; + } + + QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); + newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); + return newGraph; +} + +/*! + Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in + the plot have a channel fill set towards the removed graph, the channel fill property of those + graphs is reset to zero (no channel fill). + + Returns true on success. + + \see clearGraphs +*/ +bool QCustomPlot::removeGraph(QCPGraph *graph) +{ + return removePlottable(graph); +} + +/*! \overload + + Removes and deletes the graph by its \a index. +*/ +bool QCustomPlot::removeGraph(int index) +{ + if (index >= 0 && index < mGraphs.size()) + return removeGraph(mGraphs[index]); + else + return false; +} + +/*! + Removes all graphs from the plot and deletes them. Corresponding legend items are also removed + from the default legend (QCustomPlot::legend). + + Returns the number of graphs removed. + + \see removeGraph +*/ +int QCustomPlot::clearGraphs() +{ + int c = mGraphs.size(); + for (int i=c-1; i >= 0; --i) + removeGraph(mGraphs[i]); + return c; +} + +/*! + Returns the number of currently existing graphs in the plot + + \see graph, addGraph +*/ +int QCustomPlot::graphCount() const +{ + return mGraphs.size(); +} + +/*! + Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. + + If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, + etc., use \ref selectedPlottables. + + \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedGraphs() const +{ + QList result; + Q_FOREACH (QCPGraph *graph, mGraphs) + { + if (graph->selected()) + result.append(graph); + } + return result; +} + +/*! + Returns the item with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + item, see QCustomPlot::item() + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item(int index) const +{ + if (index >= 0 && index < mItems.size()) + { + return mItems.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last item that was added to this plot. If there are no items in the plot, + returns 0. + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item() const +{ + if (!mItems.isEmpty()) + { + return mItems.last(); + } else + return 0; +} + +/*! + Removes the specified item from the plot and deletes it. + + Returns true on success. + + \see clearItems +*/ +bool QCustomPlot::removeItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + delete item; + mItems.removeOne(item); + return true; + } else + { + qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); + return false; + } +} + +/*! \overload + + Removes and deletes the item by its \a index. +*/ +bool QCustomPlot::removeItem(int index) +{ + if (index >= 0 && index < mItems.size()) + return removeItem(mItems[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all items from the plot and deletes them. + + Returns the number of items removed. + + \see removeItem +*/ +int QCustomPlot::clearItems() +{ + int c = mItems.size(); + for (int i=c-1; i >= 0; --i) + removeItem(mItems[i]); + return c; +} + +/*! + Returns the number of currently existing items in the plot + + \see item +*/ +int QCustomPlot::itemCount() const +{ + return mItems.size(); +} + +/*! + Returns a list of the selected items. If no items are currently selected, the list is empty. + + \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected +*/ +QList QCustomPlot::selectedItems() const +{ + QList result; + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (item->selected()) + result.append(item); + } + return result; +} + +/*! + Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref + QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref + setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is + returned. + + If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are + considered. + + If there is no item at \a pos, the return value is 0. + + \see plottableAt, layoutElementAt +*/ +QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractItem *resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + continue; + if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it + { + double currentDistance = item->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultItem = item; + resultDistance = currentDistance; + } + } + } + + return resultItem; +} + +/*! + Returns whether this QCustomPlot contains the \a item. + + \see item +*/ +bool QCustomPlot::hasItem(QCPAbstractItem *item) const +{ + return mItems.contains(item); +} + +/*! + Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is + returned. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(const QString &name) const +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + if (layer->name() == name) + return layer; + } + return 0; +} + +/*! \overload + + Returns the layer by \a index. If the index is invalid, 0 is returned. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(int index) const +{ + if (index >= 0 && index < mLayers.size()) + { + return mLayers.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Returns the layer that is set as current layer (see \ref setCurrentLayer). +*/ +QCPLayer *QCustomPlot::currentLayer() const +{ + return mCurrentLayer; +} + +/*! + Sets the layer with the specified \a name to be the current layer. All layerables (\ref + QCPLayerable), e.g. plottables and items, are created on the current layer. + + Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer +*/ +bool QCustomPlot::setCurrentLayer(const QString &name) +{ + if (QCPLayer *newCurrentLayer = layer(name)) + { + return setCurrentLayer(newCurrentLayer); + } else + { + qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; + return false; + } +} + +/*! \overload + + Sets the provided \a layer to be the current layer. + + Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. + + \see addLayer, moveLayer, removeLayer +*/ +bool QCustomPlot::setCurrentLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + + mCurrentLayer = layer; + return true; +} + +/*! + Returns the number of currently existing layers in the plot + + \see layer, addLayer +*/ +int QCustomPlot::layerCount() const +{ + return mLayers.size(); +} + +/*! + Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which + must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. + + Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a + valid layer inside this QCustomPlot. + + If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. + + For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. + + \see layer, moveLayer, removeLayer +*/ +bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!otherLayer) + otherLayer = mLayers.last(); + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + if (layer(name)) + { + qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; + return false; + } + + QCPLayer *newLayer = new QCPLayer(this, name); + mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); + updateLayerIndices(); + setupPaintBuffers(); // associates new layer with the appropriate paint buffer + return true; +} + +/*! + Removes the specified \a layer and returns true on success. + + All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below + \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both + cases, the total rendering order of all layerables in the QCustomPlot is preserved. + + If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom + layer) becomes the new current layer. + + It is not possible to remove the last layer of the plot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::removeLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (mLayers.size() < 2) + { + qDebug() << Q_FUNC_INFO << "can't remove last layer"; + return false; + } + + // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) + int removedIndex = layer->index(); + bool isFirstLayer = removedIndex==0; + QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); + QList children = layer->children(); + if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) + { + for (int i=children.size()-1; i>=0; --i) + children.at(i)->moveToLayer(targetLayer, true); + } else // append normally + { + for (int i=0; imoveToLayer(targetLayer, false); + } + // if removed layer is current layer, change current layer to layer below/above: + if (layer == mCurrentLayer) + setCurrentLayer(targetLayer); + // invalidate the paint buffer that was responsible for this layer: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + // remove layer: + delete layer; + mLayers.removeOne(layer); + updateLayerIndices(); + return true; +} + +/*! + Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or + below is controlled with \a insertMode. + + Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the + QCustomPlot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + + if (layer->index() > otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); + else if (layer->index() < otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); + + // invalidate the paint buffers that are responsible for the layers: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + if (!otherLayer->mPaintBuffer.isNull()) + otherLayer->mPaintBuffer.data()->setInvalidated(); + + updateLayerIndices(); + return true; +} + +/*! + Returns the number of axis rects in the plot. + + All axis rects can be accessed via QCustomPlot::axisRect(). + + Initially, only one axis rect exists in the plot. + + \see axisRect, axisRects +*/ +int QCustomPlot::axisRectCount() const +{ + return axisRects().size(); +} + +/*! + Returns the axis rect with \a index. + + Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were + added, all of them may be accessed with this function in a linear fashion (even when they are + nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). + + \see axisRectCount, axisRects +*/ +QCPAxisRect *QCustomPlot::axisRect(int index) const +{ + const QList rectList = axisRects(); + if (index >= 0 && index < rectList.size()) + { + return rectList.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; + return 0; + } +} + +/*! + Returns all axis rects in the plot. + + \see axisRectCount, axisRect +*/ +QList QCustomPlot::axisRects() const +{ + QList result; + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) + { + if (element) + { + elementStack.push(element); + if (QCPAxisRect *ar = qobject_cast(element)) + result.append(ar); + } + } + } + + return result; +} + +/*! + Returns the layout element at pixel position \a pos. If there is no element at that position, + returns 0. + + Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on + any of its parent elements is set to false, it will not be considered. + + \see itemAt, plottableAt +*/ +QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const +{ + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + break; + } + } + } + return currentElement; +} + +/*! + Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores + other layout elements even if they are visually in front of the axis rect (e.g. a \ref + QCPLegend). If there is no axis rect at that position, returns 0. + + Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or + on any of its parent elements is set to false, it will not be considered. + + \see layoutElementAt +*/ +QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const +{ + QCPAxisRect *result = 0; + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + if (QCPAxisRect *ar = qobject_cast(currentElement)) + result = ar; + break; + } + } + } + return result; +} + +/*! + Returns the axes that currently have selected parts, i.e. whose selection state is not \ref + QCPAxis::spNone. + + \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, + QCPAxis::setSelectableParts +*/ +QList QCustomPlot::selectedAxes() const +{ + QList result, allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + { + if (axis->selectedParts() != QCPAxis::spNone) + result.append(axis); + } + + return result; +} + +/*! + Returns the legends that currently have selected parts, i.e. whose selection state is not \ref + QCPLegend::spNone. + + \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, + QCPLegend::setSelectableParts, QCPLegend::selectedItems +*/ +QList QCustomPlot::selectedLegends() const +{ + QList result; + + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) + { + if (subElement) + { + elementStack.push(subElement); + if (QCPLegend *leg = qobject_cast(subElement)) + { + if (leg->selectedParts() != QCPLegend::spNone) + result.append(leg); + } + } + } + } + + return result; +} + +/*! + Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. + + Since calling this function is not a user interaction, this does not emit the \ref + selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the + objects were previously selected. + + \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends +*/ +void QCustomPlot::deselectAll() +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + layerable->deselectEvent(0); + } +} + +/*! + Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is + refreshed with the new buffer contents. This is the method that must be called to make changes to + the plot, e.g. on the axis ranges or data points of graphs, visible. + + The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example + if your application calls \ref replot very quickly in succession (e.g. multiple independent + functions change some aspects of the plot and each wants to make sure the change gets replotted), + it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the + actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref + replot with this priority will only cause a single replot, avoiding redundant replots and + improving performance. + + Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the + QCustomPlot widget and user interactions (object selection and range dragging/zooming). + + Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref + afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two + signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite + recursion. + + If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to + replot only that specific layer via \ref QCPLayer::replot. See the documentation there for + details. +*/ +void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) +{ + if (refreshPriority == QCustomPlot::rpQueuedReplot) + { + if (!mReplotQueued) + { + mReplotQueued = true; + QTimer::singleShot(0, this, SLOT(replot())); + } + return; + } + + if (mReplotting) // incase signals loop back to replot slot + return; + mReplotting = true; + mReplotQueued = false; + Q_EMIT beforeReplot(); + + updateLayout(); + // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: + setupPaintBuffers(); + Q_FOREACH (QCPLayer *layer, mLayers) + layer->drawToPaintBuffer(); + for (int i=0; isetInvalidated(false); + + if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) + repaint(); + else + update(); + + Q_EMIT afterReplot(); + mReplotting = false; +} + +/*! + Rescales the axes such that all plottables (like graphs) in the plot are fully visible. + + if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true + (QCPLayerable::setVisible), will be used to rescale the axes. + + \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale +*/ +void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) +{ + QList allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + axis->rescale(onlyVisiblePlottables); +} + +/*! + Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale + of texts and lines will be derived from the specified \a width and \a height. This means, the + output will look like the normal on-screen output of a QCustomPlot widget with the corresponding + pixel width and height. If either \a width or \a height is zero, the exported image will have the + same dimensions as the QCustomPlot widget currently has. + + Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when + drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as + a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information + about cosmetic pens, see the QPainter and QPen documentation. + + The objects of the plot will appear in the current selection state. If you don't want any + selected objects to be painted in their selected look, deselect everything with \ref deselectAll + before calling this function. + + Returns true on success. + + \warning + \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it + is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines + (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). + \li If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting + PDF file. + + \note On Android systems, this method does nothing and issues an according qDebug warning + message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. + + \see savePng, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) +{ + bool success = false; +#ifdef QT_NO_PRINTER + Q_UNUSED(fileName) + Q_UNUSED(exportPen) + Q_UNUSED(width) + Q_UNUSED(height) + Q_UNUSED(pdfCreator) + Q_UNUSED(pdfTitle) + qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; +#else + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFileName(fileName); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); + printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + printer.setFullPage(true); + printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); +#else + QPageLayout pageLayout; + pageLayout.setMode(QPageLayout::FullPageMode); + pageLayout.setOrientation(QPageLayout::Portrait); + pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); + pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); + printer.setPageLayout(pageLayout); +#endif + QCPPainter printpainter; + if (printpainter.begin(&printer)) + { + printpainter.setMode(QCPPainter::pmVectorized); + printpainter.setMode(QCPPainter::pmNoCaching); + printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); + printpainter.setWindow(mViewport); + if (mBackgroundBrush.style() != Qt::NoBrush && + mBackgroundBrush.color() != Qt::white && + mBackgroundBrush.color() != Qt::transparent && + mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent + printpainter.fillRect(viewport(), mBackgroundBrush); + draw(&printpainter); + printpainter.end(); + success = true; + } + setViewport(oldViewport); +#endif // QT_NO_PRINTER + return success; +} + +/*! + Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the PNG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) + with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); +} + +/*! + Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the JPEG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveBmp, saveRastered +*/ +bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); +} + +/*! + Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the BMP format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveJpg, saveRastered +*/ +bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); +} + +/*! \internal + + Returns a minimum size hint that corresponds to the minimum size of the top level layout + (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum + size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. + This is especially important, when placed in a QLayout where other components try to take in as + much space as possible (e.g. QMdiArea). +*/ +QSize QCustomPlot::minimumSizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Returns a size hint that is the same as \ref minimumSizeHint. + +*/ +QSize QCustomPlot::sizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but + draws the internal buffer on the widget surface. +*/ +void QCustomPlot::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QCPPainter painter(this); + if (painter.isActive()) + { + painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem + if (mBackgroundBrush.style() != Qt::NoBrush) + painter.fillRect(mViewport, mBackgroundBrush); + drawBackground(&painter); + for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) + mPaintBuffers.at(bufferIndex)->draw(&painter); + } +} + +/*! \internal + + Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect + of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. +*/ +void QCustomPlot::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + // resize and repaint the buffer: + setViewport(rect()); + replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) +} + +/*! \internal + + Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then + determines the layerable under the cursor and forwards the event to it. Finally, emits the + specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref + axisDoubleClick, etc.). + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_EMIT mouseDoubleClick(event); + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + // determine layerable under the cursor (this event is called instead of the second press event in a double-click): + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + + // emit specialized object double click signals: + if (!candidates.isEmpty()) + { + if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) + { + int dataIndex = 0; + if (!details.first().value().isEmpty()) + dataIndex = details.first().value().dataRange().begin(); + Q_EMIT plottableDoubleClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(candidates.first())) + Q_EMIT axisDoubleClick(ax, details.first().value(), event); + else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) + Q_EMIT itemDoubleClick(ai, event); + else if (QCPLegend *lg = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(li->parentLegend(), li, event); + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is pressed. Emits the mousePress signal. + + If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the + selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCustomPlot::mousePressEvent(QMouseEvent *event) +{ + Q_EMIT mousePress(event); + // save some state to tell in releaseEvent whether it was a click: + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + if (mSelectionRect && mSelectionRectMode != QCP::srmNone) + { + if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect + mSelectionRect->startSelection(event); + } else + { + // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + if (!candidates.isEmpty()) + { + mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) + mMouseSignalLayerableDetails = details.first(); + } + // forward event to topmost candidate which accepts the event: + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list + candidates.at(i)->mousePressEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when the cursor is moved. Emits the \ref mouseMove signal. + + If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it + in order to update the rect geometry. + + Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the + layout element before), the mouseMoveEvent is forwarded to that element. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseMoveEvent(QMouseEvent *event) +{ + Q_EMIT mouseMove(event); + + if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) + mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release + + if (mSelectionRect && mSelectionRect->isActive()) + mSelectionRect->moveSelection(event); + else if (mMouseEventLayerable) // call event of affected layerable: + mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. + + If the mouse was moved less than a certain threshold in any direction since the \ref + mousePressEvent, it is considered a click which causes the selection mechanism (if activated via + \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse + click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) + + If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable + before), the \ref mouseReleaseEvent is forwarded to that element. + + \see mousePressEvent, mouseMoveEvent +*/ +void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) +{ + Q_EMIT mouseRelease(event); + + if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click + { + if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here + mSelectionRect->cancel(); + if (event->button() == Qt::LeftButton) + processPointSelection(event); + + // emit specialized click signals of QCustomPlot instance: + if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) + { + int dataIndex = 0; + if (!mMouseSignalLayerableDetails.value().isEmpty()) + dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); + Q_EMIT plottableClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) + Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); + else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) + Q_EMIT itemClick(ai, event); + else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(li->parentLegend(), li, event); + mMouseSignalLayerable = 0; + } + + if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there + { + // finish selection rect, the appropriate action will be taken via signal-slot connection: + mSelectionRect->endSelection(event); + } else + { + // call event of affected layerable: + if (mMouseEventLayerable) + { + mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); + mMouseEventLayerable = 0; + } + } + + if (noAntialiasingOnDrag()) + replot(rpQueuedReplot); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then + determines the affected layerable and forwards the event to it. +*/ +void QCustomPlot::wheelEvent(QWheelEvent *event) +{ + Q_EMIT mouseWheel(event); + // forward event to layerable under cursor: + QList candidates = layerableListAt(event->pos(), false); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->wheelEvent(event); + if (event->isAccepted()) + break; + } + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + This function draws the entire plot, including background pixmap, with the specified \a painter. + It does not make use of the paint buffers like \ref replot, so this is the function typically + used by saving/exporting methods such as \ref savePdf or \ref toPainter. + + Note that it does not fill the background with the background brush (as the user may specify with + \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this + method. +*/ +void QCustomPlot::draw(QCPPainter *painter) +{ + updateLayout(); + + // draw viewport background pixmap: + drawBackground(painter); + + // draw all layered objects (grid, axes, plottables, items, legend,...): + Q_FOREACH (QCPLayer *layer, mLayers) + layer->draw(painter); + + /* Debug code to draw all layout element rects + foreach (QCPLayoutElement* el, findChildren()) + { + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->rect()); + painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->outerRect()); + } + */ +} + +/*! \internal + + Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref + QCPLayoutElement::update on the main plot layout. + + Here, the layout elements calculate their positions and margins, and prepare for the following + draw call. +*/ +void QCustomPlot::updateLayout() +{ + // run through layout phases: + mPlotLayout->update(QCPLayoutElement::upPreparation); + mPlotLayout->update(QCPLayoutElement::upMargins); + mPlotLayout->update(QCPLayoutElement::upLayout); +} + +/*! \internal + + Draws the viewport background pixmap of the plot. + + If a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the viewport with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + Note that this function does not draw a fill with the background brush + (\ref setBackground(const QBrush &brush)) beneath the pixmap. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::drawBackground(QCPPainter *painter) +{ + // Note: background color is handled in individual replot/save functions + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mViewport.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); + } + } +} + +/*! \internal + + Goes through the layers and makes sure this QCustomPlot instance holds the correct number of + paint buffers and that they have the correct configuration (size, pixel ratio, etc.). + Allocations, reallocations and deletions of paint buffers are performed as necessary. It also + associates the paint buffers with the layers, so they draw themselves into the right buffer when + \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref + QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for + layers in \ref QCPLayer::lmBuffered mode. + + This method uses \ref createPaintBuffer to create new paint buffers. + + After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated + (so an attempt to replot only a single buffered layer causes a full replot). + + This method is called in every \ref replot call, prior to actually drawing the layers (into their + associated paint buffer). If the paint buffers don't need changing/reallocating, this method + basically leaves them alone and thus finishes very fast. +*/ +void QCustomPlot::setupPaintBuffers() +{ + int bufferIndex = 0; + if (mPaintBuffers.isEmpty()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + + for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) + { + QCPLayer *layer = mLayers.at(layerIndex); + if (layer->mode() == QCPLayer::lmLogical) + { + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + } else if (layer->mode() == QCPLayer::lmBuffered) + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + } + } + } + // remove unneeded buffers: + while (mPaintBuffers.size()-1 > bufferIndex) + mPaintBuffers.removeLast(); + // resize buffers to viewport size and clear contents: + for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size + mPaintBuffers.at(i)->clear(Qt::transparent); + mPaintBuffers.at(i)->setInvalidated(); + } +} + +/*! \internal + + This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. + + Depending on the current setting of \ref setOpenGl, and the current Qt version, different + backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper + size and device pixel ratio, and returned. +*/ +QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() +{ + if (mOpenGl) + { +#if defined(QCP_OPENGL_FBO) + return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); +#elif defined(QCP_OPENGL_PBUFFER) + return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); +#else + qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +#endif + } else + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +} + +/*! + This method returns whether any of the paint buffers held by this QCustomPlot instance are + invalidated. + + If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always + causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example + the layer order has changed, new layers were added, layers were removed, or layer modes were + changed (\ref QCPLayer::setMode). + + \see QCPAbstractPaintBuffer::setInvalidated +*/ +bool QCustomPlot::hasInvalidatedPaintBuffers() +{ + for (int i=0; iinvalidated()) + return true; + } + return false; +} + +/*! \internal + + When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, + surface, paint device). + + Returns true on success. + + If this method is successful, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref + QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. + + \see freeOpenGl +*/ +bool QCustomPlot::setupOpenGl() +{ +#ifdef QCP_OPENGL_FBO + freeOpenGl(); + QSurfaceFormat proposedSurfaceFormat; + proposedSurfaceFormat.setSamples(mOpenGlMultisamples); +#ifdef QCP_OPENGL_OFFSCREENSURFACE + QOffscreenSurface *surface = new QOffscreenSurface; +#else + QWindow *surface = new QWindow; + surface->setSurfaceType(QSurface::OpenGLSurface); +#endif + surface->setFormat(proposedSurfaceFormat); + surface->create(); + mGlSurface = QSharedPointer(surface); + mGlContext = QSharedPointer(new QOpenGLContext); + mGlContext->setFormat(mGlSurface->format()); + if (!mGlContext->create()) + { + qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device + { + qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + { + qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); + return true; +#elif defined(QCP_OPENGL_PBUFFER) + return QGLFormat::hasOpenGL(); +#else + return false; +#endif +} + +/*! \internal + + When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the + context and frees resources). + + After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref + QCPPaintBufferPixmap) is used for subsequent replots. + + \see setupOpenGl +*/ +void QCustomPlot::freeOpenGl() +{ +#ifdef QCP_OPENGL_FBO + mGlPaintDevice.clear(); + mGlContext.clear(); + mGlSurface.clear(); +#endif +} + +/*! \internal + + This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot + so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. +*/ +void QCustomPlot::axisRemoved(QCPAxis *axis) +{ + if (xAxis == axis) + xAxis = 0; + if (xAxis2 == axis) + xAxis2 = 0; + if (yAxis == axis) + yAxis = 0; + if (yAxis2 == axis) + yAxis2 = 0; + + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers +} + +/*! \internal + + This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so + it may clear its QCustomPlot::legend member accordingly. +*/ +void QCustomPlot::legendRemoved(QCPLegend *legend) +{ + if (this->legend == legend) + this->legend = 0; +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmSelect. + + First, it determines which axis rect was the origin of the selection rect judging by the starting + point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be + precise) associated with that axis rect and finds the data points that are in \a rect. It does + this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. + + Then, the actual selection is done by calling the plottables' \ref + QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details + parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a + rect receive a \ref QCPAbstractPlottable::deselectEvent. + + \see processRectZoom +*/ +void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) +{ + bool selectionStateChanged = false; + + if (mInteractions.testFlag(QCP::iSelectPlottables)) + { + QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size + QRectF rectF(rect.normalized()); + if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) + { + // determine plottables that were hit by the rect and thus are candidates for selection: + Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) + { + if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) + { + QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); + if (!dataSel.isEmpty()) + potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); + } + } + + if (!mInteractions.testFlag(QCP::iMultiSelect)) + { + // only leave plottable with most selected points in map, since we will only select a single plottable: + if (!potentialSelections.isEmpty()) + { + QMap >::iterator it = potentialSelections.begin(); + while (it != potentialSelections.end()-1) // erase all except last element + it = potentialSelections.erase(it); + } + } + + bool additive = event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + // emit deselection except to those plottables who will be selected afterwards: + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + // go through selections in reverse (largest selection first) and emit select events: + QMap >::const_iterator it = potentialSelections.constEnd(); + while (it != potentialSelections.constBegin()) + { + --it; + if (mInteractions.testFlag(it.value().first->selectionCategory())) + { + bool selChanged = false; + it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } else if (mSelectionRect) + mSelectionRect->layer()->replot(); +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmZoom. + + It determines which axis rect was the origin of the selection rect judging by the starting point + of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the + provided \a rect (see \ref QCPAxisRect::zoom). + + \see processRectSelection +*/ +void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) +{ + Q_UNUSED(event) + if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) + { + QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); + affectedAxes.removeAll(static_cast(0)); + axisRect->zoom(QRectF(rect), affectedAxes); + } + replot(rpQueuedReplot); // always replot to make selection rect disappear +} + +/*! \internal + + This method is called when a simple left mouse click was detected on the QCustomPlot surface. + + It first determines the layerable that was hit by the click, and then calls its \ref + QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the + multi-select modifier was pressed, see \ref setMultiSelectModifier). + + In this method the hit layerable is determined a second time using \ref layerableAt (after the + one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This + implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the + clicked layerable determined here. For example, if a non-selectable layerable is in front of a + selectable layerable at the click position, the front layerable will receive mouse events but the + selectable one in the back will receive the \ref QCPLayerable::selectEvent. + + \see processRectSelection, QCPLayerable::selectTest +*/ +void QCustomPlot::processPointSelection(QMouseEvent *event) +{ + QVariant details; + QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); + bool selectionStateChanged = false; + bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) + { + // a layerable was actually clicked, call its selectEvent: + bool selChanged = false; + clickedLayerable->selectEvent(event, additive, details, &selChanged); + selectionStateChanged |= selChanged; + } + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } +} + +/*! \internal + + Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend + is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the + plottable. + + Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of + \a plottable is this QCustomPlot. + + This method is called automatically in the QCPAbstractPlottable base class constructor. +*/ +bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) +{ + if (mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); + return false; + } + if (plottable->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); + return false; + } + + mPlottables.append(plottable); + // possibly add plottable to legend: + if (mAutoAddPlottableToLegend) + plottable->addToLegend(); + if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + plottable->setLayer(currentLayer()); + return true; +} + +/*! \internal + + In order to maintain the simplified graph interface of QCustomPlot, this method is called by the + QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true + on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. + + This graph specific registration happens in addition to the call to \ref registerPlottable by the + QCPAbstractPlottable base class. +*/ +bool QCustomPlot::registerGraph(QCPGraph *graph) +{ + if (!graph) + { + qDebug() << Q_FUNC_INFO << "passed graph is zero"; + return false; + } + if (mGraphs.contains(graph)) + { + qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; + return false; + } + + mGraphs.append(graph); + return true; +} + + +/*! \internal + + Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. + + Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a + item is this QCustomPlot. + + This method is called automatically in the QCPAbstractItem base class constructor. +*/ +bool QCustomPlot::registerItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); + return false; + } + if (item->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); + return false; + } + + mItems.append(item); + if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) + item->setLayer(currentLayer()); + return true; +} + +/*! \internal + + Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called + after every operation that changes the layer indices, like layer removal, layer creation, layer + moving. +*/ +void QCustomPlot::updateLayerIndices() const +{ + for (int i=0; imIndex = i; +} + +/*! \internal + + Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, + only those layerables that are selectable will be considered. (Layerable subclasses communicate + their selectability via the QCPLayerable::selectTest method, by returning -1.) + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableListAt, layoutElementAt, axisRectAt +*/ +QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const +{ + QList details; + QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); + if (selectionDetails && !details.isEmpty()) + *selectionDetails = details.first(); + if (!candidates.isEmpty()) + return candidates.first(); + else + return 0; +} + +/*! \internal + + Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those + layerables that are selectable will be considered. (Layerable subclasses communicate their + selectability via the QCPLayerable::selectTest method, by returning -1.) + + The returned list is sorted by the layerable/drawing order. If you only need to know the top-most + layerable, rather use \ref layerableAt. + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableAt, layoutElementAt, axisRectAt +*/ +QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const +{ + QList result; + for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) + { + const QList layerables = mLayers.at(layerIndex)->children(); + for (int i=layerables.size()-1; i>=0; --i) + { + if (!layerables.at(i)->realVisibility()) + continue; + QVariant details; + double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); + if (dist >= 0 && dist < selectionTolerance()) + { + result.append(layerables.at(i)); + if (selectionDetails) + selectionDetails->append(details); + } + } + } + return result; +} + +/*! + Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is + sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead + to a full resolution file with width 200.) If the \a format supports compression, \a quality may + be between 0 and 100 to control it. + + Returns true on success. If this function fails, most likely the given \a format isn't supported + by the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The \a resolution will be written to the image file header (if the file format supports this) and + has no direct consequence for the quality or the pixel size. However, if opening the image with a + tool which respects the metadata, it will be able to scale the image to match either a given size + in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in + which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted + to the format's expected resolution unit internally. + + \see saveBmp, saveJpg, savePng, savePdf +*/ +bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + QImage buffer = toPixmap(width, height, scale).toImage(); + + int dotsPerMeter = 0; + switch (resolutionUnit) + { + case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; + case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; + case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; + } + buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + if (!buffer.isNull()) + return buffer.save(fileName, format, quality); + else + return false; +} + +/*! + Renders the plot to a pixmap and returns it. + + The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and + scale 2.0 lead to a full resolution pixmap with width 200.) + + \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf +*/ +QPixmap QCustomPlot::toPixmap(int width, int height, double scale) +{ + // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + int scaledWidth = qRound(scale*newWidth); + int scaledHeight = qRound(scale*newHeight); + + QPixmap result(scaledWidth, scaledHeight); + result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later + QCPPainter painter; + painter.begin(&result); + if (painter.isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter.setMode(QCPPainter::pmNoCaching); + if (!qFuzzyCompare(scale, 1.0)) + { + if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales + painter.setMode(QCPPainter::pmNonCosmetic); + painter.scale(scale, scale); + } + if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill + painter.fillRect(mViewport, mBackgroundBrush); + draw(&painter); + setViewport(oldViewport); + painter.end(); + } else // might happen if pixmap has width or height zero + { + qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; + return QPixmap(); + } + return result; +} + +/*! + Renders the plot using the passed \a painter. + + The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will + appear scaled accordingly. + + \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter + on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with + the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. + + \see toPixmap +*/ +void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) +{ + // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + if (painter->isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter->setMode(QCPPainter::pmNoCaching); + if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here + painter->fillRect(mViewport, mBackgroundBrush); + draw(painter); + setViewport(oldViewport); + } else + qDebug() << Q_FUNC_INFO << "Passed painter is not active"; +} +/* end of 'src/core.cpp' */ + +//amalgamation: add plottable1d.cpp + +/* including file 'src/colorgradient.cpp', size 24646 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorGradient +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorGradient + \brief Defines a color gradient for use with e.g. \ref QCPColorMap + + This class describes a color gradient which can be used to encode data with color. For example, + QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which + take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) + with a \a position from 0 to 1. In between these defined color positions, the + color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. + + Alternatively, load one of the preset color gradients shown in the image below, with \ref + loadPreset, or by directly specifying the preset in the constructor. + + Apart from red, green and blue components, the gradient also interpolates the alpha values of the + configured color stops. This allows to display some portions of the data range as transparent in + the plot. + + \image html QCPColorGradient.png + + The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref + GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset + to all the \a setGradient methods, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient + + The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the + color gradient shall be applied periodically (wrapping around) to data values that lie outside + the data range specified on the plottable instance can be controlled with \ref setPeriodic. +*/ + +/*! + Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color + stops with \ref setColorStopAt. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient() : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); +} + +/*! + Constructs a new QCPColorGradient initialized with the colors and color interpolation according + to \a preset. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient(GradientPreset preset) : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); + loadPreset(preset); +} + +/* undocumented operator */ +bool QCPColorGradient::operator==(const QCPColorGradient &other) const +{ + return ((other.mLevelCount == this->mLevelCount) && + (other.mColorInterpolation == this->mColorInterpolation) && + (other.mPeriodic == this->mPeriodic) && + (other.mColorStops == this->mColorStops)); +} + +/*! + Sets the number of discretization levels of the color gradient to \a n. The default is 350 which + is typically enough to create a smooth appearance. The minimum number of levels is 2. + + \image html QCPColorGradient-levelcount.png +*/ +void QCPColorGradient::setLevelCount(int n) +{ + if (n < 2) + { + qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; + n = 2; + } + if (n != mLevelCount) + { + mLevelCount = n; + mColorBufferInvalidated = true; + } +} + +/*! + Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the + colors are the values of the passed QMap \a colorStops. In between these color stops, the color + is interpolated according to \ref setColorInterpolation. + + A more convenient way to create a custom gradient may be to clear all color stops with \ref + clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with + \ref setColorStopAt. + + \see clearColorStops +*/ +void QCPColorGradient::setColorStops(const QMap &colorStops) +{ + mColorStops = colorStops; + mColorBufferInvalidated = true; +} + +/*! + Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between + these color stops, the color is interpolated according to \ref setColorInterpolation. + + \see setColorStops, clearColorStops +*/ +void QCPColorGradient::setColorStopAt(double position, const QColor &color) +{ + mColorStops.insert(position, color); + mColorBufferInvalidated = true; +} + +/*! + Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be + interpolated linearly in RGB or in HSV color space. + + For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, + whereas in HSV space the intermediate color is yellow. +*/ +void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) +{ + if (interpolation != mColorInterpolation) + { + mColorInterpolation = interpolation; + mColorBufferInvalidated = true; + } +} + +/*! + Sets whether data points that are outside the configured data range (e.g. \ref + QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether + they all have the same color, corresponding to the respective gradient boundary color. + + \image html QCPColorGradient-periodic.png + + As shown in the image above, gradients that have the same start and end color are especially + suitable for a periodic gradient mapping, since they produce smooth color transitions throughout + the color map. A preset that has this property is \ref gpHues. + + In practice, using periodic color gradients makes sense when the data corresponds to a periodic + dimension, such as an angle or a phase. If this is not the case, the color encoding might become + ambiguous, because multiple different data values are shown as the same color. +*/ +void QCPColorGradient::setPeriodic(bool enabled) +{ + mPeriodic = enabled; +} + +/*! \overload + + This method is used to quickly convert a \a data array to colors. The colors will be output in + the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this + function. The data range that shall be used for mapping the data value to the gradient is passed + in \a range. \a logarithmic indicates whether the data values shall be mapped to colors + logarithmically. + + if \a data actually contains 2D-data linearized via [row*columnCount + column], you can + set \a dataIndexFactor to columnCount to convert a column instead of a row of the data + array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data + is addressed data[i*dataIndexFactor]. + + Use the overloaded method to additionally provide alpha map data. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } +} + +/*! \overload + + Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which + has the same size and structure as \a data and encodes the alpha information per data point. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!alpha) + { + qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } +} + +/*! \internal + + This method is used to colorize a single data value given in \a position, to colors. The data + range that shall be used for mapping the data value to the gradient is passed in \a range. \a + logarithmic indicates whether the data value shall be mapped to a color logarithmically. + + If an entire array of data values shall be converted, rather use \ref colorize, for better + performance. + + The returned QRgb has its r, g and b components premultiplied with alpha (see + QImage::Format_ARGB32_Premultiplied). +*/ +QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) +{ + // If you change something here, make sure to also adapt ::colorize() + if (mColorBufferInvalidated) + updateColorBuffer(); + int index = 0; + if (!logarithmic) + index = (position-range.lower)*(mLevelCount-1)/range.size(); + else + index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); + if (mPeriodic) + { + index = index % mLevelCount; + if (index < 0) + index += mLevelCount; + } else + { + if (index < 0) + index = 0; + else if (index >= mLevelCount) + index = mLevelCount-1; + } + return mColorBuffer.at(index); +} + +/*! + Clears the current color stops and loads the specified \a preset. A preset consists of predefined + color stops and the corresponding color interpolation method. + + The available presets are: + \image html QCPColorGradient.png +*/ +void QCPColorGradient::loadPreset(GradientPreset preset) +{ + clearColorStops(); + switch (preset) + { + case gpGrayscale: + setColorInterpolation(ciRGB); + setColorStopAt(0, Qt::black); + setColorStopAt(1, Qt::white); + break; + case gpHot: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 0, 0)); + setColorStopAt(0.2, QColor(180, 10, 0)); + setColorStopAt(0.4, QColor(245, 50, 0)); + setColorStopAt(0.6, QColor(255, 150, 10)); + setColorStopAt(0.8, QColor(255, 255, 50)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpCold: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.2, QColor(0, 10, 180)); + setColorStopAt(0.4, QColor(0, 50, 245)); + setColorStopAt(0.6, QColor(10, 150, 255)); + setColorStopAt(0.8, QColor(50, 255, 255)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpNight: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(10, 20, 30)); + setColorStopAt(1, QColor(250, 255, 250)); + break; + case gpCandy: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(0, 0, 255)); + setColorStopAt(1, QColor(255, 250, 250)); + break; + case gpGeography: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(70, 170, 210)); + setColorStopAt(0.20, QColor(90, 160, 180)); + setColorStopAt(0.25, QColor(45, 130, 175)); + setColorStopAt(0.30, QColor(100, 140, 125)); + setColorStopAt(0.5, QColor(100, 140, 100)); + setColorStopAt(0.6, QColor(130, 145, 120)); + setColorStopAt(0.7, QColor(140, 130, 120)); + setColorStopAt(0.9, QColor(180, 190, 190)); + setColorStopAt(1, QColor(210, 210, 230)); + break; + case gpIon: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 10, 10)); + setColorStopAt(0.45, QColor(0, 0, 255)); + setColorStopAt(0.8, QColor(0, 255, 255)); + setColorStopAt(1, QColor(0, 255, 0)); + break; + case gpThermal: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.15, QColor(20, 0, 120)); + setColorStopAt(0.33, QColor(200, 30, 140)); + setColorStopAt(0.6, QColor(255, 100, 0)); + setColorStopAt(0.85, QColor(255, 255, 40)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpPolar: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 255, 255)); + setColorStopAt(0.18, QColor(10, 70, 255)); + setColorStopAt(0.28, QColor(10, 10, 190)); + setColorStopAt(0.5, QColor(0, 0, 0)); + setColorStopAt(0.72, QColor(190, 10, 10)); + setColorStopAt(0.82, QColor(255, 70, 10)); + setColorStopAt(1, QColor(255, 255, 50)); + break; + case gpSpectrum: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 0, 50)); + setColorStopAt(0.15, QColor(0, 0, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.6, QColor(255, 255, 0)); + setColorStopAt(0.75, QColor(255, 30, 0)); + setColorStopAt(1, QColor(50, 0, 0)); + break; + case gpJet: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 100)); + setColorStopAt(0.15, QColor(0, 50, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.65, QColor(255, 255, 0)); + setColorStopAt(0.85, QColor(255, 30, 0)); + setColorStopAt(1, QColor(100, 0, 0)); + break; + case gpHues: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(255, 0, 0)); + setColorStopAt(1.0/3.0, QColor(0, 0, 255)); + setColorStopAt(2.0/3.0, QColor(0, 255, 0)); + setColorStopAt(1, QColor(255, 0, 0)); + break; + } +} + +/*! + Clears all color stops. + + \see setColorStops, setColorStopAt +*/ +void QCPColorGradient::clearColorStops() +{ + mColorStops.clear(); + mColorBufferInvalidated = true; +} + +/*! + Returns an inverted gradient. The inverted gradient has all properties as this \ref + QCPColorGradient, but the order of the color stops is inverted. + + \see setColorStops, setColorStopAt +*/ +QCPColorGradient QCPColorGradient::inverted() const +{ + QCPColorGradient result(*this); + result.clearColorStops(); + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + result.setColorStopAt(1.0-it.key(), it.value()); + return result; +} + +/*! \internal + + Returns true if the color gradient uses transparency, i.e. if any of the configured color stops + has an alpha value below 255. +*/ +bool QCPColorGradient::stopsUseAlpha() const +{ + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + { + if (it.value().alpha() < 255) + return true; + } + return false; +} + +/*! \internal + + Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly + convert positions to colors. This is where the interpolation between color stops is calculated. +*/ +void QCPColorGradient::updateColorBuffer() +{ + if (mColorBuffer.size() != mLevelCount) + mColorBuffer.resize(mLevelCount); + if (mColorStops.size() > 1) + { + double indexToPosFactor = 1.0/(double)(mLevelCount-1); + const bool useAlpha = stopsUseAlpha(); + for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); + if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop + { + mColorBuffer[i] = (it-1).value().rgba(); + } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop + { + mColorBuffer[i] = it.value().rgba(); + } else // position is in between stops (or on an intermediate stop), interpolate color + { + QMap::const_iterator high = it; + QMap::const_iterator low = it-1; + double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 + switch (mColorInterpolation) + { + case ciRGB: + { + if (useAlpha) + { + const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); + const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, + ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, + ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, + alpha); + } else + { + mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), + ((1-t)*low.value().green() + t*high.value().green()), + ((1-t)*low.value().blue() + t*high.value().blue())); + } + break; + } + case ciHSV: + { + QColor lowHsv = low.value().toHsv(); + QColor highHsv = high.value().toHsv(); + double hue = 0; + double hueDiff = highHsv.hueF()-lowHsv.hueF(); + if (hueDiff > 0.5) + hue = lowHsv.hueF() - t*(1.0-hueDiff); + else if (hueDiff < -0.5) + hue = lowHsv.hueF() + t*(1.0+hueDiff); + else + hue = lowHsv.hueF() + t*hueDiff; + if (hue < 0) hue += 1.0; + else if (hue >= 1.0) hue -= 1.0; + if (useAlpha) + { + const QRgb rgb = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); + mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); + } + else + { + mColorBuffer[i] = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + } + break; + } + } + } + } + } else if (mColorStops.size() == 1) + { + const QRgb rgb = mColorStops.constBegin().value().rgb(); + const float alpha = mColorStops.constBegin().value().alphaF(); + mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); + } else // mColorStops is empty, fill color buffer with black + { + mColorBuffer.fill(qRgb(0, 0, 0)); + } + mColorBufferInvalidated = false; +} +/* end of 'src/colorgradient.cpp' */ + + +/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecoratorBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecoratorBracket + \brief A selection decorator which draws brackets around each selected data segment + + Additionally to the regular highlighting of selected segments via color, fill and scatter style, + this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data + segment of the plottable. + + The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and + \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref + setBracketBrush. + + To introduce custom bracket styles, it is only necessary to sublcass \ref + QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the + base class. +*/ + +/*! + Creates a new QCPSelectionDecoratorBracket instance with default values. +*/ +QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : + mBracketPen(QPen(Qt::black)), + mBracketBrush(Qt::NoBrush), + mBracketWidth(5), + mBracketHeight(50), + mBracketStyle(bsSquareBracket), + mTangentToData(false), + mTangentAverage(2) +{ + +} + +QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() +{ +} + +/*! + Sets the pen that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) +{ + mBracketPen = pen; +} + +/*! + Sets the brush that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) +{ + mBracketBrush = brush; +} + +/*! + Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of + the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketWidth(int width) +{ + mBracketWidth = width; +} + +/*! + Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis + of the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketHeight(int height) +{ + mBracketHeight = height; +} + +/*! + Sets the shape that the bracket/marker will have. + + \see setBracketWidth, setBracketHeight +*/ +void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) +{ + mBracketStyle = style; +} + +/*! + Sets whether the brackets will be rotated such that they align with the slope of the data at the + position that they appear in. + + For noisy data, it might be more visually appealing to average the slope over multiple data + points. This can be configured via \ref setTangentAverage. +*/ +void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) +{ + mTangentToData = enabled; +} + +/*! + Controls over how many data points the slope shall be averaged, when brackets shall be aligned + with the data (if \ref setTangentToData is true). + + From the position of the bracket, \a pointCount points towards the selected data range will be + taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to + disabling \ref setTangentToData. +*/ +void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) +{ + mTangentAverage = pointCount; + if (mTangentAverage < 1) + mTangentAverage = 1; +} + +/*! + Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and + indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening + bracket, respectively). + + The passed \a painter already contains all transformations that are necessary to position and + rotate the bracket appropriately. Painting operations can be performed as if drawing upright + brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. + + If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket + shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should + reimplement. +*/ +void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const +{ + switch (mBracketStyle) + { + case bsSquareBracket: + { + painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); + painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + break; + } + case bsHalfEllipse: + { + painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); + break; + } + case bsEllipse: + { + painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); + break; + } + case bsPlus: + { + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); + break; + } + default: + { + qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); + break; + } + } +} + +/*! + Draws the bracket decoration on the data points at the begin and end of each selected data + segment given in \a seletion. + + It uses the method \ref drawBracket to actually draw the shapes. + + \seebaseclassmethod +*/ +void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + if (!mPlottable || selection.isEmpty()) return; + + if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) + { + Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) + { + // determine position and (if tangent mode is enabled) angle of brackets: + int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; + int closeBracketDir = -openBracketDir; + QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); + QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); + double openBracketAngle = 0; + double closeBracketAngle = 0; + if (mTangentToData) + { + openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); + closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); + } + // draw opening bracket: + QTransform oldTransform = painter->transform(); + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(openBracketPos); + painter->rotate(openBracketAngle/M_PI*180.0); + drawBracket(painter, openBracketDir); + painter->setTransform(oldTransform); + // draw closing bracket: + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(closeBracketPos); + painter->rotate(closeBracketAngle/M_PI*180.0); + drawBracket(painter, closeBracketDir); + painter->setTransform(oldTransform); + } + } +} + +/*! \internal + + If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. + This method returns the angle in radians by which a bracket at the given \a dataIndex must be + rotated. + + The parameter \a direction must be set to either -1 or 1, representing whether it is an opening + or closing bracket. Since for slope calculation multiple data points are required, this defines + the direction in which the algorithm walks, starting at \a dataIndex, to average those data + points. (see \ref setTangentToData and \ref setTangentAverage) + + \a interface1d is the interface to the plottable's data which is used to query data coordinates. +*/ +double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const +{ + if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) + return 0; + direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 + + // how many steps we can actually go from index in the given direction without exceeding data bounds: + int averageCount; + if (direction < 0) + averageCount = qMin(mTangentAverage, dataIndex); + else + averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); + qDebug() << averageCount; + // calculate point average of averageCount points: + QVector points(averageCount); + QPointF pointsAverage; + int currentIndex = dataIndex; + for (int i=0; ikeyAxis(); + QCPAxis *valueAxis = mPlottable->valueAxis(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); + else + return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); +} +/* end of 'src/selectiondecorator-bracket.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisRect + \brief Holds multiple axes and arranges them in a rectangular shape. + + This class represents an axis rect, a rectangular area that is bounded on all sides with an + arbitrary number of axes. + + Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the + layout system allows to have multiple axis rects, e.g. arranged in a grid layout + (QCustomPlot::plotLayout). + + By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be + accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. + If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be + invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref + addAxes. To remove an axis, use \ref removeAxis. + + The axis rect layerable itself only draws a background pixmap or color, if specified (\ref + setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an + explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be + placed on other layers, independently of the axis rect. + + Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref + insetLayout and can be used to have other layout elements (or even other layouts with multiple + elements) hovering inside the axis rect. + + If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The + behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel + is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable + via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are + only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref + QCP::iRangeZoom. + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed + line on the far left indicates the viewport/widget border.
+*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const + + Returns the inset layout of this axis rect. It can be used to place other layout elements (or + even layouts with multiple other elements) inside/on top of an axis rect. + + \see QCPLayoutInset +*/ + +/*! \fn int QCPAxisRect::left() const + + Returns the pixel position of the left border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::right() const + + Returns the pixel position of the right border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::top() const + + Returns the pixel position of the top border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::bottom() const + + Returns the pixel position of the bottom border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::width() const + + Returns the pixel width of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::height() const + + Returns the pixel height of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QSize QCPAxisRect::size() const + + Returns the pixel size of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topLeft() const + + Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, + so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topRight() const + + Returns the top right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomLeft() const + + Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomRight() const + + Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::center() const + + Returns the center of this axis rect in pixels. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four + sides, the top and right axes are set invisible initially. +*/ +QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : + QCPLayoutElement(parentPlot), + mBackgroundBrush(Qt::NoBrush), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mInsetLayout(new QCPLayoutInset), + mRangeDrag(Qt::Horizontal|Qt::Vertical), + mRangeZoom(Qt::Horizontal|Qt::Vertical), + mRangeZoomFactorHorz(0.85), + mRangeZoomFactorVert(0.85), + mDragging(false) +{ + mInsetLayout->initializeParentPlot(mParentPlot); + mInsetLayout->setParentLayerable(this); + mInsetLayout->setParent(this); + + setMinimumSize(50, 50); + setMinimumMargins(QMargins(15, 15, 15, 15)); + mAxes.insert(QCPAxis::atLeft, QList()); + mAxes.insert(QCPAxis::atRight, QList()); + mAxes.insert(QCPAxis::atTop, QList()); + mAxes.insert(QCPAxis::atBottom, QList()); + + if (setupDefaultAxes) + { + QCPAxis *xAxis = addAxis(QCPAxis::atBottom); + QCPAxis *yAxis = addAxis(QCPAxis::atLeft); + QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); + QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); + setRangeDragAxes(xAxis, yAxis); + setRangeZoomAxes(xAxis, yAxis); + xAxis2->setVisible(false); + yAxis2->setVisible(false); + xAxis->grid()->setVisible(true); + yAxis->grid()->setVisible(true); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + xAxis2->grid()->setZeroLinePen(Qt::NoPen); + yAxis2->grid()->setZeroLinePen(Qt::NoPen); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + } +} + +QCPAxisRect::~QCPAxisRect() +{ + delete mInsetLayout; + mInsetLayout = 0; + + QList axesList = axes(); + for (int i=0; i ax(mAxes.value(type)); + if (index >= 0 && index < ax.size()) + { + return ax.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; + return 0; + } +} + +/*! + Returns all axes on the axis rect sides specified with \a types. + + \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of + multiple sides. + + \see axis +*/ +QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << mAxes.value(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << mAxes.value(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << mAxes.value(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << mAxes.value(QCPAxis::atBottom); + return result; +} + +/*! \overload + + Returns all axes of this axis rect. +*/ +QList QCPAxisRect::axes() const +{ + QList result; + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + result << it.value(); + } + return result; +} + +/*! + Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a + new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to + remove an axis, use \ref removeAxis instead of deleting it manually. + + You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was + previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership + of the axis, so you may not delete it afterwards. Further, the \a axis must have been created + with this axis rect as parent and with the same axis type as specified in \a type. If this is not + the case, a debug output is generated, the axis is not added, and the method returns 0. + + This method can not be used to move \a axis between axis rects. The same \a axis instance must + not be added multiple times to the same or different axis rects. + + If an axis rect side already contains one or more axes, the lower and upper endings of the new + axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref + QCPLineEnding::esHalfBar. + + \see addAxes, setupFullAxesBox +*/ +QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) +{ + QCPAxis *newAxis = axis; + if (!newAxis) + { + newAxis = new QCPAxis(this, type); + } else // user provided existing axis instance, do some sanity checks + { + if (newAxis->axisType() != type) + { + qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; + return 0; + } + if (newAxis->axisRect() != this) + { + qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; + return 0; + } + if (axes().contains(newAxis)) + { + qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; + return 0; + } + } + if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset + { + bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); + newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); + newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); + } + mAxes[type].append(newAxis); + + // reset convenience axis pointers on parent QCustomPlot if they are unset: + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + switch (type) + { + case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } + case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } + case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } + case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } + } + } + + return newAxis; +} + +/*! + Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an + or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. + + Returns a list of the added axes. + + \see addAxis, setupFullAxesBox +*/ +QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << addAxis(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << addAxis(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << addAxis(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << addAxis(QCPAxis::atBottom); + return result; +} + +/*! + Removes the specified \a axis from the axis rect and deletes it. + + Returns true on success, i.e. if \a axis was a valid axis in this axis rect. + + \see addAxis +*/ +bool QCPAxisRect::removeAxis(QCPAxis *axis) +{ + // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + if (it.value().contains(axis)) + { + if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) + it.value()[1]->setOffset(axis->offset()); + mAxes[it.key()].removeOne(axis); + if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) + parentPlot()->axisRemoved(axis); + delete axis; + return true; + } + } + qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); + return false; +} + +/*! + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom + specific axes, use the overloaded version of this method. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect) +{ + zoom(pixelRect, axes()); +} + +/*! \overload + + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) +{ + Q_FOREACH (QCPAxis *axis, affectedAxes) + { + if (!axis) + { + qDebug() << Q_FUNC_INFO << "a passed axis was zero"; + continue; + } + QCPRange pixelRange; + if (axis->orientation() == Qt::Horizontal) + pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); + else + pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); + axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); + } +} + +/*! + Convenience function to create an axis on each side that doesn't have any axes yet and set their + visibility to true. Further, the top/right axes are assigned the following properties of the + bottom/left axes: + + \li range (\ref QCPAxis::setRange) + \li range reversed (\ref QCPAxis::setRangeReversed) + \li scale type (\ref QCPAxis::setScaleType) + \li tick visibility (\ref QCPAxis::setTicks) + \li number format (\ref QCPAxis::setNumberFormat) + \li number precision (\ref QCPAxis::setNumberPrecision) + \li tick count of ticker (\ref QCPAxisTicker::setTickCount) + \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) + + Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. + + If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom + and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. +*/ +void QCPAxisRect::setupFullAxesBox(bool connectRanges) +{ + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + if (axisCount(QCPAxis::atBottom) == 0) + xAxis = addAxis(QCPAxis::atBottom); + else + xAxis = axis(QCPAxis::atBottom); + + if (axisCount(QCPAxis::atLeft) == 0) + yAxis = addAxis(QCPAxis::atLeft); + else + yAxis = axis(QCPAxis::atLeft); + + if (axisCount(QCPAxis::atTop) == 0) + xAxis2 = addAxis(QCPAxis::atTop); + else + xAxis2 = axis(QCPAxis::atTop); + + if (axisCount(QCPAxis::atRight) == 0) + yAxis2 = addAxis(QCPAxis::atRight); + else + yAxis2 = axis(QCPAxis::atRight); + + xAxis->setVisible(true); + yAxis->setVisible(true); + xAxis2->setVisible(true); + yAxis2->setVisible(true); + xAxis2->setTickLabels(false); + yAxis2->setTickLabels(false); + + xAxis2->setRange(xAxis->range()); + xAxis2->setRangeReversed(xAxis->rangeReversed()); + xAxis2->setScaleType(xAxis->scaleType()); + xAxis2->setTicks(xAxis->ticks()); + xAxis2->setNumberFormat(xAxis->numberFormat()); + xAxis2->setNumberPrecision(xAxis->numberPrecision()); + xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); + xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); + + yAxis2->setRange(yAxis->range()); + yAxis2->setRangeReversed(yAxis->rangeReversed()); + yAxis2->setScaleType(yAxis->scaleType()); + yAxis2->setTicks(yAxis->ticks()); + yAxis2->setNumberFormat(yAxis->numberFormat()); + yAxis2->setNumberPrecision(yAxis->numberPrecision()); + yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); + yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); + + if (connectRanges) + { + connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); + connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); + } +} + +/*! + Returns a list of all the plottables that are associated with this axis rect. + + A plottable is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see graphs, items +*/ +QList QCPAxisRect::plottables() const +{ + // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries + QList result; + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that are associated with this axis rect. + + A graph is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see plottables, items +*/ +QList QCPAxisRect::graphs() const +{ + // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries + QList result; + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis rect. + + An item is considered associated with an axis rect if any of its positions has key or value axis + set to an axis that is in this axis rect, or if any of its positions has \ref + QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref + QCPAbstractItem::setClipAxisRect) is set to this axis rect. + + \see plottables, graphs +*/ +QList QCPAxisRect::items() const +{ + // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries + // and miss those items that have this axis rect as clipAxisRect. + QList result; + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + continue; + } + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdaxisRect() == this || + positions.at(posId)->keyAxis()->axisRect() == this || + positions.at(posId)->valueAxis()->axisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + This method is called automatically upon replot and doesn't need to be called by users of + QCPAxisRect. + + Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), + and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its + QCPInsetLayout::update function. + + \seebaseclassmethod +*/ +void QCPAxisRect::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + switch (phase) + { + case upPreparation: + { + QList allAxes = axes(); + for (int i=0; isetupTickVectors(); + break; + } + case upLayout: + { + mInsetLayout->setOuterRect(rect()); + break; + } + default: break; + } + + // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): + mInsetLayout->update(phase); +} + +/* inherits documentation from base class */ +QList QCPAxisRect::elements(bool recursive) const +{ + QList result; + if (mInsetLayout) + { + result << mInsetLayout; + if (recursive) + result << mInsetLayout->elements(recursive); + } + return result; +} + +/* inherits documentation from base class */ +void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPAxisRect::draw(QCPPainter *painter) +{ + drawBackground(painter); +} + +/*! + Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the + axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect + backgrounds are usually drawn below everything else. + + For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio + is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref + setBackground(const QBrush &brush). + + \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) +*/ +void QCPAxisRect::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! \overload + + Sets \a brush as the background brush. The axis rect background will be filled with this brush. + Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds + are usually drawn below everything else. + + The brush will be drawn before (under) any background pixmap, which may be specified with \ref + setBackground(const QPixmap &pm). + + To disable drawing of a background brush, set \a brush to Qt::NoBrush. + + \see setBackground(const QPixmap &pm) +*/ +void QCPAxisRect::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled + is set to true, you may control whether and how the aspect ratio of the original pixmap is + preserved with \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the axis rect dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to + define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. + \see setBackground, setBackgroundScaled +*/ +void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeDragAxes to retrieve a list with all set axes). + + \see setRangeDragAxes +*/ +QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); + else + return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); +} + +/*! + Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). + + \see setRangeZoomAxes +*/ +QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); + else + return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); +} + +/*! + Returns all range drag axes of the \a orientation provided. + + \see rangeZoomAxis, setRangeZoomAxes +*/ +QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; iQt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeDrag to enable the range dragging interaction. + + \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag +*/ +void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) +{ + mRangeDrag = orientations; +} + +/*! + Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation + corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, + QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical + axis is the left axis (yAxis). + + To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref + QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeZoom to enable the range zooming interaction. + + \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag +*/ +void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) +{ + mRangeZoom = orientations; +} + +/*! \overload + + Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on + the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to dragging interactions. + + \see setRangeZoomAxes +*/ +void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag + orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag + motion, use the overload taking two separate lists for horizontal and vertical dragging. +*/ +void QCPAxisRect::setRangeDragAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical dragging, and + define specifically which axis reacts to which drag orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) +{ + mRangeDragHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeDragVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on + the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. + + The two axes can be zoomed with different strengths, when different factors are passed to \ref + setRangeZoomFactor(double horizontalFactor, double verticalFactor). + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to zooming interactions. + + \see setRangeDragAxes +*/ +void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical range zooming. The + zoom orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom + interaction, use the overload taking two separate lists for horizontal and vertical zooming. +*/ +void QCPAxisRect::setRangeZoomAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical zooming, and + define specifically which axis reacts to which zoom orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) +{ + mRangeZoomHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeZoomVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with + \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to + let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal + and which is vertical, can be set with \ref setRangeZoomAxes. + + When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) + will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the + same scrolling direction will zoom out. +*/ +void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) +{ + mRangeZoomFactorHorz = horizontalFactor; + mRangeZoomFactorVert = verticalFactor; +} + +/*! \overload + + Sets both the horizontal and vertical zoom \a factor. +*/ +void QCPAxisRect::setRangeZoomFactor(double factor) +{ + mRangeZoomFactorHorz = factor; + mRangeZoomFactorVert = factor; +} + +/*! \internal + + Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a + pixmap. + + If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an + according filling inside the axis rect with the provided \a painter. + + Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the axis rect with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::drawBackground(QCPPainter *painter) +{ + // draw background fill: + if (mBackgroundBrush != Qt::NoBrush) + painter->fillRect(mRect, mBackgroundBrush); + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mRect.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); + } + } +} + +/*! \internal + + This function makes sure multiple axes on the side specified with \a type don't collide, but are + distributed according to their respective space requirement (QCPAxis::calculateMargin). + + It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the + one with index zero. + + This function is called by \ref calculateAutoMargin. +*/ +void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) +{ + const QList axesList = mAxes.value(type); + if (axesList.isEmpty()) + return; + + bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false + for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); + if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) + { + if (!isFirstVisible) + offset += axesList.at(i)->tickLengthIn(); + isFirstVisible = false; + } + axesList.at(i)->setOffset(offset); + } +} + +/* inherits documentation from base class */ +int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) +{ + if (!mAutoMargins.testFlag(side)) + qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; + + updateAxesOffset(QCPAxis::marginSideToAxisType(side)); + + // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call + const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); + if (axesList.size() > 0) + return axesList.last()->offset() + axesList.last()->calculateMargin(); + else + return 0; +} + +/*! \internal + + Reacts to a change in layout to potentially set the convenience axis pointers \ref + QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective + axes of this axis rect. This is only done if the respective convenience pointer is currently zero + and if there is no QCPAxisRect at position (0, 0) of the plot layout. + + This automation makes it simpler to replace the main axis rect with a newly created one, without + the need to manually reset the convenience pointers. +*/ +void QCPAxisRect::layoutChanged() +{ + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) + mParentPlot->xAxis = axis(QCPAxis::atBottom); + if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) + mParentPlot->yAxis = axis(QCPAxis::atLeft); + if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) + mParentPlot->xAxis2 = axis(QCPAxis::atTop); + if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) + mParentPlot->yAxis2 = axis(QCPAxis::atRight); + } +} + +/*! \internal + + Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is + pressed, the range dragging interaction is initialized (the actual range manipulation happens in + the \ref mouseMoveEvent). + + The mDragging flag is set to true and some anchor points are set that are needed to determine the + distance the mouse was dragged in the mouse move/release events later. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + mDragStartHorzRange.clear(); + for (int i=0; irange()); + mDragStartVertRange.clear(); + for (int i=0; irange()); + } + } +} + +/*! \internal + + Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a + preceding \ref mousePressEvent, the range is moved accordingly. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + // Mouse range dragging interaction: + if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + + if (mRangeDrag.testFlag(Qt::Horizontal)) + { + for (int i=0; i= mDragStartHorzRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag.testFlag(Qt::Vertical)) + { + for (int i=0; i= mDragStartVertRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot + { + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } + + } +} + +/* inherits documentation from base class */ +void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the + ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of + the scaling operation is the current cursor position inside the axis rect. The scaling factor is + dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural + zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. + + Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse + wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be + multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as + exponent of the range zoom factor. This takes care of the wheel direction automatically, by + inverting the factor, when the wheel step is negative (f^-1 = 1/f). +*/ +void QCPAxisRect::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) + { + if (mRangeZoom != 0) + { + double factor; + double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + if (mRangeZoom.testFlag(Qt::Horizontal)) + { + factor = qPow(mRangeZoomFactorHorz, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); + } + } + if (mRangeZoom.testFlag(Qt::Vertical)) + { + factor = qPow(mRangeZoomFactorVert, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); + } + } + mParentPlot->replot(); + } + } +} +/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractLegendItem + \brief The abstract base class for all entries in a QCPLegend. + + It defines a very basic interface for entries in a QCPLegend. For representing plottables in the + legend, the subclass \ref QCPPlottableLegendItem is more suitable. + + Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry + that's not even associated with a plottable). + + You must implement the following pure virtual functions: + \li \ref draw (from QCPLayerable) + + You inherit the following members you may use: + + + + + + + + +
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
+*/ + +/* start of documentation of signals */ + +/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) + + This signal is emitted when the selection state of this legend item has changed, either by user + interaction or by a direct call to \ref setSelected. +*/ + +/* end of documentation of signals */ + +/*! + Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not + cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. +*/ +QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : + QCPLayoutElement(parent->parentPlot()), + mParentLegend(parent), + mFont(parent->font()), + mTextColor(parent->textColor()), + mSelectedFont(parent->selectedFont()), + mSelectedTextColor(parent->selectedTextColor()), + mSelectable(true), + mSelected(false) +{ + setLayer(QLatin1String("legend")); + setMargins(QMargins(0, 0, 0, 0)); +} + +/*! + Sets the default font of this specific legend item to \a font. + + \see setTextColor, QCPLegend::setFont +*/ +void QCPAbstractLegendItem::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the default text color of this specific legend item to \a color. + + \see setFont, QCPLegend::setTextColor +*/ +void QCPAbstractLegendItem::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + When this legend item is selected, \a font is used to draw generic text, instead of the normal + font set with \ref setFont. + + \see setFont, QCPLegend::setSelectedFont +*/ +void QCPAbstractLegendItem::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + When this legend item is selected, \a color is used to draw generic text, instead of the normal + color set with \ref setTextColor. + + \see setTextColor, QCPLegend::setSelectedTextColor +*/ +void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether this specific legend item is selectable. + + \see setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this specific legend item is selected. + + It is possible to set the selection state of this item by calling this function directly, even if + setSelectable is set to false. + + \see setSelectableParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (!mParentPlot) return -1; + if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) + return -1; + + if (mRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); +} + +/* inherits documentation from base class */ +QRect QCPAbstractLegendItem::clipRect() const +{ + return mOuterRect; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableLegendItem + \brief A legend item representing a plottable with an icon and the plottable name. + + This is the standard legend item for plottables. It displays an icon of the plottable next to the + plottable name. The icon is drawn by the respective plottable itself (\ref + QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. + For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the + middle. + + Legend items of this type are always associated with one plottable (retrievable via the + plottable() function and settable with the constructor). You may change the font of the plottable + name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref + QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. + + The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend + creates/removes legend items of this type. + + Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of + QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout + interface, QCPLegend has specialized functions for handling legend items conveniently, see the + documentation of \ref QCPLegend. +*/ + +/*! + Creates a new legend item associated with \a plottable. + + Once it's created, it can be added to the legend via \ref QCPLegend::addItem. + + A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref + QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. +*/ +QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : + QCPAbstractLegendItem(parent), + mPlottable(plottable) +{ + setAntialiased(false); +} + +/*! \internal + + Returns the pen that shall be used to draw the icon border, taking into account the selection + state of this item. +*/ +QPen QCPPlottableLegendItem::getIconBorderPen() const +{ + return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); +} + +/*! \internal + + Returns the text color that shall be used to draw text, taking into account the selection state + of this item. +*/ +QColor QCPPlottableLegendItem::getTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} + +/*! \internal + + Returns the font that shall be used to draw text, taking into account the selection state of this + item. +*/ +QFont QCPPlottableLegendItem::getFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Draws the item with \a painter. The size and position of the drawn legend item is defined by the + parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref + maximumOuterSizeHint of this legend item. +*/ +void QCPPlottableLegendItem::draw(QCPPainter *painter) +{ + if (!mPlottable) return; + painter->setFont(getFont()); + painter->setPen(QPen(getTextColor())); + QSizeF iconSize = mParentLegend->iconSize(); + QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + QRectF iconRect(mRect.topLeft(), iconSize); + int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops + painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); + // draw icon: + painter->save(); + painter->setClipRect(iconRect, Qt::IntersectClip); + mPlottable->drawLegendIcon(painter, iconRect); + painter->restore(); + // draw icon border: + if (getIconBorderPen().style() != Qt::NoPen) + { + painter->setPen(getIconBorderPen()); + painter->setBrush(Qt::NoBrush); + int halfPen = qCeil(painter->pen().widthF()*0.5)+1; + painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped + painter->drawRect(iconRect); + } +} + +/*! \internal + + Calculates and returns the size of this item. This includes the icon, the text and the padding in + between. + + \seebaseclassmethod +*/ +QSize QCPPlottableLegendItem::minimumOuterSizeHint() const +{ + if (!mPlottable) return QSize(); + QSize result(0, 0); + QRect textRect; + QFontMetrics fontMetrics(getFont()); + QSize iconSize = mParentLegend->iconSize(); + textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); + result.setHeight(qMax(textRect.height(), iconSize.height())); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLegend +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLegend + \brief Manages a legend inside a QCustomPlot. + + A legend is a small box somewhere in the plot which lists plottables with their name and icon. + + A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the + plottable, for which a legend item shall be created. In the case of the main legend (\ref + QCustomPlot::legend), simply adding plottables to the plot while \ref + QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding + legend items. The legend item associated with a certain plottable can be removed with \ref + QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and + manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref + addItem, \ref removeItem, etc. + + Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref + QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement + "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds + an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as + mentioned above. In principle, any other layout elements may also be added to a legend via the + normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout + System\endlink for examples on how to add other elements to the legend and move it outside the axis + rect. + + Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control + in which order (column first or row first) the legend is filled up when calling \ref addItem, and + at which column or row wrapping occurs. + + By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the + inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another + position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend + outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement + interface. +*/ + +/* start of documentation of signals */ + +/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); + + This signal is emitted when the selection state of this legend has changed. + + \see setSelectedParts, setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs a new QCPLegend instance with default values. + + Note that by default, QCustomPlot already contains a legend ready to be used as \ref + QCustomPlot::legend +*/ +QCPLegend::QCPLegend() +{ + setFillOrder(QCPLayoutGrid::foRowsFirst); + setWrap(0); + + setRowSpacing(3); + setColumnSpacing(8); + setMargins(QMargins(7, 5, 7, 4)); + setAntialiased(false); + setIconSize(32, 18); + + setIconTextPadding(7); + + setSelectableParts(spLegendBox | spItems); + setSelectedParts(spNone); + + setBorderPen(QPen(Qt::black, 0)); + setSelectedBorderPen(QPen(Qt::blue, 2)); + setIconBorderPen(Qt::NoPen); + setSelectedIconBorderPen(QPen(Qt::blue, 2)); + setBrush(Qt::white); + setSelectedBrush(Qt::white); + setTextColor(Qt::black); + setSelectedTextColor(Qt::blue); +} + +QCPLegend::~QCPLegend() +{ + clearItems(); + if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) + mParentPlot->legendRemoved(this); +} + +/* no doc for getter, see setSelectedParts */ +QCPLegend::SelectableParts QCPLegend::selectedParts() const +{ + // check whether any legend elements selected, if yes, add spItems to return value + bool hasSelectedItems = false; + for (int i=0; iselected()) + { + hasSelectedItems = true; + break; + } + } + if (hasSelectedItems) + return mSelectedParts | spItems; + else + return mSelectedParts & ~spItems; +} + +/*! + Sets the pen, the border of the entire legend is drawn with. +*/ +void QCPLegend::setBorderPen(const QPen &pen) +{ + mBorderPen = pen; +} + +/*! + Sets the brush of the legend background. +*/ +void QCPLegend::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will + use this font by default. However, a different font can be specified on a per-item-basis by + accessing the specific legend item. + + This function will also set \a font on all already existing legend items. + + \see QCPAbstractLegendItem::setFont +*/ +void QCPLegend::setFont(const QFont &font) +{ + mFont = font; + for (int i=0; isetFont(mFont); + } +} + +/*! + Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) + will use this color by default. However, a different colors can be specified on a per-item-basis + by accessing the specific legend item. + + This function will also set \a color on all already existing legend items. + + \see QCPAbstractLegendItem::setTextColor +*/ +void QCPLegend::setTextColor(const QColor &color) +{ + mTextColor = color; + for (int i=0; isetTextColor(color); + } +} + +/*! + Sets the size of legend icons. Legend items that draw an icon (e.g. a visual + representation of the graph) will use this size by default. +*/ +void QCPLegend::setIconSize(const QSize &size) +{ + mIconSize = size; +} + +/*! \overload +*/ +void QCPLegend::setIconSize(int width, int height) +{ + mIconSize.setWidth(width); + mIconSize.setHeight(height); +} + +/*! + Sets the horizontal space in pixels between the legend icon and the text next to it. + Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the + name of the graph) will use this space by default. +*/ +void QCPLegend::setIconTextPadding(int padding) +{ + mIconTextPadding = padding; +} + +/*! + Sets the pen used to draw a border around each legend icon. Legend items that draw an + icon (e.g. a visual representation of the graph) will use this pen by default. + + If no border is wanted, set this to \a Qt::NoPen. +*/ +void QCPLegend::setIconBorderPen(const QPen &pen) +{ + mIconBorderPen = pen; +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPLegend::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected + doesn't contain \ref spItems, those items become deselected. + + The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions + contains iSelectLegend. You only need to call this function when you wish to change the selection + state manually. + + This function can change the selection state of a part even when \ref setSelectableParts was set to a + value that actually excludes the part. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set + before, because there's no way to specify which exact items to newly select. Do this by calling + \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, + setSelectedFont +*/ +void QCPLegend::setSelectedParts(const SelectableParts &selected) +{ + SelectableParts newSelected = selected; + mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed + + if (mSelectedParts != newSelected) + { + if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) + { + qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; + newSelected &= ~spItems; + } + if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection + { + for (int i=0; isetSelected(false); + } + } + mSelectedParts = newSelected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + When the legend box is selected, this pen is used to draw the border instead of the normal pen + set via \ref setBorderPen. + + \see setSelectedParts, setSelectableParts, setSelectedBrush +*/ +void QCPLegend::setSelectedBorderPen(const QPen &pen) +{ + mSelectedBorderPen = pen; +} + +/*! + Sets the pen legend items will use to draw their icon borders, when they are selected. + + \see setSelectedParts, setSelectableParts, setSelectedFont +*/ +void QCPLegend::setSelectedIconBorderPen(const QPen &pen) +{ + mSelectedIconBorderPen = pen; +} + +/*! + When the legend box is selected, this brush is used to draw the legend background instead of the normal brush + set via \ref setBrush. + + \see setSelectedParts, setSelectableParts, setSelectedBorderPen +*/ +void QCPLegend::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the default font that is used by legend items when they are selected. + + This function will also set \a font on all already existing legend items. + + \see setFont, QCPAbstractLegendItem::setSelectedFont +*/ +void QCPLegend::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; + for (int i=0; isetSelectedFont(font); + } +} + +/*! + Sets the default text color that is used by legend items when they are selected. + + This function will also set \a color on all already existing legend items. + + \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor +*/ +void QCPLegend::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; + for (int i=0; isetSelectedTextColor(color); + } +} + +/*! + Returns the item with index \a i. + + Note that the linear index depends on the current fill order (\ref setFillOrder). + + \see itemCount, addItem, itemWithPlottable +*/ +QCPAbstractLegendItem *QCPLegend::item(int index) const +{ + return qobject_cast(elementAt(index)); +} + +/*! + Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns 0. + + \see hasItemWithPlottable +*/ +QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + for (int i=0; i(item(i))) + { + if (pli->plottable() == plottable) + return pli; + } + } + return 0; +} + +/*! + Returns the number of items currently in the legend. + + Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid + base class which allows creating empty cells), they are included in the returned count. + + \see item +*/ +int QCPLegend::itemCount() const +{ + return elementCount(); +} + +/*! + Returns whether the legend contains \a item. + + \see hasItemWithPlottable +*/ +bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const +{ + for (int i=0; iitem(i)) + return true; + } + return false; +} + +/*! + Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns false. + + \see itemWithPlottable +*/ +bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + return itemWithPlottable(plottable); +} + +/*! + Adds \a item to the legend, if it's not present already. The element is arranged according to the + current fill order (\ref setFillOrder) and wrapping (\ref setWrap). + + Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. + + The legend takes ownership of the item. + + \see removeItem, item, hasItem +*/ +bool QCPLegend::addItem(QCPAbstractLegendItem *item) +{ + return addElement(item); +} + +/*! \overload + + Removes the item with the specified \a index from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes + elements derived from \ref QCPAbstractLegendItem. + + \see itemCount, clearItems +*/ +bool QCPLegend::removeItem(int index) +{ + if (QCPAbstractLegendItem *ali = item(index)) + { + bool success = remove(ali); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; + } else + return false; +} + +/*! \overload + + Removes \a item from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. + + \see clearItems +*/ +bool QCPLegend::removeItem(QCPAbstractLegendItem *item) +{ + bool success = remove(item); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; +} + +/*! + Removes all items from the legend. +*/ +void QCPLegend::clearItems() +{ + for (int i=itemCount()-1; i>=0; --i) + removeItem(i); +} + +/*! + Returns the legend items that are currently selected. If no items are selected, + the list is empty. + + \see QCPAbstractLegendItem::setSelected, setSelectable +*/ +QList QCPLegend::selectedItems() const +{ + QList result; + for (int i=0; iselected()) + result.append(ali); + } + } + return result; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing main legend elements. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); +} + +/*! \internal + + Returns the pen used to paint the border of the legend, taking into account the selection state + of the legend box. +*/ +QPen QCPLegend::getBorderPen() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; +} + +/*! \internal + + Returns the brush used to paint the background of the legend, taking into account the selection + state of the legend box. +*/ +QBrush QCPLegend::getBrush() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; +} + +/*! \internal + + Draws the legend box with the provided \a painter. The individual legend items are layerables + themselves, thus are drawn independently. +*/ +void QCPLegend::draw(QCPPainter *painter) +{ + // draw background rect: + painter->setBrush(getBrush()); + painter->setPen(getBorderPen()); + painter->drawRect(mOuterRect); +} + +/* inherits documentation from base class */ +double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) + return -1; + + if (mOuterRect.contains(pos.toPoint())) + { + if (details) details->setValue(spLegendBox); + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/* inherits documentation from base class */ +void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + mSelectedParts = selectedParts(); // in case item selection has changed + if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPLegend::deselectEvent(bool *selectionStateChanged) +{ + mSelectedParts = selectedParts(); // in case item selection has changed + if (mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(selectedParts() & ~spLegendBox); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPLegend::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractLegendItem::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) +{ + if (parentPlot && !parentPlot->legend) + parentPlot->legend = this; +} +/* end of 'src/layoutelements/layoutelement-legend.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPTextElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPTextElement + \brief A layout element displaying a text + + The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, + \ref setTextColor, and \ref setTextFlags. + + A text element can be added as follows: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation +*/ + +/* start documentation of signals */ + +/*! \fn void QCPTextElement::selectionChanged(bool selected) + + This signal is emitted when the selection state has changed to \a selected, either by user + interaction or by a direct call to \ref setSelected. + + \see setSelected, setSelectable +*/ + +/*! \fn void QCPTextElement::clicked(QMouseEvent *event) + + This signal is emitted when the text element is clicked. + + \see doubleClicked, selectTest +*/ + +/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) + + This signal is emitted when the text element is double clicked. + + \see clicked, selectTest +*/ + +/* end documentation of signals */ + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref + setText). +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mText(), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mFont.setPointSizeF(pointSize); + mSelectedFont = parentPlot->font(); + mSelectedFont.setPointSizeF(pointSize); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize and the specified \a fontFamily. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(fontFamily, pointSize)), + mTextColor(Qt::black), + mSelectedFont(QFont(fontFamily, pointSize)), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with the specified \a font. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(font), + mTextColor(Qt::black), + mSelectedFont(font), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! + Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". + + \see setFont, setTextColor, setTextFlags +*/ +void QCPTextElement::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of + \c Qt::AlignmentFlag and \c Qt::TextFlag enums. + + Possible enums are: + - Qt::AlignLeft + - Qt::AlignRight + - Qt::AlignHCenter + - Qt::AlignJustify + - Qt::AlignTop + - Qt::AlignBottom + - Qt::AlignVCenter + - Qt::AlignCenter + - Qt::TextDontClip + - Qt::TextSingleLine + - Qt::TextExpandTabs + - Qt::TextShowMnemonic + - Qt::TextWordWrap + - Qt::TextIncludeTrailingSpaces +*/ +void QCPTextElement::setTextFlags(int flags) +{ + mTextFlags = flags; +} + +/*! + Sets the \a font of the text. + + \see setTextColor, setSelectedFont +*/ +void QCPTextElement::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the \a color of the text. + + \see setFont, setSelectedTextColor +*/ +void QCPTextElement::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). + + \see setFont +*/ +void QCPTextElement::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). + + \see setTextColor +*/ +void QCPTextElement::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether the user may select this text element. + + Note that even when \a selectable is set to false, the selection state may be changed + programmatically via \ref setSelected. +*/ +void QCPTextElement::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets the selection state of this text element to \a selected. If the selection has changed, \ref + selectionChanged is emitted. + + Note that this function can change the selection state independently of the current \ref + setSelectable state. +*/ +void QCPTextElement::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/* inherits documentation from base class */ +void QCPTextElement::draw(QCPPainter *painter) +{ + painter->setFont(mainFont()); + painter->setPen(QPen(mainTextColor())); + painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); +} + +/* inherits documentation from base class */ +QSize QCPTextElement::minimumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +QSize QCPTextElement::maximumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.setWidth(QWIDGETSIZE_MAX); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPTextElement::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/*! + Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is + within the bounding box of the text element's text. Note that this bounding box is updated in the + draw call. + + If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text + element is not selectable (\ref setSelectable), returns -1. + + \seebaseclassmethod +*/ +double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + if (mTextBoundingRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/*! + Accepts the mouse event in order to emit the according click signal in the \ref + mouseReleaseEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->accept(); +} + +/*! + Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref + mousePressEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) + Q_EMIT clicked(event); +} + +/*! + Emits the \ref doubleClicked signal. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + Q_EMIT doubleClicked(event); +} + +/*! \internal + + Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to + true, else mFont is returned. +*/ +QFont QCPTextElement::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to + true, else mTextColor is returned. +*/ +QColor QCPTextElement::mainTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} +/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScale +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScale + \brief A color scale for use with color coding data such as QCPColorMap + + This layout element can be placed on the plot to correlate a color gradient with data values. It + is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". + + \image html QCPColorScale.png + + The color scale can be either horizontal or vertical, as shown in the image above. The + orientation and the side where the numbers appear is controlled with \ref setType. + + Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are + connected, they share their gradient, data range and data scale type (\ref setGradient, \ref + setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color + scale, to make them all synchronize these properties. + + To have finer control over the number display and axis behaviour, you can directly access the + \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if + you want to change the number of automatically generated ticks, call + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount + + Placing a color scale next to the main axis rect works like with any other layout element: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation + In this case we have placed it to the right of the default axis rect, so it wasn't necessary to + call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color + scale can be set with \ref setLabel. + + For optimum appearance (like in the image above), it may be desirable to line up the axis rect and + the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup + + Color scales are initialized with a non-zero minimum top and bottom margin (\ref + setMinimumMargins), because vertical color scales are most common and the minimum top/bottom + margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a + horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you + might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPAxis *QCPColorScale::axis() const + + Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the + appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its + interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref + setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref + QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on + the QCPColorScale or on its QCPAxis. + + If the type of the color scale is changed with \ref setType, the axis returned by this method + will change, too, to either the left, right, bottom or top axis, depending on which type was set. +*/ + +/* end documentation of signals */ +/* start documentation of signals */ + +/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); + + This signal is emitted when the data range changes. + + \see setDataRange +*/ + +/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the data scale type changes. + + \see setDataScaleType +*/ + +/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); + + This signal is emitted when the gradient changes. + + \see setGradient +*/ + +/* end documentation of signals */ + +/*! + Constructs a new QCPColorScale. +*/ +QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight + mDataScaleType(QCPAxis::stLinear), + mBarWidth(20), + mAxisRect(new QCPColorScaleAxisRectPrivate(this)) +{ + setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) + setType(QCPAxis::atRight); + setDataRange(QCPRange(0, 6)); +} + +QCPColorScale::~QCPColorScale() +{ + delete mAxisRect; +} + +/* undocumented getter */ +QString QCPColorScale::label() const +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return QString(); + } + + return mColorAxis.data()->label(); +} + +/* undocumented getter */ +bool QCPColorScale::rangeDrag() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/* undocumented getter */ +bool QCPColorScale::rangeZoom() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/*! + Sets at which side of the color scale the axis is placed, and thus also its orientation. + + Note that after setting \a type to a different value, the axis returned by \ref axis() will + be a different one. The new axis will adopt the following properties from the previous axis: The + range, scale type, label and ticker (the latter will be shared and not copied). +*/ +void QCPColorScale::setType(QCPAxis::AxisType type) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + if (mType != type) + { + mType = type; + QCPRange rangeTransfer(0, 6); + QString labelTransfer; + QSharedPointer tickerTransfer; + // transfer/revert some settings on old axis if it exists: + bool doTransfer = (bool)mColorAxis; + if (doTransfer) + { + rangeTransfer = mColorAxis.data()->range(); + labelTransfer = mColorAxis.data()->label(); + tickerTransfer = mColorAxis.data()->ticker(); + mColorAxis.data()->setLabel(QString()); + disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; + Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) + { + mAxisRect.data()->axis(atype)->setTicks(atype == mType); + mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); + } + // set new mColorAxis pointer: + mColorAxis = mAxisRect.data()->axis(mType); + // transfer settings to new axis: + if (doTransfer) + { + mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) + mColorAxis.data()->setLabel(labelTransfer); + mColorAxis.data()->setTicker(tickerTransfer); + } + connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); + } +} + +/*! + Sets the range spanned by the color gradient and that is shown by the axis in the color scale. + + It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its range with \ref + QCPAxis::setRange. + + \see setDataScaleType, setGradient, rescaleDataRange +*/ +void QCPColorScale::setDataRange(const QCPRange &dataRange) +{ + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + mDataRange = dataRange; + if (mColorAxis) + mColorAxis.data()->setRange(mDataRange); + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets the scale type of the color scale, i.e. whether values are linearly associated with colors + or logarithmically. + + It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its scale type with \ref + QCPAxis::setScaleType. + + \see setDataRange, setGradient +*/ +void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + if (mColorAxis) + mColorAxis.data()->setScaleType(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + Q_EMIT dataScaleTypeChanged(mDataScaleType); + } +} + +/*! + Sets the color gradient that will be used to represent data values. + + It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. + + \see setDataRange, setDataScaleType +*/ +void QCPColorScale::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + if (mAxisRect) + mAxisRect.data()->mGradientImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on + the internal \ref axis. +*/ +void QCPColorScale::setLabel(const QString &str) +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return; + } + + mColorAxis.data()->setLabel(str); +} + +/*! + Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed + will have. +*/ +void QCPColorScale::setBarWidth(int width) +{ + mBarWidth = width; +} + +/*! + Sets whether the user can drag the data range (\ref setDataRange). + + Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeDrag(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeDrag(0); +} + +/*! + Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. + + Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeZoom(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeZoom(0); +} + +/*! + Returns a list of all the color maps associated with this color scale. +*/ +QList QCPColorScale::colorMaps() const +{ + QList result; + for (int i=0; iplottableCount(); ++i) + { + if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) + if (cm->colorScale() == this) + result.append(cm); + } + return result; +} + +/*! + Changes the data range such that all color maps associated with this color scale are fully mapped + to the gradient in the data dimension. + + \see setDataRange +*/ +void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) +{ + QList maps = colorMaps(); + QCPRange newRange; + bool haveRange = false; + QCP::SignDomain sign = QCP::sdBoth; + if (mDataScaleType == QCPAxis::stLogarithmic) + sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + for (int i=0; irealVisibility() && onlyVisibleMaps) + continue; + QCPRange mapRange; + if (maps.at(i)->colorScale() == this) + { + bool currentFoundRange = true; + mapRange = maps.at(i)->data()->dataBounds(); + if (sign == QCP::sdPositive) + { + if (mapRange.lower <= 0 && mapRange.upper > 0) + mapRange.lower = mapRange.upper*1e-3; + else if (mapRange.lower <= 0 && mapRange.upper <= 0) + currentFoundRange = false; + } else if (sign == QCP::sdNegative) + { + if (mapRange.upper >= 0 && mapRange.lower < 0) + mapRange.upper = mapRange.lower*1e-3; + else if (mapRange.upper >= 0 && mapRange.lower >= 0) + currentFoundRange = false; + } + if (currentFoundRange) + { + if (!haveRange) + newRange = mapRange; + else + newRange.expand(mapRange); + haveRange = true; + } + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mDataScaleType == QCPAxis::stLinear) + { + newRange.lower = center-mDataRange.size()/2.0; + newRange.upper = center+mDataRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); + newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); + } + } + setDataRange(newRange); + } +} + +/* inherits documentation from base class */ +void QCPColorScale::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + mAxisRect.data()->update(phase); + + switch (phase) + { + case upMargins: + { + if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) + { + setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + } else + { + setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); + setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); + } + break; + } + case upLayout: + { + mAxisRect.data()->setOuterRect(rect()); + break; + } + default: break; + } +} + +/* inherits documentation from base class */ +void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mousePressEvent(event, details); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseMoveEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseReleaseEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::wheelEvent(QWheelEvent *event) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->wheelEvent(event); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScaleAxisRectPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScaleAxisRectPrivate + + \internal + \brief An axis rect subclass for use in a QCPColorScale + + This is a private class and not part of the public QCustomPlot interface. + + It provides the axis rect functionality for the QCPColorScale class. +*/ + + +/*! + Creates a new instance, as a child of \a parentColorScale. +*/ +QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : + QCPAxisRect(parentColorScale->parentPlot(), true), + mParentColorScale(parentColorScale), + mGradientImageInvalidated(true) +{ + setParentLayerable(parentColorScale); + setMinimumMargins(QMargins(0, 0, 0, 0)); + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + axis(type)->setVisible(true); + axis(type)->grid()->setVisible(false); + axis(type)->setPadding(0); + connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); + connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); + } + + connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); + + // make layer transfers of color scale transfer to axis rect and axes + // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); +} + +/*! \internal + + Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws + it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. + + \seebaseclassmethod +*/ +void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) +{ + if (mGradientImageInvalidated) + updateGradientImage(); + + bool mirrorHorz = false; + bool mirrorVert = false; + if (mParentColorScale->mColorAxis) + { + mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); + mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); + } + + painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); + QCPAxisRect::draw(painter); +} + +/*! \internal + + Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to + generate a gradient image. This gradient image will be used in the \ref draw method. +*/ +void QCPColorScaleAxisRectPrivate::updateGradientImage() +{ + if (rect().isEmpty()) + return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + int n = mParentColorScale->mGradient.levelCount(); + int w, h; + QVector data(n); + for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) + { + w = n; + h = rect().height(); + mGradientImage = QImage(w, h, format); + QVector pixels; + for (int y=0; y(mGradientImage.scanLine(y))); + mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); + for (int y=1; y(mGradientImage.scanLine(y)); + const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); + for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectedParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); + else + axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); + } + } +} + +/*! \internal + + This slot is connected to the selectableChanged signals of the four axes in the constructor. It + synchronizes the selectability of the axes. +*/ +void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) +{ + // synchronize axis base selectability: + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectableParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); + else + axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); + } + } +} +/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ + + +/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraphData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraphData + \brief Holds the data of one single data point for QCPGraph. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPGraphDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPGraphData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPGraphData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and value set to zero. +*/ +QCPGraphData::QCPGraphData() : + key(0), + value(0) +{ +} + +/*! + Constructs a data point with the specified \a key and \a value. +*/ +QCPGraphData::QCPGraphData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraph +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraph + \brief A plottable representing a graph in a plot. + + \image html QCPGraph.png + + Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be + accessed via QCustomPlot::graph. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPGraphDataContainer. + + Graphs are used to display single-valued data. Single-valued means that there should only be one + data point per unique key coordinate. In other words, the graph can't have \a loops. If you do + want to plot non-single-valued curves, rather use the QCPCurve plottable. + + Gaps in the graph line can be created by adding data points with NaN as value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpgraph-appearance Changing the appearance + + The appearance of the graph is mainly determined by the line style, scatter style, brush and pen + of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). + + \subsection filling Filling under or between graphs + + QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to + the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, + just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. + + By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill + between this graph and another one, call \ref setChannelFillGraph with the other graph as + parameter. + + \see QCustomPlot::addGraph, QCustomPlot::graph +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPGraph::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually + but use QCustomPlot::removePlottable() instead. + + To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. +*/ +QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // special handling for QCPGraphs to maintain the simple graph interface: + mParentPlot->registerGraph(this); + + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setLineStyle(lsLine); + setScatterSkip(0); + setChannelFillGraph(0); + setAdaptiveSampling(true); +} + +QCPGraph::~QCPGraph() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. + Modifying the data in the container will then affect all graphs that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the graph's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 + + \see addData +*/ +void QCPGraph::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to + \ref lsNone and \ref setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPGraph::setLineStyle(LineStyle ls) +{ + mLineStyle = ls; +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points + are drawn (e.g. for line-only-plots with appropriate line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPGraph::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPGraph::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets the target graph for filling the area between this graph and \a targetGraph with the current + brush (\ref setBrush). + + When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To + disable any filling, set the brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) +{ + // prevent setting channel target to this graph itself: + if (targetGraph == this) + { + qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; + mChannelFillGraph = 0; + return; + } + // prevent setting channel target to a graph not in the plot: + if (targetGraph && targetGraph->mParentPlot != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; + mChannelFillGraph = 0; + return; + } + + mChannelFillGraph = targetGraph; +} + +/*! + Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive + sampling technique can drastically improve the replot performance for graphs with a larger number + of points (e.g. above 10,000), without notably changing the appearance of the graph. + + By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive + sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no + disadvantage in almost all cases. + + \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" + + As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are + reproduced reliably, as well as the overall shape of the data set. The replot time reduces + dramatically though. This allows QCustomPlot to display large amounts of data in realtime. + + \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" + + Care must be taken when using high-density scatter plots in combination with adaptive sampling. + The adaptive sampling algorithm treats scatter plots more carefully than line plots which still + gives a significant reduction of replot times, but not quite as much as for line plots. This is + because scatter plots inherently need more data points to be preserved in order to still resemble + the original, non-adaptive-sampling plot. As shown above, the results still aren't quite + identical, as banding occurs for the outer data points. This is in fact intentional, such that + the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, + depends on the point density, i.e. the number of points in the plot. + + For some situations with scatter plots it might thus be desirable to manually turn adaptive + sampling off. For example, when saving the plot to disk. This can be achieved by setting \a + enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled + back to true afterwards. +*/ +void QCPGraph::setAdaptiveSampling(bool enabled) +{ + mAdaptiveSampling = enabled; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(double key, double value) +{ + mDataContainer->add(QCPGraphData(key, value)); +} + +/* inherits documentation from base class */ +double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPGraph::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + if (mLineStyle == lsNone && mScatterStyle.isNone()) return; + + QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + // get line pixel points appropriate to line style: + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) + getLines(&lines, lineDataRange); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPGraphDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } +#endif + + // draw fill of graph: + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + drawFill(painter, &lines); + + // draw line: + if (mLineStyle != lsNone) + { + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + painter->setBrush(Qt::NoBrush); + if (mLineStyle == lsImpulse) + drawImpulsePlot(painter, lines); + else + drawLinePlot(painter, lines); // also step plots can be drawn as a line plot + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i)); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches + out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. + according to the line style of the graph. + + \a lines will be filled with points in pixel coordinates, that can be drawn with the according + draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines + aren't necessarily the original data points. For example, step line styles require additional + points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a + lines vector will be empty. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. + + \see getScatters +*/ +void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const +{ + if (!lines) return; + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + lines->clear(); + return; + } + + QVector lineData; + if (mLineStyle != lsNone) + getOptimizedLineData(&lineData, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) + std::reverse(lineData.begin(), lineData.end()); + + switch (mLineStyle) + { + case lsNone: lines->clear(); break; + case lsLine: *lines = dataToLines(lineData); break; + case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; + case lsStepRight: *lines = dataToStepRightLines(lineData); break; + case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; + case lsImpulse: *lines = dataToImpulseLines(lineData); break; + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then + converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be + passed to \ref drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. +*/ +void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const +{ + if (!scatters) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } + + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + scatters->clear(); + return; + } + + QVector data; + getOptimizedScatterData(&data, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) + std::reverse(data.begin(), data.end()); + + scatters->resize(data.size()); + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } + } else + { + for (int i=0; icoordToPixel(data.at(i).key)); + (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + } +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsLine. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + result[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key)); + result[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepLeft. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepLeftLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(lastValue); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(key); + result[i*2+1].setY(lastValue); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepRight. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepRightLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(value); + result[i*2+0].setY(lastKey); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(value); + result[i*2+1].setY(lastKey); + } + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(lastKey); + result[i*2+0].setY(value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(lastKey); + result[i*2+1].setY(value); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepCenter. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepCenterLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastValue); + result[0].setY(lastKey); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(lastValue); + result[i*2-1].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + } + result[data.size()*2-1].setX(lastValue); + result[data.size()*2-1].setY(lastKey); + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastKey); + result[0].setY(lastValue); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(key); + result[i*2-1].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + } + result[data.size()*2-1].setX(lastKey); + result[data.size()*2-1].setY(lastValue); + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsImpulse. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot +*/ +QVector QCPGraph::dataToImpulseLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(valueAxis->coordToPixel(0)); + result[i*2+0].setY(key); + result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(valueAxis->coordToPixel(0)); + result[i*2+1].setX(key); + result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Draws the fill of the graph using the specified \a painter, with the currently set brush. + + Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref + getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. + + In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), + this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to + operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN + segments of the two involved graphs, before passing the overlapping pairs to \ref + getChannelFillPolygon. + + Pass the points of this graph's line as \a lines, in pixel coordinates. + + \see drawLinePlot, drawImpulsePlot, drawScatterPlot +*/ +void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const +{ + if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot + if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; + + applyFillAntialiasingHint(painter); + QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); + if (!mChannelFillGraph) + { + // draw base fill under graph, fill goes all the way to the zero-value-line: + for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); + } else + { + // draw fill between this graph and mChannelFillGraph: + QVector otherLines; + mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); + if (!otherLines.isEmpty()) + { + QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); + QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); + for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); + } + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawLinePlot, drawImpulsePlot +*/ +void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const +{ + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in + pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines + from the regular graph data points. + + \see drawLinePlot, drawScatterPlot +*/ +void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + QPen oldPen = painter->pen(); + QPen newPen = painter->pen(); + newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line + painter->setPen(newPen); + painter->drawLines(lines); + painter->setPen(oldPen); + } +} + +/*! \internal + + Returns via \a lineData the data points that need to be visualized for this graph when plotting + graph lines, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getLines to retrieve the basic working set of data. + + \see getOptimizedScatterData +*/ +void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const +{ + if (!lineData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (begin == end) return; + + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + QCPGraphDataContainer::const_iterator it = begin; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double lastIntervalEndKey = currentIntervalStartKey; + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary + { + if (it->value < minValue) + minValue = it->value; + else if (it->value > maxValue) + maxValue = it->value; + ++intervalDataCount; + } else // new pixel interval started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + lastIntervalEndKey = (it-1)->key; + minValue = it->value; + maxValue = it->value; + currentIntervalFirstPoint = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + ++it; + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + lineData->resize(dataCount); + std::copy(begin, end, lineData->begin()); + } +} + +/*! \internal + + Returns via \a scatterData the data points that need to be visualized for this graph when + plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getScatters to retrieve the basic working set of data. + + \see getOptimizedLineData +*/ +void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const +{ + if (!scatterData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int beginIndex = begin-mDataContainer->constBegin(); + int endIndex = end-mDataContainer->constBegin(); + while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++beginIndex; + ++begin; + } + if (begin == end) return; + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + double valueMaxRange = valueAxis->range().upper; + double valueMinRange = valueAxis->range().lower; + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator minValueIt = it; + QCPGraphDataContainer::const_iterator maxValueIt = it; + QCPGraphDataContainer::const_iterator currentIntervalStart = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + // main loop over data points: + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary + { + if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) + { + minValue = it->value; + minValueIt = it; + } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) + { + maxValue = it->value; + maxValueIt = it; + } + ++intervalDataCount; + } else // new pixel started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else + intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + minValue = it->value; + maxValue = it->value; + currentIntervalStart = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int intervalItIndex = intervalIt-mDataContainer->constBegin(); + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: + { + intervalItIndex += scatterModulo; + if (intervalItIndex < itIndex) + intervalIt += scatterModulo; + else + { + intervalIt = it; + intervalItIndex = itIndex; + } + } + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + scatterData->reserve(dataCount); + while (it != end) + { + scatterData->append(*it); + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + This method takes into account that the drawing of data lines at the axis rect border always + requires the points just outside the visible axis range. So \a begin and \a end may actually + indicate a range that contains one additional data point to the left and right of the visible + axis range. +*/ +void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + if (rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + } else + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + // get visible data range: + begin = mDataContainer->findBegin(keyAxis->range().lower); + end = mDataContainer->findEnd(keyAxis->range().upper); + // limit lower/upperEnd to rangeRestriction: + mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything + } +} + +/*! \internal + + This method goes through the passed points in \a lineData and returns a list of the segments + which don't contain NaN data points. + + \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check + for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c + Qt::Vertical, the \a x member is checked. + + \see getOverlappingSegments, drawFill +*/ +QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const +{ + QVector result; + const int n = lineData->size(); + + QCPDataRange currentSegment(-1, -1); + int i = 0; + + if (keyOrientation == Qt::Horizontal) + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } else // keyOrientation == Qt::Vertical + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } + return result; +} + +/*! \internal + + This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and + \a otherSegments, and their associated point data \a thisData and \a otherData. + + It returns all pairs of segments (the first from \a thisSegments, the second from \a + otherSegments), which overlap in plot coordinates. + + This method is useful in the case of a channel fill between two graphs, when only those non-NaN + segments which actually overlap in their key coordinate shall be considered for drawing a channel + fill polygon. + + It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and + that the segments don't overlap themselves. The same is assumed for the segments in \a + otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. + + \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon +*/ +QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const +{ + QVector > result; + if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) + return result; + + int thisIndex = 0; + int otherIndex = 0; + const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; + while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) + { + if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++thisIndex; + continue; + } + if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++otherIndex; + continue; + } + double thisLower, thisUpper, otherLower, otherUpper; + if (!verticalKey) + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); + } else + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); + } + + int bPrecedence; + if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) + result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); + + if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment + ++otherIndex; + else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment + ++thisIndex; + } + + return result; +} + +/*! \internal + + Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) + have overlap. + + The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the + \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher + coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if + both segment's upper bounds are identical, 0 is returned as \a bPrecedence. + + It is assumed that the lower bounds always have smaller or equal values than the upper bounds. + + \see getOverlappingSegments +*/ +bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const +{ + bPrecedence = 0; + if (aLower > bUpper) + { + bPrecedence = -1; + return false; + } else if (bLower > aUpper) + { + bPrecedence = 1; + return false; + } else + { + if (aUpper > bUpper) + bPrecedence = -1; + else if (aUpper < bUpper) + bPrecedence = 1; + + return true; + } +} + +/*! \internal + + Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. + The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates + is in positive or negative infinity. So this case is handled separately by just closing the fill + polygon on the axis which lies in the direction towards the zero value. + + \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether + the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or + y value of the returned point, respectively. +*/ +QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + QPointF result; + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + if (keyAxis->orientation() == Qt::Horizontal) + { + result.setX(matchingDataPoint.x()); + result.setY(valueAxis->coordToPixel(0)); + } else // keyAxis->orientation() == Qt::Vertical + { + result.setX(valueAxis->coordToPixel(0)); + result.setY(matchingDataPoint.y()); + } + } else // valueAxis->mScaleType == QCPAxis::stLogarithmic + { + // In logarithmic scaling we can't just draw to value 0 so we just fill all the way + // to the axis which is in the direction towards 0 + if (keyAxis->orientation() == Qt::Vertical) + { + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setX(keyAxis->axisRect()->right()); + else + result.setX(keyAxis->axisRect()->left()); + result.setY(matchingDataPoint.y()); + } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) + { + result.setX(matchingDataPoint.x()); + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setY(keyAxis->axisRect()->top()); + else + result.setY(keyAxis->axisRect()->bottom()); + } + } + return result; +} + +/*! \internal + + Returns the polygon needed for drawing normal fills between this graph and the key axis. + + Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment + which shall be used for the fill. The collection of \a lineData points described by \a segment + must not contain NaN data points (see \ref getNonNanSegments). + + The returned fill polygon will be closed at the key axis (the zero-value line) for linear value + axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect + side (see \ref getFillBasePoint). + + For increased performance (due to implicit sharing), keep the returned QPolygonF const. + + \see drawFill, getNonNanSegments +*/ +const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const +{ + if (segment.size() < 2) + return QPolygonF(); + QPolygonF result(segment.size()+2); + + result[0] = getFillBasePoint(lineData->at(segment.begin())); + std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); + result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); + + return result; +} + +/*! \internal + + Returns the polygon needed for drawing (partial) channel fills between this graph and the graph + specified by \ref setChannelFillGraph. + + The data points of this graph are passed as pixel coordinates via \a thisData, the data of the + other graph as \a otherData. The returned polygon will be calculated for the specified data + segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a + otherData, respectively. + + The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by + \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap + need to be processed here. + + For increased performance due to implicit sharing, keep the returned QPolygonF const. + + \see drawFill, getOverlappingSegments, getNonNanSegments +*/ +const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const +{ + if (!mChannelFillGraph) + return QPolygonF(); + + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } + if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } + + if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) + return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) + + if (thisData->isEmpty()) return QPolygonF(); + QVector thisSegmentData(thisSegment.size()); + QVector otherSegmentData(otherSegment.size()); + std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); + std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); + // pointers to be able to swap them, depending which data range needs cropping: + QVector *staticData = &thisSegmentData; + QVector *croppedData = &otherSegmentData; + + // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): + if (keyAxis->orientation() == Qt::Horizontal) + { + // x is key + // crop lower bound: + if (staticData->first().x() < croppedData->first().x()) // other one must be cropped + qSwap(staticData, croppedData); + const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) + slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); + else + slope = 0; + (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); + (*croppedData)[0].setX(staticData->first().x()); + + // crop upper bound: + if (staticData->last().x() > croppedData->last().x()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveX(croppedData, staticData->last().x()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + const int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) + slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); + else + slope = 0; + (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); + (*croppedData)[li].setX(staticData->last().x()); + } else // mKeyAxis->orientation() == Qt::Vertical + { + // y is key + // crop lower bound: + if (staticData->first().y() < croppedData->first().y()) // other one must be cropped + qSwap(staticData, croppedData); + int lowBound = findIndexBelowY(croppedData, staticData->first().y()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots + slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); + else + slope = 0; + (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); + (*croppedData)[0].setY(staticData->first().y()); + + // crop upper bound: + if (staticData->last().y() > croppedData->last().y()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveY(croppedData, staticData->last().y()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots + slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); + else + slope = 0; + (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); + (*croppedData)[li].setY(staticData->last().y()); + } + + // return joined: + for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted + thisSegmentData << otherSegmentData.at(i); + return QPolygonF(thisSegmentData); +} + +/*! \internal + + Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveX(const QVector *data, double x) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).x() < x) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexBelowX(const QVector *data, double x) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).x() > x) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} + +/*! \internal + + Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is vertical. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveY(const QVector *data, double y) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).y() < y) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Calculates the minimum distance in pixels the graph's representation has from the given \a + pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if + the graph has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the graph line is also taken into account. + + If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. +*/ +double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + // calculate minimum distances to graph data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); + QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); + for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + // line displayed, calculate distance to line segments: + QVector lineData; + getLines(&lineData, QCPDataRange(0, dataCount())); + QCPVector2D p(pixelPoint); + const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected + for (int i=0; i *data, double y) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).y() > y) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} +/* end of 'src/plottables/plottable-graph.cpp' */ + + +/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurveData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurveData + \brief Holds the data of one single data point for QCPCurve. + + The stored data is: + \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) + \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) + \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPCurveDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPCurveData::sortKey() const + + Returns the \a t member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). + All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() + + Since the member \a key is the data point key coordinate and the member \a t is the data ordering + parameter, this method returns false. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPCurveData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a curve data point with t, key and value set to zero. +*/ +QCPCurveData::QCPCurveData() : + t(0), + key(0), + value(0) +{ +} + +/*! + Constructs a curve data point with the specified \a t, \a key and \a value. +*/ +QCPCurveData::QCPCurveData(double t, double key, double value) : + t(t), + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurve + \brief A plottable representing a parametric curve in a plot. + + \image html QCPCurve.png + + Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, + so their visual representation can have \a loops. This is realized by introducing a third + coordinate \a t, which defines the order of the points described by the other two coordinates \a + x and \a y. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the curve's data via the \ref data method, which returns a pointer to the + internal \ref QCPCurveDataContainer. + + Gaps in the curve can be created by adding data points with NaN as key and value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpcurve-appearance Changing the appearance + + The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). + + \section qcpcurve-usage Usage + + Like all data representing objects in QCustomPlot, the QCPCurve is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPCurve::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // modify inherited properties from abstract plottable: + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setScatterStyle(QCPScatterStyle()); + setLineStyle(lsLine); + setScatterSkip(0); +} + +QCPCurve::~QCPCurve() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. + Modifying the data in the container will then affect all curves that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the curve's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 + + \see addData +*/ +void QCPCurve::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a t, \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a t in ascending order, you can + set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(t, keys, values, alreadySorted); +} + + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + \see addData +*/ +void QCPCurve::setData(const QVector &keys, const QVector &values) +{ + mDataContainer->clear(); + addData(keys, values); +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref + QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate + line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPCurve::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPCurve::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets how the single data points are connected in the plot or how they are represented visually + apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref + setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPCurve::setLineStyle(QCPCurve::LineStyle style) +{ + mLineStyle = style; +} + +/*! \overload + + Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (t.size() != keys.size() || t.size() != values.size()) + qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); + const int n = qMin(qMin(t.size(), keys.size()), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = t[i]; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &keys, const QVector &values) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + double tStart; + if (!mDataContainer->isEmpty()) + tStart = (mDataContainer->constEnd()-1)->t + 1.0; + else + tStart = 0; + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = tStart + i; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a t, \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double t, double key, double value) +{ + mDataContainer->add(QCPCurveData(t, key, value)); +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + The t parameter is generated automatically by increments of 1 for each point, starting at the + highest t of previously existing data or 0, if the curve data is empty. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double key, double value) +{ + if (!mDataContainer->isEmpty()) + mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); + else + mDataContainer->add(QCPCurveData(0.0, key, value)); +} + +/* inherits documentation from base class */ +double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPCurve::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + + // allocate line vector: + QVector lines, scatters; + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + + // fill with curve data: + QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width + if (isSelectedSegment && mSelectionDecorator) + finalCurvePen = mSelectionDecorator->pen(); + + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) + getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); + + // check data validity if flag set: + #ifdef QCUSTOMPLOT_CHECK_DATA + for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->t) || + QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } + #endif + + // draw curve fill: + applyFillAntialiasingHint(painter); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) + painter->drawPolygon(QPolygonF(lines)); + + // draw curve line: + if (mLineStyle != lsNone) + { + painter->setPen(finalCurvePen); + painter->setBrush(Qt::NoBrush); + drawCurveLine(painter, lines); + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + Draws lines between the points in \a lines, given in pixel coordinates. + + \see drawScatterPlot, getCurveLines +*/ +void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawCurveLine, getCurveLines +*/ +void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const +{ + // draw scatter point symbols: + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const +{ + if (!lines) return; + lines->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + // add margins to rect to compensate for stroke width + const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety + const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); + const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); + const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); + const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); + QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); + if (itBegin == itEnd) + return; + QCPCurveDataContainer::const_iterator it = itBegin; + QCPCurveDataContainer::const_iterator prevIt = itEnd-1; + int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); + QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) + while (it != itEnd) + { + const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); + if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R + { + if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal + { + QPointF crossA, crossB; + if (prevRegion == 5) // we're coming from R, so add this point optimized + { + lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); + // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } else if (mayTraverse(prevRegion, currentRegion) && + getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) + { + // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: + QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; + getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); + if (it != itBegin) + { + *lines << beforeTraverseCornerPoints; + lines->append(crossA); + lines->append(crossB); + *lines << afterTraverseCornerPoints; + } else + { + lines->append(crossB); + *lines << afterTraverseCornerPoints; + trailingPoints << beforeTraverseCornerPoints << crossA ; + } + } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) + { + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } + } else // segment does end in R, so we add previous point optimized and this point at original position + { + if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end + trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + else + lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); + lines->append(coordsToPixels(it->key, it->value)); + } + } else // region didn't change + { + if (currentRegion == 5) // still in R, keep adding original points + { + lines->append(coordsToPixels(it->key, it->value)); + } else // still outside R, no need to add anything + { + // see how this is not doing anything? That's the main optimization... + } + } + prevIt = it; + prevRegion = currentRegion; + ++it; + } + *lines << trailingPoints; +} + +/*! \internal + + Called by \ref draw to generate points in pixel coordinates which represent the scatters of the + curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly + sparser. + + Scatters that aren't visible in the current axis rect are optimized away. + + \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref + drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. + + \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel + coordinates generated by this function. This is needed here to calculate an accordingly wider + margin around the axis rect when performing the data point reduction. + + \see draw, drawScatterPlot +*/ +void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const +{ + if (!scatters) return; + scatters->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); + if (begin == end) + return; + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int endIndex = end-mDataContainer->constBegin(); + + QCPRange keyRange = keyAxis->range(); + QCPRange valueRange = valueAxis->range(); + // extend range to include width of scatter symbols: + keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); + keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); + valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); + valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); + + QCPCurveDataContainer::const_iterator it = begin; + int itIndex = begin-mDataContainer->constBegin(); + while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++itIndex; + ++it; + } + if (keyAxis->orientation() == Qt::Vertical) + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } else + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + It returns the region of the given point (\a key, \a value) with respect to a rectangle defined + by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. + + The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a + keyMin to \a keyMax): + + + + + +
147
258
369
+ + With the rectangle being region 5, and the outer regions extending infinitely outwards. In the + curve optimization algorithm, region 5 is considered to be the visible portion of the plot. +*/ +int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + if (key < keyMin) // region 123 + { + if (value > valueMax) + return 1; + else if (value < valueMin) + return 3; + else + return 2; + } else if (key > keyMax) // region 789 + { + if (value > valueMax) + return 7; + else if (value < valueMin) + return 9; + else + return 8; + } else // region 456 + { + if (value > valueMax) + return 4; + else if (value < valueMin) + return 6; + else + return 5; + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method is used in case the current segment passes from inside the visible rect (region 5, + see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by + the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). + + It returns the intersection point of the segment with the border of region 5. + + For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or + whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or + leaving it. It is important though that \a otherRegion correctly identifies the other region not + equal to 5. +*/ +QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double otherValuePx = mValueAxis->coordToPixel(otherValue); + const double valuePx = mValueAxis->coordToPixel(value); + const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); + const double keyPx = mKeyAxis->coordToPixel(key); + double intersectKeyPx = keyMinPx; // initial key just a fail-safe + double intersectValuePx = valueMinPx; // initial value just a fail-safe + switch (otherRegion) + { + case 1: // top and left edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 2: // left edge + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 3: // bottom and left edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 4: // top edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 5: + { + break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table + } + case 6: // bottom edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 7: // top and right edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 8: // right edge + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 9: // bottom and right edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + } + if (mKeyAxis->orientation() == Qt::Horizontal) + return QPointF(intersectKeyPx, intersectValuePx); + else + return QPointF(intersectValuePx, intersectKeyPx); +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + In situations where a single segment skips over multiple regions it might become necessary to add + extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment + doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. + This method provides these points that must be added, assuming the original segment doesn't + start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by + \ref getTraverseCornerPoints.) + + For example, consider a segment which directly goes from region 4 to 2 but originally is far out + to the top left such that it doesn't cross region 5. Naively optimizing these points by + projecting them on the top and left borders of region 5 will create a segment that surely crosses + 5, creating a visual artifact in the plot. This method prevents this by providing extra points at + the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without + traversing 5. +*/ +QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + QVector result; + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMax); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } + case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + else + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + break; + } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMin); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); break; } + case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + else + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + break; + } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 6: + { + switch (currentRegion) + { + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 4: { result << coordsToPixels(keyMax, valueMax); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); break; } + case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + else + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + break; + } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 6: { result << coordsToPixels(keyMax, valueMin); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + else + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + break; + } + } + break; + } + } + return result; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref + getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion + nor \a currentRegion is 5 itself. + + If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the + segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref + getTraverse). +*/ +bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 4: + case 7: + case 2: + case 3: return false; + default: return true; + } + } + case 2: + { + switch (currentRegion) + { + case 1: + case 3: return false; + default: return true; + } + } + case 3: + { + switch (currentRegion) + { + case 1: + case 2: + case 6: + case 9: return false; + default: return true; + } + } + case 4: + { + switch (currentRegion) + { + case 1: + case 7: return false; + default: return true; + } + } + case 5: return false; // should never occur + case 6: + { + switch (currentRegion) + { + case 3: + case 9: return false; + default: return true; + } + } + case 7: + { + switch (currentRegion) + { + case 1: + case 4: + case 8: + case 9: return false; + default: return true; + } + } + case 8: + { + switch (currentRegion) + { + case 7: + case 9: return false; + default: return true; + } + } + case 9: + { + switch (currentRegion) + { + case 3: + case 6: + case 8: + case 7: return false; + default: return true; + } + } + default: return true; + } +} + + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref mayTraverse test has returned true, so there is a chance the + segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible + region 5. + + The return value of this method indicates whether the segment actually traverses region 5 or not. + + If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and + exit points of region 5. They will become the optimized points for that segment. +*/ +bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + QList intersections; + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double keyPx = mKeyAxis->coordToPixel(key); + const double valuePx = mValueAxis->coordToPixel(value); + const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); + const double prevValuePx = mValueAxis->coordToPixel(prevValue); + if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); + } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); + } else // line is skewed + { + double gamma; + double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); + // check top of rect: + gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); + // check bottom of rect: + gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); + const double valuePerKeyPx = 1.0/keyPerValuePx; + // check left of rect: + gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); + // check right of rect: + gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); + } + + // handle cases where found points isn't exactly 2: + if (intersections.size() > 2) + { + // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: + double distSqrMax = 0; + QPointF pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = intersections.at(i); + pv2 = intersections.at(k); + distSqrMax = distSqr; + } + } + } + intersections = QList() << pv1 << pv2; + } else if (intersections.size() != 2) + { + // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment + return false; + } + + // possibly re-sort points so optimized point segment has same direction as original segment: + double xDelta = keyPx-prevKeyPx; + double yDelta = valuePx-prevValuePx; + if (mKeyAxis->orientation() != Qt::Horizontal) + qSwap(xDelta, yDelta); + if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction + intersections.move(0, 1); + crossA = intersections.at(0); + crossB = intersections.at(1); + return true; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref getTraverse test has returned true, so the segment definitely + traverses the visible region 5 when going from \a prevRegion to \a currentRegion. + + In certain situations it is not sufficient to merely generate the entry and exit points of the + segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in + addition to traversing region 5, skips another region outside of region 5, which makes it + necessary to add an optimized corner point there (very similar to the job \ref + getOptimizedCornerPoints does for segments that are completely in outside regions and don't + traverse 5). + + As an example, consider a segment going from region 1 to region 6, traversing the lower left + corner of region 5. In this configuration, the segment additionally crosses the border between + region 1 and 2 before entering region 5. This makes it necessary to add an additional point in + the top left corner, before adding the optimized traverse points. So in this case, the output + parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be + empty. + + In some cases, such as when going from region 1 to 9, it may even be necessary to add additional + corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse + return the respective corner points. +*/ +void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: { break; } // shouldn't happen because this method only handles full traverses + case 6: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + } +} + +/*! \internal + + Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a + pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in + \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that + if the curve has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the curve line is also taken into account. + + If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns + -1.0. +*/ +double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + if (mDataContainer->size() == 1) + { + QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); + closestData = mDataContainer->constBegin(); + return QCPVector2D(dataPoint-pixelPoint).length(); + } + + // calculate minimum distances to curve data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + QVector lines; + getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width + for (int i=0; i QCPBarsGroup::bars() const + + Returns all bars currently in this group. + + \see bars(int index) +*/ + +/*! \fn int QCPBarsGroup::size() const + + Returns the number of QCPBars plottables that are part of this group. + +*/ + +/*! \fn bool QCPBarsGroup::isEmpty() const + + Returns whether this bars group is empty. + + \see size +*/ + +/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) + + Returns whether the specified \a bars plottable is part of this group. + +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new bars group for the specified QCustomPlot instance. +*/ +QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot), + mSpacingType(stAbsolute), + mSpacing(4) +{ +} + +QCPBarsGroup::~QCPBarsGroup() +{ + clear(); +} + +/*! + Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. + + The actual spacing can then be specified with \ref setSpacing. + + \see setSpacing +*/ +void QCPBarsGroup::setSpacingType(SpacingType spacingType) +{ + mSpacingType = spacingType; +} + +/*! + Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is + defined by the current \ref SpacingType, which can be set with \ref setSpacingType. + + \see setSpacingType +*/ +void QCPBarsGroup::setSpacing(double spacing) +{ + mSpacing = spacing; +} + +/*! + Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars + exists, returns 0. + + \see bars(), size +*/ +QCPBars *QCPBarsGroup::bars(int index) const +{ + if (index >= 0 && index < mBars.size()) + { + return mBars.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Removes all QCPBars plottables from this group. + + \see isEmpty +*/ +void QCPBarsGroup::clear() +{ + Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay + bars->setBarsGroup(0); // removes itself via removeBars +} + +/*! + Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref + QCPBars::setBarsGroup on the \a bars instance. + + \see insert, remove +*/ +void QCPBarsGroup::append(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + else + qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); +} + +/*! + Inserts the specified \a bars plottable into this group at the specified index position \a i. + This gives you full control over the ordering of the bars. + + \a bars may already be part of this group. In that case, \a bars is just moved to the new index + position. + + \see append, remove +*/ +void QCPBarsGroup::insert(int i, QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + // first append to bars list normally: + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + // then move to according position: + mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); +} + +/*! + Removes the specified \a bars plottable from this group. + + \see contains, clear +*/ +void QCPBarsGroup::remove(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (mBars.contains(bars)) + bars->setBarsGroup(0); + else + qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); +} + +/*! \internal + + Adds the specified \a bars to the internal mBars list of bars. This method does not change the + barsGroup property on \a bars. + + \see unregisterBars +*/ +void QCPBarsGroup::registerBars(QCPBars *bars) +{ + if (!mBars.contains(bars)) + mBars.append(bars); +} + +/*! \internal + + Removes the specified \a bars from the internal mBars list of bars. This method does not change + the barsGroup property on \a bars. + + \see registerBars +*/ +void QCPBarsGroup::unregisterBars(QCPBars *bars) +{ + mBars.removeOne(bars); +} + +/*! \internal + + Returns the pixel offset in the key dimension the specified \a bars plottable should have at the + given key coordinate \a keyCoord. The offset is relative to the pixel position of the key + coordinate \a keyCoord. +*/ +double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) +{ + // find list of all base bars in case some mBars are stacked: + QList baseBars; + Q_FOREACH (const QCPBars *b, mBars) + { + while (b->barBelow()) + b = b->barBelow(); + if (!baseBars.contains(b)) + baseBars.append(b); + } + // find base bar this "bars" is stacked on: + const QCPBars *thisBase = bars; + while (thisBase->barBelow()) + thisBase = thisBase->barBelow(); + + // determine key pixel offset of this base bars considering all other base bars in this barsgroup: + double result = 0; + int index = baseBars.indexOf(thisBase); + if (index >= 0) + { + if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) + { + return result; + } else + { + double lowerPixelWidth, upperPixelWidth; + int startIndex; + int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative + if (baseBars.size() % 2 == 0) // even number of bars + { + startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); + result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing + } else // uneven number of bars + { + startIndex = (baseBars.size()-1)/2+dir; + baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar + result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing + } + for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars + { + baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth); + result += getPixelSpacing(baseBars.at(i), keyCoord); + } + // finally half of our bars width: + baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; + // correct sign of result depending on orientation and direction of key axis: + result *= dir*thisBase->keyAxis()->pixelOrientation(); + } + } + return result; +} + +/*! \internal + + Returns the spacing in pixels which is between this \a bars and the following one, both at the + key coordinate \a keyCoord. + + \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only + needed to get access to the key axis transformation and axis rect for the modes \ref + stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in + \ref stPlotCoords on a logarithmic axis. +*/ +double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) +{ + switch (mSpacingType) + { + case stAbsolute: + { + return mSpacing; + } + case stAxisRectRatio: + { + if (bars->keyAxis()->orientation() == Qt::Horizontal) + return bars->keyAxis()->axisRect()->width()*mSpacing; + else + return bars->keyAxis()->axisRect()->height()*mSpacing; + } + case stPlotCoords: + { + double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); + return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); + } + } + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBarsData + \brief Holds the data of one single data point (one bar) for QCPBars. + + The stored data is: + \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) + \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPBarsDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPBarsData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPBarsData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a bar data point with key and value set to zero. +*/ +QCPBarsData::QCPBarsData() : + key(0), + value(0) +{ +} + +/*! + Constructs a bar data point with the specified \a key and \a value. +*/ +QCPBarsData::QCPBarsData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBars + \brief A plottable representing a bar chart in a plot. + + \image html QCPBars.png + + To plot data, assign it with the \ref setData or \ref addData functions. + + \section qcpbars-appearance Changing the appearance + + The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). + The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. + + Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other + (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear + stacked. + + If you would like to group multiple QCPBars plottables together so they appear side by side as + shown below, use QCPBarsGroup. + + \image html QCPBarsGroup.png + + \section qcpbars-usage Usage + + Like all data representing objects in QCustomPlot, the QCPBars is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/*! \fn QCPBars *QCPBars::barBelow() const + Returns the bars plottable that is directly below this bars plottable. + If there is no such plottable, returns 0. + + \see barAbove, moveBelow, moveAbove +*/ + +/*! \fn QCPBars *QCPBars::barAbove() const + Returns the bars plottable that is directly above this bars plottable. + If there is no such plottable, returns 0. + + \see barBelow, moveBelow, moveAbove +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.75), + mWidthType(wtPlotCoords), + mBarsGroup(0), + mBaseValue(0), + mStackingGap(0) +{ + // modify inherited properties from abstract plottable: + mPen.setColor(Qt::blue); + mPen.setStyle(Qt::SolidLine); + mBrush.setColor(QColor(40, 50, 255, 30)); + mBrush.setStyle(Qt::SolidPattern); + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPBars::~QCPBars() +{ + setBarsGroup(0); + if (mBarBelow || mBarAbove) + connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. + Modifying the data in the container will then affect all bars that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the bar's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 + + \see addData +*/ +void QCPBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets the width of the bars. + + How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), + depends on the currently set width type, see \ref setWidthType and \ref WidthType. +*/ +void QCPBars::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the bars is defined. See the documentation of \ref WidthType for an + explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPBars::setWidthType(QCPBars::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref + QCPBarsGroup::append. + + To remove this QCPBars from any group, set \a barsGroup to 0. +*/ +void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) +{ + // deregister at old group: + if (mBarsGroup) + mBarsGroup->unregisterBars(this); + mBarsGroup = barsGroup; + // register at new group: + if (mBarsGroup) + mBarsGroup->registerBars(this); +} + +/*! + Sets the base value of this bars plottable. + + The base value defines where on the value coordinate the bars start. How far the bars extend from + the base value is given by their individual value data. For example, if the base value is set to + 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at + 3. + + For stacked bars, only the base value of the bottom-most QCPBars has meaning. + + The default base value is 0. +*/ +void QCPBars::setBaseValue(double baseValue) +{ + mBaseValue = baseValue; +} + +/*! + If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method + allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by + the bars below it. +*/ +void QCPBars::setStackingGap(double pixels) +{ + mStackingGap = pixels; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(double key, double value) +{ + mDataContainer->add(QCPBarsData(key, value)); +} + +/*! + Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear + below the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object below itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barAbove, barBelow +*/ +void QCPBars::moveBelow(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar below it: + if (bars) + { + if (bars->mBarBelow) + connectBars(bars->mBarBelow.data(), this); + connectBars(this, bars); + } +} + +/*! + Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear + above the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object above itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barBelow, barAbove +*/ +void QCPBars::moveAbove(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar above it: + if (bars) + { + if (bars->mBarAbove) + connectBars(this, bars->mBarAbove.data()); + connectBars(bars, this); + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getBarRect(it->key, it->value))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getBarRect(it->key, it->value).contains(pos)) + { + if (details) + { + int pointIndex = it-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return mParentPlot->selectionTolerance()*0.99; + } + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in + absolute pixels), using this method to adapt the key axis range to fit the bars into the + currently visible axis range will not work perfectly. Because in the moment the axis range is + changed to the new range, the fixed pixel widths/spacings will represent different coordinate + spans than before, which in turn would require a different key range to perfectly fit, and so on. + The only solution would be to iteratively approach the perfect fitting axis range, but the + mismatch isn't large enough in most applications, to warrant this here. If a user does need a + better fit, he should call the corresponding axis rescale multiple times in a row. + */ + QCPRange range; + range = mDataContainer->keyRange(foundRange, inSignDomain); + + // determine exact range of bars by including bar width and barsgroup offset: + if (foundRange && mKeyAxis) + { + double lowerPixelWidth, upperPixelWidth, keyPixel; + // lower range bound: + getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); + const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) + range.lower = lowerCorrected; + // upper range bound: + getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); + const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) + range.upper = upperCorrected; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + // Note: can't simply use mDataContainer->valueRange here because we need to + // take into account bar base value and possible stacking of multiple bars + QCPRange range; + range.lower = mBaseValue; + range.upper = mBaseValue; + bool haveLower = true; // set to true, because baseValue should always be visible in bar charts + bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts + QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (inKeyRange != QCPRange()) + { + itBegin = mDataContainer->findBegin(inKeyRange.lower); + itEnd = mDataContainer->findEnd(inKeyRange.upper); + } + for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + + foundRange = true; // return true because bar charts always have the 0-line visible + return range; +} + +/* inherits documentation from base class */ +QPointF QCPBars::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); + const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyPixel, valuePixel); + else + return QPointF(valuePixel, keyPixel); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/* inherits documentation from base class */ +void QCPBars::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mDataContainer->isEmpty()) return; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPBarsDataContainer::const_iterator begin = visibleBegin; + QCPBarsDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +#endif + // draw bar: + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyBrush(painter); + mSelectionDecorator->applyPen(painter); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + } + applyDefaultAntialiasingHint(painter); + painter->drawPolygon(getBarRect(it->key, it->value)); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setBrush(mBrush); + painter->setPen(mPen); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + if (mDataContainer->isEmpty()) + { + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + + // get visible data range as QMap iterators + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); + double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); + double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); + bool isVisible = false; + // walk left from begin to find lower bar that actually is completely outside visible pixel range: + QCPBarsDataContainer::const_iterator it = begin; + while (it != mDataContainer->constBegin()) + { + --it; + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); + if (isVisible) + begin = it; + else + break; + } + // walk right from ubound to find upper bar that actually is completely outside visible pixel range: + it = end; + while (it != mDataContainer->constEnd()) + { + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); + if (isVisible) + end = it+1; + else + break; + ++it; + } +} + +/*! \internal + + Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The + rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref + setBaseValue), and to have non-overlapping border lines with the bars stacked below. +*/ +QRectF QCPBars::getBarRect(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double lowerPixelWidth, upperPixelWidth; + getPixelWidth(key, lowerPixelWidth, upperPixelWidth); + double base = getStackedBaseValue(key, value >= 0); + double basePixel = valueAxis->coordToPixel(base); + double valuePixel = valueAxis->coordToPixel(base+value); + double keyPixel = keyAxis->coordToPixel(key); + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, key); + double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); + bottomOffset += mBarBelow ? mStackingGap : 0; + bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); + if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) + bottomOffset = valuePixel-basePixel; + if (keyAxis->orientation() == Qt::Horizontal) + { + return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); + } else + { + return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). + + The output parameters \a lower and \a upper return the number of pixels the bar extends to lower + and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a + lower is negative and \a upper positive). +*/ +void QCPBars::getPixelWidth(double key, double &lower, double &upper) const +{ + lower = 0; + upper = 0; + switch (mWidthType) + { + case wtAbsolute: + { + upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + { + double keyPixel = mKeyAxis.data()->coordToPixel(key); + upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; + // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by + // coordinate transform which includes range direction + } else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } +} + +/*! \internal + + This function is called to find at which value to start drawing the base of a bar at \a key, when + it is stacked on top of another QCPBars (e.g. with \ref moveAbove). + + positive and negative bars are separated per stack (positive are stacked above baseValue upwards, + negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the + bar for which we need the base value is negative, set \a positive to false. +*/ +double QCPBars::getStackedBaseValue(double key, bool positive) const +{ + if (mBarBelow) + { + double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack + // find bars of mBarBelow that are approximately at key and find largest one: + double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point + if (key == 0) + epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); + QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); + QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); + while (it != itEnd) + { + if (it->key > key-epsilon && it->key < key+epsilon) + { + if ((positive && it->value > max) || + (!positive && it->value < max)) + max = it->value; + } + ++it; + } + // recurse down the bar-stack to find the total height: + return max + mBarBelow.data()->getStackedBaseValue(key, positive); + } else + return mBaseValue; +} + +/*! \internal + + Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) + currently above lower and below upper will become disconnected to lower/upper. + + If lower is zero, upper will be disconnected at the bottom. + If upper is zero, lower will be disconnected at the top. +*/ +void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) +{ + if (!lower && !upper) return; + + if (!lower) // disconnect upper at bottom + { + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + upper->mBarBelow = 0; + } else if (!upper) // disconnect lower at top + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + lower->mBarAbove = 0; + } else // connect lower and upper + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + lower->mBarAbove = upper; + upper->mBarBelow = lower; + } +} +/* end of 'src/plottables/plottable-bars.cpp' */ + + +/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBoxData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBoxData + \brief Holds the data of one single data point for QCPStatisticalBox. + + The stored data is: + + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + + \li \a minimum: the position of the lower whisker, typically the minimum measurement of the + sample that's not considered an outlier. + + \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a median: the value of the median mark inside the quartile box. The median separates the + sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) + + \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a maximum: the position of the upper whisker, typically the maximum measurement of the + sample that's not considered an outlier. + + \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key + coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) + + The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a + typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template + parameter. See the documentation there for an explanation regarding the data type's generic + methods. + + \see QCPStatisticalBoxDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPStatisticalBoxData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainValue() const + + Returns the \a median member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const + + Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box + data point, possibly further expanded by outliers. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData() : + key(0), + minimum(0), + lowerQuartile(0), + median(0), + upperQuartile(0), + maximum(0) +{ +} + +/*! + Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a + upperQuartile, \a maximum and optionally a number of \a outliers. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : + key(key), + minimum(minimum), + lowerQuartile(lowerQuartile), + median(median), + upperQuartile(upperQuartile), + maximum(maximum), + outliers(outliers) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBox +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBox + \brief A plottable representing a single statistical box in a plot. + + \image html QCPStatisticalBox.png + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPStatisticalBoxDataContainer. + + Additionally each data point can itself have a list of outliers, drawn as scatter points at the + key coordinate of the respective statistical box data point. They can either be set by using the + respective \ref addData(double,double,double,double,double,double,const QVector&) + "addData" method or accessing the individual data points through \ref data, and setting the + QVector outliers of the data points directly. + + \section qcpstatisticalbox-appearance Changing the appearance + + The appearance of each data point box, ranging from the lower to the upper quartile, is + controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref + setWidth in plot coordinates. + + Each data point's visual representation also consists of two whiskers. Whiskers are the lines + which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. + The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, + \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at + the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set + the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a + few pixels due to the pen cap being not perfectly flat. + + The median indicator line inside the box has its own pen, \ref setMedianPen. + + The outlier data points are drawn as normal scatter points. Their look can be controlled with + \ref setOutlierStyle + + \section qcpstatisticalbox-usage Usage + + Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 +*/ + +/* start documentation of inline functions */ + +/*! \fn QSharedPointer QCPStatisticalBox::data() const + + Returns a shared pointer to the internal data storage of type \ref + QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more + convenient and faster than using the regular \ref setData or \ref addData methods. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its + value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and + not have the same orientation. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not + delete it manually but use QCustomPlot::removePlottable() instead. +*/ +QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.5), + mWhiskerWidth(0.2), + mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), + mWhiskerBarPen(Qt::black), + mWhiskerAntialiased(false), + mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), + mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) +{ + setPen(QPen(Qt::black)); + setBrush(Qt::NoBrush); +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container + safely. Modifying the data in the container will then affect all statistical boxes that share the + container. Sharing can be achieved by simply exchanging the data containers wrapped in shared + pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the statistical box data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 + + \see addData +*/ +void QCPStatisticalBox::setData(QSharedPointer data) +{ + mDataContainer = data; +} +/*! \overload + + Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a + median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the + number of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); +} + +/*! + Sets the width of the boxes in key coordinates. + + \see setWhiskerWidth +*/ +void QCPStatisticalBox::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the width of the whiskers in key coordinates. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWidth +*/ +void QCPStatisticalBox::setWhiskerWidth(double width) +{ + mWhiskerWidth = width; +} + +/*! + Sets the pen used for drawing the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone + line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. + + \see setWhiskerBarPen +*/ +void QCPStatisticalBox::setWhiskerPen(const QPen &pen) +{ + mWhiskerPen = pen; +} + +/*! + Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at + each end of the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWhiskerPen +*/ +void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) +{ + mWhiskerBarPen = pen; +} + +/*! + Sets whether the statistical boxes whiskers are drawn with antialiasing or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) +{ + mWhiskerAntialiased = enabled; +} + +/*! + Sets the pen used for drawing the median indicator line inside the statistical boxes. +*/ +void QCPStatisticalBox::setMedianPen(const QPen &pen) +{ + mMedianPen = pen; +} + +/*! + Sets the appearance of the outlier data points. + + Outliers can be specified with the method + \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +*/ +void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) +{ + mOutlierStyle = style; +} + +/*! \overload + + Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and + \a maximum to the current data. The provided vectors should have equal length. Else, the number + of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || + median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" + << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); + const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->minimum = minimum[i]; + it->lowerQuartile = lowerQuartile[i]; + it->median = median[i]; + it->upperQuartile = upperQuartile[i]; + it->maximum = maximum[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile + and \a maximum to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +{ + mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getQuartileBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + double minDistSqr = std::numeric_limits::max(); + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getQuartileBox(it).contains(pos)) // quartile box + { + double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } else // whiskers + { + const QVector whiskerBackbones(getWhiskerBackboneLines(it)); + for (int i=0; iconstBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return qSqrt(minDistSqr); + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; + QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +# ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->minimum) || + QCP::isInvalidData(it->lowerQuartile, it->median) || + QCP::isInvalidData(it->upperQuartile, it->maximum)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); + for (int i=0; ioutliers.size(); ++i) + if (QCP::isInvalidData(it->outliers.at(i))) + qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +# endif + + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + QCPScatterStyle finalOutlierStyle = mOutlierStyle; + if (isSelectedSegment && mSelectionDecorator) + finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); + drawStatisticalBox(painter, it, finalOutlierStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->setBrush(mBrush); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! + Draws the graphical representation of a single statistical box with the data given by the + iterator \a it with the provided \a painter. + + If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. + + \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const +{ + // draw quartile box: + applyDefaultAntialiasingHint(painter); + const QRectF quartileBox = getQuartileBox(it); + painter->drawRect(quartileBox); + // draw median line with cliprect set to quartile box: + painter->save(); + painter->setClipRect(quartileBox, Qt::IntersectClip); + painter->setPen(mMedianPen); + painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); + painter->restore(); + // draw whisker lines: + applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); + painter->setPen(mWhiskerPen); + painter->drawLines(getWhiskerBackboneLines(it)); + painter->setPen(mWhiskerBarPen); + painter->drawLines(getWhiskerBarLines(it)); + // draw outliers: + applyScattersAntialiasingHint(painter); + outlierStyle.applyTo(painter, mPen); + for (int i=0; ioutliers.size(); ++i) + outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points +} + +/*! \internal + + Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the + value range from the lower to the upper quartile, of the data given by \a it. + + \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QRectF result; + result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); + result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); + return result; +} + +/*! \internal + + Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value + range from the minimum to the lower quartile, and from the upper quartile to the maximum of the + data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines +*/ +QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone + result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone + return result; +} + +/*! \internal + + Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the + end of the whisker backbones, at the minimum and maximum of the data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines +*/ +QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar + result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar + return result; +} +/* end of 'src/plottables/plottable-statisticalbox.cpp' */ + + +/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorMapData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorMapData + \brief Holds the two-dimensional data of a QCPColorMap plottable. + + This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref + QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a + color, depending on the value. + + The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). + Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref + setKeyRange, \ref setValueRange). + + The data cells can be accessed in two ways: They can be directly addressed by an integer index + with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot + coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are + provided by the functions \ref coordToCell and \ref cellToCoord. + + A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if + allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref + fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on + the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. + + This class also buffers the minimum and maximum values that are in the data set, to provide + QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value + that is greater than the current maximum increases this maximum to the new value. However, + setting the cell that currently holds the maximum value to a smaller value doesn't decrease the + maximum again, because finding the true new maximum would require going through the entire data + array, which might be time consuming. The same holds for the data minimum. This functionality is + given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the + true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience + parameter \a recalculateDataBounds which may be set to true to automatically call \ref + recalculateDataBounds internally. +*/ + +/* start of documentation of inline functions */ + +/*! \fn bool QCPColorMapData::isEmpty() const + + Returns whether this instance carries no data. This is equivalent to having a size where at least + one of the dimensions is 0 (see \ref setSize). +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction + and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap + at the coordinates \a keyRange and \a valueRange. + + \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange +*/ +QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : + mKeySize(0), + mValueSize(0), + mKeyRange(keyRange), + mValueRange(valueRange), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + setSize(keySize, valueSize); + fill(0); +} + +QCPColorMapData::~QCPColorMapData() +{ + if (mData) + delete[] mData; + if (mAlpha) + delete[] mAlpha; +} + +/*! + Constructs a new QCPColorMapData instance copying the data and range of \a other. +*/ +QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : + mKeySize(0), + mValueSize(0), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + *this = other; +} + +/*! + Overwrites this color map data instance with the data stored in \a other. The alpha map state is + transferred, too. +*/ +QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) +{ + if (&other != this) + { + const int keySize = other.keySize(); + const int valueSize = other.valueSize(); + if (!other.mAlpha && mAlpha) + clearAlpha(); + setSize(keySize, valueSize); + if (other.mAlpha && !mAlpha) + createAlpha(false); + setRange(other.keyRange(), other.valueRange()); + if (!isEmpty()) + { + memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); + if (mAlpha) + memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); + } + mDataBounds = other.mDataBounds; + mDataModified = true; + } + return *this; +} + +/* undocumented getter */ +double QCPColorMapData::data(double key, double value) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + return mData[valueCell*mKeySize + keyCell]; + else + return 0; +} + +/* undocumented getter */ +double QCPColorMapData::cell(int keyIndex, int valueIndex) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mData[valueIndex*mKeySize + keyIndex]; + else + return 0; +} + +/*! + Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. + + If this color map data doesn't have an alpha map (because \ref setAlpha was never called after + creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. + + \see setAlpha +*/ +unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) +{ + if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mAlpha[valueIndex*mKeySize + keyIndex]; + else + return 255; +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in + the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref + isEmpty returns true. + + \see setRange, setKeySize, setValueSize +*/ +void QCPColorMapData::setSize(int keySize, int valueSize) +{ + if (keySize != mKeySize || valueSize != mValueSize) + { + mKeySize = keySize; + mValueSize = valueSize; + if (mData) + delete[] mData; + mIsEmpty = mKeySize == 0 || mValueSize == 0; + if (!mIsEmpty) + { +#ifdef __EXCEPTIONS + try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message +#endif + mData = new double[mKeySize*mValueSize]; +#ifdef __EXCEPTIONS + } catch (...) { mData = 0; } +#endif + if (mData) + fill(0); + else + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; + } else + mData = 0; + + if (mAlpha) // if we had an alpha map, recreate it with new size + createAlpha(); + + mDataModified = true; + } +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. + + \see setKeyRange, setSize, setValueSize +*/ +void QCPColorMapData::setKeySize(int keySize) +{ + setSize(keySize, mValueSize); +} + +/*! + Resizes the data array to have \a valueSize cells in the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. + + \see setValueRange, setSize, setKeySize +*/ +void QCPColorMapData::setValueSize(int valueSize) +{ + setSize(mKeySize, valueSize); +} + +/*! + Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area + covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setSize +*/ +void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) +{ + setKeyRange(keyRange); + setValueRange(valueRange); +} + +/*! + Sets the coordinate range the data shall be distributed over in the key dimension. Together with + the value range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setRange, setValueRange, setSize +*/ +void QCPColorMapData::setKeyRange(const QCPRange &keyRange) +{ + mKeyRange = keyRange; +} + +/*! + Sets the coordinate range the data shall be distributed over in the value dimension. Together with + the key range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there + will be cells centered on the value coordinates 2, 2.5 and 3. + + \see setRange, setKeyRange, setSize +*/ +void QCPColorMapData::setValueRange(const QCPRange &valueRange) +{ + mValueRange = valueRange; +} + +/*! + Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a + z. + + \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or + value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, + you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to + determine the cell index. Rather directly access the cell index with \ref + QCPColorMapData::setCell. + + \see setCell, setRange +*/ +void QCPColorMapData::setData(double key, double value, double z) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + { + mData[valueCell*mKeySize + keyCell] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } +} + +/*! + Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices + enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see + \ref setSize). + + In the standard plot configuration (horizontal key axis and vertical value axis, both not + range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with + indices (keySize-1, valueSize-1) is in the top right corner of the color map. + + \see setData, setSize +*/ +void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + mData[valueIndex*mKeySize + keyIndex] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value + of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully + opaque cell. + + If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish + to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. + + Note that the cell-wise alpha which can be configured here is independent of any alpha configured + in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise + and gradient alpha, the alpha values will be blended accordingly during rendering of the color + map. + + \see fillAlpha, clearAlpha +*/ +void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + if (mAlpha || createAlpha()) + { + mAlpha[valueIndex*mKeySize + keyIndex] = alpha; + mDataModified = true; + } + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Goes through the data and updates the buffered minimum and maximum data values. + + Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange + and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten + with a smaller or larger value respectively, since the buffered maximum/minimum values have been + updated the last time. Why this is the case is explained in the class description (\ref + QCPColorMapData). + + Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a + recalculateDataBounds for convenience. Setting this to true will call this method for you, before + doing the rescale. +*/ +void QCPColorMapData::recalculateDataBounds() +{ + if (mKeySize > 0 && mValueSize > 0) + { + double minHeight = mData[0]; + double maxHeight = mData[0]; + const int dataCount = mValueSize*mKeySize; + for (int i=0; i maxHeight) + maxHeight = mData[i]; + if (mData[i] < minHeight) + minHeight = mData[i]; + } + mDataBounds.lower = minHeight; + mDataBounds.upper = maxHeight; + } +} + +/*! + Frees the internal data memory. + + This is equivalent to calling \ref setSize "setSize(0, 0)". +*/ +void QCPColorMapData::clear() +{ + setSize(0, 0); +} + +/*! + Frees the internal alpha map. The color map will have full opacity again. +*/ +void QCPColorMapData::clearAlpha() +{ + if (mAlpha) + { + delete[] mAlpha; + mAlpha = 0; + mDataModified = true; + } +} + +/*! + Sets all cells to the value \a z. +*/ +void QCPColorMapData::fill(double z) +{ + const int dataCount = mValueSize*mKeySize; + for (int i=0; i(data); + return; + } + if (copy) + { + *mMapData = *data; + } else + { + delete mMapData; + mMapData = data; + } + mMapImageInvalidated = true; +} + +/*! + Sets the data range of this color map to \a dataRange. The data range defines which data values + are mapped to the color gradient. + + To make the data range span the full range of the data set, use \ref rescaleDataRange. + + \see QCPColorScale::setDataRange +*/ +void QCPColorMap::setDataRange(const QCPRange &dataRange) +{ + if (!QCPRange::validRange(dataRange)) return; + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + if (mDataScaleType == QCPAxis::stLogarithmic) + mDataRange = dataRange.sanitizedForLogScale(); + else + mDataRange = dataRange.sanitizedForLinScale(); + mMapImageInvalidated = true; + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets whether the data is correlated with the color gradient linearly or logarithmically. + + \see QCPColorScale::setDataScaleType +*/ +void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + mMapImageInvalidated = true; + Q_EMIT dataScaleTypeChanged(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + } +} + +/*! + Sets the color gradient that is used to represent the data. For more details on how to create an + own gradient or use one of the preset gradients, see \ref QCPColorGradient. + + The colors defined by the gradient will be used to represent data values in the currently set + data range, see \ref setDataRange. Data points that are outside this data range will either be + colored uniformly with the respective gradient boundary color, or the gradient will repeat, + depending on \ref QCPColorGradient::setPeriodic. + + \see QCPColorScale::setGradient +*/ +void QCPColorMap::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + mMapImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets whether the color map image shall use bicubic interpolation when displaying the color map + shrinked or expanded, and not at a 1:1 pixel-to-data scale. + + \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" +*/ +void QCPColorMap::setInterpolate(bool enabled) +{ + mInterpolate = enabled; + mMapImageInvalidated = true; // because oversampling factors might need to change +} + +/*! + Sets whether the outer most data rows and columns are clipped to the specified key and value + range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). + + if \a enabled is set to false, the data points at the border of the color map are drawn with the + same width and height as all other data points. Since the data points are represented by + rectangles of one color centered on the data coordinate, this means that the shown color map + extends by half a data point over the specified key/value range in each direction. + + \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" +*/ +void QCPColorMap::setTightBoundary(bool enabled) +{ + mTightBoundary = enabled; +} + +/*! + Associates the color scale \a colorScale with this color map. + + This means that both the color scale and the color map synchronize their gradient, data range and + data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps + can be associated with one single color scale. This causes the color maps to also synchronize + those properties, via the mutual color scale. + + This function causes the color map to adopt the current color gradient, data range and data scale + type of \a colorScale. After this call, you may change these properties at either the color map + or the color scale, and the setting will be applied to both. + + Pass 0 as \a colorScale to disconnect the color scale from this color map again. +*/ +void QCPColorMap::setColorScale(QCPColorScale *colorScale) +{ + if (mColorScale) // unconnect signals from old color scale + { + disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + mColorScale = colorScale; + if (mColorScale) // connect signals to new color scale + { + setGradient(mColorScale.data()->gradient()); + setDataRange(mColorScale.data()->dataRange()); + setDataScaleType(mColorScale.data()->dataScaleType()); + connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } +} + +/*! + Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the + current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, + only for the third data dimension of the color map. + + The minimum and maximum values of the data set are buffered in the internal QCPColorMapData + instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref + QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For + performance reasons, however, they are only updated in an expanding fashion. So the buffered + maximum can only increase and the buffered minimum can only decrease. In consequence, changes to + the data that actually lower the maximum of the data set (by overwriting the cell holding the + current maximum with a smaller value), aren't recognized and the buffered maximum overestimates + the true maximum of the data set. The same happens for the buffered minimum. To recalculate the + true minimum and maximum by explicitly looking at each cell, the method + QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a + recalculateDataBounds calls this method before setting the data range to the buffered minimum and + maximum. + + \see setDataRange +*/ +void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) +{ + if (recalculateDataBounds) + mMapData->recalculateDataBounds(); + setDataRange(mMapData->dataBounds()); +} + +/*! + Takes the current appearance of the color map and updates the legend icon, which is used to + represent this color map in the legend (see \ref QCPLegend). + + The \a transformMode specifies whether the rescaling is done by a faster, low quality image + scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm + (Qt::SmoothTransformation). + + The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to + the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured + legend icon size, the thumb will be rescaled during drawing of the legend item. + + \see setDataRange +*/ +void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) +{ + if (mMapImage.isNull() && !data()->isEmpty()) + updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) + + if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again + { + bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); + } +} + +/* inherits documentation from base class */ +double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) + { + if (details) + details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. + return mParentPlot->selectionTolerance()*0.99; + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + foundRange = true; + QCPRange result = mMapData->keyRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (inKeyRange != QCPRange()) + { + if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) + { + foundRange = false; + return QCPRange(); + } + } + + foundRange = true; + QCPRange result = mMapData->valueRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/*! \internal + + Updates the internal map image buffer by going through the internal \ref QCPColorMapData and + turning the data values into color pixels with \ref QCPColorGradient::colorize. + + This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image + has been invalidated for a different reason (e.g. a change of the data range with \ref + setDataRange). + + If the map cell count is low, the image created will be oversampled in order to avoid a + QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images + without smooth transform enabled. Accordingly, oversampling isn't performed if \ref + setInterpolate is true. +*/ +void QCPColorMap::updateMapImage() +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) return; + if (mMapData->isEmpty()) return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + const int keySize = mMapData->keySize(); + const int valueSize = mMapData->valueSize(); + int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + + // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: + if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) + mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); + else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) + mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); + + if (mMapImage.isNull()) + { + qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; + mMapImage = QImage(QSize(10, 10), format); + mMapImage.fill(Qt::black); + } else + { + QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + // resize undersampled map image to actual key/value cell sizes: + if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) + mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); + else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) + mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); + localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image + } else if (!mUndersampledMapImage.isNull()) + mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it + + const double *rawData = mMapData->mData; + const unsigned char *rawAlpha = mMapData->mAlpha; + if (keyAxis->orientation() == Qt::Horizontal) + { + const int lineCount = valueSize; + const int rowCount = keySize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + } + } else // keyAxis->orientation() == Qt::Vertical + { + const int lineCount = keySize; + const int rowCount = valueSize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + } + } + + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + if (keyAxis->orientation() == Qt::Horizontal) + mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + else + mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + } + } + mMapData->mDataModified = false; + mMapImageInvalidated = false; +} + +/* inherits documentation from base class */ +void QCPColorMap::draw(QCPPainter *painter) +{ + if (mMapData->isEmpty()) return; + if (!mKeyAxis || !mValueAxis) return; + applyDefaultAntialiasingHint(painter); + + if (mMapData->mDataModified || mMapImageInvalidated) + updateMapImage(); + + // use buffer if painting vectorized (PDF): + const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); + QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized + QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in + QPixmap mapBuffer; + if (useBuffer) + { + const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps + mapBufferTarget = painter->clipRegion().boundingRect(); + mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); + mapBuffer.fill(Qt::transparent); + localPainter = new QCPPainter(&mapBuffer); + localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); + localPainter->translate(-mapBufferTarget.topLeft()); + } + + QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): + double halfCellWidth = 0; // in pixels + double halfCellHeight = 0; // in pixels + if (keyAxis()->orientation() == Qt::Horizontal) + { + if (mMapData->keySize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); + } else // keyAxis orientation is Qt::Vertical + { + if (mMapData->keySize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); + } + imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); + const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); + QRegion clipBackup; + if (mTightBoundary) + { + clipBackup = localPainter->clipRegion(); + QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + localPainter->setClipRect(tightClipRect, Qt::IntersectClip); + } + localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); + if (mTightBoundary) + localPainter->setClipRegion(clipBackup); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); + + if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter + { + delete localPainter; + painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); + } +} + +/* inherits documentation from base class */ +void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + // draw map thumbnail: + if (!mLegendIcon.isNull()) + { + QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); + QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); + iconRect.moveCenter(rect.center()); + painter->drawPixmap(iconRect.topLeft(), scaledIcon); + } + /* + // draw frame: + painter->setBrush(Qt::NoBrush); + painter->setPen(Qt::black); + painter->drawRect(rect.adjusted(1, 1, 0, 0)); + */ +} +/* end of 'src/plottables/plottable-colormap.cpp' */ + + +/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancialData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancialData + \brief Holds the data of one single data point for QCPFinancial. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a open: The opening value at the data point (this is the \a mainValue) + \li \a high: The high/maximum value at the data point + \li \a low: The low/minimum value at the data point + \li \a close: The closing value at the data point + + The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef + for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPFinancialDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPFinancialData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainValue() const + + Returns the \a open member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPFinancialData::valueRange() const + + Returns a QCPRange spanning from the \a low to the \a high value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPFinancialData::QCPFinancialData() : + key(0), + open(0), + high(0), + low(0), + close(0) +{ +} + +/*! + Constructs a data point with the specified \a key and OHLC values. +*/ +QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : + key(key), + open(open), + high(high), + low(low), + close(close) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancial +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancial + \brief A plottable representing a financial stock chart + + \image html QCPFinancial.png + + This plottable represents time series data binned to certain intervals, mainly used for stock + charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be + set via \ref setChartStyle. + + The data is passed via \ref setData as a set of open/high/low/close values at certain keys + (typically times). This means the data must be already binned appropriately. If data is only + available as a series of values (e.g. \a price against \a time), you can use the static + convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed + to \ref setData. + + The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref + setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and + the width to (or slightly less than) one time bin interval width. + + \section qcpfinancial-appearance Changing the appearance + + Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, + lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). + + If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are + represented with a different pen and brush than negative changes (\a close < \a open). These can + be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref + setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection + however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, + irrespective of whether the chart is single- or two-colored. + + \section qcpfinancial-usage Usage + + Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot + instance takes ownership of the plottable, so do not delete it manually but use + QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 + Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data + series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const + + Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods, in certain situations. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mChartStyle(csCandlestick), + mWidth(0.5), + mWidthType(wtPlotCoords), + mTwoColored(true), + mBrushPositive(QBrush(QColor(50, 160, 0))), + mBrushNegative(QBrush(QColor(180, 0, 15))), + mPenPositive(QPen(QColor(40, 150, 0))), + mPenNegative(QPen(QColor(170, 5, 5))) +{ + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPFinancial::~QCPFinancial() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. + Modifying the data in the container will then affect all financials that share the container. + Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the financial's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a + close. The provided vectors should have equal length. Else, the number of added points will be + the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, open, high, low, close, alreadySorted); +} + +/*! + Sets which representation style shall be used to display the OHLC data. +*/ +void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) +{ + mChartStyle = style; +} + +/*! + Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. + + A typical choice is to set it to (or slightly less than) one bin interval width. +*/ +void QCPFinancial::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for + an explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets whether this chart shall contrast positive from negative trends per data point by using two + separate colors to draw the respective bars/candlesticks. + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setTwoColored(bool twoColored) +{ + mTwoColored = twoColored; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushNegative, setPenPositive, setPenNegative +*/ +void QCPFinancial::setBrushPositive(const QBrush &brush) +{ + mBrushPositive = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushPositive, setPenNegative, setPenPositive +*/ +void QCPFinancial::setBrushNegative(const QBrush &brush) +{ + mBrushNegative = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setPenPositive(const QPen &pen) +{ + mPenPositive = pen; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setBrushNegative, setBrushPositive +*/ +void QCPFinancial::setPenNegative(const QPen &pen) +{ + mPenNegative = pen; +} + +/*! \overload + + Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. + The provided vectors should have equal length. Else, the number of added points will be the size + of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); + const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->open = open[i]; + it->high = high[i]; + it->low = low[i]; + it->close = close[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current + data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(double key, double open, double high, double low, double close) +{ + mDataContainer->add(QCPFinancialData(key, open, high, low, close)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(selectionHitBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + // perform select test according to configured style: + double result = -1; + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + case QCPFinancial::csCandlestick: + result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + } + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } + + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/*! + A convenience function that converts time series data (\a value against \a time) to OHLC binned + data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const + QCPFinancialDataContainer&). + + The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. + For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour + each, set \a timeBinSize to 3600. + + \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The + value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. + It merely defines the mathematical offset/phase of the bins that will be used to process the + data. +*/ +QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) +{ + QCPFinancialDataContainer data; + int count = qMin(time.size(), value.size()); + if (count == 0) + return QCPFinancialDataContainer(); + + QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); + int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); + for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); + if (i == count-1) // last data point is in current bin, finalize bin: + { + currentBinData.close = value.at(i); + currentBinData.key = timeBinOffset+(index)*timeBinSize; + data.add(currentBinData); + } + } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: + { + // finalize current bin: + currentBinData.close = value.at(i-1); + currentBinData.key = timeBinOffset+(index-1)*timeBinSize; + data.add(currentBinData); + // start next bin: + currentBinIndex = index; + currentBinData.open = value.at(i); + currentBinData.high = value.at(i); + currentBinData.low = value.at(i); + } + } + + return data; +} + +/* inherits documentation from base class */ +void QCPFinancial::draw(QCPPainter *painter) +{ + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPFinancialDataContainer::const_iterator begin = visibleBegin; + QCPFinancialDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + // draw data segment according to configured style: + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + drawOhlcPlot(painter, begin, end, isSelectedSegment); break; + case QCPFinancial::csCandlestick: + drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing + if (mChartStyle == csOhlc) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } + } else if (mChartStyle == csCandlestick) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. +*/ +void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); + // draw close: + painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); + } + } else + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); + // draw close: + painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. +*/ +void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + // draw low: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + // draw low: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); + } + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of + \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel + when this function is called). + + It returns the number of pixels the bar extends to higher keys, relative to the \a key + coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed + horizontal axis, the return value is negative. This is important so the open/close flags on the + \ref csOhlc bar are drawn to the correct side. +*/ +double QCPFinancial::getPixelWidth(double key, double keyPixel) const +{ + double result = 0; + switch (mWidthType) + { + case wtAbsolute: + { + if (mKeyAxis) + result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } + return result; +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a + end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + called by the drawing methods to determine which data (key) range is visible at the current key + axis range setting, so only that needs to be processed. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + begin may still be just outside the visible range. + + \a end returns the iterator just above the highest data point that needs to be taken into + account. Same as before, \a end may also lie just outside of the visible range + + if the plottable contains no data, both \a begin and \a end point to \c constEnd. +*/ +void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points +} + +/*! \internal + + Returns the hit box in pixel coordinates that will be used for data selection with the selection + rect (\ref selectTestRect), of the data point given by \a it. +*/ +QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double keyPixel = keyAxis->coordToPixel(it->key); + double highPixel = valueAxis->coordToPixel(it->high); + double lowPixel = valueAxis->coordToPixel(it->low); + double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); + if (keyAxis->orientation() == Qt::Horizontal) + return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); + else + return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); +} +/* end of 'src/plottables/plottable-financial.cpp' */ + + +/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBarsData + \brief Holds the data of one single error bar for QCPErrorBars. + + The stored data is: + \li \a errorMinus: how much the error bar extends towards negative coordinates from the data + point position + \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point + position + + The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a + typedef for QVector<\ref QCPErrorBarsData>. + + \see QCPErrorBarsDataContainer +*/ + +/*! + Constructs an error bar with errors set to zero. +*/ +QCPErrorBarsData::QCPErrorBarsData() : + errorMinus(0), + errorPlus(0) +{ +} + +/*! + Constructs an error bar with equal \a error in both negative and positive direction. +*/ +QCPErrorBarsData::QCPErrorBarsData(double error) : + errorMinus(error), + errorPlus(error) +{ +} + +/*! + Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, + respectively. +*/ +QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : + errorMinus(errorMinus), + errorPlus(errorPlus) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBars + \brief A plottable that adds a set of error bars to other plottables. + + \image html QCPErrorBars.png + + The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref + QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. + + Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the + error bars. The orientation of the error bars can be controlled with \ref setErrorType. + + By using \ref setData, you can supply the actual error data, either as symmetric error or + plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute + key/value position of each error bar will be adopted from the configured data plottable. The + error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points + of the data plottable. You can directly access and manipulate the error bar data via \ref data. + + Set either of the plus/minus errors to NaN (qQNaN() or + std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at + that index. + + \section qcperrorbars-appearance Changing the appearance + + The appearance of the error bars is defined by the pen (\ref setPen), and the width of the + whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data + point center to prevent that error bars are drawn too close to or even through scatter points. + This gap size can be controlled via \ref setSymbolGap. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPErrorBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You + may use it to directly manipulate the error values, which may be more convenient and faster than + using the regular \ref setData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + It is also important that the \a keyAxis and \a valueAxis are the same for the error bars + plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). + + The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not + delete it manually but use \ref QCustomPlot::removePlottable() instead. +*/ +QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QVector), + mErrorType(etValueError), + mWhiskerWidth(9), + mSymbolGap(10) +{ + setPen(QPen(Qt::black, 0)); + setBrush(Qt::NoBrush); +} + +QCPErrorBars::~QCPErrorBars() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data + container safely. Modifying the data in the container will then affect all \ref QCPErrorBars + instances that share the container. Sharing can be achieved by simply exchanging the data + containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, assign the + data containers directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 + (This uses different notation compared with other plottables, because the \ref QCPErrorBars + uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) + + \see addData +*/ +void QCPErrorBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &error) +{ + mDataContainer->clear(); + addData(error); +} + +/*! \overload + + Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) +{ + mDataContainer->clear(); + addData(errorMinus, errorPlus); +} + +/*! + Sets the data plottable to which the error bars will be applied. The error values specified e.g. + via \ref setData will be associated one-to-one by the data point index to the data points of \a + plottable. This means that the error bars will adopt the key/value coordinates of the data point + with the same index. + + The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref + QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either + of these restrictions is violated, a corresponding qDebug output is generated, and the data + plottable of this \ref QCPErrorBars instance is set to zero. + + For proper display, care must also be taken that the key and value axes of the \a plottable match + those configured for this \ref QCPErrorBars instance. +*/ +void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) +{ + if (plottable && qobject_cast(plottable)) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; + return; + } + if (plottable && !plottable->interface1D()) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; + return; + } + + mDataPlottable = plottable; +} + +/*! + Sets in which orientation the error bars shall appear on the data points. If your data needs both + error dimensions, create two \ref QCPErrorBars with different \a type. +*/ +void QCPErrorBars::setErrorType(ErrorType type) +{ + mErrorType = type; +} + +/*! + Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to + \a pixels. +*/ +void QCPErrorBars::setWhiskerWidth(double pixels) +{ + mWhiskerWidth = pixels; +} + +/*! + Sets the gap diameter around the data points that will be left out when drawing the error bar + backbones. This gap prevents that error bars are drawn too close to or even through scatter + points. +*/ +void QCPErrorBars::setSymbolGap(double pixels) +{ + mSymbolGap = pixels; +} + +/*! \overload + + Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &error) +{ + addData(error, error); +} + +/*! \overload + + Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) +{ + if (errorMinus.size() != errorPlus.size()) + qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); + const int n = qMin(errorMinus.size(), errorPlus.size()); + mDataContainer->reserve(n); + for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); +} + +/*! \overload + + Adds a single symmetrical error bar as specified in \a error. The errors will be associated + one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double error) +{ + mDataContainer->append(QCPErrorBarsData(error)); +} + +/*! \overload + + Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors + will be associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double errorMinus, double errorPlus) +{ + mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); +} + +/* inherits documentation from base class */ +int QCPErrorBars::dataCount() const +{ + return mDataContainer->size(); +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataSortKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataSortKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainValue(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainValue(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::dataValueRange(int index) const +{ + if (mDataPlottable) + { + const double value = mDataPlottable->interface1D()->dataMainValue(index); + if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) + return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); + else + return QCPRange(value, value); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QCPRange(); + } +} + +/* inherits documentation from base class */ +QPointF QCPErrorBars::dataPixelPosition(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataPixelPosition(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QPointF(); +} + +/* inherits documentation from base class */ +bool QCPErrorBars::sortKeyIsMainKey() const +{ + if (mDataPlottable) + { + return mDataPlottable->interface1D()->sortKeyIsMainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return true; + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if (!mDataPlottable) + return result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); + + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + backbones.clear(); + whiskers.clear(); + getErrorBarLines(it, backbones, whiskers); + for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); + break; + } + } + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); + if (beginIndex >= mDataContainer->size()) + beginIndex = mDataContainer->size()-1; + return beginIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); + if (endIndex > mDataContainer->size()) + endIndex = mDataContainer->size(); + return endIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mDataPlottable) return -1; + + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +void QCPErrorBars::draw(QCPPainter *painter) +{ + if (!mDataPlottable) return; + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + + // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually + // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): + bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) + qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); + } +#endif + + applyDefaultAntialiasingHint(painter); + painter->setBrush(Qt::NoBrush); + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + QVector backbones, whiskers; + for (int i=0; i= unselectedSegments.size(); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + if (painter->pen().capStyle() == Qt::SquareCap) + { + QPen capFixPen(painter->pen()); + capFixPen.setCapStyle(Qt::FlatCap); + painter->setPen(capFixPen); + } + backbones.clear(); + whiskers.clear(); + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) + getErrorBarLines(it, backbones, whiskers); + } + painter->drawLines(backbones); + painter->drawLines(whiskers); + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) + { + painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); + painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); + painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); + } else + { + painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); + painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); + painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); + } +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (mErrorType == etValueError) + { + // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } else // mErrorType == etKeyError + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(dataKey)) continue; + // plus error: + double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); + itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); + } + for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange) + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) + continue; + } + if (mErrorType == etValueError) + { + const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(dataValue)) continue; + // plus error: + double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } else // mErrorType == etKeyError + { + // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! \internal + + Calculates the lines that make up the error bar belonging to the data point \a it. + + The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so + calling this method with different \a it but the same \a backbones and \a whiskers allows to + accumulate lines for multiple data points. + + This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars + instance and within the bounds of the associated data plottable. +*/ +void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const +{ + if (!mDataPlottable) return; + + int index = it-mDataContainer->constBegin(); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) + return; + QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); + QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); + const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value + const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); + // plus error: + double errorStart, errorEnd; + if (!qIsNaN(it->errorPlus)) + { + errorStart = centerErrorAxisPixel+symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } + // minus error: + if (!qIsNaN(it->errorMinus)) + { + errorStart = centerErrorAxisPixel-symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } +} + +/*! \internal + + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key + coordinates relative to their data point key, this method checks all outer error bars whether + they truly don't reach into the visible portion of the axis rect, by calling \ref + errorBarVisible. On the other hand error bars with type \ref etValueError that are associated + with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype + "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of + error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref + QCPPlottableInterface1D::findEnd). + + If the plottable's sort key is not equal to the main key, this method returns the full data + range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a + point-by-point basis in the \ref draw method. +*/ +void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable || rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) + { + // if the sort key isn't the main key, it's not possible to find a contiguous range of visible + // data points, so this method then only applies the range restriction and otherwise returns + // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing + QCPDataRange dataRange(0, mDataContainer->size()); + dataRange = dataRange.bounded(rangeRestriction); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); + return; + } + + // get visible data range via interface from data plottable, and then restrict to available error data points: + const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); + int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); + int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); + int i = beginIndex; + while (i > 0 && i < n && i > rangeRestriction.begin()) + { + if (errorBarVisible(i)) + beginIndex = i; + --i; + } + i = endIndex; + while (i >= 0 && i < n && i < rangeRestriction.end()) + { + if (errorBarVisible(i)) + endIndex = i+1; + ++i; + } + QCPDataRange dataRange(beginIndex, endIndex); + dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); +} + +/*! \internal + + Calculates the minimum distance in pixels the error bars' representation has from the given \a + pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. +*/ +double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (!mDataPlottable || mDataContainer->isEmpty()) + return -1.0; + if (!mKeyAxis || !mValueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1.0; + } + + QCPErrorBarsDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); + + // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + getErrorBarLines(it, backbones, whiskers); + for (int i=0; i &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! \internal + + Returns whether the error bar at the specified \a index is visible within the current key axis + range. + + This method assumes for performance reasons without checking that the key axis, the value axis, + and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid + bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. +*/ +bool QCPErrorBars::errorBarVisible(int index) const +{ + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + if (qIsNaN(centerKeyPixel)) + return false; + + double keyMin, keyMax; + if (mErrorType == etKeyError) + { + const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); + const double errorPlus = mDataContainer->at(index).errorPlus; + const double errorMinus = mDataContainer->at(index).errorMinus; + keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); + keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); + } else // mErrorType == etValueError + { + keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + } + return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); +} + +/*! \internal + + Returns whether \a line intersects (or is contained in) \a pixelRect. + + \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for + error bar lines. +*/ +bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const +{ + if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) + return false; + else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) + return false; + else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) + return false; + else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) + return false; + else + return true; +} +/* end of 'src/plottables/plottable-errorbar.cpp' */ + + +/* including file 'src/items/item-straightline.cpp', size 7592 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemStraightLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemStraightLine + \brief A straight line that spans infinitely in both directions + + \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a point1 and \a point2, which define the straight line. +*/ + +/*! + Creates a straight line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + point1(createPosition(QLatin1String("point1"))), + point2(createPosition(QLatin1String("point2"))) +{ + point1->setCoords(0, 0); + point2->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemStraightLine::~QCPItemStraightLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemStraightLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemStraightLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); +} + +/* inherits documentation from base class */ +void QCPItemStraightLine::draw(QCPPainter *painter) +{ + QCPVector2D start(point1->pixelPosition()); + QCPVector2D end(point2->pixelPosition()); + // get visible segment of straight line inside clipRect: + double clipPad = mainPen().widthF(); + QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + } +} + +/*! \internal + + Returns the section of the straight line defined by \a base and direction vector \a + vec, that is visible in the specified \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const +{ + double bx, by; + double gamma; + QLineF result; + if (vec.x() == 0 && vec.y() == 0) + return result; + if (qFuzzyIsNull(vec.x())) // line is vertical + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical + } else if (qFuzzyIsNull(vec.y())) // line is horizontal + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal + } else // line is skewed + { + QList pointVectors; + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + // check right of rect: + bx = rect.right(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemStraightLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-straightline.cpp' */ + + +/* including file 'src/items/item-line.cpp', size 8498 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemLine + \brief A line from one point to another + + \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a start and \a end, which define the end points of the line. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. +*/ + +/*! + Creates a line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemLine::~QCPItemLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemLine::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemLine::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); +} + +/* inherits documentation from base class */ +void QCPItemLine::draw(QCPPainter *painter) +{ + QCPVector2D startVec(start->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if (qFuzzyIsNull((startVec-endVec).lengthSquared())) + return; + // get visible segment of straight line inside clipRect: + double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); + clipPad = qMax(clipPad, (double)mainPen().widthF()); + QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, startVec-endVec); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, endVec-startVec); + } +} + +/*! \internal + + Returns the section of the line defined by \a start and \a end, that is visible in the specified + \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const +{ + bool containsStart = rect.contains(start.x(), start.y()); + bool containsEnd = rect.contains(end.x(), end.y()); + if (containsStart && containsEnd) + return QLineF(start.toPointF(), end.toPointF()); + + QCPVector2D base = start; + QCPVector2D vec = end-start; + double bx, by; + double gamma, mu; + QLineF result; + QList pointVectors; + + if (!qFuzzyIsNull(vec.y())) // line is not horizontal + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + } + if (!qFuzzyIsNull(vec.x())) // line is not vertical + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + // check right of rect: + bx = rect.right(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + } + + if (containsStart) + pointVectors.append(start); + if (containsEnd) + pointVectors.append(end); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-line.cpp' */ + + +/* including file 'src/items/item-curve.cpp', size 7159 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemCurve + \brief A curved line from one point to another + + \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." + + It has four positions, \a start and \a end, which define the end points of the line, and two + control points which define the direction the line exits from the start and the direction from + which it approaches the end: \a startDir and \a endDir. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an + arrow. + + Often it is desirable for the control points to stay at fixed relative positions to the start/end + point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, + and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. +*/ + +/*! + Creates a curve item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + startDir(createPosition(QLatin1String("startDir"))), + endDir(createPosition(QLatin1String("endDir"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + startDir->setCoords(0.5, 0); + endDir->setCoords(0, 0.5); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemCurve::~QCPItemCurve() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemCurve::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemCurve::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemCurve::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemCurve::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF startVec(start->pixelPosition()); + QPointF startDirVec(startDir->pixelPosition()); + QPointF endDirVec(endDir->pixelPosition()); + QPointF endVec(end->pixelPosition()); + + QPainterPath cubicPath(startVec); + cubicPath.cubicTo(startDirVec, endDirVec, endVec); + + QPolygonF polygon = cubicPath.toSubpathPolygons().first(); + QCPVector2D p(pos); + double minDistSqr = std::numeric_limits::max(); + for (int i=1; ipixelPosition()); + QCPVector2D startDirVec(startDir->pixelPosition()); + QCPVector2D endDirVec(endDir->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if ((endVec-startVec).length() > 1e10) // too large curves cause crash + return; + + QPainterPath cubicPath(startVec.toPointF()); + cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); + + // paint visible segment, if existent: + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + QRect cubicRect = cubicPath.controlPointRect().toRect(); + if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position + cubicRect.adjust(0, 0, 1, 1); + if (clip.intersects(cubicRect)) + { + painter->setPen(mainPen()); + painter->drawPath(cubicPath); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemCurve::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-curve.cpp' */ + + +/* including file 'src/items/item-rect.cpp', size 6479 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemRect + \brief A rectangle + + \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemRect::~QCPItemRect() +{ +} + +/*! + Sets the pen that will be used to draw the line of the rectangle + + \see setSelectedPen, setBrush +*/ +void QCPItemRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the rectangle when selected + + \see setPen, setSelected +*/ +void QCPItemRect::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemRect::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); +} + +/* inherits documentation from base class */ +void QCPItemRect::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF rect = QRectF(p1, p2).normalized(); + double clipPad = mainPen().widthF(); + QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(rect); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemRect::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemRect::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemRect::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-rect.cpp' */ + + +/* including file 'src/items/item-text.cpp', size 13338 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemText +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemText + \brief A text label + + \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." + + Its position is defined by the member \a position and the setting of \ref setPositionAlignment. + The latter controls which part of the text rect shall be aligned with \a position. + + The text alignment itself (i.e. left, center, right) can be controlled with \ref + setTextAlignment. + + The text may be rotated around the \a position point with \ref setRotation. +*/ + +/*! + Creates a text item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemText::QCPItemText(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mText(QLatin1String("text")), + mPositionAlignment(Qt::AlignCenter), + mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), + mRotation(0) +{ + position->setCoords(0, 0); + + setPen(Qt::NoPen); + setSelectedPen(Qt::NoPen); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setColor(Qt::black); + setSelectedColor(Qt::blue); +} + +QCPItemText::~QCPItemText() +{ +} + +/*! + Sets the color of the text. +*/ +void QCPItemText::setColor(const QColor &color) +{ + mColor = color; +} + +/*! + Sets the color of the text that will be used when the item is selected. +*/ +void QCPItemText::setSelectedColor(const QColor &color) +{ + mSelectedColor = color; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text. To disable the + border, set \a pen to Qt::NoPen. + + \see setSelectedPen, setBrush, setPadding +*/ +void QCPItemText::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text, when the item is + selected. To disable the border, set \a pen to Qt::NoPen. + + \see setPen +*/ +void QCPItemText::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used do fill the background of the text. To disable the + background, set \a brush to Qt::NoBrush. + + \see setSelectedBrush, setPen, setPadding +*/ +void QCPItemText::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the + background, set \a brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemText::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the font of the text. + + \see setSelectedFont, setColor +*/ +void QCPItemText::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the font of the text that will be used when the item is selected. + + \see setFont +*/ +void QCPItemText::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the text that will be displayed. Multi-line texts are supported by inserting a line break + character, e.g. '\n'. + + \see setFont, setColor, setTextAlignment +*/ +void QCPItemText::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets which point of the text rect shall be aligned with \a position. + + Examples: + \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such + that the top of the text rect will be horizontally centered on \a position. + \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the + bottom left corner of the text rect. + + If you want to control the alignment of (multi-lined) text within the text rect, use \ref + setTextAlignment. +*/ +void QCPItemText::setPositionAlignment(Qt::Alignment alignment) +{ + mPositionAlignment = alignment; +} + +/*! + Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). +*/ +void QCPItemText::setTextAlignment(Qt::Alignment alignment) +{ + mTextAlignment = alignment; +} + +/*! + Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated + around \a position. +*/ +void QCPItemText::setRotation(double degrees) +{ + mRotation = degrees; +} + +/*! + Sets the distance between the border of the text rectangle and the text. The appearance (and + visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. +*/ +void QCPItemText::setPadding(const QMargins &padding) +{ + mPadding = padding; +} + +/* inherits documentation from base class */ +double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + // The rect may be rotated, so we transform the actual clicked pos to the rotated + // coordinate system, so we can use the normal rectDistance function for non-rotated rects: + QPointF positionPixels(position->pixelPosition()); + QTransform inputTransform; + inputTransform.translate(positionPixels.x(), positionPixels.y()); + inputTransform.rotate(-mRotation); + inputTransform.translate(-positionPixels.x(), -positionPixels.y()); + QPointF rotatedPos = inputTransform.map(pos); + QFontMetrics fontMetrics(mFont); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); + textBoxRect.moveTopLeft(textPos.toPoint()); + + return rectDistance(textBoxRect, rotatedPos, true); +} + +/* inherits documentation from base class */ +void QCPItemText::draw(QCPPainter *painter) +{ + QPointF pos(position->pixelPosition()); + QTransform transform = painter->transform(); + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + painter->setFont(mainFont()); + QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); + textBoxRect.moveTopLeft(textPos.toPoint()); + double clipPad = mainPen().widthF(); + QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) + { + painter->setTransform(transform); + if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || + (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(textBoxRect); + } + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(mainColor())); + painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemText::anchorPixelPosition(int anchorId) const +{ + // get actual rect points (pretty much copied from draw function): + QPointF pos(position->pixelPosition()); + QTransform transform; + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + QFontMetrics fontMetrics(mainFont()); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textBoxRect.moveTopLeft(textPos.toPoint()); + QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); + + switch (anchorId) + { + case aiTopLeft: return rectPoly.at(0); + case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; + case aiTopRight: return rectPoly.at(1); + case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; + case aiBottomRight: return rectPoly.at(2); + case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; + case aiBottomLeft: return rectPoly.at(3); + case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the point that must be given to the QPainter::drawText function (which expects the top + left point of the text rect), according to the position \a pos, the text bounding box \a rect and + the requested \a positionAlignment. + + For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point + will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally + drawn at that point, the lower left corner of the resulting text rect is at \a pos. +*/ +QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const +{ + if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) + return pos; + + QPointF result = pos; // start at top left + if (positionAlignment.testFlag(Qt::AlignHCenter)) + result.rx() -= rect.width()/2.0; + else if (positionAlignment.testFlag(Qt::AlignRight)) + result.rx() -= rect.width(); + if (positionAlignment.testFlag(Qt::AlignVCenter)) + result.ry() -= rect.height()/2.0; + else if (positionAlignment.testFlag(Qt::AlignBottom)) + result.ry() -= rect.height(); + return result; +} + +/*! \internal + + Returns the font that should be used for drawing text. Returns mFont when the item is not selected + and mSelectedFont when it is. +*/ +QFont QCPItemText::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the color that should be used for drawing text. Returns mColor when the item is not + selected and mSelectedColor when it is. +*/ +QColor QCPItemText::mainColor() const +{ + return mSelected ? mSelectedColor : mColor; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemText::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemText::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-text.cpp' */ + + +/* including file 'src/items/item-ellipse.cpp', size 7863 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemEllipse +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemEllipse + \brief An ellipse + + \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. +*/ + +/*! + Creates an ellipse item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), + left(createAnchor(QLatin1String("left"), aiLeft)), + center(createAnchor(QLatin1String("center"), aiCenter)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemEllipse::~QCPItemEllipse() +{ +} + +/*! + Sets the pen that will be used to draw the line of the ellipse + + \see setSelectedPen, setBrush +*/ +void QCPItemEllipse::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the ellipse when selected + + \see setPen, setSelected +*/ +void QCPItemEllipse::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemEllipse::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemEllipse::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + QPointF center((p1+p2)/2.0); + double a = qAbs(p1.x()-p2.x())/2.0; + double b = qAbs(p1.y()-p2.y())/2.0; + double x = pos.x()-center.x(); + double y = pos.y()-center.y(); + + // distance to border: + double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); + double result = qAbs(c-1)*qSqrt(x*x+y*y); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (x*x/(a*a) + y*y/(b*b) <= 1) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/* inherits documentation from base class */ +void QCPItemEllipse::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF ellipseRect = QRectF(p1, p2).normalized(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); +#ifdef __EXCEPTIONS + try // drawEllipse sometimes throws exceptions if ellipse is too big + { +#endif + painter->drawEllipse(ellipseRect); +#ifdef __EXCEPTIONS + } catch (...) + { + qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; + setVisible(false); + } +#endif + } +} + +/* inherits documentation from base class */ +QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemEllipse::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemEllipse::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-ellipse.cpp' */ + + +/* including file 'src/items/item-pixmap.cpp', size 10615 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPixmap + \brief An arbitrary pixmap + + \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will + be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to + fit the rectangle or be drawn aligned to the topLeft position. + + If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown + on the right side of the example image), the pixmap will be flipped in the respective + orientations. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mScaled(false), + mScaledPixmapInvalidated(true), + mAspectRatioMode(Qt::KeepAspectRatio), + mTransformationMode(Qt::SmoothTransformation) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(Qt::NoPen); + setSelectedPen(QPen(Qt::blue)); +} + +QCPItemPixmap::~QCPItemPixmap() +{ +} + +/*! + Sets the pixmap that will be displayed. +*/ +void QCPItemPixmap::setPixmap(const QPixmap &pixmap) +{ + mPixmap = pixmap; + mScaledPixmapInvalidated = true; + if (mPixmap.isNull()) + qDebug() << Q_FUNC_INFO << "pixmap is null"; +} + +/*! + Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a + bottomRight positions. +*/ +void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) +{ + mScaled = scaled; + mAspectRatioMode = aspectRatioMode; + mTransformationMode = transformationMode; + mScaledPixmapInvalidated = true; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap. + + \see setSelectedPen, setBrush +*/ +void QCPItemPixmap::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap when selected + + \see setPen, setSelected +*/ +void QCPItemPixmap::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return rectDistance(getFinalRect(), pos, true); +} + +/* inherits documentation from base class */ +void QCPItemPixmap::draw(QCPPainter *painter) +{ + bool flipHorz = false; + bool flipVert = false; + QRect rect = getFinalRect(&flipHorz, &flipVert); + double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); + QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) + { + updateScaledPixmap(rect, flipHorz, flipVert); + painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); + QPen pen = mainPen(); + if (pen.style() != Qt::NoPen) + { + painter->setPen(pen); + painter->setBrush(Qt::NoBrush); + painter->drawRect(rect); + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const +{ + bool flipHorz; + bool flipVert; + QRect rect = getFinalRect(&flipHorz, &flipVert); + // we actually want denormal rects (negative width/height) here, so restore + // the flipped state: + if (flipHorz) + rect.adjust(rect.width(), 0, -rect.width(), 0); + if (flipVert) + rect.adjust(0, rect.height(), 0, -rect.height()); + + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The + parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped + horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a + bottomRight.) + + This function only creates the scaled pixmap when the buffered pixmap has a different size than + the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does + not cause expensive rescaling every time. + + If scaling is disabled, sets mScaledPixmap to a null QPixmap. +*/ +void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) +{ + if (mPixmap.isNull()) + return; + + if (mScaled) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + double devicePixelRatio = mPixmap.devicePixelRatio(); +#else + double devicePixelRatio = 1.0; +#endif + if (finalRect.isNull()) + finalRect = getFinalRect(&flipHorz, &flipVert); + if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) + { + mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); + if (flipHorz || flipVert) + mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mScaledPixmap.setDevicePixelRatio(devicePixelRatio); +#endif + } + } else if (!mScaledPixmap.isNull()) + mScaledPixmap = QPixmap(); + mScaledPixmapInvalidated = false; +} + +/*! \internal + + Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions + and scaling settings. + + The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn + flipped horizontally or vertically in the returned rect. (The returned rect itself is always + normalized, i.e. the top left corner of the rect is actually further to the top/left than the + bottom right corner). This is the case when the item position \a topLeft is further to the + bottom/right than \a bottomRight. + + If scaling is disabled, returns a rect with size of the original pixmap and the top left corner + aligned with the item position \a topLeft. The position \a bottomRight is ignored. +*/ +QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const +{ + QRect result; + bool flipHorz = false; + bool flipVert = false; + QPoint p1 = topLeft->pixelPosition().toPoint(); + QPoint p2 = bottomRight->pixelPosition().toPoint(); + if (p1 == p2) + return QRect(p1, QSize(0, 0)); + if (mScaled) + { + QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); + QPoint topLeft = p1; + if (newSize.width() < 0) + { + flipHorz = true; + newSize.rwidth() *= -1; + topLeft.setX(p2.x()); + } + if (newSize.height() < 0) + { + flipVert = true; + newSize.rheight() *= -1; + topLeft.setY(p2.y()); + } + QSize scaledSize = mPixmap.size(); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + scaledSize /= mPixmap.devicePixelRatio(); + scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); +#else + scaledSize.scale(newSize, mAspectRatioMode); +#endif + result = QRect(topLeft, scaledSize); + } else + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); +#else + result = QRect(p1, mPixmap.size()); +#endif + } + if (flippedHorz) + *flippedHorz = flipHorz; + if (flippedVert) + *flippedVert = flipVert; + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemPixmap::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-pixmap.cpp' */ + + +/* including file 'src/items/item-tracer.cpp', size 14624 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemTracer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemTracer + \brief Item that sticks to QCPGraph data points + + \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." + + The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt + the coordinate axes of the graph and update its \a position to be on the graph's data. This means + the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a + QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a + position will have no effect because they will be overriden in the next redraw (this is when the + coordinate update happens). + + If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will + stay at the corresponding end of the graph. + + With \ref setInterpolating you may specify whether the tracer may only stay exactly on data + points or whether it interpolates data points linearly, if given a key that lies between two data + points of the graph. + + The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer + have no own visual appearance (set the style to \ref tsNone), and just connect other item + positions to the tracer \a position (used as an anchor) via \ref + QCPItemPosition::setParentAnchor. + + \note The tracer position is only automatically updated upon redraws. So when the data of the + graph changes and immediately afterwards (without a redraw) the position coordinates of the + tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref + updatePosition must be called manually, prior to reading the tracer coordinates. +*/ + +/*! + Creates a tracer item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + mSize(6), + mStyle(tsCrosshair), + mGraph(0), + mGraphKey(0), + mInterpolating(false) +{ + position->setCoords(0, 0); + + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemTracer::~QCPItemTracer() +{ +} + +/*! + Sets the pen that will be used to draw the line of the tracer + + \see setSelectedPen, setBrush +*/ +void QCPItemTracer::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the tracer when selected + + \see setPen, setSelected +*/ +void QCPItemTracer::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer + + \see setSelectedBrush, setPen +*/ +void QCPItemTracer::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer, when selected. + + \see setBrush, setSelected +*/ +void QCPItemTracer::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare + does, \ref tsCrosshair does not). +*/ +void QCPItemTracer::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the style/visual appearance of the tracer. + + If you only want to use the tracer \a position as an anchor for other items, set \a style to + \ref tsNone. +*/ +void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) +{ + mStyle = style; +} + +/*! + Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type + QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. + + To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed + freely like any other item position. This is the state the tracer will assume when its graph gets + deleted while still attached to it. + + \see setGraphKey +*/ +void QCPItemTracer::setGraph(QCPGraph *graph) +{ + if (graph) + { + if (graph->parentPlot() == mParentPlot) + { + position->setType(QCPItemPosition::ptPlotCoords); + position->setAxes(graph->keyAxis(), graph->valueAxis()); + mGraph = graph; + updatePosition(); + } else + qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; + } else + { + mGraph = 0; + } +} + +/*! + Sets the key of the graph's data point the tracer will be positioned at. This is the only free + coordinate of a tracer when attached to a graph. + + Depending on \ref setInterpolating, the tracer will be either positioned on the data point + closest to \a key, or will stay exactly at \a key and interpolate the value linearly. + + \see setGraph, setInterpolating +*/ +void QCPItemTracer::setGraphKey(double key) +{ + mGraphKey = key; +} + +/*! + Sets whether the value of the graph's data points shall be interpolated, when positioning the + tracer. + + If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on + the data point of the graph which is closest to the key, but which is not necessarily exactly + there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and + the appropriate value will be interpolated from the graph's data points linearly. + + \see setGraph, setGraphKey +*/ +void QCPItemTracer::setInterpolating(bool enabled) +{ + mInterpolating = enabled; +} + +/* inherits documentation from base class */ +double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return -1; + case tsPlus: + { + if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), + QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); + break; + } + case tsCrosshair: + { + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), + QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + // distance to border: + double centerDist = QCPVector2D(center-pos).length(); + double circleLine = w; + double result = qAbs(centerDist-circleLine); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (centerDist <= circleLine) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; + } + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); + } + break; + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemTracer::draw(QCPPainter *painter) +{ + updatePosition(); + if (mStyle == tsNone) + return; + + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return; + case tsPlus: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); + painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); + } + break; + } + case tsCrosshair: + { + if (center.y() > clip.top() && center.y() < clip.bottom()) + painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); + if (center.x() > clip.left() && center.x() < clip.right()) + painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); + break; + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawEllipse(center, w, w); + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); + break; + } + } +} + +/*! + If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a + position to reside on the graph data, depending on the configured key (\ref setGraphKey). + + It is called automatically on every redraw and normally doesn't need to be called manually. One + exception is when you want to read the tracer coordinates via \a position and are not sure that + the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. + In that situation, call this function before accessing \a position, to make sure you don't get + out-of-date coordinates. + + If there is no graph set on this tracer, this function does nothing. +*/ +void QCPItemTracer::updatePosition() +{ + if (mGraph) + { + if (mParentPlot->hasPlottable(mGraph)) + { + if (mGraph->data()->size() > 1) + { + QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); + QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; + if (mGraphKey <= first->key) + position->setCoords(first->key, first->value); + else if (mGraphKey >= last->key) + position->setCoords(last->key, last->value); + else + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); + if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators + { + QCPGraphDataContainer::const_iterator prevIt = it; + ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before + if (mInterpolating) + { + // interpolate between iterators around mGraphKey: + double slope = 0; + if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) + slope = (it->value-prevIt->value)/(it->key-prevIt->key); + position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); + } else + { + // find iterator with key closest to mGraphKey: + if (mGraphKey < (prevIt->key+it->key)*0.5) + position->setCoords(prevIt->key, prevIt->value); + else + position->setCoords(it->key, it->value); + } + } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) + position->setCoords(it->key, it->value); + } + } else if (mGraph->data()->size() == 1) + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); + position->setCoords(it->key, it->value); + } else + qDebug() << Q_FUNC_INFO << "graph has no data"; + } else + qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemTracer::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemTracer::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-tracer.cpp' */ + + +/* including file 'src/items/item-bracket.cpp', size 10687 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemBracket + \brief A bracket for referencing/highlighting certain parts in the plot. + + \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a left and \a right, which define the span of the bracket. If \a left is + actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the + example image. + + The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket + stretches away from the embraced span, can be controlled with \ref setLength. + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+ + It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine + or QCPItemCurve) or a text label (QCPItemText), to the bracket. +*/ + +/*! + Creates a bracket item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + left(createPosition(QLatin1String("left"))), + right(createPosition(QLatin1String("right"))), + center(createAnchor(QLatin1String("center"), aiCenter)), + mLength(8), + mStyle(bsCalligraphic) +{ + left->setCoords(0, 0); + right->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemBracket::~QCPItemBracket() +{ +} + +/*! + Sets the pen that will be used to draw the bracket. + + Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the + stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use + \ref setLength, which has a similar effect. + + \see setSelectedPen +*/ +void QCPItemBracket::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the bracket when selected + + \see setPen, setSelected +*/ +void QCPItemBracket::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the \a length in pixels how far the bracket extends in the direction towards the embraced + span of the bracket (i.e. perpendicular to the left-right-direction) + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+*/ +void QCPItemBracket::setLength(double length) +{ + mLength = length; +} + +/*! + Sets the style of the bracket, i.e. the shape/visual appearance. + + \see setPen +*/ +void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) +{ + mStyle = style; +} + +/* inherits documentation from base class */ +double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QCPVector2D p(pos); + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return -1; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (mStyle) + { + case QCPItemBracket::bsSquare: + case QCPItemBracket::bsRound: + { + double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); + double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); + return qSqrt(qMin(qMin(a, b), c)); + } + case QCPItemBracket::bsCurly: + case QCPItemBracket::bsCalligraphic: + { + double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); + double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); + return qSqrt(qMin(qMin(a, b), qMin(c, d))); + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemBracket::draw(QCPPainter *painter) +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + QPolygon boundingPoly; + boundingPoly << leftVec.toPoint() << rightVec.toPoint() + << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (clip.intersects(boundingPoly.boundingRect())) + { + painter->setPen(mainPen()); + switch (mStyle) + { + case bsSquare: + { + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + break; + } + case bsRound: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCurly: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCalligraphic: + { + painter->setPen(Qt::NoPen); + painter->setBrush(QBrush(mainPen().color())); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); + path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + + painter->drawPath(path); + break; + } + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return leftVec.toPointF(); + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (anchorId) + { + case aiCenter: + return centerVec.toPointF(); + } + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemBracket::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-bracket.cpp' */ + + From 1229dc5bfa6b1b6ce4bd7f3ffd4326891b001f4f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:45:04 -0400 Subject: [PATCH 0358/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index d831f5a9..d69568bb 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -24,7 +24,7 @@ #define POSTSATATIME 15 //_____ -#include "QProcess.h" +#include "qprocess.h" ProfilePage::ProfilePage(QWidget *parent) : QMainWindow(parent), From 711d216b2a967c73855905bfbeb583ce867cacef Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:54:44 -0400 Subject: [PATCH 0359/1324] Update qcustomplot.h --- src/qt/qcustomplot.h | 83 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index 278fbf82..5aa03f2c 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -722,7 +722,7 @@ class QCP_LIB_DECL QCPLayerable : public QObject // non-property methods: bool realVisibility() const; -signals: +Q_SIGNALS: void layerChanged(QCPLayer *newLayer); protected: @@ -1110,9 +1110,9 @@ class QCP_LIB_DECL QCPSelectionRect : public QCPLayerable void setBrush(const QBrush &brush); // non-property methods: - Q_SLOT void cancel(); + Q_SLOTS: void cancel(); -signals: +Q_SIGNALS: void started(QMouseEvent *event); void changed(const QRect &rect, QMouseEvent *event); void canceled(const QRect &rect, QInputEvent *event); @@ -2048,8 +2048,8 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable QCPGrid *grid() const { return mGrid; } // setters: - Q_SLOT void setScaleType(QCPAxis::ScaleType type); - Q_SLOT void setRange(const QCPRange &range); + Q_SLOTS: void setScaleType(QCPAxis::ScaleType type); + Q_SLOTS: void setRange(const QCPRange &range); void setRange(double lower, double upper); void setRange(double position, double size, Qt::AlignmentFlag alignment); void setRangeLower(double lower); @@ -2088,8 +2088,8 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable void setSelectedBasePen(const QPen &pen); void setSelectedTickPen(const QPen &pen); void setSelectedSubTickPen(const QPen &pen); - Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); + Q_SLOTS: void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); + Q_SLOTS: void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); void setLowerEnding(const QCPLineEnding &ending); void setUpperEnding(const QCPLineEnding &ending); @@ -2115,7 +2115,7 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } static AxisType opposite(AxisType type); -signals: +Q_SIGNALS: void rangeChanged(const QCPRange &newRange); void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); void scaleTypeChanged(QCPAxis::ScaleType scaleType); @@ -3324,8 +3324,8 @@ class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable void setBrush(const QBrush &brush); void setKeyAxis(QCPAxis *axis); void setValueAxis(QCPAxis *axis); - Q_SLOT void setSelectable(QCP::SelectionType selectable); - Q_SLOT void setSelection(QCPDataSelection selection); + Q_SLOTS: void setSelectable(QCP::SelectionType selectable); + Q_SLOTS: void setSelection(QCPDataSelection selection); void setSelectionDecorator(QCPSelectionDecorator *decorator); // introduced virtual methods: @@ -3347,7 +3347,7 @@ class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable bool removeFromLegend(QCPLegend *legend) const; bool removeFromLegend() const; -signals: +Q_SIGNALS: void selectionChanged(bool selected); void selectionChanged(const QCPDataSelection &selection); void selectableChanged(QCP::SelectionType selectable); @@ -3524,8 +3524,8 @@ class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable // setters: void setClipToAxisRect(bool clip); void setClipAxisRect(QCPAxisRect *rect); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); + Q_SLOTS: void setSelectable(bool selectable); + Q_SLOTS: void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; @@ -3537,7 +3537,7 @@ class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable QCPItemAnchor *anchor(const QString &name) const; bool hasAnchor(const QString &name) const; -signals: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -3713,11 +3713,11 @@ class QCP_LIB_DECL QCustomPlot : public QWidget QList axisRects() const; QCPLayoutElement* layoutElementAt(const QPointF &pos) const; QCPAxisRect* axisRectAt(const QPointF &pos) const; - Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); + Q_SLOTS: void rescaleAxes(bool onlyVisiblePlottables=false); QList selectedAxes() const; QList selectedLegends() const; - Q_SLOT void deselectAll(); + Q_SLOTS: void deselectAll(); bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); @@ -3726,12 +3726,12 @@ class QCP_LIB_DECL QCustomPlot : public QWidget bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); QPixmap toPixmap(int width=0, int height=0, double scale=1.0); void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); + Q_SLOTS: void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; QCPLegend *legend; -signals: +Q_SIGNALS: void mouseDoubleClick(QMouseEvent *event); void mousePress(QMouseEvent *event); void mouseMove(QMouseEvent *event); @@ -3812,9 +3812,9 @@ class QCP_LIB_DECL QCustomPlot : public QWidget virtual void updateLayout(); virtual void axisRemoved(QCPAxis *axis); virtual void legendRemoved(QCPLegend *legend); - Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processPointSelection(QMouseEvent *event); + Q_SLOTS: virtual void processRectSelection(QRect rect, QMouseEvent *event); + Q_SLOTS: virtual void processRectZoom(QRect rect, QMouseEvent *event); + Q_SLOTS: virtual void processPointSelection(QMouseEvent *event); // non-virtual methods: bool registerPlottable(QCPAbstractPlottable *plottable); @@ -4734,13 +4734,13 @@ class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement void setTextColor(const QColor &color); void setSelectedFont(const QFont &font); void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); + Q_SLOTS: void setSelectable(bool selectable); + Q_SLOTS: void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; -signals: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -4854,8 +4854,8 @@ class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid void setIconSize(int width, int height); void setIconTextPadding(int padding); void setIconBorderPen(const QPen &pen); - Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); + Q_SLOTS: void setSelectableParts(const SelectableParts &selectableParts); + Q_SLOTS: void setSelectedParts(const SelectableParts &selectedParts); void setSelectedBorderPen(const QPen &pen); void setSelectedIconBorderPen(const QPen &pen); void setSelectedBrush(const QBrush &brush); @@ -4877,7 +4877,7 @@ class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid void clearItems(); QList selectedItems() const; -signals: +Q_SIGNALS: void selectionChanged(QCPLegend::SelectableParts parts); void selectableChanged(QCPLegend::SelectableParts parts); @@ -4959,8 +4959,8 @@ class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement void setTextColor(const QColor &color); void setSelectedFont(const QFont &font); void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); + Q_SLOTS: void setSelectable(bool selectable); + Q_SLOTS: void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; @@ -4968,7 +4968,7 @@ class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; -signals: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); void clicked(QMouseEvent *event); @@ -5029,8 +5029,8 @@ class QCPColorScaleAxisRectPrivate : public QCPAxisRect using QCPAxisRect::update; virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; void updateGradientImage(); - Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); + Q_SLOTS: void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); + Q_SLOTS: void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); friend class QCPColorScale; }; @@ -5065,9 +5065,9 @@ class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement // setters: void setType(QCPAxis::AxisType type); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); + Q_SLOTS: void setDataRange(const QCPRange &dataRange); + Q_SLOTS: void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOTS: void setGradient(const QCPColorGradient &gradient); void setLabel(const QString &str); void setBarWidth(int width); void setRangeDrag(bool enabled); @@ -5080,7 +5080,7 @@ class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement // reimplemented virtual methods: virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; -signals: +Q_SIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); @@ -5760,23 +5760,23 @@ class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable // setters: void setData(QCPColorMapData *data, bool copy=false); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); + Q_SLOTS: void setDataRange(const QCPRange &dataRange); + Q_SLOTS: void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOTS: void setGradient(const QCPColorGradient &gradient); void setInterpolate(bool enabled); void setTightBoundary(bool enabled); void setColorScale(QCPColorScale *colorScale); // non-property methods: void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); + Q_SLOTS: void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; -signals: +Q_SIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); @@ -6659,4 +6659,3 @@ Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) #endif // QCUSTOMPLOT_H - From 2344bab31799f68c9553180889de743983c86a45 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:55:42 -0400 Subject: [PATCH 0360/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 51323edc..ee71a1fd 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" +#include "newaccount.h" #include #include "homepage.h" #include "QMessageBox" From 724c843b44bc3a69c735d4b92359521a8fcfbd1b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:55:59 -0400 Subject: [PATCH 0361/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 9e714c41..cd23978d 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -13,7 +13,7 @@ #include "QPushButton" #include #include "posts.h" -#include "Qstring" +#include "QString" #include #include "QFontMetrics" #include "QGroupBox" From 1dbbae08a9b0374bcdce0e7c9322ce1cbd582f4d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 02:59:28 -0400 Subject: [PATCH 0362/1324] Update qcustomplot.h --- src/qt/qcustomplot.h | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index 5aa03f2c..a0634fa7 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -1110,7 +1110,7 @@ class QCP_LIB_DECL QCPSelectionRect : public QCPLayerable void setBrush(const QBrush &brush); // non-property methods: - Q_SLOTS: void cancel(); + Q_SLOT void cancel(); Q_SIGNALS: void started(QMouseEvent *event); @@ -2048,8 +2048,8 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable QCPGrid *grid() const { return mGrid; } // setters: - Q_SLOTS: void setScaleType(QCPAxis::ScaleType type); - Q_SLOTS: void setRange(const QCPRange &range); + Q_SLOT void setScaleType(QCPAxis::ScaleType type); + Q_SLOT void setRange(const QCPRange &range); void setRange(double lower, double upper); void setRange(double position, double size, Qt::AlignmentFlag alignment); void setRangeLower(double lower); @@ -2088,8 +2088,8 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable void setSelectedBasePen(const QPen &pen); void setSelectedTickPen(const QPen &pen); void setSelectedSubTickPen(const QPen &pen); - Q_SLOTS: void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOTS: void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); + Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); void setLowerEnding(const QCPLineEnding &ending); void setUpperEnding(const QCPLineEnding &ending); @@ -3324,8 +3324,8 @@ class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable void setBrush(const QBrush &brush); void setKeyAxis(QCPAxis *axis); void setValueAxis(QCPAxis *axis); - Q_SLOTS: void setSelectable(QCP::SelectionType selectable); - Q_SLOTS: void setSelection(QCPDataSelection selection); + Q_SLOT void setSelectable(QCP::SelectionType selectable); + Q_SLOT void setSelection(QCPDataSelection selection); void setSelectionDecorator(QCPSelectionDecorator *decorator); // introduced virtual methods: @@ -3524,8 +3524,8 @@ class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable // setters: void setClipToAxisRect(bool clip); void setClipAxisRect(QCPAxisRect *rect); - Q_SLOTS: void setSelectable(bool selectable); - Q_SLOTS: void setSelected(bool selected); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; @@ -3713,7 +3713,7 @@ class QCP_LIB_DECL QCustomPlot : public QWidget QList axisRects() const; QCPLayoutElement* layoutElementAt(const QPointF &pos) const; QCPAxisRect* axisRectAt(const QPointF &pos) const; - Q_SLOTS: void rescaleAxes(bool onlyVisiblePlottables=false); + Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); QList selectedAxes() const; QList selectedLegends() const; @@ -3726,7 +3726,7 @@ class QCP_LIB_DECL QCustomPlot : public QWidget bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); QPixmap toPixmap(int width=0, int height=0, double scale=1.0); void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOTS: void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); + Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; QCPLegend *legend; @@ -3812,9 +3812,9 @@ class QCP_LIB_DECL QCustomPlot : public QWidget virtual void updateLayout(); virtual void axisRemoved(QCPAxis *axis); virtual void legendRemoved(QCPLegend *legend); - Q_SLOTS: virtual void processRectSelection(QRect rect, QMouseEvent *event); - Q_SLOTS: virtual void processRectZoom(QRect rect, QMouseEvent *event); - Q_SLOTS: virtual void processPointSelection(QMouseEvent *event); + Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processPointSelection(QMouseEvent *event); // non-virtual methods: bool registerPlottable(QCPAbstractPlottable *plottable); @@ -4734,8 +4734,8 @@ class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement void setTextColor(const QColor &color); void setSelectedFont(const QFont &font); void setSelectedTextColor(const QColor &color); - Q_SLOTS: void setSelectable(bool selectable); - Q_SLOTS: void setSelected(bool selected); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; @@ -4854,8 +4854,8 @@ class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid void setIconSize(int width, int height); void setIconTextPadding(int padding); void setIconBorderPen(const QPen &pen); - Q_SLOTS: void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOTS: void setSelectedParts(const SelectableParts &selectedParts); + Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); void setSelectedBorderPen(const QPen &pen); void setSelectedIconBorderPen(const QPen &pen); void setSelectedBrush(const QBrush &brush); @@ -4959,8 +4959,8 @@ class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement void setTextColor(const QColor &color); void setSelectedFont(const QFont &font); void setSelectedTextColor(const QColor &color); - Q_SLOTS: void setSelectable(bool selectable); - Q_SLOTS: void setSelected(bool selected); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; @@ -5029,8 +5029,8 @@ class QCPColorScaleAxisRectPrivate : public QCPAxisRect using QCPAxisRect::update; virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; void updateGradientImage(); - Q_SLOTS: void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOTS: void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); + Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); + Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); friend class QCPColorScale; }; @@ -5065,9 +5065,9 @@ class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement // setters: void setType(QCPAxis::AxisType type); - Q_SLOTS: void setDataRange(const QCPRange &dataRange); - Q_SLOTS: void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOTS: void setGradient(const QCPColorGradient &gradient); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); void setLabel(const QString &str); void setBarWidth(int width); void setRangeDrag(bool enabled); @@ -5760,16 +5760,16 @@ class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable // setters: void setData(QCPColorMapData *data, bool copy=false); - Q_SLOTS: void setDataRange(const QCPRange &dataRange); - Q_SLOTS: void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOTS: void setGradient(const QCPColorGradient &gradient); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); void setInterpolate(bool enabled); void setTightBoundary(bool enabled); void setColorScale(QCPColorScale *colorScale); // non-property methods: void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOTS: void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); + Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; From 8eb0314a89a3be57c5bef49237f7c68330c83bbe Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 03:00:06 -0400 Subject: [PATCH 0363/1324] Update qcustomplot.h --- src/qt/qcustomplot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index a0634fa7..8b0ac04e 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -3717,7 +3717,7 @@ class QCP_LIB_DECL QCustomPlot : public QWidget QList selectedAxes() const; QList selectedLegends() const; - Q_SLOTS: void deselectAll(); + Q_SLOT void deselectAll(); bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); From 634d26c0c4404a6e19dab3b011373ef00fda74f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 03:13:46 -0400 Subject: [PATCH 0364/1324] Addes files --- src/Makefile.qt.include | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index eafba4c9..a4be2ccd 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -112,7 +112,21 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp + qt/moc_walletview.cpp \ + qt/moc_main.cpp \ + qt/moc_mainwindow.cpp \ + qt/moc_newaccount.cpp \ + qt/moc_profilepage.cpp \ + qt/moc_addcomment.cpp \ + qt/moc_posts.cpp \ + qt/moc_comment.cpp \ + qt/moc_Activity.cpp \ + qt/moc_user.cpp \ + qt/moc_fileman.cpp \ + qt/moc_qcustomplot.cpp \ + qt/moc_adminwindow.cpp \ + qt/moc_statistics.cpp \ + qt/moc_homepage.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ From 043bc607c4a45d13701cb99c8a9972c5b4a486fd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 11:44:09 -0400 Subject: [PATCH 0365/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a4be2ccd..22b58993 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -113,7 +113,6 @@ QT_MOC_CPP = \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ qt/moc_walletview.cpp \ - qt/moc_main.cpp \ qt/moc_mainwindow.cpp \ qt/moc_newaccount.cpp \ qt/moc_profilepage.cpp \ From 28d61c11d0307780e99910a0775317071e33dc07 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:12:52 -0400 Subject: [PATCH 0366/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index c00afa77..b9c54cef 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -68,7 +68,7 @@
- userName + User Name txtUserMail @@ -104,7 +104,7 @@ - password + Password lineEdit_2 @@ -122,7 +122,7 @@ - confirm password + Confirm Password lineEdit_3 From f018cc30fe80a3457b8a69714354f0fd8af6b04b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:13:26 -0400 Subject: [PATCH 0367/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index b9c54cef..dd87603b 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -30,7 +30,7 @@ - if you already have an account ---> + If You Already Have An Account ---> From d9c1fa984b39e69989e2d7bec385dd0bc13bc22d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:32:26 -0400 Subject: [PATCH 0368/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 7d62c718..75d64ab5 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -QT += core gui sql +QT += core gui sql xml FORMS += \ ../src/qt/forms/aboutdialog.ui \ From 942ad9a3e1a0eb34bcabb2a43522894f9da1d892 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:33:12 -0400 Subject: [PATCH 0369/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ee71a1fd..ef8966a5 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "newaccount.h" +#include #include #include "homepage.h" #include "QMessageBox" From ca53c0d36e88f3f88fffed37025de8e49a076c75 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:33:31 -0400 Subject: [PATCH 0370/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ef8966a5..ee71a1fd 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,7 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "newaccount.h" -#include #include #include "homepage.h" #include "QMessageBox" From e671dadc20ddd1097e5ae4bd6addaf55fec19732 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:51:19 -0400 Subject: [PATCH 0371/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ee71a1fd..fd645221 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,7 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "newaccount.h" -#include +#include #include "homepage.h" #include "QMessageBox" From d5aa3ec28fd5a76a6acf47673df589adadc07980 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:53:27 -0400 Subject: [PATCH 0372/1324] Update Social-Network-Qt-Application-GUI.pro --- src/qt/Social-Network-Qt-Application-GUI.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro b/src/qt/Social-Network-Qt-Application-GUI.pro index decc1983..245f5ef5 100644 --- a/src/qt/Social-Network-Qt-Application-GUI.pro +++ b/src/qt/Social-Network-Qt-Application-GUI.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui printsupport +QT += core gui xml printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets From ebd62bf8a1098a6b7a3d6c7efe13c8ddef4d0ee5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 13:04:33 -0400 Subject: [PATCH 0373/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index fd645221..4e506c53 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -2,6 +2,7 @@ #include "ui_mainwindow.h" #include "newaccount.h" #include +#include #include "homepage.h" #include "QMessageBox" From 477839769e0ed24da132a05b2f6bfd2b3a386e43 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 13:08:33 -0400 Subject: [PATCH 0374/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4e506c53..367fd90e 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -3,6 +3,7 @@ #include "newaccount.h" #include #include +#include #include "homepage.h" #include "QMessageBox" From c342d4a03bb349e3f8a21093d510eb69290b38a6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 14:01:24 -0400 Subject: [PATCH 0375/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 75d64ab5..48a45c54 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -31,7 +31,11 @@ QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ - ..src/qt/wildrig.exe + ..src/qt/wildrig.exe \ + ..src/qt/Social-Network-Qt-Application-GUI.pro \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml INCLUDEPATH += /usr/include/QtSql LIBS += -lQtSql From a7980713df6ef168f7f05b1b6e28841f584f3cee Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 14:06:50 -0400 Subject: [PATCH 0376/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 48a45c54..7cf5bdd9 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -31,11 +31,9 @@ QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ - ..src/qt/wildrig.exe \ - ..src/qt/Social-Network-Qt-Application-GUI.pro \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml + ..src/qt/wildrig.exe -INCLUDEPATH += /usr/include/QtSql -LIBS += -lQtSql +INCLUDEPATH += ..src/qt/Social-Network-Qt-Application-GUI.pro \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml From 4335d09a9034c504a6752b474f9db6f6174eb948 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 14:17:36 -0400 Subject: [PATCH 0377/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 7cf5bdd9..6b6f8755 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -33,7 +33,7 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe -INCLUDEPATH += ..src/qt/Social-Network-Qt-Application-GUI.pro \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml +SUBDIRS += ..src/qt/Social-Network-Qt-Application-GUI.pro \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ + ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml From 084c2774efb152bd9053c6da82204977cafc44cb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:23:43 -0400 Subject: [PATCH 0378/1324] Update main.cpp --- src/qt/main.cpp | 194 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 193 insertions(+), 1 deletion(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index c72209ce..b806d689 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,4 +1,4 @@ -#include "mainwindow.h" +/*#include "mainwindow.h" #include #include "homepage.h" @@ -9,4 +9,196 @@ int main(int argc, char *argv[]) w.show(); return a.exec(); +} */ + + +#include +#include +#include +#include +#include +using namespace std; +int main(); +void login() +{ + int count; + string user,pass,u,p; + system("cls"); + cout<<"please enter the following details"<>user; + cout<<"PASSWORD :"; + cin>>pass; + + ifstream input("database.txt"); + while(input>>u>>p) + { + if(u==user && p==pass) + + { + count=1; + system("cls"); + } + } + input.close(); + if(count==1) + { + cout<<"\nHello"<>reguser; + cout<<"\nEnter the password :"; + cin>>regpass; + + ofstream reg("database.txt",ios::app); + reg<>ch; + switch(ch) + { + case 1: + { + int count=0; + string searchuser,su,sp; + cout<<"\nEnter your remembered username :"; + cin>>searchuser; + + ifstream searchu("database.txt"); + while(searchu>>su>>sp) + { + if(su==searchuser) + { + count=1; + } + } + searchu.close(); + if(count==1) + { + cout<<"\n\nHurray, account found\n"; + cout<<"\nYour password is "<>searchpass; + + ifstream searchp("database.txt"); + while(searchp>>su2>>sp2) + { + if(sp2==searchpass) + { + count=1; + } + } + searchp.close(); + if(count==1) + { + cout<<"\nYour password is found in the database \n"; + cout<<"\nYour Id is : "<>choice; + cout< Date: Wed, 10 Jun 2020 15:26:00 -0400 Subject: [PATCH 0379/1324] Update main.cpp --- src/qt/main.cpp | 194 +----------------------------------------------- 1 file changed, 1 insertion(+), 193 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index b806d689..c72209ce 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,4 +1,4 @@ -/*#include "mainwindow.h" +#include "mainwindow.h" #include #include "homepage.h" @@ -9,196 +9,4 @@ int main(int argc, char *argv[]) w.show(); return a.exec(); -} */ - - -#include -#include -#include -#include -#include -using namespace std; -int main(); -void login() -{ - int count; - string user,pass,u,p; - system("cls"); - cout<<"please enter the following details"<>user; - cout<<"PASSWORD :"; - cin>>pass; - - ifstream input("database.txt"); - while(input>>u>>p) - { - if(u==user && p==pass) - - { - count=1; - system("cls"); - } - } - input.close(); - if(count==1) - { - cout<<"\nHello"<>reguser; - cout<<"\nEnter the password :"; - cin>>regpass; - - ofstream reg("database.txt",ios::app); - reg<>ch; - switch(ch) - { - case 1: - { - int count=0; - string searchuser,su,sp; - cout<<"\nEnter your remembered username :"; - cin>>searchuser; - - ifstream searchu("database.txt"); - while(searchu>>su>>sp) - { - if(su==searchuser) - { - count=1; - } - } - searchu.close(); - if(count==1) - { - cout<<"\n\nHurray, account found\n"; - cout<<"\nYour password is "<>searchpass; - - ifstream searchp("database.txt"); - while(searchp>>su2>>sp2) - { - if(sp2==searchpass) - { - count=1; - } - } - searchp.close(); - if(count==1) - { - cout<<"\nYour password is found in the database \n"; - cout<<"\nYour Id is : "<>choice; - cout< Date: Wed, 10 Jun 2020 15:28:40 -0400 Subject: [PATCH 0380/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 198 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 177 insertions(+), 21 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 367fd90e..e63b91db 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -33,33 +33,189 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::on_signUpButton_clicked() +void MainWindow::login() { - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); + int count; + string user,pass,u,p; + system("cls"); + cout<<"please enter the following details"<>user; + cout<<"PASSWORD :"; + cin>>pass; + + ifstream input("database.txt"); + while(input>>u>>p) + { + if(u==user && p==pass) + + { + count=1; + system("cls"); + } + } + input.close(); + if(count==1) + { + cout<<"\nHello"<>reguser; + cout<<"\nEnter the password :"; + cin>>regpass; + + ofstream reg("database.txt",ios::app); + reg<>ch; + switch(ch) + { + case 1: + { + int count=0; + string searchuser,su,sp; + cout<<"\nEnter your remembered username :"; + cin>>searchuser; + + ifstream searchu("database.txt"); + while(searchu>>su>>sp) + { + if(su==searchuser) + { + count=1; + } + } + searchu.close(); + if(count==1) + { + cout<<"\n\nHurray, account found\n"; + cout<<"\nYour password is "<>searchpass; + + ifstream searchp("database.txt"); + while(searchp>>su2>>sp2) + { + if(sp2==searchpass) + { + count=1; + } + } + searchp.close(); + if(count==1) + { + cout<<"\nYour password is found in the database \n"; + cout<<"\nYour Id is : "<txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) - { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; - } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) - { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; - } + int choice; + cout<<"***********************************************************************\n\n"; + cout<<" Welcome to login page \n\n"; + cout<<"******************* MENU ********************************\n\n"; + cout<<"1.LOGIN\n"; + cout<<"2.REGISTER\n"; + cout<<"3.FORGOT PASSWORD (or) USERNAME\n"; + cout<<"4.Exit\n"; + cout<<"\nEnter your choice : "; + cin>>choice; + cout<setCurrentSessionUser_Ptr(currentSessionUser); homePageWindow->show(); From 8003006b73b0180f44b51f4fb9ad3a89314684d2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:30:26 -0400 Subject: [PATCH 0381/1324] Update mainwindow.h --- src/qt/mainwindow.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 5b17c669..e9622f10 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -18,9 +18,11 @@ class MainWindow : public QMainWindow ~MainWindow(); private Q_SLOTS: - void on_signUpButton_clicked(); + void on_registrButton_clicked(); - void on_logInButton_clicked(); + void on_loginButton_clicked(); + + void on_forgotButton_clicked(); private: Ui::MainWindow *ui; From 20bf42ce443512ccba628a7037565104c15131f2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:40:24 -0400 Subject: [PATCH 0382/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index f9070099..5c4fe3ae 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 464 - 319 + 482 + 369 @@ -443,6 +443,18 @@ + + + 0 + 0 + + + + + 100 + 30 + + PointingHandCursor @@ -505,8 +517,20 @@ - + + + + 0 + 0 + + + + + 100 + 30 + + PointingHandCursor @@ -515,6 +539,28 @@ + + + + + 0 + 0 + + + + + 100 + 30 + + + + PointingHandCursor + + + Forgot Password + + + @@ -526,8 +572,8 @@ 0 0 - 464 - 26 + 482 + 21 From 762379a42f89a6be54bede817e201f93d51a856d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:41:09 -0400 Subject: [PATCH 0383/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index 5c4fe3ae..66df09a7 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -442,7 +442,7 @@ - + 0 @@ -518,7 +518,7 @@ - + 0 From a2f7b8cc2abcf4c4428c0a933c5b80e6dd1c84d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:43:26 -0400 Subject: [PATCH 0384/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index e63b91db..31cb685d 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -33,7 +33,7 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::login() +void MainWindow::loginButton_clicked() { int count; string user,pass,u,p; @@ -68,7 +68,7 @@ void MainWindow::login() main(); } } -void MainWindow::registr() +void MainWindow::registrButton_clicked() { string reguser,regpass,ru,rp; @@ -87,7 +87,7 @@ void MainWindow::registr() } -void MainWindow::forgot() +void MainWindow::forgotButton_clicked() { int ch; system("cls"); From 5b1fec5b5f8fd3b6797b3bcc30daca96cc546ab8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:47:33 -0400 Subject: [PATCH 0385/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 31cb685d..4c505b2b 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -33,7 +33,7 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::loginButton_clicked() +void MainWindow::on_loginButton_clicked() { int count; string user,pass,u,p; @@ -68,7 +68,7 @@ void MainWindow::loginButton_clicked() main(); } } -void MainWindow::registrButton_clicked() +void MainWindow::on_registrButton_clicked() { string reguser,regpass,ru,rp; @@ -87,7 +87,7 @@ void MainWindow::registrButton_clicked() } -void MainWindow::forgotButton_clicked() +void MainWindow::on_forgotButton_clicked() { int ch; system("cls"); From 2e2ce17ddeb2e05b74c26b1dcd27622bfbca7aee Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:49:33 -0400 Subject: [PATCH 0386/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4c505b2b..de764321 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -36,7 +36,7 @@ MainWindow::~MainWindow() void MainWindow::on_loginButton_clicked() { int count; - string user,pass,u,p; + QString user,pass,u,p; system("cls"); cout<<"please enter the following details"<>reguser; @@ -102,7 +102,7 @@ void MainWindow::on_forgotButton_clicked() case 1: { int count=0; - string searchuser,su,sp; + QString searchuser,su,sp; cout<<"\nEnter your remembered username :"; cin>>searchuser; @@ -137,7 +137,7 @@ void MainWindow::on_forgotButton_clicked() case 2: { int count=0; - string searchpass,su2,sp2; + QString searchpass,su2,sp2; cout<<"\nEnter the remembered password :"; cin>>searchpass; From f163af36dc891a78de3bd4c1dd006e22f1151719 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:52:20 -0400 Subject: [PATCH 0387/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 69 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index de764321..0f572422 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include "homepage.h" #include "QMessageBox" +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -38,10 +39,10 @@ void MainWindow::on_loginButton_clicked() int count; QString user,pass,u,p; system("cls"); - cout<<"please enter the following details"<>user; - cout<<"PASSWORD :"; + std::cout<<"PASSWORD :"; cin>>pass; ifstream input("database.txt"); @@ -57,14 +58,14 @@ void MainWindow::on_loginButton_clicked() input.close(); if(count==1) { - cout<<"\nHello"<>reguser; - cout<<"\nEnter the password :"; + std::cout<<"\nEnter the password :"; cin>>regpass; ofstream reg("database.txt",ios::app); reg<>ch; switch(ch) { @@ -103,7 +104,7 @@ void MainWindow::on_forgotButton_clicked() { int count=0; QString searchuser,su,sp; - cout<<"\nEnter your remembered username :"; + std::cout<<"\nEnter your remembered username :"; cin>>searchuser; ifstream searchu("database.txt"); @@ -117,8 +118,8 @@ void MainWindow::on_forgotButton_clicked() searchu.close(); if(count==1) { - cout<<"\n\nHurray, account found\n"; - cout<<"\nYour password is "<>searchpass; ifstream searchp("database.txt"); @@ -152,8 +153,8 @@ void MainWindow::on_forgotButton_clicked() searchp.close(); if(count==1) { - cout<<"\nYour password is found in the database \n"; - cout<<"\nYour Id is : "<>choice; - cout< Date: Wed, 10 Jun 2020 15:52:58 -0400 Subject: [PATCH 0388/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 0f572422..61b85218 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -208,7 +208,7 @@ main() break; case 4: - cout<<"Thanks for using this program\nThis program is created by @Thestral9\n\n"; + std::cout<<"Thanks for using this program\nThis program is created by @Thestral9\n\n"; break; default: system("cls"); From 3587e4e74c145f44736b9d7ccba28d0dee0e9f8c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:55:26 -0400 Subject: [PATCH 0389/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 61b85218..724093ca 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -39,10 +39,10 @@ void MainWindow::on_loginButton_clicked() int count; QString user,pass,u,p; system("cls"); - std::cout<<"please enter the following details"<>user; - std::cout<<"PASSWORD :"; + cout<<"PASSWORD :"; cin>>pass; ifstream input("database.txt"); @@ -58,14 +58,14 @@ void MainWindow::on_loginButton_clicked() input.close(); if(count==1) { - std::cout<<"\nHello"<>reguser; - std::cout<<"\nEnter the password :"; + cout<<"\nEnter the password :"; cin>>regpass; ofstream reg("database.txt",ios::app); reg<>ch; switch(ch) { @@ -104,7 +104,7 @@ void MainWindow::on_forgotButton_clicked() { int count=0; QString searchuser,su,sp; - std::cout<<"\nEnter your remembered username :"; + cout<<"\nEnter your remembered username :"; cin>>searchuser; ifstream searchu("database.txt"); @@ -118,8 +118,8 @@ void MainWindow::on_forgotButton_clicked() searchu.close(); if(count==1) { - std::cout<<"\n\nHurray, account found\n"; - std::cout<<"\nYour password is "<>searchpass; ifstream searchp("database.txt"); @@ -153,8 +153,8 @@ void MainWindow::on_forgotButton_clicked() searchp.close(); if(count==1) { - std::cout<<"\nYour password is found in the database \n"; - std::cout<<"\nYour Id is : "<>choice; - std::cout< Date: Wed, 10 Jun 2020 15:56:19 -0400 Subject: [PATCH 0390/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 207 +++++------------------------------------- 1 file changed, 24 insertions(+), 183 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 724093ca..ca0bc3d4 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,12 +1,9 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newaccount.h" -#include -#include -#include +#include "newAccount.h" +#include #include "homepage.h" #include "QMessageBox" -#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -14,7 +11,7 @@ ui(new Ui::MainWindow) { ui->setupUi(this); ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/chat")); +QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); this->setWindowTitle("Social Network"); } @@ -34,189 +31,33 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::on_loginButton_clicked() +void MainWindow::on_signUpButton_clicked() { - int count; - QString user,pass,u,p; - system("cls"); - cout<<"please enter the following details"<>user; - cout<<"PASSWORD :"; - cin>>pass; - - ifstream input("database.txt"); - while(input>>u>>p) - { - if(u==user && p==pass) - - { - count=1; - system("cls"); - } - } - input.close(); - if(count==1) - { - cout<<"\nHello"<>reguser; - cout<<"\nEnter the password :"; - cin>>regpass; - - ofstream reg("database.txt",ios::app); - reg<show(); + this->hide(); } -void MainWindow::on_forgotButton_clicked() -{ - int ch; - system("cls"); - cout<<"Forgotten ? We're here for help\n"; - cout<<"1.Search your id by username"<>ch; - switch(ch) - { - case 1: - { - int count=0; - QString searchuser,su,sp; - cout<<"\nEnter your remembered username :"; - cin>>searchuser; - - ifstream searchu("database.txt"); - while(searchu>>su>>sp) - { - if(su==searchuser) - { - count=1; - } - } - searchu.close(); - if(count==1) - { - cout<<"\n\nHurray, account found\n"; - cout<<"\nYour password is "<>searchpass; - - ifstream searchp("database.txt"); - while(searchp>>su2>>sp2) - { - if(sp2==searchpass) - { - count=1; - } - } - searchp.close(); - if(count==1) - { - cout<<"\nYour password is found in the database \n"; - cout<<"\nYour Id is : "<>choice; - cout<txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; + } + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; + } HomePage *homePageWindow = new HomePage(); homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); homePageWindow->show(); From ea82d90f2a114d54fd8a2e70733b8f178d9742c7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:56:44 -0400 Subject: [PATCH 0391/1324] Update mainwindow.h --- src/qt/mainwindow.h | 77 ++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index e9622f10..ca0bc3d4 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,31 +1,66 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "newAccount.h" +#include +#include "homepage.h" +#include "QMessageBox" -#include +MainWindow::MainWindow(QWidget *parent) : +QMainWindow(parent), +ui(new Ui::MainWindow) +{ +ui->setupUi(this); +ui->signUpLabel->setText("No account? Create one!"); +QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +this->setWindowTitle("Social Network"); + +} + +MainWindow::MainWindow(int userID) : + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + ui->signUpLabel->setText("No account? Create one!"); + id=userID; + qDebug()<< "id is "<show(); + this->hide(); -private Q_SLOTS: - void on_registrButton_clicked(); - void on_loginButton_clicked(); - - void on_forgotButton_clicked(); +} -private: - Ui::MainWindow *ui; -}; +void MainWindow::on_logInButton_clicked() +{ + QString email=ui->txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; + } + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; + } + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); -#endif // MAINWINDOW_H +} From fc9b928b551a9f0400a6e9536ea1c24ac9bb0758 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:57:38 -0400 Subject: [PATCH 0392/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index 66df09a7..aa3a8aa7 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -442,7 +442,7 @@ - + 0 @@ -518,7 +518,7 @@ - + 0 @@ -539,28 +539,6 @@ - - - - - 0 - 0 - - - - - 100 - 30 - - - - PointingHandCursor - - - Forgot Password - - - From 0b8841b86706d75fb23873db0491c9a82100cf27 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:58:20 -0400 Subject: [PATCH 0393/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ca0bc3d4..ee71a1fd 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" +#include "newaccount.h" #include #include "homepage.h" #include "QMessageBox" @@ -11,7 +11,7 @@ ui(new Ui::MainWindow) { ui->setupUi(this); ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +QWidget::setWindowIcon(QIcon(":/icons/chat")); this->setWindowTitle("Social Network"); } From 459046d92378f308de4566bb8013f2611a564bff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 15:58:46 -0400 Subject: [PATCH 0394/1324] Update mainwindow.h --- src/qt/mainwindow.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index ca0bc3d4..ee71a1fd 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" +#include "newaccount.h" #include #include "homepage.h" #include "QMessageBox" @@ -11,7 +11,7 @@ ui(new Ui::MainWindow) { ui->setupUi(this); ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +QWidget::setWindowIcon(QIcon(":/icons/chat")); this->setWindowTitle("Social Network"); } From 5326d538b03993a92b385595ea31548b84acca1b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:02:50 -0400 Subject: [PATCH 0395/1324] Update mainwindow.h --- src/qt/mainwindow.h | 75 ++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 56 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index ee71a1fd..5b17c669 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,66 +1,29 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "newaccount.h" -#include -#include "homepage.h" -#include "QMessageBox" +#ifndef MAINWINDOW_H +#define MAINWINDOW_H -MainWindow::MainWindow(QWidget *parent) : -QMainWindow(parent), -ui(new Ui::MainWindow) -{ -ui->setupUi(this); -ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/chat")); -this->setWindowTitle("Social Network"); - -} - -MainWindow::MainWindow(int userID) : - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - id=userID; - qDebug()<< "id is "< +namespace Ui { +class MainWindow; } -MainWindow::~MainWindow() +class MainWindow : public QMainWindow { - delete ui; -} + Q_OBJECT -void MainWindow::on_signUpButton_clicked() -{ - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); +public: + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; + ~MainWindow(); +private Q_SLOTS: + void on_signUpButton_clicked(); -} + void on_logInButton_clicked(); -void MainWindow::on_logInButton_clicked() -{ - QString email=ui->txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) - { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; - } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) - { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; - } - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); +private: + Ui::MainWindow *ui; +}; -} +#endif // MAINWINDOW_H From 60c9a9292ebcffa6ecf4c7a17829f74ca3208138 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:14:58 -0400 Subject: [PATCH 0396/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 180 ++++++++++++++++++++++++++++--------- 1 file changed, 137 insertions(+), 43 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index aa3a8aa7..0e430af0 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -431,47 +431,82 @@ - + - - - - - No account? Create one! - - - - - - - - 0 - 0 - - - - - 100 - 30 - - - - PointingHandCursor - - - Sign Up - - - - + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + No account? Create one! + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 15 + + + + + + + + + 0 + 0 + + + + + 100 + 30 + + + + PointingHandCursor + + + Sign Up + + + + + + + - - + + @@ -485,7 +520,29 @@ - + + + + + 0 + 0 + + + + + 285 + 0 + + + + + 285 + 16777215 + + + + + @@ -499,15 +556,20 @@ - - - - - - - - + + + + 285 + 0 + + + + + 285 + 16777215 + + QLineEdit::Password @@ -517,6 +579,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 23 + + + + @@ -543,6 +621,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 30 + + + + From d83d6ae2b3fbd9900f68ab11b465524e25b94736 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:19:48 -0400 Subject: [PATCH 0397/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5d39b1d1..a492af05 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -638,7 +638,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoNewAccount())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); From 853746df9052a234e97b277c543558a829ab9b06 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:20:15 -0400 Subject: [PATCH 0398/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a2e6b772..4e29b136 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoNewAccount(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 6975ce7e030ebd40d52734834be2853d16bed371 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:22:26 -0400 Subject: [PATCH 0399/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index a492af05..8c6a8b66 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "mainwindow.h" +#include "newaccount.h" /* #include "tradingdialogpage.h" */ @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - mainWindow(0), + newaccount(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -621,8 +621,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World Social Media")); + newAccount = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + newAccount->setStatusTip(tr("HTH World Social Media")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -638,7 +638,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoNewAccount())); + connect(newAccount, SIGNAL(triggered()), this, SLOT(gotoNewAccount())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -741,7 +741,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(mainWindow); + media->addAction(newAccount); } @@ -1070,10 +1070,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoMainWindow() +void BitcoinGUI::gotoNewAccount() { mainWindow->setChecked(true); - if (walletFrame) walletFrame->gotoMainWindow(); + if (walletFrame) walletFrame->gotoNewAccount(); } /*void BitcoinGUI::gotoTradingDialogPage() From d0de39bb35e9a60b2c92700efb436e62e1ebbd44 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:23:07 -0400 Subject: [PATCH 0400/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 4e29b136..e045e829 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class MainWindow; +class NewAccount; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* mainWindow; + QAction* newAccount; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ From a6e3db8bdc64ebd79d64d6d24e39b9ed30b81be7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:23:45 -0400 Subject: [PATCH 0401/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index a170c85a..29c45e55 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoMainWindow() +void WalletFrame::gotoNewAccount() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoMainWindow(); + i.value()->gotoNewAccount(); } /*void WalletFrame::gotoTradingDialogPage() From 857ff59a6a0cc9eda46c343eb3571598817efd49 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:24:02 -0400 Subject: [PATCH 0402/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index a6eb3ece..1f368c3d 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoNewAccount(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 0a62816e12e8b6ef07f605b368b4d146021edcbb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:24:41 -0400 Subject: [PATCH 0403/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 40ca8074..bce4add4 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,7 +9,7 @@ #include "masternodelist.h" #include "governancelist.h" /* #include "tradingdialogpage.h" */ -#include "mainwindow.h" +#include "newaccount.h" @@ -28,7 +28,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class MainWindow; +class NewAccount; QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - MainWindow *mainWindow; + NewAccount *newAccount; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -89,7 +89,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoNewAccount(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From a72572d1f904b3abfaebd5b27f0cb7f9c0c5ab29 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:25:31 -0400 Subject: [PATCH 0404/1324] Update walletview.cpp --- src/qt/walletview.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 9695452c..8a762322 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "mainwindow.h" +#include "newaccount.h" #include "ui_interface.h" @@ -89,8 +89,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - mainWindow = new MainWindow(); - addWidget(mainWindow); + newAccount = new NewAccount(); + addWidget(newAccount); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -242,9 +242,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoMainWindow() +void WalletView::gotoNewAccount() { - setCurrentWidget(mainWindow); + setCurrentWidget(newAccount); } /*void WalletView::gotoTradingDialogPage() From e9adabb6cd2f26c3d2d821abfbcfe3dbbbcbe800 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:28:00 -0400 Subject: [PATCH 0405/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 8c6a8b66..a3de2556 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1072,7 +1072,7 @@ void BitcoinGUI::openClicked() void BitcoinGUI::gotoNewAccount() { - mainWindow->setChecked(true); + newAccount->setChecked(true); if (walletFrame) walletFrame->gotoNewAccount(); } From 85557944e568002ddd12bbf5a481bbc0244776ba Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:29:49 -0400 Subject: [PATCH 0406/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index a3de2556..e76f3e86 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - newaccount(0), + newAccount(0), platformStyle(_platformStyle) { /* Open CSS when configured */ From f23d1748f5bab8e00f363e37e1a4ca01cd97d6ec Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:32:10 -0400 Subject: [PATCH 0407/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index c7066d4b..33db005f 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -2,6 +2,8 @@ #include "ui_newaccount.h" #include "QMessageBox" #include +#include + newAccount::newAccount(QWidget *parent) : QMainWindow(parent), ui(new Ui::newAccount) From 04e62d303907e662d88f97311bf63e8e39653078 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:36:47 -0400 Subject: [PATCH 0408/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index dd87603b..554b88de 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -1,7 +1,7 @@ - newAccount - + NewAccount + 0 From f71347b76f41460b49faf1ab87f5b14f8ea3e7bc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:38:08 -0400 Subject: [PATCH 0409/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 33db005f..5ec6d3ea 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -4,9 +4,9 @@ #include #include -newAccount::newAccount(QWidget *parent) : +NewAccount::NewAccount(QWidget *parent) : QMainWindow(parent), - ui(new Ui::newAccount) + ui(new Ui::NewAccount) { ui->setupUi(this); user check; @@ -16,12 +16,12 @@ newAccount::newAccount(QWidget *parent) : } -newAccount::~newAccount() +NewAccount::~NewAccount() { delete ui; } -void newAccount::on_pushButton_clicked() +void NewAccount::on_pushButton_clicked() { QString password =ui->lineEdit_2->text(); QString confirm =ui->lineEdit_3->text(); @@ -42,12 +42,12 @@ void newAccount::on_pushButton_clicked() } -void newAccount::setLoginPtr(MainWindow *ptr) +void NewAccount::setLoginPtr(MainWindow *ptr) { this->mainWindowPtr = ptr; } -void newAccount::on_pushButton_2_clicked() +void NewAccount::on_pushButton_2_clicked() { MainWindow* newWindow= new MainWindow(id); newWindow->show(); From 77f3866f807ac9ea9d9201060862e99191ec8dd5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:38:29 -0400 Subject: [PATCH 0410/1324] Update newaccount.h --- src/qt/newaccount.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index b69d4800..cb6d5309 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -4,16 +4,16 @@ #include #include "mainwindow.h" namespace Ui { -class newAccount; +class NewAccount; } -class newAccount : public QMainWindow +class NewAccount : public QMainWindow { Q_OBJECT public: - explicit newAccount(QWidget *parent = 0); - ~newAccount(); + explicit NewAccount(QWidget *parent = 0); + ~NewAccount(); int id; @@ -28,7 +28,7 @@ private Q_SLOTS: private: - Ui::newAccount *ui; + Ui::NewAccount *ui; MainWindow *mainWindowPtr; }; From 098658e23608b6e029f33d65202a835875462e02 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 16:39:11 -0400 Subject: [PATCH 0411/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index ee71a1fd..82f498e2 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -33,7 +33,7 @@ MainWindow::~MainWindow() void MainWindow::on_signUpButton_clicked() { - newAccount *newAccountWindow = new newAccount; + NewAccount *newAccountWindow = new NewAccount; newAccountWindow->show(); this->hide(); From ea51933beb76b7e7e311e75ca0d7bfa859d5ed5f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:18:29 -0400 Subject: [PATCH 0412/1324] Delete Activity.cpp --- src/qt/Activity.cpp | 48 --------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/qt/Activity.cpp diff --git a/src/qt/Activity.cpp b/src/qt/Activity.cpp deleted file mode 100644 index eb388cc8..00000000 --- a/src/qt/Activity.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Activity.h" -#include -#include "posts.h" -#include"vector" - - -Activity::Activity() -{ - likesNumbers = 0; - postsNumber = 0; -} - -Activity::~Activity() -{ - -} -unsigned int Activity::getFriendsNumbers() - - {return friends.size();} - -unsigned int Activity::getPostsNumbers() - -{ return postsNumber;} - -void Activity::addFriend(QString friendName) -{ - friends.push_back(friendName); -} - -void Activity::addPost() -{ - postsNumber++; -} - -unsigned int Activity::getLikesNumbers() -{ - return likesNumbers; -} - -void Activity:: addLike() -{ - likesNumbers++; -} - -QList *Activity::getFriendsList_Ptr() -{ - return &friends; -} From 130586e660d4a9f103d618cd58520ab625afa2cd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:18:36 -0400 Subject: [PATCH 0413/1324] Delete Activity.h --- src/qt/Activity.h | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/qt/Activity.h diff --git a/src/qt/Activity.h b/src/qt/Activity.h deleted file mode 100644 index 24896d27..00000000 --- a/src/qt/Activity.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef ACTIVITY_H -#define ACTIVITY_H -#include -#include -#include "vector" -#include "posts.h" -#include "QList" -class Activity -{ - unsigned int likesNumbers; - - unsigned int postsNumber; - - QList friends; - - -public: - - Activity(); - - ~Activity(); - - unsigned int getLikesNumbers(); - - unsigned int getFriendsNumbers(); - - unsigned int getPostsNumbers(); - - void addLike(); - - void addFriend(QString); - - void addPost(); - - QList *getFriendsList_Ptr(); -}; - -#endif // ACTIVITY_H From de17d13e191a4452f82e9cb3e5cabe039f4e1e7d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:18:41 -0400 Subject: [PATCH 0414/1324] Delete Social-Network-Qt-Application-GUI.pro --- src/qt/Social-Network-Qt-Application-GUI.pro | 66 -------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro b/src/qt/Social-Network-Qt-Application-GUI.pro deleted file mode 100644 index 245f5ef5..00000000 --- a/src/qt/Social-Network-Qt-Application-GUI.pro +++ /dev/null @@ -1,66 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2018-04-19T16:47:57 -# -#------------------------------------------------- - -QT += core gui xml printsupport - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = Social-Network-Qt-Application-GUI -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - -SOURCES += \ - main.cpp \ - mainwindow.cpp \ - newaccount.cpp \ - profilepage.cpp \ - addcomment.cpp \ - posts.cpp \ - comment.cpp \ - Activity.cpp \ - user.cpp \ - fileman.cpp \ - qcustomplot.cpp \ - adminwindow.cpp \ - statistics.cpp \ - homepage.cpp - -HEADERS += \ - mainwindow.h \ - newaccount.h \ - homepage.h \ - profilepage.h \ - addcomment.h \ - posts.h \ - comment.h \ - Activity.h \ - user.h \ - fileman.h \ - qcustomplot.h \ - adminwindow.h \ - statistics.h - -FORMS += \ - mainwindow.ui \ - newaccount.ui \ - homepage.ui \ - profilepage.ui \ - addcomment.ui \ - adminwindow.ui - -RESOURCES += \ - myresources.qrc From 0db84e15823d740a0df47633d396777ec072488d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:18:48 -0400 Subject: [PATCH 0415/1324] Delete Social-Network-Qt-Application-GUI.pro.user --- ...Social-Network-Qt-Application-GUI.pro.user | 2759 ----------------- 1 file changed, 2759 deletions(-) delete mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user b/src/qt/Social-Network-Qt-Application-GUI.pro.user deleted file mode 100644 index 393889eb..00000000 --- a/src/qt/Social-Network-Qt-Application-GUI.pro.user +++ /dev/null @@ -1,2759 +0,0 @@ - - - - - - EnvironmentId - {fe1e10ad-70df-4b47-bcd1-f71c5f735ac1} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.5.1 MinGW 32bit - Desktop Qt 5.5.1 MinGW 32bit - qt.55.win32_mingw492_kit - 1 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) - Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) - qt.55.win64_msvc2013_winphone_x86_kit - 0 - -1 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - 0 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.10 - - Desktop Qt 5.11.0 MinGW 32bit2 - Desktop Qt 5.11.0 MinGW 32bit2 - qt.qt5.5110.win32_mingw53_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.2 - - Qt 5.5.1 for Windows Runtime 64bit - Qt 5.5.1 for Windows Runtime 64bit - qt.55.win64_msvc2013_winrt_x64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - - true - - Run windeployqt - WinRt.BuildStep.Deploy - --qmldir "D:\Comp-Third year\Data structures & Algorithms\Project\Social-Network-Qt-Application-GUI" - - 1 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Run windeployqt - - WinRTAppxDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.3 - - Desktop Qt 5.5.1 MSVC2010 32bit - Desktop Qt 5.5.1 MSVC2010 32bit - qt.55.win32_msvc2010_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.4 - - Desktop Qt 5.5.1 MSVC2012 32bit - Desktop Qt 5.5.1 MSVC2012 32bit - qt.55.win32_msvc2012_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.5 - - Desktop Qt 5.5.1 MSVC2013 32bit - Desktop Qt 5.5.1 MSVC2013 32bit - qt.55.win32_msvc2013_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.6 - - Desktop Qt 5.5.1 MSVC2013 64bit - Desktop Qt 5.5.1 MSVC2013 64bit - qt.55.win64_msvc2013_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.7 - - Desktop Qt 5.11.0 MSVC2015 32bit - Desktop Qt 5.11.0 MSVC2015 32bit - qt.qt5.5110.win32_msvc2015_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.8 - - Desktop Qt 5.11.0 MSVC2015 64bit - Desktop Qt 5.11.0 MSVC2015 64bit - qt.qt5.5110.win64_msvc2015_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.9 - - Desktop Qt 5.11.0 MSVC2017 64bit - Desktop Qt 5.11.0 MSVC2017 64bit - qt.qt5.5110.win64_msvc2017_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 11 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From 92986f02d7905a6df80d97c0b18aaf5974af9dfb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:18:54 -0400 Subject: [PATCH 0416/1324] Delete Social-Network-Qt-Application-GUI.pro.user.b3887f6 --- ...etwork-Qt-Application-GUI.pro.user.b3887f6 | 318 ------------------ 1 file changed, 318 deletions(-) delete mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 b/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 deleted file mode 100644 index b6c060fc..00000000 --- a/src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - EnvironmentId - {b3887f65-3e4c-4f2e-995b-8c4746b920fe} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.7.0 MinGW 32bit - Desktop Qt 5.7.0 MinGW 32bit - qt.57.win32_mingw53_kit - 0 - 0 - 0 - - C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/lenovo/Desktop/DS/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - C:/Users/lenovo/Desktop/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_7_0_MinGW_32bit-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From 2c5fe2533603a522e0a8f8a742e14f631814492f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:01 -0400 Subject: [PATCH 0417/1324] Delete Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml --- ...rk-Qt-Application-GUI.pro.user.fe1e10a.xml | 2756 ----------------- 1 file changed, 2756 deletions(-) delete mode 100644 src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml diff --git a/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml b/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml deleted file mode 100644 index df80aac0..00000000 --- a/src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml +++ /dev/null @@ -1,2756 +0,0 @@ - - - - - - EnvironmentId - {fe1e10ad-70df-4b47-bcd1-f71c5f735ac1} - - - ProjectExplorer.Project.ActiveTarget - 10 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.5.1 MinGW 32bit - Desktop Qt 5.5.1 MinGW 32bit - qt.55.win32_mingw492_kit - 1 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) - Qt 5.5.1 for Windows Phone x86 MSVC2013 32bit (Emulator) - qt.55.win64_msvc2013_winphone_x86_kit - 0 - -1 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Phone_x86_MSVC2013_32bit_Emulator-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - 0 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.10 - - Desktop Qt 5.11.0 MinGW 32bit2 - Desktop Qt 5.11.0 MinGW 32bit2 - qt.qt5.5110.win32_mingw53_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Social-Network-Qt-Application-GUI - - Qt4ProjectManager.Qt4RunConfiguration:D:/Comp-Third year/Data structures & Algorithms/Project/Social-Network-Qt-Application-GUI/Social-Network-Qt-Application-GUI.pro - true - - Social-Network-Qt-Application-GUI.pro - false - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MinGW_32bit2-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.2 - - Qt 5.5.1 for Windows Runtime 64bit - Qt 5.5.1 for Windows Runtime 64bit - qt.55.win64_msvc2013_winrt_x64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Qt_5_5_1_for_Windows_Runtime_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - - true - - Run windeployqt - WinRt.BuildStep.Deploy - --qmldir "D:\Comp-Third year\Data structures & Algorithms\Project\Social-Network-Qt-Application-GUI" - - 1 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Run windeployqt - - WinRTAppxDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.3 - - Desktop Qt 5.5.1 MSVC2010 32bit - Desktop Qt 5.5.1 MSVC2010 32bit - qt.55.win32_msvc2010_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2010_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.4 - - Desktop Qt 5.5.1 MSVC2012 32bit - Desktop Qt 5.5.1 MSVC2012 32bit - qt.55.win32_msvc2012_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2012_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.5 - - Desktop Qt 5.5.1 MSVC2013 32bit - Desktop Qt 5.5.1 MSVC2013 32bit - qt.55.win32_msvc2013_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.6 - - Desktop Qt 5.5.1 MSVC2013 64bit - Desktop Qt 5.5.1 MSVC2013 64bit - qt.55.win64_msvc2013_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_5_1_MSVC2013_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.7 - - Desktop Qt 5.11.0 MSVC2015 32bit - Desktop Qt 5.11.0 MSVC2015 32bit - qt.qt5.5110.win32_msvc2015_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.8 - - Desktop Qt 5.11.0 MSVC2015 64bit - Desktop Qt 5.11.0 MSVC2015 64bit - qt.qt5.5110.win64_msvc2015_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2015_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.9 - - Desktop Qt 5.11.0 MSVC2017 64bit - Desktop Qt 5.11.0 MSVC2017 64bit - qt.qt5.5110.win64_msvc2017_64_kit - 0 - 0 - 0 - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/Comp-Third year/Data structures & Algorithms/Project/build-Social-Network-Qt-Application-GUI-Desktop_Qt_5_11_0_MSVC2017_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - -1 - - - - %{buildDir} - Custom Executable - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 11 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From c8d3e78b8d5104c1a8696527fc26c4c2293250a2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:07 -0400 Subject: [PATCH 0418/1324] Delete addcomment.cpp --- src/qt/addcomment.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/addcomment.cpp diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp deleted file mode 100644 index 9fc92a94..00000000 --- a/src/qt/addcomment.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "addcomment.h" -#include "ui_addcomment.h" - -AddComment::AddComment(QWidget *parent) : - QDialog(parent), - ui(new Ui::AddComment) -{ - ui->setupUi(this); - commentBody = ""; - QWidget::setWindowIcon(QIcon(":/icons/chat")); -} - -AddComment::~AddComment() -{ - delete ui; -} - -void AddComment::on_AddComment_accepted() -{ - commentBody = ui->plainTextEdit->toPlainText(); -} - -QString AddComment::getCommentBody() -{ - return commentBody; -} From 94e2c40b9dd32bcb3791df7da25ac7465d979a4b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:13 -0400 Subject: [PATCH 0419/1324] Delete addcomment.h --- src/qt/addcomment.h | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/qt/addcomment.h diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h deleted file mode 100644 index 78fc9e25..00000000 --- a/src/qt/addcomment.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ADDCOMMENT_H -#define ADDCOMMENT_H - -#include - -namespace Ui { -class AddComment; -} - -class AddComment : public QDialog -{ - Q_OBJECT - -public: - explicit AddComment(QWidget *parent = 0); - - ~AddComment(); - -public Q_SLOTS: - QString getCommentBody(); - - -private Q_SLOTS: - void on_AddComment_accepted(); - - -private: - Ui::AddComment *ui; - - QString commentBody; -}; - -#endif // ADDCOMMENT_H From 7cc28ef7211c5811060737664425a0f0bb638eee Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:21 -0400 Subject: [PATCH 0420/1324] Delete adminwindow.cpp --- src/qt/adminwindow.cpp | 94 ------------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 src/qt/adminwindow.cpp diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp deleted file mode 100644 index 5b13a64e..00000000 --- a/src/qt/adminwindow.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "adminwindow.h" -#include "ui_adminwindow.h" -#include "statistics.h" -#include "fileman.h" -AdminWindow::AdminWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::AdminWindow) -{ - ui->setupUi(this); - QWidget::setWindowIcon(QIcon(":/icons/chat")); - this->showMaximized(); - this->setWindowTitle("Social Network"); - -} - -AdminWindow::~AdminWindow() -{ - delete ui; -} - - -void AdminWindow:: makePlot(QVector *plotData) -{ - ui->customPlot->clearGraphs(); - ui->customPlot->legend->setVisible(true); - ui->customPlot->legend->setFont(QFont("Helvetica", 9)); - QPen pen; - QStringList lineNames; - lineNames << "Friends Number" << "Likes Number" << "Posts Number"; - // add graphs with different line styles: - for (int i = 0; i < 3; ++i) - { - ui->customPlot->addGraph(); - if(i == 0) - pen.setColor(QColor(0x02, 0xa0, 0xc3)); - else if(i == 1) - pen.setColor(QColor(0xef, 0xef, 0x00)); - else - pen.setColor(QColor(0xef, 0x2b, 0x90)); - ui->customPlot->graph()->setPen(pen); - ui->customPlot->graph()->setName(lineNames.at(i)); - ui->customPlot->graph()->setLineStyle((QCPGraph::lsLine)); - ui->customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); - // generate data: - QVector x((*plotData).size()), y(1000); - for (int j = 0; j < (*plotData).size(); ++j) - { - x[j] = (*plotData)[j].getUserID(); - if(i == 0) - y[j] = (*plotData)[j].getFriendsNumber(); - else if(i == 1) - y[j] = (*plotData)[j].getLikesNumber(); - else - y[j] = (*plotData)[j].getPostsNumber(); - } - ui->customPlot->graph()->setData(x, y); - ui->customPlot->graph()->rescaleAxes(true); - } - // zoom out a bit: - ui->customPlot->yAxis->scaleRange(0, plotData->size()+1); - ui->customPlot->xAxis->scaleRange(0, 1000); - // set blank axis lines: - ui->customPlot->xAxis->setTicks(true); - ui->customPlot->yAxis->setTicks(true); - ui->customPlot->xAxis->setTickLabels(true); - ui->customPlot->yAxis->setTickLabels(true); - ui->customPlot->xAxis2->setVisible(true); - ui->customPlot->yAxis2->setVisible(true); - ui->customPlot->xAxis2->setTicks(false); - ui->customPlot->yAxis2->setTicks(false); - // make top right axes clones of bottom left axes: -// ui->customPlot->axisRect()->setupFullAxesBox(); - ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); - ui->customPlot->replot(); - - -} -void AdminWindow::on_showStatistics_clicked() -{ - QVector *testingData = new QVector; - fileman network; - QList emails = network.readEmails(); - testingData->resize(emails.size()); - for(int i = 0; i < emails.size(); i++) - { - (*testingData)[i].setUserID(i); - (*testingData)[i].setFriendsNumber(network.getFriends(emails[i]).size() / 3); - int likesNumber,postsNumber; - network.getActivity(emails[i],postsNumber,likesNumber); - (*testingData)[i].setPostsNumber(network.getPosts(emails[i])->size()); - (*testingData)[i].setLikesNumber(likesNumber); - } - makePlot(testingData); -} From c54cb5c302059912220ec0f79722e678b730a524 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:26 -0400 Subject: [PATCH 0421/1324] Delete adminwindow.h --- src/qt/adminwindow.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/adminwindow.h diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h deleted file mode 100644 index 3fb32a8a..00000000 --- a/src/qt/adminwindow.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ADMINWINDOW_H -#define ADMINWINDOW_H - -#include -#include "statistics.h" -namespace Ui { -class AdminWindow; -} - -class AdminWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit AdminWindow(QWidget *parent = 0); - ~AdminWindow(); - -private Q_SLOTS: - void on_showStatistics_clicked(); - - void makePlot(QVector *plotData); -private: - Ui::AdminWindow *ui; -}; - -#endif // ADMINWINDOW_H From 6b5b63163c1f2443093d1ca1fab82f055167012e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:36 -0400 Subject: [PATCH 0422/1324] Delete comment.cpp --- src/qt/comment.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/qt/comment.cpp diff --git a/src/qt/comment.cpp b/src/qt/comment.cpp deleted file mode 100644 index 09328393..00000000 --- a/src/qt/comment.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "comment.h" - -Comment::Comment() -{ - commentOwner = ""; - commentText = ""; -} - -Comment::Comment(QString owner, QString text, QString creationDate) -{ - - commentOwner = owner; - commentText = text; - commentDate = creationDate; -} - -void Comment::setCommentOwner(QString owner) -{ - commentOwner = owner; -} - -QString Comment::getCommentOwner() -{ - return commentOwner; -} - -void Comment::setCommentText(QString text) -{ - commentText = text; -} - -QString Comment::getCommentText() -{ - return commentText; -} - -void Comment::setCommentDate(QString creationDate) -{ - commentDate = creationDate; -} - -QString Comment::getCommentDate() -{ - return commentDate; -} - From 16949295c7fb115943c4f0bb03ac58533fa233e9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:45 -0400 Subject: [PATCH 0423/1324] Delete comment.h --- src/qt/comment.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/qt/comment.h diff --git a/src/qt/comment.h b/src/qt/comment.h deleted file mode 100644 index 9a54b7c9..00000000 --- a/src/qt/comment.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef COMMENT_H -#define COMMENT_H - -#include "QString" -#include "QDate" -#include "QTime" -class Date : public QDate -{ - QTime timeIsNow; -public: - QString getDateNow(){return this->currentDate().toString("yyyy.MM.dd") +" @ " +timeIsNow.currentTime().toString("HH:mm:ss");} -}; -class Comment -{ - QString commentOwner; - QString commentText; - QString commentDate; -public: - Comment(); - - Comment(QString, QString, QString); - - void setCommentOwner(QString); - - QString getCommentOwner(); - - void setCommentText(QString); - - QString getCommentText(); - - void setCommentDate(QString); - - QString getCommentDate(); -}; - -#endif // COMMENT_H From 21614a82e4035c7469945e5e63b7ef7a5f76b9f9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:19:56 -0400 Subject: [PATCH 0424/1324] Delete fileman.cpp --- src/qt/fileman.cpp | 756 --------------------------------------------- 1 file changed, 756 deletions(-) delete mode 100644 src/qt/fileman.cpp diff --git a/src/qt/fileman.cpp b/src/qt/fileman.cpp deleted file mode 100644 index cab9aee7..00000000 --- a/src/qt/fileman.cpp +++ /dev/null @@ -1,756 +0,0 @@ -#include "fileman.h" -#include - -int numberOfUsers=0; -QList emailss; -fileman::fileman() -{ - //name=username; - path=""; - -} -void fileman:: TESTTEST() -{ - QString line; - QFile in(path+name); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YOMNA SAN"; - QTextStream innn(&in); - line=innn.readLine(); - qDebug()<") - { - - line=innn.readLine(); - if(line==Date){ - line=innn.readLine(); - while(line!=NULL){ - - if(line==""){ - line=innn.readLine(); - while(line!="") - { - // cout<* fileman:: getPosts(QString email){ - QString line; - QFile in(path+"Users/"+email+".xml"); - QTextStream innn(&in); - QList *posts = new QList ; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - //bool begin_tag = false; - line=innn.readLine(); - while (line!=NULL) - { - - if(line==""){ - temp=""; - line=innn.readLine(); - while(!(line=="") ) - { - //cout<append(tempPost); - - } - line=innn.readLine(); -} - return posts; -} - - QString fileman:: getUserNameByEmail(QString email) - { - QFile in(path+"Users/"+email+".xml"); - QTextStream f (&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN the file "; - QString line=f.readLine(); - while(1) - { - if(line=="") - { - line=f.readLine(); - // qDebug()<") break; - - - } - - - - } - -void fileman:: createFile( QString passWord,QString email,QString userName,QString date ) -{ - emailss.push_back(email); - numberOfUsers++; - QString newFileStamp="\n"+userName+"\n\n"+"\n"+email+"\n\n\n"+date+"\n\n\n"+passWord+"\n\n\n\n\n0\n\n\n0\n"; - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &file ); - stream << newFileStamp; - } - - addEmail(email); - -} - -void fileman:: addPost(QString userPost, QString Date, QString name) -{ - // QString newPost=readFile("addPost.txt"); - - QFile i(path+name+".txt"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - - - - QFile in(path+"addPost.txt"); - QTextStream innn(&in); - - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString newPost=innn.readAll(); //This file is with norhaaaan doko kana wakaranai - in.close(); - - int indexText= newPost.indexOf(""); //+10 - newPost.insert(indexText+11,userPost); - - int indexDate=newPost.indexOf(""); - newPost.insert(indexDate+11,Date); - indexText= userFile.lastIndexOf(""); - userFile.insert(indexText+8,newPost); - QFile file(path+name+".txt"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} - - -void fileman:: addComment(QString userComment){ - - QString commentStamp="\n\n\n"+userComment+"\n\n\n\n\n"; - //now lets open the user file to insert el bta3 da - - QFile i(path+"addUser.txt"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - //Now we have all the user file content in userFile - int index=userFile.indexOf(""); - userFile.insert(index,commentStamp); - // qDebug()<\n\n"+nameComment+"\n\n\n"; - //now lets open the user file to insert el bta3 da - - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); -//now insert fe el userFile how is that :) - QString copy=userFile; -int from=0; -while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; -QString line="";int j=11; -line=userFile.mid(indexOfPostDate+11,Date.count()); -//userFile.insert(indexOfPostDate+j,commentStamp); - -//qDebug()<\n\n"+userPost+"\n\n"+"\n\n"+""; - - int indexText= userFile.indexOf(""); - userFile.insert(indexText+11,postStamp); - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - // qDebug()<< "couldn't open file"; - - file.close(); - -} -//QList * fileman:: getCommentsByPostDate(QString email,QString date) - -void fileman:: getCommentsByPostDate(QString email,QString date){ - - QString line; - QFile in(path+"Users/"+email+".xml"); - QTextStream inn(&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); -qDebug()< *comments = new QList ; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - - qDebug()<<"COULD NOT OPEN YA BENTY"; - int from=0; - //while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; - //QString line; - int j=11+1+1; - int indexOfCommentTag; - line=userFile.mid(indexOfPostDate+j,date.count()); - //userFile.insert(indexOfPostDate+date.count()+j+11,"hiiiiii i am here"); - // qDebug()<"; - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - int indexOfFriend=userFile.indexOf(""); - userFile.insert(indexOfFriend+9,friendStamp); -QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} -void fileman:: updateActivity(QString email, int numberOfLikes , int numberOfComments){ - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - int indexOfLikes=userFile.indexOf(""); - /* int ii=16; - QChar x=userFile[indexOfLikes+ii]; - - while(x!='\n'){ - userFile[indexOfLikes+ii]='NULL'; - ii++; - x=userFile[indexOfLikes+ii]; - - } -*/ - userFile.insert(indexOfLikes+15,"\n"+QString::number(numberOfLikes)); - int indexOfComments=userFile.indexOf(""); - userFile.insert(indexOfComments+18,"\n"+QString::number(numberOfComments)); - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); -} - - -void fileman:: networkFile(){ - QString newFileStamp="\n"+QString::number(numberOfUsers)+"\n\n"; - QFile file(path+"Users/"+"network"+".xml"); - if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &file ); - stream << newFileStamp; - } - - -} - -void fileman::addUsers(){ - QFile i(path+"Users/network.xml"); - QTextStream inn(&i); - int id=0; - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - QFile file(path+"Users/network.xml"); - fileman x; - QList emails=x.readEmails(); -for (int k = 0; k \n\n"+QString::number(id)+"\n"; - id++; - int indexText= userFile.indexOf(""); - userFile.insert(indexText+16,emailStamp); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - - } - -} - -void fileman::createEmailFile() -{ - QString stamp="\n"; - QFile f(path+"Users/"+"email"+".xml"); - if ( f.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &f ); - stream << stamp; - } -} -void fileman::addEmail(QString email){ - QFile i(path+"Users/"+"email"+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); - i.close(); - int indexText= userFile.indexOf(""); - userFile.insert(indexText+8,"\n"+email); - QFile file(path+"Users/"+"email"+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} -QList fileman:: readEmails(){ - QString line; - QFile in(path+"Users/"+"email"+".xml"); - QTextStream innn(&in); -// QList emails = new QList ; - QList emails; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - line=innn.readLine(); - - if(line==""){ - line=innn.readLine(); - while(1) - { - emails.append(line); - // qDebug()<") break; - - // if(line==NULL) break; - - } - } - - return emails; - -} - -QList fileman:: getFriends(QString email) -{ - QList result; - QFile in(path+"Users/"+email+".xml"); - QTextStream innn(&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString line=innn.readLine(); - while(1){ - if(line=="") - { - while(1) - { - line=innn.readLine(); - - if(line=="") break; - result.append(line); - if(line==""||line=="") continue; - //qDebug()<") - { - line=inn.readLine(); - numberOfLikes=line.toInt(); - break; - } - if(line=="") - { - line=inn.readLine(); - numberOfPosts=line.toInt(); - break; - } - line=inn.readLine(); - if(line=="") - break; - - } -} - -QList *fileman::getPosts_new(QString email) -{ - QList *result = new QList; - - - - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString line=inn.readLine(); - while(1) - { - Post temp; temp.setPostText(""); - if(line=="") - { - line=inn.readLine(); - while(1) - { - - if(line=="") - { - line=inn.readLine(); - temp.setPostDate(line); - // qDebug()<") - { - temp.setPostText(""); - line=inn.readLine(); - while(1) - { - if(line=="") - { - break; - } - temp.setPostText(temp.getPostText()+line); - // qDebug()<") - { - - Comment tempCom; - line=inn.readLine(); - while(1) - { - if(line=="") - { - tempCom.setCommentText(""); - line=inn.readLine(); - while(1) - { - tempCom.setCommentText(tempCom.getCommentText()+line); - line=inn.readLine(); - if(line=="")break; - } - } - if(line=="") - { - tempCom.setCommentOwner(inn.readLine()); - } - line=inn.readLine(); - if(line=="")break; - - } - //qDebug()<") - { - line=inn.readLine(); - while(line!="") - { - if(line=="") break; - if(line==""|| line=="") - { - line=inn.readLine(); - continue; - } - - temp.getPostLikesOwnersVectorPtr()->push_back(line); - - // qDebug()<") - { - fileman x; - temp.setPostOwner(email); - result->append(temp); - break; - } - - } - } - line=inn.readLine(); - if(line=="")break; - } -return result; -} - - - -void fileman ::addLikeByPostDate(QString email, QString Date, QString likePerson) -{ - QString likeStamp="\n\n"+likePerson+"\n"; - QFile i(path+"Users/"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - - int from=0; int k=0; - while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; - QString line="";int j=11; - - line=userFile.mid(indexOfPostDate+11,Date.count()); -// userFile.insert(indexOfPostDate+j,likeStamp); - - //qDebug()<",from); - int likeTagIndex= userFile.indexOf("",from); - - userFile.insert(likeTagIndex+6,likeStamp); - k++; - - qDebug()<") - { - line=f.readLine(); - // qDebug()<") break; - - - } -} From 522880f066014d37ea4141b7896be390723ce3b7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:20:04 -0400 Subject: [PATCH 0425/1324] Delete fileman.h --- src/qt/fileman.h | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 src/qt/fileman.h diff --git a/src/qt/fileman.h b/src/qt/fileman.h deleted file mode 100644 index 901e5f57..00000000 --- a/src/qt/fileman.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef FILEMAN_H -#define FILEMAN_H -#include -#include -#include -#include -#include -#include -#include "posts.h" -#include "comment.h" - - -class fileman{ -public: - QString path; - QString name; - QList posts; - - fileman(); - QString getPostByDate(QString Date); - QList * getPosts(QString email); - QString getUserNameByEmail(QString email); - void addPost(QString userPost, QString Date, QString name); - void addComment(QString userComment); - void addCommentByPostDate(QString userComment, QString Date, QString nameComment,QString nameFile); - void createFile( QString passWord,QString email,QString userName,QString date ); - void addFriend (QString friendName, QString name); - void addPost_new(QString userPost, QString Date, QString name); - void getCommentsByPostDate(QString email,QString date); - void addFriends(QString email,QString friendName); - void updateActivity(QString email, int numberOfLikes , int numberOfComments); - friend class user; - void networkFile(); - void addUsers(); - void TESTTEST(); - void createEmailFile(); - void addEmail(QString email); - QList readEmails(); - QList getFriends(QString email); - void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); - QList * getPosts_new(QString email); - -public Q_SLOTS: - void addLikeByPostDate(QString email, QString Date, QString likePerson); - QString getPassword(QString email); -}; - -#endif From 7f2ec5b766cfa842e8317f31f10da67762046bc5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:20:12 -0400 Subject: [PATCH 0426/1324] Delete form.cpp --- src/qt/form.cpp | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/qt/form.cpp diff --git a/src/qt/form.cpp b/src/qt/form.cpp deleted file mode 100644 index 20e6af24..00000000 --- a/src/qt/form.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "form.h" -#include "ui_form.h" - -Form::Form(QWidget *parent) : - QWidget(parent), - ui(new Ui::Form) -{ - ui->setupUi(this); -} - -Form::~Form() -{ - delete ui; -} From 4ea37dc6fb75e89c027071408cda6f20790206f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:20:20 -0400 Subject: [PATCH 0427/1324] Delete form.h --- src/qt/form.h | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/qt/form.h diff --git a/src/qt/form.h b/src/qt/form.h deleted file mode 100644 index 59d50c60..00000000 --- a/src/qt/form.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FORM_H -#define FORM_H - -#include - -namespace Ui { -class Form; -} - -class Form : public QWidget -{ - Q_OBJECT - -public: - explicit Form(QWidget *parent = 0); - ~Form(); - -private: - Ui::Form *ui; -}; - -#endif // FORM_H From 42becc63d3dd69336391e6213c86d6fb913c8db3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:20:30 -0400 Subject: [PATCH 0428/1324] Delete homepage.cpp --- src/qt/homepage.cpp | 441 -------------------------------------------- 1 file changed, 441 deletions(-) delete mode 100644 src/qt/homepage.cpp diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp deleted file mode 100644 index cd23978d..00000000 --- a/src/qt/homepage.cpp +++ /dev/null @@ -1,441 +0,0 @@ -#include "homepage.h" -#include "ui_homepage.h" -#include "profilepage.h" -#include "qprocess.h" - -//selim includes -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "QHBoxLayout" -#include "QVBoxLayout" -#include "QLabel" -#include "QSpacerItem" -#include "QPushButton" -#include -#include "posts.h" -#include "QString" -#include -#include "QFontMetrics" -#include "QGroupBox" -#include "QScrollBar" -#include "mainwindow.h" -#include "addcomment.h" -#include "adminwindow.h" -#define POSTSNUMBER 100 -#define COMMENTSNUMBER 3 -#define POSTSATATIME 15 -//_____ -HomePage::HomePage(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::HomePage) -{ - ui->setupUi(this); - shownPostsNumber = 0; - ui->comboBox->setVisible(false); - pagePosts = new QList; - QWidget::setWindowIcon(QIcon(":/icons/chat")); - this->showMaximized(); - this->setWindowTitle("Social Network"); - -} - -void HomePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) -{ - this->currentSessionUser = currentSessionUser_ptr; - randomPosts(currentSessionUser_ptr->userName,POSTSATATIME); - QString domain = currentSessionUser_ptr->userName.mid(currentSessionUser_ptr->userName.length()-9,9); - if( domain!= "admin.com") - ui->StatisticsWindow_btn->setVisible(false); - viewPosts(); -} - - -void HomePage::viewPosts() -{ - unsigned int j,k; - static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; - qDebug("now"); - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) - { - QGroupBox *postframe = new QGroupBox; - QVBoxLayout *postLayout = new QVBoxLayout; - postframe->setLayout(postLayout); - postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); - QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); - postLayout->addWidget(postDate); - QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber - QFontMetrics font_metrics(postBody->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added - int height = font_height * 6; - postBody->setMinimumHeight(height); - postBody->setMaximumHeight(height); - postLayout->addWidget(postBody); - ParentVerticalLayout->addWidget(postframe); - QHBoxLayout *likeAndComment = new QHBoxLayout; - QPushButton *like = new QPushButton("Like"); - like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); - connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); - like->setStyleSheet("background-color: rgb(c0,c6,c8);"); - QPushButton *comment = new QPushButton("Comment",postframe); - comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); - connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); - comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); - likeAndComment->addWidget(like); - likeAndComment->addWidget(comment); - postLayout->addLayout(likeAndComment); - std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); - for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) - { - if(currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt]) - { - like->setEnabled(false); - break; - } - } - QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) - +" people are liking this!"); - likesOwners->setObjectName("likesOwnersButton"); - connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); - QHBoxLayout *likesOwnersLayout = new QHBoxLayout; - likesOwnersLayout->addWidget(likesOwners); - postLayout->addLayout(likesOwnersLayout); - for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) - { - QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); - commentBody->setMinimumHeight(height); - commentBody->setMaximumHeight(height); - commentLayout->addWidget(commentBody); - postLayout->addLayout(commentLayout); - } - QFrame* line = new QFrame(); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - ParentVerticalLayout->addWidget(line); - } - ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); - ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); - QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); - connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); -} -void HomePage::on_LikeButton_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - button->setEnabled(false); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); - int postsNumber,likesNumber; - currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); - currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); -} -void HomePage::on_CommentButton_clicked() -{ - QString commentBody; - QVBoxLayout *postLayout; - AddComment commentWindow; - commentWindow.setModal(true); - commentWindow.exec(); - commentBody = commentWindow.getCommentBody(); - qDebug(commentBody.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QHBoxLayout *commentLayout = new QHBoxLayout; - QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); - QLabel *commentOwner = new QLabel (commentOwnerName); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBodyTextBrowser = new QTextBrowser; - commentBodyTextBrowser->setText(commentBody); - QFontMetrics font_metrics(commentBodyTextBrowser->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? - int height = font_height * 2; - commentBodyTextBrowser->setMinimumHeight(height); - commentBodyTextBrowser->setMaximumHeight(height); - commentLayout->addWidget(commentBodyTextBrowser); - postLayout->addLayout(commentLayout); - /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - qDebug(labelString.toLatin1()); - currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) - ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); -} - - -void HomePage::on_likesOwners_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); - QScrollArea* likesOwners = new QScrollArea; - QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; - likesOwners->setLayout(scrollingAreaLayout); - for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) - { - if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) - { - std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); - for(int i = 0; i < likesVector->size(); i++) - { - QLabel* userLabel = new QLabel((*likesVector)[i]); - scrollingAreaLayout->addWidget(userLabel); - } - } - } - likesOwners->show(); -} - -void HomePage::viewMorePosts(int i) -{ - QScrollBar *bar = qobject_cast (QObject::sender()); - int max = bar ->maximum(); - if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) - { - viewPosts(); - } -} - - -HomePage::~HomePage() -{ - delete ui; -} - -void HomePage::on_pushButton_clicked() -{ - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - ProfilePage * profilePageWindow=new ProfilePage; - profilePageWindow->show(); - this->hide(); - profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); -} - -void HomePage::on_Post_btn_clicked() -{ - QString postText = ui->newPost_txtEdit->toPlainText(); - Date Now; - Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); - pagePosts->push_front(recentlyAddedPost); - shownPostsNumber = 0; - viewPosts(); - currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); - -} - -void HomePage::on_StatisticsWindow_btn_clicked() -{ - AdminWindow *adminWindow = new AdminWindow; - adminWindow->show();; - this->hide(); -} - - -void HomePage::swap(QString *a,QString *b) -{ - - QString temp=*a; - *a=*b; - *b=temp; -} - -void HomePage::siftUp(QList&myList,int index) //O(log(n) -{ - - int parentIndex= (index%2==0)?(index-2)/2 : (index-1)/2; - while( index!=0 && myList[parentIndex][0]&myList,int size) //O(log(n) -{ int index=0; - int leftChild= (2*index)+1; int rightChild=(2*index)+2; - while ((leftChild& myList) //O(n log(n)) -{ - - int size= myList.count(); - while(size>1) - { - swap(&myList[0],&myList[size-1]); - size--; - siftDown(myList,size); - - } - -} - - - -void HomePage::internalSearch (QString x,QList &myList,int begin,int end,QList &temp) -{ - - if(begin>end) {temp.append("\0");return ;} //not found - int middle= (begin+end)/2; bool indicator=false; - //qDebug()< x[0]) - { - - internalSearch ( x, myList,begin,middle-1,temp); - } - else - internalSearch ( x, myList,middle+1,end,temp); - - - -} - - -QList HomePage::search (QString x,QList & myList) -{ - for(int i=1;i temp; - internalSearch(x,myList,0,myList.count()-1,temp); - return temp; -} - - -void HomePage::on_friendSearch_textChanged(const QString &arg1) -{ - QString name= ui->friendSearch->text(); - if(name=="")return; - ui->comboBox->setVisible(true); - QList list= currentSessionUser->userFileManipulator.readEmails(); //yomna's list of mails - QListoptionsList=search(name,list); - ui->comboBox->addItem("Search Results"); - for(int i=0;icomboBox->addItem(optionsList[i]); - } - -} - -void HomePage::on_comboBox_currentIndexChanged(int index) -{ - QList items = ui->comboBox->children(); - if(index == -1) - return ; - QString mail = ui->comboBox->itemText(index); - if(mail == "Search Results") - return; - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - ProfilePage * profilePageWindow=new ProfilePage; - profilePageWindow->show(); - this->hide(); - profilePageWindow->setHomePageOwnerMail(currentSessionUser->userName); - currentSessionUser->userName = mail; - profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - -} - - -QList *HomePage::randomPosts(QString mail,int number) -{ - fileman A; - QList friendsMail=A.getFriends( mail); - friendsMail.push_front(currentSessionUser->userName); - friendsMail.push_front(currentSessionUser->userName); - friendsMail.push_front(currentSessionUser->userName); - for(int i=1;i *friendsPosts=currentSessionUser->userFileManipulator.getPosts_new(friendsMail[i]); - for(int j=0; jcount()) - pagePosts->push_back((*friendsPosts)[j]); - } - } -} - -void HomePage::on_actionLog_Out_triggered() -{ - qApp->quit(); - QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); -} From adbd51c0e55398bfabfd47c12b9558492c5c596c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:20:39 -0400 Subject: [PATCH 0429/1324] Delete homepage.h --- src/qt/homepage.h | 84 ----------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 src/qt/homepage.h diff --git a/src/qt/homepage.h b/src/qt/homepage.h deleted file mode 100644 index 5ad2cb24..00000000 --- a/src/qt/homepage.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef HOMEPAGE_H -#define HOMEPAGE_H - -#include -#include "profilepage.h" -#include "posts.h" -#include "user.h" -#include "QList" -#include "QVBoxLayout" -namespace Ui { -class HomePage; -} - -class HomePage : public QMainWindow -{ - Q_OBJECT - -public: - explicit HomePage(QWidget *parent = 0); - - void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); - - friend class ProfilePage; - - QList search(char x, QList &myList); - - ~HomePage(); - - -public Q_SLOTS: - QList search(QString x, QList& myList); - - void internalSearch(QString x, QList &myList, int begin, int end, QList &temp); - - void sort(QList &myList); - - void siftDown(QList &myList, int size); - - void siftUp(QList &myList, int index); - - void swap(QString *a, QString *b); - - QList *randomPosts(QString mail, int number); - - void on_likesOwners_clicked(); - - -private: - - Ui::HomePage *ui; - - user *currentSessionUser; - -private Q_SLOTS: - - void viewPosts(); - - void on_LikeButton_clicked(); - - void viewMorePosts(int i); - - void on_CommentButton_clicked(); - - void on_Post_btn_clicked(); - - void on_pushButton_clicked(); - - void on_StatisticsWindow_btn_clicked(); - - void on_friendSearch_textChanged(const QString &arg1); - - void on_comboBox_currentIndexChanged(int index); - - void on_actionLog_Out_triggered(); - - -private: - unsigned int shownPostsNumber; - - QList *pagePosts; - -}; - -#endif // HOMEPAGE_H From 55bd867f4d16f3a6060a5561188030d90da6f54e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:05 -0400 Subject: [PATCH 0430/1324] Delete main.cpp --- src/qt/main.cpp | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp deleted file mode 100644 index c72209ce..00000000 --- a/src/qt/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mainwindow.h" -#include -#include "homepage.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} From 19e8208aa96b665fe8e2410be714cd3b56fcb1e5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:13 -0400 Subject: [PATCH 0431/1324] Delete mainwindow.cpp --- src/qt/mainwindow.cpp | 66 ------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/qt/mainwindow.cpp diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp deleted file mode 100644 index 82f498e2..00000000 --- a/src/qt/mainwindow.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "newaccount.h" -#include -#include "homepage.h" -#include "QMessageBox" - -MainWindow::MainWindow(QWidget *parent) : -QMainWindow(parent), -ui(new Ui::MainWindow) -{ -ui->setupUi(this); -ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/chat")); -this->setWindowTitle("Social Network"); - -} - -MainWindow::MainWindow(int userID) : - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - id=userID; - qDebug()<< "id is "<show(); - this->hide(); - - -} - -void MainWindow::on_logInButton_clicked() -{ - QString email=ui->txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) - { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; - } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) - { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; - } - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); - -} From 4d22bfc726a24bf82df530851c7ca55a207d86c6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:20 -0400 Subject: [PATCH 0432/1324] Delete mainwindow.h --- src/qt/mainwindow.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/qt/mainwindow.h diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h deleted file mode 100644 index 5b17c669..00000000 --- a/src/qt/mainwindow.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - MainWindow(int userID ); - int id; - ~MainWindow(); - -private Q_SLOTS: - void on_signUpButton_clicked(); - - void on_logInButton_clicked(); - -private: - Ui::MainWindow *ui; -}; - -#endif // MAINWINDOW_H From 76e8f6a72dc61576c0758fe53123697d3d36e0cb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:29 -0400 Subject: [PATCH 0433/1324] Delete newaccount.cpp --- src/qt/newaccount.cpp | 57 ------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 src/qt/newaccount.cpp diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp deleted file mode 100644 index 5ec6d3ea..00000000 --- a/src/qt/newaccount.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "newaccount.h" -#include "ui_newaccount.h" -#include "QMessageBox" -#include -#include - -NewAccount::NewAccount(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::NewAccount) -{ - ui->setupUi(this); - user check; - id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/icons/chat")); - this->setWindowTitle("Social Network"); - -} - -NewAccount::~NewAccount() -{ - delete ui; -} - -void NewAccount::on_pushButton_clicked() -{ - QString password =ui->lineEdit_2->text(); - QString confirm =ui->lineEdit_3->text(); - QString mail=ui->txtUserMail->text(); - if(password!=confirm) - { - QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); - } - else - { - user temp (password,mail,ui->txtUserName->text(),id); - temp.setUsersList(temp); - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - this->hide(); -// temp.userFileManipulator.updateActivity(mail,0,0); - } - -} - -void NewAccount::setLoginPtr(MainWindow *ptr) -{ - this->mainWindowPtr = ptr; -} - -void NewAccount::on_pushButton_2_clicked() -{ - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - // mainWindowPtr->show(); - this->hide(); - -} From cffd0699adb5c7183842d2ffa2f1fd35035e0320 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:38 -0400 Subject: [PATCH 0434/1324] Delete newaccount.h --- src/qt/newaccount.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/qt/newaccount.h diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h deleted file mode 100644 index cb6d5309..00000000 --- a/src/qt/newaccount.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef NEWACCOUNT_H -#define NEWACCOUNT_H - -#include -#include "mainwindow.h" -namespace Ui { -class NewAccount; -} - -class NewAccount : public QMainWindow -{ - Q_OBJECT - -public: - explicit NewAccount(QWidget *parent = 0); - ~NewAccount(); - int id; - - -public Q_SLOTS: - void setLoginPtr(MainWindow *ptr); - - -private Q_SLOTS: - void on_pushButton_clicked(); - - void on_pushButton_2_clicked(); - - -private: - Ui::NewAccount *ui; - - MainWindow *mainWindowPtr; -}; - -#endif // NEWACCOUNT_H From 7ff3752ac65c28732b2f86eb2a2dab0c1628c520 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:21:50 -0400 Subject: [PATCH 0435/1324] Delete posts.cpp --- src/qt/posts.cpp | 112 ----------------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 src/qt/posts.cpp diff --git a/src/qt/posts.cpp b/src/qt/posts.cpp deleted file mode 100644 index ef082536..00000000 --- a/src/qt/posts.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "posts.h" - -Post::Post() -{ - postOwner = ""; - postText = ""; -} - -Post::Post(QString owner, QString text, QString creationDate) -{ - postOwner = owner; - postText = text; - postDate = creationDate; - postLikesNumber = 0; -} - -void Post::setPostOwner(QString owner) -{ - postOwner = owner; -} - -QString Post::getPostOwner() -{ - return postOwner; -} - -void Post::setPostText(QString text) -{ - postText = text; -} - -QString Post::getPostText() -{ - return postText; -} - -void Post::addPostLike(QString likeOwner) -{ - postLikesNumber++; - postLikesOwners.push_back(likeOwner); -} - -void Post::removePostLike(QString owner) -{ - std::vector::iterator iterator; - for(iterator = postLikesOwners.begin(); iterator != postLikesOwners.end(); iterator++) - { - if(*iterator == owner) - { - postLikesOwners.erase(iterator); - break; - } - } -} - -unsigned int Post::getPostLikesNumber() -{ - return postLikesNumber; -} - -std::vector *Post::getPostLikesOwnersVectorPtr() -{ - return &postLikesOwners; -} - -void Post::addComment(Comment newComment) -{ - postComments.push_back(newComment); -} - -void Post::deleteComment(Comment toBeDeleted) -{ - std::vector::iterator iterator; - for(iterator = postComments.begin(); iterator != postComments.end(); iterator++) - { - if((*iterator).getCommentText() == toBeDeleted.getCommentText()) - { - postComments.erase(iterator); - break; - } - } -} - -std::vector *Post::getPostCommentsVectorPtr() -{ - return &postComments; -} - -void Post::setPostDate(QString creationDate) -{ - postDate = creationDate; -} - -QString Post::getPostDate() -{ - return postDate; -} - - - - - - - - - - - - - - - From e167f77905454dabddf188f3bc70f72eb8ad4510 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:01 -0400 Subject: [PATCH 0436/1324] Delete posts.h --- src/qt/posts.h | 179 ------------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 src/qt/posts.h diff --git a/src/qt/posts.h b/src/qt/posts.h deleted file mode 100644 index 094b3c17..00000000 --- a/src/qt/posts.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef POSTS_H -#define POSTS_H -#include "comment.h" -#include -#include -class Post -{ - QString postOwner; - QString postText; - unsigned int postLikesNumber; - std::vector postLikesOwners; - std::vector postComments; - QString postDate; -public: - - /** - * @brief - * - * @param - * - * @return - */ - Post(); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - Post(QString,QString,QString); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - void setPostOwner(QString); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - QString getPostOwner(); - - /** - * @brief - * - * @ - * - * @param - * - * @return - */ - void setPostText(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - QString getPostText(); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void addPostLike(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void removePostLike(QString); - - /** - * @brief - * - * @example <35 likes or so. Maybe used to view the post likes number in a label or something.> - * - * @param - * - * @return - */ - unsigned int getPostLikesNumber(); - - /** - * @brief - * - * @example - * - * @param - * - * @return * postLikesOwners> - */ - std::vector* getPostLikesOwnersVectorPtr(); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void addComment(Comment); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void deleteComment(Comment); - - /** - * @brief - * - * @example - * - * @param - * - * @return * commentsVector> - */ - std::vector* getPostCommentsVectorPtr(); - - /** - * @brief - * - * @example: - * - * @param - * - * @return - */ - void setPostDate(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - QString getPostDate(); -}; -#endif // POSTS_H From bd4d721d9aa64440700cca1d22e05f4fcd3ba42a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:11 -0400 Subject: [PATCH 0437/1324] Delete profilepage.cpp --- src/qt/profilepage.cpp | 314 ----------------------------------------- 1 file changed, 314 deletions(-) delete mode 100644 src/qt/profilepage.cpp diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp deleted file mode 100644 index d69568bb..00000000 --- a/src/qt/profilepage.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "profilepage.h" -#include "ui_profilepage.h" -#include "homepage.h" - -//selim includes -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "QHBoxLayout" -#include -#include "QLabel" -#include "QSpacerItem" -#include "QPushButton" -#include -#include "posts.h" -#include -#include -#include "QFontMetrics" -#include "QGroupBox" -#include "QScrollBar" -#include "mainwindow.h" -#include "addcomment.h" -#define POSTSNUMBER 100 -#define COMMENTSNUMBER 3 -#define POSTSATATIME 15 -//_____ - -#include "qprocess.h" - -ProfilePage::ProfilePage(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::ProfilePage) -{ - ui->setupUi(this); - shownPostsNumber = 0; - //pagePosts = makePosts(); - // viewPosts(); - QWidget::setWindowIcon(QIcon(":/icons/chat")); - this->showMaximized(); - this->setWindowTitle("Social Network"); -} - - ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) - { - - ui->setupUi(this); - user A; - // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( - ui->lblMail->setText(email);//user file's name is the email of the user - shownPostsNumber = 0; - qDebug()<<"id is "<userName = homePageOwnerMail; - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); -} - - -void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) -{ - this->currentSessionUser = currentSessionUser_ptr; - pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); - viewPosts(); - if(homePageOwnerMail != "") - { - fileman x; - QList friendsList = x.getFriends(homePageOwnerMail); - for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) - { - if(*it == currentSessionUser_ptr->userName) - { - ui->addFriendBtn->setEnabled(false); - break; - } - } - } -} - -//Selim functions -void ProfilePage::viewPosts() -{ - ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); - ui->lblMail->setText(currentSessionUser->userName); - ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); - QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); - if(homePageOwnerMail == "") - ui->addFriendBtn->setEnabled(false); - int j,k; - for(j = 1; j < friendsList.size() - 1; j = j + 3) - { - ui->friendsComboBox->addItem(friendsList[j]); - } - static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; - qDebug("now"); - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) - { - QGroupBox *postframe = new QGroupBox; - //postframe->setObjectName("frame"+QString::number(k)); - QVBoxLayout *postLayout = new QVBoxLayout; - postframe->setLayout(postLayout); - postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); - QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); - postLayout->addWidget(postDate); - QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber - QFontMetrics font_metrics(postBody->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added - int height = font_height * 6; - postBody->setMinimumHeight(height); - postBody->setMaximumHeight(height); - postLayout->addWidget(postBody); - ParentVerticalLayout->addWidget(postframe); - QHBoxLayout *likeAndComment = new QHBoxLayout; - QPushButton *like = new QPushButton("Like"); - like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); - connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); - like->setStyleSheet("background-color: rgb(c0,c6,c8);"); - QPushButton *comment = new QPushButton("Comment",postframe); - comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); - connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); - comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); - likeAndComment->addWidget(like); - likeAndComment->addWidget(comment); - postLayout->addLayout(likeAndComment); - std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); - for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) - { - if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) - { - like->setEnabled(false); - break; - } - } - QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) - +" people are liking this!"); - likesOwners->setObjectName("likesOwnersButton"); - connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); - QHBoxLayout *likesOwnersLayout = new QHBoxLayout; - likesOwnersLayout->addWidget(likesOwners); - postLayout->addLayout(likesOwnersLayout); - for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) - { - QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); - commentBody->setMinimumHeight(height); - commentBody->setMaximumHeight(height); - commentLayout->addWidget(commentBody); - postLayout->addLayout(commentLayout); - } - QFrame* line = new QFrame(); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - ParentVerticalLayout->addWidget(line); - } - ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); - ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); - //connect(ui->PostsArea,SIGNAL(ui->PostsArea->scroll(50,50)),this,SLOT(close())); - QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); - connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); -} -void ProfilePage::on_LikeButton_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - button->setEnabled(false); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - if(homePageOwnerMail == "") - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); - else - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); - int postsNumber,likesNumber; - currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); - currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); - -} -void ProfilePage::on_CommentButton_clicked() -{ - QString commentBody; - QVBoxLayout *postLayout; - AddComment commentWindow; - commentWindow.setModal(true); - commentWindow.exec(); - commentBody = commentWindow.getCommentBody(); - qDebug(commentBody.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QHBoxLayout *commentLayout = new QHBoxLayout; - QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); - QLabel *commentOwner = new QLabel (commentOwnerName); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBodyTextBrowser = new QTextBrowser; - commentBodyTextBrowser->setText(commentBody); - QFontMetrics font_metrics(commentBodyTextBrowser->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? - int height = font_height * 2; - commentBodyTextBrowser->setMinimumHeight(height); - commentBodyTextBrowser->setMaximumHeight(height); - commentLayout->addWidget(commentBodyTextBrowser); - postLayout->addLayout(commentLayout); - /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - qDebug(labelString.toLatin1()); - currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) - ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); -} - -void ProfilePage::on_likesOwners_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); - QScrollArea* likesOwners = new QScrollArea; - QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; - likesOwners->setLayout(scrollingAreaLayout); - for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) - { - if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) - { - std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); - for(int i = 0; i < likesVector->size(); i++) - { - QLabel* userLabel = new QLabel((*likesVector)[i]); - scrollingAreaLayout->addWidget(userLabel); - } - } - } - likesOwners->show(); -} - -void ProfilePage::viewMorePosts(int i) -{ - QScrollBar *bar = qobject_cast (QObject::sender()); - int max = bar ->maximum(); - if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) - { - viewPosts(); - } -} - - - -void ProfilePage::on_Post_btn_clicked() -{ - QString postText = ui->newPost_txtEdit->toPlainText(); -// currentSessionUser.userFileManipulator.addPost(postText); - Date Now; - Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); - pagePosts->push_front(recentlyAddedPost); - shownPostsNumber = 0; - // clear the post area - //ui->PostsArea-> - viewPosts(); - currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); -} - -void ProfilePage::setHomePageOwnerMail(QString owner) -{ - homePageOwnerMail = owner; - ui->newPost_txtEdit->setVisible(false); - ui->Post_btn->setVisible(false); -} - - -void ProfilePage::on_addFriendBtn_clicked() -{ - currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); - ui->addFriendBtn->setEnabled(false); -} - -void ProfilePage::on_actionLog_out_triggered() -{ - qApp->quit(); - QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); -} From 7a38a71169d28792371173278cf105b4a7ba985b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:21 -0400 Subject: [PATCH 0438/1324] Delete profilepage.h --- src/qt/profilepage.h | 61 -------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 src/qt/profilepage.h diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h deleted file mode 100644 index bfa29da9..00000000 --- a/src/qt/profilepage.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef PROFILEPAGE_H -#define PROFILEPAGE_H - -#include -#include "posts.h" -#include "user.h" -#include "homepage.h" -namespace Ui { -class ProfilePage; -} - -class ProfilePage : public QMainWindow -{ - Q_OBJECT - -public: - explicit ProfilePage(QWidget *parent = 0); - - ~ProfilePage(); - - ProfilePage(int userID,QString userFile); - -private Q_SLOTS: - void on_pushButton_2_clicked(); - - void viewPosts(); - - void on_LikeButton_clicked(); - - void viewMorePosts(int i); - - void on_CommentButton_clicked(); - - void on_addFriendBtn_clicked(); - - void on_actionLog_out_triggered(); - - -public Q_SLOTS: - void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); - - void on_Post_btn_clicked(); - - void setHomePageOwnerMail(QString owner); - - void on_likesOwners_clicked(); - - -private: - Ui::ProfilePage *ui; - - unsigned int shownPostsNumber; - - QList *pagePosts; - - user *currentSessionUser; - - QString homePageOwnerMail; -}; - -#endif // PROFILEPAGE_H From 392c2ef9449002a1fc42d4faa5359e7da19f07df Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:31 -0400 Subject: [PATCH 0439/1324] Delete qcustomplot.cpp --- src/qt/qcustomplot.cpp | 30121 --------------------------------------- 1 file changed, 30121 deletions(-) delete mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp deleted file mode 100644 index e59374ab..00000000 --- a/src/qt/qcustomplot.cpp +++ /dev/null @@ -1,30121 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#include "qcustomplot.h" - - -/* including file 'src/vector2d.cpp', size 7340 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPVector2D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPVector2D - \brief Represents two doubles as a mathematical 2D vector - - This class acts as a replacement for QVector2D with the advantage of double precision instead of - single, and some convenience methods tailored for the QCustomPlot library. -*/ - -/* start documentation of inline functions */ - -/*! \fn void QCPVector2D::setX(double x) - - Sets the x coordinate of this vector to \a x. - - \see setY -*/ - -/*! \fn void QCPVector2D::setY(double y) - - Sets the y coordinate of this vector to \a y. - - \see setX -*/ - -/*! \fn double QCPVector2D::length() const - - Returns the length of this vector. - - \see lengthSquared -*/ - -/*! \fn double QCPVector2D::lengthSquared() const - - Returns the squared length of this vector. In some situations, e.g. when just trying to find the - shortest vector of a group, this is faster than calculating \ref length, because it avoids - calculation of a square root. - - \see length -*/ - -/*! \fn QPoint QCPVector2D::toPoint() const - - Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point - information. - - \see toPointF -*/ - -/*! \fn QPointF QCPVector2D::toPointF() const - - Returns a QPointF which has the x and y coordinates of this vector. - - \see toPoint -*/ - -/*! \fn bool QCPVector2D::isNull() const - - Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y - coordinates, i.e. if both are binary equal to 0. -*/ - -/*! \fn QCPVector2D QCPVector2D::perpendicular() const - - Returns a vector perpendicular to this vector, with the same length. -*/ - -/*! \fn double QCPVector2D::dot() const - - Returns the dot/scalar product of this vector with the specified vector \a vec. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates to 0. -*/ -QCPVector2D::QCPVector2D() : - mX(0), - mY(0) -{ -} - -/*! - Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified - values. -*/ -QCPVector2D::QCPVector2D(double x, double y) : - mX(x), - mY(y) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPoint &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPointF &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Normalizes this vector. After this operation, the length of the vector is equal to 1. - - \see normalized, length, lengthSquared -*/ -void QCPVector2D::normalize() -{ - double len = length(); - mX /= len; - mY /= len; -} - -/*! - Returns a normalized version of this vector. The length of the returned vector is equal to 1. - - \see normalize, length, lengthSquared -*/ -QCPVector2D QCPVector2D::normalized() const -{ - QCPVector2D result(mX, mY); - result.normalize(); - return result; -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a start and \a end. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const -{ - QCPVector2D v(end-start); - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = v.dot(*this-start)/vLengthSqr; - if (mu < 0) - return (*this-start).lengthSquared(); - else if (mu > 1) - return (*this-end).lengthSquared(); - else - return ((start + mu*v)-*this).lengthSquared(); - } else - return (*this-start).lengthSquared(); -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a line. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QLineF &line) const -{ - return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); -} - -/*! - Returns the shortest distance of this vector (interpreted as a point) to the infinite straight - line given by a \a base point and a \a direction vector. - - \see distanceSquaredToLine -*/ -double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const -{ - return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); -} - -/*! - Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a - factor. -*/ -QCPVector2D &QCPVector2D::operator*=(double factor) -{ - mX *= factor; - mY *= factor; - return *this; -} - -/*! - Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a - divisor. -*/ -QCPVector2D &QCPVector2D::operator/=(double divisor) -{ - mX /= divisor; - mY /= divisor; - return *this; -} - -/*! - Adds the given \a vector to this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) -{ - mX += vector.mX; - mY += vector.mY; - return *this; -} - -/*! - subtracts the given \a vector from this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) -{ - mX -= vector.mX; - mY -= vector.mY; - return *this; -} -/* end of 'src/vector2d.cpp' */ - - -/* including file 'src/painter.cpp', size 8670 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPainter -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPainter - \brief QPainter subclass used internally - - This QPainter subclass is used to provide some extended functionality e.g. for tweaking position - consistency between antialiased and non-antialiased painting. Further it provides workarounds - for QPainter quirks. - - \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and - restore. So while it is possible to pass a QCPPainter instance to a function that expects a - QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because - it will call the base class implementations of the functions actually hidden by QCPPainter). -*/ - -/*! - Creates a new QCPPainter instance and sets default values -*/ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) -{ - // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and - // a call to begin() will follow -} - -/*! - Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just - like the analogous QPainter constructor, begins painting on \a device immediately. - - Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. -*/ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif -} - -/*! - Sets the pen of the painter and applies certain fixes to it, depending on the mode of this - QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QPen &pen) -{ - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QColor &color) -{ - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(Qt::PenStyle penStyle) -{ - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when - antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to - integer coordinates and then passes it to the original drawLine. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::drawLine(const QLineF &line) -{ - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); - else - QPainter::drawLine(line.toLine()); -} - -/*! - Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint - with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between - antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for - AA/Non-AA painting). -*/ -void QCPPainter::setAntialiasing(bool enabled) -{ - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) - { - mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs - { - if (mIsAntialiasing) - translate(0.5, 0.5); - else - translate(-0.5, -0.5); - } - } -} - -/*! - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setModes(QCPPainter::PainterModes modes) -{ - mModes = modes; -} - -/*! - Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a - device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, - all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that - behaviour. - - The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets - the render hint as appropriate. - - \note this function hides the non-virtual base class implementation. -*/ -bool QCPPainter::begin(QPaintDevice *device) -{ - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif - return result; -} - -/*! \overload - - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) -{ - if (!enabled && mModes.testFlag(mode)) - mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) - mModes |= mode; -} - -/*! - Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see restore -*/ -void QCPPainter::save() -{ - mAntialiasingStack.push(mIsAntialiasing); - QPainter::save(); -} - -/*! - Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see save -*/ -void QCPPainter::restore() -{ - if (!mAntialiasingStack.isEmpty()) - mIsAntialiasing = mAntialiasingStack.pop(); - else - qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; - QPainter::restore(); -} - -/*! - Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen - overrides when the \ref pmNonCosmetic mode is set. -*/ -void QCPPainter::makeNonCosmetic() -{ - if (qFuzzyIsNull(pen().widthF())) - { - QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); - } -} -/* end of 'src/painter.cpp' */ - - -/* including file 'src/paintbuffer.cpp', size 18502 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPaintBuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPaintBuffer - \brief The abstract base class for paint buffers, which define the rendering backend - - This abstract base class defines the basic interface that a paint buffer needs to provide in - order to be usable by QCustomPlot. - - A paint buffer manages both a surface to draw onto, and the matching paint device. The size of - the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref - QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the - painting is complete, \ref donePainting is called, so the paint buffer implementation can do - clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color - using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the - previous frame. - - The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular - software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and - frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. - They are used automatically if \ref QCustomPlot::setOpenGl is enabled. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 - - Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the - responsibility to delete the painter after the painting operations are complete is given to the - caller of this method. - - Once you are done using the painter, delete the painter and call \ref donePainting. - - While a painter generated with this method is active, you must not call \ref setSize, \ref - setDevicePixelRatio or \ref clear. - - This method may return 0, if a painter couldn't be activated on the buffer. This usually - indicates a problem with the respective painting backend. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 - - Draws the contents of this buffer with the provided \a painter. This is the method that is used - to finally join all paint buffers and draw them onto the screen. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 - - Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the - named color \c Qt::transparent. - - This method must not be called if there is currently a painter (acquired with \ref startPainting) - active. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 - - Reallocates the internal buffer with the currently configured size (\ref setSize) and device - pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those - properties are changed on this paint buffer. - - \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method - in their constructor, to perform the first allocation (this can not be done by the base class - because calling pure virtual methods in base class constructors is not possible). -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of inline functions */ - -/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() - - If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, - call this method as soon as you are done with the painting operations and have deleted the - painter. - - paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The - default implementation does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. - - Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. -*/ -QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : - mSize(size), - mDevicePixelRatio(devicePixelRatio), - mInvalidated(true) -{ -} - -QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() -{ -} - -/*! - Sets the paint buffer size. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - If \a size is already the current buffer size, this method does nothing. -*/ -void QCPAbstractPaintBuffer::setSize(const QSize &size) -{ - if (mSize != size) - { - mSize = size; - reallocateBuffer(); - } -} - -/*! - Sets the invalidated flag to \a invalidated. - - This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer - instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered - layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, - QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also - replots them, instead of only the layer on which the replot was called. - - The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers - were added or removed from this buffer, or if they were reordered. It is set to false as soon as - all associated \ref QCPLayer instances are drawn onto the buffer. - - Under normal circumstances, it is not necessary to manually call this method. -*/ -void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) -{ - mInvalidated = invalidated; -} - -/*! - Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. - The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - \note This method is only available for Qt versions 5.4 and higher. -*/ -void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mDevicePixelRatio = ratio; - reallocateBuffer(); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; -#endif - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferPixmap - \brief A paint buffer based on QPixmap, using software raster rendering - - This paint buffer is the default and fall-back paint buffer which uses software rendering and - QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. -*/ - -/*! - Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if - applicable. -*/ -QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : - QCPAbstractPaintBuffer(size, devicePixelRatio) -{ - QCPPaintBufferPixmap::reallocateBuffer(); -} - -QCPPaintBufferPixmap::~QCPPaintBufferPixmap() -{ -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferPixmap::startPainting() -{ - QCPPainter *result = new QCPPainter(&mBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::draw(QCPPainter *painter) const -{ - if (painter && painter->isActive()) - painter->drawPixmap(0, 0, mBuffer); - else - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::clear(const QColor &color) -{ - mBuffer.fill(color); -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::reallocateBuffer() -{ - setInvalidated(); - if (!qFuzzyCompare(1.0, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBuffer = QPixmap(mSize*mDevicePixelRatio); - mBuffer.setDevicePixelRatio(mDevicePixelRatio); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; - mBuffer = QPixmap(mSize); -#endif - } else - { - mBuffer = QPixmap(mSize); - } -} - - -#ifdef QCP_OPENGL_PBUFFER -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlPbuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlPbuffer - \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. - (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a - devicePixelRatio, if applicable. - - The parameter \a multisamples defines how many samples are used per pixel. Higher values thus - result in higher quality antialiasing. If the specified \a multisamples value exceeds the - capability of the graphics hardware, the highest supported multisampling is used. -*/ -QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlPBuffer(0), - mMultisamples(qMax(0, multisamples)) -{ - QCPPaintBufferGlPbuffer::reallocateBuffer(); -} - -QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlPbuffer::startPainting() -{ - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - QCPPainter *result = new QCPPainter(mGlPBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlPBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::clear(const QColor &color) -{ - if (mGlPBuffer->isValid()) - { - mGlPBuffer->makeCurrent(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlPBuffer->doneCurrent(); - } else - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::reallocateBuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; - - QGLFormat format; - format.setAlpha(true); - format.setSamples(mMultisamples); - mGlPBuffer = new QGLPixelBuffer(mSize, format); -} -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlFbo -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlFbo - \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and - higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, - if applicable. - - All frame buffer objects shall share one OpenGL context and paint device, which need to be set up - externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref - QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot - instance. -*/ -QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlContext(glContext), - mGlPaintDevice(glPaintDevice), - mGlFrameBuffer(0) -{ - QCPPaintBufferGlFbo::reallocateBuffer(); -} - -QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() -{ - if (mGlFrameBuffer) - delete mGlFrameBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlFbo::startPainting() -{ - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return 0; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::donePainting() -{ - if (mGlFrameBuffer && mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - else - qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlFrameBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::clear(const QColor &color) -{ - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlFrameBuffer->release(); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::reallocateBuffer() -{ - // release and delete possibly existing framebuffer: - if (mGlFrameBuffer) - { - if (mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - delete mGlFrameBuffer; - mGlFrameBuffer = 0; - } - - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return; - } - - // create new fbo with appropriate size: - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples(mGlContext.data()->format().samples()); - frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); - if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) - mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); -#endif -} -#endif // QCP_OPENGL_FBO -/* end of 'src/paintbuffer.cpp' */ - - -/* including file 'src/layer.cpp', size 37064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayer - \brief A layer that may contain objects, to control the rendering order - - The Layering system of QCustomPlot is the mechanism to control the rendering order of the - elements inside the plot. - - It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of - one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, - QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers - bottom to top and successively draws the layerables of the layers into the paint buffer(s). - - A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base - class from which almost all visible objects derive, like axes, grids, graphs, items, etc. - - \section qcplayer-defaultlayers Default layers - - Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and - "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's - selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain - the default axes and legend, so they will be drawn above plottables. In the middle, there is the - "main" layer. It is initially empty and set as the current layer (see - QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this - layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong - tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind - everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of - course, the layer affiliation of the individual objects can be changed as required (\ref - QCPLayerable::setLayer). - - \section qcplayer-ordering Controlling the rendering order via layers - - Controlling the ordering of layerables in the plot is easy: Create a new layer in the position - you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the - current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the - objects normally. They will be placed on the new layer automatically, due to the current layer - setting. Alternatively you could have also ignored the current layer setting and just moved the - objects with \ref QCPLayerable::setLayer to the desired layer after creating them. - - It is also possible to move whole layers. For example, If you want the grid to be shown in front - of all plottables/items on the "main" layer, just move it above "main" with - QCustomPlot::moveLayer. - - The rendering order within one layer is simply by order of creation or insertion. The item - created last (or added last to the layer), is drawn on top of all other objects on that layer. - - When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below - the deleted layer, see QCustomPlot::removeLayer. - - \section qcplayer-buffering Replotting only a specific layer - - If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific - layer by calling \ref replot. In certain situations this can provide better replot performance, - compared with a full replot of all layers. Upon creation of a new layer, the layer mode is - initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref - QCustomPlot instance is the "overlay" layer, containing the selection rect. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPLayer::children() const - - Returns a list of all layerables on this layer. The order corresponds to the rendering order: - layerables with higher indices are drawn above layerables with lower indices. -*/ - -/*! \fn int QCPLayer::index() const - - Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be - accessed via \ref QCustomPlot::layer. - - Layers with higher indices will be drawn above layers with lower indices. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPLayer instance. - - Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. - - \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. - This check is only performed by \ref QCustomPlot::addLayer. -*/ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true), - mMode(lmLogical) -{ - // Note: no need to make sure layerName is unique, because layer - // management is done with QCustomPlot functions. -} - -QCPLayer::~QCPLayer() -{ - // If child layerables are still on this layer, detach them, so they don't try to reach back to this - // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted - // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to - // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) - qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; -} - -/*! - Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this - layer will be invisible. - - This function doesn't change the visibility property of the layerables (\ref - QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the - visibility of the parent layer into account. -*/ -void QCPLayer::setVisible(bool visible) -{ - mVisible = visible; -} - -/*! - Sets the rendering mode of this layer. - - If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by - the parent QCustomPlot instance. This means it may be replotted individually by calling \ref - QCPLayer::replot, without needing to replot all other layers. - - Layers which are set to \ref lmLogical (the default) are used only to define the rendering order - and can't be replotted individually. - - Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the - layers below, above and for the layer itself. This increases the memory consumption and - (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So - you should carefully choose which layers benefit from having their own paint buffer. A typical - example would be a layer which contains certain layerables (e.g. items) that need to be changed - and thus replotted regularly, while all other layerables on other layers stay static. By default, - only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection - rect. - - \see replot -*/ -void QCPLayer::setMode(QCPLayer::LayerMode mode) -{ - if (mMode != mode) - { - mMode = mode; - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } -} - -/*! \internal - - Draws the contents of this layer with the provided \a painter. - - \see replot, drawToPaintBuffer -*/ -void QCPLayer::draw(QCPPainter *painter) -{ - Q_FOREACH (QCPLayerable *child, mChildren) - { - if (child->realVisibility()) - { - painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); - painter->restore(); - } - } -} - -/*! \internal - - Draws the contents of this layer into the paint buffer which is associated with this layer. The - association is established by the parent QCustomPlot, which manages all paint buffers (see \ref - QCustomPlot::setupPaintBuffers). - - \see draw -*/ -void QCPLayer::drawToPaintBuffer() -{ - if (!mPaintBuffer.isNull()) - { - if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) - { - if (painter->isActive()) - draw(painter); - else - qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; - delete painter; - mPaintBuffer.data()->donePainting(); - } else - qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; -} - -/*! - If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only - the layerables on this specific layer, without the need to replot all other layers (as a call to - \ref QCustomPlot::replot would do). - - If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on - the parent QCustomPlot instance. - - QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering - has changed since the last full replot and the other paint buffers were thus invalidated. - - \see draw -*/ -void QCPLayer::replot() -{ - if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) - { - if (!mPaintBuffer.isNull()) - { - mPaintBuffer.data()->clear(Qt::transparent); - drawToPaintBuffer(); - mPaintBuffer.data()->setInvalidated(false); - mParentPlot->update(); - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } else if (mMode == lmLogical) - mParentPlot->replot(); -} - -/*! \internal - - Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will - be prepended to the list, i.e. be drawn beneath the other layerables already in the list. - - This function does not change the \a mLayer member of \a layerable to this layer. (Use - QCPLayerable::setLayer to change the layer of an object, not this function.) - - \see removeChild -*/ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) -{ - if (!mChildren.contains(layerable)) - { - if (prepend) - mChildren.prepend(layerable); - else - mChildren.append(layerable); - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); -} - -/*! \internal - - Removes the \a layerable from the list of this layer. - - This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer - to change the layer of an object, not this function.) - - \see addChild -*/ -void QCPLayer::removeChild(QCPLayerable *layerable) -{ - if (mChildren.removeOne(layerable)) - { - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayerable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayerable - \brief Base class for all drawable objects - - This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid - etc. - - Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking - the layers accordingly. - - For details about the layering mechanism, see the QCPLayer documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const - - Returns the parent layerable of this layerable. The parent layerable is used to provide - visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables - only get drawn if their parent layerables are visible, too. - - Note that a parent layerable is not necessarily also the QObject parent for memory management. - Further, a layerable doesn't always have a parent layerable, so this function may return 0. - - A parent layerable is set implicitly when placed inside layout elements and doesn't need to be - set manually by the user. -*/ - -/* end documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 - \internal - - This function applies the default antialiasing setting to the specified \a painter, using the - function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when - \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing - setting may be specified individually, this function should set the antialiasing state of the - most prominent entity. In this case however, the \ref draw function usually calls the specialized - versions of this function before drawing each entity, effectively overriding the setting of the - default antialiasing hint. - - First example: QCPGraph has multiple entities that have an antialiasing setting: The graph - line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, - QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only - the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's - antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and - QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw - calls the respective specialized applyAntialiasingHint function. - - Second example: QCPItemLine consists only of a line so there is only one antialiasing - setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by - all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the - respective layerable subclass.) Consequently it only has the normal - QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to - care about setting any antialiasing states, because the default antialiasing hint is already set - on the painter when the \ref draw function is called, and that's the state it wants to draw the - line with. -*/ - -/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 - \internal - - This function draws the layerable with the specified \a painter. It is only called by - QCustomPlot, if the layerable is visible (\ref setVisible). - - Before this function is called, the painter's antialiasing state is set via \ref - applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was - set to \ref clipRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); - - This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to - a different layer. - - \see setLayer -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPLayerable instance. - - Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the - derived classes. - - If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a - targetLayer is an empty string, it places itself on the current layer of the plot (see \ref - QCustomPlot::setCurrentLayer). - - It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later - time with \ref initializeParentPlot. - - The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable - parents are mainly used to control visibility in a hierarchy of layerables. This means a - layerable is only drawn, if all its ancestor layerables are also visible. Note that \a - parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a - plot does. It is not uncommon to set the QObject-parent to something else in the constructors of - QCPLayerable subclasses, to guarantee a working destruction hierarchy. -*/ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) -{ - if (mParentPlot) - { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) - qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; - } -} - -QCPLayerable::~QCPLayerable() -{ - if (mLayer) - { - mLayer->removeChild(this); - mLayer = 0; - } -} - -/*! - Sets the visibility of this layerable object. If an object is not visible, it will not be drawn - on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not - possible. -*/ -void QCPLayerable::setVisible(bool on) -{ - mVisible = on; -} - -/*! - Sets the \a layer of this layerable object. The object will be placed on top of the other objects - already on \a layer. - - If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or - interact/receive events). - - Returns true if the layer of this layerable was successfully changed to \a layer. -*/ -bool QCPLayerable::setLayer(QCPLayer *layer) -{ - return moveToLayer(layer, false); -} - -/*! \overload - Sets the layer of this layerable object by name - - Returns true on success, i.e. if \a layerName is a valid layer name. -*/ -bool QCPLayerable::setLayer(const QString &layerName) -{ - if (!mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (QCPLayer *layer = mParentPlot->layer(layerName)) - { - return setLayer(layer); - } else - { - qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; - return false; - } -} - -/*! - Sets whether this object will be drawn antialiased or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPLayerable::setAntialiased(bool enabled) -{ - mAntialiased = enabled; -} - -/*! - Returns whether this layerable is visible, taking the visibility of the layerable parent and the - visibility of this layerable's layer into account. This is the method that is consulted to decide - whether a layerable shall be drawn or not. - - If this layerable has a direct layerable parent (usually set via hierarchies implemented in - subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this - layerable has its visibility set to true and the parent layerable's \ref realVisibility returns - true. -*/ -bool QCPLayerable::realVisibility() const -{ - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); -} - -/*! - This function is used to decide whether a click hits a layerable object or not. - - \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the - shortest pixel distance of this point to the object. If the object is either invisible or the - distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the - object is not selectable, -1.0 is returned, too. - - If the object is represented not by single lines but by an area like a \ref QCPItemText or the - bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In - these cases this function thus returns a constant value greater zero but still below the parent - plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). - - Providing a constant value for area objects allows selecting line objects even when they are - obscured by such area objects, by clicking close to the lines (i.e. closer than - 0.99*selectionTolerance). - - The actual setting of the selection state is not done by this function. This is handled by the - parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified - via the \ref selectEvent/\ref deselectEvent methods. - - \a details is an optional output parameter. Every layerable subclass may place any information - in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot - decides on the basis of this selectTest call, that the object was successfully selected. The - subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part - objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked - is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be - placed in \a details. So in the subsequent \ref selectEvent, the decision which part was - selected doesn't have to be done a second time for a single selection operation. - - You may pass 0 as \a details to indicate that you are not interested in those selection details. - - \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions -*/ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) - return -1.0; -} - -/*! \internal - - Sets the parent plot of this layerable. Use this function once to set the parent plot if you have - passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to - another one. - - Note that, unlike when passing a non-null parent plot in the constructor, this function does not - make \a parentPlot the QObject-parent of this layerable. If you want this, call - QObject::setParent(\a parentPlot) in addition to this function. - - Further, you will probably want to set a layer (\ref setLayer) after calling this function, to - make the layerable appear on the QCustomPlot. - - The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized - so they can react accordingly (e.g. also initialize the parent plot of child layerables, like - QCPLayout does). -*/ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) -{ - if (mParentPlot) - { - qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; - return; - } - - if (!parentPlot) - qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - - mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); -} - -/*! \internal - - Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not - become the QObject-parent (for memory management) of this layerable. - - The parent layerable has influence on the return value of the \ref realVisibility method. Only - layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be - drawn. - - \see realVisibility -*/ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) -{ - mParentLayerable = parentLayerable; -} - -/*! \internal - - Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to - the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is - false, the object will be appended. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) -{ - if (layer && !mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (layer && layer->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; - return false; - } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); - mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - Q_EMIT layerChanged(mLayer); - return true; -} - -/*! \internal - - Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a - localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is - controlled via \a overrideElement. -*/ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const -{ - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); - else - painter->setAntialiasing(localAntialiased); -} - -/*! \internal - - This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting - of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the - parent plot is set at a later time. - - For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any - QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level - element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To - propagate the parent plot to all the children of the hierarchy, the top level element then uses - this function to pass the parent plot on to its child elements. - - The default implementation does nothing. - - \see initializeParentPlot -*/ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - -/*! \internal - - Returns the selection category this layerable shall belong to. The selection category is used in - conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and - which aren't. - - Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref - QCP::iSelectOther. This is what the default implementation returns. - - \see QCustomPlot::setInteractions -*/ -QCP::Interaction QCPLayerable::selectionCategory() const -{ - return QCP::iSelectOther; -} - -/*! \internal - - Returns the clipping rectangle of this layerable object. By default, this is the viewport of the - parent QCustomPlot. Specific subclasses may reimplement this function to provide different - clipping rects. - - The returned clipping rect is set on the painter before the draw function of the respective - object is called. -*/ -QRect QCPLayerable::clipRect() const -{ - if (mParentPlot) - return mParentPlot->viewport(); - else - return QRect(); -} - -/*! \internal - - This event is called when the layerable shall be selected, as a consequence of a click by the - user. Subclasses should react to it by setting their selection state appropriately. The default - implementation does nothing. - - \a event is the mouse event that caused the selection. \a additive indicates, whether the user - was holding the multi-select-modifier while performing the selection (see \ref - QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled - (i.e. become selected when unselected and unselected when selected). - - Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. - returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). - The \a details data you output from \ref selectTest is fed back via \a details here. You may - use it to transport any kind of information from the selectTest to the possibly subsequent - selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable - that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need - to do the calculation again to find out which part was actually clicked. - - \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must - set the value either to true or false, depending on whether the selection state of this layerable - was actually changed. For layerables that only are selectable as a whole and not in parts, this - is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the - selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the - layerable was previously unselected and now is switched to the selected state. - - \see selectTest, deselectEvent -*/ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) -} - -/*! \internal - - This event is called when the layerable shall be deselected, either as consequence of a user - interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by - unsetting their selection appropriately. - - just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must - return true or false when the selection state of this layerable has changed or not changed, - respectively. - - \see selectTest, selectEvent -*/ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) -{ - Q_UNUSED(selectionStateChanged) -} - -/*! - This event gets called when the user presses a mouse button while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - QCustomPlot uses an event propagation system that works the same as Qt's system. If your - layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in - its reimplementation, the event will be propagated to the next layerable in the stacking order. - - Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and - will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse - interaction (a "mouse interaction" in this context ends with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user moves the mouse while holding a mouse button, after this - layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user releases the mouse button, after this layerable has become - the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user presses the mouse button a second time in a double-click, - while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a - preceding call to \ref selectTest. - - The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the - case of a double-click, the event succession is - pressEvent – releaseEvent – doubleClickEvent – releaseEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, - it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent - and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends - with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent -*/ -void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user turns the mouse scroll wheel while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). - - The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for - single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may - accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has - very smooth steps or none at all, the delta may be smaller. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent -*/ -void QCPLayerable::wheelEvent(QWheelEvent *event) -{ - event->ignore(); -} -/* end of 'src/layer.cpp' */ - - -/* including file 'src/axis/range.cpp', size 12221 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPRange -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPRange - \brief Represents the range an axis is encompassing. - - contains a \a lower and \a upper double value and provides convenience input, output and - modification functions. - - \see QCPAxis::setRange -*/ - -/* start of documentation of inline functions */ - -/*! \fn double QCPRange::size() const - - Returns the size of the range, i.e. \a upper-\a lower -*/ - -/*! \fn double QCPRange::center() const - - Returns the center of the range, i.e. (\a upper+\a lower)*0.5 -*/ - -/*! \fn void QCPRange::normalize() - - Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are - swapped. -*/ - -/*! \fn bool QCPRange::contains(double value) const - - Returns true when \a value lies within or exactly on the borders of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator+=(const double& value) - - Adds \a value to both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator-=(const double& value) - - Subtracts \a value from both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator*=(const double& value) - - Multiplies both boundaries of the range by \a value. -*/ - -/*! \fn QCPRange &QCPRange::operator/=(const double& value) - - Divides both boundaries of the range by \a value. -*/ - -/* end of documentation of inline functions */ - -/*! - Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller - intervals would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a minimum magnitude of roughly 1e-308. - - \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining underflowing ranges. - - \see validRange, maxRange -*/ -const double QCPRange::minRange = 1e-280; - -/*! - Maximum values (negative and positive) the range will accept in range-changing functions. - Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a maximum magnitude of roughly 1e308. - - \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining overflowing ranges. - - \see validRange, minRange -*/ -const double QCPRange::maxRange = 1e250; - -/*! - Constructs a range with \a lower and \a upper set to zero. -*/ -QCPRange::QCPRange() : - lower(0), - upper(0) -{ -} - -/*! \overload - - Constructs a range with the specified \a lower and \a upper values. - - The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically - smaller than \a upper, they will be swapped. -*/ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) -{ - normalize(); -} - -/*! \overload - - Expands this range such that \a otherRange is contained in the new range. It is assumed that both - this range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, it will be replaced by the respective bound - of \a otherRange. - - If \a otherRange is already inside the current range, this function does nothing. - - \see expanded -*/ -void QCPRange::expand(const QCPRange &otherRange) -{ - if (lower > otherRange.lower || qIsNaN(lower)) - lower = otherRange.lower; - if (upper < otherRange.upper || qIsNaN(upper)) - upper = otherRange.upper; -} - -/*! \overload - - Expands this range such that \a includeCoord is contained in the new range. It is assumed that - this range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the respective bound will be set to \a - includeCoord. - - If \a includeCoord is already inside the current range, this function does nothing. - - \see expand -*/ -void QCPRange::expand(double includeCoord) -{ - if (lower > includeCoord || qIsNaN(lower)) - lower = includeCoord; - if (upper < includeCoord || qIsNaN(upper)) - upper = includeCoord; -} - - -/*! \overload - - Returns an expanded range that contains this and \a otherRange. It is assumed that both this - range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be taken from - \a otherRange. - - \see expand -*/ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const -{ - QCPRange result = *this; - result.expand(otherRange); - return result; -} - -/*! \overload - - Returns an expanded range that includes the specified \a includeCoord. It is assumed that this - range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a - includeCoord. - - \see expand -*/ -QCPRange QCPRange::expanded(double includeCoord) const -{ - QCPRange result = *this; - result.expand(includeCoord); - return result; -} - -/*! - Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a - upperBound. If possible, the size of the current range is preserved in the process. - - If the range shall only be bounded at the lower side, you can set \a upperBound to \ref - QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref - QCPRange::maxRange. -*/ -QCPRange QCPRange::bounded(double lowerBound, double upperBound) const -{ - if (lowerBound > upperBound) - qSwap(lowerBound, upperBound); - - QCPRange result(lower, upper); - if (result.lower < lowerBound) - { - result.lower = lowerBound; - result.upper = lowerBound + size(); - if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.upper = upperBound; - } else if (result.upper > upperBound) - { - result.upper = upperBound; - result.lower = upperBound - size(); - if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.lower = lowerBound; - } - - return result; -} - -/*! - Returns a sanitized version of the range. Sanitized means for logarithmic scales, that - the range won't span the positive and negative sign domain, i.e. contain zero. Further - \a lower will always be numerically smaller (or equal) to \a upper. - - If the original range does span positive and negative sign domains or contains zero, - the returned range will try to approximate the original range as good as possible. - If the positive interval of the original range is wider than the negative interval, the - returned range will only contain the positive interval, with lower bound set to \a rangeFac or - \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval - is wider than the positive interval, this time by changing the \a upper bound. -*/ -QCPRange QCPRange::sanitizedForLogScale() const -{ - double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - // can't have range spanning negative and positive values in log plot, so change range to fix it - //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) - { - // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) - { - // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) - { - // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) - { - // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else - { - // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } - } - // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange && - !(lower > 0 && qIsInf(upper/lower)) && - !(upper < 0 && qIsInf(lower/upper))); -} - -/*! - \overload - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(const QCPRange &range) -{ - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - !(range.lower > 0 && qIsInf(range.upper/range.lower)) && - !(range.upper < 0 && qIsInf(range.lower/range.upper))); -} -/* end of 'src/axis/range.cpp' */ - - -/* including file 'src/selection.cpp', size 21906 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataRange -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataRange - \brief Describes a data range given by begin and end index - - QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index - of a contiguous set of data points. The end index points to the data point above the last data point that's part of - the data range, similarly to the nomenclature used in standard iterators. - - Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and - modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is - used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref - QCPDataSelection is thus used. - - Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, - e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref - contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be - used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding - \ref QCPDataSelection. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and - QCPDataRange. - - \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval - in floating point plot coordinates, e.g. the current axis range. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataRange::size() const - - Returns the number of data points described by this data range. This is equal to the end index - minus the begin index. - - \see length -*/ - -/*! \fn int QCPDataRange::length() const - - Returns the number of data points described by this data range. Equivalent to \ref size. -*/ - -/*! \fn void QCPDataRange::setBegin(int begin) - - Sets the begin of this data range. The \a begin index points to the first data point that is part - of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setEnd -*/ - -/*! \fn void QCPDataRange::setEnd(int end) - - Sets the end of this data range. The \a end index points to the data point just above the last - data point that is part of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setBegin -*/ - -/*! \fn bool QCPDataRange::isValid() const - - Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and - an end index greater or equal to the begin index. - - \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods - (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's - methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary - invalid begin/end values while manipulating the range. An invalid range is not necessarily empty - (\ref isEmpty), since its \ref length can be negative and thus non-zero. -*/ - -/*! \fn bool QCPDataRange::isEmpty() const - - Returns whether this range is empty, i.e. whether its begin index equals its end index. - - \see size, length -*/ - -/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const - - Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end - indices, respectively. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataRange, with begin and end set to 0. -*/ -QCPDataRange::QCPDataRange() : - mBegin(0), - mEnd(0) -{ -} - -/*! - Creates a QCPDataRange, initialized with the specified \a begin and \a end. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). -*/ -QCPDataRange::QCPDataRange(int begin, int end) : - mBegin(begin), - mEnd(end) -{ -} - -/*! - Returns a data range that matches this data range, except that parts exceeding \a other are - excluded. - - This method is very similar to \ref intersection, with one distinction: If this range and the \a - other range share no intersection, the returned data range will be empty with begin and end set - to the respective boundary side of \a other, at which this range is residing. (\ref intersection - would just return a range with begin and end set to 0.) -*/ -QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const -{ - QCPDataRange result(intersection(other)); - if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value - { - if (mEnd <= other.mBegin) - result = QCPDataRange(other.mBegin, other.mBegin); - else - result = QCPDataRange(other.mEnd, other.mEnd); - } - return result; -} - -/*! - Returns a data range that contains both this data range as well as \a other. -*/ -QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const -{ - return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); -} - -/*! - Returns the data range which is contained in both this data range and \a other. - - This method is very similar to \ref bounded, with one distinction: If this range and the \a other - range share no intersection, the returned data range will be empty with begin and end set to 0. - (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, - depending on which side this range is on.) - - \see QCPDataSelection::intersection -*/ -QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const -{ - QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); - if (result.isValid()) - return result; - else - return QCPDataRange(); -} - -/*! - Returns whether this data range and \a other share common data points. - - \see intersection, contains -*/ -bool QCPDataRange::intersects(const QCPDataRange &other) const -{ - return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || - (mEnd <= other.mBegin && mEnd < other.mEnd) ); -} - -/*! - Returns whether all data points described by this data range are also in \a other. - - \see intersects -*/ -bool QCPDataRange::contains(const QCPDataRange &other) const -{ - return mBegin <= other.mBegin && mEnd >= other.mEnd; -} - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataSelection -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataSelection - \brief Describes a data set by holding multiple QCPDataRange instances - - QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly - disjoint) set of data selection. - - The data selection can be modified with addition and subtraction operators which take - QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and - \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. - - The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange - instances. QCPDataSelection automatically simplifies when using the addition/subtraction - operators. The only case when \ref simplify is left to the user, is when calling \ref - addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data - ranges will be added to the selection successively and the overhead for simplifying after each - iteration shall be avoided. In this case, you should make sure to call \ref simplify after - completing the operation. - - Use \ref enforceType to bring the data selection into a state complying with the constraints for - selections defined in \ref QCP::SelectionType. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and - QCPDataRange. - - \section qcpdataselection-iterating Iterating over a data selection - - As an example, the following code snippet calculates the average value of a graph's data - \ref QCPAbstractPlottable::selection "selection": - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 - -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataSelection::dataRangeCount() const - - Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref - dataRange via their index. - - \see dataRange, dataPointCount -*/ - -/*! \fn QList QCPDataSelection::dataRanges() const - - Returns all data ranges that make up the data selection. If the data selection is simplified (the - usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point - index. - - \see dataRange -*/ - -/*! \fn bool QCPDataSelection::isEmpty() const - - Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection - instance. - - \see dataRangeCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataSelection. -*/ -QCPDataSelection::QCPDataSelection() -{ -} - -/*! - Creates a QCPDataSelection containing the provided \a range. -*/ -QCPDataSelection::QCPDataSelection(const QCPDataRange &range) -{ - mDataRanges.append(range); -} - -/*! - Returns true if this selection is identical (contains the same data ranges with the same begin - and end indices) to \a other. - - Note that both data selections must be in simplified state (the usual state of the selection, see - \ref simplify) for this operator to return correct results. -*/ -bool QCPDataSelection::operator==(const QCPDataSelection &other) const -{ - if (mDataRanges.size() != other.mDataRanges.size()) - return false; - for (int i=0; i= other.end()) - break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this - - if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored - { - if (thisBegin >= other.begin()) // range leading segment is encompassed - { - if (thisEnd <= other.end()) // range fully encompassed, remove completely - { - mDataRanges.removeAt(i); - continue; - } else // only leading segment is encompassed, trim accordingly - mDataRanges[i].setBegin(other.end()); - } else // leading segment is not encompassed - { - if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly - { - mDataRanges[i].setEnd(other.begin()); - } else // other lies inside this range, so split range - { - mDataRanges[i].setEnd(other.begin()); - mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); - break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here - } - } - } - ++i; - } - - return *this; -} - -/*! - Returns the total number of data points contained in all data ranges that make up this data - selection. -*/ -int QCPDataSelection::dataPointCount() const -{ - int result = 0; - for (int i=0; i= 0 && index < mDataRanges.size()) - { - return mDataRanges.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of range:" << index; - return QCPDataRange(); - } -} - -/*! - Returns a \ref QCPDataRange which spans the entire data selection, including possible - intermediate segments which are not part of the original data selection. -*/ -QCPDataRange QCPDataSelection::span() const -{ - if (isEmpty()) - return QCPDataRange(); - else - return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); -} - -/*! - Adds the given \a dataRange to this data selection. This is equivalent to the += operator but - allows disabling immediate simplification by setting \a simplify to false. This can improve - performance if adding a very large amount of data ranges successively. In this case, make sure to - call \ref simplify manually, after the operation. -*/ -void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) -{ - mDataRanges.append(dataRange); - if (simplify) - this->simplify(); -} - -/*! - Removes all data ranges. The data selection then contains no data points. - - \ref isEmpty -*/ -void QCPDataSelection::clear() -{ - mDataRanges.clear(); -} - -/*! - Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent - or overlapping ranges. This can reduce the number of individual data ranges in the selection, and - prevents possible double-counting when iterating over the data points held by the data ranges. - - This method is automatically called when using the addition/subtraction operators. The only case - when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a - simplify explicitly set to false. -*/ -void QCPDataSelection::simplify() -{ - // remove any empty ranges: - for (int i=mDataRanges.size()-1; i>=0; --i) - { - if (mDataRanges.at(i).isEmpty()) - mDataRanges.removeAt(i); - } - if (mDataRanges.isEmpty()) - return; - - // sort ranges by starting value, ascending: - std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); - - // join overlapping/contiguous ranges: - int i = 1; - while (i < mDataRanges.size()) - { - if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list - { - mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); - mDataRanges.removeAt(i); - } else - ++i; - } -} - -/*! - Makes sure this data selection conforms to the specified \a type selection type. Before the type - is enforced, \ref simplify is called. - - Depending on \a type, enforcing means adding new data points that were previously not part of the - selection, or removing data points from the selection. If the current selection already conforms - to \a type, the data selection is not changed. - - \see QCP::SelectionType -*/ -void QCPDataSelection::enforceType(QCP::SelectionType type) -{ - simplify(); - switch (type) - { - case QCP::stNone: - { - mDataRanges.clear(); - break; - } - case QCP::stWhole: - { - // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) - break; - } - case QCP::stSingleData: - { - // reduce all data ranges to the single first data point: - if (!mDataRanges.isEmpty()) - { - if (mDataRanges.size() > 1) - mDataRanges = QList() << mDataRanges.first(); - if (mDataRanges.first().length() > 1) - mDataRanges.first().setEnd(mDataRanges.first().begin()+1); - } - break; - } - case QCP::stDataRange: - { - mDataRanges = QList() << span(); - break; - } - case QCP::stMultipleDataRanges: - { - // this is the selection type that allows all concievable combinations of ranges, so do nothing - break; - } - } -} - -/*! - Returns true if the data selection \a other is contained entirely in this data selection, i.e. - all data point indices that are in \a other are also in this data selection. - - \see QCPDataRange::contains -*/ -bool QCPDataSelection::contains(const QCPDataSelection &other) const -{ - if (other.isEmpty()) return false; - - int otherIndex = 0; - int thisIndex = 0; - while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) - { - if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) - ++otherIndex; - else - ++thisIndex; - } - return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this -} - -/*! - Returns a data selection containing the points which are both in this data selection and in the - data range \a other. - - A common use case is to limit an unknown data selection to the valid range of a data container, - using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned - data selection without exceeding the data container's bounds. -*/ -QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const -{ - QCPDataSelection result; - for (int i=0; iorientation() == Qt::Horizontal) - return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); - else - return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); - } else - { - qDebug() << Q_FUNC_INFO << "called with axis zero"; - return QCPRange(); - } -} - -/*! - Sets the pen that will be used to draw the selection rect outline. - - \see setBrush -*/ -void QCPSelectionRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used to fill the selection rect. By default the selection rect is not - filled, i.e. \a brush is Qt::NoBrush. - - \see setPen -*/ -void QCPSelectionRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - If there is currently a selection interaction going on (\ref isActive), the interaction is - canceled. The selection rect will emit the \ref canceled signal. -*/ -void QCPSelectionRect::cancel() -{ - if (mActive) - { - mActive = false; - Q_EMIT canceled(mRect, 0); - } -} - -/*! \internal - - This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. - The default implementation sets the selection rect to active, initializes the selection rect - geometry and emits the \ref started signal. -*/ -void QCPSelectionRect::startSelection(QMouseEvent *event) -{ - mActive = true; - mRect = QRect(event->pos(), event->pos()); - Q_EMIT started(event); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs - to update its geometry. The default implementation updates the rect and emits the \ref changed - signal. -*/ -void QCPSelectionRect::moveSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - Q_EMIT changed(mRect, event); - layer()->replot(); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has - finished by the user releasing the mouse button. The default implementation deactivates the - selection rect and emits the \ref accepted signal. -*/ -void QCPSelectionRect::endSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - mActive = false; - Q_EMIT accepted(mRect, event); -} - -/*! \internal - - This method is called by QCustomPlot when a key has been pressed by the user while the selection - rect interaction is active. The default implementation allows to \ref cancel the interaction by - hitting the escape key. -*/ -void QCPSelectionRect::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape && mActive) - { - mActive = false; - Q_EMIT canceled(mRect, event); - } -} - -/* inherits documentation from base class */ -void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/*! \internal - - If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. - - \seebaseclassmethod -*/ -void QCPSelectionRect::draw(QCPPainter *painter) -{ - if (mActive) - { - painter->setPen(mPen); - painter->setBrush(mBrush); - painter->drawRect(mRect); - } -} -/* end of 'src/selectionrect.cpp' */ - - -/* including file 'src/layout.cpp', size 79064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPMarginGroup -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPMarginGroup - \brief A margin group allows synchronization of margin sides if working with multiple layout elements. - - QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that - they will all have the same size, based on the largest required margin in the group. - - \n - \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" - \n - - In certain situations it is desirable that margins at specific sides are synchronized across - layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will - provide a cleaner look to the user if the left and right margins of the two axis rects are of the - same size. The left axis of the top axis rect will then be at the same horizontal position as the - left axis of the lower axis rect, making them appear aligned. The same applies for the right - axes. This is what QCPMarginGroup makes possible. - - To add/remove a specific side of a layout element to/from a margin group, use the \ref - QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call - \ref clear, or just delete the margin group. - - \section QCPMarginGroup-example Example - - First create a margin group: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 - Then set this group on the layout element sides: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 - Here, we've used the first two axis rects of the plot and synchronized their left margins with - each other and their right margins with each other. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const - - Returns a list of all layout elements that have their margin \a side associated with this margin - group. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPMarginGroup instance in \a parentPlot. -*/ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) -{ - mChildren.insert(QCP::msLeft, QList()); - mChildren.insert(QCP::msRight, QList()); - mChildren.insert(QCP::msTop, QList()); - mChildren.insert(QCP::msBottom, QList()); -} - -QCPMarginGroup::~QCPMarginGroup() -{ - clear(); -} - -/*! - Returns whether this margin group is empty. If this function returns true, no layout elements use - this margin group to synchronize margin sides. -*/ -bool QCPMarginGroup::isEmpty() const -{ - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - if (!it.value().isEmpty()) - return false; - } - return true; -} - -/*! - Clears this margin group. The synchronization of the margin sides that use this margin group is - lifted and they will use their individual margin sizes again. -*/ -void QCPMarginGroup::clear() -{ - // make all children remove themselves from this margin group: - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - const QList elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild - } -} - -/*! \internal - - Returns the synchronized common margin for \a side. This is the margin value that will be used by - the layout element on the respective side, if it is part of this margin group. - - The common margin is calculated by requesting the automatic margin (\ref - QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin - group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into - account, too.) -*/ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const -{ - // query all automatic margins of the layout elements in this margin group side and find maximum: - int result = 0; - const QList elements = mChildren.value(side); - for (int i=0; iautoMargins().testFlag(side)) - continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) - result = m; - } - return result; -} - -/*! \internal - - Adds \a element to the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].contains(element)) - mChildren[side].append(element); - else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); -} - -/*! \internal - - Removes \a element from the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutElement - \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". - - This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. - - A Layout element is a rectangular object which can be placed in layouts. It has an outer rect - (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference - between outer and inner rect is called its margin. The margin can either be set to automatic or - manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be - set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, - the layout element subclass will control the value itself (via \ref calculateAutoMargin). - - Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level - layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref - QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. - - Thus in QCustomPlot one can divide layout elements into two categories: The ones that are - invisible by themselves, because they don't draw anything. Their only purpose is to manage the - position and size of other layout elements. This category of layout elements usually use - QCPLayout as base class. Then there is the category of layout elements which actually draw - something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does - not necessarily mean that the latter category can't have child layout elements. QCPLegend for - instance, actually derives from QCPLayoutGrid and the individual legend items are child layout - elements in the grid layout. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayout *QCPLayoutElement::layout() const - - Returns the parent layout of this layout element. -*/ - -/*! \fn QRect QCPLayoutElement::rect() const - - Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref - setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). - - In some cases, the area between outer and inner rect is left blank. In other cases the margin - area is used to display peripheral graphics while the main content is in the inner rect. This is - where automatic margin calculation becomes interesting because it allows the layout element to - adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect - draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if - \ref setAutoMargins is enabled) according to the space required by the labels of the axes. - - \see outerRect -*/ - -/*! \fn QRect QCPLayoutElement::outerRect() const - - Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the - margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref - setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. - - \see rect -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutElement and sets default values. -*/ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mSizeConstraintRect(scrInnerRect), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) -{ -} - -QCPLayoutElement::~QCPLayoutElement() -{ - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any - // unregister at layout: - if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); -} - -/*! - Sets the outer rect of this layout element. If the layout element is inside a layout, the layout - sets the position and size of this layout element using this function. - - Calling this function externally has no effect, since the layout will overwrite any changes to - the outer rect upon the next replot. - - The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. - - \see rect -*/ -void QCPLayoutElement::setOuterRect(const QRect &rect) -{ - if (mOuterRect != rect) - { - mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all - sides, this function is used to manually set the margin on those sides. Sides that are still set - to be handled automatically are ignored and may have any value in \a margins. - - The margin is the distance between the outer rect (controlled by the parent layout via \ref - setOuterRect) and the inner \ref rect (which usually contains the main content of this layout - element). - - \see setAutoMargins -*/ -void QCPLayoutElement::setMargins(const QMargins &margins) -{ - if (mMargins != margins) - { - mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - If \ref setAutoMargins is enabled on some or all margins, this function is used to provide - minimum values for those margins. - - The minimum values are not enforced on margin sides that were set to be under manual control via - \ref setAutoMargins. - - \see setAutoMargins -*/ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) -{ - if (mMinimumMargins != margins) - { - mMinimumMargins = margins; - } -} - -/*! - Sets on which sides the margin shall be calculated automatically. If a side is calculated - automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is - set to be controlled manually, the value may be specified with \ref setMargins. - - Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref - setMarginGroup), to synchronize (align) it with other layout elements in the plot. - - \see setMinimumMargins, setMargins, QCP::MarginSide -*/ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) -{ - mAutoMargins = sides; -} - -/*! - Sets the minimum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - If the parent layout size is not sufficient to satisfy all minimum size constraints of its child - layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot - propagates the layout's size constraints to the outside by setting its own minimum QWidget size - accordingly, so violations of \a size should be exceptions. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(const QSize &size) -{ - if (mMinimumSize != size) - { - mMinimumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the minimum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(int width, int height) -{ - setMinimumSize(QSize(width, height)); -} - -/*! - Sets the maximum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(const QSize &size) -{ - if (mMaximumSize != size) - { - mMaximumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the maximum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(int width, int height) -{ - setMaximumSize(QSize(width, height)); -} - -/*! - Sets to which rect of a layout element the size constraints apply. Size constraints can be set - via \ref setMinimumSize and \ref setMaximumSize. - - The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis - labels), whereas the inner rect (\ref rect) does not. - - \see setMinimumSize, setMaximumSize -*/ -void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) -{ - if (mSizeConstraintRect != constraintRect) - { - mSizeConstraintRect = constraintRect; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! - Sets the margin \a group of the specified margin \a sides. - - Margin groups allow synchronizing specified margins across layout elements, see the documentation - of \ref QCPMarginGroup. - - To unset the margin group of \a sides, set \a group to 0. - - Note that margin groups only work for margin sides that are set to automatic (\ref - setAutoMargins). - - \see QCP::MarginSide -*/ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) -{ - QVector sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; iremoveChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there - { - mMarginGroups.remove(side); - } else // setting to a new group - { - mMarginGroups[side] = group; - group->addChild(side, this); - } - } - } -} - -/*! - Updates the layout element and sub-elements. This function is automatically called before every - replot by the parent layout element. It is called multiple times, once for every \ref - UpdatePhase. The phases are run through in the order of the enum values. For details about what - happens at the different phases, see the documentation of \ref UpdatePhase. - - Layout elements that have child elements should call the \ref update method of their child - elements, and pass the current \a phase unchanged. - - The default implementation executes the automatic margin mechanism in the \ref upMargins phase. - Subclasses should make sure to call the base class implementation. -*/ -void QCPLayoutElement::update(UpdatePhase phase) -{ - if (phase == upMargins) - { - if (mAutoMargins != QCP::msNone) - { - // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: - QMargins newMargins = mMargins; - QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; - Q_FOREACH (QCP::MarginSide side, allMarginSides) - { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically - { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group - else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly - // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); - } - } - setMargins(newMargins); - } - } -} - -/*! - Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, - if no manual minimum size is set. - - if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size - (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum - allowed size of this layout element. - - A manual minimum size is considered set if it is non-zero. - - The default implementation simply returns the sum of the horizontal margins for the width and the - sum of the vertical margins for the height. Reimplementations may use their detailed knowledge - about the layout element's content to provide size hints. -*/ -QSize QCPLayoutElement::minimumOuterSizeHint() const -{ - return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); -} - -/*! - Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, - if no manual maximum size is set. - - if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned - size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the - maximum allowed size of this layout element. - - A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. - - The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying - no suggested maximum size. Reimplementations may use their detailed knowledge about the layout - element's content to provide size hints. -*/ -QSize QCPLayoutElement::maximumOuterSizeHint() const -{ - return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); -} - -/*! - Returns a list of all child elements in this layout element. If \a recursive is true, all - sub-child elements are included in the list, too. - - \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have - empty cells which yield 0 at the respective index.) -*/ -QList QCPLayoutElement::elements(bool recursive) const -{ - Q_UNUSED(recursive) - return QList(); -} - -/*! - Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer - rect, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is - true, -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. - - QCPLayoutElement subclasses may reimplement this method to provide more specific selection test - behaviour. -*/ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - - if (onlySelectable) - return -1; - - if (QRectF(mOuterRect).contains(pos)) - { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; - else - { - qDebug() << Q_FUNC_INFO << "parent plot not defined"; - return -1; - } - } else - return -1; -} - -/*! \internal - - propagates the parent plot initialization to all child elements, by calling \ref - QCPLayerable::initializeParentPlot on them. -*/ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_FOREACH (QCPLayoutElement* el, elements(false)) - { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); - } -} - -/*! \internal - - Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a - side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the - returned value will not be smaller than the specified minimum margin. - - The default implementation just returns the respective manual margin (\ref setMargins) or the - minimum margin, whichever is larger. -*/ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) -{ - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); -} - -/*! \internal - - This virtual method is called when this layout element was moved to a different QCPLayout, or - when this layout element has changed its logical position (e.g. row and/or column) within the - same QCPLayout. Subclasses may use this to react accordingly. - - Since this method is called after the completion of the move, you can access the new parent - layout via \ref layout(). - - The default implementation does nothing. -*/ -void QCPLayoutElement::layoutChanged() -{ -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayout -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayout - \brief The abstract base class for layouts - - This is an abstract base class for layout elements whose main purpose is to define the position - and size of other child layout elements. In most cases, layouts don't draw anything themselves - (but there are exceptions to this, e.g. QCPLegend). - - QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. - - QCPLayout introduces a common interface for accessing and manipulating the child elements. Those - functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref - simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions - to this interface which are more specialized to the form of the layout. For example, \ref - QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid - more conveniently. - - Since this is an abstract base class, you can't instantiate it directly. Rather use one of its - subclasses like QCPLayoutGrid or QCPLayoutInset. - - For a general introduction to the layout system, see the dedicated documentation page \ref - thelayoutsystem "The Layout System". -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPLayout::elementCount() const = 0 - - Returns the number of elements/cells in the layout. - - \see elements, elementAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 - - Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. - - Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. - QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check - whether a cell is empty or not. - - \see elements, elementCount, takeAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 - - Removes the element with the given \a index from the layout and returns it. - - If the \a index is invalid or the cell with that index is empty, returns 0. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see elementAt, take -*/ - -/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 - - Removes the specified \a element from the layout and returns true on success. - - If the \a element isn't in this layout, returns false. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see takeAt -*/ - -/* end documentation of pure virtual functions */ - -/*! - Creates an instance of QCPLayout and sets default values. Note that since QCPLayout - is an abstract base class, it can't be instantiated directly. -*/ -QCPLayout::QCPLayout() -{ -} - -/*! - If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to - reposition and resize their cells. - - Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". - - For details about this method and the update phases, see the documentation of \ref - QCPLayoutElement::update. -*/ -void QCPLayout::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - // set child element rects according to layout: - if (phase == upLayout) - updateLayout(); - - // propagate update call to child elements: - const int elCount = elementCount(); - for (int i=0; iupdate(phase); - } -} - -/* inherits documentation from base class */ -QList QCPLayout::elements(bool recursive) const -{ - const int c = elementCount(); - QList result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the - default implementation does nothing. - - Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit - simplification while QCPLayoutGrid does. -*/ -void QCPLayout::simplify() -{ -} - -/*! - Removes and deletes the element at the provided \a index. Returns true on success. If \a index is - invalid or points to an empty cell, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the returned element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see remove, takeAt -*/ -bool QCPLayout::removeAt(int index) -{ - if (QCPLayoutElement *el = takeAt(index)) - { - delete el; - return true; - } else - return false; -} - -/*! - Removes and deletes the provided \a element. Returns true on success. If \a element is not in the - layout, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see removeAt, take -*/ -bool QCPLayout::remove(QCPLayoutElement *element) -{ - if (take(element)) - { - delete element; - return true; - } else - return false; -} - -/*! - Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure - all empty cells are collapsed. - - \see remove, removeAt -*/ -void QCPLayout::clear() -{ - for (int i=elementCount()-1; i>=0; --i) - { - if (elementAt(i)) - removeAt(i); - } - simplify(); -} - -/*! - Subclasses call this method to report changed (minimum/maximum) size constraints. - - If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref - sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of - QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, - it may update itself and resize cells accordingly. -*/ -void QCPLayout::sizeConstraintsChanged() const -{ - if (QWidget *w = qobject_cast(parent())) - w->updateGeometry(); - else if (QCPLayout *l = qobject_cast(parent())) - l->sizeConstraintsChanged(); -} - -/*! \internal - - Subclasses reimplement this method to update the position and sizes of the child elements/cells - via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. - - The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay - within that rect. - - \ref getSectionSizes may help with the reimplementation of this function. - - \see update -*/ -void QCPLayout::updateLayout() -{ -} - - -/*! \internal - - Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the - \ref QCPLayerable::parentLayerable and the QObject parent to this layout. - - Further, if \a el didn't previously have a parent plot, calls \ref - QCPLayerable::initializeParentPlot on \a el to set the paret plot. - - This method is used by subclass specific methods that add elements to the layout. Note that this - method only changes properties in \a el. The removal from the old layout and the insertion into - the new layout must be done additionally. -*/ -void QCPLayout::adoptElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); - el->layoutChanged(); - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout - and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent - QCustomPlot. - - This method is used by subclass specific methods that remove elements from the layout (e.g. \ref - take or \ref takeAt). Note that this method only changes properties in \a el. The removal from - the old layout must be done additionally. -*/ -void QCPLayout::releaseElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); - // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - This is a helper function for the implementation of \ref updateLayout in subclasses. - - It calculates the sizes of one-dimensional sections with provided constraints on maximum section - sizes, minimum section sizes, relative stretch factors and the final total size of all sections. - - The QVector entries refer to the sections. Thus all QVectors must have the same size. - - \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size - imposed, set all vector values to Qt's QWIDGETSIZE_MAX. - - \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size - imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than - \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, - not exceeding the allowed total size is taken to be more important than not going below minimum - section sizes.) - - \a stretchFactors give the relative proportions of the sections to each other. If all sections - shall be scaled equally, set all values equal. If the first section shall be double the size of - each individual other section, set the first number of \a stretchFactors to double the value of - the other individual values (e.g. {2, 1, 1, 1}). - - \a totalSize is the value that the final section sizes will add up to. Due to rounding, the - actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, - you could distribute the remaining difference on the sections. - - The return value is a QVector containing the section sizes. -*/ -QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const -{ - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) - { - qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; - return QVector(); - } - if (stretchFactors.isEmpty()) - return QVector(); - int sectionCount = stretchFactors.size(); - QVector sectionSizes(sectionCount); - // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): - int minSizeSum = 0; - for (int i=0; i minimumLockedSections; - QList unfinishedSections; - for (int i=0; i result(sectionCount); - for (int i=0; iminimumOuterSizeHint(); - QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) - if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rwidth() += el->margins().left() + el->margins().right(); - if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; -} - -/*! \internal - - This is a helper function for the implementation of subclasses. - - It returns the maximum size that should finally be used for the outer rect of the passed layout - element \a el. - - It takes into account whether a manual maximum size is set (\ref - QCPLayoutElement::setMaximumSize), which size constraint is set (\ref - QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum - size was set (\ref QCPLayoutElement::maximumOuterSizeHint). -*/ -QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) -{ - QSize maxOuterHint = el->maximumOuterSizeHint(); - QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) - if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rwidth() += el->margins().left() + el->margins().right(); - if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutGrid - \brief A layout that arranges child elements in a grid - - Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, - \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). - - Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or - column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref - hasElement, that element can be retrieved with \ref element. If rows and columns that only have - empty cells shall be removed, call \ref simplify. Removal of elements is either done by just - adding the element to a different layout or by using the QCPLayout interface \ref take or \ref - remove. - - If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a - column, the grid layout will choose the position according to the current \ref setFillOrder and - the wrapping (\ref setWrap). - - Row and column insertion can be performed with \ref insertRow and \ref insertColumn. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPLayoutGrid::rowCount() const - - Returns the number of rows in the layout. - - \see columnCount -*/ - -/*! \fn int QCPLayoutGrid::columnCount() const - - Returns the number of columns in the layout. - - \see rowCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutGrid and sets default values. -*/ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5), - mWrap(0), - mFillOrder(foRowsFirst) -{ -} - -QCPLayoutGrid::~QCPLayoutGrid() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the element in the cell in \a row and \a column. - - Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug - message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. - - \see addElement, hasElement -*/ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const -{ - if (row >= 0 && row < mElements.size()) - { - if (column >= 0 && column < mElements.first().size()) - { - if (QCPLayoutElement *result = mElements.at(row).at(column)) - return result; - else - qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; - return 0; -} - - -/*! \overload - - Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it - is first removed from there. If \a row or \a column don't exist yet, the layout is expanded - accordingly. - - Returns true if the element was added successfully, i.e. if the cell at \a row and \a column - didn't already have an element. - - Use the overload of this method without explicit row/column index to place the element according - to the configured fill order and wrapping settings. - - \see element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) -{ - if (!hasElement(row, column)) - { - if (element && element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); - mElements[row][column] = element; - if (element) - adoptElement(element); - return true; - } else - qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; - return false; -} - -/*! \overload - - Adds the \a element to the next empty cell according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first - removed from there. If necessary, the layout is expanded to hold the new element. - - Returns true if the element was added successfully. - - \see setFillOrder, setWrap, element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(QCPLayoutElement *element) -{ - int rowIndex = 0; - int colIndex = 0; - if (mFillOrder == foColumnsFirst) - { - while (hasElement(rowIndex, colIndex)) - { - ++colIndex; - if (colIndex >= mWrap && mWrap > 0) - { - colIndex = 0; - ++rowIndex; - } - } - } else - { - while (hasElement(rowIndex, colIndex)) - { - ++rowIndex; - if (rowIndex >= mWrap && mWrap > 0) - { - rowIndex = 0; - ++colIndex; - } - } - } - return addElement(rowIndex, colIndex, element); -} - -/*! - Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't - empty. - - \see element -*/ -bool QCPLayoutGrid::hasElement(int row, int column) -{ - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); - else - return false; -} - -/*! - Sets the stretch \a factor of \a column. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) -{ - if (column >= 0 && column < columnCount()) - { - if (factor > 0) - mColumnStretchFactors[column] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid column:" << column; -} - -/*! - Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactor, setRowStretchFactors -*/ -void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) -{ - if (factors.size() == mColumnStretchFactors.size()) - { - mColumnStretchFactors = factors; - for (int i=0; i= 0 && row < rowCount()) - { - if (factor > 0) - mRowStretchFactors[row] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid row:" << row; -} - -/*! - Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setRowStretchFactor, setColumnStretchFactors -*/ -void QCPLayoutGrid::setRowStretchFactors(const QList &factors) -{ - if (factors.size() == mRowStretchFactors.size()) - { - mRowStretchFactors = factors; - for (int i=0; i tempElements; - if (rearrange) - { - tempElements.reserve(elCount); - for (int i=0; i()); - mRowStretchFactors.append(1); - } - // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i rowCount()) - newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); - QList newRow; - for (int col=0; col columnCount()) - newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row= 0 && row < rowCount()) - { - if (column >= 0 && column < columnCount()) - { - switch (mFillOrder) - { - case foRowsFirst: return column*rowCount() + row; - case foColumnsFirst: return row*columnCount() + column; - } - } else - qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; - } else - qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; - return 0; -} - -/*! - Converts the linear index to row and column indices and writes the result to \a row and \a - column. - - The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the - indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices - increase top to bottom and then left to right. - - If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. - - For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, - i.e. greater or equal to zero and smaller than the current \ref elementCount. - - \see rowColToIndex -*/ -void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const -{ - row = -1; - column = -1; - const int nCols = columnCount(); - const int nRows = rowCount(); - if (nCols == 0 || nRows == 0) - return; - if (index < 0 || index >= elementCount()) - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return; - } - - switch (mFillOrder) - { - case foRowsFirst: - { - column = index / nRows; - row = index % nRows; - break; - } - case foColumnsFirst: - { - row = index / nCols; - column = index % nCols; - break; - } - } -} - -/* inherits documentation from base class */ -void QCPLayoutGrid::updateLayout() -{ - QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - - // go through cells and set rects accordingly: - int yOffset = mRect.top(); - for (int row=0; row 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; - int xOffset = mRect.left(); - for (int col=0; col 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); - } - } -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const -{ - if (index >= 0 && index < elementCount()) - { - int row, col; - indexToRowCol(index, row, col); - return mElements.at(row).at(col); - } else - return 0; -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - int row, col; - indexToRowCol(index, row, col); - mElements[row][col] = 0; - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i QCPLayoutGrid::elements(bool recursive) const -{ - QList result; - const int elCount = elementCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(elCount); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing rows and columns which only contain empty cells. -*/ -void QCPLayoutGrid::simplify() -{ - // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) - { - bool hasElements = false; - for (int col=0; col=0; --col) - { - bool hasElements = false; - for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i QWIDGETSIZE_MAX) - result.setHeight(QWIDGETSIZE_MAX); - if (result.width() > QWIDGETSIZE_MAX) - result.setWidth(QWIDGETSIZE_MAX); - return result; -} - -/*! \internal - - Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights - respectively. - - The minimum height of a row is the largest minimum height of any element's outer rect in that - row. The minimum width of a column is the largest minimum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMaximumRowColSizes -*/ -void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const -{ - *minColWidths = QVector(columnCount(), 0); - *minRowHeights = QVector(rowCount(), 0); - for (int row=0; rowat(col) < minSize.width()) - (*minColWidths)[col] = minSize.width(); - if (minRowHeights->at(row) < minSize.height()) - (*minRowHeights)[row] = minSize.height(); - } - } - } -} - -/*! \internal - - Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights - respectively. - - The maximum height of a row is the smallest maximum height of any element's outer rect in that - row. The maximum width of a column is the smallest maximum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMinimumRowColSizes -*/ -void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const -{ - *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; rowat(col) > maxSize.width()) - (*maxColWidths)[col] = maxSize.width(); - if (maxRowHeights->at(row) > maxSize.height()) - (*maxRowHeights)[row] = maxSize.height(); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutInset -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPLayoutInset - \brief A layout that places child elements aligned to the border or arbitrarily positioned - - Elements are placed either aligned to the border or at arbitrary position in the area of the - layout. Which placement applies is controlled with the \ref InsetPlacement (\ref - setInsetPlacement). - - Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or - addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset - placement will default to \ref ipBorderAligned and the element will be aligned according to the - \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at - arbitrary position and size, defined by \a rect. - - The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. - - This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual void QCPLayoutInset::simplify() - - The QCPInsetLayout does not need simplification since it can never have empty cells due to its - linear index structure. This method does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutInset and sets default values. -*/ -QCPLayoutInset::QCPLayoutInset() -{ -} - -QCPLayoutInset::~QCPLayoutInset() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the placement type of the element with the specified \a index. -*/ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const -{ - if (elementAt(index)) - return mInsetPlacement.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return ipFree; - } -} - -/*! - Returns the alignment of the element with the specified \a index. The alignment only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. -*/ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const -{ - if (elementAt(index)) - return mInsetAlignment.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return 0; - } -} - -/*! - Returns the rect of the element with the specified \a index. The rect only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. -*/ -QRectF QCPLayoutInset::insetRect(int index) const -{ - if (elementAt(index)) - return mInsetRect.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return QRectF(); - } -} - -/*! - Sets the inset placement type of the element with the specified \a index to \a placement. - - \see InsetPlacement -*/ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) -{ - if (elementAt(index)) - mInsetPlacement[index] = placement; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function - is used to set the alignment of the element with the specified \a index to \a alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. -*/ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) -{ - if (elementAt(index)) - mInsetAlignment[index] = alignment; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the - position and size of the element with the specified \a index to \a rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - Note that the minimum and maximum sizes of the embedded element (\ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. -*/ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) -{ - if (elementAt(index)) - mInsetRect[index] = rect; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/* inherits documentation from base class */ -void QCPLayoutInset::updateLayout() -{ - for (int i=0; i finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter - } - mElements.at(i)->setOuterRect(insetRect); - } -} - -/* inherits documentation from base class */ -int QCPLayoutInset::elementCount() const -{ - return mElements.size(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const -{ - if (index >= 0 && index < mElements.size()) - return mElements.at(index); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! - Adds the specified \a element to the layout as an inset aligned at the border (\ref - setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a - alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. - - \see addElement(QCPLayoutElement *element, const QRectF &rect) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - -/*! - Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref - setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a - rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} -/* end of 'src/layout.cpp' */ - - -/* including file 'src/lineending.cpp', size 11536 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLineEnding -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLineEnding - \brief Handles the different ending decorations for line-like items - - \image html QCPLineEnding.png "The various ending styles currently supported" - - For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine - has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. - - The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can - be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of - the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. - For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite - directions, e.g. "outward". This can be changed by \ref setInverted, which would make the - respective arrow point inward. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify a - QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. - \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead -*/ - -/*! - Creates a QCPLineEnding instance with default values (style \ref esNone). -*/ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) -{ -} - -/*! - Creates a QCPLineEnding instance with the specified values. -*/ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) -{ -} - -/*! - Sets the style of the ending decoration. -*/ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) -{ - mStyle = style; -} - -/*! - Sets the width of the ending decoration, if the style supports it. On arrows, for example, the - width defines the size perpendicular to the arrow's pointing direction. - - \see setLength -*/ -void QCPLineEnding::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the length of the ending decoration, if the style supports it. On arrows, for example, the - length defines the size in pointing direction. - - \see setWidth -*/ -void QCPLineEnding::setLength(double length) -{ - mLength = length; -} - -/*! - Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point - inward when \a inverted is set to true. - - Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or - discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are - affected by it, which can be used to control to which side the half bar points to. -*/ -void QCPLineEnding::setInverted(bool inverted) -{ - mInverted = inverted; -} - -/*! \internal - - Returns the maximum pixel radius the ending decoration might cover, starting from the position - the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). - - This is relevant for clipping. Only omit painting of the decoration when the position where the - decoration is supposed to be drawn is farther away from the clipping rect than the returned - distance. -*/ -double QCPLineEnding::boundingDistance() const -{ - switch (mStyle) - { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) - - } - return 0; -} - -/*! - Starting from the origin of this line ending (which is style specific), returns the length - covered by the line ending symbol, in backward direction. - - For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if - both have the same \ref setLength value, because the spike arrow has an inward curved back, which - reduces the length along its center axis (the drawing origin for arrows is at the tip). - - This function is used for precise, style specific placement of line endings, for example in - QCPAxes. -*/ -double QCPLineEnding::realLength() const -{ - switch (mStyle) - { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; - } - return 0; -} - -/*! \internal - - Draws the line ending with the specified \a painter at the position \a pos. The direction of the - line ending is controlled with \a dir. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const -{ - if (mStyle == esNone) - return; - - QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); - if (lengthVec.isNull()) - lengthVec = QCPVector2D(1, 0); - QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); - - QPen penBackup = painter->pen(); - QBrush brushBackup = painter->brush(); - QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) - { - case esNone: break; - case esFlatArrow: - { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esSpikeArrow: - { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; - } - } -} - -/*! \internal - \overload - - Draws the line ending. The direction is controlled with the \a angle parameter in radians. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const -{ - draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); -} -/* end of 'src/lineending.cpp' */ - - -/* including file 'src/axis/axisticker.cpp', size 18664 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTicker -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTicker - \brief The base class tick generator used by QCPAxis to create tick positions and tick labels - - Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions - and tick labels for the current axis range. The ticker of an axis can be set via \ref - QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple - axes can share the same ticker instance. - - This base class generates normal tick coordinates and numeric labels for linear axes. It picks a - reasonable tick step (the separation between ticks) which results in readable tick labels. The - number of ticks that should be approximately generated can be set via \ref setTickCount. - Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either - sacrifices readability to better match the specified tick count (\ref - QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref - QCPAxisTicker::tssReadability), which is the default. - - The following more specialized axis ticker subclasses are available, see details in the - respective class documentation: - -
- - - - - - - -
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png - \image html axisticker-time2.png
-
- - \section axisticker-subclassing Creating own axis tickers - - Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and - reimplementing some or all of the available virtual methods. - - In the simplest case you might wish to just generate different tick steps than the other tickers, - so you only reimplement the method \ref getTickStep. If you additionally want control over the - string that will be shown as tick label, reimplement \ref getTickLabel. - - If you wish to have complete control, you can generate the tick vectors and tick label vectors - yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default - implementations use the previously mentioned virtual methods \ref getTickStep and \ref - getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case - of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. - - The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick - placement control is obtained by reimplementing \ref createSubTickVector. - - See the documentation of all these virtual methods in QCPAxisTicker for detailed information - about the parameters and expected return values. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTicker::QCPAxisTicker() : - mTickStepStrategy(tssReadability), - mTickCount(5), - mTickOrigin(0) -{ -} - -QCPAxisTicker::~QCPAxisTicker() -{ - -} - -/*! - Sets which strategy the axis ticker follows when choosing the size of the tick step. For the - available strategies, see \ref TickStepStrategy. -*/ -void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) -{ - mTickStepStrategy = strategy; -} - -/*! - Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count - is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with - the requested number of ticks. - - Whether the readability has priority over meeting the requested \a count can be specified with - \ref setTickStepStrategy. -*/ -void QCPAxisTicker::setTickCount(int count) -{ - if (count > 0) - mTickCount = count; - else - qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; -} - -/*! - Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a - concept and doesn't need to be inside the currently visible axis range. - - By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick - step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be - {-4, 1, 6, 11, 16,...}. -*/ -void QCPAxisTicker::setTickOrigin(double origin) -{ - mTickOrigin = origin; -} - -/*! - This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), - tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). - - The ticks are generated for the specified \a range. The generated labels typically follow the - specified \a locale, \a formatChar and number \a precision, however this might be different (or - even irrelevant) for certain QCPAxisTicker subclasses. - - The output parameter \a ticks is filled with the generated tick positions in axis coordinates. - The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) - and are respectively filled with sub tick coordinates, and tick label strings belonging to \a - ticks by index. -*/ -void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) -{ - // generate (major) ticks: - double tickStep = getTickStep(range); - ticks = createTickVector(tickStep, range); - trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) - - // generate sub ticks between major ticks: - if (subTicks) - { - if (ticks.size() > 0) - { - *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); - trimTicks(range, *subTicks, false); - } else - *subTicks = QVector(); - } - - // finally trim also outliers (no further clipping happens in axis drawing): - trimTicks(range, ticks, false); - // generate labels for visible ticks if requested: - if (tickLabels) - *tickLabels = createLabelVector(ticks, locale, formatChar, precision); -} - -/*! \internal - - Takes the entire currently visible axis range and returns a sensible tick step in - order to provide readable tick labels as well as a reasonable number of tick counts (see \ref - setTickCount, \ref setTickStepStrategy). - - If a QCPAxisTicker subclass only wants a different tick step behaviour than the default - implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper - function. -*/ -double QCPAxisTicker::getTickStep(const QCPRange &range) -{ - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return cleanMantissa(exactStep); -} - -/*! \internal - - Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns - an appropriate number of sub ticks for that specific tick step. - - Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. -*/ -int QCPAxisTicker::getSubTickCount(double tickStep) -{ - int result = 1; // default to 1, if no proper value can be found - - // separate integer and fractional part of mantissa: - double epsilon = 0.01; - double intPartf; - int intPart; - double fracPart = modf(getMantissa(tickStep), &intPartf); - intPart = intPartf; - - // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) - { - if (1.0-fracPart < epsilon) - ++intPart; - switch (intPart) - { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep - } - } else - { - // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa - { - switch (intPart) - { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep - } - } - // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default - } - - return result; -} - -/*! \internal - - This method returns the tick label string as it should be printed under the \a tick coordinate. - If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a - precision. - - If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is - enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will - be formatted accordingly using multiplication symbol and superscript during rendering of the - label automatically. -*/ -QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - return locale.toString(tick, formatChar.toLatin1(), precision); -} - -/*! \internal - - Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a - subTickCount sub ticks between each tick pair given in \a ticks. - - If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should - reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to - base its result on \a subTickCount or \a ticks. -*/ -QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) -{ - QVector result; - if (subTickCount <= 0 || ticks.size() < 2) - return result; - - result.reserve((ticks.size()-1)*subTickCount); - for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result; - // Generate tick positions according to tickStep: - qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - result.resize(tickcount); - for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) -{ - QVector result; - result.reserve(ticks.size()); - for (int i=0; i &ticks, bool keepOneOutlier) const -{ - bool lowFound = false; - bool highFound = false; - int lowIndex = 0; - int highIndex = -1; - - for (int i=0; i < ticks.size(); ++i) - { - if (ticks.at(i) >= range.lower) - { - lowFound = true; - lowIndex = i; - break; - } - } - for (int i=ticks.size()-1; i >= 0; --i) - { - if (ticks.at(i) <= range.upper) - { - highFound = true; - highIndex = i; - break; - } - } - - if (highFound && lowFound) - { - int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); - int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); - if (trimFront > 0 || trimBack > 0) - ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); - } else // all ticks are either all below or all above the range - ticks.clear(); -} - -/*! \internal - - Returns the coordinate contained in \a candidates which is closest to the provided \a target. - - This method assumes \a candidates is not empty and sorted in ascending order. -*/ -double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const -{ - if (candidates.size() == 1) - return candidates.first(); - QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); - if (it == candidates.constEnd()) - return *(it-1); - else if (it == candidates.constBegin()) - return *it; - else - return target-*(it-1) < *it-target ? *(it-1) : *it; -} - -/*! \internal - - Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also - returns the magnitude of \a input as a power of 10. - - For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. -*/ -double QCPAxisTicker::getMantissa(double input, double *magnitude) const -{ - const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); - if (magnitude) *magnitude = mag; - return input/mag; -} - -/*! \internal - - Returns a number that is close to \a input but has a clean, easier human readable mantissa. How - strongly the mantissa is altered, and thus how strong the result deviates from the original \a - input, depends on the current tick step strategy (see \ref setTickStepStrategy). -*/ -double QCPAxisTicker::cleanMantissa(double input) const -{ - double magnitude; - const double mantissa = getMantissa(input, &magnitude); - switch (mTickStepStrategy) - { - case tssReadability: - { - return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; - } - case tssMeetTickCount: - { - // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 - if (mantissa <= 5.0) - return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 - else - return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 - } - } - return input; -} -/* end of 'src/axis/axisticker.cpp' */ - - -/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerDateTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerDateTime - \brief Specialized axis ticker for calendar dates and times as axis ticks - - \image html axisticker-datetime.png - - This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The - plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 - UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods - with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime - by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey - and \ref keyToDateTime conveniently perform this conversion achieving a precision of one - millisecond on all Qt versions. - - The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. - If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. - - This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day - ticks. For example, if the axis range spans a few years such that there is one tick per year, - ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, - will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in - the image above: even though the number of days varies month by month, this ticker generates - ticks on the same day of each month. - - If you would like to change the date/time that is used as a (mathematical) starting date for the - ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a - QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at - 9:45 of every year. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation - - \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and - milliseconds, and are not interested in the intricacies of real calendar dates with months and - (leap) years, have a look at QCPAxisTickerTime instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerDateTime::QCPAxisTickerDateTime() : - mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), - mDateTimeSpec(Qt::LocalTime), - mDateStrategy(dsNone) -{ - setTickCount(4); -} - -/*! - Sets the format in which dates and times are displayed as tick labels. For details about the \a - format string, see the documentation of QDateTime::toString(). - - Newlines can be inserted with "\n". - - \see setDateTimeSpec -*/ -void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) -{ - mDateTimeFormat = format; -} - -/*! - Sets the time spec that is used for creating the tick labels from corresponding dates/times. - - The default value of QDateTime objects (and also QCPAxisTickerDateTime) is - Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form - of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC - to get the correct axis labels. - - \see setDateTimeFormat -*/ -void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) -{ - mDateTimeSpec = spec; -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, - 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which - directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(double origin) -{ - QCPAxisTicker::setTickOrigin(origin); -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) -{ - setTickOrigin(dateTimeToKey(origin)); -} - -/*! \internal - - Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - Note that this tick step isn't used exactly when generating the tick vector in \ref - createTickVector, but only as a guiding value requiring some correction for each individual tick - interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day - in the month to the last day in the previous month from tick to tick, due to the non-uniform - length of months. The same problem arises with leap years. - - \seebaseclassmethod -*/ -double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - mDateStrategy = dsNone; - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - result = cleanMantissa(result); - } else if (result < 86400*30.4375*12) // below a year - { - result = pickClosest(result, QVector() - << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range - << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range - << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) - if (result > 86400*30.4375-1) // month tick intervals or larger - mDateStrategy = dsUniformDayInMonth; - else if (result > 3600*24-1) // day tick intervals or larger - mDateStrategy = dsUniformTimeInDay; - } else // more than a year, go back to normal clean mantissa algorithm but in units of years - { - const double secondsPerYear = 86400*30.4375*12; // average including leap years - result = cleanMantissa(result/secondsPerYear)*secondsPerYear; - mDateStrategy = dsUniformDayInMonth; - } - return result; -} - -/*! \internal - - Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - \seebaseclassmethod -*/ -int QCPAxisTickerDateTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - case 86400*2: result = 1; break; - case 86400*5: result = 4; break; - case 86400*7: result = 6; break; - case 86400*14: result = 1; break; - case (int)(86400*30.4375+0.5): result = 3; break; - case (int)(86400*30.4375*2+0.5): result = 1; break; - case (int)(86400*30.4375*3+0.5): result = 2; break; - case (int)(86400*30.4375*6+0.5): result = 5; break; - case (int)(86400*30.4375*12+0.5): result = 3; break; - } - return result; -} - -/*! \internal - - Generates a date/time tick label for tick coordinate \a tick, based on the currently set format - (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). - - \seebaseclassmethod -*/ -QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -} - -/*! \internal - - Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain - non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. - - \seebaseclassmethod -*/ -QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result = QCPAxisTicker::createTickVector(tickStep, range); - if (!result.isEmpty()) - { - if (mDateStrategy == dsUniformTimeInDay) - { - QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible - QDateTime tickDateTime; - for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day - tickDateTime = tickDateTime.addMonths(-1); - tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); - result[i] = dateTimeToKey(tickDateTime); - } - } - } - return result; -} - -/*! - A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a - QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) - - \see dateTimeToKey -*/ -QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); -# else - return QDateTime::fromMSecsSinceEpoch(key*1000.0); -# endif -} - -/*! \overload - - A convenience method which turns a QDateTime object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return dateTime.toTime_t()+dateTime.time().msec()/1000.0; -# else - return dateTime.toMSecsSinceEpoch()/1000.0; -# endif -} - -/*! \overload - - A convenience method which turns a QDate object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime(date).toTime_t(); -# else - return QDateTime(date).toMSecsSinceEpoch()/1000.0; -# endif -} -/* end of 'src/axis/axistickerdatetime.cpp' */ - - -/* including file 'src/axis/axistickertime.cpp', size 11747 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerTime - \brief Specialized axis ticker for time spans in units of milliseconds to days - - \image html axisticker-time.png - - This QCPAxisTicker subclass generates ticks that corresponds to time intervals. - - The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref - setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate - zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date - and time. - - The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the - largest available unit in the format specified with \ref setTimeFormat, any time spans above will - be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at - coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick - label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour - unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis - zero will carry a leading minus sign. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation - - Here is an example of a time axis providing time information in days, hours and minutes. Due to - the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker - decided to use tick steps of 12 hours: - - \image html axisticker-time2.png - - The format string for this example is - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 - - \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime - instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerTime::QCPAxisTickerTime() : - mTimeFormat(QLatin1String("%h:%m:%s")), - mSmallestUnit(tuSeconds), - mBiggestUnit(tuHours) -{ - setTickCount(4); - mFieldWidth[tuMilliseconds] = 3; - mFieldWidth[tuSeconds] = 2; - mFieldWidth[tuMinutes] = 2; - mFieldWidth[tuHours] = 2; - mFieldWidth[tuDays] = 1; - - mFormatPattern[tuMilliseconds] = QLatin1String("%z"); - mFormatPattern[tuSeconds] = QLatin1String("%s"); - mFormatPattern[tuMinutes] = QLatin1String("%m"); - mFormatPattern[tuHours] = QLatin1String("%h"); - mFormatPattern[tuDays] = QLatin1String("%d"); -} - -/*! - Sets the format that will be used to display time in the tick labels. - - The available patterns are: - - %%z for milliseconds - - %%s for seconds - - %%m for minutes - - %%h for hours - - %%d for days - - The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. - - The largest unit that appears in \a format will carry all the remaining time of a certain tick - coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the - largest unit it might become larger than 59 in order to consume larger time values. If on the - other hand %%h is available, the minutes will wrap around to zero after 59 and the time will - carry to the hour digit. -*/ -void QCPAxisTickerTime::setTimeFormat(const QString &format) -{ - mTimeFormat = format; - - // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest - // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) - mSmallestUnit = tuMilliseconds; - mBiggestUnit = tuMilliseconds; - bool hasSmallest = false; - for (int i = tuMilliseconds; i <= tuDays; ++i) - { - TimeUnit unit = static_cast(i); - if (mTimeFormat.contains(mFormatPattern.value(unit))) - { - if (!hasSmallest) - { - mSmallestUnit = unit; - hasSmallest = true; - } - mBiggestUnit = unit; - } - } -} - -/*! - Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick - label. If the number for the specific unit is shorter than \a width, it will be padded with an - according number of zeros to the left in order to reach the field width. - - \see setTimeFormat -*/ -void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) -{ - mFieldWidth[unit] = qMax(width, 1); -} - -/*! \internal - - Returns the tick step appropriate for time displays, depending on the provided \a range and the - smallest available time unit in the current format (\ref setTimeFormat). For example if the unit - of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) - that require sub-minute precision to be displayed correctly. - - \seebaseclassmethod -*/ -double QCPAxisTickerTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - if (mSmallestUnit == tuMilliseconds) - result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond - else // have no milliseconds available in format, so stick with 1 second tickstep - result = 1.0; - } else if (result < 3600*24) // below a day - { - // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run - QVector availableSteps; - // seconds range: - if (mSmallestUnit <= tuSeconds) - availableSteps << 1; - if (mSmallestUnit == tuMilliseconds) - availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it - else if (mSmallestUnit == tuSeconds) - availableSteps << 2; - if (mSmallestUnit <= tuSeconds) - availableSteps << 5 << 10 << 15 << 30; - // minutes range: - if (mSmallestUnit <= tuMinutes) - availableSteps << 1*60; - if (mSmallestUnit <= tuSeconds) - availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it - else if (mSmallestUnit == tuMinutes) - availableSteps << 2*60; - if (mSmallestUnit <= tuMinutes) - availableSteps << 5*60 << 10*60 << 15*60 << 30*60; - // hours range: - if (mSmallestUnit <= tuHours) - availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; - // pick available step that is most appropriate to approximate ideal step: - result = pickClosest(result, availableSteps); - } else // more than a day, go back to normal clean mantissa algorithm but in units of days - { - const double secondsPerDay = 3600*24; - result = cleanMantissa(result/secondsPerDay)*secondsPerDay; - } - return result; -} - -/*! \internal - - Returns the sub tick count appropriate for the provided \a tickStep and time displays. - - \seebaseclassmethod -*/ -int QCPAxisTickerTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - } - return result; -} - -/*! \internal - - Returns the tick label corresponding to the provided \a tick and the configured format and field - widths (\ref setTimeFormat, \ref setFieldWidth). - - \seebaseclassmethod -*/ -QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - Q_UNUSED(locale) - bool negative = tick < 0; - if (negative) tick *= -1; - double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) - double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time - - restValues[tuMilliseconds] = tick*1000; - values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; - values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; - values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; - values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; - // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) - - QString result = mTimeFormat; - for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) - { - TimeUnit iUnit = static_cast(i); - replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); - } - if (negative) - result.prepend(QLatin1Char('-')); - return result; -} - -/*! \internal - - Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified - \a value, using the field width as specified with \ref setFieldWidth for the \a unit. -*/ -void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const -{ - QString valueStr = QString::number(value); - while (valueStr.size() < mFieldWidth.value(unit)) - valueStr.prepend(QLatin1Char('0')); - - text.replace(mFormatPattern.value(unit), valueStr); -} -/* end of 'src/axis/axistickertime.cpp' */ - - -/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerFixed -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerFixed - \brief Specialized axis ticker with a fixed tick step - - \image html axisticker-fixed.png - - This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It - is also possible to allow integer multiples and integer powers of the specified tick step with - \ref setScaleStrategy. - - A typical application of this ticker is to make an axis only display integers, by setting the - tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. - - Another case is when a certain number has a special meaning and axis ticks should only appear at - multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi - because despite the name it is not limited to only pi symbols/values. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerFixed::QCPAxisTickerFixed() : - mTickStep(1.0), - mScaleStrategy(ssNone) -{ -} - -/*! - Sets the fixed tick interval to \a step. - - The axis ticker will only use this tick step when generating axis ticks. This might cause a very - high tick density and overlapping labels if the axis range is zoomed out. Using \ref - setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a - step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref - setTickCount). -*/ -void QCPAxisTickerFixed::setTickStep(double step) -{ - if (step > 0) - mTickStep = step; - else - qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; -} - -/*! - Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether - modifications may be applied to it before calculating the finally used tick step, such as - permitting multiples or powers. See \ref ScaleStrategy for details. - - The default strategy is \ref ssNone, which means the tick step is absolutely fixed. -*/ -void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) -{ - mScaleStrategy = strategy; -} - -/*! \internal - - Determines the actually used tick step from the specified tick step and scale strategy (\ref - setTickStep, \ref setScaleStrategy). - - This method either returns the specified tick step exactly, or, if the scale strategy is not \ref - ssNone, a modification of it to allow varying the number of ticks in the current axis range. - - \seebaseclassmethod -*/ -double QCPAxisTickerFixed::getTickStep(const QCPRange &range) -{ - switch (mScaleStrategy) - { - case ssNone: - { - return mTickStep; - } - case ssMultiples: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - if (exactStep < mTickStep) - return mTickStep; - else - return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; - } - case ssPowers: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); - } - } - return mTickStep; -} -/* end of 'src/axis/axistickerfixed.cpp' */ - - -/* including file 'src/axis/axistickertext.cpp', size 8653 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerText -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerText - \brief Specialized axis ticker which allows arbitrary labels at specified coordinates - - \image html axisticker-text.png - - This QCPAxisTicker subclass generates ticks which can be directly specified by the user as - coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a - time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks - and modify the tick/label data there. - - This is useful for cases where the axis represents categories rather than numerical values. - - If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on - the axis range), it is a sign that you should probably create an own ticker by subclassing - QCPAxisTicker, instead of using this one. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation -*/ - -/* start of documentation of inline functions */ - -/*! \fn QMap &QCPAxisTickerText::ticks() - - Returns a non-const reference to the internal map which stores the tick coordinates and their - labels. - - You can access the map directly in order to add, remove or manipulate ticks, as an alternative to - using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerText::QCPAxisTickerText() : - mSubTickCount(0) -{ -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis - coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QMap &ticks) -{ - mTicks = ticks; -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis - coordinates, and the entries of \a labels are the respective strings that will appear as tick - labels. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) -{ - clear(); - addTicks(positions, labels); -} - -/*! - Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no - automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this - method. -*/ -void QCPAxisTickerText::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! - Clears all ticks. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see setTicks, addTicks, addTick -*/ -void QCPAxisTickerText::clear() -{ - mTicks.clear(); -} - -/*! - Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a - label. - - \see addTicks, setTicks, clear -*/ -void QCPAxisTickerText::addTick(double position, QString label) -{ - mTicks.insert(position, label); -} - -/*! \overload - - Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to - the axis coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QMap &ticks) -{ - mTicks.unite(ticks); -} - -/*! \overload - - Adds the provided ticks to the ones already existing. The entries of \a positions correspond to - the axis coordinates, and the entries of \a labels are the respective strings that will appear as - tick labels. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) -{ - if (positions.size() != labels.size()) - qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); - int n = qMin(positions.size(), labels.size()); - for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (mTicks.isEmpty()) - return result; - - QMap::const_iterator start = mTicks.lowerBound(range.lower); - QMap::const_iterator end = mTicks.upperBound(range.upper); - // this method should try to give one tick outside of range so proper subticks can be generated: - if (start != mTicks.constBegin()) --start; - if (end != mTicks.constEnd()) ++end; - for (QMap::const_iterator it = start; it != end; ++it) - result.append(it.key()); - - return result; -} -/* end of 'src/axis/axistickertext.cpp' */ - - -/* including file 'src/axis/axistickerpi.cpp', size 11170 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerPi -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerPi - \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi - - \image html axisticker-pi.png - - This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic - constant with a numerical value specified with \ref setPiValue and an appearance in the tick - labels specified with \ref setPiSymbol. - - Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the - tick label can be configured with \ref setFractionStyle. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerPi::QCPAxisTickerPi() : - mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), - mPiValue(M_PI), - mPeriodicity(0), - mFractionStyle(fsUnicodeFractions), - mPiTickStep(0) -{ - setTickCount(4); -} - -/*! - Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick - label. - - If a space shall appear between the number and the symbol, make sure the space is contained in \a - symbol. -*/ -void QCPAxisTickerPi::setPiSymbol(QString symbol) -{ - mPiSymbol = symbol; -} - -/*! - Sets the numerical value that the symbolic constant has. - - This will be used to place the appropriate fractions of the symbol at the respective axis - coordinates. -*/ -void QCPAxisTickerPi::setPiValue(double pi) -{ - mPiValue = pi; -} - -/*! - Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the - symbolic constant. - - To disable periodicity, set \a multiplesOfPi to zero. - - For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. -*/ -void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) -{ - mPeriodicity = qAbs(multiplesOfPi); -} - -/*! - Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick - labels. See \ref FractionStyle for the various options. -*/ -void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) -{ - mFractionStyle = style; -} - -/*! \internal - - Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence - the numerical/fractional part preceding the symbolic constant is made to have a readable - mantissa. - - \seebaseclassmethod -*/ -double QCPAxisTickerPi::getTickStep(const QCPRange &range) -{ - mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - mPiTickStep = cleanMantissa(mPiTickStep); - return mPiTickStep*mPiValue; -} - -/*! \internal - - Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In - consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant - reasonably, and not the total tick coordinate. - - \seebaseclassmethod -*/ -int QCPAxisTickerPi::getSubTickCount(double tickStep) -{ - return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); -} - -/*! \internal - - Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The - formatting of the fraction is done according to the specified \ref setFractionStyle. The appended - symbol is specified with \ref setPiSymbol. - - \seebaseclassmethod -*/ -QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - double tickInPis = tick/mPiValue; - if (mPeriodicity > 0) - tickInPis = fmod(tickInPis, mPeriodicity); - - if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) - { - // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above - int denominator = 1000; - int numerator = qRound(tickInPis*denominator); - simplifyFraction(numerator, denominator); - if (qAbs(numerator) == 1 && denominator == 1) - return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else if (numerator == 0) - return QLatin1String("0"); - else - return fractionToString(numerator, denominator) + mPiSymbol; - } else - { - if (qFuzzyIsNull(tickInPis)) - return QLatin1String("0"); - else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) - return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else - return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; - } -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure - the fraction is in irreducible form, i.e. numerator and denominator don't share any common - factors which could be cancelled. -*/ -void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const -{ - if (numerator == 0 || denominator == 0) - return; - - int num = numerator; - int denom = denominator; - while (denom != 0) // euclidean gcd algorithm - { - int oldDenom = denom; - denom = num % denom; - num = oldDenom; - } - // num is now gcd of numerator and denominator - numerator /= num; - denominator /= num; -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and returns a string representation. - The result depends on the configured fraction style (\ref setFractionStyle). - - This method is used to format the numerical/fractional part when generating tick labels. It - simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out - any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). -*/ -QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const -{ - if (denominator == 0) - { - qDebug() << Q_FUNC_INFO << "called with zero denominator"; - return QString(); - } - if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function - { - qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; - return QString::number(numerator/(double)denominator); // failsafe - } - int sign = numerator*denominator < 0 ? -1 : 1; - numerator = qAbs(numerator); - denominator = qAbs(denominator); - - if (denominator == 1) - { - return QString::number(sign*numerator); - } else - { - int integerPart = numerator/denominator; - int remainder = numerator%denominator; - if (remainder == 0) - { - return QString::number(sign*integerPart); - } else - { - if (mFractionStyle == fsAsciiFractions) - { - return QString(QLatin1String("%1%2%3/%4")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) - .arg(remainder) - .arg(denominator); - } else if (mFractionStyle == fsUnicodeFractions) - { - return QString(QLatin1String("%1%2%3")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) - .arg(unicodeFraction(remainder, denominator)); - } - } - } - return QString(); -} - -/*! \internal - - Returns the unicode string representation of the fraction given by \a numerator and \a - denominator. This is the representation used in \ref fractionToString when the fraction style - (\ref setFractionStyle) is \ref fsUnicodeFractions. - - This method doesn't use the single-character common fractions but builds each fraction from a - superscript unicode number, the unicode fraction character, and a subscript unicode number. -*/ -QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const -{ - return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); -} - -/*! \internal - - Returns the unicode string representing \a number as superscript. This is used to build - unicode fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSuperscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2070)); - - QString result; - while (number > 0) - { - const int digit = number%10; - switch (digit) - { - case 1: { result.prepend(QChar(0x00B9)); break; } - case 2: { result.prepend(QChar(0x00B2)); break; } - case 3: { result.prepend(QChar(0x00B3)); break; } - default: { result.prepend(QChar(0x2070+digit)); break; } - } - number /= 10; - } - return result; -} - -/*! \internal - - Returns the unicode string representing \a number as subscript. This is used to build unicode - fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSubscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2080)); - - QString result; - while (number > 0) - { - result.prepend(QChar(0x2080+number%10)); - number /= 10; - } - return result; -} -/* end of 'src/axis/axistickerpi.cpp' */ - - -/* including file 'src/axis/axistickerlog.cpp', size 7106 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerLog -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerLog - \brief Specialized axis ticker suited for logarithmic axes - - \image html axisticker-log.png - - This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic - axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). - - Especially in the case of a log base equal to 10 (the default), it might be desirable to have - tick labels in the form of powers of ten without mantissa display. To achieve this, set the - number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref - QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal - powers, so a format string of "eb". This will result in the following axis tick labels: - - \image html axisticker-log-powers.png - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerLog::QCPAxisTickerLog() : - mLogBase(10.0), - mSubTickCount(8), // generates 10 intervals - mLogBaseLnInv(1.0/qLn(mLogBase)) -{ -} - -/*! - Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer - powers of \a base. -*/ -void QCPAxisTickerLog::setLogBase(double base) -{ - if (base > 0) - { - mLogBase = base; - mLogBaseLnInv = 1.0/qLn(mLogBase); - } else - qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; -} - -/*! - Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced - linearly to provide a better visual guide, so the sub tick density increases toward the higher - tick. - - Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in - the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub - ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, - namely at 20, 30, 40, 50, 60, 70, 80 and 90. -*/ -void QCPAxisTickerLog::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! \internal - - Since logarithmic tick steps are necessarily different for each tick interval, this method does - nothing in the case of QCPAxisTickerLog - - \seebaseclassmethod -*/ -double QCPAxisTickerLog::getTickStep(const QCPRange &range) -{ - // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method - Q_UNUSED(range) - return 1.0; -} - -/*! \internal - - Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no - automatic sub tick count calculation necessary. - - \seebaseclassmethod -*/ -int QCPAxisTickerLog::getSubTickCount(double tickStep) -{ - Q_UNUSED(tickStep) - return mSubTickCount; -} - -/*! \internal - - Creates ticks with a spacing given by the logarithm base and an increasing integer power in the - provided \a range. The step in which the power increases tick by tick is chosen in order to keep - the total number of ticks as close as possible to the tick count (\ref setTickCount). The - parameter \a tickStep is ignored for QCPAxisTickerLog - - \seebaseclassmethod -*/ -QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (range.lower > 0 && range.upper > 0) // positive range - { - double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick *= newLogBase; - result.append(currentTick); - } - } else if (range.lower < 0 && range.upper < 0) // negative range - { - double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick /= newLogBase; - result.append(currentTick); - } - } else // invalid range for logarithmic scale, because lower and upper have different sign - { - qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; - } - - return result; -} -/* end of 'src/axis/axistickerlog.cpp' */ - - -/* including file 'src/axis/axis.cpp', size 99397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGrid - \brief Responsible for drawing the grid of a QCPAxis. - - This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the - grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref - QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. - - The axis and grid drawing was split into two classes to allow them to be placed on different - layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid - in the background and the axes in the foreground, and any plottables/items in between. This - described situation is the default setup, see the QCPLayer documentation. -*/ - -/*! - Creates a QCPGrid instance and sets default values. - - You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. -*/ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), - mParentAxis(parentAxis) -{ - // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); -} - -/*! - Sets whether grid lines at sub tick marks are drawn. - - \see setSubGridPen -*/ -void QCPGrid::setSubGridVisible(bool visible) -{ - mSubGridVisible = visible; -} - -/*! - Sets whether sub grid lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedSubGrid(bool enabled) -{ - mAntialiasedSubGrid = enabled; -} - -/*! - Sets whether zero lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedZeroLine(bool enabled) -{ - mAntialiasedZeroLine = enabled; -} - -/*! - Sets the pen with which (major) grid lines are drawn. -*/ -void QCPGrid::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen with which sub grid lines are drawn. -*/ -void QCPGrid::setSubGridPen(const QPen &pen) -{ - mSubGridPen = pen; -} - -/*! - Sets the pen with which zero lines are drawn. - - Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid - lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. -*/ -void QCPGrid::setZeroLinePen(const QPen &pen) -{ - mZeroLinePen = pen; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing the major grid lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); -} - -/*! \internal - - Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning - over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). -*/ -void QCPGrid::draw(QCPPainter *painter) -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mParentAxis->subTicks() && mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); -} - -/*! \internal - - Draws the main grid lines and possibly a zero line with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - const int tickCount = mParentAxis->mTickVector.size(); - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - -/*! \internal - - Draws the sub grid lines with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxis -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxis - \brief Manages a single axis inside a QCustomPlot. - - Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via - QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and - QCustomPlot::yAxis2 (right). - - Axes are always part of an axis rect, see QCPAxisRect. - \image html AxisNamesOverview.png -
Naming convention of axis parts
- \n - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line - on the left represents the QCustomPlot widget border.
- - Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and - tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of - the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the - documentation of QCPAxisTicker. -*/ - -/* start of documentation of inline functions */ - -/*! \fn Qt::Orientation QCPAxis::orientation() const - - Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced - from the axis type (left, top, right or bottom). - - \see orientation(AxisType type), pixelOrientation -*/ - -/*! \fn QCPGrid *QCPAxis::grid() const - - Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the - grid is displayed. -*/ - -/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) - - Returns the orientation of the specified axis type - - \see orientation(), pixelOrientation -*/ - -/*! \fn int QCPAxis::pixelOrientation() const - - Returns which direction points towards higher coordinate values/keys, in pixel space. - - This method returns either 1 or -1. If it returns 1, then going in the positive direction along - the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. - On the other hand, if this method returns -1, going to smaller pixel values corresponds to going - from lower to higher axis coordinates. - - For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, - without having to care about reversed or vertically aligned axes: - - \code - double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); - \endcode - - \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. -*/ - -/*! \fn QSharedPointer QCPAxis::ticker() const - - Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is - responsible for generating the tick positions and tick labels of this axis. You can access the - \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count - (\ref QCPAxisTicker::setTickCount). - - You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see - the documentation there. A new axis ticker can be set with \ref setTicker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see setTicker -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) - - This signal is emitted when the range of this axis has changed. You can connect it to the \ref - setRange slot of another axis to communicate the new range to the other axis, in order for it to - be synchronized. - - You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. - This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper - range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following - slot would limit the x axis to ranges between 0 and 10: - \code - customPlot->xAxis->setRange(newRange.bounded(0, 10)) - \endcode -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) - \overload - - Additionally to the new range, this signal also provides the previous range held by the axis as - \a oldRange. -*/ - -/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the scale type changes, by calls to \ref setScaleType -*/ - -/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) - - This signal is emitted when the selection state of this axis has changed, either by user interaction - or by a direct call to \ref setSelectedParts. -*/ - -/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); - - This signal is emitted when the selectability changes, by calls to \ref setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs an Axis instance of Type \a type for the axis rect \a parent. - - Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create - them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, - create them manually and then inject them also via \ref QCPAxisRect::addAxis. -*/ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), QString(), parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mTicker(new QCPAxisTicker), - mCachedMarginValid(false), - mCachedMargin(0) -{ - setParent(parent); - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) - { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) - { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) - { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) - { - setTickLabelPadding(5); - setLabelPadding(10); - } -} - -QCPAxis::~QCPAxis() -{ - delete mAxisPainter; - delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLabelPadding() const -{ - return mAxisPainter->tickLabelPadding; -} - -/* No documentation as it is a property getter */ -double QCPAxis::tickLabelRotation() const -{ - return mAxisPainter->tickLabelRotation; -} - -/* No documentation as it is a property getter */ -QCPAxis::LabelSide QCPAxis::tickLabelSide() const -{ - return mAxisPainter->tickLabelSide; -} - -/* No documentation as it is a property getter */ -QString QCPAxis::numberFormat() const -{ - QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) - { - result.append(QLatin1Char('b')); - if (mAxisPainter->numberMultiplyCross) - result.append(QLatin1Char('c')); - } - return result; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthIn() const -{ - return mAxisPainter->tickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthOut() const -{ - return mAxisPainter->tickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthIn() const -{ - return mAxisPainter->subTickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthOut() const -{ - return mAxisPainter->subTickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::labelPadding() const -{ - return mAxisPainter->labelPadding; -} - -/* No documentation as it is a property getter */ -int QCPAxis::offset() const -{ - return mAxisPainter->offset; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::lowerEnding() const -{ - return mAxisPainter->lowerEnding; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::upperEnding() const -{ - return mAxisPainter->upperEnding; -} - -/*! - Sets whether the axis uses a linear scale or a logarithmic scale. - - Note that this method controls the coordinate transformation. You will likely also want to use a - logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref - QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the - details of logarithmic axis tick creation. - - \ref setNumberPrecision -*/ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) -{ - if (mScaleType != type) - { - mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); - mCachedMarginValid = false; - Q_EMIT scaleTypeChanged(mScaleType); - } -} - -/*! - Sets the range of the axis. - - This slot may be connected with the \ref rangeChanged signal of another axis so this axis - is always synchronized with the other axis range, when it changes. - - To invert the direction of an axis, use \ref setRangeReversed. -*/ -void QCPAxis::setRange(const QCPRange &range) -{ - if (range.lower == mRange.lower && range.upper == mRange.upper) - return; - - if (!QCPRange::validRange(range)) return; - QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) - { - mRange = range.sanitizedForLogScale(); - } else - { - mRange = range.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectAxes.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font. - - The entire selection mechanism for axes is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you - wish to change the selection state manually. - - This function can change the selection state of a part, independent of the \ref setSelectableParts setting. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, - setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor -*/ -void QCPAxis::setSelectedParts(const SelectableParts &selected) -{ - if (mSelectedParts != selected) - { - mSelectedParts = selected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - \overload - - Sets the lower and upper bound of the axis range. - - To invert the direction of an axis, use \ref setRangeReversed. - - There is also a slot to set a range, see \ref setRange(const QCPRange &range). -*/ -void QCPAxis::setRange(double lower, double upper) -{ - if (lower == mRange.lower && upper == mRange.upper) - return; - - if (!QCPRange::validRange(lower, upper)) return; - QCPRange oldRange = mRange; - mRange.lower = lower; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - \overload - - Sets the range of the axis. - - The \a position coordinate indicates together with the \a alignment parameter, where the new - range will be positioned. \a size defines the size of the new axis range. \a alignment may be - Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, - or center of the range to be aligned with \a position. Any other values of \a alignment will - default to Qt::AlignCenter. -*/ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) -{ - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); -} - -/*! - Sets the lower bound of the axis range. The upper bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeLower(double lower) -{ - if (mRange.lower == lower) - return; - - QCPRange oldRange = mRange; - mRange.lower = lower; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets the upper bound of the axis range. The lower bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeUpper(double upper) -{ - if (mRange.upper == upper) - return; - - QCPRange oldRange = mRange; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal - axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the - direction of increasing values is inverted. - - Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part - of the \ref setRange interface will still reference the mathematically smaller number than the \a - upper part. -*/ -void QCPAxis::setRangeReversed(bool reversed) -{ - mRangeReversed = reversed; -} - -/*! - The axis ticker is responsible for generating the tick positions and tick labels. See the - documentation of QCPAxisTicker for details on how to work with axis tickers. - - You can change the tick positioning/labeling behaviour of this axis by setting a different - QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis - ticker, access it via \ref ticker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see ticker -*/ -void QCPAxis::setTicker(QSharedPointer ticker) -{ - if (ticker) - mTicker = ticker; - else - qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; - // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector -} - -/*! - Sets whether tick marks are displayed. - - Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve - that, see \ref setTickLabels. - - \see setSubTicks -*/ -void QCPAxis::setTicks(bool show) -{ - if (mTicks != show) - { - mTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. -*/ -void QCPAxis::setTickLabels(bool show) -{ - if (mTickLabels != show) - { - mTickLabels = show; - mCachedMarginValid = false; - if (!mTickLabels) - mTickVectorLabels.clear(); - } -} - -/*! - Sets the distance between the axis base line (including any outward ticks) and the tick labels. - \see setLabelPadding, setPadding -*/ -void QCPAxis::setTickLabelPadding(int padding) -{ - if (mAxisPainter->tickLabelPadding != padding) - { - mAxisPainter->tickLabelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the font of the tick labels. - - \see setTickLabels, setTickLabelColor -*/ -void QCPAxis::setTickLabelFont(const QFont &font) -{ - if (font != mTickLabelFont) - { - mTickLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the tick labels. - - \see setTickLabels, setTickLabelFont -*/ -void QCPAxis::setTickLabelColor(const QColor &color) -{ - mTickLabelColor = color; -} - -/*! - Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, - the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values - from -90 to 90 degrees. - - If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For - other angles, the label is drawn with an offset such that it seems to point toward or away from - the tick mark. -*/ -void QCPAxis::setTickLabelRotation(double degrees) -{ - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) - { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. - - The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels - to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels - appear on the inside are additionally clipped to the axis rect. -*/ -void QCPAxis::setTickLabelSide(LabelSide side) -{ - mAxisPainter->tickLabelSide = side; - mCachedMarginValid = false; -} - -/*! - Sets the number format for the numbers in tick labels. This \a formatCode is an extended version - of the format code used e.g. by QString::number() and QLocale::toString(). For reference about - that, see the "Argument Formats" section in the detailed description of the QString class. - - \a formatCode is a string of one, two or three characters. The first character is identical to - the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed - format, 'g'/'G' scientific or fixed, whichever is shorter. - - The second and third characters are optional and specific to QCustomPlot:\n - If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. - "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for - "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 - [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. - If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can - be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the - cross and 183 (0xB7) for the dot. - - Examples for \a formatCode: - \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, - normal scientific format is used - \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with - beautifully typeset decimal powers and a dot as multiplication sign - \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as - multiplication sign - \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal - powers. Format code will be reduced to 'f'. - \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format - code will not be changed. -*/ -void QCPAxis::setNumberFormat(const QString &formatCode) -{ - if (formatCode.isEmpty()) - { - qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; - return; - } - mCachedMarginValid = false; - - // interpret first char as number format char: - QString allowedFormatChars(QLatin1String("eEfgG")); - if (allowedFormatChars.contains(formatCode.at(0))) - { - mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; - return; - } - if (formatCode.length() < 2) - { - mNumberBeautifulPowers = false; - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) - { - mNumberBeautifulPowers = true; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - return; - } - if (formatCode.length() < 3) - { - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == QLatin1Char('c')) - { - mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == QLatin1Char('d')) - { - mAxisPainter->numberMultiplyCross = false; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; - return; - } -} - -/*! - Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) - for details. The effect of precisions are most notably for number Formats starting with 'e', see - \ref setNumberFormat -*/ -void QCPAxis::setNumberPrecision(int precision) -{ - if (mNumberPrecision != precision) - { - mNumberPrecision = precision; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the - plot and \a outside is the length they will reach outside the plot. If \a outside is greater than - zero, the tick labels and axis label will increase their distance to the axis accordingly, so - they won't collide with the ticks. - - \see setSubTickLength, setTickLengthIn, setTickLengthOut -*/ -void QCPAxis::setTickLength(int inside, int outside) -{ - setTickLengthIn(inside); - setTickLengthOut(outside); -} - -/*! - Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach - inside the plot. - - \see setTickLengthOut, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthIn(int inside) -{ - if (mAxisPainter->tickLengthIn != inside) - { - mAxisPainter->tickLengthIn = inside; - } -} - -/*! - Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach - outside the plot. If \a outside is greater than zero, the tick labels and axis label will - increase their distance to the axis accordingly, so they won't collide with the ticks. - - \see setTickLengthIn, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthOut(int outside) -{ - if (mAxisPainter->tickLengthOut != outside) - { - mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets whether sub tick marks are displayed. - - Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) - - \see setTicks -*/ -void QCPAxis::setSubTicks(bool show) -{ - if (mSubTicks != show) - { - mSubTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside - the plot and \a outside is the length they will reach outside the plot. If \a outside is greater - than zero, the tick labels and axis label will increase their distance to the axis accordingly, - so they won't collide with the ticks. - - \see setTickLength, setSubTickLengthIn, setSubTickLengthOut -*/ -void QCPAxis::setSubTickLength(int inside, int outside) -{ - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); -} - -/*! - Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside - the plot. - - \see setSubTickLengthOut, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthIn(int inside) -{ - if (mAxisPainter->subTickLengthIn != inside) - { - mAxisPainter->subTickLengthIn = inside; - } -} - -/*! - Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach - outside the plot. If \a outside is greater than zero, the tick labels will increase their - distance to the axis accordingly, so they won't collide with the ticks. - - \see setSubTickLengthIn, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthOut(int outside) -{ - if (mAxisPainter->subTickLengthOut != outside) - { - mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the pen, the axis base line is drawn with. - - \see setTickPen, setSubTickPen -*/ -void QCPAxis::setBasePen(const QPen &pen) -{ - mBasePen = pen; -} - -/*! - Sets the pen, tick marks will be drawn with. - - \see setTickLength, setBasePen -*/ -void QCPAxis::setTickPen(const QPen &pen) -{ - mTickPen = pen; -} - -/*! - Sets the pen, subtick marks will be drawn with. - - \see setSubTickCount, setSubTickLength, setBasePen -*/ -void QCPAxis::setSubTickPen(const QPen &pen) -{ - mSubTickPen = pen; -} - -/*! - Sets the font of the axis label. - - \see setLabelColor -*/ -void QCPAxis::setLabelFont(const QFont &font) -{ - if (mLabelFont != font) - { - mLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the axis label. - - \see setLabelFont -*/ -void QCPAxis::setLabelColor(const QColor &color) -{ - mLabelColor = color; -} - -/*! - Sets the text of the axis label that will be shown below/above or next to the axis, depending on - its orientation. To disable axis labels, pass an empty string as \a str. -*/ -void QCPAxis::setLabel(const QString &str) -{ - if (mLabel != str) - { - mLabel = str; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the tick labels and the axis label. - - \see setTickLabelPadding, setPadding -*/ -void QCPAxis::setLabelPadding(int padding) -{ - if (mAxisPainter->labelPadding != padding) - { - mAxisPainter->labelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the padding of the axis. - - When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, - that is left blank. - - The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. - - \see setLabelPadding, setTickLabelPadding -*/ -void QCPAxis::setPadding(int padding) -{ - if (mPadding != padding) - { - mPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the offset the axis has to its axis rect side. - - If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, - only the offset of the inner most axis has meaning (even if it is set to be invisible). The - offset of the other, outer axes is controlled automatically, to place them at appropriate - positions. -*/ -void QCPAxis::setOffset(int offset) -{ - mAxisPainter->offset = offset; -} - -/*! - Sets the font that is used for tick labels when they are selected. - - \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) -{ - if (font != mSelectedTickLabelFont) - { - mSelectedTickLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts - } -} - -/*! - Sets the font that is used for the axis label when it is selected. - - \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelFont(const QFont &font) -{ - mSelectedLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts -} - -/*! - Sets the color that is used for tick labels when they are selected. - - \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) -{ - if (color != mSelectedTickLabelColor) - { - mSelectedTickLabelColor = color; - } -} - -/*! - Sets the color that is used for the axis label when it is selected. - - \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelColor(const QColor &color) -{ - mSelectedLabelColor = color; -} - -/*! - Sets the pen that is used to draw the axis base line when selected. - - \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedBasePen(const QPen &pen) -{ - mSelectedBasePen = pen; -} - -/*! - Sets the pen that is used to draw the (major) ticks when selected. - - \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickPen(const QPen &pen) -{ - mSelectedTickPen = pen; -} - -/*! - Sets the pen that is used to draw the subticks when selected. - - \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) -{ - mSelectedSubTickPen = pen; -} - -/*! - Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setUpperEnding -*/ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) -{ - mAxisPainter->lowerEnding = ending; -} - -/*! - Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the right ending, for vertical axes the top ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setLowerEnding -*/ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) -{ - mAxisPainter->upperEnding = ending; -} - -/*! - If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper - bounds of the range. The range is simply moved by \a diff. - - If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This - corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). -*/ -void QCPAxis::moveRange(double diff) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - mRange.lower += diff; - mRange.upper += diff; - } else // mScaleType == stLogarithmic - { - mRange.lower *= diff; - mRange.upper *= diff; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis by \a factor around the center of the current axis range. For - example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis - range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around - the center will have moved symmetrically closer). - - If you wish to scale around a different coordinate than the current axis range center, use the - overload \ref scaleRange(double factor, double center). -*/ -void QCPAxis::scaleRange(double factor) -{ - scaleRange(factor, range().center()); -} - -/*! \overload - - Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a - factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at - coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates - around 1.0 will have moved symmetrically closer to 1.0). - - \see scaleRange(double factor) -*/ -void QCPAxis::scaleRange(double factor, double center) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic - { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range - { - QCPRange newRange; - newRange.lower = qPow(mRange.lower/center, factor)*center; - newRange.upper = qPow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLogScale(); - } else - qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will - be done around the center of the current axis range. - - For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs - plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the - axis rect has. - - This is an operation that changes the range of this axis once, it doesn't fix the scale ratio - indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent - won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent - will follow. -*/ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) -{ - int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) - otherPixelSize = otherAxis->axisRect()->width(); - else - otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) - ownPixelSize = axisRect()->width(); - else - ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); -} - -/*! - Changes the axis range such that all plottables associated with this axis are fully visible in - that dimension. - - \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPAxis::rescale(bool onlyVisiblePlottables) -{ - QList p = plottables(); - QCPRange newRange; - bool haveRange = false; - for (int i=0; irealVisibility() && onlyVisiblePlottables) - continue; - QCPRange plottableRange; - bool currentFoundRange; - QCP::SignDomain signDomain = QCP::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); - else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) - { - if (!haveRange) - newRange = plottableRange; - else - newRange.expand(plottableRange); - haveRange = true; - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) - { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); - } - } - setRange(newRange); - } -} - -/*! - Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. -*/ -double QCPAxis::pixelToCoord(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; - else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; - else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; - } - } -} - -/*! - Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. -*/ -double QCPAxis::coordToPixel(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; - else - { - if (!mRangeReversed) - return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - else - return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - } - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); - else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; - else - { - if (!mRangeReversed) - return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - else - return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - } - } - } -} - -/*! - Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function - is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this - function does not change the current selection state of the axis. - - If the axis is not visible (\ref setVisible), this function always returns \ref spNone. - - \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions -*/ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const -{ - if (!mVisible) - return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) - return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) - return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) - return spAxisLabel; - else - return spNone; -} - -/* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) - return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; -} - -/*! - Returns a list of all the plottables that have this axis as key or value axis. - - If you are only interested in plottables of type QCPGraph, see \ref graphs. - - \see graphs, items -*/ -QList QCPAxis::plottables() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that have this axis as key or value axis. - - \see plottables, items -*/ -QList QCPAxis::graphs() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis. An item is considered - associated with an axis if at least one of its positions uses the axis as key or value axis. - - \see plottables, graphs -*/ -QList QCPAxis::items() const -{ - QList result; - if (!mParentPlot) return result; - - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to - QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) -*/ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; - } - qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; - return atLeft; -} - -/*! - Returns the axis type that describes the opposite axis of an axis with the specified \a type. -*/ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) -{ - switch (type) - { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; - } -} - -/* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - SelectablePart part = details.value(); - if (mSelectableParts.testFlag(part)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) -{ - SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis - (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref - QCPAxisRect::setRangeDragAxes) - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. -*/ -void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || - !mAxisRect->rangeDrag().testFlag(orientation()) || - !mAxisRect->rangeDragAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - mDragStartRange = mRange; - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (mDragging) - { - const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); - const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); - if (mScaleType == QCPAxis::stLinear) - { - const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); - setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); - } else if (mScaleType == QCPAxis::stLogarithmic) - { - const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); - setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); - } - - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user zoom individual axes - exclusively, by performing the wheel event on top of the axis. - - For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis - (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref - QCPAxisRect::setRangeZoomAxes) - - \seebaseclassmethod - - \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the - axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. -*/ -void QCPAxis::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || - !mAxisRect->rangeZoom().testFlag(orientation()) || - !mAxisRect->rangeZoomAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); - scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); - mParentPlot->replot(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing axis lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); -} - -/*! \internal - - Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. - - \seebaseclassmethod -*/ -void QCPAxis::draw(QCPPainter *painter) -{ - QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->basePen = getBasePen(); - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->labelColor = getLabelColor(); - mAxisPainter->label = mLabel; - mAxisPainter->substituteExponent = mNumberBeautifulPowers; - mAxisPainter->tickPen = getTickPen(); - mAxisPainter->subTickPen = getSubTickPen(); - mAxisPainter->tickLabelFont = getTickLabelFont(); - mAxisPainter->tickLabelColor = getTickLabelColor(); - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; - mAxisPainter->reversedEndings = mRangeReversed; - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); -} - -/*! \internal - - Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling - QCPAxisTicker::generate on the currently installed ticker. - - If a change in the label text/count is detected, the cached axis margin is invalidated to make - sure the next margin calculation recalculates the label sizes and returns an up-to-date value. -*/ -void QCPAxis::setupTickVectors() -{ - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - - QVector oldLabels = mTickVectorLabels; - mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too -} - -/*! \internal - - Returns the pen that is used to draw the axis base line. Depending on the selection state, this - is either mSelectedBasePen or mBasePen. -*/ -QPen QCPAxis::getBasePen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; -} - -/*! \internal - - Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this - is either mSelectedTickPen or mTickPen. -*/ -QPen QCPAxis::getTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; -} - -/*! \internal - - Returns the pen that is used to draw the subticks. Depending on the selection state, this - is either mSelectedSubTickPen or mSubTickPen. -*/ -QPen QCPAxis::getSubTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; -} - -/*! \internal - - Returns the font that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelFont or mTickLabelFont. -*/ -QFont QCPAxis::getTickLabelFont() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; -} - -/*! \internal - - Returns the font that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelFont or mLabelFont. -*/ -QFont QCPAxis::getLabelFont() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; -} - -/*! \internal - - Returns the color that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelColor or mTickLabelColor. -*/ -QColor QCPAxis::getTickLabelColor() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; -} - -/*! \internal - - Returns the color that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelColor or mLabelColor. -*/ -QColor QCPAxis::getLabelColor() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; -} - -/*! \internal - - Returns the appropriate outward margin for this axis. It is needed if \ref - QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref - atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom - margin and so forth. For the calculation, this function goes through similar steps as \ref draw, - so changing one function likely requires the modification of the other one as well. - - The margin consists of the outward tick length, tick label padding, tick label size, label - padding, label size, and padding. - - The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. - unchanged are very fast. -*/ -int QCPAxis::calculateMargin() -{ - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis - return 0; - - if (mCachedMarginValid) - return mCachedMargin; - - // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels - int margin = 0; - - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->label = mLabel; - mAxisPainter->tickLabelFont = mTickLabelFont; - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - margin += mAxisPainter->size(); - margin += mPadding; - - mCachedMargin = margin; - mCachedMarginValid = true; - return margin; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAxis::selectionCategory() const -{ - return QCP::iSelectAxes; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisPainterPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisPainterPrivate - - \internal - \brief (Private) - - This is a private class and not part of the public QCustomPlot interface. - - It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and - axis label. It also buffers the labels to reduce replot times. The parameters are configured by - directly accessing the public member variables. -*/ - -/*! - Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every - redraw, to utilize the caching mechanisms. -*/ -QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : - type(QCPAxis::atLeft), - basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - lowerEnding(QCPLineEnding::esNone), - upperEnding(QCPLineEnding::esNone), - labelPadding(0), - tickLabelPadding(0), - tickLabelRotation(0), - tickLabelSide(QCPAxis::lsOutside), - substituteExponent(true), - numberMultiplyCross(false), - tickLengthIn(5), - tickLengthOut(0), - subTickLengthIn(2), - subTickLengthOut(0), - tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - offset(0), - abbreviateDecimalPowers(false), - reversedEndings(false), - mParentPlot(parentPlot), - mLabelCache(16) // cache at most 16 (tick) labels -{ -} - -QCPAxisPainterPrivate::~QCPAxisPainterPrivate() -{ -} - -/*! \internal - - Draws the axis with the specified \a painter. - - The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set - here, too. -*/ -void QCPAxisPainterPrivate::draw(QCPPainter *painter) -{ - QByteArray newHash = generateLabelParameterHash(); - if (newHash != mLabelParameterHash) - { - mLabelCache.clear(); - mLabelParameterHash = newHash; - } - - QPoint origin; - switch (type) - { - case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; - case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; - case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; - case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; - } - - double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) - switch (type) - { - case QCPAxis::atTop: yCor = -1; break; - case QCPAxis::atRight: xCor = 1; break; - default: break; - } - int margin = 0; - // draw baseline: - QLineF baseLine; - painter->setPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); - else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - - // draw ticks: - if (!tickPositions.isEmpty()) - { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); - } - } - - // draw subticks: - if (!subTickPositions.isEmpty()) - { - painter->setPen(subTickPen); - // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); - } - } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // draw axis base endings: - bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - - // tick labels: - QRect oldClipRect; - if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect - { - oldClipRect = painter->clipRegion().boundingRect(); - painter->setClipRect(axisRect); - } - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) - { - if (tickLabelSide == QCPAxis::lsOutside) - margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); - int distanceToAxis = margin; - if (tickLabelSide == QCPAxis::lsInside) - distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - for (int i=0; isetClipRect(oldClipRect); - - // axis label: - QRect labelBounds; - if (!label.isEmpty()) - { - margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atRight) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); - painter->rotate(90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - } - - // set selection boxes: - int selectionTolerance = 0; - if (mParentPlot) - selectionTolerance = mParentPlot->selectionTolerance(); - else - qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); - int selAxisInSize = selectionTolerance; - int selTickLabelSize; - int selTickLabelOffset; - if (tickLabelSide == QCPAxis::lsOutside) - { - selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - } else - { - selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - } - int selLabelSize = labelBounds.height(); - int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; - if (type == QCPAxis::atLeft) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atRight) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atTop) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); - } - mAxisSelectionBox = mAxisSelectionBox.normalized(); - mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); - mLabelSelectionBox = mLabelSelectionBox.normalized(); - // draw hitboxes for debug purposes: - //painter->setBrush(Qt::NoBrush); - //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); -} - -/*! \internal - - Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone - direction) needed to fit the axis. -*/ -int QCPAxisPainterPrivate::size() const -{ - int result = 0; - - // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // calculate size of tick labels: - if (tickLabelSide == QCPAxis::lsOutside) - { - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) - { - for (int i=0; ibufferDevicePixelRatio())); - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)tickLabelSide)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString().toLatin1()); - return result; -} - -/*! \internal - - Draws a single tick label with the provided \a painter, utilizing the internal label cache to - significantly speed up drawing of labels that were drawn in previous calls. The tick label is - always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in - pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence - for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), - at which the label should be drawn. - - In order to later draw the axis label in a place that doesn't overlap with the tick labels, the - largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref - drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a - tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently - holds. - - The label is drawn with the font and pen that are currently set on the \a painter. To draw - superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref - getTickLabelData). -*/ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) -{ - // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; - QSize finalSize; - QPointF labelAnchor; - switch (type) - { - case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; - } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled - { - CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache - if (!cachedLabel) // no cached label existed, create it - { - cachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); - if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) - { - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); -# else - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); -# endif -#endif - } else - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - cachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&cachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); - } - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); - else - labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } - mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created - } else // label caching disabled, draw text directly on surface: - { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); - else - labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); - finalSize = labelData.rotatedTotalBounds.size(); - } - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a - y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to - directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when - QCP::phCacheLabels plotting hint is not set. -*/ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const -{ - // backup painter settings that we're about to change: - QTransform oldTransform = painter->transform(); - QFont oldFont = painter->font(); - - // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - - // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - if (!labelData.suffixPart.isEmpty()) - painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); - } - - // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Transforms the passed \a text and \a font to a tickLabelData structure that can then be further - processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and - exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. -*/ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const -{ - TickLabelData result; - - // determine whether beautiful decimal powers should be used - bool useBeautifulPowers = false; - int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart - int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart - if (substituteExponent) - { - ePos = text.indexOf(QLatin1Char('e')); - if (ePos > 0 && text.at(ePos-1).isDigit()) - { - eLast = ePos; - while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) - ++eLast; - if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power - useBeautifulPowers = true; - } - } - - // calculate text bounding rects and do string preparation for beautiful decimal powers: - result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) - { - // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent - // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) - result.basePart = QLatin1String("10"); - else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); - result.expPart = text.mid(ePos+1, eLast-ePos); - // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) - result.expPart.remove(0, 1); - // prepare smaller font for exponent: - result.expFont = font; - if (result.expFont.pointSize() > 0) - result.expFont.setPointSize(result.expFont.pointSize()*0.75); - else - result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); - // calculate bounding rects of base part(s), exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - if (!result.suffixPart.isEmpty()) - result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false - { - result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); - } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - - // calculate possibly different bounding rect after rotation: - result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) - { - QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); - } - - return result; -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Calculates the offset at which the top left corner of the specified tick label shall be drawn. - The offset is relative to a point right next to the tick the label belongs to. - - This function is thus responsible for e.g. centering tick labels under ticks and positioning them - appropriately when they are rotated. -*/ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const -{ - /* - calculate label offset from base point at tick (non-trivial, for best visual appearance): short - explanation for bottom axis: The anchor, i.e. the point in the label that is placed - horizontally under the corresponding tick is always on the label side that is closer to the - axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height - is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text - will be centered under the tick (i.e. displaced horizontally by half its height). At the same - time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick - labels. - */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = 0; - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = -labelData.totalBounds.height(); - } - } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; - y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = 0; - } - } - - return QPointF(x, y); -} - -/*! \internal - - Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label - to be drawn, depending on number format etc. Since only the largest tick label is wanted for the - margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a - smaller width/height. -*/ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const -{ - // note: this function must return the same tick label sizes as the placeTickLabel function. - QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label - { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } else // label caching disabled or no label with this text cached: - { - TickLabelData labelData = getTickLabelData(font, text); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} -/* end of 'src/axis/axis.cpp' */ - - -/* including file 'src/scatterstyle.cpp', size 17450 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPScatterStyle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPScatterStyle - \brief Represents the visual appearance of scatter points - - This class holds information about shape, color and size of scatter points. In plottables like - QCPGraph it is used to store how scatter points shall be drawn. For example, \ref - QCPGraph::setScatterStyle takes a QCPScatterStyle instance. - - A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a - fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can - be controlled with \ref setSize. - - \section QCPScatterStyle-defining Specifying a scatter style - - You can set all these configurations either by calling the respective functions on an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 - - Or you can use one of the various constructors that take different parameter combinations, making - it easy to specify a scatter style in a single call, like so: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 - - \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable - - There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref - QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref - isPenDefined will return false. It leads to scatter points that inherit the pen from the - plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line - color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes - it very convenient to set up typical scatter settings: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation - - Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works - because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly - into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) - constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref - ScatterShape, where actually a QCPScatterStyle is expected. - - \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps - - QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. - - For custom shapes, you can provide a QPainterPath with the desired shape to the \ref - setCustomPath function or call the constructor that takes a painter path. The scatter shape will - automatically be set to \ref ssCustom. - - For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the - constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. - Note that \ref setSize does not influence the appearance of the pixmap. -*/ - -/* start documentation of inline functions */ - -/*! \fn bool QCPScatterStyle::isNone() const - - Returns whether the scatter shape is \ref ssNone. - - \see setShape -*/ - -/*! \fn bool QCPScatterStyle::isPenDefined() const - - Returns whether a pen has been defined for this scatter style. - - The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those - are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen - is undefined, the pen of the respective plottable will be used for drawing scatters. - - If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call - \ref undefinePen. - - \see setPen -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or - brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - and size to \a size. No brush is defined, i.e. the scatter point will not be filled. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - the brush color to \a fill (with a solid pattern), and size to \a size. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the - brush to \a brush, and size to \a size. - - \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen - and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n - QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n - doesn't necessarily lead C++ to use this constructor in some cases, but might mistake - Qt::NoPen for a QColor and use the - \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) - constructor instead (which will lead to an unexpected look of the scatter points). To prevent - this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) - instead of just Qt::blue, to clearly point out to the compiler that this constructor is - wanted. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape - is set to \ref ssPixmap. -*/ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The - scatter shape is set to \ref ssCustom. - - The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly - different meaning than for built-in scatter points: The custom path will be drawn scaled by a - factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its - original size by default. To for example double the size of the path, set \a size to 12. -*/ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Copies the specified \a properties from the \a other scatter style to this scatter style. -*/ -void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) -{ - if (properties.testFlag(spPen)) - { - setPen(other.pen()); - if (!other.isPenDefined()) - undefinePen(); - } - if (properties.testFlag(spBrush)) - setBrush(other.brush()); - if (properties.testFlag(spSize)) - setSize(other.size()); - if (properties.testFlag(spShape)) - { - setShape(other.shape()); - if (other.shape() == ssPixmap) - setPixmap(other.pixmap()); - else if (other.shape() == ssCustom) - setCustomPath(other.customPath()); - } -} - -/*! - Sets the size (pixel diameter) of the drawn scatter points to \a size. - - \see setShape -*/ -void QCPScatterStyle::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the shape to \a shape. - - Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref - ssPixmap and \ref ssCustom, respectively. - - \see setSize -*/ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) -{ - mShape = shape; -} - -/*! - Sets the pen that will be used to draw scatter points to \a pen. - - If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after - a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen - previously by calling this function and now wish to undefine the pen, call \ref undefinePen. - - \see setBrush -*/ -void QCPScatterStyle::setPen(const QPen &pen) -{ - mPenDefined = true; - mPen = pen; -} - -/*! - Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter - shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. - - \see setPen -*/ -void QCPScatterStyle::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the pixmap that will be drawn as scatter point to \a pixmap. - - Note that \ref setSize does not influence the appearance of the pixmap. - - The scatter shape is automatically set to \ref ssPixmap. -*/ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) -{ - setShape(ssPixmap); - mPixmap = pixmap; -} - -/*! - Sets the custom shape that will be drawn as scatter point to \a customPath. - - The scatter shape is automatically set to \ref ssCustom. -*/ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) -{ - setShape(ssCustom); - mCustomPath = customPath; -} - -/*! - Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen - implies). - - A call to \ref setPen will define a pen. -*/ -void QCPScatterStyle::undefinePen() -{ - mPenDefined = false; -} - -/*! - Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an - undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. - - This function is used by plottables (or any class that wants to draw scatters) just before a - number of scatters with this style shall be drawn with the \a painter. - - \see drawShape -*/ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const -{ - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); -} - -/*! - Draws the scatter shape with \a painter at position \a pos. - - This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be - called before scatter points are drawn with \ref drawShape. - - \see applyTo -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const -{ - drawShape(painter, pos.x(), pos.y()); -} - -/*! \overload - Draws the scatter shape with \a painter at position \a x and \a y. -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const -{ - double w = mSize/2.0; - switch (mShape) - { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - QPointF lineArray[4] = {QPointF(x-w, y), - QPointF( x, y-w), - QPointF(x+w, y), - QPointF( x, y+w)}; - painter->drawPolygon(lineArray, 4); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), - QPointF(x+w, y+0.755*w), - QPointF( x, y-0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssTriangleInverted: - { - QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), - QPointF(x+w, y-0.755*w), - QPointF( x, y+0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssCrossSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - break; - } - case ssPlusSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCrossCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - break; - } - case ssPlusCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssPeace: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - break; - } - case ssPixmap: - { - const double widthHalf = mPixmap.width()*0.5; - const double heightHalf = mPixmap.height()*0.5; -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) - const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#else - const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#endif - if (clipRect.contains(x, y)) - painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } - } -} -/* end of 'src/scatterstyle.cpp' */ - -//amalgamation: add datacontainer.cpp - -/* including file 'src/plottable.cpp', size 38845 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecorator -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecorator - \brief Controls how a plottable's data selection is drawn - - Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref - QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. - - The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the - scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref - QCPScatterStyle is itself composed of different properties such as color shape and size, the - decorator allows specifying exactly which of those properties shall be used for the selected data - point, via \ref setUsedScatterProperties. - - A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref - QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance - of selected segments. - - Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is - especially useful since plottables take ownership of the passed selection decorator, and thus the - same decorator instance can not be passed to multiple plottables. - - Selection decorators can also themselves perform drawing operations by reimplementing \ref - drawDecoration, which is called by the plottable's draw method. The base class \ref - QCPSelectionDecorator does not make use of this however. For example, \ref - QCPSelectionDecoratorBracket draws brackets around selected data segments. -*/ - -/*! - Creates a new QCPSelectionDecorator instance with default values -*/ -QCPSelectionDecorator::QCPSelectionDecorator() : - mPen(QColor(80, 80, 255), 2.5), - mBrush(Qt::NoBrush), - mScatterStyle(), - mUsedScatterProperties(QCPScatterStyle::spNone), - mPlottable(0) -{ -} - -QCPSelectionDecorator::~QCPSelectionDecorator() -{ -} - -/*! - Sets the pen that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the scatter style that will be used by the parent plottable to draw scatters in selected - data segments. - - \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the - plottable. The used properties can also be changed via \ref setUsedScatterProperties. -*/ -void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) -{ - mScatterStyle = scatterStyle; - setUsedScatterProperties(usedProperties); -} - -/*! - Use this method to define which properties of the scatter style (set via \ref setScatterStyle) - will be used for selected data segments. All properties of the scatter style that are not - specified in \a properties will remain as specified in the plottable's original scatter style. - - \see QCPScatterStyle::ScatterProperty -*/ -void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) -{ - mUsedScatterProperties = properties; -} - -/*! - Sets the pen of \a painter to the pen of this selection decorator. - - \see applyBrush, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyPen(QCPPainter *painter) const -{ - painter->setPen(mPen); -} - -/*! - Sets the brush of \a painter to the brush of this selection decorator. - - \see applyPen, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const -{ - painter->setBrush(mBrush); -} - -/*! - Returns the scatter style that the parent plottable shall use for selected scatter points. The - plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending - on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this - selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. - - \see applyPen, applyBrush, setScatterStyle -*/ -QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const -{ - QCPScatterStyle result(unselectedStyle); - result.setFromOther(mScatterStyle, mUsedScatterProperties); - - // if style shall inherit pen from plottable (has no own pen defined), give it the selected - // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the - // plottable: - if (!result.isPenDefined()) - result.setPen(mPen); - - return result; -} - -/*! - Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to - this selection decorator. -*/ -void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) -{ - setPen(other->pen()); - setBrush(other->brush()); - setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); -} - -/*! - This method is called by all plottables' draw methods to allow custom selection decorations to be - drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data - selection for which the decoration shall be drawn. - - The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so - this method does nothing. -*/ -void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - Q_UNUSED(painter) - Q_UNUSED(selection) -} - -/*! \internal - - This method is called as soon as a selection decorator is associated with a plottable, by a call - to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access - data points via the \ref QCPAbstractPlottable::interface1D interface). - - If the selection decorator was already added to a different plottable before, this method aborts - the registration and returns false. -*/ -bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottable) - { - mPlottable = plottable; - return true; - } else - { - qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); - return false; - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable - \brief The abstract base class for all data representing objects in a plot. - - It defines a very basic interface like name, pen, brush, visibility etc. Since this class is - abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to - create new ways of displaying data (see "Creating own plottables" below). Plottables that display - one-dimensional data (i.e. data points have a single key dimension and one or multiple values at - each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details - there. - - All further specifics are in the subclasses, for example: - \li A normal graph with possibly a line and/or scatter points \ref QCPGraph - (typically created with \ref QCustomPlot::addGraph) - \li A parametric curve: \ref QCPCurve - \li A bar chart: \ref QCPBars - \li A statistical box plot: \ref QCPStatisticalBox - \li A color encoded two-dimensional map: \ref QCPColorMap - \li An OHLC/Candlestick chart: \ref QCPFinancial - - \section plottables-subclassing Creating own plottables - - Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display - two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) - data dimensions. If you want to display data with only one logical key dimension, you should - rather derive from \ref QCPAbstractPlottable1D. - - If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must - implement: - \li \ref selectTest - \li \ref draw - \li \ref drawLegendIcon - \li \ref getKeyRange - \li \ref getValueRange - - See the documentation of those functions for what they need to do. - - For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot - coordinates to pixel coordinates. This function is quite convenient, because it takes the - orientation of the key and value axes into account for you (x and y are swapped when the key axis - is vertical and the value axis horizontal). If you are worried about performance (i.e. you need - to translate many points in a loop like QCPGraph), you can directly use \ref - QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis - yourself. - - Here are some important members you inherit from QCPAbstractPlottable: - - - - - - - - - - - - - - - - - - - - - - - - - - -
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable - (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable - (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates - to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of - the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. - When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. - Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done - by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
-*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const - - Provides access to the selection decorator of this plottable. The selection decorator controls - how selected data ranges are drawn (e.g. their pen color and fill), see \ref - QCPSelectionDecorator for details. - - If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref - setSelectionDecorator. -*/ - -/*! \fn bool QCPAbstractPlottable::selected() const - - Returns true if there are any data points of the plottable currently selected. Use \ref selection - to retrieve the current \ref QCPDataSelection. -*/ - -/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const - - Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on - this plottable. - - \see selected, setSelection, setSelectable -*/ - -/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() - - If this plottable is a one-dimensional plottable, i.e. it implements the \ref - QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case - of a \ref QCPColorMap) returns zero. - - You can use this method to gain read access to data coordinates while holding a pointer to the - abstract base class only. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of pure virtual functions */ - -/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 - \internal - - called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation - of this plottable inside \a rect, next to the plottable name. - - The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't - appear outside the legend icon border. -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 - - Returns the coordinate range that all data in this plottable span in the key axis dimension. For - logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref - QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only - negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points - will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref - QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could - be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getValueRange -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 - - Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span - in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref - QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign - domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and - all positive points will be ignored for range calculation. For no restriction, just set \a - inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates - whether a range could be found or not. If this is false, you shouldn't use the returned range - (e.g. no points in data). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getKeyRange -*/ - -/* end of documentation of pure virtual functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether - there are any points selected or not. - - \see selectionChanged(const QCPDataSelection &selection) -*/ - -/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selection holds the - currently selected data ranges. - - \see selectionChanged(bool selected) -*/ - -/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); - - This signal is emitted when the selectability of this plottable has changed. - - \see setSelectable -*/ - -/* end of documentation of signals */ - -/*! - Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as - its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance - and have perpendicular orientations. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, - it can't be directly instantiated. - - You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. -*/ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), - mName(), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mPen(Qt::black), - mBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(QCP::stWhole), - mSelectionDecorator(0) -{ - if (keyAxis->parentPlot() != valueAxis->parentPlot()) - qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) - qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; - - mParentPlot->registerPlottable(this); - setSelectionDecorator(new QCPSelectionDecorator); -} - -QCPAbstractPlottable::~QCPAbstractPlottable() -{ - if (mSelectionDecorator) - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - The name is the textual representation of this plottable as it is displayed in the legend - (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. -*/ -void QCPAbstractPlottable::setName(const QString &name) -{ - mName = name; -} - -/*! - Sets whether fills of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) -{ - mAntialiasedFill = enabled; -} - -/*! - Sets whether the scatter symbols of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) -{ - mAntialiasedScatters = enabled; -} - -/*! - The pen is used to draw basic lines that make up the plottable representation in the - plot. - - For example, the \ref QCPGraph subclass draws its graph lines with this pen. - - \see setBrush -*/ -void QCPAbstractPlottable::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - The brush is used to draw basic fills of the plottable representation in the - plot. The Fill can be a color, gradient or texture, see the usage of QBrush. - - For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when - it's not set to Qt::NoBrush. - - \see setPen -*/ -void QCPAbstractPlottable::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal - to the plottable's value axis. This function performs no checks to make sure this is the case. - The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the - y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setValueAxis -*/ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) -{ - mKeyAxis = axis; -} - -/*! - The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is - orthogonal to the plottable's key axis. This function performs no checks to make sure this is the - case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and - the y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setKeyAxis -*/ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) -{ - mValueAxis = axis; -} - - -/*! - Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently - (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref - selectionDecorator). - - The entire selection mechanism for plottables is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when - you wish to change the selection state programmatically. - - Using \ref setSelectable you can further specify for each plottable whether and to which - granularity it is selectable. If \a selection is not compatible with the current \ref - QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted - accordingly (see \ref QCPDataSelection::enforceType). - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractPlottable::setSelection(QCPDataSelection selection) -{ - selection.enforceType(mSelectable); - if (mSelection != selection) - { - mSelection = selection; - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } -} - -/*! - Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to - customize the visual representation of selected data ranges further than by using the default - QCPSelectionDecorator. - - The plottable takes ownership of the \a decorator. - - The currently set decorator can be accessed via \ref selectionDecorator. -*/ -void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) -{ - if (decorator) - { - if (decorator->registerWithPlottable(this)) - { - if (mSelectionDecorator) // delete old decorator if necessary - delete mSelectionDecorator; - mSelectionDecorator = decorator; - } - } else if (mSelectionDecorator) // just clear decorator - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - Sets whether and to which granularity this plottable can be selected. - - A selection can happen by clicking on the QCustomPlot surface (When \ref - QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect - (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by - calling \ref setSelection. - - \see setSelection, QCP::SelectionType -*/ -void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - QCPDataSelection oldSelection = mSelection; - mSelection.enforceType(mSelectable); - Q_EMIT selectableChanged(mSelectable); - if (mSelection != oldSelection) - { - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } - } -} - - -/*! - Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. - - \see pixelsToCoords, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else - { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); - } -} - -/*! \overload - - Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. -*/ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); - else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); -} - -/*! - Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. - - \see coordsToPixels, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else - { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); - } -} - -/*! \overload - - Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. -*/ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const -{ - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); -} - -/*! - Rescales the key and value axes associated with this plottable to contain all displayed data, so - the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make - sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. - Instead it will stay in the current sign domain and ignore all parts of the plottable that lie - outside of that domain. - - \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show - multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has - \a onlyEnlarge set to false (the default), and all subsequent set to true. - - \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale -*/ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const -{ - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); -} - -/*! - Rescales the key axis of the plottable so the whole plottable is visible. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); - } - } - keyAxis->setRange(newRange); - } -} - -/*! - Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is - set to true, only the data points which are in the currently visible key axis range are - considered. - - Returns true if the axis was actually scaled. This might not be the case if this plottable has an - invalid range, e.g. because it has no data points. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); - } - } - valueAxis->setRange(newRange); - } -} - -/*! \overload - - Adds this plottable to the specified \a legend. - - Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. - when the legend exists and a legend item associated with this plottable isn't already in the - legend. - - If the plottable needs a more specialized representation in the legend, you can create a - corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead - of calling this method. - - \see removeFromLegend, QCPLegend::addItem -*/ -bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - if (legend->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; - return false; - } - - if (!legend->hasItemWithPlottable(this)) - { - legend->addItem(new QCPPlottableLegendItem(legend, this)); - return true; - } else - return false; -} - -/*! \overload - - Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). - - \see removeFromLegend -*/ -bool QCPAbstractPlottable::addToLegend() -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return addToLegend(mParentPlot->legend); -} - -/*! \overload - - Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem - that is associated with this plottable is removed. - - Returns true on success, i.e. if the legend exists and a legend item associated with this - plottable was found and removed. - - \see addToLegend, QCPLegend::removeItem -*/ -bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - - if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) - return legend->removeItem(lip); - else - return false; -} - -/*! \overload - - Removes the plottable from the legend of the parent QCustomPlot. - - \see addToLegend -*/ -bool QCPAbstractPlottable::removeFromLegend() const -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return removeFromLegend(mParentPlot->legend); -} - -/* inherits documentation from base class */ -QRect QCPAbstractPlottable::clipRect() const -{ - if (mKeyAxis && mValueAxis) - return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - else - return QRect(); -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractPlottable::selectionCategory() const -{ - return QCP::iSelectPlottables; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable fills. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable scatter points. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint -*/ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - - if (mSelectable != QCP::stNone) - { - QCPDataSelection newSelection = details.value(); - QCPDataSelection selectionBefore = mSelection; - if (additive) - { - if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit - { - if (selected()) - setSelection(QCPDataSelection()); - else - setSelection(newSelection); - } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments - { - if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection - setSelection(mSelection-newSelection); - else - setSelection(mSelection+newSelection); - } - } else - setSelection(newSelection); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable != QCP::stNone) - { - QCPDataSelection selectionBefore = mSelection; - setSelection(QCPDataSelection()); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} -/* end of 'src/plottable.cpp' */ - - -/* including file 'src/item.cpp', size 49269 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemAnchor -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemAnchor - \brief An anchor of an item to which positions can be attached to. - - An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't - control anything on its item, but provides a way to tie other items via their positions to the - anchor. - - For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. - Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can - attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by - calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the - QCPItemRect. This way the start of the line will now always follow the respective anchor location - on the rect item. - - Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an - anchor to other positions. - - To learn how to provide anchors in your own item subclasses, see the subclassing section of the - QCPAbstractItem documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() - - Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if - it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). - - This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids - dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with - gcc compiler). -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) -{ -} - -QCPItemAnchor::~QCPItemAnchor() -{ - // unregister as parent at children: - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } -} - -/*! - Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. - - The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the - parent item, QCPItemAnchor is just an intermediary. -*/ -QPointF QCPItemAnchor::pixelPosition() const -{ - if (mParentItem) - { - if (mAnchorId > -1) - { - return mParentItem->anchorPixelPosition(mAnchorId); - } else - { - qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; - return QPointF(); - } - } else - { - qDebug() << Q_FUNC_INFO << "no parent item set"; - return QPointF(); - } -} - -/*! \internal - - Adds \a pos to the childX list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.contains(pos)) - mChildrenX.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childX list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - -/*! \internal - - Adds \a pos to the childY list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.contains(pos)) - mChildrenY.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childY list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPosition -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPosition - \brief Manages the position of an item. - - Every item has at least one public QCPItemPosition member pointer which provides ways to position the - item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: - \a topLeft and \a bottomRight. - - QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type - defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel - coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also - possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref - setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y - direction, while following a plot coordinate in the X direction. - - A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie - multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) - are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) - means directly ontop of the parent anchor. For example, You could attach the \a start position of - a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line - always be centered under the text label, no matter where the text is moved to. For more advanced - plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see - \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X - direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B - in Y. - - Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent - anchor for other positions. - - To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This - works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref - setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified - pixel values. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const - - Returns the current position type. - - If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the - type of the X coordinate. In that case rather use \a typeX() and \a typeY(). - - \see setType -*/ - -/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const - - Returns the current parent anchor. - - If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), - this method returns the parent anchor of the Y coordinate. In that case rather use \a - parentAnchorX() and \a parentAnchorY(). - - \see setParentAnchor -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionTypeX(ptAbsolute), - mPositionTypeY(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchorX(0), - mParentAnchorY(0) -{ -} - -QCPItemPosition::~QCPItemPosition() -{ - // unregister as parent at children: - // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then - // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } - // unregister as child in parent: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const -{ - return mAxisRect.data(); -} - -/*! - Sets the type of the position. The type defines how the coordinates passed to \ref setCoords - should be handled and how the QCPItemPosition should behave in the plot. - - The possible values for \a type can be separated in two main categories: - - \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords - and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. - By default, the QCustomPlot's x- and yAxis are used. - - \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This - corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref - ptAxisRectRatio. They differ only in the way the absolute position is described, see the - documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify - the axis rect with \ref setAxisRect. By default this is set to the main axis rect. - - Note that the position type \ref ptPlotCoords is only available (and sensible) when the position - has no parent anchor (\ref setParentAnchor). - - If the type is changed, the apparent pixel position on the plot is preserved. This means - the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. - - This method sets the type for both X and Y directions. It is also possible to set different types - for X and Y, see \ref setTypeX, \ref setTypeY. -*/ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) -{ - setTypeX(type); - setTypeY(type); -} - -/*! - This method sets the position type of the X coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeY -*/ -void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) -{ - if (mPositionTypeX != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeX = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - This method sets the position type of the Y coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeX -*/ -void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) -{ - if (mPositionTypeY != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeY = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now - follow any position changes of the anchor. The local coordinate system of positions with a parent - anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence - the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) - - if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved - during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position - will be exactly on top of the parent anchor. - - To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. - - If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is - set to \ref ptAbsolute, to keep the position in a valid state. - - This method sets the parent anchor for both X and Y directions. It is also possible to set - different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. -*/ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); - bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); - return successX && successY; -} - -/*! - This method sets the parent anchor of the X coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorY -*/ -bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorX(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) - setTypeX(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildX(this); - mParentAnchorX = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(0, coords().y()); - return true; -} - -/*! - This method sets the parent anchor of the Y coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorX -*/ -bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorY(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) - setTypeY(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildY(this); - mParentAnchorY = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(coords().x(), 0); - return true; -} - -/*! - Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type - (\ref setType, \ref setTypeX, \ref setTypeY). - - For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position - on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the - QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the - plot coordinate system defined by the axes set by \ref setAxes. By default those are the - QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available - coordinate types and their meaning. - - If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a - value must also be provided in the different coordinate systems. Here, the X type refers to \a - key, and the Y type refers to \a value. - - \see setPixelPosition -*/ -void QCPItemPosition::setCoords(double key, double value) -{ - mKey = key; - mValue = value; -} - -/*! \overload - - Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the - meaning of \a value of the \ref setCoords(double key, double value) method. -*/ -void QCPItemPosition::setCoords(const QPointF &pos) -{ - setCoords(pos.x(), pos.y()); -} - -/*! - Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It - includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). - - \see setPixelPosition -*/ -QPointF QCPItemPosition::pixelPosition() const -{ - QPointF result; - - // determine X: - switch (mPositionTypeX) - { - case ptAbsolute: - { - result.rx() = mKey; - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - result.rx() = mKey*mParentPlot->viewport().width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mParentPlot->viewport().left(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.rx() = mKey*mAxisRect.data()->width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mAxisRect.data()->left(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - // determine Y: - switch (mPositionTypeY) - { - case ptAbsolute: - { - result.ry() = mValue; - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - result.ry() = mValue*mParentPlot->viewport().height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mParentPlot->viewport().top(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.ry() = mValue*mAxisRect.data()->height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mAxisRect.data()->top(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - result.ry() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - result.ry() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - return result; -} - -/*! - When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the - coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and - yAxis of the QCustomPlot. -*/ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - mKeyAxis = keyAxis; - mValueAxis = valueAxis; -} - -/*! - When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the - coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of - the QCustomPlot. -*/ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) -{ - mAxisRect = axisRect; -} - -/*! - Sets the apparent pixel position. This works no matter what type (\ref setType) this - QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed - appropriately, to make the position finally appear at the specified pixel values. - - Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is - identical to that of \ref setCoords. - - \see pixelPosition, setCoords -*/ -void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) -{ - double x = pixelPosition.x(); - double y = pixelPosition.y(); - - switch (mPositionTypeX) - { - case ptAbsolute: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mParentPlot->viewport().left(); - x /= (double)mParentPlot->viewport().width(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mAxisRect.data()->left(); - x /= (double)mAxisRect.data()->width(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - x = mKeyAxis.data()->pixelToCoord(x); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - y = mValueAxis.data()->pixelToCoord(x); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - switch (mPositionTypeY) - { - case ptAbsolute: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mParentPlot->viewport().top(); - y /= (double)mParentPlot->viewport().height(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mAxisRect.data()->top(); - y /= (double)mAxisRect.data()->height(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - x = mKeyAxis.data()->pixelToCoord(y); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - y = mValueAxis.data()->pixelToCoord(y); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - setCoords(x, y); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractItem - \brief The abstract base class for all items in a plot. - - In QCustomPlot, items are supplemental graphical elements that are neither plottables - (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus - plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each - specific item has at least one QCPItemPosition member which controls the positioning. Some items - are defined by more than one coordinate and thus have two or more QCPItemPosition members (For - example, QCPItemRect has \a topLeft and \a bottomRight). - - This abstract base class defines a very basic interface like visibility and clipping. Since this - class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass - yourself to create new items. - - The built-in items are: - - - - - - - - - - -
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
- - \section items-clipping Clipping - - Items are by default clipped to the main axis rect (they are only visible inside the axis rect). - To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect - "setClipToAxisRect(false)". - - On the other hand if you want the item to be clipped to a different axis rect, specify it via - \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and - in principle is independent of the coordinate axes the item might be tied to via its position - members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping - also contains the axes used for the item positions. - - \section items-using Using items - - First you instantiate the item you want to use and add it to the plot: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 - by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just - set the plot coordinates where the line should start/end: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 - If we don't want the line to be positioned in plot coordinates but a different coordinate system, - e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 - Then we can set the coordinates, this time in pixels: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 - and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 - - For more advanced plots, it is even possible to set different types and parent anchors per X/Y - coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref - QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. - - \section items-subclassing Creating own items - - To create an own item, you implement a subclass of QCPAbstractItem. These are the pure - virtual functions, you must implement: - \li \ref selectTest - \li \ref draw - - See the documentation of those functions for what they need to do. - - \subsection items-positioning Allowing the item to be positioned - - As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall - have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add - a public member of type QCPItemPosition like so: - - \code QCPItemPosition * const myPosition;\endcode - - the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition - instance it points to, can be modified, of course). - The initialization of this pointer is made easy with the \ref createPosition function. Just assign - the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition - takes a string which is the name of the position, typically this is identical to the variable name. - For example, the constructor of QCPItemExample could look like this: - - \code - QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - myPosition(createPosition("myPosition")) - { - // other constructor code - } - \endcode - - \subsection items-drawing The draw function - - To give your item a visual representation, reimplement the \ref draw function and use the passed - QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the - position member(s) via \ref QCPItemPosition::pixelPosition. - - To optimize performance you should calculate a bounding rect first (don't forget to take the pen - width into account), check whether it intersects the \ref clipRect, and only draw the item at all - if this is the case. - - \subsection items-selection The selectTest function - - Your implementation of the \ref selectTest function may use the helpers \ref - QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the - selection test becomes significantly simpler for most items. See the documentation of \ref - selectTest for what the function parameters mean and what the function should return. - - \subsection anchors Providing anchors - - Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public - member, e.g. - - \code QCPItemAnchor * const bottom;\endcode - - and create it in the constructor with the \ref createAnchor function, assigning it a name and an - anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). - Since anchors can be placed anywhere, relative to the item's position(s), your item needs to - provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int - anchorId) function. - - In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel - position when anything attached to the anchor needs to know the coordinates. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QList QCPAbstractItem::positions() const - - Returns all positions of the item in a list. - - \see anchors, position -*/ - -/*! \fn QList QCPAbstractItem::anchors() const - - Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always - also an anchor, the list will also contain the positions of this item. - - \see positions, anchor -*/ - -/* end of documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 - \internal - - Draws this item with the provided \a painter. - - The cliprect of the provided painter is set to the rect returned by \ref clipRect before this - function is called. The clipRect depends on the clipping settings defined by \ref - setClipToAxisRect and \ref setClipAxisRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPAbstractItem::selectionChanged(bool selected) - This signal is emitted when the selection state of this item has changed, either by user interaction - or by a direct call to \ref setSelected. -*/ - -/* end documentation of signals */ - -/*! - Base class constructor which initializes base class members. -*/ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) -{ - parentPlot->registerItem(this); - - QList rects = parentPlot->axisRects(); - if (rects.size() > 0) - { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); - } -} - -QCPAbstractItem::~QCPAbstractItem() -{ - // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const -{ - return mClipAxisRect.data(); -} - -/*! - Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the - entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. - - \see setClipAxisRect -*/ -void QCPAbstractItem::setClipToAxisRect(bool clip) -{ - mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref - setClipToAxisRect is set to true. - - \see setClipToAxisRect -*/ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) -{ - mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected. - - \see QCustomPlot::setInteractions, setSelected -*/ -void QCPAbstractItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this item is selected or not. When selected, it might use a different visual - appearance (e.g. pen and brush), this depends on the specific item though. - - The entire selection mechanism for items is handled automatically when \ref - QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this - function when you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/*! - Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by - that name, returns 0. - - This function provides an alternative way to access item positions. Normally, you access - positions direcly by their member pointers (which typically have the same variable name as \a - name). - - \see positions, anchor -*/ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const -{ - for (int i=0; iname() == name) - return mPositions.at(i); - } - qDebug() << Q_FUNC_INFO << "position with name not found:" << name; - return 0; -} - -/*! - Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by - that name, returns 0. - - This function provides an alternative way to access item anchors. Normally, you access - anchors direcly by their member pointers (which typically have the same variable name as \a - name). - - \see anchors, position -*/ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const -{ - for (int i=0; iname() == name) - return mAnchors.at(i); - } - qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; - return 0; -} - -/*! - Returns whether this item has an anchor with the specified \a name. - - Note that you can check for positions with this function, too. This is because every position is - also an anchor (QCPItemPosition inherits from QCPItemAnchor). - - \see anchor, position -*/ -bool QCPAbstractItem::hasAnchor(const QString &name) const -{ - for (int i=0; iname() == name) - return true; - } - return false; -} - -/*! \internal - - Returns the rect the visual representation of this item is clipped to. This depends on the - current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. - - If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. - - \see draw -*/ -QRect QCPAbstractItem::clipRect() const -{ - if (mClipToAxisRect && mClipAxisRect) - return mClipAxisRect.data()->rect(); - else - return mParentPlot->viewport(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing item lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); -} - -/*! \internal - - A convenience function which returns the selectTest value for a specified \a rect and a specified - click position \a pos. \a filledRect defines whether a click inside the rect should also be - considered a hit or whether only the rect border is sensitive to hits. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - For example, if your item consists of four rects, call this function four times, once for each - rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four - returned values. -*/ -double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const -{ - double result = -1; - - // distance to border: - QList lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = std::numeric_limits::max(); - for (int i=0; i mParentPlot->selectionTolerance()*0.99) - { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/*! \internal - - Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in - item subclasses if they want to provide anchors (QCPItemAnchor). - - For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor - ids and returns the respective pixel points of the specified anchor. - - \see createAnchor -*/ -QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const -{ - qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the position - member (This is needed to provide the name-based \ref position access to positions). - - Don't delete positions created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each position member. Don't create QCPItemPositions with \b new yourself, because they - won't be registered with the item properly. - - \see createAnchor -*/ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); - return newPosition; -} - -/*! \internal - - Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the anchor - member (This is needed to provide the name based \ref anchor access to anchors). - - The \a anchorId must be a number identifying the created anchor. It is recommended to create an - enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor - to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns - the correct pixel coordinates for the passed anchor id. - - Don't delete anchors created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they - won't be registered with the item properly. - - \see createPosition -*/ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); - return newAnchor; -} - -/* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractItem::selectionCategory() const -{ - return QCP::iSelectItems; -} -/* end of 'src/item.cpp' */ - - -/* including file 'src/core.cpp', size 125037 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCustomPlot -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCustomPlot - - \brief The central class of the library. This is the QWidget which displays the plot and - interacts with the user. - - For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const - - Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used - to handle and draw selection rect interactions (see \ref setSelectionRectMode). - - \see setSelectionRect -*/ - -/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const - - Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just - one cell with the main QCPAxisRect inside. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse double click event. -*/ - -/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse press event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. -*/ - -/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse move event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. - - \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, - because the dragging starting point was saved the moment the mouse was pressed. Thus it only has - a meaning for the range drag axes that were set at that moment. If you want to change the drag - axes, consider doing this in the \ref mousePress signal instead. -*/ - -/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse release event. - - It is emitted before QCustomPlot handles any other mechanisms like object selection. So a - slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or - \ref QCPAbstractPlottable::setSelectable. -*/ - -/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse wheel event. - - It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref - QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. -*/ - -/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableDoubleClick -*/ - -/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is double clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableClick -*/ - -/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemDoubleClick -*/ - -/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is double clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemClick -*/ - -/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisDoubleClick -*/ - -/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is double clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisClick -*/ - -/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendDoubleClick -*/ - -/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is double clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendClick -*/ - -/*! \fn void QCustomPlot::selectionChangedByUser() - - This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by - clicking. It is not emitted when the selection state of an object has changed programmatically by - a direct call to setSelected()/setSelection() on an object or by calling \ref - deselectAll. - - In addition to this signal, selectable objects also provide individual signals, for example \ref - QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals - are emitted even if the selection state is changed programmatically. - - See the documentation of \ref setInteractions for details about the selection mechanism. - - \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends -*/ - -/*! \fn void QCustomPlot::beforeReplot() - - This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, afterReplot -*/ - -/*! \fn void QCustomPlot::afterReplot() - - This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, beforeReplot -*/ - -/* end of documentation of signals */ -/* start of documentation of public members */ - -/*! \var QCPAxis *QCustomPlot::xAxis - - A pointer to the primary x Axis (bottom) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis - - A pointer to the primary y Axis (left) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::xAxis2 - - A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis2 - - A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPLegend *QCustomPlot::legend - - A pointer to the default legend of the main axis rect. The legend is invisible by default. Use - QCPLegend::setVisible to change this. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple legends to the plot, use the layout system interface to - access the new legend. For example, legends can be placed inside an axis rect's \ref - QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If - the default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointer becomes 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/* end of documentation of public members */ - -/*! - Constructs a QCustomPlot and sets reasonable default values. -*/ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), - mMultiSelectModifier(Qt::ControlModifier), - mSelectionRectMode(QCP::srmNone), - mSelectionRect(0), - mOpenGl(false), - mMouseHasMoved(false), - mMouseEventLayerable(0), - mMouseSignalLayerable(0), - mReplotting(false), - mReplotQueued(false), - mOpenGlMultisamples(16), - mOpenGlAntialiasedElementsBackup(QCP::aeNone), - mOpenGlCacheLabelsBackup(true) -{ - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); -# else - setBufferDevicePixelRatio(QWidget::devicePixelRatio()); -# endif -#endif - - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // create initial layers: - mLayers.append(new QCPLayer(this, QLatin1String("background"))); - mLayers.append(new QCPLayer(this, QLatin1String("grid"))); - mLayers.append(new QCPLayer(this, QLatin1String("main"))); - mLayers.append(new QCPLayer(this, QLatin1String("axes"))); - mLayers.append(new QCPLayer(this, QLatin1String("legend"))); - mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); - updateLayerIndices(); - setCurrentLayer(QLatin1String("main")); - layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); - - // create initial layout, axis rect and legend: - mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer(QLatin1String("main")); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); - legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer(QLatin1String("background")); - xAxis->setLayer(QLatin1String("axes")); - yAxis->setLayer(QLatin1String("axes")); - xAxis2->setLayer(QLatin1String("axes")); - yAxis2->setLayer(QLatin1String("axes")); - xAxis->grid()->setLayer(QLatin1String("grid")); - yAxis->grid()->setLayer(QLatin1String("grid")); - xAxis2->grid()->setLayer(QLatin1String("grid")); - yAxis2->grid()->setLayer(QLatin1String("grid")); - legend->setLayer(QLatin1String("legend")); - - // create selection rect instance: - mSelectionRect = new QCPSelectionRect(this); - mSelectionRect->setLayer(QLatin1String("overlay")); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(rpQueuedReplot); -} - -QCustomPlot::~QCustomPlot() -{ - clearPlottables(); - clearItems(); - - if (mPlotLayout) - { - delete mPlotLayout; - mPlotLayout = 0; - } - - mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed - mLayers.clear(); -} - -/*! - Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is - removed from there. - - \see setNotAntialiasedElements -*/ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) -{ - mAntialiasedElements = antialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. - - See \ref setAntialiasedElements for details. - - \see setNotAntialiasedElement -*/ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) -{ - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements |= antialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets which elements are forcibly drawn not antialiased as an \a or combination of - QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is - removed from there. - - \see setAntialiasedElements -*/ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) -{ - mNotAntialiasedElements = notAntialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. - - See \ref setNotAntialiasedElements for details. - - \see setAntialiasedElement -*/ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) -{ - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements |= notAntialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the - plottable to the legend (QCustomPlot::legend). - - \see addGraph, QCPLegend::addItem -*/ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) -{ - mAutoAddPlottableToLegend = on; -} - -/*! - Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction - enums. There are the following types of interactions: - - Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the - respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. - For details how to control which axes the user may drag/zoom and in what orientations, see \ref - QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, - \ref QCPAxisRect::setRangeZoomAxes. - - Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref - QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and - their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the - user can actually select a plottable and its data can further be restricted with the \ref - QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the - special page about the \ref dataselection "data selection mechanism". To retrieve a list of all - currently selected plottables, call \ref selectedPlottables. If you're only interested in - QCPGraphs, you may use the convenience function \ref selectedGraphs. - - Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user - may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find - out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of - all currently selected items, call \ref selectedItems. - - Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user - may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick - labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for - each axis. To retrieve a list of all axes that currently contain selected parts, call \ref - selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). - - Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may - select the legend itself or individual items by clicking on them. What parts exactly are - selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the - legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To - find out which child items are selected, call \ref QCPLegend::selectedItems. - - All other selectable elements The selection of all other selectable objects (e.g. - QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the - user may select those objects by clicking on them. To find out which are currently selected, you - need to check their selected state explicitly. - - If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is - emitted. Each selectable object additionally emits an individual selectionChanged signal whenever - their selection state has changed, i.e. not only by user interaction. - - To allow multiple objects to be selected by holding the selection modifier (\ref - setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. - - \note In addition to the selection mechanism presented here, QCustomPlot always emits - corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and - \ref plottableDoubleClick for example. - - \see setInteraction, setSelectionTolerance -*/ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) -{ - mInteractions = interactions; -} - -/*! - Sets the single \a interaction of this QCustomPlot to \a enabled. - - For details about the interaction system, see \ref setInteractions. - - \see setInteractions -*/ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) -{ - if (!enabled && mInteractions.testFlag(interaction)) - mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) - mInteractions |= interaction; -} - -/*! - Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or - not. - - If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a - potential selection when the minimum distance between the click position and the graph line is - smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks - directly inside the area and ignore this selection tolerance. In other words, it only has meaning - for parts of objects that are too thin to exactly hit with a click and thus need such a - tolerance. - - \see setInteractions, QCPLayerable::selectTest -*/ -void QCustomPlot::setSelectionTolerance(int pixels) -{ - mSelectionTolerance = pixels; -} - -/*! - Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes - ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves - performance during dragging. Thus it creates a more responsive user experience. As soon as the - user stops dragging, the last replot is done with normal antialiasing, to restore high image - quality. - - \see setAntialiasedElements, setNotAntialiasedElements -*/ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) -{ - mNoAntialiasingOnDrag = enabled; -} - -/*! - Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. - - \see setPlottingHint -*/ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) -{ - mPlottingHints = hints; -} - -/*! - Sets the specified plotting \a hint to \a enabled. - - \see setPlottingHints -*/ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) -{ - QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) - newHints &= ~hint; - else - newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); -} - -/*! - Sets the keyboard modifier that will be recognized as multi-select-modifier. - - If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple - objects (or data points) by clicking on them one after the other while holding down \a modifier. - - By default the multi-select-modifier is set to Qt::ControlModifier. - - \see setInteractions -*/ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) -{ - mMultiSelectModifier = modifier; -} - -/*! - Sets how QCustomPlot processes mouse click-and-drag interactions by the user. - - If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For - example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref - QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref - selectionRect) becomes activated and allows e.g. rect zooming and data point selection. - - If you wish to provide your user both with axis range dragging and data selection/range zooming, - use this method to switch between the modes just before the interaction is processed, e.g. in - reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether - the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. - - If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the - interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes - will keep the selection rect active. Upon completion of the interaction, the behaviour is as - defined by the currently set \a mode, not the mode that was set when the interaction started. - - \see setInteractions, setSelectionRect, QCPSelectionRect -*/ -void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) -{ - if (mSelectionRect) - { - if (mode == QCP::srmNone) - mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect - - // disconnect old connections: - if (mSelectionRectMode == QCP::srmSelect) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - - // establish new ones: - if (mode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } - - mSelectionRectMode = mode; -} - -/*! - Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref - QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of - the passed \a selectionRect. It can be accessed later via \ref selectionRect. - - This method is useful if you wish to replace the default QCPSelectionRect instance with an - instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. - - \see setSelectionRectMode -*/ -void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) -{ - if (mSelectionRect) - delete mSelectionRect; - - mSelectionRect = selectionRect; - - if (mSelectionRect) - { - // establish connections with new selection rect: - if (mSelectionRectMode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } -} - -/*! - \warning This is still an experimental feature and its performance depends on the system that it - runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering - might cause context conflicts on some systems. - - This method allows to enable OpenGL plot rendering, for increased plotting performance of - graphically demanding plots (thick lines, translucent fills, etc.). - - If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, - continue plotting with hardware acceleration. The parameter \a multisampling controls how many - samples will be used per pixel, it essentially controls the antialiasing quality. If \a - multisampling is set too high for the current graphics hardware, the maximum allowed value will - be used. - - You can test whether switching to OpenGL rendering was successful by checking whether the - according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, - rendering continues with the regular software rasterizer, and an according qDebug output is - generated. - - If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint - "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override - for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a - higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the - OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is - controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching - settings are restored to what they were before OpenGL was enabled, if they weren't altered in the - meantime. - - \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL - defined. This define must be set before including the QCustomPlot header both during compilation - of the QCustomPlot library as well as when compiling your application. It is best to just include - the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. - \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c - QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a - newer OpenGL interface which is already in the "gui" module. -*/ -void QCustomPlot::setOpenGl(bool enabled, int multisampling) -{ - mOpenGlMultisamples = qMax(0, multisampling); -#ifdef QCUSTOMPLOT_USE_OPENGL - mOpenGl = enabled; - if (mOpenGl) - { - if (setupOpenGl()) - { - // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): - setAntialiasedElements(QCP::aeAll); - setPlottingHint(QCP::phCacheLabels, false); - } else - { - qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; - mOpenGl = false; - } - } else - { - // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: - if (mAntialiasedElements == QCP::aeAll) - setAntialiasedElements(mOpenGlAntialiasedElementsBackup); - if (!mPlottingHints.testFlag(QCP::phCacheLabels)) - setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); - freeOpenGl(); - } - // recreate all paint buffers: - mPaintBuffers.clear(); - setupPaintBuffers(); -#else - Q_UNUSED(enabled) - qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; -#endif -} - -/*! - Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the - viewport manually. - - The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take - the viewport to be the outer border of the plot. The viewport normally is the rect() of the - QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. - - Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically - an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger - and contains also the axes themselves, their tick numbers, their labels, or even additional axis - rects, color scales and other layout elements. - - This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref - savePdf, etc. by temporarily changing the viewport size. -*/ -void QCustomPlot::setViewport(const QRect &rect) -{ - mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); -} - -/*! - Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. - - Normally, this doesn't need to be set manually, because it is initialized with the regular \a - QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal - displays, 2 for High-DPI displays). - - Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called - when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and - leaves the internal buffer device pixel ratio at 1.0. -*/ -void QCustomPlot::setBufferDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBufferDevicePixelRatio = ratio; - for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mBufferDevicePixelRatio = 1.0; -#endif - } -} - -/*! - Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn - below all other objects in the plot. - - For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is - preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will - first be filled with that brush, before drawing the background pixmap. This can be useful for - background pixmaps with translucent areas. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! - Sets the background brush of the viewport (see \ref setViewport). - - Before drawing everything else, the background is filled with \a brush. If a background pixmap - was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport - before the background pixmap is drawn. This can be useful for background pixmaps with translucent - areas. - - Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be - useful for exporting to image formats which support transparency, e.g. \ref savePng. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the viewport, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is - set to true, control whether and how the aspect ratio of the original pixmap is preserved with - \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the viewport dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCustomPlot::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this - function to define whether and how the aspect ratio of the original pixmap is preserved. - - \see setBackground, setBackgroundScaled -*/ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the plottable with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - plottable, see QCustomPlot::plottable() - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - { - return mPlottables.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last plottable that was added to the plot. If there are no plottables in the plot, - returns 0. - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable() -{ - if (!mPlottables.isEmpty()) - { - return mPlottables.last(); - } else - return 0; -} - -/*! - Removes the specified plottable from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). - - Returns true on success. - - \see clearPlottables -*/ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); - return false; - } - - // remove plottable from legend: - plottable->removeFromLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast(plottable)) - mGraphs.removeOne(graph); - // remove plottable: - delete plottable; - mPlottables.removeOne(plottable); - return true; -} - -/*! \overload - - Removes and deletes the plottable by its \a index. -*/ -bool QCustomPlot::removePlottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all plottables from the plot and deletes them. Corresponding legend items are also - removed from the default legend (QCustomPlot::legend). - - Returns the number of plottables removed. - - \see removePlottable -*/ -int QCustomPlot::clearPlottables() -{ - int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); - return c; -} - -/*! - Returns the number of currently existing plottables in the plot - - \see plottable -*/ -int QCustomPlot::plottableCount() const -{ - return mPlottables.size(); -} - -/*! - Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. - - There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. - - \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedPlottables() const -{ - QList result; - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (plottable->selected()) - result.append(plottable); - } - return result; -} - -/*! - Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines - (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple - plottables come into consideration, the one closest to \a pos is returned. - - If \a onlySelectable is true, only plottables that are selectable - (QCPAbstractPlottable::setSelectable) are considered. - - If there is no plottable at \a pos, the return value is 0. - - \see itemAt, layoutElementAt -*/ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable - continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes - { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultPlottable = plottable; - resultDistance = currentDistance; - } - } - } - - return resultPlottable; -} - -/*! - Returns whether this QCustomPlot instance contains the \a plottable. -*/ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const -{ - return mPlottables.contains(plottable); -} - -/*! - Returns the graph with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last created - graph, see QCustomPlot::graph() - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph(int index) const -{ - if (index >= 0 && index < mGraphs.size()) - { - return mGraphs.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, - returns 0. - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph() const -{ - if (!mGraphs.isEmpty()) - { - return mGraphs.last(); - } else - return 0; -} - -/*! - Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the - bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a - keyAxis and \a valueAxis must reside in this QCustomPlot. - - \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically - "y") for the graph. - - Returns a pointer to the newly created graph, or 0 if adding the graph failed. - - \see graph, graphCount, removeGraph, clearGraphs -*/ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; - return 0; - } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; - return 0; - } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); - return newGraph; -} - -/*! - Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in - the plot have a channel fill set towards the removed graph, the channel fill property of those - graphs is reset to zero (no channel fill). - - Returns true on success. - - \see clearGraphs -*/ -bool QCustomPlot::removeGraph(QCPGraph *graph) -{ - return removePlottable(graph); -} - -/*! \overload - - Removes and deletes the graph by its \a index. -*/ -bool QCustomPlot::removeGraph(int index) -{ - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); - else - return false; -} - -/*! - Removes all graphs from the plot and deletes them. Corresponding legend items are also removed - from the default legend (QCustomPlot::legend). - - Returns the number of graphs removed. - - \see removeGraph -*/ -int QCustomPlot::clearGraphs() -{ - int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); - return c; -} - -/*! - Returns the number of currently existing graphs in the plot - - \see graph, addGraph -*/ -int QCustomPlot::graphCount() const -{ - return mGraphs.size(); -} - -/*! - Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. - - If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, - etc., use \ref selectedPlottables. - - \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedGraphs() const -{ - QList result; - Q_FOREACH (QCPGraph *graph, mGraphs) - { - if (graph->selected()) - result.append(graph); - } - return result; -} - -/*! - Returns the item with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - item, see QCustomPlot::item() - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item(int index) const -{ - if (index >= 0 && index < mItems.size()) - { - return mItems.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last item that was added to this plot. If there are no items in the plot, - returns 0. - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item() const -{ - if (!mItems.isEmpty()) - { - return mItems.last(); - } else - return 0; -} - -/*! - Removes the specified item from the plot and deletes it. - - Returns true on success. - - \see clearItems -*/ -bool QCustomPlot::removeItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - delete item; - mItems.removeOne(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); - return false; - } -} - -/*! \overload - - Removes and deletes the item by its \a index. -*/ -bool QCustomPlot::removeItem(int index) -{ - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all items from the plot and deletes them. - - Returns the number of items removed. - - \see removeItem -*/ -int QCustomPlot::clearItems() -{ - int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); - return c; -} - -/*! - Returns the number of currently existing items in the plot - - \see item -*/ -int QCustomPlot::itemCount() const -{ - return mItems.size(); -} - -/*! - Returns a list of the selected items. If no items are currently selected, the list is empty. - - \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected -*/ -QList QCustomPlot::selectedItems() const -{ - QList result; - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (item->selected()) - result.append(item); - } - return result; -} - -/*! - Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref - QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref - setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is - returned. - - If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are - considered. - - If there is no item at \a pos, the return value is 0. - - \see plottableAt, layoutElementAt -*/ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable - continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it - { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultItem = item; - resultDistance = currentDistance; - } - } - } - - return resultItem; -} - -/*! - Returns whether this QCustomPlot contains the \a item. - - \see item -*/ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const -{ - return mItems.contains(item); -} - -/*! - Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is - returned. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(const QString &name) const -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - if (layer->name() == name) - return layer; - } - return 0; -} - -/*! \overload - - Returns the layer by \a index. If the index is invalid, 0 is returned. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(int index) const -{ - if (index >= 0 && index < mLayers.size()) - { - return mLayers.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Returns the layer that is set as current layer (see \ref setCurrentLayer). -*/ -QCPLayer *QCustomPlot::currentLayer() const -{ - return mCurrentLayer; -} - -/*! - Sets the layer with the specified \a name to be the current layer. All layerables (\ref - QCPLayerable), e.g. plottables and items, are created on the current layer. - - Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer -*/ -bool QCustomPlot::setCurrentLayer(const QString &name) -{ - if (QCPLayer *newCurrentLayer = layer(name)) - { - return setCurrentLayer(newCurrentLayer); - } else - { - qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; - return false; - } -} - -/*! \overload - - Sets the provided \a layer to be the current layer. - - Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. - - \see addLayer, moveLayer, removeLayer -*/ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - - mCurrentLayer = layer; - return true; -} - -/*! - Returns the number of currently existing layers in the plot - - \see layer, addLayer -*/ -int QCustomPlot::layerCount() const -{ - return mLayers.size(); -} - -/*! - Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which - must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. - - Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a - valid layer inside this QCustomPlot. - - If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. - - For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. - - \see layer, moveLayer, removeLayer -*/ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!otherLayer) - otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - if (layer(name)) - { - qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; - return false; - } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); - updateLayerIndices(); - setupPaintBuffers(); // associates new layer with the appropriate paint buffer - return true; -} - -/*! - Removes the specified \a layer and returns true on success. - - All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below - \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both - cases, the total rendering order of all layerables in the QCustomPlot is preserved. - - If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom - layer) becomes the new current layer. - - It is not possible to remove the last layer of the plot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::removeLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (mLayers.size() < 2) - { - qDebug() << Q_FUNC_INFO << "can't remove last layer"; - return false; - } - - // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) - int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); - QList children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) - { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally - { - for (int i=0; imoveToLayer(targetLayer, false); - } - // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); - // invalidate the paint buffer that was responsible for this layer: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - // remove layer: - delete layer; - mLayers.removeOne(layer); - updateLayerIndices(); - return true; -} - -/*! - Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or - below is controlled with \a insertMode. - - Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the - QCustomPlot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - - if (layer->index() > otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - else if (layer->index() < otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); - - // invalidate the paint buffers that are responsible for the layers: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - if (!otherLayer->mPaintBuffer.isNull()) - otherLayer->mPaintBuffer.data()->setInvalidated(); - - updateLayerIndices(); - return true; -} - -/*! - Returns the number of axis rects in the plot. - - All axis rects can be accessed via QCustomPlot::axisRect(). - - Initially, only one axis rect exists in the plot. - - \see axisRect, axisRects -*/ -int QCustomPlot::axisRectCount() const -{ - return axisRects().size(); -} - -/*! - Returns the axis rect with \a index. - - Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were - added, all of them may be accessed with this function in a linear fashion (even when they are - nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). - - \see axisRectCount, axisRects -*/ -QCPAxisRect *QCustomPlot::axisRect(int index) const -{ - const QList rectList = axisRects(); - if (index >= 0 && index < rectList.size()) - { - return rectList.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; - return 0; - } -} - -/*! - Returns all axis rects in the plot. - - \see axisRectCount, axisRect -*/ -QList QCustomPlot::axisRects() const -{ - QList result; - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) - { - if (element) - { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast(element)) - result.append(ar); - } - } - } - - return result; -} - -/*! - Returns the layout element at pixel position \a pos. If there is no element at that position, - returns 0. - - Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on - any of its parent elements is set to false, it will not be considered. - - \see itemAt, plottableAt -*/ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const -{ - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - break; - } - } - } - return currentElement; -} - -/*! - Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores - other layout elements even if they are visually in front of the axis rect (e.g. a \ref - QCPLegend). If there is no axis rect at that position, returns 0. - - Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or - on any of its parent elements is set to false, it will not be considered. - - \see layoutElementAt -*/ -QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const -{ - QCPAxisRect *result = 0; - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - if (QCPAxisRect *ar = qobject_cast(currentElement)) - result = ar; - break; - } - } - } - return result; -} - -/*! - Returns the axes that currently have selected parts, i.e. whose selection state is not \ref - QCPAxis::spNone. - - \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, - QCPAxis::setSelectableParts -*/ -QList QCustomPlot::selectedAxes() const -{ - QList result, allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); - } - - return result; -} - -/*! - Returns the legends that currently have selected parts, i.e. whose selection state is not \ref - QCPLegend::spNone. - - \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, - QCPLegend::setSelectableParts, QCPLegend::selectedItems -*/ -QList QCustomPlot::selectedLegends() const -{ - QList result; - - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) - { - if (subElement) - { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast(subElement)) - { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); - } - } - } - } - - return result; -} - -/*! - Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. - - Since calling this function is not a user interaction, this does not emit the \ref - selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the - objects were previously selected. - - \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends -*/ -void QCustomPlot::deselectAll() -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); - } -} - -/*! - Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is - refreshed with the new buffer contents. This is the method that must be called to make changes to - the plot, e.g. on the axis ranges or data points of graphs, visible. - - The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example - if your application calls \ref replot very quickly in succession (e.g. multiple independent - functions change some aspects of the plot and each wants to make sure the change gets replotted), - it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the - actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref - replot with this priority will only cause a single replot, avoiding redundant replots and - improving performance. - - Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the - QCustomPlot widget and user interactions (object selection and range dragging/zooming). - - Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref - afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two - signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite - recursion. - - If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to - replot only that specific layer via \ref QCPLayer::replot. See the documentation there for - details. -*/ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) -{ - if (refreshPriority == QCustomPlot::rpQueuedReplot) - { - if (!mReplotQueued) - { - mReplotQueued = true; - QTimer::singleShot(0, this, SLOT(replot())); - } - return; - } - - if (mReplotting) // incase signals loop back to replot slot - return; - mReplotting = true; - mReplotQueued = false; - Q_EMIT beforeReplot(); - - updateLayout(); - // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: - setupPaintBuffers(); - Q_FOREACH (QCPLayer *layer, mLayers) - layer->drawToPaintBuffer(); - for (int i=0; isetInvalidated(false); - - if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) - repaint(); - else - update(); - - Q_EMIT afterReplot(); - mReplotting = false; -} - -/*! - Rescales the axes such that all plottables (like graphs) in the plot are fully visible. - - if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true - (QCPLayerable::setVisible), will be used to rescale the axes. - - \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale -*/ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) -{ - QList allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); -} - -/*! - Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale - of texts and lines will be derived from the specified \a width and \a height. This means, the - output will look like the normal on-screen output of a QCustomPlot widget with the corresponding - pixel width and height. If either \a width or \a height is zero, the exported image will have the - same dimensions as the QCustomPlot widget currently has. - - Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when - drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as - a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information - about cosmetic pens, see the QPainter and QPen documentation. - - The objects of the plot will appear in the current selection state. If you don't want any - selected objects to be painted in their selected look, deselect everything with \ref deselectAll - before calling this function. - - Returns true on success. - - \warning - \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it - is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines - (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). - \li If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting - PDF file. - - \note On Android systems, this method does nothing and issues an according qDebug warning - message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. - - \see savePng, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) -{ - bool success = false; -#ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(exportPen) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(pdfCreator) - Q_UNUSED(pdfTitle) - qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; -#else - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); -#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) - printer.setFullPage(true); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); -#else - QPageLayout pageLayout; - pageLayout.setMode(QPageLayout::FullPageMode); - pageLayout.setOrientation(QPageLayout::Portrait); - pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); - pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); - printer.setPageLayout(pageLayout); -#endif - QCPPainter printpainter; - if (printpainter.begin(&printer)) - { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && - mBackgroundBrush.color() != Qt::white && - mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); - printpainter.end(); - success = true; - } - setViewport(oldViewport); -#endif // QT_NO_PRINTER - return success; -} - -/*! - Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the PNG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) - with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); -} - -/*! - Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the JPEG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveBmp, saveRastered -*/ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); -} - -/*! - Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the BMP format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveJpg, saveRastered -*/ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); -} - -/*! \internal - - Returns a minimum size hint that corresponds to the minimum size of the top level layout - (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum - size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. - This is especially important, when placed in a QLayout where other components try to take in as - much space as possible (e.g. QMdiArea). -*/ -QSize QCustomPlot::minimumSizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Returns a size hint that is the same as \ref minimumSizeHint. - -*/ -QSize QCustomPlot::sizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but - draws the internal buffer on the widget surface. -*/ -void QCustomPlot::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - QCPPainter painter(this); - if (painter.isActive()) - { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - drawBackground(&painter); - for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) - mPaintBuffers.at(bufferIndex)->draw(&painter); - } -} - -/*! \internal - - Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect - of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. -*/ -void QCustomPlot::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event) - // resize and repaint the buffer: - setViewport(rect()); - replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) -} - -/*! \internal - - Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then - determines the layerable under the cursor and forwards the event to it. Finally, emits the - specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref - axisDoubleClick, etc.). - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_EMIT mouseDoubleClick(event); - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - // determine layerable under the cursor (this event is called instead of the second press event in a double-click): - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - - // emit specialized object double click signals: - if (!candidates.isEmpty()) - { - if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) - { - int dataIndex = 0; - if (!details.first().value().isEmpty()) - dataIndex = details.first().value().dataRange().begin(); - Q_EMIT plottableDoubleClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(candidates.first())) - Q_EMIT axisDoubleClick(ax, details.first().value(), event); - else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) - Q_EMIT itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(li->parentLegend(), li, event); - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is pressed. Emits the mousePress signal. - - If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the - selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCustomPlot::mousePressEvent(QMouseEvent *event) -{ - Q_EMIT mousePress(event); - // save some state to tell in releaseEvent whether it was a click: - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - if (mSelectionRect && mSelectionRectMode != QCP::srmNone) - { - if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect - mSelectionRect->startSelection(event); - } else - { - // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - if (!candidates.isEmpty()) - { - mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) - mMouseSignalLayerableDetails = details.first(); - } - // forward event to topmost candidate which accepts the event: - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list - candidates.at(i)->mousePressEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when the cursor is moved. Emits the \ref mouseMove signal. - - If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it - in order to update the rect geometry. - - Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the - layout element before), the mouseMoveEvent is forwarded to that element. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) -{ - Q_EMIT mouseMove(event); - - if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) - mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release - - if (mSelectionRect && mSelectionRect->isActive()) - mSelectionRect->moveSelection(event); - else if (mMouseEventLayerable) // call event of affected layerable: - mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. - - If the mouse was moved less than a certain threshold in any direction since the \ref - mousePressEvent, it is considered a click which causes the selection mechanism (if activated via - \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse - click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) - - If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable - before), the \ref mouseReleaseEvent is forwarded to that element. - - \see mousePressEvent, mouseMoveEvent -*/ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) -{ - Q_EMIT mouseRelease(event); - - if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click - { - if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here - mSelectionRect->cancel(); - if (event->button() == Qt::LeftButton) - processPointSelection(event); - - // emit specialized click signals of QCustomPlot instance: - if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) - { - int dataIndex = 0; - if (!mMouseSignalLayerableDetails.value().isEmpty()) - dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); - Q_EMIT plottableClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) - Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); - else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) - Q_EMIT itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(li->parentLegend(), li, event); - mMouseSignalLayerable = 0; - } - - if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there - { - // finish selection rect, the appropriate action will be taken via signal-slot connection: - mSelectionRect->endSelection(event); - } else - { - // call event of affected layerable: - if (mMouseEventLayerable) - { - mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); - mMouseEventLayerable = 0; - } - } - - if (noAntialiasingOnDrag()) - replot(rpQueuedReplot); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then - determines the affected layerable and forwards the event to it. -*/ -void QCustomPlot::wheelEvent(QWheelEvent *event) -{ - Q_EMIT mouseWheel(event); - // forward event to layerable under cursor: - QList candidates = layerableListAt(event->pos(), false); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->wheelEvent(event); - if (event->isAccepted()) - break; - } - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - This function draws the entire plot, including background pixmap, with the specified \a painter. - It does not make use of the paint buffers like \ref replot, so this is the function typically - used by saving/exporting methods such as \ref savePdf or \ref toPainter. - - Note that it does not fill the background with the background brush (as the user may specify with - \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this - method. -*/ -void QCustomPlot::draw(QCPPainter *painter) -{ - updateLayout(); - - // draw viewport background pixmap: - drawBackground(painter); - - // draw all layered objects (grid, axes, plottables, items, legend,...): - Q_FOREACH (QCPLayer *layer, mLayers) - layer->draw(painter); - - /* Debug code to draw all layout element rects - foreach (QCPLayoutElement* el, findChildren()) - { - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->rect()); - painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->outerRect()); - } - */ -} - -/*! \internal - - Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref - QCPLayoutElement::update on the main plot layout. - - Here, the layout elements calculate their positions and margins, and prepare for the following - draw call. -*/ -void QCustomPlot::updateLayout() -{ - // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); -} - -/*! \internal - - Draws the viewport background pixmap of the plot. - - If a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the viewport with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - Note that this function does not draw a fill with the background brush - (\ref setBackground(const QBrush &brush)) beneath the pixmap. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::drawBackground(QCPPainter *painter) -{ - // Note: background color is handled in individual replot/save functions - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); - } - } -} - -/*! \internal - - Goes through the layers and makes sure this QCustomPlot instance holds the correct number of - paint buffers and that they have the correct configuration (size, pixel ratio, etc.). - Allocations, reallocations and deletions of paint buffers are performed as necessary. It also - associates the paint buffers with the layers, so they draw themselves into the right buffer when - \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref - QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for - layers in \ref QCPLayer::lmBuffered mode. - - This method uses \ref createPaintBuffer to create new paint buffers. - - After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated - (so an attempt to replot only a single buffered layer causes a full replot). - - This method is called in every \ref replot call, prior to actually drawing the layers (into their - associated paint buffer). If the paint buffers don't need changing/reallocating, this method - basically leaves them alone and thus finishes very fast. -*/ -void QCustomPlot::setupPaintBuffers() -{ - int bufferIndex = 0; - if (mPaintBuffers.isEmpty()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - - for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) - { - QCPLayer *layer = mLayers.at(layerIndex); - if (layer->mode() == QCPLayer::lmLogical) - { - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - } else if (layer->mode() == QCPLayer::lmBuffered) - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - } - } - } - // remove unneeded buffers: - while (mPaintBuffers.size()-1 > bufferIndex) - mPaintBuffers.removeLast(); - // resize buffers to viewport size and clear contents: - for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size - mPaintBuffers.at(i)->clear(Qt::transparent); - mPaintBuffers.at(i)->setInvalidated(); - } -} - -/*! \internal - - This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. - - Depending on the current setting of \ref setOpenGl, and the current Qt version, different - backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper - size and device pixel ratio, and returned. -*/ -QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() -{ - if (mOpenGl) - { -#if defined(QCP_OPENGL_FBO) - return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); -#elif defined(QCP_OPENGL_PBUFFER) - return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); -#else - qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -#endif - } else - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -} - -/*! - This method returns whether any of the paint buffers held by this QCustomPlot instance are - invalidated. - - If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always - causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example - the layer order has changed, new layers were added, layers were removed, or layer modes were - changed (\ref QCPLayer::setMode). - - \see QCPAbstractPaintBuffer::setInvalidated -*/ -bool QCustomPlot::hasInvalidatedPaintBuffers() -{ - for (int i=0; iinvalidated()) - return true; - } - return false; -} - -/*! \internal - - When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, - surface, paint device). - - Returns true on success. - - If this method is successful, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref - QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. - - \see freeOpenGl -*/ -bool QCustomPlot::setupOpenGl() -{ -#ifdef QCP_OPENGL_FBO - freeOpenGl(); - QSurfaceFormat proposedSurfaceFormat; - proposedSurfaceFormat.setSamples(mOpenGlMultisamples); -#ifdef QCP_OPENGL_OFFSCREENSURFACE - QOffscreenSurface *surface = new QOffscreenSurface; -#else - QWindow *surface = new QWindow; - surface->setSurfaceType(QSurface::OpenGLSurface); -#endif - surface->setFormat(proposedSurfaceFormat); - surface->create(); - mGlSurface = QSharedPointer(surface); - mGlContext = QSharedPointer(new QOpenGLContext); - mGlContext->setFormat(mGlSurface->format()); - if (!mGlContext->create()) - { - qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device - { - qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - { - qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); - return true; -#elif defined(QCP_OPENGL_PBUFFER) - return QGLFormat::hasOpenGL(); -#else - return false; -#endif -} - -/*! \internal - - When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the - context and frees resources). - - After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref - QCPPaintBufferPixmap) is used for subsequent replots. - - \see setupOpenGl -*/ -void QCustomPlot::freeOpenGl() -{ -#ifdef QCP_OPENGL_FBO - mGlPaintDevice.clear(); - mGlContext.clear(); - mGlSurface.clear(); -#endif -} - -/*! \internal - - This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot - so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. -*/ -void QCustomPlot::axisRemoved(QCPAxis *axis) -{ - if (xAxis == axis) - xAxis = 0; - if (xAxis2 == axis) - xAxis2 = 0; - if (yAxis == axis) - yAxis = 0; - if (yAxis2 == axis) - yAxis2 = 0; - - // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers -} - -/*! \internal - - This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so - it may clear its QCustomPlot::legend member accordingly. -*/ -void QCustomPlot::legendRemoved(QCPLegend *legend) -{ - if (this->legend == legend) - this->legend = 0; -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmSelect. - - First, it determines which axis rect was the origin of the selection rect judging by the starting - point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be - precise) associated with that axis rect and finds the data points that are in \a rect. It does - this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. - - Then, the actual selection is done by calling the plottables' \ref - QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details - parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a - rect receive a \ref QCPAbstractPlottable::deselectEvent. - - \see processRectZoom -*/ -void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) -{ - bool selectionStateChanged = false; - - if (mInteractions.testFlag(QCP::iSelectPlottables)) - { - QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size - QRectF rectF(rect.normalized()); - if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) - { - // determine plottables that were hit by the rect and thus are candidates for selection: - Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) - { - if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) - { - QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); - if (!dataSel.isEmpty()) - potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); - } - } - - if (!mInteractions.testFlag(QCP::iMultiSelect)) - { - // only leave plottable with most selected points in map, since we will only select a single plottable: - if (!potentialSelections.isEmpty()) - { - QMap >::iterator it = potentialSelections.begin(); - while (it != potentialSelections.end()-1) // erase all except last element - it = potentialSelections.erase(it); - } - } - - bool additive = event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - // emit deselection except to those plottables who will be selected afterwards: - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - // go through selections in reverse (largest selection first) and emit select events: - QMap >::const_iterator it = potentialSelections.constEnd(); - while (it != potentialSelections.constBegin()) - { - --it; - if (mInteractions.testFlag(it.value().first->selectionCategory())) - { - bool selChanged = false; - it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } else if (mSelectionRect) - mSelectionRect->layer()->replot(); -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmZoom. - - It determines which axis rect was the origin of the selection rect judging by the starting point - of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the - provided \a rect (see \ref QCPAxisRect::zoom). - - \see processRectSelection -*/ -void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) -{ - Q_UNUSED(event) - if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) - { - QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); - affectedAxes.removeAll(static_cast(0)); - axisRect->zoom(QRectF(rect), affectedAxes); - } - replot(rpQueuedReplot); // always replot to make selection rect disappear -} - -/*! \internal - - This method is called when a simple left mouse click was detected on the QCustomPlot surface. - - It first determines the layerable that was hit by the click, and then calls its \ref - QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the - multi-select modifier was pressed, see \ref setMultiSelectModifier). - - In this method the hit layerable is determined a second time using \ref layerableAt (after the - one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This - implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the - clicked layerable determined here. For example, if a non-selectable layerable is in front of a - selectable layerable at the click position, the front layerable will receive mouse events but the - selectable one in the back will receive the \ref QCPLayerable::selectEvent. - - \see processRectSelection, QCPLayerable::selectTest -*/ -void QCustomPlot::processPointSelection(QMouseEvent *event) -{ - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); - bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) - { - // a layerable was actually clicked, call its selectEvent: - bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); - selectionStateChanged |= selChanged; - } - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } -} - -/*! \internal - - Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend - is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the - plottable. - - Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of - \a plottable is this QCustomPlot. - - This method is called automatically in the QCPAbstractPlottable base class constructor. -*/ -bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) -{ - if (mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); - return false; - } - if (plottable->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); - return false; - } - - mPlottables.append(plottable); - // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) - plottable->addToLegend(); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); - return true; -} - -/*! \internal - - In order to maintain the simplified graph interface of QCustomPlot, this method is called by the - QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true - on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. - - This graph specific registration happens in addition to the call to \ref registerPlottable by the - QCPAbstractPlottable base class. -*/ -bool QCustomPlot::registerGraph(QCPGraph *graph) -{ - if (!graph) - { - qDebug() << Q_FUNC_INFO << "passed graph is zero"; - return false; - } - if (mGraphs.contains(graph)) - { - qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; - return false; - } - - mGraphs.append(graph); - return true; -} - - -/*! \internal - - Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. - - Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a - item is this QCustomPlot. - - This method is called automatically in the QCPAbstractItem base class constructor. -*/ -bool QCustomPlot::registerItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); - return false; - } - if (item->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); - return false; - } - - mItems.append(item); - if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) - item->setLayer(currentLayer()); - return true; -} - -/*! \internal - - Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called - after every operation that changes the layer indices, like layer removal, layer creation, layer - moving. -*/ -void QCustomPlot::updateLayerIndices() const -{ - for (int i=0; imIndex = i; -} - -/*! \internal - - Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, - only those layerables that are selectable will be considered. (Layerable subclasses communicate - their selectability via the QCPLayerable::selectTest method, by returning -1.) - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableListAt, layoutElementAt, axisRectAt -*/ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const -{ - QList details; - QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); - if (selectionDetails && !details.isEmpty()) - *selectionDetails = details.first(); - if (!candidates.isEmpty()) - return candidates.first(); - else - return 0; -} - -/*! \internal - - Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those - layerables that are selectable will be considered. (Layerable subclasses communicate their - selectability via the QCPLayerable::selectTest method, by returning -1.) - - The returned list is sorted by the layerable/drawing order. If you only need to know the top-most - layerable, rather use \ref layerableAt. - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableAt, layoutElementAt, axisRectAt -*/ -QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const -{ - QList result; - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) - { - const QList layerables = mLayers.at(layerIndex)->children(); - for (int i=layerables.size()-1; i>=0; --i) - { - if (!layerables.at(i)->realVisibility()) - continue; - QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); - if (dist >= 0 && dist < selectionTolerance()) - { - result.append(layerables.at(i)); - if (selectionDetails) - selectionDetails->append(details); - } - } - } - return result; -} - -/*! - Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is - sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead - to a full resolution file with width 200.) If the \a format supports compression, \a quality may - be between 0 and 100 to control it. - - Returns true on success. If this function fails, most likely the given \a format isn't supported - by the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The \a resolution will be written to the image file header (if the file format supports this) and - has no direct consequence for the quality or the pixel size. However, if opening the image with a - tool which respects the metadata, it will be able to scale the image to match either a given size - in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in - which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted - to the format's expected resolution unit internally. - - \see saveBmp, saveJpg, savePng, savePdf -*/ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - QImage buffer = toPixmap(width, height, scale).toImage(); - - int dotsPerMeter = 0; - switch (resolutionUnit) - { - case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; - case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; - case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; - } - buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); - else - return false; -} - -/*! - Renders the plot to a pixmap and returns it. - - The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and - scale 2.0 lead to a full resolution pixmap with width 200.) - - \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf -*/ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) -{ - // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); - - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later - QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) - { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); - } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); - painter.end(); - } else // might happen if pixmap has width or height zero - { - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; - return QPixmap(); - } - return result; -} - -/*! - Renders the plot using the passed \a painter. - - The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will - appear scaled accordingly. - - \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter - on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with - the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. - - \see toPixmap -*/ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) -{ - // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - if (painter->isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else - qDebug() << Q_FUNC_INFO << "Passed painter is not active"; -} -/* end of 'src/core.cpp' */ - -//amalgamation: add plottable1d.cpp - -/* including file 'src/colorgradient.cpp', size 24646 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorGradient -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorGradient - \brief Defines a color gradient for use with e.g. \ref QCPColorMap - - This class describes a color gradient which can be used to encode data with color. For example, - QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which - take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) - with a \a position from 0 to 1. In between these defined color positions, the - color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. - - Alternatively, load one of the preset color gradients shown in the image below, with \ref - loadPreset, or by directly specifying the preset in the constructor. - - Apart from red, green and blue components, the gradient also interpolates the alpha values of the - configured color stops. This allows to display some portions of the data range as transparent in - the plot. - - \image html QCPColorGradient.png - - The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref - GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset - to all the \a setGradient methods, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient - - The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the - color gradient shall be applied periodically (wrapping around) to data values that lie outside - the data range specified on the plottable instance can be controlled with \ref setPeriodic. -*/ - -/*! - Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color - stops with \ref setColorStopAt. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient() : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); -} - -/*! - Constructs a new QCPColorGradient initialized with the colors and color interpolation according - to \a preset. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); -} - -/* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const -{ - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); -} - -/*! - Sets the number of discretization levels of the color gradient to \a n. The default is 350 which - is typically enough to create a smooth appearance. The minimum number of levels is 2. - - \image html QCPColorGradient-levelcount.png -*/ -void QCPColorGradient::setLevelCount(int n) -{ - if (n < 2) - { - qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; - n = 2; - } - if (n != mLevelCount) - { - mLevelCount = n; - mColorBufferInvalidated = true; - } -} - -/*! - Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the - colors are the values of the passed QMap \a colorStops. In between these color stops, the color - is interpolated according to \ref setColorInterpolation. - - A more convenient way to create a custom gradient may be to clear all color stops with \ref - clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with - \ref setColorStopAt. - - \see clearColorStops -*/ -void QCPColorGradient::setColorStops(const QMap &colorStops) -{ - mColorStops = colorStops; - mColorBufferInvalidated = true; -} - -/*! - Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between - these color stops, the color is interpolated according to \ref setColorInterpolation. - - \see setColorStops, clearColorStops -*/ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) -{ - mColorStops.insert(position, color); - mColorBufferInvalidated = true; -} - -/*! - Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be - interpolated linearly in RGB or in HSV color space. - - For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, - whereas in HSV space the intermediate color is yellow. -*/ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) -{ - if (interpolation != mColorInterpolation) - { - mColorInterpolation = interpolation; - mColorBufferInvalidated = true; - } -} - -/*! - Sets whether data points that are outside the configured data range (e.g. \ref - QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether - they all have the same color, corresponding to the respective gradient boundary color. - - \image html QCPColorGradient-periodic.png - - As shown in the image above, gradients that have the same start and end color are especially - suitable for a periodic gradient mapping, since they produce smooth color transitions throughout - the color map. A preset that has this property is \ref gpHues. - - In practice, using periodic color gradients makes sense when the data corresponds to a periodic - dimension, such as an angle or a phase. If this is not the case, the color encoding might become - ambiguous, because multiple different data values are shown as the same color. -*/ -void QCPColorGradient::setPeriodic(bool enabled) -{ - mPeriodic = enabled; -} - -/*! \overload - - This method is used to quickly convert a \a data array to colors. The colors will be output in - the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this - function. The data range that shall be used for mapping the data value to the gradient is passed - in \a range. \a logarithmic indicates whether the data values shall be mapped to colors - logarithmically. - - if \a data actually contains 2D-data linearized via [row*columnCount + column], you can - set \a dataIndexFactor to columnCount to convert a column instead of a row of the data - array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data - is addressed data[i*dataIndexFactor]. - - Use the overloaded method to additionally provide alpha map data. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } -} - -/*! \overload - - Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which - has the same size and structure as \a data and encodes the alpha information per data point. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!alpha) - { - qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } -} - -/*! \internal - - This method is used to colorize a single data value given in \a position, to colors. The data - range that shall be used for mapping the data value to the gradient is passed in \a range. \a - logarithmic indicates whether the data value shall be mapped to a color logarithmically. - - If an entire array of data values shall be converted, rather use \ref colorize, for better - performance. - - The returned QRgb has its r, g and b components premultiplied with alpha (see - QImage::Format_ARGB32_Premultiplied). -*/ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) - updateColorBuffer(); - int index = 0; - if (!logarithmic) - index = (position-range.lower)*(mLevelCount-1)/range.size(); - else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); - if (mPeriodic) - { - index = index % mLevelCount; - if (index < 0) - index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - } - return mColorBuffer.at(index); -} - -/*! - Clears the current color stops and loads the specified \a preset. A preset consists of predefined - color stops and the corresponding color interpolation method. - - The available presets are: - \image html QCPColorGradient.png -*/ -void QCPColorGradient::loadPreset(GradientPreset preset) -{ - clearColorStops(); - switch (preset) - { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; - } -} - -/*! - Clears all color stops. - - \see setColorStops, setColorStopAt -*/ -void QCPColorGradient::clearColorStops() -{ - mColorStops.clear(); - mColorBufferInvalidated = true; -} - -/*! - Returns an inverted gradient. The inverted gradient has all properties as this \ref - QCPColorGradient, but the order of the color stops is inverted. - - \see setColorStops, setColorStopAt -*/ -QCPColorGradient QCPColorGradient::inverted() const -{ - QCPColorGradient result(*this); - result.clearColorStops(); - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); - return result; -} - -/*! \internal - - Returns true if the color gradient uses transparency, i.e. if any of the configured color stops - has an alpha value below 255. -*/ -bool QCPColorGradient::stopsUseAlpha() const -{ - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - { - if (it.value().alpha() < 255) - return true; - } - return false; -} - -/*! \internal - - Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly - convert positions to colors. This is where the interpolation between color stops is calculated. -*/ -void QCPColorGradient::updateColorBuffer() -{ - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) - { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); - const bool useAlpha = stopsUseAlpha(); - for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop - { - mColorBuffer[i] = (it-1).value().rgba(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop - { - mColorBuffer[i] = it.value().rgba(); - } else // position is in between stops (or on an intermediate stop), interpolate color - { - QMap::const_iterator high = it; - QMap::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) - { - case ciRGB: - { - if (useAlpha) - { - const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); - const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, - ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, - ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, - alpha); - } else - { - mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), - ((1-t)*low.value().green() + t*high.value().green()), - ((1-t)*low.value().blue() + t*high.value().blue())); - } - break; - } - case ciHSV: - { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - if (useAlpha) - { - const QRgb rgb = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); - mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); - } - else - { - mColorBuffer[i] = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - } - break; - } - } - } - } - } else if (mColorStops.size() == 1) - { - const QRgb rgb = mColorStops.constBegin().value().rgb(); - const float alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); - } else // mColorStops is empty, fill color buffer with black - { - mColorBuffer.fill(qRgb(0, 0, 0)); - } - mColorBufferInvalidated = false; -} -/* end of 'src/colorgradient.cpp' */ - - -/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecoratorBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecoratorBracket - \brief A selection decorator which draws brackets around each selected data segment - - Additionally to the regular highlighting of selected segments via color, fill and scatter style, - this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data - segment of the plottable. - - The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and - \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref - setBracketBrush. - - To introduce custom bracket styles, it is only necessary to sublcass \ref - QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the - base class. -*/ - -/*! - Creates a new QCPSelectionDecoratorBracket instance with default values. -*/ -QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : - mBracketPen(QPen(Qt::black)), - mBracketBrush(Qt::NoBrush), - mBracketWidth(5), - mBracketHeight(50), - mBracketStyle(bsSquareBracket), - mTangentToData(false), - mTangentAverage(2) -{ - -} - -QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() -{ -} - -/*! - Sets the pen that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) -{ - mBracketPen = pen; -} - -/*! - Sets the brush that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) -{ - mBracketBrush = brush; -} - -/*! - Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of - the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketWidth(int width) -{ - mBracketWidth = width; -} - -/*! - Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis - of the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketHeight(int height) -{ - mBracketHeight = height; -} - -/*! - Sets the shape that the bracket/marker will have. - - \see setBracketWidth, setBracketHeight -*/ -void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) -{ - mBracketStyle = style; -} - -/*! - Sets whether the brackets will be rotated such that they align with the slope of the data at the - position that they appear in. - - For noisy data, it might be more visually appealing to average the slope over multiple data - points. This can be configured via \ref setTangentAverage. -*/ -void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) -{ - mTangentToData = enabled; -} - -/*! - Controls over how many data points the slope shall be averaged, when brackets shall be aligned - with the data (if \ref setTangentToData is true). - - From the position of the bracket, \a pointCount points towards the selected data range will be - taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to - disabling \ref setTangentToData. -*/ -void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) -{ - mTangentAverage = pointCount; - if (mTangentAverage < 1) - mTangentAverage = 1; -} - -/*! - Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and - indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening - bracket, respectively). - - The passed \a painter already contains all transformations that are necessary to position and - rotate the bracket appropriately. Painting operations can be performed as if drawing upright - brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. - - If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket - shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should - reimplement. -*/ -void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const -{ - switch (mBracketStyle) - { - case bsSquareBracket: - { - painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); - painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - break; - } - case bsHalfEllipse: - { - painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); - break; - } - case bsEllipse: - { - painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); - break; - } - case bsPlus: - { - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); - break; - } - default: - { - qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); - break; - } - } -} - -/*! - Draws the bracket decoration on the data points at the begin and end of each selected data - segment given in \a seletion. - - It uses the method \ref drawBracket to actually draw the shapes. - - \seebaseclassmethod -*/ -void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - if (!mPlottable || selection.isEmpty()) return; - - if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) - { - Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) - { - // determine position and (if tangent mode is enabled) angle of brackets: - int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; - int closeBracketDir = -openBracketDir; - QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); - QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); - double openBracketAngle = 0; - double closeBracketAngle = 0; - if (mTangentToData) - { - openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); - closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); - } - // draw opening bracket: - QTransform oldTransform = painter->transform(); - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(openBracketPos); - painter->rotate(openBracketAngle/M_PI*180.0); - drawBracket(painter, openBracketDir); - painter->setTransform(oldTransform); - // draw closing bracket: - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(closeBracketPos); - painter->rotate(closeBracketAngle/M_PI*180.0); - drawBracket(painter, closeBracketDir); - painter->setTransform(oldTransform); - } - } -} - -/*! \internal - - If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. - This method returns the angle in radians by which a bracket at the given \a dataIndex must be - rotated. - - The parameter \a direction must be set to either -1 or 1, representing whether it is an opening - or closing bracket. Since for slope calculation multiple data points are required, this defines - the direction in which the algorithm walks, starting at \a dataIndex, to average those data - points. (see \ref setTangentToData and \ref setTangentAverage) - - \a interface1d is the interface to the plottable's data which is used to query data coordinates. -*/ -double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const -{ - if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) - return 0; - direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 - - // how many steps we can actually go from index in the given direction without exceeding data bounds: - int averageCount; - if (direction < 0) - averageCount = qMin(mTangentAverage, dataIndex); - else - averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); - qDebug() << averageCount; - // calculate point average of averageCount points: - QVector points(averageCount); - QPointF pointsAverage; - int currentIndex = dataIndex; - for (int i=0; ikeyAxis(); - QCPAxis *valueAxis = mPlottable->valueAxis(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); - else - return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); -} -/* end of 'src/selectiondecorator-bracket.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisRect - \brief Holds multiple axes and arranges them in a rectangular shape. - - This class represents an axis rect, a rectangular area that is bounded on all sides with an - arbitrary number of axes. - - Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the - layout system allows to have multiple axis rects, e.g. arranged in a grid layout - (QCustomPlot::plotLayout). - - By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be - accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. - If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be - invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref - addAxes. To remove an axis, use \ref removeAxis. - - The axis rect layerable itself only draws a background pixmap or color, if specified (\ref - setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an - explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be - placed on other layers, independently of the axis rect. - - Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref - insetLayout and can be used to have other layout elements (or even other layouts with multiple - elements) hovering inside the axis rect. - - If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The - behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel - is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable - via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are - only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref - QCP::iRangeZoom. - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed - line on the far left indicates the viewport/widget border.
-*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const - - Returns the inset layout of this axis rect. It can be used to place other layout elements (or - even layouts with multiple other elements) inside/on top of an axis rect. - - \see QCPLayoutInset -*/ - -/*! \fn int QCPAxisRect::left() const - - Returns the pixel position of the left border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::right() const - - Returns the pixel position of the right border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::top() const - - Returns the pixel position of the top border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::bottom() const - - Returns the pixel position of the bottom border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::width() const - - Returns the pixel width of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::height() const - - Returns the pixel height of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QSize QCPAxisRect::size() const - - Returns the pixel size of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topLeft() const - - Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, - so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topRight() const - - Returns the top right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomLeft() const - - Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomRight() const - - Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::center() const - - Returns the center of this axis rect in pixels. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four - sides, the top and right axes are set invisible initially. -*/ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) -{ - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList()); - mAxes.insert(QCPAxis::atRight, QList()); - mAxes.insert(QCPAxis::atTop, QList()); - mAxes.insert(QCPAxis::atBottom, QList()); - - if (setupDefaultAxes) - { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - } -} - -QCPAxisRect::~QCPAxisRect() -{ - delete mInsetLayout; - mInsetLayout = 0; - - QList axesList = axes(); - for (int i=0; i ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) - { - return ax.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; - return 0; - } -} - -/*! - Returns all axes on the axis rect sides specified with \a types. - - \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of - multiple sides. - - \see axis -*/ -QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); - return result; -} - -/*! \overload - - Returns all axes of this axis rect. -*/ -QList QCPAxisRect::axes() const -{ - QList result; - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - result << it.value(); - } - return result; -} - -/*! - Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a - new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to - remove an axis, use \ref removeAxis instead of deleting it manually. - - You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was - previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership - of the axis, so you may not delete it afterwards. Further, the \a axis must have been created - with this axis rect as parent and with the same axis type as specified in \a type. If this is not - the case, a debug output is generated, the axis is not added, and the method returns 0. - - This method can not be used to move \a axis between axis rects. The same \a axis instance must - not be added multiple times to the same or different axis rects. - - If an axis rect side already contains one or more axes, the lower and upper endings of the new - axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref - QCPLineEnding::esHalfBar. - - \see addAxes, setupFullAxesBox -*/ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) -{ - QCPAxis *newAxis = axis; - if (!newAxis) - { - newAxis = new QCPAxis(this, type); - } else // user provided existing axis instance, do some sanity checks - { - if (newAxis->axisType() != type) - { - qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; - return 0; - } - if (newAxis->axisRect() != this) - { - qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; - return 0; - } - if (axes().contains(newAxis)) - { - qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; - return 0; - } - } - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset - { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); - } - mAxes[type].append(newAxis); - - // reset convenience axis pointers on parent QCustomPlot if they are unset: - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - switch (type) - { - case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } - case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } - case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } - case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } - } - } - - return newAxis; -} - -/*! - Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an - or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. - - Returns a list of the added axes. - - \see addAxis, setupFullAxesBox -*/ -QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); - return result; -} - -/*! - Removes the specified \a axis from the axis rect and deletes it. - - Returns true on success, i.e. if \a axis was a valid axis in this axis rect. - - \see addAxis -*/ -bool QCPAxisRect::removeAxis(QCPAxis *axis) -{ - // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(axis)) - { - if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) - it.value()[1]->setOffset(axis->offset()); - mAxes[it.key()].removeOne(axis); - if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); - delete axis; - return true; - } - } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); - return false; -} - -/*! - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom - specific axes, use the overloaded version of this method. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect) -{ - zoom(pixelRect, axes()); -} - -/*! \overload - - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) -{ - Q_FOREACH (QCPAxis *axis, affectedAxes) - { - if (!axis) - { - qDebug() << Q_FUNC_INFO << "a passed axis was zero"; - continue; - } - QCPRange pixelRange; - if (axis->orientation() == Qt::Horizontal) - pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); - else - pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); - axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); - } -} - -/*! - Convenience function to create an axis on each side that doesn't have any axes yet and set their - visibility to true. Further, the top/right axes are assigned the following properties of the - bottom/left axes: - - \li range (\ref QCPAxis::setRange) - \li range reversed (\ref QCPAxis::setRangeReversed) - \li scale type (\ref QCPAxis::setScaleType) - \li tick visibility (\ref QCPAxis::setTicks) - \li number format (\ref QCPAxis::setNumberFormat) - \li number precision (\ref QCPAxis::setNumberPrecision) - \li tick count of ticker (\ref QCPAxisTicker::setTickCount) - \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) - - Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. - - If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom - and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. -*/ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) -{ - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); - else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); - else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); - else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); - else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); - xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); - yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); - - if (connectRanges) - { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); - } -} - -/*! - Returns a list of all the plottables that are associated with this axis rect. - - A plottable is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see graphs, items -*/ -QList QCPAxisRect::plottables() const -{ - // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries - QList result; - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that are associated with this axis rect. - - A graph is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see plottables, items -*/ -QList QCPAxisRect::graphs() const -{ - // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries - QList result; - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis rect. - - An item is considered associated with an axis rect if any of its positions has key or value axis - set to an axis that is in this axis rect, or if any of its positions has \ref - QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref - QCPAbstractItem::setClipAxisRect) is set to this axis rect. - - \see plottables, graphs -*/ -QList QCPAxisRect::items() const -{ - // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries - // and miss those items that have this axis rect as clipAxisRect. - QList result; - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - continue; - } - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdaxisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - This method is called automatically upon replot and doesn't need to be called by users of - QCPAxisRect. - - Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), - and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its - QCPInsetLayout::update function. - - \seebaseclassmethod -*/ -void QCPAxisRect::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - switch (phase) - { - case upPreparation: - { - QList allAxes = axes(); - for (int i=0; isetupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; - } - - // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); -} - -/* inherits documentation from base class */ -QList QCPAxisRect::elements(bool recursive) const -{ - QList result; - if (mInsetLayout) - { - result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); - } - return result; -} - -/* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) -{ - drawBackground(painter); -} - -/*! - Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the - axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect - backgrounds are usually drawn below everything else. - - For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio - is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref - setBackground(const QBrush &brush). - - \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) -*/ -void QCPAxisRect::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! \overload - - Sets \a brush as the background brush. The axis rect background will be filled with this brush. - Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds - are usually drawn below everything else. - - The brush will be drawn before (under) any background pixmap, which may be specified with \ref - setBackground(const QPixmap &pm). - - To disable drawing of a background brush, set \a brush to Qt::NoBrush. - - \see setBackground(const QPixmap &pm) -*/ -void QCPAxisRect::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled - is set to true, you may control whether and how the aspect ratio of the original pixmap is - preserved with \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the axis rect dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to - define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. - \see setBackground, setBackgroundScaled -*/ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeDragAxes to retrieve a list with all set axes). - - \see setRangeDragAxes -*/ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); - else - return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); -} - -/*! - Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). - - \see setRangeZoomAxes -*/ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); - else - return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); -} - -/*! - Returns all range drag axes of the \a orientation provided. - - \see rangeZoomAxis, setRangeZoomAxes -*/ -QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; iQt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeDrag to enable the range dragging interaction. - - \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag -*/ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) -{ - mRangeDrag = orientations; -} - -/*! - Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation - corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, - QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical - axis is the left axis (yAxis). - - To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref - QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeZoom to enable the range zooming interaction. - - \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag -*/ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) -{ - mRangeZoom = orientations; -} - -/*! \overload - - Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on - the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to dragging interactions. - - \see setRangeZoomAxes -*/ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag - orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag - motion, use the overload taking two separate lists for horizontal and vertical dragging. -*/ -void QCPAxisRect::setRangeDragAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical dragging, and - define specifically which axis reacts to which drag orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) -{ - mRangeDragHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeDragVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on - the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. - - The two axes can be zoomed with different strengths, when different factors are passed to \ref - setRangeZoomFactor(double horizontalFactor, double verticalFactor). - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to zooming interactions. - - \see setRangeDragAxes -*/ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical range zooming. The - zoom orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom - interaction, use the overload taking two separate lists for horizontal and vertical zooming. -*/ -void QCPAxisRect::setRangeZoomAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical zooming, and - define specifically which axis reacts to which zoom orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) -{ - mRangeZoomHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeZoomVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with - \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to - let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal - and which is vertical, can be set with \ref setRangeZoomAxes. - - When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) - will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the - same scrolling direction will zoom out. -*/ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) -{ - mRangeZoomFactorHorz = horizontalFactor; - mRangeZoomFactorVert = verticalFactor; -} - -/*! \overload - - Sets both the horizontal and vertical zoom \a factor. -*/ -void QCPAxisRect::setRangeZoomFactor(double factor) -{ - mRangeZoomFactorHorz = factor; - mRangeZoomFactorVert = factor; -} - -/*! \internal - - Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a - pixmap. - - If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an - according filling inside the axis rect with the provided \a painter. - - Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the axis rect with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::drawBackground(QCPPainter *painter) -{ - // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); - } - } -} - -/*! \internal - - This function makes sure multiple axes on the side specified with \a type don't collide, but are - distributed according to their respective space requirement (QCPAxis::calculateMargin). - - It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the - one with index zero. - - This function is called by \ref calculateAutoMargin. -*/ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) -{ - const QList axesList = mAxes.value(type); - if (axesList.isEmpty()) - return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) - { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); - isFirstVisible = false; - } - axesList.at(i)->setOffset(offset); - } -} - -/* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) -{ - if (!mAutoMargins.testFlag(side)) - qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - - // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) - return axesList.last()->offset() + axesList.last()->calculateMargin(); - else - return 0; -} - -/*! \internal - - Reacts to a change in layout to potentially set the convenience axis pointers \ref - QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective - axes of this axis rect. This is only done if the respective convenience pointer is currently zero - and if there is no QCPAxisRect at position (0, 0) of the plot layout. - - This automation makes it simpler to replace the main axis rect with a newly created one, without - the need to manually reset the convenience pointers. -*/ -void QCPAxisRect::layoutChanged() -{ - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) - mParentPlot->xAxis = axis(QCPAxis::atBottom); - if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) - mParentPlot->yAxis = axis(QCPAxis::atLeft); - if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) - mParentPlot->xAxis2 = axis(QCPAxis::atTop); - if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) - mParentPlot->yAxis2 = axis(QCPAxis::atRight); - } -} - -/*! \internal - - Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is - pressed, the range dragging interaction is initialized (the actual range manipulation happens in - the \ref mouseMoveEvent). - - The mDragging flag is set to true and some anchor points are set that are needed to determine the - distance the mouse was dragged in the mouse move/release events later. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - mDragStartHorzRange.clear(); - for (int i=0; irange()); - mDragStartVertRange.clear(); - for (int i=0; irange()); - } - } -} - -/*! \internal - - Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a - preceding \ref mousePressEvent, the range is moved accordingly. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - - if (mRangeDrag.testFlag(Qt::Horizontal)) - { - for (int i=0; i= mDragStartHorzRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag.testFlag(Qt::Vertical)) - { - for (int i=0; i= mDragStartVertRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot - { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } - - } -} - -/* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the - ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of - the scaling operation is the current cursor position inside the axis rect. The scaling factor is - dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural - zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. - - Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse - wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be - multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as - exponent of the range zoom factor. This takes care of the wheel direction automatically, by - inverting the factor, when the wheel step is negative (f^-1 = 1/f). -*/ -void QCPAxisRect::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) - { - if (mRangeZoom != 0) - { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) - { - factor = qPow(mRangeZoomFactorHorz, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); - } - } - if (mRangeZoom.testFlag(Qt::Vertical)) - { - factor = qPow(mRangeZoomFactorVert, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); - } - } - mParentPlot->replot(); - } - } -} -/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractLegendItem - \brief The abstract base class for all entries in a QCPLegend. - - It defines a very basic interface for entries in a QCPLegend. For representing plottables in the - legend, the subclass \ref QCPPlottableLegendItem is more suitable. - - Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry - that's not even associated with a plottable). - - You must implement the following pure virtual functions: - \li \ref draw (from QCPLayerable) - - You inherit the following members you may use: - - - - - - - - -
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
-*/ - -/* start of documentation of signals */ - -/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) - - This signal is emitted when the selection state of this legend item has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/* end of documentation of signals */ - -/*! - Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not - cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. -*/ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) -{ - setLayer(QLatin1String("legend")); - setMargins(QMargins(0, 0, 0, 0)); -} - -/*! - Sets the default font of this specific legend item to \a font. - - \see setTextColor, QCPLegend::setFont -*/ -void QCPAbstractLegendItem::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the default text color of this specific legend item to \a color. - - \see setFont, QCPLegend::setTextColor -*/ -void QCPAbstractLegendItem::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - When this legend item is selected, \a font is used to draw generic text, instead of the normal - font set with \ref setFont. - - \see setFont, QCPLegend::setSelectedFont -*/ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - When this legend item is selected, \a color is used to draw generic text, instead of the normal - color set with \ref setTextColor. - - \see setTextColor, QCPLegend::setSelectedTextColor -*/ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether this specific legend item is selectable. - - \see setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this specific legend item is selected. - - It is possible to set the selection state of this item by calling this function directly, even if - setSelectable is set to false. - - \see setSelectableParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) - return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); -} - -/* inherits documentation from base class */ -QRect QCPAbstractLegendItem::clipRect() const -{ - return mOuterRect; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableLegendItem - \brief A legend item representing a plottable with an icon and the plottable name. - - This is the standard legend item for plottables. It displays an icon of the plottable next to the - plottable name. The icon is drawn by the respective plottable itself (\ref - QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. - For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the - middle. - - Legend items of this type are always associated with one plottable (retrievable via the - plottable() function and settable with the constructor). You may change the font of the plottable - name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref - QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. - - The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend - creates/removes legend items of this type. - - Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of - QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout - interface, QCPLegend has specialized functions for handling legend items conveniently, see the - documentation of \ref QCPLegend. -*/ - -/*! - Creates a new legend item associated with \a plottable. - - Once it's created, it can be added to the legend via \ref QCPLegend::addItem. - - A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref - QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. -*/ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) -{ - setAntialiased(false); -} - -/*! \internal - - Returns the pen that shall be used to draw the icon border, taking into account the selection - state of this item. -*/ -QPen QCPPlottableLegendItem::getIconBorderPen() const -{ - return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); -} - -/*! \internal - - Returns the text color that shall be used to draw text, taking into account the selection state - of this item. -*/ -QColor QCPPlottableLegendItem::getTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - -/*! \internal - - Returns the font that shall be used to draw text, taking into account the selection state of this - item. -*/ -QFont QCPPlottableLegendItem::getFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Draws the item with \a painter. The size and position of the drawn legend item is defined by the - parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref - maximumOuterSizeHint of this legend item. -*/ -void QCPPlottableLegendItem::draw(QCPPainter *painter) -{ - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); - QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); - // draw icon: - painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); - painter->restore(); - // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) - { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - int halfPen = qCeil(painter->pen().widthF()*0.5)+1; - painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped - painter->drawRect(iconRect); - } -} - -/*! \internal - - Calculates and returns the size of this item. This includes the icon, the text and the padding in - between. - - \seebaseclassmethod -*/ -QSize QCPPlottableLegendItem::minimumOuterSizeHint() const -{ - if (!mPlottable) return QSize(); - QSize result(0, 0); - QRect textRect; - QFontMetrics fontMetrics(getFont()); - QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); - result.setHeight(qMax(textRect.height(), iconSize.height())); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLegend -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLegend - \brief Manages a legend inside a QCustomPlot. - - A legend is a small box somewhere in the plot which lists plottables with their name and icon. - - A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the - plottable, for which a legend item shall be created. In the case of the main legend (\ref - QCustomPlot::legend), simply adding plottables to the plot while \ref - QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding - legend items. The legend item associated with a certain plottable can be removed with \ref - QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and - manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref - addItem, \ref removeItem, etc. - - Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref - QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement - "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds - an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as - mentioned above. In principle, any other layout elements may also be added to a legend via the - normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout - System\endlink for examples on how to add other elements to the legend and move it outside the axis - rect. - - Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control - in which order (column first or row first) the legend is filled up when calling \ref addItem, and - at which column or row wrapping occurs. - - By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the - inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another - position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend - outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement - interface. -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); - - This signal is emitted when the selection state of this legend has changed. - - \see setSelectedParts, setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs a new QCPLegend instance with default values. - - Note that by default, QCustomPlot already contains a legend ready to be used as \ref - QCustomPlot::legend -*/ -QCPLegend::QCPLegend() -{ - setFillOrder(QCPLayoutGrid::foRowsFirst); - setWrap(0); - - setRowSpacing(3); - setColumnSpacing(8); - setMargins(QMargins(7, 5, 7, 4)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black, 0)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); -} - -QCPLegend::~QCPLegend() -{ - clearItems(); - if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) - mParentPlot->legendRemoved(this); -} - -/* no doc for getter, see setSelectedParts */ -QCPLegend::SelectableParts QCPLegend::selectedParts() const -{ - // check whether any legend elements selected, if yes, add spItems to return value - bool hasSelectedItems = false; - for (int i=0; iselected()) - { - hasSelectedItems = true; - break; - } - } - if (hasSelectedItems) - return mSelectedParts | spItems; - else - return mSelectedParts & ~spItems; -} - -/*! - Sets the pen, the border of the entire legend is drawn with. -*/ -void QCPLegend::setBorderPen(const QPen &pen) -{ - mBorderPen = pen; -} - -/*! - Sets the brush of the legend background. -*/ -void QCPLegend::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will - use this font by default. However, a different font can be specified on a per-item-basis by - accessing the specific legend item. - - This function will also set \a font on all already existing legend items. - - \see QCPAbstractLegendItem::setFont -*/ -void QCPLegend::setFont(const QFont &font) -{ - mFont = font; - for (int i=0; isetFont(mFont); - } -} - -/*! - Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) - will use this color by default. However, a different colors can be specified on a per-item-basis - by accessing the specific legend item. - - This function will also set \a color on all already existing legend items. - - \see QCPAbstractLegendItem::setTextColor -*/ -void QCPLegend::setTextColor(const QColor &color) -{ - mTextColor = color; - for (int i=0; isetTextColor(color); - } -} - -/*! - Sets the size of legend icons. Legend items that draw an icon (e.g. a visual - representation of the graph) will use this size by default. -*/ -void QCPLegend::setIconSize(const QSize &size) -{ - mIconSize = size; -} - -/*! \overload -*/ -void QCPLegend::setIconSize(int width, int height) -{ - mIconSize.setWidth(width); - mIconSize.setHeight(height); -} - -/*! - Sets the horizontal space in pixels between the legend icon and the text next to it. - Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the - name of the graph) will use this space by default. -*/ -void QCPLegend::setIconTextPadding(int padding) -{ - mIconTextPadding = padding; -} - -/*! - Sets the pen used to draw a border around each legend icon. Legend items that draw an - icon (e.g. a visual representation of the graph) will use this pen by default. - - If no border is wanted, set this to \a Qt::NoPen. -*/ -void QCPLegend::setIconBorderPen(const QPen &pen) -{ - mIconBorderPen = pen; -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected - doesn't contain \ref spItems, those items become deselected. - - The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions - contains iSelectLegend. You only need to call this function when you wish to change the selection - state manually. - - This function can change the selection state of a part even when \ref setSelectableParts was set to a - value that actually excludes the part. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set - before, because there's no way to specify which exact items to newly select. Do this by calling - \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, - setSelectedFont -*/ -void QCPLegend::setSelectedParts(const SelectableParts &selected) -{ - SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - - if (mSelectedParts != newSelected) - { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) - { - qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; - newSelected &= ~spItems; - } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection - { - for (int i=0; isetSelected(false); - } - } - mSelectedParts = newSelected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - When the legend box is selected, this pen is used to draw the border instead of the normal pen - set via \ref setBorderPen. - - \see setSelectedParts, setSelectableParts, setSelectedBrush -*/ -void QCPLegend::setSelectedBorderPen(const QPen &pen) -{ - mSelectedBorderPen = pen; -} - -/*! - Sets the pen legend items will use to draw their icon borders, when they are selected. - - \see setSelectedParts, setSelectableParts, setSelectedFont -*/ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) -{ - mSelectedIconBorderPen = pen; -} - -/*! - When the legend box is selected, this brush is used to draw the legend background instead of the normal brush - set via \ref setBrush. - - \see setSelectedParts, setSelectableParts, setSelectedBorderPen -*/ -void QCPLegend::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the default font that is used by legend items when they are selected. - - This function will also set \a font on all already existing legend items. - - \see setFont, QCPAbstractLegendItem::setSelectedFont -*/ -void QCPLegend::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; - for (int i=0; isetSelectedFont(font); - } -} - -/*! - Sets the default text color that is used by legend items when they are selected. - - This function will also set \a color on all already existing legend items. - - \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor -*/ -void QCPLegend::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; - for (int i=0; isetSelectedTextColor(color); - } -} - -/*! - Returns the item with index \a i. - - Note that the linear index depends on the current fill order (\ref setFillOrder). - - \see itemCount, addItem, itemWithPlottable -*/ -QCPAbstractLegendItem *QCPLegend::item(int index) const -{ - return qobject_cast(elementAt(index)); -} - -/*! - Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns 0. - - \see hasItemWithPlottable -*/ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - for (int i=0; i(item(i))) - { - if (pli->plottable() == plottable) - return pli; - } - } - return 0; -} - -/*! - Returns the number of items currently in the legend. - - Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid - base class which allows creating empty cells), they are included in the returned count. - - \see item -*/ -int QCPLegend::itemCount() const -{ - return elementCount(); -} - -/*! - Returns whether the legend contains \a item. - - \see hasItemWithPlottable -*/ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const -{ - for (int i=0; iitem(i)) - return true; - } - return false; -} - -/*! - Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns false. - - \see itemWithPlottable -*/ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - return itemWithPlottable(plottable); -} - -/*! - Adds \a item to the legend, if it's not present already. The element is arranged according to the - current fill order (\ref setFillOrder) and wrapping (\ref setWrap). - - Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. - - The legend takes ownership of the item. - - \see removeItem, item, hasItem -*/ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) -{ - return addElement(item); -} - -/*! \overload - - Removes the item with the specified \a index from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes - elements derived from \ref QCPAbstractLegendItem. - - \see itemCount, clearItems -*/ -bool QCPLegend::removeItem(int index) -{ - if (QCPAbstractLegendItem *ali = item(index)) - { - bool success = remove(ali); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; - } else - return false; -} - -/*! \overload - - Removes \a item from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. - - \see clearItems -*/ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) -{ - bool success = remove(item); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; -} - -/*! - Removes all items from the legend. -*/ -void QCPLegend::clearItems() -{ - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); -} - -/*! - Returns the legend items that are currently selected. If no items are selected, - the list is empty. - - \see QCPAbstractLegendItem::setSelected, setSelectable -*/ -QList QCPLegend::selectedItems() const -{ - QList result; - for (int i=0; iselected()) - result.append(ali); - } - } - return result; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing main legend elements. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); -} - -/*! \internal - - Returns the pen used to paint the border of the legend, taking into account the selection state - of the legend box. -*/ -QPen QCPLegend::getBorderPen() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; -} - -/*! \internal - - Returns the brush used to paint the background of the legend, taking into account the selection - state of the legend box. -*/ -QBrush QCPLegend::getBrush() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; -} - -/*! \internal - - Draws the legend box with the provided \a painter. The individual legend items are layerables - themselves, thus are drawn independently. -*/ -void QCPLegend::draw(QCPPainter *painter) -{ - // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); -} - -/* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) - return -1; - - if (mOuterRect.contains(pos.toPoint())) - { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) -{ - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPLegend::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractLegendItem::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) -{ - if (parentPlot && !parentPlot->legend) - parentPlot->legend = this; -} -/* end of 'src/layoutelements/layoutelement-legend.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPTextElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPTextElement - \brief A layout element displaying a text - - The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, - \ref setTextColor, and \ref setTextFlags. - - A text element can be added as follows: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation -*/ - -/* start documentation of signals */ - -/*! \fn void QCPTextElement::selectionChanged(bool selected) - - This signal is emitted when the selection state has changed to \a selected, either by user - interaction or by a direct call to \ref setSelected. - - \see setSelected, setSelectable -*/ - -/*! \fn void QCPTextElement::clicked(QMouseEvent *event) - - This signal is emitted when the text element is clicked. - - \see doubleClicked, selectTest -*/ - -/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) - - This signal is emitted when the text element is double clicked. - - \see clicked, selectTest -*/ - -/* end documentation of signals */ - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref - setText). -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mText(), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mFont.setPointSizeF(pointSize); - mSelectedFont = parentPlot->font(); - mSelectedFont.setPointSizeF(pointSize); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize and the specified \a fontFamily. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(fontFamily, pointSize)), - mTextColor(Qt::black), - mSelectedFont(QFont(fontFamily, pointSize)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with the specified \a font. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(font), - mTextColor(Qt::black), - mSelectedFont(font), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! - Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". - - \see setFont, setTextColor, setTextFlags -*/ -void QCPTextElement::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of - \c Qt::AlignmentFlag and \c Qt::TextFlag enums. - - Possible enums are: - - Qt::AlignLeft - - Qt::AlignRight - - Qt::AlignHCenter - - Qt::AlignJustify - - Qt::AlignTop - - Qt::AlignBottom - - Qt::AlignVCenter - - Qt::AlignCenter - - Qt::TextDontClip - - Qt::TextSingleLine - - Qt::TextExpandTabs - - Qt::TextShowMnemonic - - Qt::TextWordWrap - - Qt::TextIncludeTrailingSpaces -*/ -void QCPTextElement::setTextFlags(int flags) -{ - mTextFlags = flags; -} - -/*! - Sets the \a font of the text. - - \see setTextColor, setSelectedFont -*/ -void QCPTextElement::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the \a color of the text. - - \see setFont, setSelectedTextColor -*/ -void QCPTextElement::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). - - \see setFont -*/ -void QCPTextElement::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). - - \see setTextColor -*/ -void QCPTextElement::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether the user may select this text element. - - Note that even when \a selectable is set to false, the selection state may be changed - programmatically via \ref setSelected. -*/ -void QCPTextElement::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets the selection state of this text element to \a selected. If the selection has changed, \ref - selectionChanged is emitted. - - Note that this function can change the selection state independently of the current \ref - setSelectable state. -*/ -void QCPTextElement::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/* inherits documentation from base class */ -void QCPTextElement::draw(QCPPainter *painter) -{ - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); -} - -/* inherits documentation from base class */ -QSize QCPTextElement::minimumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPTextElement::maximumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.setWidth(QWIDGETSIZE_MAX); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPTextElement::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/*! - Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is - within the bounding box of the text element's text. Note that this bounding box is updated in the - draw call. - - If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text - element is not selectable (\ref setSelectable), returns -1. - - \seebaseclassmethod -*/ -double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/*! - Accepts the mouse event in order to emit the according click signal in the \ref - mouseReleaseEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->accept(); -} - -/*! - Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref - mousePressEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) - Q_EMIT clicked(event); -} - -/*! - Emits the \ref doubleClicked signal. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - Q_EMIT doubleClicked(event); -} - -/*! \internal - - Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to - true, else mFont is returned. -*/ -QFont QCPTextElement::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to - true, else mTextColor is returned. -*/ -QColor QCPTextElement::mainTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} -/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScale -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScale - \brief A color scale for use with color coding data such as QCPColorMap - - This layout element can be placed on the plot to correlate a color gradient with data values. It - is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". - - \image html QCPColorScale.png - - The color scale can be either horizontal or vertical, as shown in the image above. The - orientation and the side where the numbers appear is controlled with \ref setType. - - Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are - connected, they share their gradient, data range and data scale type (\ref setGradient, \ref - setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color - scale, to make them all synchronize these properties. - - To have finer control over the number display and axis behaviour, you can directly access the - \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if - you want to change the number of automatically generated ticks, call - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount - - Placing a color scale next to the main axis rect works like with any other layout element: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation - In this case we have placed it to the right of the default axis rect, so it wasn't necessary to - call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color - scale can be set with \ref setLabel. - - For optimum appearance (like in the image above), it may be desirable to line up the axis rect and - the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup - - Color scales are initialized with a non-zero minimum top and bottom margin (\ref - setMinimumMargins), because vertical color scales are most common and the minimum top/bottom - margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a - horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you - might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPAxis *QCPColorScale::axis() const - - Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the - appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its - interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref - setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref - QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on - the QCPColorScale or on its QCPAxis. - - If the type of the color scale is changed with \ref setType, the axis returned by this method - will change, too, to either the left, right, bottom or top axis, depending on which type was set. -*/ - -/* end documentation of signals */ -/* start documentation of signals */ - -/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a new QCPColorScale. -*/ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) -{ - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); -} - -QCPColorScale::~QCPColorScale() -{ - delete mAxisRect; -} - -/* undocumented getter */ -QString QCPColorScale::label() const -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return QString(); - } - - return mColorAxis.data()->label(); -} - -/* undocumented getter */ -bool QCPColorScale::rangeDrag() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/* undocumented getter */ -bool QCPColorScale::rangeZoom() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/*! - Sets at which side of the color scale the axis is placed, and thus also its orientation. - - Note that after setting \a type to a different value, the axis returned by \ref axis() will - be a different one. The new axis will adopt the following properties from the previous axis: The - range, scale type, label and ticker (the latter will be shared and not copied). -*/ -void QCPColorScale::setType(QCPAxis::AxisType type) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - if (mType != type) - { - mType = type; - QCPRange rangeTransfer(0, 6); - QString labelTransfer; - QSharedPointer tickerTransfer; - // transfer/revert some settings on old axis if it exists: - bool doTransfer = (bool)mColorAxis; - if (doTransfer) - { - rangeTransfer = mColorAxis.data()->range(); - labelTransfer = mColorAxis.data()->label(); - tickerTransfer = mColorAxis.data()->ticker(); - mColorAxis.data()->setLabel(QString()); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; - Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) - { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); - } - // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); - // transfer settings to new axis: - if (doTransfer) - { - mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setTicker(tickerTransfer); - } - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); - } -} - -/*! - Sets the range spanned by the color gradient and that is shown by the axis in the color scale. - - It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its range with \ref - QCPAxis::setRange. - - \see setDataScaleType, setGradient, rescaleDataRange -*/ -void QCPColorScale::setDataRange(const QCPRange &dataRange) -{ - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets the scale type of the color scale, i.e. whether values are linearly associated with colors - or logarithmically. - - It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its scale type with \ref - QCPAxis::setScaleType. - - \see setDataRange, setGradient -*/ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - Q_EMIT dataScaleTypeChanged(mDataScaleType); - } -} - -/*! - Sets the color gradient that will be used to represent data values. - - It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. - - \see setDataRange, setDataScaleType -*/ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - if (mAxisRect) - mAxisRect.data()->mGradientImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on - the internal \ref axis. -*/ -void QCPColorScale::setLabel(const QString &str) -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return; - } - - mColorAxis.data()->setLabel(str); -} - -/*! - Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed - will have. -*/ -void QCPColorScale::setBarWidth(int width) -{ - mBarWidth = width; -} - -/*! - Sets whether the user can drag the data range (\ref setDataRange). - - Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeDrag(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeDrag(0); -} - -/*! - Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. - - Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeZoom(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeZoom(0); -} - -/*! - Returns a list of all the color maps associated with this color scale. -*/ -QList QCPColorScale::colorMaps() const -{ - QList result; - for (int i=0; iplottableCount(); ++i) - { - if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); - } - return result; -} - -/*! - Changes the data range such that all color maps associated with this color scale are fully mapped - to the gradient in the data dimension. - - \see setDataRange -*/ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) -{ - QList maps = colorMaps(); - QCPRange newRange; - bool haveRange = false; - QCP::SignDomain sign = QCP::sdBoth; - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - for (int i=0; irealVisibility() && onlyVisibleMaps) - continue; - QCPRange mapRange; - if (maps.at(i)->colorScale() == this) - { - bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == QCP::sdPositive) - { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == QCP::sdNegative) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) - currentFoundRange = false; - } - if (currentFoundRange) - { - if (!haveRange) - newRange = mapRange; - else - newRange.expand(mapRange); - haveRange = true; - } - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) - { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); - } - } - setDataRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - mAxisRect.data()->update(phase); - - switch (phase) - { - case upMargins: - { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); - } - break; - } - case upLayout: - { - mAxisRect.data()->setOuterRect(rect()); - break; - } - default: break; - } -} - -/* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mousePressEvent(event, details); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseMoveEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseReleaseEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->wheelEvent(event); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScaleAxisRectPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScaleAxisRectPrivate - - \internal - \brief An axis rect subclass for use in a QCPColorScale - - This is a private class and not part of the public QCustomPlot interface. - - It provides the axis rect functionality for the QCPColorScale class. -*/ - - -/*! - Creates a new instance, as a child of \a parentColorScale. -*/ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) -{ - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); - } - - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - - // make layer transfers of color scale transfer to axis rect and axes - // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); -} - -/*! \internal - - Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws - it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. - - \seebaseclassmethod -*/ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) -{ - if (mGradientImageInvalidated) - updateGradientImage(); - - bool mirrorHorz = false; - bool mirrorVert = false; - if (mParentColorScale->mColorAxis) - { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); - } - - painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); -} - -/*! \internal - - Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to - generate a gradient image. This gradient image will be used in the \ref draw method. -*/ -void QCPColorScaleAxisRectPrivate::updateGradientImage() -{ - if (rect().isEmpty()) - return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - int n = mParentColorScale->mGradient.levelCount(); - int w, h; - QVector data(n); - for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) - { - w = n; - h = rect().height(); - mGradientImage = QImage(w, h, format); - QVector pixels; - for (int y=0; y(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); - else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); - } - } -} - -/*! \internal - - This slot is connected to the selectableChanged signals of the four axes in the constructor. It - synchronizes the selectability of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) -{ - // synchronize axis base selectability: - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); - else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); - } - } -} -/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ - - -/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraphData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraphData - \brief Holds the data of one single data point for QCPGraph. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPGraphDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPGraphData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPGraphData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and value set to zero. -*/ -QCPGraphData::QCPGraphData() : - key(0), - value(0) -{ -} - -/*! - Constructs a data point with the specified \a key and \a value. -*/ -QCPGraphData::QCPGraphData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraph -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraph - \brief A plottable representing a graph in a plot. - - \image html QCPGraph.png - - Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be - accessed via QCustomPlot::graph. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPGraphDataContainer. - - Graphs are used to display single-valued data. Single-valued means that there should only be one - data point per unique key coordinate. In other words, the graph can't have \a loops. If you do - want to plot non-single-valued curves, rather use the QCPCurve plottable. - - Gaps in the graph line can be created by adding data points with NaN as value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpgraph-appearance Changing the appearance - - The appearance of the graph is mainly determined by the line style, scatter style, brush and pen - of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). - - \subsection filling Filling under or between graphs - - QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to - the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, - just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. - - By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill - between this graph and another one, call \ref setChannelFillGraph with the other graph as - parameter. - - \see QCustomPlot::addGraph, QCustomPlot::graph -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPGraph::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually - but use QCustomPlot::removePlottable() instead. - - To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. -*/ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // special handling for QCPGraphs to maintain the simple graph interface: - mParentPlot->registerGraph(this); - - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setScatterSkip(0); - setChannelFillGraph(0); - setAdaptiveSampling(true); -} - -QCPGraph::~QCPGraph() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. - Modifying the data in the container will then affect all graphs that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the graph's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 - - \see addData -*/ -void QCPGraph::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to - \ref lsNone and \ref setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPGraph::setLineStyle(LineStyle ls) -{ - mLineStyle = ls; -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points - are drawn (e.g. for line-only-plots with appropriate line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPGraph::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets the target graph for filling the area between this graph and \a targetGraph with the current - brush (\ref setBrush). - - When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To - disable any filling, set the brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) -{ - // prevent setting channel target to this graph itself: - if (targetGraph == this) - { - qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; - mChannelFillGraph = 0; - return; - } - // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; - mChannelFillGraph = 0; - return; - } - - mChannelFillGraph = targetGraph; -} - -/*! - Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive - sampling technique can drastically improve the replot performance for graphs with a larger number - of points (e.g. above 10,000), without notably changing the appearance of the graph. - - By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive - sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no - disadvantage in almost all cases. - - \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" - - As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are - reproduced reliably, as well as the overall shape of the data set. The replot time reduces - dramatically though. This allows QCustomPlot to display large amounts of data in realtime. - - \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" - - Care must be taken when using high-density scatter plots in combination with adaptive sampling. - The adaptive sampling algorithm treats scatter plots more carefully than line plots which still - gives a significant reduction of replot times, but not quite as much as for line plots. This is - because scatter plots inherently need more data points to be preserved in order to still resemble - the original, non-adaptive-sampling plot. As shown above, the results still aren't quite - identical, as banding occurs for the outer data points. This is in fact intentional, such that - the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, - depends on the point density, i.e. the number of points in the plot. - - For some situations with scatter plots it might thus be desirable to manually turn adaptive - sampling off. For example, when saving the plot to disk. This can be achieved by setting \a - enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled - back to true afterwards. -*/ -void QCPGraph::setAdaptiveSampling(bool enabled) -{ - mAdaptiveSampling = enabled; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(double key, double value) -{ - mDataContainer->add(QCPGraphData(key, value)); -} - -/* inherits documentation from base class */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - // get line pixel points appropriate to line style: - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) - getLines(&lines, lineDataRange); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPGraphDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw fill of graph: - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - drawFill(painter, &lines); - - // draw line: - if (mLineStyle != lsNone) - { - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - painter->setBrush(Qt::NoBrush); - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lines); - else - drawLinePlot(painter, lines); // also step plots can be drawn as a line plot - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i)); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches - out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. - according to the line style of the graph. - - \a lines will be filled with points in pixel coordinates, that can be drawn with the according - draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines - aren't necessarily the original data points. For example, step line styles require additional - points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a - lines vector will be empty. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. - - \see getScatters -*/ -void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const -{ - if (!lines) return; - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - lines->clear(); - return; - } - - QVector lineData; - if (mLineStyle != lsNone) - getOptimizedLineData(&lineData, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) - std::reverse(lineData.begin(), lineData.end()); - - switch (mLineStyle) - { - case lsNone: lines->clear(); break; - case lsLine: *lines = dataToLines(lineData); break; - case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; - case lsStepRight: *lines = dataToStepRightLines(lineData); break; - case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; - case lsImpulse: *lines = dataToImpulseLines(lineData); break; - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then - converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be - passed to \ref drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. -*/ -void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const -{ - if (!scatters) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } - - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - scatters->clear(); - return; - } - - QVector data; - getOptimizedScatterData(&data, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) - std::reverse(data.begin(), data.end()); - - scatters->resize(data.size()); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } - } else - { - for (int i=0; icoordToPixel(data.at(i).key)); - (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - } -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsLine. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - result[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key)); - result[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepLeft. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepLeftLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(lastValue); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(key); - result[i*2+1].setY(lastValue); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepRight. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepRightLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(value); - result[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(value); - result[i*2+1].setY(lastKey); - } - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(lastKey); - result[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(lastKey); - result[i*2+1].setY(value); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepCenter. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepCenterLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastValue); - result[0].setY(lastKey); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(lastValue); - result[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - } - result[data.size()*2-1].setX(lastValue); - result[data.size()*2-1].setY(lastKey); - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastKey); - result[0].setY(lastValue); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(key); - result[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - } - result[data.size()*2-1].setX(lastKey); - result[data.size()*2-1].setY(lastValue); - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsImpulse. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot -*/ -QVector QCPGraph::dataToImpulseLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(valueAxis->coordToPixel(0)); - result[i*2+0].setY(key); - result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(valueAxis->coordToPixel(0)); - result[i*2+1].setX(key); - result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Draws the fill of the graph using the specified \a painter, with the currently set brush. - - Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref - getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. - - In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), - this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to - operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN - segments of the two involved graphs, before passing the overlapping pairs to \ref - getChannelFillPolygon. - - Pass the points of this graph's line as \a lines, in pixel coordinates. - - \see drawLinePlot, drawImpulsePlot, drawScatterPlot -*/ -void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const -{ - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); - if (!mChannelFillGraph) - { - // draw base fill under graph, fill goes all the way to the zero-value-line: - for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); - } else - { - // draw fill between this graph and mChannelFillGraph: - QVector otherLines; - mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); - if (!otherLines.isEmpty()) - { - QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); - QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); - for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); - } - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawLinePlot, drawImpulsePlot -*/ -void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const -{ - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in - pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines - from the regular graph data points. - - \see drawLinePlot, drawScatterPlot -*/ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - QPen oldPen = painter->pen(); - QPen newPen = painter->pen(); - newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(newPen); - painter->drawLines(lines); - painter->setPen(oldPen); - } -} - -/*! \internal - - Returns via \a lineData the data points that need to be visualized for this graph when plotting - graph lines, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getLines to retrieve the basic working set of data. - - \see getOptimizedScatterData -*/ -void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const -{ - if (!lineData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (begin == end) return; - - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - QCPGraphDataContainer::const_iterator it = begin; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary - { - if (it->value < minValue) - minValue = it->value; - else if (it->value > maxValue) - maxValue = it->value; - ++intervalDataCount; - } else // new pixel interval started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - lastIntervalEndKey = (it-1)->key; - minValue = it->value; - maxValue = it->value; - currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - lineData->resize(dataCount); - std::copy(begin, end, lineData->begin()); - } -} - -/*! \internal - - Returns via \a scatterData the data points that need to be visualized for this graph when - plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getScatters to retrieve the basic working set of data. - - \see getOptimizedLineData -*/ -void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const -{ - if (!scatterData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int beginIndex = begin-mDataContainer->constBegin(); - int endIndex = end-mDataContainer->constBegin(); - while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++beginIndex; - ++begin; - } - if (begin == end) return; - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - double valueMaxRange = valueAxis->range().upper; - double valueMinRange = valueAxis->range().lower; - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator minValueIt = it; - QCPGraphDataContainer::const_iterator maxValueIt = it; - QCPGraphDataContainer::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - // main loop over data points: - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary - { - if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) - { - minValue = it->value; - minValueIt = it; - } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) - { - maxValue = it->value; - maxValueIt = it; - } - ++intervalDataCount; - } else // new pixel started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else - intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - minValue = it->value; - maxValue = it->value; - currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int intervalItIndex = intervalIt-mDataContainer->constBegin(); - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: - { - intervalItIndex += scatterModulo; - if (intervalItIndex < itIndex) - intervalIt += scatterModulo; - else - { - intervalIt = it; - intervalItIndex = itIndex; - } - } - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - scatterData->reserve(dataCount); - while (it != end) - { - scatterData->append(*it); - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - This method takes into account that the drawing of data lines at the axis rect border always - requires the points just outside the visible axis range. So \a begin and \a end may actually - indicate a range that contains one additional data point to the left and right of the visible - axis range. -*/ -void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - if (rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - } else - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - // get visible data range: - begin = mDataContainer->findBegin(keyAxis->range().lower); - end = mDataContainer->findEnd(keyAxis->range().upper); - // limit lower/upperEnd to rangeRestriction: - mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything - } -} - -/*! \internal - - This method goes through the passed points in \a lineData and returns a list of the segments - which don't contain NaN data points. - - \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check - for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c - Qt::Vertical, the \a x member is checked. - - \see getOverlappingSegments, drawFill -*/ -QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const -{ - QVector result; - const int n = lineData->size(); - - QCPDataRange currentSegment(-1, -1); - int i = 0; - - if (keyOrientation == Qt::Horizontal) - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } else // keyOrientation == Qt::Vertical - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } - return result; -} - -/*! \internal - - This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and - \a otherSegments, and their associated point data \a thisData and \a otherData. - - It returns all pairs of segments (the first from \a thisSegments, the second from \a - otherSegments), which overlap in plot coordinates. - - This method is useful in the case of a channel fill between two graphs, when only those non-NaN - segments which actually overlap in their key coordinate shall be considered for drawing a channel - fill polygon. - - It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and - that the segments don't overlap themselves. The same is assumed for the segments in \a - otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. - - \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon -*/ -QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const -{ - QVector > result; - if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) - return result; - - int thisIndex = 0; - int otherIndex = 0; - const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; - while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) - { - if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++thisIndex; - continue; - } - if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++otherIndex; - continue; - } - double thisLower, thisUpper, otherLower, otherUpper; - if (!verticalKey) - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); - } else - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); - } - - int bPrecedence; - if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) - result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); - - if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment - ++otherIndex; - else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment - ++thisIndex; - } - - return result; -} - -/*! \internal - - Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) - have overlap. - - The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the - \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher - coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if - both segment's upper bounds are identical, 0 is returned as \a bPrecedence. - - It is assumed that the lower bounds always have smaller or equal values than the upper bounds. - - \see getOverlappingSegments -*/ -bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const -{ - bPrecedence = 0; - if (aLower > bUpper) - { - bPrecedence = -1; - return false; - } else if (bLower > aUpper) - { - bPrecedence = 1; - return false; - } else - { - if (aUpper > bUpper) - bPrecedence = -1; - else if (aUpper < bUpper) - bPrecedence = 1; - - return true; - } -} - -/*! \internal - - Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. - The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates - is in positive or negative infinity. So this case is handled separately by just closing the fill - polygon on the axis which lies in the direction towards the zero value. - - \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether - the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or - y value of the returned point, respectively. -*/ -QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF result; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->orientation() == Qt::Horizontal) - { - result.setX(matchingDataPoint.x()); - result.setY(valueAxis->coordToPixel(0)); - } else // keyAxis->orientation() == Qt::Vertical - { - result.setX(valueAxis->coordToPixel(0)); - result.setY(matchingDataPoint.y()); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value 0 so we just fill all the way - // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setX(keyAxis->axisRect()->right()); - else - result.setX(keyAxis->axisRect()->left()); - result.setY(matchingDataPoint.y()); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - result.setX(matchingDataPoint.x()); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setY(keyAxis->axisRect()->top()); - else - result.setY(keyAxis->axisRect()->bottom()); - } - } - return result; -} - -/*! \internal - - Returns the polygon needed for drawing normal fills between this graph and the key axis. - - Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment - which shall be used for the fill. The collection of \a lineData points described by \a segment - must not contain NaN data points (see \ref getNonNanSegments). - - The returned fill polygon will be closed at the key axis (the zero-value line) for linear value - axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect - side (see \ref getFillBasePoint). - - For increased performance (due to implicit sharing), keep the returned QPolygonF const. - - \see drawFill, getNonNanSegments -*/ -const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const -{ - if (segment.size() < 2) - return QPolygonF(); - QPolygonF result(segment.size()+2); - - result[0] = getFillBasePoint(lineData->at(segment.begin())); - std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); - result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); - - return result; -} - -/*! \internal - - Returns the polygon needed for drawing (partial) channel fills between this graph and the graph - specified by \ref setChannelFillGraph. - - The data points of this graph are passed as pixel coordinates via \a thisData, the data of the - other graph as \a otherData. The returned polygon will be calculated for the specified data - segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a - otherData, respectively. - - The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by - \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap - need to be processed here. - - For increased performance due to implicit sharing, keep the returned QPolygonF const. - - \see drawFill, getOverlappingSegments, getNonNanSegments -*/ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const -{ - if (!mChannelFillGraph) - return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (thisData->isEmpty()) return QPolygonF(); - QVector thisSegmentData(thisSegment.size()); - QVector otherSegmentData(otherSegment.size()); - std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); - std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); - // pointers to be able to swap them, depending which data range needs cropping: - QVector *staticData = &thisSegmentData; - QVector *croppedData = &otherSegmentData; - - // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) - { - // x is key - // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); - else - slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - - // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - const int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); - else - slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical - { - // y is key - // crop lower bound: - if (staticData->first().y() < croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); - else - slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - - // crop upper bound: - if (staticData->last().y() > croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); - else - slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); - } - - // return joined: - for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisSegmentData << otherSegmentData.at(i); - return QPolygonF(thisSegmentData); -} - -/*! \internal - - Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveX(const QVector *data, double x) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).x() < x) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowX(const QVector *data, double x) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).x() > x) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is vertical. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveY(const QVector *data, double y) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).y() < y) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Calculates the minimum distance in pixels the graph's representation has from the given \a - pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if - the graph has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the graph line is also taken into account. - - If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. -*/ -double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - // calculate minimum distances to graph data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); - QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); - for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - // line displayed, calculate distance to line segments: - QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); - QCPVector2D p(pixelPoint); - const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected - for (int i=0; i *data, double y) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).y() > y) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} -/* end of 'src/plottables/plottable-graph.cpp' */ - - -/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurveData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurveData - \brief Holds the data of one single data point for QCPCurve. - - The stored data is: - \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) - \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) - \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPCurveDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPCurveData::sortKey() const - - Returns the \a t member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). - All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() - - Since the member \a key is the data point key coordinate and the member \a t is the data ordering - parameter, this method returns false. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPCurveData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a curve data point with t, key and value set to zero. -*/ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) -{ -} - -/*! - Constructs a curve data point with the specified \a t, \a key and \a value. -*/ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurve - \brief A plottable representing a parametric curve in a plot. - - \image html QCPCurve.png - - Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, - so their visual representation can have \a loops. This is realized by introducing a third - coordinate \a t, which defines the order of the points described by the other two coordinates \a - x and \a y. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the curve's data via the \ref data method, which returns a pointer to the - internal \ref QCPCurveDataContainer. - - Gaps in the curve can be created by adding data points with NaN as key and value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpcurve-appearance Changing the appearance - - The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). - - \section qcpcurve-usage Usage - - Like all data representing objects in QCustomPlot, the QCPCurve is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPCurve::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // modify inherited properties from abstract plottable: - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); - setScatterSkip(0); -} - -QCPCurve::~QCPCurve() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. - Modifying the data in the container will then affect all curves that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the curve's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 - - \see addData -*/ -void QCPCurve::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a t, \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a t in ascending order, you can - set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(t, keys, values, alreadySorted); -} - - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - \see addData -*/ -void QCPCurve::setData(const QVector &keys, const QVector &values) -{ - mDataContainer->clear(); - addData(keys, values); -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref - QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate - line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPCurve::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets how the single data points are connected in the plot or how they are represented visually - apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref - setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) -{ - mLineStyle = style; -} - -/*! \overload - - Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (t.size() != keys.size() || t.size() != values.size()) - qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); - const int n = qMin(qMin(t.size(), keys.size()), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = t[i]; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &keys, const QVector &values) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - double tStart; - if (!mDataContainer->isEmpty()) - tStart = (mDataContainer->constEnd()-1)->t + 1.0; - else - tStart = 0; - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = tStart + i; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a t, \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double t, double key, double value) -{ - mDataContainer->add(QCPCurveData(t, key, value)); -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - The t parameter is generated automatically by increments of 1 for each point, starting at the - highest t of previously existing data or 0, if the curve data is empty. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double key, double value) -{ - if (!mDataContainer->isEmpty()) - mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); - else - mDataContainer->add(QCPCurveData(0.0, key, value)); -} - -/* inherits documentation from base class */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - - // allocate line vector: - QVector lines, scatters; - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - - // fill with curve data: - QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width - if (isSelectedSegment && mSelectionDecorator) - finalCurvePen = mSelectionDecorator->pen(); - - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) - getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); - - // check data validity if flag set: - #ifdef QCUSTOMPLOT_CHECK_DATA - for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->t) || - QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } - #endif - - // draw curve fill: - applyFillAntialiasingHint(painter); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) - painter->drawPolygon(QPolygonF(lines)); - - // draw curve line: - if (mLineStyle != lsNone) - { - painter->setPen(finalCurvePen); - painter->setBrush(Qt::NoBrush); - drawCurveLine(painter, lines); - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - Draws lines between the points in \a lines, given in pixel coordinates. - - \see drawScatterPlot, getCurveLines -*/ -void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawCurveLine, getCurveLines -*/ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const -{ - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const -{ - if (!lines) return; - lines->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // add margins to rect to compensate for stroke width - const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety - const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); - const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); - const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); - const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); - QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); - if (itBegin == itEnd) - return; - QCPCurveDataContainer::const_iterator it = itBegin; - QCPCurveDataContainer::const_iterator prevIt = itEnd-1; - int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); - QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) - while (it != itEnd) - { - const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); - if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R - { - if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal - { - QPointF crossA, crossB; - if (prevRegion == 5) // we're coming from R, so add this point optimized - { - lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); - // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } else if (mayTraverse(prevRegion, currentRegion) && - getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) - { - // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: - QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; - getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); - if (it != itBegin) - { - *lines << beforeTraverseCornerPoints; - lines->append(crossA); - lines->append(crossB); - *lines << afterTraverseCornerPoints; - } else - { - lines->append(crossB); - *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA ; - } - } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) - { - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } - } else // segment does end in R, so we add previous point optimized and this point at original position - { - if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end - trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - else - lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); - lines->append(coordsToPixels(it->key, it->value)); - } - } else // region didn't change - { - if (currentRegion == 5) // still in R, keep adding original points - { - lines->append(coordsToPixels(it->key, it->value)); - } else // still outside R, no need to add anything - { - // see how this is not doing anything? That's the main optimization... - } - } - prevIt = it; - prevRegion = currentRegion; - ++it; - } - *lines << trailingPoints; -} - -/*! \internal - - Called by \ref draw to generate points in pixel coordinates which represent the scatters of the - curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly - sparser. - - Scatters that aren't visible in the current axis rect are optimized away. - - \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref - drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. - - \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel - coordinates generated by this function. This is needed here to calculate an accordingly wider - margin around the axis rect when performing the data point reduction. - - \see draw, drawScatterPlot -*/ -void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const -{ - if (!scatters) return; - scatters->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); - if (begin == end) - return; - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int endIndex = end-mDataContainer->constBegin(); - - QCPRange keyRange = keyAxis->range(); - QCPRange valueRange = valueAxis->range(); - // extend range to include width of scatter symbols: - keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); - keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); - valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); - valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); - - QCPCurveDataContainer::const_iterator it = begin; - int itIndex = begin-mDataContainer->constBegin(); - while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++itIndex; - ++it; - } - if (keyAxis->orientation() == Qt::Vertical) - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } else - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - It returns the region of the given point (\a key, \a value) with respect to a rectangle defined - by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. - - The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a - keyMin to \a keyMax): - - - - - -
147
258
369
- - With the rectangle being region 5, and the outer regions extending infinitely outwards. In the - curve optimization algorithm, region 5 is considered to be the visible portion of the plot. -*/ -int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - if (key < keyMin) // region 123 - { - if (value > valueMax) - return 1; - else if (value < valueMin) - return 3; - else - return 2; - } else if (key > keyMax) // region 789 - { - if (value > valueMax) - return 7; - else if (value < valueMin) - return 9; - else - return 8; - } else // region 456 - { - if (value > valueMax) - return 4; - else if (value < valueMin) - return 6; - else - return 5; - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method is used in case the current segment passes from inside the visible rect (region 5, - see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by - the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). - - It returns the intersection point of the segment with the border of region 5. - - For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or - whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or - leaving it. It is important though that \a otherRegion correctly identifies the other region not - equal to 5. -*/ -QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double otherValuePx = mValueAxis->coordToPixel(otherValue); - const double valuePx = mValueAxis->coordToPixel(value); - const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); - const double keyPx = mKeyAxis->coordToPixel(key); - double intersectKeyPx = keyMinPx; // initial key just a fail-safe - double intersectValuePx = valueMinPx; // initial value just a fail-safe - switch (otherRegion) - { - case 1: // top and left edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 2: // left edge - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 3: // bottom and left edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 4: // top edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 5: - { - break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table - } - case 6: // bottom edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 7: // top and right edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 8: // right edge - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 9: // bottom and right edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - } - if (mKeyAxis->orientation() == Qt::Horizontal) - return QPointF(intersectKeyPx, intersectValuePx); - else - return QPointF(intersectValuePx, intersectKeyPx); -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - In situations where a single segment skips over multiple regions it might become necessary to add - extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment - doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. - This method provides these points that must be added, assuming the original segment doesn't - start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by - \ref getTraverseCornerPoints.) - - For example, consider a segment which directly goes from region 4 to 2 but originally is far out - to the top left such that it doesn't cross region 5. Naively optimizing these points by - projecting them on the top and left borders of region 5 will create a segment that surely crosses - 5, creating a visual artifact in the plot. This method prevents this by providing extra points at - the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without - traversing 5. -*/ -QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - QVector result; - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMax); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } - case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - else - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - break; - } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMin); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); break; } - case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - else - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - break; - } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 6: - { - switch (currentRegion) - { - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 4: { result << coordsToPixels(keyMax, valueMax); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); break; } - case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - else - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - break; - } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 6: { result << coordsToPixels(keyMax, valueMin); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - else - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - break; - } - } - break; - } - } - return result; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref - getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion - nor \a currentRegion is 5 itself. - - If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the - segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref - getTraverse). -*/ -bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 4: - case 7: - case 2: - case 3: return false; - default: return true; - } - } - case 2: - { - switch (currentRegion) - { - case 1: - case 3: return false; - default: return true; - } - } - case 3: - { - switch (currentRegion) - { - case 1: - case 2: - case 6: - case 9: return false; - default: return true; - } - } - case 4: - { - switch (currentRegion) - { - case 1: - case 7: return false; - default: return true; - } - } - case 5: return false; // should never occur - case 6: - { - switch (currentRegion) - { - case 3: - case 9: return false; - default: return true; - } - } - case 7: - { - switch (currentRegion) - { - case 1: - case 4: - case 8: - case 9: return false; - default: return true; - } - } - case 8: - { - switch (currentRegion) - { - case 7: - case 9: return false; - default: return true; - } - } - case 9: - { - switch (currentRegion) - { - case 3: - case 6: - case 8: - case 7: return false; - default: return true; - } - } - default: return true; - } -} - - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref mayTraverse test has returned true, so there is a chance the - segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible - region 5. - - The return value of this method indicates whether the segment actually traverses region 5 or not. - - If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and - exit points of region 5. They will become the optimized points for that segment. -*/ -bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - QList intersections; - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double keyPx = mKeyAxis->coordToPixel(key); - const double valuePx = mValueAxis->coordToPixel(value); - const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); - const double prevValuePx = mValueAxis->coordToPixel(prevValue); - if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); - } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); - } else // line is skewed - { - double gamma; - double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); - // check top of rect: - gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); - // check bottom of rect: - gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); - const double valuePerKeyPx = 1.0/keyPerValuePx; - // check left of rect: - gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); - // check right of rect: - gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); - } - - // handle cases where found points isn't exactly 2: - if (intersections.size() > 2) - { - // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: - double distSqrMax = 0; - QPointF pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = intersections.at(i); - pv2 = intersections.at(k); - distSqrMax = distSqr; - } - } - } - intersections = QList() << pv1 << pv2; - } else if (intersections.size() != 2) - { - // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment - return false; - } - - // possibly re-sort points so optimized point segment has same direction as original segment: - double xDelta = keyPx-prevKeyPx; - double yDelta = valuePx-prevValuePx; - if (mKeyAxis->orientation() != Qt::Horizontal) - qSwap(xDelta, yDelta); - if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction - intersections.move(0, 1); - crossA = intersections.at(0); - crossB = intersections.at(1); - return true; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref getTraverse test has returned true, so the segment definitely - traverses the visible region 5 when going from \a prevRegion to \a currentRegion. - - In certain situations it is not sufficient to merely generate the entry and exit points of the - segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in - addition to traversing region 5, skips another region outside of region 5, which makes it - necessary to add an optimized corner point there (very similar to the job \ref - getOptimizedCornerPoints does for segments that are completely in outside regions and don't - traverse 5). - - As an example, consider a segment going from region 1 to region 6, traversing the lower left - corner of region 5. In this configuration, the segment additionally crosses the border between - region 1 and 2 before entering region 5. This makes it necessary to add an additional point in - the top left corner, before adding the optimized traverse points. So in this case, the output - parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be - empty. - - In some cases, such as when going from region 1 to 9, it may even be necessary to add additional - corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse - return the respective corner points. -*/ -void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: { break; } // shouldn't happen because this method only handles full traverses - case 6: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - } -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in - \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that - if the curve has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the curve line is also taken into account. - - If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns - -1.0. -*/ -double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - if (mDataContainer->size() == 1) - { - QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); - closestData = mDataContainer->constBegin(); - return QCPVector2D(dataPoint-pixelPoint).length(); - } - - // calculate minimum distances to curve data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - QVector lines; - getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width - for (int i=0; i QCPBarsGroup::bars() const - - Returns all bars currently in this group. - - \see bars(int index) -*/ - -/*! \fn int QCPBarsGroup::size() const - - Returns the number of QCPBars plottables that are part of this group. - -*/ - -/*! \fn bool QCPBarsGroup::isEmpty() const - - Returns whether this bars group is empty. - - \see size -*/ - -/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) - - Returns whether the specified \a bars plottable is part of this group. - -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new bars group for the specified QCustomPlot instance. -*/ -QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot), - mSpacingType(stAbsolute), - mSpacing(4) -{ -} - -QCPBarsGroup::~QCPBarsGroup() -{ - clear(); -} - -/*! - Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. - - The actual spacing can then be specified with \ref setSpacing. - - \see setSpacing -*/ -void QCPBarsGroup::setSpacingType(SpacingType spacingType) -{ - mSpacingType = spacingType; -} - -/*! - Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is - defined by the current \ref SpacingType, which can be set with \ref setSpacingType. - - \see setSpacingType -*/ -void QCPBarsGroup::setSpacing(double spacing) -{ - mSpacing = spacing; -} - -/*! - Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars - exists, returns 0. - - \see bars(), size -*/ -QCPBars *QCPBarsGroup::bars(int index) const -{ - if (index >= 0 && index < mBars.size()) - { - return mBars.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Removes all QCPBars plottables from this group. - - \see isEmpty -*/ -void QCPBarsGroup::clear() -{ - Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay - bars->setBarsGroup(0); // removes itself via removeBars -} - -/*! - Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref - QCPBars::setBarsGroup on the \a bars instance. - - \see insert, remove -*/ -void QCPBarsGroup::append(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - else - qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); -} - -/*! - Inserts the specified \a bars plottable into this group at the specified index position \a i. - This gives you full control over the ordering of the bars. - - \a bars may already be part of this group. In that case, \a bars is just moved to the new index - position. - - \see append, remove -*/ -void QCPBarsGroup::insert(int i, QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - // first append to bars list normally: - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - // then move to according position: - mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); -} - -/*! - Removes the specified \a bars plottable from this group. - - \see contains, clear -*/ -void QCPBarsGroup::remove(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (mBars.contains(bars)) - bars->setBarsGroup(0); - else - qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); -} - -/*! \internal - - Adds the specified \a bars to the internal mBars list of bars. This method does not change the - barsGroup property on \a bars. - - \see unregisterBars -*/ -void QCPBarsGroup::registerBars(QCPBars *bars) -{ - if (!mBars.contains(bars)) - mBars.append(bars); -} - -/*! \internal - - Removes the specified \a bars from the internal mBars list of bars. This method does not change - the barsGroup property on \a bars. - - \see registerBars -*/ -void QCPBarsGroup::unregisterBars(QCPBars *bars) -{ - mBars.removeOne(bars); -} - -/*! \internal - - Returns the pixel offset in the key dimension the specified \a bars plottable should have at the - given key coordinate \a keyCoord. The offset is relative to the pixel position of the key - coordinate \a keyCoord. -*/ -double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) -{ - // find list of all base bars in case some mBars are stacked: - QList baseBars; - Q_FOREACH (const QCPBars *b, mBars) - { - while (b->barBelow()) - b = b->barBelow(); - if (!baseBars.contains(b)) - baseBars.append(b); - } - // find base bar this "bars" is stacked on: - const QCPBars *thisBase = bars; - while (thisBase->barBelow()) - thisBase = thisBase->barBelow(); - - // determine key pixel offset of this base bars considering all other base bars in this barsgroup: - double result = 0; - int index = baseBars.indexOf(thisBase); - if (index >= 0) - { - if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) - { - return result; - } else - { - double lowerPixelWidth, upperPixelWidth; - int startIndex; - int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative - if (baseBars.size() % 2 == 0) // even number of bars - { - startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); - result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing - } else // uneven number of bars - { - startIndex = (baseBars.size()-1)/2+dir; - baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar - result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing - } - for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars - { - baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth); - result += getPixelSpacing(baseBars.at(i), keyCoord); - } - // finally half of our bars width: - baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; - // correct sign of result depending on orientation and direction of key axis: - result *= dir*thisBase->keyAxis()->pixelOrientation(); - } - } - return result; -} - -/*! \internal - - Returns the spacing in pixels which is between this \a bars and the following one, both at the - key coordinate \a keyCoord. - - \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only - needed to get access to the key axis transformation and axis rect for the modes \ref - stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in - \ref stPlotCoords on a logarithmic axis. -*/ -double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) -{ - switch (mSpacingType) - { - case stAbsolute: - { - return mSpacing; - } - case stAxisRectRatio: - { - if (bars->keyAxis()->orientation() == Qt::Horizontal) - return bars->keyAxis()->axisRect()->width()*mSpacing; - else - return bars->keyAxis()->axisRect()->height()*mSpacing; - } - case stPlotCoords: - { - double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); - return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); - } - } - return 0; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBarsData - \brief Holds the data of one single data point (one bar) for QCPBars. - - The stored data is: - \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) - \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPBarsDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPBarsData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPBarsData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a bar data point with key and value set to zero. -*/ -QCPBarsData::QCPBarsData() : - key(0), - value(0) -{ -} - -/*! - Constructs a bar data point with the specified \a key and \a value. -*/ -QCPBarsData::QCPBarsData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBars - \brief A plottable representing a bar chart in a plot. - - \image html QCPBars.png - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section qcpbars-appearance Changing the appearance - - The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). - The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. - - Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other - (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear - stacked. - - If you would like to group multiple QCPBars plottables together so they appear side by side as - shown below, use QCPBarsGroup. - - \image html QCPBarsGroup.png - - \section qcpbars-usage Usage - - Like all data representing objects in QCustomPlot, the QCPBars is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/*! \fn QCPBars *QCPBars::barBelow() const - Returns the bars plottable that is directly below this bars plottable. - If there is no such plottable, returns 0. - - \see barAbove, moveBelow, moveAbove -*/ - -/*! \fn QCPBars *QCPBars::barAbove() const - Returns the bars plottable that is directly above this bars plottable. - If there is no such plottable, returns 0. - - \see barBelow, moveBelow, moveAbove -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.75), - mWidthType(wtPlotCoords), - mBarsGroup(0), - mBaseValue(0), - mStackingGap(0) -{ - // modify inherited properties from abstract plottable: - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPBars::~QCPBars() -{ - setBarsGroup(0); - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. - Modifying the data in the container will then affect all bars that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the bar's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 - - \see addData -*/ -void QCPBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets the width of the bars. - - How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), - depends on the currently set width type, see \ref setWidthType and \ref WidthType. -*/ -void QCPBars::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the bars is defined. See the documentation of \ref WidthType for an - explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPBars::setWidthType(QCPBars::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref - QCPBarsGroup::append. - - To remove this QCPBars from any group, set \a barsGroup to 0. -*/ -void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) -{ - // deregister at old group: - if (mBarsGroup) - mBarsGroup->unregisterBars(this); - mBarsGroup = barsGroup; - // register at new group: - if (mBarsGroup) - mBarsGroup->registerBars(this); -} - -/*! - Sets the base value of this bars plottable. - - The base value defines where on the value coordinate the bars start. How far the bars extend from - the base value is given by their individual value data. For example, if the base value is set to - 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at - 3. - - For stacked bars, only the base value of the bottom-most QCPBars has meaning. - - The default base value is 0. -*/ -void QCPBars::setBaseValue(double baseValue) -{ - mBaseValue = baseValue; -} - -/*! - If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method - allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by - the bars below it. -*/ -void QCPBars::setStackingGap(double pixels) -{ - mStackingGap = pixels; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(double key, double value) -{ - mDataContainer->add(QCPBarsData(key, value)); -} - -/*! - Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear - below the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barAbove, barBelow -*/ -void QCPBars::moveBelow(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar below it: - if (bars) - { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); - } -} - -/*! - Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear - above the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object above itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barBelow, barAbove -*/ -void QCPBars::moveAbove(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar above it: - if (bars) - { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getBarRect(it->key, it->value))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getBarRect(it->key, it->value).contains(pos)) - { - if (details) - { - int pointIndex = it-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return mParentPlot->selectionTolerance()*0.99; - } - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in - absolute pixels), using this method to adapt the key axis range to fit the bars into the - currently visible axis range will not work perfectly. Because in the moment the axis range is - changed to the new range, the fixed pixel widths/spacings will represent different coordinate - spans than before, which in turn would require a different key range to perfectly fit, and so on. - The only solution would be to iteratively approach the perfect fitting axis range, but the - mismatch isn't large enough in most applications, to warrant this here. If a user does need a - better fit, he should call the corresponding axis rescale multiple times in a row. - */ - QCPRange range; - range = mDataContainer->keyRange(foundRange, inSignDomain); - - // determine exact range of bars by including bar width and barsgroup offset: - if (foundRange && mKeyAxis) - { - double lowerPixelWidth, upperPixelWidth, keyPixel; - // lower range bound: - getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); - const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) - range.lower = lowerCorrected; - // upper range bound: - getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); - const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) - range.upper = upperCorrected; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - // Note: can't simply use mDataContainer->valueRange here because we need to - // take into account bar base value and possible stacking of multiple bars - QCPRange range; - range.lower = mBaseValue; - range.upper = mBaseValue; - bool haveLower = true; // set to true, because baseValue should always be visible in bar charts - bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts - QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (inKeyRange != QCPRange()) - { - itBegin = mDataContainer->findBegin(inKeyRange.lower); - itEnd = mDataContainer->findEnd(inKeyRange.upper); - } - for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - - foundRange = true; // return true because bar charts always have the 0-line visible - return range; -} - -/* inherits documentation from base class */ -QPointF QCPBars::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); - const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyPixel, valuePixel); - else - return QPointF(valuePixel, keyPixel); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mDataContainer->isEmpty()) return; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPBarsDataContainer::const_iterator begin = visibleBegin; - QCPBarsDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -#endif - // draw bar: - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyBrush(painter); - mSelectionDecorator->applyPen(painter); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - } - applyDefaultAntialiasingHint(painter); - painter->drawPolygon(getBarRect(it->key, it->value)); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - if (mDataContainer->isEmpty()) - { - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - - // get visible data range as QMap iterators - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); - double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); - double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); - bool isVisible = false; - // walk left from begin to find lower bar that actually is completely outside visible pixel range: - QCPBarsDataContainer::const_iterator it = begin; - while (it != mDataContainer->constBegin()) - { - --it; - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); - if (isVisible) - begin = it; - else - break; - } - // walk right from ubound to find upper bar that actually is completely outside visible pixel range: - it = end; - while (it != mDataContainer->constEnd()) - { - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); - if (isVisible) - end = it+1; - else - break; - ++it; - } -} - -/*! \internal - - Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The - rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref - setBaseValue), and to have non-overlapping border lines with the bars stacked below. -*/ -QRectF QCPBars::getBarRect(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double lowerPixelWidth, upperPixelWidth; - getPixelWidth(key, lowerPixelWidth, upperPixelWidth); - double base = getStackedBaseValue(key, value >= 0); - double basePixel = valueAxis->coordToPixel(base); - double valuePixel = valueAxis->coordToPixel(base+value); - double keyPixel = keyAxis->coordToPixel(key); - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, key); - double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); - bottomOffset += mBarBelow ? mStackingGap : 0; - bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); - if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) - bottomOffset = valuePixel-basePixel; - if (keyAxis->orientation() == Qt::Horizontal) - { - return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); - } else - { - return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). - - The output parameters \a lower and \a upper return the number of pixels the bar extends to lower - and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a - lower is negative and \a upper positive). -*/ -void QCPBars::getPixelWidth(double key, double &lower, double &upper) const -{ - lower = 0; - upper = 0; - switch (mWidthType) - { - case wtAbsolute: - { - upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - { - double keyPixel = mKeyAxis.data()->coordToPixel(key); - upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; - // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by - // coordinate transform which includes range direction - } else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } -} - -/*! \internal - - This function is called to find at which value to start drawing the base of a bar at \a key, when - it is stacked on top of another QCPBars (e.g. with \ref moveAbove). - - positive and negative bars are separated per stack (positive are stacked above baseValue upwards, - negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the - bar for which we need the base value is negative, set \a positive to false. -*/ -double QCPBars::getStackedBaseValue(double key, bool positive) const -{ - if (mBarBelow) - { - double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack - // find bars of mBarBelow that are approximately at key and find largest one: - double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point - if (key == 0) - epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); - QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); - QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); - while (it != itEnd) - { - if (it->key > key-epsilon && it->key < key+epsilon) - { - if ((positive && it->value > max) || - (!positive && it->value < max)) - max = it->value; - } - ++it; - } - // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getStackedBaseValue(key, positive); - } else - return mBaseValue; -} - -/*! \internal - - Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) - currently above lower and below upper will become disconnected to lower/upper. - - If lower is zero, upper will be disconnected at the bottom. - If upper is zero, lower will be disconnected at the top. -*/ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) -{ - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom - { - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - lower->mBarAbove = 0; - } else // connect lower and upper - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - lower->mBarAbove = upper; - upper->mBarBelow = lower; - } -} -/* end of 'src/plottables/plottable-bars.cpp' */ - - -/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBoxData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBoxData - \brief Holds the data of one single data point for QCPStatisticalBox. - - The stored data is: - - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - - \li \a minimum: the position of the lower whisker, typically the minimum measurement of the - sample that's not considered an outlier. - - \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a median: the value of the median mark inside the quartile box. The median separates the - sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) - - \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a maximum: the position of the upper whisker, typically the maximum measurement of the - sample that's not considered an outlier. - - \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key - coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) - - The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a - typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template - parameter. See the documentation there for an explanation regarding the data type's generic - methods. - - \see QCPStatisticalBoxDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPStatisticalBoxData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainValue() const - - Returns the \a median member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const - - Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box - data point, possibly further expanded by outliers. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData() : - key(0), - minimum(0), - lowerQuartile(0), - median(0), - upperQuartile(0), - maximum(0) -{ -} - -/*! - Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a - upperQuartile, \a maximum and optionally a number of \a outliers. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : - key(key), - minimum(minimum), - lowerQuartile(lowerQuartile), - median(median), - upperQuartile(upperQuartile), - maximum(maximum), - outliers(outliers) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBox -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBox - \brief A plottable representing a single statistical box in a plot. - - \image html QCPStatisticalBox.png - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPStatisticalBoxDataContainer. - - Additionally each data point can itself have a list of outliers, drawn as scatter points at the - key coordinate of the respective statistical box data point. They can either be set by using the - respective \ref addData(double,double,double,double,double,double,const QVector&) - "addData" method or accessing the individual data points through \ref data, and setting the - QVector outliers of the data points directly. - - \section qcpstatisticalbox-appearance Changing the appearance - - The appearance of each data point box, ranging from the lower to the upper quartile, is - controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref - setWidth in plot coordinates. - - Each data point's visual representation also consists of two whiskers. Whiskers are the lines - which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. - The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, - \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at - the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set - the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a - few pixels due to the pen cap being not perfectly flat. - - The median indicator line inside the box has its own pen, \ref setMedianPen. - - The outlier data points are drawn as normal scatter points. Their look can be controlled with - \ref setOutlierStyle - - \section qcpstatisticalbox-usage Usage - - Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 -*/ - -/* start documentation of inline functions */ - -/*! \fn QSharedPointer QCPStatisticalBox::data() const - - Returns a shared pointer to the internal data storage of type \ref - QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more - convenient and faster than using the regular \ref setData or \ref addData methods. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its - value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and - not have the same orientation. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not - delete it manually but use QCustomPlot::removePlottable() instead. -*/ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.5), - mWhiskerWidth(0.2), - mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), - mWhiskerBarPen(Qt::black), - mWhiskerAntialiased(false), - mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), - mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) -{ - setPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container - safely. Modifying the data in the container will then affect all statistical boxes that share the - container. Sharing can be achieved by simply exchanging the data containers wrapped in shared - pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the statistical box data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 - - \see addData -*/ -void QCPStatisticalBox::setData(QSharedPointer data) -{ - mDataContainer = data; -} -/*! \overload - - Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a - median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the - number of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); -} - -/*! - Sets the width of the boxes in key coordinates. - - \see setWhiskerWidth -*/ -void QCPStatisticalBox::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the width of the whiskers in key coordinates. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWidth -*/ -void QCPStatisticalBox::setWhiskerWidth(double width) -{ - mWhiskerWidth = width; -} - -/*! - Sets the pen used for drawing the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone - line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. - - \see setWhiskerBarPen -*/ -void QCPStatisticalBox::setWhiskerPen(const QPen &pen) -{ - mWhiskerPen = pen; -} - -/*! - Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at - each end of the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWhiskerPen -*/ -void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) -{ - mWhiskerBarPen = pen; -} - -/*! - Sets whether the statistical boxes whiskers are drawn with antialiasing or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) -{ - mWhiskerAntialiased = enabled; -} - -/*! - Sets the pen used for drawing the median indicator line inside the statistical boxes. -*/ -void QCPStatisticalBox::setMedianPen(const QPen &pen) -{ - mMedianPen = pen; -} - -/*! - Sets the appearance of the outlier data points. - - Outliers can be specified with the method - \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -*/ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) -{ - mOutlierStyle = style; -} - -/*! \overload - - Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and - \a maximum to the current data. The provided vectors should have equal length. Else, the number - of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || - median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" - << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); - const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->minimum = minimum[i]; - it->lowerQuartile = lowerQuartile[i]; - it->median = median[i]; - it->upperQuartile = upperQuartile[i]; - it->maximum = maximum[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile - and \a maximum to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -{ - mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getQuartileBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - double minDistSqr = std::numeric_limits::max(); - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getQuartileBox(it).contains(pos)) // quartile box - { - double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } else // whiskers - { - const QVector whiskerBackbones(getWhiskerBackboneLines(it)); - for (int i=0; iconstBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return qSqrt(minDistSqr); - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; - QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -# ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->minimum) || - QCP::isInvalidData(it->lowerQuartile, it->median) || - QCP::isInvalidData(it->upperQuartile, it->maximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; ioutliers.size(); ++i) - if (QCP::isInvalidData(it->outliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -# endif - - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - QCPScatterStyle finalOutlierStyle = mOutlierStyle; - if (isSelectedSegment && mSelectionDecorator) - finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); - drawStatisticalBox(painter, it, finalOutlierStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! - Draws the graphical representation of a single statistical box with the data given by the - iterator \a it with the provided \a painter. - - If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. - - \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const -{ - // draw quartile box: - applyDefaultAntialiasingHint(painter); - const QRectF quartileBox = getQuartileBox(it); - painter->drawRect(quartileBox); - // draw median line with cliprect set to quartile box: - painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - painter->setPen(mMedianPen); - painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); - painter->restore(); - // draw whisker lines: - applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); - painter->setPen(mWhiskerPen); - painter->drawLines(getWhiskerBackboneLines(it)); - painter->setPen(mWhiskerBarPen); - painter->drawLines(getWhiskerBarLines(it)); - // draw outliers: - applyScattersAntialiasingHint(painter); - outlierStyle.applyTo(painter, mPen); - for (int i=0; ioutliers.size(); ++i) - outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points -} - -/*! \internal - - Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the - value range from the lower to the upper quartile, of the data given by \a it. - - \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QRectF result; - result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); - result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); - return result; -} - -/*! \internal - - Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value - range from the minimum to the lower quartile, and from the upper quartile to the maximum of the - data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines -*/ -QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone - result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone - return result; -} - -/*! \internal - - Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the - end of the whisker backbones, at the minimum and maximum of the data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines -*/ -QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar - result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar - return result; -} -/* end of 'src/plottables/plottable-statisticalbox.cpp' */ - - -/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMapData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMapData - \brief Holds the two-dimensional data of a QCPColorMap plottable. - - This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref - QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a - color, depending on the value. - - The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). - Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref - setKeyRange, \ref setValueRange). - - The data cells can be accessed in two ways: They can be directly addressed by an integer index - with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot - coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are - provided by the functions \ref coordToCell and \ref cellToCoord. - - A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if - allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref - fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on - the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. - - This class also buffers the minimum and maximum values that are in the data set, to provide - QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value - that is greater than the current maximum increases this maximum to the new value. However, - setting the cell that currently holds the maximum value to a smaller value doesn't decrease the - maximum again, because finding the true new maximum would require going through the entire data - array, which might be time consuming. The same holds for the data minimum. This functionality is - given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the - true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience - parameter \a recalculateDataBounds which may be set to true to automatically call \ref - recalculateDataBounds internally. -*/ - -/* start of documentation of inline functions */ - -/*! \fn bool QCPColorMapData::isEmpty() const - - Returns whether this instance carries no data. This is equivalent to having a size where at least - one of the dimensions is 0 (see \ref setSize). -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction - and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap - at the coordinates \a keyRange and \a valueRange. - - \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange -*/ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - setSize(keySize, valueSize); - fill(0); -} - -QCPColorMapData::~QCPColorMapData() -{ - if (mData) - delete[] mData; - if (mAlpha) - delete[] mAlpha; -} - -/*! - Constructs a new QCPColorMapData instance copying the data and range of \a other. -*/ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - *this = other; -} - -/*! - Overwrites this color map data instance with the data stored in \a other. The alpha map state is - transferred, too. -*/ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) -{ - if (&other != this) - { - const int keySize = other.keySize(); - const int valueSize = other.valueSize(); - if (!other.mAlpha && mAlpha) - clearAlpha(); - setSize(keySize, valueSize); - if (other.mAlpha && !mAlpha) - createAlpha(false); - setRange(other.keyRange(), other.valueRange()); - if (!isEmpty()) - { - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - if (mAlpha) - memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); - } - mDataBounds = other.mDataBounds; - mDataModified = true; - } - return *this; -} - -/* undocumented getter */ -double QCPColorMapData::data(double key, double value) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; - else - return 0; -} - -/* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; - else - return 0; -} - -/*! - Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. - - If this color map data doesn't have an alpha map (because \ref setAlpha was never called after - creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. - - \see setAlpha -*/ -unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) -{ - if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mAlpha[valueIndex*mKeySize + keyIndex]; - else - return 255; -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in - the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref - isEmpty returns true. - - \see setRange, setKeySize, setValueSize -*/ -void QCPColorMapData::setSize(int keySize, int valueSize) -{ - if (keySize != mKeySize || valueSize != mValueSize) - { - mKeySize = keySize; - mValueSize = valueSize; - if (mData) - delete[] mData; - mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) - { -#ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message -#endif - mData = new double[mKeySize*mValueSize]; -#ifdef __EXCEPTIONS - } catch (...) { mData = 0; } -#endif - if (mData) - fill(0); - else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else - mData = 0; - - if (mAlpha) // if we had an alpha map, recreate it with new size - createAlpha(); - - mDataModified = true; - } -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. - - \see setKeyRange, setSize, setValueSize -*/ -void QCPColorMapData::setKeySize(int keySize) -{ - setSize(keySize, mValueSize); -} - -/*! - Resizes the data array to have \a valueSize cells in the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. - - \see setValueRange, setSize, setKeySize -*/ -void QCPColorMapData::setValueSize(int valueSize) -{ - setSize(mKeySize, valueSize); -} - -/*! - Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area - covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setSize -*/ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) -{ - setKeyRange(keyRange); - setValueRange(valueRange); -} - -/*! - Sets the coordinate range the data shall be distributed over in the key dimension. Together with - the value range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setRange, setValueRange, setSize -*/ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) -{ - mKeyRange = keyRange; -} - -/*! - Sets the coordinate range the data shall be distributed over in the value dimension. Together with - the key range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there - will be cells centered on the value coordinates 2, 2.5 and 3. - - \see setRange, setKeyRange, setSize -*/ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) -{ - mValueRange = valueRange; -} - -/*! - Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a - z. - - \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or - value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, - you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to - determine the cell index. Rather directly access the cell index with \ref - QCPColorMapData::setCell. - - \see setCell, setRange -*/ -void QCPColorMapData::setData(double key, double value, double z) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices - enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see - \ref setSize). - - In the standard plot configuration (horizontal key axis and vertical value axis, both not - range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with - indices (keySize-1, valueSize-1) is in the top right corner of the color map. - - \see setData, setSize -*/ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value - of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully - opaque cell. - - If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish - to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. - - Note that the cell-wise alpha which can be configured here is independent of any alpha configured - in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise - and gradient alpha, the alpha values will be blended accordingly during rendering of the color - map. - - \see fillAlpha, clearAlpha -*/ -void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - if (mAlpha || createAlpha()) - { - mAlpha[valueIndex*mKeySize + keyIndex] = alpha; - mDataModified = true; - } - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Goes through the data and updates the buffered minimum and maximum data values. - - Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange - and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten - with a smaller or larger value respectively, since the buffered maximum/minimum values have been - updated the last time. Why this is the case is explained in the class description (\ref - QCPColorMapData). - - Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a - recalculateDataBounds for convenience. Setting this to true will call this method for you, before - doing the rescale. -*/ -void QCPColorMapData::recalculateDataBounds() -{ - if (mKeySize > 0 && mValueSize > 0) - { - double minHeight = mData[0]; - double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i maxHeight) - maxHeight = mData[i]; - if (mData[i] < minHeight) - minHeight = mData[i]; - } - mDataBounds.lower = minHeight; - mDataBounds.upper = maxHeight; - } -} - -/*! - Frees the internal data memory. - - This is equivalent to calling \ref setSize "setSize(0, 0)". -*/ -void QCPColorMapData::clear() -{ - setSize(0, 0); -} - -/*! - Frees the internal alpha map. The color map will have full opacity again. -*/ -void QCPColorMapData::clearAlpha() -{ - if (mAlpha) - { - delete[] mAlpha; - mAlpha = 0; - mDataModified = true; - } -} - -/*! - Sets all cells to the value \a z. -*/ -void QCPColorMapData::fill(double z) -{ - const int dataCount = mValueSize*mKeySize; - for (int i=0; i(data); - return; - } - if (copy) - { - *mMapData = *data; - } else - { - delete mMapData; - mMapData = data; - } - mMapImageInvalidated = true; -} - -/*! - Sets the data range of this color map to \a dataRange. The data range defines which data values - are mapped to the color gradient. - - To make the data range span the full range of the data set, use \ref rescaleDataRange. - - \see QCPColorScale::setDataRange -*/ -void QCPColorMap::setDataRange(const QCPRange &dataRange) -{ - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - if (mDataScaleType == QCPAxis::stLogarithmic) - mDataRange = dataRange.sanitizedForLogScale(); - else - mDataRange = dataRange.sanitizedForLinScale(); - mMapImageInvalidated = true; - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets whether the data is correlated with the color gradient linearly or logarithmically. - - \see QCPColorScale::setDataScaleType -*/ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - mMapImageInvalidated = true; - Q_EMIT dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - } -} - -/*! - Sets the color gradient that is used to represent the data. For more details on how to create an - own gradient or use one of the preset gradients, see \ref QCPColorGradient. - - The colors defined by the gradient will be used to represent data values in the currently set - data range, see \ref setDataRange. Data points that are outside this data range will either be - colored uniformly with the respective gradient boundary color, or the gradient will repeat, - depending on \ref QCPColorGradient::setPeriodic. - - \see QCPColorScale::setGradient -*/ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - mMapImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets whether the color map image shall use bicubic interpolation when displaying the color map - shrinked or expanded, and not at a 1:1 pixel-to-data scale. - - \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" -*/ -void QCPColorMap::setInterpolate(bool enabled) -{ - mInterpolate = enabled; - mMapImageInvalidated = true; // because oversampling factors might need to change -} - -/*! - Sets whether the outer most data rows and columns are clipped to the specified key and value - range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). - - if \a enabled is set to false, the data points at the border of the color map are drawn with the - same width and height as all other data points. Since the data points are represented by - rectangles of one color centered on the data coordinate, this means that the shown color map - extends by half a data point over the specified key/value range in each direction. - - \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" -*/ -void QCPColorMap::setTightBoundary(bool enabled) -{ - mTightBoundary = enabled; -} - -/*! - Associates the color scale \a colorScale with this color map. - - This means that both the color scale and the color map synchronize their gradient, data range and - data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps - can be associated with one single color scale. This causes the color maps to also synchronize - those properties, via the mutual color scale. - - This function causes the color map to adopt the current color gradient, data range and data scale - type of \a colorScale. After this call, you may change these properties at either the color map - or the color scale, and the setting will be applied to both. - - Pass 0 as \a colorScale to disconnect the color scale from this color map again. -*/ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) -{ - if (mColorScale) // unconnect signals from old color scale - { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale - { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } -} - -/*! - Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the - current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, - only for the third data dimension of the color map. - - The minimum and maximum values of the data set are buffered in the internal QCPColorMapData - instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref - QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For - performance reasons, however, they are only updated in an expanding fashion. So the buffered - maximum can only increase and the buffered minimum can only decrease. In consequence, changes to - the data that actually lower the maximum of the data set (by overwriting the cell holding the - current maximum with a smaller value), aren't recognized and the buffered maximum overestimates - the true maximum of the data set. The same happens for the buffered minimum. To recalculate the - true minimum and maximum by explicitly looking at each cell, the method - QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a - recalculateDataBounds calls this method before setting the data range to the buffered minimum and - maximum. - - \see setDataRange -*/ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) -{ - if (recalculateDataBounds) - mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); -} - -/*! - Takes the current appearance of the color map and updates the legend icon, which is used to - represent this color map in the legend (see \ref QCPLegend). - - The \a transformMode specifies whether the rescaling is done by a faster, low quality image - scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm - (Qt::SmoothTransformation). - - The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to - the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured - legend icon size, the thumb will be rescaled during drawing of the legend item. - - \see setDataRange -*/ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) -{ - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again - { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); - } -} - -/* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) - { - if (details) - details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. - return mParentPlot->selectionTolerance()*0.99; - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->keyRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (inKeyRange != QCPRange()) - { - if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) - { - foundRange = false; - return QCPRange(); - } - } - - foundRange = true; - QCPRange result = mMapData->valueRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/*! \internal - - Updates the internal map image buffer by going through the internal \ref QCPColorMapData and - turning the data values into color pixels with \ref QCPColorGradient::colorize. - - This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image - has been invalidated for a different reason (e.g. a change of the data range with \ref - setDataRange). - - If the map cell count is low, the image created will be oversampled in order to avoid a - QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images - without smooth transform enabled. Accordingly, oversampling isn't performed if \ref - setInterpolate is true. -*/ -void QCPColorMap::updateMapImage() -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - if (mMapData->isEmpty()) return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - const int keySize = mMapData->keySize(); - const int valueSize = mMapData->valueSize(); - int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - - // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) - mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) - mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); - - if (mMapImage.isNull()) - { - qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; - mMapImage = QImage(QSize(10, 10), format); - mMapImage.fill(Qt::black); - } else - { - QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - // resize undersampled map image to actual key/value cell sizes: - if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) - mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); - else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) - mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); - localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image - } else if (!mUndersampledMapImage.isNull()) - mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it - - const double *rawData = mMapData->mData; - const unsigned char *rawAlpha = mMapData->mAlpha; - if (keyAxis->orientation() == Qt::Horizontal) - { - const int lineCount = valueSize; - const int rowCount = keySize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - } - } else // keyAxis->orientation() == Qt::Vertical - { - const int lineCount = keySize; - const int rowCount = valueSize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - } - } - - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - if (keyAxis->orientation() == Qt::Horizontal) - mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - else - mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - } - } - mMapData->mDataModified = false; - mMapImageInvalidated = false; -} - -/* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) -{ - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) - updateMapImage(); - - // use buffer if painting vectorized (PDF): - const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); - QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized - QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in - QPixmap mapBuffer; - if (useBuffer) - { - const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps - mapBufferTarget = painter->clipRegion().boundingRect(); - mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); - mapBuffer.fill(Qt::transparent); - localPainter = new QCPPainter(&mapBuffer); - localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); - localPainter->translate(-mapBufferTarget.topLeft()); - } - - QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): - double halfCellWidth = 0; // in pixels - double halfCellHeight = 0; // in pixels - if (keyAxis()->orientation() == Qt::Horizontal) - { - if (mMapData->keySize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); - } else // keyAxis orientation is Qt::Vertical - { - if (mMapData->keySize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); - } - imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); - const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); - QRegion clipBackup; - if (mTightBoundary) - { - clipBackup = localPainter->clipRegion(); - QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - localPainter->setClipRect(tightClipRect, Qt::IntersectClip); - } - localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - localPainter->setClipRegion(clipBackup); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); - - if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter - { - delete localPainter; - painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); - } -} - -/* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - // draw map thumbnail: - if (!mLegendIcon.isNull()) - { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); - } - /* - // draw frame: - painter->setBrush(Qt::NoBrush); - painter->setPen(Qt::black); - painter->drawRect(rect.adjusted(1, 1, 0, 0)); - */ -} -/* end of 'src/plottables/plottable-colormap.cpp' */ - - -/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancialData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancialData - \brief Holds the data of one single data point for QCPFinancial. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a open: The opening value at the data point (this is the \a mainValue) - \li \a high: The high/maximum value at the data point - \li \a low: The low/minimum value at the data point - \li \a close: The closing value at the data point - - The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef - for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPFinancialDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPFinancialData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainValue() const - - Returns the \a open member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPFinancialData::valueRange() const - - Returns a QCPRange spanning from the \a low to the \a high value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPFinancialData::QCPFinancialData() : - key(0), - open(0), - high(0), - low(0), - close(0) -{ -} - -/*! - Constructs a data point with the specified \a key and OHLC values. -*/ -QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : - key(key), - open(open), - high(high), - low(low), - close(close) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancial -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancial - \brief A plottable representing a financial stock chart - - \image html QCPFinancial.png - - This plottable represents time series data binned to certain intervals, mainly used for stock - charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be - set via \ref setChartStyle. - - The data is passed via \ref setData as a set of open/high/low/close values at certain keys - (typically times). This means the data must be already binned appropriately. If data is only - available as a series of values (e.g. \a price against \a time), you can use the static - convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed - to \ref setData. - - The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref - setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and - the width to (or slightly less than) one time bin interval width. - - \section qcpfinancial-appearance Changing the appearance - - Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, - lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). - - If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are - represented with a different pen and brush than negative changes (\a close < \a open). These can - be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref - setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection - however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, - irrespective of whether the chart is single- or two-colored. - - \section qcpfinancial-usage Usage - - Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot - instance takes ownership of the plottable, so do not delete it manually but use - QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 - Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data - series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const - - Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods, in certain situations. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mChartStyle(csCandlestick), - mWidth(0.5), - mWidthType(wtPlotCoords), - mTwoColored(true), - mBrushPositive(QBrush(QColor(50, 160, 0))), - mBrushNegative(QBrush(QColor(180, 0, 15))), - mPenPositive(QPen(QColor(40, 150, 0))), - mPenNegative(QPen(QColor(170, 5, 5))) -{ - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPFinancial::~QCPFinancial() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. - Modifying the data in the container will then affect all financials that share the container. - Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the financial's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a - close. The provided vectors should have equal length. Else, the number of added points will be - the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, open, high, low, close, alreadySorted); -} - -/*! - Sets which representation style shall be used to display the OHLC data. -*/ -void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) -{ - mChartStyle = style; -} - -/*! - Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. - - A typical choice is to set it to (or slightly less than) one bin interval width. -*/ -void QCPFinancial::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for - an explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets whether this chart shall contrast positive from negative trends per data point by using two - separate colors to draw the respective bars/candlesticks. - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setTwoColored(bool twoColored) -{ - mTwoColored = twoColored; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushNegative, setPenPositive, setPenNegative -*/ -void QCPFinancial::setBrushPositive(const QBrush &brush) -{ - mBrushPositive = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushPositive, setPenNegative, setPenPositive -*/ -void QCPFinancial::setBrushNegative(const QBrush &brush) -{ - mBrushNegative = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setPenPositive(const QPen &pen) -{ - mPenPositive = pen; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setBrushNegative, setBrushPositive -*/ -void QCPFinancial::setPenNegative(const QPen &pen) -{ - mPenNegative = pen; -} - -/*! \overload - - Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. - The provided vectors should have equal length. Else, the number of added points will be the size - of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); - const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->open = open[i]; - it->high = high[i]; - it->low = low[i]; - it->close = close[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current - data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(double key, double open, double high, double low, double close) -{ - mDataContainer->add(QCPFinancialData(key, open, high, low, close)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(selectionHitBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - // perform select test according to configured style: - double result = -1; - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - case QCPFinancial::csCandlestick: - result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - } - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } - - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/*! - A convenience function that converts time series data (\a value against \a time) to OHLC binned - data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const - QCPFinancialDataContainer&). - - The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. - For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour - each, set \a timeBinSize to 3600. - - \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The - value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. - It merely defines the mathematical offset/phase of the bins that will be used to process the - data. -*/ -QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) -{ - QCPFinancialDataContainer data; - int count = qMin(time.size(), value.size()); - if (count == 0) - return QCPFinancialDataContainer(); - - QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); - int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); - for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); - if (i == count-1) // last data point is in current bin, finalize bin: - { - currentBinData.close = value.at(i); - currentBinData.key = timeBinOffset+(index)*timeBinSize; - data.add(currentBinData); - } - } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: - { - // finalize current bin: - currentBinData.close = value.at(i-1); - currentBinData.key = timeBinOffset+(index-1)*timeBinSize; - data.add(currentBinData); - // start next bin: - currentBinIndex = index; - currentBinData.open = value.at(i); - currentBinData.high = value.at(i); - currentBinData.low = value.at(i); - } - } - - return data; -} - -/* inherits documentation from base class */ -void QCPFinancial::draw(QCPPainter *painter) -{ - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPFinancialDataContainer::const_iterator begin = visibleBegin; - QCPFinancialDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - // draw data segment according to configured style: - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - drawOhlcPlot(painter, begin, end, isSelectedSegment); break; - case QCPFinancial::csCandlestick: - drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing - if (mChartStyle == csOhlc) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } - } else if (mChartStyle == csCandlestick) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. -*/ -void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); - // draw close: - painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); - } - } else - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); - // draw close: - painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. -*/ -void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - // draw low: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - // draw low: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); - } - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of - \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel - when this function is called). - - It returns the number of pixels the bar extends to higher keys, relative to the \a key - coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed - horizontal axis, the return value is negative. This is important so the open/close flags on the - \ref csOhlc bar are drawn to the correct side. -*/ -double QCPFinancial::getPixelWidth(double key, double keyPixel) const -{ - double result = 0; - switch (mWidthType) - { - case wtAbsolute: - { - if (mKeyAxis) - result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } - return result; -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a - end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - called by the drawing methods to determine which data (key) range is visible at the current key - axis range setting, so only that needs to be processed. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - begin may still be just outside the visible range. - - \a end returns the iterator just above the highest data point that needs to be taken into - account. Same as before, \a end may also lie just outside of the visible range - - if the plottable contains no data, both \a begin and \a end point to \c constEnd. -*/ -void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points -} - -/*! \internal - - Returns the hit box in pixel coordinates that will be used for data selection with the selection - rect (\ref selectTestRect), of the data point given by \a it. -*/ -QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double keyPixel = keyAxis->coordToPixel(it->key); - double highPixel = valueAxis->coordToPixel(it->high); - double lowPixel = valueAxis->coordToPixel(it->low); - double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); - if (keyAxis->orientation() == Qt::Horizontal) - return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); - else - return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); -} -/* end of 'src/plottables/plottable-financial.cpp' */ - - -/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBarsData - \brief Holds the data of one single error bar for QCPErrorBars. - - The stored data is: - \li \a errorMinus: how much the error bar extends towards negative coordinates from the data - point position - \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point - position - - The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a - typedef for QVector<\ref QCPErrorBarsData>. - - \see QCPErrorBarsDataContainer -*/ - -/*! - Constructs an error bar with errors set to zero. -*/ -QCPErrorBarsData::QCPErrorBarsData() : - errorMinus(0), - errorPlus(0) -{ -} - -/*! - Constructs an error bar with equal \a error in both negative and positive direction. -*/ -QCPErrorBarsData::QCPErrorBarsData(double error) : - errorMinus(error), - errorPlus(error) -{ -} - -/*! - Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, - respectively. -*/ -QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : - errorMinus(errorMinus), - errorPlus(errorPlus) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBars - \brief A plottable that adds a set of error bars to other plottables. - - \image html QCPErrorBars.png - - The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref - QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. - - Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the - error bars. The orientation of the error bars can be controlled with \ref setErrorType. - - By using \ref setData, you can supply the actual error data, either as symmetric error or - plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute - key/value position of each error bar will be adopted from the configured data plottable. The - error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points - of the data plottable. You can directly access and manipulate the error bar data via \ref data. - - Set either of the plus/minus errors to NaN (qQNaN() or - std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at - that index. - - \section qcperrorbars-appearance Changing the appearance - - The appearance of the error bars is defined by the pen (\ref setPen), and the width of the - whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data - point center to prevent that error bars are drawn too close to or even through scatter points. - This gap size can be controlled via \ref setSymbolGap. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPErrorBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You - may use it to directly manipulate the error values, which may be more convenient and faster than - using the regular \ref setData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - It is also important that the \a keyAxis and \a valueAxis are the same for the error bars - plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). - - The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not - delete it manually but use \ref QCustomPlot::removePlottable() instead. -*/ -QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QVector), - mErrorType(etValueError), - mWhiskerWidth(9), - mSymbolGap(10) -{ - setPen(QPen(Qt::black, 0)); - setBrush(Qt::NoBrush); -} - -QCPErrorBars::~QCPErrorBars() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data - container safely. Modifying the data in the container will then affect all \ref QCPErrorBars - instances that share the container. Sharing can be achieved by simply exchanging the data - containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, assign the - data containers directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 - (This uses different notation compared with other plottables, because the \ref QCPErrorBars - uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) - - \see addData -*/ -void QCPErrorBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &error) -{ - mDataContainer->clear(); - addData(error); -} - -/*! \overload - - Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) -{ - mDataContainer->clear(); - addData(errorMinus, errorPlus); -} - -/*! - Sets the data plottable to which the error bars will be applied. The error values specified e.g. - via \ref setData will be associated one-to-one by the data point index to the data points of \a - plottable. This means that the error bars will adopt the key/value coordinates of the data point - with the same index. - - The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref - QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either - of these restrictions is violated, a corresponding qDebug output is generated, and the data - plottable of this \ref QCPErrorBars instance is set to zero. - - For proper display, care must also be taken that the key and value axes of the \a plottable match - those configured for this \ref QCPErrorBars instance. -*/ -void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) -{ - if (plottable && qobject_cast(plottable)) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; - return; - } - if (plottable && !plottable->interface1D()) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; - return; - } - - mDataPlottable = plottable; -} - -/*! - Sets in which orientation the error bars shall appear on the data points. If your data needs both - error dimensions, create two \ref QCPErrorBars with different \a type. -*/ -void QCPErrorBars::setErrorType(ErrorType type) -{ - mErrorType = type; -} - -/*! - Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to - \a pixels. -*/ -void QCPErrorBars::setWhiskerWidth(double pixels) -{ - mWhiskerWidth = pixels; -} - -/*! - Sets the gap diameter around the data points that will be left out when drawing the error bar - backbones. This gap prevents that error bars are drawn too close to or even through scatter - points. -*/ -void QCPErrorBars::setSymbolGap(double pixels) -{ - mSymbolGap = pixels; -} - -/*! \overload - - Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &error) -{ - addData(error, error); -} - -/*! \overload - - Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) -{ - if (errorMinus.size() != errorPlus.size()) - qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); - const int n = qMin(errorMinus.size(), errorPlus.size()); - mDataContainer->reserve(n); - for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); -} - -/*! \overload - - Adds a single symmetrical error bar as specified in \a error. The errors will be associated - one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double error) -{ - mDataContainer->append(QCPErrorBarsData(error)); -} - -/*! \overload - - Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors - will be associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double errorMinus, double errorPlus) -{ - mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); -} - -/* inherits documentation from base class */ -int QCPErrorBars::dataCount() const -{ - return mDataContainer->size(); -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataSortKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataSortKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainValue(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainValue(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::dataValueRange(int index) const -{ - if (mDataPlottable) - { - const double value = mDataPlottable->interface1D()->dataMainValue(index); - if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) - return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); - else - return QCPRange(value, value); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QCPRange(); - } -} - -/* inherits documentation from base class */ -QPointF QCPErrorBars::dataPixelPosition(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataPixelPosition(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QPointF(); -} - -/* inherits documentation from base class */ -bool QCPErrorBars::sortKeyIsMainKey() const -{ - if (mDataPlottable) - { - return mDataPlottable->interface1D()->sortKeyIsMainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return true; - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if (!mDataPlottable) - return result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); - - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - backbones.clear(); - whiskers.clear(); - getErrorBarLines(it, backbones, whiskers); - for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); - break; - } - } - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); - if (beginIndex >= mDataContainer->size()) - beginIndex = mDataContainer->size()-1; - return beginIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); - if (endIndex > mDataContainer->size()) - endIndex = mDataContainer->size(); - return endIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mDataPlottable) return -1; - - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -void QCPErrorBars::draw(QCPPainter *painter) -{ - if (!mDataPlottable) return; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - - // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually - // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): - bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); - } -#endif - - applyDefaultAntialiasingHint(painter); - painter->setBrush(Qt::NoBrush); - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - QVector backbones, whiskers; - for (int i=0; i= unselectedSegments.size(); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - if (painter->pen().capStyle() == Qt::SquareCap) - { - QPen capFixPen(painter->pen()); - capFixPen.setCapStyle(Qt::FlatCap); - painter->setPen(capFixPen); - } - backbones.clear(); - whiskers.clear(); - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) - getErrorBarLines(it, backbones, whiskers); - } - painter->drawLines(backbones); - painter->drawLines(whiskers); - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) - { - painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); - painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); - painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); - } else - { - painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); - painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); - painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); - } -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (mErrorType == etValueError) - { - // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } else // mErrorType == etKeyError - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(dataKey)) continue; - // plus error: - double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); - itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); - } - for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange) - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) - continue; - } - if (mErrorType == etValueError) - { - const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(dataValue)) continue; - // plus error: - double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } else // mErrorType == etKeyError - { - // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! \internal - - Calculates the lines that make up the error bar belonging to the data point \a it. - - The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so - calling this method with different \a it but the same \a backbones and \a whiskers allows to - accumulate lines for multiple data points. - - This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars - instance and within the bounds of the associated data plottable. -*/ -void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const -{ - if (!mDataPlottable) return; - - int index = it-mDataContainer->constBegin(); - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) - return; - QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); - QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); - const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value - const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); - // plus error: - double errorStart, errorEnd; - if (!qIsNaN(it->errorPlus)) - { - errorStart = centerErrorAxisPixel+symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } - // minus error: - if (!qIsNaN(it->errorMinus)) - { - errorStart = centerErrorAxisPixel-symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } -} - -/*! \internal - - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key - coordinates relative to their data point key, this method checks all outer error bars whether - they truly don't reach into the visible portion of the axis rect, by calling \ref - errorBarVisible. On the other hand error bars with type \ref etValueError that are associated - with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype - "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of - error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref - QCPPlottableInterface1D::findEnd). - - If the plottable's sort key is not equal to the main key, this method returns the full data - range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a - point-by-point basis in the \ref draw method. -*/ -void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable || rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) - { - // if the sort key isn't the main key, it's not possible to find a contiguous range of visible - // data points, so this method then only applies the range restriction and otherwise returns - // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing - QCPDataRange dataRange(0, mDataContainer->size()); - dataRange = dataRange.bounded(rangeRestriction); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); - return; - } - - // get visible data range via interface from data plottable, and then restrict to available error data points: - const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); - int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); - int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); - int i = beginIndex; - while (i > 0 && i < n && i > rangeRestriction.begin()) - { - if (errorBarVisible(i)) - beginIndex = i; - --i; - } - i = endIndex; - while (i >= 0 && i < n && i < rangeRestriction.end()) - { - if (errorBarVisible(i)) - endIndex = i+1; - ++i; - } - QCPDataRange dataRange(beginIndex, endIndex); - dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); -} - -/*! \internal - - Calculates the minimum distance in pixels the error bars' representation has from the given \a - pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. -*/ -double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (!mDataPlottable || mDataContainer->isEmpty()) - return -1.0; - if (!mKeyAxis || !mValueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return -1.0; - } - - QCPErrorBarsDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); - - // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - getErrorBarLines(it, backbones, whiskers); - for (int i=0; i &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! \internal - - Returns whether the error bar at the specified \a index is visible within the current key axis - range. - - This method assumes for performance reasons without checking that the key axis, the value axis, - and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid - bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. -*/ -bool QCPErrorBars::errorBarVisible(int index) const -{ - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - if (qIsNaN(centerKeyPixel)) - return false; - - double keyMin, keyMax; - if (mErrorType == etKeyError) - { - const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); - const double errorPlus = mDataContainer->at(index).errorPlus; - const double errorMinus = mDataContainer->at(index).errorMinus; - keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); - keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); - } else // mErrorType == etValueError - { - keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - } - return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); -} - -/*! \internal - - Returns whether \a line intersects (or is contained in) \a pixelRect. - - \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for - error bar lines. -*/ -bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const -{ - if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) - return false; - else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) - return false; - else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) - return false; - else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) - return false; - else - return true; -} -/* end of 'src/plottables/plottable-errorbar.cpp' */ - - -/* including file 'src/items/item-straightline.cpp', size 7592 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemStraightLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemStraightLine - \brief A straight line that spans infinitely in both directions - - \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a point1 and \a point2, which define the straight line. -*/ - -/*! - Creates a straight line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition(QLatin1String("point1"))), - point2(createPosition(QLatin1String("point2"))) -{ - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemStraightLine::~QCPItemStraightLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemStraightLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); -} - -/* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) -{ - QCPVector2D start(point1->pixelPosition()); - QCPVector2D end(point2->pixelPosition()); - // get visible segment of straight line inside clipRect: - double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - } -} - -/*! \internal - - Returns the section of the straight line defined by \a base and direction vector \a - vec, that is visible in the specified \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const -{ - double bx, by; - double gamma; - QLineF result; - if (vec.x() == 0 && vec.y() == 0) - return result; - if (qFuzzyIsNull(vec.x())) // line is vertical - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed - { - QList pointVectors; - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - // check right of rect: - bx = rect.right(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemStraightLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-straightline.cpp' */ - - -/* including file 'src/items/item-line.cpp', size 8498 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemLine - \brief A line from one point to another - - \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a start and \a end, which define the end points of the line. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. -*/ - -/*! - Creates a line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemLine::~QCPItemLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemLine::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemLine::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); -} - -/* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) -{ - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if (qFuzzyIsNull((startVec-endVec).lengthSquared())) - return; - // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); - } -} - -/*! \internal - - Returns the section of the line defined by \a start and \a end, that is visible in the specified - \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const -{ - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - - QCPVector2D base = start; - QCPVector2D vec = end-start; - double bx, by; - double gamma, mu; - QLineF result; - QList pointVectors; - - if (!qFuzzyIsNull(vec.y())) // line is not horizontal - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - } - if (!qFuzzyIsNull(vec.x())) // line is not vertical - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - // check right of rect: - bx = rect.right(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-line.cpp' */ - - -/* including file 'src/items/item-curve.cpp', size 7159 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemCurve - \brief A curved line from one point to another - - \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." - - It has four positions, \a start and \a end, which define the end points of the line, and two - control points which define the direction the line exits from the start and the direction from - which it approaches the end: \a startDir and \a endDir. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an - arrow. - - Often it is desirable for the control points to stay at fixed relative positions to the start/end - point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, - and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. -*/ - -/*! - Creates a curve item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - startDir(createPosition(QLatin1String("startDir"))), - endDir(createPosition(QLatin1String("endDir"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemCurve::~QCPItemCurve() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemCurve::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemCurve::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemCurve::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemCurve::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF startVec(start->pixelPosition()); - QPointF startDirVec(startDir->pixelPosition()); - QPointF endDirVec(endDir->pixelPosition()); - QPointF endVec(end->pixelPosition()); - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - QPolygonF polygon = cubicPath.toSubpathPolygons().first(); - QCPVector2D p(pos); - double minDistSqr = std::numeric_limits::max(); - for (int i=1; ipixelPosition()); - QCPVector2D startDirVec(startDir->pixelPosition()); - QCPVector2D endDirVec(endDir->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if ((endVec-startVec).length() > 1e10) // too large curves cause crash - return; - - QPainterPath cubicPath(startVec.toPointF()); - cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); - - // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) - { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemCurve::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-curve.cpp' */ - - -/* including file 'src/items/item-rect.cpp', size 6479 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemRect - \brief A rectangle - - \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemRect::~QCPItemRect() -{ -} - -/*! - Sets the pen that will be used to draw the line of the rectangle - - \see setSelectedPen, setBrush -*/ -void QCPItemRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the rectangle when selected - - \see setPen, setSelected -*/ -void QCPItemRect::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemRect::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); -} - -/* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF rect = QRectF(p1, p2).normalized(); - double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemRect::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemRect::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-rect.cpp' */ - - -/* including file 'src/items/item-text.cpp', size 13338 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemText -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemText - \brief A text label - - \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." - - Its position is defined by the member \a position and the setting of \ref setPositionAlignment. - The latter controls which part of the text rect shall be aligned with \a position. - - The text alignment itself (i.e. left, center, right) can be controlled with \ref - setTextAlignment. - - The text may be rotated around the \a position point with \ref setRotation. -*/ - -/*! - Creates a text item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mText(QLatin1String("text")), - mPositionAlignment(Qt::AlignCenter), - mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), - mRotation(0) -{ - position->setCoords(0, 0); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); -} - -QCPItemText::~QCPItemText() -{ -} - -/*! - Sets the color of the text. -*/ -void QCPItemText::setColor(const QColor &color) -{ - mColor = color; -} - -/*! - Sets the color of the text that will be used when the item is selected. -*/ -void QCPItemText::setSelectedColor(const QColor &color) -{ - mSelectedColor = color; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text. To disable the - border, set \a pen to Qt::NoPen. - - \see setSelectedPen, setBrush, setPadding -*/ -void QCPItemText::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text, when the item is - selected. To disable the border, set \a pen to Qt::NoPen. - - \see setPen -*/ -void QCPItemText::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used do fill the background of the text. To disable the - background, set \a brush to Qt::NoBrush. - - \see setSelectedBrush, setPen, setPadding -*/ -void QCPItemText::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the - background, set \a brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemText::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the font of the text. - - \see setSelectedFont, setColor -*/ -void QCPItemText::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the font of the text that will be used when the item is selected. - - \see setFont -*/ -void QCPItemText::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the text that will be displayed. Multi-line texts are supported by inserting a line break - character, e.g. '\n'. - - \see setFont, setColor, setTextAlignment -*/ -void QCPItemText::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets which point of the text rect shall be aligned with \a position. - - Examples: - \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such - that the top of the text rect will be horizontally centered on \a position. - \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the - bottom left corner of the text rect. - - If you want to control the alignment of (multi-lined) text within the text rect, use \ref - setTextAlignment. -*/ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) -{ - mPositionAlignment = alignment; -} - -/*! - Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). -*/ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) -{ - mTextAlignment = alignment; -} - -/*! - Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated - around \a position. -*/ -void QCPItemText::setRotation(double degrees) -{ - mRotation = degrees; -} - -/*! - Sets the distance between the border of the text rectangle and the text. The appearance (and - visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. -*/ -void QCPItemText::setPadding(const QMargins &padding) -{ - mPadding = padding; -} - -/* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - // The rect may be rotated, so we transform the actual clicked pos to the rotated - // coordinate system, so we can use the normal rectDistance function for non-rotated rects: - QPointF positionPixels(position->pixelPosition()); - QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); - - return rectDistance(textBoxRect, rotatedPos, true); -} - -/* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) -{ - QPointF pos(position->pixelPosition()); - QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); - double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) - { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); - } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPosition(int anchorId) const -{ - // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPosition()); - QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) - { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the point that must be given to the QPainter::drawText function (which expects the top - left point of the text rect), according to the position \a pos, the text bounding box \a rect and - the requested \a positionAlignment. - - For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point - will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally - drawn at that point, the lower left corner of the resulting text rect is at \a pos. -*/ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const -{ - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) - return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) - result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) - result.ry() -= rect.height(); - return result; -} - -/*! \internal - - Returns the font that should be used for drawing text. Returns mFont when the item is not selected - and mSelectedFont when it is. -*/ -QFont QCPItemText::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the color that should be used for drawing text. Returns mColor when the item is not - selected and mSelectedColor when it is. -*/ -QColor QCPItemText::mainColor() const -{ - return mSelected ? mSelectedColor : mColor; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemText::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemText::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-text.cpp' */ - - -/* including file 'src/items/item-ellipse.cpp', size 7863 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemEllipse -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemEllipse - \brief An ellipse - - \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. -*/ - -/*! - Creates an ellipse item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), - left(createAnchor(QLatin1String("left"), aiLeft)), - center(createAnchor(QLatin1String("center"), aiCenter)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemEllipse::~QCPItemEllipse() -{ -} - -/*! - Sets the pen that will be used to draw the line of the ellipse - - \see setSelectedPen, setBrush -*/ -void QCPItemEllipse::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the ellipse when selected - - \see setPen, setSelected -*/ -void QCPItemEllipse::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemEllipse::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - - // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - double result = qAbs(c-1)*qSqrt(x*x+y*y); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); -#ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big - { -#endif - painter->drawEllipse(ellipseRect); -#ifdef __EXCEPTIONS - } catch (...) - { - qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); - } -#endif - } -} - -/* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemEllipse::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemEllipse::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-ellipse.cpp' */ - - -/* including file 'src/items/item-pixmap.cpp', size 10615 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPixmap - \brief An arbitrary pixmap - - \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will - be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to - fit the rectangle or be drawn aligned to the topLeft position. - - If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown - on the right side of the example image), the pixmap will be flipped in the respective - orientations. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mScaled(false), - mScaledPixmapInvalidated(true), - mAspectRatioMode(Qt::KeepAspectRatio), - mTransformationMode(Qt::SmoothTransformation) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); -} - -QCPItemPixmap::~QCPItemPixmap() -{ -} - -/*! - Sets the pixmap that will be displayed. -*/ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) -{ - mPixmap = pixmap; - mScaledPixmapInvalidated = true; - if (mPixmap.isNull()) - qDebug() << Q_FUNC_INFO << "pixmap is null"; -} - -/*! - Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a - bottomRight positions. -*/ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) -{ - mScaled = scaled; - mAspectRatioMode = aspectRatioMode; - mTransformationMode = transformationMode; - mScaledPixmapInvalidated = true; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap. - - \see setSelectedPen, setBrush -*/ -void QCPItemPixmap::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap when selected - - \see setPen, setSelected -*/ -void QCPItemPixmap::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return rectDistance(getFinalRect(), pos, true); -} - -/* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) -{ - bool flipHorz = false; - bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); - double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) - { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); - QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) - { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const -{ - bool flipHorz; - bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); - // we actually want denormal rects (negative width/height) here, so restore - // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The - parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped - horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a - bottomRight.) - - This function only creates the scaled pixmap when the buffered pixmap has a different size than - the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does - not cause expensive rescaling every time. - - If scaling is disabled, sets mScaledPixmap to a null QPixmap. -*/ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) -{ - if (mPixmap.isNull()) - return; - - if (mScaled) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - double devicePixelRatio = mPixmap.devicePixelRatio(); -#else - double devicePixelRatio = 1.0; -#endif - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) - { - mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mScaledPixmap.setDevicePixelRatio(devicePixelRatio); -#endif - } - } else if (!mScaledPixmap.isNull()) - mScaledPixmap = QPixmap(); - mScaledPixmapInvalidated = false; -} - -/*! \internal - - Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions - and scaling settings. - - The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn - flipped horizontally or vertically in the returned rect. (The returned rect itself is always - normalized, i.e. the top left corner of the rect is actually further to the top/left than the - bottom right corner). This is the case when the item position \a topLeft is further to the - bottom/right than \a bottomRight. - - If scaling is disabled, returns a rect with size of the original pixmap and the top left corner - aligned with the item position \a topLeft. The position \a bottomRight is ignored. -*/ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const -{ - QRect result; - bool flipHorz = false; - bool flipVert = false; - QPoint p1 = topLeft->pixelPosition().toPoint(); - QPoint p2 = bottomRight->pixelPosition().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) - { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); - QPoint topLeft = p1; - if (newSize.width() < 0) - { - flipHorz = true; - newSize.rwidth() *= -1; - topLeft.setX(p2.x()); - } - if (newSize.height() < 0) - { - flipVert = true; - newSize.rheight() *= -1; - topLeft.setY(p2.y()); - } - QSize scaledSize = mPixmap.size(); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - scaledSize /= mPixmap.devicePixelRatio(); - scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); -#else - scaledSize.scale(newSize, mAspectRatioMode); -#endif - result = QRect(topLeft, scaledSize); - } else - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); -#else - result = QRect(p1, mPixmap.size()); -#endif - } - if (flippedHorz) - *flippedHorz = flipHorz; - if (flippedVert) - *flippedVert = flipVert; - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemPixmap::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-pixmap.cpp' */ - - -/* including file 'src/items/item-tracer.cpp', size 14624 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemTracer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemTracer - \brief Item that sticks to QCPGraph data points - - \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." - - The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt - the coordinate axes of the graph and update its \a position to be on the graph's data. This means - the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a - QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a - position will have no effect because they will be overriden in the next redraw (this is when the - coordinate update happens). - - If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will - stay at the corresponding end of the graph. - - With \ref setInterpolating you may specify whether the tracer may only stay exactly on data - points or whether it interpolates data points linearly, if given a key that lies between two data - points of the graph. - - The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer - have no own visual appearance (set the style to \ref tsNone), and just connect other item - positions to the tracer \a position (used as an anchor) via \ref - QCPItemPosition::setParentAnchor. - - \note The tracer position is only automatically updated upon redraws. So when the data of the - graph changes and immediately afterwards (without a redraw) the position coordinates of the - tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref - updatePosition must be called manually, prior to reading the tracer coordinates. -*/ - -/*! - Creates a tracer item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - mSize(6), - mStyle(tsCrosshair), - mGraph(0), - mGraphKey(0), - mInterpolating(false) -{ - position->setCoords(0, 0); - - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemTracer::~QCPItemTracer() -{ -} - -/*! - Sets the pen that will be used to draw the line of the tracer - - \see setSelectedPen, setBrush -*/ -void QCPItemTracer::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the tracer when selected - - \see setPen, setSelected -*/ -void QCPItemTracer::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer - - \see setSelectedBrush, setPen -*/ -void QCPItemTracer::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer, when selected. - - \see setBrush, setSelected -*/ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare - does, \ref tsCrosshair does not). -*/ -void QCPItemTracer::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the style/visual appearance of the tracer. - - If you only want to use the tracer \a position as an anchor for other items, set \a style to - \ref tsNone. -*/ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) -{ - mStyle = style; -} - -/*! - Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type - QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. - - To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed - freely like any other item position. This is the state the tracer will assume when its graph gets - deleted while still attached to it. - - \see setGraphKey -*/ -void QCPItemTracer::setGraph(QCPGraph *graph) -{ - if (graph) - { - if (graph->parentPlot() == mParentPlot) - { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); - mGraph = graph; - updatePosition(); - } else - qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else - { - mGraph = 0; - } -} - -/*! - Sets the key of the graph's data point the tracer will be positioned at. This is the only free - coordinate of a tracer when attached to a graph. - - Depending on \ref setInterpolating, the tracer will be either positioned on the data point - closest to \a key, or will stay exactly at \a key and interpolate the value linearly. - - \see setGraph, setInterpolating -*/ -void QCPItemTracer::setGraphKey(double key) -{ - mGraphKey = key; -} - -/*! - Sets whether the value of the graph's data points shall be interpolated, when positioning the - tracer. - - If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on - the data point of the graph which is closest to the key, but which is not necessarily exactly - there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and - the appropriate value will be interpolated from the graph's data points linearly. - - \see setGraph, setGraphKey -*/ -void QCPItemTracer::setInterpolating(bool enabled) -{ - mInterpolating = enabled; -} - -/* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return -1; - case tsPlus: - { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), - QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), - QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - // distance to border: - double centerDist = QCPVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; - } - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); - } - break; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) -{ - updatePosition(); - if (mStyle == tsNone) - return; - - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return; - case tsPlus: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; - } - } -} - -/*! - If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a - position to reside on the graph data, depending on the configured key (\ref setGraphKey). - - It is called automatically on every redraw and normally doesn't need to be called manually. One - exception is when you want to read the tracer coordinates via \a position and are not sure that - the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. - In that situation, call this function before accessing \a position, to make sure you don't get - out-of-date coordinates. - - If there is no graph set on this tracer, this function does nothing. -*/ -void QCPItemTracer::updatePosition() -{ - if (mGraph) - { - if (mParentPlot->hasPlottable(mGraph)) - { - if (mGraph->data()->size() > 1) - { - QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); - QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey <= first->key) - position->setCoords(first->key, first->value); - else if (mGraphKey >= last->key) - position->setCoords(last->key, last->value); - else - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); - if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators - { - QCPGraphDataContainer::const_iterator prevIt = it; - ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before - if (mInterpolating) - { - // interpolate between iterators around mGraphKey: - double slope = 0; - if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) - slope = (it->value-prevIt->value)/(it->key-prevIt->key); - position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); - } else - { - // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt->key+it->key)*0.5) - position->setCoords(prevIt->key, prevIt->value); - else - position->setCoords(it->key, it->value); - } - } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) - position->setCoords(it->key, it->value); - } - } else if (mGraph->data()->size() == 1) - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it->key, it->value); - } else - qDebug() << Q_FUNC_INFO << "graph has no data"; - } else - qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemTracer::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemTracer::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-tracer.cpp' */ - - -/* including file 'src/items/item-bracket.cpp', size 10687 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemBracket - \brief A bracket for referencing/highlighting certain parts in the plot. - - \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a left and \a right, which define the span of the bracket. If \a left is - actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the - example image. - - The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket - stretches away from the embraced span, can be controlled with \ref setLength. - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
- - It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine - or QCPItemCurve) or a text label (QCPItemText), to the bracket. -*/ - -/*! - Creates a bracket item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition(QLatin1String("left"))), - right(createPosition(QLatin1String("right"))), - center(createAnchor(QLatin1String("center"), aiCenter)), - mLength(8), - mStyle(bsCalligraphic) -{ - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemBracket::~QCPItemBracket() -{ -} - -/*! - Sets the pen that will be used to draw the bracket. - - Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the - stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use - \ref setLength, which has a similar effect. - - \see setSelectedPen -*/ -void QCPItemBracket::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the bracket when selected - - \see setPen, setSelected -*/ -void QCPItemBracket::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the \a length in pixels how far the bracket extends in the direction towards the embraced - span of the bracket (i.e. perpendicular to the left-right-direction) - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
-*/ -void QCPItemBracket::setLength(double length) -{ - mLength = length; -} - -/*! - Sets the style of the bracket, i.e. the shape/visual appearance. - - \see setPen -*/ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) -{ - mStyle = style; -} - -/* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QCPVector2D p(pos); - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return -1; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (mStyle) - { - case QCPItemBracket::bsSquare: - case QCPItemBracket::bsRound: - { - double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); - double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); - return qSqrt(qMin(qMin(a, b), c)); - } - case QCPItemBracket::bsCurly: - case QCPItemBracket::bsCalligraphic: - { - double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); - double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); - return qSqrt(qMin(qMin(a, b), qMin(c, d))); - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - QPolygon boundingPoly; - boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) - { - painter->setPen(mainPen()); - switch (mStyle) - { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); - path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return leftVec.toPointF(); - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (anchorId) - { - case aiCenter: - return centerVec.toPointF(); - } - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemBracket::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-bracket.cpp' */ - - From 0024c476119237295f2306c39b19c3d03d4a95c7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:41 -0400 Subject: [PATCH 0440/1324] Delete qcustomplot.h --- src/qt/qcustomplot.h | 6661 ------------------------------------------ 1 file changed, 6661 deletions(-) delete mode 100644 src/qt/qcustomplot.h diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h deleted file mode 100644 index 8b0ac04e..00000000 --- a/src/qt/qcustomplot.h +++ /dev/null @@ -1,6661 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#ifndef QCUSTOMPLOT_H -#define QCUSTOMPLOT_H - -#include - -// some Qt version/configuration dependent macros to include or exclude certain code paths: -#ifdef QCUSTOMPLOT_USE_OPENGL -# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# define QCP_OPENGL_PBUFFER -# else -# define QCP_OPENGL_FBO -# endif -# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) -# define QCP_OPENGL_OFFSCREENSURFACE -# endif -#endif - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) -# define QCP_DEVICEPIXELRATIO_SUPPORTED -# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) -# define QCP_DEVICEPIXELRATIO_FLOAT -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef QCP_OPENGL_FBO -# include -# include -# ifdef QCP_OPENGL_OFFSCREENSURFACE -# include -# else -# include -# endif -#endif -#ifdef QCP_OPENGL_PBUFFER -# include -#endif -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# include -# include -# include -# include -#else -# include -# include -# include -#endif - -class QCPPainter; -class QCustomPlot; -class QCPLayerable; -class QCPLayoutElement; -class QCPLayout; -class QCPAxis; -class QCPAxisRect; -class QCPAxisPainterPrivate; -class QCPAbstractPlottable; -class QCPGraph; -class QCPAbstractItem; -class QCPPlottableInterface1D; -class QCPLegend; -class QCPItemPosition; -class QCPLayer; -class QCPAbstractLegendItem; -class QCPSelectionRect; -class QCPColorMap; -class QCPColorScale; -class QCPBars; - -/* including file 'src/global.h', size 16225 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -// decl definitions for shared library compilation/usage: -#if defined(QCUSTOMPLOT_COMPILE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_EXPORT -#elif defined(QCUSTOMPLOT_USE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_IMPORT -#else -# define QCP_LIB_DECL -#endif - -// define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5) -#ifndef Q_DECL_OVERRIDE -# define Q_DECL_OVERRIDE -#endif - -/*! - The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot - library. - - It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. -*/ -#ifndef Q_MOC_RUN -namespace QCP { -#else -class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace - Q_GADGET - Q_ENUMS(ExportPen) - Q_ENUMS(ResolutionUnit) - Q_ENUMS(SignDomain) - Q_ENUMS(MarginSide) - Q_FLAGS(MarginSides) - Q_ENUMS(AntialiasedElement) - Q_FLAGS(AntialiasedElements) - Q_ENUMS(PlottingHint) - Q_FLAGS(PlottingHints) - Q_ENUMS(Interaction) - Q_FLAGS(Interactions) - Q_ENUMS(SelectionRectMode) - Q_ENUMS(SelectionType) -public: -#endif - -/*! - Defines the different units in which the image resolution can be specified in the export - functions. - - \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered -*/ -enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) - ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) - ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) - }; - -/*! - Defines how cosmetic pens (pens with numerical width 0) are handled during export. - - \see QCustomPlot::savePdf -*/ -enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting - ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) - }; - -/*! - Represents negative and positive sign domain, e.g. for passing to \ref - QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange. - - This is primarily needed when working with logarithmic axis scales, since only one of the sign - domains can be visible at a time. -*/ -enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero - ,sdBoth ///< Both sign domains, including zero, i.e. all numbers - ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero - }; - -/*! - Defines the sides of a rectangular entity to which margins can be applied. - - \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins -*/ -enum MarginSide { msLeft = 0x01 ///< 0x01 left margin - ,msRight = 0x02 ///< 0x02 right margin - ,msTop = 0x04 ///< 0x04 top margin - ,msBottom = 0x08 ///< 0x08 bottom margin - ,msAll = 0xFF ///< 0xFF all margins - ,msNone = 0x00 ///< 0x00 no margin - }; -Q_DECLARE_FLAGS(MarginSides, MarginSide) - -/*! - Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is - neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective - element how it is drawn. Typically it provides a \a setAntialiased function for this. - - \c AntialiasedElements is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements -*/ -enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks - ,aeGrid = 0x0002 ///< 0x0002 Grid lines - ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines - ,aeLegend = 0x0008 ///< 0x0008 Legend box - ,aeLegendItems = 0x0010 ///< 0x0010 Legend items - ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables - ,aeItems = 0x0040 ///< 0x0040 Main lines of items - ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) - ,aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) - ,aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen - ,aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories - ,aeAll = 0xFFFF ///< 0xFFFF All elements - ,aeNone = 0x0000 ///< 0x0000 No elements - }; -Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) - -/*! - Defines plotting hints that control various aspects of the quality and speed of plotting. - - \see QCustomPlot::setPlottingHints -*/ -enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set - ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment - ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. - ,phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. - ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). - ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. - }; -Q_DECLARE_FLAGS(PlottingHints, PlottingHint) - -/*! - Defines the mouse interactions possible with QCustomPlot. - - \c Interactions is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setInteractions -*/ -enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) - ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) - ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking - ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) - ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) - ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) - ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) - ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) - }; -Q_DECLARE_FLAGS(Interactions, Interaction) - -/*! - Defines the behaviour of the selection rect. - - \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect -*/ -enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging - ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. - ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) - ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. - }; - -/*! - Defines the different ways a plottable can be selected. These images show the effect of the - different selection types, when the indicated selection rect was dragged: - -
- - - - - - - - -
\image html selectiontype-none.png stNone\image html selectiontype-whole.png stWhole\image html selectiontype-singledata.png stSingleData\image html selectiontype-datarange.png stDataRange\image html selectiontype-multipledataranges.png stMultipleDataRanges
-
- - \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType -*/ -enum SelectionType { stNone ///< The plottable is not selectable - ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. - ,stSingleData ///< One individual data point can be selected at a time - ,stDataRange ///< Multiple contiguous data points (a data range) can be selected - ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected - }; - -/*! \internal - - Returns whether the specified \a value is considered an invalid data value for plottables (i.e. - is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the - compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. -*/ -inline bool isInvalidData(double value) -{ - return qIsNaN(value) || qIsInf(value); -} - -/*! \internal - \overload - - Checks two arguments instead of one. -*/ -inline bool isInvalidData(double value1, double value2) -{ - return isInvalidData(value1) || isInvalidData(value2); -} - -/*! \internal - - Sets the specified \a side of \a margins to \a value - - \see getMarginValue -*/ -inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) -{ - switch (side) - { - case QCP::msLeft: margins.setLeft(value); break; - case QCP::msRight: margins.setRight(value); break; - case QCP::msTop: margins.setTop(value); break; - case QCP::msBottom: margins.setBottom(value); break; - case QCP::msAll: margins = QMargins(value, value, value, value); break; - default: break; - } -} - -/*! \internal - - Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or - \ref QCP::msAll, returns 0. - - \see setMarginValue -*/ -inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return margins.left(); - case QCP::msRight: return margins.right(); - case QCP::msTop: return margins.top(); - case QCP::msBottom: return margins.bottom(); - default: break; - } - return 0; -} - - -extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace - -} // end of namespace QCP -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) -Q_DECLARE_METATYPE(QCP::ExportPen) -Q_DECLARE_METATYPE(QCP::ResolutionUnit) -Q_DECLARE_METATYPE(QCP::SignDomain) -Q_DECLARE_METATYPE(QCP::MarginSide) -Q_DECLARE_METATYPE(QCP::AntialiasedElement) -Q_DECLARE_METATYPE(QCP::PlottingHint) -Q_DECLARE_METATYPE(QCP::Interaction) -Q_DECLARE_METATYPE(QCP::SelectionRectMode) -Q_DECLARE_METATYPE(QCP::SelectionType) - -/* end of 'src/global.h' */ - - -/* including file 'src/vector2d.h', size 4928 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPVector2D -{ -public: - QCPVector2D(); - QCPVector2D(double x, double y); - QCPVector2D(const QPoint &point); - QCPVector2D(const QPointF &point); - - // getters: - double x() const { return mX; } - double y() const { return mY; } - double &rx() { return mX; } - double &ry() { return mY; } - - // setters: - void setX(double x) { mX = x; } - void setY(double y) { mY = y; } - - // non-virtual methods: - double length() const { return qSqrt(mX*mX+mY*mY); } - double lengthSquared() const { return mX*mX+mY*mY; } - QPoint toPoint() const { return QPoint(mX, mY); } - QPointF toPointF() const { return QPointF(mX, mY); } - - bool isNull() const { return qIsNull(mX) && qIsNull(mY); } - void normalize(); - QCPVector2D normalized() const; - QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); } - double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; } - double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const; - double distanceSquaredToLine(const QLineF &line) const; - double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const; - - QCPVector2D &operator*=(double factor); - QCPVector2D &operator/=(double divisor); - QCPVector2D &operator+=(const QCPVector2D &vector); - QCPVector2D &operator-=(const QCPVector2D &vector); - -private: - // property members: - double mX, mY; - - friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec); - friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor); - friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor); - friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec); -}; -Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE); - -inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); } -inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); } - -/*! \relates QCPVector2D - - Prints \a vec in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPVector2D &vec) -{ - d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; - return d.space(); -} - -/* end of 'src/vector2d.h' */ - - -/* including file 'src/painter.h', size 4035 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPPainter : public QPainter -{ - Q_GADGET -public: - /*! - Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, - depending on whether they are wanted on the respective output device. - */ - enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices - ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. - ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels - ,pmNonCosmetic = 0x04 ///< 0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.) - }; - Q_ENUMS(PainterMode) - Q_FLAGS(PainterModes) - Q_DECLARE_FLAGS(PainterModes, PainterMode) - - QCPPainter(); - explicit QCPPainter(QPaintDevice *device); - - // getters: - bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } - PainterModes modes() const { return mModes; } - - // setters: - void setAntialiasing(bool enabled); - void setMode(PainterMode mode, bool enabled=true); - void setModes(PainterModes modes); - - // methods hiding non-virtual base class functions (QPainter bug workarounds): - bool begin(QPaintDevice *device); - void setPen(const QPen &pen); - void setPen(const QColor &color); - void setPen(Qt::PenStyle penStyle); - void drawLine(const QLineF &line); - void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} - void save(); - void restore(); - - // non-virtual methods: - void makeNonCosmetic(); - -protected: - // property members: - PainterModes mModes; - bool mIsAntialiasing; - - // non-property members: - QStack mAntialiasingStack; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) -Q_DECLARE_METATYPE(QCPPainter::PainterMode) - -/* end of 'src/painter.h' */ - - -/* including file 'src/paintbuffer.h', size 4958 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAbstractPaintBuffer -{ -public: - explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio); - virtual ~QCPAbstractPaintBuffer(); - - // getters: - QSize size() const { return mSize; } - bool invalidated() const { return mInvalidated; } - double devicePixelRatio() const { return mDevicePixelRatio; } - - // setters: - void setSize(const QSize &size); - void setInvalidated(bool invalidated=true); - void setDevicePixelRatio(double ratio); - - // introduced virtual methods: - virtual QCPPainter *startPainting() = 0; - virtual void donePainting() {} - virtual void draw(QCPPainter *painter) const = 0; - virtual void clear(const QColor &color) = 0; - -protected: - // property members: - QSize mSize; - double mDevicePixelRatio; - - // non-property members: - bool mInvalidated; - - // introduced virtual methods: - virtual void reallocateBuffer() = 0; -}; - - -class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio); - virtual ~QCPPaintBufferPixmap(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QPixmap mBuffer; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; - - -#ifdef QCP_OPENGL_PBUFFER -class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples); - virtual ~QCPPaintBufferGlPbuffer(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QGLPixelBuffer *mGlPBuffer; - int mMultisamples; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice); - virtual ~QCPPaintBufferGlFbo(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void donePainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QWeakPointer mGlContext; - QWeakPointer mGlPaintDevice; - QOpenGLFramebufferObject *mGlFrameBuffer; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; -#endif // QCP_OPENGL_FBO - -/* end of 'src/paintbuffer.h' */ - - -/* including file 'src/layer.h', size 6885 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPLayer : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(int index READ index) - Q_PROPERTY(QList children READ children) - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(LayerMode mode READ mode WRITE setMode) - /// \endcond -public: - - /*! - Defines the different rendering modes of a layer. Depending on the mode, certain layers can be - replotted individually, without the need to replot (possibly complex) layerables on other - layers. - - \see setMode - */ - enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. - ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). - }; - Q_ENUMS(LayerMode) - - QCPLayer(QCustomPlot* parentPlot, const QString &layerName); - virtual ~QCPLayer(); - - // getters: - QCustomPlot *parentPlot() const { return mParentPlot; } - QString name() const { return mName; } - int index() const { return mIndex; } - QList children() const { return mChildren; } - bool visible() const { return mVisible; } - LayerMode mode() const { return mMode; } - - // setters: - void setVisible(bool visible); - void setMode(LayerMode mode); - - // non-virtual methods: - void replot(); - -protected: - // property members: - QCustomPlot *mParentPlot; - QString mName; - int mIndex; - QList mChildren; - bool mVisible; - LayerMode mMode; - - // non-property members: - QWeakPointer mPaintBuffer; - - // non-virtual methods: - void draw(QCPPainter *painter); - void drawToPaintBuffer(); - void addChild(QCPLayerable *layerable, bool prepend); - void removeChild(QCPLayerable *layerable); - -private: - Q_DISABLE_COPY(QCPLayer) - - friend class QCustomPlot; - friend class QCPLayerable; -}; -Q_DECLARE_METATYPE(QCPLayer::LayerMode) - -class QCP_LIB_DECL QCPLayerable : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) - Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) - Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) - /// \endcond -public: - QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0); - virtual ~QCPLayerable(); - - // getters: - bool visible() const { return mVisible; } - QCustomPlot *parentPlot() const { return mParentPlot; } - QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } - QCPLayer *layer() const { return mLayer; } - bool antialiased() const { return mAntialiased; } - - // setters: - void setVisible(bool on); - Q_SLOT bool setLayer(QCPLayer *layer); - bool setLayer(const QString &layerName); - void setAntialiased(bool enabled); - - // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-property methods: - bool realVisibility() const; - -Q_SIGNALS: - void layerChanged(QCPLayer *newLayer); - -protected: - // property members: - bool mVisible; - QCustomPlot *mParentPlot; - QPointer mParentLayerable; - QCPLayer *mLayer; - bool mAntialiased; - - // introduced virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot); - virtual QCP::Interaction selectionCategory() const; - virtual QRect clipRect() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; - virtual void draw(QCPPainter *painter) = 0; - // selection events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - // low-level mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details); - virtual void wheelEvent(QWheelEvent *event); - - // non-property methods: - void initializeParentPlot(QCustomPlot *parentPlot); - void setParentLayerable(QCPLayerable* parentLayerable); - bool moveToLayer(QCPLayer *layer, bool prepend); - void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; - -private: - Q_DISABLE_COPY(QCPLayerable) - - friend class QCustomPlot; - friend class QCPLayer; - friend class QCPAxisRect; -}; - -/* end of 'src/layer.h' */ - - -/* including file 'src/axis/range.h', size 5280 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPRange -{ -public: - double lower, upper; - - QCPRange(); - QCPRange(double lower, double upper); - - bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; } - bool operator!=(const QCPRange& other) const { return !(*this == other); } - - QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } - QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } - QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } - QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } - friend inline const QCPRange operator+(const QCPRange&, double); - friend inline const QCPRange operator+(double, const QCPRange&); - friend inline const QCPRange operator-(const QCPRange& range, double value); - friend inline const QCPRange operator*(const QCPRange& range, double value); - friend inline const QCPRange operator*(double value, const QCPRange& range); - friend inline const QCPRange operator/(const QCPRange& range, double value); - - double size() const { return upper-lower; } - double center() const { return (upper+lower)*0.5; } - void normalize() { if (lower > upper) qSwap(lower, upper); } - void expand(const QCPRange &otherRange); - void expand(double includeCoord); - QCPRange expanded(const QCPRange &otherRange) const; - QCPRange expanded(double includeCoord) const; - QCPRange bounded(double lowerBound, double upperBound) const; - QCPRange sanitizedForLogScale() const; - QCPRange sanitizedForLinScale() const; - bool contains(double value) const { return value >= lower && value <= upper; } - - static bool validRange(double lower, double upper); - static bool validRange(const QCPRange &range); - static const double minRange; - static const double maxRange; - -}; -Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); - -/*! \relates QCPRange - - Prints \a range in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPRange &range) -{ - d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; - return d.space(); -} - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(const QCPRange& range, double value) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(double value, const QCPRange& range) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Subtracts \a value from both boundaries of the range. -*/ -inline const QCPRange operator-(const QCPRange& range, double value) -{ - QCPRange result(range); - result -= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(const QCPRange& range, double value) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(double value, const QCPRange& range) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Divides both boundaries of the range by \a value. -*/ -inline const QCPRange operator/(const QCPRange& range, double value) -{ - QCPRange result(range); - result /= value; - return result; -} - -/* end of 'src/axis/range.h' */ - - -/* including file 'src/selection.h', size 8579 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPDataRange -{ -public: - QCPDataRange(); - QCPDataRange(int begin, int end); - - bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; } - bool operator!=(const QCPDataRange& other) const { return !(*this == other); } - - // getters: - int begin() const { return mBegin; } - int end() const { return mEnd; } - int size() const { return mEnd-mBegin; } - int length() const { return size(); } - - // setters: - void setBegin(int begin) { mBegin = begin; } - void setEnd(int end) { mEnd = end; } - - // non-property methods: - bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); } - bool isEmpty() const { return length() == 0; } - QCPDataRange bounded(const QCPDataRange &other) const; - QCPDataRange expanded(const QCPDataRange &other) const; - QCPDataRange intersection(const QCPDataRange &other) const; - QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); } - bool intersects(const QCPDataRange &other) const; - bool contains(const QCPDataRange &other) const; - -private: - // property members: - int mBegin, mEnd; - -}; -Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE); - - -class QCP_LIB_DECL QCPDataSelection -{ -public: - explicit QCPDataSelection(); - explicit QCPDataSelection(const QCPDataRange &range); - - bool operator==(const QCPDataSelection& other) const; - bool operator!=(const QCPDataSelection& other) const { return !(*this == other); } - QCPDataSelection &operator+=(const QCPDataSelection& other); - QCPDataSelection &operator+=(const QCPDataRange& other); - QCPDataSelection &operator-=(const QCPDataSelection& other); - QCPDataSelection &operator-=(const QCPDataRange& other); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b); - - // getters: - int dataRangeCount() const { return mDataRanges.size(); } - int dataPointCount() const; - QCPDataRange dataRange(int index=0) const; - QList dataRanges() const { return mDataRanges; } - QCPDataRange span() const; - - // non-property methods: - void addDataRange(const QCPDataRange &dataRange, bool simplify=true); - void clear(); - bool isEmpty() const { return mDataRanges.isEmpty(); } - void simplify(); - void enforceType(QCP::SelectionType type); - bool contains(const QCPDataSelection &other) const; - QCPDataSelection intersection(const QCPDataRange &other) const; - QCPDataSelection intersection(const QCPDataSelection &other) const; - QCPDataSelection inverse(const QCPDataRange &outerRange) const; - -private: - // property members: - QList mDataRanges; - - inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); } -}; -Q_DECLARE_METATYPE(QCPDataSelection) - - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! \relates QCPDataRange - - Prints \a dataRange in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) -{ - d.nospace() << "[" << dataRange.begin() << ".." << dataRange.end()-1 << "]"; - return d.space(); -} - -/*! \relates QCPDataSelection - - Prints \a selection in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPDataSelection &selection) -{ - d.nospace() << "QCPDataSelection("; - for (int i=0; i elements(QCP::MarginSide side) const { return mChildren.value(side); } - bool isEmpty() const; - void clear(); - -protected: - // non-property members: - QCustomPlot *mParentPlot; - QHash > mChildren; - - // introduced virtual methods: - virtual int commonMargin(QCP::MarginSide side) const; - - // non-virtual methods: - void addChild(QCP::MarginSide side, QCPLayoutElement *element); - void removeChild(QCP::MarginSide side, QCPLayoutElement *element); - -private: - Q_DISABLE_COPY(QCPMarginGroup) - - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLayout* layout READ layout) - Q_PROPERTY(QRect rect READ rect) - Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) - Q_PROPERTY(QMargins margins READ margins WRITE setMargins) - Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) - Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) - Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) - Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect) - /// \endcond -public: - /*! - Defines the phases of the update process, that happens just before a replot. At each phase, - \ref update is called with the according UpdatePhase value. - */ - enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout - ,upMargins ///< Phase in which the margins are calculated and set - ,upLayout ///< Final phase in which the layout system places the rects of the elements - }; - Q_ENUMS(UpdatePhase) - - /*! - Defines to which rect of a layout element the size constraints that can be set via \ref - setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the - margins (e.g. in the case of a QCPAxisRect the axis labels), whereas the inner rect (\ref rect) - does not. - - \see setSizeConstraintRect - */ - enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect - , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins - }; - Q_ENUMS(SizeConstraintRect) - - explicit QCPLayoutElement(QCustomPlot *parentPlot=0); - virtual ~QCPLayoutElement(); - - // getters: - QCPLayout *layout() const { return mParentLayout; } - QRect rect() const { return mRect; } - QRect outerRect() const { return mOuterRect; } - QMargins margins() const { return mMargins; } - QMargins minimumMargins() const { return mMinimumMargins; } - QCP::MarginSides autoMargins() const { return mAutoMargins; } - QSize minimumSize() const { return mMinimumSize; } - QSize maximumSize() const { return mMaximumSize; } - SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; } - QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } - QHash marginGroups() const { return mMarginGroups; } - - // setters: - void setOuterRect(const QRect &rect); - void setMargins(const QMargins &margins); - void setMinimumMargins(const QMargins &margins); - void setAutoMargins(QCP::MarginSides sides); - void setMinimumSize(const QSize &size); - void setMinimumSize(int width, int height); - void setMaximumSize(const QSize &size); - void setMaximumSize(int width, int height); - void setSizeConstraintRect(SizeConstraintRect constraintRect); - void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); - - // introduced virtual methods: - virtual void update(UpdatePhase phase); - virtual QSize minimumOuterSizeHint() const; - virtual QSize maximumOuterSizeHint() const; - virtual QList elements(bool recursive) const; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - -protected: - // property members: - QCPLayout *mParentLayout; - QSize mMinimumSize, mMaximumSize; - SizeConstraintRect mSizeConstraintRect; - QRect mRect, mOuterRect; - QMargins mMargins, mMinimumMargins; - QCP::MarginSides mAutoMargins; - QHash mMarginGroups; - - // introduced virtual methods: - virtual int calculateAutoMargin(QCP::MarginSide side); - virtual void layoutChanged(); - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPLayoutElement) - - friend class QCustomPlot; - friend class QCPLayout; - friend class QCPMarginGroup; -}; -Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase) - - -class QCP_LIB_DECL QCPLayout : public QCPLayoutElement -{ - Q_OBJECT -public: - explicit QCPLayout(); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual int elementCount() const = 0; - virtual QCPLayoutElement* elementAt(int index) const = 0; - virtual QCPLayoutElement* takeAt(int index) = 0; - virtual bool take(QCPLayoutElement* element) = 0; - virtual void simplify(); - - // non-virtual methods: - bool removeAt(int index); - bool remove(QCPLayoutElement* element); - void clear(); - -protected: - // introduced virtual methods: - virtual void updateLayout(); - - // non-virtual methods: - void sizeConstraintsChanged() const; - void adoptElement(QCPLayoutElement *el); - void releaseElement(QCPLayoutElement *el); - QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const; - static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el); - static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el); - -private: - Q_DISABLE_COPY(QCPLayout) - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(int rowCount READ rowCount) - Q_PROPERTY(int columnCount READ columnCount) - Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) - Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder) - Q_PROPERTY(int wrap READ wrap WRITE setWrap) - /// \endcond -public: - - /*! - Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*). - The column/row at which wrapping into the next row/column occurs can be specified with \ref - setWrap. - - \see setFillOrder - */ - enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. - ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. - }; - Q_ENUMS(FillOrder) - - explicit QCPLayoutGrid(); - virtual ~QCPLayoutGrid(); - - // getters: - int rowCount() const { return mElements.size(); } - int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } - QList columnStretchFactors() const { return mColumnStretchFactors; } - QList rowStretchFactors() const { return mRowStretchFactors; } - int columnSpacing() const { return mColumnSpacing; } - int rowSpacing() const { return mRowSpacing; } - int wrap() const { return mWrap; } - FillOrder fillOrder() const { return mFillOrder; } - - // setters: - void setColumnStretchFactor(int column, double factor); - void setColumnStretchFactors(const QList &factors); - void setRowStretchFactor(int row, double factor); - void setRowStretchFactors(const QList &factors); - void setColumnSpacing(int pixels); - void setRowSpacing(int pixels); - void setWrap(int count); - void setFillOrder(FillOrder order, bool rearrange=true); - - // reimplemented virtual methods: - virtual void updateLayout() Q_DECL_OVERRIDE; - virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); } - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - virtual void simplify() Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; - - // non-virtual methods: - QCPLayoutElement *element(int row, int column) const; - bool addElement(int row, int column, QCPLayoutElement *element); - bool addElement(QCPLayoutElement *element); - bool hasElement(int row, int column); - void expandTo(int newRowCount, int newColumnCount); - void insertRow(int newIndex); - void insertColumn(int newIndex); - int rowColToIndex(int row, int column) const; - void indexToRowCol(int index, int &row, int &column) const; - -protected: - // property members: - QList > mElements; - QList mColumnStretchFactors; - QList mRowStretchFactors; - int mColumnSpacing, mRowSpacing; - int mWrap; - FillOrder mFillOrder; - - // non-virtual methods: - void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; - void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; - -private: - Q_DISABLE_COPY(QCPLayoutGrid) -}; -Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) - - -class QCP_LIB_DECL QCPLayoutInset : public QCPLayout -{ - Q_OBJECT -public: - /*! - Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. - */ - enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect - ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment - }; - Q_ENUMS(InsetPlacement) - - explicit QCPLayoutInset(); - virtual ~QCPLayoutInset(); - - // getters: - InsetPlacement insetPlacement(int index) const; - Qt::Alignment insetAlignment(int index) const; - QRectF insetRect(int index) const; - - // setters: - void setInsetPlacement(int index, InsetPlacement placement); - void setInsetAlignment(int index, Qt::Alignment alignment); - void setInsetRect(int index, const QRectF &rect); - - // reimplemented virtual methods: - virtual void updateLayout() Q_DECL_OVERRIDE; - virtual int elementCount() const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; - virtual void simplify() Q_DECL_OVERRIDE {} - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void addElement(QCPLayoutElement *element, Qt::Alignment alignment); - void addElement(QCPLayoutElement *element, const QRectF &rect); - -protected: - // property members: - QList mElements; - QList mInsetPlacement; - QList mInsetAlignment; - QList mInsetRect; - -private: - Q_DISABLE_COPY(QCPLayoutInset) -}; -Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement) - -/* end of 'src/layout.h' */ - - -/* including file 'src/lineending.h', size 4426 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPLineEnding -{ - Q_GADGET -public: - /*! - Defines the type of ending decoration for line-like items, e.g. an arrow. - - \image html QCPLineEnding.png - - The width and length of these decorations can be controlled with the functions \ref setWidth - and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only - support a width, the length property is ignored. - - \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding - */ - enum EndingStyle { esNone ///< No ending decoration - ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) - ,esSpikeArrow ///< A filled arrow head with an indented back - ,esLineArrow ///< A non-filled arrow head with open back - ,esDisc ///< A filled circle - ,esSquare ///< A filled square - ,esDiamond ///< A filled diamond (45 degrees rotated square) - ,esBar ///< A bar perpendicular to the line - ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) - ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) - }; - Q_ENUMS(EndingStyle) - - QCPLineEnding(); - QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); - - // getters: - EndingStyle style() const { return mStyle; } - double width() const { return mWidth; } - double length() const { return mLength; } - bool inverted() const { return mInverted; } - - // setters: - void setStyle(EndingStyle style); - void setWidth(double width); - void setLength(double length); - void setInverted(bool inverted); - - // non-property methods: - double boundingDistance() const; - double realLength() const; - void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const; - void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const; - -protected: - // property members: - EndingStyle mStyle; - double mWidth, mLength; - bool mInverted; -}; -Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); -Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle) - -/* end of 'src/lineending.h' */ - - -/* including file 'src/axis/axisticker.h', size 4177 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines the strategies that the axis ticker may follow when choosing the size of the tick step. - - \see setTickStepStrategy - */ - enum TickStepStrategy - { - tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) - ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count - }; - Q_ENUMS(TickStepStrategy) - - QCPAxisTicker(); - virtual ~QCPAxisTicker(); - - // getters: - TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; } - int tickCount() const { return mTickCount; } - double tickOrigin() const { return mTickOrigin; } - - // setters: - void setTickStepStrategy(TickStepStrategy strategy); - void setTickCount(int count); - void setTickOrigin(double origin); - - // introduced virtual methods: - virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels); - -protected: - // property members: - TickStepStrategy mTickStepStrategy; - int mTickCount; - double mTickOrigin; - - // introduced virtual methods: - virtual double getTickStep(const QCPRange &range); - virtual int getSubTickCount(double tickStep); - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision); - virtual QVector createTickVector(double tickStep, const QCPRange &range); - virtual QVector createSubTickVector(int subTickCount, const QVector &ticks); - virtual QVector createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision); - - // non-virtual methods: - void trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const; - double pickClosest(double target, const QVector &candidates) const; - double getMantissa(double input, double *magnitude=0) const; - double cleanMantissa(double input) const; -}; -Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy) -Q_DECLARE_METATYPE(QSharedPointer) - -/* end of 'src/axis/axisticker.h' */ - - -/* including file 'src/axis/axistickerdatetime.h', size 3289 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker -{ -public: - QCPAxisTickerDateTime(); - - // getters: - QString dateTimeFormat() const { return mDateTimeFormat; } - Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } - - // setters: - void setDateTimeFormat(const QString &format); - void setDateTimeSpec(Qt::TimeSpec spec); - void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) - void setTickOrigin(const QDateTime &origin); - - // static methods: - static QDateTime keyToDateTime(double key); - static double dateTimeToKey(const QDateTime dateTime); - static double dateTimeToKey(const QDate date); - -protected: - // property members: - QString mDateTimeFormat; - Qt::TimeSpec mDateTimeSpec; - - // non-property members: - enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; -}; - -/* end of 'src/axis/axistickerdatetime.h' */ - - -/* including file 'src/axis/axistickertime.h', size 3542 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines the logical units in which fractions of time spans can be expressed. - - \see setFieldWidth, setTimeFormat - */ - enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) - ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat) - ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat) - ,tuHours ///< Hours (%%h in \ref setTimeFormat) - ,tuDays ///< Days (%%d in \ref setTimeFormat) - }; - Q_ENUMS(TimeUnit) - - QCPAxisTickerTime(); - - // getters: - QString timeFormat() const { return mTimeFormat; } - int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); } - - // setters: - void setTimeFormat(const QString &format); - void setFieldWidth(TimeUnit unit, int width); - -protected: - // property members: - QString mTimeFormat; - QHash mFieldWidth; - - // non-property members: - TimeUnit mSmallestUnit, mBiggestUnit; - QHash mFormatPattern; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - - // non-virtual methods: - void replaceUnit(QString &text, TimeUnit unit, int value) const; -}; -Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit) - -/* end of 'src/axis/axistickertime.h' */ - - -/* including file 'src/axis/axistickerfixed.h', size 3308 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines how the axis ticker may modify the specified tick step (\ref setTickStep) in order to - control the number of ticks in the axis range. - - \see setScaleStrategy - */ - enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. - ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. - ,ssPowers ///< An integer power of the specified tick step is allowed. - }; - Q_ENUMS(ScaleStrategy) - - QCPAxisTickerFixed(); - - // getters: - double tickStep() const { return mTickStep; } - ScaleStrategy scaleStrategy() const { return mScaleStrategy; } - - // setters: - void setTickStep(double step); - void setScaleStrategy(ScaleStrategy strategy); - -protected: - // property members: - double mTickStep; - ScaleStrategy mScaleStrategy; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; -}; -Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy) - -/* end of 'src/axis/axistickerfixed.h' */ - - -/* including file 'src/axis/axistickertext.h', size 3085 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker -{ -public: - QCPAxisTickerText(); - - // getters: - QMap &ticks() { return mTicks; } - int subTickCount() const { return mSubTickCount; } - - // setters: - void setTicks(const QMap &ticks); - void setTicks(const QVector &positions, const QVector labels); - void setSubTickCount(int subTicks); - - // non-virtual methods: - void clear(); - void addTick(double position, QString label); - void addTicks(const QMap &ticks); - void addTicks(const QVector &positions, const QVector &labels); - -protected: - // property members: - QMap mTicks; - int mSubTickCount; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; - -}; - -/* end of 'src/axis/axistickertext.h' */ - - -/* including file 'src/axis/axistickerpi.h', size 3911 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines how fractions should be displayed in tick labels. - - \see setFractionStyle - */ - enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". - ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" - ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. - }; - Q_ENUMS(FractionStyle) - - QCPAxisTickerPi(); - - // getters: - QString piSymbol() const { return mPiSymbol; } - double piValue() const { return mPiValue; } - bool periodicity() const { return mPeriodicity; } - FractionStyle fractionStyle() const { return mFractionStyle; } - - // setters: - void setPiSymbol(QString symbol); - void setPiValue(double pi); - void setPeriodicity(int multiplesOfPi); - void setFractionStyle(FractionStyle style); - -protected: - // property members: - QString mPiSymbol; - double mPiValue; - int mPeriodicity; - FractionStyle mFractionStyle; - - // non-property members: - double mPiTickStep; // size of one tick step in units of mPiValue - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - - // non-virtual methods: - void simplifyFraction(int &numerator, int &denominator) const; - QString fractionToString(int numerator, int denominator) const; - QString unicodeFraction(int numerator, int denominator) const; - QString unicodeSuperscript(int number) const; - QString unicodeSubscript(int number) const; -}; -Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle) - -/* end of 'src/axis/axistickerpi.h' */ - - -/* including file 'src/axis/axistickerlog.h', size 2663 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker -{ -public: - QCPAxisTickerLog(); - - // getters: - double logBase() const { return mLogBase; } - int subTickCount() const { return mSubTickCount; } - - // setters: - void setLogBase(double base); - void setSubTickCount(int subTicks); - -protected: - // property members: - double mLogBase; - int mSubTickCount; - - // non-property members: - double mLogBaseLnInv; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; -}; - -/* end of 'src/axis/axistickerlog.h' */ - - -/* including file 'src/axis/axis.h', size 20634 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPGrid :public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) - Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) - Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) - Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) - /// \endcond -public: - explicit QCPGrid(QCPAxis *parentAxis); - - // getters: - bool subGridVisible() const { return mSubGridVisible; } - bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } - bool antialiasedZeroLine() const { return mAntialiasedZeroLine; } - QPen pen() const { return mPen; } - QPen subGridPen() const { return mSubGridPen; } - QPen zeroLinePen() const { return mZeroLinePen; } - - // setters: - void setSubGridVisible(bool visible); - void setAntialiasedSubGrid(bool enabled); - void setAntialiasedZeroLine(bool enabled); - void setPen(const QPen &pen); - void setSubGridPen(const QPen &pen); - void setZeroLinePen(const QPen &pen); - -protected: - // property members: - bool mSubGridVisible; - bool mAntialiasedSubGrid, mAntialiasedZeroLine; - QPen mPen, mSubGridPen, mZeroLinePen; - - // non-property members: - QCPAxis *mParentAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - void drawGridLines(QCPPainter *painter) const; - void drawSubGridLines(QCPPainter *painter) const; - - friend class QCPAxis; -}; - - -class QCP_LIB_DECL QCPAxis : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(AxisType axisType READ axisType) - Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) - Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) - Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) - Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) - Q_PROPERTY(QSharedPointer ticker READ ticker WRITE setTicker) - Q_PROPERTY(bool ticks READ ticks WRITE setTicks) - Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) - Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) - Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) - Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) - Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) - Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide) - Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) - Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) - Q_PROPERTY(QVector tickVector READ tickVector) - Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels) - Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) - Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) - Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks) - Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) - Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) - Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) - Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) - Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) - Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) - Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) - Q_PROPERTY(int padding READ padding WRITE setPadding) - Q_PROPERTY(int offset READ offset WRITE setOffset) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) - Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) - Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) - Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) - Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) - Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) - Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) - Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) - Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) - Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) - Q_PROPERTY(QCPGrid* grid READ grid) - /// \endcond -public: - /*! - Defines at which side of the axis rect the axis will appear. This also affects how the tick - marks are drawn, on which side the labels are placed etc. - */ - enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect - ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect - ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect - ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect - }; - Q_ENUMS(AxisType) - Q_FLAGS(AxisTypes) - Q_DECLARE_FLAGS(AxisTypes, AxisType) - /*! - Defines on which side of the axis the tick labels (numbers) shall appear. - - \see setTickLabelSide - */ - enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect - ,lsOutside ///< Tick labels will be displayed outside the axis rect - }; - Q_ENUMS(LabelSide) - /*! - Defines the scale of an axis. - \see setScaleType - */ - enum ScaleType { stLinear ///< Linear scaling - ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). - }; - Q_ENUMS(ScaleType) - /*! - Defines the selectable parts of an axis. - \see setSelectableParts, setSelectedParts - */ - enum SelectablePart { spNone = 0 ///< None of the selectable parts - ,spAxis = 0x001 ///< The axis backbone and tick marks - ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) - ,spAxisLabel = 0x004 ///< The axis label - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPAxis(QCPAxisRect *parent, AxisType type); - virtual ~QCPAxis(); - - // getters: - AxisType axisType() const { return mAxisType; } - QCPAxisRect *axisRect() const { return mAxisRect; } - ScaleType scaleType() const { return mScaleType; } - const QCPRange range() const { return mRange; } - bool rangeReversed() const { return mRangeReversed; } - QSharedPointer ticker() const { return mTicker; } - bool ticks() const { return mTicks; } - bool tickLabels() const { return mTickLabels; } - int tickLabelPadding() const; - QFont tickLabelFont() const { return mTickLabelFont; } - QColor tickLabelColor() const { return mTickLabelColor; } - double tickLabelRotation() const; - LabelSide tickLabelSide() const; - QString numberFormat() const; - int numberPrecision() const { return mNumberPrecision; } - QVector tickVector() const { return mTickVector; } - QVector tickVectorLabels() const { return mTickVectorLabels; } - int tickLengthIn() const; - int tickLengthOut() const; - bool subTicks() const { return mSubTicks; } - int subTickLengthIn() const; - int subTickLengthOut() const; - QPen basePen() const { return mBasePen; } - QPen tickPen() const { return mTickPen; } - QPen subTickPen() const { return mSubTickPen; } - QFont labelFont() const { return mLabelFont; } - QColor labelColor() const { return mLabelColor; } - QString label() const { return mLabel; } - int labelPadding() const; - int padding() const { return mPadding; } - int offset() const; - SelectableParts selectedParts() const { return mSelectedParts; } - SelectableParts selectableParts() const { return mSelectableParts; } - QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; } - QFont selectedLabelFont() const { return mSelectedLabelFont; } - QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; } - QColor selectedLabelColor() const { return mSelectedLabelColor; } - QPen selectedBasePen() const { return mSelectedBasePen; } - QPen selectedTickPen() const { return mSelectedTickPen; } - QPen selectedSubTickPen() const { return mSelectedSubTickPen; } - QCPLineEnding lowerEnding() const; - QCPLineEnding upperEnding() const; - QCPGrid *grid() const { return mGrid; } - - // setters: - Q_SLOT void setScaleType(QCPAxis::ScaleType type); - Q_SLOT void setRange(const QCPRange &range); - void setRange(double lower, double upper); - void setRange(double position, double size, Qt::AlignmentFlag alignment); - void setRangeLower(double lower); - void setRangeUpper(double upper); - void setRangeReversed(bool reversed); - void setTicker(QSharedPointer ticker); - void setTicks(bool show); - void setTickLabels(bool show); - void setTickLabelPadding(int padding); - void setTickLabelFont(const QFont &font); - void setTickLabelColor(const QColor &color); - void setTickLabelRotation(double degrees); - void setTickLabelSide(LabelSide side); - void setNumberFormat(const QString &formatCode); - void setNumberPrecision(int precision); - void setTickLength(int inside, int outside=0); - void setTickLengthIn(int inside); - void setTickLengthOut(int outside); - void setSubTicks(bool show); - void setSubTickLength(int inside, int outside=0); - void setSubTickLengthIn(int inside); - void setSubTickLengthOut(int outside); - void setBasePen(const QPen &pen); - void setTickPen(const QPen &pen); - void setSubTickPen(const QPen &pen); - void setLabelFont(const QFont &font); - void setLabelColor(const QColor &color); - void setLabel(const QString &str); - void setLabelPadding(int padding); - void setPadding(int padding); - void setOffset(int offset); - void setSelectedTickLabelFont(const QFont &font); - void setSelectedLabelFont(const QFont &font); - void setSelectedTickLabelColor(const QColor &color); - void setSelectedLabelColor(const QColor &color); - void setSelectedBasePen(const QPen &pen); - void setSelectedTickPen(const QPen &pen); - void setSelectedSubTickPen(const QPen &pen); - Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); - void setLowerEnding(const QCPLineEnding &ending); - void setUpperEnding(const QCPLineEnding &ending); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-property methods: - Qt::Orientation orientation() const { return mOrientation; } - int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; } - void moveRange(double diff); - void scaleRange(double factor); - void scaleRange(double factor, double center); - void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); - void rescale(bool onlyVisiblePlottables=false); - double pixelToCoord(double value) const; - double coordToPixel(double value) const; - SelectablePart getPartAt(const QPointF &pos) const; - QList plottables() const; - QList graphs() const; - QList items() const; - - static AxisType marginSideToAxisType(QCP::MarginSide side); - static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } - static AxisType opposite(AxisType type); - -Q_SIGNALS: - void rangeChanged(const QCPRange &newRange); - void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); - void scaleTypeChanged(QCPAxis::ScaleType scaleType); - void selectionChanged(const QCPAxis::SelectableParts &parts); - void selectableChanged(const QCPAxis::SelectableParts &parts); - -protected: - // property members: - // axis base: - AxisType mAxisType; - QCPAxisRect *mAxisRect; - //int mOffset; // in QCPAxisPainter - int mPadding; - Qt::Orientation mOrientation; - SelectableParts mSelectableParts, mSelectedParts; - QPen mBasePen, mSelectedBasePen; - //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter - // axis label: - //int mLabelPadding; // in QCPAxisPainter - QString mLabel; - QFont mLabelFont, mSelectedLabelFont; - QColor mLabelColor, mSelectedLabelColor; - // tick labels: - //int mTickLabelPadding; // in QCPAxisPainter - bool mTickLabels; - //double mTickLabelRotation; // in QCPAxisPainter - QFont mTickLabelFont, mSelectedTickLabelFont; - QColor mTickLabelColor, mSelectedTickLabelColor; - int mNumberPrecision; - QLatin1Char mNumberFormatChar; - bool mNumberBeautifulPowers; - //bool mNumberMultiplyCross; // QCPAxisPainter - // ticks and subticks: - bool mTicks; - bool mSubTicks; - //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter - QPen mTickPen, mSelectedTickPen; - QPen mSubTickPen, mSelectedSubTickPen; - // scale and range: - QCPRange mRange; - bool mRangeReversed; - ScaleType mScaleType; - - // non-property members: - QCPGrid *mGrid; - QCPAxisPainterPrivate *mAxisPainter; - QSharedPointer mTicker; - QVector mTickVector; - QVector mTickVectorLabels; - QVector mSubTickVector; - bool mCachedMarginValid; - int mCachedMargin; - bool mDragging; - QCPRange mDragStartRange; - QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - - // introduced virtual methods: - virtual int calculateMargin(); - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - // mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); - virtual void wheelEvent(QWheelEvent *event); - - // non-virtual methods: - void setupTickVectors(); - QPen getBasePen() const; - QPen getTickPen() const; - QPen getSubTickPen() const; - QFont getTickLabelFont() const; - QFont getLabelFont() const; - QColor getTickLabelColor() const; - QColor getLabelColor() const; - -private: - Q_DISABLE_COPY(QCPAxis) - - friend class QCustomPlot; - friend class QCPGrid; - friend class QCPAxisRect; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) -Q_DECLARE_METATYPE(QCPAxis::AxisType) -Q_DECLARE_METATYPE(QCPAxis::LabelSide) -Q_DECLARE_METATYPE(QCPAxis::ScaleType) -Q_DECLARE_METATYPE(QCPAxis::SelectablePart) - - -class QCPAxisPainterPrivate -{ -public: - explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); - virtual ~QCPAxisPainterPrivate(); - - virtual void draw(QCPPainter *painter); - virtual int size() const; - void clearCache(); - - QRect axisSelectionBox() const { return mAxisSelectionBox; } - QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } - QRect labelSelectionBox() const { return mLabelSelectionBox; } - - // public property members: - QCPAxis::AxisType type; - QPen basePen; - QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters - int labelPadding; // directly accessed by QCPAxis setters/getters - QFont labelFont; - QColor labelColor; - QString label; - int tickLabelPadding; // directly accessed by QCPAxis setters/getters - double tickLabelRotation; // directly accessed by QCPAxis setters/getters - QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters - bool substituteExponent; - bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters - int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters - QPen tickPen, subTickPen; - QFont tickLabelFont; - QColor tickLabelColor; - QRect axisRect, viewportRect; - double offset; // directly accessed by QCPAxis setters/getters - bool abbreviateDecimalPowers; - bool reversedEndings; - - QVector subTickPositions; - QVector tickPositions; - QVector tickLabels; - -protected: - struct CachedLabel - { - QPointF offset; - QPixmap pixmap; - }; - struct TickLabelData - { - QString basePart, expPart, suffixPart; - QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds; - QFont baseFont, expFont; - }; - QCustomPlot *mParentPlot; - QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters - QCache mLabelCache; - QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; - - virtual QByteArray generateLabelParameterHash() const; - - virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); - virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; - virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; - virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; - virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; -}; - -/* end of 'src/axis/axis.h' */ - - -/* including file 'src/scatterstyle.h', size 7275 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPScatterStyle -{ - Q_GADGET -public: - /*! - Represents the various properties of a scatter style instance. For example, this enum is used - to specify which properties of \ref QCPSelectionDecorator::setScatterStyle will be used when - highlighting selected data points. - - Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref - setFromOther. - */ - enum ScatterProperty { spNone = 0x00 ///< 0x00 None - ,spPen = 0x01 ///< 0x01 The pen property, see \ref setPen - ,spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush - ,spSize = 0x04 ///< 0x04 The size property, see \ref setSize - ,spShape = 0x08 ///< 0x08 The shape property, see \ref setShape - ,spAll = 0xFF ///< 0xFF All properties - }; - Q_ENUMS(ScatterProperty) - Q_FLAGS(ScatterProperties) - Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty) - - /*! - Defines the shape used for scatter points. - - On plottables/items that draw scatters, the sizes of these visualizations (with exception of - \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are - drawn with the pen and brush specified with \ref setPen and \ref setBrush. - */ - enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) - ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) - ,ssCross ///< \enumimage{ssCross.png} a cross - ,ssPlus ///< \enumimage{ssPlus.png} a plus - ,ssCircle ///< \enumimage{ssCircle.png} a circle - ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) - ,ssSquare ///< \enumimage{ssSquare.png} a square - ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond - ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus - ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline - ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner - ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside - ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside - ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside - ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside - ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines - ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates - ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) - }; - Q_ENUMS(ScatterShape) - - QCPScatterStyle(); - QCPScatterStyle(ScatterShape shape, double size=6); - QCPScatterStyle(ScatterShape shape, const QColor &color, double size); - QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); - QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); - QCPScatterStyle(const QPixmap &pixmap); - QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); - - // getters: - double size() const { return mSize; } - ScatterShape shape() const { return mShape; } - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QPixmap pixmap() const { return mPixmap; } - QPainterPath customPath() const { return mCustomPath; } - - // setters: - void setFromOther(const QCPScatterStyle &other, ScatterProperties properties); - void setSize(double size); - void setShape(ScatterShape shape); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setPixmap(const QPixmap &pixmap); - void setCustomPath(const QPainterPath &customPath); - - // non-property methods: - bool isNone() const { return mShape == ssNone; } - bool isPenDefined() const { return mPenDefined; } - void undefinePen(); - void applyTo(QCPPainter *painter, const QPen &defaultPen) const; - void drawShape(QCPPainter *painter, const QPointF &pos) const; - void drawShape(QCPPainter *painter, double x, double y) const; - -protected: - // property members: - double mSize; - ScatterShape mShape; - QPen mPen; - QBrush mBrush; - QPixmap mPixmap; - QPainterPath mCustomPath; - - // non-property members: - bool mPenDefined; -}; -Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) - -/* end of 'src/scatterstyle.h' */ - - -/* including file 'src/datacontainer.h', size 4596 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -/*! \relates QCPDataContainer - Returns whether the sort key of \a a is less than the sort key of \a b. - - \see QCPDataContainer::sort -*/ -template -inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); } - -template -class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) -{ -public: - typedef typename QVector::const_iterator const_iterator; - typedef typename QVector::iterator iterator; - - QCPDataContainer(); - - // getters: - int size() const { return mData.size()-mPreallocSize; } - bool isEmpty() const { return size() == 0; } - bool autoSqueeze() const { return mAutoSqueeze; } - - // setters: - void setAutoSqueeze(bool enabled); - - // non-virtual methods: - void set(const QCPDataContainer &data); - void set(const QVector &data, bool alreadySorted=false); - void add(const QCPDataContainer &data); - void add(const QVector &data, bool alreadySorted=false); - void add(const DataType &data); - void removeBefore(double sortKey); - void removeAfter(double sortKey); - void remove(double sortKeyFrom, double sortKeyTo); - void remove(double sortKey); - void clear(); - void sort(); - void squeeze(bool preAllocation=true, bool postAllocation=true); - - const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; } - const_iterator constEnd() const { return mData.constEnd(); } - iterator begin() { return mData.begin()+mPreallocSize; } - iterator end() { return mData.end(); } - const_iterator findBegin(double sortKey, bool expandedRange=true) const; - const_iterator findEnd(double sortKey, bool expandedRange=true) const; - const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); } - QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth); - QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()); - QCPDataRange dataRange() const { return QCPDataRange(0, size()); } - void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const; - -protected: - // property members: - bool mAutoSqueeze; - - // non-property memebers: - QVector mData; - int mPreallocSize; - int mPreallocIteration; - - // non-virtual methods: - void preallocateGrow(int minimumPreallocSize); - void performAutoSqueeze(); -}; - -// include implementation in header since it is a class template: - -/* including file 'src/datacontainer.cpp', size 31349 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataContainer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataContainer - \brief The generic data container for one-dimensional plottables - - This class template provides a fast container for data storage of one-dimensional data. The data - type is specified as template parameter (called \a DataType in the following) and must provide - some methods as described in the \ref qcpdatacontainer-datatype "next section". - - The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well - as retrieval of ranges (see \ref findBegin, \ref findEnd, \ref keyRange) using binary search. The - container uses a preallocation and a postallocation scheme, such that appending and prepending - data (with respect to the sort key) is very fast and minimizes reallocations. If data is added - which needs to be inserted between existing keys, the merge usually can be done quickly too, - using the fact that existing data is always sorted. The user can further improve performance by - specifying that added data is already itself sorted by key, if he can guarantee that this is the - case (see for example \ref add(const QVector &data, bool alreadySorted)). - - The data can be accessed with the provided const iterators (\ref constBegin, \ref constEnd). If - it is necessary to alter existing data in-place, the non-const iterators can be used (\ref begin, - \ref end). Changing data members that are not the sort key (for most data types called \a key) is - safe from the container's perspective. - - Great care must be taken however if the sort key is modified through the non-const iterators. For - performance reasons, the iterators don't automatically cause a re-sorting upon their - manipulation. It is thus the responsibility of the user to leave the container in a sorted state - when finished with the data manipulation, before calling any other methods on the container. A - complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling \ref - sort. Failing to do so can not be detected by the container efficiently and will cause both - rendering artifacts and potential data loss. - - Implementing one-dimensional plottables that make use of a \ref QCPDataContainer is usually - done by subclassing from \ref QCPAbstractPlottable1D "QCPAbstractPlottable1D", which - introduces an according \a mDataContainer member and some convenience methods. - - \section qcpdatacontainer-datatype Requirements for the DataType template parameter - - The template parameter DataType is the type of the stored data points. It must be - trivially copyable and have the following public methods, preferably inline: - - \li double sortKey() const\n Returns the member variable of this data point that is the - sort key, defining the ordering in the container. Often this variable is simply called \a key. - - \li static DataType fromSortKey(double sortKey)\n Returns a new instance of the data - type initialized with its sort key set to \a sortKey. - - \li static bool sortKeyIsMainKey()\n Returns true if the sort key is equal to the main - key (see method \c mainKey below). For most plottables this is the case. It is not the case for - example for \ref QCPCurve, which uses \a t as sort key and \a key as main key. This is the reason - why QCPCurve unlike QCPGraph can display parametric curves with loops. - - \li double mainKey() const\n Returns the variable of this data point considered the main - key. This is commonly the variable that is used as the coordinate of this data point on the key - axis of the plottable. This method is used for example when determining the automatic axis - rescaling of key axes (\ref QCPAxis::rescale). - - \li double mainValue() const\n Returns the variable of this data point considered the - main value. This is commonly the variable that is used as the coordinate of this data point on - the value axis of the plottable. - - \li QCPRange valueRange() const\n Returns the range this data point spans in the value - axis coordinate. If the data is single-valued (e.g. QCPGraphData), this is simply a range with - both lower and upper set to the main data point value. However if the data points can represent - multiple values at once (e.g QCPFinancialData with its \a high, \a low, \a open and \a close - values at each \a key) this method should return the range those values span. This method is used - for example when determining the automatic axis rescaling of value axes (\ref - QCPAxis::rescale). -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataContainer::size() const - - Returns the number of data points in the container. -*/ - -/*! \fn bool QCPDataContainer::isEmpty() const - - Returns whether this container holds no data points. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constBegin() const - - Returns a const iterator to the first data point in this container. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constEnd() const - - Returns a const iterator to the element past the last data point in this container. -*/ - -/*! \fn QCPDataContainer::iterator QCPDataContainer::begin() const - - Returns a non-const iterator to the first data point in this container. - - You can manipulate the data points in-place through the non-const iterators, but great care must - be taken when manipulating the sort key of a data point, see \ref sort, or the detailed - description of this class. -*/ - -/*! \fn QCPDataContainer::iterator QCPDataContainer::end() const - - Returns a non-const iterator to the element past the last data point in this container. - - You can manipulate the data points in-place through the non-const iterators, but great care must - be taken when manipulating the sort key of a data point, see \ref sort, or the detailed - description of this class. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::at(int index) const - - Returns a const iterator to the element with the specified \a index. If \a index points beyond - the available elements in this container, returns \ref constEnd, i.e. an iterator past the last - valid element. - - You can use this method to easily obtain iterators from a \ref QCPDataRange, see the \ref - dataselection-accessing "data selection page" for an example. -*/ - -/*! \fn QCPDataRange QCPDataContainer::dataRange() const - - Returns a \ref QCPDataRange encompassing the entire data set of this container. This means the - begin index of the returned range is 0, and the end index is \ref size. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted - data -*/ -template -QCPDataContainer::QCPDataContainer() : - mAutoSqueeze(true), - mPreallocSize(0), - mPreallocIteration(0) -{ -} - -/*! - Sets whether the container automatically decides when to release memory from its post- and - preallocation pools when data points are removed. By default this is enabled and for typical - applications shouldn't be changed. - - If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with - \ref squeeze. -*/ -template -void QCPDataContainer::setAutoSqueeze(bool enabled) -{ - if (mAutoSqueeze != enabled) - { - mAutoSqueeze = enabled; - if (mAutoSqueeze) - performAutoSqueeze(); - } -} - -/*! \overload - - Replaces the current data in this container with the provided \a data. - - \see add, remove -*/ -template -void QCPDataContainer::set(const QCPDataContainer &data) -{ - clear(); - add(data); -} - -/*! \overload - - Replaces the current data in this container with the provided \a data - - If you can guarantee that the data points in \a data have ascending order with respect to the - DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. - - \see add, remove -*/ -template -void QCPDataContainer::set(const QVector &data, bool alreadySorted) -{ - mData = data; - mPreallocSize = 0; - mPreallocIteration = 0; - if (!alreadySorted) - sort(); -} - -/*! \overload - - Adds the provided \a data to the current data in this container. - - \see set, remove -*/ -template -void QCPDataContainer::add(const QCPDataContainer &data) -{ - if (data.isEmpty()) - return; - - const int n = data.size(); - const int oldSize = size(); - - if (oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones - { - if (mPreallocSize < n) - preallocateGrow(n); - mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and merge if necessary - { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); - } -} - -/*! - Adds the provided data points in \a data to the current data. - - If you can guarantee that the data points in \a data have ascending order with respect to the - DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. - - \see set, remove -*/ -template -void QCPDataContainer::add(const QVector &data, bool alreadySorted) -{ - if (data.isEmpty()) - return; - if (isEmpty()) - { - set(data, alreadySorted); - return; - } - - const int n = data.size(); - const int oldSize = size(); - - if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones - { - if (mPreallocSize < n) - preallocateGrow(n); - mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and then sort and merge if necessary - { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (!alreadySorted) // sort appended subrange if it wasn't already sorted - std::sort(end()-n, end(), qcpLessThanSortKey); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); - } -} - -/*! \overload - - Adds the provided single data point to the current data. - - \see remove -*/ -template -void QCPDataContainer::add(const DataType &data) -{ - if (isEmpty() || !qcpLessThanSortKey(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones - { - mData.append(data); - } else if (qcpLessThanSortKey(data, *constBegin())) // quickly handle prepends using preallocated space - { - if (mPreallocSize < 1) - preallocateGrow(1); - --mPreallocSize; - *begin() = data; - } else // handle inserts, maintaining sorted keys - { - QCPDataContainer::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey); - mData.insert(insertionPoint, data); - } -} - -/*! - Removes all data points with (sort-)keys smaller than or equal to \a sortKey. - - \see removeAfter, remove, clear -*/ -template -void QCPDataContainer::removeBefore(double sortKey) -{ - QCPDataContainer::iterator it = begin(); - QCPDataContainer::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - mPreallocSize += itEnd-it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points with (sort-)keys greater than or equal to \a sortKey. - - \see removeBefore, remove, clear -*/ -template -void QCPDataContainer::removeAfter(double sortKey) -{ - QCPDataContainer::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - QCPDataContainer::iterator itEnd = end(); - mData.erase(it, itEnd); // typically adds it to the postallocated block - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points with (sort-)keys between \a sortKeyFrom and \a sortKeyTo. if \a - sortKeyFrom is greater or equal to \a sortKeyTo, the function does nothing. To remove a single - data point with known (sort-)key, use \ref remove(double sortKey). - - \see removeBefore, removeAfter, clear -*/ -template -void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) -{ - if (sortKeyFrom >= sortKeyTo || isEmpty()) - return; - - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey); - QCPDataContainer::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey); - mData.erase(it, itEnd); - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! \overload - - Removes a single data point at \a sortKey. If the position is not known with absolute (binary) - precision, consider using \ref remove(double sortKeyFrom, double sortKeyTo) with a small - fuzziness interval around the suspected position, depeding on the precision with which the - (sort-)key is known. - - \see removeBefore, removeAfter, clear -*/ -template -void QCPDataContainer::remove(double sortKey) -{ - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (it != end() && it->sortKey() == sortKey) - { - if (it == begin()) - ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) - else - mData.erase(it); - } - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points. - - \see remove, removeAfter, removeBefore -*/ -template -void QCPDataContainer::clear() -{ - mData.clear(); - mPreallocIteration = 0; - mPreallocSize = 0; -} - -/*! - Re-sorts all data points in the container by their sort key. - - When setting, adding or removing points using the QCPDataContainer interface (\ref set, \ref add, - \ref remove, etc.), the container makes sure to always stay in a sorted state such that a full - resort is never necessary. However, if you choose to directly manipulate the sort key on data - points by accessing and modifying it through the non-const iterators (\ref begin, \ref end), it - is your responsibility to bring the container back into a sorted state before any other methods - are called on it. This can be achieved by calling this method immediately after finishing the - sort key manipulation. -*/ -template -void QCPDataContainer::sort() -{ - std::sort(begin(), end(), qcpLessThanSortKey); -} - -/*! - Frees all unused memory that is currently in the preallocation and postallocation pools. - - Note that QCPDataContainer automatically decides whether squeezing is necessary, if \ref - setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical - applications. - - The parameters \a preAllocation and \a postAllocation control whether pre- and/or post allocation - should be freed, respectively. -*/ -template -void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation) -{ - if (preAllocation) - { - if (mPreallocSize > 0) - { - std::copy(begin(), end(), mData.begin()); - mData.resize(size()); - mPreallocSize = 0; - } - mPreallocIteration = 0; - } - if (postAllocation) - mData.squeeze(); -} - -/*! - Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just - above \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be - considered, otherwise the one just above. - - This can be used in conjunction with \ref findEnd to iterate over data points within a given key - range, including or excluding the bounding data points that are just beyond the specified range. - - If \a expandedRange is true but there are no data points below \a sortKey, \ref constBegin is - returned. - - If the container is empty, returns \ref constEnd. - - \see findEnd, QCPPlottableInterface1D::findBegin -*/ -template -typename QCPDataContainer::const_iterator QCPDataContainer::findBegin(double sortKey, bool expandedRange) const -{ - if (isEmpty()) - return constEnd(); - - QCPDataContainer::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty - --it; - return it; -} - -/*! - Returns an iterator to the element after the data point with a (sort-)key that is equal to, just - above or just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey - will be considered, otherwise the one just below. - - This can be used in conjunction with \ref findBegin to iterate over data points within a given - key range, including the bounding data points that are just below and above the specified range. - - If \a expandedRange is true but there are no data points above \a sortKey, \ref constEnd is - returned. - - If the container is empty, \ref constEnd is returned. - - \see findBegin, QCPPlottableInterface1D::findEnd -*/ -template -typename QCPDataContainer::const_iterator QCPDataContainer::findEnd(double sortKey, bool expandedRange) const -{ - if (isEmpty()) - return constEnd(); - - QCPDataContainer::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constEnd()) - ++it; - return it; -} - -/*! - Returns the range encompassed by the (main-)key coordinate of all data points. The output - parameter \a foundRange indicates whether a sensible range was found. If this is false, you - should not use the returned QCPRange (e.g. the data container is empty or all points have the - same key). - - Use \a signDomain to control which sign of the key coordinates should be considered. This is - relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a - time. - - If the DataType reports that its main key is equal to the sort key (\a sortKeyIsMainKey), as is - the case for most plottables, this method uses this fact and finds the range very quickly. - - \see valueRange -*/ -template -QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain signDomain) -{ - if (isEmpty()) - { - foundRange = false; - return QCPRange(); - } - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - double current; - - QCPDataContainer::const_iterator it = constBegin(); - QCPDataContainer::const_iterator itEnd = constEnd(); - if (signDomain == QCP::sdBoth) // range may be anywhere - { - if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value - { - while (it != itEnd) // find first non-nan going up from left - { - if (!qIsNaN(it->mainValue())) - { - range.lower = it->mainKey(); - haveLower = true; - break; - } - ++it; - } - it = itEnd; - while (it != constBegin()) // find first non-nan going down from right - { - --it; - if (!qIsNaN(it->mainValue())) - { - range.upper = it->mainKey(); - haveUpper = true; - break; - } - } - } else // DataType is not sorted by main key, go through all data points and accordingly expand range - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if ((current < range.lower || !haveLower) && current < 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current < 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if ((current < range.lower || !haveLower) && current > 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current > 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! - Returns the range encompassed by the value coordinates of the data points in the specified key - range (\a inKeyRange), using the full \a DataType::valueRange reported by the data points. The - output parameter \a foundRange indicates whether a sensible range was found. If this is false, - you should not use the returned QCPRange (e.g. the data container is empty or all points have the - same value). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Use \a signDomain to control which sign of the value coordinates should be considered. This is - relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a - time. - - \see keyRange -*/ -template -QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange) -{ - if (isEmpty()) - { - foundRange = false; - return QCPRange(); - } - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPRange current; - QCPDataContainer::const_iterator itBegin = constBegin(); - QCPDataContainer::const_iterator itEnd = constEnd(); - if (DataType::sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = findBegin(inKeyRange.lower); - itEnd = findEnd(inKeyRange.upper); - } - if (signDomain == QCP::sdBoth) // range may be anywhere - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! - Makes sure \a begin and \a end mark a data range that is both within the bounds of this data - container's data, as well as within the specified \a dataRange. The initial range described by - the passed iterators \a begin and \a end is never expanded, only contracted if necessary. - - This function doesn't require for \a dataRange to be within the bounds of this data container's - valid range. -*/ -template -void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const -{ - QCPDataRange iteratorRange(begin-constBegin(), end-constBegin()); - iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); - begin = constBegin()+iteratorRange.begin(); - end = constBegin()+iteratorRange.end(); -} - -/*! \internal - - Increases the preallocation pool to have a size of at least \a minimumPreallocSize. Depending on - the preallocation history, the container will grow by more than requested, to speed up future - consecutive size increases. - - if \a minimumPreallocSize is smaller than or equal to the current preallocation pool size, this - method does nothing. -*/ -template -void QCPDataContainer::preallocateGrow(int minimumPreallocSize) -{ - if (minimumPreallocSize <= mPreallocSize) - return; - - int newPreallocSize = minimumPreallocSize; - newPreallocSize += (1u< -void QCPDataContainer::performAutoSqueeze() -{ - const int totalAlloc = mData.capacity(); - const int postAllocSize = totalAlloc-mData.size(); - const int usedSize = size(); - bool shrinkPostAllocation = false; - bool shrinkPreAllocation = false; - if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size - { - shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! - shrinkPreAllocation = mPreallocSize*10 > usedSize; - } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother - { - shrinkPostAllocation = postAllocSize > usedSize*5; - shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller - } - - if (shrinkPreAllocation || shrinkPostAllocation) - squeeze(shrinkPreAllocation, shrinkPostAllocation); -} -/* end of 'src/datacontainer.cpp' */ - - -/* end of 'src/datacontainer.h' */ - - -/* including file 'src/plottable.h', size 8312 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPSelectionDecorator -{ - Q_GADGET -public: - QCPSelectionDecorator(); - virtual ~QCPSelectionDecorator(); - - // getters: - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; } - - // setters: - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen); - void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties); - - // non-virtual methods: - void applyPen(QCPPainter *painter) const; - void applyBrush(QCPPainter *painter) const; - QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const; - - // introduced virtual methods: - virtual void copyFrom(const QCPSelectionDecorator *other); - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection); - -protected: - // property members: - QPen mPen; - QBrush mBrush; - QCPScatterStyle mScatterStyle; - QCPScatterStyle::ScatterProperties mUsedScatterProperties; - // non-property members: - QCPAbstractPlottable *mPlottable; - - // introduced virtual methods: - virtual bool registerWithPlottable(QCPAbstractPlottable *plottable); - -private: - Q_DISABLE_COPY(QCPSelectionDecorator) - friend class QCPAbstractPlottable; -}; -Q_DECLARE_METATYPE(QCPSelectionDecorator*) - - -class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) - Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) - Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) - Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged) - Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator) - /// \endcond -public: - QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPAbstractPlottable(); - - // getters: - QString name() const { return mName; } - bool antialiasedFill() const { return mAntialiasedFill; } - bool antialiasedScatters() const { return mAntialiasedScatters; } - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCP::SelectionType selectable() const { return mSelectable; } - bool selected() const { return !mSelection.isEmpty(); } - QCPDataSelection selection() const { return mSelection; } - QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; } - - // setters: - void setName(const QString &name); - void setAntialiasedFill(bool enabled); - void setAntialiasedScatters(bool enabled); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setKeyAxis(QCPAxis *axis); - void setValueAxis(QCPAxis *axis); - Q_SLOT void setSelectable(QCP::SelectionType selectable); - Q_SLOT void setSelection(QCPDataSelection selection); - void setSelectionDecorator(QCPSelectionDecorator *decorator); - - // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; - virtual QCPPlottableInterface1D *interface1D() { return 0; } - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0; - - // non-property methods: - void coordsToPixels(double key, double value, double &x, double &y) const; - const QPointF coordsToPixels(double key, double value) const; - void pixelsToCoords(double x, double y, double &key, double &value) const; - void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; - void rescaleAxes(bool onlyEnlarge=false) const; - void rescaleKeyAxis(bool onlyEnlarge=false) const; - void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const; - bool addToLegend(QCPLegend *legend); - bool addToLegend(); - bool removeFromLegend(QCPLegend *legend) const; - bool removeFromLegend() const; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectionChanged(const QCPDataSelection &selection); - void selectableChanged(QCP::SelectionType selectable); - -protected: - // property members: - QString mName; - bool mAntialiasedFill, mAntialiasedScatters; - QPen mPen; - QBrush mBrush; - QPointer mKeyAxis, mValueAxis; - QCP::SelectionType mSelectable; - QCPDataSelection mSelection; - QCPSelectionDecorator *mSelectionDecorator; - - // reimplemented virtual methods: - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; - - // non-virtual methods: - void applyFillAntialiasingHint(QCPPainter *painter) const; - void applyScattersAntialiasingHint(QCPPainter *painter) const; - -private: - Q_DISABLE_COPY(QCPAbstractPlottable) - - friend class QCustomPlot; - friend class QCPAxis; - friend class QCPPlottableLegendItem; -}; - - -/* end of 'src/plottable.h' */ - - -/* including file 'src/item.h', size 9384 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemAnchor -{ - Q_GADGET -public: - QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1); - virtual ~QCPItemAnchor(); - - // getters: - QString name() const { return mName; } - virtual QPointF pixelPosition() const; - -protected: - // property members: - QString mName; - - // non-property members: - QCustomPlot *mParentPlot; - QCPAbstractItem *mParentItem; - int mAnchorId; - QSet mChildrenX, mChildrenY; - - // introduced virtual methods: - virtual QCPItemPosition *toQCPItemPosition() { return 0; } - - // non-virtual methods: - void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - -private: - Q_DISABLE_COPY(QCPItemAnchor) - - friend class QCPItemPosition; -}; - - - -class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor -{ - Q_GADGET -public: - /*! - Defines the ways an item position can be specified. Thus it defines what the numbers passed to - \ref setCoords actually mean. - - \see setType - */ - enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. - ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the viewport/widget, etc. - ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. - ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). - }; - Q_ENUMS(PositionType) - - QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name); - virtual ~QCPItemPosition(); - - // getters: - PositionType type() const { return typeX(); } - PositionType typeX() const { return mPositionTypeX; } - PositionType typeY() const { return mPositionTypeY; } - QCPItemAnchor *parentAnchor() const { return parentAnchorX(); } - QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; } - QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; } - double key() const { return mKey; } - double value() const { return mValue; } - QPointF coords() const { return QPointF(mKey, mValue); } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCPAxisRect *axisRect() const; - virtual QPointF pixelPosition() const Q_DECL_OVERRIDE; - - // setters: - void setType(PositionType type); - void setTypeX(PositionType type); - void setTypeY(PositionType type); - bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - void setCoords(double key, double value); - void setCoords(const QPointF &coords); - void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); - void setAxisRect(QCPAxisRect *axisRect); - void setPixelPosition(const QPointF &pixelPosition); - -protected: - // property members: - PositionType mPositionTypeX, mPositionTypeY; - QPointer mKeyAxis, mValueAxis; - QPointer mAxisRect; - double mKey, mValue; - QCPItemAnchor *mParentAnchorX, *mParentAnchorY; - - // reimplemented virtual methods: - virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } - -private: - Q_DISABLE_COPY(QCPItemPosition) - -}; -Q_DECLARE_METATYPE(QCPItemPosition::PositionType) - - -class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) - Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - explicit QCPAbstractItem(QCustomPlot *parentPlot); - virtual ~QCPAbstractItem(); - - // getters: - bool clipToAxisRect() const { return mClipToAxisRect; } - QCPAxisRect *clipAxisRect() const; - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setClipToAxisRect(bool clip); - void setClipAxisRect(QCPAxisRect *rect); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; - - // non-virtual methods: - QList positions() const { return mPositions; } - QList anchors() const { return mAnchors; } - QCPItemPosition *position(const QString &name) const; - QCPItemAnchor *anchor(const QString &name) const; - bool hasAnchor(const QString &name) const; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - bool mClipToAxisRect; - QPointer mClipAxisRect; - QList mPositions; - QList mAnchors; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual QPointF anchorPixelPosition(int anchorId) const; - - // non-virtual methods: - double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const; - QCPItemPosition *createPosition(const QString &name); - QCPItemAnchor *createAnchor(const QString &name, int anchorId); - -private: - Q_DISABLE_COPY(QCPAbstractItem) - - friend class QCustomPlot; - friend class QCPItemAnchor; -}; - -/* end of 'src/item.h' */ - - -/* including file 'src/core.h', size 14886 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCustomPlot : public QWidget -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) - Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) - Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) - Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) - Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) - Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl) - /// \endcond -public: - /*! - Defines how a layer should be inserted relative to an other layer. - - \see addLayer, moveLayer - */ - enum LayerInsertMode { limBelow ///< Layer is inserted below other layer - ,limAbove ///< Layer is inserted above other layer - }; - Q_ENUMS(LayerInsertMode) - - /*! - Defines with what timing the QCustomPlot surface is refreshed after a replot. - - \see replot - */ - enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot - ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. - ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. - ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. - }; - Q_ENUMS(RefreshPriority) - - explicit QCustomPlot(QWidget *parent = 0); - virtual ~QCustomPlot(); - - // getters: - QRect viewport() const { return mViewport; } - double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; } - QPixmap background() const { return mBackgroundPixmap; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - QCPLayoutGrid *plotLayout() const { return mPlotLayout; } - QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } - QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } - bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } - const QCP::Interactions interactions() const { return mInteractions; } - int selectionTolerance() const { return mSelectionTolerance; } - bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; } - QCP::PlottingHints plottingHints() const { return mPlottingHints; } - Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } - QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; } - QCPSelectionRect *selectionRect() const { return mSelectionRect; } - bool openGl() const { return mOpenGl; } - - // setters: - void setViewport(const QRect &rect); - void setBufferDevicePixelRatio(double ratio); - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); - void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); - void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); - void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); - void setAutoAddPlottableToLegend(bool on); - void setInteractions(const QCP::Interactions &interactions); - void setInteraction(const QCP::Interaction &interaction, bool enabled=true); - void setSelectionTolerance(int pixels); - void setNoAntialiasingOnDrag(bool enabled); - void setPlottingHints(const QCP::PlottingHints &hints); - void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); - void setMultiSelectModifier(Qt::KeyboardModifier modifier); - void setSelectionRectMode(QCP::SelectionRectMode mode); - void setSelectionRect(QCPSelectionRect *selectionRect); - void setOpenGl(bool enabled, int multisampling=16); - - // non-property methods: - // plottable interface: - QCPAbstractPlottable *plottable(int index); - QCPAbstractPlottable *plottable(); - bool removePlottable(QCPAbstractPlottable *plottable); - bool removePlottable(int index); - int clearPlottables(); - int plottableCount() const; - QList selectedPlottables() const; - QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasPlottable(QCPAbstractPlottable *plottable) const; - - // specialized interface for QCPGraph: - QCPGraph *graph(int index) const; - QCPGraph *graph() const; - QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); - bool removeGraph(QCPGraph *graph); - bool removeGraph(int index); - int clearGraphs(); - int graphCount() const; - QList selectedGraphs() const; - - // item interface: - QCPAbstractItem *item(int index) const; - QCPAbstractItem *item() const; - bool removeItem(QCPAbstractItem *item); - bool removeItem(int index); - int clearItems(); - int itemCount() const; - QList selectedItems() const; - QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasItem(QCPAbstractItem *item) const; - - // layer interface: - QCPLayer *layer(const QString &name) const; - QCPLayer *layer(int index) const; - QCPLayer *currentLayer() const; - bool setCurrentLayer(const QString &name); - bool setCurrentLayer(QCPLayer *layer); - int layerCount() const; - bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); - bool removeLayer(QCPLayer *layer); - bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); - - // axis rect/layout interface: - int axisRectCount() const; - QCPAxisRect* axisRect(int index=0) const; - QList axisRects() const; - QCPLayoutElement* layoutElementAt(const QPointF &pos) const; - QCPAxisRect* axisRectAt(const QPointF &pos) const; - Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); - - QList selectedAxes() const; - QList selectedLegends() const; - Q_SLOT void deselectAll(); - - bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); - bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - QPixmap toPixmap(int width=0, int height=0, double scale=1.0); - void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); - - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - QCPLegend *legend; - -Q_SIGNALS: - void mouseDoubleClick(QMouseEvent *event); - void mousePress(QMouseEvent *event); - void mouseMove(QMouseEvent *event); - void mouseRelease(QMouseEvent *event); - void mouseWheel(QWheelEvent *event); - - void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void itemClick(QCPAbstractItem *item, QMouseEvent *event); - void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); - void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - - void selectionChangedByUser(); - void beforeReplot(); - void afterReplot(); - -protected: - // property members: - QRect mViewport; - double mBufferDevicePixelRatio; - QCPLayoutGrid *mPlotLayout; - bool mAutoAddPlottableToLegend; - QList mPlottables; - QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph - QList mItems; - QList mLayers; - QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; - QCP::Interactions mInteractions; - int mSelectionTolerance; - bool mNoAntialiasingOnDrag; - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayer *mCurrentLayer; - QCP::PlottingHints mPlottingHints; - Qt::KeyboardModifier mMultiSelectModifier; - QCP::SelectionRectMode mSelectionRectMode; - QCPSelectionRect *mSelectionRect; - bool mOpenGl; - - // non-property members: - QList > mPaintBuffers; - QPoint mMousePressPos; - bool mMouseHasMoved; - QPointer mMouseEventLayerable; - QPointer mMouseSignalLayerable; - QVariant mMouseEventLayerableDetails; - QVariant mMouseSignalLayerableDetails; - bool mReplotting; - bool mReplotQueued; - int mOpenGlMultisamples; - QCP::AntialiasedElements mOpenGlAntialiasedElementsBackup; - bool mOpenGlCacheLabelsBackup; -#ifdef QCP_OPENGL_FBO - QSharedPointer mGlContext; - QSharedPointer mGlSurface; - QSharedPointer mGlPaintDevice; -#endif - - // reimplemented virtual methods: - virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; - virtual QSize sizeHint() const Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void draw(QCPPainter *painter); - virtual void updateLayout(); - virtual void axisRemoved(QCPAxis *axis); - virtual void legendRemoved(QCPLegend *legend); - Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processPointSelection(QMouseEvent *event); - - // non-virtual methods: - bool registerPlottable(QCPAbstractPlottable *plottable); - bool registerGraph(QCPGraph *graph); - bool registerItem(QCPAbstractItem* item); - void updateLayerIndices() const; - QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; - QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=0) const; - void drawBackground(QCPPainter *painter); - void setupPaintBuffers(); - QCPAbstractPaintBuffer *createPaintBuffer(); - bool hasInvalidatedPaintBuffers(); - bool setupOpenGl(); - void freeOpenGl(); - - friend class QCPLegend; - friend class QCPAxis; - friend class QCPLayer; - friend class QCPAxisRect; - friend class QCPAbstractPlottable; - friend class QCPGraph; - friend class QCPAbstractItem; -}; -Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode) -Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority) - -/* end of 'src/core.h' */ - - -/* including file 'src/plottable1d.h', size 4544 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCPPlottableInterface1D -{ -public: - virtual ~QCPPlottableInterface1D() {} - // introduced pure virtual methods: - virtual int dataCount() const = 0; - virtual double dataMainKey(int index) const = 0; - virtual double dataSortKey(int index) const = 0; - virtual double dataMainValue(int index) const = 0; - virtual QCPRange dataValueRange(int index) const = 0; - virtual QPointF dataPixelPosition(int index) const = 0; - virtual bool sortKeyIsMainKey() const = 0; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; - virtual int findBegin(double sortKey, bool expandedRange=true) const = 0; - virtual int findEnd(double sortKey, bool expandedRange=true) const = 0; -}; - -template -class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) -{ - // No Q_OBJECT macro due to template class - -public: - QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPAbstractPlottable1D(); - - // virtual methods of 1d plottable interface: - virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - -protected: - // property members: - QSharedPointer > mDataContainer; - - // helpers for subclasses: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - void drawPolyline(QCPPainter *painter, const QVector &lineData) const; - -private: - Q_DISABLE_COPY(QCPAbstractPlottable1D) - -}; - -// include implementation in header since it is a class template: - -/* including file 'src/plottable1d.cpp', size 22240 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableInterface1D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableInterface1D - \brief Defines an abstract interface for one-dimensional plottables - - This class contains only pure virtual methods which define a common interface to the data - of one-dimensional plottables. - - For example, it is implemented by the template class \ref QCPAbstractPlottable1D (the preferred - base class for one-dimensional plottables). So if you use that template class as base class of - your one-dimensional plottable, you won't have to care about implementing the 1d interface - yourself. - - If your plottable doesn't derive from \ref QCPAbstractPlottable1D but still wants to provide a 1d - interface (e.g. like \ref QCPErrorBars does), you should inherit from both \ref - QCPAbstractPlottable and \ref QCPPlottableInterface1D and accordingly reimplement the pure - virtual methods of the 1d interface, matching your data container. Also, reimplement \ref - QCPAbstractPlottable::interface1D to return the \c this pointer. - - If you have a \ref QCPAbstractPlottable pointer, you can check whether it implements this - interface by calling \ref QCPAbstractPlottable::interface1D and testing it for a non-zero return - value. If it indeed implements this interface, you may use it to access the plottable's data - without needing to know the exact type of the plottable or its data point type. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPPlottableInterface1D::dataCount() const = 0; - - Returns the number of data points of the plottable. -*/ - -/*! \fn virtual QCPDataSelection QCPPlottableInterface1D::selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; - - Returns a data selection containing all the data points of this plottable which are contained (or - hit by) \a rect. This is used mainly in the selection rect interaction for data selection (\ref - dataselection "data selection mechanism"). - - If \a onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not - selectable (i.e. if \ref QCPAbstractPlottable::setSelectable is \ref QCP::stNone). - - \note \a rect must be a normalized rect (positive or zero width and height). This is especially - important when using the rect of \ref QCPSelectionRect::accepted, which is not necessarily - normalized. Use QRect::normalized() when passing a rect which might not be normalized. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataMainKey(int index) const = 0 - - Returns the main key of the data point at the given \a index. - - What the main key is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataSortKey(int index) const = 0 - - Returns the sort key of the data point at the given \a index. - - What the sort key is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataMainValue(int index) const = 0 - - Returns the main value of the data point at the given \a index. - - What the main value is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual QCPRange QCPPlottableInterface1D::dataValueRange(int index) const = 0 - - Returns the value range of the data point at the given \a index. - - What the value range is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual QPointF QCPPlottableInterface1D::dataPixelPosition(int index) const = 0 - - Returns the pixel position on the widget surface at which the data point at the given \a index - appears. - - Usually this corresponds to the point of \ref dataMainKey/\ref dataMainValue, in pixel - coordinates. However, depending on the plottable, this might be a different apparent position - than just a coord-to-pixel transform of those values. For example, \ref QCPBars apparent data - values can be shifted depending on their stacking, bar grouping or configured base value. -*/ - -/*! \fn virtual bool QCPPlottableInterface1D::sortKeyIsMainKey() const = 0 - - Returns whether the sort key (\ref dataSortKey) is identical to the main key (\ref dataMainKey). - - What the sort and main keys are, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual int QCPPlottableInterface1D::findBegin(double sortKey, bool expandedRange) const = 0 - - Returns the index of the data point with a (sort-)key that is equal to, just below, or just above - \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be considered, - otherwise the one just above. - - This can be used in conjunction with \ref findEnd to iterate over data points within a given key - range, including or excluding the bounding data points that are just beyond the specified range. - - If \a expandedRange is true but there are no data points below \a sortKey, 0 is returned. - - If the container is empty, returns 0 (in that case, \ref findEnd will also return 0, so a loop - using these methods will not iterate over the index 0). - - \see findEnd, QCPDataContainer::findBegin -*/ - -/*! \fn virtual int QCPPlottableInterface1D::findEnd(double sortKey, bool expandedRange) const = 0 - - Returns the index one after the data point with a (sort-)key that is equal to, just above, or - just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey will be - considered, otherwise the one just below. - - This can be used in conjunction with \ref findBegin to iterate over data points within a given - key range, including the bounding data points that are just below and above the specified range. - - If \a expandedRange is true but there are no data points above \a sortKey, the index just above the - highest data point is returned. - - If the container is empty, returns 0. - - \see findBegin, QCPDataContainer::findEnd -*/ - -/* end documentation of pure virtual functions */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable1D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable1D - \brief A template base class for plottables with one-dimensional data - - This template class derives from \ref QCPAbstractPlottable and from the abstract interface \ref - QCPPlottableInterface1D. It serves as a base class for all one-dimensional data (i.e. data with - one key dimension), such as \ref QCPGraph and QCPCurve. - - The template parameter \a DataType is the type of the data points of this plottable (e.g. \ref - QCPGraphData or \ref QCPCurveData). The main purpose of this base class is to provide the member - \a mDataContainer (a shared pointer to a \ref QCPDataContainer "QCPDataContainer") and - implement the according virtual methods of the \ref QCPPlottableInterface1D, such that most - subclassed plottables don't need to worry about this anymore. - - Further, it provides a convenience method for retrieving selected/unselected data segments via - \ref getDataSegments. This is useful when subclasses implement their \ref draw method and need to - draw selected segments with a different pen/brush than unselected segments (also see \ref - QCPSelectionDecorator). - - This class implements basic functionality of \ref QCPAbstractPlottable::selectTest and \ref - QCPPlottableInterface1D::selectTestRect, assuming point-like data points, based on the 1D data - interface. In spite of that, most plottable subclasses will want to reimplement those methods - again, to provide a more accurate hit test based on their specific data visualization geometry. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPPlottableInterface1D *QCPAbstractPlottable1D::interface1D() - - Returns a \ref QCPPlottableInterface1D pointer to this plottable, providing access to its 1D - interface. - - \seebaseclassmethod -*/ - -/* end documentation of inline functions */ - -/*! - Forwards \a keyAxis and \a valueAxis to the \ref QCPAbstractPlottable::QCPAbstractPlottable - "QCPAbstractPlottable" constructor and allocates the \a mDataContainer. -*/ -template -QCPAbstractPlottable1D::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QCPDataContainer) -{ -} - -template -QCPAbstractPlottable1D::~QCPAbstractPlottable1D() -{ -} - -/*! - \copydoc QCPPlottableInterface1D::dataCount -*/ -template -int QCPAbstractPlottable1D::dataCount() const -{ - return mDataContainer->size(); -} - -/*! - \copydoc QCPPlottableInterface1D::dataMainKey -*/ -template -double QCPAbstractPlottable1D::dataMainKey(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->mainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataSortKey -*/ -template -double QCPAbstractPlottable1D::dataSortKey(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->sortKey(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataMainValue -*/ -template -double QCPAbstractPlottable1D::dataMainValue(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->mainValue(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataValueRange -*/ -template -QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->valueRange(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QCPRange(0, 0); - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataPixelPosition -*/ -template -QPointF QCPAbstractPlottable1D::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - return coordsToPixels(it->mainKey(), it->mainValue()); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/*! - \copydoc QCPPlottableInterface1D::sortKeyIsMainKey -*/ -template -bool QCPAbstractPlottable1D::sortKeyIsMainKey() const -{ - return DataType::sortKeyIsMainKey(); -} - -/*! - Implements a rect-selection algorithm assuming the data (accessed via the 1D data interface) is - point-like. Most subclasses will want to reimplement this method again, to provide a more - accurate hit test based on the true data visualization geometry. - - \seebaseclassmethod -*/ -template -QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - // convert rect given in pixels to ranges given in plot coordinates: - double key1, value1, key2, value2; - pixelsToCoords(rect.topLeft(), key1, value1); - pixelsToCoords(rect.bottomRight(), key2, value2); - QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 - QCPRange valueRange(value1, value2); - typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); - typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: - { - begin = mDataContainer->findBegin(keyRange.lower, false); - end = mDataContainer->findEnd(keyRange.upper, false); - } - if (begin == end) - return result; - - int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (currentSegmentBegin == -1) - { - if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment - currentSegmentBegin = it-mDataContainer->constBegin(); - } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended - { - result.addDataRange(QCPDataRange(currentSegmentBegin, it-mDataContainer->constBegin()), false); - currentSegmentBegin = -1; - } - } - // process potential last segment: - if (currentSegmentBegin != -1) - result.addDataRange(QCPDataRange(currentSegmentBegin, end-mDataContainer->constBegin()), false); - - result.simplify(); - return result; -} - -/*! - \copydoc QCPPlottableInterface1D::findBegin -*/ -template -int QCPAbstractPlottable1D::findBegin(double sortKey, bool expandedRange) const -{ - return mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin(); -} - -/*! - \copydoc QCPPlottableInterface1D::findEnd -*/ -template -int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange) const -{ - return mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin(); -} - -/*! - Implements a point-selection algorithm assuming the data (accessed via the 1D data interface) is - point-like. Most subclasses will want to reimplement this method again, to provide a more - accurate hit test based on the true data visualization geometry. - - \seebaseclassmethod -*/ -template -double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - QCPDataSelection selectionResult; - double minDistSqr = std::numeric_limits::max(); - int minDistIndex = mDataContainer->size(); - - typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); - typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: - { - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - begin = mDataContainer->findBegin(posKeyMin, true); - end = mDataContainer->findEnd(posKeyMax, true); - } - if (begin == end) - return -1; - QCPRange keyRange(mKeyAxis->range()); - QCPRange valueRange(mValueAxis->range()); - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double mainKey = it->mainKey(); - const double mainValue = it->mainValue(); - if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points - { - const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - minDistIndex = it-mDataContainer->constBegin(); - } - } - } - if (minDistIndex != mDataContainer->size()) - selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false); - - selectionResult.simplify(); - if (details) - details->setValue(selectionResult); - return qSqrt(minDistSqr); -} - -/*! - Splits all data into selected and unselected segments and outputs them via \a selectedSegments - and \a unselectedSegments, respectively. - - This is useful when subclasses implement their \ref draw method and need to draw selected - segments with a different pen/brush than unselected segments (also see \ref - QCPSelectionDecorator). - - \see setSelection -*/ -template -void QCPAbstractPlottable1D::getDataSegments(QList &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! - A helper method which draws a line with the passed \a painter, according to the pixel data in \a - lineData. NaN points create gaps in the line, as expected from QCustomPlot's plottables (this is - the main difference to QPainter's regular drawPolyline, which handles NaNs by lagging or - crashing). - - Further it uses a faster line drawing technique based on \ref QCPPainter::drawLine rather than \c - QPainter::drawPolyline if the configured \ref QCustomPlot::setPlottingHints() and \a painter - style allows. -*/ -template -void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const -{ - // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: - if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && - painter->pen().style() == Qt::SolidLine && - !painter->modes().testFlag(QCPPainter::pmVectorized) && - !painter->modes().testFlag(QCPPainter::pmNoCaching)) - { - int i = 0; - bool lastIsNan = false; - const int lineDataSize = lineData.size(); - while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN - ++i; - ++i; // because drawing works in 1 point retrospect - while (i < lineDataSize) - { - if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line - { - if (!lastIsNan) - painter->drawLine(lineData.at(i-1), lineData.at(i)); - else - lastIsNan = false; - } else - lastIsNan = true; - ++i; - } - } else - { - int segmentStart = 0; - int i = 0; - const int lineDataSize = lineData.size(); - while (i < lineDataSize) - { - if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block - { - painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point - segmentStart = i+1; - } - ++i; - } - // draw last segment: - painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart); - } -} -/* end of 'src/plottable1d.cpp' */ - - -/* end of 'src/plottable1d.h' */ - - -/* including file 'src/colorgradient.h', size 6243 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPColorGradient -{ - Q_GADGET -public: - /*! - Defines the color spaces in which color interpolation between gradient stops can be performed. - - \see setColorInterpolation - */ - enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated - ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) - }; - Q_ENUMS(ColorInterpolation) - - /*! - Defines the available presets that can be loaded with \ref loadPreset. See the documentation - there for an image of the presets. - */ - enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) - ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) - ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) - ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) - ,gpCandy ///< Blue over pink to white - ,gpGeography ///< Colors suitable to represent different elevations on geographical maps - ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) - ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white - ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values - ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) - ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) - ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) - }; - Q_ENUMS(GradientPreset) - - QCPColorGradient(); - QCPColorGradient(GradientPreset preset); - bool operator==(const QCPColorGradient &other) const; - bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } - - // getters: - int levelCount() const { return mLevelCount; } - QMap colorStops() const { return mColorStops; } - ColorInterpolation colorInterpolation() const { return mColorInterpolation; } - bool periodic() const { return mPeriodic; } - - // setters: - void setLevelCount(int n); - void setColorStops(const QMap &colorStops); - void setColorStopAt(double position, const QColor &color); - void setColorInterpolation(ColorInterpolation interpolation); - void setPeriodic(bool enabled); - - // non-property methods: - void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - QRgb color(double position, const QCPRange &range, bool logarithmic=false); - void loadPreset(GradientPreset preset); - void clearColorStops(); - QCPColorGradient inverted() const; - -protected: - // property members: - int mLevelCount; - QMap mColorStops; - ColorInterpolation mColorInterpolation; - bool mPeriodic; - - // non-property members: - QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) - bool mColorBufferInvalidated; - - // non-virtual methods: - bool stopsUseAlpha() const; - void updateColorBuffer(); -}; -Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) -Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) - -/* end of 'src/colorgradient.h' */ - - -/* including file 'src/selectiondecorator-bracket.h', size 4442 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator -{ - Q_GADGET -public: - - /*! - Defines which shape is drawn at the boundaries of selected data ranges. - - Some of the bracket styles further allow specifying a height and/or width, see \ref - setBracketHeight and \ref setBracketWidth. - */ - enum BracketStyle { bsSquareBracket ///< A square bracket is drawn. - ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsPlus ///< A plus is drawn. - ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. - }; - Q_ENUMS(BracketStyle) - - QCPSelectionDecoratorBracket(); - virtual ~QCPSelectionDecoratorBracket(); - - // getters: - QPen bracketPen() const { return mBracketPen; } - QBrush bracketBrush() const { return mBracketBrush; } - int bracketWidth() const { return mBracketWidth; } - int bracketHeight() const { return mBracketHeight; } - BracketStyle bracketStyle() const { return mBracketStyle; } - bool tangentToData() const { return mTangentToData; } - int tangentAverage() const { return mTangentAverage; } - - // setters: - void setBracketPen(const QPen &pen); - void setBracketBrush(const QBrush &brush); - void setBracketWidth(int width); - void setBracketHeight(int height); - void setBracketStyle(BracketStyle style); - void setTangentToData(bool enabled); - void setTangentAverage(int pointCount); - - // introduced virtual methods: - virtual void drawBracket(QCPPainter *painter, int direction) const; - - // virtual methods: - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE; - -protected: - // property members: - QPen mBracketPen; - QBrush mBracketBrush; - int mBracketWidth; - int mBracketHeight; - BracketStyle mBracketStyle; - bool mTangentToData; - int mTangentAverage; - - // non-virtual methods: - double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const; - QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const; - -}; -Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle) - -/* end of 'src/selectiondecorator-bracket.h' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.h', size 7507 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); - virtual ~QCPAxisRect(); - - // getters: - QPixmap background() const { return mBackgroundPixmap; } - QBrush backgroundBrush() const { return mBackgroundBrush; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - Qt::Orientations rangeDrag() const { return mRangeDrag; } - Qt::Orientations rangeZoom() const { return mRangeZoom; } - QCPAxis *rangeDragAxis(Qt::Orientation orientation); - QCPAxis *rangeZoomAxis(Qt::Orientation orientation); - QList rangeDragAxes(Qt::Orientation orientation); - QList rangeZoomAxes(Qt::Orientation orientation); - double rangeZoomFactor(Qt::Orientation orientation); - - // setters: - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setRangeDrag(Qt::Orientations orientations); - void setRangeZoom(Qt::Orientations orientations); - void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeDragAxes(QList axes); - void setRangeDragAxes(QList horizontal, QList vertical); - void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeZoomAxes(QList axes); - void setRangeZoomAxes(QList horizontal, QList vertical); - void setRangeZoomFactor(double horizontalFactor, double verticalFactor); - void setRangeZoomFactor(double factor); - - // non-property methods: - int axisCount(QCPAxis::AxisType type) const; - QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; - QList axes(QCPAxis::AxisTypes types) const; - QList axes() const; - QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0); - QList addAxes(QCPAxis::AxisTypes types); - bool removeAxis(QCPAxis *axis); - QCPLayoutInset *insetLayout() const { return mInsetLayout; } - - void zoom(const QRectF &pixelRect); - void zoom(const QRectF &pixelRect, const QList &affectedAxes); - void setupFullAxesBox(bool connectRanges=false); - QList plottables() const; - QList graphs() const; - QList items() const; - - // read-only interface imitating a QRect: - int left() const { return mRect.left(); } - int right() const { return mRect.right(); } - int top() const { return mRect.top(); } - int bottom() const { return mRect.bottom(); } - int width() const { return mRect.width(); } - int height() const { return mRect.height(); } - QSize size() const { return mRect.size(); } - QPoint topLeft() const { return mRect.topLeft(); } - QPoint topRight() const { return mRect.topRight(); } - QPoint bottomLeft() const { return mRect.bottomLeft(); } - QPoint bottomRight() const { return mRect.bottomRight(); } - QPoint center() const { return mRect.center(); } - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - -protected: - // property members: - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayoutInset *mInsetLayout; - Qt::Orientations mRangeDrag, mRangeZoom; - QList > mRangeDragHorzAxis, mRangeDragVertAxis; - QList > mRangeZoomHorzAxis, mRangeZoomVertAxis; - double mRangeZoomFactorHorz, mRangeZoomFactorVert; - - // non-property members: - QList mDragStartHorzRange, mDragStartVertRange; - QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - bool mDragging; - QHash > mAxes; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE; - virtual void layoutChanged() Q_DECL_OVERRIDE; - // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - - // non-property methods: - void drawBackground(QCPPainter *painter); - void updateAxesOffset(QCPAxis::AxisType type); - -private: - Q_DISABLE_COPY(QCPAxisRect) - - friend class QCustomPlot; -}; - - -/* end of 'src/layoutelements/layoutelement-axisrect.h' */ - - -/* including file 'src/layoutelements/layoutelement-legend.h', size 10397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) - /// \endcond -public: - explicit QCPAbstractLegendItem(QCPLegend *parent); - - // getters: - QCPLegend *parentLegend() const { return mParentLegend; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - QCPLegend *mParentLegend; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPAbstractLegendItem) - - friend class QCPLegend; -}; - - -class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem -{ - Q_OBJECT -public: - QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); - - // getters: - QCPAbstractPlottable *plottable() { return mPlottable; } - -protected: - // property members: - QCPAbstractPlottable *mPlottable; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen getIconBorderPen() const; - QColor getTextColor() const; - QFont getFont() const; -}; - - -class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) - Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) - Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) - Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) - Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - /// \endcond -public: - /*! - Defines the selectable parts of a legend - - \see setSelectedParts, setSelectableParts - */ - enum SelectablePart { spNone = 0x000 ///< 0x000 None - ,spLegendBox = 0x001 ///< 0x001 The legend box (frame) - ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPLegend(); - virtual ~QCPLegend(); - - // getters: - QPen borderPen() const { return mBorderPen; } - QBrush brush() const { return mBrush; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QSize iconSize() const { return mIconSize; } - int iconTextPadding() const { return mIconTextPadding; } - QPen iconBorderPen() const { return mIconBorderPen; } - SelectableParts selectableParts() const { return mSelectableParts; } - SelectableParts selectedParts() const; - QPen selectedBorderPen() const { return mSelectedBorderPen; } - QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - - // setters: - void setBorderPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setIconSize(const QSize &size); - void setIconSize(int width, int height); - void setIconTextPadding(int padding); - void setIconBorderPen(const QPen &pen); - Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); - void setSelectedBorderPen(const QPen &pen); - void setSelectedIconBorderPen(const QPen &pen); - void setSelectedBrush(const QBrush &brush); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QCPAbstractLegendItem *item(int index) const; - QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; - int itemCount() const; - bool hasItem(QCPAbstractLegendItem *item) const; - bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; - bool addItem(QCPAbstractLegendItem *item); - bool removeItem(int index); - bool removeItem(QCPAbstractLegendItem *item); - void clearItems(); - QList selectedItems() const; - -Q_SIGNALS: - void selectionChanged(QCPLegend::SelectableParts parts); - void selectableChanged(QCPLegend::SelectableParts parts); - -protected: - // property members: - QPen mBorderPen, mIconBorderPen; - QBrush mBrush; - QFont mFont; - QColor mTextColor; - QSize mIconSize; - int mIconTextPadding; - SelectableParts mSelectedParts, mSelectableParts; - QPen mSelectedBorderPen, mSelectedIconBorderPen; - QBrush mSelectedBrush; - QFont mSelectedFont; - QColor mSelectedTextColor; - - // reimplemented virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen getBorderPen() const; - QBrush getBrush() const; - -private: - Q_DISABLE_COPY(QCPLegend) - - friend class QCustomPlot; - friend class QCPAbstractLegendItem; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) -Q_DECLARE_METATYPE(QCPLegend::SelectablePart) - -/* end of 'src/layoutelements/layoutelement-legend.h' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.h', size 5353 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - explicit QCPTextElement(QCustomPlot *parentPlot); - QCPTextElement(QCustomPlot *parentPlot, const QString &text); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font); - - // getters: - QString text() const { return mText; } - int textFlags() const { return mTextFlags; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setText(const QString &text); - void setTextFlags(int flags); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - void clicked(QMouseEvent *event); - void doubleClicked(QMouseEvent *event); - -protected: - // property members: - QString mText; - int mTextFlags; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - QRect mTextBoundingRect; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // non-virtual methods: - QFont mainFont() const; - QColor mainTextColor() const; - -private: - Q_DISABLE_COPY(QCPTextElement) -}; - - - -/* end of 'src/layoutelements/layoutelement-textelement.h' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.h', size 5923 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -class QCPColorScaleAxisRectPrivate : public QCPAxisRect -{ - Q_OBJECT -public: - explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); -protected: - QCPColorScale *mParentColorScale; - QImage mGradientImage; - bool mGradientImageInvalidated; - // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale - using QCPAxisRect::calculateAutoMargin; - using QCPAxisRect::mousePressEvent; - using QCPAxisRect::mouseMoveEvent; - using QCPAxisRect::mouseReleaseEvent; - using QCPAxisRect::wheelEvent; - using QCPAxisRect::update; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - void updateGradientImage(); - Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); - friend class QCPColorScale; -}; - - -class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) - Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPColorScale(QCustomPlot *parentPlot); - virtual ~QCPColorScale(); - - // getters: - QCPAxis *axis() const { return mColorAxis.data(); } - QCPAxis::AxisType type() const { return mType; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - QCPColorGradient gradient() const { return mGradient; } - QString label() const; - int barWidth () const { return mBarWidth; } - bool rangeDrag() const; - bool rangeZoom() const; - - // setters: - void setType(QCPAxis::AxisType type); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setLabel(const QString &str); - void setBarWidth(int width); - void setRangeDrag(bool enabled); - void setRangeZoom(bool enabled); - - // non-property methods: - QList colorMaps() const; - void rescaleDataRange(bool onlyVisibleMaps); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); - -protected: - // property members: - QCPAxis::AxisType mType; - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorGradient mGradient; - int mBarWidth; - - // non-property members: - QPointer mAxisRect; - QPointer mColorAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPColorScale) - - friend class QCPColorScaleAxisRectPrivate; -}; - - -/* end of 'src/layoutelements/layoutelement-colorscale.h' */ - - -/* including file 'src/plottables/plottable-graph.h', size 9294 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPGraphData -{ -public: - QCPGraphData(); - QCPGraphData(double key, double value); - - inline double sortKey() const { return key; } - inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - - double key, value; -}; -Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPGraphDataContainer - - Container for storing \ref QCPGraphData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPGraph holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPGraphData, QCPGraph::setData -*/ -typedef QCPDataContainer QCPGraphDataContainer; - -class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) - Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) - /// \endcond -public: - /*! - Defines how the graph's line is represented visually in the plot. The line is drawn with the - current pen of the graph (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented - ///< with symbols according to the scatter style, see \ref setScatterStyle) - ,lsLine ///< data points are connected by a straight line - ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point - ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point - ,lsStepCenter ///< line is drawn as steps where the step is in between two data points - ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line - }; - Q_ENUMS(LineStyle) - - explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPGraph(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - LineStyle lineStyle() const { return mLineStyle; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - int scatterSkip() const { return mScatterSkip; } - QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } - bool adaptiveSampling() const { return mAdaptiveSampling; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setLineStyle(LineStyle ls); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setChannelFillGraph(QCPGraph *targetGraph); - void setAdaptiveSampling(bool enabled); - - // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - LineStyle mLineStyle; - QCPScatterStyle mScatterStyle; - int mScatterSkip; - QPointer mChannelFillGraph; - bool mAdaptiveSampling; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawFill(QCPPainter *painter, QVector *lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; - virtual void drawLinePlot(QCPPainter *painter, const QVector &lines) const; - virtual void drawImpulsePlot(QCPPainter *painter, const QVector &lines) const; - - virtual void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; - virtual void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; - - // non-virtual methods: - void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - void getLines(QVector *lines, const QCPDataRange &dataRange) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange) const; - QVector dataToLines(const QVector &data) const; - QVector dataToStepLeftLines(const QVector &data) const; - QVector dataToStepRightLines(const QVector &data) const; - QVector dataToStepCenterLines(const QVector &data) const; - QVector dataToImpulseLines(const QVector &data) const; - QVector getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const; - QVector > getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const; - bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const; - QPointF getFillBasePoint(QPointF matchingDataPoint) const; - const QPolygonF getFillPolygon(const QVector *lineData, QCPDataRange segment) const; - const QPolygonF getChannelFillPolygon(const QVector *lineData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const; - int findIndexBelowX(const QVector *data, double x) const; - int findIndexAboveX(const QVector *data, double x) const; - int findIndexBelowY(const QVector *data, double y) const; - int findIndexAboveY(const QVector *data, double y) const; - double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPGraph::LineStyle) - -/* end of 'src/plottables/plottable-graph.h' */ - - -/* including file 'src/plottables/plottable-curve.h', size 7409 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPCurveData -{ -public: - QCPCurveData(); - QCPCurveData(double t, double key, double value); - - inline double sortKey() const { return t; } - inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); } - inline static bool sortKeyIsMainKey() { return false; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - - double t, key, value; -}; -Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPCurveDataContainer - - Container for storing \ref QCPCurveData points. The data is stored sorted by \a t, so the \a - sortKey() (returning \a t) is different from \a mainKey() (returning \a key). - - This template instantiation is the container in which QCPCurve holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPCurveData, QCPCurve::setData -*/ -typedef QCPDataContainer QCPCurveDataContainer; - -class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - /// \endcond -public: - /*! - Defines how the curve's line is represented visually in the plot. The line is drawn with the - current pen of the curve (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) - ,lsLine ///< Data points are connected with a straight line - }; - Q_ENUMS(LineStyle) - - explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPCurve(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - int scatterSkip() const { return mScatterSkip; } - LineStyle lineStyle() const { return mLineStyle; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void setData(const QVector &keys, const QVector &values); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setLineStyle(LineStyle style); - - // non-property methods: - void addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(const QVector &keys, const QVector &values); - void addData(double t, double key, double value); - void addData(double key, double value); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - QCPScatterStyle mScatterStyle; - int mScatterSkip; - LineStyle mLineStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawCurveLine(QCPPainter *painter, const QVector &lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const; - - // non-virtual methods: - void getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const; - int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QVector getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - bool mayTraverse(int prevRegion, int currentRegion) const; - bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const; - void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const; - double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPCurve::LineStyle) - -/* end of 'src/plottables/plottable-curve.h' */ - - -/* including file 'src/plottables/plottable-bars.h', size 8924 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPBarsGroup : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType) - Q_PROPERTY(double spacing READ spacing WRITE setSpacing) - /// \endcond -public: - /*! - Defines the ways the spacing between bars in the group can be specified. Thus it defines what - the number passed to \ref setSpacing actually means. - - \see setSpacingType, setSpacing - */ - enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels - ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size - ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(SpacingType) - - QCPBarsGroup(QCustomPlot *parentPlot); - virtual ~QCPBarsGroup(); - - // getters: - SpacingType spacingType() const { return mSpacingType; } - double spacing() const { return mSpacing; } - - // setters: - void setSpacingType(SpacingType spacingType); - void setSpacing(double spacing); - - // non-virtual methods: - QList bars() const { return mBars; } - QCPBars* bars(int index) const; - int size() const { return mBars.size(); } - bool isEmpty() const { return mBars.isEmpty(); } - void clear(); - bool contains(QCPBars *bars) const { return mBars.contains(bars); } - void append(QCPBars *bars); - void insert(int i, QCPBars *bars); - void remove(QCPBars *bars); - -protected: - // non-property members: - QCustomPlot *mParentPlot; - SpacingType mSpacingType; - double mSpacing; - QList mBars; - - // non-virtual methods: - void registerBars(QCPBars *bars); - void unregisterBars(QCPBars *bars); - - // virtual methods: - double keyPixelOffset(const QCPBars *bars, double keyCoord); - double getPixelSpacing(const QCPBars *bars, double keyCoord); - -private: - Q_DISABLE_COPY(QCPBarsGroup) - - friend class QCPBars; -}; -Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType) - - -class QCP_LIB_DECL QCPBarsData -{ -public: - QCPBarsData(); - QCPBarsData(double key, double value); - - inline double sortKey() const { return key; } - inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here - - double key, value; -}; -Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPBarsDataContainer - - Container for storing \ref QCPBarsData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPBars holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPBarsData, QCPBars::setData -*/ -typedef QCPDataContainer QCPBarsDataContainer; - -class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) - Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup) - Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue) - Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap) - Q_PROPERTY(QCPBars* barBelow READ barBelow) - Q_PROPERTY(QCPBars* barAbove READ barAbove) - /// \endcond -public: - /*! - Defines the ways the width of the bar can be specified. Thus it defines what the number passed - to \ref setWidth actually means. - - \see setWidthType, setWidth - */ - enum WidthType { wtAbsolute ///< Bar width is in absolute pixels - ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size - ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(WidthType) - - explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPBars(); - - // getters: - double width() const { return mWidth; } - WidthType widthType() const { return mWidthType; } - QCPBarsGroup *barsGroup() const { return mBarsGroup; } - double baseValue() const { return mBaseValue; } - double stackingGap() const { return mStackingGap; } - QCPBars *barBelow() const { return mBarBelow.data(); } - QCPBars *barAbove() const { return mBarAbove.data(); } - QSharedPointer data() const { return mDataContainer; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setBarsGroup(QCPBarsGroup *barsGroup); - void setBaseValue(double baseValue); - void setStackingGap(double pixels); - - // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - void moveBelow(QCPBars *bars); - void moveAbove(QCPBars *bars); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - -protected: - // property members: - double mWidth; - WidthType mWidthType; - QCPBarsGroup *mBarsGroup; - double mBaseValue; - double mStackingGap; - QPointer mBarBelow, mBarAbove; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const; - QRectF getBarRect(double key, double value) const; - void getPixelWidth(double key, double &lower, double &upper) const; - double getStackedBaseValue(double key, bool positive) const; - static void connectBars(QCPBars* lower, QCPBars* upper); - - friend class QCustomPlot; - friend class QCPLegend; - friend class QCPBarsGroup; -}; -Q_DECLARE_METATYPE(QCPBars::WidthType) - -/* end of 'src/plottables/plottable-bars.h' */ - - -/* including file 'src/plottables/plottable-statisticalbox.h', size 7516 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPStatisticalBoxData -{ -public: - QCPStatisticalBoxData(); - QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers=QVector()); - - inline double sortKey() const { return key; } - inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return median; } - - inline QCPRange valueRange() const - { - QCPRange result(minimum, maximum); - for (QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it) - result.expand(*it); - return result; - } - - double key, minimum, lowerQuartile, median, upperQuartile, maximum; - QVector outliers; -}; -Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE); - - -/*! \typedef QCPStatisticalBoxDataContainer - - Container for storing \ref QCPStatisticalBoxData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPStatisticalBox holds its data. For - details about the generic container, see the documentation of the class template \ref - QCPDataContainer. - - \see QCPStatisticalBoxData, QCPStatisticalBox::setData -*/ -typedef QCPDataContainer QCPStatisticalBoxDataContainer; - -class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen) - Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen) - Q_PROPERTY(bool whiskerAntialiased READ whiskerAntialiased WRITE setWhiskerAntialiased) - Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen) - Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle) - /// \endcond -public: - explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis); - - // getters: - QSharedPointer data() const { return mDataContainer; } - double width() const { return mWidth; } - double whiskerWidth() const { return mWhiskerWidth; } - QPen whiskerPen() const { return mWhiskerPen; } - QPen whiskerBarPen() const { return mWhiskerBarPen; } - bool whiskerAntialiased() const { return mWhiskerAntialiased; } - QPen medianPen() const { return mMedianPen; } - QCPScatterStyle outlierStyle() const { return mOutlierStyle; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void setWidth(double width); - void setWhiskerWidth(double width); - void setWhiskerPen(const QPen &pen); - void setWhiskerBarPen(const QPen &pen); - void setWhiskerAntialiased(bool enabled); - void setMedianPen(const QPen &pen); - void setOutlierStyle(const QCPScatterStyle &style); - - // non-property methods: - void addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers=QVector()); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - double mWidth; - double mWhiskerWidth; - QPen mWhiskerPen, mWhiskerBarPen; - bool mWhiskerAntialiased; - QPen mMedianPen; - QCPScatterStyle mOutlierStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const; - - // non-virtual methods: - void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const; - QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-statisticalbox.h' */ - - -/* including file 'src/plottables/plottable-colormap.h', size 7070 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPColorMapData -{ -public: - QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); - ~QCPColorMapData(); - QCPColorMapData(const QCPColorMapData &other); - QCPColorMapData &operator=(const QCPColorMapData &other); - - // getters: - int keySize() const { return mKeySize; } - int valueSize() const { return mValueSize; } - QCPRange keyRange() const { return mKeyRange; } - QCPRange valueRange() const { return mValueRange; } - QCPRange dataBounds() const { return mDataBounds; } - double data(double key, double value); - double cell(int keyIndex, int valueIndex); - unsigned char alpha(int keyIndex, int valueIndex); - - // setters: - void setSize(int keySize, int valueSize); - void setKeySize(int keySize); - void setValueSize(int valueSize); - void setRange(const QCPRange &keyRange, const QCPRange &valueRange); - void setKeyRange(const QCPRange &keyRange); - void setValueRange(const QCPRange &valueRange); - void setData(double key, double value, double z); - void setCell(int keyIndex, int valueIndex, double z); - void setAlpha(int keyIndex, int valueIndex, unsigned char alpha); - - // non-property methods: - void recalculateDataBounds(); - void clear(); - void clearAlpha(); - void fill(double z); - void fillAlpha(unsigned char alpha); - bool isEmpty() const { return mIsEmpty; } - void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; - void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; - -protected: - // property members: - int mKeySize, mValueSize; - QCPRange mKeyRange, mValueRange; - bool mIsEmpty; - - // non-property members: - double *mData; - unsigned char *mAlpha; - QCPRange mDataBounds; - bool mDataModified; - - bool createAlpha(bool initializeOpaque=true); - - friend class QCPColorMap; -}; - - -class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) - Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) - Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) - /// \endcond -public: - explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPColorMap(); - - // getters: - QCPColorMapData *data() const { return mMapData; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - bool interpolate() const { return mInterpolate; } - bool tightBoundary() const { return mTightBoundary; } - QCPColorGradient gradient() const { return mGradient; } - QCPColorScale *colorScale() const { return mColorScale.data(); } - - // setters: - void setData(QCPColorMapData *data, bool copy=false); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setInterpolate(bool enabled); - void setTightBoundary(bool enabled); - void setColorScale(QCPColorScale *colorScale); - - // non-property methods: - void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -Q_SIGNALS: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); - -protected: - // property members: - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorMapData *mMapData; - QCPColorGradient mGradient; - bool mInterpolate; - bool mTightBoundary; - QPointer mColorScale; - - // non-property members: - QImage mMapImage, mUndersampledMapImage; - QPixmap mLegendIcon; - bool mMapImageInvalidated; - - // introduced virtual methods: - virtual void updateMapImage(); - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-colormap.h' */ - - -/* including file 'src/plottables/plottable-financial.h', size 8622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPFinancialData -{ -public: - QCPFinancialData(); - QCPFinancialData(double key, double open, double high, double low, double close); - - inline double sortKey() const { return key; } - inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return open; } - - inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them - - double key, open, high, low, close; -}; -Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPFinancialDataContainer - - Container for storing \ref QCPFinancialData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPFinancial holds its data. For details - about the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPFinancialData, QCPFinancial::setData -*/ -typedef QCPDataContainer QCPFinancialDataContainer; - -class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle) - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) - Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored) - Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive) - Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative) - Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive) - Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative) - /// \endcond -public: - /*! - Defines the ways the width of the financial bar can be specified. Thus it defines what the - number passed to \ref setWidth actually means. - - \see setWidthType, setWidth - */ - enum WidthType { wtAbsolute ///< width is in absolute pixels - ,wtAxisRectRatio ///< width is given by a fraction of the axis rect size - ,wtPlotCoords ///< width is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(WidthType) - - /*! - Defines the possible representations of OHLC data in the plot. - - \see setChartStyle - */ - enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation - ,csCandlestick ///< Candlestick representation - }; - Q_ENUMS(ChartStyle) - - explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPFinancial(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - ChartStyle chartStyle() const { return mChartStyle; } - double width() const { return mWidth; } - WidthType widthType() const { return mWidthType; } - bool twoColored() const { return mTwoColored; } - QBrush brushPositive() const { return mBrushPositive; } - QBrush brushNegative() const { return mBrushNegative; } - QPen penPositive() const { return mPenPositive; } - QPen penNegative() const { return mPenNegative; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void setChartStyle(ChartStyle style); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setTwoColored(bool twoColored); - void setBrushPositive(const QBrush &brush); - void setBrushNegative(const QBrush &brush); - void setPenPositive(const QPen &pen); - void setPenNegative(const QPen &pen); - - // non-property methods: - void addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void addData(double key, double open, double high, double low, double close); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - - // static methods: - static QCPFinancialDataContainer timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset = 0); - -protected: - // property members: - ChartStyle mChartStyle; - double mWidth; - WidthType mWidthType; - bool mTwoColored; - QBrush mBrushPositive, mBrushNegative; - QPen mPenPositive, mPenNegative; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - double getPixelWidth(double key, double keyPixel) const; - double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const; - QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPFinancial::ChartStyle) - -/* end of 'src/plottables/plottable-financial.h' */ - - -/* including file 'src/plottables/plottable-errorbar.h', size 7727 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPErrorBarsData -{ -public: - QCPErrorBarsData(); - explicit QCPErrorBarsData(double error); - QCPErrorBarsData(double errorMinus, double errorPlus); - - double errorMinus, errorPlus; -}; -Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPErrorBarsDataContainer - - Container for storing \ref QCPErrorBarsData points. It is a typedef for QVector<\ref - QCPErrorBarsData>. - - This is the container in which \ref QCPErrorBars holds its data. Unlike most other data - containers for plottables, it is not based on \ref QCPDataContainer. This is because the error - bars plottable is special in that it doesn't store its own key and value coordinate per error - bar. It adopts the key and value from the plottable to which the error bars shall be applied - (\ref QCPErrorBars::setDataPlottable). So the stored \ref QCPErrorBarsData doesn't need a - sortable key, but merely an index (as \c QVector provides), which maps one-to-one to the indices - of the other plottable's data. - - \see QCPErrorBarsData, QCPErrorBars::setData -*/ -typedef QVector QCPErrorBarsDataContainer; - -class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottableInterface1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QSharedPointer data READ data WRITE setData) - Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable) - Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap) - /// \endcond -public: - - /*! - Defines in which orientation the error bars shall appear. If your data needs both error - dimensions, create two \ref QCPErrorBars with different \ref ErrorType. - - \see setErrorType - */ - enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) - ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) - }; - Q_ENUMS(ErrorType) - - explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPErrorBars(); - // getters: - QSharedPointer data() const { return mDataContainer; } - QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); } - ErrorType errorType() const { return mErrorType; } - double whiskerWidth() const { return mWhiskerWidth; } - double symbolGap() const { return mSymbolGap; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &error); - void setData(const QVector &errorMinus, const QVector &errorPlus); - void setDataPlottable(QCPAbstractPlottable* plottable); - void setErrorType(ErrorType type); - void setWhiskerWidth(double pixels); - void setSymbolGap(double pixels); - - // non-property methods: - void addData(const QVector &error); - void addData(const QVector &errorMinus, const QVector &errorPlus); - void addData(double error); - void addData(double errorMinus, double errorPlus); - - // virtual methods of 1d plottable interface: - virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - -protected: - // property members: - QSharedPointer mDataContainer; - QPointer mDataPlottable; - ErrorType mErrorType; - double mWhiskerWidth; - double mSymbolGap; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const; - void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const; - // helpers: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - bool errorBarVisible(int index) const; - bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-errorbar.h' */ - - -/* including file 'src/items/item-straightline.h', size 3117 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - explicit QCPItemStraightLine(QCustomPlot *parentPlot); - virtual ~QCPItemStraightLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const point1; - QCPItemPosition * const point2; - -protected: - // property members: - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QLineF getRectClippedStraightLine(const QCPVector2D &point1, const QCPVector2D &vec, const QRect &rect) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-straightline.h' */ - - -/* including file 'src/items/item-line.h', size 3407 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - explicit QCPItemLine(QCustomPlot *parentPlot); - virtual ~QCPItemLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-line.h' */ - - -/* including file 'src/items/item-curve.h', size 3379 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - explicit QCPItemCurve(QCustomPlot *parentPlot); - virtual ~QCPItemCurve(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const startDir; - QCPItemPosition * const endDir; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; -}; - -/* end of 'src/items/item-curve.h' */ - - -/* including file 'src/items/item-rect.h', size 3688 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - explicit QCPItemRect(QCustomPlot *parentPlot); - virtual ~QCPItemRect(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-rect.h' */ - - -/* including file 'src/items/item-text.h', size 5554 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemText : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) - Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) - Q_PROPERTY(double rotation READ rotation WRITE setRotation) - Q_PROPERTY(QMargins padding READ padding WRITE setPadding) - /// \endcond -public: - explicit QCPItemText(QCustomPlot *parentPlot); - virtual ~QCPItemText(); - - // getters: - QColor color() const { return mColor; } - QColor selectedColor() const { return mSelectedColor; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont font() const { return mFont; } - QFont selectedFont() const { return mSelectedFont; } - QString text() const { return mText; } - Qt::Alignment positionAlignment() const { return mPositionAlignment; } - Qt::Alignment textAlignment() const { return mTextAlignment; } - double rotation() const { return mRotation; } - QMargins padding() const { return mPadding; } - - // setters; - void setColor(const QColor &color); - void setSelectedColor(const QColor &color); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setFont(const QFont &font); - void setSelectedFont(const QFont &font); - void setText(const QString &text); - void setPositionAlignment(Qt::Alignment alignment); - void setTextAlignment(Qt::Alignment alignment); - void setRotation(double degrees); - void setPadding(const QMargins &padding); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const position; - QCPItemAnchor * const topLeft; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRight; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QColor mColor, mSelectedColor; - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - QFont mFont, mSelectedFont; - QString mText; - Qt::Alignment mPositionAlignment; - Qt::Alignment mTextAlignment; - double mRotation; - QMargins mPadding; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; - QFont mainFont() const; - QColor mainColor() const; - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-text.h' */ - - -/* including file 'src/items/item-ellipse.h', size 3868 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - explicit QCPItemEllipse(QCustomPlot *parentPlot); - virtual ~QCPItemEllipse(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const topLeftRim; - QCPItemAnchor * const top; - QCPItemAnchor * const topRightRim; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRightRim; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeftRim; - QCPItemAnchor * const left; - QCPItemAnchor * const center; - -protected: - enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-ellipse.h' */ - - -/* including file 'src/items/item-pixmap.h', size 4373 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) - Q_PROPERTY(bool scaled READ scaled WRITE setScaled) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) - Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - explicit QCPItemPixmap(QCustomPlot *parentPlot); - virtual ~QCPItemPixmap(); - - // getters: - QPixmap pixmap() const { return mPixmap; } - bool scaled() const { return mScaled; } - Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; } - Qt::TransformationMode transformationMode() const { return mTransformationMode; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPixmap(const QPixmap &pixmap); - void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPixmap mPixmap; - QPixmap mScaledPixmap; - bool mScaled; - bool mScaledPixmapInvalidated; - Qt::AspectRatioMode mAspectRatioMode; - Qt::TransformationMode mTransformationMode; - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); - QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-pixmap.h' */ - - -/* including file 'src/items/item-tracer.h', size 4762 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(double size READ size WRITE setSize) - Q_PROPERTY(TracerStyle style READ style WRITE setStyle) - Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) - Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) - Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) - /// \endcond -public: - /*! - The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize. - - \see setStyle - */ - enum TracerStyle { tsNone ///< The tracer is not visible - ,tsPlus ///< A plus shaped crosshair with limited size - ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect - ,tsCircle ///< A circle - ,tsSquare ///< A square - }; - Q_ENUMS(TracerStyle) - - explicit QCPItemTracer(QCustomPlot *parentPlot); - virtual ~QCPItemTracer(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - double size() const { return mSize; } - TracerStyle style() const { return mStyle; } - QCPGraph *graph() const { return mGraph; } - double graphKey() const { return mGraphKey; } - bool interpolating() const { return mInterpolating; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setSize(double size); - void setStyle(TracerStyle style); - void setGraph(QCPGraph *graph); - void setGraphKey(double key); - void setInterpolating(bool enabled); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void updatePosition(); - - QCPItemPosition * const position; - -protected: - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - double mSize; - TracerStyle mStyle; - QCPGraph *mGraph; - double mGraphKey; - bool mInterpolating; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; -Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle) - -/* end of 'src/items/item-tracer.h' */ - - -/* including file 'src/items/item-bracket.h', size 3969 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(double length READ length WRITE setLength) - Q_PROPERTY(BracketStyle style READ style WRITE setStyle) - /// \endcond -public: - /*! - Defines the various visual shapes of the bracket item. The appearance can be further modified - by \ref setLength and \ref setPen. - - \see setStyle - */ - enum BracketStyle { bsSquare ///< A brace with angled edges - ,bsRound ///< A brace with round edges - ,bsCurly ///< A curly brace - ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression - }; - Q_ENUMS(BracketStyle) - - explicit QCPItemBracket(QCustomPlot *parentPlot); - virtual ~QCPItemBracket(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - double length() const { return mLength; } - BracketStyle style() const { return mStyle; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setLength(double length); - void setStyle(BracketStyle style); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const left; - QCPItemPosition * const right; - QCPItemAnchor * const center; - -protected: - // property members: - enum AnchorIndex {aiCenter}; - QPen mPen, mSelectedPen; - double mLength; - BracketStyle mStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; -}; -Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) - -/* end of 'src/items/item-bracket.h' */ - - -#endif // QCUSTOMPLOT_H From 0de7d624a4299d4ecb6b5bcd0df5a2542a9156d4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:22:55 -0400 Subject: [PATCH 0441/1324] Delete statistics.cpp --- src/qt/statistics.cpp | 46 ------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/qt/statistics.cpp diff --git a/src/qt/statistics.cpp b/src/qt/statistics.cpp deleted file mode 100644 index 50eb5373..00000000 --- a/src/qt/statistics.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "statistics.h" - -Statistics::Statistics() -{ - -} - -void Statistics::setLikesNumber(unsigned int number) -{ - likesNumber = number; -} - -void Statistics::setFriendsNumber(unsigned int number) -{ - friendsNumber = number; -} - -void Statistics::setPostsNumber(unsigned int number) -{ - postsNumber = number; -} - -void Statistics::setUserID(unsigned int number) -{ - userID = number; -} - -unsigned int Statistics::getLikesNumber() -{ - return likesNumber; -} - -unsigned int Statistics::getPostsNumber() -{ - return postsNumber; -} - -unsigned int Statistics::getFriendsNumber() -{ - return friendsNumber; -} - -unsigned int Statistics::getUserID() -{ - return userID; -} From ba7838f98bdaee9c2eeea27b72e3d15f124fd5bd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:23:02 -0400 Subject: [PATCH 0442/1324] Delete statistics.h --- src/qt/statistics.h | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/qt/statistics.h diff --git a/src/qt/statistics.h b/src/qt/statistics.h deleted file mode 100644 index bbb5f472..00000000 --- a/src/qt/statistics.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef STATISTICS_H -#define STATISTICS_H -#include "QString" - -class Statistics -{ -public: - Statistics(); - - void setLikesNumber(unsigned int number); - - void setFriendsNumber(unsigned int number); - - void setPostsNumber(unsigned int number); - - void setUserID(unsigned int number); - - unsigned int getLikesNumber(); - - unsigned int getPostsNumber(); - - unsigned int getFriendsNumber(); - - unsigned int getUserID(); - - -private: - unsigned int userID; - - unsigned int likesNumber; - - unsigned int friendsNumber; - - unsigned int postsNumber; -}; - -#endif // STATISTICS_H From 4900ca0e4674e60e23997b309d450a1a3cad42d4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:23:16 -0400 Subject: [PATCH 0443/1324] Delete user.cpp --- src/qt/user.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/qt/user.cpp diff --git a/src/qt/user.cpp b/src/qt/user.cpp deleted file mode 100644 index 1934e769..00000000 --- a/src/qt/user.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "user.h" - -user::user() -{ - userName=""; - id=0; -} - -user::user(QString passWord, QString email,QString name,int userID) -{ - userName=name; - userFileManipulator.name=name; - userFileManipulator.createFile(passWord,email,name,creationDate.getDateNow()); - id=userID; -} - -void user :: setUsersList(user A) -{ - usersList.append(A); -} - -QString user:: getUserName(int id) -{ - return usersList[id].userName; -} - - bool user:: usersEmpty() - { - return (usersList.size()==0); - } - -int user:: getUsersSize() -{ - return usersList.count(); -} From cfb5531d397125a49c86f4cf93d497b7393c8e44 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:23:22 -0400 Subject: [PATCH 0444/1324] Delete user.h --- src/qt/user.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/user.h diff --git a/src/qt/user.h b/src/qt/user.h deleted file mode 100644 index 35a000b0..00000000 --- a/src/qt/user.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef USER_H -#define USER_H -#include "posts.h" -#include "fileman.h" -#include -#include -class user -{ -public: - QString userName; - int id; - Post userPost; - fileman userFileManipulator; - Date creationDate; - user(); - user(QString passWord, QString email, QString name,int userID); - void setUsersList( user A ); - QString getUserName(int id); - bool usersEmpty(); - int getUsersSize(); - -private: - QList usersList; -}; - -#endif // USER_H From f6fcc596d1dde2b125aa531c31b35b6731a4bbd1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:08 -0400 Subject: [PATCH 0445/1324] Delete addcomment.ui --- src/qt/forms/addcomment.ui | 107 ------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 src/qt/forms/addcomment.ui diff --git a/src/qt/forms/addcomment.ui b/src/qt/forms/addcomment.ui deleted file mode 100644 index c670061d..00000000 --- a/src/qt/forms/addcomment.ui +++ /dev/null @@ -1,107 +0,0 @@ - - - AddComment - - - - 0 - 0 - 348 - 222 - - - - Dialog - - - - - 11 - 183 - 193 - 28 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 75 - 15 - 262 - 151 - - - - - - - 10 - 70 - 57 - 41 - - - - - - - Add - - - Qt::AlignCenter - - - - - - - Comment - - - - - - - - - - buttonBox - accepted() - AddComment - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - AddComment - reject() - - - 316 - 260 - - - 286 - 274 - - - - - From 61859a91ea79f0c60a1702ce525960f7f73cef7f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:14 -0400 Subject: [PATCH 0446/1324] Delete adminwindow.ui --- src/qt/forms/adminwindow.ui | 71 ------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/qt/forms/adminwindow.ui diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui deleted file mode 100644 index 4eb710bd..00000000 --- a/src/qt/forms/adminwindow.ui +++ /dev/null @@ -1,71 +0,0 @@ - - - AdminWindow - - - - 0 - 0 - 800 - 550 - - - - MainWindow - - - - - - - true - - - - - 0 - 0 - 776 - 440 - - - - - - - - - - - - - - Show Statistics - - - - - - - - - 0 - 0 - 800 - 26 - - - - - - - - QCustomPlot - QWidget -
qcustomplot.h
- 1 -
-
- - -
From 3968f74cb73b6c0f21999172a85bc0f26484eb9f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:22 -0400 Subject: [PATCH 0447/1324] Delete form.ui --- src/qt/forms/form.ui | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/qt/forms/form.ui diff --git a/src/qt/forms/form.ui b/src/qt/forms/form.ui deleted file mode 100644 index 55b96fdf..00000000 --- a/src/qt/forms/form.ui +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Form - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - From 645f9d906db59b8920e2b99e5b9f12c8f59f85e7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:29 -0400 Subject: [PATCH 0448/1324] Delete homepage.ui --- src/qt/forms/homepage.ui | 188 --------------------------------------- 1 file changed, 188 deletions(-) delete mode 100644 src/qt/forms/homepage.ui diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui deleted file mode 100644 index 0d3cdb97..00000000 --- a/src/qt/forms/homepage.ui +++ /dev/null @@ -1,188 +0,0 @@ - - - HomePage - - - - 0 - 0 - 1102 - 761 - - - - MainWindow - - - - - - - - - - - - - - - - 400 - 16777215 - - - - - - - - - - - View Profile - - - - - - - View Network Staristics Window - - - - - - - - - - - - 16777215 - 100 - - - - 1 - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - What's On Your Mind ?! - - - - - - - Post - - - - - - - - - - - - - - - true - - - - - 0 - 0 - 1045 - 335 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - 0 - 0 - 1102 - 26 - - - - - File - - - - - - - - - - Log Out - - - - - - From a91be386b393e2e138e90083673d86702eb41d32 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:37 -0400 Subject: [PATCH 0449/1324] Delete mainwindow.ui --- src/qt/forms/mainwindow.ui | 665 ------------------------------------- 1 file changed, 665 deletions(-) delete mode 100644 src/qt/forms/mainwindow.ui diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui deleted file mode 100644 index 0e430af0..00000000 --- a/src/qt/forms/mainwindow.ui +++ /dev/null @@ -1,665 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 482 - 369 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 106 - 100 - 92 - - - - - - - 255 - 255 - 255 - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - MainWindow - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - No account? Create one! - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 15 - - - - - - - - - 0 - 0 - - - - - 100 - 30 - - - - PointingHandCursor - - - Sign Up - - - - - - - - - - - - - - - - - - 10 - 75 - true - - - - Email - - - - - - - - 0 - 0 - - - - - 285 - 0 - - - - - 285 - 16777215 - - - - - - - - - 10 - 75 - true - - - - Password - - - - - - - - 285 - 0 - - - - - 285 - 16777215 - - - - QLineEdit::Password - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 23 - - - - - - - - - 0 - 0 - - - - - 100 - 30 - - - - PointingHandCursor - - - Log In - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 30 - - - - - - - - - - 0 - 0 - 482 - 21 - - - - - - TopToolBarArea - - - false - - - - - - - - From 2059b9173e3f6577c046360d9d79183012ab7783 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:45 -0400 Subject: [PATCH 0450/1324] Delete newaccount.ui --- src/qt/forms/newaccount.ui | 195 ------------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 src/qt/forms/newaccount.ui diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui deleted file mode 100644 index 554b88de..00000000 --- a/src/qt/forms/newaccount.ui +++ /dev/null @@ -1,195 +0,0 @@ - - - NewAccount - - - - 0 - 0 - 532 - 312 - - - - MainWindow - - - - - - - - - - - - Times New Roman - 16 - 75 - true - - - - If You Already Have An Account ---> - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign In - - - - - - - - - - - - - - - - Times New Roman - 14 - 75 - true - - - - User Name - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Email - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Password - - - lineEdit_2 - - - - - - - - Times New Roman - 14 - 75 - true - - - - Confirm Password - - - lineEdit_3 - - - - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - QLineEdit::Password - - - - - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign Up - - - - - - - - - - - - - 0 - 0 - 532 - 26 - - - - - - - - From 6ed5a30474d99b253b9ce91657c0776c2120b4b2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:25:54 -0400 Subject: [PATCH 0451/1324] Delete profilepage.ui --- src/qt/forms/profilepage.ui | 271 ------------------------------------ 1 file changed, 271 deletions(-) delete mode 100644 src/qt/forms/profilepage.ui diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui deleted file mode 100644 index 8114320a..00000000 --- a/src/qt/forms/profilepage.ui +++ /dev/null @@ -1,271 +0,0 @@ - - - ProfilePage - - - - 0 - 0 - 1008 - 596 - - - - MainWindow - - - - - - - - - - - - Arial - 15 - 75 - true - - - - User name label Area - - - - - - - Add as a friend - - - - - - - - - - - - Arial - 9 - 75 - true - - - - Home - - - - - - - - Arial - 9 - 75 - true - - - - Friends - - - 8 - - - - Friends - - - - - - - - - - - - - Arial - 12 - 75 - true - - - - INFO - - - - - - - - - - - - - Arial - 9 - - - - Email - - - - - - - lblMail - - - - - - - - - - - - Arial - 9 - - - - Number of friends - - - - - - - labelNumber - - - - - - - - - - - border-color:blue; - - - - true - - - - - 0 - 0 - 982 - 349 - - - - - - - - 16777215 - 100 - - - - - - - What's on your mind? - - - - - - - - Arial - 9 - 75 - true - - - - false - - - background-color: rgb(85, 0, 255); -color:white; -selection-color: rgb(255, 255, 255); - - - Post - - - - - - - true - - - - - 0 - 0 - 958 - 183 - - - - - - - - - - - - - - - - - - - - 0 - 0 - 1008 - 26 - - - - - File - - - - - - - - - - Log out - - - - - - From 10b78681fe6cd04932bcf58fa9ddaffa59fa2e30 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:26:22 -0400 Subject: [PATCH 0452/1324] Delete signuppage.ui --- src/qt/forms/signuppage.ui | 310 ------------------------------------- 1 file changed, 310 deletions(-) delete mode 100644 src/qt/forms/signuppage.ui diff --git a/src/qt/forms/signuppage.ui b/src/qt/forms/signuppage.ui deleted file mode 100644 index 9ea4354b..00000000 --- a/src/qt/forms/signuppage.ui +++ /dev/null @@ -1,310 +0,0 @@ - - - SignUpPage - - - - 0 - 0 - 700 - 600 - - - - Sign Up - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - - - 16 - 251 - 87 - 24 - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Birthday - - - - - - 15 - 289 - 80 - 24 - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Country - - - - - - 110 - 290 - 171 - 30 - - - - - - - 360 - 400 - 321 - 34 - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Create Account - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Back - - - - - - - - - 11 - 332 - 255 - 30 - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Gender - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Female - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Male - - - - - - - - - 10 - 60 - 621 - 170 - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - First Name - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Last Name - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Username - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Password - - - - - - - - - - font-size:15px; -font-weight:none; - - - - Use at least 6 charaster. Must include a number and a capital letter - - - - - - - - - 112 - 251 - 521 - 32 - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Month - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Date - - - - - - - - - - font-family:sans-serif; -font-size:20px; -font-weight:bold; -color:#545454; - - - Year - - - - - - - - - - - - From 7f8adaff218e3fcd7fbdd6b76e55036bf59f18fa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:44:48 -0400 Subject: [PATCH 0453/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 54 +++-------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 22b58993..229c9eca 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,13 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/tradingdialogpage.ui \ - qt/forms/transactiondescdialog.ui \ - qt/forms/mainwindow.ui \ - qt/forms/newaccount.ui \ - qt/forms/homepage.ui \ - qt/forms/profilepage.ui \ - qt/forms/addcomment.ui \ - qt/forms/adminwindow.ui + qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -112,20 +106,7 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp \ - qt/moc_mainwindow.cpp \ - qt/moc_newaccount.cpp \ - qt/moc_profilepage.cpp \ - qt/moc_addcomment.cpp \ - qt/moc_posts.cpp \ - qt/moc_comment.cpp \ - qt/moc_Activity.cpp \ - qt/moc_user.cpp \ - qt/moc_fileman.cpp \ - qt/moc_qcustomplot.cpp \ - qt/moc_adminwindow.cpp \ - qt/moc_statistics.cpp \ - qt/moc_homepage.cpp + qt/moc_walletview.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -209,20 +190,7 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h \ - qt/mainwindow.h \ - qt/newaccount.h \ - qt/homepage.h \ - qt/profilepage.h \ - qt/addcomment.h \ - qt/posts.h \ - qt/comment.h \ - qt/Activity.h \ - qt/user.h \ - qt/fileman.h \ - qt/qcustomplot.h \ - qt/adminwindow.h \ - qt/statistics.h + qt/winshutdownmonitor.h RES_ICONS = \ @@ -562,21 +530,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp \ - qt/main.cpp \ - qt/mainwindow.cpp \ - qt/newaccount.cpp \ - qt/profilepage.cpp \ - qt/addcomment.cpp \ - qt/posts.cpp \ - qt/comment.cpp \ - qt/Activity.cpp \ - qt/user.cpp \ - qt/fileman.cpp \ - qt/qcustomplot.cpp \ - qt/adminwindow.cpp \ - qt/statistics.cpp \ - qt/homepage.cpp + qt/walletview.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From ac017695a11e8c45697e836fa70855ed9ef8a704 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:45:48 -0400 Subject: [PATCH 0454/1324] Add files via upload --- src/qt/qcc-core/abstractuser.cpp | 57 ++++ src/qt/qcc-core/abstractuser.h | 156 ++++++++++ src/qt/qcc-core/qcc-core.pro | 17 ++ src/qt/qcc-core/qccpacket.cpp | 73 +++++ src/qt/qcc-core/qccpacket.h | 293 +++++++++++++++++++ src/qt/qcc-server/main.cpp | 98 +++++++ src/qt/qcc-server/qcc-server.pro | 32 +++ src/qt/qcc-server/server.cpp | 479 +++++++++++++++++++++++++++++++ src/qt/qcc-server/server.h | 118 ++++++++ src/qt/qcc-server/user.cpp | 83 ++++++ src/qt/qcc-server/user.h | 175 +++++++++++ 11 files changed, 1581 insertions(+) create mode 100644 src/qt/qcc-core/abstractuser.cpp create mode 100644 src/qt/qcc-core/abstractuser.h create mode 100644 src/qt/qcc-core/qcc-core.pro create mode 100644 src/qt/qcc-core/qccpacket.cpp create mode 100644 src/qt/qcc-core/qccpacket.h create mode 100644 src/qt/qcc-server/main.cpp create mode 100644 src/qt/qcc-server/qcc-server.pro create mode 100644 src/qt/qcc-server/server.cpp create mode 100644 src/qt/qcc-server/server.h create mode 100644 src/qt/qcc-server/user.cpp create mode 100644 src/qt/qcc-server/user.h diff --git a/src/qt/qcc-core/abstractuser.cpp b/src/qt/qcc-core/abstractuser.cpp new file mode 100644 index 00000000..a50efb49 --- /dev/null +++ b/src/qt/qcc-core/abstractuser.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "abstractuser.h" + +const char* AbstractUser::StatusNames[] = { + "Offline", + "Online" +}; + +QString AbstractUser::statusString(Status status) +{ + return AbstractUser::StatusNames[status]; +} + +AbstractUser::AbstractUser(QObject *parent) : + QObject(parent), m_status(Offline) +{ +} + +AbstractUser::AbstractUser(const QString &username, QObject *parent) : + QObject(parent), m_username(username), m_status(Offline) +{ +} + +void AbstractUser::setStatus(Status status) +{ + if (status == m_status) + return; + + m_status = status; + emit statusChanged(); +} + +void AbstractUser::reset() +{ + setStatus(Offline); +} diff --git a/src/qt/qcc-core/abstractuser.h b/src/qt/qcc-core/abstractuser.h new file mode 100644 index 00000000..4126acc8 --- /dev/null +++ b/src/qt/qcc-core/abstractuser.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef ABSTRACTUSER_H +#define ABSTRACTUSER_H + +#include + +/*! + \defgroup core QCC core library + + The core library contains classes which are used in both other QCC-modules, + the \ref server "QCC-server" and the \ref client "QCC-client". + */ + +//! The AbstractUser class is the base class for all user objects. +/*! + \ingroup core + */ +class AbstractUser : public QObject +{ + Q_OBJECT + +public: + + //! This enum describes the different states in which a user can be. + /*! + \sa StatusNames + */ + enum Status { + Offline, //!< The user is offline. + Online //!< The user is online. + }; + + //! Returns a human-readable description of the status. + /*! + \param type The status. + \return The status as a \c QString. + */ + static QString statusString(Status type); + + //! Constructs an empty user. + /*! + \param parent The parent object. + */ + explicit AbstractUser(QObject *parent = 0); + + //! Constructs an user with the username set to \a username. + /*! + \param username The username. + \param parent The parent object. + */ + AbstractUser(const QString &username, QObject *parent = 0); + + //! Returns the username. + /*! + \return The username. + \sa setUsername() + */ + inline const QString& username() const { return m_username; } + + //! Returns the status. + /*! + \return The status. + \sa setStatus(), statusString(), statusChanged() + */ + inline Status status() const { return m_status; } + + //! Returns a human-readable description of the current status. + /*! + \return The status as a \c QString. + \sa status() + */ + inline QString statusString() const { return AbstractUser::StatusNames[m_status]; } + + //! Returns \c true if the user object is valid; otherwise returns \c false. + /*! + \return \c True if the user object is valid; otherwise returns \c false. + \sa invalidate() + */ + inline bool isValid() const { return !m_username.isEmpty(); } + + //! Invalidates the user object. + /*! + \sa isValid() + */ + inline void invalidate() { m_username.clear(); } + + //! Returns \c true if the user is online; otherwise returns \c false. + /*! + \return \c True if the user is online; otherwise returns \c false. + \sa status() + */ + inline bool isOnline() const { return m_status == Online; } + +signals: + + //! This signal is emitted whenever the user's status changes. + /*! + \sa status() + */ + void statusChanged(); + +public slots: + + //! Sets the username. + /*! + \param username The username. + \sa username() + */ + inline void setUsername(const QString &username) { m_username = username; } + + //! Sets the status. + /*! + \param status The status. + \sa status(), statusChanged() + */ + void setStatus(Status status); + + //! Resets the state of the user object. + virtual void reset(); + +protected: + + QString m_username; //!< The username. + Status m_status; //!< The status. + +private: + + //! The string representation of the the different user states. + /*! + \sa Status + */ + static const char *StatusNames[]; +}; + +#endif // ABSTRACTUSER_H diff --git a/src/qt/qcc-core/qcc-core.pro b/src/qt/qcc-core/qcc-core.pro new file mode 100644 index 00000000..e82870a7 --- /dev/null +++ b/src/qt/qcc-core/qcc-core.pro @@ -0,0 +1,17 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-01-25T13:46:15 +# +#------------------------------------------------- + +QT = core network + +TARGET = qcc-core +TEMPLATE = lib +CONFIG += staticlib create_prl + +HEADERS += qccpacket.h \ + abstractuser.h + +SOURCES += qccpacket.cpp \ + abstractuser.cpp diff --git a/src/qt/qcc-core/qccpacket.cpp b/src/qt/qcc-core/qccpacket.cpp new file mode 100644 index 00000000..f450fc77 --- /dev/null +++ b/src/qt/qcc-core/qccpacket.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "qccpacket.h" + +#include + +const char* QccPacket::PacketTypeNames[] = { + "ConnectionAccepted", + "ConnectionRefused", + "UserRegister", + "RegisterSuccess", + "RegisterFailure", + "UserAuthentication", + "AuthenticationSuccess", + "AuthenticationFailure", + "RequestAuthorization", + "AuthorizationAccepted", + "AuthorizationDeclined", + "AuthorizationFailure", + "RequestContactList", + "ContactList", + "ContactStatusChanged", + "RemoveContact", + "ContactRemoved", + "Message", + "MessageSuccess", + "MessageFailure", + "IllegalMessage" +}; + +QString QccPacket::typeString(PacketType type) +{ + return QccPacket::PacketTypeNames[type]; +} + +QccPacket::QccPacket(PacketType type) : + m_type(type), m_stream(&m_data, QIODevice::WriteOnly) +{ + m_stream.setVersion(QDataStream::Qt_4_0); + m_stream << (quint32)0; + m_stream << (qint32)type; +} + +bool QccPacket::send(QTcpSocket *socket) +{ + if (!socket || m_data.length() < int(sizeof(quint32) + sizeof(qint32))) // size + type + return false; + + m_stream.device()->seek(0); + m_stream << (quint32)size(); + + return socket->write(m_data) == m_data.size(); +} diff --git a/src/qt/qcc-core/qccpacket.h b/src/qt/qcc-core/qccpacket.h new file mode 100644 index 00000000..6d90670f --- /dev/null +++ b/src/qt/qcc-core/qccpacket.h @@ -0,0 +1,293 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef TCPPACKET_H +#define TCPPACKET_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTcpSocket; +QT_END_NAMESPACE + +//! The QccPacket class is used for sending custom TCP-packets over the network. +/*! + The QccPacket class defines the different packet types QCC needs for the network + communication beween the \ref server "QCC-server" and the \ref client "QCC-client".\n + + It is also used for sending QCC-packets over the network through the TCP.\n + + Each QCC-packet consists of three parts: + -# The size of the actual packet in bytes (\c quint32).\n + The size is defined by the size of the packet-type plus the size of the payload. + -# The type of the packet (encoded as \c qint32). + -# The actual data of the packet (payload) (the data-type depends on the packet-type).\n + The payload can also be empty, because some packet-types don't need any data. + + \ingroup core + \sa PacketType + */ +class QccPacket +{ +public: + + //! This enum describes the different types of QCC-packets. + /*! + \sa PacketTypeNames + */ + enum PacketType { + + //! The connection has been accepted by the QCC-server. + /*! + This packet has no payload. + */ + ConnectionAccepted, + + //! The connection has been refused by the QCC-server. + /*! + This packet has no payload. + */ + ConnectionRefused, + + //! The QCC-client sends a user registration. + /*! + Payload: + -# \c QString(username) + -# \c QString(passwort) - SHA-256 encoded hash + -# \c QByteArray(publicKey) - RSA public key in DER-format + */ + UserRegister, + + //! The QCC-server reports that the user registration has been successful. + /*! + This packet has no payload. + */ + RegisterSuccess, + + //! The QCC-server reports that an error occured with the user registration. + /*! + Payload: + -# \c QString(reason) - reason of the failure + */ + RegisterFailure, + + //! The QCC-client sends a user authentication (login). + /*! + Payload: + -# \c QString(username) + -# \c QString(passwort) - SHA-256 encoded hash + -# \c QByteArray(publicKey) - RSA public key in DER-format + */ + UserAuthentication, + + //! The QCC-server reports that the user authentication has been successful. + /*! + This packet has no payload. + */ + AuthenticationSuccess, + + //! The QCC-server reports that an error occured with the user authentication. + /*! + Payload: + -# \c QString(reason) - reason of the failure + */ + AuthenticationFailure, + + //! The QCC-client sends an authorization request to add another user to his contacts. + /*! + Payload: + -# \c QString(username) + + The username gets replaced by the server with the username of the sender, + so that the receiver knows from where the authorization request come from. + */ + RequestAuthorization, + + //! The authorization request has been accepted. + /*! + Payload: + -# \c QString(username) + -# \c qint32(status) - user status + -# \c QByteArray(publicKey) - RSA public key in DER-format + + The \a status and \a publicKey is appended by the server. + */ + AuthorizationAccepted, + + //! The authorization request has been declined. + /*! + Payload: + -# \c QString(username) + */ + AuthorizationDeclined, + + //! The QCC-server reports that an error occured with the authorization request. + /*! + Payload: + -# \c QString(reason) - reason of the failure + */ + AuthorizationFailure, + + //! The QCC-client requests his list of contacts. + /*! + This packet has no payload. + */ + RequestContactList, + + //! The QCC-server sends a list of the user's contacts. + /*! + Payload: + -# \c qint32(count) - user count + -# list of contacts (\a count user objects) + - user object + -# \c QString(username) + -# \c qint32(status) - user status + -# \c QByteArray(publicKey) - RSA public key in DER-format + - user object ... + */ + ContactList, + + //! The QCC-Server sends a status-changed-packet. + /*! + The status-changed-packet is send to all users which have the user + who changed the status on their contact list.\n + + Payload: + -# \c QString(username) - user who changed the status + -# \c qint32(status) - user status + -# \c QByteArray(publicKey) - RSA public key in DER-format + */ + ContactStatusChanged, + + //! The QCC-client sends a request to remove a user from his contacts. + /*! + Payload: + -# \c QString(username) + */ + RemoveContact, + + //! The QCC-Server confirms that the user has been removed from the contacts. + /*! + Payload: + -# \c QString(username) + */ + ContactRemoved, + + //! RSA-encrypted message from one user to another. + /*! + Payload: + -# \c qint32(messageId) - the message id is used for association with + the following \a MessageSuccess packet (if any) + -# \c QString(receiver|sender) - username of the sender/receiver + -# \c QByteArray(message) - RSA-encrypted message + */ + Message, + + //! Confirms that the message has been successfully delivered. + /*! + Payload: + -# \c qint32(messageId) - the message id is used for association with the message + -# \c QString(sender) - username of the sender + */ + MessageSuccess, + + //! The QCC-server reports that an error occured with the message. + /*! + Payload: + -# \c qint32(messageId) - the message id is used for association with the message + -# \c QString(receiver) - username of the receiver + -# \c QString(reason) - reason of the failure + */ + MessageFailure, + + //! Used for illegal packet types that don't match any valid packet type. + IllegalPacketType = -1 + }; + + //! Returns a human-readable description of the packet type. + /*! + \param type The packet type. + \return The status as a \c QString. + */ + static QString typeString(PacketType type); + + //! Constructs a QccPacket. + /*! + \param type The type of the packet. + */ + QccPacket(PacketType type = Message); + + //! Returns the packet type. + /*! + \return The packet type. + \sa typeString() + */ + inline PacketType type() const { return m_type; } + + //! Returns a human-readable description of the current packet type. + /*! + \return The status as a \c QString. + \sa type() + */ + inline QString typeString() const { return QccPacket::PacketTypeNames[m_type]; } + + //! Returns the packet data. + /*! + \return The packet data. + \sa stream() + */ + inline QByteArray& data() { return m_data; } + + //! Returns the internal data stream to provide easy data serialization. + /*! + \return The packet data stream. + \sa data() + */ + inline QDataStream& stream() { return m_stream; } + + //! Returns the size of the playload. + /*! + \return The size of the playload. + */ + inline int size() const { return m_data.size() - sizeof(quint32); } + + //! Writes the data to the \a socket and returns \c true on success. + /*! + \param socket The TCP-Socket. + \return \c True if the data was successfully written to the socket; otherwise returns \c false. + */ + bool send(QTcpSocket *socket); + +private: + //! The string representation of the the different types of QCC-packets. + /*! + \sa PacketType + */ + static const char *PacketTypeNames[]; + + PacketType m_type; //!< The packet type. + QByteArray m_data; //!< The packet data. + QDataStream m_stream; //!< The packet data stream. +}; + +#endif // TCPPACKET_H diff --git a/src/qt/qcc-server/main.cpp b/src/qt/qcc-server/main.cpp new file mode 100644 index 00000000..185b9cf7 --- /dev/null +++ b/src/qt/qcc-server/main.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include +#include + +#ifdef DEBUG +#include +#endif + +#include "server.h" + +/*! + \defgroup server QCC server module + + The QCC-server manages all registered users and observes + the package transfer between all connected \ref client "clients". + */ + +//! The default network port, on which the server will listen. +/*! + \ingroup server + */ +const quint16 DEFAULT_PORT = 54321; + +//! Helper function for reading a command line argument of type \c quint16. +/*! + \param arguments The list of command-line arguments. + \param name The name of the agument. + \param defaultValue The default value for the argument, in case there + is none or an error occurred while processing it. + \return The value of the argument interpreted as an \c quint16 or the \a defaultValue. + \ingroup server + */ +quint16 readUShort(const QStringList &arguments, const QString &name, quint16 defaultValue = 0) +{ + if (arguments.isEmpty()) + return defaultValue; + + int index = arguments.indexOf(name); + if (index < 0 || index + 1 >= arguments.count()) + return defaultValue; + + bool ok; + quint16 value = arguments.at(index + 1).toUShort(&ok); + return ok ? value : defaultValue; +} + +//! The main entry point of this application. +/*! + \param argc The command-line argument count. + \param argv The command-line argument-array. + \return The return code of the application + \ingroup server + */ +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QStringList arguments = QCoreApplication::arguments(); + +#ifdef DEBUG + qDebug() << "QCC server started with arguments:" << arguments; +#endif + + QHostAddress adress = QHostAddress::Any; + quint16 port = readUShort(arguments, "-port", DEFAULT_PORT); + + Server server; + if (server.listen(adress, port)) { + qDebug("The server is listening on interface %s, port %i", + qPrintable(server.serverAddress().toString()), server.serverPort()); + } else { + qCritical("Failed to start the server on interface %s, port %i: %s (error code %i)", + qPrintable(adress.toString()), port, qPrintable(server.errorString()), server.serverError()); + return 1; + } + + return app.exec(); +} diff --git a/src/qt/qcc-server/qcc-server.pro b/src/qt/qcc-server/qcc-server.pro new file mode 100644 index 00000000..91398ee1 --- /dev/null +++ b/src/qt/qcc-server/qcc-server.pro @@ -0,0 +1,32 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-01-23T16:09:56 +# +#------------------------------------------------- + +QT = core network + +TARGET = qcc-server +TEMPLATE = app +CONFIG += console link_prl +CONFIG -= app_bundle + +QCC_CORE_PREFIX = ../qcc-core + +CONFIG(debug, debug|release) { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug +} else { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release +} + +INCLUDEPATH += ../qcc-core +LIBS += -L$$QCC_CORE_PREFIX -lqcc-core + +HEADERS += server.h \ + user.h + +SOURCES += main.cpp \ + server.cpp \ + user.cpp diff --git a/src/qt/qcc-server/server.cpp b/src/qt/qcc-server/server.cpp new file mode 100644 index 00000000..3b2b8ba7 --- /dev/null +++ b/src/qt/qcc-server/server.cpp @@ -0,0 +1,479 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "server.h" +#include "qccpacket.h" +#include "user.h" + +#include +#include +#include +#include + +#ifdef DEBUG +#include +#endif + +const QString Server::USERS_FILE = "users.xml"; + +Server::Server(QObject *parent) : + QTcpServer(parent) +{ + loadUsers(); +} + +Server::~Server() +{ + qDeleteAll(m_clients.values()); + qDeleteAll(m_users.values()); +} + +void Server::loadUsers() +{ +#ifdef DEBUG + qDebug("Server::loadUsers()"); +#endif + + QFile file(Server::USERS_FILE); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Server::loadUsers(): cannot read file users.xml => %s", qPrintable(file.errorString())); + return; + } + m_users.clear(); + QXmlStreamReader xml(&file); + while (!xml.atEnd()) { + if (!xml.readNextStartElement()) + continue; + if (xml.name() == "user") { + User *user = User::readUser(xml); + if (user && user->isValid()) { + connect(user, SIGNAL(statusChanged()), SLOT(client_statusChanged())); + m_users.insert(user->username(), user); +#ifdef DEBUG + qDebug() << "user:" << user->username() << "contacts =" << user->contacts(); +#endif + } + } + } + if (xml.hasError()) { + qCritical("Server::loadUsers(): parse error in file users.xml => %s: line %li, column %li", + qPrintable(xml.errorString()), (long)xml.lineNumber(), (long)xml.columnNumber()); + } + file.close(); + +#ifdef DEBUG + qDebug("Server::loadUsers(): %i users read from users.xml", m_users.count()); +#endif +} + +void Server::saveUsers() +{ +#ifdef DEBUG + qDebug("Server::saveUsers()"); +#endif + + QFile file(Server::USERS_FILE); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + qWarning("Server::saveUsers(): cannot write file users.xml => %s", qPrintable(file.errorString())); + return; + } + QXmlStreamWriter xml(&file); + xml.setAutoFormatting(true); + xml.writeStartDocument(); + xml.writeStartElement("users"); + foreach (User *user, m_users) + user->writeUser(xml); + xml.writeEndElement(); + xml.writeEndDocument(); + file.close(); + +#ifdef DEBUG + qDebug("Server::saveUsers(): %i users written to users.xml", m_users.count()); +#endif +} + +void Server::incomingConnection(int socketDescriptor) +{ + QTcpSocket *socket = new QTcpSocket(this); + socket->setSocketDescriptor(socketDescriptor); + addPendingConnection(socket); + +#ifdef DEBUG + qDebug("\nServer::incomingConnection(%i): %s:%i", socketDescriptor, + qPrintable(socket->peerAddress().toString()), socket->peerPort()); +#endif + + connect(socket, SIGNAL(disconnected()), SLOT(client_disconnected())); + connect(socket, SIGNAL(readyRead()), SLOT(client_readyRead())); + + m_clients.insert(socket, new Client); + QccPacket(QccPacket::ConnectionAccepted).send(socket); // QccPacket::ConnectionRefused + +#ifdef DEBUG + qDebug("ConnectionAccepted"); +#endif +} + +void Server::client_disconnected() +{ + QTcpSocket *socket = qobject_cast(sender()); + if (!socket) { + qWarning("Server::client_disconnected(): Cast of sender() to QTcpSocket* failed"); + return; + } + + Client *client = m_clients[socket]; + User *user = client->user; + if (user) + user->reset(); + +#ifdef DEBUG + QString username = user ? user->username() : "[no user object]"; + qDebug("\nServer::client_disconnected(): '%s' (%s:%i)", qPrintable(username), + qPrintable(socket->peerAddress().toString()), socket->peerPort()); +#endif + + m_clients.remove(socket); + delete client; +} + +void Server::client_readyRead() +{ + QTcpSocket *socket = qobject_cast(sender()); + if (!socket) { + qWarning("Server::client_readyRead(): Cast of sender() to QTcpSocket* failed"); + return; + } + +#ifdef DEBUG + qDebug("\nServer::client_readyRead(): %li bytes available", (long)socket->bytesAvailable()); +#endif + + Client *client = m_clients[socket]; + QDataStream in(socket); + in.setVersion(QDataStream::Qt_4_0); + if (client->packetSize == 0) { + if (socket->bytesAvailable() < (int)sizeof(quint32)) // packet size + return; + in >> client->packetSize; + } + if (socket->bytesAvailable() < client->packetSize) + return; + client->packetSize = 0; // reset packet size + + qint32 type; + in >> type; + +#ifdef DEBUG + qDebug("PacketType %i (%s) from '%s' (%s:%i)", type, + qPrintable(QccPacket::typeString((QccPacket::PacketType)type)), + qPrintable(client->user ? client->user->username() : "[no user object]"), + qPrintable(socket->peerAddress().toString()), socket->peerPort()); +#endif + + switch ((QccPacket::PacketType)type) { + case QccPacket::UserRegister: + { + QString username, password; + QByteArray publicKey; + in >> username >> password >> publicKey; +#ifdef DEBUG + qDebug("Username = '%s' password = '%s'", qPrintable(username), qPrintable(password)); +#endif + if (username.isEmpty()) { + QString reason = "The username cannot be empty."; + QccPacket packet(QccPacket::RegisterFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("RegisterFailure: %s", qPrintable(reason)); +#endif + break; + } + if (m_users.contains(username)) { + QString reason = QString("The username \"%1\" is not available.").arg(username); + QccPacket packet(QccPacket::RegisterFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("RegisterFailure: %s", qPrintable(reason)); +#endif + break; + } +#ifdef DEBUG + qDebug("RegisterSuccess"); +#endif + User *user = new User(username, password); + user->setPublicKey(publicKey); + user->setSocket(socket); + connect(user, SIGNAL(statusChanged()), SLOT(client_statusChanged())); + user->setStatus(User::Online); + m_users.insert(username, user); + saveUsers(); + client->user = user; + QccPacket(QccPacket::RegisterSuccess).send(socket); + break; + } + case QccPacket::UserAuthentication: + { + QString username, password; + QByteArray publicKey; + in >> username >> password >> publicKey; +#ifdef DEBUG + qDebug("Username = '%s' password = '%s'", qPrintable(username), qPrintable(password)); +#endif + User *user = m_users.contains(username) ? m_users[username] : NULL; + if (user && user->matchPassword(password)) { +#ifdef DEBUG + qDebug("AuthenticationSuccess"); +#endif + user->setPublicKey(publicKey); + user->setSocket(socket); + user->setStatus(User::Online); + client->user = user; + QccPacket(QccPacket::AuthenticationSuccess).send(socket); + } else { + QString reason = "The username or password you entered is incorrect."; + QccPacket packet(QccPacket::AuthenticationFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("AuthenticationFailure: %s", qPrintable(reason)); +#endif + } + break; + } + case QccPacket::RequestAuthorization: + { + QString username; + in >> username; + if (!m_users.contains(username)) { + QString reason = QString("The user \"%1\" does not exist.").arg(username); + QccPacket packet(QccPacket::AuthorizationFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("AuthorizationFailure: %s", qPrintable(reason)); +#endif + break; + } + if (client->user->username() == username) { + QString reason = QString("You cannot add yourself."); + QccPacket packet(QccPacket::AuthorizationFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("AuthorizationFailure: %s", qPrintable(reason)); +#endif + break; + } + if (client->user->containsContact(username)) { + QString reason = QString("The user \"%1\" is already on your contact list.").arg(username); + QccPacket packet(QccPacket::AuthorizationFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("AuthorizationFailure: %s", qPrintable(reason)); +#endif + break; + } + User *receiver = m_users.value(username); + if (receiver && receiver->isOnline()) { + QccPacket packet(QccPacket::RequestAuthorization); + packet.stream() << client->user->username(); + packet.send(receiver->socket()); +#ifdef DEBUG + qDebug("RequestAuthorization: forwarded to '%s'", qPrintable(username)); +#endif + } else { + QString reason = QString("The user \"%1\" is not online.").arg(username); + QccPacket packet(QccPacket::AuthorizationFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("AuthorizationFailure: %s", qPrintable(reason)); +#endif + } + break; + } + case QccPacket::AuthorizationAccepted: + { + QString username; + in >> username; + if (username.isEmpty()) + break; + User *receiver = m_users[username]; + if (receiver && receiver->isOnline()) { + receiver->addContact(client->user->username()); + client->user->addContact(username); + saveUsers(); + QccPacket packet(QccPacket::AuthorizationAccepted); + packet.stream() << client->user->username() << (qint32)client->user->status() << client->user->publicKey(); + packet.send(receiver->socket()); + QccPacket packet2(QccPacket::AuthorizationAccepted); + packet2.stream() << username << (qint32)receiver->status() << receiver->publicKey(); + packet2.send(socket); + } +#ifdef DEBUG + qDebug("AuthorizationAccepted: forwarded to '%s'", qPrintable(username)); +#endif + break; + } + case QccPacket::AuthorizationDeclined: + { + QString username; + in >> username; + if (username.isEmpty()) + break; + User *receiver = m_users.value(username); + if (receiver && receiver->isOnline()) { + QccPacket packet(QccPacket::AuthorizationDeclined); + packet.stream() << client->user->username(); + packet.send(receiver->socket()); + } +#ifdef DEBUG + qDebug("AuthorizationDeclined: forwarded to '%s'", qPrintable(username)); +#endif + break; + } + case QccPacket::RequestContactList: + { + QccPacket packet(QccPacket::ContactList); + QSet contacts = client->user->contacts(); + packet.stream() << (qint32)contacts.count(); + foreach (const QString &contactName, contacts) { + User *contact = m_users.value(contactName); + if (!contact) continue; + packet.stream() << contactName << qint32(contact->status()) << contact->publicKey(); + } + packet.send(socket); +#ifdef DEBUG + qDebug("ContactList: %i contacts send", contacts.count()); +#endif + break; + } + case QccPacket::RemoveContact: + { + QString username; + in >> username; + if (client->user->removeContact(username)) { + QccPacket packet(QccPacket::ContactRemoved); + packet.stream() << username; + packet.send(socket); + User *receiver = m_users[username]; + if (receiver && receiver->removeContact(client->user->username()) && receiver->isOnline()) { + QccPacket packet2(QccPacket::ContactRemoved); + packet2.stream() << client->user->username(); + packet2.send(receiver->socket()); + } + saveUsers(); +#ifdef DEBUG + qDebug("ContactRemoved: contact '%s' removed", qPrintable(username)); +#endif + } + break; + } + case QccPacket::Message: + { + qint32 id; + QString receiverName; + QString message; + in >> id >> receiverName >> message; + if (!client->user->containsContact(receiverName)) { + QString reason = QString("The user \"%1\" is not on your contact list.").arg(receiverName); + QccPacket packet(QccPacket::MessageFailure); + packet.stream() << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("MessageFailure: %s", qPrintable(reason)); +#endif + break; + } + User *receiver = m_users.value(receiverName); + if (receiver && receiver->isOnline()) { + QccPacket packet(QccPacket::Message); + packet.stream() << id << client->user->username() << message; + packet.send(receiver->socket()); +#ifdef DEBUG + qDebug("Message: forwarded to '%s'", qPrintable(receiverName)); +#endif + } else { + QString reason = QString("The user \"%1\" is not online.").arg(receiverName); + QccPacket packet(QccPacket::MessageFailure); + packet.stream() << id << receiverName << reason; + packet.send(socket); +#ifdef DEBUG + qDebug("MessageFailure: failed to forward to '%s' => %s", + qPrintable(receiverName), qPrintable(reason)); +#endif + } + break; + } + case QccPacket::MessageSuccess: + { + qint32 id; + QString receiverName; + in >> id >> receiverName; + User *receiver = m_users.value(receiverName); + if (receiver && receiver->isOnline()) { + QccPacket packet(QccPacket::MessageSuccess); + packet.stream() << id << client->user->username(); + packet.send(receiver->socket()); +#ifdef DEBUG + qDebug("MessageSuccess: forwarded to '%s'", qPrintable(receiverName)); +#endif + } + break; + } + default: + qWarning("Server::client_readyRead(): Illegal PacketType %i", type); + return; + } +} + +void Server::client_statusChanged() +{ + User *user = qobject_cast(sender()); + if (!user) { + qWarning("Server::client_statusChanged(): Cast of sender() to User* failed"); + return; + } + +#ifdef DEBUG + qDebug("\nServer::client_statusChanged(): '%s' => %i (%s)", + qPrintable(user->username()), user->status(), qPrintable(user->statusString())); +#endif + + // inform all online users that have this user on their contact list of the status change + QccPacket packet(QccPacket::ContactStatusChanged); + packet.stream() << user->username() << (qint32)user->status() << user->publicKey(); + foreach (Client *client, m_clients.values()) { + if (client->user == NULL) + continue; + if (client->user->containsContact(user->username())) { + packet.send(client->user->socket()); +#ifdef DEBUG + qDebug("ContactStatusChanged: send to contact '%s'", qPrintable(client->user->username())); +#endif + } + } +} diff --git a/src/qt/qcc-server/server.h b/src/qt/qcc-server/server.h new file mode 100644 index 00000000..b0353485 --- /dev/null +++ b/src/qt/qcc-server/server.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef SERVER_H +#define SERVER_H + +#include +#include + +class User; + +//! The Server class provides a custom TCP-based server. +/*! + The Server class provides a custom TCP-based server with user + management and robust network management of multiple clients. + + \ingroup server + */ +class Server : public QTcpServer +{ + Q_OBJECT + +public: + + //! Constructs a QCC-server object. + /*! + \param parent The parent object. + \sa QTcpServer::listen() + */ + explicit Server(QObject *parent = 0); + + //! Destroys the QCC-server object. + /*! + \sa QTcpServer::~QTcpServer() + */ + ~Server(); + + //! Loads all users from the local file system into memory. + /*! + \sa USERS_FILE, saveUsers() + */ + void loadUsers(); + + //! Saves all users to the local file system for persistent storage. + /*! + \sa USERS_FILE, loadUsers() + */ + void saveUsers(); + +private slots: + + //! This signal is emitted when the client's socket has been disconnected. + /*! + \sa incomingConnection(), QAbstractSocket::disconnected() + */ + void client_disconnected(); + + //! This signal is emitted once every time new data is available for reading from the client's socket. + /*! + \sa QIODevice::readyRead() + */ + void client_readyRead(); + + //! This signal is emitted whenever the client's status changes. + /*! + \sa AbstractUser::statusChanged() + */ + void client_statusChanged(); + +private: + + //! The internal Client struct provides a thin wrapper for a User-object and the packet size. + struct Client { + + //! Constructs a Client object with the packet size set to \c 0. + /*! + \param u The user object or \c NULL if there is not any user yet. + */ + explicit inline Client(User *u = NULL) : packetSize(0), user(u) { } + + quint32 packetSize; //!< The packet size of the incoming QccPacket. + User *user; //!< A reference to the actual user object. + }; + + //! The filename for the persistent user storage (stored in XML-format). + static const QString USERS_FILE; + + QHash m_users; //!< The hash-table for all user objects on this server. + QHash m_clients; //!< The hash-table holds track of all connected clients. + + //! This virtual function is called by \c QTcpServer when a new connection is available. + /*! + \param socketDescriptor The native socket descriptor for the accepted connection. + \sa client_disconnected(), QTcpServer::incomingConnection() + */ + void incomingConnection(int socketDescriptor); +}; + +#endif // SERVER_H diff --git a/src/qt/qcc-server/user.cpp b/src/qt/qcc-server/user.cpp new file mode 100644 index 00000000..fca95a3b --- /dev/null +++ b/src/qt/qcc-server/user.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "user.h" + +#include + +User::User(QObject *parent) : + AbstractUser(parent), m_socket(NULL) +{ +} + +User::User(const QString &username, const QString &password, QObject *parent) : + AbstractUser(username, parent), m_password(password), m_socket(NULL) +{ +} + +User* User::readUser(QXmlStreamReader &xml) +{ + QXmlStreamAttributes attr = xml.attributes(); + QString username = attr.value("username").toString(); + QString password = attr.value("password").toString(); + User *user = new User(username, password); + while (!xml.atEnd()) { + switch (xml.readNext()) { + case QXmlStreamReader::Invalid: + return NULL; + case QXmlStreamReader::StartElement: + if (xml.name() == "contact") { + if (xml.readNext() == QXmlStreamReader::Characters) { + QString contactName = xml.text().toString(); + user->addContact(contactName); + } + } + break; + case QXmlStreamReader::EndElement: + if (xml.name() == "user") + return user; + else + break; + default: + break; + } + } + return NULL; +} + +void User::writeUser(QXmlStreamWriter &xml) +{ + xml.writeStartElement("user"); + xml.writeAttribute("username", m_username); + xml.writeAttribute("password", m_password); + xml.writeStartElement("contacts"); + foreach (const QString &contactName, m_contacts) + xml.writeTextElement("contact", contactName); + xml.writeEndElement(); + xml.writeEndElement(); +} + +void User::reset() +{ + m_socket = NULL; + AbstractUser::reset(); +} diff --git a/src/qt/qcc-server/user.h b/src/qt/qcc-server/user.h new file mode 100644 index 00000000..2cdd8524 --- /dev/null +++ b/src/qt/qcc-server/user.h @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef USER_H +#define USER_H + +#include "abstractuser.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QTcpSocket; +QT_END_NAMESPACE + +//! The User class represents a single user on the server. +/*! + \ingroup server + */ +class User : public AbstractUser +{ + Q_OBJECT + +public: + + //! Constructs an empty user. + /*! + \param parent The parent object. + */ + explicit User(QObject *parent = 0); + + //! Constructs an user with a username and password. + /*! + \param username The username. + \param password The password. + \param parent The parent object. + */ + User(const QString &username, const QString &password, QObject *parent = 0); + + //! Returns the password. + /*! + \return The password. + \sa setPassword(), matchPassword() + */ + inline const QString& password() const { return m_password; } + + //! Returns the set of contacts. + /*! + \return The set of contacts. + \sa addContact(), containsContact(), removeContact(), clearContacts() + */ + inline const QSet& contacts() const { return m_contacts; } + + //! Returns the RSA public key in DER-format. + /*! + \return The RSA public key in DER-format. + \sa setPublicKey() + */ + inline const QByteArray& publicKey() const { return m_publicKey; } + + //! Returns the TCP-socket. + /*! + \return The TCP-socket. + \sa setSocket() + */ + inline QTcpSocket* socket() const { return m_socket; } + + //! Adds a contact to the user's set of contacts. + /*! + \param username The username of the contact. + \note If the user already has this contact on his set of contacts, nothing happens. + \sa contacts(), containsContact() + */ + inline void addContact(const QString &username) { m_contacts.insert(username); } + + //! Checks whether the user's set of contacts contains an user. + /*! + \param username The username of the contact to check. + \return \c True if the user's set of contacts contains the contact; otherwise returns \c false. + \sa contacts(), addContact(), removeContact() + */ + inline bool containsContact(const QString &username) const { return m_contacts.contains(username); } + + //! Removes a contact from the user's set of contacts. + /*! + \param username The username of the contact to remove. + \return \c True if the contact has been removed; otherwise returns \c false. + \sa contacts(), containsContact(), clearContacts() + */ + inline bool removeContact(const QString &username) { return m_contacts.remove(username); } + + //! Removes all contact from the user's set of contacts. + /*! + \sa contacts(), removeContact() + */ + inline void clearContacts() { m_contacts.clear(); } + + //! Compares the user's password with another one. + /*! + \param password The password to compare with. + \return \c True if the passwords match; otherwise returns \c false. + \sa password() + */ + inline bool matchPassword(const QString &password) const { return m_password == password; } + + //! Reads one user from the given XML-stream. + /*! + \param xml The XML-stream from which the user will be read. + \return The read user object or \c NULL if an error occured. + \sa writeUser() + */ + static User* readUser(QXmlStreamReader &xml); + + //! Writes this user to the given XML-stream. + /*! + \param xml The XML-stream to which the user will be written. + \sa readUser() + */ + void writeUser(QXmlStreamWriter &xml); + +public slots: + + //! Sets the password. + /*! + \param password The password. + \sa password() + */ + void setPassword(const QString &password) { m_password = password; } + + //! Sets the public key. + /*! + \param publicKey The RSA public key in DER-format. + \sa publicKey() + */ + void setPublicKey(const QByteArray &publicKey) { m_publicKey = publicKey; } + + //! Sets the TCP-socket. + /*! + \param socket The TCP-socket. + \sa socket() + */ + void setSocket(QTcpSocket *socket) { m_socket = socket; } + + //! Resets the state of the user object. + void reset(); + +private: + + QString m_password; //!< The password (should be in some cryptographic hash format). + QSet m_contacts; //!< The set of contacts. + QByteArray m_publicKey; //!< RSA public key in DER-format. + QTcpSocket *m_socket; //!< The TCP-socket. +}; + +#endif // USER_H From 4257c4be34b0b08ec72a595da2c8bc84236bef85 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:46:53 -0400 Subject: [PATCH 0455/1324] Add files via upload --- src/qt/qcc/contact.cpp | 84 +++++++ src/qt/qcc/contact.h | 93 ++++++++ src/qt/qcc/contactlistmodel.cpp | 149 ++++++++++++ src/qt/qcc/contactlistmodel.h | 135 +++++++++++ src/qt/qcc/icons.qrc | 7 + src/qt/qcc/icons/offline.png | Bin 0 -> 3270 bytes src/qt/qcc/icons/online.png | Bin 0 -> 3271 bytes src/qt/qcc/icons/qcc.ico | Bin 0 -> 140206 bytes src/qt/qcc/icons/qcc128a.png | Bin 0 -> 5538 bytes src/qt/qcc/main.cpp | 48 ++++ src/qt/qcc/mainwindow.cpp | 403 ++++++++++++++++++++++++++++++++ src/qt/qcc/mainwindow.h | 144 ++++++++++++ src/qt/qcc/mainwindow.ui | 244 +++++++++++++++++++ src/qt/qcc/messagepage.cpp | 98 ++++++++ src/qt/qcc/messagepage.h | 109 +++++++++ src/qt/qcc/messagepage.ui | 104 +++++++++ src/qt/qcc/messagewindow.cpp | 146 ++++++++++++ src/qt/qcc/messagewindow.h | 116 +++++++++ src/qt/qcc/messagewindow.ui | 28 +++ src/qt/qcc/qcc.pro | 50 ++++ src/qt/qcc/qcc.rc | 1 + src/qt/qcc/registerdialog.cpp | 69 ++++++ src/qt/qcc/registerdialog.h | 74 ++++++ src/qt/qcc/registerdialog.ui | 121 ++++++++++ 24 files changed, 2223 insertions(+) create mode 100644 src/qt/qcc/contact.cpp create mode 100644 src/qt/qcc/contact.h create mode 100644 src/qt/qcc/contactlistmodel.cpp create mode 100644 src/qt/qcc/contactlistmodel.h create mode 100644 src/qt/qcc/icons.qrc create mode 100644 src/qt/qcc/icons/offline.png create mode 100644 src/qt/qcc/icons/online.png create mode 100644 src/qt/qcc/icons/qcc.ico create mode 100644 src/qt/qcc/icons/qcc128a.png create mode 100644 src/qt/qcc/main.cpp create mode 100644 src/qt/qcc/mainwindow.cpp create mode 100644 src/qt/qcc/mainwindow.h create mode 100644 src/qt/qcc/mainwindow.ui create mode 100644 src/qt/qcc/messagepage.cpp create mode 100644 src/qt/qcc/messagepage.h create mode 100644 src/qt/qcc/messagepage.ui create mode 100644 src/qt/qcc/messagewindow.cpp create mode 100644 src/qt/qcc/messagewindow.h create mode 100644 src/qt/qcc/messagewindow.ui create mode 100644 src/qt/qcc/qcc.pro create mode 100644 src/qt/qcc/qcc.rc create mode 100644 src/qt/qcc/registerdialog.cpp create mode 100644 src/qt/qcc/registerdialog.h create mode 100644 src/qt/qcc/registerdialog.ui diff --git a/src/qt/qcc/contact.cpp b/src/qt/qcc/contact.cpp new file mode 100644 index 00000000..abf654ef --- /dev/null +++ b/src/qt/qcc/contact.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "contact.h" + +QIcon Contact::OfflineIcon; +QIcon Contact::OnlineIcon; + +Contact::Contact(QObject *parent) : + AbstractUser(parent) +{ + init(); +} + +Contact::Contact(const QString &username, QObject *parent) : + AbstractUser(username, parent) +{ + init(); +} + +void Contact::init() +{ + if (Contact::OfflineIcon.isNull()) { + Contact::OfflineIcon = QIcon(":/icons/offline.png"); + Contact::OnlineIcon = QIcon(":/icons/online.png"); + } +} + +void Contact::setPublicKey(const QByteArray &publicKey) +{ + if (publicKey.isEmpty()) // should only happen if the contact is offline + return; + + QCA::ConvertResult conversionResult; + m_publicKey = QCA::PublicKey::fromDER(publicKey, &conversionResult); + if (conversionResult != QCA::ConvertGood || !m_publicKey.canEncrypt()) + qWarning("Contact::setPublicKey: not a valid public key"); +} + +QIcon Contact::statusIcon() const +{ + switch (m_status) { + case Offline: return Contact::OfflineIcon; + case Online: return Contact::OnlineIcon; + default: return QIcon(); + } +} + +QByteArray Contact::encrypt(const QString &text) +{ + QByteArray bytes = text.toAscii(); + QCA::SecureArray result; + + static const int padding = 42; // always constant? + const int keySize = m_publicKey.bitSize() / 8; + const int blockSize = keySize - padding; + + for (int i = 0; i < bytes.length(); i += blockSize) + result.append(m_publicKey.encrypt(bytes.mid(i, blockSize), QCA::EME_PKCS1_OAEP)); + + if (result.isEmpty()) + qWarning("Error encrypting"); + + return result.toByteArray(); +} diff --git a/src/qt/qcc/contact.h b/src/qt/qcc/contact.h new file mode 100644 index 00000000..f4aebacd --- /dev/null +++ b/src/qt/qcc/contact.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef CONTACT_H +#define CONTACT_H + +#include "abstractuser.h" + +#include +#include + +//! The Contact class represents a single user on the client. +/*! + \ingroup client + */ +class Contact : public AbstractUser +{ + Q_OBJECT + +public: + + //! Constructs an empty contact. + /*! + \param parent The parent object. + */ + explicit Contact(QObject *parent = 0); + + //! Constructs a contact with a username. + /*! + \param username The username. + \param parent The parent object. + */ + Contact(const QString &username, QObject *parent = 0); + + //! Returns the RSA public. + /*! + \return The RSA public key. + \sa setPublicKey() + */ + inline const QCA::PublicKey& publicKey() const { return m_publicKey; } + + //! Sets the public key. + /*! + \param publicKey The RSA public key in DER-format. + \sa publicKey() + */ + void setPublicKey(const QByteArray &publicKey); + + //! Returns the status icon. + /*! + \return The status icon. + \sa AbstractUser::status() + */ + QIcon statusIcon() const; + + //! Returns the encrypted \a text with the RSA public key. + /*! + \return The encrypted \a text. + \sa publicKey() + */ + QByteArray encrypt(const QString &text); + +private: + + //! The status icons. + static QIcon OfflineIcon, OnlineIcon; + + QCA::PublicKey m_publicKey; //!< The RSA public key. + + //! Initializes the static icons. + void init(); +}; + +#endif // CONTACT_H diff --git a/src/qt/qcc/contactlistmodel.cpp b/src/qt/qcc/contactlistmodel.cpp new file mode 100644 index 00000000..69aea984 --- /dev/null +++ b/src/qt/qcc/contactlistmodel.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "contactlistmodel.h" +#include "contact.h" + +ContactListModel::ContactListModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +ContactListModel::~ContactListModel() +{ + qDeleteAll(m_contacts); +} + +int ContactListModel::rowCount(const QModelIndex &) const +{ + return m_contacts.count(); +} + +QVariant ContactListModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() >= m_contacts.count()) + return QVariant(); + + if (role == Qt::DisplayRole) + return m_contacts.at(index.row())->username(); + else if (role == Qt::DecorationRole) + return m_contacts.at(index.row())->statusIcon(); + + return QVariant(); +} + +void ContactListModel::add(Contact *contact) +{ + if (!contact) + return; + + beginInsertRows(QModelIndex(), m_contacts.count(), m_contacts.count()); + connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); + m_contacts.append(contact); + endInsertRows(); +} + +void ContactListModel::add(const QList &contacts) +{ + if (contacts.count() == 0) + return; + + beginInsertRows(QModelIndex(), m_contacts.count(), m_contacts.count() + contacts.count()); + foreach (Contact *contact, contacts) + connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); + m_contacts.append(contacts); + endInsertRows(); +} + +bool ContactListModel::remove(const Contact *contact) +{ + if (!contact) + return false; + + return remove(contact->username()); +} + +bool ContactListModel::remove(const QString &contactName) +{ + for (int i = 0; i < m_contacts.count(); i++) { + if (m_contacts.at(i)->username() == contactName) + return remove(index(i)); + } + return false; +} + +bool ContactListModel::remove(const QModelIndex &index) +{ + if (!index.isValid() || index.row() >= m_contacts.count()) + return false; + + beginRemoveRows(QModelIndex(), index.row(), index.row()); + delete m_contacts[index.row()]; + m_contacts.removeAt(index.row()); + endRemoveRows(); + + return true; +} + +void ContactListModel::clear() +{ + if (m_contacts.count() == 0) + return; + + beginResetModel(); + qDeleteAll(m_contacts); + m_contacts.clear(); + endResetModel(); +} + +Contact* ContactListModel::contact(const QString &contactName) +{ + foreach (Contact *contact, m_contacts) { + if (contact && contact->username() == contactName) + return contact; + } + return NULL; +} + +Contact* ContactListModel::contact(const QModelIndex &index) +{ + if (!index.isValid() || index.row() >= m_contacts.count()) + return NULL; + + return m_contacts.at(index.row()); +} + +void ContactListModel::contact_statusChanged() +{ + Contact *contact = qobject_cast(sender()); + if (!contact) { + qWarning("ContactListModel::contact_statusChanged(): Cast of sender() to Contact* failed"); + return; + } + + int listIndex = m_contacts.indexOf(contact); + if (listIndex < 0) + return; + + QModelIndex modelIndex = index(listIndex); + dataChanged(modelIndex, modelIndex); +} diff --git a/src/qt/qcc/contactlistmodel.h b/src/qt/qcc/contactlistmodel.h new file mode 100644 index 00000000..043288e0 --- /dev/null +++ b/src/qt/qcc/contactlistmodel.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef CONTACTLISTMODEL_H +#define CONTACTLISTMODEL_H + +#include +#include + +class Contact; + +//! The ContactListModel class provides a model to store and manage a list of contacts. +/*! + \ingroup client + \sa Contact + */ +class ContactListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + + //! Constructs an empty ContactListModel. + /*! + \param parent The parent object. + */ + explicit ContactListModel(QObject *parent = 0); + + //! Destroys the ContactListModel. + ~ContactListModel(); + + //! Returns contact count. + /*! + \return The contact count. + */ + int rowCount(const QModelIndex &) const; + + //! Returns the data stored under the given \a role for the contact referred to by the \a index. + /*! + \param index The index for the contact. + \param role The role. + \return The data. + \sa contact() + */ + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + //! Returns the contact with the given \a name. + /*! + \param contactName The name of the contact. + \return The contact. + \sa data() + */ + Contact* contact(const QString &contactName); + + //! Returns the contact with the given \a index. + /*! + \param index The index of the contact. + \return The contact. + \sa data(), add() + */ + Contact* contact(const QModelIndex &index); + + //! Adds a new contact to this model. + /*! + \param contact The contact to add. + \sa contact(), remove() + */ + void add(Contact *contact); + + //! Adds a list of contacts to this model. + /*! + \param contacts The list of contacts to add. + \sa remove(), clear() + */ + void add(const QList &contacts); + + //! Removes the \a contact from this model. + /*! + \param contact The contact to remove. + \return \c True if the contact was removed; returns \c false otherwise. + \sa add(), clear() + */ + bool remove(const Contact *contact); + + //! Removes the contact with the given \a name from this model. + /*! + \param contactName The name of the contact to remove. + \return \c True if the contact was removed; returns \c false otherwise. + \sa add(), clear() + */ + bool remove(const QString &contactName); + + //! Removes the contact with the given \a index from this model. + /*! + \param index The index of the contact to remove. + \return \c True if the contact was removed; returns \c false otherwise. + \sa add(), clear() + */ + bool remove(const QModelIndex &index); + +public slots: + + //! Removes all contacts from this model. + void clear(); + +private slots: + + //! This slot should be called from a \a contact whenever the status changes. + void contact_statusChanged(); + +private: + + QList m_contacts; //!< The list of contacts. +}; + +#endif // CONTACTLISTMODEL_H diff --git a/src/qt/qcc/icons.qrc b/src/qt/qcc/icons.qrc new file mode 100644 index 00000000..d6f31da0 --- /dev/null +++ b/src/qt/qcc/icons.qrc @@ -0,0 +1,7 @@ + + + icons/offline.png + icons/online.png + icons/qcc128a.png + + diff --git a/src/qt/qcc/icons/offline.png b/src/qt/qcc/icons/offline.png new file mode 100644 index 0000000000000000000000000000000000000000..fb065d9de5a85ce2bec823302c905ba2e50536bc GIT binary patch literal 3270 zcmV;%3_0_OP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0005;Nkl8&KWk){h-MxIkuBClVMU=+PGn|%-jm%{K!5O6rK-_vy`>iR@kzE>32^88Ak z-;aW^-Wi5ZhT%dGFbwql2yeGk6`Kutek9BOkfy)w>-uBMeWdT{x(|Zj!r|aau-(!$ z&+vLpmXW5mb$wCt(DG-bY0exDm-?P4A`Hj$wxuj7iYHJU+g6nV8!j6bkvu=wbw|?y zN5OtS3bKqiX0_tsL01&k$Vb6Z!+9i4PtE6^1hCtU<0lErCCjBY%cQ&%XgQ6nR>#6{ zOlI7_>&D&Vm~Y?YbuB?Q2{x#(<2bThK3{#e8{wv5v(Yq-81W0ZoZu}6M81E&v)!I( z8vTB+8%I-3qb5^7j$OZiaToP*eA{x;PGE~>O3IN=>BaQzhq?`OZZgUQ|6zrHf9TcE z;Sx7t$)ezTJ*7SF{3y%)vaYcRn{nT(4PT4tQ0dgwui>w_g4z4=;kxAS4Sm7y1@rdj zV2Qu*1@{pAGo@zFzv?XK{J<%WC-4rpxWVGl_6q+G0AS}gP;(&Jf&c&j07*qoM6N<$ Eg0(0vQ~&?~ literal 0 HcmV?d00001 diff --git a/src/qt/qcc/icons/online.png b/src/qt/qcc/icons/online.png new file mode 100644 index 0000000000000000000000000000000000000000..bb0d26142ba329b1784083c20670d02824a7b091 GIT binary patch literal 3271 zcmV;&3^?KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z00058oR5QX7~6e9$Pk#^g(Znidj0rpL}j+=D5?N$o}NWE^{=O(NR za2ssp)(9M6trba;;=f2Lg(xKmk{L|*z30rFFL=Lu@3q%nd1Y>HW_B?eFFW0Nr8-?( zi^UI#Sa)OXD#b3_9JrKybCQa}a2? zYV{FbTT7)9iK?xx6rMHyjB548&hC0Jh(to6!JyG76mt0yTv;jGk{lb?YKth7U3R*Y zDL|o6uh(d#QY$M ztbADeAAGVN|nA-DYDY0O_jJN zS4xZePNfxHySWV^_ok!>SqMYM_75z#v0VnnNmM-eR}egQs@Xc6(J zh~^Q0jc69}&xk^czeW`BvwVJ+AMuOIxs@M*i(p6PoXWF6&&t`A8~r=l>YM&IMRtj- z4thp*id+@hG4g6;hsa;S|3Bd0z`u!X16qSt9^l`=zkz=b&A1kV0+0{#eB?$L_&4zG z@Q=z_m48(^v+`B23iJfkzv=e-CfKgUCsLoL)s#BDKe-G^= zO;mfHO9O&55Y$0Sp0@zaBTLpmPzO2aLC8iAS!hAX4B>Z`Gb&#Ob3o2F(U#wodyeWI zl^WG6YHn1|sJl@;qW+8q3>q--Z=$*YX~5S(R7V~Q9RNCrYUiUZ*EZ-P;141LT8M0h zCJH?i^9T3>tAUbqkbxFF{F&?B%ITHog4Az{U0?M3jOrKFm;a8#|L4)YqYWA`Xuw4G zh&IvPc`glr=&n2mK`lgg;%6YFg`gg!1z!(Qt$ExET}TT8e!*%%dMNN<<3dmeS-wAz zFK`-2=dqAh`Sbrw`_JP%?)#$K_eH$F=t0qO(F39?e zRXXssAU#BP^Wp2k>Y@uj>+HkVM07`<3++8v9}%X9sFvuW1-fv4L0ZTMdBhDD7tle3 zwD7nFq=SEfduU-IhDgqpf`_& zUOswqb?CukhweNUy7}nBRp=b!X+ye@9y$PNqAh5H@9=$t)q(R1iV;o+&L{Xfh{*J{ zP~;1w1K}YWm;z#7B%8k|_YyrUdPMZl=m#-F;AAkIz<2Tlj%iPAtBI(UEvM!YC? z|GMuZW>ieum=Q5&V}{54EoK<@9}1)aP-RFJs|D$y${@H3Vj#~!?7-NvF@WC((Vyr2 zeDvii^occ9oHl%2SU(ZeLq}f^_yy&V$`?ZM;mLLIH~hg_bkO$ew*S}l{n2BhtHz9u zSpol_#f*gS5pX;lzK3%i2Die{;)opzSK$~EYvP8+m5(93CWyg2ALL^o*8!k^oTm*m zQA`irxsR^gn|woXfP`gvmU1n8agYqKCu@yw~YPng9u-`5vc<;R(gHfM1B~ORT^r#P;Ox zz$dua5YjdWnXdva^$rDtWTBUuJDOK)OnGE-n;CvEx zo9F`_#7)4SOJ0`6PBKd`|(BJ;Y7MX6QiIxJht63C@Md9ulTtXOK7zzJ=+D zrYam;%;f6hrP=W2quQKm#$qm4P<>wYk};Q`JItwWs?Fy0!b~4CxK68PUYhD@;-$&x zLRuK_X~D(|0I-F1Q5H}6Jrxqc8Dtv>4Y1mVk?m>Jf&VY0AJj=sNbKnDr+iLSXR9^s> zK58tiVQMTYj+%>W8iyK-`CSn1wR+zIFdxjTQKXI8eD+NA5!3@(cxfVfkY7;lFp^l| z;=>@c5cCJ+2UWV@59m9_v_l8w_=3m!2^p1tiv}it6EzS!D|Qb2{~>lJyw9MW&w%sk z9^z-f`E=l46K23UNSuj1XTkYw_!j1Xx%l;Y*nB>`FM#uf9;z>f8&G2joGk^*Jk(qU z-^;-Y54Bd-GR3fh=MKwx?69nsskxN*ECJHYBCxQg)rIvV_=)OH56(AC^8A9$Bb7sj z>A;RFxI8f!6N0{=guEc618+?E4`^V{H%SArb7SYn&WZhF>}+_S4d=6b%*4;ng7=xU z_gQd0+e6}Pc%K9BaBca9>mc9N7d_6kWUvIqiF84O4R!?Q%7ouYvEi@VySM)_Zt)BRu=4v#E}$v)M!4Ep^Rf z*jzXCd;40wek0fb*4Od$;I0ugJ zmlo097sET8S6k|#`f@m5Q3BuMdV`0TH^H~C`DIgQE4&HY>X^FQ;d@7M)Z1Cll!_hv zZo7|d^-SHZo?b$_Koiz~NDo0RC{_?Blsj0Tpj=@(J|XB2lpmoeLhB>4h2 zW)O@AE;rQpp+Bb-T6dCF`42pPA@hN_#c@Mo7sdWIZXvucfcJ&)zQ9Am0ytj?=fWZn zRTtCNm%ux)oG+uji*wp|jaBfz2HS#K>uBfeY3Cc^d=uDQ+q}HR<2%T6y;C&@NeihuWfqPJM9lXPNt&Q*w=W5?CZ-sN(cAf3C@13;I zU3E>pJ#ZuJg>%R80r&$+2a`N48k-|cZOt}XV{t`EZZArDDM;2R_#h09~frs461ML5yWq?}B794Gjha6F~x zwZ|HII*~Sln(*~de|M2@P+no&PJ+5PiYA;M_V{sv7$KkF zbYS}+_ye0Oq63#31bu;x2O2w)1~mVyexlz$uxn3(8gTKz`2w_HHIU0#aqibQUl6y7 zEN>-kekE;wCA_ZyToYH)=0Vj}@V*+}LA5os`L%Gr4(`{({RX(-2=|-eeha(@IIpvd zwhrfY_rg1z*E<030nU?-(#GLC`2;u#@2B7$g!9_?mByy=tB<3}t4&O4Xnc;>`>>xU zO`LAz`3>}7eTw`8T2QR8c?DXqJ|Un3<%`M{ZJ)vA2J!{U4;eSGb5njiu;YjH4?;PC z)*3LEWcvng{h2i2e1UWT?E3WFucu!aw>qv1_)Yw3xL*zLtKfYVys!39bq(CFf%~;^ zzYgBv-108YH<8h;|oPdy_jl(XnLus2|~XMzTUpy>Ex9rRuj&LSpT4S;o<}_BBTT5 zjnaYQg7O39iOv@=o+Mvj#|;z@G@h(}BK-ra0p$dmNATwmtOm6HjGVx(Neybi?Ni8$ z_)X>f%3tZ+aopOts_|>%Zvqp)2L9K={aScmLz`cVzh4LU>){?$+W_|);eHcsely%} zf%~m+za8#(;Olq7{cgD53-^2KgnYd9^~85+pgvc@=5yq6whiLrZTp0Kac=p7bIb81 zxc1TXHFy>-KaR93X~rS+I`?{A(MU)a(v$QM)WRwJg6|V-Zs~MDT(Esj`VEQ+#e6|n zJg^#2|A4WAQZ=CUMot5a6BJvUE*<1Y+~j9p*&34g^+f#j@V=gQ4-(hIJ*c`K-Z#KI z5bxDC!Tn~q2Q{|B{WiGY4);6YepeCib@$WWf%EhBsyMHH9PPSk!n-)3ojbl$UrY74z5;(B?J68U4V*SEr+NAbYQgsliWAl+C_YFB!MLDYk^8m2 z!0#*Aynz0q?JH{R$nPI$ZpqFmNdsDw6z&IDj~ZHY=Eno80k>yK`&9}ebgaO0{};D0 zu5J8=_|FnH!uv*e_fd5t?H;_e3GO$;`xbZymUo}?T04E-_mJ1`rOofd*B^lUgK&SC zc7B-le#rCr>X+BkxXfmJ>3UuxY^-Y=Q z>%7i~d$0Q}>nD6IxH#f+2&V%V7i|B-`2uo-kS}2DAe0*_Cs6-jme)rNX@I^#i5k#a zRINwWK83(K`a_giWAp!znr-$9$- zL7U%6o8JZZdua3U{_;M!KLGcK;1tw50_VqQFTznk|6OA_bvF@1SKvPv^PYvgX9@9P z4X;H5DTiqPXBwN-3q|eSah86)IOmx+GtJY$>IOZy&$U{RUkLXJVg5imP>fPcusLE- z11=sYCt&>0^%2!K2-kpJZxqZ2v@YFgK>OGHeF=8|qV_NrMx1?~4j_IDtLL`F|1Dt) z+;5@ngQ{C-^IPG48@vnK;eH3)?+tgW9$JF0g-}->Yry8547n+*%tF-fS zIM2G3Wu6p4%}5JQ2fBv)1DiXdgU5V<#+>8}@Mo@%5X=cm(turiJ7B`< zF9^ni$21W11A$mjk_KY59^Gl6EjgjvvxYCQ`hJemDH@f&0C*`F(J|pEiGhHh+*de+Ykn1b=@N{*S@^3Al&%2B$pk zn`~|J80RJFpurg0(aQQJWlxGpJ(X(GE~S}_YZ)Pag1lKS!#K~mn`6p@)k#1L`kdhB zN(+zafS91T5b7_4`2wo}#thU?EKvi>2gnJv2Fb<(`i5G6s5PkS7dSs44cL8+@&nR< z^8<i*~;Y-go2g_jstj7w-4L{eI#-sC5AT z55fImxIaSQ?kM~pgZmS3e-iF}-jmNVesiv&NuQf;`9E^xh$-oxel9&U>EFcEUjhHS z;s0c+Nxwv_Cq@VP3AXc+xX!(oYf8goufLNM@(JbXAQTgvFQ}*n7$eY{6!ikywr13KS8{OfFkmJtuZGuv+%zdL?n!fx9B9=P8P_j~a9pxR#A{XTf#5AO%y-G_Lu zeVAAsf1^E(Z2Ql6jkbRy)AH|l4{}%< z&w2OrOgKt=t^GW7kQ2~CP;bFJu|gW~`v&UQx^ZLm3p7@!^=od7NE*<*k=CW#b%yLw zabv~dexTT%cC-Nh6Q7k2NZ6ZjFL5tzA5`57|NG#6AKdT9=Ytvt;Qt_P{t#^*-fJJB z-5;ghAEV8mpv|8o*8}xW(eB0lS-6Mye7Jr zt;A{1Qhzj{y(r8VXw7-CSP(qhpmpTEXTg8MzJ$Js`x5_Ebw4p5ymWxJzaRb&!2dzG zKLq!OY5Sno5%@m}_s8M>1U?_sJqiD(;rx*9lxU;6xk!~==P zfvI``?hnE}sCI~$52_!A|0D2!6z-3~{c+kpaQs{D)$UI-u5-$}7Hj|V{jV^Nd!f-2 z@t?FR$u!y5#H5`~Gg((@`{ZYin;>V!_`aWS3LX?#Xb#EdgFCU$)_RtI%^_R^T{Qk?w{Cxi~{-1Fkjq7V($IjuiHcRVuv?fdAAxX@ms|{%FMdqvu@;}h$ ze}5B`aW2DTU!(2Ahqy0`_q>}v*OzIx7vbyzdHpN&_s@FBI>Y$TX&-tlob!(|E2O<7GZqYj^BAo(()EwrMU@{;keB^uTz&{_Y0b z(7~=GlRmX#{l8T4zb4tF9!RzP=Uj&m_;=igd_3*F;BJ8t@3t*p$~D>N=*OSTG8so1 z%R9)J;XY#YUbxucuk9mxK#wl`*SBW=hA?GR@y1{psrvb($ln>gu z=JW7>y0J+)itlF*qyBdMA!C_!R+9TIhWoj2KNIe!&EzPwTGjy!Uecrp2u5nNLnLhgdP&L#^5TYz}^70ewV`>94A1(#ED$ zDE}A#4c9ib{Aa$BX~e%`v-mG~-HY!9_X|8|joJQ>tma zj&``3H3KV|yIW2Ux-1O(*-B#58s?ZbFvrOFRMTC|C!&Xp6KH|&&VCIYNPoBem{5Wr z(AY%!6?DcpRqEMP)96?ule~wxznM7><}x(5A$!!A3hxu(eKfoehxbA7-k*M7ALiJ5 z!hLu0zOL}z8Qwd?x%Lz}XgxWwd4S{JKLd?3@%{{+_-s1*Zgc7!r(Fv!j~Ca<=Y8JQ zpHqKcFx|cGyF%Pb1;5(+^J0|kCjVEr5^TA{Ntmb6m$24>>tF}oUnpz?L zn+|Mh`EPoV+#e1Uo0ZRr`@+`?O^|!}`K(j4_X8Owbt{~&h4W?j-i7$ydF0=7m~WT` zW)??-neFhxyoX4l@-i6ZD7u6C*zKX(oE(VG$3Cf4V2&q)Gy7vj_xj} zo77iQO_SqI?6_sp#w1gB8UB7QcAA2X#u4jB;_HVp2Q-jzzkbZG^@e-#-iTeAbQC zX}r$n?u^@L>_+4Dny;~QcFfmVU$&HSxv`AP^-eX}?XoSOC5_=~EWc5&MyB4-dZy+C zG%%@_9oN%q%Nzd_|0(NIjQE!?mVX!j;@;w3p~=5VyT{*WoyaojoAKS#nb#ejVRAc_ zJhu>jk2xK3Oj=*!bw9pqWQwUj6^&0LXF(Uq^T}863r)7r|G*bm4ag4!Vu9@!kQZj( z!tY#VtoRc8W2`b|FMfYzvS~C9pE96{$!ecfs*Qs8l+hx?B(=iUEgG0=EvlL5=5SpI z*9CCQep2l**ZL5&P41Sb@@qR0Bh>1gWuV8b*E`7r|73~ZFt6ma(0`y zpTw6POg4>|Ha1zkvP^zUcqn1+rmUZ3b;vSJ`j8X%Yh1DRKgi=>?JxU$w&h7MbCbzgW;ZYmmoopf84Vny4@#bB z`wZlSibd*+U2k)aSSXxyn1??a$Q4h0dKjhq%e^;Q5Pk+kY7U`Sj()f3r85nL@Sw%k=Ta6xX4)9sb zl?;km3M2p*Y3D4 zz*vy8C~rwU$2yBw$eoB|P0w*XmTGeQ7x`1!>Mwu!OVErJdMsOy8#gXwpNjIIekk4c z;l#gd`-K;1|9y+v*VEop_>JoxXV0D;y2mEHo0xi&>Y1duNv6@dMm7#uA3&cV?~XTC zr1qbECfnrqF4E%jx}Q2ZbxdRy{Ii!>vB1Uw^#gS-uFl7Wf3T{e{4=h0wdq-MUHq1i z{tA7iS3P9BnqhyIJKW=bz<>d!thOF*%hI09Hfn1X;lI)PM#k|ke_x2-Z}x!pKg?S< zAU*y5_rEXgtDgGj7cN{V(f~25{&eyk`VGnlGf&bNxlA7DVgP<1f2ha(S8+d913B=o ze1I`von^LFg z#`!Zn?!T)0DJU#3@p00rytbZAj=M%>fI}7tB%~Rd~_ICEC|(%`6IE<7fT7c2-(Dm95LOanRm+T%MhRpQ-lm z_*Wla?Z0racTdt>Y5#)xTln{v_FR8QY5!c#nz@Ylc!bz5f61JY=7Jv4qycp2zLbDysFE%&LFEuwUUTfjuGFRbT3#)sz>C*lMxz8HU z*xLriUdS1>PQ$L#)p~s9ZL&5qb~B;KPs*NU{d1q2HaLub=@bo>bx+P;7j$G?cvik? zzOT7y{d#ND_EB5Y?)`Sf(B@nl(_(@5cj|LX)0DfPyjhGjz$S6vGj7z+^Ot3{H)n70ukm>Kf7|}IdHgG$l=M&cWZO6SLDovX>vX

WaQ-uoGWIY3zs%#mynD*&kz+EqXPSaD1tI?1zh9htrv+)C z&B-?QZz)ad@(Wg1L;3!@#K`;PAoN2ES5)kNGP`7&2CHb_J6Zq2oRHhgCLf^nA$ENL zdmXhtL}!{bT+pyW_mkc(-8(m#bF%IE={iH7^Yi^$3XjU;zuo0_zi592yMPW?J6N>8 z#&ghWaoKGm#8H28bmrAGr>eQKtc%Q-`6E3aP+DFQ`fR`bi~qdW zh#%$f@7|X=j5xici2t^4w>2F;;P3me2#$YUE6RVf;mu6*H;9*SHuuIL%i-VMkLEEg z|GSFwuf41qYqk7yzJc8f#hQtRiz>)}hje>xvd+%ddFoCBww}hI=wFn_f5)pGKksy{ zlX2*Ht)uC9y`$-LqmyYh#pA!Uaa0#)n+|54dsSnTzB}EHi-hxU=R^bTU;O7T^~Mxr zpOXGLyE*?K;(w~w-paeD%+dIuomsa1x4PBJl*GTZ5YoV-_NG}+uU}!?Iex9AYxCvg zNpH6>&EJCmH+lVxirr7+A&pIg)wKTr|JuuD`Bw~Jf3wX2IN!vceZgMh+zy_NO1cmC zvxdDJdgmr{cDB_3=jf}J0(Dh{&&%V#%e5|l>T$Dihr%ywrghDxAUd=pH?w@i+{EM!n1|O@!#=7wEdBXlKg;TVDq8P zOXR)TVA}msxPKGwgYExG_?Q3p`PaVkV*L9#fX+Qo4xn`v4OTQT+1-m`rQ=-J%#N9+ zVc&*E=OydBY@MARJJRz3wyuU(Q{zwN@!#!wx4(9~(am(f+1-S$H@lf`pv_b-CYH-T zKAIVX5dYa1Sv!UQcl?Wc3x6NYSHl0O;{3OJr=1D%FC91yI3HkhL2^VgBGcxbHm22^ ztxSvi^n>oTFwJh$Cl>C4d%(s2C*^;4L(}*;``E=lXHYce>A@FkN@mb%#AZnlYQ0W-{t@T{>A-Q!GFdm{EVOfsr`$8#s5wp zcY4eRg!qSh^${%hZ@~Rsc)yO1zs%UrC4XFu`No3l z)zlytptj0C%j3V-&0hcPeXF9n173QBY8u6dGi!t#Ntk2XKGIL{U z|E2Q3v%@_*O)#G35q_S^dH?52Cw(U)ro!zV7XPfV3GvU_ zSIPl(4xaqK_5BOreri>(?v2ip)7he|3ATGf==)n8&Yg8p~=TeP3nzGD2-|7*OE{GYW~S%+vNXP7^_1owUpARnM{fKVPtKA5}cDcgSq z^Z)drtifEDW^xYY*s;yl_gdQ+pfLd35A^$j*7s{%0JMEb+kd0AX?~-*$v>BGvJPaK zrW+WmV+~=-V%COoZL*%RsC}$MXRcpkfCW>%@t^W?q(=SWe<5oKHYJ&q{d^W{sqDHM z;(!|i(Aj1>>nzy*b=I-=hrBe)J5y5U%G&d#wH8?D3HPdTraD=Uf9fl#&Jrj${~L67 z(C5Hd+~ewSe~{@gtwY85?+5?08=JJ%^#6BZ8+?G)UfVp7HS`(_w&Q_}32JSm_VDJ+ z_twZful}Fr4N{k-+CE_ZDSW`y7N+%m#()_IX!npf{|H|X-wqldY;~@cX*RIrK44DA z9FsmU-85RkIL9vLf9U6E{->h+r}RxRb!Ksv#VXFS*v|U8gRC!QAA~(?jjR`WPd5!(H?U*>s)HCyT{O!-HI)K&mdfq_4Y@ny7r+d; z=V9pmp=RiVp=QYaA*SQ>juqlxYvod=utstbeZUQj|L!LDV!S5vG`{l;e4nK)`fE$H z&P4n8vSxUH*OTyX$NwtW{+kZqp5~>PwDqhT+|N2Z@_^=-o7=I#R(BZZz6_Rn*V)b{(GmG+LLRWx(nfT9czuZvloUv0a{OK&m7emlYuis zboNnh`||t$4capPFaFj3$^TVX$=2E$hYuJVQ||cBu=~Rv0WeFQRb50}LX+8h@z=-j*Jtt9=NZ4fNFVMJZC!JpJTKVf`SJ3`e{;L% z+Hp?J|K?rg^Okw{jkALDUMkMDv1eQ@CC6XJJ}FRp34ML`gVmg0)6^eR zzfAt!=ccwz_1eB_>A`*6MDjxFEUD%iwfD-M{~39IST3VaY zc(8t_*E}}=zt!{6W!;nW+bKg+?7hejq|7GPqJt(&>36SSeJlM{X+mhSg0=a>%8p0M z@ASDj!&v97*v~#AI|sPk!q_** znlW#VF~hG7xA#!i+_vLMwn^`vZr4lK9}U-I@n_@7V^}*~Zvyif!?kTTLp552cXhb8EG=+GJ4w7e*d(Fm2%_0Aq!&=Vq z^jrIQdr|c_lsEsMJDt8Q^Z)tR{rTT39{&}wQEsbT)2K%yQ@4LzQ+)(`qeg;JU^Kjs zg7*|}b!kZJ! zgtt75e`~xE#=SMpwC(SW0hYBs%Gq1@TM<0T`k(Y+>2@z(#&P{wYGG%wb!J9DOJi{|26)N@r@?FHSr(72$SBP zWHIsWiDtsv6HNDcUJg(mXKFXnfr|&>I#68I@1J!2U&d(i?LFk%T5orS{uXO4nl1DC zXyx6LVq|&RlpoS-%F?%6|5wnNy+-u;t>3>_bhbpn63+*G)%TOrI>**gvo*G;vlU0Z zE!AD~>+k)8I*jG6|J3;K|HyG~`PW$#v%U2!U*-MOoLKx%Ep&xL>L@2LhOwHPbB{{!AvO@BDu z%y>A%%zQM{%y=}zOn)@pO!GA`>5WOI{XlOlSbn^$yse`8aQv3Xf9^c;EuGJzecznt zV&g6Lw`(s(7HQylv^)8xP#oI==bST868G*bqJrUG9FPW{_x&^&-@w*aQk|uQg>XNg za|7nV{~Y+AOs=spghyuc`i?KrK$8 z+}uyTU;p5~`s_!ue>dmdImY5Wu3+|ivn^)6H`Drq3AZMgPNO;%*~Pbcd3IMj(rcs} zXVZdyW#>%JKjbaNzB=zmXMVWzopkmC{0r6(__4r!w#zjus!^A_y6<$KQ`m#g-;c(` zJ>O-|8!3%@_}6)qS)4npHR7Sqz(&vNezYE}{;c}8zKUw>R9y-G%iy2dTdKWgH89_5 z;CIwyt?>SDX#n0Y&wY2UnfKm25ASmYbKjdA(tv!yw0EbOLAwT-_CvgQ5d1qU^mrh1 z>I=L%b(b@h^}f6#Ui%83_2qbQ8n8Mz0Z(J#sV%_fUkdc+Y#&4GJK()6?p@n=+>8Ir zTZ}O>cbGSl@xeBp&cDq4Xx~}magA*q9o1G*eVq{h)ZGgCfQ9$~YB9#ni+!T=AH@H> zcjwKS|K5Bv|NZ%9!TSq5e6YZ3KsuQ7{v0#wy;)|)do#?`cc+?3k0zO+r-zzet9zLa zV>_7UZA)G^r@vcsYR$A~>wte&htAUiImg-0Ik05=6bvdbxrccT?aIa1paw$c|AhGh zt;=e57_8*`hEz}oyiR=UJHz^*E`?`o!nI zzGPnE>2be@>2j}&>2RlmX>*&o)!VI1^IK@-7VTeWbdk>~u4mt59G-Ji?3u1y-I;2- z+H+Oz5LYXp0ec>h&zbcHtj!gVPXgE0gYDhL`lsRE^3S^Gv}>FPa+UJ{udwFhGV@@s zvF7g*YyQqNC-N#|lAMjIGj??5PCd>|*4bJ*OV8F&*vp&%wKOdM)YMUp9b0Q@9sI9` zf9kHO2A{3RNG(q4asHXQyia`olY9XD-(CE{VzcDKB^HZ6Z;V(M*F9>lG?v&ZrR#v z)L>H`zW8OdeXkztU2*v||KNV^(hrxKWgjgw%RgFfuS-8#YBgYW@X;cxfq5Uyvl?)* zVB#ZB1Eby^Wrn^v)C_!Mpy~U1U(@qJPwN9Z-tB1G-Dzi9-)JFslFBNskKyXqvr!ub5Aw+RD;ph zbK>Ivg2%tk$kut;I$uxiU$qlnKE!-5wKQz|7ys1OslFZlx4`{IeE)jR=avsx1OL=w zR83au@_r6dpQi1*_pJD6#qpINuQaPZUS(E&*Tc&1uC#hs_VF^a^y8&w@kfh88kqI| zEHnMR={6QjcsRkvfe~+yuyH`SKuK|+<*k;XTtH)b71cm^PEe9BaJ&V%tmtF+UUw~x zcjfpM<=*k{+P{2&_5E<4e4e;Z`)_d0<6mdy>ugQ6f7Q{beGvYstD@REs^Et|9WR=`<$_B&tIjE#>+>@{SMOhsjZ_LOEq?T{Hx}g>h9S(j2qyedYr1uN^Ra} zQvX5x)9xp(`<}Jumzuo`&N%LmmbbQ)-Thqcz^ zgVKQd1ZDXFrvcep_78{EgrAQExpR*luO(gGYl2so+qwMCeP1xvm&Co@=jxw#5UL~T zYe4)9mj8?N{e1r~{_CG3?mPZDdskq7SdepzHCLRi>+-^i=)iFpdN$p+jJg9+CyJtUx ztN$b)0RK}qet)Cc^n*n* z4%YsFc<}wzM)6?jcfJ0h)4#n_r^KSRJYk!l#nK$;_6RsIoJZR60>OlyqUECP{ zRRbr5I#?S2v;3bW_MgW0!@p|la2~&{v7}mCs<|c~p!$2N!X54>pg0@4s#R(N+@<>0#54@C85IVB^7>@2{~MSoYmzc8tJj!1;l24FqFB zr+b}jzd&Pzt?#h^igDs#JSb_Lz-b_KB{y(fmB*!fT}juHe7xn}?P1nFM%udF&(7Hf z;$D0^WL={#aFyo{S9rb7LISoXh+iYD@dbPU{Hqq8&Hv6)8{ibaAE?fTt;2DcypMWY zs=21xdoS&#{Zoh0YQU?@`Zv|+6<5#e-_{>)J-h8k+suwnc35oxWV;czeX`AJV)KtS z+uT4pkOmYFq=CgBFShxBV!?F!1)+QZKj6lP`n}Q5<^$>*N&^}v4(5fSc;I|NV64db zgODHaeL|4G()hJ}24Z>eb?$febNEclbAWrhmo>n<_BM+1V&Lo}oquG{K!Sgr2`>KA zUt=#6P+b_+57yp)@vrf}`e(fuP@6g{s;?v;pjuni55fHb@;>VCsRpBJaaP@l51=k9 z^?9Fb{by-v+Yh(3-TtHPp8>P;lbvSgkBhMV$DR(HFHlTSZYT{b|K9R4HQ@RM(tsNy z>U^)WH%4%m^LWC1fy)bmV+G0&LSx5)xDfIQ;?MWn6}h_imBhK@U3}Z`WN*9nw}-%9 zSG(VttF2L{^ACJvUEw}1qXC_X$KJ=Zi{yl=4FvxwuMz{8|IrwrjsLWN)mT!UEzAF5 zkAKzRQyoUt<5XQ%>hpd^ectC@|6Lk@`xWAT*N=CFu=~^9Rtr0Ryu&yhIA0Ldz>@DS zF$+FgVCH-{$IN(thBrR&h&e;%i=+X~7xjOmzv=yYZ`0#}*FOyR1;MX@gVCl}!SC)LDrW59Jz)$#bJ)|P58spg)o!w3IW_rX0iSrd1||IUOJ;^wRP zx8p}Us>1(G@h{%@e7eV8^*CGyTR!pfg7rUKZ}Y+x-=lv>UMLOB{cx_C`N2#x<-MYD zLX8yElbuN|TNAHw$^fPd<7swOM7d2dpqx$0NJz55RM z@3Q;HyMH6@g}p!7Yq94iJO{fz#Ww)?f~}uyHSz`0z?vVB7k=OC8!Y^Iq1C{w4`vzl z4JN+Jyx}9piO30ty*h81^%>EE`i;^;C|^|H!S6q~ zIfn47$Nrk-rZySdHl@P5ESPHH~2mWod*-dHP*CTXI_!3ptC|$qeS~xq=C#! z#Da_DgVMlx;s7<`8lJ@mFb8PI0I9F0T6@)x!Tk}qKZNh64yX91Ht%l|_9S$1ynK~c z_@BS`)4gWjPxe{t|H*!P4QfFe*zxHOv+c**%;rxvn+-prfAGVioM6$%i_E-_7$f+w zXpCUI9}kAVJv`(KloteJg7XI*?|E~{E zKW%yDGwhlLxGucGIHkrab@kEg24faLXGZ9(pyt;D*K5pgTtf#}(ZCfnz}^vCpNtw( znHSj`e}Omv|2hjwXF#YvwrZ!U=9b2RRC7@^7*&(8>Ot~8khni_{#VI)@VnsuJMe#a z->3VGxEBum^nls_QyznTKiy}2fsF~D?zFx@8rb+FFE7+Mf#N|hCr~`FzQD~N;|rV) z1~P6e9rV$d5xIfU|KMVU^An|AEwAF%hke~mxDBBB zO+ND`e#eK-l@(gu*Sp zpx%OgBsG=?lK$R{XQlosR{ z+S6}P|IzA!xdrLLL4HEoaIii@F(eF{n-=Wr-DA!VYkiB)3PYP)j91)jZFFsO(?jbU zybiRwjwXDxyvBU@Ro1?7o>akQ#x^;}ROjQUhEV!>e88*t0BS6yoFxx9oos8T%Liy2 zP~!lK0o3HZmvA5<<*Vkqr0;|O_Hh4+_&@ZsL&b0q9XOw$ykPfFc8B7Dazn*~wLkR6 zjnzk#FPQ%kYYXWg$QMj|-XNS$4M7pR};@qsJ?44GTf7!@xXI^$ zb~n(%4dywo;S)fME1m{)X1w@UeHHPaah`gC)Y}sOItw`I6!XHY1=U$Lf;5xqGS{u{y3ONB9P+bjaK>TaZkm@Da8f#~%7YqM7 z3sAK<>z%0g2Q)CbEDpZz-yQntp*isXM{$4b=f}*^pC1iDKa&oeFL3$cuAg}QM8$(* zzJR=7+4mSb{w`z3#DuvYdAWhpfyR*K57cMW8YB4xrv;5EyIjHf2KfhR!o>?|LeO}l zAbmWB`}`~%_xPEhpS#Cgd)!4^KDysQU!d#luBOXvv>*-KL<2X-OKvcp3IA=b`Wm3N zM!_Ze1k~CQ|Ejm8nro`Nr*i@AS&%1_|5*P-{U=_>|8?jA{^!H{AH}^iVDSsCKtC(Z z7r5Ne`2zJ5T_3^DC6XUn9r!t-;)3#n$?r|JV+W6E!Os;GC!`0BD>+SQEuw>TVYR_J zb*)vGK7!Exg&=z0=X}(_&-C2l9$LDGmO#(DXah(C-EQL>ZlQx)-m4p_v(Z$8ku%}`$a%nDTR-n~LNP6{=14I@W6O#Y)<5`~&{(t81bbAZ z2?xaw2d!H#4Fg{1T+9dP2K0M?ZhZ8)hgN*_zKb62l84+O-rU9)NCP*04O~Y9)YY&) z;4=Mz*P5Gxi@pyyj}M^!UivwFz?sxPP;2!Y(eA@_f(9nT|8K?liC>(saQwTgbRZ2V zCWPk&8Z&Y+!SxmG`VxN(SvjJ{5H)_J{(}0Aw$H$NBjpLwf?~u(#uBV=Ko5!&g4F}- z(X<{(u>A_wsA`?6v|;tZ-UaPn5VV&mh{12586N{5pc63Q0h+jvCP2UY_>p^kjn%*% zG;o_f>Mi`hO~xzm0jjCc{wn=b`2gzdsMeBdZb<_=OE&vee89Pk-%^Y7g^u^(oQFS$ z{~>VwiPgX_(SQ#Vx- zqB=cjpPHa`iSiL+-r=k>{DcMj*R+RC`&UBxU_aaNH_?ZWVQ=C;-as2Z2EUFTz@P{8 zMbLuPz&-o|=yR98>22}@X@GO|tp=_W2d?=(;0k-8;9oVj3NGLSsJq9RQlH=hUdTK@ zoa6GIqk;Cve}4R)^#MNrCx3a;YT@`Vi(-R|2|-_=@q%D}7#u&84qRMNo~ZtUe1c+w z)|;r`Aip3jC|6L7(E1bYQxmKn*taVGV0{Gp6`UrlF5Vey#saGir-`>lnNdDQyg9-M z(!{Vg(8KHK0ay*(#~<9sAKYVn;x2yR4*d^l;1+Y5HyE3^-r4f68at{p(fTs$T;N~l zQ0AY{znAk$&I{GQFOTE$eh>dC@PF9F0p|z8b>Mt~azynNl^3|aqVhwH8ORqn9Vjk@ z)|@e~1&qu;_upoNid5<`H_$kaKhLmrS*Jir%lX7Yf0XyC4|f!k<+dJ3wop_(eH zu_ON5US>=H{##ta2V87^xZr%j3o))&9;Z+Gdo=JJ_@57cBiOkv_ zm`{)nw9Y{OKx+>*j-+)*(t+ZG)+1|Oy3>O74Za?nCbVx!&|YTwhbfOdJrvW#JNSrq zh#g?u+vF2(5jW6*Fw#FKb@=PdTS)`=Jq?Kees_rjxBJ+-8sc9*K>T;SN*+M1t=6x# z{tY$v=EMKjI-dWeoIcI#;lIntU!1(@cn|78ejz+2xcpH5AUJ;bm_N{(bYBN9N01hz z1N9%ZKP9LI=Nq(#+3sT|f3#X)FSGVDYd`Dscf<6+`B#%3awZ;__zv^cXkhGH_yeFb zGIdU>^#c!x2M-v7Km!BsF>iIptEJ%Ts&u_hUw|4*KL0n{yw>JxnZtb={+`8q&_Go* zumbKsD^&-6j#zBWz@J|%Ne6D7L2w;vC^iIqg4F~2RGc2<7qo}f`3A)aoo}Ii?e>fd z&N;E?9!U#21M3mK;o%f}9-cHX{%!AkOld&pta25^x&FLVR8@N6~FecdXLth8M^(JoZ zS!p_O>rv$s1npgPTF@R=7b8MiU|+k{LEzjYcm9=hAPwj|Ja;yx&Pdf+x$*%zJ6q>y z>m2>T_XgW~8qz?YTl58P_WT?CpY3|B>sPW~?^$v6JU<5wi~tXu26S~g&{g~k&KHEn zkDs4awV*w$@(b))a(kKO6Ql#H1^1~?m28n9>Na&EHD&DI&(;(zFUVgUTBo(8p5#Qy_oEIrpX+Ru}x=lR+A zf><;#1@0eO{xxRg_ZRtHXzVbk0nInN`DLer@HL3iLU2uTaKDmtpna@%PrI)Js|C(B zus(saPITUlG*ImPE6&5S8sL1)sqe6_g>!OsUb4>3wm!h;Uv(5zPXqoR!v7Tbe=d77 zo+mF~^=HF%9GD0+X7DdieEd*z3c)dCG~mVzv=&Y4&%)QDN&_JsuxBl}f6?t>b$i;~ zSr_iC6MNpx2j00yAq~9CSR-d+>YPmRud{M>Ub4>3mIl=RsiE*MYH8eq|A~X{40@*f z@xE$KzOL_s`@Y~f_}t|JwvXt~E4eWv`GHVg;IBip>rGgbtaZxTrx1z@>|fHpHMeI? z`WlYYwaiSbyTyA_jedG@w08Zm*Ktzo`AJ8`;n7 zG_dA--WeA<>%?k+vu|_;k~FXoA0Ym9CZf*8oQ)3%@&EReKTmpV(p}pBT=@S|XRf?R zc7GA?g?XhMJHPm|qnF|ScUo`axYzn4A-EP<>(kv{6}N9qd)R^+(7tx(19Z-b&b!gM zH_QEVuXG05BF@6IK7ex(E&rU63jddB|8qDq{i)7adlBvXO}Zzzug;p2o?sQcUj@Gc z|FHbCE?H}n?f#S>`*DDMOV$ste@%N>wTD?gK>W)G=vC0O|t7Z`Cj3?5$lqBf?06CgLUc`Y5$MFFW~-j_OJbk_WxJ7|0j9C zKjHtcoNe$YH1Ij+ocsd*AJP6Va`w@V16 zd&9@x^Uw!)PeUK@5BI#I_XhvtLLc~r`@R2xAG_!N2X1oDzvI2%J@vofUq#P1>II>% zt5m6@o`=59|HA*b==BNu{TD^g?G1cf^xWRSrlRNe28y2A8wh-TrAix(34b2A9eYE8 z+p#wk{ycDdl`3(A;m^Maem^(-aqu}e9R7S$@b~-yw#S#{C;a{8=_CC2<>@c{_u+be?0I?ZBmDOt2klux z`}-pJd)jL;0hZ9diy0)TnESH+qL=|XKJIUd{lWO7Vt*h{gATy@v%nu<{axUOtv?Lh zu=SUL8%)yY1#YOLo(FDVqn-zDz&;WLQlO92)*5ZL($8D_65OT2Y>a1kJFILBp{=Fr&2Qi zuT*K%F?;#;f8Sc*TMK+^fp0BPiUlG&MaF;zksTtNN4ATc8re2-TSS|Pi;=A(-;Hb) z`Ckz&BEE=d9`UD$W)c5iM4`o>BJ%lJUc`TacO!BmE>_N|ysdI}<*A@KXaHhL`MPg^ zj0K{)N7aq&8rdtdOXTLL&QWhgc8vTC`~N+%eWbzuCbEr>R$N+9ZFcAeH zALRMSi7?pQRL-jWckmf_t8!-L&6P7M_X2glH99u$9TgwdE2@7~?r|FfuWQU5!t zYm|xV0y=|^po5S0T-$**Q63kL2XWCHGy{cj667HlF5n>|8!ocoA`@g({@>s;aJ+JQ z<^Ejb|8L_Wx_@+XRKKWI(S4#niS8Z!PdG5qJ)=!@k7xr2Cb}DsyYd(wqPy_8lZOx= zj*GS)A5pEjwt|-+7X|Pkfj?Rf57`-QY zK=kk6z(n^0eL-&@y`oJ_uNV{4GsbcuK4NRGL}bE+$ANe-aPT{@=Rec_^WSd0LGgt+O-`{5*}BfN-@cAyP>&@Q6j!ulxuQ)GVe z_D}*3e}ISW@bHaq57DEetHg|onTh>>9Wxx;33@eu4bnCoC{IH)*c2T@a47+4Ah z@N=O*=m+|OKGY%a?QsSKfM^N`i817>j*P+yc z8N%y@L0}*l0QyrGRGjn%J>eys3w%^`E7}D-L^Xp8+Cz|skWcbB_&aUkK0Gx0CUFom zA!b(0xR}qYjK$Vtz-SM#qp``TSQ9rI8~Il~jvtLZg)v}kyh#|FP#oiU?%;kmCcz|* z;f&VN{B9H&!5RJH2VUZbz>PS8k78VOqg}{Hb)a1Yc_@Sj;&h0IU~KSs_#6&qz33do zOpd8tWm1*nRVHHZ@g8EwWAkwy;>KYU5I+tZ2@^adOu&8rQ-2f zG5R<^tNkMK5Hl?%r^?hSZ&jI6#l%j=-jh7UP2}(P5kCoggM`W0MVNxkr()}AiKgmw z>?h2qYF?VjIkceKEY72!T?X{~nP3K(&iSR&c;8eo8Ggix_@Ip>j)W7quAAdb4wwaIa-OL8psl<#5kADlXrBw(MEoFpl;c5uiC7)e9v)hIvBAdZKwBslpED}| z5)L}N2<;$tPHeZ>S+V~kb|!Y8fz5^K_?Q{k9VE=a<{)tvHlK~ng}K;$9(I|J-4|ka zP<=5r12vXn&t)}C&E?eOS>d79O6oL}fZ8i-8;cdxa#+S${!4lNVz3A-;9PfcGTY6t3Ai(_+Q7sdWEZXtGGh;~52LhKF_7ozt?*nTm#UxLk- zVRKM@1vX!W)>mWqwb*?F#=_{vK)t?*;qnn+E%- zA6Xjq@w>fX57M0`-b6lx28Tu@&+ z=#T7plHYH$<9b=dgY2&+CdV#|txfIgw^Rc?ehGG8g57;2F2U|gvHLRYz8t%+!0s#Y zGpn)vTI{|ayKltqo3Z&;Y`z_h@4)W6(CqHI*3Q<}2e9M81}5ncHM7cVyAH!*Wc8W7qPx89s)Z04Fdyi6k7fvi6``|-d?Bv{i`6+yq{F7@B%A=Gwh1vo+ ztMy0y{60e${E>?ZZVV$hwh9l}|4Y|pE-RK$_jgv@N_0;RXw`xjR2RPLD(t=*yRSj> zYq9-$Y`+1!ZzK=dT+`Iv=Gon99i2<-b@$+Bu)o#2v@VSwPY&6;(OK*XRI@_0YaE)K zZ(<$;wN08hP~$*n+*^KpPC{I$ZKz$~r{tr=gKZD;OT=p%r-===Ehs+w{>YALsJ{>v z6WlnGZ3`OX25|6P`pI!?;tHw1{Do>Ts}8s7u?tn#V*7R2ejRq-fZaD@cWhpB3!2}C z=C@<}UHFb1bWSDdKkgxU*Sq@18#;InL-@Oe-Sw|~T-6`n4$ZseMSM{?zj9$&I)2jM#cha-rS9o{R|7YZde~LhWA_c%eFK``i0wCH z`z^%Rt=NAXw%>v6cVYWI_?rFL`~Wr=(0tvU@UR)I_fUUZeUpTLkbR_GXK!os%h>!% zQxmN7Tjpcxz@}aH(A4K6oD2CV%LDB}F}?n7FIFqBRsO2Jg!M;`1C42j1NzR7aiDo0 z&A$cb-tr^vGY|L7&Lg1q-`w`2F6*nKy4 z-;3t=q4|T@{xE*#i09*#)5!KOFQ?5f;B^b(XL()IU|R#z@Nh$Ge_Ka4U~|>kRxQSi z8$~Fo&YOJ=uM5`Yc3fCaFVHS%6V5-`_CSnKd{7%yjIOiE%UhMNDmJVCrarVCS7Hn! z#6ehJtr!Od5r4=2GoDoECB2@ykIC_yD$Z3vZ_hSuA%JvkK(>uo$7E=2pfUFK#rv7B|#SQgM%ApinpCbJV z^$TTl-`?T24%Sf&e;j~vK-LAkUz4q*^ddOauD=IY6q+d zkUz5P0SY62!`gu4l5F}UKcn{Ic3|tUsvfWEGOIRs^_|##7k1x`-S=Skec1hgZ}-D! z{s@{shV4%fTTdmK+`hTR>>lKxuvwvLI3M4Cppi*^CDo{=ux#gS8MJX}b&XXE)gkzL zeMT`JeBWeago_Wv2Fn4tlKhcklVWo*4#<`LVU#Ma@jjo%TU zMg7D7r5c#3g(|2nvg%{2PI`?!*ncnf-;ezdV*f+ zMV`m+j{gtp&+SzWO4XuNOc8oD zY7-r5Vr!MDKBjCh8wTy2cb{5n6-4NLcd305#zU|z*!Zk^*~(di9H<>It|4Efm@E!7 zzN#^9jiqY5Li27KyVE?hT?@dRbEq9?ol3)!|b;Mxok4 zY=02jQ>VG+VRTR3?%GGO|1r=0s^KEtTfZZpe-itj!T#s4Ke{eY|4k>5yB|)q^#WD* z-q}8A@BI7Jssnj<;X%0VA@>&T!mpWZuRK?6%iP=i{Elb;oZHkd1;O^9d`a;+m?K#Z z)K@r`V*6^gpC&&1K`g!hd5w;l3lmgHgZ)(Z0=r@a4;b* z@nGU7s)MJRh^mXJ`lzatE6Db$nPhE`PR%QJ1BzaRg@m_j|Sb_|DpZR6eL+dpjr z8a$F}Yc|SG(ywfv|G>BTJs#i1_P40#Lp@N{d(C+bT*Ri-b;x>^Ic?1s}!!^hwk=(fGFQA1elEjA9Dc)+>o z_dL6+-mdJOb%wgWC&+6Kqu+z%s{7FJKHk5Fe%fC8UOY}akY>^klSdsVmY*e_h>t6N zO<(H6y0)OWU^yTr+j`y9XKQqf8jbs?(YS@a${OmkEynlE#rD&&{X}d(nmL?d#NdI9 z{r1EEXstz$SZ|G(d{AIrSd=(uANfzv&*{6oE4AQ`s~(tYLkqS}IJKfxFW%~&SgRag z<7l-vaBrHc(i{ilxi#j{KISskK94p+->S~iIwomhQibfFb}Y@-FP3kS?w##bJ5ySh z-DU5lJMdMTh}Y{F7h26&&nm_jK*~zS-hh3)n(I2oF*ebk-kECB4yBol(-|h~5z3XRR-Q|f@vtexd!sLxo3I<2bHrubU#D7o=I`m4+7 zQ;kb8S)H=1ZHwjerwlJ9IPw;)g`^jyeYchIgn521(FRe=PIG`O^U*yMwtZV2W zUzIa}{`pgWPiC`BlU$f=q6)A#a|Bw0s&$Z2op`LZ+?}KT4{PgtlxP3slgXQ@N#u>S zpP@Yq)T`9B@z%yBuTx&g?&>=oIdbH&K9zp(>tFxc{%-c{*`e20)c(?a;REU?9>DHx zi+Fb5_xs=fzQpfzKYZ`K_w09%8#gZW-8t=ZOv+?@(%MEQ?O>XX2eu8sLH3?(Q_z<0 z^v6ZM%=cszWSE5f1djvqA8FslV{yV&CYpsr1KHVtV* zHZ9Kv&KA0U`st^(?^T}tGfrgKn)ZeF3r(}5)HL?(v2x`~^OwK;CHRpQek>h09>hVz z1r1H=4*ZMSz*S93}nyuP09rH!ZgC;N%F@PGO|**Rk}dCJL5TVG!GFYNE>zO?og{yF76 zcN}E(&N5B5HnHEOSX0o~)BUslo<@a@?3ykcgV|FO-5n0PNBuUcM^wGi?4NlqvpKbK z{#!M&Y%Wb6oqZwOl^|UXWmGn=askRjS zF85g9dFRfZ$KIyz)@uq{6_}W=hJ$Z$BCaztaw|@lNYkvv*eEu6W zFU|hcrkR@iDt*TD#6W7+u@?^Z zv@bs%{?F;SwC{315AyClL;gj-&ssztg|-R?cz@UP`kvYyYTNxI(b`win|=ZNOxSZZ zwKV%vA7-2CM5$g_;Uyo`5G`!u*(2Nsix2%h`5p32#xnXs=gDFGvHLW}RI+wq&w*a9 zC=SBkFS|Tue|XntcJAESnJsixJJat9dK8%Edz+iqZ?-n=-lG=s`ySf9L(Q|@t?X;` zy72FF@6Ve?9~zyN_dU5?b4}B=O-D)@`H@OSgYlY2TCH9{aPm#P0X;_gt~}?cLJs-|lj| z|5D8&)vi(vL!tHR)}`9tY6(51ZXusLhW35?Yy3VqUz>S`{u-|nU*Z3r#QyI4a*yPi zme*UFcJH(^9X_N6w-3id>pk8*yVr+bn=NZ*nr-r8d`b3quTS2}+=c9~c{1#;HlV(d z)`B%)jabkJx%ULG$-R>8UK6|LM|-Z|AbL>rf0br`Y6gALiP}*X)DcuI$u^7ISlg8p z&)j!4-9kQbJkw-eAa9~C8E*fqvtBzb)BaO3P0nfZ!6lyl%lf{&qj@3wcl?Mt=wTeF z4Yb}(-MgWlA9DApxZZ3@Gt>Na>fx>Q>|fURG~CMA`7v)DjOGWl2Fco=7$E!C+f&ap zn%>A{clX-2`<~2>nWkZ%h9-VIV?<*ZBN{;)7>51X`^LVvFG{mNb$kA(`c10gC8(BL z+a+zwwSVen#*L3*`-|S#*8kt$c|ccrUHKj-Lsy}gUL=Z;1d>pp2qYmubkTe7y;swF zNAzxtjWNB54hGyHwqrx$WY(JZ@{)OLGGy|c`~A;%&*jtQieh6Y zGZV26-__N<-*?X5r|!M~|NV93pE1vy7ak{<)ZL!^b8hCC+;_=E@6&2#Ky+vHTtnV0iK`6sMSFirLpFaP9M zy#Dbt{r_p?-*nf*`KRrBj8o+Abl~P7?TcDnC-+~Wmjk@%A$$f0u>T*#x4`~7ea@4| zS-sVP{?Ghl`#&*ZS_7Q?wFW3QyV^41h2~bVSQ6)(j2uW@_#nz)`oH8qh<%WBFreJ$ z#mS!>R-bn}N1kKy*{O6TuVI_{ZJsRu<;Z^*@;{PfQchzhKFu6-#)~_UuP^z~^Oe7B z2F;H*H`&*-i|zkeH?vI3i>$-!pObebn}qfF2Uc;e=c>A<&G7cQj~i#PE13UxG5_Ne zaK3sg|NX=T1``{Yq&%;E?m4nc$K=F#IuO2={vRy^!{!Iuo>9=j}h;=R>c_!?CH%_Re3AYgetAwM^`4{0H0d zAMD4+bKv3rQ}GcECqF!cg+4>S$Fz;HcxH>c1p{iaxI@bqyZ(|-=Wmr)O}VvHlw+^s zijKv~U;SCnX)v5IIxo(|uO?P=D`hujFFvZh_%rqp(=glHC+oZx`tvONPxrh=lNoPo z@Q<($&3G-t&P6Rwac<;H(EJ2z?I^F`7q>4@?aKLgZt?PWzlxX^jEP2H8m2XCU! zZwbUsgY8fZWkT-++y3I7lh~U5Kl6^o-;PB7!sHGwU+n&qoJO~m*Gl=#R0dogVDfk7 z+h>G3JGt|3e9w4OZz4W}+4u?Y`_*4bSw)QN8e;HS!&16LuD|INhzM~rH%MZ~Kw zB0f~HtN4VQwDZn2#XTo6JJI5uBSxVE6;B7np1;T|bd=muh8#mS-=y*l_CMR-%0HYv zMtWEOPi>uQ8ue>rVkUq)nL;0#LHx-K{7s{X`E2jWUVSRm9;2}k?Em9fCtgl6>2G-Z zl5o$H{`9=2x!7e!W0ye(T6^M`u&yp+eO=5sWV9y}eJ=EQ?)$R;q`vOS|8dVr&Q3OU z2h}yz#}gAh37__4eBzVvhmWgfq#HfsanGsWxxR@SgO7eJ`_Qqh$zYO|2c>JzhV1l+Dc+t3K=8c z@N;VQt7W1maSoV({J}&En_hlQ`C{#F!>r#x%Qw`a=@ax#;9v-AAUR{r6}s&t@! z70xcK&-?cm;q>SFfAVzZ5MoQx&!?Ma%f31Le?~U;+SidkKIZhL-dGD~TU5JLcefUV z_A9k5bl%r@oSz}JWvY!;6b@H-+=vOxKVZ}02q@P6JnGu0=Hxs2V$6*(#+En9iF{+U z8F6)lY1PTIsf3%u_1q`@s9tJI=#P_s)A_{woMukAh>hSX@(=7C{rU_2?$iFRc_`RF zMso(nzieY$6ywsP_;c9P-rs%B|C~l$8<`3-!EJ!W6(%}z67$c*h%ev?DAxai>}!v` zG4}73cWylSCskZ7+P*vc2Io7;>{)))?_EC%{hpJ5>S8aJP;!y{n;&>+yU{uyI+usu zr?}ts?4a!B(=0^(is?f3Hnx#{tn1s)>p4m7l1!!9#7WOV{xgvOG~^FH9gcv%hpVAj z|KqqD_U}bbSbw zlaqhiaxczMvdOs07`TRwazEoB=i&48S>03je%w#E_=k+1+~)+czv9W>$=}B5Y9ITY zo};svY!SkO3XdyHw6N)sQ<49ah#Tc6moL`;F1y5}o0C?PgDaSaFPN8?9No&#J^1Kg zlhfC;3Aujrq-%Ny+8pqMh5alsH>s}#V&0ICWE9lFN%SxjJ^1t<_8x(~$RmG4?y@)Q ze!8!dzxuvpuQ*>D=Z-%zZ4hhnSB(Ej?vQL64sB>Lh{AzZT!{R^Q%&42AOuvKuOs7SiOzS?Lefp7h=h5Fd z2c>Q%W>c}U``DL<(Ls9ebkp=@FRtIkeA?K-7E#wDvd19pp<&B^8)+9R)M&2B0hTa%z`d{mBdR^^h zx?S#OI$r8%axdVwIgcIY9CnzqjDfR^^)pRP@)S zIr3kE{K2M2%}4fdHAK#de5&|c$sf6QCpX`p=D#=J=IQk3YYyt*?T0!T^5ziJ?^-|8 z^J-7i<#HF({$hJO23noN2Xzi#6XU?f(J~IC11tY9<3MAh{DAN=Qw z>zI4M;|dooT)N~R{Sy6ue$=1f%y{bf^SSTLjU+$fN6M3`T)D0&f4Xv~&wO{Lnfi`5 z4#wUdYlhz(ZU)^LWcps~YkFMmVLDyvWZGTy=Al;SJsrsBWXFMYz&s=jM7VL_bl~(L z*}3B6>Ayke_Z=sD-Ou%TyWTSY`R5#`11Ed+|3=8)&OL7+|JRGkzt&#no?Xm6 zU?8d?e_=s|#jU&s`L9I&;M2tq5WNWbzZCTmyd_VKzt9*UN97{rs$G0{u~E)qm&@L- zgK6(fGZWvQX#6_pbFGibzmjitpm`{(keD3bTJSg>IGmQfJ}>;2e~%OB^ZtG>xrfSL z_Cfq)c>vgw+7_Dfw>1=!ftEQ)+4 z{E_63?CX**^nvomDu1wwbf8@FFWr5~%)2ws%zAH@kq#!jHNlLzJ;n^XIm`^WKESR8 zT`zYv9WHh#vKF}Y*y%uPa=5w3VYK{uaN|L9$kUY2{;oCF$zA>4-}j4PA_KB-bey&K z81w%dti8xT<_L4otIR#fzt%xy58h3fPvJkSZe#A>O#cTHElj#F>f#9yUqjT=s0WdY zBcB<6xA@ND?;!hv<=YlWlQV|L4QWy@>3=;5i(g#o{6V1hDerKxlM~ z`3LzoIEvqe`KRt{$p0`t$AicoY>F^g)ppYNw;_9Qxs^9E_pGD;uR;E+kpBwgzbvW% z?viK5pK1&s`y}$`{ziG!SA9S}^$%CtB3&#+57NQ>yYtQL_hy@E?|O65=-ZwS`d{xK z)Io5-UjAqs8xWAajg>+6jZX#&@sl=&@;G`RhE@1%EB_;f(|v`_|wHaVOx(HUHN{{?!lA_rZb+ zk1JfXu<4by(DyeY|Mkd!UGz`IT_PEN-Jf+IuA4}1?>{QPyUNCoH=6Yyljr@TwPyAA zSDO_ddSl_G@4aMZql4-1PPh9aHy3F==yk1Ea9^aoX`2gef_tOjSU8JKQfD=HUiP2Y zG#&z_h+G5vm(ch0S=ZNf6~@jM$(y1W4JUVthXfOug#43Ec%{j4ba2dzArLOLA+bO8 zUS$nn|6lu1ZBzXq@&^+NR@A(>6ZvmP{%{0{tD(Zi3V(#PWa8JAyZb)!kJ#}24VTEX zZv17##~aMLkJgzrA3Yok3*TR8=H8tf)PeRzIv)(YG0Fje<6_w1qngH0DlK*g=dehYnnQ}iXc zOCp^7p2v0LM;kMc{R48|o6Yw&n=SXY*sI2Z^q{e@>ietge55sD-rad-#=A4j4<{`!Z9IkKb z9;$2ipz8m^rdQrY-`|1!;cF0Q2D~NDm4D3X5BX0nxL07d-rs7r-QQ-fTkd;$*mQ4` zos(97wAw8HaJjc8d~d#)b!V2D^3D`9{;lz5)a_B;8G-poV?k$S*(-Ejmd!$X$hnYX zS{Jr9tqNNi|Cn%RhqS=hkWMsLg%&Gc|NCda?_dLz9V-2dceSyg#Dg|FgDsEJ{0ugd z)4UE8#fhe!;Qq(afpFi_!Rv{p(QDWv;HDF&i_T!$1Bn-)@^0k66Zvna|8K4EjqvX| z9U%XGlD*3IA8a?1g9V2dz*zSZQi~%@O>K&?QZ9ugS5PJ(3gT_F` zUC4e%g{QW$Ie9+owcz7|>d5~3jvwqWw)~JQMY`DfgRNE%8}Ds2Yd;RmM;|UTS`#!M z&3tcWa4cwT9)1hE5pz=i8`w|LgT{mAC9MzIE9G7CbfIyPd(j&k+P?;MBE3*FXZefX zvjzK~uCm3-7N~3MbFEF*`7D!l?qSJ3mu<4na^Ew2?lj+_v^>?)G&_L~j(a*tKALRt zRpRHeF`zFq2H*qGIZXRd=Ai4y|69oofc#UC{f{O8oj=@Z%dSs$1@+(`3tF4qe5A3U z`AB0y>%zFV@Z|*NBB+W~1Oh^}9t}s8bPUsA$qIpW=L&fR^-Ds?Y7Wp9B6t=OS zvDZR$7$|KE`TqHbCHEYEqvV_=cKr-v?lgKh#s2t&7f+XV3=V{&jDaIfO#G|Zg^0&h z9H{KjvO~ZJ^JDg*-)c?(WS@iVf4=L7yUgxScH1Hy?EGZsBV)ntkG{XsEd7u(b6_ku zJ!npHdeFQiTekK}8WT0Vdtz01h$+_SgP7 zI`~%kx80nz^9MWgko|)_pX@PvKiO+^RSAxTA8t1VKPU*U3vMiEUC>!U`&7+IQ{Tmw z9ngd3CGC}D%hMVmU1(hNz1}yd5BV9KPNWyvTjl$a%`dccxzxp|=zaIP%SGO!biM%A zfzq)M{S~68^LeJ-*>)!P3}fLm`+$?+H%_o0Bi3Db+>|3Jrparp17OpIi3AJt0G_Eo z3;(>+!R{aK?tskyx8%O>NBhj)AMLeQzaF$MY`(wQxOHJAV__NVg3is-!<;+#6wrg4 zmnOVD!LHMOUC6GdIm+on_9ginG)7cwS@SPA z9qjqxo;LLVA4~rGf3!cS2kAm{lbw@7#)9^#p?YxRVfuUcn%T2zOlaS#^MiCT>eeVb zHgukoJ~UU!@8gQq4fb!@z~zrqk&bM+%9YaR3c9+2t}e6QUqUC8?iZQc3K<`TT};Pw zjD>R@OxrVUP0lIip_AY^z~TxMEghu1mSP$oZv11o8rrz_|0P_}LCU^Q_Fb3!_y5={ z(uYduSkU^cv9Rvrbw+y7Ue(!=v_@;Mr1e4PH;oCa3;dlL7mB}-K6I{j<733l5k^IG zmi*BwLv9d5Oc{J*uo-lnaYLNIfNKLx|Ev9N>3aoTT<&9fUSf<~>}m2ZFdhoKna<}J z2k1c9w>GB&V*pHU^EZeGLkHltuP42l^sTP7Ppe;aP#yX2vpNXq;lPg%SRF_Yp<_XF z(uRB3Fr)|Bk$ig4yd*tnZgRSiT}ir_{Ptw)^N~I@KBSW|x6lXv2gSxHE)KgnJYIuq{|nVR40r7B0Qn(PsNn zUrYT~_LxsA^KhR-{*x*HDA}v{$Aji1|N89TtGe;v?5bL)LQ0iC=#(hR@h>0-!r#>F+(_N(l((1CC!y)OoIa6aF3 zIoHK>IMczjJH=Xj5+CaEtbfcrmidjIYs1O$>%52jn;rPkflJ8$k4^`=hMSW@&(E^y zX*@^|Iy*RjoAdX`_c`~@Tfkzv!}SdF*nDUQExIfq=)P1 z;X3;(@C^g6po7bdgNvLyz+2@be{hJV;~CcC(|LbH{+E#df2#b0PH(IS<%P1r+WK*8evq{HbBliHqa`=2uZrqhA0jD=YAupasU%C7^B1*e1H zoaEDkv#q-EAp5HPZd$9Q3mcQc{G@mQ#bsz*NEfr-eHgPRJxspM97Qa#jU&FvSRk%m z_=aKEhFPqSbkOfoKRX6`obT}~d?(AmI&)73$ zPjYjT-75wBJ=WKN-_7|ymw({RO*Srr7#YPWNe^@1V{UqPc2EyCe)TqEK{`-O{hRD( zg=@Gr!VJAS)C|4?&gxSCf9P|e&lcqW7rD22p87}jv6MxWj~D}glKh>kPKAjHOP z{ca!Ocf$uNKeSyR(82Qemm9^&xEQ4cci6+e$59&uBXS)D?_86 zRL}noe@7R!uw`^X_N%cg$-ezF${)Ai$F6-3`Q!JI-%b8cd~pVUw5Nj)@qHqHHwK6q zGm6_&?5dUj+q3_ucy8o>ee$izt0%rWu?skpTK^qn`c>Pwvg{^EUGTTVennApd`141CT!^f_bTUsk-oLa};(i~MgBw|bQL)pf+Njw6=4`HZ(_ z)SY^JYPqjkpTBuqe!;%B9}j%tKlFBq61n<={c7OL5A56Cm+yG5?bB9yukDSzmnBN@)xa(7 zO#`>IHx1m<-t_nG^U=omUq5i~Q`0-{H4j_mUh^>jYxlMu?0X%o0+k3>fl3tjI#@L- zSKRAhHA|F;F7EY%hjl3Z-}!ZM^6|f4oSgmd7pE`(`+i;f`#_P`tDIs&`p+HrK7H(g zdrjX9Ry3r41}hh1Ot2EUMf-g4!HfmhS?w4JJj{-rz{Bi-4BV7k25*|H*Z#5T-N@c1 zP}9IzwqK6X#{*wjXt+_TJ^M|Nm72-Ezi>^K$Jf z_jDlt_wPzJF8LN^0p)Aq9iC_V!riM(?=s(k12?~H_p+DZNz5l4DnppY-X z=J09DRrv#Q;Eh%;2XboIJm|{*th~2rzC7GX$f7a%=o3r+YsrL?m$>Hh`&YugVs z!<8bAYJZ9B175jzp!DL}lhOnJihMrT6%HNcWLN&zw#b6MVP%0F%48r5Cx<5VheY~A zf-R?bt)=c;|0y@3+&DPjKDFF?@E=+}xWTjoPDF8oszeQeBa345xhbdH&_K~^74q!a zTw??HTtA9((<6__d}PuYdH8eTy4>hZ1O1_KKn{r|KSdVBat}Rk!IT?UE*h?>{qTKR z-nEDkw08t`rid3fY9#F)MPAo2%SiyH?`myx*0K!Hjkst zaG!|-O(l99Z5~g1C(;(UdMiz)eN)M?H=R7%6mj^fRGCFCF_oDVa{ei|m~t;F7q9Y= zRvu5xH@QeFjzAuR!90+kI;y9a3(d-*4RUCO9GZoU3CW>x$(tpcl&s~i^YeOLep>mM zh{+N6BPY{tIG3U((QZogWZFHMc2A|v(`fSy+B}Q)&Y`XIX&mr zjiI^Et3yzWdk<)26oJY~q7`O0GRhUk@XVPvskt)xn>vVOSE?}?OjS+ zmy=hH+QbA3Vcqnj5rCX!0tXaDqE`a#6ph-f$_Zo%_mqGr?fS+sjL?Vd}!=h5!@ zw0j}#UP8N<(e9Px$6HOC*U{b$v~?4?3dw08PGxbMieFrL!GmQxueVXi$yj$YINVKq zcD={LseFf47IPoU!Ojzdyc~fM^o8KOKyEI(MzD8MU!eWBN;dua^Fic-$OBRHX!m^D z4eyUirI%>;LfXBUb}u6@AZ@O`3SBE#BSm_yy@7VqX61BKE!0lEXCm!#MDm!x$5NqrLo~{_((`fqk^Gd&s6G z4}6_*0KR-|)FRpr*Mc}N#QjofF?lPOF;^{r(NtYUuH1FBdjtC3NFPV%HCIxWk+XHR zr}uh$;kbp{TpaT%amvdK=f8@$pKS@`j~52R=8#vORB|>;7BTb>^$W?N<_hqU%oUnD zZN6aUNX-jcFYQ{HO>U}|^n;ARz9|(sq?Q`{Rb&vkEV2<8``<(_qwUMkIovDa{}2z0 z_=u{mqwO1M`xf-Q4Sg3dj?sJddCX=8%_>Ia>g<@XuZ&Qh-SUCGSE7i|tz7iVofx+$ z&Lnq#m@A=CULz}mI!o)Axc%@XgMD{xbr|9x2f}%9eu3itR)jag>@^=V`fxiPY2^v3AB$_;OG!f!_JThRMf+PS7Sl*0qdjA6PgcfKadPsB7+vC?v~0dRq{zP zh}sg>O;}Uq2Df>^!M}@#z~Of*4b46?4vf z=0x^Ol}0iSG#9XMw&zRjnX}j{N(Qnwv?|^0N$sz&y}~7%pBvn#a&z0f+&jsGEB$X^ zom<0xjoi4(N33VpUR&FwbbD0)u>)f*SG8jLm5(-+JkM&kaFoj5tlTNeZKM3P$|uvz2w790JI=!l?Jcc!K5P1T6u~*g} zu^svkoFSF3+{&PJ>C3eLh2mrY)-ti;&WisQ%*_l2x$17(4G)gix+?S7tFuqn`upM- z)`79C{S&L1qz*}s^#6K;Snt==H;rF~&zyEE_pI_;Cml{Q3ERM#tc3ewKHLlBkrk(O z%rwe$%FGy3ZvkuOss<*0TfE16?_|JOuzlcABb&>&_M+OBzghWvEA(Vf)QPsYWlz)^ zy*KCl+$?ZT&^*W(AZPgJ$f8&~5_qo#!rZ9@b0Y6x-@*PyXBYLaiUT;`^k*M1fc`NE zIShT#B;|&0e}gp*EUqTC(8JS;hgtbH>&-=X6Is*8u>T!R(bc`?_gbS_QzkOE%!@T~ zo8p8^u;W2ICc=z2+||(3UJOrD>a{CZSh?sXLOjbU0&cY;99-VLg+u zn>j@JC%}U%cV>en^o<_zCarmR9>pdtnwUB*>X`DWH@GbjJ7$E5p$5 zJ??kiBWVCRMOU+b*uxwO*Js+;w6AoZnC3BdUtC7EXXVRnU#3@R`@x&({^QZ4`Y z?vvU))!JIic3@7#CQYu?6`}15s@!-|^qay$-#Xeco2^S>(%3pYiqXQ?*M~Q@#gtqw+O&D|;%m{Vm^Uc}G|n zVZvH&Z)v%u{q0g);|GEfE+8k%Ym5)&0wgb8)A3EMT>PI^y~UYp+dnwn`163OjY-{@ z%g7xlyngnrY@6pV`&zbXF{VY4&sq-WWnTL;Mr0KEo9>g)DZ#`nV!hnSxjB%(ukL#C znD=N>a@?asALL@(AxZ1eai?u53V9DP5@K0&@su!*fVwJy>o={_YZ#l%iyJ=(&0 z^coyK+Lyv9sl9qyep-<{1i|*R)}{AJe`IcmAHlr3)oZ`a^P~JeMBI&;; z?eAIkC!y^JkMOB*IqgojGg(Wrip(>b+mdsVP0XYiJEtYSLc7H)g$z{E`ldb7#)d=C zzjAB0&nUvHE!o5mi#N(IA{=_otw5fmK#n8jJ{2yyNdcJjmE@aQ%V+nIhbYW_V*0^b z_);BHe>?5hIT`zj>`St-$<|nDVkHyRmpxG@^e#V37YgksU*M;q?FSe0nR26bJloN< zS=uIS`|FJ2JiC~AZ5!*vA?gNZUh73_&(ufTKe+hzE6&qCV|Ht4f%=e+!6ZI`tT+y2@EIrFe@i+u@u7WrrDZ@@;g-pfN1y8bnM zO#2)5=R7~Pfk|A!8oL8N=mT)ns4S)Qez>P;+^MmtKZiZ^j$+#1qpqnoqME5W13Sb* zFNcimFUs$e(9X-@qyAsNd3}2pw0<~zRQRhNX@Aeco}ZGZ%JjU@({$R_>5=iDnw@HD z55NXBkn`UN%2;fZ<2egYs%eye-JgdG0eVGFW)BYik_Wynt z`~5^%8I|q_x`&q8rpn2ehz-^EmP()|G}4&G5pc_Ke1b)sWH5Ud2tZ!<{VI|ZzWT$ zYc-S7BBjWjqx;nCTGPu}iN6ZJ-6QiKScyBrs|Yis+(4oEbDnkmPnbqNJUGwOr#{`f zt>HpDtsfU^SS^qO;W<1qCqPY817{U1vKUL&t&Pb!m-w7T6;1y0OH;;<&Ywahs zf22PCx`n>>@0Fzg?sx4)Lg&BKEpTxu7Z7!CHn~}m`P6-{ zxT~J2wl>=W&k;F892ax?#PqLppE@J!m;`onmzH{=JIPa>p{EMQsBJT_jMn~ zH=Q=&$>&ISpX9t`6FWNA`fKE~viUN|SArk6M`-)U-xwbYj^ua3^4R<&%E-+CLNhPmBCr z#MFq`(DqNhIr#ARZSfjDeR^N)I$=$xlN)04TktvErXRpJApQ+;)O5Vq zF_;U&=7GSbX?YQ`Q#u=daWZgn2#$-#7PN-)Vay`2qe-7%PV}R9=87V9$m7S6&Qp zkBE~;d{yEM6AzoX^DO_P<5mrD)rQKz^##`-BnyAh`);fk*Y?o%J05?_VUEqt^2f_& zN$!Ly8}JjZqW#Ngzj7uli2679`V(Dy!(HKrza*TQ!~01N!heeoL45GyX6em15U*X^ z3vKN<5D%UB0z+ls{5sC>;rtzHTXDsGM&n1{^ZP>lZI?gI@#s4a{n{^MJB7c!`c8b1 z*sNa^Z~Gc-wkz<9EFq3$QPibyZT7!M+q((x=!&qX!v2brU3?JYM-lgl_<-zO08g1X z;Ka-KSQ*I2MSIjPS6o|lb?>=$Yo2p$_xJlCmpAQqJnELi8xD2xM~k;i?H6~t<4w1m z>G*M@mP9?#{{haeB>dcWg*~+R!vGdqSaiui{Xl#@;^xs@Ag(a+wK*AREVwx_$e9|L z7p)HrIoP&Iw;{#O?c#n8j30ly-B~;62Z2jlJm%uj*8C?9dB>maxUE=x8t7;@+!lrEFNnW=PR!t;IOWF$m6e;&qmzUmA5eV;jNZ0H)?g%Q~5vLSb&@N zjIgNUMRq&|;_MIythkW|0Li4}nFNQzbau>rLZF!3~(f;+(&*cA>3}}BN@VLJbF4tmn;R+BJ zt~jB^FD6baarS6F(3~i)Fs%zgPI|aj#ltP`PK^mSHw0xt+x(ovp}fL&E`?XvaSF?K zCVtx>pYRF%i1D}1sr z;^IpXPFeie;ttVx5RZ|#i^NqV?k>m8uf8Czz;ImH8XJyV)^Yx7zOdZC0X|>*_cI=s zujQ6ypQXK)<&{0n{t+J8^po5NyP$ljjzhNIEA@=HORMf<-QP{$hc`C5Ao?rCzo`BC zq5TJhmAA#m2kSWh#33Z!AmvNZoFHyLm#;>0P=64orFbhfHneZl_)y=l{H@Fv?y9|n zivDK#T=`t)xuRUInee%0o`ydWE?4E<6OXGnM8)AM{!sbt#GkA7!yEdw;-75$KQ4#{ zGkr^(0hT-9haQK9>kHy~bK^mrV(JUxIg}h6C$!5OBR)yT^QkpM{X=q55ht#_p7*Xf z=RKa!Hs|30rR1K6%ahXP9Nb}N;m;G7>Ph(9jJ(&GyJeU$E(yW8S86~(96sSpk`xD>_Xmwn3PQIyTN>FZ4`e`4IBxcjjO zVxMdLtCIm74z+0eP4WAPXU1{-h*w5@pyJ+h^McFWAUSA`oD46n#)f2}{gXJ{hQ8@> z9a=6u_EX~0Q&HYG%W>#<4KMdLJukxzdJ!ID_zXLpM+Rq^Ur)i|b^@OX9D2(Aix2ZA zcKPS3ch`1zh07uu{;B!9 zYp1iO*KD-U>w{} zpE^0HFKBG2FIZku-&(0XgX7lR1ixI6^ACPGahi$GY{)gZdyzrE z%l#~$Tz+A`>3p`cX@8o0bSH8?&3q&CTf;y2Wr7S6kin@S_f=p_IL<4_Eu;RRapCf5 zXlyvnH_K~z#x?*{wACjov`xON=hl;e=sd1B>Ttmw(FlA|Kyhe^Wt~t5BbR85_7`82GIL5_$MyG=ak>`e9ylq{F`46dd)hSL|H(2 zi#6kS+B>O;Z^_9(=PI2q#j_NYL4e=Kax1-s-Rahp-(in_3)}PpIF*WxTMK>uU()Yz z?!;1hv4399Uiu__J9jxx{e<>^3eV1GoU=dUy!|QmmY-mIxjX;e`6sc%Ehk@XFKn{0 ze@SimYhC{9Ng#|5%F=&4WE;2>U?o}Qk&S#Q8LSLY9OMQ#7T{NSp!Z=jxTCA%`he*` zzdq#k2(lprXcrupN3LT}2v9aSZVq=X{Xlo&0T1|(pYPtWm%p6r1Ft@%-L;r@M7wr| zw%>|Xg7xn6P;RUA26DWktK+vo&h`Pw-QEa2IK7xvo}Tmt%N!A8jR@$qsK&K~tn_`b z;*)60Gvy2Zs%-=pKa4o5zYF5wdxMwm4L+P=G4R5_tAK%z=+67yD8hU@tTSyX+miNV z5X0`;K^!+&@4urR!@g?0p7gzPBg@qxKBh2YDD@GZo#Mx{TMYX!@UIk$*CxhHSoR8F zGA%~84?fl&v`H8Y;n#&x%?z|7fZ0|&I&COK7j>RgpJ(}d#Q2E3h%pflB1Tc?QQ%ca zfn5w>(JPJvw*UrRF@cpQfytiYl_2gKjIG5R3uikVyRk5)YKyS=4r_}(EZ#Voe&zM4 z2ecvYS?XBaXCtOW3?Vk-bH%7cO^7lTCW1Ac1P*C3IHYOdEQB4O4IX74coboSUjm~6 z7SfiN0{Ch0aKcXu5A)(gVxokJ5q4UbVYMTVILNGW9(G)P3al{g_#C|OkmBm~H1Fe6 z9}G77-z_d0Y;?ux$ayAmo=v^yfuCAPotIGG03KR6L1Fk5t5|0PI17sXeGUFgFhw<& z;>THt4_EkShj&#w`he}y7|8|O6VOF~8{^-(4t|=thJFTra9-5hs6Rx{p%2gTaLo?W zTy+WcUIFG!m|kI-HwQ4i;Fn`}5w`{gDOkWJ*4srq+YT=dv+hQG@w7*6QA}c$sraMN zM}>j(tNbVrpClZ=8{a9V{=mBNOnnJ_Zf&r+|D;^>it(tl2z=@i-pI69JM|wf?Tpct+<}LZ=mj*sJn2j+v(@Ks5`i)n3rQrTD!Dh9HnCD z<3}QQ{4A=oeDls{AN1p2z>lxkABz4i->u@r<)>BOk}hJm(*`hunzuCf3db(Yp2h73 z)^GMAKV@H4Y@Sc@P)<-j*2)FcogCfDmF_U9iUCp{Mfrr&+K1GC6nMI$jcvVEXBUIv z;!cXho&?&Wwn`t;h0W9G+JGLaFQ5(JPQ_WG@nG9PoVCRowkkcr-(TG8=xxy@@ymUp zyqd}{D_?buJ@5vADXy`R@w%RVzmYiWt#wUW+oJVP7=`SQC)s+ZUBah&K9EO}c(5i1 z@hPhupd4yqePT8TE7(J)3$;O*^4Nk{Z#;uje{nSR?_a@0cJtPU;65s=%qQ$|ABh*h zr<8?n?MvlGl%KKMZq}mp%+st*l}8b8Fodx@q_U|xx~fskw2S9e|4AH^Xz{M;m+@WV z-)yq4iD|g3p^2GF9RE1hfk3G{8BD{%`W7ddbTrB0C)Eb|yBln4U~0{&WnLUYy}|uO z<K5;$~9*kga5af*PJq6!nc*>O!(!FM?PB-lZOd$S_0|=PUNv%)-K+O9vG=dkH;J>sg|$nu@tOYkTb=L}o2eL5 z7q=<-Hy+#A`p^}VtiS0q;eHf{thmm^yhN)9`Iu7|<9p9b4f`zJL-DVAM!lx>OxYCn zuEO5tmAzM{W0`8M4ftkq<6nvYy~WoZNi=DlisEKM>!LRK`%jZ`#8dC}>K@wO(C_MZ z+lFb#2>e)j*Yuz)!hP1gr&!*YW-;EGqGQ?L!{e6g>W_bAdg|-Qft-D5%hN3O(f>Vv zKTyoMtGhlU*{J>*<1&JA)oO$4=>MKyXNqG@2S1g*ylC97>gfNDUOSAH?kT*R;~fL* zHQm*}`O)SDEsl8@FU2G~{Y!T#9m)T-kGLAGJH%Eto!`{<5!b$8{qr+|a#TH1ho_oW zms?robEf%4&Z`2gb*&hq3FbXHu6W(`YyQ4fY=O_krD6(4fe(B!h~*E1L4X zI6w3#SK#W8ujh5;ZBqWS7DFFm#ng_ZzRc5L##Mh|vb4UY=cNaAp!z3`XS`-T#P#XD zrjweQ)>m4a-1qRU2XI&|r{PaSrp-DMi@TIq+>yEA*TUn;X1#;^hBe&jh;*$Gk1fQk)H||cXz{_Bm*e7W(D2^Jt&zfJ= za&zg77de#mU?B7AfO3Vd{@u=XE9_o~{~rHatNyKm_f-88d%SyJJkv zH8t&89NCrl?vCY6WPj?<8Mge8^1=F(hvaqT<56C!HWS(e$D#U9Vh7fid0@M?&@Xqw zy|N8FN>0)B%Z}fW{*%y$HF;x_Nk5#fJYpvOHDo^6iv>^3WQ`j_KlEW>RR8#P@uv2? z+9qZl+&179Yb~#3;`71EAsdwjtr~b|ZqBfr#e@9^j7q_fE9BTBzf<1KyrSb53{tIr zoSlYo-WXBcG|X>UWK0z|eiOSSS}aoR1kN*)z?%0>C^CN2bBQsZR&@L(<|dkIec3w* zcQdfE#nx!dx*xr+Jgl>O8)Bn;B)l7&^ayK{Fyuzjuo)flA(Sy z*XeUkZn{1)e-5SoD~sZ&A1W7r-0y9!8+^0bJ+gyy zp{-EJe_DGTE=2NATSOfE!Dm~)GIn~g@af&3e*J3Lx1p&plfBW@sNcic7F@q3yg8v7 zKDB$w8KWFlz1R1)I48*?^hfWd=Rd@p+WM~u#PQGeP3dDL_kkDL*C58k!l{z3B)IX^bbKPo@5azKr_JjQgG+M!4vkUlLo zV;y_704_tg5x3{JG5BvV)~KJq?*v~@;{9C@>#px9R#$uPrqi2-#a$%jCz%El8d!d) zAl_h3RFVCg>Obe5Ia$Qlf2p`~mk{XWk3!VGL;Ot0olwiH{-LSkm; zM?JECp7+kYlH>vTME>f9`0kajPHj-!hT?%0-=#QM;?@WyM1o@m* zY=HcY!&e*z-_$2 zIqV2{?N{n}xwbjOR@uTCYCSfhmDp03MTb2lRaQQ0#eFK))9J!t1Y9h% zYmdFU`ch}bKr0qlvCnCznLkf6u1_HYVxL{ybG=vVnVJV{nksM=Roag2x}f5P=uOd2 zv|p(W)W0@)fc{Cby^7gVjE-VC6~m~wJ;g36_pM?#yItuPjA^zpyysh5ooI}^_-@rz zuQg^gf2r7b-m{!J;Cj$Luf=KNc26=d93y5GTTFw)4NUEWwXH1y-lc!4u&u&V*$-8J z{SZ@;M_le76q~#K2VVT0@|`LV_WbY7w=tMw-tuD9)ehwqSC03*OL=yT=UiaFOkA@1 znA)YQ=3l*+O)Rd8;%{@#5vNOOeWtZ(d5ZG^vB!!#ZuBZ#OvKz`Q~1M+yI*`J`>odk z8(TV<*tvgqv9*es+H`-DQC>vFiV1IEW9?~&^r5k#yxi(r{y18fv)*0}(nkB9Z=8&{5TnA9p2QDUbNA z2a4xYT&LprtS%TAF0NJMTiAziF|9U#w_;kAANo2uSd|-^e8h^~R6c0sf>s`A<$xB? z2xsvJc8{1i8c&F4}a%kY+Y=r&09&FvBRP$U#Ma! zl_ONxBo{-e9Jwxj(#8&g>sRa~d2s&@u8(ibf9h`ox`?D5lPLEoHeOoul#Ll@-B2!C z7~vayWd<%Ahjjzs0>oALIH&%jdO8+&8yX0Y|y#BP4qf6qVHYhv-LgJ;NP z-Izw+y8_n0qv)WJ{Zt|KKg!;=fc$pTh`-C7baT>QMEu5|OIH5pdS^U^5ZxiFh%50% z3Rd!x(r_gnDO$hZQP>gJRSHAms+;hi7oJq2gcq(f!_DkFSP!yU9O$3-A)ccx!eiJ$;pi`#_*w_T%DY) z;7gQHoK`HQEhQMIRe@jrlm3*+FH-^EKp$d}_TlUJkenz#hoA4a@HGAwAM(%fg@1@o ze;=_4eTbuaZY?c4plmf_iq^sb_6r+Nq*x;5;ZQ7*iz5foyfN=3M#5q`QbHxaxm+^9dG%oc^;!Q?9 z^K&Pc`cxgAKY+MYZ9agd@Cd;rD{k*v z@SKbDU9kr8tyZ1Ed43${`N0)Ee(N^nZR|=Q=HpDsw33hbCqwH*e8>LixwIGli^>a# zM}f0le5Q(vsJ#UntYSID&km=seC#TUuEE55VG;e2bnm}#0B7HDzI%(UJ&28+x{B9bJj3c2iaAg|4mh@djjz6{d#<}i zZHiheAH8e>)<3_8_!E5d>8;bP{ZIDRCY_sDeq`B9WIu8Kcx(R&_}^6z8$Un{gyJ6* zPa~hZV$I}lSNtNJwrkyUb&cL09S!#LQ_f@7KV5w*@gy6)d<1H{?2pb5C4OGZ&5K_* z8UD+pL)Zu8N5>ZhGv;`(~Ai$e>?92J-jkl=&4ou7cRBntN;ZmXBHS zHi-it`i0V3!f%n8R^<75X4)Li%(Am%w{#`B7ns)h_!eG;>jgVN(sca(_#@okb#2hH zfvMP{q8G!NTc)3r0X(Mr;`hNZI4n8nBhWIUc02p4+MnE&XTvcl+pgbNsn5!WE1PD* z>I9QIDz(_p)X%7I%C*Gro?GUydp>8H57TFQwqD&!&s2S-duO|M&mTT~xISXvcWskR zUqAYu{6kOrOr6X+25!%L?)j~bwfe{ALz-J1tIguujo$(f`7V4haOODutNnV0e)NpA zHEAaMX0~aT-OPSQHfiy<`9ITeF0oO2h%IU5=~16aY@H}SVwQ?g*<;A&&Ow)FoHM&`cvcF#->Ks8p^ly z&+hr05q_IBJnP}}X@9~NIJL3c6?uM0`xM1O8L_QY3$W`|HnQj^z1? zBk|w!e0`=$UKQni3O*l<(m%Et(dOavX@7%R#BD9cm**RQq4H0hNxakn`gnkQRehvs zuck$wA3Kitp%u05vz;CrWi=A7-7j4Ghg}`^Vb?`ngWpsAUElKezm%RSPwZQ%Gg6=U znV4=dCSq*F_ucc!L%wg!r7@<{)J{dlpZb~V;_96`2!5yuo^Ll3+XA%Ywvof=W@Fiegnr7z z%l`rAiL+ZP=0G-U@w3Zb4Zq2+iA8*5{Z$>-f4F|QmROfs_kb_w39v2mguni4?SN$1s@me=e%uk(UOI1 zHIuSMlihOV&B;u;;Q()>-By?5^T_kj+&*55%H9cK@a4Z~1sj zNw^EnfJ3zQVcEEa%a#pK_HE(N<+lQ15ez4st()lZT}l=i~EELl}%B$c5%vxL&W*dga=n2Rei*>W$lO8z&u~U?sln{ z#l6dJ*y?yI!}_|9SgNPmf9v_~XYUX9j=~Q0OVvX-ZQ0UfM^pb4zmc%W!XeAA>g;E- zJq^4v(Bnlt+v%5C$FrXK{NbLj>#iT{ss>JWE#()|iR?(~qs|Uy{c+42^6`p`Pxddk zDStui#@a4tx_qtkm%ko6@9(TYzvzQKXdgb153vLNeBJlg{dVR1D}T$}@pE|4KEwvJ zkGZ_hkjq1!+xgR9hi~Gw));3xkcmcSh2ML*uA?7dxwwPbL1h(Ygl8%4dk?sWyPxi@ zXUJ?}pUIIUzr8qmq=(7Csj6a;w(Yumh<_V3jI%B= zR4$*P#m0caP~3k+d(QQ(*e|DXZb>fvfIMA2p5oRe$U8TlTzh|VxdmUG&Utbs@wZ?k zs?P@hLEa^uODYd%PVNOxg6EWN!P%s##Sg81+%xd=k5N9i%JVpvFQ{U3^C=&la2YY1 zIUjF{HL;uE7hFTE(jv~o#0^&-TG>Q(#Ws+|84UXbwt=wEU~No?fA0(NPzsY!YdvRQ za33)nIs5KmPY8#0!t0!SU*p^hr*^|V_{BHCVe?Wgn_oqFP0DlbS3VPLGDY~?qSi&d zP;p(wyE@;B?@>8<6mO+HO5N4ym6yeo zWS0FU=gFYXD-=}ds`G2rEu7oQai+bm;#%~heQ)Aw;v_jYDqlj<%bXh(d;K!yh-l}u#&NH1?=W|;}-;stWel&`eA(ku05)HC8Kb^9v+{gb8=SJt`co-4UG zIaCUWDIS&*{Eoicq@#?2qXTM&(09_Z(oB;@O^V3h-7h^S-L!lSuBau%I&^>^i+k!v z_iHq)k!d^}j(X1B4Z1ZjQG*zR{Uct7>-$jNOL;}^pD^Vim$j?EeRekS-Wxb8Pi8OF z#?yzpf80Q9H~qb{SpB^EHtvwv$=8W>TbjQ(|4Y?TKTZZuBOiB03MZdBJ?bc~ZpXwo zC$^b%Y0^K0>d@(0&kOyVtFz+2B^&>b({JUOmH!wuD{AJnThmIhf8Q}|^DxtUD55>$_HS88A1%xb#u&6X z)54@2hYKC-$i$h`%J9DZl<{q(uiN51m6 z$;r_oTzwz+9((P!>~Xgvv%g0-f6}=_=Ro;YiQW9g(5pjV#uwcEarb!A-#Ay4;%t-4 z-gPm3>=1j#!|-;jWWU&X@a4gejeXL+4gdb5L@s`?7<^#S_`6Eu@eH_k5qIcRv*;|1NP;--rGWP3$7<&;4tf=(f??i@f(jnHMTm*;S=}!-);Q&|E7UqP}Zwn_ZIaoNw)ltRG2( zlI(n}-}Tv;7BRwg4{W@w@dC}&T4%HdI@^%$<9^rQ^gZ{xuBvB^%o>F)$F#iXo|)d# zvlZ(3DtbR7(~Es}pOMW@-_5leY9@r8Lmybr~fm-wPsA^brWt(s6BAqz<$=Ny^F3A3@FVmU(7qWiH zCdFPMV*;xfHugV=@yw9^@Y!!tEUM1)y{`2#*%z?k7Q#miKF-eTx}F0o zcRI!L<<{I^(^TG6`Lw>PA2^>YaQ^(MVi2_siMz4$6?o1s=9;VvSzaL?Ec0xpNj{cr zY8|ZgtBN}+#(3ZM{$KsU>T1M8{4a5R$;P30ni01~*jUWoS9{wSCh_*c0sotZhZ@HF zzw2JF{a|ec=K4+C=hs@ZG-t_vHvSgz!Pka-M(oXA@-)?QpD*sped@9<4Ti^f59io} o>=i~1yfm<3xX*tKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z000WjNkl>39W1HC6m>9C8%0G40K$c1?5$%Ch6!oxDPJvTUPL)>gX+=&>PLXn`qG&mh9##lwwNfanMin@iAvV~KnLYT; zW|qv@GjC?>dE?(#`pF7`ncuwMXWsk0H$T6T6h#54brql{AOJ`N0I5~gcKip@oaBe= z3IhmfKHHcDnFW}s7pnj`Vpd`HhFKXvN%QGxDKm;a00dMJK)c2w%&bV#z!9qPdqrl4 z8msuK2M|ON08s!Z*k`DL=ZyeJuz!~U6aXBs&msZfZnqv|7G-y9vlRl+$*jU4$TKSu z0M4jGV<8Xw83Yh#RtE4|V*~)l>?E!+(G&vE#cW?=M+89qz$ci+d@|EgA=T z?@A4P9R8G=zjSCoAOKhx&00@r z7638U0133V!T?U8x`35qd4lf&ILWf(Fi6_`ryam9fLDG6AjE=ylHzUH8~lp3(<`=? z;2Qv=~V#K zY@fz_cZY+NlhbLZ0Ekky-_XP`#oF8x0H`Z`G|zAB6j5C;YB~V4!q*(d;lQ$bz=7b? z+J5t7yZ!9|5OZT%LgJcs#~KZQTFgO7pEr`iB=6Ll7l0(Fn8Qm-@U9Q=0C2+T#R!rk zO7hIa0-PtJuHU;ufvW%{P_5o2c~hOzoRn}20QE~761B5uB>_lCb5g(!0Q~%=4L>Pv zB|#5Zy!%Ol%nHo*0s#wD#i(6{QOs;_Z3O_5cte3B0CW%lVgew|NgYlBKoV270SFTS zVgn$}Nntwx#Nh31SxB`Ns+YW*0e~d_jDQOObt^WK*osPXQiKNpuWZFevZr9J8@Uz$ zROIO&8OE}WhniYin_L?QfDck1j0dHl?(*^G-e&rsd?0`OuWujEKb_yw{@=>2mC?b| zgR{r~W_@RU;nG)^(mXz8Zf1rqrY;U7+mmN{J9>c^LqB&*?FLqSBlc zRA!WSwxN-Zzc7Mr799g{&g{{ruTGzx{N3c3nTyf8xTV#lg^5QKt4;&3Hn}!l3q&hE ze)r`%Lu9KaL+i`N$ihWm!^IdM__-Tk+nfMELS^x4^u zW**}*uH0G~70{oE*(5M*27r}YE2H6H_-wtzW$MY)Qf4C~8zn;TcfEf@dz|x~=ec`< zm0K&LweGa+LH6->etWf6F0puhap20iD?{fx&s{S*)`zD)90RZ2SF`bI^maPOZx(l?SYYV7r$^#z^`{?b>M(sEJO z{ktpYt_+Ffk5O#(0I2)$=g#l%=$@>iROG2AQ%gJnoOm>``eXJ-?m2fYpX|)#)%o{v zCEJr{MDoWdwgC%^L;q7xv`2UB&mHEL^~QU%ntC#|#M=wh^2tt;^+Wat-EK7$40Vd+ zk5O#705H;aetXr<#bq`!vfT!9+9$(XDG*8s=uexOVAp*BWYpah$_3epfTd2Pu37y% zw|rt_^>0M?$0)V|9so$f$`k#z2yc_7gHB?16C*(wnXyBD7IVxeDnP`x&Q>FVB+o{?s64}E?!?8Fe-L1qc8sX z#j=r4R!X>z>%I7ULq=V^Nd8y>pzizXG8-8=dysvs_kTRaoh!FiM#l%oAJ`fjH!`wO zvBco%!P(5s%n(nHWK`7g?5AhTBKcz!TkeuDqhv&zl+>yTeEP?y*LtEoXOGte8p%wh zQN7YKr)uy@mC{yZK61?r*k1AnIwfIx0E7Yj+6<99f7$sv&!gK~${u7N>mAcE ze}BwLFtvbo|E>Gag8HKyQzHNltz2O2udy5JJL?NPq{~HlIsH6+!^tmUPCS}ejm$@` z@%p6aupqEMx-o6D3xFyXz_gm&)k<2{ch(nxY7wZNB2ue9HT&DaP4>q! z0A+CO4|MhZRdsrphDW6F2>@nW(4Vpq07gSV1r2z0IjLbP=b2hT zuN4450Ei7hyHZL zUMe$6&dDAC0Av~pgz5TCKVh{3z!5tzeRt5iQUJ)xjB?}#0BSF=NA2uc?I|;grTPk< zuZQPQT_7TPOC=T?xDCJo&xuH`D+i88_yHRylc~);BboQ6NDz+gx(^6{=6Bx?Ma+D|P#>1RpL3XO}^cf{7PVk!mJHeOEsyG!C5H@za0}n{IoNofFDd|F7p$&n zCjoS#b>3H`pjup;Lz5q(d0~;}fLWdm34Wg`sCE0ED5>+(DxHk#7f}<;Vm=FeUK4oF zyp_dk%d|&$TW}iJnCN%BYMy%?k5|{}kJuQw2cSb^Awhy(X1$qeo|Om>YScyyvtc0y zAPVoj<5=B|E6+@b;uw*h)Rpjdu_VGEIKe(cO}x_!EQu|^W%b_y0H3^`1Jca13;+NC07*qoM6N<$f-%Na+W-In literal 0 HcmV?d00001 diff --git a/src/qt/qcc/main.cpp b/src/qt/qcc/main.cpp new file mode 100644 index 00000000..b6c098da --- /dev/null +++ b/src/qt/qcc/main.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include +#include "mainwindow.h" + +/*! + \defgroup client QCC client module + + The QCC-client can connect to a \ref server "QCC-server" to send and receive instant + messages from other QCC-clients and also see their online status. + */ + +//! The main entry point of this application. +/*! + \param argc The command-line argument count. + \param argv The command-line argument-array. + \return The return code of the application + \ingroup client + */ +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + MainWindow mainWindow; + mainWindow.show(); + + return app.exec(); +} diff --git a/src/qt/qcc/mainwindow.cpp b/src/qt/qcc/mainwindow.cpp new file mode 100644 index 00000000..d71f0d17 --- /dev/null +++ b/src/qt/qcc/mainwindow.cpp @@ -0,0 +1,403 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "qccpacket.h" +#include "contact.h" +#include "contactlistmodel.h" +#include "messagewindow.h" +#include "registerdialog.h" + +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), ui(new Ui::MainWindow), m_contacts(new ContactListModel(this)), + m_messageWindow(new MessageWindow(&m_socket)), m_packetSize(0) +{ + ui->setupUi(this); + + connect(&m_socket, SIGNAL(connected()), SLOT(socket_connected())); + connect(&m_socket, SIGNAL(disconnected()), SLOT(socket_disconnected())); + connect(&m_socket, SIGNAL(readyRead()), SLOT(socket_readyRead())); + connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socket_error(QAbstractSocket::SocketError))); +#ifdef DEBUG + connect(&m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socket_stateChanged(QAbstractSocket::SocketState))); +#endif + + ui->contactListView->setModel(m_contacts); + + QCA::init(); + if (!QCA::isSupported("sha256") || !QCA::isSupported("pkey") || !QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA)) { + QMessageBox::critical(this, "QCA error", "QCA OpenSSL-Plugin not found!\n\nThe application will now quit."); + QTimer::singleShot(100, qApp, SLOT(quit())); + } +} + +MainWindow::~MainWindow() +{ + delete m_messageWindow; + delete m_contacts; + delete ui; +} + +void MainWindow::connectToHost() +{ + if (m_socket.state() > 0) + return; + + QStringList server = ui->serverLineEdit->text().split(':'); + QString host = server.at(0); + quint16 port = server.length() < 2 ? MainWindow::DEFAULT_PORT : server.at(1).toUShort(); + //qDebug("server = %s:%d", qPrintable(host), port); + + m_packetSize = 0; + m_socket.connectToHost(host, port); + ui->loginButton->setEnabled(false); + ui->registerButton->setEnabled(false); +} + +void MainWindow::socket_connected() +{ +#ifdef DEBUG + qDebug("MainWindow::socket_connected()"); +#endif +} + +void MainWindow::socket_disconnected() +{ +#ifdef DEBUG + qDebug("MainWindow::socket_disconnected()"); +#endif + + if (isHidden()) // hack, true when window is closing + return; + + ui->stackedWidget->setCurrentIndex(0); + setWindowTitle("QCC"); + m_messageWindow->closeAllTabs(); + m_messageWindow->close(); + ui->loginButton->setEnabled(true); + ui->registerButton->setEnabled(true); +} + +void MainWindow::socket_readyRead() +{ +#ifdef DEBUG + qDebug("MainWindow::socket_readyRead(): %li bytes available", (long)m_socket.bytesAvailable()); +#endif + + QDataStream in(&m_socket); + in.setVersion(QDataStream::Qt_4_0); + if (m_packetSize == 0) { + if (m_socket.bytesAvailable() < (int)sizeof(quint32)) // packet size + return; + in >> m_packetSize; + } + if (m_socket.bytesAvailable() < m_packetSize) + return; + m_packetSize = 0; // reset packet size + + qint32 type; + in >> type; + +#ifdef DEBUG + qDebug("PacketType = %i (%s)", type, qPrintable(QccPacket::typeString((QccPacket::PacketType)type))); +#endif + + switch ((QccPacket::PacketType)type) { + case QccPacket::ConnectionAccepted: + { + m_privateKey = QCA::KeyGenerator().createRSA(1024); + if (m_privateKey.isNull() || !m_privateKey.canDecrypt()) { + qWarning("Failed to generate private key"); + break; + } + QccPacket packet(m_register ? QccPacket::UserRegister : QccPacket::UserAuthentication); + packet.stream() << ui->usernameLineEdit->text() + << QCA::Hash("sha256").hashToString(ui->passwordLineEdit->text().toUtf8()) + << m_privateKey.toPublicKey().toDER(); + packet.send(&m_socket); + break; + } + case QccPacket::ConnectionRefused: + QMessageBox::critical(this, "Connection Refused", "Access denied!"); + break; + case QccPacket::RegisterSuccess: + QMessageBox::information(this, "Register Success", "Your registration has been successful.\n" + "You will now be logged in..."); + ui->stackedWidget->setCurrentIndex(1); + setWindowTitle("QCC - " + ui->usernameLineEdit->text()); + break; + case QccPacket::RegisterFailure: + { + QString reason; + in >> reason; + m_socket.disconnectFromHost(); + QMessageBox::warning(this, "Register Failure", reason); + break; + } + case QccPacket::AuthenticationSuccess: + QccPacket(QccPacket::RequestContactList).send(&m_socket); + ui->stackedWidget->setCurrentIndex(1); + setWindowTitle("QCC - " + ui->usernameLineEdit->text()); + break; + case QccPacket::AuthenticationFailure: + { + QString reason; + in >> reason; + m_socket.disconnectFromHost(); + QMessageBox::warning(this, "Authentication Failure", reason); + break; + } + case QccPacket::RequestAuthorization: + { + QString username; + in >> username; + + int question = QMessageBox::question(this, "Request Authorization", "The user \"" + username + + "\" would like to add you to her/his contact list.\n" + "Do you accept the authorization request?", + "Accept", "Decline"); + + QccPacket packet(question == 0 ? QccPacket::AuthorizationAccepted : QccPacket::AuthorizationDeclined); + packet.stream() << username; + packet.send(&m_socket); + break; + } + case QccPacket::AuthorizationAccepted: + { + QString username; + qint32 status; + QByteArray publicKey; + in >> username >> status >> publicKey; + Contact *contact = m_contacts->contact(username); + if (!contact) { + contact = new Contact(username); + m_contacts->add(contact); + } + contact->setPublicKey(publicKey); + contact->setStatus((Contact::Status)status); + break; + } + case QccPacket::AuthorizationDeclined: + { + QString username; + in >> username; + QMessageBox::information(this, "Authorization Declined", "The user \"" + username + "\" has declined your authorization request."); + break; + } + case QccPacket::AuthorizationFailure: + { + QString reason; + in >> reason; + QMessageBox::warning(this, "Authorization Failure", reason); + break; + } + case QccPacket::ContactList: + { + qint32 contactCount; + in >> contactCount; + m_contacts->clear(); + QList contacts; + for (int i = 0; i < contactCount; i++) { + QString username; + qint32 status; + QByteArray publicKey; + in >> username >> status >> publicKey; + Contact *contact = new Contact(username); + contact->setPublicKey(publicKey); + contact->setStatus((Contact::Status)status); + contacts.append(contact); + } + m_contacts->add(contacts); + break; + } + case QccPacket::ContactStatusChanged: + { + QString username; + qint32 status; + QByteArray publicKey; + in >> username >> status >> publicKey; + Contact *contact = m_contacts->contact(username); + if (contact) { + contact->setPublicKey(publicKey); + contact->setStatus((Contact::Status)status); + } + break; + } + case QccPacket::ContactRemoved: + { + QString username; + in >> username; + Contact *contact = m_contacts->contact(username); + if (contact) { + m_messageWindow->closeTab(contact); + m_contacts->remove(contact); + } + break; + } + case QccPacket::Message: + { + qint32 id; + QString username; + QByteArray encryptedMessage; + in >> id >> username >> encryptedMessage; + + Contact *contact = m_contacts->contact(username); + if (!contact) // received message from unknown user (not on contact list) + break; + + const int keySize = m_privateKey.bitSize() / 8; + QCA::SecureArray message; + for (int i = 0; i < encryptedMessage.length() / keySize; i++) { + QCA::SecureArray messageBlock; + if (!m_privateKey.decrypt(encryptedMessage.mid(i * keySize, keySize), &messageBlock, QCA::EME_PKCS1_OAEP)) { + qWarning("Error decrypting"); + return; + } + message.append(messageBlock); + } + m_messageWindow->appendMessage(contact, QString(message.toByteArray())); + + QccPacket packet(QccPacket::MessageSuccess); + packet.stream() << id << username; + packet.send(&m_socket); + + break; + } + case QccPacket::MessageSuccess: + { + qint32 id; + QString username; + in >> id >> username; + qDebug() << "MessageSuccess: " << id << " => " << username; + break; + } + case QccPacket::MessageFailure: + { + qint32 id; + QString username, reason; + in >> id >> username >> reason; + QMessageBox::warning(this, "Message Failure", reason); + break; + } + default: + qWarning("MainWindow::socket_readyRead(): Illegal PacketType %i", type); + return; + } +} + +void MainWindow::socket_error(QAbstractSocket::SocketError error) +{ +#ifdef DEBUG + qDebug("MainWindow::socket_error(%i) => %s", error, qPrintable(m_socket.errorString())); +#endif + + QMessageBox::critical(this, "Connection Error", m_socket.errorString()); + + ui->loginButton->setEnabled(true); + ui->registerButton->setEnabled(true); +} + +#ifdef DEBUG +void MainWindow::socket_stateChanged(QAbstractSocket::SocketState state) +{ + qDebug("MainWindow::socket_stateChanged(%i)", state); +} +#endif + +void MainWindow::on_loginButton_clicked() +{ + m_register = false; + connectToHost(); +} + +void MainWindow::on_registerButton_clicked() +{ + RegisterDialog dialog(this); + dialog.exec(); + if (dialog.result()) { + ui->usernameLineEdit->setText(dialog.username()); + ui->passwordLineEdit->setText(dialog.password()); + m_register = true; + connectToHost(); + } +} + +void MainWindow::on_contactListView_activated(const QModelIndex &index) +{ + Contact *contact = m_contacts->contact(index); + if (!contact) + return; + + m_messageWindow->addTab(contact); +} + +void MainWindow::on_contactListView_customContextMenuRequested(const QPoint &pos) +{ + Contact *contact = m_contacts->contact(ui->contactListView->currentIndex()); + if (!contact) + return; + + QMenu menu(ui->contactListView); + menu.addAction("Remove contact \"" + contact->username() + "\"", this, SLOT(removeCurrentContact(bool))); + menu.exec(ui->contactListView->mapToGlobal(pos)); +} + +void MainWindow::on_addContactButton_clicked() +{ + QString username = ui->contactLineEdit->text(); + if (username.isEmpty()) + return; + + QccPacket packet(QccPacket::RequestAuthorization); + packet.stream() << username; + packet.send(&m_socket); + + ui->contactLineEdit->clear(); +} + +void MainWindow::removeCurrentContact(bool) +{ + Contact *contact = m_contacts->contact(ui->contactListView->currentIndex()); + if (!contact || !contact->isValid()) + return; + + int question = QMessageBox::question(this, "Remove contact", "Do you really want to remove the contact \"" + + contact->username() + "\" from your contact list?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + + if (question == QMessageBox::Yes) { + QccPacket packet(QccPacket::RemoveContact); + packet.stream() << contact->username(); + packet.send(&m_socket); + } +} + +void MainWindow::closeEvent(QCloseEvent *) +{ + qApp->quit(); +} diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h new file mode 100644 index 00000000..934ec9bf --- /dev/null +++ b/src/qt/qcc/mainwindow.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include + +class ContactListModel; +class MessageWindow; + +//! The UI namespace. +namespace Ui { + class MainWindow; +} + +//! The MainWindow class defines the main window of this application. +/*! + \ingroup client + */ +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + + //! Constructs the MainWindow. + /*! + \param parent The parent object. + */ + explicit MainWindow(QWidget *parent = 0); + + //! Destroys the MainWindow. + ~MainWindow(); + +private slots: + + //! Connects the client to a QCC-server. + /*! + \sa \ref server "QCC server module" + */ + void connectToHost(); + + //! The client is connected to the server. + /*! + \sa connectToHost() + */ + void socket_connected(); + + //! Closes all open message windows and returns to the login screen. + void socket_disconnected(); + + //! Handles all incoming data packets from the server. + void socket_readyRead(); + + //! Handles all socket error messages. + /*! + \param error The socket error. + */ + void socket_error(QAbstractSocket::SocketError error); + +#ifdef DEBUG + //! Prints the sockets state to the debug output (in debug mode only). + /*! + \param state The socket state. + */ + void socket_stateChanged(QAbstractSocket::SocketState state); +#endif + + //! Removes the current contact from the contact list on the remote server. + void removeCurrentContact(bool); + + //! Establishes a connection to the QCC-server and sends a user authentication request. + /*! + \sa connectToHost(), QccPacket::UserAuthentication + */ + void on_loginButton_clicked(); + + //! Establishes a connection to the QCC-server and sends a user register request. + /*! + \sa connectToHost(), QccPacket::UserRegister + */ + void on_registerButton_clicked(); + + //! Opens the activated contact's tab of the message window. + /*! + \sa MessageWindow + */ + void on_contactListView_activated(const QModelIndex &index); + + //! Shows the context menu to remove the selected contact. + /*! + \param pos The position of the context menu. + \sa QccPacket::RemoveContact + */ + void on_contactListView_customContextMenuRequested(const QPoint &pos); + + //! Sends a authorization request to the QCC-server. + /*! + \sa QccPacket::RequestAuthorization + */ + void on_addContactButton_clicked(); + +private: + + //! The default network port, which will be used if no port is provided by the user. + static const quint16 DEFAULT_PORT = 54321; + + Ui::MainWindow *ui; //!< Pointer to the UI: + ContactListModel *m_contacts; //!< The contact list model. + MessageWindow *m_messageWindow; //!< The message window. + QTcpSocket m_socket; //!< The TCP-socket for the connection with the QCC-server. + quint32 m_packetSize; //!< The packet size of the current network packet from the server. + bool m_register; //!< Whether or not the user wants to register a new user or just log in. + + QCA::PrivateKey m_privateKey; //!< The RSA private key used for the message encryption. + + //! Exits the application. + void closeEvent(QCloseEvent *); +}; + +#endif // MAINWINDOW_H diff --git a/src/qt/qcc/mainwindow.ui b/src/qt/qcc/mainwindow.ui new file mode 100644 index 00000000..2e474be5 --- /dev/null +++ b/src/qt/qcc/mainwindow.ui @@ -0,0 +1,244 @@ + + + MainWindow + + + + 0 + 0 + 174 + 318 + + + + QCC - Qt CryptoChat + + + + + 0 + + + 0 + + + + + 0 + + + + + + + Server + + + + + + + 127.0.0.1 + + + + + + + Username + + + + + + + + + + + + + + Password + + + + + + + + + + QLineEdit::Password + + + + + + + Login + + + true + + + true + + + + + + + Register + + + + + + + + + Qt::Vertical + + + + 20 + 99999 + + + + + + + + :/icons/qcc128a.png + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + + + + + 0 + + + 0 + + + + + Qt::CustomContextMenu + + + Qt::ScrollBarAlwaysOff + + + false + + + + 16 + 16 + + + + + + + + 0 + + + + + + + + + + + + Add Contact + + + + + + + + + + + + + + + serverLineEdit + usernameLineEdit + passwordLineEdit + loginButton + registerButton + contactListView + contactLineEdit + addContactButton + + + + + + + usernameLineEdit + returnPressed() + loginButton + click() + + + 86 + 82 + + + 46 + 155 + + + + + passwordLineEdit + returnPressed() + loginButton + click() + + + 86 + 127 + + + 46 + 155 + + + + + contactLineEdit + returnPressed() + addContactButton + click() + + + 49 + 14 + + + 49 + 14 + + + + + diff --git a/src/qt/qcc/messagepage.cpp b/src/qt/qcc/messagepage.cpp new file mode 100644 index 00000000..d6f3b889 --- /dev/null +++ b/src/qt/qcc/messagepage.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "messagepage.h" +#include "ui_messagepage.h" +#include "qccpacket.h" +#include "contact.h" + +#include + +MessagePage::MessagePage(QTcpSocket *socket, Contact *contact, QWidget *parent) : + QWidget(parent), ui(new Ui::MessagePage), m_socket(socket), m_contact(contact) +{ + Q_ASSERT(m_contact); // should never happen, just in case... + + ui->setupUi(this); + connect(m_contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); + connect(ui->closeButton, SIGNAL(clicked()), SIGNAL(closeButtonClicked())); + ui->messageTextEdit->installEventFilter(this); +} + +MessagePage::~MessagePage() +{ + delete ui; +} + +void MessagePage::appendMessage(const QString &message, const QColor &color) +{ + QString messageHtml = message; + messageHtml.replace('\n', "
"); + ui->messagesTextEdit->append("" + + m_contact->username() + ": " + messageHtml); +} + +void MessagePage::contact_statusChanged() +{ + ui->messagesTextEdit->append(QString("%1 is now %2."). + arg(m_contact->username()). + arg(m_contact->statusString())); +} + +void MessagePage::on_sendButton_clicked() +{ + QString text = ui->messageTextEdit->toPlainText().trimmed(); + if (text.isEmpty() || !m_contact->isOnline()) + return; + + QccPacket message; + message.stream() << qint32(qrand()) << m_contact->username() << m_contact->encrypt(text); + message.send(m_socket); + + text.replace('\n', "
"); + ui->messagesTextEdit->append("You: " + text); + + ui->messageTextEdit->clear(); + ui->messageTextEdit->setFocus(); +} + +void MessagePage::setFocusOnInput() +{ + ui->messageTextEdit->setFocus(); +} + +bool MessagePage::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == ui->messageTextEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) + && keyEvent->modifiers() == Qt::NoModifier) { + on_sendButton_clicked(); + return true; + } else + return false; + } else + return false; + } else + return QWidget::eventFilter(obj, event); +} diff --git a/src/qt/qcc/messagepage.h b/src/qt/qcc/messagepage.h new file mode 100644 index 00000000..8020e249 --- /dev/null +++ b/src/qt/qcc/messagepage.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef MESSAGEPAGE_H +#define MESSAGEPAGE_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTcpSocket; +QT_BEGIN_NAMESPACE + +//! The UI namespace. +namespace Ui { + class MessagePage; +} + +class Contact; + +//! The MessagePage class defines one tab of the MessageWindow. +/*! + \ingroup client + */ +class MessagePage : public QWidget +{ + Q_OBJECT + +public: + + //! Constructs a MessagePage. + /*! + \param socket The TCP-socket to the server. + \param contact The contact associated with this page. + \param parent The parent object. + */ + MessagePage(QTcpSocket *socket, Contact *contact, QWidget *parent = 0); + + //! Destroys the MessagePage. + ~MessagePage(); + + //! Returns the contact of this page. + /*! + \return The contact of this page. + */ + inline Contact* contact() { return m_contact; } + + //! Appends a \a message to this page. + /*! + \param message The message to append. + \param color The color for the \a message. + \sa MessageWindow::appendMessage() + */ + void appendMessage(const QString &message, const QColor &color = Qt::black); + +signals: + + //! This signal is emitted whenever the close button of this page is clicked. + void closeButtonClicked(); + +public slots: + + //! Sets the focus on the input field of this page. + void setFocusOnInput(); + +private slots: + + //! Sends the \a message from the input field to the server. + void on_sendButton_clicked(); + + //! Prints a status changed text to the chat field. + void contact_statusChanged(); + +private: + + Ui::MessagePage *ui; //!< Pointer to the UI. + QTcpSocket *m_socket; //!< The TCP-socket to the server. + Contact *m_contact; //!< Pointer to the contact of this page. + + //! Filters key events for the input edit to send messages via the \c Return and \c Enter key. + /*! + \param obj The object to be filtered. + \param event The event that occured. + \return \c True to forward this event; otherwise returns \c false. + \sa QObject::eventFilter() + */ + bool eventFilter(QObject *obj, QEvent *event); +}; + +#endif // MESSAGEPAGE_H diff --git a/src/qt/qcc/messagepage.ui b/src/qt/qcc/messagepage.ui new file mode 100644 index 00000000..f954fc44 --- /dev/null +++ b/src/qt/qcc/messagepage.ui @@ -0,0 +1,104 @@ + + + MessagePage + + + + 0 + 0 + 400 + 300 + + + + Message + + + + 2 + + + 0 + + + + + Qt::Vertical + + + false + + + + Qt::ScrollBarAlwaysOff + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> + + + + + + 0 + 1 + + + + Qt::ScrollBarAlwaysOff + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> + + + + + + + + 2 + + + + + Close + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Send + + + + + + + + + + diff --git a/src/qt/qcc/messagewindow.cpp b/src/qt/qcc/messagewindow.cpp new file mode 100644 index 00000000..d6f8b658 --- /dev/null +++ b/src/qt/qcc/messagewindow.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "messagewindow.h" +#include "ui_messagewindow.h" +#include "contact.h" +#include "messagepage.h" + +MessageWindow::MessageWindow(QTcpSocket *socket, QWidget *parent) : + QTabWidget(parent), ui(new Ui::MessageWindow), m_socket(socket) +{ + ui->setupUi(this); + connect(this, SIGNAL(tabCloseRequested(int)), SLOT(tabCloseRequested(int))); +} + +MessageWindow::~MessageWindow() +{ + qDeleteAll(m_pages.values()); + delete ui; +} + +bool MessageWindow::addTab(Contact *contact) +{ + if (!contact) + return false; + + bool tabAdded = false; + MessagePage *page = NULL; + + if (m_pages.contains(contact)) { + page = m_pages.value(contact); + setCurrentWidget(page); + } else { + page = new MessagePage(m_socket, contact); + connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); + connect(page, SIGNAL(closeButtonClicked()), SLOT(page_closeButtonClicked())); + int index = QTabWidget::addTab(page, contact->statusIcon(), contact->username()); + m_pages.insert(contact, page); + setCurrentIndex(index); + tabAdded = true; + } + + show(); + raise(); + activateWindow(); + if (page != NULL) + page->setFocusOnInput(); + + return tabAdded; +} + +void MessageWindow::closeTab(Contact *contact) +{ + if (!m_pages.contains(contact)) + return; + + // find tab and close it + for (int i = 0; i < count(); i++) { + if (tabText(i) == contact->username()) { + tabCloseRequested(i); + return; + } + } +} + +void MessageWindow::closeAllTabs() +{ + clear(); + qDeleteAll(m_pages.values()); + m_pages.clear(); +} + +void MessageWindow::appendMessage(Contact *contact, const QString &message) +{ + if (!contact) + return; + + addTab(contact); + m_pages.value(contact)->appendMessage(message, Qt::red); +} + +void MessageWindow::contact_statusChanged() +{ + Contact *contact = qobject_cast(sender()); + if (!contact) { + qWarning("MessageWindow::contact_statusChanged(): Cast of sender() to Contact* failed"); + return; + } + + // find tab and update the icon + for (int i = 0; i < count(); i++) { + if (tabText(i) == contact->username()) { + setTabIcon(i, contact->statusIcon()); + return; + } + } +} + +void MessageWindow::tabCloseRequested(int index) +{ + MessagePage *page = qobject_cast(widget(index)); + if (!page) { + qWarning("MessageWindow::tabCloseRequested(int): Cast of sender() to MessagePage* failed"); + return; + } + + m_pages.remove(page->contact()); + removeTab(index); + disconnect(page->contact(), SIGNAL(statusChanged()), this, SLOT(contact_statusChanged())); + delete page; + +#ifdef DEBUG + qDebug("tab closed %i", index); +#endif + + if (count() == 0) { +#ifdef DEBUG + qDebug("last tab closed => closing MessageWindow"); +#endif + close(); + } +} + +void MessageWindow::page_closeButtonClicked() +{ + emit tabCloseRequested(currentIndex()); +} diff --git a/src/qt/qcc/messagewindow.h b/src/qt/qcc/messagewindow.h new file mode 100644 index 00000000..53cb0469 --- /dev/null +++ b/src/qt/qcc/messagewindow.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef MESSAGEWINDOW_H +#define MESSAGEWINDOW_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTcpSocket; +QT_BEGIN_NAMESPACE + +class Contact; +class MessagePage; + +//! The UI namespace. +namespace Ui { + class MessageWindow; +} + +//! The MessageWindow class defines the tabbed message window. +/*! + \ingroup client + */ +class MessageWindow : public QTabWidget +{ + Q_OBJECT + +public: + + //! Constructs a MessageWindow. + /*! + \param socket The TCP-socket to the server. + \param parent The parent object. + */ + explicit MessageWindow(QTcpSocket *socket, QWidget *parent = 0); + + //! Destroys the MessageWindow. + ~MessageWindow(); + + //! Adds a tab to the window. + /*! + \param contact The contact for the tab. + \return \c True if a new tab has been added; otherwise returns \c false. + \note If a tab for the contact already exists, the existing tab gets the focus. + \sa closeTab(), appendMessage() + */ + bool addTab(Contact *contact); + + //! Closes the tab for the \a contact (if any). + /*! + \param contact The contact of the tab that will be closed. + \sa addTab(), closeAllTabs() + */ + void closeTab(Contact *contact); + + //! Closes all tabs. + /*! + \sa closeTab() + */ + void closeAllTabs(); + + //! Appends a \a message to the tab of the given \a contact. + /*! + \param contact The sender of the message. + \param message The message to append. + \note If there is no tab for the \a contact, one will be created. + \sa addTab() + */ + void appendMessage(Contact *contact, const QString &message); + +private slots: + + //! This slot should be called from a \a contact whenever the status changes. + void contact_statusChanged(); + + //! Removes the tab with the given \a index. + /*! + \param index The index of the tab to remove. + */ + void tabCloseRequested(int index); + + //! Closes the current tab. + /*! + \sa QTabWidget::currentIndex() + */ + void page_closeButtonClicked(); + +private: + + Ui::MessageWindow *ui; //!< Pointer to the UI. + QTcpSocket *m_socket; //!< The TCP-socket to the server. + QHash m_pages; //!< A set of the contacts for all open tabs. +}; + +#endif // MESSAGEWINDOW_H diff --git a/src/qt/qcc/messagewindow.ui b/src/qt/qcc/messagewindow.ui new file mode 100644 index 00000000..73af770e --- /dev/null +++ b/src/qt/qcc/messagewindow.ui @@ -0,0 +1,28 @@ + + + MessageWindow + + + + 0 + 0 + 400 + 300 + + + + QCC - Messages + + + -1 + + + true + + + true + + + + + diff --git a/src/qt/qcc/qcc.pro b/src/qt/qcc/qcc.pro new file mode 100644 index 00000000..1fefe73c --- /dev/null +++ b/src/qt/qcc/qcc.pro @@ -0,0 +1,50 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-01-23T16:10:20 +# +#------------------------------------------------- + +QT = core gui network + +TARGET = qcc +TEMPLATE = app +CONFIG += link_prl crypto + +QCC_CORE_PREFIX = ../qcc-core + +CONFIG(debug, debug|release) { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug +} else { + DEFINES += RELEASE + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release +} + +INCLUDEPATH += ../qcc-core +LIBS += -L$$QCC_CORE_PREFIX -lqcc-core + +HEADERS += mainwindow.h \ + registerdialog.h \ + messagewindow.h \ + messagepage.h \ + contact.h \ + contactlistmodel.h + +SOURCES += main.cpp \ + mainwindow.cpp \ + registerdialog.cpp \ + messagewindow.cpp \ + messagepage.cpp \ + contact.cpp \ + contactlistmodel.cpp + +FORMS += mainwindow.ui \ + registerdialog.ui \ + messagewindow.ui \ + messagepage.ui + +RESOURCES += icons.qrc + +win32:RC_FILE = qcc.rc + +OTHER_FILES += qcc.rc diff --git a/src/qt/qcc/qcc.rc b/src/qt/qcc/qcc.rc new file mode 100644 index 00000000..ad53ecd2 --- /dev/null +++ b/src/qt/qcc/qcc.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "icons\\qcc.ico" diff --git a/src/qt/qcc/registerdialog.cpp b/src/qt/qcc/registerdialog.cpp new file mode 100644 index 00000000..1a67d213 --- /dev/null +++ b/src/qt/qcc/registerdialog.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#include "registerdialog.h" +#include "ui_registerdialog.h" + +#include + +RegisterDialog::RegisterDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::RegisterDialog) +{ + ui->setupUi(this); +} + +RegisterDialog::~RegisterDialog() +{ + delete ui; +} + +QString RegisterDialog::username() const +{ + return ui->usernameLineEdit->text(); +} + +QString RegisterDialog::password() const +{ + return ui->password1LineEdit->text(); +} + +void RegisterDialog::on_buttonBox_accepted() +{ + QString username = ui->usernameLineEdit->text(); + if (username.isEmpty() || username.length() < 3) { + QMessageBox::warning(this, "Username error", "The username must be at least 3 characters long."); + return; + } + + QString password = ui->password1LineEdit->text(); + if (password.isEmpty() || password.length() < 3) { + QMessageBox::warning(this, "Password error", "The password must be at least 3 characters long."); + return; + } + if (password != ui->password2LineEdit->text()) { + QMessageBox::warning(this, "Password error", "The passwords do not match."); + return; + } + + accept(); +} diff --git a/src/qt/qcc/registerdialog.h b/src/qt/qcc/registerdialog.h new file mode 100644 index 00000000..4ac96548 --- /dev/null +++ b/src/qt/qcc/registerdialog.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Alexander Vos , +** Kai Wellmann +** +** This file is part of Qt Crypto Chat (QCC). +** +** Qt Crypto Chat is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Qt Crypto Chat is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Qt Crypto Chat. If not, see . +** +****************************************************************************/ + +#ifndef REGISTERDIALOG_H +#define REGISTERDIALOG_H + +#include + +//! The UI namespace. +namespace Ui { + class RegisterDialog; +} + +//! The RegisterDialog class defines the register window. +/*! + \ingroup client + */ +class RegisterDialog : public QDialog +{ + Q_OBJECT + +public: + + //! Constructs a RegisterDialog. + /*! + \param parent The parent object. + */ + explicit RegisterDialog(QWidget *parent = 0); + + //! Destroys the RegisterDialog. + ~RegisterDialog(); + + //! Returns the username. + /*! + \return The username. + */ + QString username() const; + + //! Returns the password. + /*! + \return The password. + */ + QString password() const; + +private slots: + + //! Checks if the username and password is valid and closes the window. + void on_buttonBox_accepted(); + +private: + + Ui::RegisterDialog *ui; //!< Pointer to the UI. +}; + +#endif // REGISTERDIALOG_H diff --git a/src/qt/qcc/registerdialog.ui b/src/qt/qcc/registerdialog.ui new file mode 100644 index 00000000..a0c6016c --- /dev/null +++ b/src/qt/qcc/registerdialog.ui @@ -0,0 +1,121 @@ + + + RegisterDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 228 + 200 + + + + QCC - Register + + + true + + + + QLayout::SetFixedSize + + + + + Username + + + + + + + + + + + + + + Password + + + + + + + + + + QLineEdit::Password + + + + + + + Password (repeat) + + + + + + + + + + QLineEdit::Password + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + rejected() + RegisterDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From 73d52fec11daa3237a2b232c7bd3723ace811fd6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:48:33 -0400 Subject: [PATCH 0456/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 6b6f8755..044fad71 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -24,7 +24,7 @@ FORMS += \ RESOURCES += \ ../src/qt/dash.qrc -CONFIG += c++17 +CONFIG += c++17 ordered QMAKE_CXXFLAGS += -std=c++17 @@ -33,7 +33,14 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe -SUBDIRS += ..src/qt/Social-Network-Qt-Application-GUI.pro \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.b3887f6 \ - ..src/qt/Social-Network-Qt-Application-GUI.pro.user.fe1e10a.xml +TEMPLATE = subdirs + +SUBDIRS = qcc-core \ + qcc-server \ + qcc + +qcc-server.depends = qcc-core +qcc.depends = qcc-core + +OTHER_FILES += README.md \ + COPYING From 69b6ce97beda874457b472e412a0ad3ff10a223c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:51:19 -0400 Subject: [PATCH 0457/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e76f3e86..b056aeb8 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "newaccount.h" +#include "qcc/mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - newAccount(0), + mainWindow(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -621,8 +621,8 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - newAccount = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - newAccount->setStatusTip(tr("HTH World Social Media")); + mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + mainWindow->setStatusTip(tr("HTH World Chat")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -638,7 +638,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(newAccount, SIGNAL(triggered()), this, SLOT(gotoNewAccount())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -741,7 +741,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(newAccount); + media->addAction(mainWindow); } @@ -1070,10 +1070,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoNewAccount() +void BitcoinGUI::gotoMainWindow() { - newAccount->setChecked(true); - if (walletFrame) walletFrame->gotoNewAccount(); + mainWindow->setChecked(true); + if (walletFrame) walletFrame->gotoMainWindow(); } /*void BitcoinGUI::gotoTradingDialogPage() From 4b014f112a8d2fba55f00b2c5a1696a4e97ed0b1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:52:04 -0400 Subject: [PATCH 0458/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index e045e829..a2e6b772 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class NewAccount; +class MainWindow; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* newAccount; + QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoNewAccount(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From c9330ca8e06d073cfd3db37ff091e73aeec07cb6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:52:32 -0400 Subject: [PATCH 0459/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 29c45e55..a170c85a 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoNewAccount() +void WalletFrame::gotoMainWindow() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoNewAccount(); + i.value()->gotoMainWindow(); } /*void WalletFrame::gotoTradingDialogPage() From ce7dc40026fe46630b716c7a8348c181877bad3d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:52:53 -0400 Subject: [PATCH 0460/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 1f368c3d..a6eb3ece 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to social media page */ - void gotoNewAccount(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From c232a2902209bc0743b015600f62432df824642b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:53:51 -0400 Subject: [PATCH 0461/1324] Update walletview.cpp --- src/qt/walletview.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 8a762322..7f04f0b0 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "newaccount.h" +#include "qcc/mainwindow.h" #include "ui_interface.h" @@ -89,8 +89,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - newAccount = new NewAccount(); - addWidget(newAccount); + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -242,9 +242,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoNewAccount() +void WalletView::gotoMainWindow() { - setCurrentWidget(newAccount); + setCurrentWidget(mainWindow); } /*void WalletView::gotoTradingDialogPage() From e1fc3a17425242a3b1dc610c41f16495c6a683e6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 21:54:28 -0400 Subject: [PATCH 0462/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index bce4add4..8387d8b7 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,7 +9,7 @@ #include "masternodelist.h" #include "governancelist.h" /* #include "tradingdialogpage.h" */ -#include "newaccount.h" +#include "qcc/mainwindow.h" @@ -28,7 +28,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class NewAccount; +class MainWindow; QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - NewAccount *newAccount; + MainWindow *mainWindow; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -89,7 +89,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to social media page */ - void gotoNewAccount(); + void gotoMainWindow(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 9b0e278164808ff2003bf77490546ca6ed67397c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:04:08 -0400 Subject: [PATCH 0463/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 044fad71..a5efd81d 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -QT += core gui sql xml +QT += core gui sql xml network FORMS += \ ../src/qt/forms/aboutdialog.ui \ @@ -23,8 +23,42 @@ FORMS += \ RESOURCES += \ ../src/qt/dash.qrc + ../src/qt/qcc/icons.qrc + +win32:RC_FILE = qcc.rc + +OTHER_FILES += qcc.rc -CONFIG += c++17 ordered +CONFIG += c++17 ordered staticlib create_prl console link_prl crypto +CONFIG -= app_bundle + +QCC_CORE_PREFIX = ../qcc-core + +CONFIG(debug, debug|release) { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug +} else { + DEFINES += RELEASE + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release +} + +INCLUDEPATH += ../qcc-core +LIBS += -L$$QCC_CORE_PREFIX -lqcc-core + + +QCC_CORE_PREFIX = ../qcc-core + +CONFIG(debug, debug|release) { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug +} else { + DEFINES += DEBUG + win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release +} + +INCLUDEPATH += ../qcc-core +LIBS += -L$$QCC_CORE_PREFIX -lqcc-core + QMAKE_CXXFLAGS += -std=c++17 @@ -33,7 +67,9 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe -TEMPLATE = subdirs +TARGET = qcc-core qcc-server qcc + +TEMPLATE = subdirs lib app SUBDIRS = qcc-core \ qcc-server \ From 649da8594a76fe14981db5e8e2abbc234d6ed131 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:29:52 -0400 Subject: [PATCH 0464/1324] Update abstractuser.h --- src/qt/qcc-core/abstractuser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/qcc-core/abstractuser.h b/src/qt/qcc-core/abstractuser.h index 4126acc8..809d2f0a 100644 --- a/src/qt/qcc-core/abstractuser.h +++ b/src/qt/qcc-core/abstractuser.h @@ -112,7 +112,7 @@ class AbstractUser : public QObject */ inline bool isOnline() const { return m_status == Online; } -signals: +Q_SIGNALS: //! This signal is emitted whenever the user's status changes. /*! @@ -120,7 +120,7 @@ class AbstractUser : public QObject */ void statusChanged(); -public slots: +public Q_SLOTS: //! Sets the username. /*! From 786a67b6051497402587c0746a450277f777119f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:30:37 -0400 Subject: [PATCH 0465/1324] Update server.h --- src/qt/qcc-server/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc-server/server.h b/src/qt/qcc-server/server.h index b0353485..9a843d74 100644 --- a/src/qt/qcc-server/server.h +++ b/src/qt/qcc-server/server.h @@ -66,7 +66,7 @@ class Server : public QTcpServer */ void saveUsers(); -private slots: +private Q_SLOTS: //! This signal is emitted when the client's socket has been disconnected. /*! From b4f79ddcf5961406002f554fe936ef73f41c10b2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:30:58 -0400 Subject: [PATCH 0466/1324] Update user.h --- src/qt/qcc-server/user.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc-server/user.h b/src/qt/qcc-server/user.h index 2cdd8524..cdf37215 100644 --- a/src/qt/qcc-server/user.h +++ b/src/qt/qcc-server/user.h @@ -138,7 +138,7 @@ class User : public AbstractUser */ void writeUser(QXmlStreamWriter &xml); -public slots: +public Q_SLOTS: //! Sets the password. /*! From 1debcd2a5e1feb6b88b39e629316614fe9427b3e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:31:35 -0400 Subject: [PATCH 0467/1324] Update contactlistmodel.h --- src/qt/qcc/contactlistmodel.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/qcc/contactlistmodel.h b/src/qt/qcc/contactlistmodel.h index 043288e0..5313483a 100644 --- a/src/qt/qcc/contactlistmodel.h +++ b/src/qt/qcc/contactlistmodel.h @@ -117,12 +117,12 @@ class ContactListModel : public QAbstractListModel */ bool remove(const QModelIndex &index); -public slots: +public Q_SLOTS: //! Removes all contacts from this model. void clear(); -private slots: +private Q_SLOTS: //! This slot should be called from a \a contact whenever the status changes. void contact_statusChanged(); From 11bc2d323eb63a7a55d345ff856ba4f830772ec2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:31:57 -0400 Subject: [PATCH 0468/1324] Update mainwindow.h --- src/qt/qcc/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h index 934ec9bf..68374593 100644 --- a/src/qt/qcc/mainwindow.h +++ b/src/qt/qcc/mainwindow.h @@ -55,7 +55,7 @@ class MainWindow : public QMainWindow //! Destroys the MainWindow. ~MainWindow(); -private slots: +private Q_SLOTS: //! Connects the client to a QCC-server. /*! From 76bf17874429c9602c906a0b1474df63d51475e7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:32:19 -0400 Subject: [PATCH 0469/1324] Update messagepage.h --- src/qt/qcc/messagepage.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/qcc/messagepage.h b/src/qt/qcc/messagepage.h index 8020e249..efd761d3 100644 --- a/src/qt/qcc/messagepage.h +++ b/src/qt/qcc/messagepage.h @@ -72,17 +72,17 @@ class MessagePage : public QWidget */ void appendMessage(const QString &message, const QColor &color = Qt::black); -signals: +Q_SIGNALS: //! This signal is emitted whenever the close button of this page is clicked. void closeButtonClicked(); -public slots: +public Q_SLOTS: //! Sets the focus on the input field of this page. void setFocusOnInput(); -private slots: +private Q_SLOTS: //! Sends the \a message from the input field to the server. void on_sendButton_clicked(); From 5e8975915b4026c74902cbf854dcd451acf6e0d7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:32:37 -0400 Subject: [PATCH 0470/1324] Update messagewindow.h --- src/qt/qcc/messagewindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/messagewindow.h b/src/qt/qcc/messagewindow.h index 53cb0469..48101c82 100644 --- a/src/qt/qcc/messagewindow.h +++ b/src/qt/qcc/messagewindow.h @@ -89,7 +89,7 @@ class MessageWindow : public QTabWidget */ void appendMessage(Contact *contact, const QString &message); -private slots: +private Q_SLOTS: //! This slot should be called from a \a contact whenever the status changes. void contact_statusChanged(); From 35e33432a52067a0e78dbf6eb79a3debc053983d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:32:56 -0400 Subject: [PATCH 0471/1324] Update registerdialog.h --- src/qt/qcc/registerdialog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/registerdialog.h b/src/qt/qcc/registerdialog.h index 4ac96548..b2cb92e1 100644 --- a/src/qt/qcc/registerdialog.h +++ b/src/qt/qcc/registerdialog.h @@ -61,7 +61,7 @@ class RegisterDialog : public QDialog */ QString password() const; -private slots: +private Q_SLOTS: //! Checks if the username and password is valid and closes the window. void on_buttonBox_accepted(); From 5ff309f87566be08c7b44be4bc11efc20635f752 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:35:46 -0400 Subject: [PATCH 0472/1324] Update mainwindow.h --- src/qt/qcc/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h index 68374593..dea67f9f 100644 --- a/src/qt/qcc/mainwindow.h +++ b/src/qt/qcc/mainwindow.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include class ContactListModel; class MessageWindow; From a5a9b6a29bd4903dfe97106d737cecb405a5fb82 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:40:22 -0400 Subject: [PATCH 0473/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index a5efd81d..b98f7123 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -42,7 +42,7 @@ CONFIG(debug, debug|release) { win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release } -INCLUDEPATH += ../qcc-core +INCLUDEPATH += ../qcc-core $$ {QCA_INCDIR} / QtCrypto LIBS += -L$$QCC_CORE_PREFIX -lqcc-core From 68084d5316f6a35cf19cda4d3e43bf7ba163534c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:40:36 -0400 Subject: [PATCH 0474/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index b98f7123..a5efd81d 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -42,7 +42,7 @@ CONFIG(debug, debug|release) { win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release } -INCLUDEPATH += ../qcc-core $$ {QCA_INCDIR} / QtCrypto +INCLUDEPATH += ../qcc-core LIBS += -L$$QCC_CORE_PREFIX -lqcc-core From 67477afda24de1887fc2a9146ca90b55e8f19fc1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:57:36 -0400 Subject: [PATCH 0475/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index a5efd81d..e53c281a 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -42,8 +42,10 @@ CONFIG(debug, debug|release) { win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release } -INCLUDEPATH += ../qcc-core -LIBS += -L$$QCC_CORE_PREFIX -lqcc-core +INCLUDEPATH += ../qcc-core /usr/include/qca2/QtCrypto + +LIBS += -L$$QCC_CORE_PREFIX -lqcc-core -L/usr/lib/qca2 -lqca + QCC_CORE_PREFIX = ../qcc-core From d837ba2943b40997f2dc37d62a3b391e3a1ca397 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 22:59:38 -0400 Subject: [PATCH 0476/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index e53c281a..5d3a9baf 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -QT += core gui sql xml network +QT += core gui sql xml network crypto FORMS += \ ../src/qt/forms/aboutdialog.ui \ From f0a2fffaddfefdfedb59b552fba7c63a0c92cd21 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:00:36 -0400 Subject: [PATCH 0477/1324] Update mainwindow.h --- src/qt/qcc/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h index dea67f9f..68374593 100644 --- a/src/qt/qcc/mainwindow.h +++ b/src/qt/qcc/mainwindow.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include class ContactListModel; class MessageWindow; From 620b39da931a28b86a71e7b8d69702f23adc526c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:03:18 -0400 Subject: [PATCH 0478/1324] Update mainwindow.h --- src/qt/qcc/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h index 68374593..1c8cf993 100644 --- a/src/qt/qcc/mainwindow.h +++ b/src/qt/qcc/mainwindow.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include class ContactListModel; class MessageWindow; From 479851049c38ebaf52c6b92a461467eb472e7061 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:24:47 -0400 Subject: [PATCH 0479/1324] Update mainwindow.h --- src/qt/qcc/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h index 1c8cf993..68374593 100644 --- a/src/qt/qcc/mainwindow.h +++ b/src/qt/qcc/mainwindow.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include class ContactListModel; class MessageWindow; From 52c821fcde9cf5171586ed403af3d6a0035a4bc8 Mon Sep 17 00:00:00 2001 From: Devilking6105 Date: Wed, 10 Jun 2020 23:28:22 -0400 Subject: [PATCH 0480/1324] revert QT --- src/config/helpthehomeless-config.h | 4 +- src/qt/qcc-core/abstractuser.cpp | 57 ---- src/qt/qcc-core/abstractuser.h | 156 --------- src/qt/qcc-core/qcc-core.pro | 17 - src/qt/qcc-core/qccpacket.cpp | 73 ----- src/qt/qcc-core/qccpacket.h | 293 ----------------- src/qt/qcc-server/main.cpp | 98 ------ src/qt/qcc-server/qcc-server.pro | 32 -- src/qt/qcc-server/server.cpp | 479 ---------------------------- src/qt/qcc-server/server.h | 118 ------- src/qt/qcc-server/user.cpp | 83 ----- src/qt/qcc-server/user.h | 175 ---------- src/qt/qcc/contact.cpp | 84 ----- src/qt/qcc/contact.h | 93 ------ src/qt/qcc/contactlistmodel.cpp | 149 --------- src/qt/qcc/contactlistmodel.h | 135 -------- src/qt/qcc/icons.qrc | 7 - src/qt/qcc/icons/offline.png | Bin 3270 -> 0 bytes src/qt/qcc/icons/online.png | Bin 3271 -> 0 bytes src/qt/qcc/icons/qcc.ico | Bin 140206 -> 0 bytes src/qt/qcc/icons/qcc128a.png | Bin 5538 -> 0 bytes src/qt/qcc/main.cpp | 48 --- src/qt/qcc/mainwindow.cpp | 403 ----------------------- src/qt/qcc/mainwindow.h | 144 --------- src/qt/qcc/mainwindow.ui | 244 -------------- src/qt/qcc/messagepage.cpp | 98 ------ src/qt/qcc/messagepage.h | 109 ------- src/qt/qcc/messagepage.ui | 104 ------ src/qt/qcc/messagewindow.cpp | 146 --------- src/qt/qcc/messagewindow.h | 116 ------- src/qt/qcc/messagewindow.ui | 28 -- src/qt/qcc/qcc.pro | 50 --- src/qt/qcc/qcc.rc | 1 - src/qt/qcc/registerdialog.cpp | 69 ---- src/qt/qcc/registerdialog.h | 74 ----- src/qt/qcc/registerdialog.ui | 121 ------- 36 files changed, 2 insertions(+), 3806 deletions(-) delete mode 100644 src/qt/qcc-core/abstractuser.cpp delete mode 100644 src/qt/qcc-core/abstractuser.h delete mode 100644 src/qt/qcc-core/qcc-core.pro delete mode 100644 src/qt/qcc-core/qccpacket.cpp delete mode 100644 src/qt/qcc-core/qccpacket.h delete mode 100644 src/qt/qcc-server/main.cpp delete mode 100644 src/qt/qcc-server/qcc-server.pro delete mode 100644 src/qt/qcc-server/server.cpp delete mode 100644 src/qt/qcc-server/server.h delete mode 100644 src/qt/qcc-server/user.cpp delete mode 100644 src/qt/qcc-server/user.h delete mode 100644 src/qt/qcc/contact.cpp delete mode 100644 src/qt/qcc/contact.h delete mode 100644 src/qt/qcc/contactlistmodel.cpp delete mode 100644 src/qt/qcc/contactlistmodel.h delete mode 100644 src/qt/qcc/icons.qrc delete mode 100644 src/qt/qcc/icons/offline.png delete mode 100644 src/qt/qcc/icons/online.png delete mode 100644 src/qt/qcc/icons/qcc.ico delete mode 100644 src/qt/qcc/icons/qcc128a.png delete mode 100644 src/qt/qcc/main.cpp delete mode 100644 src/qt/qcc/mainwindow.cpp delete mode 100644 src/qt/qcc/mainwindow.h delete mode 100644 src/qt/qcc/mainwindow.ui delete mode 100644 src/qt/qcc/messagepage.cpp delete mode 100644 src/qt/qcc/messagepage.h delete mode 100644 src/qt/qcc/messagepage.ui delete mode 100644 src/qt/qcc/messagewindow.cpp delete mode 100644 src/qt/qcc/messagewindow.h delete mode 100644 src/qt/qcc/messagewindow.ui delete mode 100644 src/qt/qcc/qcc.pro delete mode 100644 src/qt/qcc/qcc.rc delete mode 100644 src/qt/qcc/registerdialog.cpp delete mode 100644 src/qt/qcc/registerdialog.h delete mode 100644 src/qt/qcc/registerdialog.ui diff --git a/src/config/helpthehomeless-config.h b/src/config/helpthehomeless-config.h index a1681236..c520c4d9 100644 --- a/src/config/helpthehomeless-config.h +++ b/src/config/helpthehomeless-config.h @@ -156,8 +156,8 @@ don't. */ #define HAVE_DECL_STRNLEN 1 - Define to 1 if you have the header file. - #undef HAVE_DLFCN_H +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLFCN_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_ENDIAN_H */ diff --git a/src/qt/qcc-core/abstractuser.cpp b/src/qt/qcc-core/abstractuser.cpp deleted file mode 100644 index a50efb49..00000000 --- a/src/qt/qcc-core/abstractuser.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "abstractuser.h" - -const char* AbstractUser::StatusNames[] = { - "Offline", - "Online" -}; - -QString AbstractUser::statusString(Status status) -{ - return AbstractUser::StatusNames[status]; -} - -AbstractUser::AbstractUser(QObject *parent) : - QObject(parent), m_status(Offline) -{ -} - -AbstractUser::AbstractUser(const QString &username, QObject *parent) : - QObject(parent), m_username(username), m_status(Offline) -{ -} - -void AbstractUser::setStatus(Status status) -{ - if (status == m_status) - return; - - m_status = status; - emit statusChanged(); -} - -void AbstractUser::reset() -{ - setStatus(Offline); -} diff --git a/src/qt/qcc-core/abstractuser.h b/src/qt/qcc-core/abstractuser.h deleted file mode 100644 index 809d2f0a..00000000 --- a/src/qt/qcc-core/abstractuser.h +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef ABSTRACTUSER_H -#define ABSTRACTUSER_H - -#include - -/*! - \defgroup core QCC core library - - The core library contains classes which are used in both other QCC-modules, - the \ref server "QCC-server" and the \ref client "QCC-client". - */ - -//! The AbstractUser class is the base class for all user objects. -/*! - \ingroup core - */ -class AbstractUser : public QObject -{ - Q_OBJECT - -public: - - //! This enum describes the different states in which a user can be. - /*! - \sa StatusNames - */ - enum Status { - Offline, //!< The user is offline. - Online //!< The user is online. - }; - - //! Returns a human-readable description of the status. - /*! - \param type The status. - \return The status as a \c QString. - */ - static QString statusString(Status type); - - //! Constructs an empty user. - /*! - \param parent The parent object. - */ - explicit AbstractUser(QObject *parent = 0); - - //! Constructs an user with the username set to \a username. - /*! - \param username The username. - \param parent The parent object. - */ - AbstractUser(const QString &username, QObject *parent = 0); - - //! Returns the username. - /*! - \return The username. - \sa setUsername() - */ - inline const QString& username() const { return m_username; } - - //! Returns the status. - /*! - \return The status. - \sa setStatus(), statusString(), statusChanged() - */ - inline Status status() const { return m_status; } - - //! Returns a human-readable description of the current status. - /*! - \return The status as a \c QString. - \sa status() - */ - inline QString statusString() const { return AbstractUser::StatusNames[m_status]; } - - //! Returns \c true if the user object is valid; otherwise returns \c false. - /*! - \return \c True if the user object is valid; otherwise returns \c false. - \sa invalidate() - */ - inline bool isValid() const { return !m_username.isEmpty(); } - - //! Invalidates the user object. - /*! - \sa isValid() - */ - inline void invalidate() { m_username.clear(); } - - //! Returns \c true if the user is online; otherwise returns \c false. - /*! - \return \c True if the user is online; otherwise returns \c false. - \sa status() - */ - inline bool isOnline() const { return m_status == Online; } - -Q_SIGNALS: - - //! This signal is emitted whenever the user's status changes. - /*! - \sa status() - */ - void statusChanged(); - -public Q_SLOTS: - - //! Sets the username. - /*! - \param username The username. - \sa username() - */ - inline void setUsername(const QString &username) { m_username = username; } - - //! Sets the status. - /*! - \param status The status. - \sa status(), statusChanged() - */ - void setStatus(Status status); - - //! Resets the state of the user object. - virtual void reset(); - -protected: - - QString m_username; //!< The username. - Status m_status; //!< The status. - -private: - - //! The string representation of the the different user states. - /*! - \sa Status - */ - static const char *StatusNames[]; -}; - -#endif // ABSTRACTUSER_H diff --git a/src/qt/qcc-core/qcc-core.pro b/src/qt/qcc-core/qcc-core.pro deleted file mode 100644 index e82870a7..00000000 --- a/src/qt/qcc-core/qcc-core.pro +++ /dev/null @@ -1,17 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2011-01-25T13:46:15 -# -#------------------------------------------------- - -QT = core network - -TARGET = qcc-core -TEMPLATE = lib -CONFIG += staticlib create_prl - -HEADERS += qccpacket.h \ - abstractuser.h - -SOURCES += qccpacket.cpp \ - abstractuser.cpp diff --git a/src/qt/qcc-core/qccpacket.cpp b/src/qt/qcc-core/qccpacket.cpp deleted file mode 100644 index f450fc77..00000000 --- a/src/qt/qcc-core/qccpacket.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "qccpacket.h" - -#include - -const char* QccPacket::PacketTypeNames[] = { - "ConnectionAccepted", - "ConnectionRefused", - "UserRegister", - "RegisterSuccess", - "RegisterFailure", - "UserAuthentication", - "AuthenticationSuccess", - "AuthenticationFailure", - "RequestAuthorization", - "AuthorizationAccepted", - "AuthorizationDeclined", - "AuthorizationFailure", - "RequestContactList", - "ContactList", - "ContactStatusChanged", - "RemoveContact", - "ContactRemoved", - "Message", - "MessageSuccess", - "MessageFailure", - "IllegalMessage" -}; - -QString QccPacket::typeString(PacketType type) -{ - return QccPacket::PacketTypeNames[type]; -} - -QccPacket::QccPacket(PacketType type) : - m_type(type), m_stream(&m_data, QIODevice::WriteOnly) -{ - m_stream.setVersion(QDataStream::Qt_4_0); - m_stream << (quint32)0; - m_stream << (qint32)type; -} - -bool QccPacket::send(QTcpSocket *socket) -{ - if (!socket || m_data.length() < int(sizeof(quint32) + sizeof(qint32))) // size + type - return false; - - m_stream.device()->seek(0); - m_stream << (quint32)size(); - - return socket->write(m_data) == m_data.size(); -} diff --git a/src/qt/qcc-core/qccpacket.h b/src/qt/qcc-core/qccpacket.h deleted file mode 100644 index 6d90670f..00000000 --- a/src/qt/qcc-core/qccpacket.h +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef TCPPACKET_H -#define TCPPACKET_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QTcpSocket; -QT_END_NAMESPACE - -//! The QccPacket class is used for sending custom TCP-packets over the network. -/*! - The QccPacket class defines the different packet types QCC needs for the network - communication beween the \ref server "QCC-server" and the \ref client "QCC-client".\n - - It is also used for sending QCC-packets over the network through the TCP.\n - - Each QCC-packet consists of three parts: - -# The size of the actual packet in bytes (\c quint32).\n - The size is defined by the size of the packet-type plus the size of the payload. - -# The type of the packet (encoded as \c qint32). - -# The actual data of the packet (payload) (the data-type depends on the packet-type).\n - The payload can also be empty, because some packet-types don't need any data. - - \ingroup core - \sa PacketType - */ -class QccPacket -{ -public: - - //! This enum describes the different types of QCC-packets. - /*! - \sa PacketTypeNames - */ - enum PacketType { - - //! The connection has been accepted by the QCC-server. - /*! - This packet has no payload. - */ - ConnectionAccepted, - - //! The connection has been refused by the QCC-server. - /*! - This packet has no payload. - */ - ConnectionRefused, - - //! The QCC-client sends a user registration. - /*! - Payload: - -# \c QString(username) - -# \c QString(passwort) - SHA-256 encoded hash - -# \c QByteArray(publicKey) - RSA public key in DER-format - */ - UserRegister, - - //! The QCC-server reports that the user registration has been successful. - /*! - This packet has no payload. - */ - RegisterSuccess, - - //! The QCC-server reports that an error occured with the user registration. - /*! - Payload: - -# \c QString(reason) - reason of the failure - */ - RegisterFailure, - - //! The QCC-client sends a user authentication (login). - /*! - Payload: - -# \c QString(username) - -# \c QString(passwort) - SHA-256 encoded hash - -# \c QByteArray(publicKey) - RSA public key in DER-format - */ - UserAuthentication, - - //! The QCC-server reports that the user authentication has been successful. - /*! - This packet has no payload. - */ - AuthenticationSuccess, - - //! The QCC-server reports that an error occured with the user authentication. - /*! - Payload: - -# \c QString(reason) - reason of the failure - */ - AuthenticationFailure, - - //! The QCC-client sends an authorization request to add another user to his contacts. - /*! - Payload: - -# \c QString(username) - - The username gets replaced by the server with the username of the sender, - so that the receiver knows from where the authorization request come from. - */ - RequestAuthorization, - - //! The authorization request has been accepted. - /*! - Payload: - -# \c QString(username) - -# \c qint32(status) - user status - -# \c QByteArray(publicKey) - RSA public key in DER-format - - The \a status and \a publicKey is appended by the server. - */ - AuthorizationAccepted, - - //! The authorization request has been declined. - /*! - Payload: - -# \c QString(username) - */ - AuthorizationDeclined, - - //! The QCC-server reports that an error occured with the authorization request. - /*! - Payload: - -# \c QString(reason) - reason of the failure - */ - AuthorizationFailure, - - //! The QCC-client requests his list of contacts. - /*! - This packet has no payload. - */ - RequestContactList, - - //! The QCC-server sends a list of the user's contacts. - /*! - Payload: - -# \c qint32(count) - user count - -# list of contacts (\a count user objects) - - user object - -# \c QString(username) - -# \c qint32(status) - user status - -# \c QByteArray(publicKey) - RSA public key in DER-format - - user object ... - */ - ContactList, - - //! The QCC-Server sends a status-changed-packet. - /*! - The status-changed-packet is send to all users which have the user - who changed the status on their contact list.\n - - Payload: - -# \c QString(username) - user who changed the status - -# \c qint32(status) - user status - -# \c QByteArray(publicKey) - RSA public key in DER-format - */ - ContactStatusChanged, - - //! The QCC-client sends a request to remove a user from his contacts. - /*! - Payload: - -# \c QString(username) - */ - RemoveContact, - - //! The QCC-Server confirms that the user has been removed from the contacts. - /*! - Payload: - -# \c QString(username) - */ - ContactRemoved, - - //! RSA-encrypted message from one user to another. - /*! - Payload: - -# \c qint32(messageId) - the message id is used for association with - the following \a MessageSuccess packet (if any) - -# \c QString(receiver|sender) - username of the sender/receiver - -# \c QByteArray(message) - RSA-encrypted message - */ - Message, - - //! Confirms that the message has been successfully delivered. - /*! - Payload: - -# \c qint32(messageId) - the message id is used for association with the message - -# \c QString(sender) - username of the sender - */ - MessageSuccess, - - //! The QCC-server reports that an error occured with the message. - /*! - Payload: - -# \c qint32(messageId) - the message id is used for association with the message - -# \c QString(receiver) - username of the receiver - -# \c QString(reason) - reason of the failure - */ - MessageFailure, - - //! Used for illegal packet types that don't match any valid packet type. - IllegalPacketType = -1 - }; - - //! Returns a human-readable description of the packet type. - /*! - \param type The packet type. - \return The status as a \c QString. - */ - static QString typeString(PacketType type); - - //! Constructs a QccPacket. - /*! - \param type The type of the packet. - */ - QccPacket(PacketType type = Message); - - //! Returns the packet type. - /*! - \return The packet type. - \sa typeString() - */ - inline PacketType type() const { return m_type; } - - //! Returns a human-readable description of the current packet type. - /*! - \return The status as a \c QString. - \sa type() - */ - inline QString typeString() const { return QccPacket::PacketTypeNames[m_type]; } - - //! Returns the packet data. - /*! - \return The packet data. - \sa stream() - */ - inline QByteArray& data() { return m_data; } - - //! Returns the internal data stream to provide easy data serialization. - /*! - \return The packet data stream. - \sa data() - */ - inline QDataStream& stream() { return m_stream; } - - //! Returns the size of the playload. - /*! - \return The size of the playload. - */ - inline int size() const { return m_data.size() - sizeof(quint32); } - - //! Writes the data to the \a socket and returns \c true on success. - /*! - \param socket The TCP-Socket. - \return \c True if the data was successfully written to the socket; otherwise returns \c false. - */ - bool send(QTcpSocket *socket); - -private: - //! The string representation of the the different types of QCC-packets. - /*! - \sa PacketType - */ - static const char *PacketTypeNames[]; - - PacketType m_type; //!< The packet type. - QByteArray m_data; //!< The packet data. - QDataStream m_stream; //!< The packet data stream. -}; - -#endif // TCPPACKET_H diff --git a/src/qt/qcc-server/main.cpp b/src/qt/qcc-server/main.cpp deleted file mode 100644 index 185b9cf7..00000000 --- a/src/qt/qcc-server/main.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include -#include - -#ifdef DEBUG -#include -#endif - -#include "server.h" - -/*! - \defgroup server QCC server module - - The QCC-server manages all registered users and observes - the package transfer between all connected \ref client "clients". - */ - -//! The default network port, on which the server will listen. -/*! - \ingroup server - */ -const quint16 DEFAULT_PORT = 54321; - -//! Helper function for reading a command line argument of type \c quint16. -/*! - \param arguments The list of command-line arguments. - \param name The name of the agument. - \param defaultValue The default value for the argument, in case there - is none or an error occurred while processing it. - \return The value of the argument interpreted as an \c quint16 or the \a defaultValue. - \ingroup server - */ -quint16 readUShort(const QStringList &arguments, const QString &name, quint16 defaultValue = 0) -{ - if (arguments.isEmpty()) - return defaultValue; - - int index = arguments.indexOf(name); - if (index < 0 || index + 1 >= arguments.count()) - return defaultValue; - - bool ok; - quint16 value = arguments.at(index + 1).toUShort(&ok); - return ok ? value : defaultValue; -} - -//! The main entry point of this application. -/*! - \param argc The command-line argument count. - \param argv The command-line argument-array. - \return The return code of the application - \ingroup server - */ -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - QStringList arguments = QCoreApplication::arguments(); - -#ifdef DEBUG - qDebug() << "QCC server started with arguments:" << arguments; -#endif - - QHostAddress adress = QHostAddress::Any; - quint16 port = readUShort(arguments, "-port", DEFAULT_PORT); - - Server server; - if (server.listen(adress, port)) { - qDebug("The server is listening on interface %s, port %i", - qPrintable(server.serverAddress().toString()), server.serverPort()); - } else { - qCritical("Failed to start the server on interface %s, port %i: %s (error code %i)", - qPrintable(adress.toString()), port, qPrintable(server.errorString()), server.serverError()); - return 1; - } - - return app.exec(); -} diff --git a/src/qt/qcc-server/qcc-server.pro b/src/qt/qcc-server/qcc-server.pro deleted file mode 100644 index 91398ee1..00000000 --- a/src/qt/qcc-server/qcc-server.pro +++ /dev/null @@ -1,32 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2011-01-23T16:09:56 -# -#------------------------------------------------- - -QT = core network - -TARGET = qcc-server -TEMPLATE = app -CONFIG += console link_prl -CONFIG -= app_bundle - -QCC_CORE_PREFIX = ../qcc-core - -CONFIG(debug, debug|release) { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug -} else { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release -} - -INCLUDEPATH += ../qcc-core -LIBS += -L$$QCC_CORE_PREFIX -lqcc-core - -HEADERS += server.h \ - user.h - -SOURCES += main.cpp \ - server.cpp \ - user.cpp diff --git a/src/qt/qcc-server/server.cpp b/src/qt/qcc-server/server.cpp deleted file mode 100644 index 3b2b8ba7..00000000 --- a/src/qt/qcc-server/server.cpp +++ /dev/null @@ -1,479 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "server.h" -#include "qccpacket.h" -#include "user.h" - -#include -#include -#include -#include - -#ifdef DEBUG -#include -#endif - -const QString Server::USERS_FILE = "users.xml"; - -Server::Server(QObject *parent) : - QTcpServer(parent) -{ - loadUsers(); -} - -Server::~Server() -{ - qDeleteAll(m_clients.values()); - qDeleteAll(m_users.values()); -} - -void Server::loadUsers() -{ -#ifdef DEBUG - qDebug("Server::loadUsers()"); -#endif - - QFile file(Server::USERS_FILE); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning("Server::loadUsers(): cannot read file users.xml => %s", qPrintable(file.errorString())); - return; - } - m_users.clear(); - QXmlStreamReader xml(&file); - while (!xml.atEnd()) { - if (!xml.readNextStartElement()) - continue; - if (xml.name() == "user") { - User *user = User::readUser(xml); - if (user && user->isValid()) { - connect(user, SIGNAL(statusChanged()), SLOT(client_statusChanged())); - m_users.insert(user->username(), user); -#ifdef DEBUG - qDebug() << "user:" << user->username() << "contacts =" << user->contacts(); -#endif - } - } - } - if (xml.hasError()) { - qCritical("Server::loadUsers(): parse error in file users.xml => %s: line %li, column %li", - qPrintable(xml.errorString()), (long)xml.lineNumber(), (long)xml.columnNumber()); - } - file.close(); - -#ifdef DEBUG - qDebug("Server::loadUsers(): %i users read from users.xml", m_users.count()); -#endif -} - -void Server::saveUsers() -{ -#ifdef DEBUG - qDebug("Server::saveUsers()"); -#endif - - QFile file(Server::USERS_FILE); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning("Server::saveUsers(): cannot write file users.xml => %s", qPrintable(file.errorString())); - return; - } - QXmlStreamWriter xml(&file); - xml.setAutoFormatting(true); - xml.writeStartDocument(); - xml.writeStartElement("users"); - foreach (User *user, m_users) - user->writeUser(xml); - xml.writeEndElement(); - xml.writeEndDocument(); - file.close(); - -#ifdef DEBUG - qDebug("Server::saveUsers(): %i users written to users.xml", m_users.count()); -#endif -} - -void Server::incomingConnection(int socketDescriptor) -{ - QTcpSocket *socket = new QTcpSocket(this); - socket->setSocketDescriptor(socketDescriptor); - addPendingConnection(socket); - -#ifdef DEBUG - qDebug("\nServer::incomingConnection(%i): %s:%i", socketDescriptor, - qPrintable(socket->peerAddress().toString()), socket->peerPort()); -#endif - - connect(socket, SIGNAL(disconnected()), SLOT(client_disconnected())); - connect(socket, SIGNAL(readyRead()), SLOT(client_readyRead())); - - m_clients.insert(socket, new Client); - QccPacket(QccPacket::ConnectionAccepted).send(socket); // QccPacket::ConnectionRefused - -#ifdef DEBUG - qDebug("ConnectionAccepted"); -#endif -} - -void Server::client_disconnected() -{ - QTcpSocket *socket = qobject_cast(sender()); - if (!socket) { - qWarning("Server::client_disconnected(): Cast of sender() to QTcpSocket* failed"); - return; - } - - Client *client = m_clients[socket]; - User *user = client->user; - if (user) - user->reset(); - -#ifdef DEBUG - QString username = user ? user->username() : "[no user object]"; - qDebug("\nServer::client_disconnected(): '%s' (%s:%i)", qPrintable(username), - qPrintable(socket->peerAddress().toString()), socket->peerPort()); -#endif - - m_clients.remove(socket); - delete client; -} - -void Server::client_readyRead() -{ - QTcpSocket *socket = qobject_cast(sender()); - if (!socket) { - qWarning("Server::client_readyRead(): Cast of sender() to QTcpSocket* failed"); - return; - } - -#ifdef DEBUG - qDebug("\nServer::client_readyRead(): %li bytes available", (long)socket->bytesAvailable()); -#endif - - Client *client = m_clients[socket]; - QDataStream in(socket); - in.setVersion(QDataStream::Qt_4_0); - if (client->packetSize == 0) { - if (socket->bytesAvailable() < (int)sizeof(quint32)) // packet size - return; - in >> client->packetSize; - } - if (socket->bytesAvailable() < client->packetSize) - return; - client->packetSize = 0; // reset packet size - - qint32 type; - in >> type; - -#ifdef DEBUG - qDebug("PacketType %i (%s) from '%s' (%s:%i)", type, - qPrintable(QccPacket::typeString((QccPacket::PacketType)type)), - qPrintable(client->user ? client->user->username() : "[no user object]"), - qPrintable(socket->peerAddress().toString()), socket->peerPort()); -#endif - - switch ((QccPacket::PacketType)type) { - case QccPacket::UserRegister: - { - QString username, password; - QByteArray publicKey; - in >> username >> password >> publicKey; -#ifdef DEBUG - qDebug("Username = '%s' password = '%s'", qPrintable(username), qPrintable(password)); -#endif - if (username.isEmpty()) { - QString reason = "The username cannot be empty."; - QccPacket packet(QccPacket::RegisterFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("RegisterFailure: %s", qPrintable(reason)); -#endif - break; - } - if (m_users.contains(username)) { - QString reason = QString("The username \"%1\" is not available.").arg(username); - QccPacket packet(QccPacket::RegisterFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("RegisterFailure: %s", qPrintable(reason)); -#endif - break; - } -#ifdef DEBUG - qDebug("RegisterSuccess"); -#endif - User *user = new User(username, password); - user->setPublicKey(publicKey); - user->setSocket(socket); - connect(user, SIGNAL(statusChanged()), SLOT(client_statusChanged())); - user->setStatus(User::Online); - m_users.insert(username, user); - saveUsers(); - client->user = user; - QccPacket(QccPacket::RegisterSuccess).send(socket); - break; - } - case QccPacket::UserAuthentication: - { - QString username, password; - QByteArray publicKey; - in >> username >> password >> publicKey; -#ifdef DEBUG - qDebug("Username = '%s' password = '%s'", qPrintable(username), qPrintable(password)); -#endif - User *user = m_users.contains(username) ? m_users[username] : NULL; - if (user && user->matchPassword(password)) { -#ifdef DEBUG - qDebug("AuthenticationSuccess"); -#endif - user->setPublicKey(publicKey); - user->setSocket(socket); - user->setStatus(User::Online); - client->user = user; - QccPacket(QccPacket::AuthenticationSuccess).send(socket); - } else { - QString reason = "The username or password you entered is incorrect."; - QccPacket packet(QccPacket::AuthenticationFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("AuthenticationFailure: %s", qPrintable(reason)); -#endif - } - break; - } - case QccPacket::RequestAuthorization: - { - QString username; - in >> username; - if (!m_users.contains(username)) { - QString reason = QString("The user \"%1\" does not exist.").arg(username); - QccPacket packet(QccPacket::AuthorizationFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("AuthorizationFailure: %s", qPrintable(reason)); -#endif - break; - } - if (client->user->username() == username) { - QString reason = QString("You cannot add yourself."); - QccPacket packet(QccPacket::AuthorizationFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("AuthorizationFailure: %s", qPrintable(reason)); -#endif - break; - } - if (client->user->containsContact(username)) { - QString reason = QString("The user \"%1\" is already on your contact list.").arg(username); - QccPacket packet(QccPacket::AuthorizationFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("AuthorizationFailure: %s", qPrintable(reason)); -#endif - break; - } - User *receiver = m_users.value(username); - if (receiver && receiver->isOnline()) { - QccPacket packet(QccPacket::RequestAuthorization); - packet.stream() << client->user->username(); - packet.send(receiver->socket()); -#ifdef DEBUG - qDebug("RequestAuthorization: forwarded to '%s'", qPrintable(username)); -#endif - } else { - QString reason = QString("The user \"%1\" is not online.").arg(username); - QccPacket packet(QccPacket::AuthorizationFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("AuthorizationFailure: %s", qPrintable(reason)); -#endif - } - break; - } - case QccPacket::AuthorizationAccepted: - { - QString username; - in >> username; - if (username.isEmpty()) - break; - User *receiver = m_users[username]; - if (receiver && receiver->isOnline()) { - receiver->addContact(client->user->username()); - client->user->addContact(username); - saveUsers(); - QccPacket packet(QccPacket::AuthorizationAccepted); - packet.stream() << client->user->username() << (qint32)client->user->status() << client->user->publicKey(); - packet.send(receiver->socket()); - QccPacket packet2(QccPacket::AuthorizationAccepted); - packet2.stream() << username << (qint32)receiver->status() << receiver->publicKey(); - packet2.send(socket); - } -#ifdef DEBUG - qDebug("AuthorizationAccepted: forwarded to '%s'", qPrintable(username)); -#endif - break; - } - case QccPacket::AuthorizationDeclined: - { - QString username; - in >> username; - if (username.isEmpty()) - break; - User *receiver = m_users.value(username); - if (receiver && receiver->isOnline()) { - QccPacket packet(QccPacket::AuthorizationDeclined); - packet.stream() << client->user->username(); - packet.send(receiver->socket()); - } -#ifdef DEBUG - qDebug("AuthorizationDeclined: forwarded to '%s'", qPrintable(username)); -#endif - break; - } - case QccPacket::RequestContactList: - { - QccPacket packet(QccPacket::ContactList); - QSet contacts = client->user->contacts(); - packet.stream() << (qint32)contacts.count(); - foreach (const QString &contactName, contacts) { - User *contact = m_users.value(contactName); - if (!contact) continue; - packet.stream() << contactName << qint32(contact->status()) << contact->publicKey(); - } - packet.send(socket); -#ifdef DEBUG - qDebug("ContactList: %i contacts send", contacts.count()); -#endif - break; - } - case QccPacket::RemoveContact: - { - QString username; - in >> username; - if (client->user->removeContact(username)) { - QccPacket packet(QccPacket::ContactRemoved); - packet.stream() << username; - packet.send(socket); - User *receiver = m_users[username]; - if (receiver && receiver->removeContact(client->user->username()) && receiver->isOnline()) { - QccPacket packet2(QccPacket::ContactRemoved); - packet2.stream() << client->user->username(); - packet2.send(receiver->socket()); - } - saveUsers(); -#ifdef DEBUG - qDebug("ContactRemoved: contact '%s' removed", qPrintable(username)); -#endif - } - break; - } - case QccPacket::Message: - { - qint32 id; - QString receiverName; - QString message; - in >> id >> receiverName >> message; - if (!client->user->containsContact(receiverName)) { - QString reason = QString("The user \"%1\" is not on your contact list.").arg(receiverName); - QccPacket packet(QccPacket::MessageFailure); - packet.stream() << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("MessageFailure: %s", qPrintable(reason)); -#endif - break; - } - User *receiver = m_users.value(receiverName); - if (receiver && receiver->isOnline()) { - QccPacket packet(QccPacket::Message); - packet.stream() << id << client->user->username() << message; - packet.send(receiver->socket()); -#ifdef DEBUG - qDebug("Message: forwarded to '%s'", qPrintable(receiverName)); -#endif - } else { - QString reason = QString("The user \"%1\" is not online.").arg(receiverName); - QccPacket packet(QccPacket::MessageFailure); - packet.stream() << id << receiverName << reason; - packet.send(socket); -#ifdef DEBUG - qDebug("MessageFailure: failed to forward to '%s' => %s", - qPrintable(receiverName), qPrintable(reason)); -#endif - } - break; - } - case QccPacket::MessageSuccess: - { - qint32 id; - QString receiverName; - in >> id >> receiverName; - User *receiver = m_users.value(receiverName); - if (receiver && receiver->isOnline()) { - QccPacket packet(QccPacket::MessageSuccess); - packet.stream() << id << client->user->username(); - packet.send(receiver->socket()); -#ifdef DEBUG - qDebug("MessageSuccess: forwarded to '%s'", qPrintable(receiverName)); -#endif - } - break; - } - default: - qWarning("Server::client_readyRead(): Illegal PacketType %i", type); - return; - } -} - -void Server::client_statusChanged() -{ - User *user = qobject_cast(sender()); - if (!user) { - qWarning("Server::client_statusChanged(): Cast of sender() to User* failed"); - return; - } - -#ifdef DEBUG - qDebug("\nServer::client_statusChanged(): '%s' => %i (%s)", - qPrintable(user->username()), user->status(), qPrintable(user->statusString())); -#endif - - // inform all online users that have this user on their contact list of the status change - QccPacket packet(QccPacket::ContactStatusChanged); - packet.stream() << user->username() << (qint32)user->status() << user->publicKey(); - foreach (Client *client, m_clients.values()) { - if (client->user == NULL) - continue; - if (client->user->containsContact(user->username())) { - packet.send(client->user->socket()); -#ifdef DEBUG - qDebug("ContactStatusChanged: send to contact '%s'", qPrintable(client->user->username())); -#endif - } - } -} diff --git a/src/qt/qcc-server/server.h b/src/qt/qcc-server/server.h deleted file mode 100644 index 9a843d74..00000000 --- a/src/qt/qcc-server/server.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef SERVER_H -#define SERVER_H - -#include -#include - -class User; - -//! The Server class provides a custom TCP-based server. -/*! - The Server class provides a custom TCP-based server with user - management and robust network management of multiple clients. - - \ingroup server - */ -class Server : public QTcpServer -{ - Q_OBJECT - -public: - - //! Constructs a QCC-server object. - /*! - \param parent The parent object. - \sa QTcpServer::listen() - */ - explicit Server(QObject *parent = 0); - - //! Destroys the QCC-server object. - /*! - \sa QTcpServer::~QTcpServer() - */ - ~Server(); - - //! Loads all users from the local file system into memory. - /*! - \sa USERS_FILE, saveUsers() - */ - void loadUsers(); - - //! Saves all users to the local file system for persistent storage. - /*! - \sa USERS_FILE, loadUsers() - */ - void saveUsers(); - -private Q_SLOTS: - - //! This signal is emitted when the client's socket has been disconnected. - /*! - \sa incomingConnection(), QAbstractSocket::disconnected() - */ - void client_disconnected(); - - //! This signal is emitted once every time new data is available for reading from the client's socket. - /*! - \sa QIODevice::readyRead() - */ - void client_readyRead(); - - //! This signal is emitted whenever the client's status changes. - /*! - \sa AbstractUser::statusChanged() - */ - void client_statusChanged(); - -private: - - //! The internal Client struct provides a thin wrapper for a User-object and the packet size. - struct Client { - - //! Constructs a Client object with the packet size set to \c 0. - /*! - \param u The user object or \c NULL if there is not any user yet. - */ - explicit inline Client(User *u = NULL) : packetSize(0), user(u) { } - - quint32 packetSize; //!< The packet size of the incoming QccPacket. - User *user; //!< A reference to the actual user object. - }; - - //! The filename for the persistent user storage (stored in XML-format). - static const QString USERS_FILE; - - QHash m_users; //!< The hash-table for all user objects on this server. - QHash m_clients; //!< The hash-table holds track of all connected clients. - - //! This virtual function is called by \c QTcpServer when a new connection is available. - /*! - \param socketDescriptor The native socket descriptor for the accepted connection. - \sa client_disconnected(), QTcpServer::incomingConnection() - */ - void incomingConnection(int socketDescriptor); -}; - -#endif // SERVER_H diff --git a/src/qt/qcc-server/user.cpp b/src/qt/qcc-server/user.cpp deleted file mode 100644 index fca95a3b..00000000 --- a/src/qt/qcc-server/user.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "user.h" - -#include - -User::User(QObject *parent) : - AbstractUser(parent), m_socket(NULL) -{ -} - -User::User(const QString &username, const QString &password, QObject *parent) : - AbstractUser(username, parent), m_password(password), m_socket(NULL) -{ -} - -User* User::readUser(QXmlStreamReader &xml) -{ - QXmlStreamAttributes attr = xml.attributes(); - QString username = attr.value("username").toString(); - QString password = attr.value("password").toString(); - User *user = new User(username, password); - while (!xml.atEnd()) { - switch (xml.readNext()) { - case QXmlStreamReader::Invalid: - return NULL; - case QXmlStreamReader::StartElement: - if (xml.name() == "contact") { - if (xml.readNext() == QXmlStreamReader::Characters) { - QString contactName = xml.text().toString(); - user->addContact(contactName); - } - } - break; - case QXmlStreamReader::EndElement: - if (xml.name() == "user") - return user; - else - break; - default: - break; - } - } - return NULL; -} - -void User::writeUser(QXmlStreamWriter &xml) -{ - xml.writeStartElement("user"); - xml.writeAttribute("username", m_username); - xml.writeAttribute("password", m_password); - xml.writeStartElement("contacts"); - foreach (const QString &contactName, m_contacts) - xml.writeTextElement("contact", contactName); - xml.writeEndElement(); - xml.writeEndElement(); -} - -void User::reset() -{ - m_socket = NULL; - AbstractUser::reset(); -} diff --git a/src/qt/qcc-server/user.h b/src/qt/qcc-server/user.h deleted file mode 100644 index cdf37215..00000000 --- a/src/qt/qcc-server/user.h +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef USER_H -#define USER_H - -#include "abstractuser.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QTcpSocket; -QT_END_NAMESPACE - -//! The User class represents a single user on the server. -/*! - \ingroup server - */ -class User : public AbstractUser -{ - Q_OBJECT - -public: - - //! Constructs an empty user. - /*! - \param parent The parent object. - */ - explicit User(QObject *parent = 0); - - //! Constructs an user with a username and password. - /*! - \param username The username. - \param password The password. - \param parent The parent object. - */ - User(const QString &username, const QString &password, QObject *parent = 0); - - //! Returns the password. - /*! - \return The password. - \sa setPassword(), matchPassword() - */ - inline const QString& password() const { return m_password; } - - //! Returns the set of contacts. - /*! - \return The set of contacts. - \sa addContact(), containsContact(), removeContact(), clearContacts() - */ - inline const QSet& contacts() const { return m_contacts; } - - //! Returns the RSA public key in DER-format. - /*! - \return The RSA public key in DER-format. - \sa setPublicKey() - */ - inline const QByteArray& publicKey() const { return m_publicKey; } - - //! Returns the TCP-socket. - /*! - \return The TCP-socket. - \sa setSocket() - */ - inline QTcpSocket* socket() const { return m_socket; } - - //! Adds a contact to the user's set of contacts. - /*! - \param username The username of the contact. - \note If the user already has this contact on his set of contacts, nothing happens. - \sa contacts(), containsContact() - */ - inline void addContact(const QString &username) { m_contacts.insert(username); } - - //! Checks whether the user's set of contacts contains an user. - /*! - \param username The username of the contact to check. - \return \c True if the user's set of contacts contains the contact; otherwise returns \c false. - \sa contacts(), addContact(), removeContact() - */ - inline bool containsContact(const QString &username) const { return m_contacts.contains(username); } - - //! Removes a contact from the user's set of contacts. - /*! - \param username The username of the contact to remove. - \return \c True if the contact has been removed; otherwise returns \c false. - \sa contacts(), containsContact(), clearContacts() - */ - inline bool removeContact(const QString &username) { return m_contacts.remove(username); } - - //! Removes all contact from the user's set of contacts. - /*! - \sa contacts(), removeContact() - */ - inline void clearContacts() { m_contacts.clear(); } - - //! Compares the user's password with another one. - /*! - \param password The password to compare with. - \return \c True if the passwords match; otherwise returns \c false. - \sa password() - */ - inline bool matchPassword(const QString &password) const { return m_password == password; } - - //! Reads one user from the given XML-stream. - /*! - \param xml The XML-stream from which the user will be read. - \return The read user object or \c NULL if an error occured. - \sa writeUser() - */ - static User* readUser(QXmlStreamReader &xml); - - //! Writes this user to the given XML-stream. - /*! - \param xml The XML-stream to which the user will be written. - \sa readUser() - */ - void writeUser(QXmlStreamWriter &xml); - -public Q_SLOTS: - - //! Sets the password. - /*! - \param password The password. - \sa password() - */ - void setPassword(const QString &password) { m_password = password; } - - //! Sets the public key. - /*! - \param publicKey The RSA public key in DER-format. - \sa publicKey() - */ - void setPublicKey(const QByteArray &publicKey) { m_publicKey = publicKey; } - - //! Sets the TCP-socket. - /*! - \param socket The TCP-socket. - \sa socket() - */ - void setSocket(QTcpSocket *socket) { m_socket = socket; } - - //! Resets the state of the user object. - void reset(); - -private: - - QString m_password; //!< The password (should be in some cryptographic hash format). - QSet m_contacts; //!< The set of contacts. - QByteArray m_publicKey; //!< RSA public key in DER-format. - QTcpSocket *m_socket; //!< The TCP-socket. -}; - -#endif // USER_H diff --git a/src/qt/qcc/contact.cpp b/src/qt/qcc/contact.cpp deleted file mode 100644 index abf654ef..00000000 --- a/src/qt/qcc/contact.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "contact.h" - -QIcon Contact::OfflineIcon; -QIcon Contact::OnlineIcon; - -Contact::Contact(QObject *parent) : - AbstractUser(parent) -{ - init(); -} - -Contact::Contact(const QString &username, QObject *parent) : - AbstractUser(username, parent) -{ - init(); -} - -void Contact::init() -{ - if (Contact::OfflineIcon.isNull()) { - Contact::OfflineIcon = QIcon(":/icons/offline.png"); - Contact::OnlineIcon = QIcon(":/icons/online.png"); - } -} - -void Contact::setPublicKey(const QByteArray &publicKey) -{ - if (publicKey.isEmpty()) // should only happen if the contact is offline - return; - - QCA::ConvertResult conversionResult; - m_publicKey = QCA::PublicKey::fromDER(publicKey, &conversionResult); - if (conversionResult != QCA::ConvertGood || !m_publicKey.canEncrypt()) - qWarning("Contact::setPublicKey: not a valid public key"); -} - -QIcon Contact::statusIcon() const -{ - switch (m_status) { - case Offline: return Contact::OfflineIcon; - case Online: return Contact::OnlineIcon; - default: return QIcon(); - } -} - -QByteArray Contact::encrypt(const QString &text) -{ - QByteArray bytes = text.toAscii(); - QCA::SecureArray result; - - static const int padding = 42; // always constant? - const int keySize = m_publicKey.bitSize() / 8; - const int blockSize = keySize - padding; - - for (int i = 0; i < bytes.length(); i += blockSize) - result.append(m_publicKey.encrypt(bytes.mid(i, blockSize), QCA::EME_PKCS1_OAEP)); - - if (result.isEmpty()) - qWarning("Error encrypting"); - - return result.toByteArray(); -} diff --git a/src/qt/qcc/contact.h b/src/qt/qcc/contact.h deleted file mode 100644 index f4aebacd..00000000 --- a/src/qt/qcc/contact.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef CONTACT_H -#define CONTACT_H - -#include "abstractuser.h" - -#include -#include - -//! The Contact class represents a single user on the client. -/*! - \ingroup client - */ -class Contact : public AbstractUser -{ - Q_OBJECT - -public: - - //! Constructs an empty contact. - /*! - \param parent The parent object. - */ - explicit Contact(QObject *parent = 0); - - //! Constructs a contact with a username. - /*! - \param username The username. - \param parent The parent object. - */ - Contact(const QString &username, QObject *parent = 0); - - //! Returns the RSA public. - /*! - \return The RSA public key. - \sa setPublicKey() - */ - inline const QCA::PublicKey& publicKey() const { return m_publicKey; } - - //! Sets the public key. - /*! - \param publicKey The RSA public key in DER-format. - \sa publicKey() - */ - void setPublicKey(const QByteArray &publicKey); - - //! Returns the status icon. - /*! - \return The status icon. - \sa AbstractUser::status() - */ - QIcon statusIcon() const; - - //! Returns the encrypted \a text with the RSA public key. - /*! - \return The encrypted \a text. - \sa publicKey() - */ - QByteArray encrypt(const QString &text); - -private: - - //! The status icons. - static QIcon OfflineIcon, OnlineIcon; - - QCA::PublicKey m_publicKey; //!< The RSA public key. - - //! Initializes the static icons. - void init(); -}; - -#endif // CONTACT_H diff --git a/src/qt/qcc/contactlistmodel.cpp b/src/qt/qcc/contactlistmodel.cpp deleted file mode 100644 index 69aea984..00000000 --- a/src/qt/qcc/contactlistmodel.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "contactlistmodel.h" -#include "contact.h" - -ContactListModel::ContactListModel(QObject *parent) : - QAbstractListModel(parent) -{ -} - -ContactListModel::~ContactListModel() -{ - qDeleteAll(m_contacts); -} - -int ContactListModel::rowCount(const QModelIndex &) const -{ - return m_contacts.count(); -} - -QVariant ContactListModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() >= m_contacts.count()) - return QVariant(); - - if (role == Qt::DisplayRole) - return m_contacts.at(index.row())->username(); - else if (role == Qt::DecorationRole) - return m_contacts.at(index.row())->statusIcon(); - - return QVariant(); -} - -void ContactListModel::add(Contact *contact) -{ - if (!contact) - return; - - beginInsertRows(QModelIndex(), m_contacts.count(), m_contacts.count()); - connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); - m_contacts.append(contact); - endInsertRows(); -} - -void ContactListModel::add(const QList &contacts) -{ - if (contacts.count() == 0) - return; - - beginInsertRows(QModelIndex(), m_contacts.count(), m_contacts.count() + contacts.count()); - foreach (Contact *contact, contacts) - connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); - m_contacts.append(contacts); - endInsertRows(); -} - -bool ContactListModel::remove(const Contact *contact) -{ - if (!contact) - return false; - - return remove(contact->username()); -} - -bool ContactListModel::remove(const QString &contactName) -{ - for (int i = 0; i < m_contacts.count(); i++) { - if (m_contacts.at(i)->username() == contactName) - return remove(index(i)); - } - return false; -} - -bool ContactListModel::remove(const QModelIndex &index) -{ - if (!index.isValid() || index.row() >= m_contacts.count()) - return false; - - beginRemoveRows(QModelIndex(), index.row(), index.row()); - delete m_contacts[index.row()]; - m_contacts.removeAt(index.row()); - endRemoveRows(); - - return true; -} - -void ContactListModel::clear() -{ - if (m_contacts.count() == 0) - return; - - beginResetModel(); - qDeleteAll(m_contacts); - m_contacts.clear(); - endResetModel(); -} - -Contact* ContactListModel::contact(const QString &contactName) -{ - foreach (Contact *contact, m_contacts) { - if (contact && contact->username() == contactName) - return contact; - } - return NULL; -} - -Contact* ContactListModel::contact(const QModelIndex &index) -{ - if (!index.isValid() || index.row() >= m_contacts.count()) - return NULL; - - return m_contacts.at(index.row()); -} - -void ContactListModel::contact_statusChanged() -{ - Contact *contact = qobject_cast(sender()); - if (!contact) { - qWarning("ContactListModel::contact_statusChanged(): Cast of sender() to Contact* failed"); - return; - } - - int listIndex = m_contacts.indexOf(contact); - if (listIndex < 0) - return; - - QModelIndex modelIndex = index(listIndex); - dataChanged(modelIndex, modelIndex); -} diff --git a/src/qt/qcc/contactlistmodel.h b/src/qt/qcc/contactlistmodel.h deleted file mode 100644 index 5313483a..00000000 --- a/src/qt/qcc/contactlistmodel.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef CONTACTLISTMODEL_H -#define CONTACTLISTMODEL_H - -#include -#include - -class Contact; - -//! The ContactListModel class provides a model to store and manage a list of contacts. -/*! - \ingroup client - \sa Contact - */ -class ContactListModel : public QAbstractListModel -{ - Q_OBJECT - -public: - - //! Constructs an empty ContactListModel. - /*! - \param parent The parent object. - */ - explicit ContactListModel(QObject *parent = 0); - - //! Destroys the ContactListModel. - ~ContactListModel(); - - //! Returns contact count. - /*! - \return The contact count. - */ - int rowCount(const QModelIndex &) const; - - //! Returns the data stored under the given \a role for the contact referred to by the \a index. - /*! - \param index The index for the contact. - \param role The role. - \return The data. - \sa contact() - */ - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - //! Returns the contact with the given \a name. - /*! - \param contactName The name of the contact. - \return The contact. - \sa data() - */ - Contact* contact(const QString &contactName); - - //! Returns the contact with the given \a index. - /*! - \param index The index of the contact. - \return The contact. - \sa data(), add() - */ - Contact* contact(const QModelIndex &index); - - //! Adds a new contact to this model. - /*! - \param contact The contact to add. - \sa contact(), remove() - */ - void add(Contact *contact); - - //! Adds a list of contacts to this model. - /*! - \param contacts The list of contacts to add. - \sa remove(), clear() - */ - void add(const QList &contacts); - - //! Removes the \a contact from this model. - /*! - \param contact The contact to remove. - \return \c True if the contact was removed; returns \c false otherwise. - \sa add(), clear() - */ - bool remove(const Contact *contact); - - //! Removes the contact with the given \a name from this model. - /*! - \param contactName The name of the contact to remove. - \return \c True if the contact was removed; returns \c false otherwise. - \sa add(), clear() - */ - bool remove(const QString &contactName); - - //! Removes the contact with the given \a index from this model. - /*! - \param index The index of the contact to remove. - \return \c True if the contact was removed; returns \c false otherwise. - \sa add(), clear() - */ - bool remove(const QModelIndex &index); - -public Q_SLOTS: - - //! Removes all contacts from this model. - void clear(); - -private Q_SLOTS: - - //! This slot should be called from a \a contact whenever the status changes. - void contact_statusChanged(); - -private: - - QList m_contacts; //!< The list of contacts. -}; - -#endif // CONTACTLISTMODEL_H diff --git a/src/qt/qcc/icons.qrc b/src/qt/qcc/icons.qrc deleted file mode 100644 index d6f31da0..00000000 --- a/src/qt/qcc/icons.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - icons/offline.png - icons/online.png - icons/qcc128a.png - - diff --git a/src/qt/qcc/icons/offline.png b/src/qt/qcc/icons/offline.png deleted file mode 100644 index fb065d9de5a85ce2bec823302c905ba2e50536bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3270 zcmV;%3_0_OP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0005;Nkl8&KWk){h-MxIkuBClVMU=+PGn|%-jm%{K!5O6rK-_vy`>iR@kzE>32^88Ak z-;aW^-Wi5ZhT%dGFbwql2yeGk6`Kutek9BOkfy)w>-uBMeWdT{x(|Zj!r|aau-(!$ z&+vLpmXW5mb$wCt(DG-bY0exDm-?P4A`Hj$wxuj7iYHJU+g6nV8!j6bkvu=wbw|?y zN5OtS3bKqiX0_tsL01&k$Vb6Z!+9i4PtE6^1hCtU<0lErCCjBY%cQ&%XgQ6nR>#6{ zOlI7_>&D&Vm~Y?YbuB?Q2{x#(<2bThK3{#e8{wv5v(Yq-81W0ZoZu}6M81E&v)!I( z8vTB+8%I-3qb5^7j$OZiaToP*eA{x;PGE~>O3IN=>BaQzhq?`OZZgUQ|6zrHf9TcE z;Sx7t$)ezTJ*7SF{3y%)vaYcRn{nT(4PT4tQ0dgwui>w_g4z4=;kxAS4Sm7y1@rdj zV2Qu*1@{pAGo@zFzv?XK{J<%WC-4rpxWVGl_6q+G0AS}gP;(&Jf&c&j07*qoM6N<$ Eg0(0vQ~&?~ diff --git a/src/qt/qcc/icons/online.png b/src/qt/qcc/icons/online.png deleted file mode 100644 index bb0d26142ba329b1784083c20670d02824a7b091..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3271 zcmV;&3^?KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z00058oR5QX7~6e9$Pk#^g(Znidj0rpL}j+=D5?N$o}NWE^{=O(NR za2ssp)(9M6trba;;=f2Lg(xKmk{L|*z30rFFL=Lu@3q%nd1Y>HW_B?eFFW0Nr8-?( zi^UI#Sa)OXD#b3_9JrKybCQa}a2? zYV{FbTT7)9iK?xx6rMHyjB548&hC0Jh(to6!JyG76mt0yTv;jGk{lb?YKth7U3R*Y zDL|o6uh(d#QY$M ztbADeAAGVN|nA-DYDY0O_jJN zS4xZePNfxHySWV^_ok!>SqMYM_75z#v0VnnNmM-eR}egQs@Xc6(J zh~^Q0jc69}&xk^czeW`BvwVJ+AMuOIxs@M*i(p6PoXWF6&&t`A8~r=l>YM&IMRtj- z4thp*id+@hG4g6;hsa;S|3Bd0z`u!X16qSt9^l`=zkz=b&A1kV0+0{#eB?$L_&4zG z@Q=z_m48(^v+`B23iJfkzv=e-CfKgUCsLoL)s#BDKe-G^= zO;mfHO9O&55Y$0Sp0@zaBTLpmPzO2aLC8iAS!hAX4B>Z`Gb&#Ob3o2F(U#wodyeWI zl^WG6YHn1|sJl@;qW+8q3>q--Z=$*YX~5S(R7V~Q9RNCrYUiUZ*EZ-P;141LT8M0h zCJH?i^9T3>tAUbqkbxFF{F&?B%ITHog4Az{U0?M3jOrKFm;a8#|L4)YqYWA`Xuw4G zh&IvPc`glr=&n2mK`lgg;%6YFg`gg!1z!(Qt$ExET}TT8e!*%%dMNN<<3dmeS-wAz zFK`-2=dqAh`Sbrw`_JP%?)#$K_eH$F=t0qO(F39?e zRXXssAU#BP^Wp2k>Y@uj>+HkVM07`<3++8v9}%X9sFvuW1-fv4L0ZTMdBhDD7tle3 zwD7nFq=SEfduU-IhDgqpf`_& zUOswqb?CukhweNUy7}nBRp=b!X+ye@9y$PNqAh5H@9=$t)q(R1iV;o+&L{Xfh{*J{ zP~;1w1K}YWm;z#7B%8k|_YyrUdPMZl=m#-F;AAkIz<2Tlj%iPAtBI(UEvM!YC? z|GMuZW>ieum=Q5&V}{54EoK<@9}1)aP-RFJs|D$y${@H3Vj#~!?7-NvF@WC((Vyr2 zeDvii^occ9oHl%2SU(ZeLq}f^_yy&V$`?ZM;mLLIH~hg_bkO$ew*S}l{n2BhtHz9u zSpol_#f*gS5pX;lzK3%i2Die{;)opzSK$~EYvP8+m5(93CWyg2ALL^o*8!k^oTm*m zQA`irxsR^gn|woXfP`gvmU1n8agYqKCu@yw~YPng9u-`5vc<;R(gHfM1B~ORT^r#P;Ox zz$dua5YjdWnXdva^$rDtWTBUuJDOK)OnGE-n;CvEx zo9F`_#7)4SOJ0`6PBKd`|(BJ;Y7MX6QiIxJht63C@Md9ulTtXOK7zzJ=+D zrYam;%;f6hrP=W2quQKm#$qm4P<>wYk};Q`JItwWs?Fy0!b~4CxK68PUYhD@;-$&x zLRuK_X~D(|0I-F1Q5H}6Jrxqc8Dtv>4Y1mVk?m>Jf&VY0AJj=sNbKnDr+iLSXR9^s> zK58tiVQMTYj+%>W8iyK-`CSn1wR+zIFdxjTQKXI8eD+NA5!3@(cxfVfkY7;lFp^l| z;=>@c5cCJ+2UWV@59m9_v_l8w_=3m!2^p1tiv}it6EzS!D|Qb2{~>lJyw9MW&w%sk z9^z-f`E=l46K23UNSuj1XTkYw_!j1Xx%l;Y*nB>`FM#uf9;z>f8&G2joGk^*Jk(qU z-^;-Y54Bd-GR3fh=MKwx?69nsskxN*ECJHYBCxQg)rIvV_=)OH56(AC^8A9$Bb7sj z>A;RFxI8f!6N0{=guEc618+?E4`^V{H%SArb7SYn&WZhF>}+_S4d=6b%*4;ng7=xU z_gQd0+e6}Pc%K9BaBca9>mc9N7d_6kWUvIqiF84O4R!?Q%7ouYvEi@VySM)_Zt)BRu=4v#E}$v)M!4Ep^Rf z*jzXCd;40wek0fb*4Od$;I0ugJ zmlo097sET8S6k|#`f@m5Q3BuMdV`0TH^H~C`DIgQE4&HY>X^FQ;d@7M)Z1Cll!_hv zZo7|d^-SHZo?b$_Koiz~NDo0RC{_?Blsj0Tpj=@(J|XB2lpmoeLhB>4h2 zW)O@AE;rQpp+Bb-T6dCF`42pPA@hN_#c@Mo7sdWIZXvucfcJ&)zQ9Am0ytj?=fWZn zRTtCNm%ux)oG+uji*wp|jaBfz2HS#K>uBfeY3Cc^d=uDQ+q}HR<2%T6y;C&@NeihuWfqPJM9lXPNt&Q*w=W5?CZ-sN(cAf3C@13;I zU3E>pJ#ZuJg>%R80r&$+2a`N48k-|cZOt}XV{t`EZZArDDM;2R_#h09~frs461ML5yWq?}B794Gjha6F~x zwZ|HII*~Sln(*~de|M2@P+no&PJ+5PiYA;M_V{sv7$KkF zbYS}+_ye0Oq63#31bu;x2O2w)1~mVyexlz$uxn3(8gTKz`2w_HHIU0#aqibQUl6y7 zEN>-kekE;wCA_ZyToYH)=0Vj}@V*+}LA5os`L%Gr4(`{({RX(-2=|-eeha(@IIpvd zwhrfY_rg1z*E<030nU?-(#GLC`2;u#@2B7$g!9_?mByy=tB<3}t4&O4Xnc;>`>>xU zO`LAz`3>}7eTw`8T2QR8c?DXqJ|Un3<%`M{ZJ)vA2J!{U4;eSGb5njiu;YjH4?;PC z)*3LEWcvng{h2i2e1UWT?E3WFucu!aw>qv1_)Yw3xL*zLtKfYVys!39bq(CFf%~;^ zzYgBv-108YH<8h;|oPdy_jl(XnLus2|~XMzTUpy>Ex9rRuj&LSpT4S;o<}_BBTT5 zjnaYQg7O39iOv@=o+Mvj#|;z@G@h(}BK-ra0p$dmNATwmtOm6HjGVx(Neybi?Ni8$ z_)X>f%3tZ+aopOts_|>%Zvqp)2L9K={aScmLz`cVzh4LU>){?$+W_|);eHcsely%} zf%~m+za8#(;Olq7{cgD53-^2KgnYd9^~85+pgvc@=5yq6whiLrZTp0Kac=p7bIb81 zxc1TXHFy>-KaR93X~rS+I`?{A(MU)a(v$QM)WRwJg6|V-Zs~MDT(Esj`VEQ+#e6|n zJg^#2|A4WAQZ=CUMot5a6BJvUE*<1Y+~j9p*&34g^+f#j@V=gQ4-(hIJ*c`K-Z#KI z5bxDC!Tn~q2Q{|B{WiGY4);6YepeCib@$WWf%EhBsyMHH9PPSk!n-)3ojbl$UrY74z5;(B?J68U4V*SEr+NAbYQgsliWAl+C_YFB!MLDYk^8m2 z!0#*Aynz0q?JH{R$nPI$ZpqFmNdsDw6z&IDj~ZHY=Eno80k>yK`&9}ebgaO0{};D0 zu5J8=_|FnH!uv*e_fd5t?H;_e3GO$;`xbZymUo}?T04E-_mJ1`rOofd*B^lUgK&SC zc7B-le#rCr>X+BkxXfmJ>3UuxY^-Y=Q z>%7i~d$0Q}>nD6IxH#f+2&V%V7i|B-`2uo-kS}2DAe0*_Cs6-jme)rNX@I^#i5k#a zRINwWK83(K`a_giWAp!znr-$9$- zL7U%6o8JZZdua3U{_;M!KLGcK;1tw50_VqQFTznk|6OA_bvF@1SKvPv^PYvgX9@9P z4X;H5DTiqPXBwN-3q|eSah86)IOmx+GtJY$>IOZy&$U{RUkLXJVg5imP>fPcusLE- z11=sYCt&>0^%2!K2-kpJZxqZ2v@YFgK>OGHeF=8|qV_NrMx1?~4j_IDtLL`F|1Dt) z+;5@ngQ{C-^IPG48@vnK;eH3)?+tgW9$JF0g-}->Yry8547n+*%tF-fS zIM2G3Wu6p4%}5JQ2fBv)1DiXdgU5V<#+>8}@Mo@%5X=cm(turiJ7B`< zF9^ni$21W11A$mjk_KY59^Gl6EjgjvvxYCQ`hJemDH@f&0C*`F(J|pEiGhHh+*de+Ykn1b=@N{*S@^3Al&%2B$pk zn`~|J80RJFpurg0(aQQJWlxGpJ(X(GE~S}_YZ)Pag1lKS!#K~mn`6p@)k#1L`kdhB zN(+zafS91T5b7_4`2wo}#thU?EKvi>2gnJv2Fb<(`i5G6s5PkS7dSs44cL8+@&nR< z^8<i*~;Y-go2g_jstj7w-4L{eI#-sC5AT z55fImxIaSQ?kM~pgZmS3e-iF}-jmNVesiv&NuQf;`9E^xh$-oxel9&U>EFcEUjhHS z;s0c+Nxwv_Cq@VP3AXc+xX!(oYf8goufLNM@(JbXAQTgvFQ}*n7$eY{6!ikywr13KS8{OfFkmJtuZGuv+%zdL?n!fx9B9=P8P_j~a9pxR#A{XTf#5AO%y-G_Lu zeVAAsf1^E(Z2Ql6jkbRy)AH|l4{}%< z&w2OrOgKt=t^GW7kQ2~CP;bFJu|gW~`v&UQx^ZLm3p7@!^=od7NE*<*k=CW#b%yLw zabv~dexTT%cC-Nh6Q7k2NZ6ZjFL5tzA5`57|NG#6AKdT9=Ytvt;Qt_P{t#^*-fJJB z-5;ghAEV8mpv|8o*8}xW(eB0lS-6Mye7Jr zt;A{1Qhzj{y(r8VXw7-CSP(qhpmpTEXTg8MzJ$Js`x5_Ebw4p5ymWxJzaRb&!2dzG zKLq!OY5Sno5%@m}_s8M>1U?_sJqiD(;rx*9lxU;6xk!~==P zfvI``?hnE}sCI~$52_!A|0D2!6z-3~{c+kpaQs{D)$UI-u5-$}7Hj|V{jV^Nd!f-2 z@t?FR$u!y5#H5`~Gg((@`{ZYin;>V!_`aWS3LX?#Xb#EdgFCU$)_RtI%^_R^T{Qk?w{Cxi~{-1Fkjq7V($IjuiHcRVuv?fdAAxX@ms|{%FMdqvu@;}h$ ze}5B`aW2DTU!(2Ahqy0`_q>}v*OzIx7vbyzdHpN&_s@FBI>Y$TX&-tlob!(|E2O<7GZqYj^BAo(()EwrMU@{;keB^uTz&{_Y0b z(7~=GlRmX#{l8T4zb4tF9!RzP=Uj&m_;=igd_3*F;BJ8t@3t*p$~D>N=*OSTG8so1 z%R9)J;XY#YUbxucuk9mxK#wl`*SBW=hA?GR@y1{psrvb($ln>gu z=JW7>y0J+)itlF*qyBdMA!C_!R+9TIhWoj2KNIe!&EzPwTGjy!Uecrp2u5nNLnLhgdP&L#^5TYz}^70ewV`>94A1(#ED$ zDE}A#4c9ib{Aa$BX~e%`v-mG~-HY!9_X|8|joJQ>tma zj&``3H3KV|yIW2Ux-1O(*-B#58s?ZbFvrOFRMTC|C!&Xp6KH|&&VCIYNPoBem{5Wr z(AY%!6?DcpRqEMP)96?ule~wxznM7><}x(5A$!!A3hxu(eKfoehxbA7-k*M7ALiJ5 z!hLu0zOL}z8Qwd?x%Lz}XgxWwd4S{JKLd?3@%{{+_-s1*Zgc7!r(Fv!j~Ca<=Y8JQ zpHqKcFx|cGyF%Pb1;5(+^J0|kCjVEr5^TA{Ntmb6m$24>>tF}oUnpz?L zn+|Mh`EPoV+#e1Uo0ZRr`@+`?O^|!}`K(j4_X8Owbt{~&h4W?j-i7$ydF0=7m~WT` zW)??-neFhxyoX4l@-i6ZD7u6C*zKX(oE(VG$3Cf4V2&q)Gy7vj_xj} zo77iQO_SqI?6_sp#w1gB8UB7QcAA2X#u4jB;_HVp2Q-jzzkbZG^@e-#-iTeAbQC zX}r$n?u^@L>_+4Dny;~QcFfmVU$&HSxv`AP^-eX}?XoSOC5_=~EWc5&MyB4-dZy+C zG%%@_9oN%q%Nzd_|0(NIjQE!?mVX!j;@;w3p~=5VyT{*WoyaojoAKS#nb#ejVRAc_ zJhu>jk2xK3Oj=*!bw9pqWQwUj6^&0LXF(Uq^T}863r)7r|G*bm4ag4!Vu9@!kQZj( z!tY#VtoRc8W2`b|FMfYzvS~C9pE96{$!ecfs*Qs8l+hx?B(=iUEgG0=EvlL5=5SpI z*9CCQep2l**ZL5&P41Sb@@qR0Bh>1gWuV8b*E`7r|73~ZFt6ma(0`y zpTw6POg4>|Ha1zkvP^zUcqn1+rmUZ3b;vSJ`j8X%Yh1DRKgi=>?JxU$w&h7MbCbzgW;ZYmmoopf84Vny4@#bB z`wZlSibd*+U2k)aSSXxyn1??a$Q4h0dKjhq%e^;Q5Pk+kY7U`Sj()f3r85nL@Sw%k=Ta6xX4)9sb zl?;km3M2p*Y3D4 zz*vy8C~rwU$2yBw$eoB|P0w*XmTGeQ7x`1!>Mwu!OVErJdMsOy8#gXwpNjIIekk4c z;l#gd`-K;1|9y+v*VEop_>JoxXV0D;y2mEHo0xi&>Y1duNv6@dMm7#uA3&cV?~XTC zr1qbECfnrqF4E%jx}Q2ZbxdRy{Ii!>vB1Uw^#gS-uFl7Wf3T{e{4=h0wdq-MUHq1i z{tA7iS3P9BnqhyIJKW=bz<>d!thOF*%hI09Hfn1X;lI)PM#k|ke_x2-Z}x!pKg?S< zAU*y5_rEXgtDgGj7cN{V(f~25{&eyk`VGnlGf&bNxlA7DVgP<1f2ha(S8+d913B=o ze1I`von^LFg z#`!Zn?!T)0DJU#3@p00rytbZAj=M%>fI}7tB%~Rd~_ICEC|(%`6IE<7fT7c2-(Dm95LOanRm+T%MhRpQ-lm z_*Wla?Z0racTdt>Y5#)xTln{v_FR8QY5!c#nz@Ylc!bz5f61JY=7Jv4qycp2zLbDysFE%&LFEuwUUTfjuGFRbT3#)sz>C*lMxz8HU z*xLriUdS1>PQ$L#)p~s9ZL&5qb~B;KPs*NU{d1q2HaLub=@bo>bx+P;7j$G?cvik? zzOT7y{d#ND_EB5Y?)`Sf(B@nl(_(@5cj|LX)0DfPyjhGjz$S6vGj7z+^Ot3{H)n70ukm>Kf7|}IdHgG$l=M&cWZO6SLDovX>vX

WaQ-uoGWIY3zs%#mynD*&kz+EqXPSaD1tI?1zh9htrv+)C z&B-?QZz)ad@(Wg1L;3!@#K`;PAoN2ES5)kNGP`7&2CHb_J6Zq2oRHhgCLf^nA$ENL zdmXhtL}!{bT+pyW_mkc(-8(m#bF%IE={iH7^Yi^$3XjU;zuo0_zi592yMPW?J6N>8 z#&ghWaoKGm#8H28bmrAGr>eQKtc%Q-`6E3aP+DFQ`fR`bi~qdW zh#%$f@7|X=j5xici2t^4w>2F;;P3me2#$YUE6RVf;mu6*H;9*SHuuIL%i-VMkLEEg z|GSFwuf41qYqk7yzJc8f#hQtRiz>)}hje>xvd+%ddFoCBww}hI=wFn_f5)pGKksy{ zlX2*Ht)uC9y`$-LqmyYh#pA!Uaa0#)n+|54dsSnTzB}EHi-hxU=R^bTU;O7T^~Mxr zpOXGLyE*?K;(w~w-paeD%+dIuomsa1x4PBJl*GTZ5YoV-_NG}+uU}!?Iex9AYxCvg zNpH6>&EJCmH+lVxirr7+A&pIg)wKTr|JuuD`Bw~Jf3wX2IN!vceZgMh+zy_NO1cmC zvxdDJdgmr{cDB_3=jf}J0(Dh{&&%V#%e5|l>T$Dihr%ywrghDxAUd=pH?w@i+{EM!n1|O@!#=7wEdBXlKg;TVDq8P zOXR)TVA}msxPKGwgYExG_?Q3p`PaVkV*L9#fX+Qo4xn`v4OTQT+1-m`rQ=-J%#N9+ zVc&*E=OydBY@MARJJRz3wyuU(Q{zwN@!#!wx4(9~(am(f+1-S$H@lf`pv_b-CYH-T zKAIVX5dYa1Sv!UQcl?Wc3x6NYSHl0O;{3OJr=1D%FC91yI3HkhL2^VgBGcxbHm22^ ztxSvi^n>oTFwJh$Cl>C4d%(s2C*^;4L(}*;``E=lXHYce>A@FkN@mb%#AZnlYQ0W-{t@T{>A-Q!GFdm{EVOfsr`$8#s5wp zcY4eRg!qSh^${%hZ@~Rsc)yO1zs%UrC4XFu`No3l z)zlytptj0C%j3V-&0hcPeXF9n173QBY8u6dGi!t#Ntk2XKGIL{U z|E2Q3v%@_*O)#G35q_S^dH?52Cw(U)ro!zV7XPfV3GvU_ zSIPl(4xaqK_5BOreri>(?v2ip)7he|3ATGf==)n8&Yg8p~=TeP3nzGD2-|7*OE{GYW~S%+vNXP7^_1owUpARnM{fKVPtKA5}cDcgSq z^Z)drtifEDW^xYY*s;yl_gdQ+pfLd35A^$j*7s{%0JMEb+kd0AX?~-*$v>BGvJPaK zrW+WmV+~=-V%COoZL*%RsC}$MXRcpkfCW>%@t^W?q(=SWe<5oKHYJ&q{d^W{sqDHM z;(!|i(Aj1>>nzy*b=I-=hrBe)J5y5U%G&d#wH8?D3HPdTraD=Uf9fl#&Jrj${~L67 z(C5Hd+~ewSe~{@gtwY85?+5?08=JJ%^#6BZ8+?G)UfVp7HS`(_w&Q_}32JSm_VDJ+ z_twZful}Fr4N{k-+CE_ZDSW`y7N+%m#()_IX!npf{|H|X-wqldY;~@cX*RIrK44DA z9FsmU-85RkIL9vLf9U6E{->h+r}RxRb!Ksv#VXFS*v|U8gRC!QAA~(?jjR`WPd5!(H?U*>s)HCyT{O!-HI)K&mdfq_4Y@ny7r+d; z=V9pmp=RiVp=QYaA*SQ>juqlxYvod=utstbeZUQj|L!LDV!S5vG`{l;e4nK)`fE$H z&P4n8vSxUH*OTyX$NwtW{+kZqp5~>PwDqhT+|N2Z@_^=-o7=I#R(BZZz6_Rn*V)b{(GmG+LLRWx(nfT9czuZvloUv0a{OK&m7emlYuis zboNnh`||t$4capPFaFj3$^TVX$=2E$hYuJVQ||cBu=~Rv0WeFQRb50}LX+8h@z=-j*Jtt9=NZ4fNFVMJZC!JpJTKVf`SJ3`e{;L% z+Hp?J|K?rg^Okw{jkALDUMkMDv1eQ@CC6XJJ}FRp34ML`gVmg0)6^eR zzfAt!=ccwz_1eB_>A`*6MDjxFEUD%iwfD-M{~39IST3VaY zc(8t_*E}}=zt!{6W!;nW+bKg+?7hejq|7GPqJt(&>36SSeJlM{X+mhSg0=a>%8p0M z@ASDj!&v97*v~#AI|sPk!q_** znlW#VF~hG7xA#!i+_vLMwn^`vZr4lK9}U-I@n_@7V^}*~Zvyif!?kTTLp552cXhb8EG=+GJ4w7e*d(Fm2%_0Aq!&=Vq z^jrIQdr|c_lsEsMJDt8Q^Z)tR{rTT39{&}wQEsbT)2K%yQ@4LzQ+)(`qeg;JU^Kjs zg7*|}b!kZJ! zgtt75e`~xE#=SMpwC(SW0hYBs%Gq1@TM<0T`k(Y+>2@z(#&P{wYGG%wb!J9DOJi{|26)N@r@?FHSr(72$SBP zWHIsWiDtsv6HNDcUJg(mXKFXnfr|&>I#68I@1J!2U&d(i?LFk%T5orS{uXO4nl1DC zXyx6LVq|&RlpoS-%F?%6|5wnNy+-u;t>3>_bhbpn63+*G)%TOrI>**gvo*G;vlU0Z zE!AD~>+k)8I*jG6|J3;K|HyG~`PW$#v%U2!U*-MOoLKx%Ep&xL>L@2LhOwHPbB{{!AvO@BDu z%y>A%%zQM{%y=}zOn)@pO!GA`>5WOI{XlOlSbn^$yse`8aQv3Xf9^c;EuGJzecznt zV&g6Lw`(s(7HQylv^)8xP#oI==bST868G*bqJrUG9FPW{_x&^&-@w*aQk|uQg>XNg za|7nV{~Y+AOs=spghyuc`i?KrK$8 z+}uyTU;p5~`s_!ue>dmdImY5Wu3+|ivn^)6H`Drq3AZMgPNO;%*~Pbcd3IMj(rcs} zXVZdyW#>%JKjbaNzB=zmXMVWzopkmC{0r6(__4r!w#zjus!^A_y6<$KQ`m#g-;c(` zJ>O-|8!3%@_}6)qS)4npHR7Sqz(&vNezYE}{;c}8zKUw>R9y-G%iy2dTdKWgH89_5 z;CIwyt?>SDX#n0Y&wY2UnfKm25ASmYbKjdA(tv!yw0EbOLAwT-_CvgQ5d1qU^mrh1 z>I=L%b(b@h^}f6#Ui%83_2qbQ8n8Mz0Z(J#sV%_fUkdc+Y#&4GJK()6?p@n=+>8Ir zTZ}O>cbGSl@xeBp&cDq4Xx~}magA*q9o1G*eVq{h)ZGgCfQ9$~YB9#ni+!T=AH@H> zcjwKS|K5Bv|NZ%9!TSq5e6YZ3KsuQ7{v0#wy;)|)do#?`cc+?3k0zO+r-zzet9zLa zV>_7UZA)G^r@vcsYR$A~>wte&htAUiImg-0Ik05=6bvdbxrccT?aIa1paw$c|AhGh zt;=e57_8*`hEz}oyiR=UJHz^*E`?`o!nI zzGPnE>2be@>2j}&>2RlmX>*&o)!VI1^IK@-7VTeWbdk>~u4mt59G-Ji?3u1y-I;2- z+H+Oz5LYXp0ec>h&zbcHtj!gVPXgE0gYDhL`lsRE^3S^Gv}>FPa+UJ{udwFhGV@@s zvF7g*YyQqNC-N#|lAMjIGj??5PCd>|*4bJ*OV8F&*vp&%wKOdM)YMUp9b0Q@9sI9` zf9kHO2A{3RNG(q4asHXQyia`olY9XD-(CE{VzcDKB^HZ6Z;V(M*F9>lG?v&ZrR#v z)L>H`zW8OdeXkztU2*v||KNV^(hrxKWgjgw%RgFfuS-8#YBgYW@X;cxfq5Uyvl?)* zVB#ZB1Eby^Wrn^v)C_!Mpy~U1U(@qJPwN9Z-tB1G-Dzi9-)JFslFBNskKyXqvr!ub5Aw+RD;ph zbK>Ivg2%tk$kut;I$uxiU$qlnKE!-5wKQz|7ys1OslFZlx4`{IeE)jR=avsx1OL=w zR83au@_r6dpQi1*_pJD6#qpINuQaPZUS(E&*Tc&1uC#hs_VF^a^y8&w@kfh88kqI| zEHnMR={6QjcsRkvfe~+yuyH`SKuK|+<*k;XTtH)b71cm^PEe9BaJ&V%tmtF+UUw~x zcjfpM<=*k{+P{2&_5E<4e4e;Z`)_d0<6mdy>ugQ6f7Q{beGvYstD@REs^Et|9WR=`<$_B&tIjE#>+>@{SMOhsjZ_LOEq?T{Hx}g>h9S(j2qyedYr1uN^Ra} zQvX5x)9xp(`<}Jumzuo`&N%LmmbbQ)-Thqcz^ zgVKQd1ZDXFrvcep_78{EgrAQExpR*luO(gGYl2so+qwMCeP1xvm&Co@=jxw#5UL~T zYe4)9mj8?N{e1r~{_CG3?mPZDdskq7SdepzHCLRi>+-^i=)iFpdN$p+jJg9+CyJtUx ztN$b)0RK}qet)Cc^n*n* z4%YsFc<}wzM)6?jcfJ0h)4#n_r^KSRJYk!l#nK$;_6RsIoJZR60>OlyqUECP{ zRRbr5I#?S2v;3bW_MgW0!@p|la2~&{v7}mCs<|c~p!$2N!X54>pg0@4s#R(N+@<>0#54@C85IVB^7>@2{~MSoYmzc8tJj!1;l24FqFB zr+b}jzd&Pzt?#h^igDs#JSb_Lz-b_KB{y(fmB*!fT}juHe7xn}?P1nFM%udF&(7Hf z;$D0^WL={#aFyo{S9rb7LISoXh+iYD@dbPU{Hqq8&Hv6)8{ibaAE?fTt;2DcypMWY zs=21xdoS&#{Zoh0YQU?@`Zv|+6<5#e-_{>)J-h8k+suwnc35oxWV;czeX`AJV)KtS z+uT4pkOmYFq=CgBFShxBV!?F!1)+QZKj6lP`n}Q5<^$>*N&^}v4(5fSc;I|NV64db zgODHaeL|4G()hJ}24Z>eb?$febNEclbAWrhmo>n<_BM+1V&Lo}oquG{K!Sgr2`>KA zUt=#6P+b_+57yp)@vrf}`e(fuP@6g{s;?v;pjuni55fHb@;>VCsRpBJaaP@l51=k9 z^?9Fb{by-v+Yh(3-TtHPp8>P;lbvSgkBhMV$DR(HFHlTSZYT{b|K9R4HQ@RM(tsNy z>U^)WH%4%m^LWC1fy)bmV+G0&LSx5)xDfIQ;?MWn6}h_imBhK@U3}Z`WN*9nw}-%9 zSG(VttF2L{^ACJvUEw}1qXC_X$KJ=Zi{yl=4FvxwuMz{8|IrwrjsLWN)mT!UEzAF5 zkAKzRQyoUt<5XQ%>hpd^ectC@|6Lk@`xWAT*N=CFu=~^9Rtr0Ryu&yhIA0Ldz>@DS zF$+FgVCH-{$IN(thBrR&h&e;%i=+X~7xjOmzv=yYZ`0#}*FOyR1;MX@gVCl}!SC)LDrW59Jz)$#bJ)|P58spg)o!w3IW_rX0iSrd1||IUOJ;^wRP zx8p}Us>1(G@h{%@e7eV8^*CGyTR!pfg7rUKZ}Y+x-=lv>UMLOB{cx_C`N2#x<-MYD zLX8yElbuN|TNAHw$^fPd<7swOM7d2dpqx$0NJz55RM z@3Q;HyMH6@g}p!7Yq94iJO{fz#Ww)?f~}uyHSz`0z?vVB7k=OC8!Y^Iq1C{w4`vzl z4JN+Jyx}9piO30ty*h81^%>EE`i;^;C|^|H!S6q~ zIfn47$Nrk-rZySdHl@P5ESPHH~2mWod*-dHP*CTXI_!3ptC|$qeS~xq=C#! z#Da_DgVMlx;s7<`8lJ@mFb8PI0I9F0T6@)x!Tk}qKZNh64yX91Ht%l|_9S$1ynK~c z_@BS`)4gWjPxe{t|H*!P4QfFe*zxHOv+c**%;rxvn+-prfAGVioM6$%i_E-_7$f+w zXpCUI9}kAVJv`(KloteJg7XI*?|E~{E zKW%yDGwhlLxGucGIHkrab@kEg24faLXGZ9(pyt;D*K5pgTtf#}(ZCfnz}^vCpNtw( znHSj`e}Omv|2hjwXF#YvwrZ!U=9b2RRC7@^7*&(8>Ot~8khni_{#VI)@VnsuJMe#a z->3VGxEBum^nls_QyznTKiy}2fsF~D?zFx@8rb+FFE7+Mf#N|hCr~`FzQD~N;|rV) z1~P6e9rV$d5xIfU|KMVU^An|AEwAF%hke~mxDBBB zO+ND`e#eK-l@(gu*Sp zpx%OgBsG=?lK$R{XQlosR{ z+S6}P|IzA!xdrLLL4HEoaIii@F(eF{n-=Wr-DA!VYkiB)3PYP)j91)jZFFsO(?jbU zybiRwjwXDxyvBU@Ro1?7o>akQ#x^;}ROjQUhEV!>e88*t0BS6yoFxx9oos8T%Liy2 zP~!lK0o3HZmvA5<<*Vkqr0;|O_Hh4+_&@ZsL&b0q9XOw$ykPfFc8B7Dazn*~wLkR6 zjnzk#FPQ%kYYXWg$QMj|-XNS$4M7pR};@qsJ?44GTf7!@xXI^$ zb~n(%4dywo;S)fME1m{)X1w@UeHHPaah`gC)Y}sOItw`I6!XHY1=U$Lf;5xqGS{u{y3ONB9P+bjaK>TaZkm@Da8f#~%7YqM7 z3sAK<>z%0g2Q)CbEDpZz-yQntp*isXM{$4b=f}*^pC1iDKa&oeFL3$cuAg}QM8$(* zzJR=7+4mSb{w`z3#DuvYdAWhpfyR*K57cMW8YB4xrv;5EyIjHf2KfhR!o>?|LeO}l zAbmWB`}`~%_xPEhpS#Cgd)!4^KDysQU!d#luBOXvv>*-KL<2X-OKvcp3IA=b`Wm3N zM!_Ze1k~CQ|Ejm8nro`Nr*i@AS&%1_|5*P-{U=_>|8?jA{^!H{AH}^iVDSsCKtC(Z z7r5Ne`2zJ5T_3^DC6XUn9r!t-;)3#n$?r|JV+W6E!Os;GC!`0BD>+SQEuw>TVYR_J zb*)vGK7!Exg&=z0=X}(_&-C2l9$LDGmO#(DXah(C-EQL>ZlQx)-m4p_v(Z$8ku%}`$a%nDTR-n~LNP6{=14I@W6O#Y)<5`~&{(t81bbAZ z2?xaw2d!H#4Fg{1T+9dP2K0M?ZhZ8)hgN*_zKb62l84+O-rU9)NCP*04O~Y9)YY&) z;4=Mz*P5Gxi@pyyj}M^!UivwFz?sxPP;2!Y(eA@_f(9nT|8K?liC>(saQwTgbRZ2V zCWPk&8Z&Y+!SxmG`VxN(SvjJ{5H)_J{(}0Aw$H$NBjpLwf?~u(#uBV=Ko5!&g4F}- z(X<{(u>A_wsA`?6v|;tZ-UaPn5VV&mh{12586N{5pc63Q0h+jvCP2UY_>p^kjn%*% zG;o_f>Mi`hO~xzm0jjCc{wn=b`2gzdsMeBdZb<_=OE&vee89Pk-%^Y7g^u^(oQFS$ z{~>VwiPgX_(SQ#Vx- zqB=cjpPHa`iSiL+-r=k>{DcMj*R+RC`&UBxU_aaNH_?ZWVQ=C;-as2Z2EUFTz@P{8 zMbLuPz&-o|=yR98>22}@X@GO|tp=_W2d?=(;0k-8;9oVj3NGLSsJq9RQlH=hUdTK@ zoa6GIqk;Cve}4R)^#MNrCx3a;YT@`Vi(-R|2|-_=@q%D}7#u&84qRMNo~ZtUe1c+w z)|;r`Aip3jC|6L7(E1bYQxmKn*taVGV0{Gp6`UrlF5Vey#saGir-`>lnNdDQyg9-M z(!{Vg(8KHK0ay*(#~<9sAKYVn;x2yR4*d^l;1+Y5HyE3^-r4f68at{p(fTs$T;N~l zQ0AY{znAk$&I{GQFOTE$eh>dC@PF9F0p|z8b>Mt~azynNl^3|aqVhwH8ORqn9Vjk@ z)|@e~1&qu;_upoNid5<`H_$kaKhLmrS*Jir%lX7Yf0XyC4|f!k<+dJ3wop_(eH zu_ON5US>=H{##ta2V87^xZr%j3o))&9;Z+Gdo=JJ_@57cBiOkv_ zm`{)nw9Y{OKx+>*j-+)*(t+ZG)+1|Oy3>O74Za?nCbVx!&|YTwhbfOdJrvW#JNSrq zh#g?u+vF2(5jW6*Fw#FKb@=PdTS)`=Jq?Kees_rjxBJ+-8sc9*K>T;SN*+M1t=6x# z{tY$v=EMKjI-dWeoIcI#;lIntU!1(@cn|78ejz+2xcpH5AUJ;bm_N{(bYBN9N01hz z1N9%ZKP9LI=Nq(#+3sT|f3#X)FSGVDYd`Dscf<6+`B#%3awZ;__zv^cXkhGH_yeFb zGIdU>^#c!x2M-v7Km!BsF>iIptEJ%Ts&u_hUw|4*KL0n{yw>JxnZtb={+`8q&_Go* zumbKsD^&-6j#zBWz@J|%Ne6D7L2w;vC^iIqg4F~2RGc2<7qo}f`3A)aoo}Ii?e>fd z&N;E?9!U#21M3mK;o%f}9-cHX{%!AkOld&pta25^x&FLVR8@N6~FecdXLth8M^(JoZ zS!p_O>rv$s1npgPTF@R=7b8MiU|+k{LEzjYcm9=hAPwj|Ja;yx&Pdf+x$*%zJ6q>y z>m2>T_XgW~8qz?YTl58P_WT?CpY3|B>sPW~?^$v6JU<5wi~tXu26S~g&{g~k&KHEn zkDs4awV*w$@(b))a(kKO6Ql#H1^1~?m28n9>Na&EHD&DI&(;(zFUVgUTBo(8p5#Qy_oEIrpX+Ru}x=lR+A zf><;#1@0eO{xxRg_ZRtHXzVbk0nInN`DLer@HL3iLU2uTaKDmtpna@%PrI)Js|C(B zus(saPITUlG*ImPE6&5S8sL1)sqe6_g>!OsUb4>3wm!h;Uv(5zPXqoR!v7Tbe=d77 zo+mF~^=HF%9GD0+X7DdieEd*z3c)dCG~mVzv=&Y4&%)QDN&_JsuxBl}f6?t>b$i;~ zSr_iC6MNpx2j00yAq~9CSR-d+>YPmRud{M>Ub4>3mIl=RsiE*MYH8eq|A~X{40@*f z@xE$KzOL_s`@Y~f_}t|JwvXt~E4eWv`GHVg;IBip>rGgbtaZxTrx1z@>|fHpHMeI? z`WlYYwaiSbyTyA_jedG@w08Zm*Ktzo`AJ8`;n7 zG_dA--WeA<>%?k+vu|_;k~FXoA0Ym9CZf*8oQ)3%@&EReKTmpV(p}pBT=@S|XRf?R zc7GA?g?XhMJHPm|qnF|ScUo`axYzn4A-EP<>(kv{6}N9qd)R^+(7tx(19Z-b&b!gM zH_QEVuXG05BF@6IK7ex(E&rU63jddB|8qDq{i)7adlBvXO}Zzzug;p2o?sQcUj@Gc z|FHbCE?H}n?f#S>`*DDMOV$ste@%N>wTD?gK>W)G=vC0O|t7Z`Cj3?5$lqBf?06CgLUc`Y5$MFFW~-j_OJbk_WxJ7|0j9C zKjHtcoNe$YH1Ij+ocsd*AJP6Va`w@V16 zd&9@x^Uw!)PeUK@5BI#I_XhvtLLc~r`@R2xAG_!N2X1oDzvI2%J@vofUq#P1>II>% zt5m6@o`=59|HA*b==BNu{TD^g?G1cf^xWRSrlRNe28y2A8wh-TrAix(34b2A9eYE8 z+p#wk{ycDdl`3(A;m^Maem^(-aqu}e9R7S$@b~-yw#S#{C;a{8=_CC2<>@c{_u+be?0I?ZBmDOt2klux z`}-pJd)jL;0hZ9diy0)TnESH+qL=|XKJIUd{lWO7Vt*h{gATy@v%nu<{axUOtv?Lh zu=SUL8%)yY1#YOLo(FDVqn-zDz&;WLQlO92)*5ZL($8D_65OT2Y>a1kJFILBp{=Fr&2Qi zuT*K%F?;#;f8Sc*TMK+^fp0BPiUlG&MaF;zksTtNN4ATc8re2-TSS|Pi;=A(-;Hb) z`Ckz&BEE=d9`UD$W)c5iM4`o>BJ%lJUc`TacO!BmE>_N|ysdI}<*A@KXaHhL`MPg^ zj0K{)N7aq&8rdtdOXTLL&QWhgc8vTC`~N+%eWbzuCbEr>R$N+9ZFcAeH zALRMSi7?pQRL-jWckmf_t8!-L&6P7M_X2glH99u$9TgwdE2@7~?r|FfuWQU5!t zYm|xV0y=|^po5S0T-$**Q63kL2XWCHGy{cj667HlF5n>|8!ocoA`@g({@>s;aJ+JQ z<^Ejb|8L_Wx_@+XRKKWI(S4#niS8Z!PdG5qJ)=!@k7xr2Cb}DsyYd(wqPy_8lZOx= zj*GS)A5pEjwt|-+7X|Pkfj?Rf57`-QY zK=kk6z(n^0eL-&@y`oJ_uNV{4GsbcuK4NRGL}bE+$ANe-aPT{@=Rec_^WSd0LGgt+O-`{5*}BfN-@cAyP>&@Q6j!ulxuQ)GVe z_D}*3e}ISW@bHaq57DEetHg|onTh>>9Wxx;33@eu4bnCoC{IH)*c2T@a47+4Ah z@N=O*=m+|OKGY%a?QsSKfM^N`i817>j*P+yc z8N%y@L0}*l0QyrGRGjn%J>eys3w%^`E7}D-L^Xp8+Cz|skWcbB_&aUkK0Gx0CUFom zA!b(0xR}qYjK$Vtz-SM#qp``TSQ9rI8~Il~jvtLZg)v}kyh#|FP#oiU?%;kmCcz|* z;f&VN{B9H&!5RJH2VUZbz>PS8k78VOqg}{Hb)a1Yc_@Sj;&h0IU~KSs_#6&qz33do zOpd8tWm1*nRVHHZ@g8EwWAkwy;>KYU5I+tZ2@^adOu&8rQ-2f zG5R<^tNkMK5Hl?%r^?hSZ&jI6#l%j=-jh7UP2}(P5kCoggM`W0MVNxkr()}AiKgmw z>?h2qYF?VjIkceKEY72!T?X{~nP3K(&iSR&c;8eo8Ggix_@Ip>j)W7quAAdb4wwaIa-OL8psl<#5kADlXrBw(MEoFpl;c5uiC7)e9v)hIvBAdZKwBslpED}| z5)L}N2<;$tPHeZ>S+V~kb|!Y8fz5^K_?Q{k9VE=a<{)tvHlK~ng}K;$9(I|J-4|ka zP<=5r12vXn&t)}C&E?eOS>d79O6oL}fZ8i-8;cdxa#+S${!4lNVz3A-;9PfcGTY6t3Ai(_+Q7sdWEZXtGGh;~52LhKF_7ozt?*nTm#UxLk- zVRKM@1vX!W)>mWqwb*?F#=_{vK)t?*;qnn+E%- zA6Xjq@w>fX57M0`-b6lx28Tu@&+ z=#T7plHYH$<9b=dgY2&+CdV#|txfIgw^Rc?ehGG8g57;2F2U|gvHLRYz8t%+!0s#Y zGpn)vTI{|ayKltqo3Z&;Y`z_h@4)W6(CqHI*3Q<}2e9M81}5ncHM7cVyAH!*Wc8W7qPx89s)Z04Fdyi6k7fvi6``|-d?Bv{i`6+yq{F7@B%A=Gwh1vo+ ztMy0y{60e${E>?ZZVV$hwh9l}|4Y|pE-RK$_jgv@N_0;RXw`xjR2RPLD(t=*yRSj> zYq9-$Y`+1!ZzK=dT+`Iv=Gon99i2<-b@$+Bu)o#2v@VSwPY&6;(OK*XRI@_0YaE)K zZ(<$;wN08hP~$*n+*^KpPC{I$ZKz$~r{tr=gKZD;OT=p%r-===Ehs+w{>YALsJ{>v z6WlnGZ3`OX25|6P`pI!?;tHw1{Do>Ts}8s7u?tn#V*7R2ejRq-fZaD@cWhpB3!2}C z=C@<}UHFb1bWSDdKkgxU*Sq@18#;InL-@Oe-Sw|~T-6`n4$ZseMSM{?zj9$&I)2jM#cha-rS9o{R|7YZde~LhWA_c%eFK``i0wCH z`z^%Rt=NAXw%>v6cVYWI_?rFL`~Wr=(0tvU@UR)I_fUUZeUpTLkbR_GXK!os%h>!% zQxmN7Tjpcxz@}aH(A4K6oD2CV%LDB}F}?n7FIFqBRsO2Jg!M;`1C42j1NzR7aiDo0 z&A$cb-tr^vGY|L7&Lg1q-`w`2F6*nKy4 z-;3t=q4|T@{xE*#i09*#)5!KOFQ?5f;B^b(XL()IU|R#z@Nh$Ge_Ka4U~|>kRxQSi z8$~Fo&YOJ=uM5`Yc3fCaFVHS%6V5-`_CSnKd{7%yjIOiE%UhMNDmJVCrarVCS7Hn! z#6ehJtr!Od5r4=2GoDoECB2@ykIC_yD$Z3vZ_hSuA%JvkK(>uo$7E=2pfUFK#rv7B|#SQgM%ApinpCbJV z^$TTl-`?T24%Sf&e;j~vK-LAkUz4q*^ddOauD=IY6q+d zkUz5P0SY62!`gu4l5F}UKcn{Ic3|tUsvfWEGOIRs^_|##7k1x`-S=Skec1hgZ}-D! z{s@{shV4%fTTdmK+`hTR>>lKxuvwvLI3M4Cppi*^CDo{=ux#gS8MJX}b&XXE)gkzL zeMT`JeBWeago_Wv2Fn4tlKhcklVWo*4#<`LVU#Ma@jjo%TU zMg7D7r5c#3g(|2nvg%{2PI`?!*ncnf-;ezdV*f+ zMV`m+j{gtp&+SzWO4XuNOc8oD zY7-r5Vr!MDKBjCh8wTy2cb{5n6-4NLcd305#zU|z*!Zk^*~(di9H<>It|4Efm@E!7 zzN#^9jiqY5Li27KyVE?hT?@dRbEq9?ol3)!|b;Mxok4 zY=02jQ>VG+VRTR3?%GGO|1r=0s^KEtTfZZpe-itj!T#s4Ke{eY|4k>5yB|)q^#WD* z-q}8A@BI7Jssnj<;X%0VA@>&T!mpWZuRK?6%iP=i{Elb;oZHkd1;O^9d`a;+m?K#Z z)K@r`V*6^gpC&&1K`g!hd5w;l3lmgHgZ)(Z0=r@a4;b* z@nGU7s)MJRh^mXJ`lzatE6Db$nPhE`PR%QJ1BzaRg@m_j|Sb_|DpZR6eL+dpjr z8a$F}Yc|SG(ywfv|G>BTJs#i1_P40#Lp@N{d(C+bT*Ri-b;x>^Ic?1s}!!^hwk=(fGFQA1elEjA9Dc)+>o z_dL6+-mdJOb%wgWC&+6Kqu+z%s{7FJKHk5Fe%fC8UOY}akY>^klSdsVmY*e_h>t6N zO<(H6y0)OWU^yTr+j`y9XKQqf8jbs?(YS@a${OmkEynlE#rD&&{X}d(nmL?d#NdI9 z{r1EEXstz$SZ|G(d{AIrSd=(uANfzv&*{6oE4AQ`s~(tYLkqS}IJKfxFW%~&SgRag z<7l-vaBrHc(i{ilxi#j{KISskK94p+->S~iIwomhQibfFb}Y@-FP3kS?w##bJ5ySh z-DU5lJMdMTh}Y{F7h26&&nm_jK*~zS-hh3)n(I2oF*ebk-kECB4yBol(-|h~5z3XRR-Q|f@vtexd!sLxo3I<2bHrubU#D7o=I`m4+7 zQ;kb8S)H=1ZHwjerwlJ9IPw;)g`^jyeYchIgn521(FRe=PIG`O^U*yMwtZV2W zUzIa}{`pgWPiC`BlU$f=q6)A#a|Bw0s&$Z2op`LZ+?}KT4{PgtlxP3slgXQ@N#u>S zpP@Yq)T`9B@z%yBuTx&g?&>=oIdbH&K9zp(>tFxc{%-c{*`e20)c(?a;REU?9>DHx zi+Fb5_xs=fzQpfzKYZ`K_w09%8#gZW-8t=ZOv+?@(%MEQ?O>XX2eu8sLH3?(Q_z<0 z^v6ZM%=cszWSE5f1djvqA8FslV{yV&CYpsr1KHVtV* zHZ9Kv&KA0U`st^(?^T}tGfrgKn)ZeF3r(}5)HL?(v2x`~^OwK;CHRpQek>h09>hVz z1r1H=4*ZMSz*S93}nyuP09rH!ZgC;N%F@PGO|**Rk}dCJL5TVG!GFYNE>zO?og{yF76 zcN}E(&N5B5HnHEOSX0o~)BUslo<@a@?3ykcgV|FO-5n0PNBuUcM^wGi?4NlqvpKbK z{#!M&Y%Wb6oqZwOl^|UXWmGn=askRjS zF85g9dFRfZ$KIyz)@uq{6_}W=hJ$Z$BCaztaw|@lNYkvv*eEu6W zFU|hcrkR@iDt*TD#6W7+u@?^Z zv@bs%{?F;SwC{315AyClL;gj-&ssztg|-R?cz@UP`kvYyYTNxI(b`win|=ZNOxSZZ zwKV%vA7-2CM5$g_;Uyo`5G`!u*(2Nsix2%h`5p32#xnXs=gDFGvHLW}RI+wq&w*a9 zC=SBkFS|Tue|XntcJAESnJsixJJat9dK8%Edz+iqZ?-n=-lG=s`ySf9L(Q|@t?X;` zy72FF@6Ve?9~zyN_dU5?b4}B=O-D)@`H@OSgYlY2TCH9{aPm#P0X;_gt~}?cLJs-|lj| z|5D8&)vi(vL!tHR)}`9tY6(51ZXusLhW35?Yy3VqUz>S`{u-|nU*Z3r#QyI4a*yPi zme*UFcJH(^9X_N6w-3id>pk8*yVr+bn=NZ*nr-r8d`b3quTS2}+=c9~c{1#;HlV(d z)`B%)jabkJx%ULG$-R>8UK6|LM|-Z|AbL>rf0br`Y6gALiP}*X)DcuI$u^7ISlg8p z&)j!4-9kQbJkw-eAa9~C8E*fqvtBzb)BaO3P0nfZ!6lyl%lf{&qj@3wcl?Mt=wTeF z4Yb}(-MgWlA9DApxZZ3@Gt>Na>fx>Q>|fURG~CMA`7v)DjOGWl2Fco=7$E!C+f&ap zn%>A{clX-2`<~2>nWkZ%h9-VIV?<*ZBN{;)7>51X`^LVvFG{mNb$kA(`c10gC8(BL z+a+zwwSVen#*L3*`-|S#*8kt$c|ccrUHKj-Lsy}gUL=Z;1d>pp2qYmubkTe7y;swF zNAzxtjWNB54hGyHwqrx$WY(JZ@{)OLGGy|c`~A;%&*jtQieh6Y zGZV26-__N<-*?X5r|!M~|NV93pE1vy7ak{<)ZL!^b8hCC+;_=E@6&2#Ky+vHTtnV0iK`6sMSFirLpFaP9M zy#Dbt{r_p?-*nf*`KRrBj8o+Abl~P7?TcDnC-+~Wmjk@%A$$f0u>T*#x4`~7ea@4| zS-sVP{?Ghl`#&*ZS_7Q?wFW3QyV^41h2~bVSQ6)(j2uW@_#nz)`oH8qh<%WBFreJ$ z#mS!>R-bn}N1kKy*{O6TuVI_{ZJsRu<;Z^*@;{PfQchzhKFu6-#)~_UuP^z~^Oe7B z2F;H*H`&*-i|zkeH?vI3i>$-!pObebn}qfF2Uc;e=c>A<&G7cQj~i#PE13UxG5_Ne zaK3sg|NX=T1``{Yq&%;E?m4nc$K=F#IuO2={vRy^!{!Iuo>9=j}h;=R>c_!?CH%_Re3AYgetAwM^`4{0H0d zAMD4+bKv3rQ}GcECqF!cg+4>S$Fz;HcxH>c1p{iaxI@bqyZ(|-=Wmr)O}VvHlw+^s zijKv~U;SCnX)v5IIxo(|uO?P=D`hujFFvZh_%rqp(=glHC+oZx`tvONPxrh=lNoPo z@Q<($&3G-t&P6Rwac<;H(EJ2z?I^F`7q>4@?aKLgZt?PWzlxX^jEP2H8m2XCU! zZwbUsgY8fZWkT-++y3I7lh~U5Kl6^o-;PB7!sHGwU+n&qoJO~m*Gl=#R0dogVDfk7 z+h>G3JGt|3e9w4OZz4W}+4u?Y`_*4bSw)QN8e;HS!&16LuD|INhzM~rH%MZ~Kw zB0f~HtN4VQwDZn2#XTo6JJI5uBSxVE6;B7np1;T|bd=muh8#mS-=y*l_CMR-%0HYv zMtWEOPi>uQ8ue>rVkUq)nL;0#LHx-K{7s{X`E2jWUVSRm9;2}k?Em9fCtgl6>2G-Z zl5o$H{`9=2x!7e!W0ye(T6^M`u&yp+eO=5sWV9y}eJ=EQ?)$R;q`vOS|8dVr&Q3OU z2h}yz#}gAh37__4eBzVvhmWgfq#HfsanGsWxxR@SgO7eJ`_Qqh$zYO|2c>JzhV1l+Dc+t3K=8c z@N;VQt7W1maSoV({J}&En_hlQ`C{#F!>r#x%Qw`a=@ax#;9v-AAUR{r6}s&t@! z70xcK&-?cm;q>SFfAVzZ5MoQx&!?Ma%f31Le?~U;+SidkKIZhL-dGD~TU5JLcefUV z_A9k5bl%r@oSz}JWvY!;6b@H-+=vOxKVZ}02q@P6JnGu0=Hxs2V$6*(#+En9iF{+U z8F6)lY1PTIsf3%u_1q`@s9tJI=#P_s)A_{woMukAh>hSX@(=7C{rU_2?$iFRc_`RF zMso(nzieY$6ywsP_;c9P-rs%B|C~l$8<`3-!EJ!W6(%}z67$c*h%ev?DAxai>}!v` zG4}73cWylSCskZ7+P*vc2Io7;>{)))?_EC%{hpJ5>S8aJP;!y{n;&>+yU{uyI+usu zr?}ts?4a!B(=0^(is?f3Hnx#{tn1s)>p4m7l1!!9#7WOV{xgvOG~^FH9gcv%hpVAj z|KqqD_U}bbSbw zlaqhiaxczMvdOs07`TRwazEoB=i&48S>03je%w#E_=k+1+~)+czv9W>$=}B5Y9ITY zo};svY!SkO3XdyHw6N)sQ<49ah#Tc6moL`;F1y5}o0C?PgDaSaFPN8?9No&#J^1Kg zlhfC;3Aujrq-%Ny+8pqMh5alsH>s}#V&0ICWE9lFN%SxjJ^1t<_8x(~$RmG4?y@)Q ze!8!dzxuvpuQ*>D=Z-%zZ4hhnSB(Ej?vQL64sB>Lh{AzZT!{R^Q%&42AOuvKuOs7SiOzS?Lefp7h=h5Fd z2c>Q%W>c}U``DL<(Ls9ebkp=@FRtIkeA?K-7E#wDvd19pp<&B^8)+9R)M&2B0hTa%z`d{mBdR^^h zx?S#OI$r8%axdVwIgcIY9CnzqjDfR^^)pRP@)S zIr3kE{K2M2%}4fdHAK#de5&|c$sf6QCpX`p=D#=J=IQk3YYyt*?T0!T^5ziJ?^-|8 z^J-7i<#HF({$hJO23noN2Xzi#6XU?f(J~IC11tY9<3MAh{DAN=Qw z>zI4M;|dooT)N~R{Sy6ue$=1f%y{bf^SSTLjU+$fN6M3`T)D0&f4Xv~&wO{Lnfi`5 z4#wUdYlhz(ZU)^LWcps~YkFMmVLDyvWZGTy=Al;SJsrsBWXFMYz&s=jM7VL_bl~(L z*}3B6>Ayke_Z=sD-Ou%TyWTSY`R5#`11Ed+|3=8)&OL7+|JRGkzt&#no?Xm6 zU?8d?e_=s|#jU&s`L9I&;M2tq5WNWbzZCTmyd_VKzt9*UN97{rs$G0{u~E)qm&@L- zgK6(fGZWvQX#6_pbFGibzmjitpm`{(keD3bTJSg>IGmQfJ}>;2e~%OB^ZtG>xrfSL z_Cfq)c>vgw+7_Dfw>1=!ftEQ)+4 z{E_63?CX**^nvomDu1wwbf8@FFWr5~%)2ws%zAH@kq#!jHNlLzJ;n^XIm`^WKESR8 zT`zYv9WHh#vKF}Y*y%uPa=5w3VYK{uaN|L9$kUY2{;oCF$zA>4-}j4PA_KB-bey&K z81w%dti8xT<_L4otIR#fzt%xy58h3fPvJkSZe#A>O#cTHElj#F>f#9yUqjT=s0WdY zBcB<6xA@ND?;!hv<=YlWlQV|L4QWy@>3=;5i(g#o{6V1hDerKxlM~ z`3LzoIEvqe`KRt{$p0`t$AicoY>F^g)ppYNw;_9Qxs^9E_pGD;uR;E+kpBwgzbvW% z?viK5pK1&s`y}$`{ziG!SA9S}^$%CtB3&#+57NQ>yYtQL_hy@E?|O65=-ZwS`d{xK z)Io5-UjAqs8xWAajg>+6jZX#&@sl=&@;G`RhE@1%EB_;f(|v`_|wHaVOx(HUHN{{?!lA_rZb+ zk1JfXu<4by(DyeY|Mkd!UGz`IT_PEN-Jf+IuA4}1?>{QPyUNCoH=6Yyljr@TwPyAA zSDO_ddSl_G@4aMZql4-1PPh9aHy3F==yk1Ea9^aoX`2gef_tOjSU8JKQfD=HUiP2Y zG#&z_h+G5vm(ch0S=ZNf6~@jM$(y1W4JUVthXfOug#43Ec%{j4ba2dzArLOLA+bO8 zUS$nn|6lu1ZBzXq@&^+NR@A(>6ZvmP{%{0{tD(Zi3V(#PWa8JAyZb)!kJ#}24VTEX zZv17##~aMLkJgzrA3Yok3*TR8=H8tf)PeRzIv)(YG0Fje<6_w1qngH0DlK*g=dehYnnQ}iXc zOCp^7p2v0LM;kMc{R48|o6Yw&n=SXY*sI2Z^q{e@>ietge55sD-rad-#=A4j4<{`!Z9IkKb z9;$2ipz8m^rdQrY-`|1!;cF0Q2D~NDm4D3X5BX0nxL07d-rs7r-QQ-fTkd;$*mQ4` zos(97wAw8HaJjc8d~d#)b!V2D^3D`9{;lz5)a_B;8G-poV?k$S*(-Ejmd!$X$hnYX zS{Jr9tqNNi|Cn%RhqS=hkWMsLg%&Gc|NCda?_dLz9V-2dceSyg#Dg|FgDsEJ{0ugd z)4UE8#fhe!;Qq(afpFi_!Rv{p(QDWv;HDF&i_T!$1Bn-)@^0k66Zvna|8K4EjqvX| z9U%XGlD*3IA8a?1g9V2dz*zSZQi~%@O>K&?QZ9ugS5PJ(3gT_F` zUC4e%g{QW$Ie9+owcz7|>d5~3jvwqWw)~JQMY`DfgRNE%8}Ds2Yd;RmM;|UTS`#!M z&3tcWa4cwT9)1hE5pz=i8`w|LgT{mAC9MzIE9G7CbfIyPd(j&k+P?;MBE3*FXZefX zvjzK~uCm3-7N~3MbFEF*`7D!l?qSJ3mu<4na^Ew2?lj+_v^>?)G&_L~j(a*tKALRt zRpRHeF`zFq2H*qGIZXRd=Ai4y|69oofc#UC{f{O8oj=@Z%dSs$1@+(`3tF4qe5A3U z`AB0y>%zFV@Z|*NBB+W~1Oh^}9t}s8bPUsA$qIpW=L&fR^-Ds?Y7Wp9B6t=OS zvDZR$7$|KE`TqHbCHEYEqvV_=cKr-v?lgKh#s2t&7f+XV3=V{&jDaIfO#G|Zg^0&h z9H{KjvO~ZJ^JDg*-)c?(WS@iVf4=L7yUgxScH1Hy?EGZsBV)ntkG{XsEd7u(b6_ku zJ!npHdeFQiTekK}8WT0Vdtz01h$+_SgP7 zI`~%kx80nz^9MWgko|)_pX@PvKiO+^RSAxTA8t1VKPU*U3vMiEUC>!U`&7+IQ{Tmw z9ngd3CGC}D%hMVmU1(hNz1}yd5BV9KPNWyvTjl$a%`dccxzxp|=zaIP%SGO!biM%A zfzq)M{S~68^LeJ-*>)!P3}fLm`+$?+H%_o0Bi3Db+>|3Jrparp17OpIi3AJt0G_Eo z3;(>+!R{aK?tskyx8%O>NBhj)AMLeQzaF$MY`(wQxOHJAV__NVg3is-!<;+#6wrg4 zmnOVD!LHMOUC6GdIm+on_9ginG)7cwS@SPA z9qjqxo;LLVA4~rGf3!cS2kAm{lbw@7#)9^#p?YxRVfuUcn%T2zOlaS#^MiCT>eeVb zHgukoJ~UU!@8gQq4fb!@z~zrqk&bM+%9YaR3c9+2t}e6QUqUC8?iZQc3K<`TT};Pw zjD>R@OxrVUP0lIip_AY^z~TxMEghu1mSP$oZv11o8rrz_|0P_}LCU^Q_Fb3!_y5={ z(uYduSkU^cv9Rvrbw+y7Ue(!=v_@;Mr1e4PH;oCa3;dlL7mB}-K6I{j<733l5k^IG zmi*BwLv9d5Oc{J*uo-lnaYLNIfNKLx|Ev9N>3aoTT<&9fUSf<~>}m2ZFdhoKna<}J z2k1c9w>GB&V*pHU^EZeGLkHltuP42l^sTP7Ppe;aP#yX2vpNXq;lPg%SRF_Yp<_XF z(uRB3Fr)|Bk$ig4yd*tnZgRSiT}ir_{Ptw)^N~I@KBSW|x6lXv2gSxHE)KgnJYIuq{|nVR40r7B0Qn(PsNn zUrYT~_LxsA^KhR-{*x*HDA}v{$Aji1|N89TtGe;v?5bL)LQ0iC=#(hR@h>0-!r#>F+(_N(l((1CC!y)OoIa6aF3 zIoHK>IMczjJH=Xj5+CaEtbfcrmidjIYs1O$>%52jn;rPkflJ8$k4^`=hMSW@&(E^y zX*@^|Iy*RjoAdX`_c`~@Tfkzv!}SdF*nDUQExIfq=)P1 z;X3;(@C^g6po7bdgNvLyz+2@be{hJV;~CcC(|LbH{+E#df2#b0PH(IS<%P1r+WK*8evq{HbBliHqa`=2uZrqhA0jD=YAupasU%C7^B1*e1H zoaEDkv#q-EAp5HPZd$9Q3mcQc{G@mQ#bsz*NEfr-eHgPRJxspM97Qa#jU&FvSRk%m z_=aKEhFPqSbkOfoKRX6`obT}~d?(AmI&)73$ zPjYjT-75wBJ=WKN-_7|ymw({RO*Srr7#YPWNe^@1V{UqPc2EyCe)TqEK{`-O{hRD( zg=@Gr!VJAS)C|4?&gxSCf9P|e&lcqW7rD22p87}jv6MxWj~D}glKh>kPKAjHOP z{ca!Ocf$uNKeSyR(82Qemm9^&xEQ4cci6+e$59&uBXS)D?_86 zRL}noe@7R!uw`^X_N%cg$-ezF${)Ai$F6-3`Q!JI-%b8cd~pVUw5Nj)@qHqHHwK6q zGm6_&?5dUj+q3_ucy8o>ee$izt0%rWu?skpTK^qn`c>Pwvg{^EUGTTVennApd`141CT!^f_bTUsk-oLa};(i~MgBw|bQL)pf+Njw6=4`HZ(_ z)SY^JYPqjkpTBuqe!;%B9}j%tKlFBq61n<={c7OL5A56Cm+yG5?bB9yukDSzmnBN@)xa(7 zO#`>IHx1m<-t_nG^U=omUq5i~Q`0-{H4j_mUh^>jYxlMu?0X%o0+k3>fl3tjI#@L- zSKRAhHA|F;F7EY%hjl3Z-}!ZM^6|f4oSgmd7pE`(`+i;f`#_P`tDIs&`p+HrK7H(g zdrjX9Ry3r41}hh1Ot2EUMf-g4!HfmhS?w4JJj{-rz{Bi-4BV7k25*|H*Z#5T-N@c1 zP}9IzwqK6X#{*wjXt+_TJ^M|Nm72-Ezi>^K$Jf z_jDlt_wPzJF8LN^0p)Aq9iC_V!riM(?=s(k12?~H_p+DZNz5l4DnppY-X z=J09DRrv#Q;Eh%;2XboIJm|{*th~2rzC7GX$f7a%=o3r+YsrL?m$>Hh`&YugVs z!<8bAYJZ9B175jzp!DL}lhOnJihMrT6%HNcWLN&zw#b6MVP%0F%48r5Cx<5VheY~A zf-R?bt)=c;|0y@3+&DPjKDFF?@E=+}xWTjoPDF8oszeQeBa345xhbdH&_K~^74q!a zTw??HTtA9((<6__d}PuYdH8eTy4>hZ1O1_KKn{r|KSdVBat}Rk!IT?UE*h?>{qTKR z-nEDkw08t`rid3fY9#F)MPAo2%SiyH?`myx*0K!Hjkst zaG!|-O(l99Z5~g1C(;(UdMiz)eN)M?H=R7%6mj^fRGCFCF_oDVa{ei|m~t;F7q9Y= zRvu5xH@QeFjzAuR!90+kI;y9a3(d-*4RUCO9GZoU3CW>x$(tpcl&s~i^YeOLep>mM zh{+N6BPY{tIG3U((QZogWZFHMc2A|v(`fSy+B}Q)&Y`XIX&mr zjiI^Et3yzWdk<)26oJY~q7`O0GRhUk@XVPvskt)xn>vVOSE?}?OjS+ zmy=hH+QbA3Vcqnj5rCX!0tXaDqE`a#6ph-f$_Zo%_mqGr?fS+sjL?Vd}!=h5!@ zw0j}#UP8N<(e9Px$6HOC*U{b$v~?4?3dw08PGxbMieFrL!GmQxueVXi$yj$YINVKq zcD={LseFf47IPoU!Ojzdyc~fM^o8KOKyEI(MzD8MU!eWBN;dua^Fic-$OBRHX!m^D z4eyUirI%>;LfXBUb}u6@AZ@O`3SBE#BSm_yy@7VqX61BKE!0lEXCm!#MDm!x$5NqrLo~{_((`fqk^Gd&s6G z4}6_*0KR-|)FRpr*Mc}N#QjofF?lPOF;^{r(NtYUuH1FBdjtC3NFPV%HCIxWk+XHR zr}uh$;kbp{TpaT%amvdK=f8@$pKS@`j~52R=8#vORB|>;7BTb>^$W?N<_hqU%oUnD zZN6aUNX-jcFYQ{HO>U}|^n;ARz9|(sq?Q`{Rb&vkEV2<8``<(_qwUMkIovDa{}2z0 z_=u{mqwO1M`xf-Q4Sg3dj?sJddCX=8%_>Ia>g<@XuZ&Qh-SUCGSE7i|tz7iVofx+$ z&Lnq#m@A=CULz}mI!o)Axc%@XgMD{xbr|9x2f}%9eu3itR)jag>@^=V`fxiPY2^v3AB$_;OG!f!_JThRMf+PS7Sl*0qdjA6PgcfKadPsB7+vC?v~0dRq{zP zh}sg>O;}Uq2Df>^!M}@#z~Of*4b46?4vf z=0x^Ol}0iSG#9XMw&zRjnX}j{N(Qnwv?|^0N$sz&y}~7%pBvn#a&z0f+&jsGEB$X^ zom<0xjoi4(N33VpUR&FwbbD0)u>)f*SG8jLm5(-+JkM&kaFoj5tlTNeZKM3P$|uvz2w790JI=!l?Jcc!K5P1T6u~*g} zu^svkoFSF3+{&PJ>C3eLh2mrY)-ti;&WisQ%*_l2x$17(4G)gix+?S7tFuqn`upM- z)`79C{S&L1qz*}s^#6K;Snt==H;rF~&zyEE_pI_;Cml{Q3ERM#tc3ewKHLlBkrk(O z%rwe$%FGy3ZvkuOss<*0TfE16?_|JOuzlcABb&>&_M+OBzghWvEA(Vf)QPsYWlz)^ zy*KCl+$?ZT&^*W(AZPgJ$f8&~5_qo#!rZ9@b0Y6x-@*PyXBYLaiUT;`^k*M1fc`NE zIShT#B;|&0e}gp*EUqTC(8JS;hgtbH>&-=X6Is*8u>T!R(bc`?_gbS_QzkOE%!@T~ zo8p8^u;W2ICc=z2+||(3UJOrD>a{CZSh?sXLOjbU0&cY;99-VLg+u zn>j@JC%}U%cV>en^o<_zCarmR9>pdtnwUB*>X`DWH@GbjJ7$E5p$5 zJ??kiBWVCRMOU+b*uxwO*Js+;w6AoZnC3BdUtC7EXXVRnU#3@R`@x&({^QZ4`Y z?vvU))!JIic3@7#CQYu?6`}15s@!-|^qay$-#Xeco2^S>(%3pYiqXQ?*M~Q@#gtqw+O&D|;%m{Vm^Uc}G|n zVZvH&Z)v%u{q0g);|GEfE+8k%Ym5)&0wgb8)A3EMT>PI^y~UYp+dnwn`163OjY-{@ z%g7xlyngnrY@6pV`&zbXF{VY4&sq-WWnTL;Mr0KEo9>g)DZ#`nV!hnSxjB%(ukL#C znD=N>a@?asALL@(AxZ1eai?u53V9DP5@K0&@su!*fVwJy>o={_YZ#l%iyJ=(&0 z^coyK+Lyv9sl9qyep-<{1i|*R)}{AJe`IcmAHlr3)oZ`a^P~JeMBI&;; z?eAIkC!y^JkMOB*IqgojGg(Wrip(>b+mdsVP0XYiJEtYSLc7H)g$z{E`ldb7#)d=C zzjAB0&nUvHE!o5mi#N(IA{=_otw5fmK#n8jJ{2yyNdcJjmE@aQ%V+nIhbYW_V*0^b z_);BHe>?5hIT`zj>`St-$<|nDVkHyRmpxG@^e#V37YgksU*M;q?FSe0nR26bJloN< zS=uIS`|FJ2JiC~AZ5!*vA?gNZUh73_&(ufTKe+hzE6&qCV|Ht4f%=e+!6ZI`tT+y2@EIrFe@i+u@u7WrrDZ@@;g-pfN1y8bnM zO#2)5=R7~Pfk|A!8oL8N=mT)ns4S)Qez>P;+^MmtKZiZ^j$+#1qpqnoqME5W13Sb* zFNcimFUs$e(9X-@qyAsNd3}2pw0<~zRQRhNX@Aeco}ZGZ%JjU@({$R_>5=iDnw@HD z55NXBkn`UN%2;fZ<2egYs%eye-JgdG0eVGFW)BYik_Wynt z`~5^%8I|q_x`&q8rpn2ehz-^EmP()|G}4&G5pc_Ke1b)sWH5Ud2tZ!<{VI|ZzWT$ zYc-S7BBjWjqx;nCTGPu}iN6ZJ-6QiKScyBrs|Yis+(4oEbDnkmPnbqNJUGwOr#{`f zt>HpDtsfU^SS^qO;W<1qCqPY817{U1vKUL&t&Pb!m-w7T6;1y0OH;;<&Ywahs zf22PCx`n>>@0Fzg?sx4)Lg&BKEpTxu7Z7!CHn~}m`P6-{ zxT~J2wl>=W&k;F892ax?#PqLppE@J!m;`onmzH{=JIPa>p{EMQsBJT_jMn~ zH=Q=&$>&ISpX9t`6FWNA`fKE~viUN|SArk6M`-)U-xwbYj^ua3^4R<&%E-+CLNhPmBCr z#MFq`(DqNhIr#ARZSfjDeR^N)I$=$xlN)04TktvErXRpJApQ+;)O5Vq zF_;U&=7GSbX?YQ`Q#u=daWZgn2#$-#7PN-)Vay`2qe-7%PV}R9=87V9$m7S6&Qp zkBE~;d{yEM6AzoX^DO_P<5mrD)rQKz^##`-BnyAh`);fk*Y?o%J05?_VUEqt^2f_& zN$!Ly8}JjZqW#Ngzj7uli2679`V(Dy!(HKrza*TQ!~01N!heeoL45GyX6em15U*X^ z3vKN<5D%UB0z+ls{5sC>;rtzHTXDsGM&n1{^ZP>lZI?gI@#s4a{n{^MJB7c!`c8b1 z*sNa^Z~Gc-wkz<9EFq3$QPibyZT7!M+q((x=!&qX!v2brU3?JYM-lgl_<-zO08g1X z;Ka-KSQ*I2MSIjPS6o|lb?>=$Yo2p$_xJlCmpAQqJnELi8xD2xM~k;i?H6~t<4w1m z>G*M@mP9?#{{haeB>dcWg*~+R!vGdqSaiui{Xl#@;^xs@Ag(a+wK*AREVwx_$e9|L z7p)HrIoP&Iw;{#O?c#n8j30ly-B~;62Z2jlJm%uj*8C?9dB>maxUE=x8t7;@+!lrEFNnW=PR!t;IOWF$m6e;&qmzUmA5eV;jNZ0H)?g%Q~5vLSb&@N zjIgNUMRq&|;_MIythkW|0Li4}nFNQzbau>rLZF!3~(f;+(&*cA>3}}BN@VLJbF4tmn;R+BJ zt~jB^FD6baarS6F(3~i)Fs%zgPI|aj#ltP`PK^mSHw0xt+x(ovp}fL&E`?XvaSF?K zCVtx>pYRF%i1D}1sr z;^IpXPFeie;ttVx5RZ|#i^NqV?k>m8uf8Czz;ImH8XJyV)^Yx7zOdZC0X|>*_cI=s zujQ6ypQXK)<&{0n{t+J8^po5NyP$ljjzhNIEA@=HORMf<-QP{$hc`C5Ao?rCzo`BC zq5TJhmAA#m2kSWh#33Z!AmvNZoFHyLm#;>0P=64orFbhfHneZl_)y=l{H@Fv?y9|n zivDK#T=`t)xuRUInee%0o`ydWE?4E<6OXGnM8)AM{!sbt#GkA7!yEdw;-75$KQ4#{ zGkr^(0hT-9haQK9>kHy~bK^mrV(JUxIg}h6C$!5OBR)yT^QkpM{X=q55ht#_p7*Xf z=RKa!Hs|30rR1K6%ahXP9Nb}N;m;G7>Ph(9jJ(&GyJeU$E(yW8S86~(96sSpk`xD>_Xmwn3PQIyTN>FZ4`e`4IBxcjjO zVxMdLtCIm74z+0eP4WAPXU1{-h*w5@pyJ+h^McFWAUSA`oD46n#)f2}{gXJ{hQ8@> z9a=6u_EX~0Q&HYG%W>#<4KMdLJukxzdJ!ID_zXLpM+Rq^Ur)i|b^@OX9D2(Aix2ZA zcKPS3ch`1zh07uu{;B!9 zYp1iO*KD-U>w{} zpE^0HFKBG2FIZku-&(0XgX7lR1ixI6^ACPGahi$GY{)gZdyzrE z%l#~$Tz+A`>3p`cX@8o0bSH8?&3q&CTf;y2Wr7S6kin@S_f=p_IL<4_Eu;RRapCf5 zXlyvnH_K~z#x?*{wACjov`xON=hl;e=sd1B>Ttmw(FlA|Kyhe^Wt~t5BbR85_7`82GIL5_$MyG=ak>`e9ylq{F`46dd)hSL|H(2 zi#6kS+B>O;Z^_9(=PI2q#j_NYL4e=Kax1-s-Rahp-(in_3)}PpIF*WxTMK>uU()Yz z?!;1hv4399Uiu__J9jxx{e<>^3eV1GoU=dUy!|QmmY-mIxjX;e`6sc%Ehk@XFKn{0 ze@SimYhC{9Ng#|5%F=&4WE;2>U?o}Qk&S#Q8LSLY9OMQ#7T{NSp!Z=jxTCA%`he*` zzdq#k2(lprXcrupN3LT}2v9aSZVq=X{Xlo&0T1|(pYPtWm%p6r1Ft@%-L;r@M7wr| zw%>|Xg7xn6P;RUA26DWktK+vo&h`Pw-QEa2IK7xvo}Tmt%N!A8jR@$qsK&K~tn_`b z;*)60Gvy2Zs%-=pKa4o5zYF5wdxMwm4L+P=G4R5_tAK%z=+67yD8hU@tTSyX+miNV z5X0`;K^!+&@4urR!@g?0p7gzPBg@qxKBh2YDD@GZo#Mx{TMYX!@UIk$*CxhHSoR8F zGA%~84?fl&v`H8Y;n#&x%?z|7fZ0|&I&COK7j>RgpJ(}d#Q2E3h%pflB1Tc?QQ%ca zfn5w>(JPJvw*UrRF@cpQfytiYl_2gKjIG5R3uikVyRk5)YKyS=4r_}(EZ#Voe&zM4 z2ecvYS?XBaXCtOW3?Vk-bH%7cO^7lTCW1Ac1P*C3IHYOdEQB4O4IX74coboSUjm~6 z7SfiN0{Ch0aKcXu5A)(gVxokJ5q4UbVYMTVILNGW9(G)P3al{g_#C|OkmBm~H1Fe6 z9}G77-z_d0Y;?ux$ayAmo=v^yfuCAPotIGG03KR6L1Fk5t5|0PI17sXeGUFgFhw<& z;>THt4_EkShj&#w`he}y7|8|O6VOF~8{^-(4t|=thJFTra9-5hs6Rx{p%2gTaLo?W zTy+WcUIFG!m|kI-HwQ4i;Fn`}5w`{gDOkWJ*4srq+YT=dv+hQG@w7*6QA}c$sraMN zM}>j(tNbVrpClZ=8{a9V{=mBNOnnJ_Zf&r+|D;^>it(tl2z=@i-pI69JM|wf?Tpct+<}LZ=mj*sJn2j+v(@Ks5`i)n3rQrTD!Dh9HnCD z<3}QQ{4A=oeDls{AN1p2z>lxkABz4i->u@r<)>BOk}hJm(*`hunzuCf3db(Yp2h73 z)^GMAKV@H4Y@Sc@P)<-j*2)FcogCfDmF_U9iUCp{Mfrr&+K1GC6nMI$jcvVEXBUIv z;!cXho&?&Wwn`t;h0W9G+JGLaFQ5(JPQ_WG@nG9PoVCRowkkcr-(TG8=xxy@@ymUp zyqd}{D_?buJ@5vADXy`R@w%RVzmYiWt#wUW+oJVP7=`SQC)s+ZUBah&K9EO}c(5i1 z@hPhupd4yqePT8TE7(J)3$;O*^4Nk{Z#;uje{nSR?_a@0cJtPU;65s=%qQ$|ABh*h zr<8?n?MvlGl%KKMZq}mp%+st*l}8b8Fodx@q_U|xx~fskw2S9e|4AH^Xz{M;m+@WV z-)yq4iD|g3p^2GF9RE1hfk3G{8BD{%`W7ddbTrB0C)Eb|yBln4U~0{&WnLUYy}|uO z<K5;$~9*kga5af*PJq6!nc*>O!(!FM?PB-lZOd$S_0|=PUNv%)-K+O9vG=dkH;J>sg|$nu@tOYkTb=L}o2eL5 z7q=<-Hy+#A`p^}VtiS0q;eHf{thmm^yhN)9`Iu7|<9p9b4f`zJL-DVAM!lx>OxYCn zuEO5tmAzM{W0`8M4ftkq<6nvYy~WoZNi=DlisEKM>!LRK`%jZ`#8dC}>K@wO(C_MZ z+lFb#2>e)j*Yuz)!hP1gr&!*YW-;EGqGQ?L!{e6g>W_bAdg|-Qft-D5%hN3O(f>Vv zKTyoMtGhlU*{J>*<1&JA)oO$4=>MKyXNqG@2S1g*ylC97>gfNDUOSAH?kT*R;~fL* zHQm*}`O)SDEsl8@FU2G~{Y!T#9m)T-kGLAGJH%Eto!`{<5!b$8{qr+|a#TH1ho_oW zms?robEf%4&Z`2gb*&hq3FbXHu6W(`YyQ4fY=O_krD6(4fe(B!h~*E1L4X zI6w3#SK#W8ujh5;ZBqWS7DFFm#ng_ZzRc5L##Mh|vb4UY=cNaAp!z3`XS`-T#P#XD zrjweQ)>m4a-1qRU2XI&|r{PaSrp-DMi@TIq+>yEA*TUn;X1#;^hBe&jh;*$Gk1fQk)H||cXz{_Bm*e7W(D2^Jt&zfJ= za&zg77de#mU?B7AfO3Vd{@u=XE9_o~{~rHatNyKm_f-88d%SyJJkv zH8t&89NCrl?vCY6WPj?<8Mge8^1=F(hvaqT<56C!HWS(e$D#U9Vh7fid0@M?&@Xqw zy|N8FN>0)B%Z}fW{*%y$HF;x_Nk5#fJYpvOHDo^6iv>^3WQ`j_KlEW>RR8#P@uv2? z+9qZl+&179Yb~#3;`71EAsdwjtr~b|ZqBfr#e@9^j7q_fE9BTBzf<1KyrSb53{tIr zoSlYo-WXBcG|X>UWK0z|eiOSSS}aoR1kN*)z?%0>C^CN2bBQsZR&@L(<|dkIec3w* zcQdfE#nx!dx*xr+Jgl>O8)Bn;B)l7&^ayK{Fyuzjuo)flA(Sy z*XeUkZn{1)e-5SoD~sZ&A1W7r-0y9!8+^0bJ+gyy zp{-EJe_DGTE=2NATSOfE!Dm~)GIn~g@af&3e*J3Lx1p&plfBW@sNcic7F@q3yg8v7 zKDB$w8KWFlz1R1)I48*?^hfWd=Rd@p+WM~u#PQGeP3dDL_kkDL*C58k!l{z3B)IX^bbKPo@5azKr_JjQgG+M!4vkUlLo zV;y_704_tg5x3{JG5BvV)~KJq?*v~@;{9C@>#px9R#$uPrqi2-#a$%jCz%El8d!d) zAl_h3RFVCg>Obe5Ia$Qlf2p`~mk{XWk3!VGL;Ot0olwiH{-LSkm; zM?JECp7+kYlH>vTME>f9`0kajPHj-!hT?%0-=#QM;?@WyM1o@m* zY=HcY!&e*z-_$2 zIqV2{?N{n}xwbjOR@uTCYCSfhmDp03MTb2lRaQQ0#eFK))9J!t1Y9h% zYmdFU`ch}bKr0qlvCnCznLkf6u1_HYVxL{ybG=vVnVJV{nksM=Roag2x}f5P=uOd2 zv|p(W)W0@)fc{Cby^7gVjE-VC6~m~wJ;g36_pM?#yItuPjA^zpyysh5ooI}^_-@rz zuQg^gf2r7b-m{!J;Cj$Luf=KNc26=d93y5GTTFw)4NUEWwXH1y-lc!4u&u&V*$-8J z{SZ@;M_le76q~#K2VVT0@|`LV_WbY7w=tMw-tuD9)ehwqSC03*OL=yT=UiaFOkA@1 znA)YQ=3l*+O)Rd8;%{@#5vNOOeWtZ(d5ZG^vB!!#ZuBZ#OvKz`Q~1M+yI*`J`>odk z8(TV<*tvgqv9*es+H`-DQC>vFiV1IEW9?~&^r5k#yxi(r{y18fv)*0}(nkB9Z=8&{5TnA9p2QDUbNA z2a4xYT&LprtS%TAF0NJMTiAziF|9U#w_;kAANo2uSd|-^e8h^~R6c0sf>s`A<$xB? z2xsvJc8{1i8c&F4}a%kY+Y=r&09&FvBRP$U#Ma! zl_ONxBo{-e9Jwxj(#8&g>sRa~d2s&@u8(ibf9h`ox`?D5lPLEoHeOoul#Ll@-B2!C z7~vayWd<%Ahjjzs0>oALIH&%jdO8+&8yX0Y|y#BP4qf6qVHYhv-LgJ;NP z-Izw+y8_n0qv)WJ{Zt|KKg!;=fc$pTh`-C7baT>QMEu5|OIH5pdS^U^5ZxiFh%50% z3Rd!x(r_gnDO$hZQP>gJRSHAms+;hi7oJq2gcq(f!_DkFSP!yU9O$3-A)ccx!eiJ$;pi`#_*w_T%DY) z;7gQHoK`HQEhQMIRe@jrlm3*+FH-^EKp$d}_TlUJkenz#hoA4a@HGAwAM(%fg@1@o ze;=_4eTbuaZY?c4plmf_iq^sb_6r+Nq*x;5;ZQ7*iz5foyfN=3M#5q`QbHxaxm+^9dG%oc^;!Q?9 z^K&Pc`cxgAKY+MYZ9agd@Cd;rD{k*v z@SKbDU9kr8tyZ1Ed43${`N0)Ee(N^nZR|=Q=HpDsw33hbCqwH*e8>LixwIGli^>a# zM}f0le5Q(vsJ#UntYSID&km=seC#TUuEE55VG;e2bnm}#0B7HDzI%(UJ&28+x{B9bJj3c2iaAg|4mh@djjz6{d#<}i zZHiheAH8e>)<3_8_!E5d>8;bP{ZIDRCY_sDeq`B9WIu8Kcx(R&_}^6z8$Un{gyJ6* zPa~hZV$I}lSNtNJwrkyUb&cL09S!#LQ_f@7KV5w*@gy6)d<1H{?2pb5C4OGZ&5K_* z8UD+pL)Zu8N5>ZhGv;`(~Ai$e>?92J-jkl=&4ou7cRBntN;ZmXBHS zHi-it`i0V3!f%n8R^<75X4)Li%(Am%w{#`B7ns)h_!eG;>jgVN(sca(_#@okb#2hH zfvMP{q8G!NTc)3r0X(Mr;`hNZI4n8nBhWIUc02p4+MnE&XTvcl+pgbNsn5!WE1PD* z>I9QIDz(_p)X%7I%C*Gro?GUydp>8H57TFQwqD&!&s2S-duO|M&mTT~xISXvcWskR zUqAYu{6kOrOr6X+25!%L?)j~bwfe{ALz-J1tIguujo$(f`7V4haOODutNnV0e)NpA zHEAaMX0~aT-OPSQHfiy<`9ITeF0oO2h%IU5=~16aY@H}SVwQ?g*<;A&&Ow)FoHM&`cvcF#->Ks8p^ly z&+hr05q_IBJnP}}X@9~NIJL3c6?uM0`xM1O8L_QY3$W`|HnQj^z1? zBk|w!e0`=$UKQni3O*l<(m%Et(dOavX@7%R#BD9cm**RQq4H0hNxakn`gnkQRehvs zuck$wA3Kitp%u05vz;CrWi=A7-7j4Ghg}`^Vb?`ngWpsAUElKezm%RSPwZQ%Gg6=U znV4=dCSq*F_ucc!L%wg!r7@<{)J{dlpZb~V;_96`2!5yuo^Ll3+XA%Ywvof=W@Fiegnr7z z%l`rAiL+ZP=0G-U@w3Zb4Zq2+iA8*5{Z$>-f4F|QmROfs_kb_w39v2mguni4?SN$1s@me=e%uk(UOI1 zHIuSMlihOV&B;u;;Q()>-By?5^T_kj+&*55%H9cK@a4Z~1sj zNw^EnfJ3zQVcEEa%a#pK_HE(N<+lQ15ez4st()lZT}l=i~EELl}%B$c5%vxL&W*dga=n2Rei*>W$lO8z&u~U?sln{ z#l6dJ*y?yI!}_|9SgNPmf9v_~XYUX9j=~Q0OVvX-ZQ0UfM^pb4zmc%W!XeAA>g;E- zJq^4v(Bnlt+v%5C$FrXK{NbLj>#iT{ss>JWE#()|iR?(~qs|Uy{c+42^6`p`Pxddk zDStui#@a4tx_qtkm%ko6@9(TYzvzQKXdgb153vLNeBJlg{dVR1D}T$}@pE|4KEwvJ zkGZ_hkjq1!+xgR9hi~Gw));3xkcmcSh2ML*uA?7dxwwPbL1h(Ygl8%4dk?sWyPxi@ zXUJ?}pUIIUzr8qmq=(7Csj6a;w(Yumh<_V3jI%B= zR4$*P#m0caP~3k+d(QQ(*e|DXZb>fvfIMA2p5oRe$U8TlTzh|VxdmUG&Utbs@wZ?k zs?P@hLEa^uODYd%PVNOxg6EWN!P%s##Sg81+%xd=k5N9i%JVpvFQ{U3^C=&la2YY1 zIUjF{HL;uE7hFTE(jv~o#0^&-TG>Q(#Ws+|84UXbwt=wEU~No?fA0(NPzsY!YdvRQ za33)nIs5KmPY8#0!t0!SU*p^hr*^|V_{BHCVe?Wgn_oqFP0DlbS3VPLGDY~?qSi&d zP;p(wyE@;B?@>8<6mO+HO5N4ym6yeo zWS0FU=gFYXD-=}ds`G2rEu7oQai+bm;#%~heQ)Aw;v_jYDqlj<%bXh(d;K!yh-l}u#&NH1?=W|;}-;stWel&`eA(ku05)HC8Kb^9v+{gb8=SJt`co-4UG zIaCUWDIS&*{Eoicq@#?2qXTM&(09_Z(oB;@O^V3h-7h^S-L!lSuBau%I&^>^i+k!v z_iHq)k!d^}j(X1B4Z1ZjQG*zR{Uct7>-$jNOL;}^pD^Vim$j?EeRekS-Wxb8Pi8OF z#?yzpf80Q9H~qb{SpB^EHtvwv$=8W>TbjQ(|4Y?TKTZZuBOiB03MZdBJ?bc~ZpXwo zC$^b%Y0^K0>d@(0&kOyVtFz+2B^&>b({JUOmH!wuD{AJnThmIhf8Q}|^DxtUD55>$_HS88A1%xb#u&6X z)54@2hYKC-$i$h`%J9DZl<{q(uiN51m6 z$;r_oTzwz+9((P!>~Xgvv%g0-f6}=_=Ro;YiQW9g(5pjV#uwcEarb!A-#Ay4;%t-4 z-gPm3>=1j#!|-;jWWU&X@a4gejeXL+4gdb5L@s`?7<^#S_`6Eu@eH_k5qIcRv*;|1NP;--rGWP3$7<&;4tf=(f??i@f(jnHMTm*;S=}!-);Q&|E7UqP}Zwn_ZIaoNw)ltRG2( zlI(n}-}Tv;7BRwg4{W@w@dC}&T4%HdI@^%$<9^rQ^gZ{xuBvB^%o>F)$F#iXo|)d# zvlZ(3DtbR7(~Es}pOMW@-_5leY9@r8Lmybr~fm-wPsA^brWt(s6BAqz<$=Ny^F3A3@FVmU(7qWiH zCdFPMV*;xfHugV=@yw9^@Y!!tEUM1)y{`2#*%z?k7Q#miKF-eTx}F0o zcRI!L<<{I^(^TG6`Lw>PA2^>YaQ^(MVi2_siMz4$6?o1s=9;VvSzaL?Ec0xpNj{cr zY8|ZgtBN}+#(3ZM{$KsU>T1M8{4a5R$;P30ni01~*jUWoS9{wSCh_*c0sotZhZ@HF zzw2JF{a|ec=K4+C=hs@ZG-t_vHvSgz!Pka-M(oXA@-)?QpD*sped@9<4Ti^f59io} o>=i~1yfm<3xX*tKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z000WjNkl>39W1HC6m>9C8%0G40K$c1?5$%Ch6!oxDPJvTUPL)>gX+=&>PLXn`qG&mh9##lwwNfanMin@iAvV~KnLYT; zW|qv@GjC?>dE?(#`pF7`ncuwMXWsk0H$T6T6h#54brql{AOJ`N0I5~gcKip@oaBe= z3IhmfKHHcDnFW}s7pnj`Vpd`HhFKXvN%QGxDKm;a00dMJK)c2w%&bV#z!9qPdqrl4 z8msuK2M|ON08s!Z*k`DL=ZyeJuz!~U6aXBs&msZfZnqv|7G-y9vlRl+$*jU4$TKSu z0M4jGV<8Xw83Yh#RtE4|V*~)l>?E!+(G&vE#cW?=M+89qz$ci+d@|EgA=T z?@A4P9R8G=zjSCoAOKhx&00@r z7638U0133V!T?U8x`35qd4lf&ILWf(Fi6_`ryam9fLDG6AjE=ylHzUH8~lp3(<`=? z;2Qv=~V#K zY@fz_cZY+NlhbLZ0Ekky-_XP`#oF8x0H`Z`G|zAB6j5C;YB~V4!q*(d;lQ$bz=7b? z+J5t7yZ!9|5OZT%LgJcs#~KZQTFgO7pEr`iB=6Ll7l0(Fn8Qm-@U9Q=0C2+T#R!rk zO7hIa0-PtJuHU;ufvW%{P_5o2c~hOzoRn}20QE~761B5uB>_lCb5g(!0Q~%=4L>Pv zB|#5Zy!%Ol%nHo*0s#wD#i(6{QOs;_Z3O_5cte3B0CW%lVgew|NgYlBKoV270SFTS zVgn$}Nntwx#Nh31SxB`Ns+YW*0e~d_jDQOObt^WK*osPXQiKNpuWZFevZr9J8@Uz$ zROIO&8OE}WhniYin_L?QfDck1j0dHl?(*^G-e&rsd?0`OuWujEKb_yw{@=>2mC?b| zgR{r~W_@RU;nG)^(mXz8Zf1rqrY;U7+mmN{J9>c^LqB&*?FLqSBlc zRA!WSwxN-Zzc7Mr799g{&g{{ruTGzx{N3c3nTyf8xTV#lg^5QKt4;&3Hn}!l3q&hE ze)r`%Lu9KaL+i`N$ihWm!^IdM__-Tk+nfMELS^x4^u zW**}*uH0G~70{oE*(5M*27r}YE2H6H_-wtzW$MY)Qf4C~8zn;TcfEf@dz|x~=ec`< zm0K&LweGa+LH6->etWf6F0puhap20iD?{fx&s{S*)`zD)90RZ2SF`bI^maPOZx(l?SYYV7r$^#z^`{?b>M(sEJO z{ktpYt_+Ffk5O#(0I2)$=g#l%=$@>iROG2AQ%gJnoOm>``eXJ-?m2fYpX|)#)%o{v zCEJr{MDoWdwgC%^L;q7xv`2UB&mHEL^~QU%ntC#|#M=wh^2tt;^+Wat-EK7$40Vd+ zk5O#705H;aetXr<#bq`!vfT!9+9$(XDG*8s=uexOVAp*BWYpah$_3epfTd2Pu37y% zw|rt_^>0M?$0)V|9so$f$`k#z2yc_7gHB?16C*(wnXyBD7IVxeDnP`x&Q>FVB+o{?s64}E?!?8Fe-L1qc8sX z#j=r4R!X>z>%I7ULq=V^Nd8y>pzizXG8-8=dysvs_kTRaoh!FiM#l%oAJ`fjH!`wO zvBco%!P(5s%n(nHWK`7g?5AhTBKcz!TkeuDqhv&zl+>yTeEP?y*LtEoXOGte8p%wh zQN7YKr)uy@mC{yZK61?r*k1AnIwfIx0E7Yj+6<99f7$sv&!gK~${u7N>mAcE ze}BwLFtvbo|E>Gag8HKyQzHNltz2O2udy5JJL?NPq{~HlIsH6+!^tmUPCS}ejm$@` z@%p6aupqEMx-o6D3xFyXz_gm&)k<2{ch(nxY7wZNB2ue9HT&DaP4>q! z0A+CO4|MhZRdsrphDW6F2>@nW(4Vpq07gSV1r2z0IjLbP=b2hT zuN4450Ei7hyHZL zUMe$6&dDAC0Av~pgz5TCKVh{3z!5tzeRt5iQUJ)xjB?}#0BSF=NA2uc?I|;grTPk< zuZQPQT_7TPOC=T?xDCJo&xuH`D+i88_yHRylc~);BboQ6NDz+gx(^6{=6Bx?Ma+D|P#>1RpL3XO}^cf{7PVk!mJHeOEsyG!C5H@za0}n{IoNofFDd|F7p$&n zCjoS#b>3H`pjup;Lz5q(d0~;}fLWdm34Wg`sCE0ED5>+(DxHk#7f}<;Vm=FeUK4oF zyp_dk%d|&$TW}iJnCN%BYMy%?k5|{}kJuQw2cSb^Awhy(X1$qeo|Om>YScyyvtc0y zAPVoj<5=B|E6+@b;uw*h)Rpjdu_VGEIKe(cO}x_!EQu|^W%b_y0H3^`1Jca13;+NC07*qoM6N<$f-%Na+W-In diff --git a/src/qt/qcc/main.cpp b/src/qt/qcc/main.cpp deleted file mode 100644 index b6c098da..00000000 --- a/src/qt/qcc/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include -#include "mainwindow.h" - -/*! - \defgroup client QCC client module - - The QCC-client can connect to a \ref server "QCC-server" to send and receive instant - messages from other QCC-clients and also see their online status. - */ - -//! The main entry point of this application. -/*! - \param argc The command-line argument count. - \param argv The command-line argument-array. - \return The return code of the application - \ingroup client - */ -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - MainWindow mainWindow; - mainWindow.show(); - - return app.exec(); -} diff --git a/src/qt/qcc/mainwindow.cpp b/src/qt/qcc/mainwindow.cpp deleted file mode 100644 index d71f0d17..00000000 --- a/src/qt/qcc/mainwindow.cpp +++ /dev/null @@ -1,403 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "qccpacket.h" -#include "contact.h" -#include "contactlistmodel.h" -#include "messagewindow.h" -#include "registerdialog.h" - -#include -#include -#include -#include - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), ui(new Ui::MainWindow), m_contacts(new ContactListModel(this)), - m_messageWindow(new MessageWindow(&m_socket)), m_packetSize(0) -{ - ui->setupUi(this); - - connect(&m_socket, SIGNAL(connected()), SLOT(socket_connected())); - connect(&m_socket, SIGNAL(disconnected()), SLOT(socket_disconnected())); - connect(&m_socket, SIGNAL(readyRead()), SLOT(socket_readyRead())); - connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socket_error(QAbstractSocket::SocketError))); -#ifdef DEBUG - connect(&m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socket_stateChanged(QAbstractSocket::SocketState))); -#endif - - ui->contactListView->setModel(m_contacts); - - QCA::init(); - if (!QCA::isSupported("sha256") || !QCA::isSupported("pkey") || !QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA)) { - QMessageBox::critical(this, "QCA error", "QCA OpenSSL-Plugin not found!\n\nThe application will now quit."); - QTimer::singleShot(100, qApp, SLOT(quit())); - } -} - -MainWindow::~MainWindow() -{ - delete m_messageWindow; - delete m_contacts; - delete ui; -} - -void MainWindow::connectToHost() -{ - if (m_socket.state() > 0) - return; - - QStringList server = ui->serverLineEdit->text().split(':'); - QString host = server.at(0); - quint16 port = server.length() < 2 ? MainWindow::DEFAULT_PORT : server.at(1).toUShort(); - //qDebug("server = %s:%d", qPrintable(host), port); - - m_packetSize = 0; - m_socket.connectToHost(host, port); - ui->loginButton->setEnabled(false); - ui->registerButton->setEnabled(false); -} - -void MainWindow::socket_connected() -{ -#ifdef DEBUG - qDebug("MainWindow::socket_connected()"); -#endif -} - -void MainWindow::socket_disconnected() -{ -#ifdef DEBUG - qDebug("MainWindow::socket_disconnected()"); -#endif - - if (isHidden()) // hack, true when window is closing - return; - - ui->stackedWidget->setCurrentIndex(0); - setWindowTitle("QCC"); - m_messageWindow->closeAllTabs(); - m_messageWindow->close(); - ui->loginButton->setEnabled(true); - ui->registerButton->setEnabled(true); -} - -void MainWindow::socket_readyRead() -{ -#ifdef DEBUG - qDebug("MainWindow::socket_readyRead(): %li bytes available", (long)m_socket.bytesAvailable()); -#endif - - QDataStream in(&m_socket); - in.setVersion(QDataStream::Qt_4_0); - if (m_packetSize == 0) { - if (m_socket.bytesAvailable() < (int)sizeof(quint32)) // packet size - return; - in >> m_packetSize; - } - if (m_socket.bytesAvailable() < m_packetSize) - return; - m_packetSize = 0; // reset packet size - - qint32 type; - in >> type; - -#ifdef DEBUG - qDebug("PacketType = %i (%s)", type, qPrintable(QccPacket::typeString((QccPacket::PacketType)type))); -#endif - - switch ((QccPacket::PacketType)type) { - case QccPacket::ConnectionAccepted: - { - m_privateKey = QCA::KeyGenerator().createRSA(1024); - if (m_privateKey.isNull() || !m_privateKey.canDecrypt()) { - qWarning("Failed to generate private key"); - break; - } - QccPacket packet(m_register ? QccPacket::UserRegister : QccPacket::UserAuthentication); - packet.stream() << ui->usernameLineEdit->text() - << QCA::Hash("sha256").hashToString(ui->passwordLineEdit->text().toUtf8()) - << m_privateKey.toPublicKey().toDER(); - packet.send(&m_socket); - break; - } - case QccPacket::ConnectionRefused: - QMessageBox::critical(this, "Connection Refused", "Access denied!"); - break; - case QccPacket::RegisterSuccess: - QMessageBox::information(this, "Register Success", "Your registration has been successful.\n" - "You will now be logged in..."); - ui->stackedWidget->setCurrentIndex(1); - setWindowTitle("QCC - " + ui->usernameLineEdit->text()); - break; - case QccPacket::RegisterFailure: - { - QString reason; - in >> reason; - m_socket.disconnectFromHost(); - QMessageBox::warning(this, "Register Failure", reason); - break; - } - case QccPacket::AuthenticationSuccess: - QccPacket(QccPacket::RequestContactList).send(&m_socket); - ui->stackedWidget->setCurrentIndex(1); - setWindowTitle("QCC - " + ui->usernameLineEdit->text()); - break; - case QccPacket::AuthenticationFailure: - { - QString reason; - in >> reason; - m_socket.disconnectFromHost(); - QMessageBox::warning(this, "Authentication Failure", reason); - break; - } - case QccPacket::RequestAuthorization: - { - QString username; - in >> username; - - int question = QMessageBox::question(this, "Request Authorization", "The user \"" + username + - "\" would like to add you to her/his contact list.\n" - "Do you accept the authorization request?", - "Accept", "Decline"); - - QccPacket packet(question == 0 ? QccPacket::AuthorizationAccepted : QccPacket::AuthorizationDeclined); - packet.stream() << username; - packet.send(&m_socket); - break; - } - case QccPacket::AuthorizationAccepted: - { - QString username; - qint32 status; - QByteArray publicKey; - in >> username >> status >> publicKey; - Contact *contact = m_contacts->contact(username); - if (!contact) { - contact = new Contact(username); - m_contacts->add(contact); - } - contact->setPublicKey(publicKey); - contact->setStatus((Contact::Status)status); - break; - } - case QccPacket::AuthorizationDeclined: - { - QString username; - in >> username; - QMessageBox::information(this, "Authorization Declined", "The user \"" + username + "\" has declined your authorization request."); - break; - } - case QccPacket::AuthorizationFailure: - { - QString reason; - in >> reason; - QMessageBox::warning(this, "Authorization Failure", reason); - break; - } - case QccPacket::ContactList: - { - qint32 contactCount; - in >> contactCount; - m_contacts->clear(); - QList contacts; - for (int i = 0; i < contactCount; i++) { - QString username; - qint32 status; - QByteArray publicKey; - in >> username >> status >> publicKey; - Contact *contact = new Contact(username); - contact->setPublicKey(publicKey); - contact->setStatus((Contact::Status)status); - contacts.append(contact); - } - m_contacts->add(contacts); - break; - } - case QccPacket::ContactStatusChanged: - { - QString username; - qint32 status; - QByteArray publicKey; - in >> username >> status >> publicKey; - Contact *contact = m_contacts->contact(username); - if (contact) { - contact->setPublicKey(publicKey); - contact->setStatus((Contact::Status)status); - } - break; - } - case QccPacket::ContactRemoved: - { - QString username; - in >> username; - Contact *contact = m_contacts->contact(username); - if (contact) { - m_messageWindow->closeTab(contact); - m_contacts->remove(contact); - } - break; - } - case QccPacket::Message: - { - qint32 id; - QString username; - QByteArray encryptedMessage; - in >> id >> username >> encryptedMessage; - - Contact *contact = m_contacts->contact(username); - if (!contact) // received message from unknown user (not on contact list) - break; - - const int keySize = m_privateKey.bitSize() / 8; - QCA::SecureArray message; - for (int i = 0; i < encryptedMessage.length() / keySize; i++) { - QCA::SecureArray messageBlock; - if (!m_privateKey.decrypt(encryptedMessage.mid(i * keySize, keySize), &messageBlock, QCA::EME_PKCS1_OAEP)) { - qWarning("Error decrypting"); - return; - } - message.append(messageBlock); - } - m_messageWindow->appendMessage(contact, QString(message.toByteArray())); - - QccPacket packet(QccPacket::MessageSuccess); - packet.stream() << id << username; - packet.send(&m_socket); - - break; - } - case QccPacket::MessageSuccess: - { - qint32 id; - QString username; - in >> id >> username; - qDebug() << "MessageSuccess: " << id << " => " << username; - break; - } - case QccPacket::MessageFailure: - { - qint32 id; - QString username, reason; - in >> id >> username >> reason; - QMessageBox::warning(this, "Message Failure", reason); - break; - } - default: - qWarning("MainWindow::socket_readyRead(): Illegal PacketType %i", type); - return; - } -} - -void MainWindow::socket_error(QAbstractSocket::SocketError error) -{ -#ifdef DEBUG - qDebug("MainWindow::socket_error(%i) => %s", error, qPrintable(m_socket.errorString())); -#endif - - QMessageBox::critical(this, "Connection Error", m_socket.errorString()); - - ui->loginButton->setEnabled(true); - ui->registerButton->setEnabled(true); -} - -#ifdef DEBUG -void MainWindow::socket_stateChanged(QAbstractSocket::SocketState state) -{ - qDebug("MainWindow::socket_stateChanged(%i)", state); -} -#endif - -void MainWindow::on_loginButton_clicked() -{ - m_register = false; - connectToHost(); -} - -void MainWindow::on_registerButton_clicked() -{ - RegisterDialog dialog(this); - dialog.exec(); - if (dialog.result()) { - ui->usernameLineEdit->setText(dialog.username()); - ui->passwordLineEdit->setText(dialog.password()); - m_register = true; - connectToHost(); - } -} - -void MainWindow::on_contactListView_activated(const QModelIndex &index) -{ - Contact *contact = m_contacts->contact(index); - if (!contact) - return; - - m_messageWindow->addTab(contact); -} - -void MainWindow::on_contactListView_customContextMenuRequested(const QPoint &pos) -{ - Contact *contact = m_contacts->contact(ui->contactListView->currentIndex()); - if (!contact) - return; - - QMenu menu(ui->contactListView); - menu.addAction("Remove contact \"" + contact->username() + "\"", this, SLOT(removeCurrentContact(bool))); - menu.exec(ui->contactListView->mapToGlobal(pos)); -} - -void MainWindow::on_addContactButton_clicked() -{ - QString username = ui->contactLineEdit->text(); - if (username.isEmpty()) - return; - - QccPacket packet(QccPacket::RequestAuthorization); - packet.stream() << username; - packet.send(&m_socket); - - ui->contactLineEdit->clear(); -} - -void MainWindow::removeCurrentContact(bool) -{ - Contact *contact = m_contacts->contact(ui->contactListView->currentIndex()); - if (!contact || !contact->isValid()) - return; - - int question = QMessageBox::question(this, "Remove contact", "Do you really want to remove the contact \"" + - contact->username() + "\" from your contact list?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - - if (question == QMessageBox::Yes) { - QccPacket packet(QccPacket::RemoveContact); - packet.stream() << contact->username(); - packet.send(&m_socket); - } -} - -void MainWindow::closeEvent(QCloseEvent *) -{ - qApp->quit(); -} diff --git a/src/qt/qcc/mainwindow.h b/src/qt/qcc/mainwindow.h deleted file mode 100644 index 68374593..00000000 --- a/src/qt/qcc/mainwindow.h +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include -#include - -class ContactListModel; -class MessageWindow; - -//! The UI namespace. -namespace Ui { - class MainWindow; -} - -//! The MainWindow class defines the main window of this application. -/*! - \ingroup client - */ -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - - //! Constructs the MainWindow. - /*! - \param parent The parent object. - */ - explicit MainWindow(QWidget *parent = 0); - - //! Destroys the MainWindow. - ~MainWindow(); - -private Q_SLOTS: - - //! Connects the client to a QCC-server. - /*! - \sa \ref server "QCC server module" - */ - void connectToHost(); - - //! The client is connected to the server. - /*! - \sa connectToHost() - */ - void socket_connected(); - - //! Closes all open message windows and returns to the login screen. - void socket_disconnected(); - - //! Handles all incoming data packets from the server. - void socket_readyRead(); - - //! Handles all socket error messages. - /*! - \param error The socket error. - */ - void socket_error(QAbstractSocket::SocketError error); - -#ifdef DEBUG - //! Prints the sockets state to the debug output (in debug mode only). - /*! - \param state The socket state. - */ - void socket_stateChanged(QAbstractSocket::SocketState state); -#endif - - //! Removes the current contact from the contact list on the remote server. - void removeCurrentContact(bool); - - //! Establishes a connection to the QCC-server and sends a user authentication request. - /*! - \sa connectToHost(), QccPacket::UserAuthentication - */ - void on_loginButton_clicked(); - - //! Establishes a connection to the QCC-server and sends a user register request. - /*! - \sa connectToHost(), QccPacket::UserRegister - */ - void on_registerButton_clicked(); - - //! Opens the activated contact's tab of the message window. - /*! - \sa MessageWindow - */ - void on_contactListView_activated(const QModelIndex &index); - - //! Shows the context menu to remove the selected contact. - /*! - \param pos The position of the context menu. - \sa QccPacket::RemoveContact - */ - void on_contactListView_customContextMenuRequested(const QPoint &pos); - - //! Sends a authorization request to the QCC-server. - /*! - \sa QccPacket::RequestAuthorization - */ - void on_addContactButton_clicked(); - -private: - - //! The default network port, which will be used if no port is provided by the user. - static const quint16 DEFAULT_PORT = 54321; - - Ui::MainWindow *ui; //!< Pointer to the UI: - ContactListModel *m_contacts; //!< The contact list model. - MessageWindow *m_messageWindow; //!< The message window. - QTcpSocket m_socket; //!< The TCP-socket for the connection with the QCC-server. - quint32 m_packetSize; //!< The packet size of the current network packet from the server. - bool m_register; //!< Whether or not the user wants to register a new user or just log in. - - QCA::PrivateKey m_privateKey; //!< The RSA private key used for the message encryption. - - //! Exits the application. - void closeEvent(QCloseEvent *); -}; - -#endif // MAINWINDOW_H diff --git a/src/qt/qcc/mainwindow.ui b/src/qt/qcc/mainwindow.ui deleted file mode 100644 index 2e474be5..00000000 --- a/src/qt/qcc/mainwindow.ui +++ /dev/null @@ -1,244 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 174 - 318 - - - - QCC - Qt CryptoChat - - - - - 0 - - - 0 - - - - - 0 - - - - - - - Server - - - - - - - 127.0.0.1 - - - - - - - Username - - - - - - - - - - - - - - Password - - - - - - - - - - QLineEdit::Password - - - - - - - Login - - - true - - - true - - - - - - - Register - - - - - - - - - Qt::Vertical - - - - 20 - 99999 - - - - - - - - :/icons/qcc128a.png - - - Qt::AlignBottom|Qt::AlignHCenter - - - - - - - - - - - 0 - - - 0 - - - - - Qt::CustomContextMenu - - - Qt::ScrollBarAlwaysOff - - - false - - - - 16 - 16 - - - - - - - - 0 - - - - - - - - - - - - Add Contact - - - - - - - - - - - - - - - serverLineEdit - usernameLineEdit - passwordLineEdit - loginButton - registerButton - contactListView - contactLineEdit - addContactButton - - - - - - - usernameLineEdit - returnPressed() - loginButton - click() - - - 86 - 82 - - - 46 - 155 - - - - - passwordLineEdit - returnPressed() - loginButton - click() - - - 86 - 127 - - - 46 - 155 - - - - - contactLineEdit - returnPressed() - addContactButton - click() - - - 49 - 14 - - - 49 - 14 - - - - - diff --git a/src/qt/qcc/messagepage.cpp b/src/qt/qcc/messagepage.cpp deleted file mode 100644 index d6f3b889..00000000 --- a/src/qt/qcc/messagepage.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "messagepage.h" -#include "ui_messagepage.h" -#include "qccpacket.h" -#include "contact.h" - -#include - -MessagePage::MessagePage(QTcpSocket *socket, Contact *contact, QWidget *parent) : - QWidget(parent), ui(new Ui::MessagePage), m_socket(socket), m_contact(contact) -{ - Q_ASSERT(m_contact); // should never happen, just in case... - - ui->setupUi(this); - connect(m_contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); - connect(ui->closeButton, SIGNAL(clicked()), SIGNAL(closeButtonClicked())); - ui->messageTextEdit->installEventFilter(this); -} - -MessagePage::~MessagePage() -{ - delete ui; -} - -void MessagePage::appendMessage(const QString &message, const QColor &color) -{ - QString messageHtml = message; - messageHtml.replace('\n', "
"); - ui->messagesTextEdit->append("" + - m_contact->username() + ": " + messageHtml); -} - -void MessagePage::contact_statusChanged() -{ - ui->messagesTextEdit->append(QString("%1 is now %2."). - arg(m_contact->username()). - arg(m_contact->statusString())); -} - -void MessagePage::on_sendButton_clicked() -{ - QString text = ui->messageTextEdit->toPlainText().trimmed(); - if (text.isEmpty() || !m_contact->isOnline()) - return; - - QccPacket message; - message.stream() << qint32(qrand()) << m_contact->username() << m_contact->encrypt(text); - message.send(m_socket); - - text.replace('\n', "
"); - ui->messagesTextEdit->append("You: " + text); - - ui->messageTextEdit->clear(); - ui->messageTextEdit->setFocus(); -} - -void MessagePage::setFocusOnInput() -{ - ui->messageTextEdit->setFocus(); -} - -bool MessagePage::eventFilter(QObject *obj, QEvent *event) -{ - if (obj == ui->messageTextEdit) { - if (event->type() == QEvent::KeyPress) { - QKeyEvent *keyEvent = static_cast(event); - if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) - && keyEvent->modifiers() == Qt::NoModifier) { - on_sendButton_clicked(); - return true; - } else - return false; - } else - return false; - } else - return QWidget::eventFilter(obj, event); -} diff --git a/src/qt/qcc/messagepage.h b/src/qt/qcc/messagepage.h deleted file mode 100644 index efd761d3..00000000 --- a/src/qt/qcc/messagepage.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef MESSAGEPAGE_H -#define MESSAGEPAGE_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QTcpSocket; -QT_BEGIN_NAMESPACE - -//! The UI namespace. -namespace Ui { - class MessagePage; -} - -class Contact; - -//! The MessagePage class defines one tab of the MessageWindow. -/*! - \ingroup client - */ -class MessagePage : public QWidget -{ - Q_OBJECT - -public: - - //! Constructs a MessagePage. - /*! - \param socket The TCP-socket to the server. - \param contact The contact associated with this page. - \param parent The parent object. - */ - MessagePage(QTcpSocket *socket, Contact *contact, QWidget *parent = 0); - - //! Destroys the MessagePage. - ~MessagePage(); - - //! Returns the contact of this page. - /*! - \return The contact of this page. - */ - inline Contact* contact() { return m_contact; } - - //! Appends a \a message to this page. - /*! - \param message The message to append. - \param color The color for the \a message. - \sa MessageWindow::appendMessage() - */ - void appendMessage(const QString &message, const QColor &color = Qt::black); - -Q_SIGNALS: - - //! This signal is emitted whenever the close button of this page is clicked. - void closeButtonClicked(); - -public Q_SLOTS: - - //! Sets the focus on the input field of this page. - void setFocusOnInput(); - -private Q_SLOTS: - - //! Sends the \a message from the input field to the server. - void on_sendButton_clicked(); - - //! Prints a status changed text to the chat field. - void contact_statusChanged(); - -private: - - Ui::MessagePage *ui; //!< Pointer to the UI. - QTcpSocket *m_socket; //!< The TCP-socket to the server. - Contact *m_contact; //!< Pointer to the contact of this page. - - //! Filters key events for the input edit to send messages via the \c Return and \c Enter key. - /*! - \param obj The object to be filtered. - \param event The event that occured. - \return \c True to forward this event; otherwise returns \c false. - \sa QObject::eventFilter() - */ - bool eventFilter(QObject *obj, QEvent *event); -}; - -#endif // MESSAGEPAGE_H diff --git a/src/qt/qcc/messagepage.ui b/src/qt/qcc/messagepage.ui deleted file mode 100644 index f954fc44..00000000 --- a/src/qt/qcc/messagepage.ui +++ /dev/null @@ -1,104 +0,0 @@ - - - MessagePage - - - - 0 - 0 - 400 - 300 - - - - Message - - - - 2 - - - 0 - - - - - Qt::Vertical - - - false - - - - Qt::ScrollBarAlwaysOff - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> - - - - - - 0 - 1 - - - - Qt::ScrollBarAlwaysOff - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> - - - - - - - - 2 - - - - - Close - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Send - - - - - - - - - - diff --git a/src/qt/qcc/messagewindow.cpp b/src/qt/qcc/messagewindow.cpp deleted file mode 100644 index d6f8b658..00000000 --- a/src/qt/qcc/messagewindow.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "messagewindow.h" -#include "ui_messagewindow.h" -#include "contact.h" -#include "messagepage.h" - -MessageWindow::MessageWindow(QTcpSocket *socket, QWidget *parent) : - QTabWidget(parent), ui(new Ui::MessageWindow), m_socket(socket) -{ - ui->setupUi(this); - connect(this, SIGNAL(tabCloseRequested(int)), SLOT(tabCloseRequested(int))); -} - -MessageWindow::~MessageWindow() -{ - qDeleteAll(m_pages.values()); - delete ui; -} - -bool MessageWindow::addTab(Contact *contact) -{ - if (!contact) - return false; - - bool tabAdded = false; - MessagePage *page = NULL; - - if (m_pages.contains(contact)) { - page = m_pages.value(contact); - setCurrentWidget(page); - } else { - page = new MessagePage(m_socket, contact); - connect(contact, SIGNAL(statusChanged()), SLOT(contact_statusChanged())); - connect(page, SIGNAL(closeButtonClicked()), SLOT(page_closeButtonClicked())); - int index = QTabWidget::addTab(page, contact->statusIcon(), contact->username()); - m_pages.insert(contact, page); - setCurrentIndex(index); - tabAdded = true; - } - - show(); - raise(); - activateWindow(); - if (page != NULL) - page->setFocusOnInput(); - - return tabAdded; -} - -void MessageWindow::closeTab(Contact *contact) -{ - if (!m_pages.contains(contact)) - return; - - // find tab and close it - for (int i = 0; i < count(); i++) { - if (tabText(i) == contact->username()) { - tabCloseRequested(i); - return; - } - } -} - -void MessageWindow::closeAllTabs() -{ - clear(); - qDeleteAll(m_pages.values()); - m_pages.clear(); -} - -void MessageWindow::appendMessage(Contact *contact, const QString &message) -{ - if (!contact) - return; - - addTab(contact); - m_pages.value(contact)->appendMessage(message, Qt::red); -} - -void MessageWindow::contact_statusChanged() -{ - Contact *contact = qobject_cast(sender()); - if (!contact) { - qWarning("MessageWindow::contact_statusChanged(): Cast of sender() to Contact* failed"); - return; - } - - // find tab and update the icon - for (int i = 0; i < count(); i++) { - if (tabText(i) == contact->username()) { - setTabIcon(i, contact->statusIcon()); - return; - } - } -} - -void MessageWindow::tabCloseRequested(int index) -{ - MessagePage *page = qobject_cast(widget(index)); - if (!page) { - qWarning("MessageWindow::tabCloseRequested(int): Cast of sender() to MessagePage* failed"); - return; - } - - m_pages.remove(page->contact()); - removeTab(index); - disconnect(page->contact(), SIGNAL(statusChanged()), this, SLOT(contact_statusChanged())); - delete page; - -#ifdef DEBUG - qDebug("tab closed %i", index); -#endif - - if (count() == 0) { -#ifdef DEBUG - qDebug("last tab closed => closing MessageWindow"); -#endif - close(); - } -} - -void MessageWindow::page_closeButtonClicked() -{ - emit tabCloseRequested(currentIndex()); -} diff --git a/src/qt/qcc/messagewindow.h b/src/qt/qcc/messagewindow.h deleted file mode 100644 index 48101c82..00000000 --- a/src/qt/qcc/messagewindow.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef MESSAGEWINDOW_H -#define MESSAGEWINDOW_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QTcpSocket; -QT_BEGIN_NAMESPACE - -class Contact; -class MessagePage; - -//! The UI namespace. -namespace Ui { - class MessageWindow; -} - -//! The MessageWindow class defines the tabbed message window. -/*! - \ingroup client - */ -class MessageWindow : public QTabWidget -{ - Q_OBJECT - -public: - - //! Constructs a MessageWindow. - /*! - \param socket The TCP-socket to the server. - \param parent The parent object. - */ - explicit MessageWindow(QTcpSocket *socket, QWidget *parent = 0); - - //! Destroys the MessageWindow. - ~MessageWindow(); - - //! Adds a tab to the window. - /*! - \param contact The contact for the tab. - \return \c True if a new tab has been added; otherwise returns \c false. - \note If a tab for the contact already exists, the existing tab gets the focus. - \sa closeTab(), appendMessage() - */ - bool addTab(Contact *contact); - - //! Closes the tab for the \a contact (if any). - /*! - \param contact The contact of the tab that will be closed. - \sa addTab(), closeAllTabs() - */ - void closeTab(Contact *contact); - - //! Closes all tabs. - /*! - \sa closeTab() - */ - void closeAllTabs(); - - //! Appends a \a message to the tab of the given \a contact. - /*! - \param contact The sender of the message. - \param message The message to append. - \note If there is no tab for the \a contact, one will be created. - \sa addTab() - */ - void appendMessage(Contact *contact, const QString &message); - -private Q_SLOTS: - - //! This slot should be called from a \a contact whenever the status changes. - void contact_statusChanged(); - - //! Removes the tab with the given \a index. - /*! - \param index The index of the tab to remove. - */ - void tabCloseRequested(int index); - - //! Closes the current tab. - /*! - \sa QTabWidget::currentIndex() - */ - void page_closeButtonClicked(); - -private: - - Ui::MessageWindow *ui; //!< Pointer to the UI. - QTcpSocket *m_socket; //!< The TCP-socket to the server. - QHash m_pages; //!< A set of the contacts for all open tabs. -}; - -#endif // MESSAGEWINDOW_H diff --git a/src/qt/qcc/messagewindow.ui b/src/qt/qcc/messagewindow.ui deleted file mode 100644 index 73af770e..00000000 --- a/src/qt/qcc/messagewindow.ui +++ /dev/null @@ -1,28 +0,0 @@ - - - MessageWindow - - - - 0 - 0 - 400 - 300 - - - - QCC - Messages - - - -1 - - - true - - - true - - - - - diff --git a/src/qt/qcc/qcc.pro b/src/qt/qcc/qcc.pro deleted file mode 100644 index 1fefe73c..00000000 --- a/src/qt/qcc/qcc.pro +++ /dev/null @@ -1,50 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2011-01-23T16:10:20 -# -#------------------------------------------------- - -QT = core gui network - -TARGET = qcc -TEMPLATE = app -CONFIG += link_prl crypto - -QCC_CORE_PREFIX = ../qcc-core - -CONFIG(debug, debug|release) { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug -} else { - DEFINES += RELEASE - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release -} - -INCLUDEPATH += ../qcc-core -LIBS += -L$$QCC_CORE_PREFIX -lqcc-core - -HEADERS += mainwindow.h \ - registerdialog.h \ - messagewindow.h \ - messagepage.h \ - contact.h \ - contactlistmodel.h - -SOURCES += main.cpp \ - mainwindow.cpp \ - registerdialog.cpp \ - messagewindow.cpp \ - messagepage.cpp \ - contact.cpp \ - contactlistmodel.cpp - -FORMS += mainwindow.ui \ - registerdialog.ui \ - messagewindow.ui \ - messagepage.ui - -RESOURCES += icons.qrc - -win32:RC_FILE = qcc.rc - -OTHER_FILES += qcc.rc diff --git a/src/qt/qcc/qcc.rc b/src/qt/qcc/qcc.rc deleted file mode 100644 index ad53ecd2..00000000 --- a/src/qt/qcc/qcc.rc +++ /dev/null @@ -1 +0,0 @@ -IDI_ICON1 ICON DISCARDABLE "icons\\qcc.ico" diff --git a/src/qt/qcc/registerdialog.cpp b/src/qt/qcc/registerdialog.cpp deleted file mode 100644 index 1a67d213..00000000 --- a/src/qt/qcc/registerdialog.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#include "registerdialog.h" -#include "ui_registerdialog.h" - -#include - -RegisterDialog::RegisterDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::RegisterDialog) -{ - ui->setupUi(this); -} - -RegisterDialog::~RegisterDialog() -{ - delete ui; -} - -QString RegisterDialog::username() const -{ - return ui->usernameLineEdit->text(); -} - -QString RegisterDialog::password() const -{ - return ui->password1LineEdit->text(); -} - -void RegisterDialog::on_buttonBox_accepted() -{ - QString username = ui->usernameLineEdit->text(); - if (username.isEmpty() || username.length() < 3) { - QMessageBox::warning(this, "Username error", "The username must be at least 3 characters long."); - return; - } - - QString password = ui->password1LineEdit->text(); - if (password.isEmpty() || password.length() < 3) { - QMessageBox::warning(this, "Password error", "The password must be at least 3 characters long."); - return; - } - if (password != ui->password2LineEdit->text()) { - QMessageBox::warning(this, "Password error", "The passwords do not match."); - return; - } - - accept(); -} diff --git a/src/qt/qcc/registerdialog.h b/src/qt/qcc/registerdialog.h deleted file mode 100644 index b2cb92e1..00000000 --- a/src/qt/qcc/registerdialog.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Alexander Vos , -** Kai Wellmann -** -** This file is part of Qt Crypto Chat (QCC). -** -** Qt Crypto Chat is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Qt Crypto Chat is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Qt Crypto Chat. If not, see . -** -****************************************************************************/ - -#ifndef REGISTERDIALOG_H -#define REGISTERDIALOG_H - -#include - -//! The UI namespace. -namespace Ui { - class RegisterDialog; -} - -//! The RegisterDialog class defines the register window. -/*! - \ingroup client - */ -class RegisterDialog : public QDialog -{ - Q_OBJECT - -public: - - //! Constructs a RegisterDialog. - /*! - \param parent The parent object. - */ - explicit RegisterDialog(QWidget *parent = 0); - - //! Destroys the RegisterDialog. - ~RegisterDialog(); - - //! Returns the username. - /*! - \return The username. - */ - QString username() const; - - //! Returns the password. - /*! - \return The password. - */ - QString password() const; - -private Q_SLOTS: - - //! Checks if the username and password is valid and closes the window. - void on_buttonBox_accepted(); - -private: - - Ui::RegisterDialog *ui; //!< Pointer to the UI. -}; - -#endif // REGISTERDIALOG_H diff --git a/src/qt/qcc/registerdialog.ui b/src/qt/qcc/registerdialog.ui deleted file mode 100644 index a0c6016c..00000000 --- a/src/qt/qcc/registerdialog.ui +++ /dev/null @@ -1,121 +0,0 @@ - - - RegisterDialog - - - Qt::ApplicationModal - - - - 0 - 0 - 228 - 200 - - - - QCC - Register - - - true - - - - QLayout::SetFixedSize - - - - - Username - - - - - - - - - - - - - - Password - - - - - - - - - - QLineEdit::Password - - - - - - - Password (repeat) - - - - - - - - - - QLineEdit::Password - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - rejected() - RegisterDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - From 427a72a9e4ddbf12f7033e03d7b4c91606c21d33 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:30:55 -0400 Subject: [PATCH 0481/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 53 ++------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index 5d3a9baf..c840b732 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -1,4 +1,4 @@ -QT += core gui sql xml network crypto +QT += core gui sql xml network FORMS += \ ../src/qt/forms/aboutdialog.ui \ @@ -24,43 +24,8 @@ FORMS += \ RESOURCES += \ ../src/qt/dash.qrc ../src/qt/qcc/icons.qrc - -win32:RC_FILE = qcc.rc - -OTHER_FILES += qcc.rc -CONFIG += c++17 ordered staticlib create_prl console link_prl crypto -CONFIG -= app_bundle - -QCC_CORE_PREFIX = ../qcc-core - -CONFIG(debug, debug|release) { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug -} else { - DEFINES += RELEASE - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release -} - -INCLUDEPATH += ../qcc-core /usr/include/qca2/QtCrypto - -LIBS += -L$$QCC_CORE_PREFIX -lqcc-core -L/usr/lib/qca2 -lqca - - - -QCC_CORE_PREFIX = ../qcc-core - -CONFIG(debug, debug|release) { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/debug -} else { - DEFINES += DEBUG - win32:QCC_CORE_PREFIX = $$QCC_CORE_PREFIX/release -} - -INCLUDEPATH += ../qcc-core -LIBS += -L$$QCC_CORE_PREFIX -lqcc-core - +CONFIG += c++17 QMAKE_CXXFLAGS += -std=c++17 @@ -68,17 +33,3 @@ SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ ..src/qt/wildrig.exe - -TARGET = qcc-core qcc-server qcc - -TEMPLATE = subdirs lib app - -SUBDIRS = qcc-core \ - qcc-server \ - qcc - -qcc-server.depends = qcc-core -qcc.depends = qcc-core - -OTHER_FILES += README.md \ - COPYING From 396dad58a6ce4a6bc0b6f35db920ac4cc83961e9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:32:51 -0400 Subject: [PATCH 0482/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index b056aeb8..053f1a40 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,6 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "qcc/mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -638,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -1070,10 +1069,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoMainWindow() +void BitcoinGUI::gotoOverviewPage() { mainWindow->setChecked(true); - if (walletFrame) walletFrame->gotoMainWindow(); + if (walletFrame) walletFrame->gotoOverviewPage(); } /*void BitcoinGUI::gotoTradingDialogPage() From 4f3e8c2f6410e7e57ef70e8411f88f7cf6b08367 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:33:25 -0400 Subject: [PATCH 0483/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a2e6b772..a05d0f99 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -236,7 +236,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoOverviewPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 3618ef4ddf86671f5ea1eff3d40fe87825d0197b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:33:49 -0400 Subject: [PATCH 0484/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index a170c85a..5b70105e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoMainWindow() +void WalletFrame::gotoOverviewPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoMainWindow(); + i.value()->gotoOverviewPage(); } /*void WalletFrame::gotoTradingDialogPage() From 66a684183fe2cfe8fac3b0c4df1cd6f97f04591d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:34:05 -0400 Subject: [PATCH 0485/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index a6eb3ece..0a48b233 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoOverviewPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 8c5daa9e1162923949279d7faac64c2c74ee24ea Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:34:40 -0400 Subject: [PATCH 0486/1324] Update walletview.cpp --- src/qt/walletview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7f04f0b0..c2db28b6 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,6 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "qcc/mainwindow.h" #include "ui_interface.h" @@ -242,7 +241,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoMainWindow() +void WalletView::gotoOverviewPage() { setCurrentWidget(mainWindow); } From 426e84561264434285f9755e0b65b1fb55728148 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 10 Jun 2020 23:35:02 -0400 Subject: [PATCH 0487/1324] Update walletview.h --- src/qt/walletview.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 8387d8b7..482d7b7a 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -9,9 +9,6 @@ #include "masternodelist.h" #include "governancelist.h" /* #include "tradingdialogpage.h" */ -#include "qcc/mainwindow.h" - - #include @@ -89,7 +86,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoOverviewPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From d2e98bf295f58bef306d238c6fc9ad99e3d63825 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:52:16 -0400 Subject: [PATCH 0488/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 053f1a40..5ffe73e4 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -143,7 +143,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - mainWindow(0), + chatAction(0), + chatMenuAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -619,9 +620,23 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - // HTH Chat - mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World Chat")); + //chat + + chatAction = new QAction(QIcon(":/icons/" + theme + "/overview"), tr("&Messenger"), this); + chatAction->setStatusTip(tr("Messenger")); + chatAction->setToolTip(chatAction->statusTip()); + chatAction->setCheckable(true); + + #ifdef Q_OS_MAC + chatAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); + #else + chatAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); + #endif + tabGroup->addAction(chatAction); + + chatMenuAction = new QAction(QIcon(":/icons/" + theme + "/overview"), chatAction->text(), this); + chatMenuAction->setStatusTip(chatAction->statusTip()); + chatMenuAction->setToolTip(chatMenuAction->statusTip()); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -636,8 +651,11 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); - // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); + connect(chatAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(chatAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); + + connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -740,7 +758,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(mainWindow); + media->addAction(chatAction); } @@ -756,6 +774,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(receiveCoinsAction); toolbar->addAction(historyAction); /* toolbar->addAction(privatesendAction); */ + toolbar->addAction(chatAction); QSettings settings; @@ -929,6 +948,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); openAction->setEnabled(enabled); + chatAction->setEnabled(enabled); + chatMenuAction->setEnabled(enabled); } @@ -1069,11 +1090,11 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoOverviewPage() +void BitcoinGUI::gotoChatPage() { - mainWindow->setChecked(true); - if (walletFrame) walletFrame->gotoOverviewPage(); -} + chatAction->setChecked(true); + if (walletFrame) walletFrame->gotoChatPage(); +} /*void BitcoinGUI::gotoTradingDialogPage() { From f1f3d8cdbe9de9f1b02f8034bed58612bbfa50d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:53:40 -0400 Subject: [PATCH 0489/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a05d0f99..c2d4ef11 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ -class MainWindow; +class ChatAction; class CWallet; @@ -105,7 +105,8 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* mainWindow; + QAction *chatAction; + QAction *chatMenuAction; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -235,10 +236,12 @@ private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to social media page */ - void gotoOverviewPage(); + /** Switch to chat coins page */ + void gotoChatPage(); + /** Switch to trading page */ /* void gotoTradingDialogPage(); */ + /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 25c0bf70acf9976fac1a9a09128e9ddb0223021e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:54:24 -0400 Subject: [PATCH 0490/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 5b70105e..e56efdcf 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,14 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoOverviewPage() +void WalletFrame::gotoChatPage() { - - QMap::const_iterator i; + QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoOverviewPage(); -} - + i.value()->gotoChatPage(); +} /*void WalletFrame::gotoTradingDialogPage() { From 7a698d56c20cce0f2301fb596dec23158ca359ab Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:55:04 -0400 Subject: [PATCH 0491/1324] Update walletframe.h --- src/qt/walletframe.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 0a48b233..7f6274b6 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,8 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to social media page */ - void gotoOverviewPage(); + /** Switch to Chat page */ + void gotoChatPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From d48a675f375a6b77fce707c49c562a27c61437ef Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:59:45 -0400 Subject: [PATCH 0492/1324] Update walletview.cpp --- src/qt/walletview.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index c2db28b6..d4a3257d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,6 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" +#include "chatdialog.h" #include "ui_interface.h" @@ -73,6 +74,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); + + ChatPage = new ChatDialog(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); @@ -84,12 +87,13 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); + addWidget(ChatPage); /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - mainWindow = new MainWindow(); - addWidget(mainWindow); + chatPagen = new ChatPage(); + addWidget(chatPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -123,6 +127,11 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + + // Pass through messages from ChatPage + connect(ChatPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + + } WalletView::~WalletView() @@ -165,6 +174,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); + ChatPage->setClientModel(clientModel); } @@ -182,6 +192,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) } governanceListPage->setWalletModel(_walletModel); + ChatPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); @@ -241,10 +252,10 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoOverviewPage() +void WalletView::gotoChatPage() { - setCurrentWidget(mainWindow); -} + setCurrentWidget(ChatPage); +} /*void WalletView::gotoTradingDialogPage() { From 3ced4cbb80cdc9574d41fdc55f9232847c744757 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:00:39 -0400 Subject: [PATCH 0493/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 482d7b7a..58420a98 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -25,7 +25,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; /* class TradingDialogPage; */ -class MainWindow; +class ChatDialog; QT_BEGIN_NAMESPACE @@ -77,7 +77,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - MainWindow *mainWindow; + ChatDialog *ChatPage; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -85,8 +85,8 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to social media page */ - void gotoOverviewPage(); + /** Switch to chat page */ + void gotoChatPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From b15e8351e2342c66bdac01f219ffecc6ed686fa7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:01:19 -0400 Subject: [PATCH 0494/1324] Add files via upload --- src/qt/chatdialog.cpp | 952 ++++++++++++++++++++++++++++++++++++++++++ src/qt/chatdialog.h | 106 +++++ src/qt/chatentry.cpp | 558 +++++++++++++++++++++++++ src/qt/chatentry.h | 99 +++++ 4 files changed, 1715 insertions(+) create mode 100644 src/qt/chatdialog.cpp create mode 100644 src/qt/chatdialog.h create mode 100644 src/qt/chatentry.cpp create mode 100644 src/qt/chatentry.h diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp new file mode 100644 index 00000000..d1c770d8 --- /dev/null +++ b/src/qt/chatdialog.cpp @@ -0,0 +1,952 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chatdialog.h" +#include "ui_chatdialog.h" + +#include "addresstablemodel.h" +#include "bitcoinunits.h" +#include "clientmodel.h" +#include "coincontroldialog.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "platformstyle.h" +#include "chatentry.h" +#include "walletmodel.h" + +#include "base58.h" +#include "coincontrol.h" +#include "validation.h" // mempool and minRelayTxFee +#include "ui_interface.h" +#include "txmempool.h" +#include "wallet/wallet.h" + +#include "privatesend.h" + +#include +#include +#include +#include + +ChatDialog::ChatDialog(const PlatformStyle *platformStyle, QWidget *parent) : + QDialog(parent), + ui(new Ui::ChatDialog), + clientModel(0), + model(0), + fNewRecipientAllowed(true), + fFeeMinimized(true), + platformStyle(platformStyle) +{ + ui->setupUi(this); + QString theme = GUIUtil::getThemeName(); + + if (!platformStyle->getImagesOnButtons()) { + ui->addButton->setIcon(QIcon()); + ui->clearButton->setIcon(QIcon()); + ui->sendButton->setIcon(QIcon()); + } else { + ui->addButton->setIcon(QIcon(":/icons/" + theme + "/add")); + ui->clearButton->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->sendButton->setIcon(QIcon(":/icons/" + theme + "/send")); + + + } + + GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); + + addEntry(); + + connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); + connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); + + // Coin Control + connect(ui->pushButtonCoinControl, SIGNAL(clicked()), this, SLOT(coinControlButtonClicked())); + connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); + connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); + + // Dash specific + QSettings settings; + if (!settings.contains("bUseDarkSend")) + settings.setValue("bUseDarkSend", false); + if (!settings.contains("bUseInstantX")) + settings.setValue("bUseInstantX", false); +// + bool fUsePrivateSend = settings.value("bUseDarkSend").toBool(); + bool fUseInstantSend = settings.value("bUseInstantX").toBool(); + if(fLiteMode) { + ui->checkUsePrivateSend->setChecked(false); + ui->checkUsePrivateSend->setVisible(false); + ui->checkUseInstantSend->setVisible(false); + CoinControlDialog::coinControl->fUsePrivateSend = false; + CoinControlDialog::coinControl->fUseInstantSend = false; + } + else{ + ui->checkUsePrivateSend->setChecked(fUsePrivateSend); + ui->checkUseInstantSend->setChecked(fUseInstantSend); + CoinControlDialog::coinControl->fUsePrivateSend = fUsePrivateSend; + CoinControlDialog::coinControl->fUseInstantSend = fUseInstantSend; + } +// + connect(ui->checkUsePrivateSend, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); + connect(ui->checkUseInstantSend, SIGNAL(stateChanged ( int )), this, SLOT(updateInstantSend())); +// +// // Coin Control: clipboard actions + QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); + QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this); + QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this); + QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this); + QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this); + QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this); + QAction *clipboardChangeAction = new QAction(tr("Copy change"), this); + connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity())); + connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount())); + connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardFee())); + connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAfterFee())); + connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardBytes())); + connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardLowOutput())); + connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardChange())); + ui->labelCoinControlQuantity->addAction(clipboardQuantityAction); + ui->labelCoinControlAmount->addAction(clipboardAmountAction); + ui->labelCoinControlFee->addAction(clipboardFeeAction); + ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction); + ui->labelCoinControlBytes->addAction(clipboardBytesAction); + ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction); + ui->labelCoinControlChange->addAction(clipboardChangeAction); + + // init transaction fee section + if (!settings.contains("fFeeSectionMinimized")) + settings.setValue("fFeeSectionMinimized", true); + if (!settings.contains("nFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility + settings.setValue("nFeeRadio", 1); // custom + if (!settings.contains("nFeeRadio")) + settings.setValue("nFeeRadio", 0); // recommended + if (!settings.contains("nCustomFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility + settings.setValue("nCustomFeeRadio", 1); // total at least + if (!settings.contains("nCustomFeeRadio")) + settings.setValue("nCustomFeeRadio", 0); // per kilobyte + if (!settings.contains("nSmartFeeSliderPosition")) + settings.setValue("nSmartFeeSliderPosition", 0); + if (!settings.contains("nTransactionFee")) + settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); + if (!settings.contains("fPayOnlyMinFee")) + settings.setValue("fPayOnlyMinFee", false); + if (!settings.contains("fSendFreeTransactions")) + settings.setValue("fSendFreeTransactions", false); + + ui->groupFee->setId(ui->radioSmartFee, 0); + ui->groupFee->setId(ui->radioCustomFee, 1); + ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); + ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); + ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1); + ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); + ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt()); + ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); + ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); + ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); + minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); +} + +void ChatDialog::setClientModel(ClientModel *clientModel) +{ + this->clientModel = clientModel; + + if (clientModel) { + connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(updateSmartFeeLabel())); + } +} + +void ChatDialog::setModel(WalletModel *model) +{ + this->model = model; + + if(model && model->getOptionsModel()) + { + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + entry->setModel(model); + } + } + + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), + model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); + connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount))); + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + updateDisplayUnit(); + + // Coin Control + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool))); + ui->frameCoinControl->setVisible(model->getOptionsModel()->getCoinControlFeatures()); + coinControlUpdateLabels(); + + // fee section + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel())); + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(updateGlobalFeeVariables())); + connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); + ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000)); + updateFeeSectionControls(); + updateMinFeeLabel(); + updateSmartFeeLabel(); + updateGlobalFeeVariables(); + } +} + +ChatDialog::~ChatDialog() +{ + QSettings settings; + settings.setValue("fFeeSectionMinimized", fFeeMinimized); + settings.setValue("nFeeRadio", ui->groupFee->checkedId()); + settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId()); + settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); + settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); + settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); + settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); + + delete ui; +} + +void ChatDialog::on_sendButton_clicked() +{ + if(!model || !model->getOptionsModel()) + return; + + QList recipients; + bool valid = true; + + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + if(entry->validate()) + { + recipients.append(entry->getValue()); + } + else + { + // valid = false; + } + } + } + + if(!valid || recipients.isEmpty()) + { + return; + } + + QString strFunds = tr("using") + " " + tr("anonymous funds") + ""; + QString strFee = ""; + recipients[0].inputType = ONLY_DENOMINATED; + + if(ui->checkUsePrivateSend->isChecked()) { + recipients[0].inputType = ONLY_DENOMINATED; + strFunds = tr("using") + " " + tr("anonymous funds") + ""; + QString strNearestAmount( + BitcoinUnits::formatWithUnit( + model->getOptionsModel()->getDisplayUnit(), CPrivateSend::GetSmallestDenomination())); + strFee = QString(tr( + "(privatesend requires this amount to be rounded up to the nearest %1)." + ).arg(strNearestAmount)); + } else { + recipients[0].inputType = ALL_COINS; + strFunds = tr("using") + " " + tr("any available funds (not anonymous)") + ""; + } + + if(ui->checkUseInstantSend->isChecked()) { + recipients[0].fUseInstantSend = true; + strFunds += " "; + strFunds += tr("and InstantSend"); + } else { + recipients[0].fUseInstantSend = false; + } + + + fNewRecipientAllowed = false; + // request unlock only if was locked or unlocked for mixing: + // this way we let users unlock by walletpassphrase or by menu + // and make many transactions while unlocking through this dialog + // will call relock + WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); + if(encStatus == model->Locked || encStatus == model->UnlockedForMixingOnly) + { + WalletModel::UnlockContext ctx(model->requestUnlock()); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled + fNewRecipientAllowed = true; + return; + } + send(recipients, strFee, strFunds); + return; + } + // already unlocked or not encrypted at all + send(recipients, strFee, strFunds); +} + +void ChatDialog::send(QList recipients, QString strFee, QString strFunds) +{ + // prepare transaction for getting txFee earlier + WalletModelTransaction currentTransaction(recipients); + WalletModel::SendCoinsReturn prepareStatus; + if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled + prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); + else + prepareStatus = model->prepareTransaction(currentTransaction); + + // process prepareStatus and on error generate message shown to user + processSendCoinsReturn(prepareStatus, + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); + + if(prepareStatus.status != WalletModel::OK) { + fNewRecipientAllowed = true; + return; + } + + CAmount txFee = currentTransaction.getTransactionFee(); + + // Format confirmation message + QStringList formatted; + Q_FOREACH(const SendCoinsRecipient &rcp, currentTransaction.getRecipients()) + { + // generate bold amount string + QString amount = "" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); + amount.append(" ").append(strFunds); + + // generate monospace address string + QString address = "" + rcp.address; + address.append(""); + + QString recipientElement; + + if (!rcp.paymentRequest.IsInitialized()) // normal payment + { + if(rcp.label.length() > 0) // label with address + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); + recipientElement.append(QString(" (%1)").arg(address)); + } + else // just address + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + } + else if(!rcp.authenticatedMerchant.isEmpty()) // authenticated payment request + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); + } + else // unauthenticated payment request + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + + formatted.append(recipientElement); + } + + QString questionString = tr("Are you sure you want to send?"); + questionString.append("

%1"); + + if(txFee > 0.5) + { + // append fee string if a fee is required + questionString.append("


"); + questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); + questionString.append(" "); + questionString.append(tr("are added as transaction fee")); + questionString.append(" "); + questionString.append(strFee); + + // append transaction size + questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)"); + } + + // add total amount in all subdivision units + questionString.append("
"); + CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; + QStringList alternativeUnits; + Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) + { + if(u != model->getOptionsModel()->getDisplayUnit()) + alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); + } + + // Show total amount + all alternative units + questionString.append(tr("Total Amount = %1
= %2") + .arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) + .arg(alternativeUnits.join("
= "))); + + // Limit number of displayed entries + int messageEntries = formatted.size(); + int displayedEntries = 0; + for(int i = 0; i < formatted.size(); i++){ + if(i >= MAX_SEND_POPUP_ENTRIESCHAT){ + formatted.removeLast(); + i--; + } + else{ + displayedEntries = i+1; + } + } + questionString.append("
"); + questionString.append(tr("(%1 of %2 entries displayed)").arg(displayedEntries).arg(messageEntries)); + + // Display message box + if(txFee > 0.05) + { + + QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), + questionString.arg(formatted.join("
")), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + + if(retval != QMessageBox::Yes) + { + fNewRecipientAllowed = true; + return; + } + } + // now send the prepared transaction + WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); + // process sendStatus and on error generate message shown to user + processSendCoinsReturn(sendStatus); + + if (sendStatus.status == WalletModel::OK) + { + accept(); + //CoinControlDialog::coinControl->UnSelectAll(); + coinControlUpdateLabels(); + } + fNewRecipientAllowed = true; +} + +void ChatDialog::clear() +{ + // Remove entries until only one left + while(ui->entries->count()) + { + ui->entries->takeAt(0)->widget()->deleteLater(); + } + addEntry(); + + updateTabsAndLabels(); +} + +void ChatDialog::reject() +{ + // clear(); +} + +void ChatDialog::accept() +{ + // clear(); +} + +ChatEntry *ChatDialog::addEntry() +{ + ChatEntry *entry = new ChatEntry(platformStyle, this); + entry->setModel(model); + ui->entries->addWidget(entry); + connect(entry, SIGNAL(removeEntry(ChatEntry*)), this, SLOT(removeEntry(ChatEntry*))); + connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); + connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels())); + + // Focus the field, so that entry can start immediately + entry->clear(); + entry->setFocus(); + ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint()); + qApp->processEvents(); + QScrollBar* bar = ui->scrollArea->verticalScrollBar(); + if(bar) + bar->setSliderPosition(bar->maximum()); + + updateTabsAndLabels(); + return entry; +} + +void ChatDialog::updateTabsAndLabels() +{ + setupTabChain(0); + coinControlUpdateLabels(); +} + +void ChatDialog::removeEntry(ChatEntry* entry) +{ + entry->hide(); + + // If the last entry is about to be removed add an empty one + if (ui->entries->count() == 1) + addEntry(); + + entry->deleteLater(); + + updateTabsAndLabels(); +} + +QWidget *ChatDialog::setupTabChain(QWidget *prev) +{ + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + prev = entry->setupTabChain(prev); + } + } + QWidget::setTabOrder(prev, ui->sendButton); + QWidget::setTabOrder(ui->sendButton, ui->clearButton); + QWidget::setTabOrder(ui->clearButton, ui->addButton); + return ui->addButton; +} + +void ChatDialog::setAddress(const QString &address, QString imgbase64) +{ + ChatEntry *entry = 0; + // Replace the first entry if it is still unused + if(ui->entries->count() == 1) + { + ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); + if(first->isClear()) + { + entry = first; + } + } + if(!entry) + { + entry = addEntry(); + } + + entry->setAddress(address,imgbase64); +} + +void ChatDialog::pasteEntry(const SendCoinsRecipient &rv) +{ + if(!fNewRecipientAllowed) + return; + + ChatEntry *entry = 0; + // Replace the first entry if it is still unused + if(ui->entries->count() == 1) + { + ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); + if(first->isClear()) + { + entry = first; + } + } + if(!entry) + { + entry = addEntry(); + } + + entry->setValue(rv); + updateTabsAndLabels(); +} + +bool ChatDialog::handlePaymentRequest(const SendCoinsRecipient &rv) +{ + // Just paste the entry, all pre-checks + // are done in paymentserver.cpp. + pasteEntry(rv); + return true; +} + +void ChatDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, + const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance) +{ + Q_UNUSED(unconfirmedBalance); + Q_UNUSED(immatureBalance); + Q_UNUSED(anonymizedBalance); + Q_UNUSED(watchBalance); + Q_UNUSED(watchUnconfirmedBalance); + Q_UNUSED(watchImmatureBalance); + + if(model && model->getOptionsModel()) + { + uint64_t bal = 0; + QSettings settings; + settings.setValue("bUseDarkSend", ui->checkUsePrivateSend->isChecked()); + if(ui->checkUsePrivateSend->isChecked()) { + bal = anonymizedBalance; + } else { + bal = balance; + } + + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); + } +} + +void ChatDialog::updateDisplayUnit() +{ + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), + model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); + CoinControlDialog::coinControl->fUsePrivateSend = ui->checkUsePrivateSend->isChecked(); + coinControlUpdateLabels(); + ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + updateMinFeeLabel(); + updateSmartFeeLabel(); +} + +void ChatDialog::updateInstantSend() +{ + QSettings settings; + settings.setValue("bUseInstantX", ui->checkUseInstantSend->isChecked()); + CoinControlDialog::coinControl->fUseInstantSend = ui->checkUseInstantSend->isChecked(); + coinControlUpdateLabels(); +} + +void ChatDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) +{ + QPair msgParams; + // Default to a warning message, override if error message is needed + msgParams.second = CClientUIInterface::MSG_WARNING; + + // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. + // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() + // all others are used only in WalletModel::prepareTransaction() + switch(sendCoinsReturn.status) + { + case WalletModel::InvalidAddress: + msgParams.first = tr("The recipient address is not valid. Please recheck."); + break; + case WalletModel::InvalidAmount: + msgParams.first = tr("The amount to pay must be larger than 0."); + break; + case WalletModel::AmountExceedsBalance: + msgParams.first = tr("The amount exceeds your balance."); + break; + case WalletModel::AmountWithFeeExceedsBalance: + msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); + break; + case WalletModel::DuplicateAddress: + msgParams.first = tr("Duplicate address found: addresses should only be used once each."); + break; + case WalletModel::TransactionCreationFailed: + msgParams.first = tr("Transaction creation failed!"); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::TransactionCommitFailed: + msgParams.first = tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::AbsurdFee: + msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), maxTxFee)); + break; + case WalletModel::PaymentRequestExpired: + msgParams.first = tr("Payment request expired."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + // included to prevent a compiler warning. + case WalletModel::OK: + default: + return; + } + + Q_EMIT message(tr("Send Coins"), msgParams.first, msgParams.second); +} + +void ChatDialog::minimizeFeeSection(bool fMinimize) +{ + ui->labelFeeMinimized->setVisible(fMinimize); + ui->buttonChooseFee ->setVisible(fMinimize); + ui->buttonMinimizeFee->setVisible(!fMinimize); + ui->frameFeeSelection->setVisible(!fMinimize); + ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0, 0); + fFeeMinimized = fMinimize; +} + +void ChatDialog::on_buttonChooseFee_clicked() +{ + minimizeFeeSection(false); +} + +void ChatDialog::on_buttonMinimizeFee_clicked() +{ + updateFeeMinimizedLabel(); + minimizeFeeSection(true); +} + +void ChatDialog::setMinimumFee() +{ + ui->radioCustomPerKilobyte->setChecked(true); + ui->customFee->setValue(CWallet::GetRequiredFee(1000)); +} + +void ChatDialog::updateFeeSectionControls() +{ + ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked()); + ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked()); + ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked()); + ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); + ui->radioCustomAtLeast ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() && CoinControlDialog::coinControl->HasSelected()); + ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); +} + +void ChatDialog::updateGlobalFeeVariables() +{ + if (ui->radioSmartFee->isChecked()) + { + nTxConfirmTarget = defaultConfirmTargetChat - ui->sliderSmartFee->value(); + payTxFee = CFeeRate(0); + + // set nMinimumTotalFee to 0 to not accidentally pay a custom fee + CoinControlDialog::coinControl->nMinimumTotalFee = 0; + } + else + { + nTxConfirmTarget = defaultConfirmTargetChat; + payTxFee = CFeeRate(ui->customFee->value()); + + // if user has selected to set a minimum absolute fee, pass the value to coincontrol + // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB + CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; + } + + fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); +} + +void ChatDialog::updateFeeMinimizedLabel() +{ + if(!model || !model->getOptionsModel()) + return; + + if (ui->radioSmartFee->isChecked()) + ui->labelFeeMinimized->setText(ui->labelSmartFee->text()); + else { + ui->labelFeeMinimized->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ui->customFee->value()) + + ((ui->radioCustomPerKilobyte->isChecked()) ? "/kB" : "")); + } +} + +void ChatDialog::updateMinFeeLabel() +{ + if (model && model->getOptionsModel()) + ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg( + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB") + ); +} + +void ChatDialog::updateSmartFeeLabel() +{ + if(!model || !model->getOptionsModel()) + return; + + int nBlocksToConfirm = defaultConfirmTargetChat - ui->sliderSmartFee->value(); + int estimateFoundAtBlocks = nBlocksToConfirm; + CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks); + if (feeRate <= CFeeRate(0)) // not enough data => minfee + { + ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), + std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); + ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) + ui->labelFeeEstimation->setText(""); + } + else + { + ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), + std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); + ui->labelSmartFee2->hide(); + ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks)); + } + + updateFeeMinimizedLabel(); +} + +// Coin Control: copy label "Quantity" to clipboard +void ChatDialog::coinControlClipboardQuantity() +{ + GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); +} + +// Coin Control: copy label "Amount" to clipboard +void ChatDialog::coinControlClipboardAmount() +{ + GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); +} + +// Coin Control: copy label "Fee" to clipboard +void ChatDialog::coinControlClipboardFee() +{ + GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "After fee" to clipboard +void ChatDialog::coinControlClipboardAfterFee() +{ + GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "Bytes" to clipboard +void ChatDialog::coinControlClipboardBytes() +{ + GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "Dust" to clipboard +void ChatDialog::coinControlClipboardLowOutput() +{ + GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); +} + +// Coin Control: copy label "Change" to clipboard +void ChatDialog::coinControlClipboardChange() +{ + GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: settings menu - coin control enabled/disabled by user +void ChatDialog::coinControlFeatureChanged(bool checked) +{ + ui->frameCoinControl->setVisible(checked); + + if (!checked && model) // coin control features disabled + CoinControlDialog::coinControl->SetNull(); + + coinControlUpdateLabels(); +} + +// Coin Control: button inputs -> show actual coin control dialog +void ChatDialog::coinControlButtonClicked() +{ + CoinControlDialog dlg(platformStyle); + dlg.setModel(model); + dlg.exec(); + coinControlUpdateLabels(); +} + +// Coin Control: checkbox custom change address +void ChatDialog::coinControlChangeChecked(int state) +{ + if (state == Qt::Unchecked) + { + CoinControlDialog::coinControl->destChange = CNoDestination(); + ui->labelCoinControlChangeLabel->clear(); + } + else + // use this to re-validate an already entered address + coinControlChangeEdited(ui->lineEditCoinControlChange->text()); + + ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); +} + +// Coin Control: custom change address changed +void ChatDialog::coinControlChangeEdited(const QString& text) +{ + if (model && model->getAddressTableModel()) + { + // Default to no change address until verified + CoinControlDialog::coinControl->destChange = CNoDestination(); + ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); + + CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); + + if (text.isEmpty()) // Nothing entered + { + ui->labelCoinControlChangeLabel->setText(""); + } + else if (!addr.IsValid()) // Invalid address + { + ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Dash address")); + } + else // Valid address + { + CKeyID keyid; + addr.GetKeyID(keyid); + if (!model->havePrivKey(keyid)) // Unknown change address + { + ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); + } + else // Known change address + { + ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); + + // Query label + QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); + if (!associatedLabel.isEmpty()) + ui->labelCoinControlChangeLabel->setText(associatedLabel); + else + ui->labelCoinControlChangeLabel->setText(tr("(no label)")); + + CoinControlDialog::coinControl->destChange = addr.Get(); + } + } + } +} + +// Coin Control: update labels +void ChatDialog::coinControlUpdateLabels() +{ + if (!model || !model->getOptionsModel()) + return; + + if (model->getOptionsModel()->getCoinControlFeatures()) + { + // enable minimum absolute fee UI controls + ui->radioCustomAtLeast->setVisible(true); + + // only enable the feature if inputs are selected + ui->radioCustomAtLeast->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() &&CoinControlDialog::coinControl->HasSelected()); + } + else + { + // in case coin control is disabled (=default), hide minimum absolute fee UI controls + ui->radioCustomAtLeast->setVisible(false); + return; + } + + // set pay amounts + CoinControlDialog::payAmounts.clear(); + CoinControlDialog::fSubtractFeeFromAmount = false; + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry && !entry->isHidden()) + { + SendCoinsRecipient rcp = entry->getValue(); + CoinControlDialog::payAmounts.append(rcp.amount); + if (rcp.fSubtractFeeFromAmount) + CoinControlDialog::fSubtractFeeFromAmount = true; + } + } + + ui->checkUsePrivateSend->setChecked(CoinControlDialog::coinControl->fUsePrivateSend); + + if (CoinControlDialog::coinControl->HasSelected()) + { + // actual coin control calculation + CoinControlDialog::updateLabels(model, this); + + // show coin control stats + ui->labelCoinControlAutomaticallySelected->hide(); + ui->widgetCoinControl->show(); + } + else + { + // hide coin control stats + ui->labelCoinControlAutomaticallySelected->show(); + ui->widgetCoinControl->hide(); + ui->labelCoinControlInsuffFunds->hide(); + } +} diff --git a/src/qt/chatdialog.h b/src/qt/chatdialog.h new file mode 100644 index 00000000..9abf9d7e --- /dev/null +++ b/src/qt/chatdialog.h @@ -0,0 +1,106 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_CHATDIALOG_H +#define BITCOIN_QT_CHATDIALOG_H + +#include "walletmodel.h" + +#include +#include + +static const int MAX_SEND_POPUP_ENTRIESCHAT = 10; + +class ClientModel; +class OptionsModel; +class PlatformStyle; +class ChatEntry; +class SendCoinsRecipient; + +namespace Ui { + class ChatDialog; +} + +QT_BEGIN_NAMESPACE +class QUrl; +QT_END_NAMESPACE + +const int defaultConfirmTargetChat = 25; + +/** Dialog for sending bitcoins */ +class ChatDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ChatDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ChatDialog(); + + void setClientModel(ClientModel *clientModel); + void setModel(WalletModel *model); + + /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907). + */ + QWidget *setupTabChain(QWidget *prev); + + void setAddress(const QString &address, QString imgbase64); + void pasteEntry(const SendCoinsRecipient &rv); + bool handlePaymentRequest(const SendCoinsRecipient &recipient); + +public Q_SLOTS: + void clear(); + void reject(); + void accept(); + ChatEntry *addEntry(); + void updateTabsAndLabels(); + void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, + const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); + +private: + Ui::ChatDialog *ui; + ClientModel *clientModel; + WalletModel *model; + bool fNewRecipientAllowed; + void send(QList recipients, QString strFee, QString strFunds); + bool fFeeMinimized; + const PlatformStyle *platformStyle; + + // Process WalletModel::SendCoinsReturn and generate a pair consisting + // of a message and message flags for use in Q_EMIT message(). + // Additional parameter msgArg can be used via .arg(msgArg). + void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString()); + void minimizeFeeSection(bool fMinimize); + void updateFeeMinimizedLabel(); + +private Q_SLOTS: + void on_sendButton_clicked(); + void on_buttonChooseFee_clicked(); + void on_buttonMinimizeFee_clicked(); + void removeEntry(ChatEntry* entry); + void updateDisplayUnit(); + void updateInstantSend(); + void coinControlFeatureChanged(bool); + void coinControlButtonClicked(); + void coinControlChangeChecked(int); + void coinControlChangeEdited(const QString &); + void coinControlUpdateLabels(); + void coinControlClipboardQuantity(); + void coinControlClipboardAmount(); + void coinControlClipboardFee(); + void coinControlClipboardAfterFee(); + void coinControlClipboardBytes(); + void coinControlClipboardLowOutput(); + void coinControlClipboardChange(); + void setMinimumFee(); + void updateFeeSectionControls(); + void updateMinFeeLabel(); + void updateSmartFeeLabel(); + void updateGlobalFeeVariables(); + +Q_SIGNALS: + // Fired when a message should be reported to the user + void message(const QString &title, const QString &message, unsigned int style); +}; + +#endif // BITCOIN_QT_CHATDIALOG_H diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp new file mode 100644 index 00000000..3dee680d --- /dev/null +++ b/src/qt/chatentry.cpp @@ -0,0 +1,558 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chatentry.h" +#include "ui_chatentry.h" + +#include "addressbookpage.h" +#include "addresstablemodel.h" +#include "transactionfilterproxy.h" +#include "transactiontablemodel.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "platformstyle.h" +#include "walletmodel.h" +#include "base64.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +base64 base64chat; +typedef unsigned char BYTE; + +bool fileselectedchat=false; + +ChatEntry::ChatEntry(const PlatformStyle *platformStyle, QWidget *parent) : + QStackedWidget(parent), + ui(new Ui::ChatEntry), + model(0), + platformStyle(platformStyle) +{ + ui->setupUi(this); + + setCurrentWidget(ui->Chat); + + if (platformStyle->getUseExtraSpacing()) + ui->chatToLayout->setSpacing(4); + + + QString theme = GUIUtil::getThemeName(); + + // These icons are needed on Mac also! + ui->addressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); + ui->pasteButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + ui->deleteButton->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->deleteButton_is->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->deleteButton_s->setIcon(QIcon(":/icons/" + theme + "/remove")); + //ui->pasteButtonBase64->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + ui->Imgbase64Edit->setMaxLength(10000000); + + //receive address icons + + ui->ReceiveAddressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); + ui->pasteReceiveButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + + //ui->payAmount->setDisabled(true); + + ui->payAmount->setValue(0.0001); + + + // ui->payAmount->setVisible(false); + + // normal dash address field + GUIUtil::setupAddressWidget(ui->chatReceive, this); + GUIUtil::setupAddressWidget(ui->chatTo, this); + // just a label for displaying dash address(es) + ui->payTo_is->setFont(GUIUtil::fixedPitchFont()); + + // Connect signals + //connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged())); + //connect(ui->chatTo, SIGNAL(textChanged()), this, SIGNAL(on_chatTo_textChanged())); + //connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged())); + connect(ui->pasteButton, SIGNAL(clicked()), this, SLOT(on_pasteButton_clicked())); + connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); + connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked())); + connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked())); + + + connect(ui->ReceiveAddressBookButton, SIGNAL(clicked()), this, SLOT(on_addressReceiveBookButton_clicked())); + + connect(ui->pasteReceiveButton, SIGNAL(clicked()), this, SLOT(on_pasteReceiveAddressButton_clicked())); + + + + //connect(ui->chooserButton, SIGNAL(clicked()), this, SLOT(on_chooserButton_clicked())); + //connect(ui->pasteButtonBase64, SIGNAL(clicked()), this, SLOT(on_pasteButtonBase64_clicked())); + +} + +ChatEntry::~ChatEntry() +{ + delete ui; +} + +void ChatEntry::on_pasteButton_clicked() +{ + // Paste text from clipboard into recipient field + ui->chatTo->setText(QApplication::clipboard()->text()); +} + + +void ChatEntry::on_pasteReceiveAddressButton_clicked() +{ + // Paste text from clipboard into recipient field + ui->chatReceive->setText(QApplication::clipboard()->text()); +} + +void ChatEntry::on_pasteButtonBase64_clicked() +{ + // Paste text from clipboard into recipient field + ui->Imgbase64Edit->setText(QApplication::clipboard()->text()); +} + +void ChatEntry::on_addressBookButton_clicked() +{ + if(!model) + return; + AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this); + dlg.setModel(model->getAddressTableModel()); + if(dlg.exec()) + { + ui->chatTo->setText(dlg.getReturnValue()); + //ui->payAmount->setFocus(); + } +} + +void ChatEntry::on_addressReceiveBookButton_clicked() +{ + if(!model) + return; + AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); + dlg.setModel(model->getAddressTableModel()); + + if(dlg.exec()) + { + ui->chatReceive->setText(dlg.getReturnValue()); + //ui->payAmount->setFocus(); + } +} + +void ChatEntry::on_chatTo_textChanged(const QString &address) +{ + updateLabel(address); + checkaddresstransactions(address); +} + +void ChatEntry::on_chatReceive_textChanged(const QString &address) +{ + checkaddresstransactions(address); +} + +void ChatEntry::checkaddresstransactions(const QString &address) +{ + if (model->validateAddress(ui->chatTo->text()) && model->validateAddress(ui->chatReceive->text())) + { + + ui->chatTo->setDisabled(true); + ui->chatReceive->setDisabled(true); + ui->Imgbase64Edit->setText("Start messaging using to address : " + ui->chatReceive->text() + " and me : " + ui->chatTo->text()); + transactionProxyModel = new TransactionFilterProxy(this); + transactionProxyModel->setAddressPrefix(ui->chatTo->text(),ui->chatReceive->text()); + transactionProxyModel->setSourceModel(model->getTransactionTableModel()); + + + + ui->chattableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->chattableView->setTabKeyNavigation(false); + ui->chattableView->setContextMenuPolicy(Qt::CustomContextMenu); + ui->chattableView->installEventFilter(this); + + QAction *copyImgbase64Action = new QAction(tr("Copy "), this); + + contextMenu = new QMenu(this); + + contextMenu->addAction(copyImgbase64Action); + + connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); + + connect(ui->chattableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); + + transactionView = ui->chattableView; + transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + transactionView->setModel(transactionProxyModel); + transactionView->setAlternatingRowColors(true); + transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); + transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); + transactionView->setSortingEnabled(true); + transactionView->sortByColumn(TransactionTableModel::Date, Qt::AscendingOrder); + transactionView->verticalHeader()->hide(); + //transactionView->horizontalHeader()->hide(); + transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH); + //transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Imgbase64, IMGBASE64_COLUMN_WIDTH); + //transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); + // Actions + + + connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); + + columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, IMGBASE64_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this); + + + // show/hide column Watch-only + + transactionView->setColumnHidden(TransactionTableModel::Watchonly, true); //Watchonly + + transactionView->setColumnHidden(TransactionTableModel::ToAddress, true); //To address + + transactionView->setColumnHidden(TransactionTableModel::Amount, true); // Amount + + // Watch-only signal + // connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool))); + + + } +} + +void ChatEntry::setModel(WalletModel *model) +{ + this->model = model; + + if (model && model->getOptionsModel()) + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + + clear(); +} + +void ChatEntry::clear() +{ + // clear UI elements for normal payment + ui->chatReceive->clear(); + ui->chatTo->clear(); + //ui->addAsLabel->clear(); + //ui->payAmount->clear(); + ui->Imgbase64Edit->clear(); + ui->Imgbase64Edit->setEnabled(1); + fileselectedchat=false; + //ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); + ui->messageTextLabel->clear(); + ui->messageTextLabel->hide(); + ui->messageLabel->hide(); + // clear UI elements for unauthenticated payment request + ui->payTo_is->clear(); + ui->memoTextLabel_is->clear(); + //ui->payAmount_is->clear(); + // clear UI elements for authenticated payment request + ui->payTo_s->clear(); + ui->memoTextLabel_s->clear(); + ui->payAmount_s->clear(); + + // update the display unit, to not use the default ("BTC") + updateDisplayUnit(); +} + + +void ChatEntry::on_chooserButton_clicked() +{ + //clear + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); + ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); + + // Paste text from clipboard into recipient field + QFileDialog dialog(this); + dialog.setFileMode(QFileDialog::ExistingFiles); + + //dialog.setViewMode(QFileDialog::List); + dialog.setOption(QFileDialog::DontUseNativeDialog, false); + + if (dialog.exec()){ + QStringList fileNames = dialog.selectedFiles(); + + if(fileNames.size()>0){ + + + + QString file = fileNames[0]; + ui->FileNamesTxt->setText(file); + std::string filestr = file.toUtf8().constData(); + std::string encodedstring = base64chat.encode(filestr); + QString qsencoded = QString::fromStdString(encodedstring); + + if(!base64chat.base64Validator(encodedstring)){ + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Base64 string not valid."); + ui->Imgbase64Edit->setText(""); + return; + } + if(qsencoded.size()>10000000) + { + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); + ui->Imgbase64Edit->setText(""); + return; + } + fileselectedchat=true; + ui->Imgbase64Edit->setText(qsencoded); + ui->Imgbase64Edit->setDisabled(1); + } + } +} + +void ChatEntry::deleteClicked() +{ + Q_EMIT removeEntry(this); +} + +bool ChatEntry::validate() +{ + if (!model) + return false; + + + // Check input validity + bool retval = true; + + // Skip checks for payment request + if (recipient.paymentRequest.IsInitialized()) + return retval; + + if (!model->validateAddress(ui->chatTo->text())) + { + ui->chatTo->setValid(false); + retval = false; + } + + if (!model->validateAddress(ui->chatReceive->text())) + { + ui->chatReceive->setValid(false); + retval = false; + } + + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); + ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); + if (!ui->Imgbase64Edit->text().isEmpty()) + { + + std::string imgbase64=ui->Imgbase64Edit->text().toUtf8().constData(); + + + if(fileselectedchat) + { + if(!base64chat.base64Validator(imgbase64)){ + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Base64 string not valid."); + ui->Imgbase64Edit->setText(""); + retval = false; + } + } + + + if(ui->Imgbase64Edit->text().length()>10000000) + { + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); + ui->Imgbase64Edit->setText(""); + retval = false; + } + } + else { + retval = false; + } + + if (!ui->payAmount->validate()) + { + retval = false; + } + + // Sending a zero amount is invalid + if (ui->payAmount->value(0) <= 0) + { + ui->payAmount->setValid(false); + retval = false; + } + + // Reject dust outputs: + // if (retval && GUIUtil::isDust(ui->chatTo->text(), ui->payAmount->value())) { + // ui->payAmount->setValid(false); + // retval = false; + //} + + return retval; +} + +SendCoinsRecipient ChatEntry::getValue() +{ + // Payment request + if (recipient.paymentRequest.IsInitialized()) + return recipient; + + // Normal payment + recipient.address = ui->chatTo->text(); + //recipient.label = ui->addAsLabel->text(); + recipient.imgbase64 = ui->Imgbase64Edit->text(); + if(ui->Imgbase64Edit->text().size()>0 && !fileselectedchat){ //message + recipient.imgbase64 ="from:" + ui->chatReceive->text() + ":"+ ui->Imgbase64Edit->text(); + } + recipient.amount = ui->payAmount->value(); + recipient.message = ui->messageTextLabel->text(); + recipient.fSubtractFeeFromAmount = false;//(ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); + + return recipient; +} + +QWidget *ChatEntry::setupTabChain(QWidget *prev) +{ + QWidget::setTabOrder(prev, ui->chatTo); + QWidget::setTabOrder(ui->chatTo, ui->labelchatTo); + //QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel); + //QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount); + //QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton); + + QWidget::setTabOrder(ui->ReceiveAddressBookButton, ui->pasteReceiveButton); + QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton); + QWidget::setTabOrder(ui->pasteButton, ui->deleteButton); + return ui->deleteButton; +} + +void ChatEntry::setValue(const SendCoinsRecipient &value) +{ + recipient = value; + + if (recipient.paymentRequest.IsInitialized()) // payment request + { + if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated + { + ui->chatTo->setText(recipient.address); + //ui->memoTextLabel_is->setText(recipient.message); + ui->payAmount_is->setValue(recipient.amount); + ui->Imgbase64Edit->setText(recipient.imgbase64); + ui->payAmount->setValue(recipient.amount); + ui->payAmount_is->setReadOnly(true); + setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); + } + else // authenticated + { + ui->chatTo->setText(recipient.authenticatedMerchant); + //ui->memoTextLabel_s->setText(recipient.message); + + ui->payAmount_s->setValue(recipient.amount); + ui->payAmount_s->setReadOnly(true); + ui->Imgbase64Edit->setText(recipient.imgbase64); + setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); + } + } + else // normal payment + { + // message + ui->messageTextLabel->setText(recipient.message); + ui->messageTextLabel->setVisible(!recipient.message.isEmpty()); + ui->messageLabel->setVisible(!recipient.message.isEmpty()); + + //ui->addAsLabel->clear(); + ui->chatTo->setText(recipient.address); // this may set a label from addressbook + if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label + ui->labelchatTo->setText(recipient.label); + ui->payAmount->setValue(recipient.amount); + ui->Imgbase64Edit->setText(recipient.imgbase64); + } +} + +void ChatEntry::setAddress(const QString &address, QString imgbase64) +{ + ui->chatTo->setText(address); + if(!imgbase64.isNull()) ui->Imgbase64Edit->setText(imgbase64); + //ui->payAmount->setFocus(); +} + +bool ChatEntry::isClear() +{ + return ui->chatTo->text().isEmpty() && ui->chatReceive->text().isEmpty(); +} + +void ChatEntry::setFocus() +{ + ui->chatTo->setFocus(); +} + +void ChatEntry::updateDisplayUnit() +{ + if(model && model->getOptionsModel()) + { + // Update payAmount with the current unit + ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + } +} + +bool ChatEntry::updateLabel(const QString &address) +{ + if(!model) + return false; + + // Fill in label from address book, if address has an associated label + QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); + if(!associatedLabel.isEmpty()) + { + ui->labelchatTo->setText(associatedLabel); + return true; + } + + return false; +} + +void ChatEntry::contextualMenu(const QPoint &point) +{ + QModelIndex index = transactionView->indexAt(point); + QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); + if (selection.empty()) + return; + + // check if transaction can be abandoned, disable context menu action in case it doesn't + uint256 hash; + hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); + // abandonAction->setEnabled(model->transactionCanBeAbandoned(hash)); + + if(index.isValid()) + { + contextMenu->exec(QCursor::pos()); + } +} + +void ChatEntry::copyImgbase64() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); +} diff --git a/src/qt/chatentry.h b/src/qt/chatentry.h new file mode 100644 index 00000000..e7515a5f --- /dev/null +++ b/src/qt/chatentry.h @@ -0,0 +1,99 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2019- The IMAGEcOIN Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_CHATENTRY_H +#define BITCOIN_QT_CHATENTRY_H + +#include "walletmodel.h" +#include "guiutil.h" +#include +#include + +class WalletModel; +class PlatformStyle; +class TransactionFilterProxy; +class QTableView; +class QMenu; + +namespace Ui { + class ChatEntry; +} + +/** + * A single entry in the dialog for sending bitcoins. + * Stacked widget, with different UIs for payment requests + * with a strong payee identity. + */ +class ChatEntry : public QStackedWidget +{ + Q_OBJECT + +public: + explicit ChatEntry(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ChatEntry(); + + void setModel(WalletModel *model); + bool validate(); + SendCoinsRecipient getValue(); + + /** Return whether the entry is still empty and unedited */ + bool isClear(); + + void setValue(const SendCoinsRecipient &value); + void setAddress(const QString &address,QString imgbase64); + + /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases + * (issue https://bugreports.qt-project.org/browse/QTBUG-10907). + */ + QWidget *setupTabChain(QWidget *prev); + + void setFocus(); + + enum ColumnWidths { + STATUS_COLUMN_WIDTH = 30, + WATCHONLY_COLUMN_WIDTH = 23, + DATE_COLUMN_WIDTH = 120, + TYPE_COLUMN_WIDTH = 180, + IMGBASE64_COLUMN_WIDTH = 580, + AMOUNT_MINIMUM_COLUMN_WIDTH = 120, + MINIMUM_COLUMN_WIDTH = 23 + }; + +public Q_SLOTS: + void clear(); + +Q_SIGNALS: + void removeEntry(ChatEntry *entry); + void payAmountChanged(); + void subtractFeeFromAmountChanged(); + +private Q_SLOTS: + void deleteClicked(); + void on_chatTo_textChanged(const QString &address); + void on_addressBookButton_clicked(); + void on_addressReceiveBookButton_clicked(); + void on_pasteButton_clicked(); + void on_pasteReceiveAddressButton_clicked(); + void updateDisplayUnit(); + void on_chooserButton_clicked(); + void on_pasteButtonBase64_clicked(); + void copyImgbase64(); + void contextualMenu(const QPoint &); + void on_chatReceive_textChanged(const QString &address); + +private: + SendCoinsRecipient recipient; + Ui::ChatEntry *ui; + WalletModel *model; + const PlatformStyle *platformStyle; + TransactionFilterProxy *transactionProxyModel; + QTableView *transactionView; + QMenu *contextMenu; + GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; + bool updateLabel(const QString &address); + void checkaddresstransactions(const QString &address); +}; + +#endif // BITCOIN_QT_CHATIMGENTRY_H From 5d920600ca6eeb5dbfd4a47f125842727765d8f9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:01:46 -0400 Subject: [PATCH 0495/1324] Add files via upload --- src/qt/forms/chatdialog.ui | 1374 +++++++++++++++++++++++++++++++++++ src/qt/forms/chatentry.ui | 1389 ++++++++++++++++++++++++++++++++++++ 2 files changed, 2763 insertions(+) create mode 100644 src/qt/forms/chatdialog.ui create mode 100644 src/qt/forms/chatentry.ui diff --git a/src/qt/forms/chatdialog.ui b/src/qt/forms/chatdialog.ui new file mode 100644 index 00000000..762e717f --- /dev/null +++ b/src/qt/forms/chatdialog.ui @@ -0,0 +1,1374 @@ + + + ChatDialog + + + + 0 + 0 + 850 + 526 + + + + Chat + + + + 8 + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + 10 + + + 10 + + + + + 15 + + + + + + 0 + 0 + + + + + 75 + true + + + + font-weight:bold; + + + Coin Control Features + + + + + + + + + 8 + + + 10 + + + + + + + + Inputs... + + + false + + + + + + + automatically selected + + + 5 + + + + + + + + 75 + true + + + + color:red;font-weight:bold; + + + Insufficient funds! + + + 5 + + + + + + + Qt::Horizontal + + + + 40 + 1 + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 20 + + + 0 + + + 10 + + + + + 10 + + + 14 + + + 10 + + + 4 + + + 6 + + + + + + 75 + true + + + + Quantity: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0 + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Bytes: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + Amount: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Dust: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + no + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + Fee: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + After Fee: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Change: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + + + 12 + + + QLayout::SetDefaultConstraint + + + 5 + + + 5 + + + + + If this is activated, but the change address is empty or invalid, change will be sent to a newly generated address. + + + Custom change address + + + + + + + false + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + 3 + + + + + + + + + Qt::Vertical + + + + 800 + 1 + + + + + + + + + + + + + true + + + + + 0 + 0 + 830 + 69 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 6 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 10 + + + 0 + + + + + 0 + + + + + 0 + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 4 + + + + + + + + 10 + + + + + + 0 + 0 + + + + + 75 + true + + + + font-weight:bold; + + + Transaction Fee: + + + + + + + + + + + + + + Choose... + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + collapse fee-settings + + + Hide + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 10 + + + 4 + + + 10 + + + 4 + + + + + 6 + + + + + + + If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. + + + per kilobyte + + + true + + + groupCustomFee + + + + + + + If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "total at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. + + + total at least + + + groupCustomFee + + + + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. + + + + + + + + + + true + + + Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. + + + (read the tooltip) + + + 5 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + + + Recommended: + + + true + + + groupFee + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + + Custom: + + + groupFee + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + 6 + + + 2 + + + + + + + + + + 2 + + + + + + + + + + + + + + (Smart fee not initialized yet. This usually takes a few blocks...) + + + 2 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + + + Confirmation time: + + + 2 + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + 30 + + + + + 0 + + + 24 + + + 1 + + + 0 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + + + normal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + fast + + + + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + + 8 + + + 4 + + + + + Send as zero-fee transaction if possible + + + + + + + (confirmation may take longer) + + + 5 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + Qt::Vertical + + + + 800 + 1 + + + + + + + + + + + + + + + + 150 + 0 + + + + Confirm the send action + + + S&end + + + false + + + true + + + + + + + + 0 + 0 + + + + Clear all fields of the form. + + + Clear &All + + + false + + + + + + + Send to multiple recipients at once + + + Add &Recipient + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 3 + + + + + + 95 + 0 + + + + PrivateSend + + + false + + + + + + + true + + + + 85 + 0 + + + + InstantSend + + + + + + + Balance: + + + + + + + + 0 + 0 + + + + IBeamCursor + + + 123.456 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+ + BitcoinAmountField + QLineEdit +
bitcoinamountfield.h
+ 1 +
+
+ + + + + + + + +
\ No newline at end of file diff --git a/src/qt/forms/chatentry.ui b/src/qt/forms/chatentry.ui new file mode 100644 index 00000000..da92f8af --- /dev/null +++ b/src/qt/forms/chatentry.ui @@ -0,0 +1,1389 @@ + + + ChatEntry + + + + 0 + 0 + 729 + 552 + + + + Qt::TabFocus + + + false + + + 0 + + + + This is a normal payment. + + + QFrame::NoFrame + + + + 8 + + + 4 + + + 12 + + + 8 + + + + + 0 + + + + + The IMG address to send the message + + + + + + + Choose previously used address + + + + + + + 22 + 22 + + + + Alt+A + + + + + + + Paste address from clipboard + + + + + + + 22 + 22 + + + + Alt+P + + + + + + + + + Me: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 25 + + + + + + + + + + + 0 + + + + + IMG address to sender send you message + + + 33774 + + + + + + + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + + + + Remove this entry + + + + + + + 22 + 22 + + + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + chatTo + + + + + + + + 600 + 240 + + + + + 16777215 + 240 + + + + + + + + Message: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Imgbase64Edit + + + + + + + + 16777215 + 25 + + + + A message that was attached to the dash: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Dash network. + + + Qt::PlainText + + + + + + + 0 + + + 0 + + + + + true + + + Enter a message to send. + + + margin-left:12px + + + 3000000 + + + + + + + + + 0 + + + 0 + + + + + Image/Video: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + margin-left:12px + + + + + + + Chooser + + + + + + + + + + + true + + + + + + + false + + + false + + + The fee will be deducted from the amount being sent. The recipient will receive a lower amount of Dash than you enter in the amount field. If multiple recipients are selected, the fee is split equally. + + + S&ubtract fee from amount + + + + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 191 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 191 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 255 + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + This is an unauthenticated payment request. + + + true + + + QFrame::NoFrame + + + + 12 + + + + + Pay To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + + + + Remove this entry + + + + + + + + + + + + Memo: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::PlainText + + + + + + + A&mount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + payAmount_is + + + + + + + false + + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 0 + 0 + 0 + + + + + + + 155 + 255 + 147 + + + + + + + 0 + 0 + 0 + + + + + + + 119 + 255 + 233 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 197 + 243 + 187 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 0 + 0 + 0 + + + + + + + 155 + 255 + 147 + + + + + + + 0 + 0 + 0 + + + + + + + 119 + 255 + 233 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 197 + 243 + 187 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 70 + 116 + 59 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 70 + 116 + 59 + + + + + + + 155 + 255 + 147 + + + + + + + 70 + 116 + 59 + + + + + + + 140 + 232 + 119 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + This is an authenticated payment request. + + + true + + + QFrame::NoFrame + + + + 12 + + + + + Pay To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + Qt::PlainText + + + + + + + Remove this entry + + + + + + + + + + + + Memo: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::PlainText + + + + + + + A&mount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + payAmount_s + + + + + + + false + + + + + + + + + BitcoinAmountField + QWidget +
bitcoinamountfield.h
+ 1 +
+ + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+
+ + addressBookButton + pasteButton + payAmount_is + deleteButton_is + payAmount_s + deleteButton_s + + + + + +
From b47f0a0f26c08b278f015cb6fd8b2796cf524ed8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:04:01 -0400 Subject: [PATCH 0496/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 229c9eca..e1fb8162 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,6 +33,8 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ + qt/forms/chatdialog.ui \ + qt/forms/chatentry.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ @@ -64,6 +66,8 @@ QT_MOC_CPP = \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ + qt/moc_chatdialog.cpp \ + qt/moc_chatentry.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -139,6 +143,8 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ + qt/chatdialog.h \ + qt/chatentry.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ @@ -502,6 +508,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ + qt/chatdialog.cpp \ + qt/chatentry.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ From 69d476942481d32340ca3b961b46d476334c2cb8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:11:20 -0400 Subject: [PATCH 0497/1324] Add files via upload --- src/qt/base64.cpp | 209 ++++++++++++++++++++++++++++++++++++++++++++++ src/qt/base64.h | 30 +++++++ 2 files changed, 239 insertions(+) create mode 100644 src/qt/base64.cpp create mode 100644 src/qt/base64.h diff --git a/src/qt/base64.cpp b/src/qt/base64.cpp new file mode 100644 index 00000000..a0790d9a --- /dev/null +++ b/src/qt/base64.cpp @@ -0,0 +1,209 @@ +/* + * base64.cpp + * + * Created on: 03/11/2018 + * Author: manue + */ + +#include "base64.h" +#include "util.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +base64::base64() { + // TODO Auto-generated constructor stub + + +} + +base64::~base64() { + // TODO Auto-generated destructor stub +} + + +static const uint8_t from_base64[128] = { + // 8 rows of 16 = 128 + // note: only require 123 entries, as we only lookup for <= z , which z=122 + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 62, 255, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 0, 255, 255, 255, + 255, 0, 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, 255, 255, 255, 255, 63, + 255, 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, 255, 255, 255, 255, 255 + }; + +static const char to_base64[65] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + + +typedef unsigned char BYTE; + +static inline bool is_base64(BYTE c) { + return (isalnum(c) || (c == '+') || (c == '/')); +} + +std::string base64::encode(std::string filename) +{ + + std::ifstream infile; + infile.open(filename, std::ifstream::binary); + + std::vector data(100); + + std::string encodedData; + + infile.seekg(0, std::ios::end); + size_t file_size_in_byte = infile.tellg(); + data.resize(file_size_in_byte); + + infile.seekg(0, std::ios::beg); + infile.read(&data[0], file_size_in_byte); + + + encodedData = base64::base64_encode(data,data.size()); + + return encodedData; + +} + +std::vector base64::decode(std::string imgbase64) +{ + + return base64::base64_decode(imgbase64); +} + + + +std::string base64::base64_encode(std::vector buf,unsigned int bufLen) { + + std::string ret; + + try { + + // Calculate how many bytes that needs to be added to get a multiple of 3 + size_t missing = 0; + size_t ret_size = bufLen; + while ((ret_size % 3) != 0) + { + ++ret_size; + ++missing; + } + + // Expand the return string size to a multiple of 4 + ret_size = 4*ret_size/3; + + ret.clear(); + ret.reserve(ret_size); + + for (size_t i = 0; i < ret_size/4; ++i) + { + // Read a group of three bytes (avoid buffer overrun by replacing with 0) + const size_t index = i*3; + const uint8_t b3_0 = (index+0 < bufLen) ? buf[index+0] : 0; + const uint8_t b3_1 = (index+1 < bufLen) ? buf[index+1] : 0; + const uint8_t b3_2 = (index+2 < bufLen) ? buf[index+2] : 0; + + // Transform into four base 64 characters + const uint8_t b4_0 = ((b3_0 & 0xfc) >> 2); + const uint8_t b4_1 = ((b3_0 & 0x03) << 4) + ((b3_1 & 0xf0) >> 4); + const uint8_t b4_2 = ((b3_1 & 0x0f) << 2) + ((b3_2 & 0xc0) >> 6); + const uint8_t b4_3 = ((b3_2 & 0x3f) << 0); + + // Add the base 64 characters to the return value + ret.push_back(to_base64[b4_0]); + ret.push_back(to_base64[b4_1]); + ret.push_back(to_base64[b4_2]); + ret.push_back(to_base64[b4_3]); + } + + // Replace data that is invalid (always as many as there are missing bytes) + for (size_t i = 0; i != missing; ++i) + ret[ret_size - i - 1] = '='; + + LogPrintf("success: %s","encodebase64"); + + return ret; + } + catch(std::exception& e) { + + LogPrintf("exception encode: %s",e.what()); + + return ret; + } +} + + + +std::vector base64::base64_decode(std::string encoded_string) { + size_t encoded_size = encoded_string.size(); + std::vector ret; + ret.reserve(3*encoded_size/4); +try { + for (size_t i=0; i> 4); + b3[1] = ((b4[1] & 0x0f) << 4) + ((b4[2] & 0x3c) >> 2); + b3[2] = ((b4[2] & 0x03) << 6) + ((b4[3] & 0x3f)); + + ret.push_back(b3[0]); + ret.push_back(b3[1]); + ret.push_back(b3[2]); + } + + + + LogPrintf("success: %s","decodebase64"); + return ret; + } + catch(std::exception& e) { + //Other errors + std::vector vempty; + LogPrintf("exception decode: %s",e.what()); + return vempty; + } +} + + + +bool base64::base64Validator(std::string encoded_string) +{ + std::string expr="^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$"; + + return base64::regexValidate(expr,encoded_string); + +} + + + +bool base64::regexValidate(std::string expr, std::string teststring) +{ + std::regex ex(expr); + + if(teststring.size()>1000) + teststring=teststring.substr(0,1000); + + if ( std::regex_match (teststring,ex) ) { + return true; + } + + return false; +} diff --git a/src/qt/base64.h b/src/qt/base64.h new file mode 100644 index 00000000..40c867af --- /dev/null +++ b/src/qt/base64.h @@ -0,0 +1,30 @@ +/* + * base64.h + * + * Created on: 03/11/2018 + * Author: manue + */ + +#ifndef BITCOIN_QT_BASE64_H +#define BITCOIN_QT_BASE64_H + +#include +#include +#include + +class base64 { + + typedef unsigned char BYTE; + +public: + explicit base64(); + ~base64(); + std::string encode(std::string filename); + std::vector decode(std::string imgbase64); + std::string base64_encode(std::vector buf, unsigned int bufLen); + std::vector base64_decode(std::string encoded_string); + bool base64Validator(std::string encoded_string); + bool regexValidate (std::string expr, std::string teststring); +}; + +#endif /* SRC_QT_BASE64_H_ */ From 7f5b39ce54e8e3a886eef8ca301e53cad7b7da3b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:12:44 -0400 Subject: [PATCH 0498/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e1fb8162..09e119fc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -62,6 +62,7 @@ QT_MOC_CPP = \ qt/moc_addresstablemodel.cpp \ qt/moc_askpassphrasedialog.cpp \ qt/moc_bantablemodel.cpp \ + qt/moc_base64.cpp \ qt/moc_bitcoinaddressvalidator.cpp \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ @@ -139,6 +140,7 @@ BITCOIN_QT_H = \ qt/addresstablemodel.h \ qt/askpassphrasedialog.h \ qt/bantablemodel.h \ + qt/base64.h \ qt/bitcoinaddressvalidator.h \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ @@ -508,6 +510,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ + qt/base64.cpp \ qt/chatdialog.cpp \ qt/chatentry.cpp \ qt/coincontroldialog.cpp \ From c6104ce09261414813d761f3f1a1eabf167bbbf0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:13:37 -0400 Subject: [PATCH 0499/1324] Add files via upload --- src/coincontrol.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/coincontrol.h diff --git a/src/coincontrol.h b/src/coincontrol.h new file mode 100644 index 00000000..ff8f33a8 --- /dev/null +++ b/src/coincontrol.h @@ -0,0 +1,74 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_COINCONTROL_H +#define BITCOIN_COINCONTROL_H + +#include "primitives/transaction.h" + +/** Coin Control Features. */ +class CCoinControl +{ +public: + CTxDestination destChange; + bool fUsePrivateSend; + bool fUseInstantSend; + //! If false, allows unselected inputs, but requires all selected inputs be used + bool fAllowOtherInputs; + //! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria + bool fAllowWatchOnly; + //! Minimum absolute fee (not per kilobyte) + CAmount nMinimumTotalFee; + + CCoinControl() + { + SetNull(); + } + + void SetNull() + { + destChange = CNoDestination(); + fAllowOtherInputs = false; + fAllowWatchOnly = false; + setSelected.clear(); + fUseInstantSend = false; + fUsePrivateSend = true; + nMinimumTotalFee = 0; + } + + bool HasSelected() const + { + return (setSelected.size() > 0); + } + + bool IsSelected(const COutPoint& output) const + { + return (setSelected.count(output) > 0); + } + + void Select(const COutPoint& output) + { + setSelected.insert(output); + } + + void UnSelect(const COutPoint& output) + { + setSelected.erase(output); + } + + void UnSelectAll() + { + setSelected.clear(); + } + + void ListSelected(std::vector& vOutpoints) const + { + vOutpoints.assign(setSelected.begin(), setSelected.end()); + } + +private: + std::set setSelected; +}; + +#endif // BITCOIN_COINCONTROL_H From 1850b918470366345115ad16540aebe4e4116079 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:14:39 -0400 Subject: [PATCH 0500/1324] Update Makefile.am --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index ac252b97..5ea8460b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -122,6 +122,7 @@ BITCOIN_CORE_H = \ checkpoints.h \ checkqueue.h \ clientversion.h \ + coincontrol.h \ coins.h \ compat.h \ compat/byteswap.h \ From e21902d6295968b6eb7667a8b490c949118c2bc4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:25:40 -0400 Subject: [PATCH 0501/1324] Update transactionrecord.cpp --- src/qt/transactionrecord.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index f5ef2140..fb0f1fb7 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -44,22 +44,22 @@ QList TransactionRecord::decomposeTransaction(const CWallet * CAmount nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; - + std::string imgbase64=mapValue["imgbase64"]; if (nNet > 0 || wtx.IsCoinBase()) { // // Credit // - for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) + BOOST_FOREACH(const CTxOut& txout, wtx.vout) { - const CTxOut& txout = wtx.tx->vout[i]; isminetype mine = wallet->IsMine(txout); if(mine) { TransactionRecord sub(hash, nTime); CTxDestination address; - sub.idx = i; // vout index + sub.idx = parts.size(); // sequence number sub.credit = txout.nValue; + sub.imgbase64=txout.imgbase64; sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address)) { @@ -114,7 +114,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * } if(fAllFromMeDenom && fAllToMeDenom && nFromMe * nToMe) { - parts.append(TransactionRecord(hash, nTime, TransactionRecord::PrivateSendDenominate, "", -nDebit, nCredit)); + parts.append(TransactionRecord(hash, nTime, TransactionRecord::PrivateSendDenominate, "", imgbase64, -nDebit, nCredit)); parts.last().involvesWatchAddress = false; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe && fAllToMe) @@ -127,7 +127,8 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // Payment to self by default sub.type = TransactionRecord::SendToSelf; sub.address = ""; - + const CTxOut& txoutex = wtx.vout[0]; + sub.imgbase64=txoutex.imgbase64; if(mapValue["DS"] == "1") { sub.type = TransactionRecord::PrivateSend; @@ -199,7 +200,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * TransactionRecord sub(hash, nTime); sub.idx = nOut; sub.involvesWatchAddress = involvesWatchAddress; - + sub.imgbase64=txout.imgbase64; if(wallet->IsMine(txout)) { // Ignore parts sent to self, as this is usually the change @@ -243,7 +244,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // // Mixed debit transaction, can't break down payees // - parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); + parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", imgbase64, nNet, 0)); parts.last().involvesWatchAddress = involvesWatchAddress; } } From b0d8741b2b84b900b7c870308b9696a9332647a7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:27:37 -0400 Subject: [PATCH 0502/1324] Update transactionrecord.h --- src/qt/transactionrecord.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 3ad6556f..32d13cc6 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -98,20 +98,20 @@ class TransactionRecord static const int RecommendedNumConfirmations = 6; TransactionRecord(): - hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0) + hash(), time(0), type(Other), address(""), imgbase64(""), debit(0), credit(0), idx(0) { } TransactionRecord(uint256 _hash, qint64 _time): - hash(_hash), time(_time), type(Other), address(""), debit(0), + hash(_hash), time(_time), type(Other), address(""), imgbase64(""), debit(0), credit(0), idx(0) { } TransactionRecord(uint256 _hash, qint64 _time, - Type _type, const std::string &_address, + Type type, const std::string &address,const std::string &imgbase64, const CAmount& _debit, const CAmount& _credit): - hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit), + hash(_hash), time(_time), type(_type), address(_address), imgbase64(imgbase64), debit(_debit), credit(_credit), idx(0) { } @@ -127,6 +127,7 @@ class TransactionRecord qint64 time; Type type; std::string address; + std::string imgbase64; CAmount debit; CAmount credit; /**@}*/ From 69d6eacd5264fcd97c3acc609927a533d4745d17 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:30:59 -0400 Subject: [PATCH 0503/1324] Update transaction.cpp --- src/primitives/transaction.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index a6bec141..e831de33 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -48,16 +48,20 @@ std::string CTxIn::ToString() const return str; } -CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, int nRoundsIn) +CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, std::string imgbase64in, int nRoundsIn) { nValue = nValueIn; scriptPubKey = scriptPubKeyIn; + if(imgbase64.size()<=1000000000){ + imgbase64=imgbase64in; + } + else throw std::runtime_error("CTxOut::Imgbase64in(): value out of range"); nRounds = nRoundsIn; } std::string CTxOut::ToString() const { - return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30)); + return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s, imgbase64=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30), imgbase64); } CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nLockTime(0) {} From 9e79f1f9300feef21fa3626a25780310c1197008 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:33:02 -0400 Subject: [PATCH 0504/1324] Update walletmodel.h --- src/qt/walletmodel.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 83c262f4..6aeed507 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -41,8 +41,8 @@ class SendCoinsRecipient { public: explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { } - explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message): - address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} + explicit SendCoinsRecipient(const QString &addr, const QString &_label, const QString &imgbase64, const CAmount& _amount, const QString &_message): + address(addr), label(_label), amount(_amount), imgbase64(imgbase64) , message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} // If from an unauthenticated payment request, this is used for storing // the addresses, e.g. address-A
address-B
address-C. @@ -51,6 +51,7 @@ class SendCoinsRecipient // Todo: This is a hack, should be replaced with a cleaner solution! QString address; QString label; + QString imgbase64; #ifdef ENABLE_WALLET AvailableCoinsType inputType; #endif // ENABLE_WALLET @@ -80,6 +81,7 @@ class SendCoinsRecipient std::string sAddress = address.toStdString(); std::string sLabel = label.toStdString(); std::string sMessage = message.toStdString(); + std::string simgbase64 = imgbase64.toStdString(); std::string sPaymentRequest; if (!ser_action.ForRead() && paymentRequest.IsInitialized()) paymentRequest.SerializeToString(&sPaymentRequest); @@ -89,6 +91,7 @@ class SendCoinsRecipient READWRITE(sAddress); READWRITE(sLabel); READWRITE(amount); + READWRITE(simgbase64); READWRITE(sMessage); READWRITE(sPaymentRequest); READWRITE(sAuthenticatedMerchant); @@ -97,6 +100,7 @@ class SendCoinsRecipient { address = QString::fromStdString(sAddress); label = QString::fromStdString(sLabel); + imgbase64= QString::fromStdString(simgbase64); message = QString::fromStdString(sMessage); if (!sPaymentRequest.empty()) paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size())); From 43a91dec08eb9fa8e06249c939d03d1bb42b1b27 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:34:46 -0400 Subject: [PATCH 0505/1324] Update transaction.h --- src/primitives/transaction.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 76cdc346..bba8947e 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -146,6 +146,7 @@ class CTxOut public: CAmount nValue; CScript scriptPubKey; + std::string imgbase64; int nRounds; CTxOut() @@ -153,7 +154,7 @@ class CTxOut SetNull(); } - CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, int nRoundsIn = -10); + CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, std::string imgbase64, int nRoundsIn = -10); ADD_SERIALIZE_METHODS; @@ -161,12 +162,14 @@ class CTxOut inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(nValue); READWRITE(*(CScriptBase*)(&scriptPubKey)); + READWRITE(imgbase64); } void SetNull() { nValue = -1; scriptPubKey.clear(); + imgbase64=""; nRounds = -10; // an initial value, should be no way to get this by calculations } @@ -200,6 +203,7 @@ class CTxOut { return (a.nValue == b.nValue && a.scriptPubKey == b.scriptPubKey && + a.imgbase64 == b.imgbase64 && a.nRounds == b.nRounds); } From 86f30a145feebd59aed36c3df9a62389d284af3a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:47:08 -0400 Subject: [PATCH 0506/1324] Update rpcwallet.cpp --- src/wallet/rpcwallet.cpp | 150 +++++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 47 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fbd76bc7..6a2cd4fb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -378,7 +378,7 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA std::string strError; std::vector vecSend; int nChangePosRet = -1; - CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, nValue, wtxNew.mapValue["imgbase64"], fSubtractFeeFromAmount}; vecSend.push_back(recipient); if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend)) { @@ -422,13 +422,14 @@ UniValue sendtoaddress(const JSONRPCRequest& request) " The recipient will receive less amount of Dash than you enter in the amount field.\n" "6. \"use_is\" (bool, optional, default=false) Send this transaction as InstantSend\n" "7. \"use_ps\" (bool, optional, default=false) Use anonymized funds only\n" + "8. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "\nResult:\n" "\"txid\" (string) The transaction id.\n" "\nExamples:\n" + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1") - + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"donation\" \"seans outpost\"") - + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"\" \"\" true") - + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"imgbase64\" \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"\" \"\" \"\" true") + + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.1, \"imgbase64\" \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwallet->cs_wallet); @@ -444,25 +445,38 @@ UniValue sendtoaddress(const JSONRPCRequest& request) // Wallet comments CWalletTx wtx; - if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty()) - wtx.mapValue["comment"] = request.params[2].get_str(); - if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) - wtx.mapValue["to"] = request.params[3].get_str(); + if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) + { + wtx.mapValue["imgbase64"] = ""; + if(params[2].get_str().size()<10000000){ + wtx.mapValue["imgbase64"] = params[2].get_str(); + } + else if (params[2].get_str().size()>10000000){ + throw JSONRPCError(RPC_TYPE_ERROR, "Imgbase64 max length is 10000000"); + } + else if (!base64rpcwallet.base64Validator(params[2].get_str())) { + throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); + } + } + if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty()) + wtx.mapValue["comment"] = params[3].get_str(); + if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty()) + wtx.mapValue["to"] = params[4].get_str(); bool fSubtractFeeFromAmount = false; - if (request.params.size() > 4) - fSubtractFeeFromAmount = request.params[4].get_bool(); + if (params.size() > 5) + fSubtractFeeFromAmount = params[5].get_bool(); bool fUseInstantSend = false; bool fUsePrivateSend = false; - if (request.params.size() > 5) - fUseInstantSend = request.params[5].get_bool(); - if (request.params.size() > 6) - fUsePrivateSend = request.params[6].get_bool(); + if (params.size() > 6) + fUseInstantSend = params[6].get_bool(); + if (params.size() > 7) + fUsePrivateSend = params[7].get_bool(); - EnsureWalletIsUnlocked(pwallet); + EnsureWalletIsUnlocked(); - SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend); + SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend); return wtx.GetHash().GetHex(); } @@ -479,6 +493,7 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request) "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" + HelpRequiringPassphrase(pwallet) + "\nArguments:\n" + "3. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"address\" (string, required) The dash address to send to.\n" "2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" @@ -508,23 +523,7 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request) if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); - // Wallet comments - CWalletTx wtx; - if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty()) - wtx.mapValue["comment"] = request.params[2].get_str(); - if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) - wtx.mapValue["to"] = request.params[3].get_str(); - - bool fSubtractFeeFromAmount = false; - if (request.params.size() > 4) - fSubtractFeeFromAmount = request.params[4].get_bool(); - - EnsureWalletIsUnlocked(pwallet); - - SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true); - - return wtx.GetHash().GetHex(); -} + "3. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" UniValue listaddressgroupings(const JSONRPCRequest& request) { @@ -911,6 +910,7 @@ UniValue movecmd(const JSONRPCRequest& request) "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n" "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n" "\nArguments:\n" + "0. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n" "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n" "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" @@ -937,13 +937,54 @@ UniValue movecmd(const JSONRPCRequest& request) if (request.params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)request.params[3].get_int(); - std::string strComment; - if (request.params.size() > 4) - strComment = request.params[4].get_str(); + + string strimgbase64; + if (params.size() > 4 && !params[4].get_str().empty()){ + + if(params[4].get_str().size()<10000000){ + strimgbase64 = params[4].get_str(); + } + else if (params[4].get_str().size()>10000000){ + throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64, or max length is 10000000"); + } + else if (params[4].get_str().size()>2 && !base64rpcwallet.base64Validator(params[4].get_str())) { + throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); + } + } + string strComment; + if (params.size() > 5) + strComment = params[5].get_str(); + + CWalletDB walletdb(pwalletMain->strWalletFile); + if (!walletdb.TxnBegin()) + throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); - if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) { + int64_t nNow = GetAdjustedTime(); + + // Debit + CAccountingEntry debit; + debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); + debit.strAccount = strFrom; + debit.nCreditDebit = -nAmount; + debit.imgbase64 = strimgbase64; + debit.nTime = nNow; + debit.strOtherAccount = strTo; + debit.strComment = strComment; + pwalletMain->AddAccountingEntry(debit, walletdb); + + // Credit + CAccountingEntry credit; + credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); + credit.strAccount = strTo; + credit.nCreditDebit = nAmount; + credit.imgbase64 = strimgbase64; + credit.nTime = nNow; + credit.strOtherAccount = strFrom; + credit.strComment = strComment; + pwalletMain->AddAccountingEntry(credit, walletdb); + + if (!walletdb.TxnCommit()) throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); - } return true; } @@ -962,6 +1003,7 @@ UniValue sendfrom(const JSONRPCRequest& request) "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a dash address." + HelpRequiringPassphrase(pwallet) + "\n" "\nArguments:\n" + "0. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" " Specifying an account does not influence coin selection, but it does associate the newly created\n" " transaction with the account, so the account's balance computation and transaction history can reflect\n" @@ -1002,24 +1044,35 @@ UniValue sendfrom(const JSONRPCRequest& request) CWalletTx wtx; wtx.strFromAccount = strAccount; - if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty()) - wtx.mapValue["comment"] = request.params[5].get_str(); - if (request.params.size() > 6 && !request.params[6].isNull() && !request.params[6].get_str().empty()) - wtx.mapValue["to"] = request.params[6].get_str(); - - EnsureWalletIsUnlocked(pwallet); + if (params.size() > 5 && !params[5].isNull() && !params[5].get_str().empty()){ + wtx.mapValue["imgbase64"] = ""; + if(params[5].get_str().size()<10000000){ + wtx.mapValue["imgbase64"] = params[5].get_str(); + } + else if (params[5].get_str().size()>10000000){ + throw JSONRPCError(RPC_TYPE_ERROR, "Imgbase64 max length is 10000000"); + } + else if (!base64rpcwallet.base64Validator(params[5].get_str())) { + throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); + } + } + if (params.size() > 6 && !params[6].isNull() && !params[6].get_str().empty()) + wtx.mapValue["comment"] = params[6].get_str(); + if (params.size() > 7 && !params[7].isNull() && !params[7].get_str().empty()) + wtx.mapValue["to"] = params[7].get_str(); + + EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLocked); + CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); - SendMoney(pwallet, address.Get(), nAmount, false, wtx); + SendMoney(address.Get(), nAmount, false, wtx); return wtx.GetHash().GetHex(); } - UniValue sendmany(const JSONRPCRequest& request) { CWallet * const pwallet = GetWalletForJSONRPCRequest(request); @@ -1466,6 +1519,7 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std:: std::map::const_iterator it = wtx.mapValue.find("DS"); entry.push_back(Pair("category", (it != wtx.mapValue.end() && it->second == "1") ? "privatesend" : "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); + entry.push_back(Pair("imgbase64",s.imgbase64)); if (pwallet->mapAddressBook.count(s.destination)) { entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name)); } @@ -1509,6 +1563,7 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std:: entry.push_back(Pair("category", "receive")); } entry.push_back(Pair("amount", ValueFromAmount(r.amount))); + entry.push_back(Pair("imgbase64",r.imgbase64)); if (pwallet->mapAddressBook.count(r.destination)) { entry.push_back(Pair("label", account)); } @@ -1532,6 +1587,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccoun entry.push_back(Pair("category", "move")); entry.push_back(Pair("time", acentry.nTime)); entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit))); + entry.push_back(Pair("imgbase64", acentry.imgbase64)); entry.push_back(Pair("otheraccount", acentry.strOtherAccount)); entry.push_back(Pair("comment", acentry.strComment)); ret.push_back(entry); From a260a65110be99ecb81b509100ac6c9a65ff0e7c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:48:11 -0400 Subject: [PATCH 0507/1324] Update walletview.cpp --- src/qt/walletview.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d4a3257d..7b99a1ef 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -296,12 +296,12 @@ void WalletView::gotoReceiveCoinsPage() setCurrentWidget(receiveCoinsPage); } -void WalletView::gotoSendCoinsPage(QString addr) +void WalletView::gotoSendCoinsPage(QString addr,QString imgbase64) { setCurrentWidget(sendCoinsPage); - if (!addr.isEmpty()) - sendCoinsPage->setAddress(addr); + if (!addr.isEmpty() || !imgbase64.isEmpty()) + sendCoinsPage->setAddress(addr, imgbase64); } void WalletView::gotoSignMessageTab(QString addr) @@ -456,3 +456,7 @@ void WalletView::trxAmount(QString amount) { transactionSum->setText(amount); } +void WalletView::encodebase64ClickedSignal(const QString &address, const QString &imgbase64){ + + gotoSendCoinsPage(address,imgbase64); +} From ae5ade213a1b5e6f01a9f5838859e86d75973e53 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:51:12 -0400 Subject: [PATCH 0508/1324] Update transactiontablemodel.cpp --- src/qt/transactiontablemodel.cpp | 45 ++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 36de15b8..fb8404a6 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -37,6 +37,7 @@ static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, /* type */ Qt::AlignLeft|Qt::AlignVCenter, /* address */ Qt::AlignRight|Qt::AlignVCenter /* amount */ + Qt::AlignLeft|Qt::AlignVCenter, /* imgbase64 */ }; // Comparison operator for sort/binary search of model tx list @@ -244,7 +245,7 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle fProcessingQueuedTransactions(false), platformStyle(_platformStyle) { - columns << QString() << QString() << QString() << tr("Date") << tr("Type") << tr("Address / Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit()); + columns << QString() << QString() << QString() << tr("Date") << tr("Type") << tr("Address / Label") << tr("Imgbase64") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit()); priv->refreshWallet(); connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); @@ -610,6 +611,23 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxType(rec); case ToAddress: return formatTxToAddress(rec, false); + case Imgbase64:{ + QString qimgbase64 = QString(); + qimgbase64 = QString::fromStdString(rec->imgbase64); + if(qimgbase64.size()>500){ + + qimgbase64 = qimgbase64.left(499); + qimgbase64 = qimgbase64 + " ..."; + } + + if(qimgbase64.size()>2) { + QString mensage = qimgbase64.section(":", 0, 0, QString::SectionSkipEmpty); + if(mensage=="m") qimgbase64 = qimgbase64.mid(2); + if(mensage=="from") qimgbase64 = qimgbase64.mid(40); + } + + return qimgbase64; + } case Amount: return formatTxAmount(rec, true, BitcoinUnits::separatorAlways); } @@ -626,10 +644,19 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxType(rec); case Watchonly: return (rec->involvesWatchAddress ? 1 : 0); - case InstantSend: - return (rec->status.lockedByInstantSend ? 1 : 0); case ToAddress: return formatTxToAddress(rec, true); + case Imgbase64:{ + QString qimgbase64 = QString(); + qimgbase64 = QString::fromStdString(rec->imgbase64); + if(qimgbase64.size()>500){ + + qimgbase64 = qimgbase64.left(499); + //qimgbase64->setText(qimgbase64->toUtf8() + " ..."); + qimgbase64 = qimgbase64 + " ..."; + } + return qimgbase64; + } case Amount: return qint64(rec->credit + rec->debit); } @@ -644,10 +671,6 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const { return COLOR_TX_STATUS_DANGER; } - if(rec->status.lockedByInstantSend) - { - return COLOR_TX_STATUS_LOCKED; - } // Non-confirmed (but not immature) as transactions are grey if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature) { @@ -670,16 +693,14 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return rec->involvesWatchAddress; case WatchonlyDecorationRole: return txWatchonlyDecoration(rec); - case InstantSendRole: - return rec->status.lockedByInstantSend; - case InstantSendDecorationRole: - return txInstantSendDecoration(rec); case LongDescriptionRole: return priv->describe(rec, walletModel->getOptionsModel()->getDisplayUnit()); case AddressRole: return QString::fromStdString(rec->address); case LabelRole: return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address)); + case Imgbase64Role: + return QString::fromStdString(rec->imgbase64); case AmountRole: return qint64(rec->credit + rec->debit); case TxIDRole: @@ -722,7 +743,9 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxAmount(rec, false, BitcoinUnits::separatorNever); case StatusRole: return rec->status.status; + } + return QVariant(); } From 10ee16b68e9617ebda332f081971cae389e7c5e2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:52:10 -0400 Subject: [PATCH 0509/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index e56efdcf..1d491469 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -164,11 +164,11 @@ void WalletFrame::gotoReceiveCoinsPage() i.value()->gotoReceiveCoinsPage(); } -void WalletFrame::gotoSendCoinsPage(QString addr) +void WalletFrame::gotoSendCoinsPage(QString addr, QString imgbase64) { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoSendCoinsPage(addr); + i.value()->gotoSendCoinsPage(addr,imgbase64); } void WalletFrame::gotoSignMessageTab(QString addr) From 8f8f6a8e3ba49b0debc84d72eb0140c0019b4256 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:52:51 -0400 Subject: [PATCH 0510/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 58420a98..ed419efb 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -101,8 +101,8 @@ public Q_SLOTS: void gotoMasternodePage(); /** Switch to receive coins page */ void gotoReceiveCoinsPage(); - /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = ""); + /** Switch to send coins page */ + void gotoSendCoinsPage(QString addr = "",QString imgbase64 = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); From f0288a3bcee159e2eb95700350e9e70c2de702a3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 11 Jun 2020 23:53:34 -0400 Subject: [PATCH 0511/1324] Update walletview.h --- src/qt/walletview.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index ed419efb..3a6643d8 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -142,6 +142,7 @@ public Q_SLOTS: /** Update selected HTH amount from transactionview */ void trxAmount(QString amount); + void encodebase64ClickedSignal(const QString &address, const QString &imgbase64); Q_SIGNALS: /** Signal that we want to show the main window */ void showNormalIfMinimized(); From fa1867b41b541a8938d6e7e56b3b17453efa4e2f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:01:09 -0400 Subject: [PATCH 0512/1324] Update walletdb.cpp --- src/wallet/walletdb.cpp | 338 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 335 insertions(+), 3 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 645c8b21..debf34e5 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -56,12 +56,344 @@ bool CWalletDB::ErasePurpose(const std::string& strPurpose) return Erase(make_pair(std::string("purpose"), strPurpose)); } -bool CWalletDB::WriteTx(const CWalletTx& wtx) +bool CWalletDB::WriteTx(uint256 hash, const CWalletTx &tx) { - nWalletDBUpdateCounter++; - return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx); + nWalletDBUpdated++; + + bool res = false; + if (m_imageDB == 0) + { + this->Write(std::make_pair(std::string("tx"), hash), tx); + } + else + { + CWalletTx wtx = tx; + std::vector image; + + std::vector &vout = (*const_cast*>(&wtx.vout)); + + for (auto &e : vout) { + image.push_back(e.imgbase64); + e.imgbase64 = ""; + } + + res = m_imageDB->setImage(hash, image); + if (res) { + res = this-Write(std::make_pair(std::string("tx"), hash), wtx); + LogPrintf("CWalletDB::WriteTx: hash<%s>, success<%d>\n", hash.ToString().c_str(), res); + } + } + + return res; } +bool ReadKeyValue(CWallet* pwallet, + CDataStream& ssKey, + CDataStream& ssValue, + CWalletScanState &wss, + string& strType, + string& strErr, + CImageDB* idb = 0); + + +// ================================= +// loadImage +bool CImageDB::readKeyValue(CDataStream& ssKey, CDataStream& ssValue, + int &nFileVersion, string& strType) +{ + try { + ssKey >> strType; + LogPrintf("==============================================\n"); + LogPrintf("CImageDB::readKeyValue. strType: %s\n", strType.c_str()); + + if (strType == "image") + { + uint256 hash; + ssKey >> hash; + ssValue >> m_imageMap[hash]; + LogPrintf("CImageDB tx hash:%s\n", hash.ToString().c_str()); + int i = 0; + for (auto &imgbase64 : m_imageMap[hash]) { + LogPrintf(" imgbase64[%d] len: %lu\n", i++, imgbase64.length()); + } + } + else if (strType == "version") + { + ssValue >> nFileVersion; + LogPrintf("CImageDB::ReadKeyValue version: %d\n", nFileVersion); + } + else if (strType == "minversion") + { + int minversion; + ssValue >> minversion; + LogPrintf("CImageDB::ReadKeyValue minversion: %d\n", minversion); + } + } catch (...) + { + return false; + } + + return true; +} + +DBErrors CImageDB::loadImage() +{ + DBErrors result = DB_LOAD_OK; + bool fNoncriticalErrors = false; + LogPrintf("CImageDB::loadImage: enter\n"); + int nFileVersion = 0; + try { + + int nMinVersion = 0; + if (Read((string)"minversion", nMinVersion)) + { + LogPrintf("CImageDB::loadImage: nMinVersion is %d\n", nMinVersion); + if (nMinVersion > CLIENT_VERSION) + return DB_TOO_NEW; + } + else + { + LogPrintf("CImageDB::loadImage: Failed to load nMinVersion\n"); + } + // Get cursor + Dbc* pcursor = CDB::GetCursor(); + if (!pcursor) + { + LogPrintf("Error getting image database cursor\n"); + return DB_CORRUPT; + } + + while (true) + { + // Read next record + CDataStream ssKey(SER_DISK, CLIENT_VERSION); + CDataStream ssValue(SER_DISK, CLIENT_VERSION); + int ret = CDB::ReadAtCursor(pcursor, ssKey, ssValue); + if (ret == DB_NOTFOUND) + break; + else if (ret != 0) + { + LogPrintf("Error reading next record from wallet database\n"); + return DB_CORRUPT; + } + + string strType; + if (!this->readKeyValue(ssKey, ssValue, nFileVersion, strType)) + { + // read error + if (strType == "image") + { + // rescan if failed to read an image + fNoncriticalErrors = true; // ... but do warn the user there is something wrong. + SoftSetBoolArg("-rescan", true); + } + else + { + result = DB_CORRUPT; + } + } + } + pcursor->close(); + } + catch (const boost::thread_interrupted&) { + throw; + } + catch (...) { + result = DB_CORRUPT; + } + + if (fNoncriticalErrors && result == DB_LOAD_OK) + result = DB_NONCRITICAL_ERROR; + + if (result != DB_LOAD_OK) + return result; + + if (nFileVersion < CLIENT_VERSION) // Update + this->WriteVersion(CLIENT_VERSION); + + LogPrintf("CImageDB::loadImage exit!\n"); + return result; +} + +// DBErrors CImageDB::loadImage() +// ======================================================= +DBErrors CWalletDB::LoadWallet(CWallet *pwallet) { + pwallet->vchDefaultKey = CPubKey(); + CWalletScanState wss; + bool fNoncriticalErrors = false; + bool imageErrors = false; + DBErrors result = DB_LOAD_OK; + + + try { + LOCK(pwallet->cs_wallet); + if (m_imageDB != 0) + { + DBErrors res = m_imageDB->loadImage(); + if (res != DB_LOAD_OK) { + LogPrintf("Failed to loadImage. result: %d\n", result); + } + } + + LogPrintf("======CWalletDB::LoadWallet start======\n"); + int nMinVersion = 0; + if (Read((string) "minversion", nMinVersion)) { + + LogPrintf("CWalletDb::LoadWallet ReadKeyValue: minversion: %d\n", nMinVersion); + + if (nMinVersion > CLIENT_VERSION) + return DB_TOO_NEW; + + pwallet->LoadMinVersion(nMinVersion); + } + + // Get cursor + Dbc *pcursor = CDB::GetCursor(); + if (!pcursor) { + LogPrintf("Error getting wallet database cursor\n"); + return DB_CORRUPT; + } + + std::map failedKey; + std::map successKey; + + while (true) { + // Read next record + CDataStream ssKey(SER_DISK, CLIENT_VERSION); + CDataStream ssValue(SER_DISK, CLIENT_VERSION); + int ret = CDB::ReadAtCursor(pcursor, ssKey, ssValue); + if (ret == DB_NOTFOUND) + break; + else if (ret != 0) { + LogPrintf("Error reading next record from wallet database\n"); + return DB_CORRUPT; + } + + // Try to be tolerant of single corrupt records: + string strType, strErr; + if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr, m_imageDB)) + { + failedKey[strType]++; + // losing keys is considered a catastrophic error, anything else + // we assume the user can live with: + if (IsKeyType(strType)) + { + result = DB_CORRUPT; + } + else { + // Leave other errors alone, if we try to fix them we might make things worse. + fNoncriticalErrors = true; // ... but do warn the user there is something wrong. + if (strType == "tx") { + LogPrintf("Rescan as there is a bad transaction record\n"); + if (strErr == "Image is invalid") { + imageErrors = true; + } + SoftSetBoolArg("-rescan", true); + } + } + } + else + { + successKey[strType]++; + } + if (!strErr.empty()) + LogPrintf("%s\n", strErr); + } + + dumpWalletDBState(successKey, "success"); + dumpWalletDBState(failedKey, "failed"); + pcursor->close(); + + // Store initial external keypool size since we mostly use external keys in mixing + pwallet->nKeysLeftSinceAutoBackup = pwallet->KeypoolCountExternalKeys(); + LogPrintf("nKeysLeftSinceAutoBackup: %d\n", pwallet->nKeysLeftSinceAutoBackup); + } + catch (const boost::thread_interrupted &) { + throw; + } + catch (...) { + result = DB_CORRUPT; + } + + if (fNoncriticalErrors && result == DB_LOAD_OK) + result = DB_NONCRITICAL_ERROR; + + if (imageErrors && result == DB_LOAD_OK) + result = DB_RESCAN_IMAGE; + + // Any wallet corruption at all: skip any rewriting or + // upgrading, we don't want to make it worse. + if (result != DB_LOAD_OK) + return result; + + LogPrintf("nFileVersion = %d\n", wss.nFileVersion); + + LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n", + wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys); + + // nTimeFirstKey is only reliable if all keys have metadata + if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta) + pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value' + + BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade) + this->WriteTx(hash, pwallet->mapWallet[hash]); + + // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: + if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000)) + return DB_NEED_REWRITE; + + if (wss.nFileVersion < CLIENT_VERSION) // Update + this->WriteVersion(CLIENT_VERSION); + + if (wss.fAnyUnordered) + result = ReorderTransactions(pwallet); + + pwallet->laccentries.clear(); + ListAccountCreditDebit("*", pwallet->laccentries); + BOOST_FOREACH(CAccountingEntry & entry, pwallet->laccentries) + { + pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx *) 0, &entry))); + } + + LogPrintf("======CWalletDB::LoadWallet exit!======\n"); + + return result; +} + + +bool CWalletTx::resetImage(uint256 expectedHash, const std::vector& imageList) +{ + bool res = false; + if (this->vout.size() == imageList.size()) { + + LogPrintf("CWalletTx::resetImage\n"); + + for (size_t i = 0; i < imageList.size(); ++i) { + std::vector &txOut = *const_cast*>(&this->vout); + txOut[i].imgbase64 = imageList[i]; + } + + int i = 0; + for (auto &out : this->vout) { + LogPrintf(" image.dat: imgbase64[%d] len: %lu\n", i++, out.imgbase64.length()); + } + this->UpdateHash(); + LogPrintf("txHash with image: %s\n", this->GetHash().ToString().c_str()); + + if (this->GetHash() == expectedHash) { + res = true; + } else { + LogPrintf("Invalid tx hash! expected hash<%s>, updated hash<%s>\n", + expectedHash.ToString().c_str(), GetHash().ToString().c_str()); + } + + } else { + LogPrintf("wtx.vout.size() != imageList.size()\n"); + } + return res; +} + + bool CWalletDB::EraseTx(uint256 hash) { nWalletDBUpdateCounter++; From 8ae9ba8aa0a7908731f8e65a7aecb7d36ed71de5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:02:14 -0400 Subject: [PATCH 0513/1324] Update transactionview.h --- src/qt/transactionview.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index 334d2052..04e08333 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -70,6 +70,7 @@ class TransactionView : public QWidget QComboBox *instantsendWidget; QLineEdit *addressWidget; QLineEdit *amountWidget; + QLineEdit *imgbase64Widget; QMenu *contextMenu; QSignalMapper *mapperThirdPartyTxUrls; @@ -102,6 +103,7 @@ private Q_SLOTS: void openThirdPartyTxUrl(QString url); void updateWatchOnlyColumn(bool fHaveWatchOnly); void abandonTx(); + void copyImgbase64(); Q_SIGNALS: void doubleClicked(const QModelIndex&); From 01c17482b94ca067e104798522a63e851b33cf5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:03:15 -0400 Subject: [PATCH 0514/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 7f6274b6..6630fb40 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -80,7 +80,7 @@ public Q_SLOTS: /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = ""); + void gotoSendCoinsPage(QString addr = "",QString imgbase64 = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); From a1557d73c44b267a203e1cef27bd4d52df505666 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:05:28 -0400 Subject: [PATCH 0515/1324] Update transactionview.cpp --- src/qt/transactionview.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 7f2be564..437790c2 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -119,6 +119,13 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa #endif addressWidget->setObjectName("addressWidget"); hlayout->addWidget(addressWidget); + + // imgbase64Widget = new QLineEdit(this); +// #if QT_VERSION >= 0x040700 +// imgbase64Widget->setPlaceholderText(tr("Enter Imgbase64 to search")); +// #endif +// imgbase64Widget->setObjectName("imgbase64Widget"); +// hlayout->addWidget(imgbase64Widget); amountWidget = new QLineEdit(this); #if QT_VERSION >= 0x040700 @@ -169,6 +176,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *showDetailsAction = new QAction(tr("Show transaction details"), this); QAction *showAddressQRCodeAction = new QAction(tr("Show address QR code"), this); + QAction *copyImgbase64Action = new QAction(tr("Copy img"), this); contextMenu = new QMenu(this); contextMenu->addAction(copyAddressAction); @@ -182,6 +190,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa contextMenu->addSeparator(); contextMenu->addAction(abandonAction); contextMenu->addAction(editLabelAction); + contextMenu->addAction(copyImgbase64Action); mapperThirdPartyTxUrls = new QSignalMapper(this); @@ -194,6 +203,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa connect(instantsendWidget, SIGNAL(activated(int)), this, SLOT(chooseInstantSend(int))); connect(addressWidget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString))); connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString))); + //connect(imgbase64Widget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString))); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(computeSum())); @@ -209,6 +219,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); connect(showAddressQRCodeAction, SIGNAL(triggered()), this, SLOT(showAddressQRCode())); + connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); } void TransactionView::setModel(WalletModel *_model) @@ -240,6 +251,7 @@ void TransactionView::setModel(WalletModel *_model) transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Imgbase64, TYPE_COLUMN_WIDTH); // Note: it's a good idea to connect this signal AFTER the model is set connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); @@ -410,6 +422,7 @@ void TransactionView::exportClicked() writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole); writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole); + writer.addColumn(tr("Imgbase64"), 0, TransactionTableModel::Imgbase64Role); if(!writer.write()) { Q_EMIT message(tr("Exporting Failed"), tr("There was an error trying to save the transaction history to %1.").arg(filename), @@ -464,6 +477,11 @@ void TransactionView::copyAddress() GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole); } +void TransactionView::copyImgbase64() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); +} + void TransactionView::copyLabel() { GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole); From 29394442fedba71f053514b8ff334a3c0faf3351 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:07:05 -0400 Subject: [PATCH 0516/1324] Update transactiontablemodel.h --- src/qt/transactiontablemodel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index 81c94dcf..2cba491c 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -34,6 +34,7 @@ class TransactionTableModel : public QAbstractTableModel Date = 3, Type = 4, ToAddress = 5, + Imgbase64 = 5, Amount = 6 }; @@ -59,6 +60,7 @@ class TransactionTableModel : public QAbstractTableModel AddressRole, /** Label of address related to transaction */ LabelRole, + Imgbase64Role, /** Net amount of transaction */ AmountRole, /** Unique identifier */ From 0eb18a8e38f4275fe37971de2eca5c660c519ff5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:09:13 -0400 Subject: [PATCH 0517/1324] Update wallet.h --- src/wallet/wallet.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 49026792..0113ab92 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -173,6 +173,7 @@ struct CRecipient { CScript scriptPubKey; CAmount nAmount; + std::string imgbase64; bool fSubtractFeeFromAmount; // DAC: @@ -207,6 +208,7 @@ struct COutputEntry { CTxDestination destination; CAmount amount; + std::string imgbase64; int vout; }; @@ -598,6 +600,7 @@ class CAccountingEntry public: std::string strAccount; CAmount nCreditDebit; + std::string imgbase64; int64_t nTime; std::string strOtherAccount; std::string strComment; @@ -619,6 +622,7 @@ class CAccountingEntry strComment.clear(); nOrderPos = -1; nEntryNo = 0; + imgbase64.clear(); } ADD_SERIALIZE_METHODS; @@ -632,6 +636,7 @@ class CAccountingEntry READWRITE(nCreditDebit); READWRITE(nTime); READWRITE(LIMITED_STRING(strOtherAccount, 65536)); + READWRITE(LIMITED_STRING(imgbase64, 1655366)); if (!ser_action.ForRead()) { From eb8526580064d6399635f33e115dd2d614471b50 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:10:44 -0400 Subject: [PATCH 0518/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index c2d4ef11..5cc7c836 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -255,7 +255,7 @@ private Q_SLOTS: /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = ""); + void gotoSendCoinsPage(QString addr = "", QString imgbase64=""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); From 1347258b1cef78b3552f161666559b5cd3729c81 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:11:53 -0400 Subject: [PATCH 0519/1324] Update walletmodel.cpp --- src/qt/walletmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index ab235c43..4bf18187 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -278,7 +278,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact const unsigned char* scriptStr = (const unsigned char*)out.script().data(); CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); CAmount nAmount = out.amount(); - CRecipient recipient = {scriptPubKey, nAmount, rcp.fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, nAmount, rcp.imgbase64.toStdString() , rcp.fSubtractFeeFromAmount}; vecSend.push_back(recipient); } if (subtotal <= 0) @@ -301,7 +301,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact ++nAddresses; CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); - CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, rcp.amount, rcp.imgbase64.toStdString(), rcp.fSubtractFeeFromAmount}; vecSend.push_back(recipient); total += rcp.amount; From f997c735dca0039103d05fdfdd80f380f72478ae Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:19:14 -0400 Subject: [PATCH 0520/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 121 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7c116009..30258a91 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1769,7 +1769,7 @@ void CWalletTx::GetAmounts(std::list& listReceived, address = CNoDestination(); } - COutputEntry output = {address, txout.nValue, (int)i}; + COutputEntry output = {address, txout.nValue, txout.imgbase64 , (int)i}; // If we are debited by the transaction, add the output as a "sent" entry if (nDebit > 0) @@ -2893,10 +2893,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov std::vector vecSend; // Turn the txout set into a CRecipient vector - for (size_t idx = 0; idx < tx.vout.size(); idx++) + BOOST_FOREACH(const CTxOut& txOut, tx.vout) { - const CTxOut& txOut = tx.vout[idx]; - CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1}; + CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, txOut.imgbase64, false}; vecSend.push_back(recipient); } @@ -3243,6 +3242,7 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std CReserveKey reservekey(this); CAmount nValue = 0; + std::string imgbase64=""; CTxDSIn txdsinCollateral; if (!GetCollateralTxDSIn(txdsinCollateral, nValue)) { @@ -3269,7 +3269,10 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std // create dummy data output only and pay everything as a fee txCollateral.vout.push_back(CTxOut(0, CScript() << OP_RETURN)); } - + //pay collateral charge in fees + CTxOut txout = CTxOut(nValue - CPrivateSend::GetCollateralAmount(), scriptChange, imgbase64 ); + txCollateral.vout.push_back(txout); + if (!SignSignature(*this, txdsinCollateral.prevPubKey, txCollateral, 0)) { strReason = "Unable to sign collateral transaction!"; return false; @@ -3278,7 +3281,7 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std return true; } -bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend, const COutPoint& outpoint) +bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend) { // make our change address CReserveKey reservekey(this); @@ -3289,14 +3292,11 @@ bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount a CAmount nFeeRet = 0; int nChangePosRet = -1; std::string strFail = ""; - std::vector< CRecipient > vecSend; - vecSend.push_back((CRecipient){scriptChange, amount, false}); + vector< CRecipient > vecSend; + vecSend.push_back((CRecipient){scriptChange, amount, tx.mapValue["imgbase64"] , false}); - CCoinControl coinControl; - if (!outpoint.IsNull()) { - coinControl.Select(outpoint); - } - bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, &coinControl, true, ALL_COINS, fUseInstantSend); + CCoinControl *coinControl=NULL; + bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, coinControl, true, ALL_COINS, fUseInstantSend); if(!success){ LogPrintf("CWallet::GetBudgetSystemCollateralTX -- Error: %s\n", strFail); return false; @@ -3323,25 +3323,18 @@ bool CWallet::ConvertList(std::vector vecTxIn, std::vector& vecA return true; } -bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, - int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, AvailableCoinsType nCoinType, bool fUseInstantSend, int nExtraPayloadSize) +bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, + int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl, bool sign, AvailableCoinsType nCoinType, bool fUseInstantSend) { - if (!llmq::IsOldInstantSendEnabled()) { - // The new system does not require special handling for InstantSend as this is all done in CInstantSendManager. - // There is also no need for an extra fee anymore. - fUseInstantSend = false; - } - - CAmount nFeePay = fUseInstantSend ? CTxLockRequest().GetMinFee(true) : 0; - + CAmount nFeePay = fUseInstantSend ? CTxLockRequest().GetMinFee() : 0; + std::string imgbase64=""; CAmount nValue = 0; - int nChangePosRequest = nChangePosInOut; unsigned int nSubtractFeeFromAmount = 0; - for (const auto& recipient : vecSend) + BOOST_FOREACH (const CRecipient& recipient, vecSend) { if (nValue < 0 || recipient.nAmount < 0) { - strFailReason = _("Transaction amounts must not be negative"); + strFailReason = _("Transaction amounts must be positive"); return false; } nValue += recipient.nAmount; @@ -3349,9 +3342,9 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT if (recipient.fSubtractFeeFromAmount) nSubtractFeeFromAmount++; } - if (vecSend.empty()) + if (vecSend.empty() || nValue < 0) { - strFailReason = _("Transaction must have at least one recipient"); + strFailReason = _("Transaction amounts must be positive"); return false; } @@ -3359,6 +3352,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT wtxNew.BindWallet(this); CMutableTransaction txNew; + // Discourage fee sniping. // // For a large miner the value of the transactions in the best block and @@ -3393,32 +3387,29 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT assert(txNew.nLockTime < LOCKTIME_THRESHOLD); { - std::set > setCoins; - std::vector vecTxDSInTmp; LOCK2(cs_main, cs_wallet); { - std::vector vAvailableCoins; - AvailableCoins(vAvailableCoins, true, coinControl, false, nCoinType, fUseInstantSend); - int nInstantSendConfirmationsRequired = Params().GetConsensus().nInstantSendConfirmationsRequired; - nFeeRet = 0; if(nFeePay > 0) nFeeRet = nFeePay; // Start with no fee and loop until there is enough fee while (true) { - nChangePosInOut = nChangePosRequest; txNew.vin.clear(); txNew.vout.clear(); wtxNew.fFromMe = true; + nChangePosRet = -1; bool fFirst = true; CAmount nValueToSelect = nValue; if (nSubtractFeeFromAmount == 0) nValueToSelect += nFeeRet; + double dPriority = 0; // vouts to the payees - for (const auto& recipient : vecSend) + BOOST_FOREACH (const CRecipient& recipient, vecSend) { - CTxOut txout(recipient.nAmount, recipient.scriptPubKey); + + CTxOut txout(recipient.nAmount, recipient.scriptPubKey, recipient.imgbase64); + if (recipient.fSubtractFeeFromAmount) { @@ -3431,7 +3422,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT } } - if (txout.IsDust(dustRelayFee)) + if (txout.IsDust(::minRelayTxFee)) { if (recipient.fSubtractFeeFromAmount && nFeeRet > 0) { @@ -3448,9 +3439,10 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT } // Choose coins to use + set > setCoins; CAmount nValueIn = 0; - setCoins.clear(); - if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, nValueIn, coinControl, nCoinType, fUseInstantSend)) + + if (!SelectCoins(nValueToSelect, setCoins, nValueIn, coinControl, nCoinType, fUseInstantSend)) { if (nCoinType == ONLY_NONDENOMINATED) { strFailReason = _("Unable to locate enough PrivateSend non-denominated funds for this transaction."); @@ -3461,17 +3453,31 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT strFailReason = _("Insufficient funds."); if (fUseInstantSend) { // could be not true but most likely that's the reason - strFailReason += " " + strprintf(_("InstantSend requires inputs with at least %d confirmations, you might need to wait a few minutes and try again."), nInstantSendConfirmationsRequired); + strFailReason += " " + strprintf(_("InstantSend requires inputs with at least %d confirmations, you might need to wait a few minutes and try again."), INSTANTSEND_CONFIRMATIONS_REQUIRED); } } return false; } if (fUseInstantSend && nValueIn > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) { - strFailReason += " " + strprintf(_("InstantSend doesn't support sending values that high yet. Transactions are currently limited to %1 HTH."), sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)); + strFailReason += " " + strprintf(_("InstantSend doesn't support sending values that high yet. Transactions are currently limited to %1 DASH."), sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)); return false; } + BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) + { + CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; + //The coin age after the next block (depth+1) is used instead of the current, + //reflecting an assumption the user would accept a bit more delay for + //a chance at a free transaction. + //But mempool inputs might still be in the mempool, so their age stays 0 + int age = pcoin.first->GetDepthInMainChain(); + assert(age >= 0); + if (age != 0) + age += 1; + dPriority += (double)nCredit * age; + } + const CAmount nChange = nValueIn - nValueToSelect; CTxOut newTxOut; @@ -3482,6 +3488,8 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT if (nCoinType == ONLY_DENOMINATED) { nFeeRet += nChange; wtxNew.mapValue["DS"] = "1"; + // recheck skipped denominations during next mixing + privateSendClient.ClearSkippedDenominations(); } else { // Fill a vout to ourself @@ -3513,21 +3521,21 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT scriptChange = GetScriptForDestination(vchPubKey.GetID()); } - newTxOut = CTxOut(nChange, scriptChange); + newTxOut = CTxOut(nChange, scriptChange, imgbase64); // We do not move dust-change to fees, because the sender would end up paying more than requested. // This would be against the purpose of the all-inclusive feature. // So instead we raise the change and deduct from the recipient. - if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(dustRelayFee)) + if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(::minRelayTxFee)) { - CAmount nDust = newTxOut.GetDustThreshold(dustRelayFee) - newTxOut.nValue; + CAmount nDust = newTxOut.GetDustThreshold(::minRelayTxFee) - newTxOut.nValue; newTxOut.nValue += nDust; // raise change until no more dust for (unsigned int i = 0; i < vecSend.size(); i++) // subtract from first recipient { if (vecSend[i].fSubtractFeeFromAmount) { txNew.vout[i].nValue -= nDust; - if (txNew.vout[i].IsDust(dustRelayFee)) + if (txNew.vout[i].IsDust(::minRelayTxFee)) { strFailReason = _("The transaction amount is too small to send after the fee has been deducted"); return false; @@ -3539,30 +3547,21 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT // Never create dust outputs; if we would, just // add the dust to the fee. - if (newTxOut.IsDust(dustRelayFee)) + if (newTxOut.IsDust(::minRelayTxFee)) { - nChangePosInOut = -1; nFeeRet += nChange; reservekey.ReturnKey(); } else { - if (nChangePosInOut == -1) - { - // Insert change txn at random position: - nChangePosInOut = GetRandInt(txNew.vout.size()+1); - } - else if ((unsigned int)nChangePosInOut > txNew.vout.size()) - { - strFailReason = _("Change index out of range"); - return false; - } - - std::vector::iterator position = txNew.vout.begin()+nChangePosInOut; + // Insert change txn at random position: + nChangePosRet = GetRandInt(txNew.vout.size()+1); + vector::iterator position = txNew.vout.begin()+nChangePosRet; txNew.vout.insert(position, newTxOut); } } - } else { + } + else reservekey.ReturnKey(); nChangePosInOut = -1; } From b8539bd7b7bbf7d6457934d2f04c1b796d10e4a0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:20:25 -0400 Subject: [PATCH 0521/1324] Update paymentserver.cpp --- src/qt/paymentserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 38c180c9..9d5fed55 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -580,7 +580,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen } // Extract and check amounts - CTxOut txOut(sendingTo.second, sendingTo.first); + CTxOut txOut(sendingTo.second, sendingTo.first,recipient.imgbase64.toUtf8().constData()); if (txOut.IsDust(dustRelayFee)) { Q_EMIT message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).") .arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)), From 85032454252ff34b684e4adc3ab7a9f29bb80ca8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:21:11 -0400 Subject: [PATCH 0522/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5ffe73e4..a6eba479 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1161,10 +1161,10 @@ void BitcoinGUI::gotoReceiveCoinsPage() if (walletFrame) walletFrame->gotoReceiveCoinsPage(); } -void BitcoinGUI::gotoSendCoinsPage(QString addr) +oid BitcoinGUI::gotoSendCoinsPage(QString addr,QString imgbase64) { sendCoinsAction->setChecked(true); - if (walletFrame) walletFrame->gotoSendCoinsPage(addr); + if (walletFrame) walletFrame->gotoSendCoinsPage(addr,imgbase64); } void BitcoinGUI::gotoSignMessageTab(QString addr) From 7c92b2348a8efab4e810be2a2ea4a91a2adb4c20 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:22:39 -0400 Subject: [PATCH 0523/1324] Update validation.cpp --- src/validation.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 17822dab..8a4fd700 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1386,6 +1386,15 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs))) return false; + + for (unsigned int i = 0; i < tx.vout.size(); i++) + { + if(tx.vout[i].imgbase64.size()>25000000){ + LogPrint("bench", "Large length imgbase64 checkInputs"); + return false; + } + } + if (pvChecks) pvChecks->reserve(tx.vin.size()); From 00999a34a200a1d0a17d58683b83b8d6bdee0a85 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:18:37 -0400 Subject: [PATCH 0524/1324] Update transaction.cpp --- src/primitives/transaction.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index e831de33..a6bec141 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -48,20 +48,16 @@ std::string CTxIn::ToString() const return str; } -CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, std::string imgbase64in, int nRoundsIn) +CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, int nRoundsIn) { nValue = nValueIn; scriptPubKey = scriptPubKeyIn; - if(imgbase64.size()<=1000000000){ - imgbase64=imgbase64in; - } - else throw std::runtime_error("CTxOut::Imgbase64in(): value out of range"); nRounds = nRoundsIn; } std::string CTxOut::ToString() const { - return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s, imgbase64=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30), imgbase64); + return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30)); } CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nLockTime(0) {} From 3af862b012f88da3af20706e0502ad413a13a1bd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:19:09 -0400 Subject: [PATCH 0525/1324] Update transaction.h --- src/primitives/transaction.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index bba8947e..76cdc346 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -146,7 +146,6 @@ class CTxOut public: CAmount nValue; CScript scriptPubKey; - std::string imgbase64; int nRounds; CTxOut() @@ -154,7 +153,7 @@ class CTxOut SetNull(); } - CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, std::string imgbase64, int nRoundsIn = -10); + CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn, int nRoundsIn = -10); ADD_SERIALIZE_METHODS; @@ -162,14 +161,12 @@ class CTxOut inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(nValue); READWRITE(*(CScriptBase*)(&scriptPubKey)); - READWRITE(imgbase64); } void SetNull() { nValue = -1; scriptPubKey.clear(); - imgbase64=""; nRounds = -10; // an initial value, should be no way to get this by calculations } @@ -203,7 +200,6 @@ class CTxOut { return (a.nValue == b.nValue && a.scriptPubKey == b.scriptPubKey && - a.imgbase64 == b.imgbase64 && a.nRounds == b.nRounds); } From 9cd65377cb98c29a77acd9705a11be254f777a98 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:21:11 -0400 Subject: [PATCH 0526/1324] Update rpcwallet.cpp --- src/wallet/rpcwallet.cpp | 150 ++++++++++++--------------------------- 1 file changed, 47 insertions(+), 103 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a2cd4fb..fbd76bc7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -378,7 +378,7 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA std::string strError; std::vector vecSend; int nChangePosRet = -1; - CRecipient recipient = {scriptPubKey, nValue, wtxNew.mapValue["imgbase64"], fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; vecSend.push_back(recipient); if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend)) { @@ -422,14 +422,13 @@ UniValue sendtoaddress(const JSONRPCRequest& request) " The recipient will receive less amount of Dash than you enter in the amount field.\n" "6. \"use_is\" (bool, optional, default=false) Send this transaction as InstantSend\n" "7. \"use_ps\" (bool, optional, default=false) Use anonymized funds only\n" - "8. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "\nResult:\n" "\"txid\" (string) The transaction id.\n" "\nExamples:\n" + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1") - + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"imgbase64\" \"donation\" \"seans outpost\"") - + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"\" \"\" \"\" true") - + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.1, \"imgbase64\" \"donation\", \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"\" \"\" true") + + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwallet->cs_wallet); @@ -445,38 +444,25 @@ UniValue sendtoaddress(const JSONRPCRequest& request) // Wallet comments CWalletTx wtx; - if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) - { - wtx.mapValue["imgbase64"] = ""; - if(params[2].get_str().size()<10000000){ - wtx.mapValue["imgbase64"] = params[2].get_str(); - } - else if (params[2].get_str().size()>10000000){ - throw JSONRPCError(RPC_TYPE_ERROR, "Imgbase64 max length is 10000000"); - } - else if (!base64rpcwallet.base64Validator(params[2].get_str())) { - throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); - } - } - if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty()) - wtx.mapValue["comment"] = params[3].get_str(); - if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty()) - wtx.mapValue["to"] = params[4].get_str(); + if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty()) + wtx.mapValue["comment"] = request.params[2].get_str(); + if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) + wtx.mapValue["to"] = request.params[3].get_str(); bool fSubtractFeeFromAmount = false; - if (params.size() > 5) - fSubtractFeeFromAmount = params[5].get_bool(); + if (request.params.size() > 4) + fSubtractFeeFromAmount = request.params[4].get_bool(); bool fUseInstantSend = false; bool fUsePrivateSend = false; - if (params.size() > 6) - fUseInstantSend = params[6].get_bool(); - if (params.size() > 7) - fUsePrivateSend = params[7].get_bool(); + if (request.params.size() > 5) + fUseInstantSend = request.params[5].get_bool(); + if (request.params.size() > 6) + fUsePrivateSend = request.params[6].get_bool(); - EnsureWalletIsUnlocked(); + EnsureWalletIsUnlocked(pwallet); - SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend); + SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend); return wtx.GetHash().GetHex(); } @@ -493,7 +479,6 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request) "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" + HelpRequiringPassphrase(pwallet) + "\nArguments:\n" - "3. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"address\" (string, required) The dash address to send to.\n" "2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" @@ -523,7 +508,23 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request) if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); - "3. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" + // Wallet comments + CWalletTx wtx; + if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty()) + wtx.mapValue["comment"] = request.params[2].get_str(); + if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty()) + wtx.mapValue["to"] = request.params[3].get_str(); + + bool fSubtractFeeFromAmount = false; + if (request.params.size() > 4) + fSubtractFeeFromAmount = request.params[4].get_bool(); + + EnsureWalletIsUnlocked(pwallet); + + SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true); + + return wtx.GetHash().GetHex(); +} UniValue listaddressgroupings(const JSONRPCRequest& request) { @@ -910,7 +911,6 @@ UniValue movecmd(const JSONRPCRequest& request) "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n" "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n" "\nArguments:\n" - "0. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n" "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n" "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" @@ -937,54 +937,13 @@ UniValue movecmd(const JSONRPCRequest& request) if (request.params.size() > 3) // unused parameter, used to be nMinDepth, keep type-checking it though (void)request.params[3].get_int(); - - string strimgbase64; - if (params.size() > 4 && !params[4].get_str().empty()){ - - if(params[4].get_str().size()<10000000){ - strimgbase64 = params[4].get_str(); - } - else if (params[4].get_str().size()>10000000){ - throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64, or max length is 10000000"); - } - else if (params[4].get_str().size()>2 && !base64rpcwallet.base64Validator(params[4].get_str())) { - throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); - } - } - string strComment; - if (params.size() > 5) - strComment = params[5].get_str(); - - CWalletDB walletdb(pwalletMain->strWalletFile); - if (!walletdb.TxnBegin()) - throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); + std::string strComment; + if (request.params.size() > 4) + strComment = request.params[4].get_str(); - int64_t nNow = GetAdjustedTime(); - - // Debit - CAccountingEntry debit; - debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); - debit.strAccount = strFrom; - debit.nCreditDebit = -nAmount; - debit.imgbase64 = strimgbase64; - debit.nTime = nNow; - debit.strOtherAccount = strTo; - debit.strComment = strComment; - pwalletMain->AddAccountingEntry(debit, walletdb); - - // Credit - CAccountingEntry credit; - credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); - credit.strAccount = strTo; - credit.nCreditDebit = nAmount; - credit.imgbase64 = strimgbase64; - credit.nTime = nNow; - credit.strOtherAccount = strFrom; - credit.strComment = strComment; - pwalletMain->AddAccountingEntry(credit, walletdb); - - if (!walletdb.TxnCommit()) + if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) { throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); + } return true; } @@ -1003,7 +962,6 @@ UniValue sendfrom(const JSONRPCRequest& request) "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a dash address." + HelpRequiringPassphrase(pwallet) + "\n" "\nArguments:\n" - "0. \"imgbase64\" (string, optional) A imgbase64 used to store base64 encode of img. \n" "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" " Specifying an account does not influence coin selection, but it does associate the newly created\n" " transaction with the account, so the account's balance computation and transaction history can reflect\n" @@ -1044,35 +1002,24 @@ UniValue sendfrom(const JSONRPCRequest& request) CWalletTx wtx; wtx.strFromAccount = strAccount; - if (params.size() > 5 && !params[5].isNull() && !params[5].get_str().empty()){ - wtx.mapValue["imgbase64"] = ""; - if(params[5].get_str().size()<10000000){ - wtx.mapValue["imgbase64"] = params[5].get_str(); - } - else if (params[5].get_str().size()>10000000){ - throw JSONRPCError(RPC_TYPE_ERROR, "Imgbase64 max length is 10000000"); - } - else if (!base64rpcwallet.base64Validator(params[5].get_str())) { - throw JSONRPCError(RPC_TYPE_ERROR, "Invalid imgbase64"); - } - } - if (params.size() > 6 && !params[6].isNull() && !params[6].get_str().empty()) - wtx.mapValue["comment"] = params[6].get_str(); - if (params.size() > 7 && !params[7].isNull() && !params[7].get_str().empty()) - wtx.mapValue["to"] = params[7].get_str(); - - EnsureWalletIsUnlocked(); + if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty()) + wtx.mapValue["comment"] = request.params[5].get_str(); + if (request.params.size() > 6 && !request.params[6].isNull() && !request.params[6].get_str().empty()) + wtx.mapValue["to"] = request.params[6].get_str(); + + EnsureWalletIsUnlocked(pwallet); // Check funds - CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf); + CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLocked); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); - SendMoney(address.Get(), nAmount, false, wtx); + SendMoney(pwallet, address.Get(), nAmount, false, wtx); return wtx.GetHash().GetHex(); } + UniValue sendmany(const JSONRPCRequest& request) { CWallet * const pwallet = GetWalletForJSONRPCRequest(request); @@ -1519,7 +1466,6 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std:: std::map::const_iterator it = wtx.mapValue.find("DS"); entry.push_back(Pair("category", (it != wtx.mapValue.end() && it->second == "1") ? "privatesend" : "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); - entry.push_back(Pair("imgbase64",s.imgbase64)); if (pwallet->mapAddressBook.count(s.destination)) { entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name)); } @@ -1563,7 +1509,6 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std:: entry.push_back(Pair("category", "receive")); } entry.push_back(Pair("amount", ValueFromAmount(r.amount))); - entry.push_back(Pair("imgbase64",r.imgbase64)); if (pwallet->mapAddressBook.count(r.destination)) { entry.push_back(Pair("label", account)); } @@ -1587,7 +1532,6 @@ void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccoun entry.push_back(Pair("category", "move")); entry.push_back(Pair("time", acentry.nTime)); entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit))); - entry.push_back(Pair("imgbase64", acentry.imgbase64)); entry.push_back(Pair("otheraccount", acentry.strOtherAccount)); entry.push_back(Pair("comment", acentry.strComment)); ret.push_back(entry); From d4acff091c992bbcb1200838e76f1244f726bec9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:21:48 -0400 Subject: [PATCH 0527/1324] Update wallet.h --- src/wallet/wallet.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0113ab92..ef17e23d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -173,14 +173,7 @@ struct CRecipient { CScript scriptPubKey; CAmount nAmount; - std::string imgbase64; bool fSubtractFeeFromAmount; - // DAC: - - bool fDonate; - - std::string txtMessage; - // END OF DAC }; typedef std::map mapValue_t; @@ -208,7 +201,6 @@ struct COutputEntry { CTxDestination destination; CAmount amount; - std::string imgbase64; int vout; }; @@ -600,7 +592,6 @@ class CAccountingEntry public: std::string strAccount; CAmount nCreditDebit; - std::string imgbase64; int64_t nTime; std::string strOtherAccount; std::string strComment; @@ -622,7 +613,6 @@ class CAccountingEntry strComment.clear(); nOrderPos = -1; nEntryNo = 0; - imgbase64.clear(); } ADD_SERIALIZE_METHODS; @@ -636,7 +626,6 @@ class CAccountingEntry READWRITE(nCreditDebit); READWRITE(nTime); READWRITE(LIMITED_STRING(strOtherAccount, 65536)); - READWRITE(LIMITED_STRING(imgbase64, 1655366)); if (!ser_action.ForRead()) { From bbf067679f934c23c6f86bd26e6b97ff281ae102 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:22:22 -0400 Subject: [PATCH 0528/1324] Update walletdb.cpp --- src/wallet/walletdb.cpp | 338 +--------------------------------------- 1 file changed, 3 insertions(+), 335 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index debf34e5..645c8b21 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -56,344 +56,12 @@ bool CWalletDB::ErasePurpose(const std::string& strPurpose) return Erase(make_pair(std::string("purpose"), strPurpose)); } -bool CWalletDB::WriteTx(uint256 hash, const CWalletTx &tx) +bool CWalletDB::WriteTx(const CWalletTx& wtx) { - nWalletDBUpdated++; - - bool res = false; - if (m_imageDB == 0) - { - this->Write(std::make_pair(std::string("tx"), hash), tx); - } - else - { - CWalletTx wtx = tx; - std::vector image; - - std::vector &vout = (*const_cast*>(&wtx.vout)); - - for (auto &e : vout) { - image.push_back(e.imgbase64); - e.imgbase64 = ""; - } - - res = m_imageDB->setImage(hash, image); - if (res) { - res = this-Write(std::make_pair(std::string("tx"), hash), wtx); - LogPrintf("CWalletDB::WriteTx: hash<%s>, success<%d>\n", hash.ToString().c_str(), res); - } - } - - return res; -} - -bool ReadKeyValue(CWallet* pwallet, - CDataStream& ssKey, - CDataStream& ssValue, - CWalletScanState &wss, - string& strType, - string& strErr, - CImageDB* idb = 0); - - -// ================================= -// loadImage -bool CImageDB::readKeyValue(CDataStream& ssKey, CDataStream& ssValue, - int &nFileVersion, string& strType) -{ - try { - ssKey >> strType; - LogPrintf("==============================================\n"); - LogPrintf("CImageDB::readKeyValue. strType: %s\n", strType.c_str()); - - if (strType == "image") - { - uint256 hash; - ssKey >> hash; - ssValue >> m_imageMap[hash]; - LogPrintf("CImageDB tx hash:%s\n", hash.ToString().c_str()); - int i = 0; - for (auto &imgbase64 : m_imageMap[hash]) { - LogPrintf(" imgbase64[%d] len: %lu\n", i++, imgbase64.length()); - } - } - else if (strType == "version") - { - ssValue >> nFileVersion; - LogPrintf("CImageDB::ReadKeyValue version: %d\n", nFileVersion); - } - else if (strType == "minversion") - { - int minversion; - ssValue >> minversion; - LogPrintf("CImageDB::ReadKeyValue minversion: %d\n", minversion); - } - } catch (...) - { - return false; - } - - return true; -} - -DBErrors CImageDB::loadImage() -{ - DBErrors result = DB_LOAD_OK; - bool fNoncriticalErrors = false; - LogPrintf("CImageDB::loadImage: enter\n"); - int nFileVersion = 0; - try { - - int nMinVersion = 0; - if (Read((string)"minversion", nMinVersion)) - { - LogPrintf("CImageDB::loadImage: nMinVersion is %d\n", nMinVersion); - if (nMinVersion > CLIENT_VERSION) - return DB_TOO_NEW; - } - else - { - LogPrintf("CImageDB::loadImage: Failed to load nMinVersion\n"); - } - // Get cursor - Dbc* pcursor = CDB::GetCursor(); - if (!pcursor) - { - LogPrintf("Error getting image database cursor\n"); - return DB_CORRUPT; - } - - while (true) - { - // Read next record - CDataStream ssKey(SER_DISK, CLIENT_VERSION); - CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = CDB::ReadAtCursor(pcursor, ssKey, ssValue); - if (ret == DB_NOTFOUND) - break; - else if (ret != 0) - { - LogPrintf("Error reading next record from wallet database\n"); - return DB_CORRUPT; - } - - string strType; - if (!this->readKeyValue(ssKey, ssValue, nFileVersion, strType)) - { - // read error - if (strType == "image") - { - // rescan if failed to read an image - fNoncriticalErrors = true; // ... but do warn the user there is something wrong. - SoftSetBoolArg("-rescan", true); - } - else - { - result = DB_CORRUPT; - } - } - } - pcursor->close(); - } - catch (const boost::thread_interrupted&) { - throw; - } - catch (...) { - result = DB_CORRUPT; - } - - if (fNoncriticalErrors && result == DB_LOAD_OK) - result = DB_NONCRITICAL_ERROR; - - if (result != DB_LOAD_OK) - return result; - - if (nFileVersion < CLIENT_VERSION) // Update - this->WriteVersion(CLIENT_VERSION); - - LogPrintf("CImageDB::loadImage exit!\n"); - return result; -} - -// DBErrors CImageDB::loadImage() -// ======================================================= -DBErrors CWalletDB::LoadWallet(CWallet *pwallet) { - pwallet->vchDefaultKey = CPubKey(); - CWalletScanState wss; - bool fNoncriticalErrors = false; - bool imageErrors = false; - DBErrors result = DB_LOAD_OK; - - - try { - LOCK(pwallet->cs_wallet); - if (m_imageDB != 0) - { - DBErrors res = m_imageDB->loadImage(); - if (res != DB_LOAD_OK) { - LogPrintf("Failed to loadImage. result: %d\n", result); - } - } - - LogPrintf("======CWalletDB::LoadWallet start======\n"); - int nMinVersion = 0; - if (Read((string) "minversion", nMinVersion)) { - - LogPrintf("CWalletDb::LoadWallet ReadKeyValue: minversion: %d\n", nMinVersion); - - if (nMinVersion > CLIENT_VERSION) - return DB_TOO_NEW; - - pwallet->LoadMinVersion(nMinVersion); - } - - // Get cursor - Dbc *pcursor = CDB::GetCursor(); - if (!pcursor) { - LogPrintf("Error getting wallet database cursor\n"); - return DB_CORRUPT; - } - - std::map failedKey; - std::map successKey; - - while (true) { - // Read next record - CDataStream ssKey(SER_DISK, CLIENT_VERSION); - CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = CDB::ReadAtCursor(pcursor, ssKey, ssValue); - if (ret == DB_NOTFOUND) - break; - else if (ret != 0) { - LogPrintf("Error reading next record from wallet database\n"); - return DB_CORRUPT; - } - - // Try to be tolerant of single corrupt records: - string strType, strErr; - if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr, m_imageDB)) - { - failedKey[strType]++; - // losing keys is considered a catastrophic error, anything else - // we assume the user can live with: - if (IsKeyType(strType)) - { - result = DB_CORRUPT; - } - else { - // Leave other errors alone, if we try to fix them we might make things worse. - fNoncriticalErrors = true; // ... but do warn the user there is something wrong. - if (strType == "tx") { - LogPrintf("Rescan as there is a bad transaction record\n"); - if (strErr == "Image is invalid") { - imageErrors = true; - } - SoftSetBoolArg("-rescan", true); - } - } - } - else - { - successKey[strType]++; - } - if (!strErr.empty()) - LogPrintf("%s\n", strErr); - } - - dumpWalletDBState(successKey, "success"); - dumpWalletDBState(failedKey, "failed"); - pcursor->close(); - - // Store initial external keypool size since we mostly use external keys in mixing - pwallet->nKeysLeftSinceAutoBackup = pwallet->KeypoolCountExternalKeys(); - LogPrintf("nKeysLeftSinceAutoBackup: %d\n", pwallet->nKeysLeftSinceAutoBackup); - } - catch (const boost::thread_interrupted &) { - throw; - } - catch (...) { - result = DB_CORRUPT; - } - - if (fNoncriticalErrors && result == DB_LOAD_OK) - result = DB_NONCRITICAL_ERROR; - - if (imageErrors && result == DB_LOAD_OK) - result = DB_RESCAN_IMAGE; - - // Any wallet corruption at all: skip any rewriting or - // upgrading, we don't want to make it worse. - if (result != DB_LOAD_OK) - return result; - - LogPrintf("nFileVersion = %d\n", wss.nFileVersion); - - LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n", - wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys); - - // nTimeFirstKey is only reliable if all keys have metadata - if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta) - pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value' - - BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade) - this->WriteTx(hash, pwallet->mapWallet[hash]); - - // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: - if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000)) - return DB_NEED_REWRITE; - - if (wss.nFileVersion < CLIENT_VERSION) // Update - this->WriteVersion(CLIENT_VERSION); - - if (wss.fAnyUnordered) - result = ReorderTransactions(pwallet); - - pwallet->laccentries.clear(); - ListAccountCreditDebit("*", pwallet->laccentries); - BOOST_FOREACH(CAccountingEntry & entry, pwallet->laccentries) - { - pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx *) 0, &entry))); - } - - LogPrintf("======CWalletDB::LoadWallet exit!======\n"); - - return result; -} - - -bool CWalletTx::resetImage(uint256 expectedHash, const std::vector& imageList) -{ - bool res = false; - if (this->vout.size() == imageList.size()) { - - LogPrintf("CWalletTx::resetImage\n"); - - for (size_t i = 0; i < imageList.size(); ++i) { - std::vector &txOut = *const_cast*>(&this->vout); - txOut[i].imgbase64 = imageList[i]; - } - - int i = 0; - for (auto &out : this->vout) { - LogPrintf(" image.dat: imgbase64[%d] len: %lu\n", i++, out.imgbase64.length()); - } - this->UpdateHash(); - LogPrintf("txHash with image: %s\n", this->GetHash().ToString().c_str()); - - if (this->GetHash() == expectedHash) { - res = true; - } else { - LogPrintf("Invalid tx hash! expected hash<%s>, updated hash<%s>\n", - expectedHash.ToString().c_str(), GetHash().ToString().c_str()); - } - - } else { - LogPrintf("wtx.vout.size() != imageList.size()\n"); - } - return res; + nWalletDBUpdateCounter++; + return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx); } - bool CWalletDB::EraseTx(uint256 hash) { nWalletDBUpdateCounter++; From 4323f5aea78f477e60ab4ae2633d1506a7763d2c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:22:43 -0400 Subject: [PATCH 0529/1324] Delete base64.cpp --- src/qt/base64.cpp | 209 ---------------------------------------------- 1 file changed, 209 deletions(-) delete mode 100644 src/qt/base64.cpp diff --git a/src/qt/base64.cpp b/src/qt/base64.cpp deleted file mode 100644 index a0790d9a..00000000 --- a/src/qt/base64.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * base64.cpp - * - * Created on: 03/11/2018 - * Author: manue - */ - -#include "base64.h" -#include "util.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -base64::base64() { - // TODO Auto-generated constructor stub - - -} - -base64::~base64() { - // TODO Auto-generated destructor stub -} - - -static const uint8_t from_base64[128] = { - // 8 rows of 16 = 128 - // note: only require 123 entries, as we only lookup for <= z , which z=122 - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 62, 255, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 0, 255, 255, 255, - 255, 0, 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, 255, 255, 255, 255, 63, - 255, 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, 255, 255, 255, 255, 255 - }; - -static const char to_base64[65] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - -typedef unsigned char BYTE; - -static inline bool is_base64(BYTE c) { - return (isalnum(c) || (c == '+') || (c == '/')); -} - -std::string base64::encode(std::string filename) -{ - - std::ifstream infile; - infile.open(filename, std::ifstream::binary); - - std::vector data(100); - - std::string encodedData; - - infile.seekg(0, std::ios::end); - size_t file_size_in_byte = infile.tellg(); - data.resize(file_size_in_byte); - - infile.seekg(0, std::ios::beg); - infile.read(&data[0], file_size_in_byte); - - - encodedData = base64::base64_encode(data,data.size()); - - return encodedData; - -} - -std::vector base64::decode(std::string imgbase64) -{ - - return base64::base64_decode(imgbase64); -} - - - -std::string base64::base64_encode(std::vector buf,unsigned int bufLen) { - - std::string ret; - - try { - - // Calculate how many bytes that needs to be added to get a multiple of 3 - size_t missing = 0; - size_t ret_size = bufLen; - while ((ret_size % 3) != 0) - { - ++ret_size; - ++missing; - } - - // Expand the return string size to a multiple of 4 - ret_size = 4*ret_size/3; - - ret.clear(); - ret.reserve(ret_size); - - for (size_t i = 0; i < ret_size/4; ++i) - { - // Read a group of three bytes (avoid buffer overrun by replacing with 0) - const size_t index = i*3; - const uint8_t b3_0 = (index+0 < bufLen) ? buf[index+0] : 0; - const uint8_t b3_1 = (index+1 < bufLen) ? buf[index+1] : 0; - const uint8_t b3_2 = (index+2 < bufLen) ? buf[index+2] : 0; - - // Transform into four base 64 characters - const uint8_t b4_0 = ((b3_0 & 0xfc) >> 2); - const uint8_t b4_1 = ((b3_0 & 0x03) << 4) + ((b3_1 & 0xf0) >> 4); - const uint8_t b4_2 = ((b3_1 & 0x0f) << 2) + ((b3_2 & 0xc0) >> 6); - const uint8_t b4_3 = ((b3_2 & 0x3f) << 0); - - // Add the base 64 characters to the return value - ret.push_back(to_base64[b4_0]); - ret.push_back(to_base64[b4_1]); - ret.push_back(to_base64[b4_2]); - ret.push_back(to_base64[b4_3]); - } - - // Replace data that is invalid (always as many as there are missing bytes) - for (size_t i = 0; i != missing; ++i) - ret[ret_size - i - 1] = '='; - - LogPrintf("success: %s","encodebase64"); - - return ret; - } - catch(std::exception& e) { - - LogPrintf("exception encode: %s",e.what()); - - return ret; - } -} - - - -std::vector base64::base64_decode(std::string encoded_string) { - size_t encoded_size = encoded_string.size(); - std::vector ret; - ret.reserve(3*encoded_size/4); -try { - for (size_t i=0; i> 4); - b3[1] = ((b4[1] & 0x0f) << 4) + ((b4[2] & 0x3c) >> 2); - b3[2] = ((b4[2] & 0x03) << 6) + ((b4[3] & 0x3f)); - - ret.push_back(b3[0]); - ret.push_back(b3[1]); - ret.push_back(b3[2]); - } - - - - LogPrintf("success: %s","decodebase64"); - return ret; - } - catch(std::exception& e) { - //Other errors - std::vector vempty; - LogPrintf("exception decode: %s",e.what()); - return vempty; - } -} - - - -bool base64::base64Validator(std::string encoded_string) -{ - std::string expr="^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$"; - - return base64::regexValidate(expr,encoded_string); - -} - - - -bool base64::regexValidate(std::string expr, std::string teststring) -{ - std::regex ex(expr); - - if(teststring.size()>1000) - teststring=teststring.substr(0,1000); - - if ( std::regex_match (teststring,ex) ) { - return true; - } - - return false; -} From 19173fbe0566468beaa89abc11237f3c03f4f202 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:22:50 -0400 Subject: [PATCH 0530/1324] Delete base64.h --- src/qt/base64.h | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/qt/base64.h diff --git a/src/qt/base64.h b/src/qt/base64.h deleted file mode 100644 index 40c867af..00000000 --- a/src/qt/base64.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * base64.h - * - * Created on: 03/11/2018 - * Author: manue - */ - -#ifndef BITCOIN_QT_BASE64_H -#define BITCOIN_QT_BASE64_H - -#include -#include -#include - -class base64 { - - typedef unsigned char BYTE; - -public: - explicit base64(); - ~base64(); - std::string encode(std::string filename); - std::vector decode(std::string imgbase64); - std::string base64_encode(std::vector buf, unsigned int bufLen); - std::vector base64_decode(std::string encoded_string); - bool base64Validator(std::string encoded_string); - bool regexValidate (std::string expr, std::string teststring); -}; - -#endif /* SRC_QT_BASE64_H_ */ From a28608554bb79a5ef18747a94d5ffa78704e06a2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:23:04 -0400 Subject: [PATCH 0531/1324] Delete chatdialog.cpp --- src/qt/chatdialog.cpp | 952 ------------------------------------------ 1 file changed, 952 deletions(-) delete mode 100644 src/qt/chatdialog.cpp diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp deleted file mode 100644 index d1c770d8..00000000 --- a/src/qt/chatdialog.cpp +++ /dev/null @@ -1,952 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "chatdialog.h" -#include "ui_chatdialog.h" - -#include "addresstablemodel.h" -#include "bitcoinunits.h" -#include "clientmodel.h" -#include "coincontroldialog.h" -#include "guiutil.h" -#include "optionsmodel.h" -#include "platformstyle.h" -#include "chatentry.h" -#include "walletmodel.h" - -#include "base58.h" -#include "coincontrol.h" -#include "validation.h" // mempool and minRelayTxFee -#include "ui_interface.h" -#include "txmempool.h" -#include "wallet/wallet.h" - -#include "privatesend.h" - -#include -#include -#include -#include - -ChatDialog::ChatDialog(const PlatformStyle *platformStyle, QWidget *parent) : - QDialog(parent), - ui(new Ui::ChatDialog), - clientModel(0), - model(0), - fNewRecipientAllowed(true), - fFeeMinimized(true), - platformStyle(platformStyle) -{ - ui->setupUi(this); - QString theme = GUIUtil::getThemeName(); - - if (!platformStyle->getImagesOnButtons()) { - ui->addButton->setIcon(QIcon()); - ui->clearButton->setIcon(QIcon()); - ui->sendButton->setIcon(QIcon()); - } else { - ui->addButton->setIcon(QIcon(":/icons/" + theme + "/add")); - ui->clearButton->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->sendButton->setIcon(QIcon(":/icons/" + theme + "/send")); - - - } - - GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); - - addEntry(); - - connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); - connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); - - // Coin Control - connect(ui->pushButtonCoinControl, SIGNAL(clicked()), this, SLOT(coinControlButtonClicked())); - connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); - connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); - - // Dash specific - QSettings settings; - if (!settings.contains("bUseDarkSend")) - settings.setValue("bUseDarkSend", false); - if (!settings.contains("bUseInstantX")) - settings.setValue("bUseInstantX", false); -// - bool fUsePrivateSend = settings.value("bUseDarkSend").toBool(); - bool fUseInstantSend = settings.value("bUseInstantX").toBool(); - if(fLiteMode) { - ui->checkUsePrivateSend->setChecked(false); - ui->checkUsePrivateSend->setVisible(false); - ui->checkUseInstantSend->setVisible(false); - CoinControlDialog::coinControl->fUsePrivateSend = false; - CoinControlDialog::coinControl->fUseInstantSend = false; - } - else{ - ui->checkUsePrivateSend->setChecked(fUsePrivateSend); - ui->checkUseInstantSend->setChecked(fUseInstantSend); - CoinControlDialog::coinControl->fUsePrivateSend = fUsePrivateSend; - CoinControlDialog::coinControl->fUseInstantSend = fUseInstantSend; - } -// - connect(ui->checkUsePrivateSend, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); - connect(ui->checkUseInstantSend, SIGNAL(stateChanged ( int )), this, SLOT(updateInstantSend())); -// -// // Coin Control: clipboard actions - QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); - QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this); - QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this); - QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this); - QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this); - QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this); - QAction *clipboardChangeAction = new QAction(tr("Copy change"), this); - connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity())); - connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount())); - connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardFee())); - connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAfterFee())); - connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardBytes())); - connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardLowOutput())); - connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardChange())); - ui->labelCoinControlQuantity->addAction(clipboardQuantityAction); - ui->labelCoinControlAmount->addAction(clipboardAmountAction); - ui->labelCoinControlFee->addAction(clipboardFeeAction); - ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction); - ui->labelCoinControlBytes->addAction(clipboardBytesAction); - ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction); - ui->labelCoinControlChange->addAction(clipboardChangeAction); - - // init transaction fee section - if (!settings.contains("fFeeSectionMinimized")) - settings.setValue("fFeeSectionMinimized", true); - if (!settings.contains("nFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility - settings.setValue("nFeeRadio", 1); // custom - if (!settings.contains("nFeeRadio")) - settings.setValue("nFeeRadio", 0); // recommended - if (!settings.contains("nCustomFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility - settings.setValue("nCustomFeeRadio", 1); // total at least - if (!settings.contains("nCustomFeeRadio")) - settings.setValue("nCustomFeeRadio", 0); // per kilobyte - if (!settings.contains("nSmartFeeSliderPosition")) - settings.setValue("nSmartFeeSliderPosition", 0); - if (!settings.contains("nTransactionFee")) - settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); - if (!settings.contains("fPayOnlyMinFee")) - settings.setValue("fPayOnlyMinFee", false); - if (!settings.contains("fSendFreeTransactions")) - settings.setValue("fSendFreeTransactions", false); - - ui->groupFee->setId(ui->radioSmartFee, 0); - ui->groupFee->setId(ui->radioCustomFee, 1); - ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); - ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); - ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1); - ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); - ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt()); - ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); - ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); - ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); - minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); -} - -void ChatDialog::setClientModel(ClientModel *clientModel) -{ - this->clientModel = clientModel; - - if (clientModel) { - connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(updateSmartFeeLabel())); - } -} - -void ChatDialog::setModel(WalletModel *model) -{ - this->model = model; - - if(model && model->getOptionsModel()) - { - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - entry->setModel(model); - } - } - - setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), - model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); - connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount))); - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - updateDisplayUnit(); - - // Coin Control - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool))); - ui->frameCoinControl->setVisible(model->getOptionsModel()->getCoinControlFeatures()); - coinControlUpdateLabels(); - - // fee section - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel())); - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(updateGlobalFeeVariables())); - connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000)); - updateFeeSectionControls(); - updateMinFeeLabel(); - updateSmartFeeLabel(); - updateGlobalFeeVariables(); - } -} - -ChatDialog::~ChatDialog() -{ - QSettings settings; - settings.setValue("fFeeSectionMinimized", fFeeMinimized); - settings.setValue("nFeeRadio", ui->groupFee->checkedId()); - settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId()); - settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); - settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); - settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); - settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); - - delete ui; -} - -void ChatDialog::on_sendButton_clicked() -{ - if(!model || !model->getOptionsModel()) - return; - - QList recipients; - bool valid = true; - - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - if(entry->validate()) - { - recipients.append(entry->getValue()); - } - else - { - // valid = false; - } - } - } - - if(!valid || recipients.isEmpty()) - { - return; - } - - QString strFunds = tr("using") + " " + tr("anonymous funds") + ""; - QString strFee = ""; - recipients[0].inputType = ONLY_DENOMINATED; - - if(ui->checkUsePrivateSend->isChecked()) { - recipients[0].inputType = ONLY_DENOMINATED; - strFunds = tr("using") + " " + tr("anonymous funds") + ""; - QString strNearestAmount( - BitcoinUnits::formatWithUnit( - model->getOptionsModel()->getDisplayUnit(), CPrivateSend::GetSmallestDenomination())); - strFee = QString(tr( - "(privatesend requires this amount to be rounded up to the nearest %1)." - ).arg(strNearestAmount)); - } else { - recipients[0].inputType = ALL_COINS; - strFunds = tr("using") + " " + tr("any available funds (not anonymous)") + ""; - } - - if(ui->checkUseInstantSend->isChecked()) { - recipients[0].fUseInstantSend = true; - strFunds += " "; - strFunds += tr("and InstantSend"); - } else { - recipients[0].fUseInstantSend = false; - } - - - fNewRecipientAllowed = false; - // request unlock only if was locked or unlocked for mixing: - // this way we let users unlock by walletpassphrase or by menu - // and make many transactions while unlocking through this dialog - // will call relock - WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); - if(encStatus == model->Locked || encStatus == model->UnlockedForMixingOnly) - { - WalletModel::UnlockContext ctx(model->requestUnlock()); - if(!ctx.isValid()) - { - // Unlock wallet was cancelled - fNewRecipientAllowed = true; - return; - } - send(recipients, strFee, strFunds); - return; - } - // already unlocked or not encrypted at all - send(recipients, strFee, strFunds); -} - -void ChatDialog::send(QList recipients, QString strFee, QString strFunds) -{ - // prepare transaction for getting txFee earlier - WalletModelTransaction currentTransaction(recipients); - WalletModel::SendCoinsReturn prepareStatus; - if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled - prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); - else - prepareStatus = model->prepareTransaction(currentTransaction); - - // process prepareStatus and on error generate message shown to user - processSendCoinsReturn(prepareStatus, - BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); - - if(prepareStatus.status != WalletModel::OK) { - fNewRecipientAllowed = true; - return; - } - - CAmount txFee = currentTransaction.getTransactionFee(); - - // Format confirmation message - QStringList formatted; - Q_FOREACH(const SendCoinsRecipient &rcp, currentTransaction.getRecipients()) - { - // generate bold amount string - QString amount = "" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); - amount.append(" ").append(strFunds); - - // generate monospace address string - QString address = "" + rcp.address; - address.append(""); - - QString recipientElement; - - if (!rcp.paymentRequest.IsInitialized()) // normal payment - { - if(rcp.label.length() > 0) // label with address - { - recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); - recipientElement.append(QString(" (%1)").arg(address)); - } - else // just address - { - recipientElement = tr("%1 to %2").arg(amount, address); - } - } - else if(!rcp.authenticatedMerchant.isEmpty()) // authenticated payment request - { - recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); - } - else // unauthenticated payment request - { - recipientElement = tr("%1 to %2").arg(amount, address); - } - - formatted.append(recipientElement); - } - - QString questionString = tr("Are you sure you want to send?"); - questionString.append("

%1"); - - if(txFee > 0.5) - { - // append fee string if a fee is required - questionString.append("
"); - questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); - questionString.append(" "); - questionString.append(tr("are added as transaction fee")); - questionString.append(" "); - questionString.append(strFee); - - // append transaction size - questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)"); - } - - // add total amount in all subdivision units - questionString.append("
"); - CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; - QStringList alternativeUnits; - Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) - { - if(u != model->getOptionsModel()->getDisplayUnit()) - alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); - } - - // Show total amount + all alternative units - questionString.append(tr("Total Amount = %1
= %2") - .arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) - .arg(alternativeUnits.join("
= "))); - - // Limit number of displayed entries - int messageEntries = formatted.size(); - int displayedEntries = 0; - for(int i = 0; i < formatted.size(); i++){ - if(i >= MAX_SEND_POPUP_ENTRIESCHAT){ - formatted.removeLast(); - i--; - } - else{ - displayedEntries = i+1; - } - } - questionString.append("
"); - questionString.append(tr("(%1 of %2 entries displayed)").arg(displayedEntries).arg(messageEntries)); - - // Display message box - if(txFee > 0.05) - { - - QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), - questionString.arg(formatted.join("
")), - QMessageBox::Yes | QMessageBox::Cancel, - QMessageBox::Cancel); - - if(retval != QMessageBox::Yes) - { - fNewRecipientAllowed = true; - return; - } - } - // now send the prepared transaction - WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); - // process sendStatus and on error generate message shown to user - processSendCoinsReturn(sendStatus); - - if (sendStatus.status == WalletModel::OK) - { - accept(); - //CoinControlDialog::coinControl->UnSelectAll(); - coinControlUpdateLabels(); - } - fNewRecipientAllowed = true; -} - -void ChatDialog::clear() -{ - // Remove entries until only one left - while(ui->entries->count()) - { - ui->entries->takeAt(0)->widget()->deleteLater(); - } - addEntry(); - - updateTabsAndLabels(); -} - -void ChatDialog::reject() -{ - // clear(); -} - -void ChatDialog::accept() -{ - // clear(); -} - -ChatEntry *ChatDialog::addEntry() -{ - ChatEntry *entry = new ChatEntry(platformStyle, this); - entry->setModel(model); - ui->entries->addWidget(entry); - connect(entry, SIGNAL(removeEntry(ChatEntry*)), this, SLOT(removeEntry(ChatEntry*))); - connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); - connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels())); - - // Focus the field, so that entry can start immediately - entry->clear(); - entry->setFocus(); - ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint()); - qApp->processEvents(); - QScrollBar* bar = ui->scrollArea->verticalScrollBar(); - if(bar) - bar->setSliderPosition(bar->maximum()); - - updateTabsAndLabels(); - return entry; -} - -void ChatDialog::updateTabsAndLabels() -{ - setupTabChain(0); - coinControlUpdateLabels(); -} - -void ChatDialog::removeEntry(ChatEntry* entry) -{ - entry->hide(); - - // If the last entry is about to be removed add an empty one - if (ui->entries->count() == 1) - addEntry(); - - entry->deleteLater(); - - updateTabsAndLabels(); -} - -QWidget *ChatDialog::setupTabChain(QWidget *prev) -{ - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - prev = entry->setupTabChain(prev); - } - } - QWidget::setTabOrder(prev, ui->sendButton); - QWidget::setTabOrder(ui->sendButton, ui->clearButton); - QWidget::setTabOrder(ui->clearButton, ui->addButton); - return ui->addButton; -} - -void ChatDialog::setAddress(const QString &address, QString imgbase64) -{ - ChatEntry *entry = 0; - // Replace the first entry if it is still unused - if(ui->entries->count() == 1) - { - ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); - if(first->isClear()) - { - entry = first; - } - } - if(!entry) - { - entry = addEntry(); - } - - entry->setAddress(address,imgbase64); -} - -void ChatDialog::pasteEntry(const SendCoinsRecipient &rv) -{ - if(!fNewRecipientAllowed) - return; - - ChatEntry *entry = 0; - // Replace the first entry if it is still unused - if(ui->entries->count() == 1) - { - ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); - if(first->isClear()) - { - entry = first; - } - } - if(!entry) - { - entry = addEntry(); - } - - entry->setValue(rv); - updateTabsAndLabels(); -} - -bool ChatDialog::handlePaymentRequest(const SendCoinsRecipient &rv) -{ - // Just paste the entry, all pre-checks - // are done in paymentserver.cpp. - pasteEntry(rv); - return true; -} - -void ChatDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, - const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance) -{ - Q_UNUSED(unconfirmedBalance); - Q_UNUSED(immatureBalance); - Q_UNUSED(anonymizedBalance); - Q_UNUSED(watchBalance); - Q_UNUSED(watchUnconfirmedBalance); - Q_UNUSED(watchImmatureBalance); - - if(model && model->getOptionsModel()) - { - uint64_t bal = 0; - QSettings settings; - settings.setValue("bUseDarkSend", ui->checkUsePrivateSend->isChecked()); - if(ui->checkUsePrivateSend->isChecked()) { - bal = anonymizedBalance; - } else { - bal = balance; - } - - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); - } -} - -void ChatDialog::updateDisplayUnit() -{ - setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), - model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); - CoinControlDialog::coinControl->fUsePrivateSend = ui->checkUsePrivateSend->isChecked(); - coinControlUpdateLabels(); - ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - updateMinFeeLabel(); - updateSmartFeeLabel(); -} - -void ChatDialog::updateInstantSend() -{ - QSettings settings; - settings.setValue("bUseInstantX", ui->checkUseInstantSend->isChecked()); - CoinControlDialog::coinControl->fUseInstantSend = ui->checkUseInstantSend->isChecked(); - coinControlUpdateLabels(); -} - -void ChatDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) -{ - QPair msgParams; - // Default to a warning message, override if error message is needed - msgParams.second = CClientUIInterface::MSG_WARNING; - - // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. - // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() - // all others are used only in WalletModel::prepareTransaction() - switch(sendCoinsReturn.status) - { - case WalletModel::InvalidAddress: - msgParams.first = tr("The recipient address is not valid. Please recheck."); - break; - case WalletModel::InvalidAmount: - msgParams.first = tr("The amount to pay must be larger than 0."); - break; - case WalletModel::AmountExceedsBalance: - msgParams.first = tr("The amount exceeds your balance."); - break; - case WalletModel::AmountWithFeeExceedsBalance: - msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); - break; - case WalletModel::DuplicateAddress: - msgParams.first = tr("Duplicate address found: addresses should only be used once each."); - break; - case WalletModel::TransactionCreationFailed: - msgParams.first = tr("Transaction creation failed!"); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - case WalletModel::TransactionCommitFailed: - msgParams.first = tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - case WalletModel::AbsurdFee: - msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), maxTxFee)); - break; - case WalletModel::PaymentRequestExpired: - msgParams.first = tr("Payment request expired."); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - // included to prevent a compiler warning. - case WalletModel::OK: - default: - return; - } - - Q_EMIT message(tr("Send Coins"), msgParams.first, msgParams.second); -} - -void ChatDialog::minimizeFeeSection(bool fMinimize) -{ - ui->labelFeeMinimized->setVisible(fMinimize); - ui->buttonChooseFee ->setVisible(fMinimize); - ui->buttonMinimizeFee->setVisible(!fMinimize); - ui->frameFeeSelection->setVisible(!fMinimize); - ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0, 0); - fFeeMinimized = fMinimize; -} - -void ChatDialog::on_buttonChooseFee_clicked() -{ - minimizeFeeSection(false); -} - -void ChatDialog::on_buttonMinimizeFee_clicked() -{ - updateFeeMinimizedLabel(); - minimizeFeeSection(true); -} - -void ChatDialog::setMinimumFee() -{ - ui->radioCustomPerKilobyte->setChecked(true); - ui->customFee->setValue(CWallet::GetRequiredFee(1000)); -} - -void ChatDialog::updateFeeSectionControls() -{ - ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked()); - ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked()); - ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked()); - ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); - ui->radioCustomAtLeast ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() && CoinControlDialog::coinControl->HasSelected()); - ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); -} - -void ChatDialog::updateGlobalFeeVariables() -{ - if (ui->radioSmartFee->isChecked()) - { - nTxConfirmTarget = defaultConfirmTargetChat - ui->sliderSmartFee->value(); - payTxFee = CFeeRate(0); - - // set nMinimumTotalFee to 0 to not accidentally pay a custom fee - CoinControlDialog::coinControl->nMinimumTotalFee = 0; - } - else - { - nTxConfirmTarget = defaultConfirmTargetChat; - payTxFee = CFeeRate(ui->customFee->value()); - - // if user has selected to set a minimum absolute fee, pass the value to coincontrol - // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB - CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; - } - - fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); -} - -void ChatDialog::updateFeeMinimizedLabel() -{ - if(!model || !model->getOptionsModel()) - return; - - if (ui->radioSmartFee->isChecked()) - ui->labelFeeMinimized->setText(ui->labelSmartFee->text()); - else { - ui->labelFeeMinimized->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ui->customFee->value()) + - ((ui->radioCustomPerKilobyte->isChecked()) ? "/kB" : "")); - } -} - -void ChatDialog::updateMinFeeLabel() -{ - if (model && model->getOptionsModel()) - ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg( - BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB") - ); -} - -void ChatDialog::updateSmartFeeLabel() -{ - if(!model || !model->getOptionsModel()) - return; - - int nBlocksToConfirm = defaultConfirmTargetChat - ui->sliderSmartFee->value(); - int estimateFoundAtBlocks = nBlocksToConfirm; - CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks); - if (feeRate <= CFeeRate(0)) // not enough data => minfee - { - ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), - std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); - ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) - ui->labelFeeEstimation->setText(""); - } - else - { - ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), - std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); - ui->labelSmartFee2->hide(); - ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks)); - } - - updateFeeMinimizedLabel(); -} - -// Coin Control: copy label "Quantity" to clipboard -void ChatDialog::coinControlClipboardQuantity() -{ - GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); -} - -// Coin Control: copy label "Amount" to clipboard -void ChatDialog::coinControlClipboardAmount() -{ - GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); -} - -// Coin Control: copy label "Fee" to clipboard -void ChatDialog::coinControlClipboardFee() -{ - GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "After fee" to clipboard -void ChatDialog::coinControlClipboardAfterFee() -{ - GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "Bytes" to clipboard -void ChatDialog::coinControlClipboardBytes() -{ - GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "Dust" to clipboard -void ChatDialog::coinControlClipboardLowOutput() -{ - GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); -} - -// Coin Control: copy label "Change" to clipboard -void ChatDialog::coinControlClipboardChange() -{ - GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: settings menu - coin control enabled/disabled by user -void ChatDialog::coinControlFeatureChanged(bool checked) -{ - ui->frameCoinControl->setVisible(checked); - - if (!checked && model) // coin control features disabled - CoinControlDialog::coinControl->SetNull(); - - coinControlUpdateLabels(); -} - -// Coin Control: button inputs -> show actual coin control dialog -void ChatDialog::coinControlButtonClicked() -{ - CoinControlDialog dlg(platformStyle); - dlg.setModel(model); - dlg.exec(); - coinControlUpdateLabels(); -} - -// Coin Control: checkbox custom change address -void ChatDialog::coinControlChangeChecked(int state) -{ - if (state == Qt::Unchecked) - { - CoinControlDialog::coinControl->destChange = CNoDestination(); - ui->labelCoinControlChangeLabel->clear(); - } - else - // use this to re-validate an already entered address - coinControlChangeEdited(ui->lineEditCoinControlChange->text()); - - ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); -} - -// Coin Control: custom change address changed -void ChatDialog::coinControlChangeEdited(const QString& text) -{ - if (model && model->getAddressTableModel()) - { - // Default to no change address until verified - CoinControlDialog::coinControl->destChange = CNoDestination(); - ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); - - CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); - - if (text.isEmpty()) // Nothing entered - { - ui->labelCoinControlChangeLabel->setText(""); - } - else if (!addr.IsValid()) // Invalid address - { - ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Dash address")); - } - else // Valid address - { - CKeyID keyid; - addr.GetKeyID(keyid); - if (!model->havePrivKey(keyid)) // Unknown change address - { - ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); - } - else // Known change address - { - ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); - - // Query label - QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); - if (!associatedLabel.isEmpty()) - ui->labelCoinControlChangeLabel->setText(associatedLabel); - else - ui->labelCoinControlChangeLabel->setText(tr("(no label)")); - - CoinControlDialog::coinControl->destChange = addr.Get(); - } - } - } -} - -// Coin Control: update labels -void ChatDialog::coinControlUpdateLabels() -{ - if (!model || !model->getOptionsModel()) - return; - - if (model->getOptionsModel()->getCoinControlFeatures()) - { - // enable minimum absolute fee UI controls - ui->radioCustomAtLeast->setVisible(true); - - // only enable the feature if inputs are selected - ui->radioCustomAtLeast->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() &&CoinControlDialog::coinControl->HasSelected()); - } - else - { - // in case coin control is disabled (=default), hide minimum absolute fee UI controls - ui->radioCustomAtLeast->setVisible(false); - return; - } - - // set pay amounts - CoinControlDialog::payAmounts.clear(); - CoinControlDialog::fSubtractFeeFromAmount = false; - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry && !entry->isHidden()) - { - SendCoinsRecipient rcp = entry->getValue(); - CoinControlDialog::payAmounts.append(rcp.amount); - if (rcp.fSubtractFeeFromAmount) - CoinControlDialog::fSubtractFeeFromAmount = true; - } - } - - ui->checkUsePrivateSend->setChecked(CoinControlDialog::coinControl->fUsePrivateSend); - - if (CoinControlDialog::coinControl->HasSelected()) - { - // actual coin control calculation - CoinControlDialog::updateLabels(model, this); - - // show coin control stats - ui->labelCoinControlAutomaticallySelected->hide(); - ui->widgetCoinControl->show(); - } - else - { - // hide coin control stats - ui->labelCoinControlAutomaticallySelected->show(); - ui->widgetCoinControl->hide(); - ui->labelCoinControlInsuffFunds->hide(); - } -} From 4c02f3535febf30ade763c0594b8dba88cc635be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:23:13 -0400 Subject: [PATCH 0532/1324] Delete chatdialog.h --- src/qt/chatdialog.h | 106 -------------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 src/qt/chatdialog.h diff --git a/src/qt/chatdialog.h b/src/qt/chatdialog.h deleted file mode 100644 index 9abf9d7e..00000000 --- a/src/qt/chatdialog.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_CHATDIALOG_H -#define BITCOIN_QT_CHATDIALOG_H - -#include "walletmodel.h" - -#include -#include - -static const int MAX_SEND_POPUP_ENTRIESCHAT = 10; - -class ClientModel; -class OptionsModel; -class PlatformStyle; -class ChatEntry; -class SendCoinsRecipient; - -namespace Ui { - class ChatDialog; -} - -QT_BEGIN_NAMESPACE -class QUrl; -QT_END_NAMESPACE - -const int defaultConfirmTargetChat = 25; - -/** Dialog for sending bitcoins */ -class ChatDialog : public QDialog -{ - Q_OBJECT - -public: - explicit ChatDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ChatDialog(); - - void setClientModel(ClientModel *clientModel); - void setModel(WalletModel *model); - - /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907). - */ - QWidget *setupTabChain(QWidget *prev); - - void setAddress(const QString &address, QString imgbase64); - void pasteEntry(const SendCoinsRecipient &rv); - bool handlePaymentRequest(const SendCoinsRecipient &recipient); - -public Q_SLOTS: - void clear(); - void reject(); - void accept(); - ChatEntry *addEntry(); - void updateTabsAndLabels(); - void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, - const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); - -private: - Ui::ChatDialog *ui; - ClientModel *clientModel; - WalletModel *model; - bool fNewRecipientAllowed; - void send(QList recipients, QString strFee, QString strFunds); - bool fFeeMinimized; - const PlatformStyle *platformStyle; - - // Process WalletModel::SendCoinsReturn and generate a pair consisting - // of a message and message flags for use in Q_EMIT message(). - // Additional parameter msgArg can be used via .arg(msgArg). - void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString()); - void minimizeFeeSection(bool fMinimize); - void updateFeeMinimizedLabel(); - -private Q_SLOTS: - void on_sendButton_clicked(); - void on_buttonChooseFee_clicked(); - void on_buttonMinimizeFee_clicked(); - void removeEntry(ChatEntry* entry); - void updateDisplayUnit(); - void updateInstantSend(); - void coinControlFeatureChanged(bool); - void coinControlButtonClicked(); - void coinControlChangeChecked(int); - void coinControlChangeEdited(const QString &); - void coinControlUpdateLabels(); - void coinControlClipboardQuantity(); - void coinControlClipboardAmount(); - void coinControlClipboardFee(); - void coinControlClipboardAfterFee(); - void coinControlClipboardBytes(); - void coinControlClipboardLowOutput(); - void coinControlClipboardChange(); - void setMinimumFee(); - void updateFeeSectionControls(); - void updateMinFeeLabel(); - void updateSmartFeeLabel(); - void updateGlobalFeeVariables(); - -Q_SIGNALS: - // Fired when a message should be reported to the user - void message(const QString &title, const QString &message, unsigned int style); -}; - -#endif // BITCOIN_QT_CHATDIALOG_H From 68cb5aa705260cc565a5a8a1cab6595fa023d106 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:23:19 -0400 Subject: [PATCH 0533/1324] Delete chatentry.cpp --- src/qt/chatentry.cpp | 558 ------------------------------------------- 1 file changed, 558 deletions(-) delete mode 100644 src/qt/chatentry.cpp diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp deleted file mode 100644 index 3dee680d..00000000 --- a/src/qt/chatentry.cpp +++ /dev/null @@ -1,558 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "chatentry.h" -#include "ui_chatentry.h" - -#include "addressbookpage.h" -#include "addresstablemodel.h" -#include "transactionfilterproxy.h" -#include "transactiontablemodel.h" -#include "guiutil.h" -#include "optionsmodel.h" -#include "platformstyle.h" -#include "walletmodel.h" -#include "base64.h" - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -base64 base64chat; -typedef unsigned char BYTE; - -bool fileselectedchat=false; - -ChatEntry::ChatEntry(const PlatformStyle *platformStyle, QWidget *parent) : - QStackedWidget(parent), - ui(new Ui::ChatEntry), - model(0), - platformStyle(platformStyle) -{ - ui->setupUi(this); - - setCurrentWidget(ui->Chat); - - if (platformStyle->getUseExtraSpacing()) - ui->chatToLayout->setSpacing(4); - - - QString theme = GUIUtil::getThemeName(); - - // These icons are needed on Mac also! - ui->addressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); - ui->pasteButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - ui->deleteButton->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->deleteButton_is->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->deleteButton_s->setIcon(QIcon(":/icons/" + theme + "/remove")); - //ui->pasteButtonBase64->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - ui->Imgbase64Edit->setMaxLength(10000000); - - //receive address icons - - ui->ReceiveAddressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); - ui->pasteReceiveButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - - //ui->payAmount->setDisabled(true); - - ui->payAmount->setValue(0.0001); - - - // ui->payAmount->setVisible(false); - - // normal dash address field - GUIUtil::setupAddressWidget(ui->chatReceive, this); - GUIUtil::setupAddressWidget(ui->chatTo, this); - // just a label for displaying dash address(es) - ui->payTo_is->setFont(GUIUtil::fixedPitchFont()); - - // Connect signals - //connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged())); - //connect(ui->chatTo, SIGNAL(textChanged()), this, SIGNAL(on_chatTo_textChanged())); - //connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged())); - connect(ui->pasteButton, SIGNAL(clicked()), this, SLOT(on_pasteButton_clicked())); - connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); - connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked())); - connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked())); - - - connect(ui->ReceiveAddressBookButton, SIGNAL(clicked()), this, SLOT(on_addressReceiveBookButton_clicked())); - - connect(ui->pasteReceiveButton, SIGNAL(clicked()), this, SLOT(on_pasteReceiveAddressButton_clicked())); - - - - //connect(ui->chooserButton, SIGNAL(clicked()), this, SLOT(on_chooserButton_clicked())); - //connect(ui->pasteButtonBase64, SIGNAL(clicked()), this, SLOT(on_pasteButtonBase64_clicked())); - -} - -ChatEntry::~ChatEntry() -{ - delete ui; -} - -void ChatEntry::on_pasteButton_clicked() -{ - // Paste text from clipboard into recipient field - ui->chatTo->setText(QApplication::clipboard()->text()); -} - - -void ChatEntry::on_pasteReceiveAddressButton_clicked() -{ - // Paste text from clipboard into recipient field - ui->chatReceive->setText(QApplication::clipboard()->text()); -} - -void ChatEntry::on_pasteButtonBase64_clicked() -{ - // Paste text from clipboard into recipient field - ui->Imgbase64Edit->setText(QApplication::clipboard()->text()); -} - -void ChatEntry::on_addressBookButton_clicked() -{ - if(!model) - return; - AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this); - dlg.setModel(model->getAddressTableModel()); - if(dlg.exec()) - { - ui->chatTo->setText(dlg.getReturnValue()); - //ui->payAmount->setFocus(); - } -} - -void ChatEntry::on_addressReceiveBookButton_clicked() -{ - if(!model) - return; - AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); - dlg.setModel(model->getAddressTableModel()); - - if(dlg.exec()) - { - ui->chatReceive->setText(dlg.getReturnValue()); - //ui->payAmount->setFocus(); - } -} - -void ChatEntry::on_chatTo_textChanged(const QString &address) -{ - updateLabel(address); - checkaddresstransactions(address); -} - -void ChatEntry::on_chatReceive_textChanged(const QString &address) -{ - checkaddresstransactions(address); -} - -void ChatEntry::checkaddresstransactions(const QString &address) -{ - if (model->validateAddress(ui->chatTo->text()) && model->validateAddress(ui->chatReceive->text())) - { - - ui->chatTo->setDisabled(true); - ui->chatReceive->setDisabled(true); - ui->Imgbase64Edit->setText("Start messaging using to address : " + ui->chatReceive->text() + " and me : " + ui->chatTo->text()); - transactionProxyModel = new TransactionFilterProxy(this); - transactionProxyModel->setAddressPrefix(ui->chatTo->text(),ui->chatReceive->text()); - transactionProxyModel->setSourceModel(model->getTransactionTableModel()); - - - - ui->chattableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - ui->chattableView->setTabKeyNavigation(false); - ui->chattableView->setContextMenuPolicy(Qt::CustomContextMenu); - ui->chattableView->installEventFilter(this); - - QAction *copyImgbase64Action = new QAction(tr("Copy "), this); - - contextMenu = new QMenu(this); - - contextMenu->addAction(copyImgbase64Action); - - connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); - - connect(ui->chattableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); - - transactionView = ui->chattableView; - transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - transactionView->setModel(transactionProxyModel); - transactionView->setAlternatingRowColors(true); - transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); - transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); - transactionView->setSortingEnabled(true); - transactionView->sortByColumn(TransactionTableModel::Date, Qt::AscendingOrder); - transactionView->verticalHeader()->hide(); - //transactionView->horizontalHeader()->hide(); - transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH); - //transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Imgbase64, IMGBASE64_COLUMN_WIDTH); - //transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); - // Actions - - - connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); - - columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, IMGBASE64_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this); - - - // show/hide column Watch-only - - transactionView->setColumnHidden(TransactionTableModel::Watchonly, true); //Watchonly - - transactionView->setColumnHidden(TransactionTableModel::ToAddress, true); //To address - - transactionView->setColumnHidden(TransactionTableModel::Amount, true); // Amount - - // Watch-only signal - // connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool))); - - - } -} - -void ChatEntry::setModel(WalletModel *model) -{ - this->model = model; - - if (model && model->getOptionsModel()) - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - - clear(); -} - -void ChatEntry::clear() -{ - // clear UI elements for normal payment - ui->chatReceive->clear(); - ui->chatTo->clear(); - //ui->addAsLabel->clear(); - //ui->payAmount->clear(); - ui->Imgbase64Edit->clear(); - ui->Imgbase64Edit->setEnabled(1); - fileselectedchat=false; - //ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); - ui->messageTextLabel->clear(); - ui->messageTextLabel->hide(); - ui->messageLabel->hide(); - // clear UI elements for unauthenticated payment request - ui->payTo_is->clear(); - ui->memoTextLabel_is->clear(); - //ui->payAmount_is->clear(); - // clear UI elements for authenticated payment request - ui->payTo_s->clear(); - ui->memoTextLabel_s->clear(); - ui->payAmount_s->clear(); - - // update the display unit, to not use the default ("BTC") - updateDisplayUnit(); -} - - -void ChatEntry::on_chooserButton_clicked() -{ - //clear - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); - ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); - - // Paste text from clipboard into recipient field - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::ExistingFiles); - - //dialog.setViewMode(QFileDialog::List); - dialog.setOption(QFileDialog::DontUseNativeDialog, false); - - if (dialog.exec()){ - QStringList fileNames = dialog.selectedFiles(); - - if(fileNames.size()>0){ - - - - QString file = fileNames[0]; - ui->FileNamesTxt->setText(file); - std::string filestr = file.toUtf8().constData(); - std::string encodedstring = base64chat.encode(filestr); - QString qsencoded = QString::fromStdString(encodedstring); - - if(!base64chat.base64Validator(encodedstring)){ - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Base64 string not valid."); - ui->Imgbase64Edit->setText(""); - return; - } - if(qsencoded.size()>10000000) - { - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); - ui->Imgbase64Edit->setText(""); - return; - } - fileselectedchat=true; - ui->Imgbase64Edit->setText(qsencoded); - ui->Imgbase64Edit->setDisabled(1); - } - } -} - -void ChatEntry::deleteClicked() -{ - Q_EMIT removeEntry(this); -} - -bool ChatEntry::validate() -{ - if (!model) - return false; - - - // Check input validity - bool retval = true; - - // Skip checks for payment request - if (recipient.paymentRequest.IsInitialized()) - return retval; - - if (!model->validateAddress(ui->chatTo->text())) - { - ui->chatTo->setValid(false); - retval = false; - } - - if (!model->validateAddress(ui->chatReceive->text())) - { - ui->chatReceive->setValid(false); - retval = false; - } - - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); - ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); - if (!ui->Imgbase64Edit->text().isEmpty()) - { - - std::string imgbase64=ui->Imgbase64Edit->text().toUtf8().constData(); - - - if(fileselectedchat) - { - if(!base64chat.base64Validator(imgbase64)){ - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Base64 string not valid."); - ui->Imgbase64Edit->setText(""); - retval = false; - } - } - - - if(ui->Imgbase64Edit->text().length()>10000000) - { - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); - ui->Imgbase64Edit->setText(""); - retval = false; - } - } - else { - retval = false; - } - - if (!ui->payAmount->validate()) - { - retval = false; - } - - // Sending a zero amount is invalid - if (ui->payAmount->value(0) <= 0) - { - ui->payAmount->setValid(false); - retval = false; - } - - // Reject dust outputs: - // if (retval && GUIUtil::isDust(ui->chatTo->text(), ui->payAmount->value())) { - // ui->payAmount->setValid(false); - // retval = false; - //} - - return retval; -} - -SendCoinsRecipient ChatEntry::getValue() -{ - // Payment request - if (recipient.paymentRequest.IsInitialized()) - return recipient; - - // Normal payment - recipient.address = ui->chatTo->text(); - //recipient.label = ui->addAsLabel->text(); - recipient.imgbase64 = ui->Imgbase64Edit->text(); - if(ui->Imgbase64Edit->text().size()>0 && !fileselectedchat){ //message - recipient.imgbase64 ="from:" + ui->chatReceive->text() + ":"+ ui->Imgbase64Edit->text(); - } - recipient.amount = ui->payAmount->value(); - recipient.message = ui->messageTextLabel->text(); - recipient.fSubtractFeeFromAmount = false;//(ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); - - return recipient; -} - -QWidget *ChatEntry::setupTabChain(QWidget *prev) -{ - QWidget::setTabOrder(prev, ui->chatTo); - QWidget::setTabOrder(ui->chatTo, ui->labelchatTo); - //QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel); - //QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount); - //QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton); - - QWidget::setTabOrder(ui->ReceiveAddressBookButton, ui->pasteReceiveButton); - QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton); - QWidget::setTabOrder(ui->pasteButton, ui->deleteButton); - return ui->deleteButton; -} - -void ChatEntry::setValue(const SendCoinsRecipient &value) -{ - recipient = value; - - if (recipient.paymentRequest.IsInitialized()) // payment request - { - if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated - { - ui->chatTo->setText(recipient.address); - //ui->memoTextLabel_is->setText(recipient.message); - ui->payAmount_is->setValue(recipient.amount); - ui->Imgbase64Edit->setText(recipient.imgbase64); - ui->payAmount->setValue(recipient.amount); - ui->payAmount_is->setReadOnly(true); - setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); - } - else // authenticated - { - ui->chatTo->setText(recipient.authenticatedMerchant); - //ui->memoTextLabel_s->setText(recipient.message); - - ui->payAmount_s->setValue(recipient.amount); - ui->payAmount_s->setReadOnly(true); - ui->Imgbase64Edit->setText(recipient.imgbase64); - setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); - } - } - else // normal payment - { - // message - ui->messageTextLabel->setText(recipient.message); - ui->messageTextLabel->setVisible(!recipient.message.isEmpty()); - ui->messageLabel->setVisible(!recipient.message.isEmpty()); - - //ui->addAsLabel->clear(); - ui->chatTo->setText(recipient.address); // this may set a label from addressbook - if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label - ui->labelchatTo->setText(recipient.label); - ui->payAmount->setValue(recipient.amount); - ui->Imgbase64Edit->setText(recipient.imgbase64); - } -} - -void ChatEntry::setAddress(const QString &address, QString imgbase64) -{ - ui->chatTo->setText(address); - if(!imgbase64.isNull()) ui->Imgbase64Edit->setText(imgbase64); - //ui->payAmount->setFocus(); -} - -bool ChatEntry::isClear() -{ - return ui->chatTo->text().isEmpty() && ui->chatReceive->text().isEmpty(); -} - -void ChatEntry::setFocus() -{ - ui->chatTo->setFocus(); -} - -void ChatEntry::updateDisplayUnit() -{ - if(model && model->getOptionsModel()) - { - // Update payAmount with the current unit - ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - } -} - -bool ChatEntry::updateLabel(const QString &address) -{ - if(!model) - return false; - - // Fill in label from address book, if address has an associated label - QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); - if(!associatedLabel.isEmpty()) - { - ui->labelchatTo->setText(associatedLabel); - return true; - } - - return false; -} - -void ChatEntry::contextualMenu(const QPoint &point) -{ - QModelIndex index = transactionView->indexAt(point); - QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); - if (selection.empty()) - return; - - // check if transaction can be abandoned, disable context menu action in case it doesn't - uint256 hash; - hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); - // abandonAction->setEnabled(model->transactionCanBeAbandoned(hash)); - - if(index.isValid()) - { - contextMenu->exec(QCursor::pos()); - } -} - -void ChatEntry::copyImgbase64() -{ - GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); -} From 73f9f4570c40c9a37ee9b53a3b1e7763762a458d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:23:27 -0400 Subject: [PATCH 0534/1324] Delete chatentry.h --- src/qt/chatentry.h | 99 ---------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 src/qt/chatentry.h diff --git a/src/qt/chatentry.h b/src/qt/chatentry.h deleted file mode 100644 index e7515a5f..00000000 --- a/src/qt/chatentry.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2019- The IMAGEcOIN Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_CHATENTRY_H -#define BITCOIN_QT_CHATENTRY_H - -#include "walletmodel.h" -#include "guiutil.h" -#include -#include - -class WalletModel; -class PlatformStyle; -class TransactionFilterProxy; -class QTableView; -class QMenu; - -namespace Ui { - class ChatEntry; -} - -/** - * A single entry in the dialog for sending bitcoins. - * Stacked widget, with different UIs for payment requests - * with a strong payee identity. - */ -class ChatEntry : public QStackedWidget -{ - Q_OBJECT - -public: - explicit ChatEntry(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ChatEntry(); - - void setModel(WalletModel *model); - bool validate(); - SendCoinsRecipient getValue(); - - /** Return whether the entry is still empty and unedited */ - bool isClear(); - - void setValue(const SendCoinsRecipient &value); - void setAddress(const QString &address,QString imgbase64); - - /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases - * (issue https://bugreports.qt-project.org/browse/QTBUG-10907). - */ - QWidget *setupTabChain(QWidget *prev); - - void setFocus(); - - enum ColumnWidths { - STATUS_COLUMN_WIDTH = 30, - WATCHONLY_COLUMN_WIDTH = 23, - DATE_COLUMN_WIDTH = 120, - TYPE_COLUMN_WIDTH = 180, - IMGBASE64_COLUMN_WIDTH = 580, - AMOUNT_MINIMUM_COLUMN_WIDTH = 120, - MINIMUM_COLUMN_WIDTH = 23 - }; - -public Q_SLOTS: - void clear(); - -Q_SIGNALS: - void removeEntry(ChatEntry *entry); - void payAmountChanged(); - void subtractFeeFromAmountChanged(); - -private Q_SLOTS: - void deleteClicked(); - void on_chatTo_textChanged(const QString &address); - void on_addressBookButton_clicked(); - void on_addressReceiveBookButton_clicked(); - void on_pasteButton_clicked(); - void on_pasteReceiveAddressButton_clicked(); - void updateDisplayUnit(); - void on_chooserButton_clicked(); - void on_pasteButtonBase64_clicked(); - void copyImgbase64(); - void contextualMenu(const QPoint &); - void on_chatReceive_textChanged(const QString &address); - -private: - SendCoinsRecipient recipient; - Ui::ChatEntry *ui; - WalletModel *model; - const PlatformStyle *platformStyle; - TransactionFilterProxy *transactionProxyModel; - QTableView *transactionView; - QMenu *contextMenu; - GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; - bool updateLabel(const QString &address); - void checkaddresstransactions(const QString &address); -}; - -#endif // BITCOIN_QT_CHATIMGENTRY_H From ec4fc6f211ba177da984eeb654b09a440f344992 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:24:09 -0400 Subject: [PATCH 0535/1324] Update walletview.h --- src/qt/walletview.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 3a6643d8..5365b665 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -24,8 +24,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -/* class TradingDialogPage; */ -class ChatDialog; +/* class TradingDialogPage; */ QT_BEGIN_NAMESPACE @@ -77,7 +76,7 @@ class WalletView : public QStackedWidget GovernanceList *governanceListPage; TransactionView *transactionView; /* TradingDialogPage *tradingDialogPage; */ - ChatDialog *ChatPage; + QProgressDialog *progressDialog; QLabel *transactionSum; @@ -85,8 +84,6 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to chat page */ - void gotoChatPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ee3b3ea22a54279b6fcc06c746cd3e9586a30684 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:25:14 -0400 Subject: [PATCH 0536/1324] Update walletview.cpp --- src/qt/walletview.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7b99a1ef..7f584ed8 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,6 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "chatdialog.h" #include "ui_interface.h" @@ -75,9 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - ChatPage = new ChatDialog(platformStyle); - - + usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); @@ -86,14 +83,11 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); - addWidget(ChatPage); + addWidget(privateSendPage); /* tradingDialogPage = new TradingDialogPage(); addWidget(tradingDialogPage); */ - - chatPagen = new ChatPage(); - addWidget(chatPage); + QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -252,10 +246,6 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoChatPage() -{ - setCurrentWidget(ChatPage); -} /*void WalletView::gotoTradingDialogPage() { From 7862307504280bfca60cb1ecd981aea594dbdc1a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:26:51 -0400 Subject: [PATCH 0537/1324] Update walletview.cpp --- src/qt/walletview.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7f584ed8..90a8f733 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -121,10 +121,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - - // Pass through messages from ChatPage - connect(ChatPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - + } @@ -167,8 +164,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); } - governanceListPage->setClientModel(_clientModel); - ChatPage->setClientModel(clientModel); + governanceListPage->setClientModel(_clientModel); } @@ -185,8 +181,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } - governanceListPage->setWalletModel(_walletModel); - ChatPage->setModel(walletModel); + governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From 2439bef24ff44e1405b7a6333ad71394b0a93676 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:28:13 -0400 Subject: [PATCH 0538/1324] Update walletmodel.h --- src/qt/walletmodel.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 6aeed507..095c94a1 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -41,8 +41,8 @@ class SendCoinsRecipient { public: explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { } - explicit SendCoinsRecipient(const QString &addr, const QString &_label, const QString &imgbase64, const CAmount& _amount, const QString &_message): - address(addr), label(_label), amount(_amount), imgbase64(imgbase64) , message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} + explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message): + address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} // If from an unauthenticated payment request, this is used for storing // the addresses, e.g. address-A
address-B
address-C. @@ -51,7 +51,6 @@ class SendCoinsRecipient // Todo: This is a hack, should be replaced with a cleaner solution! QString address; QString label; - QString imgbase64; #ifdef ENABLE_WALLET AvailableCoinsType inputType; #endif // ENABLE_WALLET @@ -59,10 +58,6 @@ class SendCoinsRecipient CAmount amount; // If from a payment request, this is used for storing the memo QString message; - - // DAC message or prayer - QString txtMessage; - bool fDonate; // If from a payment request, paymentRequest.IsInitialized() will be true PaymentRequestPlus paymentRequest; @@ -81,7 +76,6 @@ class SendCoinsRecipient std::string sAddress = address.toStdString(); std::string sLabel = label.toStdString(); std::string sMessage = message.toStdString(); - std::string simgbase64 = imgbase64.toStdString(); std::string sPaymentRequest; if (!ser_action.ForRead() && paymentRequest.IsInitialized()) paymentRequest.SerializeToString(&sPaymentRequest); @@ -91,7 +85,6 @@ class SendCoinsRecipient READWRITE(sAddress); READWRITE(sLabel); READWRITE(amount); - READWRITE(simgbase64); READWRITE(sMessage); READWRITE(sPaymentRequest); READWRITE(sAuthenticatedMerchant); @@ -100,7 +93,6 @@ class SendCoinsRecipient { address = QString::fromStdString(sAddress); label = QString::fromStdString(sLabel); - imgbase64= QString::fromStdString(simgbase64); message = QString::fromStdString(sMessage); if (!sPaymentRequest.empty()) paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size())); From b3097312a9bda37fa7f5c01b5182891080ce71e6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:28:46 -0400 Subject: [PATCH 0539/1324] Update walletview.h --- src/qt/walletview.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 5365b665..0949d744 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -/* #include "tradingdialogpage.h" */ + #include @@ -22,9 +22,9 @@ class SendCoinsRecipient; class TransactionView; class WalletModel; class AddressBookPage; -class PrivateSendPage; +class OverviewAPage; class GovernancePage; -/* class TradingDialogPage; */ + QT_BEGIN_NAMESPACE @@ -72,11 +72,10 @@ class WalletView : public QStackedWidget AddressBookPage *usedSendingAddressesPage; AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; - PrivateSendPage *privateSendPage; - GovernanceList *governanceListPage; + OverviewAPage *overviewAPage; + GovernanceList *governanceListPage; + TransactionView *transactionView; - /* TradingDialogPage *tradingDialogPage; */ - QProgressDialog *progressDialog; QLabel *transactionSum; @@ -84,12 +83,10 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to trading page */ - /* void gotoTradingDialogPage(); */ /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoPrivateSendPage(); + void gotoOverviewAPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ @@ -98,8 +95,8 @@ public Q_SLOTS: void gotoMasternodePage(); /** Switch to receive coins page */ void gotoReceiveCoinsPage(); - /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = "",QString imgbase64 = ""); + /** Switch to send coins page */ + void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); @@ -107,7 +104,6 @@ public Q_SLOTS: void gotoVerifyMessageTab(QString addr = ""); /** Show incoming transaction notification for new transactions. - The new items are those between start and end inclusive, under the given parent item. */ void processNewTransaction(const QModelIndex& parent, int start, int /*end*/); @@ -139,7 +135,6 @@ public Q_SLOTS: /** Update selected HTH amount from transactionview */ void trxAmount(QString amount); - void encodebase64ClickedSignal(const QString &address, const QString &imgbase64); Q_SIGNALS: /** Signal that we want to show the main window */ void showNormalIfMinimized(); From b7ec39bb6bf05f0073ec0ecac8d683241d968b78 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:29:11 -0400 Subject: [PATCH 0540/1324] Update walletview.cpp --- src/qt/walletview.cpp | 60 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 90a8f733..eb5e886f 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -20,7 +20,7 @@ #include "transactiontablemodel.h" #include "transactionview.h" #include "walletmodel.h" -#include "privatesendpage.h" +#include "overviewapage.h" #include "ui_interface.h" @@ -41,8 +41,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): platformStyle(_platformStyle) { // Create tabs - overviewPage = new OverviewPage(platformStyle); - privateSendPage = new PrivateSendPage(platformStyle); + overviewPage = new OverviewPage(platformStyle); + overviewAPage = new OverviewAPage(platformStyle); transactionsPage = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); QHBoxLayout *hbox_buttons = new QHBoxLayout(); @@ -70,41 +70,34 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): hbox_buttons->addWidget(exportButton); vbox->addLayout(hbox_buttons); transactionsPage->setLayout(vbox); - + receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - - + usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); - addWidget(overviewPage); addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); - - /* tradingDialogPage = new TradingDialogPage(); - addWidget(tradingDialogPage); */ - + addWidget(overviewAPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage = new MasternodeList(platformStyle); addWidget(masternodeListPage); } - governanceListPage = new GovernanceList(platformStyle); + governanceListPage = new GovernanceList(platformStyle); addWidget(governanceListPage); - // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page - connect(privateSendPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); - connect(privateSendPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); + connect(overviewAPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); + connect(overviewAPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); // Double-clicking on a transaction on the transaction history page shows details @@ -121,8 +114,6 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - - } WalletView::~WalletView() @@ -137,7 +128,7 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui) connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); // Clicking on a transaction on the overview page simply sends you to transaction history page - connect(privateSendPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); + connect(overviewAPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); // Receive and report messages connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int))); @@ -158,14 +149,13 @@ void WalletView::setClientModel(ClientModel *_clientModel) this->clientModel = _clientModel; overviewPage->setClientModel(_clientModel); - privateSendPage->setClientModel(_clientModel); + overviewAPage->setClientModel(_clientModel); sendCoinsPage->setClientModel(_clientModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); } - governanceListPage->setClientModel(_clientModel); - + governanceListPage->setClientModel(_clientModel); } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -175,18 +165,16 @@ void WalletView::setWalletModel(WalletModel *_walletModel) // Put transaction list in tabs transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); - privateSendPage->setWalletModel(_walletModel); + overviewAPage->setWalletModel(_walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - - governanceListPage->setWalletModel(_walletModel); + governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel()); - if (_walletModel) { @@ -241,21 +229,15 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } - -/*void WalletView::gotoTradingDialogPage() -{ - setCurrentWidget(tradingDialogPage); -} */ - void WalletView::gotoGovernancePage() { QSettings settings; setCurrentWidget(governanceListPage); } -void WalletView::gotoPrivateSendPage() +void WalletView::gotoOverviewAPage() { - setCurrentWidget(privateSendPage); + setCurrentWidget(overviewAPage); } void WalletView::gotoOverviewPage() @@ -281,12 +263,12 @@ void WalletView::gotoReceiveCoinsPage() setCurrentWidget(receiveCoinsPage); } -void WalletView::gotoSendCoinsPage(QString addr,QString imgbase64) +void WalletView::gotoSendCoinsPage(QString addr) { setCurrentWidget(sendCoinsPage); - if (!addr.isEmpty() || !imgbase64.isEmpty()) - sendCoinsPage->setAddress(addr, imgbase64); + if (!addr.isEmpty()) + sendCoinsPage->setAddress(addr); } void WalletView::gotoSignMessageTab(QString addr) @@ -441,7 +423,3 @@ void WalletView::trxAmount(QString amount) { transactionSum->setText(amount); } -void WalletView::encodebase64ClickedSignal(const QString &address, const QString &imgbase64){ - - gotoSendCoinsPage(address,imgbase64); -} From 631ce2da88a4015963212843631ceec8cee315d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:29:44 -0400 Subject: [PATCH 0541/1324] Update walletmodel.cpp --- src/qt/walletmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 4bf18187..ab235c43 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -278,7 +278,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact const unsigned char* scriptStr = (const unsigned char*)out.script().data(); CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); CAmount nAmount = out.amount(); - CRecipient recipient = {scriptPubKey, nAmount, rcp.imgbase64.toStdString() , rcp.fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, nAmount, rcp.fSubtractFeeFromAmount}; vecSend.push_back(recipient); } if (subtotal <= 0) @@ -301,7 +301,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact ++nAddresses; CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); - CRecipient recipient = {scriptPubKey, rcp.amount, rcp.imgbase64.toStdString(), rcp.fSubtractFeeFromAmount}; + CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount}; vecSend.push_back(recipient); total += rcp.amount; From 3f4251b7cea60cfbfa8d7f42e110fed992921219 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:30:26 -0400 Subject: [PATCH 0542/1324] Update walletframe.h --- src/qt/walletframe.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 6630fb40..c131813e 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,14 +63,10 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to Chat page */ - void gotoChatPage(); - /** Switch to trading page */ - /* void gotoTradingDialogPage(); */ /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoPrivateSendPage(); + void gotoOverviewAPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ @@ -80,7 +76,7 @@ public Q_SLOTS: /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = "",QString imgbase64 = ""); + void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); From 85a6b491837a8497c7d7ed11ee8a57b861fc632d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:30:59 -0400 Subject: [PATCH 0543/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 1d491469..6abc45c3 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,20 +108,6 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoChatPage() -{ - QMap::const_iterator i; - for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoChatPage(); -} -/*void WalletFrame::gotoTradingDialogPage() -{ - - QMap::const_iterator i; - for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoTradingDialogPage(); -} */ - void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; @@ -129,11 +115,11 @@ void WalletFrame::gotoGovernancePage() i.value()->gotoGovernancePage(); } -void WalletFrame::gotoPrivateSendPage() +void WalletFrame::gotoOverviewAPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoPrivateSendPage(); + i.value()->gotoOverviewAPage(); } void WalletFrame::gotoOverviewPage() @@ -164,11 +150,11 @@ void WalletFrame::gotoReceiveCoinsPage() i.value()->gotoReceiveCoinsPage(); } -void WalletFrame::gotoSendCoinsPage(QString addr, QString imgbase64) +void WalletFrame::gotoSendCoinsPage(QString addr) { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoSendCoinsPage(addr,imgbase64); + i.value()->gotoSendCoinsPage(addr); } void WalletFrame::gotoSignMessageTab(QString addr) From 2f905f352c541b03ac4332305933509749b9a932 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:31:30 -0400 Subject: [PATCH 0544/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 5cc7c836..405958e3 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -10,7 +10,6 @@ #endif #include "amount.h" -#include "governancelist.h" #include #include @@ -38,8 +37,6 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -/*class tradingDialogPage; */ -class ChatAction; class CWallet; @@ -105,12 +102,8 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction *chatAction; - QAction *chatMenuAction; - QAction* externalDonate; QAction *governanceAction; - /* QAction *tradingAction; */ - /* QAction* privatesendAction; */ + QAction* overviewaAction; QAction *overviewAction; QAction *historyAction; QAction *masternodeAction; @@ -141,8 +134,7 @@ class BitcoinGUI : public QMainWindow QAction *showBackupsAction; QAction *openAction; QAction *showHelpMessageAction; -/* QAction *showPrivateSendHelpAction; */ - + QAction *showPrivateSendHelpAction; QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; @@ -234,18 +226,11 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - - - /** Switch to chat coins page */ - void gotoChatPage(); - /** Switch to trading page */ - /* void gotoTradingDialogPage(); */ - - /** Switch to governance page */ + /** Switch to masternode page */ void gotoGovernancePage(); /** Switch to private send page */ - /* void gotoPrivateSendPage(); */ + void gotoOverviewAPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ @@ -255,7 +240,7 @@ private Q_SLOTS: /** Switch to receive coins page */ void gotoReceiveCoinsPage(); /** Switch to send coins page */ - void gotoSendCoinsPage(QString addr = "", QString imgbase64=""); + void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); @@ -271,9 +256,6 @@ private Q_SLOTS: void aboutClicked(); /** Show debug window */ void showDebugWindow(); - /** Open external URL */ - void openDonate(); - void openExternalURL(QString url = ""); /** Show debug window and set focus to the appropriate tab */ void showInfo(); @@ -290,7 +272,7 @@ private Q_SLOTS: /** Show help message dialog */ void showHelpMessageClicked(); /** Show PrivateSend help message dialog */ -/* void showPrivateSendHelpClicked(); */ + void showPrivateSendHelpClicked(); #ifndef Q_OS_MAC /** Handle tray icon clicked */ void trayIconActivated(QSystemTrayIcon::ActivationReason reason); From d81207bfee0e9ce163926c118e5202f310cfd89b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:32:12 -0400 Subject: [PATCH 0545/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 201 +++++++----------------------------------- 1 file changed, 31 insertions(+), 170 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index a6eba479..ff06205f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,8 +22,6 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -/* #include "tradingdialogpage.h" */ - #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -130,7 +128,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * openRPCConsoleAction(0), openAction(0), showHelpMessageAction(0), - /* showPrivateSendHelpAction(0), */ + showPrivateSendHelpAction(0), trayIcon(0), trayIconMenu(0), dockIconMenu(0), @@ -141,10 +139,6 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * prevBlocks(0), spinnerFrame(0), governanceAction(0), - /* tradingAction(0), */ - externalDonate(0), - chatAction(0), - chatMenuAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -435,7 +429,7 @@ void BitcoinGUI::createActions() sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2)); #endif tabGroup->addAction(sendCoinsAction); - + sendCoinsMenuAction = new QAction(QIcon(":/icons/" + theme + "/send"), sendCoinsAction->text(), this); sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip()); sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip()); @@ -454,7 +448,6 @@ void BitcoinGUI::createActions() receiveCoinsMenuAction = new QAction(QIcon(":/icons/" + theme + "/receiving_addresses"), receiveCoinsAction->text(), this); receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip()); receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip()); - historyAction = new QAction(QIcon(":/icons/" + theme + "/history"), tr("&Transactions"), this); historyAction->setStatusTip(tr("Browse transaction history")); @@ -490,40 +483,25 @@ void BitcoinGUI::createActions() governanceAction->setToolTip(governanceAction->statusTip()); governanceAction->setCheckable(true); #ifdef Q_OS_MAC - governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); + governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_5)); #else - governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); + governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5)); #endif tabGroup->addAction(governanceAction); connect(governanceAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); - } - /* { - tradingAction = new QAction(QIcon(":/icons/chat"), tr("&Trading"), this); - tradingAction->setStatusTip(tr("Trade HTH Today")); - tradingAction->setToolTip(tradingAction->statusTip()); - tradingAction->setCheckable(true); + + overviewaAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); + overviewaAction->setStatusTip(tr("Show Private Send of wallet")); + overviewaAction->setToolTip(overviewaAction->statusTip()); + overviewaAction->setCheckable(true); #ifdef Q_OS_MAC - tradingAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); + overviewaAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); #else - tradingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); + overviewaAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif - tabGroup->addAction(tradingAction); - connect(tradingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(tradingAction, SIGNAL(triggered()), this, SLOT(gotoTradingDialogPage())); - - } */ - /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); - privatesendAction->setStatusTip(tr("Show Private Send of wallet")); - privatesendAction->setToolTip(privatesendAction->statusTip()); - privatesendAction->setCheckable(true); -#ifdef Q_OS_MAC - privatesendAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); -#else - privatesendAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); -#endif - tabGroup->addAction(privatesendAction); */ + tabGroup->addAction(overviewaAction); // These showNormalIfMinimized are needed because Send Coins and Receive Coins @@ -540,8 +518,8 @@ void BitcoinGUI::createActions() connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); - /* connect(privatesendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(privatesendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); */ + connect(overviewaAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(overviewaAction, SIGNAL(triggered()), this, SLOT(gotoOverviewAPage())); #endif // ENABLE_WALLET @@ -598,7 +576,7 @@ void BitcoinGUI::createActions() openGraphAction->setEnabled(false); openPeersAction->setEnabled(false); openRepairAction->setEnabled(false); - + usedSendingAddressesAction = new QAction(QIcon(":/icons/" + theme + "/address-book"), tr("&Sending addresses..."), this); usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels")); usedReceivingAddressesAction = new QAction(QIcon(":/icons/" + theme + "/address-book"), tr("&Receiving addresses..."), this); @@ -611,52 +589,18 @@ void BitcoinGUI::createActions() showHelpMessageAction->setMenuRole(QAction::NoRole); showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Dash command-line options").arg(tr(PACKAGE_NAME))); -/* showPrivateSendHelpAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&PrivateSend information"), this); + showPrivateSendHelpAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&PrivateSend information"), this); showPrivateSendHelpAction->setMenuRole(QAction::NoRole); - showPrivateSendHelpAction->setStatusTip(tr("Show the PrivateSend basic information")); */ - - - // HTHW Donate - externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); - externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - - //chat + showPrivateSendHelpAction->setStatusTip(tr("Show the PrivateSend basic information")); - chatAction = new QAction(QIcon(":/icons/" + theme + "/overview"), tr("&Messenger"), this); - chatAction->setStatusTip(tr("Messenger")); - chatAction->setToolTip(chatAction->statusTip()); - chatAction->setCheckable(true); - - #ifdef Q_OS_MAC - chatAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); - #else - chatAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); - #endif - tabGroup->addAction(chatAction); - - chatMenuAction = new QAction(QIcon(":/icons/" + theme + "/overview"), chatAction->text(), this); - chatMenuAction->setStatusTip(chatAction->statusTip()); - chatMenuAction->setToolTip(chatMenuAction->statusTip()); - - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden())); connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked())); -/* connect(showPrivateSendHelpAction, SIGNAL(triggered()), this, SLOT(showPrivateSendHelpClicked())); */ - - - // HTHW Donate - connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); - - connect(chatAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(chatAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); + connect(showPrivateSendHelpAction, SIGNAL(triggered()), this, SLOT(showPrivateSendHelpClicked())); - connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); - // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -744,22 +688,14 @@ void BitcoinGUI::createMenuBar() tools->addSeparator(); tools->addAction(openConfEditorAction); tools->addAction(showBackupsAction); - } - + QMenu *help = appMenuBar->addMenu(tr("&Help")); help->addAction(showHelpMessageAction); - /* help->addAction(showPrivateSendHelpAction); */ + help->addAction(showPrivateSendHelpAction); help->addSeparator(); help->addAction(aboutAction); help->addAction(aboutQtAction); - - QMenu* donate = appMenuBar->addMenu(tr("&Donate")); - donate->addAction(externalDonate); - - QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(chatAction); - } void BitcoinGUI::createToolBars() @@ -773,9 +709,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(sendCoinsAction); toolbar->addAction(receiveCoinsAction); toolbar->addAction(historyAction); -/* toolbar->addAction(privatesendAction); */ - toolbar->addAction(chatAction); - + toolbar->addAction(overviewaAction); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) @@ -784,10 +718,7 @@ void BitcoinGUI::createToolBars() } toolbar->addAction(governanceAction); toolbar->addAction(unlockWalletAction); - - /* toolbar->addAction(tradingAction); - toolbar->addAction(unlockWalletAction); */ - + toolbar->setMovable(false); // remove unused icon in upper left corner overviewAction->setChecked(true); @@ -938,7 +869,6 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } - /*tradingAction->setEnabled(enabled); */ governanceAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); @@ -948,9 +878,6 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); openAction->setEnabled(enabled); - chatAction->setEnabled(enabled); - chatMenuAction->setEnabled(enabled); - } void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) @@ -1072,13 +999,14 @@ void BitcoinGUI::showHelpMessageClicked() helpMessageDialog->show(); } -/*void BitcoinGUI::showPrivateSendHelpClicked() +void BitcoinGUI::showPrivateSendHelpClicked() { if(!clientModel) return; + HelpMessageDialog dlg(this, HelpMessageDialog::pshelp); dlg.exec(); -} */ +} #ifdef ENABLE_WALLET void BitcoinGUI::openClicked() @@ -1090,35 +1018,6 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoChatPage() -{ - chatAction->setChecked(true); - if (walletFrame) walletFrame->gotoChatPage(); -} - -/*void BitcoinGUI::gotoTradingDialogPage() -{ - - tradingAction->setChecked(true); - if (walletFrame) walletFrame->gotoTradingDialogPage(); -} */ - -void BitcoinGUI::openDonate() -{ - openExternalURL("https://helpthehomelessworldwide.org/donate"); -} - -void BitcoinGUI::openExternalURL(QString url) -{ - QMessageBox::StandardButton reply = QMessageBox::question(this, tr("Notice – External Link"), - QStringLiteral("This action will open up the following website in your default browser:

Help The Homeless Worldwide A NJ Nonprofit Corporation's Donation Page



To continue, hit your Enter key or press Ok.
Remember, never share your personal information or private keys on any social website.").arg(url), - QMessageBox::Cancel | QMessageBox::Ok, - QMessageBox::Ok); - - if (reply == QMessageBox::Ok) { - QDesktopServices::openUrl(QUrl(url)); - } -} void BitcoinGUI::gotoGovernancePage() { @@ -1126,11 +1025,11 @@ void BitcoinGUI::gotoGovernancePage() if (walletFrame) walletFrame->gotoGovernancePage(); } -/*void BitcoinGUI::gotoPrivateSendPage() +void BitcoinGUI::gotoOverviewAPage() { - privatesendAction->setChecked(true); - if (walletFrame) walletFrame->gotoPrivateSendPage(); -} */ + overviewaAction->setChecked(true); + if (walletFrame) walletFrame->gotoOverviewAPage(); +} void BitcoinGUI::gotoOverviewPage() { @@ -1161,10 +1060,10 @@ void BitcoinGUI::gotoReceiveCoinsPage() if (walletFrame) walletFrame->gotoReceiveCoinsPage(); } -oid BitcoinGUI::gotoSendCoinsPage(QString addr,QString imgbase64) +void BitcoinGUI::gotoSendCoinsPage(QString addr) { sendCoinsAction->setChecked(true); - if (walletFrame) walletFrame->gotoSendCoinsPage(addr,imgbase64); + if (walletFrame) walletFrame->gotoSendCoinsPage(addr); } void BitcoinGUI::gotoSignMessageTab(QString addr) @@ -1534,7 +1433,6 @@ void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) // Accept only URIs if(event->mimeData()->hasUrls()) event->acceptProposedAction(); - } void BitcoinGUI::dropEvent(QDropEvent *event) @@ -1672,43 +1570,6 @@ void BitcoinGUI::detectShutdown() } } - -// Governance - Check to see if we should submit a proposal - /* nProposalModulus++; - if (nProposalModulus % 15 == 0 && !fLoadingIndex) - { - nProposalModulus = 0; - if (!msURL.empty()) - { - QString qNav = GUIUtil::TOQS(msURL); - msURL = std::string(); - QDesktopServices::openUrl(QUrl(qNav)); - } - if (fProposalNeedsSubmitted) - { - nProposalModulus = 0; - if(masternodeSync.IsSynced() && chainActive.Tip() && chainActive.Tip()->nHeight > (nProposalPrepareHeight + 6)) - { - fProposalNeedsSubmitted = false; - std::string sError; - std::string sGovObj; - bool fSubmitted = SubmitProposalToNetwork(uTxIdFee, nProposalStartTime, msProposalHex, sError, sGovObj); - if (!sError.empty()) - { - LogPrintf("Proposal Submission Problem: %s ", sError); - } - msProposalResult = fSubmitted ? "Submitted Proposal Successfully
( " + sGovObj + " )" : sError; - LogPrintf(" Proposal Submission Result: %s \n", msProposalResult.c_str()); - } - else - { - msProposalResult = "Waiting for block " + RoundToString(nProposalPrepareHeight + 6, 0) + " to submit pending proposal. "; - } - } - } -} */ - - void BitcoinGUI::showProgress(const QString &title, int nProgress) { if (nProgress == 0) From 418306810b842b2ee1107e0b5c38ebdffaa0af26 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:32:26 -0400 Subject: [PATCH 0546/1324] Delete chatdialog.ui --- src/qt/forms/chatdialog.ui | 1374 ------------------------------------ 1 file changed, 1374 deletions(-) delete mode 100644 src/qt/forms/chatdialog.ui diff --git a/src/qt/forms/chatdialog.ui b/src/qt/forms/chatdialog.ui deleted file mode 100644 index 762e717f..00000000 --- a/src/qt/forms/chatdialog.ui +++ /dev/null @@ -1,1374 +0,0 @@ - - - ChatDialog - - - - 0 - 0 - 850 - 526 - - - - Chat - - - - 8 - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - 0 - - - 10 - - - 10 - - - - - 15 - - - - - - 0 - 0 - - - - - 75 - true - - - - font-weight:bold; - - - Coin Control Features - - - - - - - - - 8 - - - 10 - - - - - - - - Inputs... - - - false - - - - - - - automatically selected - - - 5 - - - - - - - - 75 - true - - - - color:red;font-weight:bold; - - - Insufficient funds! - - - 5 - - - - - - - Qt::Horizontal - - - - 40 - 1 - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 20 - - - 0 - - - 10 - - - - - 10 - - - 14 - - - 10 - - - 4 - - - 6 - - - - - - 75 - true - - - - Quantity: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0 - - - 0 - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Bytes: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0 - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - Amount: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Dust: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - no - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - Fee: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - After Fee: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Change: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - - - - - - 12 - - - QLayout::SetDefaultConstraint - - - 5 - - - 5 - - - - - If this is activated, but the change address is empty or invalid, change will be sent to a newly generated address. - - - Custom change address - - - - - - - false - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - 3 - - - - - - - - - Qt::Vertical - - - - 800 - 1 - - - - - - - - - - - - - true - - - - - 0 - 0 - 830 - 69 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 6 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - 10 - - - 0 - - - - - 0 - - - - - 0 - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 1 - 4 - - - - - - - - 10 - - - - - - 0 - 0 - - - - - 75 - true - - - - font-weight:bold; - - - Transaction Fee: - - - - - - - - - - - - - - Choose... - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - collapse fee-settings - - - Hide - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 10 - - - 4 - - - 10 - - - 4 - - - - - 6 - - - - - - - If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. - - - per kilobyte - - - true - - - groupCustomFee - - - - - - - If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "total at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. - - - total at least - - - groupCustomFee - - - - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. - - - - - - - - - - true - - - Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. - - - (read the tooltip) - - - 5 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - - - Recommended: - - - true - - - groupFee - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - - Custom: - - - groupFee - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - 6 - - - 2 - - - - - - - - - - 2 - - - - - - - - - - - - - - (Smart fee not initialized yet. This usually takes a few blocks...) - - - 2 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - - - Confirmation time: - - - 2 - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - 30 - - - - - 0 - - - 24 - - - 1 - - - 0 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - - - normal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - fast - - - - - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - - 8 - - - 4 - - - - - Send as zero-fee transaction if possible - - - - - - - (confirmation may take longer) - - - 5 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - Qt::Vertical - - - - 800 - 1 - - - - - - - - - - - - - - - - 150 - 0 - - - - Confirm the send action - - - S&end - - - false - - - true - - - - - - - - 0 - 0 - - - - Clear all fields of the form. - - - Clear &All - - - false - - - - - - - Send to multiple recipients at once - - - Add &Recipient - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 3 - - - - - - 95 - 0 - - - - PrivateSend - - - false - - - - - - - true - - - - 85 - 0 - - - - InstantSend - - - - - - - Balance: - - - - - - - - 0 - 0 - - - - IBeamCursor - - - 123.456 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
- - BitcoinAmountField - QLineEdit -
bitcoinamountfield.h
- 1 -
-
- - - - - - - - -
\ No newline at end of file From bc3b340c939c019508190e2dcee4ea5fd811e919 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:32:32 -0400 Subject: [PATCH 0547/1324] Delete chatentry.ui --- src/qt/forms/chatentry.ui | 1389 ------------------------------------- 1 file changed, 1389 deletions(-) delete mode 100644 src/qt/forms/chatentry.ui diff --git a/src/qt/forms/chatentry.ui b/src/qt/forms/chatentry.ui deleted file mode 100644 index da92f8af..00000000 --- a/src/qt/forms/chatentry.ui +++ /dev/null @@ -1,1389 +0,0 @@ - - - ChatEntry - - - - 0 - 0 - 729 - 552 - - - - Qt::TabFocus - - - false - - - 0 - - - - This is a normal payment. - - - QFrame::NoFrame - - - - 8 - - - 4 - - - 12 - - - 8 - - - - - 0 - - - - - The IMG address to send the message - - - - - - - Choose previously used address - - - - - - - 22 - 22 - - - - Alt+A - - - - - - - Paste address from clipboard - - - - - - - 22 - 22 - - - - Alt+P - - - - - - - - - Me: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 16777215 - 25 - - - - - - - - - - - 0 - - - - - IMG address to sender send you message - - - 33774 - - - - - - - - - - - 22 - 22 - - - - - - - - - - - - 22 - 22 - - - - - - - - Remove this entry - - - - - - - 22 - 22 - - - - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - chatTo - - - - - - - - 600 - 240 - - - - - 16777215 - 240 - - - - - - - - Message: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Imgbase64Edit - - - - - - - - 16777215 - 25 - - - - A message that was attached to the dash: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Dash network. - - - Qt::PlainText - - - - - - - 0 - - - 0 - - - - - true - - - Enter a message to send. - - - margin-left:12px - - - 3000000 - - - - - - - - - 0 - - - 0 - - - - - Image/Video: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - false - - - margin-left:12px - - - - - - - Chooser - - - - - - - - - - - true - - - - - - - false - - - false - - - The fee will be deducted from the amount being sent. The recipient will receive a lower amount of Dash than you enter in the amount field. If multiple recipients are selected, the fee is split equally. - - - S&ubtract fee from amount - - - - - - - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 191 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 191 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 255 - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - This is an unauthenticated payment request. - - - true - - - QFrame::NoFrame - - - - 12 - - - - - Pay To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0 - - - - - - - - Remove this entry - - - - - - - - - - - - Memo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::PlainText - - - - - - - A&mount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - payAmount_is - - - - - - - false - - - - - - - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 0 - 0 - 0 - - - - - - - 155 - 255 - 147 - - - - - - - 0 - 0 - 0 - - - - - - - 119 - 255 - 233 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 197 - 243 - 187 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 0 - 0 - 0 - - - - - - - 155 - 255 - 147 - - - - - - - 0 - 0 - 0 - - - - - - - 119 - 255 - 233 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 197 - 243 - 187 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 70 - 116 - 59 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 70 - 116 - 59 - - - - - - - 155 - 255 - 147 - - - - - - - 70 - 116 - 59 - - - - - - - 140 - 232 - 119 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - This is an authenticated payment request. - - - true - - - QFrame::NoFrame - - - - 12 - - - - - Pay To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0 - - - - - Qt::PlainText - - - - - - - Remove this entry - - - - - - - - - - - - Memo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::PlainText - - - - - - - A&mount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - payAmount_s - - - - - - - false - - - - - - - - - BitcoinAmountField - QWidget -
bitcoinamountfield.h
- 1 -
- - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
-
- - addressBookButton - pasteButton - payAmount_is - deleteButton_is - payAmount_s - deleteButton_s - - - - - -
From 8e039d72cfd1e8e97b8f018bf2345ee52265e952 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:33:16 -0400 Subject: [PATCH 0548/1324] Update Makefile.am --- src/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5ea8460b..15b14cf7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -122,7 +122,6 @@ BITCOIN_CORE_H = \ checkpoints.h \ checkqueue.h \ clientversion.h \ - coincontrol.h \ coins.h \ compat.h \ compat/byteswap.h \ @@ -248,6 +247,7 @@ BITCOIN_CORE_H = \ zmq/zmqnotificationinterface.h \ zmq/zmqpublishnotifier.h + obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \ @@ -436,6 +436,7 @@ crypto_libhelpthehomeless_crypto_a_SOURCES = \ crypto/SWIFFTX/lane.h \ crypto/SWIFFTX/blake2s.h + # consensus: shared between all executables that validate any consensus rules. libhelpthehomeless_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libhelpthehomeless_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) From 9d6d8d6ef1979ef5b54d15040225b0da29c289b8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:33:59 -0400 Subject: [PATCH 0549/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 09e119fc..7b6e2512 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,8 +33,6 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ - qt/forms/chatdialog.ui \ - qt/forms/chatentry.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ @@ -47,14 +45,13 @@ QT_FORMS_UI = \ qt/forms/openuridialog.ui \ qt/forms/optionsdialog.ui \ qt/forms/overviewpage.ui \ - qt/forms/privatesendpage.ui \ + qt/forms/overviewapage.ui \ qt/forms/receivecoinsdialog.ui \ qt/forms/receiverequestdialog.ui \ qt/forms/debugwindow.ui \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ - qt/forms/tradingdialogpage.ui \ qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ @@ -62,13 +59,10 @@ QT_MOC_CPP = \ qt/moc_addresstablemodel.cpp \ qt/moc_askpassphrasedialog.cpp \ qt/moc_bantablemodel.cpp \ - qt/moc_base64.cpp \ qt/moc_bitcoinaddressvalidator.cpp \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ - qt/moc_chatdialog.cpp \ - qt/moc_chatentry.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -87,7 +81,7 @@ QT_MOC_CPP = \ qt/moc_optionsdialog.cpp \ qt/moc_optionsmodel.cpp \ qt/moc_overviewpage.cpp \ - qt/moc_privatesendpage.cpp \ + qt/moc_overviewapage.cpp \ qt/moc_peertablemodel.cpp \ qt/moc_paymentserver.cpp \ qt/moc_qrdialog.cpp \ @@ -101,7 +95,6 @@ QT_MOC_CPP = \ qt/moc_sendcoinsentry.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ - qt/moc_tradingdialogpage.cpp \ qt/moc_trafficgraphwidget.cpp \ qt/moc_transactiondesc.cpp \ qt/moc_transactiondescdialog.cpp \ @@ -123,7 +116,7 @@ QT_MOC = \ qt/bitcoinamountfield.moc \ qt/intro.moc \ qt/overviewpage.moc \ - qt/privatesendpage.moc \ + qt/overviewapage.moc \ qt/rpcconsole.moc QT_QRC_CPP = qt/qrc_helpthehomeless.cpp @@ -140,13 +133,10 @@ BITCOIN_QT_H = \ qt/addresstablemodel.h \ qt/askpassphrasedialog.h \ qt/bantablemodel.h \ - qt/base64.h \ qt/bitcoinaddressvalidator.h \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ - qt/chatdialog.h \ - qt/chatentry.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ @@ -168,7 +158,7 @@ BITCOIN_QT_H = \ qt/optionsdialog.h \ qt/optionsmodel.h \ qt/overviewpage.h \ - qt/privatesendpage.h \ + qt/overviewapage.h \ qt/paymentrequestplus.h \ qt/paymentserver.h \ qt/peertablemodel.h \ @@ -184,7 +174,6 @@ BITCOIN_QT_H = \ qt/sendcoinsentry.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ - qt/tradingdialogpage.h \ qt/trafficgraphdata.h \ qt/trafficgraphwidget.h \ qt/transactiondesc.h \ @@ -200,7 +189,6 @@ BITCOIN_QT_H = \ qt/walletview.h \ qt/winshutdownmonitor.h - RES_ICONS = \ qt/res/icons/bitcoin.ico \ qt/res/icons/bitcoin_testnet.ico \ @@ -510,9 +498,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ - qt/base64.cpp \ - qt/chatdialog.cpp \ - qt/chatentry.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ @@ -521,7 +506,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ - qt/privatesendpage.cpp \ + qt/overviewapage.cpp \ qt/paymentrequestplus.cpp \ qt/paymentserver.cpp \ qt/qrdialog.cpp \ @@ -531,7 +516,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ qt/signverifymessagedialog.cpp \ - qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ qt/transactiondescdialog.cpp \ qt/transactionfilterproxy.cpp \ From 616862556a78c706d5e60e1b958bbe285b6cfb77 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:34:21 -0400 Subject: [PATCH 0550/1324] Delete coincontrol.h --- src/coincontrol.h | 74 ----------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/coincontrol.h diff --git a/src/coincontrol.h b/src/coincontrol.h deleted file mode 100644 index ff8f33a8..00000000 --- a/src/coincontrol.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_COINCONTROL_H -#define BITCOIN_COINCONTROL_H - -#include "primitives/transaction.h" - -/** Coin Control Features. */ -class CCoinControl -{ -public: - CTxDestination destChange; - bool fUsePrivateSend; - bool fUseInstantSend; - //! If false, allows unselected inputs, but requires all selected inputs be used - bool fAllowOtherInputs; - //! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria - bool fAllowWatchOnly; - //! Minimum absolute fee (not per kilobyte) - CAmount nMinimumTotalFee; - - CCoinControl() - { - SetNull(); - } - - void SetNull() - { - destChange = CNoDestination(); - fAllowOtherInputs = false; - fAllowWatchOnly = false; - setSelected.clear(); - fUseInstantSend = false; - fUsePrivateSend = true; - nMinimumTotalFee = 0; - } - - bool HasSelected() const - { - return (setSelected.size() > 0); - } - - bool IsSelected(const COutPoint& output) const - { - return (setSelected.count(output) > 0); - } - - void Select(const COutPoint& output) - { - setSelected.insert(output); - } - - void UnSelect(const COutPoint& output) - { - setSelected.erase(output); - } - - void UnSelectAll() - { - setSelected.clear(); - } - - void ListSelected(std::vector& vOutpoints) const - { - vOutpoints.assign(setSelected.begin(), setSelected.end()); - } - -private: - std::set setSelected; -}; - -#endif // BITCOIN_COINCONTROL_H From d7565f765da3141bec4354359af7e14a937c1cc9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:36:44 -0400 Subject: [PATCH 0551/1324] Update validation.cpp --- src/validation.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 8a4fd700..17822dab 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1386,15 +1386,6 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs))) return false; - - for (unsigned int i = 0; i < tx.vout.size(); i++) - { - if(tx.vout[i].imgbase64.size()>25000000){ - LogPrint("bench", "Large length imgbase64 checkInputs"); - return false; - } - } - if (pvChecks) pvChecks->reserve(tx.vin.size()); From 252513d998fe5b9659dd7d333c269f13e9a2978b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:41:43 -0400 Subject: [PATCH 0552/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index ff06205f..e0ac5ccd 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -519,7 +519,7 @@ void BitcoinGUI::createActions() connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); connect(overviewaAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(overviewaAction, SIGNAL(triggered()), this, SLOT(gotoOverviewAPage())); + connect(overviewaAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); #endif // ENABLE_WALLET @@ -709,7 +709,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(sendCoinsAction); toolbar->addAction(receiveCoinsAction); toolbar->addAction(historyAction); - toolbar->addAction(overviewaAction); + toolbar->addAction(privateSendAction); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) @@ -1025,10 +1025,10 @@ void BitcoinGUI::gotoGovernancePage() if (walletFrame) walletFrame->gotoGovernancePage(); } -void BitcoinGUI::gotoOverviewAPage() +void BitcoinGUI::gotoPrivateSendPage() { - overviewaAction->setChecked(true); - if (walletFrame) walletFrame->gotoOverviewAPage(); + privateSendAction->setChecked(true); + if (walletFrame) walletFrame->gotoPrivateSendPage(); } void BitcoinGUI::gotoOverviewPage() From 8eae9ddadfae1bb115d4a6ead4df54e43aeb3801 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:42:38 -0400 Subject: [PATCH 0553/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e0ac5ccd..6faf8ecf 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -492,16 +492,16 @@ void BitcoinGUI::createActions() connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); } - overviewaAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); - overviewaAction->setStatusTip(tr("Show Private Send of wallet")); - overviewaAction->setToolTip(overviewaAction->statusTip()); - overviewaAction->setCheckable(true); + privateSendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); + privateSendAction->setStatusTip(tr("Show Private Send of wallet")); + privateSendAction->setToolTip(privateSendAction->statusTip()); + privateSendAction->setCheckable(true); #ifdef Q_OS_MAC - overviewaAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); + privateSendAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); #else - overviewaAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); + privateSendAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif - tabGroup->addAction(overviewaAction); + tabGroup->addAction(privateSendAction); // These showNormalIfMinimized are needed because Send Coins and Receive Coins From 259977db5fb2ba5cf364deb2c5dda437a2e2f84c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:43:25 -0400 Subject: [PATCH 0554/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 405958e3..62a7529c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -103,7 +103,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; QAction *governanceAction; - QAction* overviewaAction; + QAction* privateSendAction; QAction *overviewAction; QAction *historyAction; QAction *masternodeAction; @@ -230,7 +230,7 @@ private Q_SLOTS: /** Switch to masternode page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoOverviewAPage(); + void gotoPrivateSendPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ From 7139e8d44bae8e13bfc18bf35d544668e78a67d9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:44:10 -0400 Subject: [PATCH 0555/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 6abc45c3..6783019e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -115,11 +115,11 @@ void WalletFrame::gotoGovernancePage() i.value()->gotoGovernancePage(); } -void WalletFrame::gotoOverviewAPage() +void WalletFrame::gotoPrivateSendPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoOverviewAPage(); + i.value()->gotoPrivateSendPage(); } void WalletFrame::gotoOverviewPage() From 0db2ae60a38fcbfd2a7f38fc05ca754f956cf37e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:44:26 -0400 Subject: [PATCH 0556/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index c131813e..54527997 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -66,7 +66,7 @@ public Q_SLOTS: /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoOverviewAPage(); + void gotoPrivateSendPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ From 8582719c4962216921c3090587cf54b7d0021d9d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:46:28 -0400 Subject: [PATCH 0557/1324] Update walletview.cpp --- src/qt/walletview.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index eb5e886f..ba7978cd 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -20,7 +20,7 @@ #include "transactiontablemodel.h" #include "transactionview.h" #include "walletmodel.h" -#include "overviewapage.h" +#include "privatesendpage.h" #include "ui_interface.h" @@ -42,7 +42,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): { // Create tabs overviewPage = new OverviewPage(platformStyle); - overviewAPage = new OverviewAPage(platformStyle); + privateSendPage = new PrivateSendPage(platformStyle); transactionsPage = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); QHBoxLayout *hbox_buttons = new QHBoxLayout(); @@ -81,7 +81,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(overviewAPage); + addWidget(privateSendPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -96,8 +96,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page - connect(overviewAPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); - connect(overviewAPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); + connect(privateSendPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); + connect(privateSendPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); // Double-clicking on a transaction on the transaction history page shows details @@ -128,7 +128,7 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui) connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); // Clicking on a transaction on the overview page simply sends you to transaction history page - connect(overviewAPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); + connect(privateSendPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage())); // Receive and report messages connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int))); @@ -149,7 +149,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) this->clientModel = _clientModel; overviewPage->setClientModel(_clientModel); - overviewAPage->setClientModel(_clientModel); + privateSendPage->setClientModel(_clientModel); sendCoinsPage->setClientModel(_clientModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -165,7 +165,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) // Put transaction list in tabs transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); - overviewAPage->setWalletModel(_walletModel); + privateSendPage->setWalletModel(_walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); @@ -235,9 +235,9 @@ void WalletView::gotoGovernancePage() setCurrentWidget(governanceListPage); } -void WalletView::gotoOverviewAPage() +void WalletView::gotoPrivateSendPage() { - setCurrentWidget(overviewAPage); + setCurrentWidget(privateSendPage); } void WalletView::gotoOverviewPage() From c7945a48613d27ea499a40ced7c4b32fe70d128a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:47:17 -0400 Subject: [PATCH 0558/1324] Update walletview.h --- src/qt/walletview.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 0949d744..ef368efe 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -22,7 +22,7 @@ class SendCoinsRecipient; class TransactionView; class WalletModel; class AddressBookPage; -class OverviewAPage; +class PrivateSendPage; class GovernancePage; @@ -72,7 +72,7 @@ class WalletView : public QStackedWidget AddressBookPage *usedSendingAddressesPage; AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; - OverviewAPage *overviewAPage; + PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; TransactionView *transactionView; @@ -86,7 +86,7 @@ public Q_SLOTS: /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoOverviewAPage(); + void gotoPrivateSendPage(); /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ From b809b0dede290f0adb0f0181ab61377f52c2f88f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:49:13 -0400 Subject: [PATCH 0559/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 7b6e2512..faa4d1cc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -45,7 +45,7 @@ QT_FORMS_UI = \ qt/forms/openuridialog.ui \ qt/forms/optionsdialog.ui \ qt/forms/overviewpage.ui \ - qt/forms/overviewapage.ui \ + qt/forms/privatesendpage.ui \ qt/forms/receivecoinsdialog.ui \ qt/forms/receiverequestdialog.ui \ qt/forms/debugwindow.ui \ @@ -81,7 +81,7 @@ QT_MOC_CPP = \ qt/moc_optionsdialog.cpp \ qt/moc_optionsmodel.cpp \ qt/moc_overviewpage.cpp \ - qt/moc_overviewapage.cpp \ + qt/moc_privatesendpage.cpp \ qt/moc_peertablemodel.cpp \ qt/moc_paymentserver.cpp \ qt/moc_qrdialog.cpp \ @@ -158,7 +158,7 @@ BITCOIN_QT_H = \ qt/optionsdialog.h \ qt/optionsmodel.h \ qt/overviewpage.h \ - qt/overviewapage.h \ + qt/privatesendpage.h \ qt/paymentrequestplus.h \ qt/paymentserver.h \ qt/peertablemodel.h \ @@ -506,7 +506,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/masternodelist.cpp \ qt/openuridialog.cpp \ qt/overviewpage.cpp \ - qt/overviewapage.cpp \ + qt/privatesendpage.cpp \ qt/paymentrequestplus.cpp \ qt/paymentserver.cpp \ qt/qrdialog.cpp \ From e66cfba7dded0e08d2861cfb8a793e3c306b8c45 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:51:57 -0400 Subject: [PATCH 0560/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 121 +++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 30258a91..7c116009 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1769,7 +1769,7 @@ void CWalletTx::GetAmounts(std::list& listReceived, address = CNoDestination(); } - COutputEntry output = {address, txout.nValue, txout.imgbase64 , (int)i}; + COutputEntry output = {address, txout.nValue, (int)i}; // If we are debited by the transaction, add the output as a "sent" entry if (nDebit > 0) @@ -2893,9 +2893,10 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov std::vector vecSend; // Turn the txout set into a CRecipient vector - BOOST_FOREACH(const CTxOut& txOut, tx.vout) + for (size_t idx = 0; idx < tx.vout.size(); idx++) { - CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, txOut.imgbase64, false}; + const CTxOut& txOut = tx.vout[idx]; + CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1}; vecSend.push_back(recipient); } @@ -3242,7 +3243,6 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std CReserveKey reservekey(this); CAmount nValue = 0; - std::string imgbase64=""; CTxDSIn txdsinCollateral; if (!GetCollateralTxDSIn(txdsinCollateral, nValue)) { @@ -3269,10 +3269,7 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std // create dummy data output only and pay everything as a fee txCollateral.vout.push_back(CTxOut(0, CScript() << OP_RETURN)); } - //pay collateral charge in fees - CTxOut txout = CTxOut(nValue - CPrivateSend::GetCollateralAmount(), scriptChange, imgbase64 ); - txCollateral.vout.push_back(txout); - + if (!SignSignature(*this, txdsinCollateral.prevPubKey, txCollateral, 0)) { strReason = "Unable to sign collateral transaction!"; return false; @@ -3281,7 +3278,7 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std return true; } -bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend) +bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend, const COutPoint& outpoint) { // make our change address CReserveKey reservekey(this); @@ -3292,11 +3289,14 @@ bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount a CAmount nFeeRet = 0; int nChangePosRet = -1; std::string strFail = ""; - vector< CRecipient > vecSend; - vecSend.push_back((CRecipient){scriptChange, amount, tx.mapValue["imgbase64"] , false}); + std::vector< CRecipient > vecSend; + vecSend.push_back((CRecipient){scriptChange, amount, false}); - CCoinControl *coinControl=NULL; - bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, coinControl, true, ALL_COINS, fUseInstantSend); + CCoinControl coinControl; + if (!outpoint.IsNull()) { + coinControl.Select(outpoint); + } + bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, &coinControl, true, ALL_COINS, fUseInstantSend); if(!success){ LogPrintf("CWallet::GetBudgetSystemCollateralTX -- Error: %s\n", strFail); return false; @@ -3323,18 +3323,25 @@ bool CWallet::ConvertList(std::vector vecTxIn, std::vector& vecA return true; } -bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, - int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl, bool sign, AvailableCoinsType nCoinType, bool fUseInstantSend) +bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, + int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, AvailableCoinsType nCoinType, bool fUseInstantSend, int nExtraPayloadSize) { - CAmount nFeePay = fUseInstantSend ? CTxLockRequest().GetMinFee() : 0; - std::string imgbase64=""; + if (!llmq::IsOldInstantSendEnabled()) { + // The new system does not require special handling for InstantSend as this is all done in CInstantSendManager. + // There is also no need for an extra fee anymore. + fUseInstantSend = false; + } + + CAmount nFeePay = fUseInstantSend ? CTxLockRequest().GetMinFee(true) : 0; + CAmount nValue = 0; + int nChangePosRequest = nChangePosInOut; unsigned int nSubtractFeeFromAmount = 0; - BOOST_FOREACH (const CRecipient& recipient, vecSend) + for (const auto& recipient : vecSend) { if (nValue < 0 || recipient.nAmount < 0) { - strFailReason = _("Transaction amounts must be positive"); + strFailReason = _("Transaction amounts must not be negative"); return false; } nValue += recipient.nAmount; @@ -3342,9 +3349,9 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt if (recipient.fSubtractFeeFromAmount) nSubtractFeeFromAmount++; } - if (vecSend.empty() || nValue < 0) + if (vecSend.empty()) { - strFailReason = _("Transaction amounts must be positive"); + strFailReason = _("Transaction must have at least one recipient"); return false; } @@ -3352,7 +3359,6 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt wtxNew.BindWallet(this); CMutableTransaction txNew; - // Discourage fee sniping. // // For a large miner the value of the transactions in the best block and @@ -3387,29 +3393,32 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt assert(txNew.nLockTime < LOCKTIME_THRESHOLD); { + std::set > setCoins; + std::vector vecTxDSInTmp; LOCK2(cs_main, cs_wallet); { + std::vector vAvailableCoins; + AvailableCoins(vAvailableCoins, true, coinControl, false, nCoinType, fUseInstantSend); + int nInstantSendConfirmationsRequired = Params().GetConsensus().nInstantSendConfirmationsRequired; + nFeeRet = 0; if(nFeePay > 0) nFeeRet = nFeePay; // Start with no fee and loop until there is enough fee while (true) { + nChangePosInOut = nChangePosRequest; txNew.vin.clear(); txNew.vout.clear(); wtxNew.fFromMe = true; - nChangePosRet = -1; bool fFirst = true; CAmount nValueToSelect = nValue; if (nSubtractFeeFromAmount == 0) nValueToSelect += nFeeRet; - double dPriority = 0; // vouts to the payees - BOOST_FOREACH (const CRecipient& recipient, vecSend) + for (const auto& recipient : vecSend) { - - CTxOut txout(recipient.nAmount, recipient.scriptPubKey, recipient.imgbase64); - + CTxOut txout(recipient.nAmount, recipient.scriptPubKey); if (recipient.fSubtractFeeFromAmount) { @@ -3422,7 +3431,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt } } - if (txout.IsDust(::minRelayTxFee)) + if (txout.IsDust(dustRelayFee)) { if (recipient.fSubtractFeeFromAmount && nFeeRet > 0) { @@ -3439,10 +3448,9 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt } // Choose coins to use - set > setCoins; CAmount nValueIn = 0; - - if (!SelectCoins(nValueToSelect, setCoins, nValueIn, coinControl, nCoinType, fUseInstantSend)) + setCoins.clear(); + if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, nValueIn, coinControl, nCoinType, fUseInstantSend)) { if (nCoinType == ONLY_NONDENOMINATED) { strFailReason = _("Unable to locate enough PrivateSend non-denominated funds for this transaction."); @@ -3453,31 +3461,17 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt strFailReason = _("Insufficient funds."); if (fUseInstantSend) { // could be not true but most likely that's the reason - strFailReason += " " + strprintf(_("InstantSend requires inputs with at least %d confirmations, you might need to wait a few minutes and try again."), INSTANTSEND_CONFIRMATIONS_REQUIRED); + strFailReason += " " + strprintf(_("InstantSend requires inputs with at least %d confirmations, you might need to wait a few minutes and try again."), nInstantSendConfirmationsRequired); } } return false; } if (fUseInstantSend && nValueIn > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) { - strFailReason += " " + strprintf(_("InstantSend doesn't support sending values that high yet. Transactions are currently limited to %1 DASH."), sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)); + strFailReason += " " + strprintf(_("InstantSend doesn't support sending values that high yet. Transactions are currently limited to %1 HTH."), sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)); return false; } - BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) - { - CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; - //The coin age after the next block (depth+1) is used instead of the current, - //reflecting an assumption the user would accept a bit more delay for - //a chance at a free transaction. - //But mempool inputs might still be in the mempool, so their age stays 0 - int age = pcoin.first->GetDepthInMainChain(); - assert(age >= 0); - if (age != 0) - age += 1; - dPriority += (double)nCredit * age; - } - const CAmount nChange = nValueIn - nValueToSelect; CTxOut newTxOut; @@ -3488,8 +3482,6 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt if (nCoinType == ONLY_DENOMINATED) { nFeeRet += nChange; wtxNew.mapValue["DS"] = "1"; - // recheck skipped denominations during next mixing - privateSendClient.ClearSkippedDenominations(); } else { // Fill a vout to ourself @@ -3521,21 +3513,21 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt scriptChange = GetScriptForDestination(vchPubKey.GetID()); } - newTxOut = CTxOut(nChange, scriptChange, imgbase64); + newTxOut = CTxOut(nChange, scriptChange); // We do not move dust-change to fees, because the sender would end up paying more than requested. // This would be against the purpose of the all-inclusive feature. // So instead we raise the change and deduct from the recipient. - if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(::minRelayTxFee)) + if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(dustRelayFee)) { - CAmount nDust = newTxOut.GetDustThreshold(::minRelayTxFee) - newTxOut.nValue; + CAmount nDust = newTxOut.GetDustThreshold(dustRelayFee) - newTxOut.nValue; newTxOut.nValue += nDust; // raise change until no more dust for (unsigned int i = 0; i < vecSend.size(); i++) // subtract from first recipient { if (vecSend[i].fSubtractFeeFromAmount) { txNew.vout[i].nValue -= nDust; - if (txNew.vout[i].IsDust(::minRelayTxFee)) + if (txNew.vout[i].IsDust(dustRelayFee)) { strFailReason = _("The transaction amount is too small to send after the fee has been deducted"); return false; @@ -3547,21 +3539,30 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt // Never create dust outputs; if we would, just // add the dust to the fee. - if (newTxOut.IsDust(::minRelayTxFee)) + if (newTxOut.IsDust(dustRelayFee)) { + nChangePosInOut = -1; nFeeRet += nChange; reservekey.ReturnKey(); } else { - // Insert change txn at random position: - nChangePosRet = GetRandInt(txNew.vout.size()+1); - vector::iterator position = txNew.vout.begin()+nChangePosRet; + if (nChangePosInOut == -1) + { + // Insert change txn at random position: + nChangePosInOut = GetRandInt(txNew.vout.size()+1); + } + else if ((unsigned int)nChangePosInOut > txNew.vout.size()) + { + strFailReason = _("Change index out of range"); + return false; + } + + std::vector::iterator position = txNew.vout.begin()+nChangePosInOut; txNew.vout.insert(position, newTxOut); } } - } - else + } else { reservekey.ReturnKey(); nChangePosInOut = -1; } From 5861dd95d22e189b89dace8e48619064774b5dd9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:24:19 -0400 Subject: [PATCH 0561/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6faf8ecf..6328f5ad 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -518,8 +518,8 @@ void BitcoinGUI::createActions() connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); - connect(overviewaAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(overviewaAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); + connect(privateSendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(privateSendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); #endif // ENABLE_WALLET From a27095d123cf9d111bbaa0f3308523e6554ec112 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:27:53 -0400 Subject: [PATCH 0562/1324] Update paymentserver.cpp --- src/qt/paymentserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 9d5fed55..38c180c9 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -580,7 +580,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen } // Extract and check amounts - CTxOut txOut(sendingTo.second, sendingTo.first,recipient.imgbase64.toUtf8().constData()); + CTxOut txOut(sendingTo.second, sendingTo.first); if (txOut.IsDust(dustRelayFee)) { Q_EMIT message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).") .arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)), From 4a794922ba1aa4365879743878a515a5d766b8af Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:29:00 -0400 Subject: [PATCH 0563/1324] Update transactionrecord.cpp --- src/qt/transactionrecord.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index fb0f1fb7..f5ef2140 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -44,22 +44,22 @@ QList TransactionRecord::decomposeTransaction(const CWallet * CAmount nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; - std::string imgbase64=mapValue["imgbase64"]; + if (nNet > 0 || wtx.IsCoinBase()) { // // Credit // - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) { + const CTxOut& txout = wtx.tx->vout[i]; isminetype mine = wallet->IsMine(txout); if(mine) { TransactionRecord sub(hash, nTime); CTxDestination address; - sub.idx = parts.size(); // sequence number + sub.idx = i; // vout index sub.credit = txout.nValue; - sub.imgbase64=txout.imgbase64; sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address)) { @@ -114,7 +114,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * } if(fAllFromMeDenom && fAllToMeDenom && nFromMe * nToMe) { - parts.append(TransactionRecord(hash, nTime, TransactionRecord::PrivateSendDenominate, "", imgbase64, -nDebit, nCredit)); + parts.append(TransactionRecord(hash, nTime, TransactionRecord::PrivateSendDenominate, "", -nDebit, nCredit)); parts.last().involvesWatchAddress = false; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe && fAllToMe) @@ -127,8 +127,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // Payment to self by default sub.type = TransactionRecord::SendToSelf; sub.address = ""; - const CTxOut& txoutex = wtx.vout[0]; - sub.imgbase64=txoutex.imgbase64; + if(mapValue["DS"] == "1") { sub.type = TransactionRecord::PrivateSend; @@ -200,7 +199,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * TransactionRecord sub(hash, nTime); sub.idx = nOut; sub.involvesWatchAddress = involvesWatchAddress; - sub.imgbase64=txout.imgbase64; + if(wallet->IsMine(txout)) { // Ignore parts sent to self, as this is usually the change @@ -244,7 +243,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // // Mixed debit transaction, can't break down payees // - parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", imgbase64, nNet, 0)); + parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); parts.last().involvesWatchAddress = involvesWatchAddress; } } From 2d86a157cd0bf0bbb04e501e81c21ccd23e6c134 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:29:36 -0400 Subject: [PATCH 0564/1324] Update transactionrecord.h --- src/qt/transactionrecord.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 32d13cc6..3ad6556f 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -98,20 +98,20 @@ class TransactionRecord static const int RecommendedNumConfirmations = 6; TransactionRecord(): - hash(), time(0), type(Other), address(""), imgbase64(""), debit(0), credit(0), idx(0) + hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0) { } TransactionRecord(uint256 _hash, qint64 _time): - hash(_hash), time(_time), type(Other), address(""), imgbase64(""), debit(0), + hash(_hash), time(_time), type(Other), address(""), debit(0), credit(0), idx(0) { } TransactionRecord(uint256 _hash, qint64 _time, - Type type, const std::string &address,const std::string &imgbase64, + Type _type, const std::string &_address, const CAmount& _debit, const CAmount& _credit): - hash(_hash), time(_time), type(_type), address(_address), imgbase64(imgbase64), debit(_debit), credit(_credit), + hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit), idx(0) { } @@ -127,7 +127,6 @@ class TransactionRecord qint64 time; Type type; std::string address; - std::string imgbase64; CAmount debit; CAmount credit; /**@}*/ From a157628232e8579bf9c9cfca593400e93ca58d86 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:30:02 -0400 Subject: [PATCH 0565/1324] Update transactiontablemodel.cpp --- src/qt/transactiontablemodel.cpp | 46 ++++++++------------------------ 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index fb8404a6..3a739770 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -37,7 +37,6 @@ static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, /* type */ Qt::AlignLeft|Qt::AlignVCenter, /* address */ Qt::AlignRight|Qt::AlignVCenter /* amount */ - Qt::AlignLeft|Qt::AlignVCenter, /* imgbase64 */ }; // Comparison operator for sort/binary search of model tx list @@ -94,7 +93,6 @@ class TransactionTablePriv /* Update our model of the wallet incrementally, to synchronize our model of the wallet with that of the core. - Call with transaction that was added, removed or changed. */ void updateWallet(const uint256 &hash, int status, bool showTransaction) @@ -245,7 +243,7 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle fProcessingQueuedTransactions(false), platformStyle(_platformStyle) { - columns << QString() << QString() << QString() << tr("Date") << tr("Type") << tr("Address / Label") << tr("Imgbase64") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit()); + columns << QString() << QString() << QString() << tr("Date") << tr("Type") << tr("Address / Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit()); priv->refreshWallet(); connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); @@ -611,23 +609,6 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxType(rec); case ToAddress: return formatTxToAddress(rec, false); - case Imgbase64:{ - QString qimgbase64 = QString(); - qimgbase64 = QString::fromStdString(rec->imgbase64); - if(qimgbase64.size()>500){ - - qimgbase64 = qimgbase64.left(499); - qimgbase64 = qimgbase64 + " ..."; - } - - if(qimgbase64.size()>2) { - QString mensage = qimgbase64.section(":", 0, 0, QString::SectionSkipEmpty); - if(mensage=="m") qimgbase64 = qimgbase64.mid(2); - if(mensage=="from") qimgbase64 = qimgbase64.mid(40); - } - - return qimgbase64; - } case Amount: return formatTxAmount(rec, true, BitcoinUnits::separatorAlways); } @@ -644,19 +625,10 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxType(rec); case Watchonly: return (rec->involvesWatchAddress ? 1 : 0); + case InstantSend: + return (rec->status.lockedByInstantSend ? 1 : 0); case ToAddress: return formatTxToAddress(rec, true); - case Imgbase64:{ - QString qimgbase64 = QString(); - qimgbase64 = QString::fromStdString(rec->imgbase64); - if(qimgbase64.size()>500){ - - qimgbase64 = qimgbase64.left(499); - //qimgbase64->setText(qimgbase64->toUtf8() + " ..."); - qimgbase64 = qimgbase64 + " ..."; - } - return qimgbase64; - } case Amount: return qint64(rec->credit + rec->debit); } @@ -671,6 +643,10 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const { return COLOR_TX_STATUS_DANGER; } + if(rec->status.lockedByInstantSend) + { + return COLOR_TX_STATUS_LOCKED; + } // Non-confirmed (but not immature) as transactions are grey if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature) { @@ -693,14 +669,16 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return rec->involvesWatchAddress; case WatchonlyDecorationRole: return txWatchonlyDecoration(rec); + case InstantSendRole: + return rec->status.lockedByInstantSend; + case InstantSendDecorationRole: + return txInstantSendDecoration(rec); case LongDescriptionRole: return priv->describe(rec, walletModel->getOptionsModel()->getDisplayUnit()); case AddressRole: return QString::fromStdString(rec->address); case LabelRole: return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address)); - case Imgbase64Role: - return QString::fromStdString(rec->imgbase64); case AmountRole: return qint64(rec->credit + rec->debit); case TxIDRole: @@ -743,9 +721,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const return formatTxAmount(rec, false, BitcoinUnits::separatorNever); case StatusRole: return rec->status.status; - } - return QVariant(); } From 018631d60b510c3c3faac3668b1bfd7db58499bd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:30:49 -0400 Subject: [PATCH 0566/1324] Update transactiontablemodel.h --- src/qt/transactiontablemodel.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index 2cba491c..81c94dcf 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -34,7 +34,6 @@ class TransactionTableModel : public QAbstractTableModel Date = 3, Type = 4, ToAddress = 5, - Imgbase64 = 5, Amount = 6 }; @@ -60,7 +59,6 @@ class TransactionTableModel : public QAbstractTableModel AddressRole, /** Label of address related to transaction */ LabelRole, - Imgbase64Role, /** Net amount of transaction */ AmountRole, /** Unique identifier */ From 0ab20d9c4716e89751d31767467243ee4f3da0b4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:31:11 -0400 Subject: [PATCH 0567/1324] Update transactionview.h --- src/qt/transactionview.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index 04e08333..334d2052 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -70,7 +70,6 @@ class TransactionView : public QWidget QComboBox *instantsendWidget; QLineEdit *addressWidget; QLineEdit *amountWidget; - QLineEdit *imgbase64Widget; QMenu *contextMenu; QSignalMapper *mapperThirdPartyTxUrls; @@ -103,7 +102,6 @@ private Q_SLOTS: void openThirdPartyTxUrl(QString url); void updateWatchOnlyColumn(bool fHaveWatchOnly); void abandonTx(); - void copyImgbase64(); Q_SIGNALS: void doubleClicked(const QModelIndex&); From 97f1196947b4bbe6ffb19b0b910bfb91437bdd75 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:31:38 -0400 Subject: [PATCH 0568/1324] Update transactionview.cpp --- src/qt/transactionview.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 437790c2..7f2be564 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -119,13 +119,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa #endif addressWidget->setObjectName("addressWidget"); hlayout->addWidget(addressWidget); - - // imgbase64Widget = new QLineEdit(this); -// #if QT_VERSION >= 0x040700 -// imgbase64Widget->setPlaceholderText(tr("Enter Imgbase64 to search")); -// #endif -// imgbase64Widget->setObjectName("imgbase64Widget"); -// hlayout->addWidget(imgbase64Widget); amountWidget = new QLineEdit(this); #if QT_VERSION >= 0x040700 @@ -176,7 +169,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *showDetailsAction = new QAction(tr("Show transaction details"), this); QAction *showAddressQRCodeAction = new QAction(tr("Show address QR code"), this); - QAction *copyImgbase64Action = new QAction(tr("Copy img"), this); contextMenu = new QMenu(this); contextMenu->addAction(copyAddressAction); @@ -190,7 +182,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa contextMenu->addSeparator(); contextMenu->addAction(abandonAction); contextMenu->addAction(editLabelAction); - contextMenu->addAction(copyImgbase64Action); mapperThirdPartyTxUrls = new QSignalMapper(this); @@ -203,7 +194,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa connect(instantsendWidget, SIGNAL(activated(int)), this, SLOT(chooseInstantSend(int))); connect(addressWidget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString))); connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString))); - //connect(imgbase64Widget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString))); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(computeSum())); @@ -219,7 +209,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); connect(showAddressQRCodeAction, SIGNAL(triggered()), this, SLOT(showAddressQRCode())); - connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); } void TransactionView::setModel(WalletModel *_model) @@ -251,7 +240,6 @@ void TransactionView::setModel(WalletModel *_model) transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Imgbase64, TYPE_COLUMN_WIDTH); // Note: it's a good idea to connect this signal AFTER the model is set connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); @@ -422,7 +410,6 @@ void TransactionView::exportClicked() writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole); writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole); - writer.addColumn(tr("Imgbase64"), 0, TransactionTableModel::Imgbase64Role); if(!writer.write()) { Q_EMIT message(tr("Exporting Failed"), tr("There was an error trying to save the transaction history to %1.").arg(filename), @@ -477,11 +464,6 @@ void TransactionView::copyAddress() GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole); } -void TransactionView::copyImgbase64() -{ - GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); -} - void TransactionView::copyLabel() { GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole); From a8232583470057c20a57f227e521801825f37ba7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:38:59 -0400 Subject: [PATCH 0569/1324] Update walletmodel.h --- src/qt/walletmodel.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 095c94a1..83c262f4 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -58,6 +58,10 @@ class SendCoinsRecipient CAmount amount; // If from a payment request, this is used for storing the memo QString message; + + // DAC message or prayer + QString txtMessage; + bool fDonate; // If from a payment request, paymentRequest.IsInitialized() will be true PaymentRequestPlus paymentRequest; From a21dffc5fb6d443e61a779db376e1f9e5a568117 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:39:45 -0400 Subject: [PATCH 0570/1324] Update wallet.h --- src/wallet/wallet.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ef17e23d..49026792 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -174,6 +174,12 @@ struct CRecipient CScript scriptPubKey; CAmount nAmount; bool fSubtractFeeFromAmount; + // DAC: + + bool fDonate; + + std::string txtMessage; + // END OF DAC }; typedef std::map mapValue_t; From aa37b4a1ed0d4ff02b2624247b43f2f00a33c1c5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:32:43 -0400 Subject: [PATCH 0571/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 159 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 129 insertions(+), 30 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6328f5ad..c0f24c4f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,6 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +/* #include "tradingdialogpage.h" */ + #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -128,7 +130,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * openRPCConsoleAction(0), openAction(0), showHelpMessageAction(0), - showPrivateSendHelpAction(0), + /* showPrivateSendHelpAction(0), */ trayIcon(0), trayIconMenu(0), dockIconMenu(0), @@ -139,6 +141,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * prevBlocks(0), spinnerFrame(0), governanceAction(0), + /* tradingAction(0), */ + externalDonate(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -429,7 +433,7 @@ void BitcoinGUI::createActions() sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2)); #endif tabGroup->addAction(sendCoinsAction); - + sendCoinsMenuAction = new QAction(QIcon(":/icons/" + theme + "/send"), sendCoinsAction->text(), this); sendCoinsMenuAction->setStatusTip(sendCoinsAction->statusTip()); sendCoinsMenuAction->setToolTip(sendCoinsMenuAction->statusTip()); @@ -448,6 +452,7 @@ void BitcoinGUI::createActions() receiveCoinsMenuAction = new QAction(QIcon(":/icons/" + theme + "/receiving_addresses"), receiveCoinsAction->text(), this); receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip()); receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip()); + historyAction = new QAction(QIcon(":/icons/" + theme + "/history"), tr("&Transactions"), this); historyAction->setStatusTip(tr("Browse transaction history")); @@ -483,25 +488,40 @@ void BitcoinGUI::createActions() governanceAction->setToolTip(governanceAction->statusTip()); governanceAction->setCheckable(true); #ifdef Q_OS_MAC - governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_5)); + governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); #else - governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5)); + governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); #endif tabGroup->addAction(governanceAction); connect(governanceAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); + } - - privateSendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); - privateSendAction->setStatusTip(tr("Show Private Send of wallet")); - privateSendAction->setToolTip(privateSendAction->statusTip()); - privateSendAction->setCheckable(true); + /* { + tradingAction = new QAction(QIcon(":/icons/chat"), tr("&Trading"), this); + tradingAction->setStatusTip(tr("Trade HTH Today")); + tradingAction->setToolTip(tradingAction->statusTip()); + tradingAction->setCheckable(true); #ifdef Q_OS_MAC - privateSendAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); + tradingAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); #else - privateSendAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); + tradingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif - tabGroup->addAction(privateSendAction); + tabGroup->addAction(tradingAction); + connect(tradingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(tradingAction, SIGNAL(triggered()), this, SLOT(gotoTradingDialogPage())); + + } */ + /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); + privatesendAction->setStatusTip(tr("Show Private Send of wallet")); + privatesendAction->setToolTip(privatesendAction->statusTip()); + privatesendAction->setCheckable(true); +#ifdef Q_OS_MAC + privatesendAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); +#else + privatesendAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); +#endif + tabGroup->addAction(privatesendAction); */ // These showNormalIfMinimized are needed because Send Coins and Receive Coins @@ -518,8 +538,8 @@ void BitcoinGUI::createActions() connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); - connect(privateSendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(privateSendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); + /* connect(privatesendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(privatesendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); */ #endif // ENABLE_WALLET @@ -576,7 +596,7 @@ void BitcoinGUI::createActions() openGraphAction->setEnabled(false); openPeersAction->setEnabled(false); openRepairAction->setEnabled(false); - + usedSendingAddressesAction = new QAction(QIcon(":/icons/" + theme + "/address-book"), tr("&Sending addresses..."), this); usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels")); usedReceivingAddressesAction = new QAction(QIcon(":/icons/" + theme + "/address-book"), tr("&Receiving addresses..."), this); @@ -589,18 +609,27 @@ void BitcoinGUI::createActions() showHelpMessageAction->setMenuRole(QAction::NoRole); showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Dash command-line options").arg(tr(PACKAGE_NAME))); - showPrivateSendHelpAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&PrivateSend information"), this); +/* showPrivateSendHelpAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&PrivateSend information"), this); showPrivateSendHelpAction->setMenuRole(QAction::NoRole); - showPrivateSendHelpAction->setStatusTip(tr("Show the PrivateSend basic information")); - + showPrivateSendHelpAction->setStatusTip(tr("Show the PrivateSend basic information")); */ + + + // HTHW Donate + externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); + externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden())); connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked())); - connect(showPrivateSendHelpAction, SIGNAL(triggered()), this, SLOT(showPrivateSendHelpClicked())); - +/* connect(showPrivateSendHelpAction, SIGNAL(triggered()), this, SLOT(showPrivateSendHelpClicked())); */ + + + // HTHW Donate + connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); + // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -688,14 +717,19 @@ void BitcoinGUI::createMenuBar() tools->addSeparator(); tools->addAction(openConfEditorAction); tools->addAction(showBackupsAction); + } - + QMenu *help = appMenuBar->addMenu(tr("&Help")); help->addAction(showHelpMessageAction); - help->addAction(showPrivateSendHelpAction); + /* help->addAction(showPrivateSendHelpAction); */ help->addSeparator(); help->addAction(aboutAction); help->addAction(aboutQtAction); + + QMenu* donate = appMenuBar->addMenu(tr("&Donate")); + donate->addAction(externalDonate); + } void BitcoinGUI::createToolBars() @@ -709,7 +743,8 @@ void BitcoinGUI::createToolBars() toolbar->addAction(sendCoinsAction); toolbar->addAction(receiveCoinsAction); toolbar->addAction(historyAction); - toolbar->addAction(privateSendAction); +/* toolbar->addAction(privatesendAction); */ + QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) @@ -718,7 +753,10 @@ void BitcoinGUI::createToolBars() } toolbar->addAction(governanceAction); toolbar->addAction(unlockWalletAction); - + + /* toolbar->addAction(tradingAction); + toolbar->addAction(unlockWalletAction); */ + toolbar->setMovable(false); // remove unused icon in upper left corner overviewAction->setChecked(true); @@ -869,6 +907,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } + /*tradingAction->setEnabled(enabled); */ governanceAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); @@ -878,6 +917,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); openAction->setEnabled(enabled); + } void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle) @@ -999,14 +1039,13 @@ void BitcoinGUI::showHelpMessageClicked() helpMessageDialog->show(); } -void BitcoinGUI::showPrivateSendHelpClicked() +/*void BitcoinGUI::showPrivateSendHelpClicked() { if(!clientModel) return; - HelpMessageDialog dlg(this, HelpMessageDialog::pshelp); dlg.exec(); -} +} */ #ifdef ENABLE_WALLET void BitcoinGUI::openClicked() @@ -1018,6 +1057,28 @@ void BitcoinGUI::openClicked() } } +/*void BitcoinGUI::gotoTradingDialogPage() +{ + tradingAction->setChecked(true); + if (walletFrame) walletFrame->gotoTradingDialogPage(); +} */ + +void BitcoinGUI::openDonate() +{ + openExternalURL("https://helpthehomelessworldwide.org/donate"); +} + +void BitcoinGUI::openExternalURL(QString url) +{ + QMessageBox::StandardButton reply = QMessageBox::question(this, tr("Notice – External Link"), + QStringLiteral("This action will open up the following website in your default browser:

Help The Homeless Worldwide A NJ Nonprofit Corporation's Donation Page



To continue, hit your Enter key or press Ok.
Remember, never share your personal information or private keys on any social website.").arg(url), + QMessageBox::Cancel | QMessageBox::Ok, + QMessageBox::Ok); + + if (reply == QMessageBox::Ok) { + QDesktopServices::openUrl(QUrl(url)); + } +} void BitcoinGUI::gotoGovernancePage() { @@ -1025,11 +1086,11 @@ void BitcoinGUI::gotoGovernancePage() if (walletFrame) walletFrame->gotoGovernancePage(); } -void BitcoinGUI::gotoPrivateSendPage() +/*void BitcoinGUI::gotoPrivateSendPage() { - privateSendAction->setChecked(true); + privatesendAction->setChecked(true); if (walletFrame) walletFrame->gotoPrivateSendPage(); -} +} */ void BitcoinGUI::gotoOverviewPage() { @@ -1433,6 +1494,7 @@ void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) // Accept only URIs if(event->mimeData()->hasUrls()) event->acceptProposedAction(); + } void BitcoinGUI::dropEvent(QDropEvent *event) @@ -1570,6 +1632,43 @@ void BitcoinGUI::detectShutdown() } } + +// Governance - Check to see if we should submit a proposal + /* nProposalModulus++; + if (nProposalModulus % 15 == 0 && !fLoadingIndex) + { + nProposalModulus = 0; + if (!msURL.empty()) + { + QString qNav = GUIUtil::TOQS(msURL); + msURL = std::string(); + QDesktopServices::openUrl(QUrl(qNav)); + } + if (fProposalNeedsSubmitted) + { + nProposalModulus = 0; + if(masternodeSync.IsSynced() && chainActive.Tip() && chainActive.Tip()->nHeight > (nProposalPrepareHeight + 6)) + { + fProposalNeedsSubmitted = false; + std::string sError; + std::string sGovObj; + bool fSubmitted = SubmitProposalToNetwork(uTxIdFee, nProposalStartTime, msProposalHex, sError, sGovObj); + if (!sError.empty()) + { + LogPrintf("Proposal Submission Problem: %s ", sError); + } + msProposalResult = fSubmitted ? "Submitted Proposal Successfully
( " + sGovObj + " )" : sError; + LogPrintf(" Proposal Submission Result: %s \n", msProposalResult.c_str()); + } + else + { + msProposalResult = "Waiting for block " + RoundToString(nProposalPrepareHeight + 6, 0) + " to submit pending proposal. "; + } + } + } +} */ + + void BitcoinGUI::showProgress(const QString &title, int nProgress) { if (nProgress == 0) From ee96eaa3e0508ec04659203efa87659212c86fa0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:33:44 -0400 Subject: [PATCH 0572/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 62a7529c..1eb58065 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -10,6 +10,7 @@ #endif #include "amount.h" +#include "governancelist.h" #include #include @@ -37,6 +38,7 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; +/*class tradingDialogPage; */ class CWallet; @@ -102,8 +104,10 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; + QAction* externalDonate; QAction *governanceAction; - QAction* privateSendAction; + /* QAction *tradingAction; */ + /* QAction* privatesendAction; */ QAction *overviewAction; QAction *historyAction; QAction *masternodeAction; @@ -134,7 +138,8 @@ class BitcoinGUI : public QMainWindow QAction *showBackupsAction; QAction *openAction; QAction *showHelpMessageAction; - QAction *showPrivateSendHelpAction; +/* QAction *showPrivateSendHelpAction; */ + QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; @@ -226,11 +231,14 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - - /** Switch to masternode page */ + + + /** Switch to trading page */ + /* void gotoTradingDialogPage(); */ + /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - void gotoPrivateSendPage(); + /* void gotoPrivateSendPage(); */ /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ @@ -256,6 +264,9 @@ private Q_SLOTS: void aboutClicked(); /** Show debug window */ void showDebugWindow(); + /** Open external URL */ + void openDonate(); + void openExternalURL(QString url = ""); /** Show debug window and set focus to the appropriate tab */ void showInfo(); @@ -272,7 +283,7 @@ private Q_SLOTS: /** Show help message dialog */ void showHelpMessageClicked(); /** Show PrivateSend help message dialog */ - void showPrivateSendHelpClicked(); +/* void showPrivateSendHelpClicked(); */ #ifndef Q_OS_MAC /** Handle tray icon clicked */ void trayIconActivated(QSystemTrayIcon::ActivationReason reason); From 53b749d936e5307ba05dd843d7611501abf71c25 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:46:58 -0400 Subject: [PATCH 0573/1324] Add files via upload --- src/bbpsocket.cpp | 197 +++++ src/bbpsocket.h | 18 + src/masternodeman.cpp | 1578 ++++++++++++++++++++++++++++++++++ src/masternodeman.h | 240 ++++++ src/rpcpodc.cpp | 285 ++++++ src/rpcpodc.h | 33 + src/rpcpog.cpp | 1056 +++++++++++++++++++++++ src/rpcpog.h | 312 +++++++ src/smartcontract-client.cpp | 38 + src/smartcontract-client.h | 27 + src/smartcontract-server.cpp | 101 +++ src/smartcontract-server.h | 47 + 12 files changed, 3932 insertions(+) create mode 100644 src/bbpsocket.cpp create mode 100644 src/bbpsocket.h create mode 100644 src/masternodeman.cpp create mode 100644 src/masternodeman.h create mode 100644 src/rpcpodc.cpp create mode 100644 src/rpcpodc.h create mode 100644 src/rpcpog.cpp create mode 100644 src/rpcpog.h create mode 100644 src/smartcontract-client.cpp create mode 100644 src/smartcontract-client.h create mode 100644 src/smartcontract-server.cpp create mode 100644 src/smartcontract-server.h diff --git a/src/bbpsocket.cpp b/src/bbpsocket.cpp new file mode 100644 index 00000000..19ffdd5d --- /dev/null +++ b/src/bbpsocket.cpp @@ -0,0 +1,197 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "bbpsocket.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::asio::deadline_timer; +using boost::asio::ip::tcp; +using boost::lambda::bind; +using boost::lambda::var; +using boost::lambda::_1; + +//---------------------------------------------------------------------- + +// +// This class manages socket timeouts by subclassing a deadline timer. +// Each asynchronous operation is given a deadline by which it must complete. +// Deadlines are enforced by the check_deadline actor that persists for the lifetime of the socket object: +// +// +----------------+ +// | | +// | check_deadline |<---+ +// | | | +// +----------------+ | async_wait() +// | | +// +---------+ +// +// If the actor determines that the deadline has expired, the socket is closed +// and any outstanding operations are consequently cancelled. The socket +// operations themselves use boost::lambda function objects as completion +// handlers. For a given socket operation, the socket object runs the +// io_service to block thread execution until the actor completes. +// +// Written by Christopher M. Kohlhoff (Chris@Kohlhoff.com) and the DAC developers + + +class bbpsocket +{ +public: + bbpsocket() : socket_(io_service_), deadline_(io_service_) + { + deadline_.expires_at(boost::posix_time::pos_infin); + check_deadline(); + } + + void connect(const std::string& host, const std::string& service, + boost::posix_time::time_duration timeout) + { + tcp::resolver::query query(host, service); + tcp::resolver::iterator iter = tcp::resolver(io_service_).resolve(query); + + // Set a deadline for the asynchronous operation. + deadline_.expires_from_now(timeout); + boost::system::error_code ec = boost::asio::error::would_block; + + // Start the asynchronous operation itself. The boost::lambda function + // object is used as a callback and will update the ec when the operation completes. + boost::asio::async_connect(socket_, iter, var(ec) = boost::lambda::_1); + + // Block until the asynchronous operation has completed. + do io_service_.run_one(); while (ec == boost::asio::error::would_block); + if (ec || !socket_.is_open()) + throw boost::system::system_error( + ec ? ec : boost::asio::error::operation_aborted); + } + + std::string read_line(boost::posix_time::time_duration timeout) + { + // Set a deadline + deadline_.expires_from_now(timeout); + boost::system::error_code ec = boost::asio::error::would_block; + boost::asio::async_read_until(socket_, input_buffer_, '\n', var(ec) = boost::lambda::_1); + // Block until the asynchronous operation has completed. + do io_service_.run_one(); while (ec == boost::asio::error::would_block); + + if (ec) + throw boost::system::system_error(ec); + + std::string line; + std::istream is(&input_buffer_); + std::getline(is, line); + return line; + } + + void write_line(const std::string& line, + boost::posix_time::time_duration timeout) + { + std::string data = line + "\n"; + // Set a deadline + deadline_.expires_from_now(timeout); + boost::system::error_code ec = boost::asio::error::would_block; + boost::asio::async_write(socket_, boost::asio::buffer(data), var(ec) = boost::lambda::_1); + // Block until the asynchronous operation has completed. + do io_service_.run_one(); while (ec == boost::asio::error::would_block); + if (ec) + throw boost::system::system_error(ec); + } + +private: + void check_deadline() + { + if (deadline_.expires_at() <= deadline_timer::traits_type::now()) + { + // The deadline has passed. + boost::system::error_code ignored_ec; + socket_.close(ignored_ec); + deadline_.expires_at(boost::posix_time::pos_infin); + } + // Put the actor back to sleep. + deadline_.async_wait(bind(&bbpsocket::check_deadline, this)); + } + + boost::asio::io_service io_service_; + tcp::socket socket_; + deadline_timer deadline_; + boost::asio::streambuf input_buffer_; +}; + +//---------------------------------------------------------------------- + +std::string sPrepareVersion() +{ + ServiceFlags nLocalNodeServices = g_connman->GetLocalServices(); + CAddress addrYou = CAddress(CService(), nLocalNodeServices); + CAddress addrMe = CAddress(CService(), nLocalNodeServices); + uint256 mnauthChallenge; + GetRandBytes(mnauthChallenge.begin(), mnauthChallenge.size()); + int64_t nTime = GetAdjustedTime(); + CSerializedNetMsg msgmversion = CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe, + 1, strSubVersion, 0, ::fRelayTxes, mnauthChallenge); + std::string sVersion = VectorToString(msgmversion.data); + return sVersion; +} + +std::string PrepareHTTPPost(bool bPost, std::string sPage, std::string sHostHeader, const std::string& sMsg, const std::map& mapRequestHeaders) +{ + std::ostringstream s; + std::string sUserAgent = "Mozilla/5.0"; + std::string sMethod = bPost ? "POST" : "GET"; + + s << sMethod + " /" + sPage + " HTTP/1.1\r\n" + << "User-Agent: " + sUserAgent + "/" << FormatFullVersion() << "\r\n" + << "Host: " + sHostHeader + "" << "\r\n" + << "Content-Length: " << sMsg.size() << "\r\n"; + + for (auto item : mapRequestHeaders) + { + s << item.first << ": " << item.second << "\r\n"; + } + s << "\r\n" << sMsg; + return s.str(); +} + +std::string DACPost(std::string sHost, std::string sService, std::string sPage, std::string sPayload, int iTimeout) +{ + std::string sData; + try + { + bbpsocket c; + c.connect(sHost, sService, boost::posix_time::seconds(iTimeout)); + boost::posix_time::ptime time_sent = boost::posix_time::microsec_clock::universal_time(); + std::map mapRequestHeaders; + mapRequestHeaders["Agent"] = FormatFullVersion(); + std::string sPost = PrepareHTTPPost(true, sPage, sHost, sPayload, mapRequestHeaders); + c.write_line(sPost, boost::posix_time::seconds(iTimeout)); + for (;;) + { + std::string line = c.read_line(boost::posix_time::seconds(iTimeout)); + sData += line; + if (Contains(line, "") || Contains(line,"") || Contains(line,"")) + break; + } + } + catch (std::exception& e) + { + std::string sErr = std::string("DACPostException::") + e.what(); + return sErr; + } + return sData; +} + + + \ No newline at end of file diff --git a/src/bbpsocket.h b/src/bbpsocket.h new file mode 100644 index 00000000..567fb72c --- /dev/null +++ b/src/bbpsocket.h @@ -0,0 +1,18 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BBPSOCKET_H +#define BBPSOCKET_H + +#include +#include "util.h" +#include "clientversion.h" +#include "rpcpog.h" +#include "netmessagemaker.h" +#include "activemasternode.h" + +std::string DACPost(std::string sHost, std::string sService, std::string sPage, std::string sPayload, int iTimeout); +std::string PrepareHTTPPost(bool bPost, std::string sPage, std::string sHostHeader, const std::string& sMsg, const std::map& mapRequestHeaders); + +#endif diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp new file mode 100644 index 00000000..3bd9bfb0 --- /dev/null +++ b/src/masternodeman.cpp @@ -0,0 +1,1578 @@ +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "activemasternode.h" +#include "addrman.h" +#include "governance.h" +#include "masternode-payments.h" +#include "masternode-sync.h" +#include "masternodeman.h" +#include "messagesigner.h" +#include "netfulfilledman.h" +#ifdef ENABLE_WALLET +#include "privatesend-client.h" +#endif // ENABLE_WALLET +#include "script/standard.h" +#include "util.h" + +/** Masternode manager */ +CMasternodeMan mnodeman; + +const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-7"; + +struct CompareLastPaidBlock +{ + bool operator()(const std::pair& t1, + const std::pair& t2) const + { + return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); + } +}; + +struct CompareScoreMN +{ + bool operator()(const std::pair& t1, + const std::pair& t2) const + { + return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); + } +}; + +struct CompareByAddr + +{ + bool operator()(const CMasternode* t1, + const CMasternode* t2) const + { + return t1->addr < t2->addr; + } +}; + +CMasternodeMan::CMasternodeMan() +: cs(), + mapMasternodes(), + mAskedUsForMasternodeList(), + mWeAskedForMasternodeList(), + mWeAskedForMasternodeListEntry(), + mWeAskedForVerification(), + mMnbRecoveryRequests(), + mMnbRecoveryGoodReplies(), + listScheduledMnbRequestConnections(), + fMasternodesAdded(false), + fMasternodesRemoved(false), + vecDirtyGovernanceObjectHashes(), + nLastWatchdogVoteTime(0), + mapSeenMasternodeBroadcast(), + mapSeenMasternodePing(), + nDsqCount(0) +{} + +bool CMasternodeMan::Add(CMasternode &mn) +{ + LOCK(cs); + + if (Has(mn.vin.prevout)) return false; + + LogPrint("masternode", "CMasternodeMan::Add -- Adding new Masternode: addr=%s, %i now\n", mn.addr.ToString(), size() + 1); + mapMasternodes[mn.vin.prevout] = mn; + fMasternodesAdded = true; + return true; +} + +void CMasternodeMan::AskForMN(CNode* pnode, const COutPoint& outpoint, CConnman& connman) +{ + if(!pnode) return; + + LOCK(cs); + + std::map >::iterator it1 = mWeAskedForMasternodeListEntry.find(outpoint); + if (it1 != mWeAskedForMasternodeListEntry.end()) { + std::map::iterator it2 = it1->second.find(pnode->addr); + if (it2 != it1->second.end()) { + if (GetTime() < it2->second) { + // we've asked recently, should not repeat too often or we could get banned + return; + } + // we asked this node for this outpoint but it's ok to ask again already + LogPrintf("CMasternodeMan::AskForMN -- Asking same peer %s for missing masternode entry again: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); + } else { + // we already asked for this outpoint but not this node + LogPrintf("CMasternodeMan::AskForMN -- Asking new peer %s for missing masternode entry: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); + } + } else { + // we never asked any node for this outpoint + LogPrintf("CMasternodeMan::AskForMN -- Asking peer %s for missing masternode entry for the first time: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); + } + mWeAskedForMasternodeListEntry[outpoint][pnode->addr] = GetTime() + DSEG_UPDATE_SECONDS; + + connman.PushMessage(pnode, NetMsgType::DSEG, CTxIn(outpoint)); +} + +bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if (!pmn) { + return false; + } + nDsqCount++; + pmn->nLastDsq = nDsqCount; + pmn->fAllowMixingTx = true; + + return true; +} + +bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if (!pmn) { + return false; + } + pmn->fAllowMixingTx = false; + + return true; +} + +bool CMasternodeMan::PoSeBan(const COutPoint &outpoint) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if (!pmn) { + return false; + } + pmn->PoSeBan(); + + return true; +} + +void CMasternodeMan::Check() +{ + LOCK(cs); + + LogPrint("masternode", "CMasternodeMan::Check -- nLastWatchdogVoteTime=%d, IsWatchdogActive()=%d\n", nLastWatchdogVoteTime, IsWatchdogActive()); + + for (auto& mnpair : mapMasternodes) { + mnpair.second.Check(); + } +} + +void CMasternodeMan::CheckAndRemove(CConnman& connman) +{ + if(!masternodeSync.IsMasternodeListSynced()) return; + + LogPrintf("CMasternodeMan::CheckAndRemove\n"); + + { + // Need LOCK2 here to ensure consistent locking order because code below locks cs_main + // in CheckMnbAndUpdateMasternodeList() + LOCK2(cs_main, cs); + + Check(); + + // Remove spent masternodes, prepare structures and make requests to reasure the state of inactive ones + rank_pair_vec_t vecMasternodeRanks; + // ask for up to MNB_RECOVERY_MAX_ASK_ENTRIES masternode entries at a time + int nAskForMnbRecovery = MNB_RECOVERY_MAX_ASK_ENTRIES; + std::map::iterator it = mapMasternodes.begin(); + while (it != mapMasternodes.end()) { + CMasternodeBroadcast mnb = CMasternodeBroadcast(it->second); + uint256 hash = mnb.GetHash(); + // If collateral was spent ... + if (it->second.IsOutpointSpent()) { + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing Masternode: %s addr=%s %i now\n", it->second.GetStateString(), it->second.addr.ToString(), size() - 1); + + // erase all of the broadcasts we've seen from this txin, ... + mapSeenMasternodeBroadcast.erase(hash); + mWeAskedForMasternodeListEntry.erase(it->first); + + // and finally remove it from the list + it->second.FlagGovernanceItemsAsDirty(); + mapMasternodes.erase(it++); + fMasternodesRemoved = true; + } else { + bool fAsk = (nAskForMnbRecovery > 0) && + masternodeSync.IsSynced() && + it->second.IsNewStartRequired() && + !IsMnbRecoveryRequested(hash); + if(fAsk) { + // this mn is in a non-recoverable state and we haven't asked other nodes yet + std::set setRequested; + // calulate only once and only when it's needed + if(vecMasternodeRanks.empty()) { + int nRandomBlockHeight = GetRandInt(nCachedBlockHeight); + GetMasternodeRanks(vecMasternodeRanks, nRandomBlockHeight); + } + bool fAskedForMnbRecovery = false; + // ask first MNB_RECOVERY_QUORUM_TOTAL masternodes we can connect to and we haven't asked recently + for(int i = 0; setRequested.size() < MNB_RECOVERY_QUORUM_TOTAL && i < (int)vecMasternodeRanks.size(); i++) { + // avoid banning + if(mWeAskedForMasternodeListEntry.count(it->first) && mWeAskedForMasternodeListEntry[it->first].count(vecMasternodeRanks[i].second.addr)) continue; + // didn't ask recently, ok to ask now + CService addr = vecMasternodeRanks[i].second.addr; + setRequested.insert(addr); + listScheduledMnbRequestConnections.push_back(std::make_pair(addr, hash)); + fAskedForMnbRecovery = true; + } + if(fAskedForMnbRecovery) { + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Recovery initiated, masternode=%s\n", it->first.ToStringShort()); + nAskForMnbRecovery--; + } + // wait for mnb recovery replies for MNB_RECOVERY_WAIT_SECONDS seconds + mMnbRecoveryRequests[hash] = std::make_pair(GetTime() + MNB_RECOVERY_WAIT_SECONDS, setRequested); + } + ++it; + } + } + + // proces replies for MASTERNODE_NEW_START_REQUIRED masternodes + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- mMnbRecoveryGoodReplies size=%d\n", (int)mMnbRecoveryGoodReplies.size()); + std::map >::iterator itMnbReplies = mMnbRecoveryGoodReplies.begin(); + while(itMnbReplies != mMnbRecoveryGoodReplies.end()){ + if(mMnbRecoveryRequests[itMnbReplies->first].first < GetTime()) { + // all nodes we asked should have replied now + if(itMnbReplies->second.size() >= MNB_RECOVERY_QUORUM_REQUIRED) { + // majority of nodes we asked agrees that this mn doesn't require new mnb, reprocess one of new mnbs + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- reprocessing mnb, masternode=%s\n", itMnbReplies->second[0].vin.prevout.ToStringShort()); + // mapSeenMasternodeBroadcast.erase(itMnbReplies->first); + int nDos; + itMnbReplies->second[0].fRecovery = true; + CheckMnbAndUpdateMasternodeList(NULL, itMnbReplies->second[0], nDos, connman); + } + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- removing mnb recovery reply, masternode=%s, size=%d\n", itMnbReplies->second[0].vin.prevout.ToStringShort(), (int)itMnbReplies->second.size()); + mMnbRecoveryGoodReplies.erase(itMnbReplies++); + } else { + ++itMnbReplies; + } + } + } + { + // no need for cm_main below + LOCK(cs); + + std::map > >::iterator itMnbRequest = mMnbRecoveryRequests.begin(); + while(itMnbRequest != mMnbRecoveryRequests.end()){ + // Allow this mnb to be re-verified again after MNB_RECOVERY_RETRY_SECONDS seconds + // if mn is still in MASTERNODE_NEW_START_REQUIRED state. + if(GetTime() - itMnbRequest->second.first > MNB_RECOVERY_RETRY_SECONDS) { + mMnbRecoveryRequests.erase(itMnbRequest++); + } else { + ++itMnbRequest; + } + } + + // check who's asked for the Masternode list + std::map::iterator it1 = mAskedUsForMasternodeList.begin(); + while(it1 != mAskedUsForMasternodeList.end()){ + if((*it1).second < GetTime()) { + mAskedUsForMasternodeList.erase(it1++); + } else { + ++it1; + } + } + + // check who we asked for the Masternode list + it1 = mWeAskedForMasternodeList.begin(); + while(it1 != mWeAskedForMasternodeList.end()){ + if((*it1).second < GetTime()){ + mWeAskedForMasternodeList.erase(it1++); + } else { + ++it1; + } + } + + // check which Masternodes we've asked for + std::map >::iterator it2 = mWeAskedForMasternodeListEntry.begin(); + while(it2 != mWeAskedForMasternodeListEntry.end()){ + std::map::iterator it3 = it2->second.begin(); + while(it3 != it2->second.end()){ + if(it3->second < GetTime()){ + it2->second.erase(it3++); + } else { + ++it3; + } + } + if(it2->second.empty()) { + mWeAskedForMasternodeListEntry.erase(it2++); + } else { + ++it2; + } + } + + std::map::iterator it3 = mWeAskedForVerification.begin(); + while(it3 != mWeAskedForVerification.end()){ + if(it3->second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) { + mWeAskedForVerification.erase(it3++); + } else { + ++it3; + } + } + + // NOTE: do not expire mapSeenMasternodeBroadcast entries here, clean them on mnb updates! + + // remove expired mapSeenMasternodePing + std::map::iterator it4 = mapSeenMasternodePing.begin(); + while(it4 != mapSeenMasternodePing.end()){ + if((*it4).second.IsExpired()) { + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing expired Masternode ping: hash=%s\n", (*it4).second.GetHash().ToString()); + mapSeenMasternodePing.erase(it4++); + } else { + ++it4; + } + } + + // remove expired mapSeenMasternodeVerification + std::map::iterator itv2 = mapSeenMasternodeVerification.begin(); + while(itv2 != mapSeenMasternodeVerification.end()){ + if((*itv2).second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS){ + LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing expired Masternode verification: hash=%s\n", (*itv2).first.ToString()); + mapSeenMasternodeVerification.erase(itv2++); + } else { + ++itv2; + } + } + + LogPrintf("CMasternodeMan::CheckAndRemove -- %s\n", ToString()); + } + + if(fMasternodesRemoved) { + NotifyMasternodeUpdates(connman); + } +} + +void CMasternodeMan::Clear() +{ + LOCK(cs); + mapMasternodes.clear(); + mAskedUsForMasternodeList.clear(); + mWeAskedForMasternodeList.clear(); + mWeAskedForMasternodeListEntry.clear(); + mapSeenMasternodeBroadcast.clear(); + mapSeenMasternodePing.clear(); + nDsqCount = 0; + nLastWatchdogVoteTime = 0; +} + +int CMasternodeMan::CountMasternodes(int nProtocolVersion) +{ + LOCK(cs); + int nCount = 0; + nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; + + for (auto& mnpair : mapMasternodes) { + if(mnpair.second.nProtocolVersion < nProtocolVersion) continue; + nCount++; + } + + return nCount; +} + +int CMasternodeMan::CountEnabled(int nProtocolVersion) +{ + LOCK(cs); + int nCount = 0; + nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; + + for (auto& mnpair : mapMasternodes) { + if(mnpair.second.nProtocolVersion < nProtocolVersion || !mnpair.second.IsEnabled()) continue; + nCount++; + } + + return nCount; +} + +/* Only IPv4 masternodes are allowed in 12.1, saving this for later +int CMasternodeMan::CountByIP(int nNetworkType) +{ + LOCK(cs); + int nNodeCount = 0; + + for (auto& mnpair : mapMasternodes) + if ((nNetworkType == NET_IPV4 && mnpair.second.addr.IsIPv4()) || + (nNetworkType == NET_TOR && mnpair.second.addr.IsTor()) || + (nNetworkType == NET_IPV6 && mnpair.second.addr.IsIPv6())) { + nNodeCount++; + } + + return nNodeCount; +} +*/ + +void CMasternodeMan::DsegUpdate(CNode* pnode, CConnman& connman) +{ + LOCK(cs); + + if(Params().NetworkIDString() == CBaseChainParams::MAIN) { + if(!(pnode->addr.IsRFC1918() || pnode->addr.IsLocal())) { + std::map::iterator it = mWeAskedForMasternodeList.find(pnode->addr); + if(it != mWeAskedForMasternodeList.end() && GetTime() < (*it).second) { + LogPrintf("CMasternodeMan::DsegUpdate -- we already asked %s for the list; skipping...\n", pnode->addr.ToString()); + return; + } + } + } + + connman.PushMessage(pnode, NetMsgType::DSEG, CTxIn()); + int64_t askAgain = GetTime() + DSEG_UPDATE_SECONDS; + mWeAskedForMasternodeList[pnode->addr] = askAgain; + + LogPrint("masternode", "CMasternodeMan::DsegUpdate -- asked %s for the list\n", pnode->addr.ToString()); +} + +CMasternode* CMasternodeMan::Find(const COutPoint &outpoint) +{ + LOCK(cs); + auto it = mapMasternodes.find(outpoint); + return it == mapMasternodes.end() ? NULL : &(it->second); +} + +bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternode& masternodeRet) +{ + // Theses mutexes are recursive so double locking by the same thread is safe. + LOCK(cs); + auto it = mapMasternodes.find(outpoint); + if (it == mapMasternodes.end()) { + return false; + } + + masternodeRet = it->second; + return true; +} + +bool CMasternodeMan::GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet) +{ + LOCK(cs); + auto it = mapMasternodes.find(outpoint); + if (it == mapMasternodes.end()) { + return false; + } + mnInfoRet = it->second.GetInfo(); + return true; +} + +bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet) +{ + LOCK(cs); + for (auto& mnpair : mapMasternodes) { + if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { + mnInfoRet = mnpair.second.GetInfo(); + return true; + } + } + return false; +} + +bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet) +{ + LOCK(cs); + for (auto& mnpair : mapMasternodes) { + CScript scriptCollateralAddress = GetScriptForDestination(mnpair.second.pubKeyCollateralAddress.GetID()); + if (scriptCollateralAddress == payee) { + mnInfoRet = mnpair.second.GetInfo(); + return true; + } + } + return false; +} + +bool CMasternodeMan::Has(const COutPoint& outpoint) +{ + LOCK(cs); + return mapMasternodes.find(outpoint) != mapMasternodes.end(); +} + +// +// Deterministically select the oldest/best masternode to pay on the network +// +bool CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) +{ + return GetNextMasternodeInQueueForPayment(nCachedBlockHeight, fFilterSigTime, nCountRet, mnInfoRet); +} + +bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) +{ + mnInfoRet = masternode_info_t(); + nCountRet = 0; + + if (!masternodeSync.IsWinnersListSynced()) { + // without winner list we can't reliably find the next winner anyway + return false; + } + + // Need LOCK2 here to ensure consistent locking order because the GetBlockHash call below locks cs_main + LOCK2(cs_main,cs); + + std::vector > vecMasternodeLastPaid; + + /* + Make a vector with all of the last paid times + */ + + int nMnCount = CountMasternodes(); + + for (auto& mnpair : mapMasternodes) { + if(!mnpair.second.IsValidForPayment()) continue; + + //check protocol version + if(mnpair.second.nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) continue; + + //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it + if(mnpayments.IsScheduled(mnpair.second, nBlockHeight)) continue; + + //it's too new, wait for a cycle + if(fFilterSigTime && mnpair.second.sigTime + (nMnCount*2.6*60) > GetAdjustedTime()) continue; + + //make sure it has at least as many confirmations as there are masternodes + if(GetUTXOConfirmations(mnpair.first) < nMnCount) continue; + + vecMasternodeLastPaid.push_back(std::make_pair(mnpair.second.GetLastPaidBlock(), &mnpair.second)); + } + + nCountRet = (int)vecMasternodeLastPaid.size(); + + //when the network is in the process of upgrading, don't penalize nodes that recently restarted + if(fFilterSigTime && nCountRet < nMnCount/3) + return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCountRet, mnInfoRet); + + // Sort them low to high + sort(vecMasternodeLastPaid.begin(), vecMasternodeLastPaid.end(), CompareLastPaidBlock()); + + uint256 blockHash; + if(!GetBlockHash(blockHash, nBlockHeight - 101)) { + LogPrintf("CMasternode::GetNextMasternodeInQueueForPayment -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", nBlockHeight - 101); + return false; + } + // Look at 1/10 of the oldest nodes (by last payment), calculate their scores and pay the best one + // -- This doesn't look at who is being paid in the +8-10 blocks, allowing for double payments very rarely + // -- 1/100 payments should be a double payment on mainnet - (1/(3000/10))*2 + // -- (chance per block * chances before IsScheduled will fire) + int nTenthNetwork = nMnCount/10; + int nCountTenth = 0; + arith_uint256 nHighest = 0; + CMasternode *pBestMasternode = NULL; + BOOST_FOREACH (PAIRTYPE(int, CMasternode*)& s, vecMasternodeLastPaid){ + arith_uint256 nScore = s.second->CalculateScore(blockHash); + if(nScore > nHighest){ + nHighest = nScore; + pBestMasternode = s.second; + } + nCountTenth++; + if(nCountTenth >= nTenthNetwork) break; + } + if (pBestMasternode) { + mnInfoRet = pBestMasternode->GetInfo(); + } + return mnInfoRet.fInfoValid; +} + +masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vector &vecToExclude, int nProtocolVersion) +{ + LOCK(cs); + + nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; + + int nCountEnabled = CountEnabled(nProtocolVersion); + int nCountNotExcluded = nCountEnabled - vecToExclude.size(); + + LogPrintf("CMasternodeMan::FindRandomNotInVec -- %d enabled masternodes, %d masternodes to choose from\n", nCountEnabled, nCountNotExcluded); + if(nCountNotExcluded < 1) return masternode_info_t(); + + // fill a vector of pointers + std::vector vpMasternodesShuffled; + for (auto& mnpair : mapMasternodes) { + vpMasternodesShuffled.push_back(&mnpair.second); + } + + InsecureRand insecureRand; + // shuffle pointers + std::random_shuffle(vpMasternodesShuffled.begin(), vpMasternodesShuffled.end(), insecureRand); + bool fExclude; + + // loop through + BOOST_FOREACH(CMasternode* pmn, vpMasternodesShuffled) { + if(pmn->nProtocolVersion < nProtocolVersion || !pmn->IsEnabled()) continue; + fExclude = false; + BOOST_FOREACH(const COutPoint &outpointToExclude, vecToExclude) { + if(pmn->vin.prevout == outpointToExclude) { + fExclude = true; + break; + } + } + if(fExclude) continue; + // found the one not in vecToExclude + LogPrint("masternode", "CMasternodeMan::FindRandomNotInVec -- found, masternode=%s\n", pmn->vin.prevout.ToStringShort()); + return pmn->GetInfo(); + } + + LogPrint("masternode", "CMasternodeMan::FindRandomNotInVec -- failed\n"); + return masternode_info_t(); +} + +bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeMan::score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol) +{ + vecMasternodeScoresRet.clear(); + + if (!masternodeSync.IsMasternodeListSynced()) + return false; + + AssertLockHeld(cs); + + if (mapMasternodes.empty()) + return false; + + // calculate scores + for (auto& mnpair : mapMasternodes) { + if (mnpair.second.nProtocolVersion >= nMinProtocol) { + vecMasternodeScoresRet.push_back(std::make_pair(mnpair.second.CalculateScore(nBlockHash), &mnpair.second)); + } + } + + sort(vecMasternodeScoresRet.rbegin(), vecMasternodeScoresRet.rend(), CompareScoreMN()); + return !vecMasternodeScoresRet.empty(); +} + +bool CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int& nRankRet, int nBlockHeight, int nMinProtocol) +{ + nRankRet = -1; + + if (!masternodeSync.IsMasternodeListSynced()) + return false; + + // make sure we know about this block + uint256 nBlockHash = uint256(); + if (!GetBlockHash(nBlockHash, nBlockHeight)) { + LogPrintf("CMasternodeMan::%s -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", __func__, nBlockHeight); + return false; + } + + LOCK(cs); + + score_pair_vec_t vecMasternodeScores; + if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol)) + return false; + + int nRank = 0; + for (auto& scorePair : vecMasternodeScores) { + nRank++; + if(scorePair.second->vin.prevout == outpoint) { + nRankRet = nRank; + return true; + } + } + + return false; +} + +bool CMasternodeMan::GetMasternodeRanks(CMasternodeMan::rank_pair_vec_t& vecMasternodeRanksRet, int nBlockHeight, int nMinProtocol) +{ + vecMasternodeRanksRet.clear(); + + if (!masternodeSync.IsMasternodeListSynced()) + return false; + + // make sure we know about this block + uint256 nBlockHash = uint256(); + if (!GetBlockHash(nBlockHash, nBlockHeight)) { + LogPrintf("CMasternodeMan::%s -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", __func__, nBlockHeight); + return false; + } + + LOCK(cs); + + score_pair_vec_t vecMasternodeScores; + if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol)) + return false; + + int nRank = 0; + for (auto& scorePair : vecMasternodeScores) { + nRank++; + vecMasternodeRanksRet.push_back(std::make_pair(nRank, *scorePair.second)); + } + + return true; +} + +void CMasternodeMan::ProcessMasternodeConnections(CConnman& connman) +{ + //we don't care about this for regtest + if(Params().NetworkIDString() == CBaseChainParams::REGTEST) return; + + connman.ForEachNode(CConnman::AllNodes, [](CNode* pnode) { +#ifdef ENABLE_WALLET + if(pnode->fMasternode && !privateSendClient.IsMixingMasternode(pnode)) { +#else + if(pnode->fMasternode) { +#endif // ENABLE_WALLET + LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->id, pnode->addr.ToString()); + pnode->fDisconnect = true; + } + }); +} + +std::pair > CMasternodeMan::PopScheduledMnbRequestConnection() +{ + LOCK(cs); + if(listScheduledMnbRequestConnections.empty()) { + return std::make_pair(CService(), std::set()); + } + + std::set setResult; + + listScheduledMnbRequestConnections.sort(); + std::pair pairFront = listScheduledMnbRequestConnections.front(); + + // squash hashes from requests with the same CService as the first one into setResult + std::list< std::pair >::iterator it = listScheduledMnbRequestConnections.begin(); + while(it != listScheduledMnbRequestConnections.end()) { + if(pairFront.first == it->first) { + setResult.insert(it->second); + it = listScheduledMnbRequestConnections.erase(it); + } else { + // since list is sorted now, we can be sure that there is no more hashes left + // to ask for from this addr + break; + } + } + return std::make_pair(pairFront.first, setResult); +} + + +void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman) +{ + if(fLiteMode) return; // disable all Dash specific functionality + + if (strCommand == NetMsgType::MNANNOUNCE) { //Masternode Broadcast + + CMasternodeBroadcast mnb; + vRecv >> mnb; + + pfrom->setAskFor.erase(mnb.GetHash()); + + if(!masternodeSync.IsBlockchainSynced()) return; + + LogPrint("masternode", "MNANNOUNCE -- Masternode announce, masternode=%s\n", mnb.vin.prevout.ToStringShort()); + + int nDos = 0; + + if (CheckMnbAndUpdateMasternodeList(pfrom, mnb, nDos, connman)) { + // use announced Masternode as a peer + connman.AddNewAddress(CAddress(mnb.addr, NODE_NETWORK), pfrom->addr, 2*60*60); + } else if(nDos > 0) { + Misbehaving(pfrom->GetId(), nDos); + } + + if(fMasternodesAdded) { + NotifyMasternodeUpdates(connman); + } + } else if (strCommand == NetMsgType::MNPING) { //Masternode Ping + + CMasternodePing mnp; + vRecv >> mnp; + + uint256 nHash = mnp.GetHash(); + + pfrom->setAskFor.erase(nHash); + + if(!masternodeSync.IsBlockchainSynced()) return; + + LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort()); + + // Need LOCK2 here to ensure consistent locking order because the CheckAndUpdate call below locks cs_main + LOCK2(cs_main, cs); + + if(mapSeenMasternodePing.count(nHash)) return; //seen + mapSeenMasternodePing.insert(std::make_pair(nHash, mnp)); + + LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); + + // see if we have this Masternode + CMasternode* pmn = Find(mnp.vin.prevout); + + // if masternode uses sentinel ping instead of watchdog + // we shoud update nTimeLastWatchdogVote here if sentinel + // ping flag is actual + if(pmn && mnp.fSentinelIsCurrent) + UpdateWatchdogVoteTime(mnp.vin.prevout, mnp.sigTime); + + // too late, new MNANNOUNCE is required + if(pmn && pmn->IsNewStartRequired()) return; + + int nDos = 0; + if(mnp.CheckAndUpdate(pmn, false, nDos, connman)) return; + + if(nDos > 0) { + // if anything significant failed, mark that node + Misbehaving(pfrom->GetId(), nDos); + } else if(pmn != NULL) { + // nothing significant failed, mn is a known one too + return; + } + + // something significant is broken or mn is unknown, + // we might have to ask for a masternode entry once + AskForMN(pfrom, mnp.vin.prevout, connman); + + } else if (strCommand == NetMsgType::DSEG) { //Get Masternode list or specific entry + // Ignore such requests until we are fully synced. + // We could start processing this after masternode list is synced + // but this is a heavy one so it's better to finish sync first. + if (!masternodeSync.IsSynced()) return; + + CTxIn vin; + vRecv >> vin; + + LogPrint("masternode", "DSEG -- Masternode list, masternode=%s\n", vin.prevout.ToStringShort()); + + LOCK(cs); + + if(vin == CTxIn()) { //only should ask for this once + //local network + bool isLocal = (pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal()); + + if(!isLocal && Params().NetworkIDString() == CBaseChainParams::MAIN) { + std::map::iterator it = mAskedUsForMasternodeList.find(pfrom->addr); + if (it != mAskedUsForMasternodeList.end() && it->second > GetTime()) { + Misbehaving(pfrom->GetId(), 34); + LogPrintf("DSEG -- peer already asked me for the list, peer=%d\n", pfrom->id); + return; + } + int64_t askAgain = GetTime() + DSEG_UPDATE_SECONDS; + mAskedUsForMasternodeList[pfrom->addr] = askAgain; + } + } //else, asking for a specific node which is ok + + int nInvCount = 0; + + for (auto& mnpair : mapMasternodes) { + if (vin != CTxIn() && vin != mnpair.second.vin) continue; // asked for specific vin but we are not there yet + if (mnpair.second.addr.IsRFC1918() || mnpair.second.addr.IsLocal()) continue; // do not send local network masternode + if (mnpair.second.IsUpdateRequired()) continue; // do not send outdated masternodes + + LogPrint("masternode", "DSEG -- Sending Masternode entry: masternode=%s addr=%s\n", mnpair.first.ToStringShort(), mnpair.second.addr.ToString()); + CMasternodeBroadcast mnb = CMasternodeBroadcast(mnpair.second); + CMasternodePing mnp = mnpair.second.lastPing; + uint256 hashMNB = mnb.GetHash(); + uint256 hashMNP = mnp.GetHash(); + pfrom->PushInventory(CInv(MSG_MASTERNODE_ANNOUNCE, hashMNB)); + pfrom->PushInventory(CInv(MSG_MASTERNODE_PING, hashMNP)); + nInvCount++; + + mapSeenMasternodeBroadcast.insert(std::make_pair(hashMNB, std::make_pair(GetTime(), mnb))); + mapSeenMasternodePing.insert(std::make_pair(hashMNP, mnp)); + + if (vin.prevout == mnpair.first) { + LogPrintf("DSEG -- Sent 1 Masternode inv to peer %d\n", pfrom->id); + return; + } + } + + if(vin == CTxIn()) { + connman.PushMessage(pfrom, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_LIST, nInvCount); + LogPrintf("DSEG -- Sent %d Masternode invs to peer %d\n", nInvCount, pfrom->id); + return; + } + // smth weird happen - someone asked us for vin we have no idea about? + LogPrint("masternode", "DSEG -- No invs sent to peer %d\n", pfrom->id); + + } else if (strCommand == NetMsgType::MNVERIFY) { // Masternode Verify + + // Need LOCK2 here to ensure consistent locking order because the all functions below call GetBlockHash which locks cs_main + LOCK2(cs_main, cs); + + CMasternodeVerification mnv; + vRecv >> mnv; + + pfrom->setAskFor.erase(mnv.GetHash()); + + if(!masternodeSync.IsMasternodeListSynced()) return; + + if(mnv.vchSig1.empty()) { + // CASE 1: someone asked me to verify myself /IP we are using/ + SendVerifyReply(pfrom, mnv, connman); + } else if (mnv.vchSig2.empty()) { + // CASE 2: we _probably_ got verification we requested from some masternode + ProcessVerifyReply(pfrom, mnv); + } else { + // CASE 3: we _probably_ got verification broadcast signed by some masternode which verified another one + ProcessVerifyBroadcast(pfrom, mnv); + } + } +} + +// Verification of masternodes via unique direct requests. + +void CMasternodeMan::DoFullVerificationStep(CConnman& connman) +{ + if(activeMasternode.outpoint == COutPoint()) return; + if(!masternodeSync.IsSynced()) return; + + rank_pair_vec_t vecMasternodeRanks; + GetMasternodeRanks(vecMasternodeRanks, nCachedBlockHeight - 1, MIN_POSE_PROTO_VERSION); + + // Need LOCK2 here to ensure consistent locking order because the SendVerifyRequest call below locks cs_main + // through GetHeight() signal in ConnectNode + LOCK2(cs_main, cs); + + int nCount = 0; + + int nMyRank = -1; + int nRanksTotal = (int)vecMasternodeRanks.size(); + + // send verify requests only if we are in top MAX_POSE_RANK + std::vector >::iterator it = vecMasternodeRanks.begin(); + while(it != vecMasternodeRanks.end()) { + if(it->first > MAX_POSE_RANK) { + LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n", + (int)MAX_POSE_RANK); + return; + } + if(it->second.vin.prevout == activeMasternode.outpoint) { + nMyRank = it->first; + LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n", + nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS); + break; + } + ++it; + } + + // edge case: list is too short and this masternode is not enabled + if(nMyRank == -1) return; + + // send verify requests to up to MAX_POSE_CONNECTIONS masternodes + // starting from MAX_POSE_RANK + nMyRank and using MAX_POSE_CONNECTIONS as a step + int nOffset = MAX_POSE_RANK + nMyRank - 1; + if(nOffset >= (int)vecMasternodeRanks.size()) return; + + std::vector vSortedByAddr; + for (auto& mnpair : mapMasternodes) { + vSortedByAddr.push_back(&mnpair.second); + } + + sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); + + it = vecMasternodeRanks.begin() + nOffset; + while(it != vecMasternodeRanks.end()) { + if(it->second.IsPoSeVerified() || it->second.IsPoSeBanned()) { + LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Already %s%s%s masternode %s address %s, skipping...\n", + it->second.IsPoSeVerified() ? "verified" : "", + it->second.IsPoSeVerified() && it->second.IsPoSeBanned() ? " and " : "", + it->second.IsPoSeBanned() ? "banned" : "", + it->second.vin.prevout.ToStringShort(), it->second.addr.ToString()); + nOffset += MAX_POSE_CONNECTIONS; + if(nOffset >= (int)vecMasternodeRanks.size()) break; + it += MAX_POSE_CONNECTIONS; + continue; + } + LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Verifying masternode %s rank %d/%d address %s\n", + it->second.vin.prevout.ToStringShort(), it->first, nRanksTotal, it->second.addr.ToString()); + if(SendVerifyRequest(CAddress(it->second.addr, NODE_NETWORK), vSortedByAddr, connman)) { + nCount++; + if(nCount >= MAX_POSE_CONNECTIONS) break; + } + nOffset += MAX_POSE_CONNECTIONS; + if(nOffset >= (int)vecMasternodeRanks.size()) break; + it += MAX_POSE_CONNECTIONS; + } + + LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Sent verification requests to %d masternodes\n", nCount); +} + +// This function tries to find masternodes with the same addr, +// find a verified one and ban all the other. If there are many nodes +// with the same addr but none of them is verified yet, then none of them are banned. +// It could take many times to run this before most of the duplicate nodes are banned. + +void CMasternodeMan::CheckSameAddr() +{ + if(!masternodeSync.IsSynced() || mapMasternodes.empty()) return; + + std::vector vBan; + std::vector vSortedByAddr; + + { + LOCK(cs); + + CMasternode* pprevMasternode = NULL; + CMasternode* pverifiedMasternode = NULL; + + for (auto& mnpair : mapMasternodes) { + vSortedByAddr.push_back(&mnpair.second); + } + + sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); + + BOOST_FOREACH(CMasternode* pmn, vSortedByAddr) { + // check only (pre)enabled masternodes + if(!pmn->IsEnabled() && !pmn->IsPreEnabled()) continue; + // initial step + if(!pprevMasternode) { + pprevMasternode = pmn; + pverifiedMasternode = pmn->IsPoSeVerified() ? pmn : NULL; + continue; + } + // second+ step + if(pmn->addr == pprevMasternode->addr) { + if(pverifiedMasternode) { + // another masternode with the same ip is verified, ban this one + vBan.push_back(pmn); + } else if(pmn->IsPoSeVerified()) { + // this masternode with the same ip is verified, ban previous one + vBan.push_back(pprevMasternode); + // and keep a reference to be able to ban following masternodes with the same ip + pverifiedMasternode = pmn; + } + } else { + pverifiedMasternode = pmn->IsPoSeVerified() ? pmn : NULL; + } + pprevMasternode = pmn; + } + } + + // ban duplicates + BOOST_FOREACH(CMasternode* pmn, vBan) { + LogPrintf("CMasternodeMan::CheckSameAddr -- increasing PoSe ban score for masternode %s\n", pmn->vin.prevout.ToStringShort()); + pmn->IncreasePoSeBanScore(); + } +} + +bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) +{ + if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { + // we already asked for verification, not a good idea to do this too often, skip it + LogPrint("masternode", "CMasternodeMan::SendVerifyRequest -- too many requests, skipping... addr=%s\n", addr.ToString()); + return false; + } + + CNode* pnode = connman.ConnectNode(addr, NULL, true); + if(pnode == NULL) { + LogPrintf("CMasternodeMan::SendVerifyRequest -- can't connect to node to verify it, addr=%s\n", addr.ToString()); + return false; + } + + netfulfilledman.AddFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request"); + // use random nonce, store it and require node to reply with correct one later + CMasternodeVerification mnv(addr, GetRandInt(999999), nCachedBlockHeight - 1); + mWeAskedForVerification[addr] = mnv; + LogPrintf("CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n", mnv.nonce, addr.ToString()); + connman.PushMessage(pnode, NetMsgType::MNVERIFY, mnv); + + return true; +} + +void CMasternodeMan::SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, CConnman& connman) +{ + // only masternodes can sign this, why would someone ask regular node? + if(!fMasterNode) { + // do not ban, malicious node might be using my IP + // and trying to confuse the node which tries to verify it + return; + } + + if(netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-reply")) { + // peer should not ask us that often + LogPrintf("MasternodeMan::SendVerifyReply -- ERROR: peer already asked me recently, peer=%d\n", pnode->id); + Misbehaving(pnode->id, 20); + return; + } + + uint256 blockHash; + if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { + LogPrintf("MasternodeMan::SendVerifyReply -- can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); + return; + } + + std::string strMessage = strprintf("%s%d%s", activeMasternode.service.ToString(false), mnv.nonce, blockHash.ToString()); + + if(!CMessageSigner::SignMessage(strMessage, mnv.vchSig1, activeMasternode.keyMasternode)) { + LogPrintf("MasternodeMan::SendVerifyReply -- SignMessage() failed\n"); + return; + } + + std::string strError; + + if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig1, strMessage, strError)) { + LogPrintf("MasternodeMan::SendVerifyReply -- VerifyMessage() failed, error: %s\n", strError); + return; + } + + connman.PushMessage(pnode, NetMsgType::MNVERIFY, mnv); + netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-reply"); +} + +void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& mnv) +{ + std::string strError; + + // did we even ask for it? if that's the case we should have matching fulfilled request + if(!netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { + LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: we didn't ask for verification of %s, peer=%d\n", pnode->addr.ToString(), pnode->id); + Misbehaving(pnode->id, 20); + return; + } + + // Received nonce for a known address must match the one we sent + if(mWeAskedForVerification[pnode->addr].nonce != mnv.nonce) { + LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: wrong nounce: requested=%d, received=%d, peer=%d\n", + mWeAskedForVerification[pnode->addr].nonce, mnv.nonce, pnode->id); + Misbehaving(pnode->id, 20); + return; + } + + // Received nBlockHeight for a known address must match the one we sent + if(mWeAskedForVerification[pnode->addr].nBlockHeight != mnv.nBlockHeight) { + LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: wrong nBlockHeight: requested=%d, received=%d, peer=%d\n", + mWeAskedForVerification[pnode->addr].nBlockHeight, mnv.nBlockHeight, pnode->id); + Misbehaving(pnode->id, 20); + return; + } + + uint256 blockHash; + if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { + // this shouldn't happen... + LogPrintf("MasternodeMan::ProcessVerifyReply -- can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); + return; + } + + // we already verified this address, why node is spamming? + if(netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done")) { + LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: already verified %s recently\n", pnode->addr.ToString()); + Misbehaving(pnode->id, 20); + return; + } + + { + LOCK(cs); + + CMasternode* prealMasternode = NULL; + std::vector vpMasternodesToBan; + std::string strMessage1 = strprintf("%s%d%s", pnode->addr.ToString(false), mnv.nonce, blockHash.ToString()); + for (auto& mnpair : mapMasternodes) { + if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) { + if(CMessageSigner::VerifyMessage(mnpair.second.pubKeyMasternode, mnv.vchSig1, strMessage1, strError)) { + // found it! + prealMasternode = &mnpair.second; + if(!mnpair.second.IsPoSeVerified()) { + mnpair.second.DecreasePoSeBanScore(); + } + netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done"); + + // we can only broadcast it if we are an activated masternode + if(activeMasternode.outpoint == COutPoint()) continue; + // update ... + mnv.addr = mnpair.second.addr; + mnv.vin1 = mnpair.second.vin; + mnv.vin2 = CTxIn(activeMasternode.outpoint); + std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), + mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); + // ... and sign it + if(!CMessageSigner::SignMessage(strMessage2, mnv.vchSig2, activeMasternode.keyMasternode)) { + LogPrintf("MasternodeMan::ProcessVerifyReply -- SignMessage() failed\n"); + return; + } + + std::string strError; + + if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { + LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyMessage() failed, error: %s\n", strError); + return; + } + + mWeAskedForVerification[pnode->addr] = mnv; + mapSeenMasternodeVerification.insert(std::make_pair(mnv.GetHash(), mnv)); + mnv.Relay(); + + } else { + vpMasternodesToBan.push_back(&mnpair.second); + } + } + } + // no real masternode found?... + if(!prealMasternode) { + // this should never be the case normally, + // only if someone is trying to game the system in some way or smth like that + LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: no real masternode found for addr %s\n", pnode->addr.ToString()); + Misbehaving(pnode->id, 20); + return; + } + LogPrintf("CMasternodeMan::ProcessVerifyReply -- verified real masternode %s for addr %s\n", + prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString()); + // increase ban score for everyone else + BOOST_FOREACH(CMasternode* pmn, vpMasternodesToBan) { + pmn->IncreasePoSeBanScore(); + LogPrint("masternode", "CMasternodeMan::ProcessVerifyReply -- increased PoSe ban score for %s addr %s, new score %d\n", + prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString(), pmn->nPoSeBanScore); + } + if(!vpMasternodesToBan.empty()) + LogPrintf("CMasternodeMan::ProcessVerifyReply -- PoSe score increased for %d fake masternodes, addr %s\n", + (int)vpMasternodesToBan.size(), pnode->addr.ToString()); + } +} + +void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerification& mnv) +{ + std::string strError; + + if(mapSeenMasternodeVerification.find(mnv.GetHash()) != mapSeenMasternodeVerification.end()) { + // we already have one + return; + } + mapSeenMasternodeVerification[mnv.GetHash()] = mnv; + + // we don't care about history + if(mnv.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) { + LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Outdated: current block %d, verification block %d, peer=%d\n", + nCachedBlockHeight, mnv.nBlockHeight, pnode->id); + return; + } + + if(mnv.vin1.prevout == mnv.vin2.prevout) { + LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- ERROR: same vins %s, peer=%d\n", + mnv.vin1.prevout.ToStringShort(), pnode->id); + // that was NOT a good idea to cheat and verify itself, + // ban the node we received such message from + Misbehaving(pnode->id, 100); + return; + } + + uint256 blockHash; + if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { + // this shouldn't happen... + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- Can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); + return; + } + + int nRank; + + if (!GetMasternodeRank(mnv.vin2.prevout, nRank, mnv.nBlockHeight, MIN_POSE_PROTO_VERSION)) { + LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Can't calculate rank for masternode %s\n", + mnv.vin2.prevout.ToStringShort()); + return; + } + + if(nRank > MAX_POSE_RANK) { + LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Masternode %s is not in top %d, current rank %d, peer=%d\n", + mnv.vin2.prevout.ToStringShort(), (int)MAX_POSE_RANK, nRank, pnode->id); + return; + } + + { + LOCK(cs); + + std::string strMessage1 = strprintf("%s%d%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString()); + std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), + mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); + + CMasternode* pmn1 = Find(mnv.vin1.prevout); + if(!pmn1) { + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode1 %s\n", mnv.vin1.prevout.ToStringShort()); + return; + } + + CMasternode* pmn2 = Find(mnv.vin2.prevout); + if(!pmn2) { + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode2 %s\n", mnv.vin2.prevout.ToStringShort()); + return; + } + + if(pmn1->addr != mnv.addr) { + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- addr %s does not match %s\n", mnv.addr.ToString(), pmn1->addr.ToString()); + return; + } + + if(!CMessageSigner::VerifyMessage(pmn1->pubKeyMasternode, mnv.vchSig1, strMessage1, strError)) { + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode1 failed, error: %s\n", strError); + return; + } + + if(!CMessageSigner::VerifyMessage(pmn2->pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode2 failed, error: %s\n", strError); + return; + } + + if(!pmn1->IsPoSeVerified()) { + pmn1->DecreasePoSeBanScore(); + } + mnv.Relay(); + + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- verified masternode %s for addr %s\n", + pmn1->vin.prevout.ToStringShort(), pmn1->addr.ToString()); + + // increase ban score for everyone else with the same addr + int nCount = 0; + for (auto& mnpair : mapMasternodes) { + if(mnpair.second.addr != mnv.addr || mnpair.first == mnv.vin1.prevout) continue; + mnpair.second.IncreasePoSeBanScore(); + nCount++; + LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- increased PoSe ban score for %s addr %s, new score %d\n", + mnpair.first.ToStringShort(), mnpair.second.addr.ToString(), mnpair.second.nPoSeBanScore); + } + if(nCount) + LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- PoSe score increased for %d fake masternodes, addr %s\n", + nCount, pmn1->addr.ToString()); + } +} + +std::string CMasternodeMan::ToString() const +{ + std::ostringstream info; + + info << "Masternodes: " << (int)mapMasternodes.size() << + ", peers who asked us for Masternode list: " << (int)mAskedUsForMasternodeList.size() << + ", peers we asked for Masternode list: " << (int)mWeAskedForMasternodeList.size() << + ", entries in Masternode list we asked for: " << (int)mWeAskedForMasternodeListEntry.size() << + ", nDsqCount: " << (int)nDsqCount; + + return info.str(); +} + +void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman) +{ + LOCK2(cs_main, cs); + mapSeenMasternodePing.insert(std::make_pair(mnb.lastPing.GetHash(), mnb.lastPing)); + mapSeenMasternodeBroadcast.insert(std::make_pair(mnb.GetHash(), std::make_pair(GetTime(), mnb))); + + LogPrintf("CMasternodeMan::UpdateMasternodeList -- masternode=%s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); + + CMasternode* pmn = Find(mnb.vin.prevout); + if(pmn == NULL) { + if(Add(mnb)) { + masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - new"); + } + } else { + CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; + if(pmn->UpdateFromNewBroadcast(mnb, connman)) { + masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - seen"); + mapSeenMasternodeBroadcast.erase(mnbOld.GetHash()); + } + } +} + +bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman) +{ + // Need to lock cs_main here to ensure consistent locking order because the SimpleCheck call below locks cs_main + LOCK(cs_main); + + { + LOCK(cs); + nDos = 0; + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s\n", mnb.vin.prevout.ToStringShort()); + + uint256 hash = mnb.GetHash(); + if(mapSeenMasternodeBroadcast.count(hash) && !mnb.fRecovery) { //seen + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen\n", mnb.vin.prevout.ToStringShort()); + // less then 2 pings left before this MN goes into non-recoverable state, bump sync timeout + if(GetTime() - mapSeenMasternodeBroadcast[hash].first > MASTERNODE_NEW_START_REQUIRED_SECONDS - MASTERNODE_MIN_MNP_SECONDS * 2) { + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen update\n", mnb.vin.prevout.ToStringShort()); + mapSeenMasternodeBroadcast[hash].first = GetTime(); + masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - seen"); + } + // did we ask this node for it? + if(pfrom && IsMnbRecoveryRequested(hash) && GetTime() < mMnbRecoveryRequests[hash].first) { + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request\n", hash.ToString()); + if(mMnbRecoveryRequests[hash].second.count(pfrom->addr)) { + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s\n", hash.ToString(), pfrom->addr.ToString()); + // do not allow node to send same mnb multiple times in recovery mode + mMnbRecoveryRequests[hash].second.erase(pfrom->addr); + // does it have newer lastPing? + if(mnb.lastPing.sigTime > mapSeenMasternodeBroadcast[hash].second.lastPing.sigTime) { + // simulate Check + CMasternode mnTemp = CMasternode(mnb); + mnTemp.Check(); + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetAdjustedTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString()); + if(mnTemp.IsValidStateForAutoStart(mnTemp.nActiveState)) { + // this node thinks it's a good one + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen good\n", mnb.vin.prevout.ToStringShort()); + mMnbRecoveryGoodReplies[hash].push_back(mnb); + } + } + } + } + return true; + } + mapSeenMasternodeBroadcast.insert(std::make_pair(hash, std::make_pair(GetTime(), mnb))); + + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s new\n", mnb.vin.prevout.ToStringShort()); + + if(!mnb.SimpleCheck(nDos)) { + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- SimpleCheck() failed, masternode=%s\n", mnb.vin.prevout.ToStringShort()); + return false; + } + + // search Masternode list + CMasternode* pmn = Find(mnb.vin.prevout); + if(pmn) { + CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; + if(!mnb.Update(pmn, nDos, connman)) { + LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Update() failed, masternode=%s\n", mnb.vin.prevout.ToStringShort()); + return false; + } + if(hash != mnbOld.GetHash()) { + mapSeenMasternodeBroadcast.erase(mnbOld.GetHash()); + } + return true; + } + } + + if(mnb.CheckOutpoint(nDos)) { + Add(mnb); + masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - new"); + // if it matches our Masternode privkey... + if(fMasterNode && mnb.pubKeyMasternode == activeMasternode.pubKeyMasternode) { + mnb.nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; + if(mnb.nProtocolVersion == PROTOCOL_VERSION) { + // ... and PROTOCOL_VERSION, then we've been remotely activated ... + LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Got NEW Masternode entry: masternode=%s sigTime=%lld addr=%s\n", + mnb.vin.prevout.ToStringShort(), mnb.sigTime, mnb.addr.ToString()); + activeMasternode.ManageState(connman); + } else { + // ... otherwise we need to reactivate our node, do not add it to the list and do not relay + // but also do not ban the node we get this message from + LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- wrong PROTOCOL_VERSION, re-activate your MN: message nProtocolVersion=%d PROTOCOL_VERSION=%d\n", mnb.nProtocolVersion, PROTOCOL_VERSION); + return false; + } + } + mnb.Relay(connman); + } else { + LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Rejected Masternode entry: %s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); + return false; + } + + return true; +} + +void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) +{ + LOCK(cs); + + if(fLiteMode || !masternodeSync.IsWinnersListSynced() || mapMasternodes.empty()) return; + + static bool IsFirstRun = true; + // Do full scan on first run or if we are not a masternode + // (MNs should update this info on every block, so limited scan should be enough for them) + int nMaxBlocksToScanBack = (IsFirstRun || !fMasterNode) ? mnpayments.GetStorageLimit() : LAST_PAID_SCAN_BLOCKS; + + // LogPrint("mnpayments", "CMasternodeMan::UpdateLastPaid -- nHeight=%d, nMaxBlocksToScanBack=%d, IsFirstRun=%s\n", + // nCachedBlockHeight, nMaxBlocksToScanBack, IsFirstRun ? "true" : "false"); + + for (auto& mnpair: mapMasternodes) { + mnpair.second.UpdateLastPaid(pindex, nMaxBlocksToScanBack); + } + + IsFirstRun = false; +} + +void CMasternodeMan::UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if(!pmn) { + return; + } + pmn->UpdateWatchdogVoteTime(nVoteTime); + nLastWatchdogVoteTime = GetTime(); +} + +bool CMasternodeMan::IsWatchdogActive() +{ + LOCK(cs); + // Check if any masternodes have voted recently, otherwise return false + return (GetTime() - nLastWatchdogVoteTime) <= MASTERNODE_WATCHDOG_MAX_SECONDS; +} + +bool CMasternodeMan::AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if(!pmn) { + return false; + } + pmn->AddGovernanceVote(nGovernanceObjectHash); + return true; +} + +void CMasternodeMan::RemoveGovernanceObject(uint256 nGovernanceObjectHash) +{ + LOCK(cs); + for(auto& mnpair : mapMasternodes) { + mnpair.second.RemoveGovernanceObject(nGovernanceObjectHash); + } +} + +void CMasternodeMan::CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce) +{ + LOCK(cs); + for (auto& mnpair : mapMasternodes) { + if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { + mnpair.second.Check(fForce); + return; + } + } +} + +bool CMasternodeMan::IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + return pmn ? pmn->IsPingedWithin(nSeconds, nTimeToCheckAt) : false; +} + +void CMasternodeMan::SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp) +{ + LOCK(cs); + CMasternode* pmn = Find(outpoint); + if(!pmn) { + return; + } + pmn->lastPing = mnp; + // if masternode uses sentinel ping instead of watchdog + // we shoud update nTimeLastWatchdogVote here if sentinel + // ping flag is actual + if(mnp.fSentinelIsCurrent) { + UpdateWatchdogVoteTime(mnp.vin.prevout, mnp.sigTime); + } + mapSeenMasternodePing.insert(std::make_pair(mnp.GetHash(), mnp)); + + CMasternodeBroadcast mnb(*pmn); + uint256 hash = mnb.GetHash(); + if(mapSeenMasternodeBroadcast.count(hash)) { + mapSeenMasternodeBroadcast[hash].second.lastPing = mnp; + } +} + +void CMasternodeMan::UpdatedBlockTip(const CBlockIndex *pindex) +{ + nCachedBlockHeight = pindex->nHeight; + LogPrint("masternode", "CMasternodeMan::UpdatedBlockTip -- nCachedBlockHeight=%d\n", nCachedBlockHeight); + + CheckSameAddr(); + + if(fMasterNode) { + // normal wallet does not need to update this every block, doing update on rpc call should be enough + UpdateLastPaid(pindex); + } +} + +void CMasternodeMan::NotifyMasternodeUpdates(CConnman& connman) +{ + // Avoid double locking + bool fMasternodesAddedLocal = false; + bool fMasternodesRemovedLocal = false; + { + LOCK(cs); + fMasternodesAddedLocal = fMasternodesAdded; + fMasternodesRemovedLocal = fMasternodesRemoved; + } + + if(fMasternodesAddedLocal) { + governance.CheckMasternodeOrphanObjects(connman); + governance.CheckMasternodeOrphanVotes(connman); + } + if(fMasternodesRemovedLocal) { + governance.UpdateCachesAndClean(); + } + + LOCK(cs); + fMasternodesAdded = false; + fMasternodesRemoved = false; +} diff --git a/src/masternodeman.h b/src/masternodeman.h new file mode 100644 index 00000000..1927ddaa --- /dev/null +++ b/src/masternodeman.h @@ -0,0 +1,240 @@ +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef MASTERNODEMAN_H +#define MASTERNODEMAN_H + +#include "masternode.h" +#include "sync.h" + +using namespace std; + +class CMasternodeMan; +class CConnman; + +extern CMasternodeMan mnodeman; + +class CMasternodeMan +{ +public: + typedef std::pair score_pair_t; + typedef std::vector score_pair_vec_t; + typedef std::pair rank_pair_t; + typedef std::vector rank_pair_vec_t; + +private: + static const std::string SERIALIZATION_VERSION_STRING; + + static const int DSEG_UPDATE_SECONDS = 3 * 60 * 60; + + static const int LAST_PAID_SCAN_BLOCKS = 100; + + static const int MIN_POSE_PROTO_VERSION = 70203; + static const int MAX_POSE_CONNECTIONS = 10; + static const int MAX_POSE_RANK = 10; + static const int MAX_POSE_BLOCKS = 10; + + static const int MNB_RECOVERY_QUORUM_TOTAL = 10; + static const int MNB_RECOVERY_QUORUM_REQUIRED = 6; + static const int MNB_RECOVERY_MAX_ASK_ENTRIES = 10; + static const int MNB_RECOVERY_WAIT_SECONDS = 60; + static const int MNB_RECOVERY_RETRY_SECONDS = 3 * 60 * 60; + + + // critical section to protect the inner data structures + mutable CCriticalSection cs; + + // Keep track of current block height + int nCachedBlockHeight; + + // map to hold all MNs + std::map mapMasternodes; + // who's asked for the Masternode list and the last time + std::map mAskedUsForMasternodeList; + // who we asked for the Masternode list and the last time + std::map mWeAskedForMasternodeList; + // which Masternodes we've asked for + std::map > mWeAskedForMasternodeListEntry; + // who we asked for the masternode verification + std::map mWeAskedForVerification; + + // these maps are used for masternode recovery from MASTERNODE_NEW_START_REQUIRED state + std::map > > mMnbRecoveryRequests; + std::map > mMnbRecoveryGoodReplies; + std::list< std::pair > listScheduledMnbRequestConnections; + + /// Set when masternodes are added, cleared when CGovernanceManager is notified + bool fMasternodesAdded; + + /// Set when masternodes are removed, cleared when CGovernanceManager is notified + bool fMasternodesRemoved; + + std::vector vecDirtyGovernanceObjectHashes; + + int64_t nLastWatchdogVoteTime; + + friend class CMasternodeSync; + /// Find an entry + CMasternode* Find(const COutPoint& outpoint); + + bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol = 0); + +public: + // Keep track of all broadcasts I've seen + std::map > mapSeenMasternodeBroadcast; + // Keep track of all pings I've seen + std::map mapSeenMasternodePing; + // Keep track of all verifications I've seen + std::map mapSeenMasternodeVerification; + // keep track of dsq count to prevent masternodes from gaming darksend queue + int64_t nDsqCount; + + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + LOCK(cs); + std::string strVersion; + if(ser_action.ForRead()) { + READWRITE(strVersion); + } + else { + strVersion = SERIALIZATION_VERSION_STRING; + READWRITE(strVersion); + } + + READWRITE(mapMasternodes); + READWRITE(mAskedUsForMasternodeList); + READWRITE(mWeAskedForMasternodeList); + READWRITE(mWeAskedForMasternodeListEntry); + READWRITE(mMnbRecoveryRequests); + READWRITE(mMnbRecoveryGoodReplies); + READWRITE(nLastWatchdogVoteTime); + READWRITE(nDsqCount); + + READWRITE(mapSeenMasternodeBroadcast); + READWRITE(mapSeenMasternodePing); + if(ser_action.ForRead() && (strVersion != SERIALIZATION_VERSION_STRING)) { + Clear(); + } + } + + CMasternodeMan(); + + /// Add an entry + bool Add(CMasternode &mn); + + /// Ask (source) node for mnb + void AskForMN(CNode *pnode, const COutPoint& outpoint, CConnman& connman); + void AskForMnb(CNode *pnode, const uint256 &hash); + + bool PoSeBan(const COutPoint &outpoint); + bool AllowMixing(const COutPoint &outpoint); + bool DisallowMixing(const COutPoint &outpoint); + + /// Check all Masternodes + void Check(); + + /// Check all Masternodes and remove inactive + void CheckAndRemove(CConnman& connman); + /// This is dummy overload to be used for dumping/loading mncache.dat + void CheckAndRemove() {} + + /// Clear Masternode vector + void Clear(); + + /// Count Masternodes filtered by nProtocolVersion. + /// Masternode nProtocolVersion should match or be above the one specified in param here. + int CountMasternodes(int nProtocolVersion = -1); + /// Count enabled Masternodes filtered by nProtocolVersion. + /// Masternode nProtocolVersion should match or be above the one specified in param here. + int CountEnabled(int nProtocolVersion = -1); + + /// Count Masternodes by network type - NET_IPV4, NET_IPV6, NET_TOR + // int CountByIP(int nNetworkType); + + void DsegUpdate(CNode* pnode, CConnman& connman); + + /// Versions of Find that are safe to use from outside the class + bool Get(const COutPoint& outpoint, CMasternode& masternodeRet); + bool Has(const COutPoint& outpoint); + + bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet); + bool GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet); + bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet); + + /// Find an entry in the masternode list that is next to be paid + bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); + /// Same as above but use current block height + bool GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); + + /// Find a random entry + masternode_info_t FindRandomNotInVec(const std::vector &vecToExclude, int nProtocolVersion = -1); + + std::map GetFullMasternodeMap() { return mapMasternodes; } + + bool GetMasternodeRanks(rank_pair_vec_t& vecMasternodeRanksRet, int nBlockHeight = -1, int nMinProtocol = 0); + bool GetMasternodeRank(const COutPoint &outpoint, int& nRankRet, int nBlockHeight = -1, int nMinProtocol = 0); + + void ProcessMasternodeConnections(CConnman& connman); + std::pair > PopScheduledMnbRequestConnection(); + + void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman); + + void DoFullVerificationStep(CConnman& connman); + void CheckSameAddr(); + bool SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman); + void SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, CConnman& connman); + void ProcessVerifyReply(CNode* pnode, CMasternodeVerification& mnv); + void ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerification& mnv); + + /// Return the number of (unique) Masternodes + int size() { return mapMasternodes.size(); } + + std::string ToString() const; + + /// Update masternode list and maps using provided CMasternodeBroadcast + void UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman); + /// Perform complete check and only then update list and maps + bool CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman); + bool IsMnbRecoveryRequested(const uint256& hash) { return mMnbRecoveryRequests.count(hash); } + + void UpdateLastPaid(const CBlockIndex* pindex); + + void AddDirtyGovernanceObjectHash(const uint256& nHash) + { + LOCK(cs); + vecDirtyGovernanceObjectHashes.push_back(nHash); + } + + std::vector GetAndClearDirtyGovernanceObjectHashes() + { + LOCK(cs); + std::vector vecTmp = vecDirtyGovernanceObjectHashes; + vecDirtyGovernanceObjectHashes.clear(); + return vecTmp;; + } + + bool IsWatchdogActive(); + void UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime = 0); + bool AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash); + void RemoveGovernanceObject(uint256 nGovernanceObjectHash); + + void CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce); + + bool IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt = -1); + void SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp); + + void UpdatedBlockTip(const CBlockIndex *pindex); + + /** + * Called to notify CGovernanceManager that the masternode index has been updated. + * Must be called while not holding the CMasternodeMan::cs mutex + */ + void NotifyMasternodeUpdates(CConnman& connman); + +}; + +#endif diff --git a/src/rpcpodc.cpp b/src/rpcpodc.cpp new file mode 100644 index 00000000..b6d1ee19 --- /dev/null +++ b/src/rpcpodc.cpp @@ -0,0 +1,285 @@ +// Copyright (c) 2014-2019 The Dash-Core Developers, The DAC Core Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "spork.h" +#include "utilmoneystr.h" +#include "masternode-payments.h" +#include "masternodeconfig.h" +#include "activemasternode.h" +#include "governance-classes.h" +#include "masternode-sync.h" +#include "smartcontract-server.h" +#include "rpcpog.h" +#include +#include // for to_lower() +#include // for trim() +#include // for StringToUnixTime() +#include +#include +#include +#include +#include +#include +#include +#include + +extern CWallet* pwalletMain; + +const std::string CURRENCY_NAME = "IMAGECOIN"; + +std::string GetSANDirectory2() +{ + std::string prefix = CURRENCY_NAME; + boost::to_lower(prefix); + boost::filesystem::path pathConfigFile(GetArg("-conf", prefix + ".conf")); + if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile; + boost::filesystem::path dir = pathConfigFile.parent_path(); + std::string sDir = dir.string() + "/SAN/"; + boost::filesystem::path pathSAN(sDir); + if (!boost::filesystem::exists(pathSAN)) + { + boost::filesystem::create_directory(pathSAN); + } + return sDir; +} + +std::string ToYesNo(bool bValue) +{ + std::string sYesNo = bValue ? "Yes" : "No"; + return sYesNo; +} + +std::string strReplace(std::string& str, const std::string& oldStr, const std::string& newStr) +{ + size_t pos = 0; + while((pos = str.find(oldStr, pos)) != std::string::npos){ + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } + return str; +} + +bool SignStake(std::string sBitcoinAddress, std::string strMessage, std::string& sError, std::string& sSignature) +{ + LOCK(cs_main); + { + CBitcoinAddress addr(sBitcoinAddress); + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + { + sError = "Address does not refer to key"; + return false; + } + CKey key; + if (!pwalletMain->GetKey(keyID, key)) + { + sError = "Private key not available for " + sBitcoinAddress + "."; + LogPrintf("Unable to sign message %s with key %s.\n", strMessage, sBitcoinAddress); + return false; + } + CHashWriter ss(SER_GETHASH, 0); + ss << strMessageMagic; + ss << strMessage; + std::vector vchSig; + if (!key.SignCompact(ss.GetHash(), vchSig)) + { + sError = "Sign failed"; + return false; + } + sSignature = EncodeBase64(&vchSig[0], vchSig.size()); + LogPrintf("Signed message %s successfully with address %s \n", strMessage, sBitcoinAddress); + return true; + } +} + + +std::string SendBlockchainMessage(std::string sType, std::string sPrimaryKey, std::string sValue, double dStorageFee, bool Sign, std::string sExtraPayload, std::string& sError) +{ + const Consensus::Params& consensusParams = Params().GetConsensus(); + std::string sAddress = "MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG"; + CBitcoinAddress address(sAddress); + if (!address.IsValid()) + { + sError = "Invalid Destination Address"; + return sError; + } + CAmount nAmount = CAmountFromValue(dStorageFee); + CAmount nMinimumBalance = CAmountFromValue(dStorageFee); + CWalletTx wtx; + boost::to_upper(sPrimaryKey); // DC Message can't be found if not uppercase + boost::to_upper(sType); + std::string sNonceValue = RoundToString(GetAdjustedTime(), 0); + std::string sMessageType = "" + sType + ""; + std::string sMessageKey = "" + sPrimaryKey + ""; + std::string sMessageValue = "" + sValue + ""; + std::string sNonce = "" + sNonceValue + ""; + std::string sMessageSig = ""; + if (Sign) + { + std::string sSignature = ""; + bool bSigned = SignStake("MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG", sValue + sNonceValue, sError, sSignature); + if (bSigned) + { + sMessageSig = "" + sSignature + ""; + sMessageSig += "" + sSignature + ""; + sMessageSig += "MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG"; + } + if (!bSigned) LogPrintf("Unable to sign spork %s ", sError); + LogPrintf(" Signing Nonce%f , With spork Sig %s on message %s \n", (double)GetAdjustedTime(), + sMessageSig.c_str(), sValue.c_str()); + } + std::string s1 = sMessageType + sMessageKey + sMessageValue + sNonce + sMessageSig + sExtraPayload; + LogPrintf("SendBlockchainMessage %s", s1); + bool fSubtractFee = false; + bool fInstantSend = false; + bool fSent = RPCSendMoney(sError, address.Get(), nAmount, fSubtractFee, wtx, fInstantSend, s1); + + if (!sError.empty()) + return std::string(); + return wtx.GetHash().GetHex().c_str(); +} + + +std::string GetGithubVersion() +{ + std::string sURL = "https://" + GetSporkValue("bms"); + std::string sRestfulURL = "BMS/LAST_MANDATORY_VERSION"; + //std::string sV = ExtractXML(HTTPSPost(false, 0, "", "", "", sURL, sRestfulURL, 443, "", 25, 10000, 1), "", ""); + std::string sV; + return sV; +} + + + +bool GetTransactionTimeAndAmount(uint256 txhash, int nVout, int64_t& nTime, CAmount& nAmount) +{ + uint256 hashBlock = uint256(); + CTransaction tx2; + if (GetTransaction(txhash, tx2, Params().GetConsensus(), hashBlock, true)) + { + BlockMap::iterator mi = mapBlockIndex.find(hashBlock); + if (mi != mapBlockIndex.end() && (*mi).second) + { + CBlockIndex* pMNIndex = (*mi).second; + nTime = pMNIndex->GetBlockTime(); + nAmount = tx2.vout[nVout].nValue; + return true; + } + } + return false; +} + +std::string rPad(std::string data, int minWidth) +{ + if ((int)data.length() >= minWidth) return data; + int iPadding = minWidth - data.length(); + std::string sPadding = std::string(iPadding,' '); + std::string sOut = data + sPadding; + return sOut; +} + +int64_t GetDCCFileAge() +{ + std::string sRACFile = GetSANDirectory2() + "wcg.rac"; + boost::filesystem::path pathFiltered(sRACFile); + if (!boost::filesystem::exists(pathFiltered)) + return GetAdjustedTime() - 0; + int64_t nTime = last_write_time(pathFiltered); + int64_t nAge = GetAdjustedTime() - nTime; + return nAge; +} + +int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints) +{ + std::string sDomain = "https://www.worldcommunitygrid.org"; + std::string sRestfulURL = "verifyMember.do?name=" + sMemberName + "&code=" + sAuthCode; + //std::string sResponse = HTTPSPost(true, 0, "", "", "", sDomain, sRestfulURL, 443, "", 12, 14000, 1); + std::string sResponse; + int iID = (int)cdbl(ExtractXML(sResponse, "",""), 0); + nPoints = cdbl(ExtractXML(sResponse, "", ""), 2); + return iID; +} + +Researcher GetResearcherByID(int nID) +{ + BOOST_FOREACH(const PAIRTYPE(const std::string, Researcher)& myResearcher, mvResearchers) + { + if (myResearcher.second.found && myResearcher.second.id == nID) + { + return mvResearchers[myResearcher.second.cpid]; + } + } + Researcher r; + r.found = false; + r.teamid = 0; + return r; +} + +std::map GetPayableResearchers() +{ + // Rules: + + // Researcher is in the team + // RAC > 1 + // Researchers reverse CPID lookup matches the signed association record (this ensures the LIFO rule is honored allowing re-associations) + // Each CPID is only included ONCE + // The CPID is Unbanked if the RAC < 250 + // Unbanked researchers do not need to post daily stake collateral + // Banked researchers do need to post daily stake collateral: RAC^1.30 in COIN-AGE per day + std::vector > vFIFO; + vFIFO.reserve(mvResearchers.size() * 2); + std::map r; + std::map cpid_reverse_lookup; + for (auto ii : mvApplicationCache) + { + if (Contains(ii.first.first, "CPK-WCG")) + { + std::string sData = ii.second.first; + int64_t nLockTime = ii.second.second; + std::string cpid = GetCPIDElementByData(sData, 8); + std::string sCPK = GetCPIDElementByData(sData, 0); + vFIFO.push_back(std::make_tuple(nLockTime, cpid, sCPK)); + LogPrintf("cpid %s cpk %s locktime %f", cpid, sCPK, nLockTime); + } + } + + + // LIFO Sort + std::sort(vFIFO.begin(), vFIFO.end()); + + for (auto item : vFIFO) + { + std::string cpid = std::get<1>(item); //item.second; + std::string sCPK = std::get<2>(item); //item.third; + cpid_reverse_lookup[cpid] = sCPK; + LogPrintf("Adding cpid %s with %s ", cpid, sCPK); + } + + // Payable Researchers + BOOST_FOREACH(const PAIRTYPE(const std::string, Researcher)& myResearcher, mvResearchers) + { + if (myResearcher.second.found) + { + if (myResearcher.second.rac > 1) + { + std::string sSourceCPK = cpid_reverse_lookup[myResearcher.second.cpid]; + std::string sSignedCPID = GetCPIDByCPK(sSourceCPK); + + if (sSignedCPID == myResearcher.second.cpid && !myResearcher.second.cpid.empty()) + { + if (myResearcher.second.rac > 1) + { + r[sSignedCPID] = myResearcher.second; + LogPrintf("\nGetPayableResearchers::Adding %s for %s", sSignedCPID, sSourceCPK); + } + } + else + { + LogPrintf("\nGPR::Not Adding %s because %s", sSignedCPID, sSourceCPK); + } + } + } + } + return r; +} diff --git a/src/rpcpodc.h b/src/rpcpodc.h new file mode 100644 index 00000000..90ba3bc2 --- /dev/null +++ b/src/rpcpodc.h @@ -0,0 +1,33 @@ +// Copyright (c) 2014-2017 The D�sh Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RPCPODC_H +#define RPCPODC_H + +#include "hash.h" +#include "net.h" +#include "utilstrencodings.h" +#include +#include + + +std::string strReplace(std::string& str, const std::string& oldStr, const std::string& newStr); +double GetCryptoPrice(std::string sURL); +bool SignStake(std::string sBitcoinAddress, std::string strMessage, std::string& sError, std::string& sSignature); +std::string GetGithubVersion(); +std::string SerializeSanctuaryQuorumTrigger(int iContractAssessmentHeight, int nEventBlockHeight, std::string sContract); +bool VerifySigner(std::string sXML); +double GetPBase(double& out_BTC); +std::string GetCPID(); +bool GetTransactionTimeAndAmount(uint256 txhash, int nVout, int64_t& nTime, CAmount& nAmount); +std::string SendBlockchainMessage(std::string sType, std::string sPrimaryKey, std::string sValue, double dStorageFee, bool Sign, std::string sExtraPayload, std::string& sError); +std::string ToYesNo(bool bValue); +bool VoteForGobject(uint256 govobj, std::string sVoteOutcome, std::string& sError); +int64_t GetDCCFileAge(); +std::string GetSANDirectory2(); +int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints); +Researcher GetResearcherByID(int nID); +std::map GetPayableResearchers(); + +#endif diff --git a/src/rpcpog.cpp b/src/rpcpog.cpp new file mode 100644 index 00000000..a28c9b04 --- /dev/null +++ b/src/rpcpog.cpp @@ -0,0 +1,1056 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "rpcpog.h" +#include "spork.h" +#include "util.h" +#include "utilmoneystr.h" +#include "rpcpodc.h" +#include "init.h" +#include "bbpsocket.h" +#include "activemasternode.h" +#include "governance.h" +#include "governance-vote.h" +#include "governance-classes.h" +#include "governance-validators.h" +#include "masternode.h" +#include "masternode-sync.h" +#include "masternodeconfig.h" +#include "masternodeman.h" +#include "masternode-payments.h" +#include "messagesigner.h" +#include "smartcontract-server.h" +#include "smartcontract-client.h" +#include +#include // for to_lower() +#include // for trim() +#include // for StringToUnixTime() +#include /* round, floor, ceil, trunc */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "txmempool.h" +// For HTTPS (for the pool communication) +#include +#include +#include +#include +#include "net.h" // for CService +#include "netaddress.h" +#include "netbase.h" // for LookupHost +#include "wallet/wallet.h" +#include +//#include "randomx.h" + +#ifdef ENABLE_WALLET +extern CWallet* pwalletMain; + +#endif // ENABLE_WALLET + +CValidationState state; + +UniValue VoteWithMasternodes(const std::map& keys, + const uint256& hash, vote_signal_enum_t eVoteSignal, + vote_outcome_enum_t eVoteOutcome); + +std::string GenerateNewAddress(std::string& sError, std::string sName) +{ + LOCK2(cs_main, pwalletMain->cs_wallet); + { + if (!pwalletMain->IsLocked(true)) + pwalletMain->TopUpKeyPool(); + // Generate a new key that is added to wallet + CPubKey newKey; + if (!pwalletMain->GetKeyFromPool(newKey, false)) + { + sError = "Keypool ran out, please call keypoolrefill first"; + return std::string(); + } + CKeyID keyID = newKey.GetID(); + pwalletMain->SetAddressBook(keyID, sName, "receive"); //receive == visible in address book, hidden = non-visible + LogPrintf(" created new address %s ", CBitcoinAddress(keyID).ToString().c_str()); + return CBitcoinAddress(keyID).ToString(); + } +} + +std::string GJE(std::string sKey, std::string sValue, bool bIncludeDelimiter, bool bQuoteValue) +{ + // This is a helper for the Governance gobject create method + std::string sQ = "\""; + std::string sOut = sQ + sKey + sQ + ":"; + if (bQuoteValue) + { + sOut += sQ + sValue + sQ; + } + else + { + sOut += sValue; + } + if (bIncludeDelimiter) sOut += ","; + return sOut; +} + +std::string RoundToString(double d, int place) +{ + std::ostringstream ss; + ss << std::fixed << std::setprecision(place) << d ; + return ss.str() ; +} + +double Round(double d, int place) +{ + std::ostringstream ss; + ss << std::fixed << std::setprecision(place) << d ; + double r = 0; + try + { + r = boost::lexical_cast(ss.str()); + return r; + } + catch(boost::bad_lexical_cast const& e) + { + LogPrintf("caught bad lexical cast %f", 1); + return 0; + } + catch(...) + { + LogPrintf("caught bad lexical cast %f", 2); + } + return r; +} + +std::vector Split(std::string s, std::string delim) +{ + size_t pos = 0; + std::string token; + std::vector elems; + while ((pos = s.find(delim)) != std::string::npos) + { + token = s.substr(0, pos); + elems.push_back(token); + s.erase(0, pos + delim.length()); + } + elems.push_back(s); + return elems; +} + +double cdbl(std::string s, int place) +{ + if (s=="") s = "0"; + if (s.length() > 255) return 0; + s = strReplace(s, "\r",""); + s = strReplace(s, "\n",""); + std::string t = ""; + for (int i = 0; i < (int)s.length(); i++) + { + std::string u = s.substr(i,1); + if (u=="0" || u=="1" || u=="2" || u=="3" || u=="4" || u=="5" || u=="6" || u == "7" || u=="8" || u=="9" || u=="." || u=="-") + { + t += u; + } + } + double r= 0; + try + { + r = boost::lexical_cast(t); + } + catch(boost::bad_lexical_cast const& e) + { + LogPrintf("caught cdbl bad lexical cast %f from %s with %f", 1, s, (double)place); + return 0; + } + catch(...) + { + LogPrintf("caught cdbl bad lexical cast %f", 2); + } + double d = Round(r, place); + return d; +} + +bool Contains(std::string data, std::string instring) +{ + std::size_t found = 0; + found = data.find(instring); + if (found != std::string::npos) return true; + return false; +} + +std::string GetElement(std::string sIn, std::string sDelimiter, int iPos) +{ + if (sIn.empty()) + return std::string(); + std::vector vInput = Split(sIn.c_str(), sDelimiter); + if (iPos < (int)vInput.size()) + { + return vInput[iPos]; + } + return std::string(); +} + +std::string GetSporkValue(std::string sKey) +{ + boost::to_upper(sKey); + std::pair v = mvApplicationCache[std::make_pair("SPORK", sKey)]; + return v.first; +} + +double GetSporkDouble(std::string sName, double nDefault) +{ + double dSetting = cdbl(GetSporkValue(sName), 2); + if (dSetting == 0) return nDefault; + return dSetting; +} + +std::map GetSporkMap(std::string sPrimaryKey, std::string sSecondaryKey) +{ + boost::to_upper(sPrimaryKey); + boost::to_upper(sSecondaryKey); + std::string sDelimiter = "|"; + std::pair v = mvApplicationCache[std::make_pair(sPrimaryKey, sSecondaryKey)]; + std::vector vSporks = Split(v.first, sDelimiter); + std::map mSporkMap; + for (int i = 0; i < vSporks.size(); i++) + { + std::string sMySpork = vSporks[i]; + if (!sMySpork.empty()) + mSporkMap.insert(std::make_pair(sMySpork, RoundToString(i, 0))); + } + return mSporkMap; +} + +std::string Left(std::string sSource, int bytes) +{ + if (sSource.length() >= bytes) + { + return sSource.substr(0, bytes); + } + return std::string(); +} + +bool CheckStakeSignature(std::string sBitcoinAddress, std::string sSignature, std::string strMessage, std::string& strError) +{ + CBitcoinAddress addr2(sBitcoinAddress); + if (!addr2.IsValid()) + { + strError = "Invalid address"; + return false; + } + CKeyID keyID2; + if (!addr2.GetKeyID(keyID2)) + { + strError = "Address does not refer to key"; + return false; + } + bool fInvalid = false; + std::vector vchSig2 = DecodeBase64(sSignature.c_str(), &fInvalid); + if (fInvalid) + { + strError = "Malformed base64 encoding"; + return false; + } + CHashWriter ss2(SER_GETHASH, 0); + ss2 << strMessageMagic; + ss2 << strMessage; + CPubKey pubkey2; + if (!pubkey2.RecoverCompact(ss2.GetHash(), vchSig2)) + { + strError = "Unable to recover public key."; + return false; + } + bool fSuccess = (pubkey2.GetID() == keyID2); + return fSuccess; +} + + +CPK GetCPK(std::string sData) +{ + // CPK DATA FORMAT: sCPK + "|" + Sanitized NickName + "|" + LockTime + "|" + SecurityHash + "|" + CPK Signature + "|" + Email + "|" + VendorType + "|" + OptData + CPK k; + std::vector vDec = Split(sData.c_str(), "|"); + if (vDec.size() < 5) return k; + std::string sSecurityHash = vDec[3]; + std::string sSig = vDec[4]; + std::string sCPK = vDec[0]; + if (sCPK.empty()) return k; + if (vDec.size() >= 6) + k.sEmail = vDec[5]; + if (vDec.size() >= 7) + k.sVendorType = vDec[6]; + if (vDec.size() >= 8) + k.sOptData = vDec[7]; + + k.fValid = CheckStakeSignature(sCPK, sSig, sSecurityHash, k.sError); + if (!k.fValid) + { + LogPrintf("GetCPK::Error Sig %s, SH %s, Err %s, CPK %s, NickName %s ", sSig, sSecurityHash, k.sError, sCPK, vDec[1]); + return k; + } + + k.sAddress = sCPK; + k.sNickName = vDec[1]; + k.nLockTime = (int64_t)cdbl(vDec[2], 0); + + return k; + +} + +std::map GetChildMap(std::string sGSCObjType) +{ + std::map mCPKMap; + boost::to_upper(sGSCObjType); + int i = 0; + for (auto ii : mvApplicationCache) + { + if (Contains(ii.first.first, sGSCObjType)) + { + CPK k = GetCPK(ii.second.first); + i++; + mCPKMap.insert(std::make_pair(k.sAddress + "-" + RoundToString(i, 0), k)); + } + } + return mCPKMap; +} + + +std::map GetGSCMap(std::string sGSCObjType, std::string sSearch, bool fRequireSig) +{ + std::map mCPKMap; + boost::to_upper(sGSCObjType); + for (auto ii : mvApplicationCache) + { + if (ii.first.first == sGSCObjType) + { + CPK k = GetCPK(ii.second.first); + if (!k.sAddress.empty() && k.fValid) + { + if ((!sSearch.empty() && (sSearch == k.sAddress || sSearch == k.sNickName)) || sSearch.empty()) + { + mCPKMap.insert(std::make_pair(k.sAddress, k)); + } + } + } + } + return mCPKMap; +} + +CAmount CAmountFromValue(const UniValue& value) +{ + if (!value.isNum() && !value.isStr()) return 0; + CAmount amount; + if (!ParseFixedPoint(value.getValStr(), 8, &amount)) return 0; + if (!MoneyRange(amount)) return 0; + return amount; +} + +static CCriticalSection csReadWait; +std::string ReadCache(std::string sSection, std::string sKey) +{ + LOCK(csReadWait); + std::string sLookupSection = sSection; + std::string sLookupKey = sKey; + boost::to_upper(sLookupSection); + boost::to_upper(sLookupKey); + // NON-CRITICAL TODO : Find a way to eliminate this to_upper while we transition to non-financial transactions + if (sLookupSection.empty() || sLookupKey.empty()) + return std::string(); + std::pair t = mvApplicationCache[std::make_pair(sLookupSection, sLookupKey)]; + return t.first; +} + +std::string TimestampToHRDate(double dtm) +{ + if (dtm == 0) return "1-1-1970 00:00:00"; + if (dtm > 9888888888) return "1-1-2199 00:00:00"; + std::string sDt = DateTimeStrFormat("%m-%d-%Y %H:%M:%S",dtm); + return sDt; +} + +std::string ExtractXML(std::string XMLdata, std::string key, std::string key_end) +{ + std::string extraction = ""; + std::string::size_type loc = XMLdata.find( key, 0 ); + if( loc != std::string::npos ) + { + std::string::size_type loc_end = XMLdata.find( key_end, loc+3); + if (loc_end != std::string::npos ) + { + extraction = XMLdata.substr(loc+(key.length()),loc_end-loc-(key.length())); + } + } + return extraction; +} + + +std::string AmountToString(const CAmount& amount) +{ + bool sign = amount < 0; + int64_t n_abs = (sign ? -amount : amount); + int64_t quotient = n_abs / COIN; + int64_t remainder = n_abs % COIN; + std::string sAmount = strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder); + return sAmount; +} + +static CBlockIndex* pblockindexFBBHLast; +CBlockIndex* FindBlockByHeight(int nHeight) +{ + CBlockIndex *pblockindex; + if (nHeight < 0 || nHeight > chainActive.Tip()->nHeight) return NULL; + + if (nHeight < chainActive.Tip()->nHeight / 2) + pblockindex = mapBlockIndex[chainActive.Genesis()->GetBlockHash()]; + else + pblockindex = chainActive.Tip(); + if (pblockindexFBBHLast && abs(nHeight - pblockindex->nHeight) > abs(nHeight - pblockindexFBBHLast->nHeight)) + pblockindex = pblockindexFBBHLast; + while (pblockindex->nHeight > nHeight) + pblockindex = pblockindex->pprev; + while (pblockindex->nHeight < nHeight) + pblockindex = chainActive.Next(pblockindex); + pblockindexFBBHLast = pblockindex; + return pblockindex; +} + +std::string DefaultRecAddress(std::string sType) +{ + std::string sDefaultRecAddress; + for (auto item : pwalletMain->mapAddressBook) + { + const CBitcoinAddress& address = item.first; + std::string strName = item.second.name; + bool fMine = IsMine(*pwalletMain, address.Get()); + if (fMine) + { + sDefaultRecAddress=CBitcoinAddress(address).ToString(); + boost::to_upper(strName); + boost::to_upper(sType); + if (strName == sType) + { + sDefaultRecAddress = CBitcoinAddress(address).ToString(); + return sDefaultRecAddress; + } + } + } + + if (!sType.empty()) + { + std::string sError; + sDefaultRecAddress = GenerateNewAddress(sError, sType); + if (sError.empty()) return sDefaultRecAddress; + } + + return sDefaultRecAddress; +} + + +std::string RetrieveMd5(std::string s1) +{ + try + { + const char* chIn = s1.c_str(); + unsigned char digest2[16]; + MD5((unsigned char*)chIn, strlen(chIn), (unsigned char*)&digest2); + char mdString2[33]; + for(int i = 0; i < 16; i++) sprintf(&mdString2[i*2], "%02x", (unsigned int)digest2[i]); + std::string xmd5(mdString2); + return xmd5; + } + catch (std::exception &e) + { + return std::string(); + } +} + + +std::string PubKeyToAddress(const CScript& scriptPubKey) +{ + CTxDestination address1; + ExtractDestination(scriptPubKey, address1); + CBitcoinAddress address2(address1); + return address2.ToString(); +} + + +void GetTxTimeAndAmountAndHeight(uint256 hashInput, int hashInputOrdinal, int64_t& out_nTime, CAmount& out_caAmount, int& out_height) +{ + CTransaction tx1; + uint256 hashBlock1; + if (GetTransaction(hashInput, tx1, Params().GetConsensus(), hashBlock1, true)) + { + out_caAmount = tx1.vout[hashInputOrdinal].nValue; + BlockMap::iterator mi = mapBlockIndex.find(hashBlock1); + if (mi != mapBlockIndex.end()) + { + CBlockIndex* pindexHistorical = mapBlockIndex[hashBlock1]; + out_nTime = pindexHistorical->GetBlockTime(); + out_height = pindexHistorical->nHeight; + return; + } + else + { + LogPrintf("\nUnable to find hashBlock %s", hashBlock1.GetHex().c_str()); + } + } + else + { + LogPrintf("\nUnable to find hashblock1 in GetTransaction %s ",hashInput.GetHex().c_str()); + } +} + + + +CAmount GetRPCBalance() +{ + return pwalletMain->GetBalance(); +} + +bool RPCSendMoney(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend, std::string sOptionalData, double nCoinAge) +{ + CAmount curBalance = pwalletMain->GetBalance(); + + // Check amount + if (nValue <= 0) + { + sError = "Invalid amount"; + return false; + } + + if (pwalletMain->IsLocked()) + { + sError = "Wallet unlock required"; + return false; + } + + if (nValue > curBalance) + { + sError = "Insufficient funds"; + return false; + } + // Parse address + CScript scriptPubKey = GetScriptForDestination(address); + + // Create and send the transaction + CReserveKey reservekey(pwalletMain); + CAmount nFeeRequired; + std::string strError; + std::vector vecSend; + int nChangePosRet = -1; + bool fForce = false; + CRecipient recipient = {scriptPubKey, nValue, "", fSubtractFeeFromAmount}; + vecSend.push_back(recipient); + + int nMinConfirms = 0; + if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, ONLY_DENOMINATED, fUseInstantSend)) + { + if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance()) + { + sError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired)); + return false; + } + sError = "Unable to Create Transaction: " + strError; + return false; + } + //CValidationState state; + + if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX)) + { + sError = "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."; + return false; + } + return true; +} + +CAmount R20(CAmount amount) +{ + double nAmount = amount / COIN; + nAmount = nAmount + 0.5 - (nAmount < 0); + int iAmount = (int)nAmount; + return (iAmount * COIN); +} + +double R2X(double var) +{ + double value = (int)(var * 100 + .5); + return (double)value / 100; +} + +double Quantize(double nFloor, double nCeiling, double nValue) +{ + double nSpan = nCeiling - nFloor; + double nLevel = nSpan * nValue; + double nOut = nFloor + nLevel; + if (nOut > std::max(nFloor, nCeiling)) nOut = std::max(nFloor, nCeiling); + if (nOut < std::min(nCeiling, nFloor)) nOut = std::min(nCeiling, nFloor); + return nOut; +} + +int GetHeightByEpochTime(int64_t nEpoch) +{ + if (!chainActive.Tip()) return 0; + int nLast = chainActive.Tip()->nHeight; + if (nLast < 1) return 0; + for (int nHeight = nLast; nHeight > 0; nHeight--) + { + CBlockIndex* pindex = FindBlockByHeight(nHeight); + if (pindex) + { + int64_t nTime = pindex->GetBlockTime(); + if (nEpoch > nTime) return nHeight; + } + } + return -1; +} + +void GetGovSuperblockHeights(int& nNextSuperblock, int& nLastSuperblock) +{ + + int nBlockHeight = 0; + { + LOCK(cs_main); + nBlockHeight = (int)chainActive.Height(); + } + int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock; + int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle; + int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle; + int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset; + if(nBlockHeight < nFirstSuperblock) + { + nLastSuperblock = 0; + nNextSuperblock = nFirstSuperblock; + } else { + nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle; + nNextSuperblock = nLastSuperblock + nSuperblockCycle; + } +} + +std::string GetActiveProposals() +{ + int nStartTime = GetAdjustedTime() - (86400 * 32); + LOCK2(cs_main, governance.cs); + std::vector objs = governance.GetAllNewerThan(nStartTime); + std::string sXML; + int id = 0; + std::string sDelim = "|"; + std::string sZero = "\0"; + int nLastSuperblock = 0; + int nNextSuperblock = 0; + GetGovSuperblockHeights(nNextSuperblock, nLastSuperblock); + for (CGovernanceObject* pGovObj : objs) + { + if (pGovObj->GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) continue; + int64_t nEpoch = 0; + int64_t nStartEpoch = 0; + CGovernanceObject* myGov = governance.FindGovernanceObject(pGovObj->GetHash()); + UniValue obj = myGov->GetJSONObject(); + std::string sURL; + std::string sProposalType; + nStartEpoch = cdbl(obj["start_epoch"].getValStr(), 0); + nEpoch = cdbl(obj["end_epoch"].getValStr(), 0); + sURL = obj["url"].getValStr(); + sProposalType = obj["expensetype"].getValStr(); + if (sProposalType.empty()) sProposalType = "N/A"; + DACProposal dProposal = GetProposalByHash(pGovObj->GetHash(), nLastSuperblock); + std::string sHash = pGovObj->GetHash().GetHex(); + int nEpochHeight = GetHeightByEpochTime(nStartEpoch); + // First ensure the proposals gov height has not passed yet + bool bIsPaid = nEpochHeight < nLastSuperblock; + std::string sReport = DescribeProposal(dProposal); + if (fDebug) + LogPrintf("\nGetActiveProposals::Proposal %s , epochHeight %f, nLastSuperblock %f, IsPaid %f ", + sReport, nEpochHeight, nLastSuperblock, (double)bIsPaid); + if (!bIsPaid) + { + int iYes = pGovObj->GetYesCount(VOTE_SIGNAL_FUNDING); + int iNo = pGovObj->GetNoCount(VOTE_SIGNAL_FUNDING); + int iAbstain = pGovObj->GetAbstainCount(VOTE_SIGNAL_FUNDING); + id++; + if (sProposalType.empty()) sProposalType = "NA"; + std::string sProposalTime = TimestampToHRDate(nStartEpoch); + if (id == 1) sURL += "&t=" + RoundToString(GetAdjustedTime(), 0); + std::string sName; + sName = obj["name"].getValStr(); + double dCharityAmount = 0; + dCharityAmount = cdbl(obj["payment_amount"].getValStr(), 2); + std::string sRow = "" + sHash + sDelim + + sName + sDelim + + RoundToString(dCharityAmount, 2) + sDelim + + sProposalType + sDelim + + sProposalTime + sDelim + + RoundToString(iYes, 0) + sDelim + + RoundToString(iNo, 0) + sDelim + RoundToString(iAbstain,0) + + sDelim + sURL; + sXML += sRow; + } + } + return sXML; +} + +bool VoteManyForGobject(std::string govobj, std::string strVoteSignal, std::string strVoteOutcome, + int iVotingLimit, int& nSuccessful, int& nFailed, std::string& sError) +{ + + uint256 hash(uint256S(govobj)); + vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal); + if(eVoteSignal == VOTE_SIGNAL_NONE) + { + sError = "Invalid vote signal (funding)."; + return false; + } + vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome); + if(eVoteOutcome == VOTE_OUTCOME_NONE) + { + sError = "Invalid vote outcome (yes/no/abstain)"; + return false; + } + +#ifdef ENABLE_WALLET + if (!pwalletMain) + { + sError = "Voting is not supported when wallet is disabled."; + return false; + } +#endif + + std::map votingKeys; + + +// auto mnList = deterministicMNManager->GetListAtChainTip(); +// mnList.ForEachMN(true, [&](const CDeterministicMNCPtr& dmn) +// { +// CKey votingKey; +// if (pwalletMain->GetKey(dmn->pdmnState->keyIDVoting, votingKey)) +// { +// votingKeys.emplace(dmn->proTxHash, votingKey); +// } +// }); + + + + UniValue vOutcome; + + + try + { + + std::vector mnEntries; + mnEntries = masternodeConfig.getEntries(); + + UniValue resultsObj(UniValue::VOBJ); + + BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) { + std::string strError; + std::vector vchMasterNodeSignature; + std::string strMasterNodeSignMessage; + + CPubKey pubKeyCollateralAddress; + CKey keyCollateralAddress; + CPubKey pubKeyMasternode; + CKey keyMasternode; + + UniValue statusObj(UniValue::VOBJ); + + if(!CMessageSigner::GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)){ + nFailed++; + statusObj.push_back(Pair("result", "failed")); + statusObj.push_back(Pair("errorMessage", "Masternode signing error, could not set key correctly")); + resultsObj.push_back(Pair(mne.getAlias(), statusObj)); + continue; + } + + uint256 nTxHash; + nTxHash.SetHex(mne.getTxHash()); + + int nOutputIndex = 0; + if(!ParseInt32(mne.getOutputIndex(), &nOutputIndex)) { + continue; + } + + COutPoint outpoint(nTxHash, nOutputIndex); + + CMasternode mn; + bool fMnFound = mnodeman.Get(outpoint, mn); + + if(!fMnFound) { + nFailed++; + statusObj.push_back(Pair("result", "failed")); + statusObj.push_back(Pair("errorMessage", "Can't find masternode by collateral output")); + resultsObj.push_back(Pair(mne.getAlias(), statusObj)); + continue; + } + + CGovernanceVote vote(mn.vin.prevout, hash, eVoteSignal, eVoteOutcome); + if(!vote.Sign(keyMasternode, pubKeyMasternode)){ + nFailed++; + statusObj.push_back(Pair("result", "failed")); + statusObj.push_back(Pair("errorMessage", "Failure to sign.")); + resultsObj.push_back(Pair(mne.getAlias(), statusObj)); + continue; + } + + CGovernanceException exception; + if(governance.ProcessVoteAndRelay(vote, exception, *g_connman)) { + nSuccessful++; + statusObj.push_back(Pair("result", "success")); + } + else { + nFailed++; + statusObj.push_back(Pair("result", "failed")); + statusObj.push_back(Pair("errorMessage", exception.GetMessage())); + } + + resultsObj.push_back(Pair(mne.getAlias(), statusObj)); + } + + UniValue returnObj(UniValue::VOBJ); + returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", nSuccessful, nFailed))); + returnObj.push_back(Pair("detail", resultsObj)); + returnObj.push_back(Pair("success_count", nSuccessful)); + + vOutcome = returnObj; + + //vOutcome = VoteWithMasternodes(votingKeys, hash, eVoteSignal, eVoteOutcome); + } + catch(std::runtime_error& e) + { + sError = e.what(); + return false; + } + catch (...) + { + sError = "Voting failed."; + return false; + } + + nSuccessful = cdbl(vOutcome["success_count"].getValStr(), 0); + bool fResult = nSuccessful > 0 ? true : false; + return fResult; +} + + +std::string CreateGovernanceCollateral(uint256 GovObjHash, CAmount caFee, std::string& sError) +{ + CWalletTx wtx; + if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, GovObjHash, caFee, false)) + { + sError = "Error creating collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked."; + return std::string(); + } + if (sError.empty()) + { + // -- make our change address + CReserveKey reservekey(pwalletMain); + //CValidationState state; + pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), NetMsgType::TX); + DBG( cout << "gobject: prepare " + << " strData = " << govobj.GetDataAsString() + << ", hash = " << govobj.GetHash().GetHex() + << ", txidFee = " << wtx.GetHash().GetHex() + << endl; ); + return wtx.GetHash().ToString(); + } + return std::string(); +} + +int GetNextSuperblock() +{ + int nLastSuperblock, nNextSuperblock; + // Get current block height + int nBlockHeight = 0; + { + LOCK(cs_main); + nBlockHeight = (int)chainActive.Height(); + } + + // Get chain parameters + int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock; + int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle; + + // Get first superblock + int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle; + int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset; + + if(nBlockHeight < nFirstSuperblock) + { + nLastSuperblock = 0; + nNextSuperblock = nFirstSuperblock; + } + else + { + nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle; + nNextSuperblock = nLastSuperblock + nSuperblockCycle; + } + return nNextSuperblock; +} + + +bool SubmitProposalToNetwork(uint256 txidFee, int64_t nStartTime, std::string sHex, std::string& sError, std::string& out_sGovObj) +{ + if(!masternodeSync.IsBlockchainSynced()) + { + sError = "Must wait for client to sync with masternode network. "; + return false; + } + // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS + uint256 hashParent = uint256(); + int nRevision = 1; + CGovernanceObject govobj(hashParent, nRevision, nStartTime, txidFee, sHex); + DBG( cout << "gobject: submit " + << " strData = " << govobj.GetDataAsString() + << ", hash = " << govobj.GetHash().GetHex() + << ", txidFee = " << txidFee.GetHex() + << endl; ); + + std::string strHash = govobj.GetHash().ToString(); + if(!govobj.IsValidLocally(sError, true)) + { + sError += "Object submission rejected because object is not valid."; + LogPrintf("\n OBJECT REJECTED:\n gobject submit 0 1 %f %s %s \n", (double)nStartTime, sHex.c_str(), txidFee.GetHex().c_str()); + return false; + } + // RELAY THIS OBJECT - Reject if rate check fails but don't update buffer + + bool fRateCheckBypassed = false; + if(!governance.MasternodeRateCheck(govobj, true, false, fRateCheckBypassed)) + { + sError = "Object creation rate limit exceeded"; + return false; + } + //governance.AddSeenGovernanceObject(govobj.GetHash(), SEEN_OBJECT_IS_VALID); + govobj.Relay(*g_connman); + governance.AddGovernanceObject(govobj, *g_connman); + out_sGovObj = govobj.GetHash().ToString(); + return true; +} + + +static double HTTP_PROTO_VERSION = 2.0; +//std::string HTTPSPost(bool bPost, int iThreadID, std::string sActionName, std::string sDistinctUser, std::string sPayload, std::string sBaseURL, std::string sPage, int iPort, +// std::string sSolution, int iTimeoutSecs, int iMaxSize, int iBOE) +//{ +// std::string sData; +// int iChunkSize = 1024; +// if (iMaxSize > 512000) +// { +// sData.reserve(iMaxSize); +// iChunkSize = 65536; +// } +// +// // The OpenSSL version of Post *only* works with SSL websites, hence the need for HTTPPost(2) (using BOOST). The dev team is working on cleaning this up before the end of 2019 to have one standard version with cleaner code and less internal parts. // +// try +// { +// double dDebugLevel = cdbl(GetArg("-devdebuglevel", "0"), 0); +// +// std::map mapRequestHeaders; +// mapRequestHeaders["Miner"] = sDistinctUser; +// mapRequestHeaders["Action"] = sPayload; +// mapRequestHeaders["Solution"] = sSolution; +// mapRequestHeaders["Agent"] = FormatFullVersion(); +// // Supported pool Network Chain modes: main, test, regtest +// const CChainParams& chainparams = Params(); +// mapRequestHeaders["NetworkID"] = chainparams.NetworkIDString(); +// mapRequestHeaders["ThreadID"] = RoundToString(iThreadID, 0); +// mapRequestHeaders["OS"] = sOS; +// +// mapRequestHeaders["SessionID"] = msSessionID; +// mapRequestHeaders["WorkerID1"] = GetArg("-workerid", ""); +// mapRequestHeaders["WorkerID2"] = GetArg("-workeridfunded", ""); +// mapRequestHeaders["HTTP_PROTO_VERSION"] = RoundToString(HTTP_PROTO_VERSION, 0); +// +// BIO* bio; +// SSL_CTX* ctx; +// // Registers the SSL/TLS ciphers and digests and starts the security layer. +// SSL_library_init(); +// ctx = SSL_CTX_new(SSLv23_client_method()); +// if (ctx == NULL) +// { +// return "CTX_IS_NULL"; +// } +// bio = BIO_new_ssl_connect(ctx); +// std::string sDomain = GetDomainFromURL(sBaseURL); +// std::string sDomainWithPort = sDomain + ":" + RoundToString(iPort, 0); +// +// // Compatibility with strict d-dos prevention rules (like cloudflare) +// SSL * ssl(nullptr); +// BIO_get_ssl(bio, &ssl); +// SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); +// SSL_set_tlsext_host_name(ssl, const_cast(sDomain.c_str())); +// BIO_set_conn_int_port(bio, &iPort); +// +// BIO_set_conn_hostname(bio, sDomainWithPort.c_str()); +// if(BIO_do_connect(bio) <= 0) +// { +// return "Failed connection to " + sDomainWithPort + ""; +// } +// +// if (sDomain.empty()) return "DOMAIN_MISSING"; +// // Evo requires 2 args instead of 3, the last used to be true for DNS resolution=true +// +// CNetAddr cnaMyHost; +// LookupHost(sDomain.c_str(), cnaMyHost, true); +// CService addrConnect = CService(cnaMyHost, 443); +// +// if (!addrConnect.IsValid()) +// { +// return "DNS_ERROR"; +// } +// std::string sPost = PrepareHTTPPost(bPost, sPage, sDomain, sPayload, mapRequestHeaders); +// if (dDebugLevel == 1) +// LogPrintf("Trying connection to %s ", sPost); +// const char* write_buf = sPost.c_str(); +// if(BIO_write(bio, write_buf, strlen(write_buf)) <= 0) +// { +// return "FAILED_HTTPS_POST"; +// } +// // Variables used to read the response from the server +// int size; +// clock_t begin = clock(); +// char buf[65536]; +// for(;;) +// { +// // Get chunks of the response +// size = BIO_read(bio, buf, 65535); +// if(size <= 0) +// { +// break; +// } +// buf[size] = 0; +// std::string MyData(buf); +// sData += MyData; +// clock_t end = clock(); +// double elapsed_secs = double(end - begin) / (CLOCKS_PER_SEC + .01); +// if (elapsed_secs > iTimeoutSecs) break; +// if (TermPeekFound(sData, iBOE)) break; +// +// if (sData.find("Content-Length:") != std::string::npos) +// { +// double dMaxSize = cdbl(ExtractXML(sData,"Content-Length: ","\n"),0); +// std::size_t foundPos = sData.find("Content-Length:"); +// if (dMaxSize > 0) +// { +// iMaxSize = dMaxSize + (int)foundPos + 16; +// } +// } +// if ((int)sData.size() >= (iMaxSize-1)) break; +// } +// // R ANDREW - JAN 4 2018: Free bio resources +// BIO_free_all(bio); +// if (dDebugLevel == 1) +// LogPrintf("Received %s ", sData); +// return sData; +// } +// catch (std::exception &e) +// { +// return "WEB_EXCEPTION"; +// } +// catch (...) +// { +// return "GENERAL_WEB_EXCEPTION"; +// } +//} diff --git a/src/rpcpog.h b/src/rpcpog.h new file mode 100644 index 00000000..69b888a7 --- /dev/null +++ b/src/rpcpog.h @@ -0,0 +1,312 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RPCPOG_H +#define RPCPOG_H + +#include "wallet/wallet.h" +#include "consensus/validation.h" +#include "hash.h" +#include "net.h" +#include "utilstrencodings.h" +#include "validation.h" +#include +#include + +class CWallet; + + + + + +std::string RetrieveMd5(std::string s1); + +struct UserVote +{ + int nTotalYesCount = 0; + int nTotalNoCount = 0; + int nTotalAbstainCount = 0; + int nTotalYesWeight = 0; + int nTotalNoWeight = 0; + int nTotalAbstainWeight = 0; +}; + +struct CPK +{ + std::string sAddress; + int64_t nLockTime = 0; + std::string sCampaign; + std::string sNickName; + std::string sEmail; + std::string sVendorType; + std::string sError; + std::string sChildId; + std::string sOptData; + std::string cpid; + double nProminence = 0; + double nPoints = 0; + bool fValid = false; +}; + +struct DACResult +{ + std::string Response; + bool fError = false; + std::string ErrorCode; +}; + +struct Researcher +{ + std::string nickname; + int teamid = 0; + std::string country; + int64_t creationtime = 0; + double totalcredit = 0; + double wcgpoints = 0; + double rac = 0; + int id = 0; + std::string cpid; + bool found = false; + bool unbanked = false; + double CoinAge = 0; + std::string CPK; +}; + +struct CoinVin +{ + COutPoint OutPoint; + uint256 HashBlock = uint256S("0x0"); + int64_t BlockTime = 0; + double CoinAge = 0; + CAmount Amount = 0; + std::string Destination = std::string(); + bool Found = false; + CTransaction TxRef; +}; + +struct WhaleStake +{ + double Amount = 0; + double RewardAmount = 0; + double TotalOwed = 0; + int64_t BurnTime = 0; + int BurnHeight = 0; + int Duration = 0; + double DWU = 0; + double ActualDWU = 0; + int64_t MaturityTime = 0; + int MaturityHeight = 0; + std::string CPK = std::string(); + uint256 TXID = uint256S("0x0"); + std::string XML = std::string(); + std::string ReturnAddress = std::string(); + bool found = false; + bool paid = false; +}; + +static double MAX_DAILY_WHALE_COMMITMENTS = 5000000; +static double MAX_WHALE_DWU = 2.0; +struct WhaleMetric +{ + double nTotalFutureCommitments = 0; + double nTotalGrossFutureCommitments = 0; + + double nTotalCommitmentsDueToday = 0; + double nTotalGrossCommitmentsDueToday = 0; + + double nTotalBurnsToday = 0; + double nTotalGrossBurnsToday = 0; + + double nTotalMonthlyCommitments = 0; + double nTotalGrossMonthlyCommitments = 0; + + double nTotalAnnualReward = 0; + + double nSaturationPercentAnnual = 0; + double nSaturationPercentMonthly = 0; + double DWU = 0; +}; + +struct DACProposal +{ + std::string sName; + int64_t nStartEpoch = 0; + int64_t nEndEpoch = 0; + std::string sURL; + std::string sExpenseType; + double nAmount = 0; + std::string sAddress; + uint256 uHash = uint256S("0x0"); + int nHeight = 0; + bool fPassing = false; + int nNetYesVotes = 0; + int nYesVotes = 0; + int nNoVotes = 0; + int nAbstainVotes = 0; + int nMinPassing = 0; + int nLastSuperblock = 0; + bool fIsPaid = false; + std::string sProposalHRTime; +}; + +///** Comparison function for sorting the getchaintips heads. */ +//struct CompareBlocksByHeight +//{ +// bool operator()(const CBlockIndex* a, const CBlockIndex* b) const +// { +// /* Make sure that unequal blocks with the same height do not compare +// equal. Use the pointers themselves to make a distinction. */ +// +// if (a->nHeight != b->nHeight) +// return (a->nHeight > b->nHeight); +// +// return a < b; +// } +//}; + +CAmount CAmountFromValue(const UniValue& value); +std::string RoundToString(double d, int place); +std::string QueryBibleHashVerses(uint256 hash, uint64_t nBlockTime, uint64_t nPrevBlockTime, int nPrevHeight, CBlockIndex* pindexPrev); +CAmount GetDailyMinerEmissions(int nHeight); +std::string CreateBankrollDenominations(double nQuantity, CAmount denominationAmount, std::string& sError); +std::string DefaultRecAddress(std::string sType); +std::string GenerateNewAddress(std::string& sError, std::string sName); +CAmount GetTitheTotal(CTransaction tx); +bool IsTitheLegal(CTransaction ctx, CBlockIndex* pindex, CAmount tithe_amount); +void GetTxTimeAndAmountAndHeight(uint256 hashInput, int hashInputOrdinal, int64_t& out_nTime, CAmount& out_caAmount, int& out_height); +std::string SendTithe(CAmount caTitheAmount, double dMinCoinAge, CAmount caMinCoinAmount, CAmount caMaxTitheAmount, + std::string sSpecificTxId, int nSpecificOutput, std::string& sError); +CAmount GetTitheCap(const CBlockIndex* pindexLast); +double R2X(double var); +double Quantize(double nFloor, double nCeiling, double nValue); +CAmount Get24HourTithes(const CBlockIndex* pindexLast); +double GetPOGDifficulty(const CBlockIndex* pindex); +std::string GetActiveProposals(); +bool VoteManyForGobject(std::string govobj, std::string strVoteSignal, std::string strVoteOutcome, + int iVotingLimit, int& nSuccessful, int& nFailed, std::string& sError); +bool AmIMasternode(); +std::string CreateGovernanceCollateral(uint256 GovObjHash, CAmount caFee, std::string& sError); +int GetNextSuperblock(); +std::string StoreBusinessObjectWithPK(UniValue& oBusinessObject, std::string& sError); +std::string StoreBusinessObject(UniValue& oBusinessObject, std::string& sError); +bool is_email_valid(const std::string& e); +double GetSporkDouble(std::string sName, double nDefault); +int64_t GetFileSize(std::string sPath); +std::string AddBlockchainMessages(std::string sAddress, std::string sType, std::string sPrimaryKey, + std::string sHTML, CAmount nAmount, double minCoinAge, std::string& sError); +std::string ReadCache(std::string sSection, std::string sKey); +void ClearCache(std::string sSection); +void WriteCache(std::string sSection, std::string sKey, std::string sValue, int64_t locktime, bool IgnoreCase=true); +std::string GetSporkValue(std::string sKey); +std::string TimestampToHRDate(double dtm); +std::string GetArrayElement(std::string s, std::string delim, int iPos); +void GetMiningParams(int nPrevHeight, bool& f7000, bool& f8000, bool& f9000, bool& fTitheBlocksActive); +std::string RetrieveTxOutInfo(const CBlockIndex* pindexLast, int iLookback, int iTxOffset, int ivOutOffset, int iDataType); +double GetBlockMagnitude(int nChainHeight); +uint256 PercentToBigIntBase(int iPercent); +std::string GetIPFromAddress(std::string sAddress); +bool SubmitProposalToNetwork(uint256 txidFee, int64_t nStartTime, std::string sHex, std::string& sError, std::string& out_sGovObj); +std::string SubmitToIPFS(std::string sPath, std::string& sError); +UniValue GetDataList(std::string sType, int iMaxAgeInDays, int& iSpecificEntry, std::string sSearch, std::string& outEntry); +int GetSignalInt(std::string sLocalSignal); +double GetDifficulty(const CBlockIndex* blockindex); +bool LogLimiter(int iMax1000); +std::string PubKeyToAddress(const CScript& scriptPubKey); +UniValue ContributionReport(); +int DeserializePrayersFromFile(); +double Round(double d, int place); +void SerializePrayersToFile(int nHeight); +std::string AmountToString(const CAmount& amount); +CBlockIndex* FindBlockByHeight(int nHeight); +std::string rPad(std::string data, int minWidth); +double cdbl(std::string s, int place); +std::string AmountToString(const CAmount& amount); +std::string ExtractXML(std::string XMLdata, std::string key, std::string key_end); +bool Contains(std::string data, std::string instring); +std::string GetVersionAlert(); +bool CheckNonce(bool f9000, unsigned int nNonce, int nPrevHeight, int64_t nPrevBlockTime, int64_t nBlockTime, const Consensus::Params& params); +bool RPCSendMoney(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend=false, std::string sOptionalData = "", double nCoinAge = 0); +bool FundWithExternalPurse(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend, CAmount nExactAmount, std::string sOptionalData, double dMinCoinAge, std::string sPursePubKey); +std::vector ReadBytesAll(char const* filename); +std::string VectToString(std::vector v); +CAmount StringToAmount(std::string sValue); +bool CompareMask(CAmount nValue, CAmount nMask); +std::string GetElement(std::string sIn, std::string sDelimiter, int iPos); +bool CopyFile(std::string sSrc, std::string sDest); +std::string Caption(std::string sDefault, int iMaxLen); +std::vector Split(std::string s, std::string delim); +void MemorizeBlockChainPrayers(bool fDuringConnectBlock, bool fSubThread, bool fColdBoot, bool fDuringSanctuaryQuorum); +double GetBlockVersion(std::string sXML); +bool CheckStakeSignature(std::string sBitcoinAddress, std::string sSignature, std::string strMessage, std::string& strError); +std::string HTTPSPost(bool bPost, int iThreadID, std::string sActionName, std::string sDistinctUser, std::string sPayload, std::string sBaseURL, std::string sPage, int iPort, + std::string sSolution, int iTimeoutSecs, int iMaxSize, int iBreakOnError); +std::string HTTPSPost2(bool bPost, std::string sProtocol, std::string sDomain, std::string sPage, std::string sPayload, std::string sFileName); +std::string FormatHTML(std::string sInput, int iInsertCount, std::string sStringToInsert); +std::string GJE(std::string sKey, std::string sValue, bool bIncludeDelimiter, bool bQuoteValue); +bool InstantiateOneClickMiningEntries(); +bool WriteKey(std::string sKey, std::string sValue); +std::string GetTransactionMessage(CTransaction tx); +std::map GetChildMap(std::string sGSCObjType); +bool AdvertiseChristianPublicKeypair(std::string sProjectId, std::string sNickName, std::string sEmail, std::string sVendorType, bool fUnJoin, bool fForce, CAmount nFee, std::string sOptData, std::string &sError); +CWalletTx CreateAntiBotNetTx(CBlockIndex* pindexLast, double nMinCoinAge, CReserveKey& reservekey, std::string& sXML, std::string sPoolMiningPublicKey, std::string& sError); +double GetAntiBotNetWeight(int64_t nBlockTime, CTransaction tx, bool fDebug, std::string sSolver); +double GetABNWeight(const CBlock& block, bool fMining); +std::map GetSporkMap(std::string sPrimaryKey, std::string sSecondaryKey); +std::map GetGSCMap(std::string sGSCObjType, std::string sSearch, bool fRequireSig); +void WriteCacheDouble(std::string sKey, double dValue); +double ReadCacheDouble(std::string sKey); +bool CheckAntiBotNetSignature(CTransaction tx, std::string sType, std::string sSolver); +double GetVINCoinAge(int64_t nBlockTime, CTransaction tx, bool fDebug); +CAmount GetTitheAmount(CTransaction ctx); +CPK GetCPK(std::string sData); +std::string GetCPKData(std::string sProjectId, std::string sPK); +CAmount GetRPCBalance(); +void GetGovSuperblockHeights(int& nNextSuperblock, int& nLastSuperblock); +int GetHeightByEpochTime(int64_t nEpoch); +bool CheckABNSignature(const CBlock& block, std::string& out_CPK); +std::string GetPOGBusinessObjectList(std::string sType, std::string sFields); +std::string SignMessageEvo(std::string strAddress, std::string strMessage, std::string& sError); +const CBlockIndex* GetBlockIndexByTransactionHash(const uint256 &hash); +double AddVector(std::string sData, std::string sDelim); +int ReassessAllChains(); +double GetFees(CTransaction tx); +int64_t GetCacheEntryAge(std::string sSection, std::string sKey); +void LogPrintWithTimeLimit(std::string sSection, std::string sValue, int64_t nMaxAgeInSeconds); +std::vector GetVectorOfFilesInDirectory(const std::string &dirPath, const std::vector dirSkipList); +std::string GetAttachmentData(std::string sPath); +std::string BIPFS_UploadSingleFile(std::string sPath, std::string sWebPath); +std::string Path_Combine(std::string sPath, std::string sFileName); +std::string DSQL_Ansi92Query(std::string sSQL); +void ProcessBLSCommand(CTransaction tx); +DACResult GetDecentralizedURL(); +std::string BIPFS_Payment(CAmount nAmount, std::string sTXID, std::string sXML); +DACResult DSQL_ReadOnlyQuery(std::string sXMLSource); +DACResult DSQL_ReadOnlyQuery(std::string sEndpoint, std::string sXML); +int LoadResearchers(); +std::string TeamToName(int iTeamID); +std::string GetResearcherCPID(std::string sSearch); +bool CreateExternalPurse(std::string& sError); +bool VerifyMemoryPoolCPID(CTransaction tx); +std::string GetEPArg(bool fPublic); +std::vector GetDWS(bool fIncludeMemoryPool); +WhaleMetric GetWhaleMetrics(int nHeight, bool fIncludeMemoryPool); +bool VerifyDynamicWhaleStake(CTransaction tx, std::string& sError); +double GetDWUBasedOnMaturity(double nDuration, double dDWU); +double GetOwedBasedOnMaturity(double nDuration, double dDWU, double dAmount); +std::vector GetPayableWhaleStakes(int nHeight, double& nOwed); +CoinVin GetCoinVIN(COutPoint o, int64_t nTxTime); +bool GetTxDAC(uint256 txid, CTransaction& tx1); +double GetWhaleStakesInMemoryPool(std::string sCPK); +std::string GetCPKByCPID(std::string sCPID); +int GetNextPODCTransmissionHeight(int height); +int GetWhaleStakeSuperblockHeight(int nHeight); +std::string SearchChain(int nBlocks, std::string sDest); +std::string GetResDataBySearch(std::string sSearch); +int GetWCGIdByCPID(std::string sSearch); +uint256 ComputeRandomXTarget(uint256 hash, int64_t nPrevBlockTime, int64_t nBlockTime); +std::string ReverseHex(std::string const & src); +uint256 GetRandomXHash(std::string sHeaderHex, uint256 key, uint256 hashPrevBlock, int iThreadID); +std::string GenerateFaucetCode(); + +#endif diff --git a/src/smartcontract-client.cpp b/src/smartcontract-client.cpp new file mode 100644 index 00000000..0ee35049 --- /dev/null +++ b/src/smartcontract-client.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "smartcontract-client.h" +#include "smartcontract-server.h" +#include "util.h" +#include "utilmoneystr.h" +#include "rpcpodc.h" +#include "rpcpog.h" +#include "init.h" +#include "activemasternode.h" +#include "governance-classes.h" +#include "governance.h" +#include "masternode-sync.h" +#include "masternode-payments.h" +#include "masternodeconfig.h" +#include "messagesigner.h" +#include +#include // for to_lower() +#include // for trim() +#include // for StringToUnixTime() +#include /* round, floor, ceil, trunc */ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ENABLE_WALLET +extern CWallet* pwalletMain; +#endif // ENABLE_WALLET + +//////////////////////////////////////////////////////////////////// DAC - SMART CONTRACTS - CLIENT SIDE /////////////////////////////////////////////////////////////////////////////////////////////// + diff --git a/src/smartcontract-client.h b/src/smartcontract-client.h new file mode 100644 index 00000000..0a62823c --- /dev/null +++ b/src/smartcontract-client.h @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef SMARTCONTRACTCLIENT_H +#define SMARTCONTRACTCLIENT_H + +#include "wallet/wallet.h" +#include "hash.h" +#include "net.h" +#include "rpcpog.h" +#include "utilstrencodings.h" +#include + +class CWallet; + +UniValue GetCampaigns(); +bool CheckCampaign(std::string sName); +bool Enrolled(std::string sCampaignName, std::string& sError); +CPK GetCPKFromProject(std::string sProjName, std::string sCPKPtr); +UniValue SentGSCCReport(int nHeight, std::string sMyCPK); +CPK GetMyCPK(std::string sProjectName); +bool CreateGSCTransmission(bool fForce, std::string sDiary, std::string& sError, std::string sSpecificCampaignName, std::string& sWarning); +bool CreateAllGSCTransmissions(std::string& sError); +double GetNecessaryCoinAgePercentageForPODC(); + +#endif diff --git a/src/smartcontract-server.cpp b/src/smartcontract-server.cpp new file mode 100644 index 00000000..cf3873b8 --- /dev/null +++ b/src/smartcontract-server.cpp @@ -0,0 +1,101 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "smartcontract-server.h" +#include "util.h" +#include "utilmoneystr.h" +#include "rpcpog.h" +#include "rpcpodc.h" +#include "smartcontract-client.h" +#include "init.h" +#include "activemasternode.h" +#include "governance-classes.h" +#include "governance.h" +#include "masternode-sync.h" +#include "masternode-payments.h" +#include "messagesigner.h" +#include "spork.h" +#include +#include // for to_lower() +#include // for trim(), and case insensitive compare +#include // for StringToUnixTime() +#include /* round, floor, ceil, trunc */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef ENABLE_WALLET +extern CWallet* pwalletMain; +#endif // ENABLE_WALLET + + + +//////////////////////////////////////////////////////////////////////////////// Watchman-On-The-Wall ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// DAC's version of The Sentinel, March 31st, 2019 // + +// // + + + +std::string GetCPIDByCPK(std::string sCPK) +{ + std::string sData = ReadCache("CPK-WCG", sCPK); + std::vector vP = Split(sData.c_str(), "|"); + if (vP.size() < 10) + return std::string(); + std::string cpid = vP[8]; + return cpid; +} + +DACProposal GetProposalByHash(uint256 govObj, int nLastSuperblock) +{ + int nMinPassing = 500 * .10; + if (nMinPassing < 1) nMinPassing = 1; + CGovernanceObject* myGov = governance.FindGovernanceObject(govObj); + UniValue obj = myGov->GetJSONObject(); + DACProposal dacProposal; + dacProposal.sName = obj["name"].getValStr(); + dacProposal.nStartEpoch = cdbl(obj["start_epoch"].getValStr(), 0); + dacProposal.nEndEpoch = cdbl(obj["end_epoch"].getValStr(), 0); + dacProposal.sURL = obj["url"].getValStr(); + dacProposal.sExpenseType = obj["expensetype"].getValStr(); + dacProposal.nAmount = cdbl(obj["payment_amount"].getValStr(), 2); + dacProposal.sAddress = obj["payment_address"].getValStr(); + dacProposal.uHash = myGov->GetHash(); + dacProposal.nHeight = GetHeightByEpochTime(dacProposal.nStartEpoch); + dacProposal.nMinPassing = 1; + dacProposal.nYesVotes = myGov->GetYesCount(VOTE_SIGNAL_FUNDING); + dacProposal.nNoVotes = myGov->GetNoCount(VOTE_SIGNAL_FUNDING); + dacProposal.nAbstainVotes = myGov->GetAbstainCount(VOTE_SIGNAL_FUNDING); + dacProposal.nNetYesVotes = myGov->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING); + dacProposal.nLastSuperblock = nLastSuperblock; + dacProposal.sProposalHRTime = TimestampToHRDate(dacProposal.nStartEpoch); + dacProposal.fPassing = dacProposal.nNetYesVotes >= nMinPassing; + dacProposal.fIsPaid = dacProposal.nHeight < nLastSuperblock; + return dacProposal; +} + +std::string DescribeProposal(DACProposal dacProposal) +{ + std::string sReport = "Proposal StartDate: " + dacProposal.sProposalHRTime + ", Hash: " + dacProposal.uHash.GetHex() + " for Amount: " + RoundToString(dacProposal.nAmount, 2) + "IMAGECOIN, Name: " + + dacProposal.sName + ", ExpType: " + dacProposal.sExpenseType + ", PAD: " + dacProposal.sAddress + + ", Height: " + RoundToString(dacProposal.nHeight, 0) + + ", Votes: " + RoundToString(dacProposal.nNetYesVotes, 0) + ", LastSB: " + + RoundToString(dacProposal.nLastSuperblock, 0); + return sReport; +} + +std::string GetCPIDElementByData(std::string sData, int iElement) +{ + std::vector vP = Split(sData.c_str(), "|"); + if (vP.size() < 10) + return std::string(); + return vP[iElement]; +} + diff --git a/src/smartcontract-server.h b/src/smartcontract-server.h new file mode 100644 index 00000000..ab12b9c5 --- /dev/null +++ b/src/smartcontract-server.h @@ -0,0 +1,47 @@ +// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef SMARTCONTRACTSERVER_H +#define SMARTCONTRACTSERVER_H + +#include "wallet/wallet.h" +#include "hash.h" +#include "net.h" +#include "utilstrencodings.h" +#include "rpcpog.h" +#include + +class CWallet; + +std::string AssessBlocks(int nHeight, bool fCreating); +int GetLastGSCSuperblockHeight(int nCurrentHeight, int& nNextSuperblock); +std::string GetGSCContract(int nHeight, bool fCreating); +bool SubmitGSCTrigger(std::string sHex, std::string& gobjecthash, std::string& sError); +void GetGSCGovObjByHeight(int nHeight, uint256 uOptFilter, int& out_nVotes, uint256& out_uGovObjHash, std::string& out_PaymentAddresses, std::string& out_PaymentAmounts); +uint256 GetPAMHashByContract(std::string sContract); +uint256 GetPAMHash(std::string sAddresses, std::string sAmounts); +bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string& sError); +std::string ExecuteGenericSmartContractQuorumProcess(); +UniValue GetProminenceLevels(int nHeight, std::string sFilterName); +bool NickNameExists(std::string sProjectName, std::string sNickName); +int GetRequiredQuorumLevel(int nHeight); +void GetTransactionPoints(CBlockIndex* pindex, CTransactionRef tx, double& nCoinAge, CAmount& nDonation); +bool ChainSynced(CBlockIndex* pindex); +std::string WatchmanOnTheWall(bool fForce, std::string& sContract); +void GetGovObjDataByPamHash(int nHeight, uint256 hPamHash, std::string& out_Data); +DACProposal GetProposalByHash(uint256 govObj, int nLastSuperblock); +std::string DescribeProposal(DACProposal dacProposal); +std::string GetTxCPK(CTransactionRef tx, std::string& sCampaignName); +double CalculatePoints(std::string sCampaign, std::string sDiary, double nCoinAge, CAmount nDonation, std::string sCPK); +double GetChildBalance(std::string sChildID, std::string sCharity); +double GetProminenceCap(std::string sCampaignName, double nPoints, double nProminence); +std::string GetCPIDByCPK(std::string sCPK); +std::string GetCPIDElementByData(std::string sData, int iElement); +double GetRequiredCoinAgeForPODC(double nRAC, double nTeamID); +double GetCoinPrice(); +bool VerifyChild(std::string childID, std::string sCharity); +bool IsOverBudget(int nHeight, std::string sAmounts); +std::string CheckGSCHealth(); + +#endif From cbec13efcfbff148fb5006b11061ea09c7004541 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:47:18 -0400 Subject: [PATCH 0574/1324] Add files via upload --- src/qt/forms/proposaladddialog.ui | 290 ++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 src/qt/forms/proposaladddialog.ui diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/proposaladddialog.ui new file mode 100644 index 00000000..00a19b44 --- /dev/null +++ b/src/qt/forms/proposaladddialog.ui @@ -0,0 +1,290 @@ + + + ProposalAddDialog + + + + 0 + 0 + 827 + 438 + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + + + + + + + + + + + + Proposal Amount + + + Qt::ImhDigitsOnly + + + + + + + Enter Proposal Amount + + + &Proposal Amount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + txtAmount + + + + + + + Discussion URL + + + + + + + Discussion URL + + + &Discussion URL: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + txtURL + + + + + + + Enter Proposal Name + + + + + + + Add New Proposal - v1.1<br> + + + + + + + Enter Proposal Name + + + &Proposal Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + txtName + + + + + + + + + + 150 + 0 + + + + &Submit Proposal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + + Expense Type + + + Expense Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Address + + + Qt::ImhNone + + + QLineEdit::Normal + + + + + + + Receiving Address + + + Funding Receiving Address: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 75 + true + + + + <html><head/><body><p align="center"><span style=" font-size:12pt; font-style:italic;">IMG Governance System</span></p></body></html> + + + + + + + + + + 15 + 75 + true + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + txtName + txtAmount + txtURL + txtAddress + cmbExpenseType + btnSubmit + + + + + + From 128c293c6a7ac41bdb3d25c2dddcab3a3a59473a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:47:45 -0400 Subject: [PATCH 0575/1324] Add files via upload --- src/qt/proposaladddialog.cpp | 192 +++++++++++++++++++++++++++++++++++ src/qt/proposaladddialog.h | 66 ++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 src/qt/proposaladddialog.cpp create mode 100644 src/qt/proposaladddialog.h diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp new file mode 100644 index 00000000..fa1a5511 --- /dev/null +++ b/src/qt/proposaladddialog.cpp @@ -0,0 +1,192 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "proposaladddialog.h" +#include "ui_proposaladddialog.h" +#include "addressbookpage.h" +#include "addresstablemodel.h" +#include "bitcoinunits.h" +#include "guiutil.h" +#include "util.h" +#include "optionsmodel.h" +#include "timedata.h" +#include "platformstyle.h" +#include "receiverequestdialog.h" +#include "recentrequeststablemodel.h" +#include "governance.h" +#include "governance-vote.h" +#include "governance-classes.h" + +#include "walletmodel.h" +#include "validation.h" +#include "rpcpodc.h" +#include "rpcpog.h" +#include +#include +#include +#include +#include +#include + +ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : + QDialog(parent), + ui(new Ui::ProposalAddDialog), + model(0), + platformStyle(platformStyle) +{ + ui->setupUi(this); + QString theme = GUIUtil::getThemeName(); + + if (!platformStyle->getImagesOnButtons()) { + ui->btnSubmit->setIcon(QIcon()); + } else { + ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); + } + + ui->cmbExpenseType->clear(); + ui->cmbExpenseType->addItem("IT"); + ui->cmbExpenseType->addItem("MKT"); + ui->cmbExpenseType->addItem("PR"); + ui->cmbExpenseType->addItem("P2P"); + + } + + +void ProposalAddDialog::UpdateDisplay() +{ + int nNextHeight = GetNextSuperblock(); + + std::string sInfo = "Note: Proposal Cost is 5 IMG. Next Superblock at height: " + RoundToString(nNextHeight, 0) + "
Warning: You must unlock the wallet before submitting the proposal."; + + if (fProposalNeedsSubmitted) + { + sInfo += "
NOTE: You have a proposal waiting to be submitted.
Status: " + msProposalResult; + } + else if (!msProposalResult.empty()) + { + sInfo = "
NOTE: Your last proposal has been submitted.
Status: " + msProposalResult; + } + + ui->txtInfo->setText(GUIUtil::TOQS(sInfo)); +} + + +void ProposalAddDialog::setModel(WalletModel *model) +{ + this->model = model; + + if(model && model->getOptionsModel()) + { + UpdateDisplay(); + } +} + +ProposalAddDialog::~ProposalAddDialog() +{ + delete ui; +} + +void ProposalAddDialog::clear() +{ + ui->txtName->setText(""); + ui->txtURL->setText(""); + ui->txtAmount->setText(""); + ui->txtAddress->setText(""); +} + + +void ProposalAddDialog::on_btnSubmit_clicked() +{ + if(!model || !model->getOptionsModel()) + return; + std::string sName = GUIUtil::FROMQS(ui->txtName->text()); + std::string sAddress = GUIUtil::FROMQS(ui->txtAddress->text()); + std::string sAmount = GUIUtil::FROMQS(ui->txtAmount->text()); + std::string sURL = GUIUtil::FROMQS(ui->txtURL->text()); + std::string sError; + if (sName.length() < 3) sError += "Proposal Name must be populated. "; + CBitcoinAddress address(sAddress); + if (!address.IsValid()) sError += "Proposal Funding Address is invalid. "; + if (cdbl(sAmount,0) < 100) sError += "Proposal Amount is too low. "; + if (sURL.length() < 10) sError += "You must enter a discussion URL. "; + std::string sExpenseType = GUIUtil::FROMQS(ui->cmbExpenseType->currentText()); + if (sExpenseType.empty()) sError += "Expense Type must be chosen. "; + CAmount nBalance = GetRPCBalance(); + + if (fProposalNeedsSubmitted) + { + sError += "There is a proposal already being submitted (" + msProposalResult + "). Please wait until this proposal is sent before creating a new one. "; + } + else + { + if (nBalance < (6*COIN)) sError += "Sorry balance too low to create proposal collateral. "; + } + + std::string sPrepareTxId; + std::string sHex; + int64_t unixStartTimestamp = GetAdjustedTime(); + int64_t unixEndTimestamp = GetAdjustedTime() + (60 * 60 * 24 * 30); + // Evo requires no spaces + sName = strReplace(sName, " ", "_"); + + if (sError.empty()) + { + // gobject prepare 0 1 EPOCH_TIME HEX + std::string sType = "1"; //Proposal + std::string sQ = "\""; + std::string sJson = "[[" + sQ + "proposal" + sQ + ",{"; + sJson += GJE("start_epoch", RoundToString(unixStartTimestamp, 0), true, false); + sJson += GJE("end_epoch", RoundToString(unixEndTimestamp, 0), true, false); + sJson += GJE("name", sName, true, true); + sJson += GJE("payment_address", sAddress, true, true); + sJson += GJE("payment_amount", sAmount, true, false); + sJson += GJE("type", sType, true, false); + sJson += GJE("expensetype", sExpenseType, true, true); + sJson += GJE("url", sURL, false, true); + sJson += "}]]"; + // make into hex + std::vector vchJson = std::vector(sJson.begin(), sJson.end()); + sHex = HexStr(vchJson.begin(), vchJson.end()); + // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS + uint256 hashParent = uint256(); + int nRevision = 1; + // CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT + CGovernanceObject govobj(hashParent, nRevision, unixStartTimestamp, uint256(), sHex); + if((govobj.GetObjectType() == GOVERNANCE_OBJECT_TRIGGER) || (govobj.GetObjectType() == GOVERNANCE_OBJECT_WATCHDOG)) + { + sError = "Trigger and watchdog objects cannot be created from the UI yet."; + } + if (sError.empty()) + { + if(!govobj.IsValidLocally(sError, false)) + { + LogPrintf("Error while creating governance object %s, object not valid. Error: %s \n", sJson, sError); + sError += "Governance object is not valid - " + govobj.GetHash().ToString(); + } + + if (sError.empty()) + { + sPrepareTxId = CreateGovernanceCollateral(govobj.GetHash(), govobj.GetMinCollateralFee(), sError); + } + } + } + std::string sNarr = (sError.empty()) ? "Successfully Prepared Proposal " + sPrepareTxId + ". NOTE: You must wait 6 confirms for the proposal to be submitted. Please check back on this page periodically " + + " to ensure a successful transmission and that no error message is listed in the bottom area of the page. " + + "
WARNING: Do not shut down the core wallet until the proposal is submitted, otherwise you may lose your proposal submission and proposal collateral. " + +"

Thank you for using our Governance System." : sError; + if (sError.empty()) + { + // Set the proposal up to be submitted after 6 confirms using our Governance Service: + nProposalPrepareHeight = chainActive.Tip()->nHeight; + msProposalResult = "Submitting Proposal at height " + RoundToString(nProposalPrepareHeight + 6, 0) + "..."; + uTxIdFee = uint256S(sPrepareTxId); + nProposalStartTime = unixStartTimestamp; + msProposalHex = sHex; + fProposalNeedsSubmitted = true; + clear(); + } + QMessageBox::warning(this, tr("Proposal Add Result"), GUIUtil::TOQS(sNarr), QMessageBox::Ok, QMessageBox::Ok); + + UpdateDisplay(); +} diff --git a/src/qt/proposaladddialog.h b/src/qt/proposaladddialog.h new file mode 100644 index 00000000..56679642 --- /dev/null +++ b/src/qt/proposaladddialog.h @@ -0,0 +1,66 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_PROPOSALADDDIALOG_H +#define BITCOIN_QT_PROPOSALADDDIALOG_H + +#include "guiutil.h" + +#include +#include +#include +#include +#include +#include +#include + +class OptionsModel; +class PlatformStyle; +class WalletModel; + +namespace Ui { + class ProposalAddDialog; +} + +QT_BEGIN_NAMESPACE +class QModelIndex; +QT_END_NAMESPACE + +/** Dialog for Adding a Governance Proposal */ +class ProposalAddDialog : public QDialog +{ + Q_OBJECT + +public: + enum ColumnWidths { + DATE_COLUMN_WIDTH = 130, + LABEL_COLUMN_WIDTH = 120, + AMOUNT_MINIMUM_COLUMN_WIDTH = 160, + MINIMUM_COLUMN_WIDTH = 130 + }; + + explicit ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ProposalAddDialog(); + + void setModel(WalletModel *model); + void UpdateDisplay(); + +public Q_SLOTS: + void clear(); + +protected: + + +private: + Ui::ProposalAddDialog *ui; + GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; + WalletModel *model; + QMenu *contextMenu; + const PlatformStyle *platformStyle; + +private Q_SLOTS: + void on_btnSubmit_clicked(); +}; + +#endif // BITCOIN_QT_PROPOSALADDDIALOG_H From 02a78fc524fcfa92581b496f5f8ebb5c44cd1adf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:51:55 -0400 Subject: [PATCH 0576/1324] Update Makefile.am --- src/Makefile.am | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 15b14cf7..678aa617 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -245,7 +245,13 @@ BITCOIN_CORE_H = \ zmq/zmqabstractnotifier.h \ zmq/zmqconfig.h\ zmq/zmqnotificationinterface.h \ - zmq/zmqpublishnotifier.h + zmq/zmqpublishnotifier.h \ + bbpsocket.h \ + masternodeman.h \ + smartcontract-client.h \ + smartcontract-server.h \ + rpcpodc.h \ + rpcpog.h obj/build.h: FORCE @@ -338,6 +344,7 @@ libhelpthehomeless_server_a_SOURCES = \ validation.cpp \ validationinterface.cpp \ versionbits.cpp \ + masternodeman.cpp \ $(BITCOIN_CORE_H) if ENABLE_ZMQ @@ -364,6 +371,8 @@ libhelpthehomeless_wallet_a_SOURCES = \ wallet/rpcwallet.cpp \ wallet/wallet.cpp \ wallet/walletdb.cpp \ + rpcpodc.cpp \ + rpcpog.cpp $(BITCOIN_CORE_H) # crypto primitives library From ea35281262ac68d12d5062429a23f29e282cada0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 20:54:43 -0400 Subject: [PATCH 0577/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index faa4d1cc..a412bb00 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -52,7 +52,8 @@ QT_FORMS_UI = \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ - qt/forms/transactiondescdialog.ui + qt/forms/transactiondescdialog.ui \ + qt/forms/proposaladddialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -104,7 +105,12 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp + qt/moc_walletview.cpp \ + moc_rpcpodc.cpp \ + moc_rpcpog.cpp \ + moc_smartcontract-server.cpp \ + moc_smartcontract-client.cpp \ + qt/moc_proposaladddialog.cpp \ BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -187,7 +193,12 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h + qt/winshutdownmonitor.h \ + rpcpodc.h \ + rpcpog.h \ + smartcontract-server.h \ + smartcontract-client.h \ + qt/proposaladddialog.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -525,7 +536,12 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp + qt/walletview.cpp \ + rpcpodc.cpp \ + rpcpog.cpp \ + smartcontract-server.cpp \ + smartcontract-client.cpp \ + qt/proposaladddialog.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 746d7c71087d985e86d6d7058e886392c48c28cf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:02:11 -0400 Subject: [PATCH 0578/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index c0f24c4f..c8f8067d 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,6 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +#include "proposaladddialog.h" /* #include "tradingdialogpage.h" */ @@ -143,6 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), + proposalAdd(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -618,6 +620,10 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); + // HTHW ProposalAdd + proposalAdd = new QAction(QIcon(":/icons/" + theme + "/about"), tr("HTH Add Proposals"), this); + proposalAdd->setStatusTip(tr("Add Proposals to the HTH Blockchain")); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); @@ -630,6 +636,9 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); + // HTHW ProposalAdd + connect(proposalAdd, SIGNAL(triggered()), this, SLOT(gotoProposalAddPage())); + // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -729,6 +738,9 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); + + QMenu* proposal = appMenuBar->addMenu(tr("&HTH Proposal")); + proposal->addAction(proposalAdd); } @@ -1057,6 +1069,12 @@ void BitcoinGUI::openClicked() } } +void BitcoinGUI::gotoProposalAddPage() +{ + proposalAdd->setChecked(true); + if (walletFrame) walletFrame->gotoProposalAddPage(); +} + /*void BitcoinGUI::gotoTradingDialogPage() { tradingAction->setChecked(true); From af898a1f7cd5144df4d80f49b995a3224b399e5e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:03:46 -0400 Subject: [PATCH 0579/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 1eb58065..6ab1acd4 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -104,6 +104,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; + QAction* proposalAdd; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ @@ -232,7 +233,8 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - + /** Switch to add proposal page */ + void gotoProposalAddPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 712261a827a267ebed309884c4ad74d422b5d2be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:08:58 -0400 Subject: [PATCH 0580/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a412bb00..4c24ea3b 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -110,7 +110,7 @@ QT_MOC_CPP = \ moc_rpcpog.cpp \ moc_smartcontract-server.cpp \ moc_smartcontract-client.cpp \ - qt/moc_proposaladddialog.cpp \ + qt/moc_proposaladddialog.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ From 3e5231619250fe1b6e78d3f5abb6bb284a835769 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:19:59 -0400 Subject: [PATCH 0581/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 6783019e..38b4eebf 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,6 +108,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } +void WalletFrame::gotoProposalAddPage() +{ + QMap::const_iterator i; + for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) + i.value()->gotoProposalAddPage(); +} + void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; From 4417fde35775d38074a1a19a6851603b7f5c76ec Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:20:27 -0400 Subject: [PATCH 0582/1324] Update walletframe.h --- src/qt/walletframe.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 54527997..bf9d166d 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,6 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: + /** Switch to ProposalAdd page */ + void gotoProposalAddPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From ea7f7eacf31bf9d1e0e08c7d056088536c90bbb2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:23:29 -0400 Subject: [PATCH 0583/1324] Update walletview.cpp --- src/qt/walletview.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index ba7978cd..8ddb6dbe 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,6 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" +#include "proposaladddialog.h" #include "ui_interface.h" @@ -73,6 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); + proposalAdd = new ProposalAddDialog(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); @@ -81,7 +83,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); + addWidget(privateSendPage); + addWidget(proposalAddPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -111,6 +114,9 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from sendCoinsPage connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + + // Pass through messages from EncryptDecryptPage + connect(proposalAdd, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); @@ -156,6 +162,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); + //proposalAdd->setClientModel(clientModel); } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -171,10 +178,12 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); + proposalAdd->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); usedSendingAddressesPage->setModel(_walletModel->getAddressTableModel()); + if (_walletModel) { @@ -229,6 +238,12 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } +void WalletView::gotoProposalAddPage() +{ + setCurrentWidget(proposalAdd); +} + + void WalletView::gotoGovernancePage() { QSettings settings; From eaaf30178dac8f8f107f05ae6c7fc3c7aeb15ff2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:24:40 -0400 Subject: [PATCH 0584/1324] Update walletview.h --- src/qt/walletview.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index ef368efe..d46e0ae0 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -24,6 +24,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; +class ProposalAddDialog; @@ -74,6 +75,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; + ProposalAddDialog *proposalAdd; TransactionView *transactionView; @@ -83,6 +85,8 @@ class WalletView : public QStackedWidget public Q_SLOTS: + /** Switch to ProposalAdd page */ + void gotoProposalAddPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From d4f99637bbb54385ab242fa889bd91722978cf6f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:25:36 -0400 Subject: [PATCH 0585/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 8ddb6dbe..f34554a9 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -84,7 +84,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); - addWidget(proposalAddPage); + addWidget(proposalAdd); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { From 957b0740c388369e97088cf57f679175f0aee6e7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:28:46 -0400 Subject: [PATCH 0586/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f34554a9..60332871 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - proposalAdd->setModel(walletModel); + /*proposalAdd->setModel(walletModel);*/ receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From de53cf83eb182313c087c03f8e38c91735ffb4e3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:35:41 -0400 Subject: [PATCH 0587/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index fa1a5511..a3644743 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -41,7 +41,7 @@ ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget if (!platformStyle->getImagesOnButtons()) { ui->btnSubmit->setIcon(QIcon()); } else { - ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); + ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/about")); } ui->cmbExpenseType->clear(); From 4bd11a7344b5b53931e57ced377441648916a2b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:37:36 -0400 Subject: [PATCH 0588/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index d46e0ae0..e6535918 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -75,7 +75,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - ProposalAddDialog *proposalAdd; + ProposalAddDialog *proposalAddPage; TransactionView *transactionView; From 5cc89d4674dfa655c832c31cade9e5bb9a702afe Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:39:05 -0400 Subject: [PATCH 0589/1324] Update walletview.cpp --- src/qt/walletview.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 60332871..7b0f2df9 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -74,7 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - proposalAdd = new ProposalAddDialog(platformStyle); + proposalAddPage = new ProposalAddDialog(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); @@ -84,7 +84,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); - addWidget(proposalAdd); + addWidget(proposalAddPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -116,7 +116,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from EncryptDecryptPage - connect(proposalAdd, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); @@ -162,7 +162,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); - //proposalAdd->setClientModel(clientModel); + //proposalAddPage->setClientModel(clientModel); } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - /*proposalAdd->setModel(walletModel);*/ + proposalAddPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); @@ -240,7 +240,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoProposalAddPage() { - setCurrentWidget(proposalAdd); + setCurrentWidget(proposalAddPage); } From c775e33e96282aa3dc6ef48b74643ca7eb7a6c91 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:40:54 -0400 Subject: [PATCH 0590/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 6ab1acd4..7b4cb172 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -104,7 +104,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* proposalAdd; + QAction *proposalAddAction; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ From ad9a1bf2a1c6b8b9c72c6fe93b3219bc5f7cd9fc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:43:25 -0400 Subject: [PATCH 0591/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index c8f8067d..1d855616 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - proposalAdd(0), + proposalAddAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -620,9 +620,8 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - // HTHW ProposalAdd - proposalAdd = new QAction(QIcon(":/icons/" + theme + "/about"), tr("HTH Add Proposals"), this); - proposalAdd->setStatusTip(tr("Add Proposals to the HTH Blockchain")); + proposalAddAction = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Add Proposal"), this); + proposalAddAction->setStatusTip(tr("Submit proposal")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -637,7 +636,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW ProposalAdd - connect(proposalAdd, SIGNAL(triggered()), this, SLOT(gotoProposalAddPage())); + connect(proposalAddAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -740,7 +739,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu* proposal = appMenuBar->addMenu(tr("&HTH Proposal")); - proposal->addAction(proposalAdd); + proposal->addAction(proposalAddAction); } @@ -929,6 +928,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); openAction->setEnabled(enabled); + proposalAddAction->setEnabled(enabled); } @@ -1071,7 +1071,7 @@ void BitcoinGUI::openClicked() void BitcoinGUI::gotoProposalAddPage() { - proposalAdd->setChecked(true); + //WebWindowAction->setChecked(true); if (walletFrame) walletFrame->gotoProposalAddPage(); } From c8dd9c5e85a2fbbdd5a7fc791c50f0b8be019a69 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:49:02 -0400 Subject: [PATCH 0592/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7b0f2df9..e691616e 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - proposalAddPage->setModel(walletModel); + /* proposalAddPage->setModel(walletModel); */ receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From 27ab2c0371c3be1a6a2768717c99cf981f604ed4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:52:09 -0400 Subject: [PATCH 0593/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index e691616e..109da980 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -162,7 +162,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); - //proposalAddPage->setClientModel(clientModel); + proposalAddPage->setClientModel(clientModel); } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - /* proposalAddPage->setModel(walletModel); */ + proposalAddPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From f58d422fbceaa7615b5b8a9d5c69a1ed4953601e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:53:47 -0400 Subject: [PATCH 0594/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 109da980..01833772 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -162,7 +162,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); - proposalAddPage->setClientModel(clientModel); + /*proposalAddPage->setClientModel(clientModel);*/ } void WalletView::setWalletModel(WalletModel *_walletModel) From 0abef8d78f67126961391255e7a93c9fd1fadb2a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:57:31 -0400 Subject: [PATCH 0595/1324] Update walletview.h --- src/qt/walletview.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index e6535918..41dc5086 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,6 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" +#include "proposaladddialog.h" #include From 23c35a3053c1d09dd3cc2c307eb7ce04f605266d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:01:20 -0400 Subject: [PATCH 0596/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 01833772..fb613859 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - proposalAddPage->setModel(walletModel); + /*proposalAddPage->setModel(walletModel); */ receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From 3967742b617d3d6cbb72e6eb230614a1bf42cbdc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:02:00 -0400 Subject: [PATCH 0597/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index fb613859..01833772 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -178,7 +178,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - /*proposalAddPage->setModel(walletModel); */ + proposalAddPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From 5fc9859d06e57e9c0db59d565df7babc0f7593db Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:05:58 -0400 Subject: [PATCH 0598/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 01833772..d66e6d3b 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -116,7 +116,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from EncryptDecryptPage - connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + /* connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); */ // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); From 28577daaf2a0ad1f15ef797c57246b9d539d1c06 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:07:04 -0400 Subject: [PATCH 0599/1324] Update walletview.cpp --- src/qt/walletview.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d66e6d3b..acf506fb 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -116,7 +116,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from EncryptDecryptPage - /* connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); */ + connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); @@ -173,12 +173,13 @@ void WalletView::setWalletModel(WalletModel *_walletModel) transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); + proposalAddPage->setWalletModel(_walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - proposalAddPage->setModel(walletModel); + /* proposalAddPage->setModel(walletModel); */ receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From df4e92991d399fdb1b7dbee49eb45585ab7bab42 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:08:30 -0400 Subject: [PATCH 0600/1324] Update walletview.cpp --- src/qt/walletview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index acf506fb..0c741b14 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -173,13 +173,12 @@ void WalletView::setWalletModel(WalletModel *_walletModel) transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); - proposalAddPage->setWalletModel(_walletModel); + proposalAddPage->setModel(_walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } governanceListPage->setWalletModel(_walletModel); - /* proposalAddPage->setModel(walletModel); */ receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From e819f257d408ce8e3b97a223fa98fc0f8ef8ad90 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:10:51 -0400 Subject: [PATCH 0601/1324] Update and rename proposaladddialog.cpp to proposaladd.cpp --- .../{proposaladddialog.cpp => proposaladd.cpp} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/qt/{proposaladddialog.cpp => proposaladd.cpp} (93%) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladd.cpp similarity index 93% rename from src/qt/proposaladddialog.cpp rename to src/qt/proposaladd.cpp index a3644743..280d8f1e 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladd.cpp @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "proposaladddialog.h" -#include "ui_proposaladddialog.h" +#include "proposaladd.h" +#include "ui_proposaladd.h" #include "addressbookpage.h" #include "addresstablemodel.h" #include "bitcoinunits.h" @@ -29,9 +29,9 @@ #include #include -ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : +ProposalAdd::ProposalAdd(const PlatformStyle *platformStyle, QWidget *parent) : QDialog(parent), - ui(new Ui::ProposalAddDialog), + ui(new Ui::ProposalAdd), model(0), platformStyle(platformStyle) { @@ -53,7 +53,7 @@ ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget } -void ProposalAddDialog::UpdateDisplay() +void ProposalAdd::UpdateDisplay() { int nNextHeight = GetNextSuperblock(); @@ -72,7 +72,7 @@ void ProposalAddDialog::UpdateDisplay() } -void ProposalAddDialog::setModel(WalletModel *model) +void ProposalAdd::setModel(WalletModel *model) { this->model = model; @@ -82,12 +82,12 @@ void ProposalAddDialog::setModel(WalletModel *model) } } -ProposalAddDialog::~ProposalAddDialog() +ProposalAdd::~ProposalAdd() { delete ui; } -void ProposalAddDialog::clear() +void ProposalAdd::clear() { ui->txtName->setText(""); ui->txtURL->setText(""); @@ -96,7 +96,7 @@ void ProposalAddDialog::clear() } -void ProposalAddDialog::on_btnSubmit_clicked() +void ProposalAdd::on_btnSubmit_clicked() { if(!model || !model->getOptionsModel()) return; From 46c13a79627d5ede4a7e44a233582de3707e72a5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:11:22 -0400 Subject: [PATCH 0602/1324] Update proposaladddialog.h --- src/qt/proposaladddialog.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/proposaladddialog.h b/src/qt/proposaladddialog.h index 56679642..3c059ca9 100644 --- a/src/qt/proposaladddialog.h +++ b/src/qt/proposaladddialog.h @@ -20,7 +20,7 @@ class PlatformStyle; class WalletModel; namespace Ui { - class ProposalAddDialog; + class ProposalAdd; } QT_BEGIN_NAMESPACE @@ -28,7 +28,7 @@ class QModelIndex; QT_END_NAMESPACE /** Dialog for Adding a Governance Proposal */ -class ProposalAddDialog : public QDialog +class ProposalAdd : public QDialog { Q_OBJECT @@ -40,8 +40,8 @@ class ProposalAddDialog : public QDialog MINIMUM_COLUMN_WIDTH = 130 }; - explicit ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ProposalAddDialog(); + explicit ProposalAdd(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ProposalAdd(); void setModel(WalletModel *model); void UpdateDisplay(); @@ -53,7 +53,7 @@ public Q_SLOTS: private: - Ui::ProposalAddDialog *ui; + Ui::ProposalAdd *ui; GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; WalletModel *model; QMenu *contextMenu; From aae597de0d92f58cef00994819e10eba5e3adaa3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:12:31 -0400 Subject: [PATCH 0603/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 1d855616..bb8638cb 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "proposaladddialog.h" +#include "proposaladd.h" /* #include "tradingdialogpage.h" */ From 04833ed5005c6b0f613f176523ca116854fc29eb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:32:14 -0400 Subject: [PATCH 0604/1324] Rename proposaladddialog.h to proposaladd.h --- src/qt/{proposaladddialog.h => proposaladd.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{proposaladddialog.h => proposaladd.h} (100%) diff --git a/src/qt/proposaladddialog.h b/src/qt/proposaladd.h similarity index 100% rename from src/qt/proposaladddialog.h rename to src/qt/proposaladd.h From c5c061d2a0dbecff1a3d07223ccf34523895be60 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:33:28 -0400 Subject: [PATCH 0605/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 0c741b14..46e1ef9d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "proposaladddialog.h" +#include "proposaladd.h" #include "ui_interface.h" @@ -74,7 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - proposalAddPage = new ProposalAddDialog(platformStyle); + proposalAddPage = new ProposalAdd(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); From b5bbc9003c478763e343d3d12695b07ae84325f2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:33:56 -0400 Subject: [PATCH 0606/1324] Update walletview.h --- src/qt/walletview.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 41dc5086..c4d6b9ca 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "proposaladddialog.h" +#include "proposaladd.h" #include @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class ProposalAddDialog; +class ProposalAdd; @@ -76,7 +76,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - ProposalAddDialog *proposalAddPage; + ProposalAdd *proposalAddPage; TransactionView *transactionView; From 221727b8f11d6a6c72f36d63076ff9e6718e1e87 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:34:25 -0400 Subject: [PATCH 0607/1324] Update and rename proposaladddialog.ui to proposaladd.ui --- src/qt/forms/{proposaladddialog.ui => proposaladd.ui} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/qt/forms/{proposaladddialog.ui => proposaladd.ui} (99%) diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/proposaladd.ui similarity index 99% rename from src/qt/forms/proposaladddialog.ui rename to src/qt/forms/proposaladd.ui index 00a19b44..ba4db768 100644 --- a/src/qt/forms/proposaladddialog.ui +++ b/src/qt/forms/proposaladd.ui @@ -1,7 +1,7 @@ - ProposalAddDialog - + ProposalAdd + 0 From 82341911ddb91bea2f36a53c18deb238489be7ed Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:35:13 -0400 Subject: [PATCH 0608/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 4c24ea3b..b9ed8e5e 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/proposaladddialog.ui + qt/forms/proposaladd.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -110,7 +110,7 @@ QT_MOC_CPP = \ moc_rpcpog.cpp \ moc_smartcontract-server.cpp \ moc_smartcontract-client.cpp \ - qt/moc_proposaladddialog.cpp + qt/moc_proposaladd.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -198,7 +198,7 @@ BITCOIN_QT_H = \ rpcpog.h \ smartcontract-server.h \ smartcontract-client.h \ - qt/proposaladddialog.h + qt/proposaladd.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -541,7 +541,7 @@ BITCOIN_QT_WALLET_CPP = \ rpcpog.cpp \ smartcontract-server.cpp \ smartcontract-client.cpp \ - qt/proposaladddialog.cpp + qt/proposaladd.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From d304419d76c420feb72a23847554c610496955f2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:38:50 -0400 Subject: [PATCH 0609/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 46e1ef9d..14977e40 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -173,7 +173,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); - proposalAddPage->setModel(_walletModel); + /*proposalAddPage->setModel(_walletModel); */ QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); From 4532412c8e13b0223f0af996f1ef27221b78c4e1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:42:45 -0400 Subject: [PATCH 0610/1324] Update walletview.cpp --- src/qt/walletview.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 14977e40..49f88e25 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -74,7 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - proposalAddPage = new ProposalAdd(platformStyle); + usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); @@ -84,7 +84,9 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); - addWidget(proposalAddPage); + + proposalPage = new ProposalPage(); + addWidget(proposalPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -115,9 +117,6 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from sendCoinsPage connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - // Pass through messages from EncryptDecryptPage - connect(proposalAddPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); } @@ -162,7 +161,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); - /*proposalAddPage->setClientModel(clientModel);*/ + } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -173,7 +172,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel) transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); - /*proposalAddPage->setModel(_walletModel); */ QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); @@ -240,8 +238,8 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoProposalAddPage() { - setCurrentWidget(proposalAddPage); -} + setCurrentWidget(proposalPage); +} void WalletView::gotoGovernancePage() From a9d1128c70b96a41d5dc1e54bf803ce76d9bdc43 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:44:08 -0400 Subject: [PATCH 0611/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index c4d6b9ca..4e637fa4 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class ProposalAdd; +class ProposalPage; @@ -76,7 +76,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - ProposalAdd *proposalAddPage; + ProposalPage *proposalPage; TransactionView *transactionView; From 47e05fee519f508ea0edb7e61a1e248377674383 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:44:36 -0400 Subject: [PATCH 0612/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 49f88e25..e73bb7d8 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "proposaladd.h" +#include "proposalpage.h" #include "ui_interface.h" From 9a310dd8893bf0a80c93d1be0dd6460b100db444 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:46:56 -0400 Subject: [PATCH 0613/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 7b4cb172..7337444c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,6 +39,7 @@ class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; /*class tradingDialogPage; */ +class ProposalPage; class CWallet; @@ -104,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction *proposalAddAction; + QAction *proposalPage; QAction* externalDonate; QAction *governanceAction; /* QAction *tradingAction; */ From 4ac170ac3743f9a9225b3f638f70b3dd31fb911f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:50:36 -0400 Subject: [PATCH 0614/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index bb8638cb..88c64f79 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "proposaladd.h" +#include "proposalpage.h" /* #include "tradingdialogpage.h" */ @@ -144,7 +144,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * governanceAction(0), /* tradingAction(0), */ externalDonate(0), - proposalAddAction(0), + proposalPage(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -620,8 +620,9 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - proposalAddAction = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Add Proposal"), this); - proposalAddAction->setStatusTip(tr("Submit proposal")); + // HTH Submit Proposal + proposalPage = new QAction(QIcon(":/icons/" + theme + "/about"), tr("HTH Proposals"), this); + proposalPage->setStatusTip(tr("Submit a Proposal Today")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -636,7 +637,7 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW ProposalAdd - connect(proposalAddAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); + connect(proposalPage, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -738,8 +739,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* proposal = appMenuBar->addMenu(tr("&HTH Proposal")); - proposal->addAction(proposalAddAction); + QMenu* proposal = appMenuBar->addMenu(tr("&HTH Proposals")); + proposal->addAction(proposalPage); } @@ -927,8 +928,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) verifyMessageAction->setEnabled(enabled); usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); - openAction->setEnabled(enabled); - proposalAddAction->setEnabled(enabled); + openAction->setEnabled(enabled); } From b83fd9b67c9e5bf0d26499608241f384256cef5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:51:43 -0400 Subject: [PATCH 0615/1324] Update and rename proposaladd.cpp to proposalpage.cpp --- src/qt/{proposaladd.cpp => proposalpage.cpp} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/qt/{proposaladd.cpp => proposalpage.cpp} (94%) diff --git a/src/qt/proposaladd.cpp b/src/qt/proposalpage.cpp similarity index 94% rename from src/qt/proposaladd.cpp rename to src/qt/proposalpage.cpp index 280d8f1e..6fe47c8b 100644 --- a/src/qt/proposaladd.cpp +++ b/src/qt/proposalpage.cpp @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "proposaladd.h" -#include "ui_proposaladd.h" +#include "proposalpage.h" +#include "ui_proposalpage.h" #include "addressbookpage.h" #include "addresstablemodel.h" #include "bitcoinunits.h" @@ -29,9 +29,9 @@ #include #include -ProposalAdd::ProposalAdd(const PlatformStyle *platformStyle, QWidget *parent) : +ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) : QDialog(parent), - ui(new Ui::ProposalAdd), + ui(new Ui::ProposalPage), model(0), platformStyle(platformStyle) { @@ -53,7 +53,7 @@ ProposalAdd::ProposalAdd(const PlatformStyle *platformStyle, QWidget *parent) : } -void ProposalAdd::UpdateDisplay() +void ProposalPage::UpdateDisplay() { int nNextHeight = GetNextSuperblock(); @@ -72,7 +72,7 @@ void ProposalAdd::UpdateDisplay() } -void ProposalAdd::setModel(WalletModel *model) +void ProposalPage::setModel(WalletModel *model) { this->model = model; @@ -82,12 +82,12 @@ void ProposalAdd::setModel(WalletModel *model) } } -ProposalAdd::~ProposalAdd() +ProposalPage::~ProposalPage() { delete ui; } -void ProposalAdd::clear() +void ProposalPage::clear() { ui->txtName->setText(""); ui->txtURL->setText(""); @@ -96,7 +96,7 @@ void ProposalAdd::clear() } -void ProposalAdd::on_btnSubmit_clicked() +void ProposalPage::on_btnSubmit_clicked() { if(!model || !model->getOptionsModel()) return; From f63b314ff67d437ff526e599b831b13f2037d964 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:52:11 -0400 Subject: [PATCH 0616/1324] Update and rename proposaladd.h to proposalpage.h --- src/qt/{proposaladd.h => proposalpage.h} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename src/qt/{proposaladd.h => proposalpage.h} (86%) diff --git a/src/qt/proposaladd.h b/src/qt/proposalpage.h similarity index 86% rename from src/qt/proposaladd.h rename to src/qt/proposalpage.h index 3c059ca9..f6bee5ff 100644 --- a/src/qt/proposaladd.h +++ b/src/qt/proposalpage.h @@ -20,7 +20,7 @@ class PlatformStyle; class WalletModel; namespace Ui { - class ProposalAdd; + class ProposalPage; } QT_BEGIN_NAMESPACE @@ -28,7 +28,7 @@ class QModelIndex; QT_END_NAMESPACE /** Dialog for Adding a Governance Proposal */ -class ProposalAdd : public QDialog +class ProposalPage : public QDialog { Q_OBJECT @@ -40,8 +40,8 @@ class ProposalAdd : public QDialog MINIMUM_COLUMN_WIDTH = 130 }; - explicit ProposalAdd(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ProposalAdd(); + explicit ProposalPage(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ProposalPage(); void setModel(WalletModel *model); void UpdateDisplay(); @@ -53,7 +53,7 @@ public Q_SLOTS: private: - Ui::ProposalAdd *ui; + Ui::ProposalPage *ui; GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; WalletModel *model; QMenu *contextMenu; From 4e284b75de728660ac07d4bcdb9d9125a1558d58 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:52:30 -0400 Subject: [PATCH 0617/1324] Update and rename proposaladd.ui to proposalpage.ui --- src/qt/forms/{proposaladd.ui => proposalpage.ui} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/qt/forms/{proposaladd.ui => proposalpage.ui} (99%) diff --git a/src/qt/forms/proposaladd.ui b/src/qt/forms/proposalpage.ui similarity index 99% rename from src/qt/forms/proposaladd.ui rename to src/qt/forms/proposalpage.ui index ba4db768..c9fafeb5 100644 --- a/src/qt/forms/proposaladd.ui +++ b/src/qt/forms/proposalpage.ui @@ -1,7 +1,7 @@ - ProposalAdd - + ProposalPage + 0 From 42af4dbc5a3c672d24c3de80f679d3dc51d3c991 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:53:13 -0400 Subject: [PATCH 0618/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index b9ed8e5e..8ddcda60 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/proposaladd.ui + qt/forms/proposalpage.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -110,7 +110,7 @@ QT_MOC_CPP = \ moc_rpcpog.cpp \ moc_smartcontract-server.cpp \ moc_smartcontract-client.cpp \ - qt/moc_proposaladd.cpp + qt/moc_proposalpage.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -198,7 +198,7 @@ BITCOIN_QT_H = \ rpcpog.h \ smartcontract-server.h \ smartcontract-client.h \ - qt/proposaladd.h + qt/proposalpage.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -541,7 +541,7 @@ BITCOIN_QT_WALLET_CPP = \ rpcpog.cpp \ smartcontract-server.cpp \ smartcontract-client.cpp \ - qt/proposaladd.cpp + qt/proposalpage.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 223ad788149a67471687bebd39296b6b30c61d2e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:54:05 -0400 Subject: [PATCH 0619/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 4e637fa4..2145f56b 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "proposaladd.h" +#include "proposalpage.h" #include From d9a8909e38c8ab364dfe62697baa835190aabd3d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:57:55 -0400 Subject: [PATCH 0620/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index e73bb7d8..65e70bb6 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,7 +85,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - proposalPage = new ProposalPage(); + proposalPage = new ProposalPage(platformStyle); addWidget(proposalPage); QSettings settings; From 0c9cfaacf0d119b45c07ad4e7e0372511c12f16b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:03:24 -0400 Subject: [PATCH 0621/1324] Update proposalpage.cpp --- src/qt/proposalpage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/proposalpage.cpp b/src/qt/proposalpage.cpp index 6fe47c8b..a9f74714 100644 --- a/src/qt/proposalpage.cpp +++ b/src/qt/proposalpage.cpp @@ -29,11 +29,11 @@ #include #include -ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) : +ProposalPage::ProposalPage(/*const PlatformStyle *platformStyle, */ QWidget *parent) : QDialog(parent), ui(new Ui::ProposalPage), model(0), - platformStyle(platformStyle) + /* platformStyle(platformStyle) */ { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 668aea8c43719653961145e559c8bd6e08a96ff9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:03:57 -0400 Subject: [PATCH 0622/1324] Update proposalpage.h --- src/qt/proposalpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/proposalpage.h b/src/qt/proposalpage.h index f6bee5ff..601462f6 100644 --- a/src/qt/proposalpage.h +++ b/src/qt/proposalpage.h @@ -40,7 +40,7 @@ class ProposalPage : public QDialog MINIMUM_COLUMN_WIDTH = 130 }; - explicit ProposalPage(const PlatformStyle *platformStyle, QWidget *parent = 0); + explicit ProposalPage(/*const PlatformStyle *platformStyle, */ QWidget *parent = 0); ~ProposalPage(); void setModel(WalletModel *model); From a832e3dcbebec05a0d166d9d561ec19252c8a099 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:04:37 -0400 Subject: [PATCH 0623/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 65e70bb6..e73bb7d8 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,7 +85,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - proposalPage = new ProposalPage(platformStyle); + proposalPage = new ProposalPage(); addWidget(proposalPage); QSettings settings; From 42331d6b618ab07942732e34f7a9c8b1e2068046 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:10:28 -0400 Subject: [PATCH 0624/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 52 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 88c64f79..814c3e2b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -142,9 +142,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * prevBlocks(0), spinnerFrame(0), governanceAction(0), - /* tradingAction(0), */ + proposalAction(0), externalDonate(0), - proposalPage(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -499,21 +498,21 @@ void BitcoinGUI::createActions() connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); } - /* { - tradingAction = new QAction(QIcon(":/icons/chat"), tr("&Trading"), this); - tradingAction->setStatusTip(tr("Trade HTH Today")); - tradingAction->setToolTip(tradingAction->statusTip()); - tradingAction->setCheckable(true); + { + proposalAction = new QAction(QIcon(":/icons/about"), tr("&Proposal"), this); + proposalAction->setStatusTip(tr("Submit A Proposal")); + proposalAction->setToolTip(proposalAction->statusTip()); + proposalAction->setCheckable(true); #ifdef Q_OS_MAC - tradingAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); + proposalAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); #else - tradingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); + proposalAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif tabGroup->addAction(tradingAction); - connect(tradingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(tradingAction, SIGNAL(triggered()), this, SLOT(gotoTradingDialogPage())); + connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalPage())); - } */ + } /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -620,10 +619,6 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - // HTH Submit Proposal - proposalPage = new QAction(QIcon(":/icons/" + theme + "/about"), tr("HTH Proposals"), this); - proposalPage->setStatusTip(tr("Submit a Proposal Today")); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); @@ -636,9 +631,6 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); - // HTHW ProposalAdd - connect(proposalPage, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); - // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -738,9 +730,6 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - - QMenu* proposal = appMenuBar->addMenu(tr("&HTH Proposals")); - proposal->addAction(proposalPage); } @@ -766,8 +755,8 @@ void BitcoinGUI::createToolBars() toolbar->addAction(governanceAction); toolbar->addAction(unlockWalletAction); - /* toolbar->addAction(tradingAction); - toolbar->addAction(unlockWalletAction); */ + toolbar->addAction(proposalAction); + toolbar->addAction(unlockWalletAction); toolbar->setMovable(false); // remove unused icon in upper left corner overviewAction->setChecked(true); @@ -919,7 +908,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } - /*tradingAction->setEnabled(enabled); */ + proposalAction->setEnabled(enabled); governanceAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); @@ -1069,17 +1058,12 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoProposalAddPage() -{ - //WebWindowAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalAddPage(); -} -/*void BitcoinGUI::gotoTradingDialogPage() +void BitcoinGUI::gotoProposalPage() { - tradingAction->setChecked(true); - if (walletFrame) walletFrame->gotoTradingDialogPage(); -} */ + proposalAction->setChecked(true); + if (walletFrame) walletFrame->gotoProposalPage(); +} void BitcoinGUI::openDonate() { From 801bdf3b1894346401f2a0b2643cb4344ad5ee95 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:12:24 -0400 Subject: [PATCH 0625/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 7337444c..f578a5a5 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -38,8 +38,6 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -/*class tradingDialogPage; */ -class ProposalPage; class CWallet; @@ -105,10 +103,10 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction *proposalPage; + QAction* externalDonate; QAction *governanceAction; - /* QAction *tradingAction; */ + QAction *proposalAction; /* QAction* privatesendAction; */ QAction *overviewAction; QAction *historyAction; From 773debc171ea640a31bba702db436c75262c7091 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:14:52 -0400 Subject: [PATCH 0626/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index e73bb7d8..23814837 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -161,6 +161,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); + proposalPage->setClientModel(_clientModel); } @@ -176,6 +177,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } + proposalPage->setWalletModel(_walletModel); governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); From 58318b1ad101bc45e41eed692a27b69fea3ff05b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:17:48 -0400 Subject: [PATCH 0627/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 23814837..e73bb7d8 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -161,7 +161,6 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); - proposalPage->setClientModel(_clientModel); } @@ -177,7 +176,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - proposalPage->setWalletModel(_walletModel); governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); From 801b1e7798ffb2e034eac66e45acb461a6805239 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:21:17 -0400 Subject: [PATCH 0628/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 814c3e2b..51b62bfd 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -508,7 +508,7 @@ void BitcoinGUI::createActions() #else proposalAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif - tabGroup->addAction(tradingAction); + tabGroup->addAction(proposalAction); connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalPage())); From d58cbb131858446eb44fc289d7053c71f0127d3d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:23:33 -0400 Subject: [PATCH 0629/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index f578a5a5..9c8c639a 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -233,7 +233,7 @@ private Q_SLOTS: #ifdef ENABLE_WALLET /** Switch to add proposal page */ - void gotoProposalAddPage(); + void gotoProposalPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 8ebe312e7537e3151860bb97906ac50304fa120b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:23:52 -0400 Subject: [PATCH 0630/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 38b4eebf..d23b56e2 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,11 +108,11 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoProposalAddPage() +void WalletFrame::gotoProposalPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalAddPage(); + i.value()->gotoProposalPage(); } void WalletFrame::gotoGovernancePage() From 1b4466b3aade2642b0981a0118d2f59719a5d28b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:24:07 -0400 Subject: [PATCH 0631/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index bf9d166d..607c182b 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + void gotoProposalPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From bb1170d4e48f003d1ac61046d4ddb65eca2d7db7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:24:26 -0400 Subject: [PATCH 0632/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index e73bb7d8..b31ac8ba 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -236,7 +236,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoProposalAddPage() +void WalletView::gotoProposalPage() { setCurrentWidget(proposalPage); } From 52a1145ef2ac84fb295f70b2411a89a39396795b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:24:43 -0400 Subject: [PATCH 0633/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 2145f56b..c9479983 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -87,7 +87,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + void gotoProposalPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From a73c396167cdca321819574a48fde322445fb030 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:46:56 -0400 Subject: [PATCH 0634/1324] Update proposalpage.h --- src/qt/proposalpage.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/proposalpage.h b/src/qt/proposalpage.h index 601462f6..fa6e8534 100644 --- a/src/qt/proposalpage.h +++ b/src/qt/proposalpage.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_QT_PROPOSALADDDIALOG_H -#define BITCOIN_QT_PROPOSALADDDIALOG_H +#ifndef BITCOIN_QT_PROPOSALPAGE_H +#define BITCOIN_QT_PROPOSALPAGE_H #include "guiutil.h" @@ -63,4 +63,4 @@ private Q_SLOTS: void on_btnSubmit_clicked(); }; -#endif // BITCOIN_QT_PROPOSALADDDIALOG_H +#endif // BITCOIN_QT_PROPOSALPAGE_H From a8f1831956fd14d8c2d992a07a730bed94c3598e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:48:20 -0400 Subject: [PATCH 0635/1324] Update proposalpage.cpp --- src/qt/proposalpage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/proposalpage.cpp b/src/qt/proposalpage.cpp index a9f74714..9fe1c03a 100644 --- a/src/qt/proposalpage.cpp +++ b/src/qt/proposalpage.cpp @@ -29,11 +29,11 @@ #include #include -ProposalPage::ProposalPage(/*const PlatformStyle *platformStyle, */ QWidget *parent) : +ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) : QDialog(parent), ui(new Ui::ProposalPage), model(0), - /* platformStyle(platformStyle) */ + platformStyle(platformStyle) { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 3f9117fa9bd6b289d3e7cbe00833df94cde706f0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:48:58 -0400 Subject: [PATCH 0636/1324] Update proposalpage.h --- src/qt/proposalpage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/proposalpage.h b/src/qt/proposalpage.h index fa6e8534..0186d45c 100644 --- a/src/qt/proposalpage.h +++ b/src/qt/proposalpage.h @@ -40,7 +40,7 @@ class ProposalPage : public QDialog MINIMUM_COLUMN_WIDTH = 130 }; - explicit ProposalPage(/*const PlatformStyle *platformStyle, */ QWidget *parent = 0); + explicit ProposalPage(const PlatformStyle *platformStyle, QWidget *parent = 0); ~ProposalPage(); void setModel(WalletModel *model); From 80a5c84f558c58cd51e8c7d76e132b91f0102806 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:49:40 -0400 Subject: [PATCH 0637/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index b31ac8ba..f6e5d17d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,7 +85,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - proposalPage = new ProposalPage(); + proposalPage = new ProposalPage(platformStyle); addWidget(proposalPage); QSettings settings; From 605b014a797b81178cdd1e6df6079147aae4acf5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:00:46 -0400 Subject: [PATCH 0638/1324] Update and rename proposalpage.h to proposaladddialog.h --- src/qt/{proposalpage.h => proposaladddialog.h} | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename src/qt/{proposalpage.h => proposaladddialog.h} (76%) diff --git a/src/qt/proposalpage.h b/src/qt/proposaladddialog.h similarity index 76% rename from src/qt/proposalpage.h rename to src/qt/proposaladddialog.h index 0186d45c..56679642 100644 --- a/src/qt/proposalpage.h +++ b/src/qt/proposaladddialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_QT_PROPOSALPAGE_H -#define BITCOIN_QT_PROPOSALPAGE_H +#ifndef BITCOIN_QT_PROPOSALADDDIALOG_H +#define BITCOIN_QT_PROPOSALADDDIALOG_H #include "guiutil.h" @@ -20,7 +20,7 @@ class PlatformStyle; class WalletModel; namespace Ui { - class ProposalPage; + class ProposalAddDialog; } QT_BEGIN_NAMESPACE @@ -28,7 +28,7 @@ class QModelIndex; QT_END_NAMESPACE /** Dialog for Adding a Governance Proposal */ -class ProposalPage : public QDialog +class ProposalAddDialog : public QDialog { Q_OBJECT @@ -40,8 +40,8 @@ class ProposalPage : public QDialog MINIMUM_COLUMN_WIDTH = 130 }; - explicit ProposalPage(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ProposalPage(); + explicit ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ProposalAddDialog(); void setModel(WalletModel *model); void UpdateDisplay(); @@ -53,7 +53,7 @@ public Q_SLOTS: private: - Ui::ProposalPage *ui; + Ui::ProposalAddDialog *ui; GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; WalletModel *model; QMenu *contextMenu; @@ -63,4 +63,4 @@ private Q_SLOTS: void on_btnSubmit_clicked(); }; -#endif // BITCOIN_QT_PROPOSALPAGE_H +#endif // BITCOIN_QT_PROPOSALADDDIALOG_H From 83158eafac73ce566de5fc83968cce8a7cf318d0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:01:14 -0400 Subject: [PATCH 0639/1324] Update and rename proposalpage.cpp to proposaladddialog.cpp --- ...proposalpage.cpp => proposaladddialog.cpp} | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename src/qt/{proposalpage.cpp => proposaladddialog.cpp} (92%) diff --git a/src/qt/proposalpage.cpp b/src/qt/proposaladddialog.cpp similarity index 92% rename from src/qt/proposalpage.cpp rename to src/qt/proposaladddialog.cpp index 9fe1c03a..fa1a5511 100644 --- a/src/qt/proposalpage.cpp +++ b/src/qt/proposaladddialog.cpp @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "proposalpage.h" -#include "ui_proposalpage.h" +#include "proposaladddialog.h" +#include "ui_proposaladddialog.h" #include "addressbookpage.h" #include "addresstablemodel.h" #include "bitcoinunits.h" @@ -29,9 +29,9 @@ #include #include -ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) : +ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : QDialog(parent), - ui(new Ui::ProposalPage), + ui(new Ui::ProposalAddDialog), model(0), platformStyle(platformStyle) { @@ -41,7 +41,7 @@ ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) if (!platformStyle->getImagesOnButtons()) { ui->btnSubmit->setIcon(QIcon()); } else { - ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/about")); + ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); } ui->cmbExpenseType->clear(); @@ -53,7 +53,7 @@ ProposalPage::ProposalPage(const PlatformStyle *platformStyle, QWidget *parent) } -void ProposalPage::UpdateDisplay() +void ProposalAddDialog::UpdateDisplay() { int nNextHeight = GetNextSuperblock(); @@ -72,7 +72,7 @@ void ProposalPage::UpdateDisplay() } -void ProposalPage::setModel(WalletModel *model) +void ProposalAddDialog::setModel(WalletModel *model) { this->model = model; @@ -82,12 +82,12 @@ void ProposalPage::setModel(WalletModel *model) } } -ProposalPage::~ProposalPage() +ProposalAddDialog::~ProposalAddDialog() { delete ui; } -void ProposalPage::clear() +void ProposalAddDialog::clear() { ui->txtName->setText(""); ui->txtURL->setText(""); @@ -96,7 +96,7 @@ void ProposalPage::clear() } -void ProposalPage::on_btnSubmit_clicked() +void ProposalAddDialog::on_btnSubmit_clicked() { if(!model || !model->getOptionsModel()) return; From 705980e60c9b37de9468a3a223756f2ecd644c40 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:03:27 -0400 Subject: [PATCH 0640/1324] Update and rename proposalpage.ui to proposaladddialog.ui --- src/qt/forms/{proposalpage.ui => proposaladddialog.ui} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/qt/forms/{proposalpage.ui => proposaladddialog.ui} (97%) diff --git a/src/qt/forms/proposalpage.ui b/src/qt/forms/proposaladddialog.ui similarity index 97% rename from src/qt/forms/proposalpage.ui rename to src/qt/forms/proposaladddialog.ui index c9fafeb5..1c2622c8 100644 --- a/src/qt/forms/proposalpage.ui +++ b/src/qt/forms/proposaladddialog.ui @@ -1,7 +1,7 @@ - ProposalPage - + ProposalAddDialog + 0 @@ -235,7 +235,7 @@
- <html><head/><body><p align="center"><span style=" font-size:12pt; font-style:italic;">IMG Governance System</span></p></body></html> + <html><head/><body><p align="center"><span style=" font-size:12pt; font-style:italic;">HTH Governance System</span></p></body></html> @@ -284,7 +284,7 @@ btnSubmit - + From 6a844673eda2abacf80a339ad57eb849b6ff0f60 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:05:13 -0400 Subject: [PATCH 0641/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 51b62bfd..ff43bbc4 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "proposalpage.h" +#include "proposaladddialog.h" /* #include "tradingdialogpage.h" */ @@ -510,7 +510,7 @@ void BitcoinGUI::createActions() #endif tabGroup->addAction(proposalAction); connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalPage())); + connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalAddPage())); } /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); @@ -1059,10 +1059,10 @@ void BitcoinGUI::openClicked() } -void BitcoinGUI::gotoProposalPage() +void BitcoinGUI::gotoProposalAddPage() { proposalAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalPage(); + if (walletFrame) walletFrame->gotoProposalAddPage(); } void BitcoinGUI::openDonate() From b4c82e963b8acb4446d9cf67f251dfc8f88e0eb4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:05:35 -0400 Subject: [PATCH 0642/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 9c8c639a..f578a5a5 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -233,7 +233,7 @@ private Q_SLOTS: #ifdef ENABLE_WALLET /** Switch to add proposal page */ - void gotoProposalPage(); + void gotoProposalAddPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 88465628158777fdf363c059a4cdeb2ca2cc07aa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:05:55 -0400 Subject: [PATCH 0643/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index d23b56e2..38b4eebf 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,11 +108,11 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoProposalPage() +void WalletFrame::gotoProposalAddPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalPage(); + i.value()->gotoProposalAddPage(); } void WalletFrame::gotoGovernancePage() From 33197005639bacdb81b8e8083b13d1ed6d6ced83 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:06:10 -0400 Subject: [PATCH 0644/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 607c182b..bf9d166d 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalPage(); + void gotoProposalAddPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 0dc786b1aa2f6e86830f4770aefe3f6489c51673 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:06:51 -0400 Subject: [PATCH 0645/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f6e5d17d..82bc474f 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "proposalpage.h" +#include "proposaladddialog.h" #include "ui_interface.h" @@ -236,7 +236,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoProposalPage() +void WalletView::gotoProposalAddPage() { setCurrentWidget(proposalPage); } From c12172be49dbe2b440fd22039c53a1cb03c3515e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:07:15 -0400 Subject: [PATCH 0646/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index c9479983..a483aa79 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "proposalpage.h" +#include "proposaladddialog.h" #include @@ -87,7 +87,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalPage(); + void gotoProposalAddPage(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 441aa09dab691e63a4412ca23d5bce05001ab0c0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:08:19 -0400 Subject: [PATCH 0647/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 8ddcda60..4c24ea3b 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/proposalpage.ui + qt/forms/proposaladddialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -110,7 +110,7 @@ QT_MOC_CPP = \ moc_rpcpog.cpp \ moc_smartcontract-server.cpp \ moc_smartcontract-client.cpp \ - qt/moc_proposalpage.cpp + qt/moc_proposaladddialog.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -198,7 +198,7 @@ BITCOIN_QT_H = \ rpcpog.h \ smartcontract-server.h \ smartcontract-client.h \ - qt/proposalpage.h + qt/proposaladddialog.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -541,7 +541,7 @@ BITCOIN_QT_WALLET_CPP = \ rpcpog.cpp \ smartcontract-server.cpp \ smartcontract-client.cpp \ - qt/proposalpage.cpp + qt/proposaladddialog.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 7391c9424e057d3984f052808a09e4b2e32e46be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:10:46 -0400 Subject: [PATCH 0648/1324] Update walletview.cpp --- src/qt/walletview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 82bc474f..0191fa6f 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,8 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - proposalPage = new ProposalPage(platformStyle); - addWidget(proposalPage); + proposalAddPage = new ProposalAddDialog(platformStyle); + addWidget(proposalAddPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -238,7 +238,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoProposalAddPage() { - setCurrentWidget(proposalPage); + setCurrentWidget(proposalAddPage); } From f71a69a51f4a0f7988bd5d909adf31a9b63bdd0a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:11:34 -0400 Subject: [PATCH 0649/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index a483aa79..46dac8ec 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class ProposalPage; +class ProposalAddPage; @@ -76,7 +76,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - ProposalPage *proposalPage; + ProposalAddPage *proposalAddPage; TransactionView *transactionView; From f2dc12c0afeb2b4273cd8dc908667dba3e7b6eb2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:12:47 -0400 Subject: [PATCH 0650/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 0191fa6f..858d9068 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,8 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - proposalAddPage = new ProposalAddDialog(platformStyle); - addWidget(proposalAddPage); + proposalAddDialog = new ProposalAddDialog(platformStyle); + addWidget(proposalAddDialog); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { From 9149d03b37c2ce45cf0c5dce81937cad6f709533 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:14:39 -0400 Subject: [PATCH 0651/1324] Update walletview.cpp --- src/qt/walletview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 858d9068..214fb389 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -176,6 +176,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } + proposalAddPage->setModel(walletModel); governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); From f7545d57b060baba9d93cb97a2fa852d75ac5718 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:15:46 -0400 Subject: [PATCH 0652/1324] Update walletview.h --- src/qt/walletview.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 46dac8ec..267b46b7 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class ProposalAddPage; +class ProposalAddDialog; @@ -76,7 +76,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - ProposalAddPage *proposalAddPage; + ProposalAddDialog *proposalAddDialog; TransactionView *transactionView; From e227b2eb5650c517d38633111bcaa5cddf7628fb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:16:31 -0400 Subject: [PATCH 0653/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 214fb389..30c0cf07 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -176,7 +176,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - proposalAddPage->setModel(walletModel); + proposalAddDialog->setModel(walletModel); governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); @@ -239,7 +239,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoProposalAddPage() { - setCurrentWidget(proposalAddPage); + setCurrentWidget(ProposalAddDialog); } From 54ba12c4cd218ea2a27bcd64dcc347a574b4e17e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:17:51 -0400 Subject: [PATCH 0654/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 30c0cf07..9054de1b 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -237,7 +237,7 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoProposalAddPage() +void WalletView::gotoProposalAddDialog() { setCurrentWidget(ProposalAddDialog); } From 253c5d2143a52b1d47356616c3b89d6251e5bef9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:18:14 -0400 Subject: [PATCH 0655/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 267b46b7..53c9bd00 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -87,7 +87,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + void gotoProposalAddDialog(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 6ee8f9b89b38ffb9b9040c7ee35b7425f3c018c9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:18:30 -0400 Subject: [PATCH 0656/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index bf9d166d..9ed86454 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -64,7 +64,7 @@ class WalletFrame : public QFrame public Q_SLOTS: /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + void gotoProposalAddDialog(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From d8b1e353fc27cc0e28dac11462f20b7199afb680 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:18:48 -0400 Subject: [PATCH 0657/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 38b4eebf..41cd87ba 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,11 +108,11 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoProposalAddPage() +void WalletFrame::gotoProposalAddDialog() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalAddPage(); + i.value()->gotoProposalAddDialog(); } void WalletFrame::gotoGovernancePage() From 3c65cfdde955336afb3ec2551c1cae3b296bd73a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:19:07 -0400 Subject: [PATCH 0658/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index f578a5a5..598c717a 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -233,7 +233,7 @@ private Q_SLOTS: #ifdef ENABLE_WALLET /** Switch to add proposal page */ - void gotoProposalAddPage(); + void gotoProposalAddDialog(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From ea06d0f31051ae24663ae87124a987fc3e272cf7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:19:40 -0400 Subject: [PATCH 0659/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index ff43bbc4..5cf70e71 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -510,7 +510,7 @@ void BitcoinGUI::createActions() #endif tabGroup->addAction(proposalAction); connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalAddPage())); + connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalAddDialog())); } /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); @@ -1059,10 +1059,10 @@ void BitcoinGUI::openClicked() } -void BitcoinGUI::gotoProposalAddPage() +void BitcoinGUI::gotoProposalAddDialog() { proposalAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalAddPage(); + if (walletFrame) walletFrame->gotoProposalAddDialog(); } void BitcoinGUI::openDonate() From a988accf986f74c8996c848772e3111b00f7e14a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:23:24 -0400 Subject: [PATCH 0660/1324] Update walletview.cpp --- src/qt/walletview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 9054de1b..f8069c43 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -239,8 +239,8 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int void WalletView::gotoProposalAddDialog() { - setCurrentWidget(ProposalAddDialog); -} + setCurrentWidget(proposalAddDialog); +} void WalletView::gotoGovernancePage() From e3fab1d7b68f2f2b09d1627f055f3a2bd60eee1c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:26:12 -0400 Subject: [PATCH 0661/1324] Update walletview.cpp --- src/qt/walletview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f8069c43..243a8659 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -34,6 +34,7 @@ #include #include #include +#include WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): QStackedWidget(parent), From 9347b1cd66e3e78137d108d56cc392961c777e2a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:27:02 -0400 Subject: [PATCH 0662/1324] Update proposaladddialog.ui --- src/qt/forms/proposaladddialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/proposaladddialog.ui index 1c2622c8..a40b4398 100644 --- a/src/qt/forms/proposaladddialog.ui +++ b/src/qt/forms/proposaladddialog.ui @@ -284,7 +284,7 @@ btnSubmit - + From 9fd17076e0dae2b4f20c86f2b7579a16897641ff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:27:39 -0400 Subject: [PATCH 0663/1324] Update proposaladddialog.ui --- src/qt/forms/proposaladddialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/proposaladddialog.ui index a40b4398..1c2622c8 100644 --- a/src/qt/forms/proposaladddialog.ui +++ b/src/qt/forms/proposaladddialog.ui @@ -284,7 +284,7 @@ btnSubmit - + From dbc30f49eb3ffceca8b51107863e450995c58240 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:29:26 -0400 Subject: [PATCH 0664/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index fa1a5511..a3644743 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -41,7 +41,7 @@ ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget if (!platformStyle->getImagesOnButtons()) { ui->btnSubmit->setIcon(QIcon()); } else { - ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); + ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/about")); } ui->cmbExpenseType->clear(); From cbbefcc5f298ebf5d2c4f1c3dc2f2d44c6e33cac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:31:32 -0400 Subject: [PATCH 0665/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index a3644743..b6ef8335 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -30,10 +30,9 @@ #include ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : - QDialog(parent), - ui(new Ui::ProposalAddDialog), - model(0), - platformStyle(platformStyle) + ui(new Ui::ProposalAddDialog) +{ + ui->setupUi(this); { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 376d8b4cb22411d6e2c01d342398f5e162567ee9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:32:35 -0400 Subject: [PATCH 0666/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index b6ef8335..a3644743 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -30,9 +30,10 @@ #include ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : - ui(new Ui::ProposalAddDialog) -{ - ui->setupUi(this); + QDialog(parent), + ui(new Ui::ProposalAddDialog), + model(0), + platformStyle(platformStyle) { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 53dd98553f4eadcb204ce0091d14fc63ac03c51a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:33:13 -0400 Subject: [PATCH 0667/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 243a8659..52261160 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -177,7 +177,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - proposalAddDialog->setModel(walletModel); + /* proposalAddDialog->setModel(walletModel); */ governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); From bfdd18a09dba173d57c36653b6c7a50131cd7540 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:33:58 -0400 Subject: [PATCH 0668/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 52261160..d482e9d1 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -36,7 +36,7 @@ #include #include -WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): +WalletView::WalletView(/*const PlatformStyle *_platformStyle,*/ QWidget *parent): QStackedWidget(parent), clientModel(0), walletModel(0), From c1402eac865aaa22abc428f9ec2ad5ecc4e51892 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:35:20 -0400 Subject: [PATCH 0669/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index d482e9d1..52261160 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -36,7 +36,7 @@ #include #include -WalletView::WalletView(/*const PlatformStyle *_platformStyle,*/ QWidget *parent): +WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): QStackedWidget(parent), clientModel(0), walletModel(0), From ef9187af52911afc026727eee333245ce2f41f46 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:36:01 -0400 Subject: [PATCH 0670/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index a3644743..3a0908df 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -29,11 +29,11 @@ #include #include -ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : +ProposalAddDialog::ProposalAddDialog(/*const PlatformStyle *platformStyle,*/ QWidget *parent) : QDialog(parent), ui(new Ui::ProposalAddDialog), - model(0), - platformStyle(platformStyle) + /*model(0), + platformStyle(platformStyle) */ { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 196fa3b42e31f16cb6cb6afda5d66e5bd84ea856 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:36:32 -0400 Subject: [PATCH 0671/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index 3a0908df..df1497e0 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -29,11 +29,11 @@ #include #include -ProposalAddDialog::ProposalAddDialog(/*const PlatformStyle *platformStyle,*/ QWidget *parent) : +ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : QDialog(parent), ui(new Ui::ProposalAddDialog), - /*model(0), - platformStyle(platformStyle) */ + model(0), + platformStyle(platformStyle) { ui->setupUi(this); QString theme = GUIUtil::getThemeName(); From 720bf89ecb67972fb60d8e68cb0eb0ed7083aada Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:39:24 -0400 Subject: [PATCH 0672/1324] Rename proposaladddialog.ui to ProposalAddDialog.ui --- src/qt/forms/{proposaladddialog.ui => ProposalAddDialog.ui} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/forms/{proposaladddialog.ui => ProposalAddDialog.ui} (100%) diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/ProposalAddDialog.ui similarity index 100% rename from src/qt/forms/proposaladddialog.ui rename to src/qt/forms/ProposalAddDialog.ui From a5e0c62c67dea64ac8e637f8c7fa937594277d98 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 00:39:45 -0400 Subject: [PATCH 0673/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 4c24ea3b..dd0840b6 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/proposaladddialog.ui + qt/forms/ProposalAddDialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ From 91b75c74a79cc80425690b1299001ca4c5fcdf18 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:08:32 -0400 Subject: [PATCH 0674/1324] Rename ProposalAddDialog.ui to proposaladddialog.ui --- src/qt/forms/{ProposalAddDialog.ui => proposaladddialog.ui} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/forms/{ProposalAddDialog.ui => proposaladddialog.ui} (100%) diff --git a/src/qt/forms/ProposalAddDialog.ui b/src/qt/forms/proposaladddialog.ui similarity index 100% rename from src/qt/forms/ProposalAddDialog.ui rename to src/qt/forms/proposaladddialog.ui From 7a0b5591e8be1747923f6bb6dac5fae2e6c7a9f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:15:41 -0400 Subject: [PATCH 0675/1324] Add files via upload --- src/qt/proposals.cpp | 273 +++++++++++++++++++++++++++++++++++++++++++ src/qt/proposals.h | 59 ++++++++++ src/qt/secdialog.cpp | 90 ++++++++++++++ src/qt/secdialog.h | 34 ++++++ 4 files changed, 456 insertions(+) create mode 100644 src/qt/proposals.cpp create mode 100644 src/qt/proposals.h create mode 100644 src/qt/secdialog.cpp create mode 100644 src/qt/secdialog.h diff --git a/src/qt/proposals.cpp b/src/qt/proposals.cpp new file mode 100644 index 00000000..c46c9fe1 --- /dev/null +++ b/src/qt/proposals.cpp @@ -0,0 +1,273 @@ +#include "proposals.h" +#include "bitcoinunits.h" +#include "ui_proposals.h" +#include "secdialog.h" +#include "ui_secdialog.h" +#include "walletmodel.h" +#include "guiutil.h" +#include "rpcpog.h" +#include +#include +#include +#include + + +QStringList Proposals::GetHeaders() +{ + QStringList pHeaders; + pHeaders << tr("Proposal ID") + << tr("Proposal Name") + << tr("Amount") + << tr("Expense Type") + << tr("Created") + << tr("Yes Ct") + << tr("No Ct") + << tr("Abstain Ct") + << tr("Url"); + return pHeaders; +} + +Proposals::Proposals(const PlatformStyle *platformStyle, QWidget *parent) : + ui(new Ui::Proposals) +{ + ui->setupUi(this); + + /* Reserved - Use when we add buttons to this page + QString theme = GUIUtil::getThemeName(); + + if (!platformStyle->getImagesOnButtons()) + { + ui->btnSubmit->setIcon(QIcon()); + } else { + ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); + } + */ + UpdateDisplay(); +} + +/* Input String Format + 1,proposal name1,amount1,expensetype1,createtime1,yescount1,nocount1,abstaincount1,url1 +*/ + +Proposals::~Proposals() +{ + delete ui; +} + + +void Proposals::setModel(WalletModel *model) +{ + this->model = model; + + if(model && model->getOptionsModel()) + { + UpdateDisplay(); + } +} + + +void Proposals::UpdateDisplay() +{ + QString pString = GUIUtil::TOQS(GetActiveProposals()); + QStringList pHeaders = GetHeaders(); + this->createUI(pHeaders, pString); +} + + +void Proposals::createUI(const QStringList &headers, const QString &pStr) +{ + + ui->tableWidget->setShowGrid(true); + ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); + ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); + + QVector > pMatrix; + if (pStr == "") return; + + pMatrix = SplitData(pStr); + int rows = pMatrix.size(); + ui->tableWidget->setRowCount(rows); + int cols = pMatrix[0].size(); + if (cols > 9) cols = 9; //Limit to the URL column for now + ui->tableWidget->setColumnCount(cols); + ui->tableWidget->setHorizontalHeaderLabels(headers); + + QString s; + for(int i=0; itableWidget->setItem(i,j, new QTableWidgetItem(pMatrix[i][j])); + + ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->tableWidget->resizeRowsToContents(); + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); + // Column 0 width should be slimmer + ui->tableWidget->setColumnWidth(0, 115); + ui->tableWidget->setColumnWidth(1, 150); + ui->tableWidget->setColumnWidth(2, 80); //Amount + ui->tableWidget->setColumnWidth(3, 80); //Expense Type + ui->tableWidget->setColumnWidth(4, 100); //Created Date + ui->tableWidget->setColumnWidth(5, 50); + + ui->tableWidget->setColumnWidth(6, 50); + ui->tableWidget->setColumnWidth(7, 65); + ui->tableWidget->setColumnWidth(8, 120); + + ui->tableWidget->sortByColumn(4, Qt::AscendingOrder); + + // Connect SLOT to context menu + connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotCustomMenuRequested(QPoint))); +} + +void Proposals::slotCustomMenuRequested(QPoint pos) +{ + /* Create an object context menu */ + QMenu * menu = new QMenu(this); + // Create, Connect and Set the actions to the menu + menu->addAction(tr("Vote For"), this, SLOT(slotVoteFor())); + menu->addAction(tr("Vote Against"), this, SLOT(slotVoteAgainst())); + menu->addAction(tr("Vote Abstain"), this, SLOT(slotAbstainCount())); + menu->addAction(tr("Chart Proposal"), this, SLOT(slotChartProposal())); + menu->addAction(tr("View Proposal"), this, SLOT(slotViewProposal())); + menu->popup(ui->tableWidget->viewport()->mapToGlobal(pos)); +} + + +void Proposals::ProcessVote(std::string gobject, std::string signal, std::string outcome) +{ + std::string sError = ""; + int nSuccessful = 0; + int nFailed = 0; + VoteManyForGobject(gobject, signal, outcome, 0, nSuccessful, nFailed, sError); + std::string sVoteNarr = ""; + if (nSuccessful > 0) + { + sVoteNarr = "Voting was successful. Voted " + RoundToString(nSuccessful, 0) + " times, failed to vote " + RoundToString(nFailed, 0) + " time(s). "; + if (!sError.empty()) sVoteNarr += " [" + sError + "]"; + } + else + { + sVoteNarr = "Voting Failed! Failed to vote " + RoundToString(nFailed, 0) + " time(s). "; + if (sError.empty()) sVoteNarr += " (Note: You must wait 3 minutes in-between re-votes due to network rules. Please ensure your wallet is unlocked also. )"; + if (!sError.empty()) sVoteNarr += " [" + sError + "]"; + } + QMessageBox msgOutcome; + msgOutcome.setWindowTitle(tr("Voting Outcome")); + msgOutcome.setText(GUIUtil::TOQS(sVoteNarr)); + msgOutcome.setStandardButtons(QMessageBox::Ok); + msgOutcome.setDefaultButton(QMessageBox::Ok); + msgOutcome.exec(); + + // Refresh + + QString pString = GUIUtil::TOQS(GetActiveProposals()); + QStringList pHeaders = GetHeaders(); + this->createUI(pHeaders, pString); +} + +void Proposals::slotVoteAgainst() +{ + int row = ui->tableWidget->selectionModel()->currentIndex().row(); + if(row >= 0) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Proposal")); + msgBox.setText("Vote Against the Proposal?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (QMessageBox::Yes == msgBox.exec()) + { + std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); + ProcessVote(gobject, "funding", "no"); + } + } +} + +void Proposals::slotVoteFor() +{ + int row = ui->tableWidget->selectionModel()->currentIndex().row(); + if(row >= 0) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Proposal")); + msgBox.setText("Vote For the Proposal ?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (QMessageBox::Yes == msgBox.exec()) + { + std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); + ProcessVote(gobject, "funding", "yes"); + } + } +} + +void Proposals::slotAbstainCount() +{ + int row = ui->tableWidget->selectionModel()->currentIndex().row(); + if(row >= 0) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Proposal")); + msgBox.setText("Do you want to Abstain from voting?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (QMessageBox::Yes == msgBox.exec()) + { + std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); + ProcessVote(gobject, "funding", "abstain"); + } + } +} + + +void Proposals::slotChartProposal() +{ + int row = ui->tableWidget->selectionModel()->currentIndex().row(); + if(row >= 0) + { + int voteFor = ui->tableWidget->item(row,5)->text().toInt(); + int voteAgainst = ui->tableWidget->item(row,6)->text().toInt(); + int abstainCount = ui->tableWidget->item(row,7)->text().toInt(); + // int total = voteFor + voteAgainst + abstainCount; + SecDialog *secdialog = new SecDialog(this); + secdialog->setGraphPts(voteFor, voteAgainst, abstainCount); + secdialog->setWindowTitle(" "); + secdialog->exec(); + + } +} + +void Proposals::slotViewProposal() +{ + int row = ui->tableWidget->selectionModel()->currentIndex().row(); + if(row >= 0) + { + QString Url = ui->tableWidget->item(row,8)->text(); + QUrl pUrl(Url); + QDesktopServices::openUrl(pUrl); + } +} + +QVector > Proposals::SplitData(const QString &pStr) +{ + QStringList proposals = pStr.split(QRegExp(""),QString::SkipEmptyParts); + int nProposals = proposals.size(); + QVector > proposalMatrix; + for (int i=0; i()); + QStringList proposalDetail = proposals[i].split('|'); + int detailSize = proposalDetail.size(); + for (int j = 0; j < detailSize; j++) + { + QString sData = proposalDetail[j]; + if (j==2) + { + sData = BitcoinUnits::format(2, cdbl(GUIUtil::FROMQS(sData), 2) * 100, false, BitcoinUnits::separatorAlways); + } + proposalMatrix[i].append(sData); + } + } + return proposalMatrix; +} diff --git a/src/qt/proposals.h b/src/qt/proposals.h new file mode 100644 index 00000000..f1134f92 --- /dev/null +++ b/src/qt/proposals.h @@ -0,0 +1,59 @@ +#ifndef PROPOSALS_H +#define PROPOSALS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class OptionsModel; +class PlatformStyle; +class WalletModel; + + +namespace Ui { +class Proposals; +} + +QT_BEGIN_NAMESPACE +class QModelIndex; +QT_END_NAMESPACE + +class Proposals : public QWidget +{ + Q_OBJECT + +public: + explicit Proposals(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~Proposals(); + void setModel(WalletModel *model); + void UpdateDisplay(); + +private Q_SLOTS: + void slotVoteFor(); + void slotVoteAgainst(); + void slotAbstainCount(); + void slotChartProposal(); + void slotViewProposal(); + void slotCustomMenuRequested(QPoint pos); + +private: + Ui::Proposals *ui; + WalletModel *model; + +private: + void createUI(const QStringList &headers, const QString &pStr); + QVector > SplitData(const QString &pStr); + void ProcessVote(std::string gobject, std::string signal, std::string outcome); + QStringList GetHeaders(); + + +}; + +#endif // PROPOSALS_H diff --git a/src/qt/secdialog.cpp b/src/qt/secdialog.cpp new file mode 100644 index 00000000..ff798bee --- /dev/null +++ b/src/qt/secdialog.cpp @@ -0,0 +1,90 @@ +#include "secdialog.h" +#include "ui_secdialog.h" +#include "rpcpog.h" +#include "guiutil.h" + +SecDialog::SecDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SecDialog) +{ + ui->setupUi(this); +} + +void SecDialog::closeForm() +{ + this->close(); +} + +void SecDialog::getGraphPts(int &voteFor, int &voteAgainst, int &abstainCount) +{ + voteFor = this->forCount; + voteAgainst = this->againstCount; + abstainCount = this->absCount; +} + +void SecDialog::setGraphPts(int voteFor, int voteAgainst, int abstainCount) +{ + this->forCount = voteFor; + this->againstCount = voteAgainst; + this->absCount = abstainCount; +} + +SecDialog::~SecDialog() +{ + delete ui; +} + +void SecDialog::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + + QRectF rec(this->width() * 2/5, 10, this->width()/5, this->height()/30); + painter.drawRect(rec); + painter.drawText(rec, Qt::AlignCenter, "Voting Results"); + + QRectF size = QRectF(this->width()/5, this->width()/5, this->width()/4, this->width()/4); + int voteFor, voteAgainst, abstainCount; + getGraphPts(voteFor, voteAgainst, abstainCount); + int total = voteFor + voteAgainst + abstainCount; + connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(close())); + + if (total <= 0) return; + + int forSlice = qRound(360 * (double)voteFor/(double)total); + + int againstSlice = qRound(360 * (double)voteAgainst/(double)total); + + int abstainSlice = qRound(360 * (double)abstainCount/(double)total); + + painter.setBrush(Qt::darkGreen); + painter.drawPie(size, 0, forSlice*16); + + painter.setBrush(Qt::red); + painter.drawPie(size, forSlice*16, againstSlice*16); + + painter.setBrush(Qt::gray); + painter.drawPie(size, (forSlice+againstSlice)*16, abstainSlice*16); + + QTextDocument doc; + QRect legend (0, 0, this->width()/3, this->width()/3); + painter.translate(this->width()*3/5, this->width()/3.5); + doc.setTextWidth(legend.width()); + std::string s = ""; + if (voteFor) + { + s = "
Vote For Count: " + + RoundToString(100*(double)voteFor/(double)total, 2) + "%
"; + } + if (voteAgainst) + { + s += "
Vote Against Count: " + + RoundToString(100*(double)voteAgainst/(double)total, 2) + "%
"; + } + if (abstainCount) + { + s += "
Abstain Count: " + + RoundToString(100*(double)abstainCount/(double)total, 2) + "%
"; + } + doc.setHtml(GUIUtil::TOQS(s)); + doc.drawContents(&painter, legend); +} diff --git a/src/qt/secdialog.h b/src/qt/secdialog.h new file mode 100644 index 00000000..6b415ab3 --- /dev/null +++ b/src/qt/secdialog.h @@ -0,0 +1,34 @@ +#ifndef SECDIALOG_H + +#define SECDIALOG_H + +#include +#include +#include +#include + +namespace Ui { +class SecDialog; +} + +class SecDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SecDialog(QWidget *parent = 0); + void getGraphPts(int &voteFor, int &voteAgainst, int &abstainCount); + void setGraphPts(int voteFor=0, int voteAgainst=0, int abstainCount=0); + ~SecDialog(); + +protected: + void paintEvent(QPaintEvent *); + void closeForm(); + +private: + Ui::SecDialog *ui; + int forCount, againstCount, absCount; + +}; + +#endif // SECDIALOG_H From 6835a6ec1c5b29bf3eb7638c70048be717c96a75 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:16:15 -0400 Subject: [PATCH 0676/1324] Add files via upload --- src/qt/forms/proposals.ui | 47 +++++++++++++++++++++++++++++++++++++++ src/qt/forms/secdialog.ui | 35 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/qt/forms/proposals.ui create mode 100644 src/qt/forms/secdialog.ui diff --git a/src/qt/forms/proposals.ui b/src/qt/forms/proposals.ui new file mode 100644 index 00000000..60375aa6 --- /dev/null +++ b/src/qt/forms/proposals.ui @@ -0,0 +1,47 @@ + + + Proposals + + + + 0 + 0 + 710 + 410 + + + + + 0 + 0 + + + + Form + + + + + 9 + 0 + 700 + 400 + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOn + + + + + + diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui new file mode 100644 index 00000000..bfdb967e --- /dev/null +++ b/src/qt/forms/secdialog.ui @@ -0,0 +1,35 @@ + + + SecDialog + + + Qt::WindowModal + + + + 0 + 0 + 1010 + 639 + + + + Dialog + + + + + 420 + 610 + 75 + 23 + + + + Close + + + + + + From 7f49e17487d697b376c5e079edabeff18b547573 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:19:16 -0400 Subject: [PATCH 0677/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index dd0840b6..468e68ec 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,9 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/ProposalAddDialog.ui + qt/forms/proposaladddialog.ui \ + qt/forms/proposals.ui \ + qt/forms/secdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -110,7 +112,9 @@ QT_MOC_CPP = \ moc_rpcpog.cpp \ moc_smartcontract-server.cpp \ moc_smartcontract-client.cpp \ - qt/moc_proposaladddialog.cpp + qt/moc_proposaladddialog.cpp \ + qt/moc_proposals.cpp \ + qt/moc_secdialog.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -198,7 +202,9 @@ BITCOIN_QT_H = \ rpcpog.h \ smartcontract-server.h \ smartcontract-client.h \ - qt/proposaladddialog.h + qt/proposaladddialog.h \ + qt/proposals.h \ + qt/secdialog.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -541,7 +547,9 @@ BITCOIN_QT_WALLET_CPP = \ rpcpog.cpp \ smartcontract-server.cpp \ smartcontract-client.cpp \ - qt/proposaladddialog.cpp + qt/proposaladddialog.cpp \ + qt/proposals.cpp \ + qt/secdialog.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 8a77b2f9fcbad16a6825b2c74182d037177c09c1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:24:09 -0400 Subject: [PATCH 0678/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5cf70e71..2777c0ad 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -141,7 +141,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * modalOverlay(0), prevBlocks(0), spinnerFrame(0), - governanceAction(0), + proposalsListAction(0), proposalAction(0), externalDonate(0), platformStyle(_platformStyle) @@ -484,18 +484,18 @@ void BitcoinGUI::createActions() connect(masternodeAction, SIGNAL(triggered()), this, SLOT(gotoMasternodePage())); } { - governanceAction = new QAction(QIcon(":/icons/governance"), tr("&Governance"), this); - governanceAction->setStatusTip(tr("Show governance items")); - governanceAction->setToolTip(governanceAction->statusTip()); - governanceAction->setCheckable(true); + proposalsListAction = new QAction(QIcon(":/icons/governance"), tr("&Proposals"), this); + proposalsListAction->setStatusTip(tr("Show governance items")); + proposalsListAction->setToolTip(proposalsListAction->statusTip()); + proposalsListAction->setCheckable(true); #ifdef Q_OS_MAC - governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); + proposalsListAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); #else - governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); + proposalsListAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); #endif - tabGroup->addAction(governanceAction); - connect(governanceAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); + tabGroup->addAction(proposalsListAction); + connect(proposalsListAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(proposalsListAction, SIGNAL(triggered()), this, SLOT(gotoProposalsListPage())); } { @@ -908,8 +908,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } - proposalAction->setEnabled(enabled); - governanceAction->setEnabled(enabled); + proposalAction->setEnabled(enabled); + proposalsListAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); changePassphraseAction->setEnabled(enabled); @@ -1082,10 +1082,10 @@ void BitcoinGUI::openExternalURL(QString url) } } -void BitcoinGUI::gotoGovernancePage() +void BitcoinGUI::gotoProposalsListPage() { - governanceAction->setChecked(true); - if (walletFrame) walletFrame->gotoGovernancePage(); + proposalsListAction->setChecked(true); + if (walletFrame) walletFrame->proposalsListAction(); } /*void BitcoinGUI::gotoPrivateSendPage() From a62619d7b73ebbf21f2705f33b99a07caea1d22c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:24:51 -0400 Subject: [PATCH 0679/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 598c717a..bf1627e2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QAction* externalDonate; - QAction *governanceAction; + QAction *proposalsListAction; QAction *proposalAction; /* QAction* privatesendAction; */ QAction *overviewAction; @@ -233,7 +233,7 @@ private Q_SLOTS: #ifdef ENABLE_WALLET /** Switch to add proposal page */ - void gotoProposalAddDialog(); + void gotoProposalsListPage(); /** Switch to trading page */ /* void gotoTradingDialogPage(); */ /** Switch to governance page */ From 02b12ec967b96f6f7539dd78fff75d49c6d7bc8d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:25:16 -0400 Subject: [PATCH 0680/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 41cd87ba..e9094ab1 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -115,11 +115,11 @@ void WalletFrame::gotoProposalAddDialog() i.value()->gotoProposalAddDialog(); } -void WalletFrame::gotoGovernancePage() +void WalletFrame::gotoProposalsListPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoGovernancePage(); + i.value()->gotoProposalsListPage(); } void WalletFrame::gotoPrivateSendPage() From 8d5a80c52c2794fcf1a9959ce9dd083529c5116d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:25:32 -0400 Subject: [PATCH 0681/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 9ed86454..06ed7c60 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -66,7 +66,7 @@ public Q_SLOTS: /** Switch to ProposalAdd page */ void gotoProposalAddDialog(); /** Switch to governance page */ - void gotoGovernancePage(); + void gotoProposalsListPage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 58e36ee9032dba9c0ed726df116c76c26da6da54 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:30:26 -0400 Subject: [PATCH 0682/1324] Update walletview.cpp --- src/qt/walletview.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 52261160..dd585de3 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -75,6 +75,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); + proposalsPage = new Proposals(platformStyle); + proposalAddDialog = new ProposalAddDialog(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); @@ -85,18 +87,16 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); - - proposalAddDialog = new ProposalAddDialog(platformStyle); + addWidget(proposalsPage); addWidget(proposalAddDialog); + QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage = new MasternodeList(platformStyle); addWidget(masternodeListPage); } - governanceListPage = new GovernanceList(platformStyle); - addWidget(governanceListPage); - + // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo())); @@ -161,7 +161,6 @@ void WalletView::setClientModel(ClientModel *_clientModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); } - governanceListPage->setClientModel(_clientModel); } @@ -177,8 +176,8 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - /* proposalAddDialog->setModel(walletModel); */ - governanceListPage->setWalletModel(_walletModel); + proposalsPage->setModel(walletModel); + proposalAddDialog->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); @@ -244,10 +243,10 @@ void WalletView::gotoProposalAddDialog() } -void WalletView::gotoGovernancePage() +void WalletView::gotoProposalsListPage() { QSettings settings; - setCurrentWidget(governanceListPage); + setCurrentWidget(proposalsPage); } void WalletView::gotoPrivateSendPage() From 66d1dd941fbb53a6c38269f0fed2081148008433 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 01:31:28 -0400 Subject: [PATCH 0683/1324] Update walletview.h --- src/qt/walletview.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 53c9bd00..0c8af4cf 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -24,7 +24,7 @@ class TransactionView; class WalletModel; class AddressBookPage; class PrivateSendPage; -class GovernancePage; +class Proposals; class ProposalAddDialog; @@ -75,7 +75,7 @@ class WalletView : public QStackedWidget AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; - GovernanceList *governanceListPage; + Proposals *proposalsPage; ProposalAddDialog *proposalAddDialog; TransactionView *transactionView; @@ -89,7 +89,7 @@ public Q_SLOTS: /** Switch to ProposalAdd page */ void gotoProposalAddDialog(); /** Switch to governance page */ - void gotoGovernancePage(); + void gotoProposalsListPage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 0fefd35ee37ef2ccde1a82607a3ccefd0cc4c1ad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:40:39 -0400 Subject: [PATCH 0684/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 56 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2777c0ad..ab1a7d4f 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -142,7 +142,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * prevBlocks(0), spinnerFrame(0), proposalsListAction(0), - proposalAction(0), + proposalAddAction(0), externalDonate(0), platformStyle(_platformStyle) { @@ -483,22 +483,8 @@ void BitcoinGUI::createActions() connect(masternodeAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(masternodeAction, SIGNAL(triggered()), this, SLOT(gotoMasternodePage())); } - { - proposalsListAction = new QAction(QIcon(":/icons/governance"), tr("&Proposals"), this); - proposalsListAction->setStatusTip(tr("Show governance items")); - proposalsListAction->setToolTip(proposalsListAction->statusTip()); - proposalsListAction->setCheckable(true); -#ifdef Q_OS_MAC - proposalsListAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); -#else - proposalsListAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); -#endif - tabGroup->addAction(proposalsListAction); - connect(proposalsListAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(proposalsListAction, SIGNAL(triggered()), this, SLOT(gotoProposalsListPage())); - - } - { + + /* { proposalAction = new QAction(QIcon(":/icons/about"), tr("&Proposal"), this); proposalAction->setStatusTip(tr("Submit A Proposal")); proposalAction->setToolTip(proposalAction->statusTip()); @@ -512,7 +498,7 @@ void BitcoinGUI::createActions() connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalAddDialog())); - } + } */ /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -576,6 +562,11 @@ void BitcoinGUI::createActions() signMessageAction->setStatusTip(tr("Sign messages with your HelpTheHomeless addresses to prove you own them")); verifyMessageAction = new QAction(QIcon(":/icons/" + theme + "/transaction_0"), tr("&Verify message..."), this); verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified HelpTheHomeless addresses")); + + proposalAddAction = new QAction(QIcon(":/icons/" + theme + "/filesave"), tr("Add Proposal"), this); + proposalAddAction->setStatusTip(tr("Submit proposal")); + proposalsListAction = new QAction(QIcon(":/icons/" + theme + "/edit"), tr("&List Proposals"), this); + proposalsListAction->setStatusTip(tr("List all Proposal of Governance System")); openInfoAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&Information"), this); openInfoAction->setStatusTip(tr("Show diagnostic information")); @@ -618,6 +609,9 @@ void BitcoinGUI::createActions() // HTHW Donate externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); + + connect(proposalAddAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); + connect(proposalsListAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalsListPage())); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -718,6 +712,10 @@ void BitcoinGUI::createMenuBar() tools->addSeparator(); tools->addAction(openConfEditorAction); tools->addAction(showBackupsAction); + + QMenu *proposal = appMenuBar->addMenu(tr("&Proposals")); + proposal->addAction(proposalsListAction); + proposal->addAction(proposalAddAction); } @@ -755,7 +753,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(governanceAction); toolbar->addAction(unlockWalletAction); - toolbar->addAction(proposalAction); + toolbar->addAction(unlockWalletAction); toolbar->setMovable(false); // remove unused icon in upper left corner @@ -908,8 +906,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } - proposalAction->setEnabled(enabled); proposalsListAction->setEnabled(enabled); + proposalAddAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); changePassphraseAction->setEnabled(enabled); @@ -1059,10 +1057,16 @@ void BitcoinGUI::openClicked() } -void BitcoinGUI::gotoProposalAddDialog() +void BitcoinGUI::gotoProposalsListPage() +{ + //WebWindowAction->setChecked(true); + if (walletFrame) walletFrame->gotoProposalsListPage(); +} + +void BitcoinGUI::gotoProposalAddPage() { - proposalAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalAddDialog(); + //WebWindowAction->setChecked(true); + if (walletFrame) walletFrame->gotoProposalAddPage(); } void BitcoinGUI::openDonate() @@ -1082,12 +1086,6 @@ void BitcoinGUI::openExternalURL(QString url) } } -void BitcoinGUI::gotoProposalsListPage() -{ - proposalsListAction->setChecked(true); - if (walletFrame) walletFrame->proposalsListAction(); -} - /*void BitcoinGUI::gotoPrivateSendPage() { privatesendAction->setChecked(true); From 72e528f6d744945863dd3ec6b847d17f8290f25b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:42:59 -0400 Subject: [PATCH 0685/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index bf1627e2..47960a9a 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -10,7 +10,7 @@ #endif #include "amount.h" -#include "governancelist.h" +/*#include "proposals.h" */ #include #include @@ -106,7 +106,7 @@ class BitcoinGUI : public QMainWindow QAction* externalDonate; QAction *proposalsListAction; - QAction *proposalAction; + QAction *proposalAddAction; /* QAction* privatesendAction; */ QAction *overviewAction; QAction *historyAction; @@ -232,27 +232,39 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to add proposal page */ - void gotoProposalsListPage(); + /** Switch to ProposalsList page */ + void gotoProposalsListPage(); + + /** Switch to ProposalAdd page */ + void gotoProposalAddPage(); + /** Switch to trading page */ /* void gotoTradingDialogPage(); */ + /** Switch to governance page */ void gotoGovernancePage(); + /** Switch to private send page */ /* void gotoPrivateSendPage(); */ + /** Switch to overview (home) page */ void gotoOverviewPage(); + /** Switch to history (transactions) page */ void gotoHistoryPage(); + /** Switch to masternode page */ void gotoMasternodePage(); + /** Switch to receive coins page */ void gotoReceiveCoinsPage(); + /** Switch to send coins page */ void gotoSendCoinsPage(QString addr = ""); /** Show Sign/Verify Message dialog and switch to sign message tab */ void gotoSignMessageTab(QString addr = ""); + /** Show Sign/Verify Message dialog and switch to verify message tab */ void gotoVerifyMessageTab(QString addr = ""); From 4b8e0ecb57544d73c4044421e68b1d031db2a4ff Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:43:48 -0400 Subject: [PATCH 0686/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index e9094ab1..cfeec6e0 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,13 +108,14 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoProposalAddDialog() +void WalletFrame::gotoProposalAddPage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalAddDialog(); + i.value()->gotoProposalAddPage(); } + void WalletFrame::gotoProposalsListPage() { QMap::const_iterator i; From f64323820e29584953e7cb7ffdd1aae234c74404 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:44:24 -0400 Subject: [PATCH 0687/1324] Update walletframe.h --- src/qt/walletframe.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 06ed7c60..6c022375 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,10 +63,11 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to ProposalAdd page */ - void gotoProposalAddDialog(); - /** Switch to governance page */ - void gotoProposalsListPage(); + /** Switch to ProposalsList page */ + void gotoProposalsListPage(); + + /** Switch to ProposalAdd page */ + void gotoProposalAddPage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 0cbab6effcda70cf4bf3a2eb379890240f328214 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:46:21 -0400 Subject: [PATCH 0688/1324] Update walletview.cpp --- src/qt/walletview.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index dd585de3..6a9b80bc 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -22,6 +22,7 @@ #include "walletmodel.h" #include "privatesendpage.h" #include "proposaladddialog.h" +#include "proposals.h" #include "ui_interface.h" @@ -76,7 +77,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); proposalsPage = new Proposals(platformStyle); - proposalAddDialog = new ProposalAddDialog(platformStyle); + proposalAddPage = new ProposalAddDialog(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); @@ -88,7 +89,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); addWidget(proposalsPage); - addWidget(proposalAddDialog); + addWidget(proposalAddPage); QSettings settings; @@ -176,8 +177,8 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - proposalsPage->setModel(walletModel); - proposalAddDialog->setModel(walletModel); + proposalsPage->setModel(walletModel); + proposalAddPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); @@ -237,16 +238,14 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoProposalAddDialog() +void WalletView::gotoProposalsListPage() { - setCurrentWidget(proposalAddDialog); + setCurrentWidget(proposalsPage); } - -void WalletView::gotoProposalsListPage() +void WalletView::gotoProposalAddPage() { - QSettings settings; - setCurrentWidget(proposalsPage); + setCurrentWidget(proposalAddPage); } void WalletView::gotoPrivateSendPage() From ac065b3e54421f7b917236c714ada8c067e60de5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:47:27 -0400 Subject: [PATCH 0689/1324] Update walletview.h --- src/qt/walletview.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 0c8af4cf..c84ab520 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -24,8 +24,8 @@ class TransactionView; class WalletModel; class AddressBookPage; class PrivateSendPage; -class Proposals; class ProposalAddDialog; +class Proposals; @@ -75,8 +75,8 @@ class WalletView : public QStackedWidget AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; + ProposalAddDialog *proposalAddPage; Proposals *proposalsPage; - ProposalAddDialog *proposalAddDialog; TransactionView *transactionView; @@ -86,10 +86,12 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to ProposalAdd page */ - void gotoProposalAddDialog(); - /** Switch to governance page */ - void gotoProposalsListPage(); + /** Switch to ProposalsList page */ + void gotoProposalsListPage(); + + /** Switch to ProposalAdd page */ + void gotoProposalAddPage(); + /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From fbbaf1ee5933011861a2ff5030250530e033dc08 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:51:48 -0400 Subject: [PATCH 0690/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index ab1a7d4f..e6b2d3b5 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -750,8 +750,8 @@ void BitcoinGUI::createToolBars() { toolbar->addAction(masternodeAction); } - toolbar->addAction(governanceAction); - toolbar->addAction(unlockWalletAction); + /* toolbar->addAction(governanceAction); + toolbar->addAction(unlockWalletAction); */ toolbar->addAction(unlockWalletAction); From 0652a7a3906f2e308c2fb7b588bd204b7ffbdc35 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:52:28 -0400 Subject: [PATCH 0691/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 47960a9a..0aa700e8 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -242,7 +242,7 @@ private Q_SLOTS: /* void gotoTradingDialogPage(); */ /** Switch to governance page */ - void gotoGovernancePage(); + /* void gotoGovernancePage(); */ /** Switch to private send page */ /* void gotoPrivateSendPage(); */ From 932ee95d598a37b2c0183d58330ca200a103ccda Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:53:09 -0400 Subject: [PATCH 0692/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index c84ab520..cb5813ab 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -7,7 +7,7 @@ #include "amount.h" #include "masternodelist.h" -#include "governancelist.h" +/*#include "governancelist.h" */ #include "proposaladddialog.h" From 31cba56f64c2ae019c9adfe1c843ea088742a329 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:08:33 -0400 Subject: [PATCH 0693/1324] Update proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp index df1497e0..7a15610b 100644 --- a/src/qt/proposaladddialog.cpp +++ b/src/qt/proposaladddialog.cpp @@ -30,7 +30,7 @@ #include ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : - QDialog(parent), + QWidget(parent), ui(new Ui::ProposalAddDialog), model(0), platformStyle(platformStyle) From 4db76a1fa48c24338f70e1ea2560551ad1e483b8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:34:18 -0400 Subject: [PATCH 0694/1324] Update Makefile.am --- src/Makefile.am | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 678aa617..e69b7188 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -253,7 +253,6 @@ BITCOIN_CORE_H = \ rpcpodc.h \ rpcpog.h - obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \ @@ -356,7 +355,6 @@ libhelpthehomeless_zmq_a_SOURCES = \ zmq/zmqpublishnotifier.cpp endif - # wallet: shared between helpthehomelessd and helpthehomeless-qt, but only linked # when wallet enabled libhelpthehomeless_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) @@ -445,7 +443,6 @@ crypto_libhelpthehomeless_crypto_a_SOURCES = \ crypto/SWIFFTX/lane.h \ crypto/SWIFFTX/blake2s.h - # consensus: shared between all executables that validate any consensus rules. libhelpthehomeless_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libhelpthehomeless_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -662,7 +659,6 @@ DISTCLEANFILES = obj/build.h EXTRA_DIST = $(CTAES_DIST) EXTRA_DIST += $(IMMER_DIST) - config/helpthehomeless-config.h: config/stamp-h1 @$(MAKE) -C $(top_builddir) $(subdir)/$(@) config/stamp-h1: $(top_srcdir)/$(subdir)/config/helpthehomeless-config.h.in $(top_builddir)/config.status From b49d146db894615bfd672e09ecd27c206de78311 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:38:34 -0400 Subject: [PATCH 0695/1324] Update Makefile.am --- src/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e69b7188..ebe40651 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -343,7 +343,6 @@ libhelpthehomeless_server_a_SOURCES = \ validation.cpp \ validationinterface.cpp \ versionbits.cpp \ - masternodeman.cpp \ $(BITCOIN_CORE_H) if ENABLE_ZMQ @@ -355,6 +354,7 @@ libhelpthehomeless_zmq_a_SOURCES = \ zmq/zmqpublishnotifier.cpp endif + # wallet: shared between helpthehomelessd and helpthehomeless-qt, but only linked # when wallet enabled libhelpthehomeless_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) @@ -370,7 +370,7 @@ libhelpthehomeless_wallet_a_SOURCES = \ wallet/wallet.cpp \ wallet/walletdb.cpp \ rpcpodc.cpp \ - rpcpog.cpp + rpcpog.cpp \ $(BITCOIN_CORE_H) # crypto primitives library @@ -659,6 +659,7 @@ DISTCLEANFILES = obj/build.h EXTRA_DIST = $(CTAES_DIST) EXTRA_DIST += $(IMMER_DIST) + config/helpthehomeless-config.h: config/stamp-h1 @$(MAKE) -C $(top_builddir) $(subdir)/$(@) config/stamp-h1: $(top_srcdir)/$(subdir)/config/helpthehomeless-config.h.in $(top_builddir)/config.status From 56a01606d40576d537be0267f1c23e54e3c85f3c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:39:33 -0400 Subject: [PATCH 0696/1324] Update Makefile.am From 6895beaed7a6d5dbcb2ae72bb558d49b7c5fd68f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 16:53:09 -0400 Subject: [PATCH 0697/1324] Update Makefile.am --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index ebe40651..75b13e39 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -252,7 +252,7 @@ BITCOIN_CORE_H = \ smartcontract-server.h \ rpcpodc.h \ rpcpog.h - + obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \ From 672ce48d43ca04f4db380d3786c4255894f412f9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:02:07 -0400 Subject: [PATCH 0698/1324] Update Makefile.am --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 75b13e39..04cc2a0a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -251,7 +251,7 @@ BITCOIN_CORE_H = \ smartcontract-client.h \ smartcontract-server.h \ rpcpodc.h \ - rpcpog.h + rpcpog.h \ obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj From 429f0943c0aadaaf209715e78d5b1b28b504860b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:02:30 -0400 Subject: [PATCH 0699/1324] Update Makefile.am --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 04cc2a0a..75b13e39 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -251,7 +251,7 @@ BITCOIN_CORE_H = \ smartcontract-client.h \ smartcontract-server.h \ rpcpodc.h \ - rpcpog.h \ + rpcpog.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj From 1bd23dd6fb890a147278002a2337ba5b8cf18ed1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:27:26 -0400 Subject: [PATCH 0700/1324] Update rpcpodc.cpp --- src/rpcpodc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcpodc.cpp b/src/rpcpodc.cpp index b6d1ee19..4d5a7b6c 100644 --- a/src/rpcpodc.cpp +++ b/src/rpcpodc.cpp @@ -5,7 +5,7 @@ #include "spork.h" #include "utilmoneystr.h" #include "masternode-payments.h" -#include "masternodeconfig.h" +#include "masternode-utils.h" #include "activemasternode.h" #include "governance-classes.h" #include "masternode-sync.h" @@ -26,7 +26,7 @@ extern CWallet* pwalletMain; -const std::string CURRENCY_NAME = "IMAGECOIN"; +const std::string CURRENCY_NAME = "HelpTheHomelessCoin"; std::string GetSANDirectory2() { @@ -192,7 +192,7 @@ int64_t GetDCCFileAge() int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints) { - std::string sDomain = "https://www.worldcommunitygrid.org"; + std::string sDomain = "https://www.helpthehomelessworldwide.org"; std::string sRestfulURL = "verifyMember.do?name=" + sMemberName + "&code=" + sAuthCode; //std::string sResponse = HTTPSPost(true, 0, "", "", "", sDomain, sRestfulURL, 443, "", 12, 14000, 1); std::string sResponse; From 9097ddf2f83ebcfd4e847c9b1bf5c196e351a611 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:28:08 -0400 Subject: [PATCH 0701/1324] Update rpcpog.cpp --- src/rpcpog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcpog.cpp b/src/rpcpog.cpp index a28c9b04..557b83c7 100644 --- a/src/rpcpog.cpp +++ b/src/rpcpog.cpp @@ -14,7 +14,7 @@ #include "governance-vote.h" #include "governance-classes.h" #include "governance-validators.h" -#include "masternode.h" +#include "masternode-utils.h" #include "masternode-sync.h" #include "masternodeconfig.h" #include "masternodeman.h" From 495ca2d32cbcb34ffd9c8a501b5719f1b026a301 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:34:24 -0400 Subject: [PATCH 0702/1324] Update rpcpog.cpp --- src/rpcpog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcpog.cpp b/src/rpcpog.cpp index 557b83c7..e6a7e8f6 100644 --- a/src/rpcpog.cpp +++ b/src/rpcpog.cpp @@ -16,7 +16,7 @@ #include "governance-validators.h" #include "masternode-utils.h" #include "masternode-sync.h" -#include "masternodeconfig.h" +/*#include "masternodeconfig.h" */ #include "masternodeman.h" #include "masternode-payments.h" #include "messagesigner.h" From f8a0ccfb62ab011594b390449c0db0891e9cd451 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:37:06 -0400 Subject: [PATCH 0703/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e6b2d3b5..3d865189 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1634,7 +1634,7 @@ void BitcoinGUI::detectShutdown() // Governance - Check to see if we should submit a proposal - /* nProposalModulus++; + nProposalModulus++; if (nProposalModulus % 15 == 0 && !fLoadingIndex) { nProposalModulus = 0; @@ -1666,7 +1666,7 @@ void BitcoinGUI::detectShutdown() } } } -} */ +} void BitcoinGUI::showProgress(const QString &title, int nProgress) From 59a385fc9096dd1ab5a9d4a0c656a9e668b2bab3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:38:19 -0400 Subject: [PATCH 0704/1324] Update validation.cpp --- src/validation.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index 17822dab..6527f8f8 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -95,8 +95,19 @@ uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE; +std::map mvResearchers; + +int nProposalModulus = 0; +std::string msURL; +bool fProposalNeedsSubmitted= false; +int64_t nProposalStartTime = 0; +uint256 uTxIdFee = uint256S("0x0"); +int nProposalPrepareHeight = 0; + +std::string msProposalResult; +std::string msProposalHex; +std::atomic fDIP0001WasLockedIn{false}; std::atomic fDIP0001ActiveAtTip{false}; -std::atomic fDIP0003ActiveAtTip{false}; uint256 hashAssumeValid; From 9fe41376d952123f6032bc80caf5c2f2160bfdac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:40:29 -0400 Subject: [PATCH 0705/1324] Update validation.h --- src/validation.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/validation.h b/src/validation.h index 47ec4e18..dfc44e12 100644 --- a/src/validation.h +++ b/src/validation.h @@ -186,10 +186,23 @@ extern int64_t nMaxTipAge; extern bool fLargeWorkForkFound; extern bool fLargeWorkInvalidChainFound; +extern std::string msProposalHex; +extern std::string msURL; +extern int64_t nProposalStartTime; + +extern bool fProposalNeedsSubmitted; +extern int nProposalPrepareHeight; +extern int nProposalModulus; +extern uint256 uTxIdFee; +extern std::string msProposalResult; + extern std::map mapRejectedBlocks; extern std::atomic fDIP0001ActiveAtTip; +struct Researcher; +extern std::map mvResearchers; + /** Block hash whose ancestors we will assume to have valid scripts without checking them. */ extern uint256 hashAssumeValid; From 91df229b7cd9c19693389c28c065a45d69723891 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:44:31 -0400 Subject: [PATCH 0706/1324] Update validation.cpp --- src/validation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 6527f8f8..d83492ec 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -95,6 +95,8 @@ uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE; +std::map, std::pair> mvApplicationCache; + std::map mvResearchers; int nProposalModulus = 0; From fe72693ad15dd3f7fff4d74e729c51bb934b5920 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:45:28 -0400 Subject: [PATCH 0707/1324] Update validation.h --- src/validation.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/validation.h b/src/validation.h index dfc44e12..0698d4e1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -198,6 +198,8 @@ extern std::string msProposalResult; extern std::map mapRejectedBlocks; +extern std::map, std::pair> mvApplicationCache; + extern std::atomic fDIP0001ActiveAtTip; struct Researcher; From 1653fd63073534d574de80db9371d7e9f6ae3bd9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 17:45:55 -0400 Subject: [PATCH 0708/1324] Update masternodeman.h --- src/masternodeman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodeman.h b/src/masternodeman.h index 1927ddaa..a80bd2c7 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -5,7 +5,7 @@ #ifndef MASTERNODEMAN_H #define MASTERNODEMAN_H -#include "masternode.h" +#include "masternode-utils.h" #include "sync.h" using namespace std; From af22424faf755ccbc74c551921f5c0579ddc9aa0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 18:01:00 -0400 Subject: [PATCH 0709/1324] Update masternodeman.h --- src/masternodeman.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/masternodeman.h b/src/masternodeman.h index a80bd2c7..d3e10afe 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -18,9 +18,9 @@ extern CMasternodeMan mnodeman; class CMasternodeMan { public: - typedef std::pair score_pair_t; + typedef std::pair score_pair_t; typedef std::vector score_pair_vec_t; - typedef std::pair rank_pair_t; + typedef std::pair rank_pair_t; typedef std::vector rank_pair_vec_t; private: @@ -49,7 +49,7 @@ class CMasternodeMan int nCachedBlockHeight; // map to hold all MNs - std::map mapMasternodes; + std::map mapMasternodes; // who's asked for the Masternode list and the last time std::map mAskedUsForMasternodeList; // who we asked for the Masternode list and the last time @@ -76,7 +76,7 @@ class CMasternodeMan friend class CMasternodeSync; /// Find an entry - CMasternode* Find(const COutPoint& outpoint); + CMasternodeMan* Find(const COutPoint& outpoint); bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol = 0); @@ -124,7 +124,7 @@ class CMasternodeMan CMasternodeMan(); /// Add an entry - bool Add(CMasternode &mn); + bool Add(CMasternodeMan &mn); /// Ask (source) node for mnb void AskForMN(CNode *pnode, const COutPoint& outpoint, CConnman& connman); @@ -158,7 +158,7 @@ class CMasternodeMan void DsegUpdate(CNode* pnode, CConnman& connman); /// Versions of Find that are safe to use from outside the class - bool Get(const COutPoint& outpoint, CMasternode& masternodeRet); + bool Get(const COutPoint& outpoint, CMasternodeMan& masternodeRet); bool Has(const COutPoint& outpoint); bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet); From cce3e4af9cf1fd7bf314e27fee0f8bc48ebf90b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Mon, 15 Jun 2020 18:07:36 -0400 Subject: [PATCH 0710/1324] Update masternodeman.cpp --- src/masternodeman.cpp | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 3bd9bfb0..aceab806 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -23,8 +23,8 @@ const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan struct CompareLastPaidBlock { - bool operator()(const std::pair& t1, - const std::pair& t2) const + bool operator()(const std::pair& t1, + const std::pair& t2) const { return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); } @@ -32,8 +32,8 @@ struct CompareLastPaidBlock struct CompareScoreMN { - bool operator()(const std::pair& t1, - const std::pair& t2) const + bool operator()(const std::pair& t1, + const std::pair& t2) const { return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); } @@ -42,8 +42,8 @@ struct CompareScoreMN struct CompareByAddr { - bool operator()(const CMasternode* t1, - const CMasternode* t2) const + bool operator()(const CMasternodeMan* t1, + const CMasternodeMan* t2) const { return t1->addr < t2->addr; } @@ -68,7 +68,7 @@ CMasternodeMan::CMasternodeMan() nDsqCount(0) {} -bool CMasternodeMan::Add(CMasternode &mn) +bool CMasternodeMan::Add(CMasternodeMan &mn) { LOCK(cs); @@ -112,7 +112,7 @@ void CMasternodeMan::AskForMN(CNode* pnode, const COutPoint& outpoint, CConnman& bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) { LOCK(cs); - CMasternode* pmn = Find(outpoint); + CMasternodeMan* pmn = Find(outpoint); if (!pmn) { return false; } @@ -126,7 +126,7 @@ bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) { LOCK(cs); - CMasternode* pmn = Find(outpoint); + CMasternodeMan* pmn = Find(outpoint); if (!pmn) { return false; } @@ -138,7 +138,7 @@ bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) bool CMasternodeMan::PoSeBan(const COutPoint &outpoint) { LOCK(cs); - CMasternode* pmn = Find(outpoint); + CMasternodeMan* pmn = Find(outpoint); if (!pmn) { return false; } @@ -175,7 +175,7 @@ void CMasternodeMan::CheckAndRemove(CConnman& connman) rank_pair_vec_t vecMasternodeRanks; // ask for up to MNB_RECOVERY_MAX_ASK_ENTRIES masternode entries at a time int nAskForMnbRecovery = MNB_RECOVERY_MAX_ASK_ENTRIES; - std::map::iterator it = mapMasternodes.begin(); + std::map::iterator it = mapMasternodes.begin(); while (it != mapMasternodes.end()) { CMasternodeBroadcast mnb = CMasternodeBroadcast(it->second); uint256 hash = mnb.GetHash(); @@ -427,7 +427,7 @@ CMasternode* CMasternodeMan::Find(const COutPoint &outpoint) return it == mapMasternodes.end() ? NULL : &(it->second); } -bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternode& masternodeRet) +bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternodeMan& masternodeRet) { // Theses mutexes are recursive so double locking by the same thread is safe. LOCK(cs); @@ -503,7 +503,7 @@ bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool f // Need LOCK2 here to ensure consistent locking order because the GetBlockHash call below locks cs_main LOCK2(cs_main,cs); - std::vector > vecMasternodeLastPaid; + std::vector > vecMasternodeLastPaid; /* Make a vector with all of the last paid times @@ -579,7 +579,7 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vector vpMasternodesShuffled; + std::vector vpMasternodesShuffled; for (auto& mnpair : mapMasternodes) { vpMasternodesShuffled.push_back(&mnpair.second); } @@ -590,7 +590,7 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vectornProtocolVersion < nProtocolVersion || !pmn->IsEnabled()) continue; fExclude = false; BOOST_FOREACH(const COutPoint &outpointToExclude, vecToExclude) { @@ -787,7 +787,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); // see if we have this Masternode - CMasternode* pmn = Find(mnp.vin.prevout); + CMasternodeMan* pmn = Find(mnp.vin.prevout); // if masternode uses sentinel ping instead of watchdog // we shoud update nTimeLastWatchdogVote here if sentinel @@ -920,7 +920,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) int nRanksTotal = (int)vecMasternodeRanks.size(); // send verify requests only if we are in top MAX_POSE_RANK - std::vector >::iterator it = vecMasternodeRanks.begin(); + std::vector >::iterator it = vecMasternodeRanks.begin(); while(it != vecMasternodeRanks.end()) { if(it->first > MAX_POSE_RANK) { LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n", @@ -944,7 +944,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) int nOffset = MAX_POSE_RANK + nMyRank - 1; if(nOffset >= (int)vecMasternodeRanks.size()) return; - std::vector vSortedByAddr; + std::vector vSortedByAddr; for (auto& mnpair : mapMasternodes) { vSortedByAddr.push_back(&mnpair.second); } @@ -987,14 +987,14 @@ void CMasternodeMan::CheckSameAddr() { if(!masternodeSync.IsSynced() || mapMasternodes.empty()) return; - std::vector vBan; - std::vector vSortedByAddr; + std::vector vBan; + std::vector vSortedByAddr; { LOCK(cs); - CMasternode* pprevMasternode = NULL; - CMasternode* pverifiedMasternode = NULL; + CMasternodeMan* pprevMasternode = NULL; + CMasternodeMan* pverifiedMasternode = NULL; for (auto& mnpair : mapMasternodes) { vSortedByAddr.push_back(&mnpair.second); @@ -1002,7 +1002,7 @@ void CMasternodeMan::CheckSameAddr() sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); - BOOST_FOREACH(CMasternode* pmn, vSortedByAddr) { + BOOST_FOREACH(CMasternodeMan* pmn, vSortedByAddr) { // check only (pre)enabled masternodes if(!pmn->IsEnabled() && !pmn->IsPreEnabled()) continue; // initial step @@ -1030,13 +1030,13 @@ void CMasternodeMan::CheckSameAddr() } // ban duplicates - BOOST_FOREACH(CMasternode* pmn, vBan) { + BOOST_FOREACH(CMasternodeMan* pmn, vBan) { LogPrintf("CMasternodeMan::CheckSameAddr -- increasing PoSe ban score for masternode %s\n", pmn->vin.prevout.ToStringShort()); pmn->IncreasePoSeBanScore(); } } -bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) +bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) { if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { // we already asked for verification, not a good idea to do this too often, skip it @@ -1144,8 +1144,8 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m { LOCK(cs); - CMasternode* prealMasternode = NULL; - std::vector vpMasternodesToBan; + CMasternodeMan* prealMasternode = NULL; + std::vector vpMasternodesToBan; std::string strMessage1 = strprintf("%s%d%s", pnode->addr.ToString(false), mnv.nonce, blockHash.ToString()); for (auto& mnpair : mapMasternodes) { if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) { @@ -1198,7 +1198,7 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m LogPrintf("CMasternodeMan::ProcessVerifyReply -- verified real masternode %s for addr %s\n", prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString()); // increase ban score for everyone else - BOOST_FOREACH(CMasternode* pmn, vpMasternodesToBan) { + BOOST_FOREACH(CMasternodeMan* pmn, vpMasternodesToBan) { pmn->IncreasePoSeBanScore(); LogPrint("masternode", "CMasternodeMan::ProcessVerifyReply -- increased PoSe ban score for %s addr %s, new score %d\n", prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString(), pmn->nPoSeBanScore); @@ -1263,13 +1263,13 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); - CMasternode* pmn1 = Find(mnv.vin1.prevout); + CMasternodeMan* pmn1 = Find(mnv.vin1.prevout); if(!pmn1) { LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode1 %s\n", mnv.vin1.prevout.ToStringShort()); return; } - CMasternode* pmn2 = Find(mnv.vin2.prevout); + CMasternodeMan* pmn2 = Find(mnv.vin2.prevout); if(!pmn2) { LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode2 %s\n", mnv.vin2.prevout.ToStringShort()); return; @@ -1334,7 +1334,7 @@ void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& co LogPrintf("CMasternodeMan::UpdateMasternodeList -- masternode=%s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); - CMasternode* pmn = Find(mnb.vin.prevout); + CMasternodeMan* pmn = Find(mnb.vin.prevout); if(pmn == NULL) { if(Add(mnb)) { masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - new"); @@ -1377,7 +1377,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr // does it have newer lastPing? if(mnb.lastPing.sigTime > mapSeenMasternodeBroadcast[hash].second.lastPing.sigTime) { // simulate Check - CMasternode mnTemp = CMasternode(mnb); + CMasternodeMan mnTemp = CMasternodeMan(mnb); mnTemp.Check(); LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetAdjustedTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString()); if(mnTemp.IsValidStateForAutoStart(mnTemp.nActiveState)) { @@ -1400,7 +1400,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr } // search Masternode list - CMasternode* pmn = Find(mnb.vin.prevout); + CMasternodeMan* pmn = Find(mnb.vin.prevout); if(pmn) { CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; if(!mnb.Update(pmn, nDos, connman)) { @@ -1465,7 +1465,7 @@ void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) void CMasternodeMan::UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime) { LOCK(cs); - CMasternode* pmn = Find(outpoint); + CMasternodeMan* pmn = Find(outpoint); if(!pmn) { return; } @@ -1483,7 +1483,7 @@ bool CMasternodeMan::IsWatchdogActive() bool CMasternodeMan::AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash) { LOCK(cs); - CMasternode* pmn = Find(outpoint); + CMasternodeMan* pmn = Find(outpoint); if(!pmn) { return false; } From 505576caf06c963076910157680b971adffc35d7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:56:42 -0400 Subject: [PATCH 0711/1324] Update masternodeman.cpp --- src/masternodeman.cpp | 72 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index aceab806..d445d945 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -23,8 +23,8 @@ const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan struct CompareLastPaidBlock { - bool operator()(const std::pair& t1, - const std::pair& t2) const + bool operator()(const std::pair& t1, + const std::pair& t2) const { return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); } @@ -32,8 +32,8 @@ struct CompareLastPaidBlock struct CompareScoreMN { - bool operator()(const std::pair& t1, - const std::pair& t2) const + bool operator()(const std::pair& t1, + const std::pair& t2) const { return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); } @@ -42,8 +42,8 @@ struct CompareScoreMN struct CompareByAddr { - bool operator()(const CMasternodeMan* t1, - const CMasternodeMan* t2) const + bool operator()(const CMasternode* t1, + const CMasternode* t2) const { return t1->addr < t2->addr; } @@ -68,7 +68,7 @@ CMasternodeMan::CMasternodeMan() nDsqCount(0) {} -bool CMasternodeMan::Add(CMasternodeMan &mn) +bool CMasternodeMan::Add(CMasternode &mn) { LOCK(cs); @@ -112,7 +112,7 @@ void CMasternodeMan::AskForMN(CNode* pnode, const COutPoint& outpoint, CConnman& bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) { LOCK(cs); - CMasternodeMan* pmn = Find(outpoint); + CMasternode* pmn = Find(outpoint); if (!pmn) { return false; } @@ -126,7 +126,7 @@ bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) { LOCK(cs); - CMasternodeMan* pmn = Find(outpoint); + CMasternode* pmn = Find(outpoint); if (!pmn) { return false; } @@ -138,7 +138,7 @@ bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) bool CMasternodeMan::PoSeBan(const COutPoint &outpoint) { LOCK(cs); - CMasternodeMan* pmn = Find(outpoint); + CMasternode* pmn = Find(outpoint); if (!pmn) { return false; } @@ -175,7 +175,7 @@ void CMasternodeMan::CheckAndRemove(CConnman& connman) rank_pair_vec_t vecMasternodeRanks; // ask for up to MNB_RECOVERY_MAX_ASK_ENTRIES masternode entries at a time int nAskForMnbRecovery = MNB_RECOVERY_MAX_ASK_ENTRIES; - std::map::iterator it = mapMasternodes.begin(); + std::map::iterator it = mapMasternodes.begin(); while (it != mapMasternodes.end()) { CMasternodeBroadcast mnb = CMasternodeBroadcast(it->second); uint256 hash = mnb.GetHash(); @@ -387,14 +387,12 @@ int CMasternodeMan::CountByIP(int nNetworkType) { LOCK(cs); int nNodeCount = 0; - for (auto& mnpair : mapMasternodes) if ((nNetworkType == NET_IPV4 && mnpair.second.addr.IsIPv4()) || (nNetworkType == NET_TOR && mnpair.second.addr.IsTor()) || (nNetworkType == NET_IPV6 && mnpair.second.addr.IsIPv6())) { nNodeCount++; } - return nNodeCount; } */ @@ -427,7 +425,7 @@ CMasternode* CMasternodeMan::Find(const COutPoint &outpoint) return it == mapMasternodes.end() ? NULL : &(it->second); } -bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternodeMan& masternodeRet) +bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternode& masternodeRet) { // Theses mutexes are recursive so double locking by the same thread is safe. LOCK(cs); @@ -503,7 +501,7 @@ bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool f // Need LOCK2 here to ensure consistent locking order because the GetBlockHash call below locks cs_main LOCK2(cs_main,cs); - std::vector > vecMasternodeLastPaid; + std::vector > vecMasternodeLastPaid; /* Make a vector with all of the last paid times @@ -579,7 +577,7 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vector vpMasternodesShuffled; + std::vector vpMasternodesShuffled; for (auto& mnpair : mapMasternodes) { vpMasternodesShuffled.push_back(&mnpair.second); } @@ -590,7 +588,7 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vectornProtocolVersion < nProtocolVersion || !pmn->IsEnabled()) continue; fExclude = false; BOOST_FOREACH(const COutPoint &outpointToExclude, vecToExclude) { @@ -787,7 +785,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); // see if we have this Masternode - CMasternodeMan* pmn = Find(mnp.vin.prevout); + CMasternode* pmn = Find(mnp.vin.prevout); // if masternode uses sentinel ping instead of watchdog // we shoud update nTimeLastWatchdogVote here if sentinel @@ -920,7 +918,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) int nRanksTotal = (int)vecMasternodeRanks.size(); // send verify requests only if we are in top MAX_POSE_RANK - std::vector >::iterator it = vecMasternodeRanks.begin(); + std::vector >::iterator it = vecMasternodeRanks.begin(); while(it != vecMasternodeRanks.end()) { if(it->first > MAX_POSE_RANK) { LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n", @@ -944,7 +942,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) int nOffset = MAX_POSE_RANK + nMyRank - 1; if(nOffset >= (int)vecMasternodeRanks.size()) return; - std::vector vSortedByAddr; + std::vector vSortedByAddr; for (auto& mnpair : mapMasternodes) { vSortedByAddr.push_back(&mnpair.second); } @@ -987,14 +985,14 @@ void CMasternodeMan::CheckSameAddr() { if(!masternodeSync.IsSynced() || mapMasternodes.empty()) return; - std::vector vBan; - std::vector vSortedByAddr; + std::vector vBan; + std::vector vSortedByAddr; { LOCK(cs); - CMasternodeMan* pprevMasternode = NULL; - CMasternodeMan* pverifiedMasternode = NULL; + CMasternode* pprevMasternode = NULL; + CMasternode* pverifiedMasternode = NULL; for (auto& mnpair : mapMasternodes) { vSortedByAddr.push_back(&mnpair.second); @@ -1002,7 +1000,7 @@ void CMasternodeMan::CheckSameAddr() sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); - BOOST_FOREACH(CMasternodeMan* pmn, vSortedByAddr) { + BOOST_FOREACH(CMasternode* pmn, vSortedByAddr) { // check only (pre)enabled masternodes if(!pmn->IsEnabled() && !pmn->IsPreEnabled()) continue; // initial step @@ -1030,13 +1028,13 @@ void CMasternodeMan::CheckSameAddr() } // ban duplicates - BOOST_FOREACH(CMasternodeMan* pmn, vBan) { + BOOST_FOREACH(CMasternode* pmn, vBan) { LogPrintf("CMasternodeMan::CheckSameAddr -- increasing PoSe ban score for masternode %s\n", pmn->vin.prevout.ToStringShort()); pmn->IncreasePoSeBanScore(); } } -bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) +bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) { if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { // we already asked for verification, not a good idea to do this too often, skip it @@ -1144,8 +1142,8 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m { LOCK(cs); - CMasternodeMan* prealMasternode = NULL; - std::vector vpMasternodesToBan; + CMasternode* prealMasternode = NULL; + std::vector vpMasternodesToBan; std::string strMessage1 = strprintf("%s%d%s", pnode->addr.ToString(false), mnv.nonce, blockHash.ToString()); for (auto& mnpair : mapMasternodes) { if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) { @@ -1198,7 +1196,7 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m LogPrintf("CMasternodeMan::ProcessVerifyReply -- verified real masternode %s for addr %s\n", prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString()); // increase ban score for everyone else - BOOST_FOREACH(CMasternodeMan* pmn, vpMasternodesToBan) { + BOOST_FOREACH(CMasternode* pmn, vpMasternodesToBan) { pmn->IncreasePoSeBanScore(); LogPrint("masternode", "CMasternodeMan::ProcessVerifyReply -- increased PoSe ban score for %s addr %s, new score %d\n", prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString(), pmn->nPoSeBanScore); @@ -1263,13 +1261,13 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); - CMasternodeMan* pmn1 = Find(mnv.vin1.prevout); + CMasternode* pmn1 = Find(mnv.vin1.prevout); if(!pmn1) { LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode1 %s\n", mnv.vin1.prevout.ToStringShort()); return; } - CMasternodeMan* pmn2 = Find(mnv.vin2.prevout); + CMasternode* pmn2 = Find(mnv.vin2.prevout); if(!pmn2) { LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode2 %s\n", mnv.vin2.prevout.ToStringShort()); return; @@ -1334,7 +1332,7 @@ void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& co LogPrintf("CMasternodeMan::UpdateMasternodeList -- masternode=%s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); - CMasternodeMan* pmn = Find(mnb.vin.prevout); + CMasternode* pmn = Find(mnb.vin.prevout); if(pmn == NULL) { if(Add(mnb)) { masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - new"); @@ -1377,7 +1375,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr // does it have newer lastPing? if(mnb.lastPing.sigTime > mapSeenMasternodeBroadcast[hash].second.lastPing.sigTime) { // simulate Check - CMasternodeMan mnTemp = CMasternodeMan(mnb); + CMasternode mnTemp = CMasternode(mnb); mnTemp.Check(); LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetAdjustedTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString()); if(mnTemp.IsValidStateForAutoStart(mnTemp.nActiveState)) { @@ -1400,7 +1398,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr } // search Masternode list - CMasternodeMan* pmn = Find(mnb.vin.prevout); + CMasternode* pmn = Find(mnb.vin.prevout); if(pmn) { CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; if(!mnb.Update(pmn, nDos, connman)) { @@ -1465,7 +1463,7 @@ void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) void CMasternodeMan::UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime) { LOCK(cs); - CMasternodeMan* pmn = Find(outpoint); + CMasternode* pmn = Find(outpoint); if(!pmn) { return; } @@ -1483,7 +1481,7 @@ bool CMasternodeMan::IsWatchdogActive() bool CMasternodeMan::AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash) { LOCK(cs); - CMasternodeMan* pmn = Find(outpoint); + CMasternode* pmn = Find(outpoint); if(!pmn) { return false; } From b007f6e6e83073b54f076ec02f23d432b224bc1d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:57:15 -0400 Subject: [PATCH 0712/1324] Update masternodeman.h --- src/masternodeman.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/masternodeman.h b/src/masternodeman.h index d3e10afe..1927ddaa 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -5,7 +5,7 @@ #ifndef MASTERNODEMAN_H #define MASTERNODEMAN_H -#include "masternode-utils.h" +#include "masternode.h" #include "sync.h" using namespace std; @@ -18,9 +18,9 @@ extern CMasternodeMan mnodeman; class CMasternodeMan { public: - typedef std::pair score_pair_t; + typedef std::pair score_pair_t; typedef std::vector score_pair_vec_t; - typedef std::pair rank_pair_t; + typedef std::pair rank_pair_t; typedef std::vector rank_pair_vec_t; private: @@ -49,7 +49,7 @@ class CMasternodeMan int nCachedBlockHeight; // map to hold all MNs - std::map mapMasternodes; + std::map mapMasternodes; // who's asked for the Masternode list and the last time std::map mAskedUsForMasternodeList; // who we asked for the Masternode list and the last time @@ -76,7 +76,7 @@ class CMasternodeMan friend class CMasternodeSync; /// Find an entry - CMasternodeMan* Find(const COutPoint& outpoint); + CMasternode* Find(const COutPoint& outpoint); bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol = 0); @@ -124,7 +124,7 @@ class CMasternodeMan CMasternodeMan(); /// Add an entry - bool Add(CMasternodeMan &mn); + bool Add(CMasternode &mn); /// Ask (source) node for mnb void AskForMN(CNode *pnode, const COutPoint& outpoint, CConnman& connman); @@ -158,7 +158,7 @@ class CMasternodeMan void DsegUpdate(CNode* pnode, CConnman& connman); /// Versions of Find that are safe to use from outside the class - bool Get(const COutPoint& outpoint, CMasternodeMan& masternodeRet); + bool Get(const COutPoint& outpoint, CMasternode& masternodeRet); bool Has(const COutPoint& outpoint); bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet); From 64ba8319609294583c33784a21fb4af085c31d99 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:57:50 -0400 Subject: [PATCH 0713/1324] Update rpcpodc.cpp --- src/rpcpodc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcpodc.cpp b/src/rpcpodc.cpp index 4d5a7b6c..b6d1ee19 100644 --- a/src/rpcpodc.cpp +++ b/src/rpcpodc.cpp @@ -5,7 +5,7 @@ #include "spork.h" #include "utilmoneystr.h" #include "masternode-payments.h" -#include "masternode-utils.h" +#include "masternodeconfig.h" #include "activemasternode.h" #include "governance-classes.h" #include "masternode-sync.h" @@ -26,7 +26,7 @@ extern CWallet* pwalletMain; -const std::string CURRENCY_NAME = "HelpTheHomelessCoin"; +const std::string CURRENCY_NAME = "IMAGECOIN"; std::string GetSANDirectory2() { @@ -192,7 +192,7 @@ int64_t GetDCCFileAge() int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints) { - std::string sDomain = "https://www.helpthehomelessworldwide.org"; + std::string sDomain = "https://www.worldcommunitygrid.org"; std::string sRestfulURL = "verifyMember.do?name=" + sMemberName + "&code=" + sAuthCode; //std::string sResponse = HTTPSPost(true, 0, "", "", "", sDomain, sRestfulURL, 443, "", 12, 14000, 1); std::string sResponse; From d85fc1ff108d4ccd8d90b2bad003078ab52c4806 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:58:12 -0400 Subject: [PATCH 0714/1324] Update rpcpodc.h From 1e3fbbc015eb88afe149b81446be89bcdbb0e7b7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:58:39 -0400 Subject: [PATCH 0715/1324] Update rpcpog.cpp --- src/rpcpog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcpog.cpp b/src/rpcpog.cpp index e6a7e8f6..a28c9b04 100644 --- a/src/rpcpog.cpp +++ b/src/rpcpog.cpp @@ -14,9 +14,9 @@ #include "governance-vote.h" #include "governance-classes.h" #include "governance-validators.h" -#include "masternode-utils.h" +#include "masternode.h" #include "masternode-sync.h" -/*#include "masternodeconfig.h" */ +#include "masternodeconfig.h" #include "masternodeman.h" #include "masternode-payments.h" #include "messagesigner.h" From 4d37daf4da8da682466aee9bc61de43be7e380dc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:59:10 -0400 Subject: [PATCH 0716/1324] Update rpcpog.h From 78f0d894c5bb2f23a25fcdb89a28097d665bf899 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:01:03 -0400 Subject: [PATCH 0717/1324] Create masternodeconfig.cpp --- src/masternodeconfig.cpp | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/masternodeconfig.cpp diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp new file mode 100644 index 00000000..2832fd16 --- /dev/null +++ b/src/masternodeconfig.cpp @@ -0,0 +1,90 @@ +#include "netbase.h" +#include "masternodeconfig.h" +#include "util.h" +#include "chainparams.h" + +#include +#include + +CMasternodeConfig masternodeConfig; + +void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { + CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex); + entries.push_back(cme); +} + +bool CMasternodeConfig::read(std::string& strErr) { + int linenumber = 1; + boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile(); + boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile); + + if (!streamConfig.good()) { + FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a"); + if (configFile != NULL) { + std::string strHeader = "# Masternode config file\n" + "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" + "# Example: mn1 127.0.0.2:6888 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n"; + fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile); + fclose(configFile); + } + return true; // Nothing to read, so just return + } + + for(std::string line; std::getline(streamConfig, line); linenumber++) + { + if(line.empty()) continue; + + std::istringstream iss(line); + std::string comment, alias, ip, privKey, txHash, outputIndex; + + if (iss >> comment) { + if(comment.at(0) == '#') continue; + iss.str(line); + iss.clear(); + } + + if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { + iss.str(line); + iss.clear(); + if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { + strErr = _("Could not parse masternode.conf") + "\n" + + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; + streamConfig.close(); + return false; + } + } + + int port = 0; + std::string hostname = ""; + SplitHostPort(ip, port, hostname); + if(port == 0 || hostname == "") { + strErr = _("Failed to parse host:port string") + "\n"+ + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; + streamConfig.close(); + return false; + } + int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); + if(Params().NetworkIDString() == CBaseChainParams::MAIN) { + if(port != mainnetDefaultPort) { + strErr = _("Invalid port detected in masternode.conf") + "\n" + + strprintf(_("Port: %d"), port) + "\n" + + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + + strprintf(_("(must be %d for mainnet)"), mainnetDefaultPort); + streamConfig.close(); + return false; + } + } else if(port == mainnetDefaultPort) { + strErr = _("Invalid port detected in masternode.conf") + "\n" + + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + + strprintf(_("(%d could be used only on mainnet)"), mainnetDefaultPort); + streamConfig.close(); + return false; + } + + + add(alias, ip, privKey, txHash, outputIndex); + } + + streamConfig.close(); + return true; +} From 04d7612f0ffd9f99ed4bd17cb09dca8e5c4cde98 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:01:29 -0400 Subject: [PATCH 0718/1324] Create masternodeconfig.h --- src/masternodeconfig.h | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/masternodeconfig.h diff --git a/src/masternodeconfig.h b/src/masternodeconfig.h new file mode 100644 index 00000000..6896d5c9 --- /dev/null +++ b/src/masternodeconfig.h @@ -0,0 +1,98 @@ +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef SRC_MASTERNODECONFIG_H_ +#define SRC_MASTERNODECONFIG_H_ + +class CMasternodeConfig; +extern CMasternodeConfig masternodeConfig; + +class CMasternodeConfig +{ + +public: + + class CMasternodeEntry { + + private: + std::string alias; + std::string ip; + std::string privKey; + std::string txHash; + std::string outputIndex; + public: + + CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { + this->alias = alias; + this->ip = ip; + this->privKey = privKey; + this->txHash = txHash; + this->outputIndex = outputIndex; + } + + const std::string& getAlias() const { + return alias; + } + + void setAlias(const std::string& alias) { + this->alias = alias; + } + + const std::string& getOutputIndex() const { + return outputIndex; + } + + void setOutputIndex(const std::string& outputIndex) { + this->outputIndex = outputIndex; + } + + const std::string& getPrivKey() const { + return privKey; + } + + void setPrivKey(const std::string& privKey) { + this->privKey = privKey; + } + + const std::string& getTxHash() const { + return txHash; + } + + void setTxHash(const std::string& txHash) { + this->txHash = txHash; + } + + const std::string& getIp() const { + return ip; + } + + void setIp(const std::string& ip) { + this->ip = ip; + } + }; + + CMasternodeConfig() { + entries = std::vector(); + } + + void clear(); + bool read(std::string& strErr); + void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); + + std::vector& getEntries() { + return entries; + } + + int getCount() { + return (int)entries.size(); + } + +private: + std::vector entries; + + +}; + + +#endif /* SRC_MASTERNODECONFIG_H_ */ From 6bce8e49817737ac023cf47e5f4942fbfe3a0362 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:02:40 -0400 Subject: [PATCH 0719/1324] Update Makefile.am --- src/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 75b13e39..6fe48323 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -251,7 +251,8 @@ BITCOIN_CORE_H = \ smartcontract-client.h \ smartcontract-server.h \ rpcpodc.h \ - rpcpog.h + rpcpog.h \ + masternodeconfig.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @@ -343,6 +344,7 @@ libhelpthehomeless_server_a_SOURCES = \ validation.cpp \ validationinterface.cpp \ versionbits.cpp \ + masternodeconfig.cpp \ $(BITCOIN_CORE_H) if ENABLE_ZMQ From 83f9ca7bd895e334f487b71bdd3d0302af8e2c6d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:13:45 -0400 Subject: [PATCH 0720/1324] Update util.cpp --- src/util.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index d7fa626e..8b9c5e8a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -650,6 +650,13 @@ boost::filesystem::path GetConfigFile(const std::string& confPath) return pathConfigFile; } +boost::filesystem::path GetMasternodeConfigFile() +{ + boost::filesystem::path pathConfigFile(GetArg("-mnconf", "masternode.conf")); + if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile; + return pathConfigFile; +} + void ReadConfigFile(const std::string& confPath) { boost::filesystem::ifstream streamConfig(GetConfigFile(confPath)); From b2f389f20266e2794176eb9dd96b072674985d1a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:14:30 -0400 Subject: [PATCH 0721/1324] Update util.h --- src/util.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.h b/src/util.h index 45294b3e..dd7b9394 100644 --- a/src/util.h +++ b/src/util.h @@ -140,6 +140,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); boost::filesystem::path GetBackupsDir(); void ClearDatadirCache(); boost::filesystem::path GetConfigFile(const std::string& confPath); +boost::filesystem::path GetMasternodeConfigFile(); #ifndef WIN32 boost::filesystem::path GetPidFile(); void CreatePidFile(const boost::filesystem::path &path, pid_t pid); From 10b3959520110b39ae7c2bb90246e35f58754eec Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:19:06 -0400 Subject: [PATCH 0722/1324] Create masternode.cpp --- src/masternode.cpp | 875 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 875 insertions(+) create mode 100644 src/masternode.cpp diff --git a/src/masternode.cpp b/src/masternode.cpp new file mode 100644 index 00000000..fa498a1c --- /dev/null +++ b/src/masternode.cpp @@ -0,0 +1,875 @@ +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "activemasternode.h" +#include "base58.h" +#include "init.h" +#include "netbase.h" +#include "masternode.h" +#include "masternode-payments.h" +#include "masternode-sync.h" +#include "masternodeman.h" +#include "messagesigner.h" +#include "script/standard.h" +#include "util.h" +#ifdef ENABLE_WALLET +#include "wallet/wallet.h" +#endif // ENABLE_WALLET + +#include + + +CMasternode::CMasternode() : + masternode_info_t{ MASTERNODE_ENABLED, PROTOCOL_VERSION, GetAdjustedTime()}, + fAllowMixingTx(true) +{} + +CMasternode::CMasternode(CService addr, COutPoint outpoint, CPubKey pubKeyCollateralAddress, CPubKey pubKeyMasternode, int nProtocolVersionIn) : + masternode_info_t{ MASTERNODE_ENABLED, nProtocolVersionIn, GetAdjustedTime(), + outpoint, addr, pubKeyCollateralAddress, pubKeyMasternode}, + fAllowMixingTx(true) +{} + +CMasternode::CMasternode(const CMasternode& other) : + masternode_info_t{other}, + lastPing(other.lastPing), + vchSig(other.vchSig), + nCollateralMinConfBlockHash(other.nCollateralMinConfBlockHash), + nBlockLastPaid(other.nBlockLastPaid), + nPoSeBanScore(other.nPoSeBanScore), + nPoSeBanHeight(other.nPoSeBanHeight), + fAllowMixingTx(other.fAllowMixingTx), + fUnitTest(other.fUnitTest) +{} + +CMasternode::CMasternode(const CMasternodeBroadcast& mnb) : + masternode_info_t{ mnb.nActiveState, mnb.nProtocolVersion, mnb.sigTime, + mnb.vin.prevout, mnb.addr, mnb.pubKeyCollateralAddress, mnb.pubKeyMasternode, + mnb.sigTime /*nTimeLastWatchdogVote*/}, + lastPing(mnb.lastPing), + vchSig(mnb.vchSig), + fAllowMixingTx(true) +{} + +// +// When a new masternode broadcast is sent, update our information +// +bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman) +{ + if(mnb.sigTime <= sigTime && !mnb.fRecovery) return false; + + pubKeyMasternode = mnb.pubKeyMasternode; + sigTime = mnb.sigTime; + vchSig = mnb.vchSig; + nProtocolVersion = mnb.nProtocolVersion; + addr = mnb.addr; + nPoSeBanScore = 0; + nPoSeBanHeight = 0; + nTimeLastChecked = 0; + int nDos = 0; + if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(this, true, nDos, connman))) { + lastPing = mnb.lastPing; + mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing)); + } + // if it matches our Masternode privkey... + if(fMasterNode && pubKeyMasternode == activeMasternode.pubKeyMasternode) { + nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; + if(nProtocolVersion == PROTOCOL_VERSION) { + // ... and PROTOCOL_VERSION, then we've been remotely activated ... + activeMasternode.ManageState(connman); + } else { + // ... otherwise we need to reactivate our node, do not add it to the list and do not relay + // but also do not ban the node we get this message from + LogPrintf("CMasternode::UpdateFromNewBroadcast -- wrong PROTOCOL_VERSION, re-activate your MN: message nProtocolVersion=%d PROTOCOL_VERSION=%d\n", nProtocolVersion, PROTOCOL_VERSION); + return false; + } + } + return true; +} + +// +// Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to +// the proof of work for that block. The further away they are the better, the furthest will win the election +// and get paid this block +// +arith_uint256 CMasternode::CalculateScore(const uint256& blockHash) +{ + // Deterministically calculate a "score" for a Masternode based on any given (block)hash + CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + ss << vin.prevout << nCollateralMinConfBlockHash << blockHash; + return UintToArith256(ss.GetHash()); +} + +CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint) +{ + int nHeight; + return CheckCollateral(outpoint, nHeight); +} + +CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, int& nHeightRet) +{ + AssertLockHeld(cs_main); + + Coin coin; + if(!GetUTXOCoin(outpoint, coin)) { + return COLLATERAL_UTXO_NOT_FOUND; + } + + if(coin.out.nValue != 1000000 * COIN) { + return COLLATERAL_INVALID_AMOUNT; + } + + nHeightRet = coin.nHeight; + return COLLATERAL_OK; +} + +void CMasternode::Check(bool fForce) +{ + LOCK(cs); + + if(ShutdownRequested()) return; + + if(!fForce && (GetTime() - nTimeLastChecked < MASTERNODE_CHECK_SECONDS)) return; + nTimeLastChecked = GetTime(); + + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state\n", vin.prevout.ToStringShort(), GetStateString()); + + //once spent, stop doing the checks + if(IsOutpointSpent()) return; + + int nHeight = 0; + if(!fUnitTest) { + TRY_LOCK(cs_main, lockMain); + if(!lockMain) return; + + CollateralStatus err = CheckCollateral(vin.prevout); + if (err == COLLATERAL_UTXO_NOT_FOUND) { + nActiveState = MASTERNODE_OUTPOINT_SPENT; + LogPrint("masternode", "CMasternode::Check -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort()); + return; + } + + nHeight = chainActive.Height(); + } + + if(IsPoSeBanned()) { + if(nHeight < nPoSeBanHeight) return; // too early? + // Otherwise give it a chance to proceed further to do all the usual checks and to change its state. + // Masternode still will be on the edge and can be banned back easily if it keeps ignoring mnverify + // or connect attempts. Will require few mnverify messages to strengthen its position in mn list. + LogPrintf("CMasternode::Check -- Masternode %s is unbanned and back in list now\n", vin.prevout.ToStringShort()); + DecreasePoSeBanScore(); + } else if(nPoSeBanScore >= MASTERNODE_POSE_BAN_MAX_SCORE) { + nActiveState = MASTERNODE_POSE_BAN; + // ban for the whole payment cycle + nPoSeBanHeight = nHeight + mnodeman.size(); + LogPrintf("CMasternode::Check -- Masternode %s is banned till block %d now\n", vin.prevout.ToStringShort(), nPoSeBanHeight); + return; + } + + int nActiveStatePrev = nActiveState; + bool fOurMasternode = fMasterNode && activeMasternode.pubKeyMasternode == pubKeyMasternode; + + // masternode doesn't meet payment protocol requirements ... + bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() || + // or it's our own node and we just updated it to the new protocol but we are still waiting for activation ... + (fOurMasternode && nProtocolVersion < PROTOCOL_VERSION); + + if(fRequireUpdate) { + nActiveState = MASTERNODE_UPDATE_REQUIRED; + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } + return; + } + + // keep old masternodes on start, give them a chance to receive updates... + bool fWaitForPing = !masternodeSync.IsMasternodeListSynced() && !IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS); + + if(fWaitForPing && !fOurMasternode) { + // ...but if it was already expired before the initial check - return right away + if(IsExpired() || IsWatchdogExpired() || IsNewStartRequired()) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state, waiting for ping\n", vin.prevout.ToStringShort(), GetStateString()); + return; + } + } + + // don't expire if we are still in "waiting for ping" mode unless it's our own masternode + if(!fWaitForPing || fOurMasternode) { + + if(!IsPingedWithin(MASTERNODE_NEW_START_REQUIRED_SECONDS)) { + nActiveState = MASTERNODE_NEW_START_REQUIRED; + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } + return; + } + + bool fWatchdogActive = masternodeSync.IsSynced() && mnodeman.IsWatchdogActive(); + bool fWatchdogExpired = (fWatchdogActive && ((GetAdjustedTime() - nTimeLastWatchdogVote) > MASTERNODE_WATCHDOG_MAX_SECONDS)); + + LogPrint("masternode", "CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetAdjustedTime()=%d, fWatchdogExpired=%d\n", + vin.prevout.ToStringShort(), nTimeLastWatchdogVote, GetAdjustedTime(), fWatchdogExpired); + + if(fWatchdogExpired) { + nActiveState = MASTERNODE_WATCHDOG_EXPIRED; + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } + return; + } + + if(!IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS)) { + nActiveState = MASTERNODE_EXPIRED; + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } + return; + } + } + + if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS) { + nActiveState = MASTERNODE_PRE_ENABLED; + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } + return; + } + + nActiveState = MASTERNODE_ENABLED; // OK + if(nActiveStatePrev != nActiveState) { + LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); + } +} + +bool CMasternode::IsInputAssociatedWithPubkey() +{ + CScript payee; + payee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); + + CTransaction tx; + uint256 hash; + if(GetTransaction(vin.prevout.hash, tx, Params().GetConsensus(), hash, true)) { + BOOST_FOREACH(CTxOut out, tx.vout) + if(out.nValue == 1000000*COIN && out.scriptPubKey == payee) return true; + } + + return false; +} + +bool CMasternode::IsValidNetAddr() +{ + return IsValidNetAddr(addr); +} + +bool CMasternode::IsValidNetAddr(CService addrIn) +{ + // TODO: regtest is fine with any addresses for now, + // should probably be a bit smarter if one day we start to implement tests for this + return Params().NetworkIDString() == CBaseChainParams::REGTEST || + (addrIn.IsIPv4() && IsReachable(addrIn) && addrIn.IsRoutable()); +} + +masternode_info_t CMasternode::GetInfo() +{ + masternode_info_t info{*this}; + info.nTimeLastPing = lastPing.sigTime; + info.fInfoValid = true; + return info; +} + +std::string CMasternode::StateToString(int nStateIn) +{ + switch(nStateIn) { + case MASTERNODE_PRE_ENABLED: return "PRE_ENABLED"; + case MASTERNODE_ENABLED: return "ENABLED"; + case MASTERNODE_EXPIRED: return "EXPIRED"; + case MASTERNODE_OUTPOINT_SPENT: return "OUTPOINT_SPENT"; + case MASTERNODE_UPDATE_REQUIRED: return "UPDATE_REQUIRED"; + case MASTERNODE_WATCHDOG_EXPIRED: return "WATCHDOG_EXPIRED"; + case MASTERNODE_NEW_START_REQUIRED: return "NEW_START_REQUIRED"; + case MASTERNODE_POSE_BAN: return "POSE_BAN"; + default: return "UNKNOWN"; + } +} + +std::string CMasternode::GetStateString() const +{ + return StateToString(nActiveState); +} + +std::string CMasternode::GetStatus() const +{ + // TODO: return smth a bit more human readable here + return GetStateString(); +} + +void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack) +{ + if(!pindex) return; + + const CBlockIndex *BlockReading = pindex; + + CScript mnpayee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); + // LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s\n", vin.prevout.ToStringShort()); + + LOCK(cs_mapMasternodeBlocks); + + for (int i = 0; BlockReading && BlockReading->nHeight > nBlockLastPaid && i < nMaxBlocksToScanBack; i++) { + if(mnpayments.mapMasternodeBlocks.count(BlockReading->nHeight) && + mnpayments.mapMasternodeBlocks[BlockReading->nHeight].HasPayeeWithVotes(mnpayee, 2)) + { + CBlock block; + if(!ReadBlockFromDisk(block, BlockReading, Params().GetConsensus())) // shouldn't really happen + continue; + + CAmount nMasternodePayment = GetMasternodePayment(BlockReading->nHeight, block.vtx[0].GetValueOut()); + + BOOST_FOREACH(CTxOut txout, block.vtx[0].vout) + if(mnpayee == txout.scriptPubKey && nMasternodePayment == txout.nValue) { + nBlockLastPaid = BlockReading->nHeight; + nTimeLastPaid = BlockReading->nTime; + LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- found new %d\n", vin.prevout.ToStringShort(), nBlockLastPaid); + return; + } + } + + if (BlockReading->pprev == NULL) { assert(BlockReading); break; } + BlockReading = BlockReading->pprev; + } + + // Last payment for this masternode wasn't found in latest mnpayments blocks + // or it was found in mnpayments blocks but wasn't found in the blockchain. + // LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- keeping old %d\n", vin.prevout.ToStringShort(), nBlockLastPaid); +} + +#ifdef ENABLE_WALLET +bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline) +{ + COutPoint outpoint; + CPubKey pubKeyCollateralAddressNew; + CKey keyCollateralAddressNew; + CPubKey pubKeyMasternodeNew; + CKey keyMasternodeNew; + + auto Log = [&strErrorRet](std::string sErr)->bool + { + strErrorRet = sErr; + LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); + return false; + }; + + //need correct blocks to send ping + if (!fOffline && !masternodeSync.IsBlockchainSynced()) + return Log("Sync in progress. Must wait until sync is complete to start Masternode"); + + if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) + return Log(strprintf("Invalid masternode key %s", strKeyMasternode)); + + if (!pwalletMain->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex)) + return Log(strprintf("Could not allocate outpoint %s:%s for masternode %s", strTxHash, strOutputIndex, strService)); + + CService service; + if (!Lookup(strService.c_str(), service, 0, false)) + return Log(strprintf("Invalid address %s for masternode.", strService)); + int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); + if (Params().NetworkIDString() == CBaseChainParams::MAIN) { + if (service.GetPort() != mainnetDefaultPort) + return Log(strprintf("Invalid port %u for masternode %s, only %d is supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort)); + } else if (service.GetPort() == mainnetDefaultPort) + return Log(strprintf("Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort)); + + return Create(outpoint, service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet); +} + +bool CMasternodeBroadcast::Create(const COutPoint& outpoint, const CService& service, const CKey& keyCollateralAddressNew, const CPubKey& pubKeyCollateralAddressNew, const CKey& keyMasternodeNew, const CPubKey& pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet) +{ + // wait for reindex and/or import to finish + if (fImporting || fReindex) return false; + + LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", + CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), + pubKeyMasternodeNew.GetID().ToString()); + + auto Log = [&strErrorRet,&mnbRet](std::string sErr)->bool + { + strErrorRet = sErr; + LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); + mnbRet = CMasternodeBroadcast(); + return false; + }; + + CMasternodePing mnp(outpoint); + if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) + return Log(strprintf("Failed to sign ping, masternode=%s", outpoint.ToStringShort())); + + mnbRet = CMasternodeBroadcast(service, outpoint, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); + + if (!mnbRet.IsValidNetAddr()) + return Log(strprintf("Invalid IP address, masternode=%s", outpoint.ToStringShort())); + + mnbRet.lastPing = mnp; + if (!mnbRet.Sign(keyCollateralAddressNew)) + return Log(strprintf("Failed to sign broadcast, masternode=%s", outpoint.ToStringShort())); + + return true; +} +#endif // ENABLE_WALLET + +bool CMasternodeBroadcast::SimpleCheck(int& nDos) +{ + nDos = 0; + + // make sure addr is valid + if(!IsValidNetAddr()) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- Invalid addr, rejected: masternode=%s addr=%s\n", + vin.prevout.ToStringShort(), addr.ToString()); + return false; + } + + // make sure signature isn't in the future (past is OK) + if (sigTime > GetAdjustedTime() + 60 * 60) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- Signature rejected, too far into the future: masternode=%s\n", vin.prevout.ToStringShort()); + nDos = 1; + return false; + } + + // empty ping or incorrect sigTime/unknown blockhash + if(lastPing == CMasternodePing() || !lastPing.SimpleCheck(nDos)) { + // one of us is probably forked or smth, just mark it as expired and check the rest of the rules + nActiveState = MASTERNODE_EXPIRED; + } + + if(nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- ignoring outdated Masternode: masternode=%s nProtocolVersion=%d\n", vin.prevout.ToStringShort(), nProtocolVersion); + return false; + } + + CScript pubkeyScript; + pubkeyScript = GetScriptForDestination(pubKeyCollateralAddress.GetID()); + + if(pubkeyScript.size() != 25) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyCollateralAddress has the wrong size\n"); + nDos = 100; + return false; + } + + CScript pubkeyScript2; + pubkeyScript2 = GetScriptForDestination(pubKeyMasternode.GetID()); + + if(pubkeyScript2.size() != 25) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyMasternode has the wrong size\n"); + nDos = 100; + return false; + } + + if(!vin.scriptSig.empty()) { + LogPrintf("CMasternodeBroadcast::SimpleCheck -- Ignore Not Empty ScriptSig %s\n",vin.ToString()); + nDos = 100; + return false; + } + + int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); + if(Params().NetworkIDString() == CBaseChainParams::MAIN) { + if(addr.GetPort() != mainnetDefaultPort) return false; + } else if(addr.GetPort() == mainnetDefaultPort) return false; + + return true; +} + +bool CMasternodeBroadcast::Update(CMasternode* pmn, int& nDos, CConnman& connman) +{ + nDos = 0; + + if(pmn->sigTime == sigTime && !fRecovery) { + // mapSeenMasternodeBroadcast in CMasternodeMan::CheckMnbAndUpdateMasternodeList should filter legit duplicates + // but this still can happen if we just started, which is ok, just do nothing here. + return false; + } + + // this broadcast is older than the one that we already have - it's bad and should never happen + // unless someone is doing something fishy + if(pmn->sigTime > sigTime) { + LogPrintf("CMasternodeBroadcast::Update -- Bad sigTime %d (existing broadcast is at %d) for Masternode %s %s\n", + sigTime, pmn->sigTime, vin.prevout.ToStringShort(), addr.ToString()); + return false; + } + + pmn->Check(); + + // masternode is banned by PoSe + if(pmn->IsPoSeBanned()) { + LogPrintf("CMasternodeBroadcast::Update -- Banned by PoSe, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + // IsVnAssociatedWithPubkey is validated once in CheckOutpoint, after that they just need to match + if(pmn->pubKeyCollateralAddress != pubKeyCollateralAddress) { + LogPrintf("CMasternodeBroadcast::Update -- Got mismatched pubKeyCollateralAddress and vin\n"); + nDos = 33; + return false; + } + + if (!CheckSignature(nDos)) { + LogPrintf("CMasternodeBroadcast::Update -- CheckSignature() failed, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + // if ther was no masternode broadcast recently or if it matches our Masternode privkey... + if(!pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS) || (fMasterNode && pubKeyMasternode == activeMasternode.pubKeyMasternode)) { + // take the newest entry + LogPrintf("CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n", addr.ToString()); + if(pmn->UpdateFromNewBroadcast(*this, connman)) { + pmn->Check(); + Relay(connman); + } + masternodeSync.BumpAssetLastTime("CMasternodeBroadcast::Update"); + } + + return true; +} + +bool CMasternodeBroadcast::CheckOutpoint(int& nDos) +{ + // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey) + // so nothing to do here for us + if(fMasterNode && vin.prevout == activeMasternode.outpoint && pubKeyMasternode == activeMasternode.pubKeyMasternode) { + return false; + } + + if (!CheckSignature(nDos)) { + LogPrintf("CMasternodeBroadcast::CheckOutpoint -- CheckSignature() failed, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + { + TRY_LOCK(cs_main, lockMain); + if(!lockMain) { + // not mnb fault, let it to be checked again later + LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to aquire lock, addr=%s", addr.ToString()); + mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); + return false; + } + + int nHeight; + CollateralStatus err = CheckCollateral(vin.prevout, nHeight); + if (err == COLLATERAL_UTXO_NOT_FOUND) { + LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + if (err == COLLATERAL_INVALID_AMOUNT) { + LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should have 1000 DASH, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + if(chainActive.Height() - nHeight + 1 < Params().GetConsensus().nMasternodeMinimumConfirmations) { + LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO must have at least %d confirmations, masternode=%s\n", + Params().GetConsensus().nMasternodeMinimumConfirmations, vin.prevout.ToStringShort()); + // maybe we miss few blocks, let this mnb to be checked again later + mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); + return false; + } + // remember the hash of the block where masternode collateral had minimum required confirmations + nCollateralMinConfBlockHash = chainActive[nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]->GetBlockHash(); + } + + LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO verified\n"); + + // make sure the input that was signed in masternode broadcast message is related to the transaction + // that spawned the Masternode - this is expensive, so it's only done once per Masternode + if(!IsInputAssociatedWithPubkey()) { + LogPrintf("CMasternodeMan::CheckOutpoint -- Got mismatched pubKeyCollateralAddress and vin\n"); + nDos = 33; + return false; + } + + // verify that sig time is legit in past + // should be at least not earlier than block when 1000 DASH tx got nMasternodeMinimumConfirmations + uint256 hashBlock = uint256(); + CTransaction tx2; + GetTransaction(vin.prevout.hash, tx2, Params().GetConsensus(), hashBlock, true); + { + LOCK(cs_main); + BlockMap::iterator mi = mapBlockIndex.find(hashBlock); + if (mi != mapBlockIndex.end() && (*mi).second) { + CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation + CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]; // block where tx got nMasternodeMinimumConfirmations + if(pConfIndex->GetBlockTime() > sigTime) { + LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Bad sigTime %d (%d conf block is at %d) for Masternode %s %s\n", + sigTime, Params().GetConsensus().nMasternodeMinimumConfirmations, pConfIndex->GetBlockTime(), vin.prevout.ToStringShort(), addr.ToString()); + return false; + } + } + } + + return true; +} + +bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress) +{ + std::string strError; + std::string strMessage; + + sigTime = GetAdjustedTime(); + + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + + boost::lexical_cast(nProtocolVersion); + + if(!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) { + LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n"); + return false; + } + + if(!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)) { + LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError); + return false; + } + + return true; +} + +bool CMasternodeBroadcast::CheckSignature(int& nDos) +{ + std::string strMessage; + std::string strError = ""; + nDos = 0; + + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + + boost::lexical_cast(nProtocolVersion); + + LogPrint("masternode", "CMasternodeBroadcast::CheckSignature -- strMessage: %s pubKeyCollateralAddress address: %s sig: %s\n", strMessage, CBitcoinAddress(pubKeyCollateralAddress.GetID()).ToString(), EncodeBase64(&vchSig[0], vchSig.size())); + + if(!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ + LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError); + nDos = 100; + return false; + } + + return true; +} + +void CMasternodeBroadcast::Relay(CConnman& connman) +{ + // Do not relay until fully synced + if(!masternodeSync.IsSynced()) { + LogPrint("masternode", "CMasternodeBroadcast::Relay -- won't relay until fully synced\n"); + return; + } + + CInv inv(MSG_MASTERNODE_ANNOUNCE, GetHash()); + connman.RelayInv(inv); +} + +CMasternodePing::CMasternodePing(const COutPoint& outpoint) +{ + LOCK(cs_main); + if (!chainActive.Tip() || chainActive.Height() < 12) return; + + vin = CTxIn(outpoint); + blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash(); + sigTime = GetAdjustedTime(); +} + +bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) +{ + std::string strError; + std::string strMasterNodeSignMessage; + + // TODO: add sentinel data + sigTime = GetAdjustedTime(); + std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); + + if(!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) { + LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n"); + return false; + } + + if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { + LogPrintf("CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError); + return false; + } + + return true; +} + +bool CMasternodePing::CheckSignature(CPubKey& pubKeyMasternode, int &nDos) +{ + // TODO: add sentinel data + std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); + std::string strError = ""; + nDos = 0; + + if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { + LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", vin.prevout.ToStringShort(), strError); + nDos = 33; + return false; + } + return true; +} + +bool CMasternodePing::SimpleCheck(int& nDos) +{ + // don't ban by default + nDos = 0; + + if (sigTime > GetAdjustedTime() + 60 * 60) { + LogPrintf("CMasternodePing::SimpleCheck -- Signature rejected, too far into the future, masternode=%s\n", vin.prevout.ToStringShort()); + nDos = 1; + return false; + } + + { + AssertLockHeld(cs_main); + BlockMap::iterator mi = mapBlockIndex.find(blockHash); + if (mi == mapBlockIndex.end()) { + LogPrint("masternode", "CMasternodePing::SimpleCheck -- Masternode ping is invalid, unknown block hash: masternode=%s blockHash=%s\n", vin.prevout.ToStringShort(), blockHash.ToString()); + // maybe we stuck or forked so we shouldn't ban this node, just fail to accept this ping + // TODO: or should we also request this block? + return false; + } + } + LogPrint("masternode", "CMasternodePing::SimpleCheck -- Masternode ping verified: masternode=%s blockHash=%s sigTime=%d\n", vin.prevout.ToStringShort(), blockHash.ToString(), sigTime); + return true; +} + +bool CMasternodePing::CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman) +{ + // don't ban by default + nDos = 0; + + if (!SimpleCheck(nDos)) { + return false; + } + + if (pmn == NULL) { + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Couldn't find Masternode entry, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + if(!fFromNewBroadcast) { + if (pmn->IsUpdateRequired()) { + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- masternode protocol is outdated, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + + if (pmn->IsNewStartRequired()) { + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- masternode is completely expired, new start is required, masternode=%s\n", vin.prevout.ToStringShort()); + return false; + } + } + + { + LOCK(cs_main); + BlockMap::iterator mi = mapBlockIndex.find(blockHash); + if ((*mi).second && (*mi).second->nHeight < chainActive.Height() - 24) { + LogPrintf("CMasternodePing::CheckAndUpdate -- Masternode ping is invalid, block hash is too old: masternode=%s blockHash=%s\n", vin.prevout.ToStringShort(), blockHash.ToString()); + // nDos = 1; + return false; + } + } + + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- New ping: masternode=%s blockHash=%s sigTime=%d\n", vin.prevout.ToStringShort(), blockHash.ToString(), sigTime); + + // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.prevout.ToStringShort()); + // update only if there is no known ping for this masternode or + // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one + if (pmn->IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS - 60, sigTime)) { + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping arrived too early, masternode=%s\n", vin.prevout.ToStringShort()); + //nDos = 1; //disable, this is happening frequently and causing banned peers + return false; + } + + if (!CheckSignature(pmn->pubKeyMasternode, nDos)) return false; + + // so, ping seems to be ok + + // if we are still syncing and there was no known ping for this mn for quite a while + // (NOTE: assuming that MASTERNODE_EXPIRATION_SECONDS/2 should be enough to finish mn list sync) + if(!masternodeSync.IsMasternodeListSynced() && !pmn->IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS/2)) { + // let's bump sync timeout + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- bumping sync timeout, masternode=%s\n", vin.prevout.ToStringShort()); + masternodeSync.BumpAssetLastTime("CMasternodePing::CheckAndUpdate"); + } + + // let's store this ping as the last one + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping accepted, masternode=%s\n", vin.prevout.ToStringShort()); + pmn->lastPing = *this; + + // and update mnodeman.mapSeenMasternodeBroadcast.lastPing which is probably outdated + CMasternodeBroadcast mnb(*pmn); + uint256 hash = mnb.GetHash(); + if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) { + mnodeman.mapSeenMasternodeBroadcast[hash].second.lastPing = *this; + } + + // force update, ignoring cache + pmn->Check(true); + // relay ping for nodes in ENABLED/EXPIRED/WATCHDOG_EXPIRED state only, skip everyone else + if (!pmn->IsEnabled() && !pmn->IsExpired() && !pmn->IsWatchdogExpired()) return false; + + LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping acceepted and relayed, masternode=%s\n", vin.prevout.ToStringShort()); + Relay(connman); + + return true; +} + +void CMasternodePing::Relay(CConnman& connman) +{ + // Do not relay until fully synced + if(!masternodeSync.IsSynced()) { + LogPrint("masternode", "CMasternodePing::Relay -- won't relay until fully synced\n"); + return; + } + + CInv inv(MSG_MASTERNODE_PING, GetHash()); + connman.RelayInv(inv); +} + +void CMasternode::AddGovernanceVote(uint256 nGovernanceObjectHash) +{ + if(mapGovernanceObjectsVotedOn.count(nGovernanceObjectHash)) { + mapGovernanceObjectsVotedOn[nGovernanceObjectHash]++; + } else { + mapGovernanceObjectsVotedOn.insert(std::make_pair(nGovernanceObjectHash, 1)); + } +} + +void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash) +{ + std::map::iterator it = mapGovernanceObjectsVotedOn.find(nGovernanceObjectHash); + if(it == mapGovernanceObjectsVotedOn.end()) { + return; + } + mapGovernanceObjectsVotedOn.erase(it); +} + +void CMasternode::UpdateWatchdogVoteTime(uint64_t nVoteTime) +{ + LOCK(cs); + nTimeLastWatchdogVote = (nVoteTime == 0) ? GetAdjustedTime() : nVoteTime; +} + +/** +* FLAG GOVERNANCE ITEMS AS DIRTY +* +* - When masternode come and go on the network, we must flag the items they voted on to recalc it's cached flags +* +*/ +void CMasternode::FlagGovernanceItemsAsDirty() +{ + std::vector vecDirty; + { + std::map::iterator it = mapGovernanceObjectsVotedOn.begin(); + while(it != mapGovernanceObjectsVotedOn.end()) { + vecDirty.push_back(it->first); + ++it; + } + } + for(size_t i = 0; i < vecDirty.size(); ++i) { + mnodeman.AddDirtyGovernanceObjectHash(vecDirty[i]); + } +} From 3ab0eb2d1819192d0440eeb2010b46a82957ed12 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:19:50 -0400 Subject: [PATCH 0723/1324] Create masternode.h --- src/masternode.h | 410 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 src/masternode.h diff --git a/src/masternode.h b/src/masternode.h new file mode 100644 index 00000000..4bcc2e1e --- /dev/null +++ b/src/masternode.h @@ -0,0 +1,410 @@ +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef MASTERNODE_H +#define MASTERNODE_H + +#include "key.h" +#include "validation.h" +#include "spork.h" + +class CMasternode; +class CMasternodeBroadcast; +class CConnman; + +static const int MASTERNODE_CHECK_SECONDS = 5; +static const int MASTERNODE_MIN_MNB_SECONDS = 5 * 60; +static const int MASTERNODE_MIN_MNP_SECONDS = 10 * 60; +static const int MASTERNODE_EXPIRATION_SECONDS = 65 * 60; +static const int MASTERNODE_WATCHDOG_MAX_SECONDS = 120 * 60; +static const int MASTERNODE_NEW_START_REQUIRED_SECONDS = 180 * 60; + +static const int MASTERNODE_POSE_BAN_MAX_SCORE = 5; + +// +// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network +// + +// sentinel version before sentinel ping implementation +#define DEFAULT_SENTINEL_VERSION 0x010001 + +class CMasternodePing +{ +public: + CTxIn vin{}; + uint256 blockHash{}; + int64_t sigTime{}; //mnb message times + std::vector vchSig{}; + bool fSentinelIsCurrent = false; // true if last sentinel ping was actual + // MSB is always 0, other 3 bits corresponds to x.x.x version scheme + uint32_t nSentinelVersion{DEFAULT_SENTINEL_VERSION}; + + CMasternodePing() = default; + + CMasternodePing(const COutPoint& outpoint); + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(vin); + READWRITE(blockHash); + READWRITE(sigTime); + READWRITE(vchSig); + if(ser_action.ForRead() && (s.size() == 0)) + { + fSentinelIsCurrent = false; + nSentinelVersion = DEFAULT_SENTINEL_VERSION; + return; + } + READWRITE(fSentinelIsCurrent); + READWRITE(nSentinelVersion); + } + + uint256 GetHash() const + { + CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + ss << vin; + ss << sigTime; + return ss.GetHash(); + } + + bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; } + + bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); + bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos); + bool SimpleCheck(int& nDos); + bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman); + void Relay(CConnman& connman); +}; + +inline bool operator==(const CMasternodePing& a, const CMasternodePing& b) +{ + return a.vin == b.vin && a.blockHash == b.blockHash; +} +inline bool operator!=(const CMasternodePing& a, const CMasternodePing& b) +{ + return !(a == b); +} + +struct masternode_info_t +{ + // Note: all these constructors can be removed once C++14 is enabled. + // (in C++11 the member initializers wrongly disqualify this as an aggregate) + masternode_info_t() = default; + masternode_info_t(masternode_info_t const&) = default; + + masternode_info_t(int activeState, int protoVer, int64_t sTime) : + nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime} {} + + masternode_info_t(int activeState, int protoVer, int64_t sTime, + COutPoint const& outpoint, CService const& addr, + CPubKey const& pkCollAddr, CPubKey const& pkMN, + int64_t tWatchdogV = 0) : + nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime}, + vin{outpoint}, addr{addr}, + pubKeyCollateralAddress{pkCollAddr}, pubKeyMasternode{pkMN}, + nTimeLastWatchdogVote{tWatchdogV} {} + + int nActiveState = 0; + int nProtocolVersion = 0; + int64_t sigTime = 0; //mnb message time + + CTxIn vin{}; + CService addr{}; + CPubKey pubKeyCollateralAddress{}; + CPubKey pubKeyMasternode{}; + int64_t nTimeLastWatchdogVote = 0; + + int64_t nLastDsq = 0; //the dsq count from the last dsq broadcast of this node + int64_t nTimeLastChecked = 0; + int64_t nTimeLastPaid = 0; + int64_t nTimeLastPing = 0; //* not in CMN + bool fInfoValid = false; //* not in CMN +}; + +// +// The Masternode Class. For managing the Darksend process. It contains the input of the 1000DRK, signature to prove +// it's the one who own that ip address and code for calculating the payment election. +// +class CMasternode : public masternode_info_t +{ +private: + // critical section to protect the inner data structures + mutable CCriticalSection cs; + +public: + enum state { + MASTERNODE_PRE_ENABLED, + MASTERNODE_ENABLED, + MASTERNODE_EXPIRED, + MASTERNODE_OUTPOINT_SPENT, + MASTERNODE_UPDATE_REQUIRED, + MASTERNODE_WATCHDOG_EXPIRED, + MASTERNODE_NEW_START_REQUIRED, + MASTERNODE_POSE_BAN + }; + + enum CollateralStatus { + COLLATERAL_OK, + COLLATERAL_UTXO_NOT_FOUND, + COLLATERAL_INVALID_AMOUNT + }; + + + CMasternodePing lastPing{}; + std::vector vchSig{}; + + uint256 nCollateralMinConfBlockHash{}; + int nBlockLastPaid{}; + int nPoSeBanScore{}; + int nPoSeBanHeight{}; + bool fAllowMixingTx{}; + bool fUnitTest = false; + + // KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION + std::map mapGovernanceObjectsVotedOn; + + CMasternode(); + CMasternode(const CMasternode& other); + CMasternode(const CMasternodeBroadcast& mnb); + CMasternode(CService addrNew, COutPoint outpointNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn); + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + LOCK(cs); + READWRITE(vin); + READWRITE(addr); + READWRITE(pubKeyCollateralAddress); + READWRITE(pubKeyMasternode); + READWRITE(lastPing); + READWRITE(vchSig); + READWRITE(sigTime); + READWRITE(nLastDsq); + READWRITE(nTimeLastChecked); + READWRITE(nTimeLastPaid); + READWRITE(nTimeLastWatchdogVote); + READWRITE(nActiveState); + READWRITE(nCollateralMinConfBlockHash); + READWRITE(nBlockLastPaid); + READWRITE(nProtocolVersion); + READWRITE(nPoSeBanScore); + READWRITE(nPoSeBanHeight); + READWRITE(fAllowMixingTx); + READWRITE(fUnitTest); + READWRITE(mapGovernanceObjectsVotedOn); + } + + // CALCULATE A RANK AGAINST OF GIVEN BLOCK + arith_uint256 CalculateScore(const uint256& blockHash); + + bool UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman); + + static CollateralStatus CheckCollateral(const COutPoint& outpoint); + static CollateralStatus CheckCollateral(const COutPoint& outpoint, int& nHeightRet); + void Check(bool fForce = false); + + bool IsBroadcastedWithin(int nSeconds) { return GetAdjustedTime() - sigTime < nSeconds; } + + bool IsPingedWithin(int nSeconds, int64_t nTimeToCheckAt = -1) + { + if(lastPing == CMasternodePing()) return false; + + if(nTimeToCheckAt == -1) { + nTimeToCheckAt = GetAdjustedTime(); + } + return nTimeToCheckAt - lastPing.sigTime < nSeconds; + } + + bool IsEnabled() { return nActiveState == MASTERNODE_ENABLED; } + bool IsPreEnabled() { return nActiveState == MASTERNODE_PRE_ENABLED; } + bool IsPoSeBanned() { return nActiveState == MASTERNODE_POSE_BAN; } + // NOTE: this one relies on nPoSeBanScore, not on nActiveState as everything else here + bool IsPoSeVerified() { return nPoSeBanScore <= -MASTERNODE_POSE_BAN_MAX_SCORE; } + bool IsExpired() { return nActiveState == MASTERNODE_EXPIRED; } + bool IsOutpointSpent() { return nActiveState == MASTERNODE_OUTPOINT_SPENT; } + bool IsUpdateRequired() { return nActiveState == MASTERNODE_UPDATE_REQUIRED; } + bool IsWatchdogExpired() { return nActiveState == MASTERNODE_WATCHDOG_EXPIRED; } + bool IsNewStartRequired() { return nActiveState == MASTERNODE_NEW_START_REQUIRED; } + + static bool IsValidStateForAutoStart(int nActiveStateIn) + { + return nActiveStateIn == MASTERNODE_ENABLED || + nActiveStateIn == MASTERNODE_PRE_ENABLED || + nActiveStateIn == MASTERNODE_EXPIRED || + nActiveStateIn == MASTERNODE_WATCHDOG_EXPIRED; + } + + bool IsValidForPayment() + { + if(nActiveState == MASTERNODE_ENABLED) { + return true; + } + if(!sporkManager.IsSporkActive(SPORK_14_REQUIRE_SENTINEL_FLAG) && + (nActiveState == MASTERNODE_WATCHDOG_EXPIRED)) { + return true; + } + + return false; + } + + /// Is the input associated with collateral public key? (and there is 1000 DASH - checking if valid masternode) + bool IsInputAssociatedWithPubkey(); + + bool IsValidNetAddr(); + static bool IsValidNetAddr(CService addrIn); + + void IncreasePoSeBanScore() { if(nPoSeBanScore < MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore++; } + void DecreasePoSeBanScore() { if(nPoSeBanScore > -MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore--; } + void PoSeBan() { nPoSeBanScore = MASTERNODE_POSE_BAN_MAX_SCORE; } + + masternode_info_t GetInfo(); + + static std::string StateToString(int nStateIn); + std::string GetStateString() const; + std::string GetStatus() const; + + int GetLastPaidTime() { return nTimeLastPaid; } + int GetLastPaidBlock() { return nBlockLastPaid; } + void UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack); + + // KEEP TRACK OF EACH GOVERNANCE ITEM INCASE THIS NODE GOES OFFLINE, SO WE CAN RECALC THEIR STATUS + void AddGovernanceVote(uint256 nGovernanceObjectHash); + // RECALCULATE CACHED STATUS FLAGS FOR ALL AFFECTED OBJECTS + void FlagGovernanceItemsAsDirty(); + + void RemoveGovernanceObject(uint256 nGovernanceObjectHash); + + void UpdateWatchdogVoteTime(uint64_t nVoteTime = 0); + + CMasternode& operator=(CMasternode const& from) + { + static_cast(*this)=from; + lastPing = from.lastPing; + vchSig = from.vchSig; + nCollateralMinConfBlockHash = from.nCollateralMinConfBlockHash; + nBlockLastPaid = from.nBlockLastPaid; + nPoSeBanScore = from.nPoSeBanScore; + nPoSeBanHeight = from.nPoSeBanHeight; + fAllowMixingTx = from.fAllowMixingTx; + fUnitTest = from.fUnitTest; + mapGovernanceObjectsVotedOn = from.mapGovernanceObjectsVotedOn; + return *this; + } +}; + +inline bool operator==(const CMasternode& a, const CMasternode& b) +{ + return a.vin == b.vin; +} +inline bool operator!=(const CMasternode& a, const CMasternode& b) +{ + return !(a.vin == b.vin); +} + + +// +// The Masternode Broadcast Class : Contains a different serialize method for sending masternodes through the network +// + +class CMasternodeBroadcast : public CMasternode +{ +public: + + bool fRecovery; + + CMasternodeBroadcast() : CMasternode(), fRecovery(false) {} + CMasternodeBroadcast(const CMasternode& mn) : CMasternode(mn), fRecovery(false) {} + CMasternodeBroadcast(CService addrNew, COutPoint outpointNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn) : + CMasternode(addrNew, outpointNew, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nProtocolVersionIn), fRecovery(false) {} + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(vin); + READWRITE(addr); + READWRITE(pubKeyCollateralAddress); + READWRITE(pubKeyMasternode); + READWRITE(vchSig); + READWRITE(sigTime); + READWRITE(nProtocolVersion); + READWRITE(lastPing); + } + + uint256 GetHash() const + { + CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + ss << vin; + ss << pubKeyCollateralAddress; + ss << sigTime; + return ss.GetHash(); + } + + /// Create Masternode broadcast, needs to be relayed manually after that + static bool Create(const COutPoint& outpoint, const CService& service, const CKey& keyCollateralAddressNew, const CPubKey& pubKeyCollateralAddressNew, const CKey& keyMasternodeNew, const CPubKey& pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet); + static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline = false); + + bool SimpleCheck(int& nDos); + bool Update(CMasternode* pmn, int& nDos, CConnman& connman); + bool CheckOutpoint(int& nDos); + + bool Sign(const CKey& keyCollateralAddress); + bool CheckSignature(int& nDos); + void Relay(CConnman& connman); +}; + +class CMasternodeVerification +{ +public: + CTxIn vin1{}; + CTxIn vin2{}; + CService addr{}; + int nonce{}; + int nBlockHeight{}; + std::vector vchSig1{}; + std::vector vchSig2{}; + + CMasternodeVerification() = default; + + CMasternodeVerification(CService addr, int nonce, int nBlockHeight) : + addr(addr), + nonce(nonce), + nBlockHeight(nBlockHeight) + {} + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(vin1); + READWRITE(vin2); + READWRITE(addr); + READWRITE(nonce); + READWRITE(nBlockHeight); + READWRITE(vchSig1); + READWRITE(vchSig2); + } + + uint256 GetHash() const + { + CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + ss << vin1; + ss << vin2; + ss << addr; + ss << nonce; + ss << nBlockHeight; + return ss.GetHash(); + } + + void Relay() const + { + CInv inv(MSG_MASTERNODE_VERIFY, GetHash()); + g_connman->RelayInv(inv); + } +}; + +#endif From b2a3c7a383e1e15e341c5e3a2f51afa6702079a6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:20:21 -0400 Subject: [PATCH 0724/1324] Update Makefile.am --- src/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 6fe48323..f7d9c462 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -252,7 +252,8 @@ BITCOIN_CORE_H = \ smartcontract-server.h \ rpcpodc.h \ rpcpog.h \ - masternodeconfig.h + masternodeconfig.h \ + masternode.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @@ -345,6 +346,7 @@ libhelpthehomeless_server_a_SOURCES = \ validationinterface.cpp \ versionbits.cpp \ masternodeconfig.cpp \ + masternode.cpp \ $(BITCOIN_CORE_H) if ENABLE_ZMQ From 69626b840a67696c88633391fc6d75cbe6d4870c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:29:42 -0400 Subject: [PATCH 0725/1324] Update Makefile.am --- src/Makefile.am | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index f7d9c462..4f3defa8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -245,15 +245,7 @@ BITCOIN_CORE_H = \ zmq/zmqabstractnotifier.h \ zmq/zmqconfig.h\ zmq/zmqnotificationinterface.h \ - zmq/zmqpublishnotifier.h \ - bbpsocket.h \ - masternodeman.h \ - smartcontract-client.h \ - smartcontract-server.h \ - rpcpodc.h \ - rpcpog.h \ - masternodeconfig.h \ - masternode.h + zmq/zmqpublishnotifier.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @@ -345,8 +337,6 @@ libhelpthehomeless_server_a_SOURCES = \ validation.cpp \ validationinterface.cpp \ versionbits.cpp \ - masternodeconfig.cpp \ - masternode.cpp \ $(BITCOIN_CORE_H) if ENABLE_ZMQ @@ -373,8 +363,6 @@ libhelpthehomeless_wallet_a_SOURCES = \ wallet/rpcwallet.cpp \ wallet/wallet.cpp \ wallet/walletdb.cpp \ - rpcpodc.cpp \ - rpcpog.cpp \ $(BITCOIN_CORE_H) # crypto primitives library From ac9f4b52ca14e8169dfb8892444fff7fe716fa69 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:30:33 -0400 Subject: [PATCH 0726/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 468e68ec..faa4d1cc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -52,10 +52,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ - qt/forms/transactiondescdialog.ui \ - qt/forms/proposaladddialog.ui \ - qt/forms/proposals.ui \ - qt/forms/secdialog.ui + qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -107,14 +104,7 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp \ - moc_rpcpodc.cpp \ - moc_rpcpog.cpp \ - moc_smartcontract-server.cpp \ - moc_smartcontract-client.cpp \ - qt/moc_proposaladddialog.cpp \ - qt/moc_proposals.cpp \ - qt/moc_secdialog.cpp + qt/moc_walletview.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -197,14 +187,7 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h \ - rpcpodc.h \ - rpcpog.h \ - smartcontract-server.h \ - smartcontract-client.h \ - qt/proposaladddialog.h \ - qt/proposals.h \ - qt/secdialog.h + qt/winshutdownmonitor.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -542,14 +525,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp \ - rpcpodc.cpp \ - rpcpog.cpp \ - smartcontract-server.cpp \ - smartcontract-client.cpp \ - qt/proposaladddialog.cpp \ - qt/proposals.cpp \ - qt/secdialog.cpp + qt/walletview.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 274487da0b3ae968267ffb60bdecbb10d1476ab8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:30:47 -0400 Subject: [PATCH 0727/1324] Delete bbpsocket.cpp --- src/bbpsocket.cpp | 197 ---------------------------------------------- 1 file changed, 197 deletions(-) delete mode 100644 src/bbpsocket.cpp diff --git a/src/bbpsocket.cpp b/src/bbpsocket.cpp deleted file mode 100644 index 19ffdd5d..00000000 --- a/src/bbpsocket.cpp +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "bbpsocket.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using boost::asio::deadline_timer; -using boost::asio::ip::tcp; -using boost::lambda::bind; -using boost::lambda::var; -using boost::lambda::_1; - -//---------------------------------------------------------------------- - -// -// This class manages socket timeouts by subclassing a deadline timer. -// Each asynchronous operation is given a deadline by which it must complete. -// Deadlines are enforced by the check_deadline actor that persists for the lifetime of the socket object: -// -// +----------------+ -// | | -// | check_deadline |<---+ -// | | | -// +----------------+ | async_wait() -// | | -// +---------+ -// -// If the actor determines that the deadline has expired, the socket is closed -// and any outstanding operations are consequently cancelled. The socket -// operations themselves use boost::lambda function objects as completion -// handlers. For a given socket operation, the socket object runs the -// io_service to block thread execution until the actor completes. -// -// Written by Christopher M. Kohlhoff (Chris@Kohlhoff.com) and the DAC developers - - -class bbpsocket -{ -public: - bbpsocket() : socket_(io_service_), deadline_(io_service_) - { - deadline_.expires_at(boost::posix_time::pos_infin); - check_deadline(); - } - - void connect(const std::string& host, const std::string& service, - boost::posix_time::time_duration timeout) - { - tcp::resolver::query query(host, service); - tcp::resolver::iterator iter = tcp::resolver(io_service_).resolve(query); - - // Set a deadline for the asynchronous operation. - deadline_.expires_from_now(timeout); - boost::system::error_code ec = boost::asio::error::would_block; - - // Start the asynchronous operation itself. The boost::lambda function - // object is used as a callback and will update the ec when the operation completes. - boost::asio::async_connect(socket_, iter, var(ec) = boost::lambda::_1); - - // Block until the asynchronous operation has completed. - do io_service_.run_one(); while (ec == boost::asio::error::would_block); - if (ec || !socket_.is_open()) - throw boost::system::system_error( - ec ? ec : boost::asio::error::operation_aborted); - } - - std::string read_line(boost::posix_time::time_duration timeout) - { - // Set a deadline - deadline_.expires_from_now(timeout); - boost::system::error_code ec = boost::asio::error::would_block; - boost::asio::async_read_until(socket_, input_buffer_, '\n', var(ec) = boost::lambda::_1); - // Block until the asynchronous operation has completed. - do io_service_.run_one(); while (ec == boost::asio::error::would_block); - - if (ec) - throw boost::system::system_error(ec); - - std::string line; - std::istream is(&input_buffer_); - std::getline(is, line); - return line; - } - - void write_line(const std::string& line, - boost::posix_time::time_duration timeout) - { - std::string data = line + "\n"; - // Set a deadline - deadline_.expires_from_now(timeout); - boost::system::error_code ec = boost::asio::error::would_block; - boost::asio::async_write(socket_, boost::asio::buffer(data), var(ec) = boost::lambda::_1); - // Block until the asynchronous operation has completed. - do io_service_.run_one(); while (ec == boost::asio::error::would_block); - if (ec) - throw boost::system::system_error(ec); - } - -private: - void check_deadline() - { - if (deadline_.expires_at() <= deadline_timer::traits_type::now()) - { - // The deadline has passed. - boost::system::error_code ignored_ec; - socket_.close(ignored_ec); - deadline_.expires_at(boost::posix_time::pos_infin); - } - // Put the actor back to sleep. - deadline_.async_wait(bind(&bbpsocket::check_deadline, this)); - } - - boost::asio::io_service io_service_; - tcp::socket socket_; - deadline_timer deadline_; - boost::asio::streambuf input_buffer_; -}; - -//---------------------------------------------------------------------- - -std::string sPrepareVersion() -{ - ServiceFlags nLocalNodeServices = g_connman->GetLocalServices(); - CAddress addrYou = CAddress(CService(), nLocalNodeServices); - CAddress addrMe = CAddress(CService(), nLocalNodeServices); - uint256 mnauthChallenge; - GetRandBytes(mnauthChallenge.begin(), mnauthChallenge.size()); - int64_t nTime = GetAdjustedTime(); - CSerializedNetMsg msgmversion = CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe, - 1, strSubVersion, 0, ::fRelayTxes, mnauthChallenge); - std::string sVersion = VectorToString(msgmversion.data); - return sVersion; -} - -std::string PrepareHTTPPost(bool bPost, std::string sPage, std::string sHostHeader, const std::string& sMsg, const std::map& mapRequestHeaders) -{ - std::ostringstream s; - std::string sUserAgent = "Mozilla/5.0"; - std::string sMethod = bPost ? "POST" : "GET"; - - s << sMethod + " /" + sPage + " HTTP/1.1\r\n" - << "User-Agent: " + sUserAgent + "/" << FormatFullVersion() << "\r\n" - << "Host: " + sHostHeader + "" << "\r\n" - << "Content-Length: " << sMsg.size() << "\r\n"; - - for (auto item : mapRequestHeaders) - { - s << item.first << ": " << item.second << "\r\n"; - } - s << "\r\n" << sMsg; - return s.str(); -} - -std::string DACPost(std::string sHost, std::string sService, std::string sPage, std::string sPayload, int iTimeout) -{ - std::string sData; - try - { - bbpsocket c; - c.connect(sHost, sService, boost::posix_time::seconds(iTimeout)); - boost::posix_time::ptime time_sent = boost::posix_time::microsec_clock::universal_time(); - std::map mapRequestHeaders; - mapRequestHeaders["Agent"] = FormatFullVersion(); - std::string sPost = PrepareHTTPPost(true, sPage, sHost, sPayload, mapRequestHeaders); - c.write_line(sPost, boost::posix_time::seconds(iTimeout)); - for (;;) - { - std::string line = c.read_line(boost::posix_time::seconds(iTimeout)); - sData += line; - if (Contains(line, "") || Contains(line,"") || Contains(line,"")) - break; - } - } - catch (std::exception& e) - { - std::string sErr = std::string("DACPostException::") + e.what(); - return sErr; - } - return sData; -} - - - \ No newline at end of file From 63b1a9cfaf582325fb46b3982faebfcc56839700 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:30:56 -0400 Subject: [PATCH 0728/1324] Delete bbpsocket.h --- src/bbpsocket.h | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/bbpsocket.h diff --git a/src/bbpsocket.h b/src/bbpsocket.h deleted file mode 100644 index 567fb72c..00000000 --- a/src/bbpsocket.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BBPSOCKET_H -#define BBPSOCKET_H - -#include -#include "util.h" -#include "clientversion.h" -#include "rpcpog.h" -#include "netmessagemaker.h" -#include "activemasternode.h" - -std::string DACPost(std::string sHost, std::string sService, std::string sPage, std::string sPayload, int iTimeout); -std::string PrepareHTTPPost(bool bPost, std::string sPage, std::string sHostHeader, const std::string& sMsg, const std::map& mapRequestHeaders); - -#endif From 098ba2685ebafab0af1e320b129a35bbab64dcf8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:15 -0400 Subject: [PATCH 0729/1324] Delete masternode.cpp --- src/masternode.cpp | 875 --------------------------------------------- 1 file changed, 875 deletions(-) delete mode 100644 src/masternode.cpp diff --git a/src/masternode.cpp b/src/masternode.cpp deleted file mode 100644 index fa498a1c..00000000 --- a/src/masternode.cpp +++ /dev/null @@ -1,875 +0,0 @@ -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "activemasternode.h" -#include "base58.h" -#include "init.h" -#include "netbase.h" -#include "masternode.h" -#include "masternode-payments.h" -#include "masternode-sync.h" -#include "masternodeman.h" -#include "messagesigner.h" -#include "script/standard.h" -#include "util.h" -#ifdef ENABLE_WALLET -#include "wallet/wallet.h" -#endif // ENABLE_WALLET - -#include - - -CMasternode::CMasternode() : - masternode_info_t{ MASTERNODE_ENABLED, PROTOCOL_VERSION, GetAdjustedTime()}, - fAllowMixingTx(true) -{} - -CMasternode::CMasternode(CService addr, COutPoint outpoint, CPubKey pubKeyCollateralAddress, CPubKey pubKeyMasternode, int nProtocolVersionIn) : - masternode_info_t{ MASTERNODE_ENABLED, nProtocolVersionIn, GetAdjustedTime(), - outpoint, addr, pubKeyCollateralAddress, pubKeyMasternode}, - fAllowMixingTx(true) -{} - -CMasternode::CMasternode(const CMasternode& other) : - masternode_info_t{other}, - lastPing(other.lastPing), - vchSig(other.vchSig), - nCollateralMinConfBlockHash(other.nCollateralMinConfBlockHash), - nBlockLastPaid(other.nBlockLastPaid), - nPoSeBanScore(other.nPoSeBanScore), - nPoSeBanHeight(other.nPoSeBanHeight), - fAllowMixingTx(other.fAllowMixingTx), - fUnitTest(other.fUnitTest) -{} - -CMasternode::CMasternode(const CMasternodeBroadcast& mnb) : - masternode_info_t{ mnb.nActiveState, mnb.nProtocolVersion, mnb.sigTime, - mnb.vin.prevout, mnb.addr, mnb.pubKeyCollateralAddress, mnb.pubKeyMasternode, - mnb.sigTime /*nTimeLastWatchdogVote*/}, - lastPing(mnb.lastPing), - vchSig(mnb.vchSig), - fAllowMixingTx(true) -{} - -// -// When a new masternode broadcast is sent, update our information -// -bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman) -{ - if(mnb.sigTime <= sigTime && !mnb.fRecovery) return false; - - pubKeyMasternode = mnb.pubKeyMasternode; - sigTime = mnb.sigTime; - vchSig = mnb.vchSig; - nProtocolVersion = mnb.nProtocolVersion; - addr = mnb.addr; - nPoSeBanScore = 0; - nPoSeBanHeight = 0; - nTimeLastChecked = 0; - int nDos = 0; - if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(this, true, nDos, connman))) { - lastPing = mnb.lastPing; - mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing)); - } - // if it matches our Masternode privkey... - if(fMasterNode && pubKeyMasternode == activeMasternode.pubKeyMasternode) { - nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; - if(nProtocolVersion == PROTOCOL_VERSION) { - // ... and PROTOCOL_VERSION, then we've been remotely activated ... - activeMasternode.ManageState(connman); - } else { - // ... otherwise we need to reactivate our node, do not add it to the list and do not relay - // but also do not ban the node we get this message from - LogPrintf("CMasternode::UpdateFromNewBroadcast -- wrong PROTOCOL_VERSION, re-activate your MN: message nProtocolVersion=%d PROTOCOL_VERSION=%d\n", nProtocolVersion, PROTOCOL_VERSION); - return false; - } - } - return true; -} - -// -// Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to -// the proof of work for that block. The further away they are the better, the furthest will win the election -// and get paid this block -// -arith_uint256 CMasternode::CalculateScore(const uint256& blockHash) -{ - // Deterministically calculate a "score" for a Masternode based on any given (block)hash - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << vin.prevout << nCollateralMinConfBlockHash << blockHash; - return UintToArith256(ss.GetHash()); -} - -CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint) -{ - int nHeight; - return CheckCollateral(outpoint, nHeight); -} - -CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, int& nHeightRet) -{ - AssertLockHeld(cs_main); - - Coin coin; - if(!GetUTXOCoin(outpoint, coin)) { - return COLLATERAL_UTXO_NOT_FOUND; - } - - if(coin.out.nValue != 1000000 * COIN) { - return COLLATERAL_INVALID_AMOUNT; - } - - nHeightRet = coin.nHeight; - return COLLATERAL_OK; -} - -void CMasternode::Check(bool fForce) -{ - LOCK(cs); - - if(ShutdownRequested()) return; - - if(!fForce && (GetTime() - nTimeLastChecked < MASTERNODE_CHECK_SECONDS)) return; - nTimeLastChecked = GetTime(); - - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state\n", vin.prevout.ToStringShort(), GetStateString()); - - //once spent, stop doing the checks - if(IsOutpointSpent()) return; - - int nHeight = 0; - if(!fUnitTest) { - TRY_LOCK(cs_main, lockMain); - if(!lockMain) return; - - CollateralStatus err = CheckCollateral(vin.prevout); - if (err == COLLATERAL_UTXO_NOT_FOUND) { - nActiveState = MASTERNODE_OUTPOINT_SPENT; - LogPrint("masternode", "CMasternode::Check -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort()); - return; - } - - nHeight = chainActive.Height(); - } - - if(IsPoSeBanned()) { - if(nHeight < nPoSeBanHeight) return; // too early? - // Otherwise give it a chance to proceed further to do all the usual checks and to change its state. - // Masternode still will be on the edge and can be banned back easily if it keeps ignoring mnverify - // or connect attempts. Will require few mnverify messages to strengthen its position in mn list. - LogPrintf("CMasternode::Check -- Masternode %s is unbanned and back in list now\n", vin.prevout.ToStringShort()); - DecreasePoSeBanScore(); - } else if(nPoSeBanScore >= MASTERNODE_POSE_BAN_MAX_SCORE) { - nActiveState = MASTERNODE_POSE_BAN; - // ban for the whole payment cycle - nPoSeBanHeight = nHeight + mnodeman.size(); - LogPrintf("CMasternode::Check -- Masternode %s is banned till block %d now\n", vin.prevout.ToStringShort(), nPoSeBanHeight); - return; - } - - int nActiveStatePrev = nActiveState; - bool fOurMasternode = fMasterNode && activeMasternode.pubKeyMasternode == pubKeyMasternode; - - // masternode doesn't meet payment protocol requirements ... - bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() || - // or it's our own node and we just updated it to the new protocol but we are still waiting for activation ... - (fOurMasternode && nProtocolVersion < PROTOCOL_VERSION); - - if(fRequireUpdate) { - nActiveState = MASTERNODE_UPDATE_REQUIRED; - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } - return; - } - - // keep old masternodes on start, give them a chance to receive updates... - bool fWaitForPing = !masternodeSync.IsMasternodeListSynced() && !IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS); - - if(fWaitForPing && !fOurMasternode) { - // ...but if it was already expired before the initial check - return right away - if(IsExpired() || IsWatchdogExpired() || IsNewStartRequired()) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state, waiting for ping\n", vin.prevout.ToStringShort(), GetStateString()); - return; - } - } - - // don't expire if we are still in "waiting for ping" mode unless it's our own masternode - if(!fWaitForPing || fOurMasternode) { - - if(!IsPingedWithin(MASTERNODE_NEW_START_REQUIRED_SECONDS)) { - nActiveState = MASTERNODE_NEW_START_REQUIRED; - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } - return; - } - - bool fWatchdogActive = masternodeSync.IsSynced() && mnodeman.IsWatchdogActive(); - bool fWatchdogExpired = (fWatchdogActive && ((GetAdjustedTime() - nTimeLastWatchdogVote) > MASTERNODE_WATCHDOG_MAX_SECONDS)); - - LogPrint("masternode", "CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetAdjustedTime()=%d, fWatchdogExpired=%d\n", - vin.prevout.ToStringShort(), nTimeLastWatchdogVote, GetAdjustedTime(), fWatchdogExpired); - - if(fWatchdogExpired) { - nActiveState = MASTERNODE_WATCHDOG_EXPIRED; - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } - return; - } - - if(!IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS)) { - nActiveState = MASTERNODE_EXPIRED; - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } - return; - } - } - - if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS) { - nActiveState = MASTERNODE_PRE_ENABLED; - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } - return; - } - - nActiveState = MASTERNODE_ENABLED; // OK - if(nActiveStatePrev != nActiveState) { - LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); - } -} - -bool CMasternode::IsInputAssociatedWithPubkey() -{ - CScript payee; - payee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); - - CTransaction tx; - uint256 hash; - if(GetTransaction(vin.prevout.hash, tx, Params().GetConsensus(), hash, true)) { - BOOST_FOREACH(CTxOut out, tx.vout) - if(out.nValue == 1000000*COIN && out.scriptPubKey == payee) return true; - } - - return false; -} - -bool CMasternode::IsValidNetAddr() -{ - return IsValidNetAddr(addr); -} - -bool CMasternode::IsValidNetAddr(CService addrIn) -{ - // TODO: regtest is fine with any addresses for now, - // should probably be a bit smarter if one day we start to implement tests for this - return Params().NetworkIDString() == CBaseChainParams::REGTEST || - (addrIn.IsIPv4() && IsReachable(addrIn) && addrIn.IsRoutable()); -} - -masternode_info_t CMasternode::GetInfo() -{ - masternode_info_t info{*this}; - info.nTimeLastPing = lastPing.sigTime; - info.fInfoValid = true; - return info; -} - -std::string CMasternode::StateToString(int nStateIn) -{ - switch(nStateIn) { - case MASTERNODE_PRE_ENABLED: return "PRE_ENABLED"; - case MASTERNODE_ENABLED: return "ENABLED"; - case MASTERNODE_EXPIRED: return "EXPIRED"; - case MASTERNODE_OUTPOINT_SPENT: return "OUTPOINT_SPENT"; - case MASTERNODE_UPDATE_REQUIRED: return "UPDATE_REQUIRED"; - case MASTERNODE_WATCHDOG_EXPIRED: return "WATCHDOG_EXPIRED"; - case MASTERNODE_NEW_START_REQUIRED: return "NEW_START_REQUIRED"; - case MASTERNODE_POSE_BAN: return "POSE_BAN"; - default: return "UNKNOWN"; - } -} - -std::string CMasternode::GetStateString() const -{ - return StateToString(nActiveState); -} - -std::string CMasternode::GetStatus() const -{ - // TODO: return smth a bit more human readable here - return GetStateString(); -} - -void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack) -{ - if(!pindex) return; - - const CBlockIndex *BlockReading = pindex; - - CScript mnpayee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); - // LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s\n", vin.prevout.ToStringShort()); - - LOCK(cs_mapMasternodeBlocks); - - for (int i = 0; BlockReading && BlockReading->nHeight > nBlockLastPaid && i < nMaxBlocksToScanBack; i++) { - if(mnpayments.mapMasternodeBlocks.count(BlockReading->nHeight) && - mnpayments.mapMasternodeBlocks[BlockReading->nHeight].HasPayeeWithVotes(mnpayee, 2)) - { - CBlock block; - if(!ReadBlockFromDisk(block, BlockReading, Params().GetConsensus())) // shouldn't really happen - continue; - - CAmount nMasternodePayment = GetMasternodePayment(BlockReading->nHeight, block.vtx[0].GetValueOut()); - - BOOST_FOREACH(CTxOut txout, block.vtx[0].vout) - if(mnpayee == txout.scriptPubKey && nMasternodePayment == txout.nValue) { - nBlockLastPaid = BlockReading->nHeight; - nTimeLastPaid = BlockReading->nTime; - LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- found new %d\n", vin.prevout.ToStringShort(), nBlockLastPaid); - return; - } - } - - if (BlockReading->pprev == NULL) { assert(BlockReading); break; } - BlockReading = BlockReading->pprev; - } - - // Last payment for this masternode wasn't found in latest mnpayments blocks - // or it was found in mnpayments blocks but wasn't found in the blockchain. - // LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- keeping old %d\n", vin.prevout.ToStringShort(), nBlockLastPaid); -} - -#ifdef ENABLE_WALLET -bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline) -{ - COutPoint outpoint; - CPubKey pubKeyCollateralAddressNew; - CKey keyCollateralAddressNew; - CPubKey pubKeyMasternodeNew; - CKey keyMasternodeNew; - - auto Log = [&strErrorRet](std::string sErr)->bool - { - strErrorRet = sErr; - LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); - return false; - }; - - //need correct blocks to send ping - if (!fOffline && !masternodeSync.IsBlockchainSynced()) - return Log("Sync in progress. Must wait until sync is complete to start Masternode"); - - if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) - return Log(strprintf("Invalid masternode key %s", strKeyMasternode)); - - if (!pwalletMain->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex)) - return Log(strprintf("Could not allocate outpoint %s:%s for masternode %s", strTxHash, strOutputIndex, strService)); - - CService service; - if (!Lookup(strService.c_str(), service, 0, false)) - return Log(strprintf("Invalid address %s for masternode.", strService)); - int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); - if (Params().NetworkIDString() == CBaseChainParams::MAIN) { - if (service.GetPort() != mainnetDefaultPort) - return Log(strprintf("Invalid port %u for masternode %s, only %d is supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort)); - } else if (service.GetPort() == mainnetDefaultPort) - return Log(strprintf("Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort)); - - return Create(outpoint, service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet); -} - -bool CMasternodeBroadcast::Create(const COutPoint& outpoint, const CService& service, const CKey& keyCollateralAddressNew, const CPubKey& pubKeyCollateralAddressNew, const CKey& keyMasternodeNew, const CPubKey& pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet) -{ - // wait for reindex and/or import to finish - if (fImporting || fReindex) return false; - - LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", - CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), - pubKeyMasternodeNew.GetID().ToString()); - - auto Log = [&strErrorRet,&mnbRet](std::string sErr)->bool - { - strErrorRet = sErr; - LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); - mnbRet = CMasternodeBroadcast(); - return false; - }; - - CMasternodePing mnp(outpoint); - if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) - return Log(strprintf("Failed to sign ping, masternode=%s", outpoint.ToStringShort())); - - mnbRet = CMasternodeBroadcast(service, outpoint, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); - - if (!mnbRet.IsValidNetAddr()) - return Log(strprintf("Invalid IP address, masternode=%s", outpoint.ToStringShort())); - - mnbRet.lastPing = mnp; - if (!mnbRet.Sign(keyCollateralAddressNew)) - return Log(strprintf("Failed to sign broadcast, masternode=%s", outpoint.ToStringShort())); - - return true; -} -#endif // ENABLE_WALLET - -bool CMasternodeBroadcast::SimpleCheck(int& nDos) -{ - nDos = 0; - - // make sure addr is valid - if(!IsValidNetAddr()) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- Invalid addr, rejected: masternode=%s addr=%s\n", - vin.prevout.ToStringShort(), addr.ToString()); - return false; - } - - // make sure signature isn't in the future (past is OK) - if (sigTime > GetAdjustedTime() + 60 * 60) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- Signature rejected, too far into the future: masternode=%s\n", vin.prevout.ToStringShort()); - nDos = 1; - return false; - } - - // empty ping or incorrect sigTime/unknown blockhash - if(lastPing == CMasternodePing() || !lastPing.SimpleCheck(nDos)) { - // one of us is probably forked or smth, just mark it as expired and check the rest of the rules - nActiveState = MASTERNODE_EXPIRED; - } - - if(nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- ignoring outdated Masternode: masternode=%s nProtocolVersion=%d\n", vin.prevout.ToStringShort(), nProtocolVersion); - return false; - } - - CScript pubkeyScript; - pubkeyScript = GetScriptForDestination(pubKeyCollateralAddress.GetID()); - - if(pubkeyScript.size() != 25) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyCollateralAddress has the wrong size\n"); - nDos = 100; - return false; - } - - CScript pubkeyScript2; - pubkeyScript2 = GetScriptForDestination(pubKeyMasternode.GetID()); - - if(pubkeyScript2.size() != 25) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyMasternode has the wrong size\n"); - nDos = 100; - return false; - } - - if(!vin.scriptSig.empty()) { - LogPrintf("CMasternodeBroadcast::SimpleCheck -- Ignore Not Empty ScriptSig %s\n",vin.ToString()); - nDos = 100; - return false; - } - - int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); - if(Params().NetworkIDString() == CBaseChainParams::MAIN) { - if(addr.GetPort() != mainnetDefaultPort) return false; - } else if(addr.GetPort() == mainnetDefaultPort) return false; - - return true; -} - -bool CMasternodeBroadcast::Update(CMasternode* pmn, int& nDos, CConnman& connman) -{ - nDos = 0; - - if(pmn->sigTime == sigTime && !fRecovery) { - // mapSeenMasternodeBroadcast in CMasternodeMan::CheckMnbAndUpdateMasternodeList should filter legit duplicates - // but this still can happen if we just started, which is ok, just do nothing here. - return false; - } - - // this broadcast is older than the one that we already have - it's bad and should never happen - // unless someone is doing something fishy - if(pmn->sigTime > sigTime) { - LogPrintf("CMasternodeBroadcast::Update -- Bad sigTime %d (existing broadcast is at %d) for Masternode %s %s\n", - sigTime, pmn->sigTime, vin.prevout.ToStringShort(), addr.ToString()); - return false; - } - - pmn->Check(); - - // masternode is banned by PoSe - if(pmn->IsPoSeBanned()) { - LogPrintf("CMasternodeBroadcast::Update -- Banned by PoSe, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - // IsVnAssociatedWithPubkey is validated once in CheckOutpoint, after that they just need to match - if(pmn->pubKeyCollateralAddress != pubKeyCollateralAddress) { - LogPrintf("CMasternodeBroadcast::Update -- Got mismatched pubKeyCollateralAddress and vin\n"); - nDos = 33; - return false; - } - - if (!CheckSignature(nDos)) { - LogPrintf("CMasternodeBroadcast::Update -- CheckSignature() failed, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - // if ther was no masternode broadcast recently or if it matches our Masternode privkey... - if(!pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS) || (fMasterNode && pubKeyMasternode == activeMasternode.pubKeyMasternode)) { - // take the newest entry - LogPrintf("CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n", addr.ToString()); - if(pmn->UpdateFromNewBroadcast(*this, connman)) { - pmn->Check(); - Relay(connman); - } - masternodeSync.BumpAssetLastTime("CMasternodeBroadcast::Update"); - } - - return true; -} - -bool CMasternodeBroadcast::CheckOutpoint(int& nDos) -{ - // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey) - // so nothing to do here for us - if(fMasterNode && vin.prevout == activeMasternode.outpoint && pubKeyMasternode == activeMasternode.pubKeyMasternode) { - return false; - } - - if (!CheckSignature(nDos)) { - LogPrintf("CMasternodeBroadcast::CheckOutpoint -- CheckSignature() failed, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - { - TRY_LOCK(cs_main, lockMain); - if(!lockMain) { - // not mnb fault, let it to be checked again later - LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to aquire lock, addr=%s", addr.ToString()); - mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); - return false; - } - - int nHeight; - CollateralStatus err = CheckCollateral(vin.prevout, nHeight); - if (err == COLLATERAL_UTXO_NOT_FOUND) { - LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - if (err == COLLATERAL_INVALID_AMOUNT) { - LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should have 1000 DASH, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - if(chainActive.Height() - nHeight + 1 < Params().GetConsensus().nMasternodeMinimumConfirmations) { - LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO must have at least %d confirmations, masternode=%s\n", - Params().GetConsensus().nMasternodeMinimumConfirmations, vin.prevout.ToStringShort()); - // maybe we miss few blocks, let this mnb to be checked again later - mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); - return false; - } - // remember the hash of the block where masternode collateral had minimum required confirmations - nCollateralMinConfBlockHash = chainActive[nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]->GetBlockHash(); - } - - LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO verified\n"); - - // make sure the input that was signed in masternode broadcast message is related to the transaction - // that spawned the Masternode - this is expensive, so it's only done once per Masternode - if(!IsInputAssociatedWithPubkey()) { - LogPrintf("CMasternodeMan::CheckOutpoint -- Got mismatched pubKeyCollateralAddress and vin\n"); - nDos = 33; - return false; - } - - // verify that sig time is legit in past - // should be at least not earlier than block when 1000 DASH tx got nMasternodeMinimumConfirmations - uint256 hashBlock = uint256(); - CTransaction tx2; - GetTransaction(vin.prevout.hash, tx2, Params().GetConsensus(), hashBlock, true); - { - LOCK(cs_main); - BlockMap::iterator mi = mapBlockIndex.find(hashBlock); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation - CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]; // block where tx got nMasternodeMinimumConfirmations - if(pConfIndex->GetBlockTime() > sigTime) { - LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Bad sigTime %d (%d conf block is at %d) for Masternode %s %s\n", - sigTime, Params().GetConsensus().nMasternodeMinimumConfirmations, pConfIndex->GetBlockTime(), vin.prevout.ToStringShort(), addr.ToString()); - return false; - } - } - } - - return true; -} - -bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress) -{ - std::string strError; - std::string strMessage; - - sigTime = GetAdjustedTime(); - - strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + - pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + - boost::lexical_cast(nProtocolVersion); - - if(!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) { - LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n"); - return false; - } - - if(!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)) { - LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError); - return false; - } - - return true; -} - -bool CMasternodeBroadcast::CheckSignature(int& nDos) -{ - std::string strMessage; - std::string strError = ""; - nDos = 0; - - strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + - pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + - boost::lexical_cast(nProtocolVersion); - - LogPrint("masternode", "CMasternodeBroadcast::CheckSignature -- strMessage: %s pubKeyCollateralAddress address: %s sig: %s\n", strMessage, CBitcoinAddress(pubKeyCollateralAddress.GetID()).ToString(), EncodeBase64(&vchSig[0], vchSig.size())); - - if(!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ - LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError); - nDos = 100; - return false; - } - - return true; -} - -void CMasternodeBroadcast::Relay(CConnman& connman) -{ - // Do not relay until fully synced - if(!masternodeSync.IsSynced()) { - LogPrint("masternode", "CMasternodeBroadcast::Relay -- won't relay until fully synced\n"); - return; - } - - CInv inv(MSG_MASTERNODE_ANNOUNCE, GetHash()); - connman.RelayInv(inv); -} - -CMasternodePing::CMasternodePing(const COutPoint& outpoint) -{ - LOCK(cs_main); - if (!chainActive.Tip() || chainActive.Height() < 12) return; - - vin = CTxIn(outpoint); - blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash(); - sigTime = GetAdjustedTime(); -} - -bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) -{ - std::string strError; - std::string strMasterNodeSignMessage; - - // TODO: add sentinel data - sigTime = GetAdjustedTime(); - std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); - - if(!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) { - LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n"); - return false; - } - - if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { - LogPrintf("CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError); - return false; - } - - return true; -} - -bool CMasternodePing::CheckSignature(CPubKey& pubKeyMasternode, int &nDos) -{ - // TODO: add sentinel data - std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); - std::string strError = ""; - nDos = 0; - - if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { - LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", vin.prevout.ToStringShort(), strError); - nDos = 33; - return false; - } - return true; -} - -bool CMasternodePing::SimpleCheck(int& nDos) -{ - // don't ban by default - nDos = 0; - - if (sigTime > GetAdjustedTime() + 60 * 60) { - LogPrintf("CMasternodePing::SimpleCheck -- Signature rejected, too far into the future, masternode=%s\n", vin.prevout.ToStringShort()); - nDos = 1; - return false; - } - - { - AssertLockHeld(cs_main); - BlockMap::iterator mi = mapBlockIndex.find(blockHash); - if (mi == mapBlockIndex.end()) { - LogPrint("masternode", "CMasternodePing::SimpleCheck -- Masternode ping is invalid, unknown block hash: masternode=%s blockHash=%s\n", vin.prevout.ToStringShort(), blockHash.ToString()); - // maybe we stuck or forked so we shouldn't ban this node, just fail to accept this ping - // TODO: or should we also request this block? - return false; - } - } - LogPrint("masternode", "CMasternodePing::SimpleCheck -- Masternode ping verified: masternode=%s blockHash=%s sigTime=%d\n", vin.prevout.ToStringShort(), blockHash.ToString(), sigTime); - return true; -} - -bool CMasternodePing::CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman) -{ - // don't ban by default - nDos = 0; - - if (!SimpleCheck(nDos)) { - return false; - } - - if (pmn == NULL) { - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Couldn't find Masternode entry, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - if(!fFromNewBroadcast) { - if (pmn->IsUpdateRequired()) { - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- masternode protocol is outdated, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - - if (pmn->IsNewStartRequired()) { - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- masternode is completely expired, new start is required, masternode=%s\n", vin.prevout.ToStringShort()); - return false; - } - } - - { - LOCK(cs_main); - BlockMap::iterator mi = mapBlockIndex.find(blockHash); - if ((*mi).second && (*mi).second->nHeight < chainActive.Height() - 24) { - LogPrintf("CMasternodePing::CheckAndUpdate -- Masternode ping is invalid, block hash is too old: masternode=%s blockHash=%s\n", vin.prevout.ToStringShort(), blockHash.ToString()); - // nDos = 1; - return false; - } - } - - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- New ping: masternode=%s blockHash=%s sigTime=%d\n", vin.prevout.ToStringShort(), blockHash.ToString(), sigTime); - - // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.prevout.ToStringShort()); - // update only if there is no known ping for this masternode or - // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one - if (pmn->IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS - 60, sigTime)) { - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping arrived too early, masternode=%s\n", vin.prevout.ToStringShort()); - //nDos = 1; //disable, this is happening frequently and causing banned peers - return false; - } - - if (!CheckSignature(pmn->pubKeyMasternode, nDos)) return false; - - // so, ping seems to be ok - - // if we are still syncing and there was no known ping for this mn for quite a while - // (NOTE: assuming that MASTERNODE_EXPIRATION_SECONDS/2 should be enough to finish mn list sync) - if(!masternodeSync.IsMasternodeListSynced() && !pmn->IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS/2)) { - // let's bump sync timeout - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- bumping sync timeout, masternode=%s\n", vin.prevout.ToStringShort()); - masternodeSync.BumpAssetLastTime("CMasternodePing::CheckAndUpdate"); - } - - // let's store this ping as the last one - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping accepted, masternode=%s\n", vin.prevout.ToStringShort()); - pmn->lastPing = *this; - - // and update mnodeman.mapSeenMasternodeBroadcast.lastPing which is probably outdated - CMasternodeBroadcast mnb(*pmn); - uint256 hash = mnb.GetHash(); - if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) { - mnodeman.mapSeenMasternodeBroadcast[hash].second.lastPing = *this; - } - - // force update, ignoring cache - pmn->Check(true); - // relay ping for nodes in ENABLED/EXPIRED/WATCHDOG_EXPIRED state only, skip everyone else - if (!pmn->IsEnabled() && !pmn->IsExpired() && !pmn->IsWatchdogExpired()) return false; - - LogPrint("masternode", "CMasternodePing::CheckAndUpdate -- Masternode ping acceepted and relayed, masternode=%s\n", vin.prevout.ToStringShort()); - Relay(connman); - - return true; -} - -void CMasternodePing::Relay(CConnman& connman) -{ - // Do not relay until fully synced - if(!masternodeSync.IsSynced()) { - LogPrint("masternode", "CMasternodePing::Relay -- won't relay until fully synced\n"); - return; - } - - CInv inv(MSG_MASTERNODE_PING, GetHash()); - connman.RelayInv(inv); -} - -void CMasternode::AddGovernanceVote(uint256 nGovernanceObjectHash) -{ - if(mapGovernanceObjectsVotedOn.count(nGovernanceObjectHash)) { - mapGovernanceObjectsVotedOn[nGovernanceObjectHash]++; - } else { - mapGovernanceObjectsVotedOn.insert(std::make_pair(nGovernanceObjectHash, 1)); - } -} - -void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash) -{ - std::map::iterator it = mapGovernanceObjectsVotedOn.find(nGovernanceObjectHash); - if(it == mapGovernanceObjectsVotedOn.end()) { - return; - } - mapGovernanceObjectsVotedOn.erase(it); -} - -void CMasternode::UpdateWatchdogVoteTime(uint64_t nVoteTime) -{ - LOCK(cs); - nTimeLastWatchdogVote = (nVoteTime == 0) ? GetAdjustedTime() : nVoteTime; -} - -/** -* FLAG GOVERNANCE ITEMS AS DIRTY -* -* - When masternode come and go on the network, we must flag the items they voted on to recalc it's cached flags -* -*/ -void CMasternode::FlagGovernanceItemsAsDirty() -{ - std::vector vecDirty; - { - std::map::iterator it = mapGovernanceObjectsVotedOn.begin(); - while(it != mapGovernanceObjectsVotedOn.end()) { - vecDirty.push_back(it->first); - ++it; - } - } - for(size_t i = 0; i < vecDirty.size(); ++i) { - mnodeman.AddDirtyGovernanceObjectHash(vecDirty[i]); - } -} From df2fe69b0630caf53008ce3352994e166c49b39f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:23 -0400 Subject: [PATCH 0730/1324] Delete masternode.h --- src/masternode.h | 410 ----------------------------------------------- 1 file changed, 410 deletions(-) delete mode 100644 src/masternode.h diff --git a/src/masternode.h b/src/masternode.h deleted file mode 100644 index 4bcc2e1e..00000000 --- a/src/masternode.h +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef MASTERNODE_H -#define MASTERNODE_H - -#include "key.h" -#include "validation.h" -#include "spork.h" - -class CMasternode; -class CMasternodeBroadcast; -class CConnman; - -static const int MASTERNODE_CHECK_SECONDS = 5; -static const int MASTERNODE_MIN_MNB_SECONDS = 5 * 60; -static const int MASTERNODE_MIN_MNP_SECONDS = 10 * 60; -static const int MASTERNODE_EXPIRATION_SECONDS = 65 * 60; -static const int MASTERNODE_WATCHDOG_MAX_SECONDS = 120 * 60; -static const int MASTERNODE_NEW_START_REQUIRED_SECONDS = 180 * 60; - -static const int MASTERNODE_POSE_BAN_MAX_SCORE = 5; - -// -// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network -// - -// sentinel version before sentinel ping implementation -#define DEFAULT_SENTINEL_VERSION 0x010001 - -class CMasternodePing -{ -public: - CTxIn vin{}; - uint256 blockHash{}; - int64_t sigTime{}; //mnb message times - std::vector vchSig{}; - bool fSentinelIsCurrent = false; // true if last sentinel ping was actual - // MSB is always 0, other 3 bits corresponds to x.x.x version scheme - uint32_t nSentinelVersion{DEFAULT_SENTINEL_VERSION}; - - CMasternodePing() = default; - - CMasternodePing(const COutPoint& outpoint); - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(vin); - READWRITE(blockHash); - READWRITE(sigTime); - READWRITE(vchSig); - if(ser_action.ForRead() && (s.size() == 0)) - { - fSentinelIsCurrent = false; - nSentinelVersion = DEFAULT_SENTINEL_VERSION; - return; - } - READWRITE(fSentinelIsCurrent); - READWRITE(nSentinelVersion); - } - - uint256 GetHash() const - { - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << vin; - ss << sigTime; - return ss.GetHash(); - } - - bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; } - - bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); - bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos); - bool SimpleCheck(int& nDos); - bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman); - void Relay(CConnman& connman); -}; - -inline bool operator==(const CMasternodePing& a, const CMasternodePing& b) -{ - return a.vin == b.vin && a.blockHash == b.blockHash; -} -inline bool operator!=(const CMasternodePing& a, const CMasternodePing& b) -{ - return !(a == b); -} - -struct masternode_info_t -{ - // Note: all these constructors can be removed once C++14 is enabled. - // (in C++11 the member initializers wrongly disqualify this as an aggregate) - masternode_info_t() = default; - masternode_info_t(masternode_info_t const&) = default; - - masternode_info_t(int activeState, int protoVer, int64_t sTime) : - nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime} {} - - masternode_info_t(int activeState, int protoVer, int64_t sTime, - COutPoint const& outpoint, CService const& addr, - CPubKey const& pkCollAddr, CPubKey const& pkMN, - int64_t tWatchdogV = 0) : - nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime}, - vin{outpoint}, addr{addr}, - pubKeyCollateralAddress{pkCollAddr}, pubKeyMasternode{pkMN}, - nTimeLastWatchdogVote{tWatchdogV} {} - - int nActiveState = 0; - int nProtocolVersion = 0; - int64_t sigTime = 0; //mnb message time - - CTxIn vin{}; - CService addr{}; - CPubKey pubKeyCollateralAddress{}; - CPubKey pubKeyMasternode{}; - int64_t nTimeLastWatchdogVote = 0; - - int64_t nLastDsq = 0; //the dsq count from the last dsq broadcast of this node - int64_t nTimeLastChecked = 0; - int64_t nTimeLastPaid = 0; - int64_t nTimeLastPing = 0; //* not in CMN - bool fInfoValid = false; //* not in CMN -}; - -// -// The Masternode Class. For managing the Darksend process. It contains the input of the 1000DRK, signature to prove -// it's the one who own that ip address and code for calculating the payment election. -// -class CMasternode : public masternode_info_t -{ -private: - // critical section to protect the inner data structures - mutable CCriticalSection cs; - -public: - enum state { - MASTERNODE_PRE_ENABLED, - MASTERNODE_ENABLED, - MASTERNODE_EXPIRED, - MASTERNODE_OUTPOINT_SPENT, - MASTERNODE_UPDATE_REQUIRED, - MASTERNODE_WATCHDOG_EXPIRED, - MASTERNODE_NEW_START_REQUIRED, - MASTERNODE_POSE_BAN - }; - - enum CollateralStatus { - COLLATERAL_OK, - COLLATERAL_UTXO_NOT_FOUND, - COLLATERAL_INVALID_AMOUNT - }; - - - CMasternodePing lastPing{}; - std::vector vchSig{}; - - uint256 nCollateralMinConfBlockHash{}; - int nBlockLastPaid{}; - int nPoSeBanScore{}; - int nPoSeBanHeight{}; - bool fAllowMixingTx{}; - bool fUnitTest = false; - - // KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION - std::map mapGovernanceObjectsVotedOn; - - CMasternode(); - CMasternode(const CMasternode& other); - CMasternode(const CMasternodeBroadcast& mnb); - CMasternode(CService addrNew, COutPoint outpointNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn); - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - LOCK(cs); - READWRITE(vin); - READWRITE(addr); - READWRITE(pubKeyCollateralAddress); - READWRITE(pubKeyMasternode); - READWRITE(lastPing); - READWRITE(vchSig); - READWRITE(sigTime); - READWRITE(nLastDsq); - READWRITE(nTimeLastChecked); - READWRITE(nTimeLastPaid); - READWRITE(nTimeLastWatchdogVote); - READWRITE(nActiveState); - READWRITE(nCollateralMinConfBlockHash); - READWRITE(nBlockLastPaid); - READWRITE(nProtocolVersion); - READWRITE(nPoSeBanScore); - READWRITE(nPoSeBanHeight); - READWRITE(fAllowMixingTx); - READWRITE(fUnitTest); - READWRITE(mapGovernanceObjectsVotedOn); - } - - // CALCULATE A RANK AGAINST OF GIVEN BLOCK - arith_uint256 CalculateScore(const uint256& blockHash); - - bool UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman); - - static CollateralStatus CheckCollateral(const COutPoint& outpoint); - static CollateralStatus CheckCollateral(const COutPoint& outpoint, int& nHeightRet); - void Check(bool fForce = false); - - bool IsBroadcastedWithin(int nSeconds) { return GetAdjustedTime() - sigTime < nSeconds; } - - bool IsPingedWithin(int nSeconds, int64_t nTimeToCheckAt = -1) - { - if(lastPing == CMasternodePing()) return false; - - if(nTimeToCheckAt == -1) { - nTimeToCheckAt = GetAdjustedTime(); - } - return nTimeToCheckAt - lastPing.sigTime < nSeconds; - } - - bool IsEnabled() { return nActiveState == MASTERNODE_ENABLED; } - bool IsPreEnabled() { return nActiveState == MASTERNODE_PRE_ENABLED; } - bool IsPoSeBanned() { return nActiveState == MASTERNODE_POSE_BAN; } - // NOTE: this one relies on nPoSeBanScore, not on nActiveState as everything else here - bool IsPoSeVerified() { return nPoSeBanScore <= -MASTERNODE_POSE_BAN_MAX_SCORE; } - bool IsExpired() { return nActiveState == MASTERNODE_EXPIRED; } - bool IsOutpointSpent() { return nActiveState == MASTERNODE_OUTPOINT_SPENT; } - bool IsUpdateRequired() { return nActiveState == MASTERNODE_UPDATE_REQUIRED; } - bool IsWatchdogExpired() { return nActiveState == MASTERNODE_WATCHDOG_EXPIRED; } - bool IsNewStartRequired() { return nActiveState == MASTERNODE_NEW_START_REQUIRED; } - - static bool IsValidStateForAutoStart(int nActiveStateIn) - { - return nActiveStateIn == MASTERNODE_ENABLED || - nActiveStateIn == MASTERNODE_PRE_ENABLED || - nActiveStateIn == MASTERNODE_EXPIRED || - nActiveStateIn == MASTERNODE_WATCHDOG_EXPIRED; - } - - bool IsValidForPayment() - { - if(nActiveState == MASTERNODE_ENABLED) { - return true; - } - if(!sporkManager.IsSporkActive(SPORK_14_REQUIRE_SENTINEL_FLAG) && - (nActiveState == MASTERNODE_WATCHDOG_EXPIRED)) { - return true; - } - - return false; - } - - /// Is the input associated with collateral public key? (and there is 1000 DASH - checking if valid masternode) - bool IsInputAssociatedWithPubkey(); - - bool IsValidNetAddr(); - static bool IsValidNetAddr(CService addrIn); - - void IncreasePoSeBanScore() { if(nPoSeBanScore < MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore++; } - void DecreasePoSeBanScore() { if(nPoSeBanScore > -MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore--; } - void PoSeBan() { nPoSeBanScore = MASTERNODE_POSE_BAN_MAX_SCORE; } - - masternode_info_t GetInfo(); - - static std::string StateToString(int nStateIn); - std::string GetStateString() const; - std::string GetStatus() const; - - int GetLastPaidTime() { return nTimeLastPaid; } - int GetLastPaidBlock() { return nBlockLastPaid; } - void UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack); - - // KEEP TRACK OF EACH GOVERNANCE ITEM INCASE THIS NODE GOES OFFLINE, SO WE CAN RECALC THEIR STATUS - void AddGovernanceVote(uint256 nGovernanceObjectHash); - // RECALCULATE CACHED STATUS FLAGS FOR ALL AFFECTED OBJECTS - void FlagGovernanceItemsAsDirty(); - - void RemoveGovernanceObject(uint256 nGovernanceObjectHash); - - void UpdateWatchdogVoteTime(uint64_t nVoteTime = 0); - - CMasternode& operator=(CMasternode const& from) - { - static_cast(*this)=from; - lastPing = from.lastPing; - vchSig = from.vchSig; - nCollateralMinConfBlockHash = from.nCollateralMinConfBlockHash; - nBlockLastPaid = from.nBlockLastPaid; - nPoSeBanScore = from.nPoSeBanScore; - nPoSeBanHeight = from.nPoSeBanHeight; - fAllowMixingTx = from.fAllowMixingTx; - fUnitTest = from.fUnitTest; - mapGovernanceObjectsVotedOn = from.mapGovernanceObjectsVotedOn; - return *this; - } -}; - -inline bool operator==(const CMasternode& a, const CMasternode& b) -{ - return a.vin == b.vin; -} -inline bool operator!=(const CMasternode& a, const CMasternode& b) -{ - return !(a.vin == b.vin); -} - - -// -// The Masternode Broadcast Class : Contains a different serialize method for sending masternodes through the network -// - -class CMasternodeBroadcast : public CMasternode -{ -public: - - bool fRecovery; - - CMasternodeBroadcast() : CMasternode(), fRecovery(false) {} - CMasternodeBroadcast(const CMasternode& mn) : CMasternode(mn), fRecovery(false) {} - CMasternodeBroadcast(CService addrNew, COutPoint outpointNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn) : - CMasternode(addrNew, outpointNew, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nProtocolVersionIn), fRecovery(false) {} - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(vin); - READWRITE(addr); - READWRITE(pubKeyCollateralAddress); - READWRITE(pubKeyMasternode); - READWRITE(vchSig); - READWRITE(sigTime); - READWRITE(nProtocolVersion); - READWRITE(lastPing); - } - - uint256 GetHash() const - { - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << vin; - ss << pubKeyCollateralAddress; - ss << sigTime; - return ss.GetHash(); - } - - /// Create Masternode broadcast, needs to be relayed manually after that - static bool Create(const COutPoint& outpoint, const CService& service, const CKey& keyCollateralAddressNew, const CPubKey& pubKeyCollateralAddressNew, const CKey& keyMasternodeNew, const CPubKey& pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet); - static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline = false); - - bool SimpleCheck(int& nDos); - bool Update(CMasternode* pmn, int& nDos, CConnman& connman); - bool CheckOutpoint(int& nDos); - - bool Sign(const CKey& keyCollateralAddress); - bool CheckSignature(int& nDos); - void Relay(CConnman& connman); -}; - -class CMasternodeVerification -{ -public: - CTxIn vin1{}; - CTxIn vin2{}; - CService addr{}; - int nonce{}; - int nBlockHeight{}; - std::vector vchSig1{}; - std::vector vchSig2{}; - - CMasternodeVerification() = default; - - CMasternodeVerification(CService addr, int nonce, int nBlockHeight) : - addr(addr), - nonce(nonce), - nBlockHeight(nBlockHeight) - {} - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(vin1); - READWRITE(vin2); - READWRITE(addr); - READWRITE(nonce); - READWRITE(nBlockHeight); - READWRITE(vchSig1); - READWRITE(vchSig2); - } - - uint256 GetHash() const - { - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << vin1; - ss << vin2; - ss << addr; - ss << nonce; - ss << nBlockHeight; - return ss.GetHash(); - } - - void Relay() const - { - CInv inv(MSG_MASTERNODE_VERIFY, GetHash()); - g_connman->RelayInv(inv); - } -}; - -#endif From 605f6dc0f233fad68f4a9f63331cc032e389c79b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:32 -0400 Subject: [PATCH 0731/1324] Delete masternodeconfig.cpp --- src/masternodeconfig.cpp | 90 ---------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 src/masternodeconfig.cpp diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp deleted file mode 100644 index 2832fd16..00000000 --- a/src/masternodeconfig.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "netbase.h" -#include "masternodeconfig.h" -#include "util.h" -#include "chainparams.h" - -#include -#include - -CMasternodeConfig masternodeConfig; - -void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { - CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex); - entries.push_back(cme); -} - -bool CMasternodeConfig::read(std::string& strErr) { - int linenumber = 1; - boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile(); - boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile); - - if (!streamConfig.good()) { - FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a"); - if (configFile != NULL) { - std::string strHeader = "# Masternode config file\n" - "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" - "# Example: mn1 127.0.0.2:6888 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n"; - fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile); - fclose(configFile); - } - return true; // Nothing to read, so just return - } - - for(std::string line; std::getline(streamConfig, line); linenumber++) - { - if(line.empty()) continue; - - std::istringstream iss(line); - std::string comment, alias, ip, privKey, txHash, outputIndex; - - if (iss >> comment) { - if(comment.at(0) == '#') continue; - iss.str(line); - iss.clear(); - } - - if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { - iss.str(line); - iss.clear(); - if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { - strErr = _("Could not parse masternode.conf") + "\n" + - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; - streamConfig.close(); - return false; - } - } - - int port = 0; - std::string hostname = ""; - SplitHostPort(ip, port, hostname); - if(port == 0 || hostname == "") { - strErr = _("Failed to parse host:port string") + "\n"+ - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; - streamConfig.close(); - return false; - } - int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); - if(Params().NetworkIDString() == CBaseChainParams::MAIN) { - if(port != mainnetDefaultPort) { - strErr = _("Invalid port detected in masternode.conf") + "\n" + - strprintf(_("Port: %d"), port) + "\n" + - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + - strprintf(_("(must be %d for mainnet)"), mainnetDefaultPort); - streamConfig.close(); - return false; - } - } else if(port == mainnetDefaultPort) { - strErr = _("Invalid port detected in masternode.conf") + "\n" + - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + - strprintf(_("(%d could be used only on mainnet)"), mainnetDefaultPort); - streamConfig.close(); - return false; - } - - - add(alias, ip, privKey, txHash, outputIndex); - } - - streamConfig.close(); - return true; -} From 6b8cb4ca0a885af0c4d503335b34aeb98f4253c3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:41 -0400 Subject: [PATCH 0732/1324] Delete masternodeconfig.h --- src/masternodeconfig.h | 98 ------------------------------------------ 1 file changed, 98 deletions(-) delete mode 100644 src/masternodeconfig.h diff --git a/src/masternodeconfig.h b/src/masternodeconfig.h deleted file mode 100644 index 6896d5c9..00000000 --- a/src/masternodeconfig.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef SRC_MASTERNODECONFIG_H_ -#define SRC_MASTERNODECONFIG_H_ - -class CMasternodeConfig; -extern CMasternodeConfig masternodeConfig; - -class CMasternodeConfig -{ - -public: - - class CMasternodeEntry { - - private: - std::string alias; - std::string ip; - std::string privKey; - std::string txHash; - std::string outputIndex; - public: - - CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) { - this->alias = alias; - this->ip = ip; - this->privKey = privKey; - this->txHash = txHash; - this->outputIndex = outputIndex; - } - - const std::string& getAlias() const { - return alias; - } - - void setAlias(const std::string& alias) { - this->alias = alias; - } - - const std::string& getOutputIndex() const { - return outputIndex; - } - - void setOutputIndex(const std::string& outputIndex) { - this->outputIndex = outputIndex; - } - - const std::string& getPrivKey() const { - return privKey; - } - - void setPrivKey(const std::string& privKey) { - this->privKey = privKey; - } - - const std::string& getTxHash() const { - return txHash; - } - - void setTxHash(const std::string& txHash) { - this->txHash = txHash; - } - - const std::string& getIp() const { - return ip; - } - - void setIp(const std::string& ip) { - this->ip = ip; - } - }; - - CMasternodeConfig() { - entries = std::vector(); - } - - void clear(); - bool read(std::string& strErr); - void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); - - std::vector& getEntries() { - return entries; - } - - int getCount() { - return (int)entries.size(); - } - -private: - std::vector entries; - - -}; - - -#endif /* SRC_MASTERNODECONFIG_H_ */ From 7684c70491d68822ccbf83c3b9f881e5852ef133 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:49 -0400 Subject: [PATCH 0733/1324] Delete masternodeman.cpp --- src/masternodeman.cpp | 1576 ----------------------------------------- 1 file changed, 1576 deletions(-) delete mode 100644 src/masternodeman.cpp diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp deleted file mode 100644 index d445d945..00000000 --- a/src/masternodeman.cpp +++ /dev/null @@ -1,1576 +0,0 @@ -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "activemasternode.h" -#include "addrman.h" -#include "governance.h" -#include "masternode-payments.h" -#include "masternode-sync.h" -#include "masternodeman.h" -#include "messagesigner.h" -#include "netfulfilledman.h" -#ifdef ENABLE_WALLET -#include "privatesend-client.h" -#endif // ENABLE_WALLET -#include "script/standard.h" -#include "util.h" - -/** Masternode manager */ -CMasternodeMan mnodeman; - -const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-7"; - -struct CompareLastPaidBlock -{ - bool operator()(const std::pair& t1, - const std::pair& t2) const - { - return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); - } -}; - -struct CompareScoreMN -{ - bool operator()(const std::pair& t1, - const std::pair& t2) const - { - return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->vin < t2.second->vin); - } -}; - -struct CompareByAddr - -{ - bool operator()(const CMasternode* t1, - const CMasternode* t2) const - { - return t1->addr < t2->addr; - } -}; - -CMasternodeMan::CMasternodeMan() -: cs(), - mapMasternodes(), - mAskedUsForMasternodeList(), - mWeAskedForMasternodeList(), - mWeAskedForMasternodeListEntry(), - mWeAskedForVerification(), - mMnbRecoveryRequests(), - mMnbRecoveryGoodReplies(), - listScheduledMnbRequestConnections(), - fMasternodesAdded(false), - fMasternodesRemoved(false), - vecDirtyGovernanceObjectHashes(), - nLastWatchdogVoteTime(0), - mapSeenMasternodeBroadcast(), - mapSeenMasternodePing(), - nDsqCount(0) -{} - -bool CMasternodeMan::Add(CMasternode &mn) -{ - LOCK(cs); - - if (Has(mn.vin.prevout)) return false; - - LogPrint("masternode", "CMasternodeMan::Add -- Adding new Masternode: addr=%s, %i now\n", mn.addr.ToString(), size() + 1); - mapMasternodes[mn.vin.prevout] = mn; - fMasternodesAdded = true; - return true; -} - -void CMasternodeMan::AskForMN(CNode* pnode, const COutPoint& outpoint, CConnman& connman) -{ - if(!pnode) return; - - LOCK(cs); - - std::map >::iterator it1 = mWeAskedForMasternodeListEntry.find(outpoint); - if (it1 != mWeAskedForMasternodeListEntry.end()) { - std::map::iterator it2 = it1->second.find(pnode->addr); - if (it2 != it1->second.end()) { - if (GetTime() < it2->second) { - // we've asked recently, should not repeat too often or we could get banned - return; - } - // we asked this node for this outpoint but it's ok to ask again already - LogPrintf("CMasternodeMan::AskForMN -- Asking same peer %s for missing masternode entry again: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); - } else { - // we already asked for this outpoint but not this node - LogPrintf("CMasternodeMan::AskForMN -- Asking new peer %s for missing masternode entry: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); - } - } else { - // we never asked any node for this outpoint - LogPrintf("CMasternodeMan::AskForMN -- Asking peer %s for missing masternode entry for the first time: %s\n", pnode->addr.ToString(), outpoint.ToStringShort()); - } - mWeAskedForMasternodeListEntry[outpoint][pnode->addr] = GetTime() + DSEG_UPDATE_SECONDS; - - connman.PushMessage(pnode, NetMsgType::DSEG, CTxIn(outpoint)); -} - -bool CMasternodeMan::AllowMixing(const COutPoint &outpoint) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if (!pmn) { - return false; - } - nDsqCount++; - pmn->nLastDsq = nDsqCount; - pmn->fAllowMixingTx = true; - - return true; -} - -bool CMasternodeMan::DisallowMixing(const COutPoint &outpoint) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if (!pmn) { - return false; - } - pmn->fAllowMixingTx = false; - - return true; -} - -bool CMasternodeMan::PoSeBan(const COutPoint &outpoint) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if (!pmn) { - return false; - } - pmn->PoSeBan(); - - return true; -} - -void CMasternodeMan::Check() -{ - LOCK(cs); - - LogPrint("masternode", "CMasternodeMan::Check -- nLastWatchdogVoteTime=%d, IsWatchdogActive()=%d\n", nLastWatchdogVoteTime, IsWatchdogActive()); - - for (auto& mnpair : mapMasternodes) { - mnpair.second.Check(); - } -} - -void CMasternodeMan::CheckAndRemove(CConnman& connman) -{ - if(!masternodeSync.IsMasternodeListSynced()) return; - - LogPrintf("CMasternodeMan::CheckAndRemove\n"); - - { - // Need LOCK2 here to ensure consistent locking order because code below locks cs_main - // in CheckMnbAndUpdateMasternodeList() - LOCK2(cs_main, cs); - - Check(); - - // Remove spent masternodes, prepare structures and make requests to reasure the state of inactive ones - rank_pair_vec_t vecMasternodeRanks; - // ask for up to MNB_RECOVERY_MAX_ASK_ENTRIES masternode entries at a time - int nAskForMnbRecovery = MNB_RECOVERY_MAX_ASK_ENTRIES; - std::map::iterator it = mapMasternodes.begin(); - while (it != mapMasternodes.end()) { - CMasternodeBroadcast mnb = CMasternodeBroadcast(it->second); - uint256 hash = mnb.GetHash(); - // If collateral was spent ... - if (it->second.IsOutpointSpent()) { - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing Masternode: %s addr=%s %i now\n", it->second.GetStateString(), it->second.addr.ToString(), size() - 1); - - // erase all of the broadcasts we've seen from this txin, ... - mapSeenMasternodeBroadcast.erase(hash); - mWeAskedForMasternodeListEntry.erase(it->first); - - // and finally remove it from the list - it->second.FlagGovernanceItemsAsDirty(); - mapMasternodes.erase(it++); - fMasternodesRemoved = true; - } else { - bool fAsk = (nAskForMnbRecovery > 0) && - masternodeSync.IsSynced() && - it->second.IsNewStartRequired() && - !IsMnbRecoveryRequested(hash); - if(fAsk) { - // this mn is in a non-recoverable state and we haven't asked other nodes yet - std::set setRequested; - // calulate only once and only when it's needed - if(vecMasternodeRanks.empty()) { - int nRandomBlockHeight = GetRandInt(nCachedBlockHeight); - GetMasternodeRanks(vecMasternodeRanks, nRandomBlockHeight); - } - bool fAskedForMnbRecovery = false; - // ask first MNB_RECOVERY_QUORUM_TOTAL masternodes we can connect to and we haven't asked recently - for(int i = 0; setRequested.size() < MNB_RECOVERY_QUORUM_TOTAL && i < (int)vecMasternodeRanks.size(); i++) { - // avoid banning - if(mWeAskedForMasternodeListEntry.count(it->first) && mWeAskedForMasternodeListEntry[it->first].count(vecMasternodeRanks[i].second.addr)) continue; - // didn't ask recently, ok to ask now - CService addr = vecMasternodeRanks[i].second.addr; - setRequested.insert(addr); - listScheduledMnbRequestConnections.push_back(std::make_pair(addr, hash)); - fAskedForMnbRecovery = true; - } - if(fAskedForMnbRecovery) { - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Recovery initiated, masternode=%s\n", it->first.ToStringShort()); - nAskForMnbRecovery--; - } - // wait for mnb recovery replies for MNB_RECOVERY_WAIT_SECONDS seconds - mMnbRecoveryRequests[hash] = std::make_pair(GetTime() + MNB_RECOVERY_WAIT_SECONDS, setRequested); - } - ++it; - } - } - - // proces replies for MASTERNODE_NEW_START_REQUIRED masternodes - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- mMnbRecoveryGoodReplies size=%d\n", (int)mMnbRecoveryGoodReplies.size()); - std::map >::iterator itMnbReplies = mMnbRecoveryGoodReplies.begin(); - while(itMnbReplies != mMnbRecoveryGoodReplies.end()){ - if(mMnbRecoveryRequests[itMnbReplies->first].first < GetTime()) { - // all nodes we asked should have replied now - if(itMnbReplies->second.size() >= MNB_RECOVERY_QUORUM_REQUIRED) { - // majority of nodes we asked agrees that this mn doesn't require new mnb, reprocess one of new mnbs - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- reprocessing mnb, masternode=%s\n", itMnbReplies->second[0].vin.prevout.ToStringShort()); - // mapSeenMasternodeBroadcast.erase(itMnbReplies->first); - int nDos; - itMnbReplies->second[0].fRecovery = true; - CheckMnbAndUpdateMasternodeList(NULL, itMnbReplies->second[0], nDos, connman); - } - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- removing mnb recovery reply, masternode=%s, size=%d\n", itMnbReplies->second[0].vin.prevout.ToStringShort(), (int)itMnbReplies->second.size()); - mMnbRecoveryGoodReplies.erase(itMnbReplies++); - } else { - ++itMnbReplies; - } - } - } - { - // no need for cm_main below - LOCK(cs); - - std::map > >::iterator itMnbRequest = mMnbRecoveryRequests.begin(); - while(itMnbRequest != mMnbRecoveryRequests.end()){ - // Allow this mnb to be re-verified again after MNB_RECOVERY_RETRY_SECONDS seconds - // if mn is still in MASTERNODE_NEW_START_REQUIRED state. - if(GetTime() - itMnbRequest->second.first > MNB_RECOVERY_RETRY_SECONDS) { - mMnbRecoveryRequests.erase(itMnbRequest++); - } else { - ++itMnbRequest; - } - } - - // check who's asked for the Masternode list - std::map::iterator it1 = mAskedUsForMasternodeList.begin(); - while(it1 != mAskedUsForMasternodeList.end()){ - if((*it1).second < GetTime()) { - mAskedUsForMasternodeList.erase(it1++); - } else { - ++it1; - } - } - - // check who we asked for the Masternode list - it1 = mWeAskedForMasternodeList.begin(); - while(it1 != mWeAskedForMasternodeList.end()){ - if((*it1).second < GetTime()){ - mWeAskedForMasternodeList.erase(it1++); - } else { - ++it1; - } - } - - // check which Masternodes we've asked for - std::map >::iterator it2 = mWeAskedForMasternodeListEntry.begin(); - while(it2 != mWeAskedForMasternodeListEntry.end()){ - std::map::iterator it3 = it2->second.begin(); - while(it3 != it2->second.end()){ - if(it3->second < GetTime()){ - it2->second.erase(it3++); - } else { - ++it3; - } - } - if(it2->second.empty()) { - mWeAskedForMasternodeListEntry.erase(it2++); - } else { - ++it2; - } - } - - std::map::iterator it3 = mWeAskedForVerification.begin(); - while(it3 != mWeAskedForVerification.end()){ - if(it3->second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) { - mWeAskedForVerification.erase(it3++); - } else { - ++it3; - } - } - - // NOTE: do not expire mapSeenMasternodeBroadcast entries here, clean them on mnb updates! - - // remove expired mapSeenMasternodePing - std::map::iterator it4 = mapSeenMasternodePing.begin(); - while(it4 != mapSeenMasternodePing.end()){ - if((*it4).second.IsExpired()) { - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing expired Masternode ping: hash=%s\n", (*it4).second.GetHash().ToString()); - mapSeenMasternodePing.erase(it4++); - } else { - ++it4; - } - } - - // remove expired mapSeenMasternodeVerification - std::map::iterator itv2 = mapSeenMasternodeVerification.begin(); - while(itv2 != mapSeenMasternodeVerification.end()){ - if((*itv2).second.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS){ - LogPrint("masternode", "CMasternodeMan::CheckAndRemove -- Removing expired Masternode verification: hash=%s\n", (*itv2).first.ToString()); - mapSeenMasternodeVerification.erase(itv2++); - } else { - ++itv2; - } - } - - LogPrintf("CMasternodeMan::CheckAndRemove -- %s\n", ToString()); - } - - if(fMasternodesRemoved) { - NotifyMasternodeUpdates(connman); - } -} - -void CMasternodeMan::Clear() -{ - LOCK(cs); - mapMasternodes.clear(); - mAskedUsForMasternodeList.clear(); - mWeAskedForMasternodeList.clear(); - mWeAskedForMasternodeListEntry.clear(); - mapSeenMasternodeBroadcast.clear(); - mapSeenMasternodePing.clear(); - nDsqCount = 0; - nLastWatchdogVoteTime = 0; -} - -int CMasternodeMan::CountMasternodes(int nProtocolVersion) -{ - LOCK(cs); - int nCount = 0; - nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; - - for (auto& mnpair : mapMasternodes) { - if(mnpair.second.nProtocolVersion < nProtocolVersion) continue; - nCount++; - } - - return nCount; -} - -int CMasternodeMan::CountEnabled(int nProtocolVersion) -{ - LOCK(cs); - int nCount = 0; - nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; - - for (auto& mnpair : mapMasternodes) { - if(mnpair.second.nProtocolVersion < nProtocolVersion || !mnpair.second.IsEnabled()) continue; - nCount++; - } - - return nCount; -} - -/* Only IPv4 masternodes are allowed in 12.1, saving this for later -int CMasternodeMan::CountByIP(int nNetworkType) -{ - LOCK(cs); - int nNodeCount = 0; - for (auto& mnpair : mapMasternodes) - if ((nNetworkType == NET_IPV4 && mnpair.second.addr.IsIPv4()) || - (nNetworkType == NET_TOR && mnpair.second.addr.IsTor()) || - (nNetworkType == NET_IPV6 && mnpair.second.addr.IsIPv6())) { - nNodeCount++; - } - return nNodeCount; -} -*/ - -void CMasternodeMan::DsegUpdate(CNode* pnode, CConnman& connman) -{ - LOCK(cs); - - if(Params().NetworkIDString() == CBaseChainParams::MAIN) { - if(!(pnode->addr.IsRFC1918() || pnode->addr.IsLocal())) { - std::map::iterator it = mWeAskedForMasternodeList.find(pnode->addr); - if(it != mWeAskedForMasternodeList.end() && GetTime() < (*it).second) { - LogPrintf("CMasternodeMan::DsegUpdate -- we already asked %s for the list; skipping...\n", pnode->addr.ToString()); - return; - } - } - } - - connman.PushMessage(pnode, NetMsgType::DSEG, CTxIn()); - int64_t askAgain = GetTime() + DSEG_UPDATE_SECONDS; - mWeAskedForMasternodeList[pnode->addr] = askAgain; - - LogPrint("masternode", "CMasternodeMan::DsegUpdate -- asked %s for the list\n", pnode->addr.ToString()); -} - -CMasternode* CMasternodeMan::Find(const COutPoint &outpoint) -{ - LOCK(cs); - auto it = mapMasternodes.find(outpoint); - return it == mapMasternodes.end() ? NULL : &(it->second); -} - -bool CMasternodeMan::Get(const COutPoint& outpoint, CMasternode& masternodeRet) -{ - // Theses mutexes are recursive so double locking by the same thread is safe. - LOCK(cs); - auto it = mapMasternodes.find(outpoint); - if (it == mapMasternodes.end()) { - return false; - } - - masternodeRet = it->second; - return true; -} - -bool CMasternodeMan::GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet) -{ - LOCK(cs); - auto it = mapMasternodes.find(outpoint); - if (it == mapMasternodes.end()) { - return false; - } - mnInfoRet = it->second.GetInfo(); - return true; -} - -bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet) -{ - LOCK(cs); - for (auto& mnpair : mapMasternodes) { - if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { - mnInfoRet = mnpair.second.GetInfo(); - return true; - } - } - return false; -} - -bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet) -{ - LOCK(cs); - for (auto& mnpair : mapMasternodes) { - CScript scriptCollateralAddress = GetScriptForDestination(mnpair.second.pubKeyCollateralAddress.GetID()); - if (scriptCollateralAddress == payee) { - mnInfoRet = mnpair.second.GetInfo(); - return true; - } - } - return false; -} - -bool CMasternodeMan::Has(const COutPoint& outpoint) -{ - LOCK(cs); - return mapMasternodes.find(outpoint) != mapMasternodes.end(); -} - -// -// Deterministically select the oldest/best masternode to pay on the network -// -bool CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) -{ - return GetNextMasternodeInQueueForPayment(nCachedBlockHeight, fFilterSigTime, nCountRet, mnInfoRet); -} - -bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) -{ - mnInfoRet = masternode_info_t(); - nCountRet = 0; - - if (!masternodeSync.IsWinnersListSynced()) { - // without winner list we can't reliably find the next winner anyway - return false; - } - - // Need LOCK2 here to ensure consistent locking order because the GetBlockHash call below locks cs_main - LOCK2(cs_main,cs); - - std::vector > vecMasternodeLastPaid; - - /* - Make a vector with all of the last paid times - */ - - int nMnCount = CountMasternodes(); - - for (auto& mnpair : mapMasternodes) { - if(!mnpair.second.IsValidForPayment()) continue; - - //check protocol version - if(mnpair.second.nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto()) continue; - - //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it - if(mnpayments.IsScheduled(mnpair.second, nBlockHeight)) continue; - - //it's too new, wait for a cycle - if(fFilterSigTime && mnpair.second.sigTime + (nMnCount*2.6*60) > GetAdjustedTime()) continue; - - //make sure it has at least as many confirmations as there are masternodes - if(GetUTXOConfirmations(mnpair.first) < nMnCount) continue; - - vecMasternodeLastPaid.push_back(std::make_pair(mnpair.second.GetLastPaidBlock(), &mnpair.second)); - } - - nCountRet = (int)vecMasternodeLastPaid.size(); - - //when the network is in the process of upgrading, don't penalize nodes that recently restarted - if(fFilterSigTime && nCountRet < nMnCount/3) - return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCountRet, mnInfoRet); - - // Sort them low to high - sort(vecMasternodeLastPaid.begin(), vecMasternodeLastPaid.end(), CompareLastPaidBlock()); - - uint256 blockHash; - if(!GetBlockHash(blockHash, nBlockHeight - 101)) { - LogPrintf("CMasternode::GetNextMasternodeInQueueForPayment -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", nBlockHeight - 101); - return false; - } - // Look at 1/10 of the oldest nodes (by last payment), calculate their scores and pay the best one - // -- This doesn't look at who is being paid in the +8-10 blocks, allowing for double payments very rarely - // -- 1/100 payments should be a double payment on mainnet - (1/(3000/10))*2 - // -- (chance per block * chances before IsScheduled will fire) - int nTenthNetwork = nMnCount/10; - int nCountTenth = 0; - arith_uint256 nHighest = 0; - CMasternode *pBestMasternode = NULL; - BOOST_FOREACH (PAIRTYPE(int, CMasternode*)& s, vecMasternodeLastPaid){ - arith_uint256 nScore = s.second->CalculateScore(blockHash); - if(nScore > nHighest){ - nHighest = nScore; - pBestMasternode = s.second; - } - nCountTenth++; - if(nCountTenth >= nTenthNetwork) break; - } - if (pBestMasternode) { - mnInfoRet = pBestMasternode->GetInfo(); - } - return mnInfoRet.fInfoValid; -} - -masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vector &vecToExclude, int nProtocolVersion) -{ - LOCK(cs); - - nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; - - int nCountEnabled = CountEnabled(nProtocolVersion); - int nCountNotExcluded = nCountEnabled - vecToExclude.size(); - - LogPrintf("CMasternodeMan::FindRandomNotInVec -- %d enabled masternodes, %d masternodes to choose from\n", nCountEnabled, nCountNotExcluded); - if(nCountNotExcluded < 1) return masternode_info_t(); - - // fill a vector of pointers - std::vector vpMasternodesShuffled; - for (auto& mnpair : mapMasternodes) { - vpMasternodesShuffled.push_back(&mnpair.second); - } - - InsecureRand insecureRand; - // shuffle pointers - std::random_shuffle(vpMasternodesShuffled.begin(), vpMasternodesShuffled.end(), insecureRand); - bool fExclude; - - // loop through - BOOST_FOREACH(CMasternode* pmn, vpMasternodesShuffled) { - if(pmn->nProtocolVersion < nProtocolVersion || !pmn->IsEnabled()) continue; - fExclude = false; - BOOST_FOREACH(const COutPoint &outpointToExclude, vecToExclude) { - if(pmn->vin.prevout == outpointToExclude) { - fExclude = true; - break; - } - } - if(fExclude) continue; - // found the one not in vecToExclude - LogPrint("masternode", "CMasternodeMan::FindRandomNotInVec -- found, masternode=%s\n", pmn->vin.prevout.ToStringShort()); - return pmn->GetInfo(); - } - - LogPrint("masternode", "CMasternodeMan::FindRandomNotInVec -- failed\n"); - return masternode_info_t(); -} - -bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeMan::score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol) -{ - vecMasternodeScoresRet.clear(); - - if (!masternodeSync.IsMasternodeListSynced()) - return false; - - AssertLockHeld(cs); - - if (mapMasternodes.empty()) - return false; - - // calculate scores - for (auto& mnpair : mapMasternodes) { - if (mnpair.second.nProtocolVersion >= nMinProtocol) { - vecMasternodeScoresRet.push_back(std::make_pair(mnpair.second.CalculateScore(nBlockHash), &mnpair.second)); - } - } - - sort(vecMasternodeScoresRet.rbegin(), vecMasternodeScoresRet.rend(), CompareScoreMN()); - return !vecMasternodeScoresRet.empty(); -} - -bool CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int& nRankRet, int nBlockHeight, int nMinProtocol) -{ - nRankRet = -1; - - if (!masternodeSync.IsMasternodeListSynced()) - return false; - - // make sure we know about this block - uint256 nBlockHash = uint256(); - if (!GetBlockHash(nBlockHash, nBlockHeight)) { - LogPrintf("CMasternodeMan::%s -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", __func__, nBlockHeight); - return false; - } - - LOCK(cs); - - score_pair_vec_t vecMasternodeScores; - if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol)) - return false; - - int nRank = 0; - for (auto& scorePair : vecMasternodeScores) { - nRank++; - if(scorePair.second->vin.prevout == outpoint) { - nRankRet = nRank; - return true; - } - } - - return false; -} - -bool CMasternodeMan::GetMasternodeRanks(CMasternodeMan::rank_pair_vec_t& vecMasternodeRanksRet, int nBlockHeight, int nMinProtocol) -{ - vecMasternodeRanksRet.clear(); - - if (!masternodeSync.IsMasternodeListSynced()) - return false; - - // make sure we know about this block - uint256 nBlockHash = uint256(); - if (!GetBlockHash(nBlockHash, nBlockHeight)) { - LogPrintf("CMasternodeMan::%s -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", __func__, nBlockHeight); - return false; - } - - LOCK(cs); - - score_pair_vec_t vecMasternodeScores; - if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol)) - return false; - - int nRank = 0; - for (auto& scorePair : vecMasternodeScores) { - nRank++; - vecMasternodeRanksRet.push_back(std::make_pair(nRank, *scorePair.second)); - } - - return true; -} - -void CMasternodeMan::ProcessMasternodeConnections(CConnman& connman) -{ - //we don't care about this for regtest - if(Params().NetworkIDString() == CBaseChainParams::REGTEST) return; - - connman.ForEachNode(CConnman::AllNodes, [](CNode* pnode) { -#ifdef ENABLE_WALLET - if(pnode->fMasternode && !privateSendClient.IsMixingMasternode(pnode)) { -#else - if(pnode->fMasternode) { -#endif // ENABLE_WALLET - LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->id, pnode->addr.ToString()); - pnode->fDisconnect = true; - } - }); -} - -std::pair > CMasternodeMan::PopScheduledMnbRequestConnection() -{ - LOCK(cs); - if(listScheduledMnbRequestConnections.empty()) { - return std::make_pair(CService(), std::set()); - } - - std::set setResult; - - listScheduledMnbRequestConnections.sort(); - std::pair pairFront = listScheduledMnbRequestConnections.front(); - - // squash hashes from requests with the same CService as the first one into setResult - std::list< std::pair >::iterator it = listScheduledMnbRequestConnections.begin(); - while(it != listScheduledMnbRequestConnections.end()) { - if(pairFront.first == it->first) { - setResult.insert(it->second); - it = listScheduledMnbRequestConnections.erase(it); - } else { - // since list is sorted now, we can be sure that there is no more hashes left - // to ask for from this addr - break; - } - } - return std::make_pair(pairFront.first, setResult); -} - - -void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman) -{ - if(fLiteMode) return; // disable all Dash specific functionality - - if (strCommand == NetMsgType::MNANNOUNCE) { //Masternode Broadcast - - CMasternodeBroadcast mnb; - vRecv >> mnb; - - pfrom->setAskFor.erase(mnb.GetHash()); - - if(!masternodeSync.IsBlockchainSynced()) return; - - LogPrint("masternode", "MNANNOUNCE -- Masternode announce, masternode=%s\n", mnb.vin.prevout.ToStringShort()); - - int nDos = 0; - - if (CheckMnbAndUpdateMasternodeList(pfrom, mnb, nDos, connman)) { - // use announced Masternode as a peer - connman.AddNewAddress(CAddress(mnb.addr, NODE_NETWORK), pfrom->addr, 2*60*60); - } else if(nDos > 0) { - Misbehaving(pfrom->GetId(), nDos); - } - - if(fMasternodesAdded) { - NotifyMasternodeUpdates(connman); - } - } else if (strCommand == NetMsgType::MNPING) { //Masternode Ping - - CMasternodePing mnp; - vRecv >> mnp; - - uint256 nHash = mnp.GetHash(); - - pfrom->setAskFor.erase(nHash); - - if(!masternodeSync.IsBlockchainSynced()) return; - - LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort()); - - // Need LOCK2 here to ensure consistent locking order because the CheckAndUpdate call below locks cs_main - LOCK2(cs_main, cs); - - if(mapSeenMasternodePing.count(nHash)) return; //seen - mapSeenMasternodePing.insert(std::make_pair(nHash, mnp)); - - LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); - - // see if we have this Masternode - CMasternode* pmn = Find(mnp.vin.prevout); - - // if masternode uses sentinel ping instead of watchdog - // we shoud update nTimeLastWatchdogVote here if sentinel - // ping flag is actual - if(pmn && mnp.fSentinelIsCurrent) - UpdateWatchdogVoteTime(mnp.vin.prevout, mnp.sigTime); - - // too late, new MNANNOUNCE is required - if(pmn && pmn->IsNewStartRequired()) return; - - int nDos = 0; - if(mnp.CheckAndUpdate(pmn, false, nDos, connman)) return; - - if(nDos > 0) { - // if anything significant failed, mark that node - Misbehaving(pfrom->GetId(), nDos); - } else if(pmn != NULL) { - // nothing significant failed, mn is a known one too - return; - } - - // something significant is broken or mn is unknown, - // we might have to ask for a masternode entry once - AskForMN(pfrom, mnp.vin.prevout, connman); - - } else if (strCommand == NetMsgType::DSEG) { //Get Masternode list or specific entry - // Ignore such requests until we are fully synced. - // We could start processing this after masternode list is synced - // but this is a heavy one so it's better to finish sync first. - if (!masternodeSync.IsSynced()) return; - - CTxIn vin; - vRecv >> vin; - - LogPrint("masternode", "DSEG -- Masternode list, masternode=%s\n", vin.prevout.ToStringShort()); - - LOCK(cs); - - if(vin == CTxIn()) { //only should ask for this once - //local network - bool isLocal = (pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal()); - - if(!isLocal && Params().NetworkIDString() == CBaseChainParams::MAIN) { - std::map::iterator it = mAskedUsForMasternodeList.find(pfrom->addr); - if (it != mAskedUsForMasternodeList.end() && it->second > GetTime()) { - Misbehaving(pfrom->GetId(), 34); - LogPrintf("DSEG -- peer already asked me for the list, peer=%d\n", pfrom->id); - return; - } - int64_t askAgain = GetTime() + DSEG_UPDATE_SECONDS; - mAskedUsForMasternodeList[pfrom->addr] = askAgain; - } - } //else, asking for a specific node which is ok - - int nInvCount = 0; - - for (auto& mnpair : mapMasternodes) { - if (vin != CTxIn() && vin != mnpair.second.vin) continue; // asked for specific vin but we are not there yet - if (mnpair.second.addr.IsRFC1918() || mnpair.second.addr.IsLocal()) continue; // do not send local network masternode - if (mnpair.second.IsUpdateRequired()) continue; // do not send outdated masternodes - - LogPrint("masternode", "DSEG -- Sending Masternode entry: masternode=%s addr=%s\n", mnpair.first.ToStringShort(), mnpair.second.addr.ToString()); - CMasternodeBroadcast mnb = CMasternodeBroadcast(mnpair.second); - CMasternodePing mnp = mnpair.second.lastPing; - uint256 hashMNB = mnb.GetHash(); - uint256 hashMNP = mnp.GetHash(); - pfrom->PushInventory(CInv(MSG_MASTERNODE_ANNOUNCE, hashMNB)); - pfrom->PushInventory(CInv(MSG_MASTERNODE_PING, hashMNP)); - nInvCount++; - - mapSeenMasternodeBroadcast.insert(std::make_pair(hashMNB, std::make_pair(GetTime(), mnb))); - mapSeenMasternodePing.insert(std::make_pair(hashMNP, mnp)); - - if (vin.prevout == mnpair.first) { - LogPrintf("DSEG -- Sent 1 Masternode inv to peer %d\n", pfrom->id); - return; - } - } - - if(vin == CTxIn()) { - connman.PushMessage(pfrom, NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_LIST, nInvCount); - LogPrintf("DSEG -- Sent %d Masternode invs to peer %d\n", nInvCount, pfrom->id); - return; - } - // smth weird happen - someone asked us for vin we have no idea about? - LogPrint("masternode", "DSEG -- No invs sent to peer %d\n", pfrom->id); - - } else if (strCommand == NetMsgType::MNVERIFY) { // Masternode Verify - - // Need LOCK2 here to ensure consistent locking order because the all functions below call GetBlockHash which locks cs_main - LOCK2(cs_main, cs); - - CMasternodeVerification mnv; - vRecv >> mnv; - - pfrom->setAskFor.erase(mnv.GetHash()); - - if(!masternodeSync.IsMasternodeListSynced()) return; - - if(mnv.vchSig1.empty()) { - // CASE 1: someone asked me to verify myself /IP we are using/ - SendVerifyReply(pfrom, mnv, connman); - } else if (mnv.vchSig2.empty()) { - // CASE 2: we _probably_ got verification we requested from some masternode - ProcessVerifyReply(pfrom, mnv); - } else { - // CASE 3: we _probably_ got verification broadcast signed by some masternode which verified another one - ProcessVerifyBroadcast(pfrom, mnv); - } - } -} - -// Verification of masternodes via unique direct requests. - -void CMasternodeMan::DoFullVerificationStep(CConnman& connman) -{ - if(activeMasternode.outpoint == COutPoint()) return; - if(!masternodeSync.IsSynced()) return; - - rank_pair_vec_t vecMasternodeRanks; - GetMasternodeRanks(vecMasternodeRanks, nCachedBlockHeight - 1, MIN_POSE_PROTO_VERSION); - - // Need LOCK2 here to ensure consistent locking order because the SendVerifyRequest call below locks cs_main - // through GetHeight() signal in ConnectNode - LOCK2(cs_main, cs); - - int nCount = 0; - - int nMyRank = -1; - int nRanksTotal = (int)vecMasternodeRanks.size(); - - // send verify requests only if we are in top MAX_POSE_RANK - std::vector >::iterator it = vecMasternodeRanks.begin(); - while(it != vecMasternodeRanks.end()) { - if(it->first > MAX_POSE_RANK) { - LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n", - (int)MAX_POSE_RANK); - return; - } - if(it->second.vin.prevout == activeMasternode.outpoint) { - nMyRank = it->first; - LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n", - nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS); - break; - } - ++it; - } - - // edge case: list is too short and this masternode is not enabled - if(nMyRank == -1) return; - - // send verify requests to up to MAX_POSE_CONNECTIONS masternodes - // starting from MAX_POSE_RANK + nMyRank and using MAX_POSE_CONNECTIONS as a step - int nOffset = MAX_POSE_RANK + nMyRank - 1; - if(nOffset >= (int)vecMasternodeRanks.size()) return; - - std::vector vSortedByAddr; - for (auto& mnpair : mapMasternodes) { - vSortedByAddr.push_back(&mnpair.second); - } - - sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); - - it = vecMasternodeRanks.begin() + nOffset; - while(it != vecMasternodeRanks.end()) { - if(it->second.IsPoSeVerified() || it->second.IsPoSeBanned()) { - LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Already %s%s%s masternode %s address %s, skipping...\n", - it->second.IsPoSeVerified() ? "verified" : "", - it->second.IsPoSeVerified() && it->second.IsPoSeBanned() ? " and " : "", - it->second.IsPoSeBanned() ? "banned" : "", - it->second.vin.prevout.ToStringShort(), it->second.addr.ToString()); - nOffset += MAX_POSE_CONNECTIONS; - if(nOffset >= (int)vecMasternodeRanks.size()) break; - it += MAX_POSE_CONNECTIONS; - continue; - } - LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Verifying masternode %s rank %d/%d address %s\n", - it->second.vin.prevout.ToStringShort(), it->first, nRanksTotal, it->second.addr.ToString()); - if(SendVerifyRequest(CAddress(it->second.addr, NODE_NETWORK), vSortedByAddr, connman)) { - nCount++; - if(nCount >= MAX_POSE_CONNECTIONS) break; - } - nOffset += MAX_POSE_CONNECTIONS; - if(nOffset >= (int)vecMasternodeRanks.size()) break; - it += MAX_POSE_CONNECTIONS; - } - - LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Sent verification requests to %d masternodes\n", nCount); -} - -// This function tries to find masternodes with the same addr, -// find a verified one and ban all the other. If there are many nodes -// with the same addr but none of them is verified yet, then none of them are banned. -// It could take many times to run this before most of the duplicate nodes are banned. - -void CMasternodeMan::CheckSameAddr() -{ - if(!masternodeSync.IsSynced() || mapMasternodes.empty()) return; - - std::vector vBan; - std::vector vSortedByAddr; - - { - LOCK(cs); - - CMasternode* pprevMasternode = NULL; - CMasternode* pverifiedMasternode = NULL; - - for (auto& mnpair : mapMasternodes) { - vSortedByAddr.push_back(&mnpair.second); - } - - sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); - - BOOST_FOREACH(CMasternode* pmn, vSortedByAddr) { - // check only (pre)enabled masternodes - if(!pmn->IsEnabled() && !pmn->IsPreEnabled()) continue; - // initial step - if(!pprevMasternode) { - pprevMasternode = pmn; - pverifiedMasternode = pmn->IsPoSeVerified() ? pmn : NULL; - continue; - } - // second+ step - if(pmn->addr == pprevMasternode->addr) { - if(pverifiedMasternode) { - // another masternode with the same ip is verified, ban this one - vBan.push_back(pmn); - } else if(pmn->IsPoSeVerified()) { - // this masternode with the same ip is verified, ban previous one - vBan.push_back(pprevMasternode); - // and keep a reference to be able to ban following masternodes with the same ip - pverifiedMasternode = pmn; - } - } else { - pverifiedMasternode = pmn->IsPoSeVerified() ? pmn : NULL; - } - pprevMasternode = pmn; - } - } - - // ban duplicates - BOOST_FOREACH(CMasternode* pmn, vBan) { - LogPrintf("CMasternodeMan::CheckSameAddr -- increasing PoSe ban score for masternode %s\n", pmn->vin.prevout.ToStringShort()); - pmn->IncreasePoSeBanScore(); - } -} - -bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman) -{ - if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { - // we already asked for verification, not a good idea to do this too often, skip it - LogPrint("masternode", "CMasternodeMan::SendVerifyRequest -- too many requests, skipping... addr=%s\n", addr.ToString()); - return false; - } - - CNode* pnode = connman.ConnectNode(addr, NULL, true); - if(pnode == NULL) { - LogPrintf("CMasternodeMan::SendVerifyRequest -- can't connect to node to verify it, addr=%s\n", addr.ToString()); - return false; - } - - netfulfilledman.AddFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request"); - // use random nonce, store it and require node to reply with correct one later - CMasternodeVerification mnv(addr, GetRandInt(999999), nCachedBlockHeight - 1); - mWeAskedForVerification[addr] = mnv; - LogPrintf("CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n", mnv.nonce, addr.ToString()); - connman.PushMessage(pnode, NetMsgType::MNVERIFY, mnv); - - return true; -} - -void CMasternodeMan::SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, CConnman& connman) -{ - // only masternodes can sign this, why would someone ask regular node? - if(!fMasterNode) { - // do not ban, malicious node might be using my IP - // and trying to confuse the node which tries to verify it - return; - } - - if(netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-reply")) { - // peer should not ask us that often - LogPrintf("MasternodeMan::SendVerifyReply -- ERROR: peer already asked me recently, peer=%d\n", pnode->id); - Misbehaving(pnode->id, 20); - return; - } - - uint256 blockHash; - if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { - LogPrintf("MasternodeMan::SendVerifyReply -- can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); - return; - } - - std::string strMessage = strprintf("%s%d%s", activeMasternode.service.ToString(false), mnv.nonce, blockHash.ToString()); - - if(!CMessageSigner::SignMessage(strMessage, mnv.vchSig1, activeMasternode.keyMasternode)) { - LogPrintf("MasternodeMan::SendVerifyReply -- SignMessage() failed\n"); - return; - } - - std::string strError; - - if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig1, strMessage, strError)) { - LogPrintf("MasternodeMan::SendVerifyReply -- VerifyMessage() failed, error: %s\n", strError); - return; - } - - connman.PushMessage(pnode, NetMsgType::MNVERIFY, mnv); - netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-reply"); -} - -void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& mnv) -{ - std::string strError; - - // did we even ask for it? if that's the case we should have matching fulfilled request - if(!netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { - LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: we didn't ask for verification of %s, peer=%d\n", pnode->addr.ToString(), pnode->id); - Misbehaving(pnode->id, 20); - return; - } - - // Received nonce for a known address must match the one we sent - if(mWeAskedForVerification[pnode->addr].nonce != mnv.nonce) { - LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: wrong nounce: requested=%d, received=%d, peer=%d\n", - mWeAskedForVerification[pnode->addr].nonce, mnv.nonce, pnode->id); - Misbehaving(pnode->id, 20); - return; - } - - // Received nBlockHeight for a known address must match the one we sent - if(mWeAskedForVerification[pnode->addr].nBlockHeight != mnv.nBlockHeight) { - LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: wrong nBlockHeight: requested=%d, received=%d, peer=%d\n", - mWeAskedForVerification[pnode->addr].nBlockHeight, mnv.nBlockHeight, pnode->id); - Misbehaving(pnode->id, 20); - return; - } - - uint256 blockHash; - if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { - // this shouldn't happen... - LogPrintf("MasternodeMan::ProcessVerifyReply -- can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); - return; - } - - // we already verified this address, why node is spamming? - if(netfulfilledman.HasFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done")) { - LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: already verified %s recently\n", pnode->addr.ToString()); - Misbehaving(pnode->id, 20); - return; - } - - { - LOCK(cs); - - CMasternode* prealMasternode = NULL; - std::vector vpMasternodesToBan; - std::string strMessage1 = strprintf("%s%d%s", pnode->addr.ToString(false), mnv.nonce, blockHash.ToString()); - for (auto& mnpair : mapMasternodes) { - if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) { - if(CMessageSigner::VerifyMessage(mnpair.second.pubKeyMasternode, mnv.vchSig1, strMessage1, strError)) { - // found it! - prealMasternode = &mnpair.second; - if(!mnpair.second.IsPoSeVerified()) { - mnpair.second.DecreasePoSeBanScore(); - } - netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done"); - - // we can only broadcast it if we are an activated masternode - if(activeMasternode.outpoint == COutPoint()) continue; - // update ... - mnv.addr = mnpair.second.addr; - mnv.vin1 = mnpair.second.vin; - mnv.vin2 = CTxIn(activeMasternode.outpoint); - std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), - mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); - // ... and sign it - if(!CMessageSigner::SignMessage(strMessage2, mnv.vchSig2, activeMasternode.keyMasternode)) { - LogPrintf("MasternodeMan::ProcessVerifyReply -- SignMessage() failed\n"); - return; - } - - std::string strError; - - if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { - LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyMessage() failed, error: %s\n", strError); - return; - } - - mWeAskedForVerification[pnode->addr] = mnv; - mapSeenMasternodeVerification.insert(std::make_pair(mnv.GetHash(), mnv)); - mnv.Relay(); - - } else { - vpMasternodesToBan.push_back(&mnpair.second); - } - } - } - // no real masternode found?... - if(!prealMasternode) { - // this should never be the case normally, - // only if someone is trying to game the system in some way or smth like that - LogPrintf("CMasternodeMan::ProcessVerifyReply -- ERROR: no real masternode found for addr %s\n", pnode->addr.ToString()); - Misbehaving(pnode->id, 20); - return; - } - LogPrintf("CMasternodeMan::ProcessVerifyReply -- verified real masternode %s for addr %s\n", - prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString()); - // increase ban score for everyone else - BOOST_FOREACH(CMasternode* pmn, vpMasternodesToBan) { - pmn->IncreasePoSeBanScore(); - LogPrint("masternode", "CMasternodeMan::ProcessVerifyReply -- increased PoSe ban score for %s addr %s, new score %d\n", - prealMasternode->vin.prevout.ToStringShort(), pnode->addr.ToString(), pmn->nPoSeBanScore); - } - if(!vpMasternodesToBan.empty()) - LogPrintf("CMasternodeMan::ProcessVerifyReply -- PoSe score increased for %d fake masternodes, addr %s\n", - (int)vpMasternodesToBan.size(), pnode->addr.ToString()); - } -} - -void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerification& mnv) -{ - std::string strError; - - if(mapSeenMasternodeVerification.find(mnv.GetHash()) != mapSeenMasternodeVerification.end()) { - // we already have one - return; - } - mapSeenMasternodeVerification[mnv.GetHash()] = mnv; - - // we don't care about history - if(mnv.nBlockHeight < nCachedBlockHeight - MAX_POSE_BLOCKS) { - LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Outdated: current block %d, verification block %d, peer=%d\n", - nCachedBlockHeight, mnv.nBlockHeight, pnode->id); - return; - } - - if(mnv.vin1.prevout == mnv.vin2.prevout) { - LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- ERROR: same vins %s, peer=%d\n", - mnv.vin1.prevout.ToStringShort(), pnode->id); - // that was NOT a good idea to cheat and verify itself, - // ban the node we received such message from - Misbehaving(pnode->id, 100); - return; - } - - uint256 blockHash; - if(!GetBlockHash(blockHash, mnv.nBlockHeight)) { - // this shouldn't happen... - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- Can't get block hash for unknown block height %d, peer=%d\n", mnv.nBlockHeight, pnode->id); - return; - } - - int nRank; - - if (!GetMasternodeRank(mnv.vin2.prevout, nRank, mnv.nBlockHeight, MIN_POSE_PROTO_VERSION)) { - LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Can't calculate rank for masternode %s\n", - mnv.vin2.prevout.ToStringShort()); - return; - } - - if(nRank > MAX_POSE_RANK) { - LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- Masternode %s is not in top %d, current rank %d, peer=%d\n", - mnv.vin2.prevout.ToStringShort(), (int)MAX_POSE_RANK, nRank, pnode->id); - return; - } - - { - LOCK(cs); - - std::string strMessage1 = strprintf("%s%d%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString()); - std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), - mnv.vin1.prevout.ToStringShort(), mnv.vin2.prevout.ToStringShort()); - - CMasternode* pmn1 = Find(mnv.vin1.prevout); - if(!pmn1) { - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode1 %s\n", mnv.vin1.prevout.ToStringShort()); - return; - } - - CMasternode* pmn2 = Find(mnv.vin2.prevout); - if(!pmn2) { - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- can't find masternode2 %s\n", mnv.vin2.prevout.ToStringShort()); - return; - } - - if(pmn1->addr != mnv.addr) { - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- addr %s does not match %s\n", mnv.addr.ToString(), pmn1->addr.ToString()); - return; - } - - if(!CMessageSigner::VerifyMessage(pmn1->pubKeyMasternode, mnv.vchSig1, strMessage1, strError)) { - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode1 failed, error: %s\n", strError); - return; - } - - if(!CMessageSigner::VerifyMessage(pmn2->pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode2 failed, error: %s\n", strError); - return; - } - - if(!pmn1->IsPoSeVerified()) { - pmn1->DecreasePoSeBanScore(); - } - mnv.Relay(); - - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- verified masternode %s for addr %s\n", - pmn1->vin.prevout.ToStringShort(), pmn1->addr.ToString()); - - // increase ban score for everyone else with the same addr - int nCount = 0; - for (auto& mnpair : mapMasternodes) { - if(mnpair.second.addr != mnv.addr || mnpair.first == mnv.vin1.prevout) continue; - mnpair.second.IncreasePoSeBanScore(); - nCount++; - LogPrint("masternode", "CMasternodeMan::ProcessVerifyBroadcast -- increased PoSe ban score for %s addr %s, new score %d\n", - mnpair.first.ToStringShort(), mnpair.second.addr.ToString(), mnpair.second.nPoSeBanScore); - } - if(nCount) - LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- PoSe score increased for %d fake masternodes, addr %s\n", - nCount, pmn1->addr.ToString()); - } -} - -std::string CMasternodeMan::ToString() const -{ - std::ostringstream info; - - info << "Masternodes: " << (int)mapMasternodes.size() << - ", peers who asked us for Masternode list: " << (int)mAskedUsForMasternodeList.size() << - ", peers we asked for Masternode list: " << (int)mWeAskedForMasternodeList.size() << - ", entries in Masternode list we asked for: " << (int)mWeAskedForMasternodeListEntry.size() << - ", nDsqCount: " << (int)nDsqCount; - - return info.str(); -} - -void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman) -{ - LOCK2(cs_main, cs); - mapSeenMasternodePing.insert(std::make_pair(mnb.lastPing.GetHash(), mnb.lastPing)); - mapSeenMasternodeBroadcast.insert(std::make_pair(mnb.GetHash(), std::make_pair(GetTime(), mnb))); - - LogPrintf("CMasternodeMan::UpdateMasternodeList -- masternode=%s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); - - CMasternode* pmn = Find(mnb.vin.prevout); - if(pmn == NULL) { - if(Add(mnb)) { - masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - new"); - } - } else { - CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; - if(pmn->UpdateFromNewBroadcast(mnb, connman)) { - masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - seen"); - mapSeenMasternodeBroadcast.erase(mnbOld.GetHash()); - } - } -} - -bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman) -{ - // Need to lock cs_main here to ensure consistent locking order because the SimpleCheck call below locks cs_main - LOCK(cs_main); - - { - LOCK(cs); - nDos = 0; - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s\n", mnb.vin.prevout.ToStringShort()); - - uint256 hash = mnb.GetHash(); - if(mapSeenMasternodeBroadcast.count(hash) && !mnb.fRecovery) { //seen - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen\n", mnb.vin.prevout.ToStringShort()); - // less then 2 pings left before this MN goes into non-recoverable state, bump sync timeout - if(GetTime() - mapSeenMasternodeBroadcast[hash].first > MASTERNODE_NEW_START_REQUIRED_SECONDS - MASTERNODE_MIN_MNP_SECONDS * 2) { - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen update\n", mnb.vin.prevout.ToStringShort()); - mapSeenMasternodeBroadcast[hash].first = GetTime(); - masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - seen"); - } - // did we ask this node for it? - if(pfrom && IsMnbRecoveryRequested(hash) && GetTime() < mMnbRecoveryRequests[hash].first) { - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request\n", hash.ToString()); - if(mMnbRecoveryRequests[hash].second.count(pfrom->addr)) { - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s\n", hash.ToString(), pfrom->addr.ToString()); - // do not allow node to send same mnb multiple times in recovery mode - mMnbRecoveryRequests[hash].second.erase(pfrom->addr); - // does it have newer lastPing? - if(mnb.lastPing.sigTime > mapSeenMasternodeBroadcast[hash].second.lastPing.sigTime) { - // simulate Check - CMasternode mnTemp = CMasternode(mnb); - mnTemp.Check(); - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- mnb=%s seen request, addr=%s, better lastPing: %d min ago, projected mn state: %s\n", hash.ToString(), pfrom->addr.ToString(), (GetAdjustedTime() - mnb.lastPing.sigTime)/60, mnTemp.GetStateString()); - if(mnTemp.IsValidStateForAutoStart(mnTemp.nActiveState)) { - // this node thinks it's a good one - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s seen good\n", mnb.vin.prevout.ToStringShort()); - mMnbRecoveryGoodReplies[hash].push_back(mnb); - } - } - } - } - return true; - } - mapSeenMasternodeBroadcast.insert(std::make_pair(hash, std::make_pair(GetTime(), mnb))); - - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- masternode=%s new\n", mnb.vin.prevout.ToStringShort()); - - if(!mnb.SimpleCheck(nDos)) { - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- SimpleCheck() failed, masternode=%s\n", mnb.vin.prevout.ToStringShort()); - return false; - } - - // search Masternode list - CMasternode* pmn = Find(mnb.vin.prevout); - if(pmn) { - CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second; - if(!mnb.Update(pmn, nDos, connman)) { - LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Update() failed, masternode=%s\n", mnb.vin.prevout.ToStringShort()); - return false; - } - if(hash != mnbOld.GetHash()) { - mapSeenMasternodeBroadcast.erase(mnbOld.GetHash()); - } - return true; - } - } - - if(mnb.CheckOutpoint(nDos)) { - Add(mnb); - masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - new"); - // if it matches our Masternode privkey... - if(fMasterNode && mnb.pubKeyMasternode == activeMasternode.pubKeyMasternode) { - mnb.nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; - if(mnb.nProtocolVersion == PROTOCOL_VERSION) { - // ... and PROTOCOL_VERSION, then we've been remotely activated ... - LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Got NEW Masternode entry: masternode=%s sigTime=%lld addr=%s\n", - mnb.vin.prevout.ToStringShort(), mnb.sigTime, mnb.addr.ToString()); - activeMasternode.ManageState(connman); - } else { - // ... otherwise we need to reactivate our node, do not add it to the list and do not relay - // but also do not ban the node we get this message from - LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- wrong PROTOCOL_VERSION, re-activate your MN: message nProtocolVersion=%d PROTOCOL_VERSION=%d\n", mnb.nProtocolVersion, PROTOCOL_VERSION); - return false; - } - } - mnb.Relay(connman); - } else { - LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Rejected Masternode entry: %s addr=%s\n", mnb.vin.prevout.ToStringShort(), mnb.addr.ToString()); - return false; - } - - return true; -} - -void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) -{ - LOCK(cs); - - if(fLiteMode || !masternodeSync.IsWinnersListSynced() || mapMasternodes.empty()) return; - - static bool IsFirstRun = true; - // Do full scan on first run or if we are not a masternode - // (MNs should update this info on every block, so limited scan should be enough for them) - int nMaxBlocksToScanBack = (IsFirstRun || !fMasterNode) ? mnpayments.GetStorageLimit() : LAST_PAID_SCAN_BLOCKS; - - // LogPrint("mnpayments", "CMasternodeMan::UpdateLastPaid -- nHeight=%d, nMaxBlocksToScanBack=%d, IsFirstRun=%s\n", - // nCachedBlockHeight, nMaxBlocksToScanBack, IsFirstRun ? "true" : "false"); - - for (auto& mnpair: mapMasternodes) { - mnpair.second.UpdateLastPaid(pindex, nMaxBlocksToScanBack); - } - - IsFirstRun = false; -} - -void CMasternodeMan::UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if(!pmn) { - return; - } - pmn->UpdateWatchdogVoteTime(nVoteTime); - nLastWatchdogVoteTime = GetTime(); -} - -bool CMasternodeMan::IsWatchdogActive() -{ - LOCK(cs); - // Check if any masternodes have voted recently, otherwise return false - return (GetTime() - nLastWatchdogVoteTime) <= MASTERNODE_WATCHDOG_MAX_SECONDS; -} - -bool CMasternodeMan::AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if(!pmn) { - return false; - } - pmn->AddGovernanceVote(nGovernanceObjectHash); - return true; -} - -void CMasternodeMan::RemoveGovernanceObject(uint256 nGovernanceObjectHash) -{ - LOCK(cs); - for(auto& mnpair : mapMasternodes) { - mnpair.second.RemoveGovernanceObject(nGovernanceObjectHash); - } -} - -void CMasternodeMan::CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce) -{ - LOCK(cs); - for (auto& mnpair : mapMasternodes) { - if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { - mnpair.second.Check(fForce); - return; - } - } -} - -bool CMasternodeMan::IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - return pmn ? pmn->IsPingedWithin(nSeconds, nTimeToCheckAt) : false; -} - -void CMasternodeMan::SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp) -{ - LOCK(cs); - CMasternode* pmn = Find(outpoint); - if(!pmn) { - return; - } - pmn->lastPing = mnp; - // if masternode uses sentinel ping instead of watchdog - // we shoud update nTimeLastWatchdogVote here if sentinel - // ping flag is actual - if(mnp.fSentinelIsCurrent) { - UpdateWatchdogVoteTime(mnp.vin.prevout, mnp.sigTime); - } - mapSeenMasternodePing.insert(std::make_pair(mnp.GetHash(), mnp)); - - CMasternodeBroadcast mnb(*pmn); - uint256 hash = mnb.GetHash(); - if(mapSeenMasternodeBroadcast.count(hash)) { - mapSeenMasternodeBroadcast[hash].second.lastPing = mnp; - } -} - -void CMasternodeMan::UpdatedBlockTip(const CBlockIndex *pindex) -{ - nCachedBlockHeight = pindex->nHeight; - LogPrint("masternode", "CMasternodeMan::UpdatedBlockTip -- nCachedBlockHeight=%d\n", nCachedBlockHeight); - - CheckSameAddr(); - - if(fMasterNode) { - // normal wallet does not need to update this every block, doing update on rpc call should be enough - UpdateLastPaid(pindex); - } -} - -void CMasternodeMan::NotifyMasternodeUpdates(CConnman& connman) -{ - // Avoid double locking - bool fMasternodesAddedLocal = false; - bool fMasternodesRemovedLocal = false; - { - LOCK(cs); - fMasternodesAddedLocal = fMasternodesAdded; - fMasternodesRemovedLocal = fMasternodesRemoved; - } - - if(fMasternodesAddedLocal) { - governance.CheckMasternodeOrphanObjects(connman); - governance.CheckMasternodeOrphanVotes(connman); - } - if(fMasternodesRemovedLocal) { - governance.UpdateCachesAndClean(); - } - - LOCK(cs); - fMasternodesAdded = false; - fMasternodesRemoved = false; -} From 1adb3b3b681882b4f9c45f4be9e43e69499f4cc7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:31:58 -0400 Subject: [PATCH 0734/1324] Delete masternodeman.h --- src/masternodeman.h | 240 -------------------------------------------- 1 file changed, 240 deletions(-) delete mode 100644 src/masternodeman.h diff --git a/src/masternodeman.h b/src/masternodeman.h deleted file mode 100644 index 1927ddaa..00000000 --- a/src/masternodeman.h +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef MASTERNODEMAN_H -#define MASTERNODEMAN_H - -#include "masternode.h" -#include "sync.h" - -using namespace std; - -class CMasternodeMan; -class CConnman; - -extern CMasternodeMan mnodeman; - -class CMasternodeMan -{ -public: - typedef std::pair score_pair_t; - typedef std::vector score_pair_vec_t; - typedef std::pair rank_pair_t; - typedef std::vector rank_pair_vec_t; - -private: - static const std::string SERIALIZATION_VERSION_STRING; - - static const int DSEG_UPDATE_SECONDS = 3 * 60 * 60; - - static const int LAST_PAID_SCAN_BLOCKS = 100; - - static const int MIN_POSE_PROTO_VERSION = 70203; - static const int MAX_POSE_CONNECTIONS = 10; - static const int MAX_POSE_RANK = 10; - static const int MAX_POSE_BLOCKS = 10; - - static const int MNB_RECOVERY_QUORUM_TOTAL = 10; - static const int MNB_RECOVERY_QUORUM_REQUIRED = 6; - static const int MNB_RECOVERY_MAX_ASK_ENTRIES = 10; - static const int MNB_RECOVERY_WAIT_SECONDS = 60; - static const int MNB_RECOVERY_RETRY_SECONDS = 3 * 60 * 60; - - - // critical section to protect the inner data structures - mutable CCriticalSection cs; - - // Keep track of current block height - int nCachedBlockHeight; - - // map to hold all MNs - std::map mapMasternodes; - // who's asked for the Masternode list and the last time - std::map mAskedUsForMasternodeList; - // who we asked for the Masternode list and the last time - std::map mWeAskedForMasternodeList; - // which Masternodes we've asked for - std::map > mWeAskedForMasternodeListEntry; - // who we asked for the masternode verification - std::map mWeAskedForVerification; - - // these maps are used for masternode recovery from MASTERNODE_NEW_START_REQUIRED state - std::map > > mMnbRecoveryRequests; - std::map > mMnbRecoveryGoodReplies; - std::list< std::pair > listScheduledMnbRequestConnections; - - /// Set when masternodes are added, cleared when CGovernanceManager is notified - bool fMasternodesAdded; - - /// Set when masternodes are removed, cleared when CGovernanceManager is notified - bool fMasternodesRemoved; - - std::vector vecDirtyGovernanceObjectHashes; - - int64_t nLastWatchdogVoteTime; - - friend class CMasternodeSync; - /// Find an entry - CMasternode* Find(const COutPoint& outpoint); - - bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol = 0); - -public: - // Keep track of all broadcasts I've seen - std::map > mapSeenMasternodeBroadcast; - // Keep track of all pings I've seen - std::map mapSeenMasternodePing; - // Keep track of all verifications I've seen - std::map mapSeenMasternodeVerification; - // keep track of dsq count to prevent masternodes from gaming darksend queue - int64_t nDsqCount; - - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - LOCK(cs); - std::string strVersion; - if(ser_action.ForRead()) { - READWRITE(strVersion); - } - else { - strVersion = SERIALIZATION_VERSION_STRING; - READWRITE(strVersion); - } - - READWRITE(mapMasternodes); - READWRITE(mAskedUsForMasternodeList); - READWRITE(mWeAskedForMasternodeList); - READWRITE(mWeAskedForMasternodeListEntry); - READWRITE(mMnbRecoveryRequests); - READWRITE(mMnbRecoveryGoodReplies); - READWRITE(nLastWatchdogVoteTime); - READWRITE(nDsqCount); - - READWRITE(mapSeenMasternodeBroadcast); - READWRITE(mapSeenMasternodePing); - if(ser_action.ForRead() && (strVersion != SERIALIZATION_VERSION_STRING)) { - Clear(); - } - } - - CMasternodeMan(); - - /// Add an entry - bool Add(CMasternode &mn); - - /// Ask (source) node for mnb - void AskForMN(CNode *pnode, const COutPoint& outpoint, CConnman& connman); - void AskForMnb(CNode *pnode, const uint256 &hash); - - bool PoSeBan(const COutPoint &outpoint); - bool AllowMixing(const COutPoint &outpoint); - bool DisallowMixing(const COutPoint &outpoint); - - /// Check all Masternodes - void Check(); - - /// Check all Masternodes and remove inactive - void CheckAndRemove(CConnman& connman); - /// This is dummy overload to be used for dumping/loading mncache.dat - void CheckAndRemove() {} - - /// Clear Masternode vector - void Clear(); - - /// Count Masternodes filtered by nProtocolVersion. - /// Masternode nProtocolVersion should match or be above the one specified in param here. - int CountMasternodes(int nProtocolVersion = -1); - /// Count enabled Masternodes filtered by nProtocolVersion. - /// Masternode nProtocolVersion should match or be above the one specified in param here. - int CountEnabled(int nProtocolVersion = -1); - - /// Count Masternodes by network type - NET_IPV4, NET_IPV6, NET_TOR - // int CountByIP(int nNetworkType); - - void DsegUpdate(CNode* pnode, CConnman& connman); - - /// Versions of Find that are safe to use from outside the class - bool Get(const COutPoint& outpoint, CMasternode& masternodeRet); - bool Has(const COutPoint& outpoint); - - bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet); - bool GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet); - bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet); - - /// Find an entry in the masternode list that is next to be paid - bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); - /// Same as above but use current block height - bool GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet); - - /// Find a random entry - masternode_info_t FindRandomNotInVec(const std::vector &vecToExclude, int nProtocolVersion = -1); - - std::map GetFullMasternodeMap() { return mapMasternodes; } - - bool GetMasternodeRanks(rank_pair_vec_t& vecMasternodeRanksRet, int nBlockHeight = -1, int nMinProtocol = 0); - bool GetMasternodeRank(const COutPoint &outpoint, int& nRankRet, int nBlockHeight = -1, int nMinProtocol = 0); - - void ProcessMasternodeConnections(CConnman& connman); - std::pair > PopScheduledMnbRequestConnection(); - - void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman); - - void DoFullVerificationStep(CConnman& connman); - void CheckSameAddr(); - bool SendVerifyRequest(const CAddress& addr, const std::vector& vSortedByAddr, CConnman& connman); - void SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, CConnman& connman); - void ProcessVerifyReply(CNode* pnode, CMasternodeVerification& mnv); - void ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerification& mnv); - - /// Return the number of (unique) Masternodes - int size() { return mapMasternodes.size(); } - - std::string ToString() const; - - /// Update masternode list and maps using provided CMasternodeBroadcast - void UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman); - /// Perform complete check and only then update list and maps - bool CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman); - bool IsMnbRecoveryRequested(const uint256& hash) { return mMnbRecoveryRequests.count(hash); } - - void UpdateLastPaid(const CBlockIndex* pindex); - - void AddDirtyGovernanceObjectHash(const uint256& nHash) - { - LOCK(cs); - vecDirtyGovernanceObjectHashes.push_back(nHash); - } - - std::vector GetAndClearDirtyGovernanceObjectHashes() - { - LOCK(cs); - std::vector vecTmp = vecDirtyGovernanceObjectHashes; - vecDirtyGovernanceObjectHashes.clear(); - return vecTmp;; - } - - bool IsWatchdogActive(); - void UpdateWatchdogVoteTime(const COutPoint& outpoint, uint64_t nVoteTime = 0); - bool AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash); - void RemoveGovernanceObject(uint256 nGovernanceObjectHash); - - void CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce); - - bool IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt = -1); - void SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp); - - void UpdatedBlockTip(const CBlockIndex *pindex); - - /** - * Called to notify CGovernanceManager that the masternode index has been updated. - * Must be called while not holding the CMasternodeMan::cs mutex - */ - void NotifyMasternodeUpdates(CConnman& connman); - -}; - -#endif From 616f428a5d8ce683237e7a7d4fc5fb5443d01dad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:32:16 -0400 Subject: [PATCH 0735/1324] Update util.h --- src/util.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.h b/src/util.h index dd7b9394..45294b3e 100644 --- a/src/util.h +++ b/src/util.h @@ -140,7 +140,6 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); boost::filesystem::path GetBackupsDir(); void ClearDatadirCache(); boost::filesystem::path GetConfigFile(const std::string& confPath); -boost::filesystem::path GetMasternodeConfigFile(); #ifndef WIN32 boost::filesystem::path GetPidFile(); void CreatePidFile(const boost::filesystem::path &path, pid_t pid); From 09b296ce4a7c574d0a0348498dae0ce4932e497b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:32:55 -0400 Subject: [PATCH 0736/1324] Update util.cpp --- src/util.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 8b9c5e8a..d7fa626e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -650,13 +650,6 @@ boost::filesystem::path GetConfigFile(const std::string& confPath) return pathConfigFile; } -boost::filesystem::path GetMasternodeConfigFile() -{ - boost::filesystem::path pathConfigFile(GetArg("-mnconf", "masternode.conf")); - if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile; - return pathConfigFile; -} - void ReadConfigFile(const std::string& confPath) { boost::filesystem::ifstream streamConfig(GetConfigFile(confPath)); From 68c941b4b2d64a0c8f1f0f728bca880148f22882 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:33:20 -0400 Subject: [PATCH 0737/1324] Delete rpcpodc.cpp --- src/rpcpodc.cpp | 285 ------------------------------------------------ 1 file changed, 285 deletions(-) delete mode 100644 src/rpcpodc.cpp diff --git a/src/rpcpodc.cpp b/src/rpcpodc.cpp deleted file mode 100644 index b6d1ee19..00000000 --- a/src/rpcpodc.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright (c) 2014-2019 The Dash-Core Developers, The DAC Core Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "spork.h" -#include "utilmoneystr.h" -#include "masternode-payments.h" -#include "masternodeconfig.h" -#include "activemasternode.h" -#include "governance-classes.h" -#include "masternode-sync.h" -#include "smartcontract-server.h" -#include "rpcpog.h" -#include -#include // for to_lower() -#include // for trim() -#include // for StringToUnixTime() -#include -#include -#include -#include -#include -#include -#include -#include - -extern CWallet* pwalletMain; - -const std::string CURRENCY_NAME = "IMAGECOIN"; - -std::string GetSANDirectory2() -{ - std::string prefix = CURRENCY_NAME; - boost::to_lower(prefix); - boost::filesystem::path pathConfigFile(GetArg("-conf", prefix + ".conf")); - if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile; - boost::filesystem::path dir = pathConfigFile.parent_path(); - std::string sDir = dir.string() + "/SAN/"; - boost::filesystem::path pathSAN(sDir); - if (!boost::filesystem::exists(pathSAN)) - { - boost::filesystem::create_directory(pathSAN); - } - return sDir; -} - -std::string ToYesNo(bool bValue) -{ - std::string sYesNo = bValue ? "Yes" : "No"; - return sYesNo; -} - -std::string strReplace(std::string& str, const std::string& oldStr, const std::string& newStr) -{ - size_t pos = 0; - while((pos = str.find(oldStr, pos)) != std::string::npos){ - str.replace(pos, oldStr.length(), newStr); - pos += newStr.length(); - } - return str; -} - -bool SignStake(std::string sBitcoinAddress, std::string strMessage, std::string& sError, std::string& sSignature) -{ - LOCK(cs_main); - { - CBitcoinAddress addr(sBitcoinAddress); - CKeyID keyID; - if (!addr.GetKeyID(keyID)) - { - sError = "Address does not refer to key"; - return false; - } - CKey key; - if (!pwalletMain->GetKey(keyID, key)) - { - sError = "Private key not available for " + sBitcoinAddress + "."; - LogPrintf("Unable to sign message %s with key %s.\n", strMessage, sBitcoinAddress); - return false; - } - CHashWriter ss(SER_GETHASH, 0); - ss << strMessageMagic; - ss << strMessage; - std::vector vchSig; - if (!key.SignCompact(ss.GetHash(), vchSig)) - { - sError = "Sign failed"; - return false; - } - sSignature = EncodeBase64(&vchSig[0], vchSig.size()); - LogPrintf("Signed message %s successfully with address %s \n", strMessage, sBitcoinAddress); - return true; - } -} - - -std::string SendBlockchainMessage(std::string sType, std::string sPrimaryKey, std::string sValue, double dStorageFee, bool Sign, std::string sExtraPayload, std::string& sError) -{ - const Consensus::Params& consensusParams = Params().GetConsensus(); - std::string sAddress = "MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG"; - CBitcoinAddress address(sAddress); - if (!address.IsValid()) - { - sError = "Invalid Destination Address"; - return sError; - } - CAmount nAmount = CAmountFromValue(dStorageFee); - CAmount nMinimumBalance = CAmountFromValue(dStorageFee); - CWalletTx wtx; - boost::to_upper(sPrimaryKey); // DC Message can't be found if not uppercase - boost::to_upper(sType); - std::string sNonceValue = RoundToString(GetAdjustedTime(), 0); - std::string sMessageType = "" + sType + ""; - std::string sMessageKey = "" + sPrimaryKey + ""; - std::string sMessageValue = "" + sValue + ""; - std::string sNonce = "" + sNonceValue + ""; - std::string sMessageSig = ""; - if (Sign) - { - std::string sSignature = ""; - bool bSigned = SignStake("MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG", sValue + sNonceValue, sError, sSignature); - if (bSigned) - { - sMessageSig = "" + sSignature + ""; - sMessageSig += "" + sSignature + ""; - sMessageSig += "MuqsghdUQKH3KE7C4PoR1o7Dq5G3eEvhuG"; - } - if (!bSigned) LogPrintf("Unable to sign spork %s ", sError); - LogPrintf(" Signing Nonce%f , With spork Sig %s on message %s \n", (double)GetAdjustedTime(), - sMessageSig.c_str(), sValue.c_str()); - } - std::string s1 = sMessageType + sMessageKey + sMessageValue + sNonce + sMessageSig + sExtraPayload; - LogPrintf("SendBlockchainMessage %s", s1); - bool fSubtractFee = false; - bool fInstantSend = false; - bool fSent = RPCSendMoney(sError, address.Get(), nAmount, fSubtractFee, wtx, fInstantSend, s1); - - if (!sError.empty()) - return std::string(); - return wtx.GetHash().GetHex().c_str(); -} - - -std::string GetGithubVersion() -{ - std::string sURL = "https://" + GetSporkValue("bms"); - std::string sRestfulURL = "BMS/LAST_MANDATORY_VERSION"; - //std::string sV = ExtractXML(HTTPSPost(false, 0, "", "", "", sURL, sRestfulURL, 443, "", 25, 10000, 1), "", ""); - std::string sV; - return sV; -} - - - -bool GetTransactionTimeAndAmount(uint256 txhash, int nVout, int64_t& nTime, CAmount& nAmount) -{ - uint256 hashBlock = uint256(); - CTransaction tx2; - if (GetTransaction(txhash, tx2, Params().GetConsensus(), hashBlock, true)) - { - BlockMap::iterator mi = mapBlockIndex.find(hashBlock); - if (mi != mapBlockIndex.end() && (*mi).second) - { - CBlockIndex* pMNIndex = (*mi).second; - nTime = pMNIndex->GetBlockTime(); - nAmount = tx2.vout[nVout].nValue; - return true; - } - } - return false; -} - -std::string rPad(std::string data, int minWidth) -{ - if ((int)data.length() >= minWidth) return data; - int iPadding = minWidth - data.length(); - std::string sPadding = std::string(iPadding,' '); - std::string sOut = data + sPadding; - return sOut; -} - -int64_t GetDCCFileAge() -{ - std::string sRACFile = GetSANDirectory2() + "wcg.rac"; - boost::filesystem::path pathFiltered(sRACFile); - if (!boost::filesystem::exists(pathFiltered)) - return GetAdjustedTime() - 0; - int64_t nTime = last_write_time(pathFiltered); - int64_t nAge = GetAdjustedTime() - nTime; - return nAge; -} - -int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints) -{ - std::string sDomain = "https://www.worldcommunitygrid.org"; - std::string sRestfulURL = "verifyMember.do?name=" + sMemberName + "&code=" + sAuthCode; - //std::string sResponse = HTTPSPost(true, 0, "", "", "", sDomain, sRestfulURL, 443, "", 12, 14000, 1); - std::string sResponse; - int iID = (int)cdbl(ExtractXML(sResponse, "",""), 0); - nPoints = cdbl(ExtractXML(sResponse, "", ""), 2); - return iID; -} - -Researcher GetResearcherByID(int nID) -{ - BOOST_FOREACH(const PAIRTYPE(const std::string, Researcher)& myResearcher, mvResearchers) - { - if (myResearcher.second.found && myResearcher.second.id == nID) - { - return mvResearchers[myResearcher.second.cpid]; - } - } - Researcher r; - r.found = false; - r.teamid = 0; - return r; -} - -std::map GetPayableResearchers() -{ - // Rules: - - // Researcher is in the team - // RAC > 1 - // Researchers reverse CPID lookup matches the signed association record (this ensures the LIFO rule is honored allowing re-associations) - // Each CPID is only included ONCE - // The CPID is Unbanked if the RAC < 250 - // Unbanked researchers do not need to post daily stake collateral - // Banked researchers do need to post daily stake collateral: RAC^1.30 in COIN-AGE per day - std::vector > vFIFO; - vFIFO.reserve(mvResearchers.size() * 2); - std::map r; - std::map cpid_reverse_lookup; - for (auto ii : mvApplicationCache) - { - if (Contains(ii.first.first, "CPK-WCG")) - { - std::string sData = ii.second.first; - int64_t nLockTime = ii.second.second; - std::string cpid = GetCPIDElementByData(sData, 8); - std::string sCPK = GetCPIDElementByData(sData, 0); - vFIFO.push_back(std::make_tuple(nLockTime, cpid, sCPK)); - LogPrintf("cpid %s cpk %s locktime %f", cpid, sCPK, nLockTime); - } - } - - - // LIFO Sort - std::sort(vFIFO.begin(), vFIFO.end()); - - for (auto item : vFIFO) - { - std::string cpid = std::get<1>(item); //item.second; - std::string sCPK = std::get<2>(item); //item.third; - cpid_reverse_lookup[cpid] = sCPK; - LogPrintf("Adding cpid %s with %s ", cpid, sCPK); - } - - // Payable Researchers - BOOST_FOREACH(const PAIRTYPE(const std::string, Researcher)& myResearcher, mvResearchers) - { - if (myResearcher.second.found) - { - if (myResearcher.second.rac > 1) - { - std::string sSourceCPK = cpid_reverse_lookup[myResearcher.second.cpid]; - std::string sSignedCPID = GetCPIDByCPK(sSourceCPK); - - if (sSignedCPID == myResearcher.second.cpid && !myResearcher.second.cpid.empty()) - { - if (myResearcher.second.rac > 1) - { - r[sSignedCPID] = myResearcher.second; - LogPrintf("\nGetPayableResearchers::Adding %s for %s", sSignedCPID, sSourceCPK); - } - } - else - { - LogPrintf("\nGPR::Not Adding %s because %s", sSignedCPID, sSourceCPK); - } - } - } - } - return r; -} From aac3e16bd1ede7c729fd67309e17fbf1ac58404b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:33:31 -0400 Subject: [PATCH 0738/1324] Delete rpcpodc.h --- src/rpcpodc.h | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/rpcpodc.h diff --git a/src/rpcpodc.h b/src/rpcpodc.h deleted file mode 100644 index 90ba3bc2..00000000 --- a/src/rpcpodc.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2014-2017 The D�sh Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef RPCPODC_H -#define RPCPODC_H - -#include "hash.h" -#include "net.h" -#include "utilstrencodings.h" -#include -#include - - -std::string strReplace(std::string& str, const std::string& oldStr, const std::string& newStr); -double GetCryptoPrice(std::string sURL); -bool SignStake(std::string sBitcoinAddress, std::string strMessage, std::string& sError, std::string& sSignature); -std::string GetGithubVersion(); -std::string SerializeSanctuaryQuorumTrigger(int iContractAssessmentHeight, int nEventBlockHeight, std::string sContract); -bool VerifySigner(std::string sXML); -double GetPBase(double& out_BTC); -std::string GetCPID(); -bool GetTransactionTimeAndAmount(uint256 txhash, int nVout, int64_t& nTime, CAmount& nAmount); -std::string SendBlockchainMessage(std::string sType, std::string sPrimaryKey, std::string sValue, double dStorageFee, bool Sign, std::string sExtraPayload, std::string& sError); -std::string ToYesNo(bool bValue); -bool VoteForGobject(uint256 govobj, std::string sVoteOutcome, std::string& sError); -int64_t GetDCCFileAge(); -std::string GetSANDirectory2(); -int GetWCGMemberID(std::string sMemberName, std::string sAuthCode, double& nPoints); -Researcher GetResearcherByID(int nID); -std::map GetPayableResearchers(); - -#endif From 6889bd2f10a200a4300ea55430bb6ea5237e9308 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:33:42 -0400 Subject: [PATCH 0739/1324] Delete rpcpog.cpp --- src/rpcpog.cpp | 1056 ------------------------------------------------ 1 file changed, 1056 deletions(-) delete mode 100644 src/rpcpog.cpp diff --git a/src/rpcpog.cpp b/src/rpcpog.cpp deleted file mode 100644 index a28c9b04..00000000 --- a/src/rpcpog.cpp +++ /dev/null @@ -1,1056 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "rpcpog.h" -#include "spork.h" -#include "util.h" -#include "utilmoneystr.h" -#include "rpcpodc.h" -#include "init.h" -#include "bbpsocket.h" -#include "activemasternode.h" -#include "governance.h" -#include "governance-vote.h" -#include "governance-classes.h" -#include "governance-validators.h" -#include "masternode.h" -#include "masternode-sync.h" -#include "masternodeconfig.h" -#include "masternodeman.h" -#include "masternode-payments.h" -#include "messagesigner.h" -#include "smartcontract-server.h" -#include "smartcontract-client.h" -#include -#include // for to_lower() -#include // for trim() -#include // for StringToUnixTime() -#include /* round, floor, ceil, trunc */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "txmempool.h" -// For HTTPS (for the pool communication) -#include -#include -#include -#include -#include "net.h" // for CService -#include "netaddress.h" -#include "netbase.h" // for LookupHost -#include "wallet/wallet.h" -#include -//#include "randomx.h" - -#ifdef ENABLE_WALLET -extern CWallet* pwalletMain; - -#endif // ENABLE_WALLET - -CValidationState state; - -UniValue VoteWithMasternodes(const std::map& keys, - const uint256& hash, vote_signal_enum_t eVoteSignal, - vote_outcome_enum_t eVoteOutcome); - -std::string GenerateNewAddress(std::string& sError, std::string sName) -{ - LOCK2(cs_main, pwalletMain->cs_wallet); - { - if (!pwalletMain->IsLocked(true)) - pwalletMain->TopUpKeyPool(); - // Generate a new key that is added to wallet - CPubKey newKey; - if (!pwalletMain->GetKeyFromPool(newKey, false)) - { - sError = "Keypool ran out, please call keypoolrefill first"; - return std::string(); - } - CKeyID keyID = newKey.GetID(); - pwalletMain->SetAddressBook(keyID, sName, "receive"); //receive == visible in address book, hidden = non-visible - LogPrintf(" created new address %s ", CBitcoinAddress(keyID).ToString().c_str()); - return CBitcoinAddress(keyID).ToString(); - } -} - -std::string GJE(std::string sKey, std::string sValue, bool bIncludeDelimiter, bool bQuoteValue) -{ - // This is a helper for the Governance gobject create method - std::string sQ = "\""; - std::string sOut = sQ + sKey + sQ + ":"; - if (bQuoteValue) - { - sOut += sQ + sValue + sQ; - } - else - { - sOut += sValue; - } - if (bIncludeDelimiter) sOut += ","; - return sOut; -} - -std::string RoundToString(double d, int place) -{ - std::ostringstream ss; - ss << std::fixed << std::setprecision(place) << d ; - return ss.str() ; -} - -double Round(double d, int place) -{ - std::ostringstream ss; - ss << std::fixed << std::setprecision(place) << d ; - double r = 0; - try - { - r = boost::lexical_cast(ss.str()); - return r; - } - catch(boost::bad_lexical_cast const& e) - { - LogPrintf("caught bad lexical cast %f", 1); - return 0; - } - catch(...) - { - LogPrintf("caught bad lexical cast %f", 2); - } - return r; -} - -std::vector Split(std::string s, std::string delim) -{ - size_t pos = 0; - std::string token; - std::vector elems; - while ((pos = s.find(delim)) != std::string::npos) - { - token = s.substr(0, pos); - elems.push_back(token); - s.erase(0, pos + delim.length()); - } - elems.push_back(s); - return elems; -} - -double cdbl(std::string s, int place) -{ - if (s=="") s = "0"; - if (s.length() > 255) return 0; - s = strReplace(s, "\r",""); - s = strReplace(s, "\n",""); - std::string t = ""; - for (int i = 0; i < (int)s.length(); i++) - { - std::string u = s.substr(i,1); - if (u=="0" || u=="1" || u=="2" || u=="3" || u=="4" || u=="5" || u=="6" || u == "7" || u=="8" || u=="9" || u=="." || u=="-") - { - t += u; - } - } - double r= 0; - try - { - r = boost::lexical_cast(t); - } - catch(boost::bad_lexical_cast const& e) - { - LogPrintf("caught cdbl bad lexical cast %f from %s with %f", 1, s, (double)place); - return 0; - } - catch(...) - { - LogPrintf("caught cdbl bad lexical cast %f", 2); - } - double d = Round(r, place); - return d; -} - -bool Contains(std::string data, std::string instring) -{ - std::size_t found = 0; - found = data.find(instring); - if (found != std::string::npos) return true; - return false; -} - -std::string GetElement(std::string sIn, std::string sDelimiter, int iPos) -{ - if (sIn.empty()) - return std::string(); - std::vector vInput = Split(sIn.c_str(), sDelimiter); - if (iPos < (int)vInput.size()) - { - return vInput[iPos]; - } - return std::string(); -} - -std::string GetSporkValue(std::string sKey) -{ - boost::to_upper(sKey); - std::pair v = mvApplicationCache[std::make_pair("SPORK", sKey)]; - return v.first; -} - -double GetSporkDouble(std::string sName, double nDefault) -{ - double dSetting = cdbl(GetSporkValue(sName), 2); - if (dSetting == 0) return nDefault; - return dSetting; -} - -std::map GetSporkMap(std::string sPrimaryKey, std::string sSecondaryKey) -{ - boost::to_upper(sPrimaryKey); - boost::to_upper(sSecondaryKey); - std::string sDelimiter = "|"; - std::pair v = mvApplicationCache[std::make_pair(sPrimaryKey, sSecondaryKey)]; - std::vector vSporks = Split(v.first, sDelimiter); - std::map mSporkMap; - for (int i = 0; i < vSporks.size(); i++) - { - std::string sMySpork = vSporks[i]; - if (!sMySpork.empty()) - mSporkMap.insert(std::make_pair(sMySpork, RoundToString(i, 0))); - } - return mSporkMap; -} - -std::string Left(std::string sSource, int bytes) -{ - if (sSource.length() >= bytes) - { - return sSource.substr(0, bytes); - } - return std::string(); -} - -bool CheckStakeSignature(std::string sBitcoinAddress, std::string sSignature, std::string strMessage, std::string& strError) -{ - CBitcoinAddress addr2(sBitcoinAddress); - if (!addr2.IsValid()) - { - strError = "Invalid address"; - return false; - } - CKeyID keyID2; - if (!addr2.GetKeyID(keyID2)) - { - strError = "Address does not refer to key"; - return false; - } - bool fInvalid = false; - std::vector vchSig2 = DecodeBase64(sSignature.c_str(), &fInvalid); - if (fInvalid) - { - strError = "Malformed base64 encoding"; - return false; - } - CHashWriter ss2(SER_GETHASH, 0); - ss2 << strMessageMagic; - ss2 << strMessage; - CPubKey pubkey2; - if (!pubkey2.RecoverCompact(ss2.GetHash(), vchSig2)) - { - strError = "Unable to recover public key."; - return false; - } - bool fSuccess = (pubkey2.GetID() == keyID2); - return fSuccess; -} - - -CPK GetCPK(std::string sData) -{ - // CPK DATA FORMAT: sCPK + "|" + Sanitized NickName + "|" + LockTime + "|" + SecurityHash + "|" + CPK Signature + "|" + Email + "|" + VendorType + "|" + OptData - CPK k; - std::vector vDec = Split(sData.c_str(), "|"); - if (vDec.size() < 5) return k; - std::string sSecurityHash = vDec[3]; - std::string sSig = vDec[4]; - std::string sCPK = vDec[0]; - if (sCPK.empty()) return k; - if (vDec.size() >= 6) - k.sEmail = vDec[5]; - if (vDec.size() >= 7) - k.sVendorType = vDec[6]; - if (vDec.size() >= 8) - k.sOptData = vDec[7]; - - k.fValid = CheckStakeSignature(sCPK, sSig, sSecurityHash, k.sError); - if (!k.fValid) - { - LogPrintf("GetCPK::Error Sig %s, SH %s, Err %s, CPK %s, NickName %s ", sSig, sSecurityHash, k.sError, sCPK, vDec[1]); - return k; - } - - k.sAddress = sCPK; - k.sNickName = vDec[1]; - k.nLockTime = (int64_t)cdbl(vDec[2], 0); - - return k; - -} - -std::map GetChildMap(std::string sGSCObjType) -{ - std::map mCPKMap; - boost::to_upper(sGSCObjType); - int i = 0; - for (auto ii : mvApplicationCache) - { - if (Contains(ii.first.first, sGSCObjType)) - { - CPK k = GetCPK(ii.second.first); - i++; - mCPKMap.insert(std::make_pair(k.sAddress + "-" + RoundToString(i, 0), k)); - } - } - return mCPKMap; -} - - -std::map GetGSCMap(std::string sGSCObjType, std::string sSearch, bool fRequireSig) -{ - std::map mCPKMap; - boost::to_upper(sGSCObjType); - for (auto ii : mvApplicationCache) - { - if (ii.first.first == sGSCObjType) - { - CPK k = GetCPK(ii.second.first); - if (!k.sAddress.empty() && k.fValid) - { - if ((!sSearch.empty() && (sSearch == k.sAddress || sSearch == k.sNickName)) || sSearch.empty()) - { - mCPKMap.insert(std::make_pair(k.sAddress, k)); - } - } - } - } - return mCPKMap; -} - -CAmount CAmountFromValue(const UniValue& value) -{ - if (!value.isNum() && !value.isStr()) return 0; - CAmount amount; - if (!ParseFixedPoint(value.getValStr(), 8, &amount)) return 0; - if (!MoneyRange(amount)) return 0; - return amount; -} - -static CCriticalSection csReadWait; -std::string ReadCache(std::string sSection, std::string sKey) -{ - LOCK(csReadWait); - std::string sLookupSection = sSection; - std::string sLookupKey = sKey; - boost::to_upper(sLookupSection); - boost::to_upper(sLookupKey); - // NON-CRITICAL TODO : Find a way to eliminate this to_upper while we transition to non-financial transactions - if (sLookupSection.empty() || sLookupKey.empty()) - return std::string(); - std::pair t = mvApplicationCache[std::make_pair(sLookupSection, sLookupKey)]; - return t.first; -} - -std::string TimestampToHRDate(double dtm) -{ - if (dtm == 0) return "1-1-1970 00:00:00"; - if (dtm > 9888888888) return "1-1-2199 00:00:00"; - std::string sDt = DateTimeStrFormat("%m-%d-%Y %H:%M:%S",dtm); - return sDt; -} - -std::string ExtractXML(std::string XMLdata, std::string key, std::string key_end) -{ - std::string extraction = ""; - std::string::size_type loc = XMLdata.find( key, 0 ); - if( loc != std::string::npos ) - { - std::string::size_type loc_end = XMLdata.find( key_end, loc+3); - if (loc_end != std::string::npos ) - { - extraction = XMLdata.substr(loc+(key.length()),loc_end-loc-(key.length())); - } - } - return extraction; -} - - -std::string AmountToString(const CAmount& amount) -{ - bool sign = amount < 0; - int64_t n_abs = (sign ? -amount : amount); - int64_t quotient = n_abs / COIN; - int64_t remainder = n_abs % COIN; - std::string sAmount = strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder); - return sAmount; -} - -static CBlockIndex* pblockindexFBBHLast; -CBlockIndex* FindBlockByHeight(int nHeight) -{ - CBlockIndex *pblockindex; - if (nHeight < 0 || nHeight > chainActive.Tip()->nHeight) return NULL; - - if (nHeight < chainActive.Tip()->nHeight / 2) - pblockindex = mapBlockIndex[chainActive.Genesis()->GetBlockHash()]; - else - pblockindex = chainActive.Tip(); - if (pblockindexFBBHLast && abs(nHeight - pblockindex->nHeight) > abs(nHeight - pblockindexFBBHLast->nHeight)) - pblockindex = pblockindexFBBHLast; - while (pblockindex->nHeight > nHeight) - pblockindex = pblockindex->pprev; - while (pblockindex->nHeight < nHeight) - pblockindex = chainActive.Next(pblockindex); - pblockindexFBBHLast = pblockindex; - return pblockindex; -} - -std::string DefaultRecAddress(std::string sType) -{ - std::string sDefaultRecAddress; - for (auto item : pwalletMain->mapAddressBook) - { - const CBitcoinAddress& address = item.first; - std::string strName = item.second.name; - bool fMine = IsMine(*pwalletMain, address.Get()); - if (fMine) - { - sDefaultRecAddress=CBitcoinAddress(address).ToString(); - boost::to_upper(strName); - boost::to_upper(sType); - if (strName == sType) - { - sDefaultRecAddress = CBitcoinAddress(address).ToString(); - return sDefaultRecAddress; - } - } - } - - if (!sType.empty()) - { - std::string sError; - sDefaultRecAddress = GenerateNewAddress(sError, sType); - if (sError.empty()) return sDefaultRecAddress; - } - - return sDefaultRecAddress; -} - - -std::string RetrieveMd5(std::string s1) -{ - try - { - const char* chIn = s1.c_str(); - unsigned char digest2[16]; - MD5((unsigned char*)chIn, strlen(chIn), (unsigned char*)&digest2); - char mdString2[33]; - for(int i = 0; i < 16; i++) sprintf(&mdString2[i*2], "%02x", (unsigned int)digest2[i]); - std::string xmd5(mdString2); - return xmd5; - } - catch (std::exception &e) - { - return std::string(); - } -} - - -std::string PubKeyToAddress(const CScript& scriptPubKey) -{ - CTxDestination address1; - ExtractDestination(scriptPubKey, address1); - CBitcoinAddress address2(address1); - return address2.ToString(); -} - - -void GetTxTimeAndAmountAndHeight(uint256 hashInput, int hashInputOrdinal, int64_t& out_nTime, CAmount& out_caAmount, int& out_height) -{ - CTransaction tx1; - uint256 hashBlock1; - if (GetTransaction(hashInput, tx1, Params().GetConsensus(), hashBlock1, true)) - { - out_caAmount = tx1.vout[hashInputOrdinal].nValue; - BlockMap::iterator mi = mapBlockIndex.find(hashBlock1); - if (mi != mapBlockIndex.end()) - { - CBlockIndex* pindexHistorical = mapBlockIndex[hashBlock1]; - out_nTime = pindexHistorical->GetBlockTime(); - out_height = pindexHistorical->nHeight; - return; - } - else - { - LogPrintf("\nUnable to find hashBlock %s", hashBlock1.GetHex().c_str()); - } - } - else - { - LogPrintf("\nUnable to find hashblock1 in GetTransaction %s ",hashInput.GetHex().c_str()); - } -} - - - -CAmount GetRPCBalance() -{ - return pwalletMain->GetBalance(); -} - -bool RPCSendMoney(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend, std::string sOptionalData, double nCoinAge) -{ - CAmount curBalance = pwalletMain->GetBalance(); - - // Check amount - if (nValue <= 0) - { - sError = "Invalid amount"; - return false; - } - - if (pwalletMain->IsLocked()) - { - sError = "Wallet unlock required"; - return false; - } - - if (nValue > curBalance) - { - sError = "Insufficient funds"; - return false; - } - // Parse address - CScript scriptPubKey = GetScriptForDestination(address); - - // Create and send the transaction - CReserveKey reservekey(pwalletMain); - CAmount nFeeRequired; - std::string strError; - std::vector vecSend; - int nChangePosRet = -1; - bool fForce = false; - CRecipient recipient = {scriptPubKey, nValue, "", fSubtractFeeFromAmount}; - vecSend.push_back(recipient); - - int nMinConfirms = 0; - if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, ONLY_DENOMINATED, fUseInstantSend)) - { - if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance()) - { - sError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired)); - return false; - } - sError = "Unable to Create Transaction: " + strError; - return false; - } - //CValidationState state; - - if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX)) - { - sError = "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."; - return false; - } - return true; -} - -CAmount R20(CAmount amount) -{ - double nAmount = amount / COIN; - nAmount = nAmount + 0.5 - (nAmount < 0); - int iAmount = (int)nAmount; - return (iAmount * COIN); -} - -double R2X(double var) -{ - double value = (int)(var * 100 + .5); - return (double)value / 100; -} - -double Quantize(double nFloor, double nCeiling, double nValue) -{ - double nSpan = nCeiling - nFloor; - double nLevel = nSpan * nValue; - double nOut = nFloor + nLevel; - if (nOut > std::max(nFloor, nCeiling)) nOut = std::max(nFloor, nCeiling); - if (nOut < std::min(nCeiling, nFloor)) nOut = std::min(nCeiling, nFloor); - return nOut; -} - -int GetHeightByEpochTime(int64_t nEpoch) -{ - if (!chainActive.Tip()) return 0; - int nLast = chainActive.Tip()->nHeight; - if (nLast < 1) return 0; - for (int nHeight = nLast; nHeight > 0; nHeight--) - { - CBlockIndex* pindex = FindBlockByHeight(nHeight); - if (pindex) - { - int64_t nTime = pindex->GetBlockTime(); - if (nEpoch > nTime) return nHeight; - } - } - return -1; -} - -void GetGovSuperblockHeights(int& nNextSuperblock, int& nLastSuperblock) -{ - - int nBlockHeight = 0; - { - LOCK(cs_main); - nBlockHeight = (int)chainActive.Height(); - } - int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock; - int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle; - int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle; - int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset; - if(nBlockHeight < nFirstSuperblock) - { - nLastSuperblock = 0; - nNextSuperblock = nFirstSuperblock; - } else { - nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle; - nNextSuperblock = nLastSuperblock + nSuperblockCycle; - } -} - -std::string GetActiveProposals() -{ - int nStartTime = GetAdjustedTime() - (86400 * 32); - LOCK2(cs_main, governance.cs); - std::vector objs = governance.GetAllNewerThan(nStartTime); - std::string sXML; - int id = 0; - std::string sDelim = "|"; - std::string sZero = "\0"; - int nLastSuperblock = 0; - int nNextSuperblock = 0; - GetGovSuperblockHeights(nNextSuperblock, nLastSuperblock); - for (CGovernanceObject* pGovObj : objs) - { - if (pGovObj->GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) continue; - int64_t nEpoch = 0; - int64_t nStartEpoch = 0; - CGovernanceObject* myGov = governance.FindGovernanceObject(pGovObj->GetHash()); - UniValue obj = myGov->GetJSONObject(); - std::string sURL; - std::string sProposalType; - nStartEpoch = cdbl(obj["start_epoch"].getValStr(), 0); - nEpoch = cdbl(obj["end_epoch"].getValStr(), 0); - sURL = obj["url"].getValStr(); - sProposalType = obj["expensetype"].getValStr(); - if (sProposalType.empty()) sProposalType = "N/A"; - DACProposal dProposal = GetProposalByHash(pGovObj->GetHash(), nLastSuperblock); - std::string sHash = pGovObj->GetHash().GetHex(); - int nEpochHeight = GetHeightByEpochTime(nStartEpoch); - // First ensure the proposals gov height has not passed yet - bool bIsPaid = nEpochHeight < nLastSuperblock; - std::string sReport = DescribeProposal(dProposal); - if (fDebug) - LogPrintf("\nGetActiveProposals::Proposal %s , epochHeight %f, nLastSuperblock %f, IsPaid %f ", - sReport, nEpochHeight, nLastSuperblock, (double)bIsPaid); - if (!bIsPaid) - { - int iYes = pGovObj->GetYesCount(VOTE_SIGNAL_FUNDING); - int iNo = pGovObj->GetNoCount(VOTE_SIGNAL_FUNDING); - int iAbstain = pGovObj->GetAbstainCount(VOTE_SIGNAL_FUNDING); - id++; - if (sProposalType.empty()) sProposalType = "NA"; - std::string sProposalTime = TimestampToHRDate(nStartEpoch); - if (id == 1) sURL += "&t=" + RoundToString(GetAdjustedTime(), 0); - std::string sName; - sName = obj["name"].getValStr(); - double dCharityAmount = 0; - dCharityAmount = cdbl(obj["payment_amount"].getValStr(), 2); - std::string sRow = "" + sHash + sDelim - + sName + sDelim - + RoundToString(dCharityAmount, 2) + sDelim - + sProposalType + sDelim - + sProposalTime + sDelim - + RoundToString(iYes, 0) + sDelim - + RoundToString(iNo, 0) + sDelim + RoundToString(iAbstain,0) - + sDelim + sURL; - sXML += sRow; - } - } - return sXML; -} - -bool VoteManyForGobject(std::string govobj, std::string strVoteSignal, std::string strVoteOutcome, - int iVotingLimit, int& nSuccessful, int& nFailed, std::string& sError) -{ - - uint256 hash(uint256S(govobj)); - vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal); - if(eVoteSignal == VOTE_SIGNAL_NONE) - { - sError = "Invalid vote signal (funding)."; - return false; - } - vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome); - if(eVoteOutcome == VOTE_OUTCOME_NONE) - { - sError = "Invalid vote outcome (yes/no/abstain)"; - return false; - } - -#ifdef ENABLE_WALLET - if (!pwalletMain) - { - sError = "Voting is not supported when wallet is disabled."; - return false; - } -#endif - - std::map votingKeys; - - -// auto mnList = deterministicMNManager->GetListAtChainTip(); -// mnList.ForEachMN(true, [&](const CDeterministicMNCPtr& dmn) -// { -// CKey votingKey; -// if (pwalletMain->GetKey(dmn->pdmnState->keyIDVoting, votingKey)) -// { -// votingKeys.emplace(dmn->proTxHash, votingKey); -// } -// }); - - - - UniValue vOutcome; - - - try - { - - std::vector mnEntries; - mnEntries = masternodeConfig.getEntries(); - - UniValue resultsObj(UniValue::VOBJ); - - BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) { - std::string strError; - std::vector vchMasterNodeSignature; - std::string strMasterNodeSignMessage; - - CPubKey pubKeyCollateralAddress; - CKey keyCollateralAddress; - CPubKey pubKeyMasternode; - CKey keyMasternode; - - UniValue statusObj(UniValue::VOBJ); - - if(!CMessageSigner::GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)){ - nFailed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Masternode signing error, could not set key correctly")); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - uint256 nTxHash; - nTxHash.SetHex(mne.getTxHash()); - - int nOutputIndex = 0; - if(!ParseInt32(mne.getOutputIndex(), &nOutputIndex)) { - continue; - } - - COutPoint outpoint(nTxHash, nOutputIndex); - - CMasternode mn; - bool fMnFound = mnodeman.Get(outpoint, mn); - - if(!fMnFound) { - nFailed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Can't find masternode by collateral output")); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - CGovernanceVote vote(mn.vin.prevout, hash, eVoteSignal, eVoteOutcome); - if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - nFailed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Failure to sign.")); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - CGovernanceException exception; - if(governance.ProcessVoteAndRelay(vote, exception, *g_connman)) { - nSuccessful++; - statusObj.push_back(Pair("result", "success")); - } - else { - nFailed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", exception.GetMessage())); - } - - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - } - - UniValue returnObj(UniValue::VOBJ); - returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", nSuccessful, nFailed))); - returnObj.push_back(Pair("detail", resultsObj)); - returnObj.push_back(Pair("success_count", nSuccessful)); - - vOutcome = returnObj; - - //vOutcome = VoteWithMasternodes(votingKeys, hash, eVoteSignal, eVoteOutcome); - } - catch(std::runtime_error& e) - { - sError = e.what(); - return false; - } - catch (...) - { - sError = "Voting failed."; - return false; - } - - nSuccessful = cdbl(vOutcome["success_count"].getValStr(), 0); - bool fResult = nSuccessful > 0 ? true : false; - return fResult; -} - - -std::string CreateGovernanceCollateral(uint256 GovObjHash, CAmount caFee, std::string& sError) -{ - CWalletTx wtx; - if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, GovObjHash, caFee, false)) - { - sError = "Error creating collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked."; - return std::string(); - } - if (sError.empty()) - { - // -- make our change address - CReserveKey reservekey(pwalletMain); - //CValidationState state; - pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), NetMsgType::TX); - DBG( cout << "gobject: prepare " - << " strData = " << govobj.GetDataAsString() - << ", hash = " << govobj.GetHash().GetHex() - << ", txidFee = " << wtx.GetHash().GetHex() - << endl; ); - return wtx.GetHash().ToString(); - } - return std::string(); -} - -int GetNextSuperblock() -{ - int nLastSuperblock, nNextSuperblock; - // Get current block height - int nBlockHeight = 0; - { - LOCK(cs_main); - nBlockHeight = (int)chainActive.Height(); - } - - // Get chain parameters - int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock; - int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle; - - // Get first superblock - int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle; - int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset; - - if(nBlockHeight < nFirstSuperblock) - { - nLastSuperblock = 0; - nNextSuperblock = nFirstSuperblock; - } - else - { - nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle; - nNextSuperblock = nLastSuperblock + nSuperblockCycle; - } - return nNextSuperblock; -} - - -bool SubmitProposalToNetwork(uint256 txidFee, int64_t nStartTime, std::string sHex, std::string& sError, std::string& out_sGovObj) -{ - if(!masternodeSync.IsBlockchainSynced()) - { - sError = "Must wait for client to sync with masternode network. "; - return false; - } - // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS - uint256 hashParent = uint256(); - int nRevision = 1; - CGovernanceObject govobj(hashParent, nRevision, nStartTime, txidFee, sHex); - DBG( cout << "gobject: submit " - << " strData = " << govobj.GetDataAsString() - << ", hash = " << govobj.GetHash().GetHex() - << ", txidFee = " << txidFee.GetHex() - << endl; ); - - std::string strHash = govobj.GetHash().ToString(); - if(!govobj.IsValidLocally(sError, true)) - { - sError += "Object submission rejected because object is not valid."; - LogPrintf("\n OBJECT REJECTED:\n gobject submit 0 1 %f %s %s \n", (double)nStartTime, sHex.c_str(), txidFee.GetHex().c_str()); - return false; - } - // RELAY THIS OBJECT - Reject if rate check fails but don't update buffer - - bool fRateCheckBypassed = false; - if(!governance.MasternodeRateCheck(govobj, true, false, fRateCheckBypassed)) - { - sError = "Object creation rate limit exceeded"; - return false; - } - //governance.AddSeenGovernanceObject(govobj.GetHash(), SEEN_OBJECT_IS_VALID); - govobj.Relay(*g_connman); - governance.AddGovernanceObject(govobj, *g_connman); - out_sGovObj = govobj.GetHash().ToString(); - return true; -} - - -static double HTTP_PROTO_VERSION = 2.0; -//std::string HTTPSPost(bool bPost, int iThreadID, std::string sActionName, std::string sDistinctUser, std::string sPayload, std::string sBaseURL, std::string sPage, int iPort, -// std::string sSolution, int iTimeoutSecs, int iMaxSize, int iBOE) -//{ -// std::string sData; -// int iChunkSize = 1024; -// if (iMaxSize > 512000) -// { -// sData.reserve(iMaxSize); -// iChunkSize = 65536; -// } -// -// // The OpenSSL version of Post *only* works with SSL websites, hence the need for HTTPPost(2) (using BOOST). The dev team is working on cleaning this up before the end of 2019 to have one standard version with cleaner code and less internal parts. // -// try -// { -// double dDebugLevel = cdbl(GetArg("-devdebuglevel", "0"), 0); -// -// std::map mapRequestHeaders; -// mapRequestHeaders["Miner"] = sDistinctUser; -// mapRequestHeaders["Action"] = sPayload; -// mapRequestHeaders["Solution"] = sSolution; -// mapRequestHeaders["Agent"] = FormatFullVersion(); -// // Supported pool Network Chain modes: main, test, regtest -// const CChainParams& chainparams = Params(); -// mapRequestHeaders["NetworkID"] = chainparams.NetworkIDString(); -// mapRequestHeaders["ThreadID"] = RoundToString(iThreadID, 0); -// mapRequestHeaders["OS"] = sOS; -// -// mapRequestHeaders["SessionID"] = msSessionID; -// mapRequestHeaders["WorkerID1"] = GetArg("-workerid", ""); -// mapRequestHeaders["WorkerID2"] = GetArg("-workeridfunded", ""); -// mapRequestHeaders["HTTP_PROTO_VERSION"] = RoundToString(HTTP_PROTO_VERSION, 0); -// -// BIO* bio; -// SSL_CTX* ctx; -// // Registers the SSL/TLS ciphers and digests and starts the security layer. -// SSL_library_init(); -// ctx = SSL_CTX_new(SSLv23_client_method()); -// if (ctx == NULL) -// { -// return "CTX_IS_NULL"; -// } -// bio = BIO_new_ssl_connect(ctx); -// std::string sDomain = GetDomainFromURL(sBaseURL); -// std::string sDomainWithPort = sDomain + ":" + RoundToString(iPort, 0); -// -// // Compatibility with strict d-dos prevention rules (like cloudflare) -// SSL * ssl(nullptr); -// BIO_get_ssl(bio, &ssl); -// SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); -// SSL_set_tlsext_host_name(ssl, const_cast(sDomain.c_str())); -// BIO_set_conn_int_port(bio, &iPort); -// -// BIO_set_conn_hostname(bio, sDomainWithPort.c_str()); -// if(BIO_do_connect(bio) <= 0) -// { -// return "Failed connection to " + sDomainWithPort + ""; -// } -// -// if (sDomain.empty()) return "DOMAIN_MISSING"; -// // Evo requires 2 args instead of 3, the last used to be true for DNS resolution=true -// -// CNetAddr cnaMyHost; -// LookupHost(sDomain.c_str(), cnaMyHost, true); -// CService addrConnect = CService(cnaMyHost, 443); -// -// if (!addrConnect.IsValid()) -// { -// return "DNS_ERROR"; -// } -// std::string sPost = PrepareHTTPPost(bPost, sPage, sDomain, sPayload, mapRequestHeaders); -// if (dDebugLevel == 1) -// LogPrintf("Trying connection to %s ", sPost); -// const char* write_buf = sPost.c_str(); -// if(BIO_write(bio, write_buf, strlen(write_buf)) <= 0) -// { -// return "FAILED_HTTPS_POST"; -// } -// // Variables used to read the response from the server -// int size; -// clock_t begin = clock(); -// char buf[65536]; -// for(;;) -// { -// // Get chunks of the response -// size = BIO_read(bio, buf, 65535); -// if(size <= 0) -// { -// break; -// } -// buf[size] = 0; -// std::string MyData(buf); -// sData += MyData; -// clock_t end = clock(); -// double elapsed_secs = double(end - begin) / (CLOCKS_PER_SEC + .01); -// if (elapsed_secs > iTimeoutSecs) break; -// if (TermPeekFound(sData, iBOE)) break; -// -// if (sData.find("Content-Length:") != std::string::npos) -// { -// double dMaxSize = cdbl(ExtractXML(sData,"Content-Length: ","\n"),0); -// std::size_t foundPos = sData.find("Content-Length:"); -// if (dMaxSize > 0) -// { -// iMaxSize = dMaxSize + (int)foundPos + 16; -// } -// } -// if ((int)sData.size() >= (iMaxSize-1)) break; -// } -// // R ANDREW - JAN 4 2018: Free bio resources -// BIO_free_all(bio); -// if (dDebugLevel == 1) -// LogPrintf("Received %s ", sData); -// return sData; -// } -// catch (std::exception &e) -// { -// return "WEB_EXCEPTION"; -// } -// catch (...) -// { -// return "GENERAL_WEB_EXCEPTION"; -// } -//} From daff994acdd6e2f447303fd8e422a096732e861a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:33:52 -0400 Subject: [PATCH 0740/1324] Delete rpcpog.h --- src/rpcpog.h | 312 --------------------------------------------------- 1 file changed, 312 deletions(-) delete mode 100644 src/rpcpog.h diff --git a/src/rpcpog.h b/src/rpcpog.h deleted file mode 100644 index 69b888a7..00000000 --- a/src/rpcpog.h +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef RPCPOG_H -#define RPCPOG_H - -#include "wallet/wallet.h" -#include "consensus/validation.h" -#include "hash.h" -#include "net.h" -#include "utilstrencodings.h" -#include "validation.h" -#include -#include - -class CWallet; - - - - - -std::string RetrieveMd5(std::string s1); - -struct UserVote -{ - int nTotalYesCount = 0; - int nTotalNoCount = 0; - int nTotalAbstainCount = 0; - int nTotalYesWeight = 0; - int nTotalNoWeight = 0; - int nTotalAbstainWeight = 0; -}; - -struct CPK -{ - std::string sAddress; - int64_t nLockTime = 0; - std::string sCampaign; - std::string sNickName; - std::string sEmail; - std::string sVendorType; - std::string sError; - std::string sChildId; - std::string sOptData; - std::string cpid; - double nProminence = 0; - double nPoints = 0; - bool fValid = false; -}; - -struct DACResult -{ - std::string Response; - bool fError = false; - std::string ErrorCode; -}; - -struct Researcher -{ - std::string nickname; - int teamid = 0; - std::string country; - int64_t creationtime = 0; - double totalcredit = 0; - double wcgpoints = 0; - double rac = 0; - int id = 0; - std::string cpid; - bool found = false; - bool unbanked = false; - double CoinAge = 0; - std::string CPK; -}; - -struct CoinVin -{ - COutPoint OutPoint; - uint256 HashBlock = uint256S("0x0"); - int64_t BlockTime = 0; - double CoinAge = 0; - CAmount Amount = 0; - std::string Destination = std::string(); - bool Found = false; - CTransaction TxRef; -}; - -struct WhaleStake -{ - double Amount = 0; - double RewardAmount = 0; - double TotalOwed = 0; - int64_t BurnTime = 0; - int BurnHeight = 0; - int Duration = 0; - double DWU = 0; - double ActualDWU = 0; - int64_t MaturityTime = 0; - int MaturityHeight = 0; - std::string CPK = std::string(); - uint256 TXID = uint256S("0x0"); - std::string XML = std::string(); - std::string ReturnAddress = std::string(); - bool found = false; - bool paid = false; -}; - -static double MAX_DAILY_WHALE_COMMITMENTS = 5000000; -static double MAX_WHALE_DWU = 2.0; -struct WhaleMetric -{ - double nTotalFutureCommitments = 0; - double nTotalGrossFutureCommitments = 0; - - double nTotalCommitmentsDueToday = 0; - double nTotalGrossCommitmentsDueToday = 0; - - double nTotalBurnsToday = 0; - double nTotalGrossBurnsToday = 0; - - double nTotalMonthlyCommitments = 0; - double nTotalGrossMonthlyCommitments = 0; - - double nTotalAnnualReward = 0; - - double nSaturationPercentAnnual = 0; - double nSaturationPercentMonthly = 0; - double DWU = 0; -}; - -struct DACProposal -{ - std::string sName; - int64_t nStartEpoch = 0; - int64_t nEndEpoch = 0; - std::string sURL; - std::string sExpenseType; - double nAmount = 0; - std::string sAddress; - uint256 uHash = uint256S("0x0"); - int nHeight = 0; - bool fPassing = false; - int nNetYesVotes = 0; - int nYesVotes = 0; - int nNoVotes = 0; - int nAbstainVotes = 0; - int nMinPassing = 0; - int nLastSuperblock = 0; - bool fIsPaid = false; - std::string sProposalHRTime; -}; - -///** Comparison function for sorting the getchaintips heads. */ -//struct CompareBlocksByHeight -//{ -// bool operator()(const CBlockIndex* a, const CBlockIndex* b) const -// { -// /* Make sure that unequal blocks with the same height do not compare -// equal. Use the pointers themselves to make a distinction. */ -// -// if (a->nHeight != b->nHeight) -// return (a->nHeight > b->nHeight); -// -// return a < b; -// } -//}; - -CAmount CAmountFromValue(const UniValue& value); -std::string RoundToString(double d, int place); -std::string QueryBibleHashVerses(uint256 hash, uint64_t nBlockTime, uint64_t nPrevBlockTime, int nPrevHeight, CBlockIndex* pindexPrev); -CAmount GetDailyMinerEmissions(int nHeight); -std::string CreateBankrollDenominations(double nQuantity, CAmount denominationAmount, std::string& sError); -std::string DefaultRecAddress(std::string sType); -std::string GenerateNewAddress(std::string& sError, std::string sName); -CAmount GetTitheTotal(CTransaction tx); -bool IsTitheLegal(CTransaction ctx, CBlockIndex* pindex, CAmount tithe_amount); -void GetTxTimeAndAmountAndHeight(uint256 hashInput, int hashInputOrdinal, int64_t& out_nTime, CAmount& out_caAmount, int& out_height); -std::string SendTithe(CAmount caTitheAmount, double dMinCoinAge, CAmount caMinCoinAmount, CAmount caMaxTitheAmount, - std::string sSpecificTxId, int nSpecificOutput, std::string& sError); -CAmount GetTitheCap(const CBlockIndex* pindexLast); -double R2X(double var); -double Quantize(double nFloor, double nCeiling, double nValue); -CAmount Get24HourTithes(const CBlockIndex* pindexLast); -double GetPOGDifficulty(const CBlockIndex* pindex); -std::string GetActiveProposals(); -bool VoteManyForGobject(std::string govobj, std::string strVoteSignal, std::string strVoteOutcome, - int iVotingLimit, int& nSuccessful, int& nFailed, std::string& sError); -bool AmIMasternode(); -std::string CreateGovernanceCollateral(uint256 GovObjHash, CAmount caFee, std::string& sError); -int GetNextSuperblock(); -std::string StoreBusinessObjectWithPK(UniValue& oBusinessObject, std::string& sError); -std::string StoreBusinessObject(UniValue& oBusinessObject, std::string& sError); -bool is_email_valid(const std::string& e); -double GetSporkDouble(std::string sName, double nDefault); -int64_t GetFileSize(std::string sPath); -std::string AddBlockchainMessages(std::string sAddress, std::string sType, std::string sPrimaryKey, - std::string sHTML, CAmount nAmount, double minCoinAge, std::string& sError); -std::string ReadCache(std::string sSection, std::string sKey); -void ClearCache(std::string sSection); -void WriteCache(std::string sSection, std::string sKey, std::string sValue, int64_t locktime, bool IgnoreCase=true); -std::string GetSporkValue(std::string sKey); -std::string TimestampToHRDate(double dtm); -std::string GetArrayElement(std::string s, std::string delim, int iPos); -void GetMiningParams(int nPrevHeight, bool& f7000, bool& f8000, bool& f9000, bool& fTitheBlocksActive); -std::string RetrieveTxOutInfo(const CBlockIndex* pindexLast, int iLookback, int iTxOffset, int ivOutOffset, int iDataType); -double GetBlockMagnitude(int nChainHeight); -uint256 PercentToBigIntBase(int iPercent); -std::string GetIPFromAddress(std::string sAddress); -bool SubmitProposalToNetwork(uint256 txidFee, int64_t nStartTime, std::string sHex, std::string& sError, std::string& out_sGovObj); -std::string SubmitToIPFS(std::string sPath, std::string& sError); -UniValue GetDataList(std::string sType, int iMaxAgeInDays, int& iSpecificEntry, std::string sSearch, std::string& outEntry); -int GetSignalInt(std::string sLocalSignal); -double GetDifficulty(const CBlockIndex* blockindex); -bool LogLimiter(int iMax1000); -std::string PubKeyToAddress(const CScript& scriptPubKey); -UniValue ContributionReport(); -int DeserializePrayersFromFile(); -double Round(double d, int place); -void SerializePrayersToFile(int nHeight); -std::string AmountToString(const CAmount& amount); -CBlockIndex* FindBlockByHeight(int nHeight); -std::string rPad(std::string data, int minWidth); -double cdbl(std::string s, int place); -std::string AmountToString(const CAmount& amount); -std::string ExtractXML(std::string XMLdata, std::string key, std::string key_end); -bool Contains(std::string data, std::string instring); -std::string GetVersionAlert(); -bool CheckNonce(bool f9000, unsigned int nNonce, int nPrevHeight, int64_t nPrevBlockTime, int64_t nBlockTime, const Consensus::Params& params); -bool RPCSendMoney(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend=false, std::string sOptionalData = "", double nCoinAge = 0); -bool FundWithExternalPurse(std::string& sError, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend, CAmount nExactAmount, std::string sOptionalData, double dMinCoinAge, std::string sPursePubKey); -std::vector ReadBytesAll(char const* filename); -std::string VectToString(std::vector v); -CAmount StringToAmount(std::string sValue); -bool CompareMask(CAmount nValue, CAmount nMask); -std::string GetElement(std::string sIn, std::string sDelimiter, int iPos); -bool CopyFile(std::string sSrc, std::string sDest); -std::string Caption(std::string sDefault, int iMaxLen); -std::vector Split(std::string s, std::string delim); -void MemorizeBlockChainPrayers(bool fDuringConnectBlock, bool fSubThread, bool fColdBoot, bool fDuringSanctuaryQuorum); -double GetBlockVersion(std::string sXML); -bool CheckStakeSignature(std::string sBitcoinAddress, std::string sSignature, std::string strMessage, std::string& strError); -std::string HTTPSPost(bool bPost, int iThreadID, std::string sActionName, std::string sDistinctUser, std::string sPayload, std::string sBaseURL, std::string sPage, int iPort, - std::string sSolution, int iTimeoutSecs, int iMaxSize, int iBreakOnError); -std::string HTTPSPost2(bool bPost, std::string sProtocol, std::string sDomain, std::string sPage, std::string sPayload, std::string sFileName); -std::string FormatHTML(std::string sInput, int iInsertCount, std::string sStringToInsert); -std::string GJE(std::string sKey, std::string sValue, bool bIncludeDelimiter, bool bQuoteValue); -bool InstantiateOneClickMiningEntries(); -bool WriteKey(std::string sKey, std::string sValue); -std::string GetTransactionMessage(CTransaction tx); -std::map GetChildMap(std::string sGSCObjType); -bool AdvertiseChristianPublicKeypair(std::string sProjectId, std::string sNickName, std::string sEmail, std::string sVendorType, bool fUnJoin, bool fForce, CAmount nFee, std::string sOptData, std::string &sError); -CWalletTx CreateAntiBotNetTx(CBlockIndex* pindexLast, double nMinCoinAge, CReserveKey& reservekey, std::string& sXML, std::string sPoolMiningPublicKey, std::string& sError); -double GetAntiBotNetWeight(int64_t nBlockTime, CTransaction tx, bool fDebug, std::string sSolver); -double GetABNWeight(const CBlock& block, bool fMining); -std::map GetSporkMap(std::string sPrimaryKey, std::string sSecondaryKey); -std::map GetGSCMap(std::string sGSCObjType, std::string sSearch, bool fRequireSig); -void WriteCacheDouble(std::string sKey, double dValue); -double ReadCacheDouble(std::string sKey); -bool CheckAntiBotNetSignature(CTransaction tx, std::string sType, std::string sSolver); -double GetVINCoinAge(int64_t nBlockTime, CTransaction tx, bool fDebug); -CAmount GetTitheAmount(CTransaction ctx); -CPK GetCPK(std::string sData); -std::string GetCPKData(std::string sProjectId, std::string sPK); -CAmount GetRPCBalance(); -void GetGovSuperblockHeights(int& nNextSuperblock, int& nLastSuperblock); -int GetHeightByEpochTime(int64_t nEpoch); -bool CheckABNSignature(const CBlock& block, std::string& out_CPK); -std::string GetPOGBusinessObjectList(std::string sType, std::string sFields); -std::string SignMessageEvo(std::string strAddress, std::string strMessage, std::string& sError); -const CBlockIndex* GetBlockIndexByTransactionHash(const uint256 &hash); -double AddVector(std::string sData, std::string sDelim); -int ReassessAllChains(); -double GetFees(CTransaction tx); -int64_t GetCacheEntryAge(std::string sSection, std::string sKey); -void LogPrintWithTimeLimit(std::string sSection, std::string sValue, int64_t nMaxAgeInSeconds); -std::vector GetVectorOfFilesInDirectory(const std::string &dirPath, const std::vector dirSkipList); -std::string GetAttachmentData(std::string sPath); -std::string BIPFS_UploadSingleFile(std::string sPath, std::string sWebPath); -std::string Path_Combine(std::string sPath, std::string sFileName); -std::string DSQL_Ansi92Query(std::string sSQL); -void ProcessBLSCommand(CTransaction tx); -DACResult GetDecentralizedURL(); -std::string BIPFS_Payment(CAmount nAmount, std::string sTXID, std::string sXML); -DACResult DSQL_ReadOnlyQuery(std::string sXMLSource); -DACResult DSQL_ReadOnlyQuery(std::string sEndpoint, std::string sXML); -int LoadResearchers(); -std::string TeamToName(int iTeamID); -std::string GetResearcherCPID(std::string sSearch); -bool CreateExternalPurse(std::string& sError); -bool VerifyMemoryPoolCPID(CTransaction tx); -std::string GetEPArg(bool fPublic); -std::vector GetDWS(bool fIncludeMemoryPool); -WhaleMetric GetWhaleMetrics(int nHeight, bool fIncludeMemoryPool); -bool VerifyDynamicWhaleStake(CTransaction tx, std::string& sError); -double GetDWUBasedOnMaturity(double nDuration, double dDWU); -double GetOwedBasedOnMaturity(double nDuration, double dDWU, double dAmount); -std::vector GetPayableWhaleStakes(int nHeight, double& nOwed); -CoinVin GetCoinVIN(COutPoint o, int64_t nTxTime); -bool GetTxDAC(uint256 txid, CTransaction& tx1); -double GetWhaleStakesInMemoryPool(std::string sCPK); -std::string GetCPKByCPID(std::string sCPID); -int GetNextPODCTransmissionHeight(int height); -int GetWhaleStakeSuperblockHeight(int nHeight); -std::string SearchChain(int nBlocks, std::string sDest); -std::string GetResDataBySearch(std::string sSearch); -int GetWCGIdByCPID(std::string sSearch); -uint256 ComputeRandomXTarget(uint256 hash, int64_t nPrevBlockTime, int64_t nBlockTime); -std::string ReverseHex(std::string const & src); -uint256 GetRandomXHash(std::string sHeaderHex, uint256 key, uint256 hashPrevBlock, int iThreadID); -std::string GenerateFaucetCode(); - -#endif From 454f75eed868ad3c9dc0d2ee3b20fb3b557252f3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:34:07 -0400 Subject: [PATCH 0741/1324] Delete smartcontract-client.cpp --- src/smartcontract-client.cpp | 38 ------------------------------------ 1 file changed, 38 deletions(-) delete mode 100644 src/smartcontract-client.cpp diff --git a/src/smartcontract-client.cpp b/src/smartcontract-client.cpp deleted file mode 100644 index 0ee35049..00000000 --- a/src/smartcontract-client.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "smartcontract-client.h" -#include "smartcontract-server.h" -#include "util.h" -#include "utilmoneystr.h" -#include "rpcpodc.h" -#include "rpcpog.h" -#include "init.h" -#include "activemasternode.h" -#include "governance-classes.h" -#include "governance.h" -#include "masternode-sync.h" -#include "masternode-payments.h" -#include "masternodeconfig.h" -#include "messagesigner.h" -#include -#include // for to_lower() -#include // for trim() -#include // for StringToUnixTime() -#include /* round, floor, ceil, trunc */ -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ENABLE_WALLET -extern CWallet* pwalletMain; -#endif // ENABLE_WALLET - -//////////////////////////////////////////////////////////////////// DAC - SMART CONTRACTS - CLIENT SIDE /////////////////////////////////////////////////////////////////////////////////////////////// - From 9cfd9f61ce7d0836ae4bae4868a059954a1e5e31 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:34:16 -0400 Subject: [PATCH 0742/1324] Delete smartcontract-client.h --- src/smartcontract-client.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/smartcontract-client.h diff --git a/src/smartcontract-client.h b/src/smartcontract-client.h deleted file mode 100644 index 0a62823c..00000000 --- a/src/smartcontract-client.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef SMARTCONTRACTCLIENT_H -#define SMARTCONTRACTCLIENT_H - -#include "wallet/wallet.h" -#include "hash.h" -#include "net.h" -#include "rpcpog.h" -#include "utilstrencodings.h" -#include - -class CWallet; - -UniValue GetCampaigns(); -bool CheckCampaign(std::string sName); -bool Enrolled(std::string sCampaignName, std::string& sError); -CPK GetCPKFromProject(std::string sProjName, std::string sCPKPtr); -UniValue SentGSCCReport(int nHeight, std::string sMyCPK); -CPK GetMyCPK(std::string sProjectName); -bool CreateGSCTransmission(bool fForce, std::string sDiary, std::string& sError, std::string sSpecificCampaignName, std::string& sWarning); -bool CreateAllGSCTransmissions(std::string& sError); -double GetNecessaryCoinAgePercentageForPODC(); - -#endif From 8319384fb7199574c5367643e731220d535e5a8e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:34:25 -0400 Subject: [PATCH 0743/1324] Delete smartcontract-server.cpp --- src/smartcontract-server.cpp | 101 ----------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 src/smartcontract-server.cpp diff --git a/src/smartcontract-server.cpp b/src/smartcontract-server.cpp deleted file mode 100644 index cf3873b8..00000000 --- a/src/smartcontract-server.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "smartcontract-server.h" -#include "util.h" -#include "utilmoneystr.h" -#include "rpcpog.h" -#include "rpcpodc.h" -#include "smartcontract-client.h" -#include "init.h" -#include "activemasternode.h" -#include "governance-classes.h" -#include "governance.h" -#include "masternode-sync.h" -#include "masternode-payments.h" -#include "messagesigner.h" -#include "spork.h" -#include -#include // for to_lower() -#include // for trim(), and case insensitive compare -#include // for StringToUnixTime() -#include /* round, floor, ceil, trunc */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef ENABLE_WALLET -extern CWallet* pwalletMain; -#endif // ENABLE_WALLET - - - -//////////////////////////////////////////////////////////////////////////////// Watchman-On-The-Wall ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// DAC's version of The Sentinel, March 31st, 2019 // - -// // - - - -std::string GetCPIDByCPK(std::string sCPK) -{ - std::string sData = ReadCache("CPK-WCG", sCPK); - std::vector vP = Split(sData.c_str(), "|"); - if (vP.size() < 10) - return std::string(); - std::string cpid = vP[8]; - return cpid; -} - -DACProposal GetProposalByHash(uint256 govObj, int nLastSuperblock) -{ - int nMinPassing = 500 * .10; - if (nMinPassing < 1) nMinPassing = 1; - CGovernanceObject* myGov = governance.FindGovernanceObject(govObj); - UniValue obj = myGov->GetJSONObject(); - DACProposal dacProposal; - dacProposal.sName = obj["name"].getValStr(); - dacProposal.nStartEpoch = cdbl(obj["start_epoch"].getValStr(), 0); - dacProposal.nEndEpoch = cdbl(obj["end_epoch"].getValStr(), 0); - dacProposal.sURL = obj["url"].getValStr(); - dacProposal.sExpenseType = obj["expensetype"].getValStr(); - dacProposal.nAmount = cdbl(obj["payment_amount"].getValStr(), 2); - dacProposal.sAddress = obj["payment_address"].getValStr(); - dacProposal.uHash = myGov->GetHash(); - dacProposal.nHeight = GetHeightByEpochTime(dacProposal.nStartEpoch); - dacProposal.nMinPassing = 1; - dacProposal.nYesVotes = myGov->GetYesCount(VOTE_SIGNAL_FUNDING); - dacProposal.nNoVotes = myGov->GetNoCount(VOTE_SIGNAL_FUNDING); - dacProposal.nAbstainVotes = myGov->GetAbstainCount(VOTE_SIGNAL_FUNDING); - dacProposal.nNetYesVotes = myGov->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING); - dacProposal.nLastSuperblock = nLastSuperblock; - dacProposal.sProposalHRTime = TimestampToHRDate(dacProposal.nStartEpoch); - dacProposal.fPassing = dacProposal.nNetYesVotes >= nMinPassing; - dacProposal.fIsPaid = dacProposal.nHeight < nLastSuperblock; - return dacProposal; -} - -std::string DescribeProposal(DACProposal dacProposal) -{ - std::string sReport = "Proposal StartDate: " + dacProposal.sProposalHRTime + ", Hash: " + dacProposal.uHash.GetHex() + " for Amount: " + RoundToString(dacProposal.nAmount, 2) + "IMAGECOIN, Name: " - + dacProposal.sName + ", ExpType: " + dacProposal.sExpenseType + ", PAD: " + dacProposal.sAddress - + ", Height: " + RoundToString(dacProposal.nHeight, 0) - + ", Votes: " + RoundToString(dacProposal.nNetYesVotes, 0) + ", LastSB: " - + RoundToString(dacProposal.nLastSuperblock, 0); - return sReport; -} - -std::string GetCPIDElementByData(std::string sData, int iElement) -{ - std::vector vP = Split(sData.c_str(), "|"); - if (vP.size() < 10) - return std::string(); - return vP[iElement]; -} - From 8c631e1385f9cc848cdaf1511b767adc002b48d7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:34:33 -0400 Subject: [PATCH 0744/1324] Delete smartcontract-server.h --- src/smartcontract-server.h | 47 -------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/smartcontract-server.h diff --git a/src/smartcontract-server.h b/src/smartcontract-server.h deleted file mode 100644 index ab12b9c5..00000000 --- a/src/smartcontract-server.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2014-2019 The Dash Core Developers, The DAC Core Developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef SMARTCONTRACTSERVER_H -#define SMARTCONTRACTSERVER_H - -#include "wallet/wallet.h" -#include "hash.h" -#include "net.h" -#include "utilstrencodings.h" -#include "rpcpog.h" -#include - -class CWallet; - -std::string AssessBlocks(int nHeight, bool fCreating); -int GetLastGSCSuperblockHeight(int nCurrentHeight, int& nNextSuperblock); -std::string GetGSCContract(int nHeight, bool fCreating); -bool SubmitGSCTrigger(std::string sHex, std::string& gobjecthash, std::string& sError); -void GetGSCGovObjByHeight(int nHeight, uint256 uOptFilter, int& out_nVotes, uint256& out_uGovObjHash, std::string& out_PaymentAddresses, std::string& out_PaymentAmounts); -uint256 GetPAMHashByContract(std::string sContract); -uint256 GetPAMHash(std::string sAddresses, std::string sAmounts); -bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string& sError); -std::string ExecuteGenericSmartContractQuorumProcess(); -UniValue GetProminenceLevels(int nHeight, std::string sFilterName); -bool NickNameExists(std::string sProjectName, std::string sNickName); -int GetRequiredQuorumLevel(int nHeight); -void GetTransactionPoints(CBlockIndex* pindex, CTransactionRef tx, double& nCoinAge, CAmount& nDonation); -bool ChainSynced(CBlockIndex* pindex); -std::string WatchmanOnTheWall(bool fForce, std::string& sContract); -void GetGovObjDataByPamHash(int nHeight, uint256 hPamHash, std::string& out_Data); -DACProposal GetProposalByHash(uint256 govObj, int nLastSuperblock); -std::string DescribeProposal(DACProposal dacProposal); -std::string GetTxCPK(CTransactionRef tx, std::string& sCampaignName); -double CalculatePoints(std::string sCampaign, std::string sDiary, double nCoinAge, CAmount nDonation, std::string sCPK); -double GetChildBalance(std::string sChildID, std::string sCharity); -double GetProminenceCap(std::string sCampaignName, double nPoints, double nProminence); -std::string GetCPIDByCPK(std::string sCPK); -std::string GetCPIDElementByData(std::string sData, int iElement); -double GetRequiredCoinAgeForPODC(double nRAC, double nTeamID); -double GetCoinPrice(); -bool VerifyChild(std::string childID, std::string sCharity); -bool IsOverBudget(int nHeight, std::string sAmounts); -std::string CheckGSCHealth(); - -#endif From ff27fe07cf6ffb3ff6a3fb54cdb9f5ead574bdb9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:35:48 -0400 Subject: [PATCH 0745/1324] Update validation.cpp --- src/validation.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index d83492ec..17822dab 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -95,21 +95,8 @@ uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE; -std::map, std::pair> mvApplicationCache; - -std::map mvResearchers; - -int nProposalModulus = 0; -std::string msURL; -bool fProposalNeedsSubmitted= false; -int64_t nProposalStartTime = 0; -uint256 uTxIdFee = uint256S("0x0"); -int nProposalPrepareHeight = 0; - -std::string msProposalResult; -std::string msProposalHex; -std::atomic fDIP0001WasLockedIn{false}; std::atomic fDIP0001ActiveAtTip{false}; +std::atomic fDIP0003ActiveAtTip{false}; uint256 hashAssumeValid; From d7d79ce89b76716aa4944a315f519fb9ef0a7e12 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:36:13 -0400 Subject: [PATCH 0746/1324] Update validation.h --- src/validation.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/validation.h b/src/validation.h index 0698d4e1..083dfaf4 100644 --- a/src/validation.h +++ b/src/validation.h @@ -186,25 +186,10 @@ extern int64_t nMaxTipAge; extern bool fLargeWorkForkFound; extern bool fLargeWorkInvalidChainFound; -extern std::string msProposalHex; -extern std::string msURL; -extern int64_t nProposalStartTime; - -extern bool fProposalNeedsSubmitted; -extern int nProposalPrepareHeight; -extern int nProposalModulus; -extern uint256 uTxIdFee; -extern std::string msProposalResult; - extern std::map mapRejectedBlocks; -extern std::map, std::pair> mvApplicationCache; - extern std::atomic fDIP0001ActiveAtTip; -struct Researcher; -extern std::map mvResearchers; - /** Block hash whose ancestors we will assume to have valid scripts without checking them. */ extern uint256 hashAssumeValid; @@ -307,7 +292,6 @@ double ConvertBitsToDouble(unsigned int nBits); CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false); CAmount GetMasternodePayment(int nHeight, CAmount blockValue); CAmount GetDevelopersPayment(int nHeight, CAmount blockValue); -CAmount GetBlockSubsidy(int nHeight, CAmount blockValue); /** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex); From 46624b838c958bfbf94774ed802b7855a117fa2e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:36:26 -0400 Subject: [PATCH 0747/1324] Delete proposaladddialog.ui --- src/qt/forms/proposaladddialog.ui | 290 ------------------------------ 1 file changed, 290 deletions(-) delete mode 100644 src/qt/forms/proposaladddialog.ui diff --git a/src/qt/forms/proposaladddialog.ui b/src/qt/forms/proposaladddialog.ui deleted file mode 100644 index 1c2622c8..00000000 --- a/src/qt/forms/proposaladddialog.ui +++ /dev/null @@ -1,290 +0,0 @@ - - - ProposalAddDialog - - - - 0 - 0 - 827 - 438 - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - - - - - - - - - - - - Proposal Amount - - - Qt::ImhDigitsOnly - - - - - - - Enter Proposal Amount - - - &Proposal Amount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - txtAmount - - - - - - - Discussion URL - - - - - - - Discussion URL - - - &Discussion URL: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - txtURL - - - - - - - Enter Proposal Name - - - - - - - Add New Proposal - v1.1<br> - - - - - - - Enter Proposal Name - - - &Proposal Name: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - txtName - - - - - - - - - - 150 - 0 - - - - &Submit Proposal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - - Expense Type - - - Expense Type: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Address - - - Qt::ImhNone - - - QLineEdit::Normal - - - - - - - Receiving Address - - - Funding Receiving Address: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - Qt::Vertical - - - - 20 - 10 - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - 75 - true - - - - <html><head/><body><p align="center"><span style=" font-size:12pt; font-style:italic;">HTH Governance System</span></p></body></html> - - - - - - - - - - 15 - 75 - true - - - - ... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - txtName - txtAmount - txtURL - txtAddress - cmbExpenseType - btnSubmit - - - - - - From 5f4e33bd318a0b9f60e91e001ad6381244ef6ba1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:36:33 -0400 Subject: [PATCH 0748/1324] Delete proposals.ui --- src/qt/forms/proposals.ui | 47 --------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/qt/forms/proposals.ui diff --git a/src/qt/forms/proposals.ui b/src/qt/forms/proposals.ui deleted file mode 100644 index 60375aa6..00000000 --- a/src/qt/forms/proposals.ui +++ /dev/null @@ -1,47 +0,0 @@ - - - Proposals - - - - 0 - 0 - 710 - 410 - - - - - 0 - 0 - - - - Form - - - - - 9 - 0 - 700 - 400 - - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOn - - - - - - From 20ee90e5c0d3b8595c38fd775cf2dcfd487c6695 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:36:39 -0400 Subject: [PATCH 0749/1324] Delete secdialog.ui --- src/qt/forms/secdialog.ui | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/qt/forms/secdialog.ui diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui deleted file mode 100644 index bfdb967e..00000000 --- a/src/qt/forms/secdialog.ui +++ /dev/null @@ -1,35 +0,0 @@ - - - SecDialog - - - Qt::WindowModal - - - - 0 - 0 - 1010 - 639 - - - - Dialog - - - - - 420 - 610 - 75 - 23 - - - - Close - - - - - - From 6618c33caa26f4b4dbdc7da368dfa106ca9f79b9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:03 -0400 Subject: [PATCH 0750/1324] Delete proposaladddialog.cpp --- src/qt/proposaladddialog.cpp | 192 ----------------------------------- 1 file changed, 192 deletions(-) delete mode 100644 src/qt/proposaladddialog.cpp diff --git a/src/qt/proposaladddialog.cpp b/src/qt/proposaladddialog.cpp deleted file mode 100644 index 7a15610b..00000000 --- a/src/qt/proposaladddialog.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "proposaladddialog.h" -#include "ui_proposaladddialog.h" -#include "addressbookpage.h" -#include "addresstablemodel.h" -#include "bitcoinunits.h" -#include "guiutil.h" -#include "util.h" -#include "optionsmodel.h" -#include "timedata.h" -#include "platformstyle.h" -#include "receiverequestdialog.h" -#include "recentrequeststablemodel.h" -#include "governance.h" -#include "governance-vote.h" -#include "governance-classes.h" - -#include "walletmodel.h" -#include "validation.h" -#include "rpcpodc.h" -#include "rpcpog.h" -#include -#include -#include -#include -#include -#include - -ProposalAddDialog::ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent) : - QWidget(parent), - ui(new Ui::ProposalAddDialog), - model(0), - platformStyle(platformStyle) -{ - ui->setupUi(this); - QString theme = GUIUtil::getThemeName(); - - if (!platformStyle->getImagesOnButtons()) { - ui->btnSubmit->setIcon(QIcon()); - } else { - ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/about")); - } - - ui->cmbExpenseType->clear(); - ui->cmbExpenseType->addItem("IT"); - ui->cmbExpenseType->addItem("MKT"); - ui->cmbExpenseType->addItem("PR"); - ui->cmbExpenseType->addItem("P2P"); - - } - - -void ProposalAddDialog::UpdateDisplay() -{ - int nNextHeight = GetNextSuperblock(); - - std::string sInfo = "Note: Proposal Cost is 5 IMG. Next Superblock at height: " + RoundToString(nNextHeight, 0) + "
Warning: You must unlock the wallet before submitting the proposal."; - - if (fProposalNeedsSubmitted) - { - sInfo += "
NOTE: You have a proposal waiting to be submitted.
Status: " + msProposalResult; - } - else if (!msProposalResult.empty()) - { - sInfo = "
NOTE: Your last proposal has been submitted.
Status: " + msProposalResult; - } - - ui->txtInfo->setText(GUIUtil::TOQS(sInfo)); -} - - -void ProposalAddDialog::setModel(WalletModel *model) -{ - this->model = model; - - if(model && model->getOptionsModel()) - { - UpdateDisplay(); - } -} - -ProposalAddDialog::~ProposalAddDialog() -{ - delete ui; -} - -void ProposalAddDialog::clear() -{ - ui->txtName->setText(""); - ui->txtURL->setText(""); - ui->txtAmount->setText(""); - ui->txtAddress->setText(""); -} - - -void ProposalAddDialog::on_btnSubmit_clicked() -{ - if(!model || !model->getOptionsModel()) - return; - std::string sName = GUIUtil::FROMQS(ui->txtName->text()); - std::string sAddress = GUIUtil::FROMQS(ui->txtAddress->text()); - std::string sAmount = GUIUtil::FROMQS(ui->txtAmount->text()); - std::string sURL = GUIUtil::FROMQS(ui->txtURL->text()); - std::string sError; - if (sName.length() < 3) sError += "Proposal Name must be populated. "; - CBitcoinAddress address(sAddress); - if (!address.IsValid()) sError += "Proposal Funding Address is invalid. "; - if (cdbl(sAmount,0) < 100) sError += "Proposal Amount is too low. "; - if (sURL.length() < 10) sError += "You must enter a discussion URL. "; - std::string sExpenseType = GUIUtil::FROMQS(ui->cmbExpenseType->currentText()); - if (sExpenseType.empty()) sError += "Expense Type must be chosen. "; - CAmount nBalance = GetRPCBalance(); - - if (fProposalNeedsSubmitted) - { - sError += "There is a proposal already being submitted (" + msProposalResult + "). Please wait until this proposal is sent before creating a new one. "; - } - else - { - if (nBalance < (6*COIN)) sError += "Sorry balance too low to create proposal collateral. "; - } - - std::string sPrepareTxId; - std::string sHex; - int64_t unixStartTimestamp = GetAdjustedTime(); - int64_t unixEndTimestamp = GetAdjustedTime() + (60 * 60 * 24 * 30); - // Evo requires no spaces - sName = strReplace(sName, " ", "_"); - - if (sError.empty()) - { - // gobject prepare 0 1 EPOCH_TIME HEX - std::string sType = "1"; //Proposal - std::string sQ = "\""; - std::string sJson = "[[" + sQ + "proposal" + sQ + ",{"; - sJson += GJE("start_epoch", RoundToString(unixStartTimestamp, 0), true, false); - sJson += GJE("end_epoch", RoundToString(unixEndTimestamp, 0), true, false); - sJson += GJE("name", sName, true, true); - sJson += GJE("payment_address", sAddress, true, true); - sJson += GJE("payment_amount", sAmount, true, false); - sJson += GJE("type", sType, true, false); - sJson += GJE("expensetype", sExpenseType, true, true); - sJson += GJE("url", sURL, false, true); - sJson += "}]]"; - // make into hex - std::vector vchJson = std::vector(sJson.begin(), sJson.end()); - sHex = HexStr(vchJson.begin(), vchJson.end()); - // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS - uint256 hashParent = uint256(); - int nRevision = 1; - // CREATE A NEW COLLATERAL TRANSACTION FOR THIS SPECIFIC OBJECT - CGovernanceObject govobj(hashParent, nRevision, unixStartTimestamp, uint256(), sHex); - if((govobj.GetObjectType() == GOVERNANCE_OBJECT_TRIGGER) || (govobj.GetObjectType() == GOVERNANCE_OBJECT_WATCHDOG)) - { - sError = "Trigger and watchdog objects cannot be created from the UI yet."; - } - if (sError.empty()) - { - if(!govobj.IsValidLocally(sError, false)) - { - LogPrintf("Error while creating governance object %s, object not valid. Error: %s \n", sJson, sError); - sError += "Governance object is not valid - " + govobj.GetHash().ToString(); - } - - if (sError.empty()) - { - sPrepareTxId = CreateGovernanceCollateral(govobj.GetHash(), govobj.GetMinCollateralFee(), sError); - } - } - } - std::string sNarr = (sError.empty()) ? "Successfully Prepared Proposal " + sPrepareTxId + ". NOTE: You must wait 6 confirms for the proposal to be submitted. Please check back on this page periodically " - + " to ensure a successful transmission and that no error message is listed in the bottom area of the page. " - + "
WARNING: Do not shut down the core wallet until the proposal is submitted, otherwise you may lose your proposal submission and proposal collateral. " - +"

Thank you for using our Governance System." : sError; - if (sError.empty()) - { - // Set the proposal up to be submitted after 6 confirms using our Governance Service: - nProposalPrepareHeight = chainActive.Tip()->nHeight; - msProposalResult = "Submitting Proposal at height " + RoundToString(nProposalPrepareHeight + 6, 0) + "..."; - uTxIdFee = uint256S(sPrepareTxId); - nProposalStartTime = unixStartTimestamp; - msProposalHex = sHex; - fProposalNeedsSubmitted = true; - clear(); - } - QMessageBox::warning(this, tr("Proposal Add Result"), GUIUtil::TOQS(sNarr), QMessageBox::Ok, QMessageBox::Ok); - - UpdateDisplay(); -} From 9397709ce8bff480343f7ed0e79c1c2b46d4b55c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:12 -0400 Subject: [PATCH 0751/1324] Delete proposaladddialog.h --- src/qt/proposaladddialog.h | 66 -------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/qt/proposaladddialog.h diff --git a/src/qt/proposaladddialog.h b/src/qt/proposaladddialog.h deleted file mode 100644 index 56679642..00000000 --- a/src/qt/proposaladddialog.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_PROPOSALADDDIALOG_H -#define BITCOIN_QT_PROPOSALADDDIALOG_H - -#include "guiutil.h" - -#include -#include -#include -#include -#include -#include -#include - -class OptionsModel; -class PlatformStyle; -class WalletModel; - -namespace Ui { - class ProposalAddDialog; -} - -QT_BEGIN_NAMESPACE -class QModelIndex; -QT_END_NAMESPACE - -/** Dialog for Adding a Governance Proposal */ -class ProposalAddDialog : public QDialog -{ - Q_OBJECT - -public: - enum ColumnWidths { - DATE_COLUMN_WIDTH = 130, - LABEL_COLUMN_WIDTH = 120, - AMOUNT_MINIMUM_COLUMN_WIDTH = 160, - MINIMUM_COLUMN_WIDTH = 130 - }; - - explicit ProposalAddDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ProposalAddDialog(); - - void setModel(WalletModel *model); - void UpdateDisplay(); - -public Q_SLOTS: - void clear(); - -protected: - - -private: - Ui::ProposalAddDialog *ui; - GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; - WalletModel *model; - QMenu *contextMenu; - const PlatformStyle *platformStyle; - -private Q_SLOTS: - void on_btnSubmit_clicked(); -}; - -#endif // BITCOIN_QT_PROPOSALADDDIALOG_H From 301d04b5e3583d760700f377544ac5adc4329b6f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:19 -0400 Subject: [PATCH 0752/1324] Delete proposals.cpp --- src/qt/proposals.cpp | 273 ------------------------------------------- 1 file changed, 273 deletions(-) delete mode 100644 src/qt/proposals.cpp diff --git a/src/qt/proposals.cpp b/src/qt/proposals.cpp deleted file mode 100644 index c46c9fe1..00000000 --- a/src/qt/proposals.cpp +++ /dev/null @@ -1,273 +0,0 @@ -#include "proposals.h" -#include "bitcoinunits.h" -#include "ui_proposals.h" -#include "secdialog.h" -#include "ui_secdialog.h" -#include "walletmodel.h" -#include "guiutil.h" -#include "rpcpog.h" -#include -#include -#include -#include - - -QStringList Proposals::GetHeaders() -{ - QStringList pHeaders; - pHeaders << tr("Proposal ID") - << tr("Proposal Name") - << tr("Amount") - << tr("Expense Type") - << tr("Created") - << tr("Yes Ct") - << tr("No Ct") - << tr("Abstain Ct") - << tr("Url"); - return pHeaders; -} - -Proposals::Proposals(const PlatformStyle *platformStyle, QWidget *parent) : - ui(new Ui::Proposals) -{ - ui->setupUi(this); - - /* Reserved - Use when we add buttons to this page - QString theme = GUIUtil::getThemeName(); - - if (!platformStyle->getImagesOnButtons()) - { - ui->btnSubmit->setIcon(QIcon()); - } else { - ui->btnSubmit->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses")); - } - */ - UpdateDisplay(); -} - -/* Input String Format - 1,proposal name1,amount1,expensetype1,createtime1,yescount1,nocount1,abstaincount1,url1 -*/ - -Proposals::~Proposals() -{ - delete ui; -} - - -void Proposals::setModel(WalletModel *model) -{ - this->model = model; - - if(model && model->getOptionsModel()) - { - UpdateDisplay(); - } -} - - -void Proposals::UpdateDisplay() -{ - QString pString = GUIUtil::TOQS(GetActiveProposals()); - QStringList pHeaders = GetHeaders(); - this->createUI(pHeaders, pString); -} - - -void Proposals::createUI(const QStringList &headers, const QString &pStr) -{ - - ui->tableWidget->setShowGrid(true); - ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); - ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); - ui->tableWidget->horizontalHeader()->setStretchLastSection(true); - - QVector > pMatrix; - if (pStr == "") return; - - pMatrix = SplitData(pStr); - int rows = pMatrix.size(); - ui->tableWidget->setRowCount(rows); - int cols = pMatrix[0].size(); - if (cols > 9) cols = 9; //Limit to the URL column for now - ui->tableWidget->setColumnCount(cols); - ui->tableWidget->setHorizontalHeaderLabels(headers); - - QString s; - for(int i=0; itableWidget->setItem(i,j, new QTableWidgetItem(pMatrix[i][j])); - - ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->tableWidget->resizeRowsToContents(); - ui->tableWidget->resizeColumnsToContents(); - ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); - // Column 0 width should be slimmer - ui->tableWidget->setColumnWidth(0, 115); - ui->tableWidget->setColumnWidth(1, 150); - ui->tableWidget->setColumnWidth(2, 80); //Amount - ui->tableWidget->setColumnWidth(3, 80); //Expense Type - ui->tableWidget->setColumnWidth(4, 100); //Created Date - ui->tableWidget->setColumnWidth(5, 50); - - ui->tableWidget->setColumnWidth(6, 50); - ui->tableWidget->setColumnWidth(7, 65); - ui->tableWidget->setColumnWidth(8, 120); - - ui->tableWidget->sortByColumn(4, Qt::AscendingOrder); - - // Connect SLOT to context menu - connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotCustomMenuRequested(QPoint))); -} - -void Proposals::slotCustomMenuRequested(QPoint pos) -{ - /* Create an object context menu */ - QMenu * menu = new QMenu(this); - // Create, Connect and Set the actions to the menu - menu->addAction(tr("Vote For"), this, SLOT(slotVoteFor())); - menu->addAction(tr("Vote Against"), this, SLOT(slotVoteAgainst())); - menu->addAction(tr("Vote Abstain"), this, SLOT(slotAbstainCount())); - menu->addAction(tr("Chart Proposal"), this, SLOT(slotChartProposal())); - menu->addAction(tr("View Proposal"), this, SLOT(slotViewProposal())); - menu->popup(ui->tableWidget->viewport()->mapToGlobal(pos)); -} - - -void Proposals::ProcessVote(std::string gobject, std::string signal, std::string outcome) -{ - std::string sError = ""; - int nSuccessful = 0; - int nFailed = 0; - VoteManyForGobject(gobject, signal, outcome, 0, nSuccessful, nFailed, sError); - std::string sVoteNarr = ""; - if (nSuccessful > 0) - { - sVoteNarr = "Voting was successful. Voted " + RoundToString(nSuccessful, 0) + " times, failed to vote " + RoundToString(nFailed, 0) + " time(s). "; - if (!sError.empty()) sVoteNarr += " [" + sError + "]"; - } - else - { - sVoteNarr = "Voting Failed! Failed to vote " + RoundToString(nFailed, 0) + " time(s). "; - if (sError.empty()) sVoteNarr += " (Note: You must wait 3 minutes in-between re-votes due to network rules. Please ensure your wallet is unlocked also. )"; - if (!sError.empty()) sVoteNarr += " [" + sError + "]"; - } - QMessageBox msgOutcome; - msgOutcome.setWindowTitle(tr("Voting Outcome")); - msgOutcome.setText(GUIUtil::TOQS(sVoteNarr)); - msgOutcome.setStandardButtons(QMessageBox::Ok); - msgOutcome.setDefaultButton(QMessageBox::Ok); - msgOutcome.exec(); - - // Refresh - - QString pString = GUIUtil::TOQS(GetActiveProposals()); - QStringList pHeaders = GetHeaders(); - this->createUI(pHeaders, pString); -} - -void Proposals::slotVoteAgainst() -{ - int row = ui->tableWidget->selectionModel()->currentIndex().row(); - if(row >= 0) - { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Proposal")); - msgBox.setText("Vote Against the Proposal?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - if (QMessageBox::Yes == msgBox.exec()) - { - std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); - ProcessVote(gobject, "funding", "no"); - } - } -} - -void Proposals::slotVoteFor() -{ - int row = ui->tableWidget->selectionModel()->currentIndex().row(); - if(row >= 0) - { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Proposal")); - msgBox.setText("Vote For the Proposal ?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - if (QMessageBox::Yes == msgBox.exec()) - { - std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); - ProcessVote(gobject, "funding", "yes"); - } - } -} - -void Proposals::slotAbstainCount() -{ - int row = ui->tableWidget->selectionModel()->currentIndex().row(); - if(row >= 0) - { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Proposal")); - msgBox.setText("Do you want to Abstain from voting?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - if (QMessageBox::Yes == msgBox.exec()) - { - std::string gobject = GUIUtil::FROMQS(ui->tableWidget->item(row,0)->text()); - ProcessVote(gobject, "funding", "abstain"); - } - } -} - - -void Proposals::slotChartProposal() -{ - int row = ui->tableWidget->selectionModel()->currentIndex().row(); - if(row >= 0) - { - int voteFor = ui->tableWidget->item(row,5)->text().toInt(); - int voteAgainst = ui->tableWidget->item(row,6)->text().toInt(); - int abstainCount = ui->tableWidget->item(row,7)->text().toInt(); - // int total = voteFor + voteAgainst + abstainCount; - SecDialog *secdialog = new SecDialog(this); - secdialog->setGraphPts(voteFor, voteAgainst, abstainCount); - secdialog->setWindowTitle(" "); - secdialog->exec(); - - } -} - -void Proposals::slotViewProposal() -{ - int row = ui->tableWidget->selectionModel()->currentIndex().row(); - if(row >= 0) - { - QString Url = ui->tableWidget->item(row,8)->text(); - QUrl pUrl(Url); - QDesktopServices::openUrl(pUrl); - } -} - -QVector > Proposals::SplitData(const QString &pStr) -{ - QStringList proposals = pStr.split(QRegExp(""),QString::SkipEmptyParts); - int nProposals = proposals.size(); - QVector > proposalMatrix; - for (int i=0; i()); - QStringList proposalDetail = proposals[i].split('|'); - int detailSize = proposalDetail.size(); - for (int j = 0; j < detailSize; j++) - { - QString sData = proposalDetail[j]; - if (j==2) - { - sData = BitcoinUnits::format(2, cdbl(GUIUtil::FROMQS(sData), 2) * 100, false, BitcoinUnits::separatorAlways); - } - proposalMatrix[i].append(sData); - } - } - return proposalMatrix; -} From c3700db38fac34894070b4d3ddcbb51faa8da987 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:25 -0400 Subject: [PATCH 0753/1324] Delete proposals.h --- src/qt/proposals.h | 59 ---------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 src/qt/proposals.h diff --git a/src/qt/proposals.h b/src/qt/proposals.h deleted file mode 100644 index f1134f92..00000000 --- a/src/qt/proposals.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef PROPOSALS_H -#define PROPOSALS_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class OptionsModel; -class PlatformStyle; -class WalletModel; - - -namespace Ui { -class Proposals; -} - -QT_BEGIN_NAMESPACE -class QModelIndex; -QT_END_NAMESPACE - -class Proposals : public QWidget -{ - Q_OBJECT - -public: - explicit Proposals(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~Proposals(); - void setModel(WalletModel *model); - void UpdateDisplay(); - -private Q_SLOTS: - void slotVoteFor(); - void slotVoteAgainst(); - void slotAbstainCount(); - void slotChartProposal(); - void slotViewProposal(); - void slotCustomMenuRequested(QPoint pos); - -private: - Ui::Proposals *ui; - WalletModel *model; - -private: - void createUI(const QStringList &headers, const QString &pStr); - QVector > SplitData(const QString &pStr); - void ProcessVote(std::string gobject, std::string signal, std::string outcome); - QStringList GetHeaders(); - - -}; - -#endif // PROPOSALS_H From 7b5752adaa4a927a72684e33157ff4eaf680e7e2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:37 -0400 Subject: [PATCH 0754/1324] Delete secdialog.cpp --- src/qt/secdialog.cpp | 90 -------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 src/qt/secdialog.cpp diff --git a/src/qt/secdialog.cpp b/src/qt/secdialog.cpp deleted file mode 100644 index ff798bee..00000000 --- a/src/qt/secdialog.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "secdialog.h" -#include "ui_secdialog.h" -#include "rpcpog.h" -#include "guiutil.h" - -SecDialog::SecDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::SecDialog) -{ - ui->setupUi(this); -} - -void SecDialog::closeForm() -{ - this->close(); -} - -void SecDialog::getGraphPts(int &voteFor, int &voteAgainst, int &abstainCount) -{ - voteFor = this->forCount; - voteAgainst = this->againstCount; - abstainCount = this->absCount; -} - -void SecDialog::setGraphPts(int voteFor, int voteAgainst, int abstainCount) -{ - this->forCount = voteFor; - this->againstCount = voteAgainst; - this->absCount = abstainCount; -} - -SecDialog::~SecDialog() -{ - delete ui; -} - -void SecDialog::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - - QRectF rec(this->width() * 2/5, 10, this->width()/5, this->height()/30); - painter.drawRect(rec); - painter.drawText(rec, Qt::AlignCenter, "Voting Results"); - - QRectF size = QRectF(this->width()/5, this->width()/5, this->width()/4, this->width()/4); - int voteFor, voteAgainst, abstainCount; - getGraphPts(voteFor, voteAgainst, abstainCount); - int total = voteFor + voteAgainst + abstainCount; - connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(close())); - - if (total <= 0) return; - - int forSlice = qRound(360 * (double)voteFor/(double)total); - - int againstSlice = qRound(360 * (double)voteAgainst/(double)total); - - int abstainSlice = qRound(360 * (double)abstainCount/(double)total); - - painter.setBrush(Qt::darkGreen); - painter.drawPie(size, 0, forSlice*16); - - painter.setBrush(Qt::red); - painter.drawPie(size, forSlice*16, againstSlice*16); - - painter.setBrush(Qt::gray); - painter.drawPie(size, (forSlice+againstSlice)*16, abstainSlice*16); - - QTextDocument doc; - QRect legend (0, 0, this->width()/3, this->width()/3); - painter.translate(this->width()*3/5, this->width()/3.5); - doc.setTextWidth(legend.width()); - std::string s = ""; - if (voteFor) - { - s = "
Vote For Count: " - + RoundToString(100*(double)voteFor/(double)total, 2) + "%
"; - } - if (voteAgainst) - { - s += "
Vote Against Count: " - + RoundToString(100*(double)voteAgainst/(double)total, 2) + "%
"; - } - if (abstainCount) - { - s += "
Abstain Count: " - + RoundToString(100*(double)abstainCount/(double)total, 2) + "%
"; - } - doc.setHtml(GUIUtil::TOQS(s)); - doc.drawContents(&painter, legend); -} From 8459f2f5623eae78a497a08891373e0a4e7bd623 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:37:44 -0400 Subject: [PATCH 0755/1324] Delete secdialog.h --- src/qt/secdialog.h | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/qt/secdialog.h diff --git a/src/qt/secdialog.h b/src/qt/secdialog.h deleted file mode 100644 index 6b415ab3..00000000 --- a/src/qt/secdialog.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SECDIALOG_H - -#define SECDIALOG_H - -#include -#include -#include -#include - -namespace Ui { -class SecDialog; -} - -class SecDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SecDialog(QWidget *parent = 0); - void getGraphPts(int &voteFor, int &voteAgainst, int &abstainCount); - void setGraphPts(int voteFor=0, int voteAgainst=0, int abstainCount=0); - ~SecDialog(); - -protected: - void paintEvent(QPaintEvent *); - void closeForm(); - -private: - Ui::SecDialog *ui; - int forCount, againstCount, absCount; - -}; - -#endif // SECDIALOG_H From 7441b618074975590aa712e829cf0e7baa371b6d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:41:36 -0400 Subject: [PATCH 0756/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 51 ++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 3d865189..597e3018 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,6 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "proposaladddialog.h" /* #include "tradingdialogpage.h" */ @@ -141,9 +140,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * modalOverlay(0), prevBlocks(0), spinnerFrame(0), - proposalsListAction(0), - proposalAddAction(0), externalDonate(0), + governanceAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -484,21 +482,21 @@ void BitcoinGUI::createActions() connect(masternodeAction, SIGNAL(triggered()), this, SLOT(gotoMasternodePage())); } - /* { - proposalAction = new QAction(QIcon(":/icons/about"), tr("&Proposal"), this); - proposalAction->setStatusTip(tr("Submit A Proposal")); - proposalAction->setToolTip(proposalAction->statusTip()); - proposalAction->setCheckable(true); + { + governanceAction = new QAction(QIcon(":/icons/about"), tr("&Proposal"), this); + governanceAction->setStatusTip(tr("Submit A Proposal")); + governanceAction->setToolTip(governanceAction->statusTip()); + governanceAction->setCheckable(true); #ifdef Q_OS_MAC - proposalAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); + governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); #else - proposalAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); + governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); #endif - tabGroup->addAction(proposalAction); - connect(proposalAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(proposalAction, SIGNAL(triggered()), this, SLOT(gotoProposalAddDialog())); + tabGroup->addAction(governanceAction); + connect(governanceAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); - } */ + } /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -713,9 +711,9 @@ void BitcoinGUI::createMenuBar() tools->addAction(openConfEditorAction); tools->addAction(showBackupsAction); - QMenu *proposal = appMenuBar->addMenu(tr("&Proposals")); - proposal->addAction(proposalsListAction); - proposal->addAction(proposalAddAction); + QMenu *governance = appMenuBar->addMenu(tr("&Proposals")); + governance->addAction(governanceAction); + } @@ -750,8 +748,8 @@ void BitcoinGUI::createToolBars() { toolbar->addAction(masternodeAction); } - /* toolbar->addAction(governanceAction); - toolbar->addAction(unlockWalletAction); */ + toolbar->addAction(governanceAction); + toolbar->addAction(unlockWalletAction); toolbar->addAction(unlockWalletAction); @@ -906,8 +904,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } - proposalsListAction->setEnabled(enabled); - proposalAddAction->setEnabled(enabled); + governanceAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); changePassphraseAction->setEnabled(enabled); @@ -1057,16 +1054,10 @@ void BitcoinGUI::openClicked() } -void BitcoinGUI::gotoProposalsListPage() -{ - //WebWindowAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalsListPage(); -} - -void BitcoinGUI::gotoProposalAddPage() +void BitcoinGUI::gotoGovernancePage() { - //WebWindowAction->setChecked(true); - if (walletFrame) walletFrame->gotoProposalAddPage(); + governanceAction->setChecked(true); + if (walletFrame) walletFrame->gotoGovernancePage(); } void BitcoinGUI::openDonate() From 70f09c48028e39ff57135b52cecab92771741954 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:44:09 -0400 Subject: [PATCH 0757/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 0aa700e8..a1817f84 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -10,7 +10,7 @@ #endif #include "amount.h" -/*#include "proposals.h" */ +#include "governancelist.h" #include #include @@ -105,8 +105,7 @@ class BitcoinGUI : public QMainWindow QAction* externalDonate; - QAction *proposalsListAction; - QAction *proposalAddAction; + QAction *governanceAction; /* QAction* privatesendAction; */ QAction *overviewAction; QAction *historyAction; @@ -232,17 +231,11 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to ProposalsList page */ - void gotoProposalsListPage(); - - /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + /** Switch to masternode page */ + void gotoGovernancePage(); /** Switch to trading page */ - /* void gotoTradingDialogPage(); */ - - /** Switch to governance page */ - /* void gotoGovernancePage(); */ + /* void gotoTradingDialogPage(); */ /** Switch to private send page */ /* void gotoPrivateSendPage(); */ From a7414e035915dab43e38f27ab5ed8b3cc9e8950f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:44:52 -0400 Subject: [PATCH 0758/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index cfeec6e0..6783019e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,19 +108,11 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoProposalAddPage() +void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalAddPage(); -} - - -void WalletFrame::gotoProposalsListPage() -{ - QMap::const_iterator i; - for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoProposalsListPage(); + i.value()->gotoGovernancePage(); } void WalletFrame::gotoPrivateSendPage() From 156723bf93cce1ce747ca12595d86bfe7a6a0eb1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:45:29 -0400 Subject: [PATCH 0759/1324] Update walletframe.h --- src/qt/walletframe.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 6c022375..dbb28330 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,11 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to ProposalsList page */ - void gotoProposalsListPage(); - - /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); + /** Switch to governance page */ + void gotoGovernancePage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 67337fb214ef55f794fb468d11ed67488c9a73f1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:47:06 -0400 Subject: [PATCH 0760/1324] Update walletview.cpp --- src/qt/walletview.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 6a9b80bc..4c8925d4 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,8 +21,6 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "proposaladddialog.h" -#include "proposals.h" #include "ui_interface.h" @@ -76,8 +74,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - proposalsPage = new Proposals(platformStyle); - proposalAddPage = new ProposalAddDialog(platformStyle); + governanceListPage = new GovernanceList(platformStyle); + addWidget(governanceListPage); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); @@ -87,10 +85,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); - addWidget(proposalsPage); - addWidget(proposalAddPage); - + addWidget(privateSendPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -158,6 +153,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) overviewPage->setClientModel(_clientModel); privateSendPage->setClientModel(_clientModel); sendCoinsPage->setClientModel(_clientModel); + governanceListPage->setClientModel(_clientModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); @@ -173,6 +169,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) transactionView->setModel(_walletModel); overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); + governanceListPage->setWalletModel(_walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); @@ -238,14 +235,10 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoProposalsListPage() +void WalletView::gotoGovernancePage() { - setCurrentWidget(proposalsPage); -} - -void WalletView::gotoProposalAddPage() -{ - setCurrentWidget(proposalAddPage); + QSettings settings; + setCurrentWidget(governanceListPage); } void WalletView::gotoPrivateSendPage() From cf604fc30a1ce99d5d363b2acb266b26e1863977 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 21:59:17 -0400 Subject: [PATCH 0761/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 597e3018..6c471a48 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -561,11 +561,6 @@ void BitcoinGUI::createActions() verifyMessageAction = new QAction(QIcon(":/icons/" + theme + "/transaction_0"), tr("&Verify message..."), this); verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified HelpTheHomeless addresses")); - proposalAddAction = new QAction(QIcon(":/icons/" + theme + "/filesave"), tr("Add Proposal"), this); - proposalAddAction->setStatusTip(tr("Submit proposal")); - proposalsListAction = new QAction(QIcon(":/icons/" + theme + "/edit"), tr("&List Proposals"), this); - proposalsListAction->setStatusTip(tr("List all Proposal of Governance System")); - openInfoAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&Information"), this); openInfoAction->setStatusTip(tr("Show diagnostic information")); openRPCConsoleAction = new QAction(QIcon(":/icons/" + theme + "/debugwindow"), tr("&Debug console"), this); @@ -1623,43 +1618,6 @@ void BitcoinGUI::detectShutdown() } } - -// Governance - Check to see if we should submit a proposal - nProposalModulus++; - if (nProposalModulus % 15 == 0 && !fLoadingIndex) - { - nProposalModulus = 0; - if (!msURL.empty()) - { - QString qNav = GUIUtil::TOQS(msURL); - msURL = std::string(); - QDesktopServices::openUrl(QUrl(qNav)); - } - if (fProposalNeedsSubmitted) - { - nProposalModulus = 0; - if(masternodeSync.IsSynced() && chainActive.Tip() && chainActive.Tip()->nHeight > (nProposalPrepareHeight + 6)) - { - fProposalNeedsSubmitted = false; - std::string sError; - std::string sGovObj; - bool fSubmitted = SubmitProposalToNetwork(uTxIdFee, nProposalStartTime, msProposalHex, sError, sGovObj); - if (!sError.empty()) - { - LogPrintf("Proposal Submission Problem: %s ", sError); - } - msProposalResult = fSubmitted ? "Submitted Proposal Successfully
( " + sGovObj + " )" : sError; - LogPrintf(" Proposal Submission Result: %s \n", msProposalResult.c_str()); - } - else - { - msProposalResult = "Waiting for block " + RoundToString(nProposalPrepareHeight + 6, 0) + " to submit pending proposal. "; - } - } - } -} - - void BitcoinGUI::showProgress(const QString &title, int nProgress) { if (nProgress == 0) From 8a9d486520253a2a66a95b313027fbef6141950c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:01:33 -0400 Subject: [PATCH 0762/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6c471a48..7ba2ebe6 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -602,10 +602,7 @@ void BitcoinGUI::createActions() // HTHW Donate externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - - connect(proposalAddAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalAddPage())); - connect(proposalsListAction, SIGNAL(triggered()), walletFrame, SLOT(gotoProposalsListPage())); - + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); From 00e222e28fe23cdf4d411c73bfc75bf9389dac26 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:03:19 -0400 Subject: [PATCH 0763/1324] Update walletview.h --- src/qt/walletview.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index cb5813ab..d72e2923 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -7,8 +7,7 @@ #include "amount.h" #include "masternodelist.h" -/*#include "governancelist.h" */ -#include "proposaladddialog.h" +#include "governancelist.h" #include From 7b2c9d9ba1db00c3bad3bef42818b043da6bfac3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:05:27 -0400 Subject: [PATCH 0764/1324] Update walletview.h --- src/qt/walletview.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index d72e2923..2fd154af 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -23,8 +23,7 @@ class TransactionView; class WalletModel; class AddressBookPage; class PrivateSendPage; -class ProposalAddDialog; -class Proposals; +class GovernancePage; From a39f61f117af30cf43d8790556d15443c97d5f3e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:06:45 -0400 Subject: [PATCH 0765/1324] Update walletview.h --- src/qt/walletview.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 2fd154af..56483b23 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -73,8 +73,7 @@ class WalletView : public QStackedWidget AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; - ProposalAddDialog *proposalAddPage; - Proposals *proposalsPage; + GovernanceList *governanceListPage; TransactionView *transactionView; @@ -83,13 +82,9 @@ class WalletView : public QStackedWidget const PlatformStyle *platformStyle; public Q_SLOTS: - - /** Switch to ProposalsList page */ - void gotoProposalsListPage(); - - /** Switch to ProposalAdd page */ - void gotoProposalAddPage(); - + + /** Switch to governance page */ + void gotoGovernancePage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 8a2964773f2d792cd9fb2c71f98b38fafc239d21 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:07:36 -0400 Subject: [PATCH 0766/1324] Update walletview.cpp --- src/qt/walletview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 4c8925d4..cba3948d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -174,8 +174,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } - proposalsPage->setModel(walletModel); - proposalAddPage->setModel(walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); usedReceivingAddressesPage->setModel(_walletModel->getAddressTableModel()); From 183c954b550b7774687ffe83a51ce532efa657bb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:30:03 -0400 Subject: [PATCH 0767/1324] Add files via upload --- src/qt/forms/adminwindow.ui | 71 +++++ src/qt/forms/form.ui | 21 ++ src/qt/forms/homepage.ui | 188 +++++++++++++ src/qt/forms/mainwindow.ui | 547 ++++++++++++++++++++++++++++++++++++ src/qt/forms/newaccount.ui | 195 +++++++++++++ src/qt/forms/profilepage.ui | 271 ++++++++++++++++++ 6 files changed, 1293 insertions(+) create mode 100644 src/qt/forms/adminwindow.ui create mode 100644 src/qt/forms/form.ui create mode 100644 src/qt/forms/homepage.ui create mode 100644 src/qt/forms/mainwindow.ui create mode 100644 src/qt/forms/newaccount.ui create mode 100644 src/qt/forms/profilepage.ui diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui new file mode 100644 index 00000000..4eb710bd --- /dev/null +++ b/src/qt/forms/adminwindow.ui @@ -0,0 +1,71 @@ + + + AdminWindow + + + + 0 + 0 + 800 + 550 + + + + MainWindow + + + + + + + true + + + + + 0 + 0 + 776 + 440 + + + + + + + + + + + + + + Show Statistics + + + + + + + + + 0 + 0 + 800 + 26 + + + + + + + + QCustomPlot + QWidget +
qcustomplot.h
+ 1 +
+
+ + +
diff --git a/src/qt/forms/form.ui b/src/qt/forms/form.ui new file mode 100644 index 00000000..55b96fdf --- /dev/null +++ b/src/qt/forms/form.ui @@ -0,0 +1,21 @@ + + + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui new file mode 100644 index 00000000..0d3cdb97 --- /dev/null +++ b/src/qt/forms/homepage.ui @@ -0,0 +1,188 @@ + + + HomePage + + + + 0 + 0 + 1102 + 761 + + + + MainWindow + + + + + + + + + + + + + + + + 400 + 16777215 + + + + + + + + + + + View Profile + + + + + + + View Network Staristics Window + + + + + + + + + + + + 16777215 + 100 + + + + 1 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + What's On Your Mind ?! + + + + + + + Post + + + + + + + + + + + + + + + true + + + + + 0 + 0 + 1045 + 335 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + 0 + 0 + 1102 + 26 + + + + + File + + + + + + + + + + Log Out + + + + + + diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui new file mode 100644 index 00000000..f9070099 --- /dev/null +++ b/src/qt/forms/mainwindow.ui @@ -0,0 +1,547 @@ + + + MainWindow + + + + 0 + 0 + 464 + 319 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 106 + 100 + 92 + + + + + + + 255 + 255 + 255 + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + MainWindow + + + + + + + + + + + No account? Create one! + + + + + + + PointingHandCursor + + + Sign Up + + + + + + + + + + + + + + + + 10 + 75 + true + + + + Email + + + + + + + + 10 + 75 + true + + + + Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + PointingHandCursor + + + Log In + + + + + + + + + + + + + 0 + 0 + 464 + 26 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui new file mode 100644 index 00000000..c00afa77 --- /dev/null +++ b/src/qt/forms/newaccount.ui @@ -0,0 +1,195 @@ + + + newAccount + + + + 0 + 0 + 532 + 312 + + + + MainWindow + + + + + + + + + + + + Times New Roman + 16 + 75 + true + + + + if you already have an account ---> + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign In + + + + + + + + + + + + + + + + Times New Roman + 14 + 75 + true + + + + userName + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + Email + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + password + + + lineEdit_2 + + + + + + + + Times New Roman + 14 + 75 + true + + + + confirm password + + + lineEdit_3 + + + + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + QLineEdit::Password + + + + + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign Up + + + + + + + + + + + + + 0 + 0 + 532 + 26 + + + + + + + + diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui new file mode 100644 index 00000000..8114320a --- /dev/null +++ b/src/qt/forms/profilepage.ui @@ -0,0 +1,271 @@ + + + ProfilePage + + + + 0 + 0 + 1008 + 596 + + + + MainWindow + + + + + + + + + + + + Arial + 15 + 75 + true + + + + User name label Area + + + + + + + Add as a friend + + + + + + + + + + + + Arial + 9 + 75 + true + + + + Home + + + + + + + + Arial + 9 + 75 + true + + + + Friends + + + 8 + + + + Friends + + + + + + + + + + + + + Arial + 12 + 75 + true + + + + INFO + + + + + + + + + + + + + Arial + 9 + + + + Email + + + + + + + lblMail + + + + + + + + + + + + Arial + 9 + + + + Number of friends + + + + + + + labelNumber + + + + + + + + + + + border-color:blue; + + + + true + + + + + 0 + 0 + 982 + 349 + + + + + + + + 16777215 + 100 + + + + + + + What's on your mind? + + + + + + + + Arial + 9 + 75 + true + + + + false + + + background-color: rgb(85, 0, 255); +color:white; +selection-color: rgb(255, 255, 255); + + + Post + + + + + + + true + + + + + 0 + 0 + 958 + 183 + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1008 + 26 + + + + + File + + + + + + + + + + Log out + + + + + + From d4282f472a97aed246e35060d65f14ed5c14b877 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:31:38 -0400 Subject: [PATCH 0768/1324] Add files via upload --- src/qt/Activity.cpp | 48 + src/qt/Activity.h | 38 + src/qt/addcomment.cpp | 26 + src/qt/addcomment.h | 33 + src/qt/adminwindow.cpp | 94 + src/qt/adminwindow.h | 26 + src/qt/comment.cpp | 46 + src/qt/comment.h | 36 + src/qt/fileman.cpp | 756 + src/qt/fileman.h | 48 + src/qt/form.cpp | 14 + src/qt/form.h | 22 + src/qt/homepage.cpp | 441 + src/qt/homepage.h | 84 + src/qt/main.cpp | 12 + src/qt/mainwindow.cpp | 44 + src/qt/mainwindow.h | 27 + src/qt/myresources.qrc | 6 + src/qt/newaccount.cpp | 55 + src/qt/newaccount.h | 36 + src/qt/posts.cpp | 112 + src/qt/posts.h | 179 + src/qt/profilepage.cpp | 314 + src/qt/profilepage.h | 61 + src/qt/qcustomplot.cpp | 30121 +++++++++++++++++++++++++++++++++++++++ src/qt/qcustomplot.h | 6662 +++++++++ src/qt/statistics.cpp | 46 + src/qt/statistics.h | 37 + src/qt/user.cpp | 35 + src/qt/user.h | 26 + 30 files changed, 39485 insertions(+) create mode 100644 src/qt/Activity.cpp create mode 100644 src/qt/Activity.h create mode 100644 src/qt/addcomment.cpp create mode 100644 src/qt/addcomment.h create mode 100644 src/qt/adminwindow.cpp create mode 100644 src/qt/adminwindow.h create mode 100644 src/qt/comment.cpp create mode 100644 src/qt/comment.h create mode 100644 src/qt/fileman.cpp create mode 100644 src/qt/fileman.h create mode 100644 src/qt/form.cpp create mode 100644 src/qt/form.h create mode 100644 src/qt/homepage.cpp create mode 100644 src/qt/homepage.h create mode 100644 src/qt/main.cpp create mode 100644 src/qt/mainwindow.cpp create mode 100644 src/qt/mainwindow.h create mode 100644 src/qt/myresources.qrc create mode 100644 src/qt/newaccount.cpp create mode 100644 src/qt/newaccount.h create mode 100644 src/qt/posts.cpp create mode 100644 src/qt/posts.h create mode 100644 src/qt/profilepage.cpp create mode 100644 src/qt/profilepage.h create mode 100644 src/qt/qcustomplot.cpp create mode 100644 src/qt/qcustomplot.h create mode 100644 src/qt/statistics.cpp create mode 100644 src/qt/statistics.h create mode 100644 src/qt/user.cpp create mode 100644 src/qt/user.h diff --git a/src/qt/Activity.cpp b/src/qt/Activity.cpp new file mode 100644 index 00000000..eb388cc8 --- /dev/null +++ b/src/qt/Activity.cpp @@ -0,0 +1,48 @@ +#include "Activity.h" +#include +#include "posts.h" +#include"vector" + + +Activity::Activity() +{ + likesNumbers = 0; + postsNumber = 0; +} + +Activity::~Activity() +{ + +} +unsigned int Activity::getFriendsNumbers() + + {return friends.size();} + +unsigned int Activity::getPostsNumbers() + +{ return postsNumber;} + +void Activity::addFriend(QString friendName) +{ + friends.push_back(friendName); +} + +void Activity::addPost() +{ + postsNumber++; +} + +unsigned int Activity::getLikesNumbers() +{ + return likesNumbers; +} + +void Activity:: addLike() +{ + likesNumbers++; +} + +QList *Activity::getFriendsList_Ptr() +{ + return &friends; +} diff --git a/src/qt/Activity.h b/src/qt/Activity.h new file mode 100644 index 00000000..24896d27 --- /dev/null +++ b/src/qt/Activity.h @@ -0,0 +1,38 @@ +#ifndef ACTIVITY_H +#define ACTIVITY_H +#include +#include +#include "vector" +#include "posts.h" +#include "QList" +class Activity +{ + unsigned int likesNumbers; + + unsigned int postsNumber; + + QList friends; + + +public: + + Activity(); + + ~Activity(); + + unsigned int getLikesNumbers(); + + unsigned int getFriendsNumbers(); + + unsigned int getPostsNumbers(); + + void addLike(); + + void addFriend(QString); + + void addPost(); + + QList *getFriendsList_Ptr(); +}; + +#endif // ACTIVITY_H diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp new file mode 100644 index 00000000..fde45cd1 --- /dev/null +++ b/src/qt/addcomment.cpp @@ -0,0 +1,26 @@ +#include "addcomment.h" +#include "ui_addcomment.h" + +AddComment::AddComment(QWidget *parent) : + QDialog(parent), + ui(new Ui::AddComment) +{ + ui->setupUi(this); + commentBody = ""; + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +} + +AddComment::~AddComment() +{ + delete ui; +} + +void AddComment::on_AddComment_accepted() +{ + commentBody = ui->plainTextEdit->toPlainText(); +} + +QString AddComment::getCommentBody() +{ + return commentBody; +} diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h new file mode 100644 index 00000000..bb61bc05 --- /dev/null +++ b/src/qt/addcomment.h @@ -0,0 +1,33 @@ +#ifndef ADDCOMMENT_H +#define ADDCOMMENT_H + +#include + +namespace Ui { +class AddComment; +} + +class AddComment : public QDialog +{ + Q_OBJECT + +public: + explicit AddComment(QWidget *parent = 0); + + ~AddComment(); + +public slots: + QString getCommentBody(); + + +private slots: + void on_AddComment_accepted(); + + +private: + Ui::AddComment *ui; + + QString commentBody; +}; + +#endif // ADDCOMMENT_H diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp new file mode 100644 index 00000000..4d6b37a6 --- /dev/null +++ b/src/qt/adminwindow.cpp @@ -0,0 +1,94 @@ +#include "adminwindow.h" +#include "ui_adminwindow.h" +#include "statistics.h" +#include "fileman.h" +AdminWindow::AdminWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::AdminWindow) +{ + ui->setupUi(this); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); + +} + +AdminWindow::~AdminWindow() +{ + delete ui; +} + + +void AdminWindow:: makePlot(QVector *plotData) +{ + ui->customPlot->clearGraphs(); + ui->customPlot->legend->setVisible(true); + ui->customPlot->legend->setFont(QFont("Helvetica", 9)); + QPen pen; + QStringList lineNames; + lineNames << "Friends Number" << "Likes Number" << "Posts Number"; + // add graphs with different line styles: + for (int i = 0; i < 3; ++i) + { + ui->customPlot->addGraph(); + if(i == 0) + pen.setColor(QColor(0x02, 0xa0, 0xc3)); + else if(i == 1) + pen.setColor(QColor(0xef, 0xef, 0x00)); + else + pen.setColor(QColor(0xef, 0x2b, 0x90)); + ui->customPlot->graph()->setPen(pen); + ui->customPlot->graph()->setName(lineNames.at(i)); + ui->customPlot->graph()->setLineStyle((QCPGraph::lsLine)); + ui->customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); + // generate data: + QVector x((*plotData).size()), y(1000); + for (int j = 0; j < (*plotData).size(); ++j) + { + x[j] = (*plotData)[j].getUserID(); + if(i == 0) + y[j] = (*plotData)[j].getFriendsNumber(); + else if(i == 1) + y[j] = (*plotData)[j].getLikesNumber(); + else + y[j] = (*plotData)[j].getPostsNumber(); + } + ui->customPlot->graph()->setData(x, y); + ui->customPlot->graph()->rescaleAxes(true); + } + // zoom out a bit: + ui->customPlot->yAxis->scaleRange(0, plotData->size()+1); + ui->customPlot->xAxis->scaleRange(0, 1000); + // set blank axis lines: + ui->customPlot->xAxis->setTicks(true); + ui->customPlot->yAxis->setTicks(true); + ui->customPlot->xAxis->setTickLabels(true); + ui->customPlot->yAxis->setTickLabels(true); + ui->customPlot->xAxis2->setVisible(true); + ui->customPlot->yAxis2->setVisible(true); + ui->customPlot->xAxis2->setTicks(false); + ui->customPlot->yAxis2->setTicks(false); + // make top right axes clones of bottom left axes: +// ui->customPlot->axisRect()->setupFullAxesBox(); + ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); + ui->customPlot->replot(); + + +} +void AdminWindow::on_showStatistics_clicked() +{ + QVector *testingData = new QVector; + fileman network; + QList emails = network.readEmails(); + testingData->resize(emails.size()); + for(int i = 0; i < emails.size(); i++) + { + (*testingData)[i].setUserID(i); + (*testingData)[i].setFriendsNumber(network.getFriends(emails[i]).size() / 3); + int likesNumber,postsNumber; + network.getActivity(emails[i],postsNumber,likesNumber); + (*testingData)[i].setPostsNumber(network.getPosts(emails[i])->size()); + (*testingData)[i].setLikesNumber(likesNumber); + } + makePlot(testingData); +} diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h new file mode 100644 index 00000000..308af0fe --- /dev/null +++ b/src/qt/adminwindow.h @@ -0,0 +1,26 @@ +#ifndef ADMINWINDOW_H +#define ADMINWINDOW_H + +#include +#include "statistics.h" +namespace Ui { +class AdminWindow; +} + +class AdminWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit AdminWindow(QWidget *parent = 0); + ~AdminWindow(); + +private slots: + void on_showStatistics_clicked(); + + void makePlot(QVector *plotData); +private: + Ui::AdminWindow *ui; +}; + +#endif // ADMINWINDOW_H diff --git a/src/qt/comment.cpp b/src/qt/comment.cpp new file mode 100644 index 00000000..09328393 --- /dev/null +++ b/src/qt/comment.cpp @@ -0,0 +1,46 @@ +#include "comment.h" + +Comment::Comment() +{ + commentOwner = ""; + commentText = ""; +} + +Comment::Comment(QString owner, QString text, QString creationDate) +{ + + commentOwner = owner; + commentText = text; + commentDate = creationDate; +} + +void Comment::setCommentOwner(QString owner) +{ + commentOwner = owner; +} + +QString Comment::getCommentOwner() +{ + return commentOwner; +} + +void Comment::setCommentText(QString text) +{ + commentText = text; +} + +QString Comment::getCommentText() +{ + return commentText; +} + +void Comment::setCommentDate(QString creationDate) +{ + commentDate = creationDate; +} + +QString Comment::getCommentDate() +{ + return commentDate; +} + diff --git a/src/qt/comment.h b/src/qt/comment.h new file mode 100644 index 00000000..9a54b7c9 --- /dev/null +++ b/src/qt/comment.h @@ -0,0 +1,36 @@ +#ifndef COMMENT_H +#define COMMENT_H + +#include "QString" +#include "QDate" +#include "QTime" +class Date : public QDate +{ + QTime timeIsNow; +public: + QString getDateNow(){return this->currentDate().toString("yyyy.MM.dd") +" @ " +timeIsNow.currentTime().toString("HH:mm:ss");} +}; +class Comment +{ + QString commentOwner; + QString commentText; + QString commentDate; +public: + Comment(); + + Comment(QString, QString, QString); + + void setCommentOwner(QString); + + QString getCommentOwner(); + + void setCommentText(QString); + + QString getCommentText(); + + void setCommentDate(QString); + + QString getCommentDate(); +}; + +#endif // COMMENT_H diff --git a/src/qt/fileman.cpp b/src/qt/fileman.cpp new file mode 100644 index 00000000..cab9aee7 --- /dev/null +++ b/src/qt/fileman.cpp @@ -0,0 +1,756 @@ +#include "fileman.h" +#include + +int numberOfUsers=0; +QList emailss; +fileman::fileman() +{ + //name=username; + path=""; + +} +void fileman:: TESTTEST() +{ + QString line; + QFile in(path+name); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YOMNA SAN"; + QTextStream innn(&in); + line=innn.readLine(); + qDebug()<") + { + + line=innn.readLine(); + if(line==Date){ + line=innn.readLine(); + while(line!=NULL){ + + if(line==""){ + line=innn.readLine(); + while(line!="") + { + // cout<* fileman:: getPosts(QString email){ + QString line; + QFile in(path+"Users/"+email+".xml"); + QTextStream innn(&in); + QList *posts = new QList ; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + //bool begin_tag = false; + line=innn.readLine(); + while (line!=NULL) + { + + if(line==""){ + temp=""; + line=innn.readLine(); + while(!(line=="") ) + { + //cout<append(tempPost); + + } + line=innn.readLine(); +} + return posts; +} + + QString fileman:: getUserNameByEmail(QString email) + { + QFile in(path+"Users/"+email+".xml"); + QTextStream f (&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN the file "; + QString line=f.readLine(); + while(1) + { + if(line=="") + { + line=f.readLine(); + // qDebug()<") break; + + + } + + + + } + +void fileman:: createFile( QString passWord,QString email,QString userName,QString date ) +{ + emailss.push_back(email); + numberOfUsers++; + QString newFileStamp="\n"+userName+"\n\n"+"\n"+email+"\n\n\n"+date+"\n\n\n"+passWord+"\n\n\n\n\n0\n\n\n0\n"; + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &file ); + stream << newFileStamp; + } + + addEmail(email); + +} + +void fileman:: addPost(QString userPost, QString Date, QString name) +{ + // QString newPost=readFile("addPost.txt"); + + QFile i(path+name+".txt"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + + + + QFile in(path+"addPost.txt"); + QTextStream innn(&in); + + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString newPost=innn.readAll(); //This file is with norhaaaan doko kana wakaranai + in.close(); + + int indexText= newPost.indexOf(""); //+10 + newPost.insert(indexText+11,userPost); + + int indexDate=newPost.indexOf(""); + newPost.insert(indexDate+11,Date); + indexText= userFile.lastIndexOf(""); + userFile.insert(indexText+8,newPost); + QFile file(path+name+".txt"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} + + +void fileman:: addComment(QString userComment){ + + QString commentStamp="\n\n\n"+userComment+"\n\n\n\n\n"; + //now lets open the user file to insert el bta3 da + + QFile i(path+"addUser.txt"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + //Now we have all the user file content in userFile + int index=userFile.indexOf(""); + userFile.insert(index,commentStamp); + // qDebug()<\n\n"+nameComment+"\n\n\n"; + //now lets open the user file to insert el bta3 da + + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); +//now insert fe el userFile how is that :) + QString copy=userFile; +int from=0; +while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; +QString line="";int j=11; +line=userFile.mid(indexOfPostDate+11,Date.count()); +//userFile.insert(indexOfPostDate+j,commentStamp); + +//qDebug()<\n\n"+userPost+"\n\n"+"\n\n"+""; + + int indexText= userFile.indexOf(""); + userFile.insert(indexText+11,postStamp); + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + // qDebug()<< "couldn't open file"; + + file.close(); + +} +//QList * fileman:: getCommentsByPostDate(QString email,QString date) + +void fileman:: getCommentsByPostDate(QString email,QString date){ + + QString line; + QFile in(path+"Users/"+email+".xml"); + QTextStream inn(&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); +qDebug()< *comments = new QList ; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + + qDebug()<<"COULD NOT OPEN YA BENTY"; + int from=0; + //while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; + //QString line; + int j=11+1+1; + int indexOfCommentTag; + line=userFile.mid(indexOfPostDate+j,date.count()); + //userFile.insert(indexOfPostDate+date.count()+j+11,"hiiiiii i am here"); + // qDebug()<"; + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + int indexOfFriend=userFile.indexOf(""); + userFile.insert(indexOfFriend+9,friendStamp); +QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} +void fileman:: updateActivity(QString email, int numberOfLikes , int numberOfComments){ + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + int indexOfLikes=userFile.indexOf(""); + /* int ii=16; + QChar x=userFile[indexOfLikes+ii]; + + while(x!='\n'){ + userFile[indexOfLikes+ii]='NULL'; + ii++; + x=userFile[indexOfLikes+ii]; + + } +*/ + userFile.insert(indexOfLikes+15,"\n"+QString::number(numberOfLikes)); + int indexOfComments=userFile.indexOf(""); + userFile.insert(indexOfComments+18,"\n"+QString::number(numberOfComments)); + QFile file(path+"Users/"+email+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); +} + + +void fileman:: networkFile(){ + QString newFileStamp="\n"+QString::number(numberOfUsers)+"\n\n"; + QFile file(path+"Users/"+"network"+".xml"); + if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &file ); + stream << newFileStamp; + } + + +} + +void fileman::addUsers(){ + QFile i(path+"Users/network.xml"); + QTextStream inn(&i); + int id=0; + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + QFile file(path+"Users/network.xml"); + fileman x; + QList emails=x.readEmails(); +for (int k = 0; k \n\n"+QString::number(id)+"\n"; + id++; + int indexText= userFile.indexOf(""); + userFile.insert(indexText+16,emailStamp); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + + } + +} + +void fileman::createEmailFile() +{ + QString stamp="\n"; + QFile f(path+"Users/"+"email"+".xml"); + if ( f.open(QIODevice::WriteOnly | QIODevice::Text) ) + { + QTextStream stream( &f ); + stream << stamp; + } +} +void fileman::addEmail(QString email){ + QFile i(path+"Users/"+"email"+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); + i.close(); + int indexText= userFile.indexOf(""); + userFile.insert(indexText+8,"\n"+email); + QFile file(path+"Users/"+"email"+".xml"); + if ( file.open(QIODevice::ReadWrite) ) + { + QTextStream stream( &file ); + stream << userFile << endl; + } + else + qDebug()<< "couldn't open file"; + + file.close(); + +} +QList fileman:: readEmails(){ + QString line; + QFile in(path+"Users/"+"email"+".xml"); + QTextStream innn(&in); +// QList emails = new QList ; + QList emails; + QString temp=""; + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + line=innn.readLine(); + + if(line==""){ + line=innn.readLine(); + while(1) + { + emails.append(line); + // qDebug()<") break; + + // if(line==NULL) break; + + } + } + + return emails; + +} + +QList fileman:: getFriends(QString email) +{ + QList result; + QFile in(path+"Users/"+email+".xml"); + QTextStream innn(&in); + if(!in.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString line=innn.readLine(); + while(1){ + if(line=="") + { + while(1) + { + line=innn.readLine(); + + if(line=="") break; + result.append(line); + if(line==""||line=="") continue; + //qDebug()<") + { + line=inn.readLine(); + numberOfLikes=line.toInt(); + break; + } + if(line=="") + { + line=inn.readLine(); + numberOfPosts=line.toInt(); + break; + } + line=inn.readLine(); + if(line=="") + break; + + } +} + +QList *fileman::getPosts_new(QString email) +{ + QList *result = new QList; + + + + QFile i(path+"Users\\"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString line=inn.readLine(); + while(1) + { + Post temp; temp.setPostText(""); + if(line=="") + { + line=inn.readLine(); + while(1) + { + + if(line=="") + { + line=inn.readLine(); + temp.setPostDate(line); + // qDebug()<") + { + temp.setPostText(""); + line=inn.readLine(); + while(1) + { + if(line=="") + { + break; + } + temp.setPostText(temp.getPostText()+line); + // qDebug()<") + { + + Comment tempCom; + line=inn.readLine(); + while(1) + { + if(line=="") + { + tempCom.setCommentText(""); + line=inn.readLine(); + while(1) + { + tempCom.setCommentText(tempCom.getCommentText()+line); + line=inn.readLine(); + if(line=="")break; + } + } + if(line=="") + { + tempCom.setCommentOwner(inn.readLine()); + } + line=inn.readLine(); + if(line=="")break; + + } + //qDebug()<") + { + line=inn.readLine(); + while(line!="") + { + if(line=="") break; + if(line==""|| line=="") + { + line=inn.readLine(); + continue; + } + + temp.getPostLikesOwnersVectorPtr()->push_back(line); + + // qDebug()<") + { + fileman x; + temp.setPostOwner(email); + result->append(temp); + break; + } + + } + } + line=inn.readLine(); + if(line=="")break; + } +return result; +} + + + +void fileman ::addLikeByPostDate(QString email, QString Date, QString likePerson) +{ + QString likeStamp="\n\n"+likePerson+"\n"; + QFile i(path+"Users/"+email+".xml"); + QTextStream inn(&i); + if(!i.open(QFile::ReadOnly| QFile::Text)) + qDebug()<<"COULD NOT OPEN YA BENTY"; + QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai + i.close(); + + int from=0; int k=0; + while(from<=userFile.count()){ + int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; + QString line="";int j=11; + + line=userFile.mid(indexOfPostDate+11,Date.count()); +// userFile.insert(indexOfPostDate+j,likeStamp); + + //qDebug()<",from); + int likeTagIndex= userFile.indexOf("",from); + + userFile.insert(likeTagIndex+6,likeStamp); + k++; + + qDebug()<") + { + line=f.readLine(); + // qDebug()<") break; + + + } +} diff --git a/src/qt/fileman.h b/src/qt/fileman.h new file mode 100644 index 00000000..3e434553 --- /dev/null +++ b/src/qt/fileman.h @@ -0,0 +1,48 @@ +#ifndef FILEMAN_H +#define FILEMAN_H +#include +#include +#include +#include +#include +#include +#include "posts.h" +#include "comment.h" + + +class fileman{ +public: + QString path; + QString name; + QList posts; + + fileman(); + QString getPostByDate(QString Date); + QList * getPosts(QString email); + QString getUserNameByEmail(QString email); + void addPost(QString userPost, QString Date, QString name); + void addComment(QString userComment); + void addCommentByPostDate(QString userComment, QString Date, QString nameComment,QString nameFile); + void createFile( QString passWord,QString email,QString userName,QString date ); + void addFriend (QString friendName, QString name); + void addPost_new(QString userPost, QString Date, QString name); + void getCommentsByPostDate(QString email,QString date); + void addFriends(QString email,QString friendName); + void updateActivity(QString email, int numberOfLikes , int numberOfComments); + friend class user; + void networkFile(); + void addUsers(); + void TESTTEST(); + void createEmailFile(); + void addEmail(QString email); + QList readEmails(); + QList getFriends(QString email); + void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); + QList * getPosts_new(QString email); + +public slots: + void addLikeByPostDate(QString email, QString Date, QString likePerson); + QString getPassword(QString email); +}; + +#endif diff --git a/src/qt/form.cpp b/src/qt/form.cpp new file mode 100644 index 00000000..20e6af24 --- /dev/null +++ b/src/qt/form.cpp @@ -0,0 +1,14 @@ +#include "form.h" +#include "ui_form.h" + +Form::Form(QWidget *parent) : + QWidget(parent), + ui(new Ui::Form) +{ + ui->setupUi(this); +} + +Form::~Form() +{ + delete ui; +} diff --git a/src/qt/form.h b/src/qt/form.h new file mode 100644 index 00000000..59d50c60 --- /dev/null +++ b/src/qt/form.h @@ -0,0 +1,22 @@ +#ifndef FORM_H +#define FORM_H + +#include + +namespace Ui { +class Form; +} + +class Form : public QWidget +{ + Q_OBJECT + +public: + explicit Form(QWidget *parent = 0); + ~Form(); + +private: + Ui::Form *ui; +}; + +#endif // FORM_H diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp new file mode 100644 index 00000000..bf45b4d9 --- /dev/null +++ b/src/qt/homepage.cpp @@ -0,0 +1,441 @@ +#include "homepage.h" +#include "ui_homepage.h" +#include "profilepage.h" +#include "qprocess.h" + +//selim includes +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "QHBoxLayout" +#include "QVBoxLayout" +#include "QLabel" +#include "QSpacerItem" +#include "QPushButton" +#include +#include "posts.h" +#include "Qstring" +#include +#include "QFontMetrics" +#include "QGroupBox" +#include "QScrollBar" +#include "mainwindow.h" +#include "addcomment.h" +#include "adminwindow.h" +#define POSTSNUMBER 100 +#define COMMENTSNUMBER 3 +#define POSTSATATIME 15 +//_____ +HomePage::HomePage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::HomePage) +{ + ui->setupUi(this); + shownPostsNumber = 0; + ui->comboBox->setVisible(false); + pagePosts = new QList; + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); + +} + +void HomePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) +{ + this->currentSessionUser = currentSessionUser_ptr; + randomPosts(currentSessionUser_ptr->userName,POSTSATATIME); + QString domain = currentSessionUser_ptr->userName.mid(currentSessionUser_ptr->userName.length()-9,9); + if( domain!= "admin.com") + ui->StatisticsWindow_btn->setVisible(false); + viewPosts(); +} + + +void HomePage::viewPosts() +{ + unsigned int j,k; + static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; + qDebug("now"); + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) + { + QGroupBox *postframe = new QGroupBox; + QVBoxLayout *postLayout = new QVBoxLayout; + postframe->setLayout(postLayout); + postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); + QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); + postLayout->addWidget(postDate); + QTextBrowser *postBody = new QTextBrowser; + postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber + QFontMetrics font_metrics(postBody->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added + int height = font_height * 6; + postBody->setMinimumHeight(height); + postBody->setMaximumHeight(height); + postLayout->addWidget(postBody); + ParentVerticalLayout->addWidget(postframe); + QHBoxLayout *likeAndComment = new QHBoxLayout; + QPushButton *like = new QPushButton("Like"); + like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); + connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); + like->setStyleSheet("background-color: rgb(c0,c6,c8);"); + QPushButton *comment = new QPushButton("Comment",postframe); + comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); + connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); + comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); + likeAndComment->addWidget(like); + likeAndComment->addWidget(comment); + postLayout->addLayout(likeAndComment); + std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); + for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) + { + if(currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt]) + { + like->setEnabled(false); + break; + } + } + QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) + +" people are liking this!"); + likesOwners->setObjectName("likesOwnersButton"); + connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); + QHBoxLayout *likesOwnersLayout = new QHBoxLayout; + likesOwnersLayout->addWidget(likesOwners); + postLayout->addLayout(likesOwnersLayout); + for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) + { + QHBoxLayout *commentLayout = new QHBoxLayout; + QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBody = new QTextBrowser; + commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); + commentBody->setMinimumHeight(height); + commentBody->setMaximumHeight(height); + commentLayout->addWidget(commentBody); + postLayout->addLayout(commentLayout); + } + QFrame* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + ParentVerticalLayout->addWidget(line); + } + ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); + ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); + QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); + connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); +} +void HomePage::on_LikeButton_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + button->setEnabled(false); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); + int postsNumber,likesNumber; + currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); + currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); +} +void HomePage::on_CommentButton_clicked() +{ + QString commentBody; + QVBoxLayout *postLayout; + AddComment commentWindow; + commentWindow.setModal(true); + commentWindow.exec(); + commentBody = commentWindow.getCommentBody(); + qDebug(commentBody.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QHBoxLayout *commentLayout = new QHBoxLayout; + QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); + QLabel *commentOwner = new QLabel (commentOwnerName); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBodyTextBrowser = new QTextBrowser; + commentBodyTextBrowser->setText(commentBody); + QFontMetrics font_metrics(commentBodyTextBrowser->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? + int height = font_height * 2; + commentBodyTextBrowser->setMinimumHeight(height); + commentBodyTextBrowser->setMaximumHeight(height); + commentLayout->addWidget(commentBodyTextBrowser); + postLayout->addLayout(commentLayout); + /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + qDebug(labelString.toLatin1()); + currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) + ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); +} + + +void HomePage::on_likesOwners_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); + QScrollArea* likesOwners = new QScrollArea; + QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; + likesOwners->setLayout(scrollingAreaLayout); + for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) + { + if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) + { + std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); + for(int i = 0; i < likesVector->size(); i++) + { + QLabel* userLabel = new QLabel((*likesVector)[i]); + scrollingAreaLayout->addWidget(userLabel); + } + } + } + likesOwners->show(); +} + +void HomePage::viewMorePosts(int i) +{ + QScrollBar *bar = qobject_cast (QObject::sender()); + int max = bar ->maximum(); + if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) + { + viewPosts(); + } +} + + +HomePage::~HomePage() +{ + delete ui; +} + +void HomePage::on_pushButton_clicked() +{ + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + ProfilePage * profilePageWindow=new ProfilePage; + profilePageWindow->show(); + this->hide(); + profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); +} + +void HomePage::on_Post_btn_clicked() +{ + QString postText = ui->newPost_txtEdit->toPlainText(); + Date Now; + Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); + pagePosts->push_front(recentlyAddedPost); + shownPostsNumber = 0; + viewPosts(); + currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); + +} + +void HomePage::on_StatisticsWindow_btn_clicked() +{ + AdminWindow *adminWindow = new AdminWindow; + adminWindow->show();; + this->hide(); +} + + +void HomePage::swap(QString *a,QString *b) +{ + + QString temp=*a; + *a=*b; + *b=temp; +} + +void HomePage::siftUp(QList&myList,int index) //O(log(n) +{ + + int parentIndex= (index%2==0)?(index-2)/2 : (index-1)/2; + while( index!=0 && myList[parentIndex][0]&myList,int size) //O(log(n) +{ int index=0; + int leftChild= (2*index)+1; int rightChild=(2*index)+2; + while ((leftChild& myList) //O(n log(n)) +{ + + int size= myList.count(); + while(size>1) + { + swap(&myList[0],&myList[size-1]); + size--; + siftDown(myList,size); + + } + +} + + + +void HomePage::internalSearch (QString x,QList &myList,int begin,int end,QList &temp) +{ + + if(begin>end) {temp.append("\0");return ;} //not found + int middle= (begin+end)/2; bool indicator=false; + //qDebug()< x[0]) + { + + internalSearch ( x, myList,begin,middle-1,temp); + } + else + internalSearch ( x, myList,middle+1,end,temp); + + + +} + + +QList HomePage::search (QString x,QList & myList) +{ + for(int i=1;i temp; + internalSearch(x,myList,0,myList.count()-1,temp); + return temp; +} + + +void HomePage::on_friendSearch_textChanged(const QString &arg1) +{ + QString name= ui->friendSearch->text(); + if(name=="")return; + ui->comboBox->setVisible(true); + QList list= currentSessionUser->userFileManipulator.readEmails(); //yomna's list of mails + QListoptionsList=search(name,list); + ui->comboBox->addItem("Search Results"); + for(int i=0;icomboBox->addItem(optionsList[i]); + } + +} + +void HomePage::on_comboBox_currentIndexChanged(int index) +{ + QList items = ui->comboBox->children(); + if(index == -1) + return ; + QString mail = ui->comboBox->itemText(index); + if(mail == "Search Results") + return; + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + ProfilePage * profilePageWindow=new ProfilePage; + profilePageWindow->show(); + this->hide(); + profilePageWindow->setHomePageOwnerMail(currentSessionUser->userName); + currentSessionUser->userName = mail; + profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + +} + + +QList *HomePage::randomPosts(QString mail,int number) +{ + fileman A; + QList friendsMail=A.getFriends( mail); + friendsMail.push_front(currentSessionUser->userName); + friendsMail.push_front(currentSessionUser->userName); + friendsMail.push_front(currentSessionUser->userName); + for(int i=1;i *friendsPosts=currentSessionUser->userFileManipulator.getPosts_new(friendsMail[i]); + for(int j=0; jcount()) + pagePosts->push_back((*friendsPosts)[j]); + } + } +} + +void HomePage::on_actionLog_Out_triggered() +{ + qApp->quit(); + QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); +} diff --git a/src/qt/homepage.h b/src/qt/homepage.h new file mode 100644 index 00000000..01dc23e8 --- /dev/null +++ b/src/qt/homepage.h @@ -0,0 +1,84 @@ +#ifndef HOMEPAGE_H +#define HOMEPAGE_H + +#include +#include "profilepage.h" +#include "posts.h" +#include "user.h" +#include "QList" +#include "QVBoxLayout" +namespace Ui { +class HomePage; +} + +class HomePage : public QMainWindow +{ + Q_OBJECT + +public: + explicit HomePage(QWidget *parent = 0); + + void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); + + friend class ProfilePage; + + QList search(char x, QList &myList); + + ~HomePage(); + + +public slots: + QList search(QString x, QList& myList); + + void internalSearch(QString x, QList &myList, int begin, int end, QList &temp); + + void sort(QList &myList); + + void siftDown(QList &myList, int size); + + void siftUp(QList &myList, int index); + + void swap(QString *a, QString *b); + + QList *randomPosts(QString mail, int number); + + void on_likesOwners_clicked(); + + +private: + + Ui::HomePage *ui; + + user *currentSessionUser; + +private slots: + + void viewPosts(); + + void on_LikeButton_clicked(); + + void viewMorePosts(int i); + + void on_CommentButton_clicked(); + + void on_Post_btn_clicked(); + + void on_pushButton_clicked(); + + void on_StatisticsWindow_btn_clicked(); + + void on_friendSearch_textChanged(const QString &arg1); + + void on_comboBox_currentIndexChanged(int index); + + void on_actionLog_Out_triggered(); + + +private: + unsigned int shownPostsNumber; + + QList *pagePosts; + +}; + +#endif // HOMEPAGE_H diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..4a4ca2b9 --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,12 @@ +#include "mainwindow.h" +#include +#include "homepage.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 00000000..3699f475 --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,44 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "newAccount.h" +#include +#include "homepage.h" +#include "QMessageBox" +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include + + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + QPixmap pix(":/resources/img/login-icon.png"); + int w = ui->label_pic->width(); + int h = ui->label_pic->height(); + ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); + +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_Login_clicked() +{ + QString username = ui->lineEdit_username->text(); + QString password = ui->lineEdit_password->text(); + + if(username == "test" && password == "test") { + QMessageBox::information(this, "Login", "Username and password is correct"); + //hide(); + secDialog = new SecDialog(this); + secDialog->show(); + } + else { + QMessageBox::warning(this,"Login", "Username and password is not correct"); + } +} \ No newline at end of file diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h new file mode 100644 index 00000000..ed46f860 --- /dev/null +++ b/src/qt/mainwindow.h @@ -0,0 +1,27 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_signUpButton_clicked(); + + void on_logInButton_clicked(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/src/qt/myresources.qrc b/src/qt/myresources.qrc new file mode 100644 index 00000000..ea9c18d1 --- /dev/null +++ b/src/qt/myresources.qrc @@ -0,0 +1,6 @@ + + + logo.png + network.jpg + + diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp new file mode 100644 index 00000000..89c986e8 --- /dev/null +++ b/src/qt/newaccount.cpp @@ -0,0 +1,55 @@ +#include "newaccount.h" +#include "ui_newaccount.h" +#include "QMessageBox" +#include +newAccount::newAccount(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::newAccount) +{ + ui->setupUi(this); + user check; + id=check.getUsersSize(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->setWindowTitle("Social Network"); + +} + +newAccount::~newAccount() +{ + delete ui; +} + +void newAccount::on_pushButton_clicked() +{ + QString password =ui->lineEdit_2->text(); + QString confirm =ui->lineEdit_3->text(); + QString mail=ui->txtUserMail->text(); + if(password!=confirm) + { + QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); + } + else + { + user temp (password,mail,ui->txtUserName->text(),id); + temp.setUsersList(temp); + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + this->hide(); +// temp.userFileManipulator.updateActivity(mail,0,0); + } + +} + +void newAccount::setLoginPtr(MainWindow *ptr) +{ + this->mainWindowPtr = ptr; +} + +void newAccount::on_pushButton_2_clicked() +{ + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + // mainWindowPtr->show(); + this->hide(); + +} diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h new file mode 100644 index 00000000..9114dcdd --- /dev/null +++ b/src/qt/newaccount.h @@ -0,0 +1,36 @@ +#ifndef NEWACCOUNT_H +#define NEWACCOUNT_H + +#include +#include "mainwindow.h" +namespace Ui { +class newAccount; +} + +class newAccount : public QMainWindow +{ + Q_OBJECT + +public: + explicit newAccount(QWidget *parent = 0); + ~newAccount(); + int id; + + +public slots: + void setLoginPtr(MainWindow *ptr); + + +private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + +private: + Ui::newAccount *ui; + + MainWindow *mainWindowPtr; +}; + +#endif // NEWACCOUNT_H diff --git a/src/qt/posts.cpp b/src/qt/posts.cpp new file mode 100644 index 00000000..ef082536 --- /dev/null +++ b/src/qt/posts.cpp @@ -0,0 +1,112 @@ +#include "posts.h" + +Post::Post() +{ + postOwner = ""; + postText = ""; +} + +Post::Post(QString owner, QString text, QString creationDate) +{ + postOwner = owner; + postText = text; + postDate = creationDate; + postLikesNumber = 0; +} + +void Post::setPostOwner(QString owner) +{ + postOwner = owner; +} + +QString Post::getPostOwner() +{ + return postOwner; +} + +void Post::setPostText(QString text) +{ + postText = text; +} + +QString Post::getPostText() +{ + return postText; +} + +void Post::addPostLike(QString likeOwner) +{ + postLikesNumber++; + postLikesOwners.push_back(likeOwner); +} + +void Post::removePostLike(QString owner) +{ + std::vector::iterator iterator; + for(iterator = postLikesOwners.begin(); iterator != postLikesOwners.end(); iterator++) + { + if(*iterator == owner) + { + postLikesOwners.erase(iterator); + break; + } + } +} + +unsigned int Post::getPostLikesNumber() +{ + return postLikesNumber; +} + +std::vector *Post::getPostLikesOwnersVectorPtr() +{ + return &postLikesOwners; +} + +void Post::addComment(Comment newComment) +{ + postComments.push_back(newComment); +} + +void Post::deleteComment(Comment toBeDeleted) +{ + std::vector::iterator iterator; + for(iterator = postComments.begin(); iterator != postComments.end(); iterator++) + { + if((*iterator).getCommentText() == toBeDeleted.getCommentText()) + { + postComments.erase(iterator); + break; + } + } +} + +std::vector *Post::getPostCommentsVectorPtr() +{ + return &postComments; +} + +void Post::setPostDate(QString creationDate) +{ + postDate = creationDate; +} + +QString Post::getPostDate() +{ + return postDate; +} + + + + + + + + + + + + + + + diff --git a/src/qt/posts.h b/src/qt/posts.h new file mode 100644 index 00000000..094b3c17 --- /dev/null +++ b/src/qt/posts.h @@ -0,0 +1,179 @@ +#ifndef POSTS_H +#define POSTS_H +#include "comment.h" +#include +#include +class Post +{ + QString postOwner; + QString postText; + unsigned int postLikesNumber; + std::vector postLikesOwners; + std::vector postComments; + QString postDate; +public: + + /** + * @brief + * + * @param + * + * @return + */ + Post(); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + Post(QString,QString,QString); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + void setPostOwner(QString); + + /** + * @brief + * + * @param + * + * @example + * + * @return + */ + QString getPostOwner(); + + /** + * @brief + * + * @ + * + * @param + * + * @return + */ + void setPostText(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + QString getPostText(); + + /** + * @brief + * + * @example
+ * + * @param + * + * @return + */ + void addPostLike(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void removePostLike(QString); + + /** + * @brief + * + * @example <35 likes or so. Maybe used to view the post likes number in a label or something.> + * + * @param + * + * @return + */ + unsigned int getPostLikesNumber(); + + /** + * @brief + * + * @example + * + * @param + * + * @return * postLikesOwners> + */ + std::vector* getPostLikesOwnersVectorPtr(); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void addComment(Comment); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + void deleteComment(Comment); + + /** + * @brief + * + * @example + * + * @param + * + * @return * commentsVector> + */ + std::vector* getPostCommentsVectorPtr(); + + /** + * @brief + * + * @example: + * + * @param + * + * @return + */ + void setPostDate(QString); + + /** + * @brief + * + * @example + * + * @param + * + * @return + */ + QString getPostDate(); +}; +#endif // POSTS_H diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp new file mode 100644 index 00000000..581314ea --- /dev/null +++ b/src/qt/profilepage.cpp @@ -0,0 +1,314 @@ +#include "profilepage.h" +#include "ui_profilepage.h" +#include "homepage.h" + +//selim includes +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "QHBoxLayout" +#include "QVBoxLayout" +#include "QLabel" +#include "QSpacerItem" +#include "QPushButton" +#include +#include "posts.h" +#include "Qstring" +#include +#include "QFontMetrics" +#include "QGroupBox" +#include "QScrollBar" +#include "mainwindow.h" +#include "addcomment.h" +#define POSTSNUMBER 100 +#define COMMENTSNUMBER 3 +#define POSTSATATIME 15 +//_____ + +#include "qprocess.h" + +ProfilePage::ProfilePage(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ProfilePage) +{ + ui->setupUi(this); + shownPostsNumber = 0; + //pagePosts = makePosts(); + // viewPosts(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); +} + + ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) + { + + ui->setupUi(this); + user A; + // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( + ui->lblMail->setText(email);//user file's name is the email of the user + shownPostsNumber = 0; + qDebug()<<"id is "<userName = homePageOwnerMail; + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); +} + + +void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) +{ + this->currentSessionUser = currentSessionUser_ptr; + pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); + viewPosts(); + if(homePageOwnerMail != "") + { + fileman x; + QList friendsList = x.getFriends(homePageOwnerMail); + for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) + { + if(*it == currentSessionUser_ptr->userName) + { + ui->addFriendBtn->setEnabled(false); + break; + } + } + } +} + +//Selim functions +void ProfilePage::viewPosts() +{ + ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); + ui->lblMail->setText(currentSessionUser->userName); + ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); + QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); + if(homePageOwnerMail == "") + ui->addFriendBtn->setEnabled(false); + int j,k; + for(j = 1; j < friendsList.size() - 1; j = j + 3) + { + ui->friendsComboBox->addItem(friendsList[j]); + } + static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; + qDebug("now"); + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) + { + QGroupBox *postframe = new QGroupBox; + //postframe->setObjectName("frame"+QString::number(k)); + QVBoxLayout *postLayout = new QVBoxLayout; + postframe->setLayout(postLayout); + postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); + QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); + postLayout->addWidget(postDate); + QTextBrowser *postBody = new QTextBrowser; + postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber + QFontMetrics font_metrics(postBody->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added + int height = font_height * 6; + postBody->setMinimumHeight(height); + postBody->setMaximumHeight(height); + postLayout->addWidget(postBody); + ParentVerticalLayout->addWidget(postframe); + QHBoxLayout *likeAndComment = new QHBoxLayout; + QPushButton *like = new QPushButton("Like"); + like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); + connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); + like->setStyleSheet("background-color: rgb(c0,c6,c8);"); + QPushButton *comment = new QPushButton("Comment",postframe); + comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); + connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); + comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); + likeAndComment->addWidget(like); + likeAndComment->addWidget(comment); + postLayout->addLayout(likeAndComment); + std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); + for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) + { + if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) + { + like->setEnabled(false); + break; + } + } + QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) + +" people are liking this!"); + likesOwners->setObjectName("likesOwnersButton"); + connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); + QHBoxLayout *likesOwnersLayout = new QHBoxLayout; + likesOwnersLayout->addWidget(likesOwners); + postLayout->addLayout(likesOwnersLayout); + for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) + { + QHBoxLayout *commentLayout = new QHBoxLayout; + QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBody = new QTextBrowser; + commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); + commentBody->setMinimumHeight(height); + commentBody->setMaximumHeight(height); + commentLayout->addWidget(commentBody); + postLayout->addLayout(commentLayout); + } + QFrame* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + ParentVerticalLayout->addWidget(line); + } + ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); + ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); + //connect(ui->PostsArea,SIGNAL(ui->PostsArea->scroll(50,50)),this,SLOT(close())); + QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); + connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); +} +void ProfilePage::on_LikeButton_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + button->setEnabled(false); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + if(homePageOwnerMail == "") + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); + else + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); + int postsNumber,likesNumber; + currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); + currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); + +} +void ProfilePage::on_CommentButton_clicked() +{ + QString commentBody; + QVBoxLayout *postLayout; + AddComment commentWindow; + commentWindow.setModal(true); + commentWindow.exec(); + commentBody = commentWindow.getCommentBody(); + qDebug(commentBody.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QHBoxLayout *commentLayout = new QHBoxLayout; + QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); + QLabel *commentOwner = new QLabel (commentOwnerName); + commentLayout->addWidget(commentOwner); + QTextBrowser *commentBodyTextBrowser = new QTextBrowser; + commentBodyTextBrowser->setText(commentBody); + QFontMetrics font_metrics(commentBodyTextBrowser->font()); + int font_height = font_metrics.height(); + // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? + int height = font_height * 2; + commentBodyTextBrowser->setMinimumHeight(height); + commentBodyTextBrowser->setMaximumHeight(height); + commentLayout->addWidget(commentBodyTextBrowser); + postLayout->addLayout(commentLayout); + /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + qDebug(labelString.toLatin1()); + currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) + ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); +} + +void ProfilePage::on_likesOwners_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); + QScrollArea* likesOwners = new QScrollArea; + QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; + likesOwners->setLayout(scrollingAreaLayout); + for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) + { + if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) + { + std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); + for(int i = 0; i < likesVector->size(); i++) + { + QLabel* userLabel = new QLabel((*likesVector)[i]); + scrollingAreaLayout->addWidget(userLabel); + } + } + } + likesOwners->show(); +} + +void ProfilePage::viewMorePosts(int i) +{ + QScrollBar *bar = qobject_cast (QObject::sender()); + int max = bar ->maximum(); + if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) + { + viewPosts(); + } +} + + + +void ProfilePage::on_Post_btn_clicked() +{ + QString postText = ui->newPost_txtEdit->toPlainText(); +// currentSessionUser.userFileManipulator.addPost(postText); + Date Now; + Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); + pagePosts->push_front(recentlyAddedPost); + shownPostsNumber = 0; + // clear the post area + //ui->PostsArea-> + viewPosts(); + currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); +} + +void ProfilePage::setHomePageOwnerMail(QString owner) +{ + homePageOwnerMail = owner; + ui->newPost_txtEdit->setVisible(false); + ui->Post_btn->setVisible(false); +} + + +void ProfilePage::on_addFriendBtn_clicked() +{ + currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); + ui->addFriendBtn->setEnabled(false); +} + +void ProfilePage::on_actionLog_out_triggered() +{ + qApp->quit(); + QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); +} diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h new file mode 100644 index 00000000..00222ec0 --- /dev/null +++ b/src/qt/profilepage.h @@ -0,0 +1,61 @@ +#ifndef PROFILEPAGE_H +#define PROFILEPAGE_H + +#include +#include "posts.h" +#include "user.h" +#include "homepage.h" +namespace Ui { +class ProfilePage; +} + +class ProfilePage : public QMainWindow +{ + Q_OBJECT + +public: + explicit ProfilePage(QWidget *parent = 0); + + ~ProfilePage(); + + ProfilePage(int userID,QString userFile); + +private slots: + void on_pushButton_2_clicked(); + + void viewPosts(); + + void on_LikeButton_clicked(); + + void viewMorePosts(int i); + + void on_CommentButton_clicked(); + + void on_addFriendBtn_clicked(); + + void on_actionLog_out_triggered(); + + +public slots: + void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); + + void on_Post_btn_clicked(); + + void setHomePageOwnerMail(QString owner); + + void on_likesOwners_clicked(); + + +private: + Ui::ProfilePage *ui; + + unsigned int shownPostsNumber; + + QList *pagePosts; + + user *currentSessionUser; + + QString homePageOwnerMail; +}; + +#endif // PROFILEPAGE_H diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp new file mode 100644 index 00000000..e59374ab --- /dev/null +++ b/src/qt/qcustomplot.cpp @@ -0,0 +1,30121 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#include "qcustomplot.h" + + +/* including file 'src/vector2d.cpp', size 7340 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPVector2D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPVector2D + \brief Represents two doubles as a mathematical 2D vector + + This class acts as a replacement for QVector2D with the advantage of double precision instead of + single, and some convenience methods tailored for the QCustomPlot library. +*/ + +/* start documentation of inline functions */ + +/*! \fn void QCPVector2D::setX(double x) + + Sets the x coordinate of this vector to \a x. + + \see setY +*/ + +/*! \fn void QCPVector2D::setY(double y) + + Sets the y coordinate of this vector to \a y. + + \see setX +*/ + +/*! \fn double QCPVector2D::length() const + + Returns the length of this vector. + + \see lengthSquared +*/ + +/*! \fn double QCPVector2D::lengthSquared() const + + Returns the squared length of this vector. In some situations, e.g. when just trying to find the + shortest vector of a group, this is faster than calculating \ref length, because it avoids + calculation of a square root. + + \see length +*/ + +/*! \fn QPoint QCPVector2D::toPoint() const + + Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point + information. + + \see toPointF +*/ + +/*! \fn QPointF QCPVector2D::toPointF() const + + Returns a QPointF which has the x and y coordinates of this vector. + + \see toPoint +*/ + +/*! \fn bool QCPVector2D::isNull() const + + Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y + coordinates, i.e. if both are binary equal to 0. +*/ + +/*! \fn QCPVector2D QCPVector2D::perpendicular() const + + Returns a vector perpendicular to this vector, with the same length. +*/ + +/*! \fn double QCPVector2D::dot() const + + Returns the dot/scalar product of this vector with the specified vector \a vec. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates to 0. +*/ +QCPVector2D::QCPVector2D() : + mX(0), + mY(0) +{ +} + +/*! + Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified + values. +*/ +QCPVector2D::QCPVector2D(double x, double y) : + mX(x), + mY(y) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPoint &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPointF &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Normalizes this vector. After this operation, the length of the vector is equal to 1. + + \see normalized, length, lengthSquared +*/ +void QCPVector2D::normalize() +{ + double len = length(); + mX /= len; + mY /= len; +} + +/*! + Returns a normalized version of this vector. The length of the returned vector is equal to 1. + + \see normalize, length, lengthSquared +*/ +QCPVector2D QCPVector2D::normalized() const +{ + QCPVector2D result(mX, mY); + result.normalize(); + return result; +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a start and \a end. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const +{ + QCPVector2D v(end-start); + double vLengthSqr = v.lengthSquared(); + if (!qFuzzyIsNull(vLengthSqr)) + { + double mu = v.dot(*this-start)/vLengthSqr; + if (mu < 0) + return (*this-start).lengthSquared(); + else if (mu > 1) + return (*this-end).lengthSquared(); + else + return ((start + mu*v)-*this).lengthSquared(); + } else + return (*this-start).lengthSquared(); +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a line. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QLineF &line) const +{ + return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); +} + +/*! + Returns the shortest distance of this vector (interpreted as a point) to the infinite straight + line given by a \a base point and a \a direction vector. + + \see distanceSquaredToLine +*/ +double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const +{ + return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); +} + +/*! + Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a + factor. +*/ +QCPVector2D &QCPVector2D::operator*=(double factor) +{ + mX *= factor; + mY *= factor; + return *this; +} + +/*! + Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a + divisor. +*/ +QCPVector2D &QCPVector2D::operator/=(double divisor) +{ + mX /= divisor; + mY /= divisor; + return *this; +} + +/*! + Adds the given \a vector to this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) +{ + mX += vector.mX; + mY += vector.mY; + return *this; +} + +/*! + subtracts the given \a vector from this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) +{ + mX -= vector.mX; + mY -= vector.mY; + return *this; +} +/* end of 'src/vector2d.cpp' */ + + +/* including file 'src/painter.cpp', size 8670 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPainter +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPainter + \brief QPainter subclass used internally + + This QPainter subclass is used to provide some extended functionality e.g. for tweaking position + consistency between antialiased and non-antialiased painting. Further it provides workarounds + for QPainter quirks. + + \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and + restore. So while it is possible to pass a QCPPainter instance to a function that expects a + QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because + it will call the base class implementations of the functions actually hidden by QCPPainter). +*/ + +/*! + Creates a new QCPPainter instance and sets default values +*/ +QCPPainter::QCPPainter() : + QPainter(), + mModes(pmDefault), + mIsAntialiasing(false) +{ + // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and + // a call to begin() will follow +} + +/*! + Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just + like the analogous QPainter constructor, begins painting on \a device immediately. + + Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. +*/ +QCPPainter::QCPPainter(QPaintDevice *device) : + QPainter(device), + mModes(pmDefault), + mIsAntialiasing(false) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (isActive()) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif +} + +/*! + Sets the pen of the painter and applies certain fixes to it, depending on the mode of this + QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QPen &pen) +{ + QPainter::setPen(pen); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QColor &color) +{ + QPainter::setPen(color); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(Qt::PenStyle penStyle) +{ + QPainter::setPen(penStyle); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when + antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to + integer coordinates and then passes it to the original drawLine. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::drawLine(const QLineF &line) +{ + if (mIsAntialiasing || mModes.testFlag(pmVectorized)) + QPainter::drawLine(line); + else + QPainter::drawLine(line.toLine()); +} + +/*! + Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint + with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between + antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for + AA/Non-AA painting). +*/ +void QCPPainter::setAntialiasing(bool enabled) +{ + setRenderHint(QPainter::Antialiasing, enabled); + if (mIsAntialiasing != enabled) + { + mIsAntialiasing = enabled; + if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs + { + if (mIsAntialiasing) + translate(0.5, 0.5); + else + translate(-0.5, -0.5); + } + } +} + +/*! + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setModes(QCPPainter::PainterModes modes) +{ + mModes = modes; +} + +/*! + Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a + device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, + all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that + behaviour. + + The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets + the render hint as appropriate. + + \note this function hides the non-virtual base class implementation. +*/ +bool QCPPainter::begin(QPaintDevice *device) +{ + bool result = QPainter::begin(device); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (result) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif + return result; +} + +/*! \overload + + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) +{ + if (!enabled && mModes.testFlag(mode)) + mModes &= ~mode; + else if (enabled && !mModes.testFlag(mode)) + mModes |= mode; +} + +/*! + Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see restore +*/ +void QCPPainter::save() +{ + mAntialiasingStack.push(mIsAntialiasing); + QPainter::save(); +} + +/*! + Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see save +*/ +void QCPPainter::restore() +{ + if (!mAntialiasingStack.isEmpty()) + mIsAntialiasing = mAntialiasingStack.pop(); + else + qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; + QPainter::restore(); +} + +/*! + Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen + overrides when the \ref pmNonCosmetic mode is set. +*/ +void QCPPainter::makeNonCosmetic() +{ + if (qFuzzyIsNull(pen().widthF())) + { + QPen p = pen(); + p.setWidth(1); + QPainter::setPen(p); + } +} +/* end of 'src/painter.cpp' */ + + +/* including file 'src/paintbuffer.cpp', size 18502 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPaintBuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPaintBuffer + \brief The abstract base class for paint buffers, which define the rendering backend + + This abstract base class defines the basic interface that a paint buffer needs to provide in + order to be usable by QCustomPlot. + + A paint buffer manages both a surface to draw onto, and the matching paint device. The size of + the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref + QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the + painting is complete, \ref donePainting is called, so the paint buffer implementation can do + clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color + using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the + previous frame. + + The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular + software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and + frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. + They are used automatically if \ref QCustomPlot::setOpenGl is enabled. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 + + Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the + responsibility to delete the painter after the painting operations are complete is given to the + caller of this method. + + Once you are done using the painter, delete the painter and call \ref donePainting. + + While a painter generated with this method is active, you must not call \ref setSize, \ref + setDevicePixelRatio or \ref clear. + + This method may return 0, if a painter couldn't be activated on the buffer. This usually + indicates a problem with the respective painting backend. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 + + Draws the contents of this buffer with the provided \a painter. This is the method that is used + to finally join all paint buffers and draw them onto the screen. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 + + Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the + named color \c Qt::transparent. + + This method must not be called if there is currently a painter (acquired with \ref startPainting) + active. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 + + Reallocates the internal buffer with the currently configured size (\ref setSize) and device + pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those + properties are changed on this paint buffer. + + \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method + in their constructor, to perform the first allocation (this can not be done by the base class + because calling pure virtual methods in base class constructors is not possible). +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of inline functions */ + +/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() + + If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, + call this method as soon as you are done with the painting operations and have deleted the + painter. + + paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The + default implementation does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. + + Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. +*/ +QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : + mSize(size), + mDevicePixelRatio(devicePixelRatio), + mInvalidated(true) +{ +} + +QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() +{ +} + +/*! + Sets the paint buffer size. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + If \a size is already the current buffer size, this method does nothing. +*/ +void QCPAbstractPaintBuffer::setSize(const QSize &size) +{ + if (mSize != size) + { + mSize = size; + reallocateBuffer(); + } +} + +/*! + Sets the invalidated flag to \a invalidated. + + This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer + instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered + layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, + QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also + replots them, instead of only the layer on which the replot was called. + + The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers + were added or removed from this buffer, or if they were reordered. It is set to false as soon as + all associated \ref QCPLayer instances are drawn onto the buffer. + + Under normal circumstances, it is not necessary to manually call this method. +*/ +void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) +{ + mInvalidated = invalidated; +} + +/*! + Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. + The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + \note This method is only available for Qt versions 5.4 and higher. +*/ +void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mDevicePixelRatio = ratio; + reallocateBuffer(); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; +#endif + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferPixmap + \brief A paint buffer based on QPixmap, using software raster rendering + + This paint buffer is the default and fall-back paint buffer which uses software rendering and + QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. +*/ + +/*! + Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if + applicable. +*/ +QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : + QCPAbstractPaintBuffer(size, devicePixelRatio) +{ + QCPPaintBufferPixmap::reallocateBuffer(); +} + +QCPPaintBufferPixmap::~QCPPaintBufferPixmap() +{ +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferPixmap::startPainting() +{ + QCPPainter *result = new QCPPainter(&mBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::draw(QCPPainter *painter) const +{ + if (painter && painter->isActive()) + painter->drawPixmap(0, 0, mBuffer); + else + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::clear(const QColor &color) +{ + mBuffer.fill(color); +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::reallocateBuffer() +{ + setInvalidated(); + if (!qFuzzyCompare(1.0, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBuffer = QPixmap(mSize*mDevicePixelRatio); + mBuffer.setDevicePixelRatio(mDevicePixelRatio); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; + mBuffer = QPixmap(mSize); +#endif + } else + { + mBuffer = QPixmap(mSize); + } +} + + +#ifdef QCP_OPENGL_PBUFFER +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlPbuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlPbuffer + \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. + (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a + devicePixelRatio, if applicable. + + The parameter \a multisamples defines how many samples are used per pixel. Higher values thus + result in higher quality antialiasing. If the specified \a multisamples value exceeds the + capability of the graphics hardware, the highest supported multisampling is used. +*/ +QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlPBuffer(0), + mMultisamples(qMax(0, multisamples)) +{ + QCPPaintBufferGlPbuffer::reallocateBuffer(); +} + +QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlPbuffer::startPainting() +{ + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + QCPPainter *result = new QCPPainter(mGlPBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlPBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::clear(const QColor &color) +{ + if (mGlPBuffer->isValid()) + { + mGlPBuffer->makeCurrent(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlPBuffer->doneCurrent(); + } else + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::reallocateBuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; + + QGLFormat format; + format.setAlpha(true); + format.setSamples(mMultisamples); + mGlPBuffer = new QGLPixelBuffer(mSize, format); +} +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlFbo +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlFbo + \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and + higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, + if applicable. + + All frame buffer objects shall share one OpenGL context and paint device, which need to be set up + externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref + QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot + instance. +*/ +QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlContext(glContext), + mGlPaintDevice(glPaintDevice), + mGlFrameBuffer(0) +{ + QCPPaintBufferGlFbo::reallocateBuffer(); +} + +QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() +{ + if (mGlFrameBuffer) + delete mGlFrameBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlFbo::startPainting() +{ + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return 0; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::donePainting() +{ + if (mGlFrameBuffer && mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + else + qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlFrameBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::clear(const QColor &color) +{ + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlFrameBuffer->release(); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::reallocateBuffer() +{ + // release and delete possibly existing framebuffer: + if (mGlFrameBuffer) + { + if (mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + delete mGlFrameBuffer; + mGlFrameBuffer = 0; + } + + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return; + } + + // create new fbo with appropriate size: + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + QOpenGLFramebufferObjectFormat frameBufferFormat; + frameBufferFormat.setSamples(mGlContext.data()->format().samples()); + frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); + if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) + mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); +#endif +} +#endif // QCP_OPENGL_FBO +/* end of 'src/paintbuffer.cpp' */ + + +/* including file 'src/layer.cpp', size 37064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayer + \brief A layer that may contain objects, to control the rendering order + + The Layering system of QCustomPlot is the mechanism to control the rendering order of the + elements inside the plot. + + It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of + one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, + QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers + bottom to top and successively draws the layerables of the layers into the paint buffer(s). + + A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base + class from which almost all visible objects derive, like axes, grids, graphs, items, etc. + + \section qcplayer-defaultlayers Default layers + + Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and + "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's + selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain + the default axes and legend, so they will be drawn above plottables. In the middle, there is the + "main" layer. It is initially empty and set as the current layer (see + QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this + layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong + tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind + everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of + course, the layer affiliation of the individual objects can be changed as required (\ref + QCPLayerable::setLayer). + + \section qcplayer-ordering Controlling the rendering order via layers + + Controlling the ordering of layerables in the plot is easy: Create a new layer in the position + you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the + current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the + objects normally. They will be placed on the new layer automatically, due to the current layer + setting. Alternatively you could have also ignored the current layer setting and just moved the + objects with \ref QCPLayerable::setLayer to the desired layer after creating them. + + It is also possible to move whole layers. For example, If you want the grid to be shown in front + of all plottables/items on the "main" layer, just move it above "main" with + QCustomPlot::moveLayer. + + The rendering order within one layer is simply by order of creation or insertion. The item + created last (or added last to the layer), is drawn on top of all other objects on that layer. + + When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below + the deleted layer, see QCustomPlot::removeLayer. + + \section qcplayer-buffering Replotting only a specific layer + + If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific + layer by calling \ref replot. In certain situations this can provide better replot performance, + compared with a full replot of all layers. Upon creation of a new layer, the layer mode is + initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref + QCustomPlot instance is the "overlay" layer, containing the selection rect. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPLayer::children() const + + Returns a list of all layerables on this layer. The order corresponds to the rendering order: + layerables with higher indices are drawn above layerables with lower indices. +*/ + +/*! \fn int QCPLayer::index() const + + Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be + accessed via \ref QCustomPlot::layer. + + Layers with higher indices will be drawn above layers with lower indices. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPLayer instance. + + Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. + + \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. + This check is only performed by \ref QCustomPlot::addLayer. +*/ +QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : + QObject(parentPlot), + mParentPlot(parentPlot), + mName(layerName), + mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function + mVisible(true), + mMode(lmLogical) +{ + // Note: no need to make sure layerName is unique, because layer + // management is done with QCustomPlot functions. +} + +QCPLayer::~QCPLayer() +{ + // If child layerables are still on this layer, detach them, so they don't try to reach back to this + // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted + // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to + // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) + + while (!mChildren.isEmpty()) + mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() + + if (mParentPlot->currentLayer() == this) + qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; +} + +/*! + Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this + layer will be invisible. + + This function doesn't change the visibility property of the layerables (\ref + QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the + visibility of the parent layer into account. +*/ +void QCPLayer::setVisible(bool visible) +{ + mVisible = visible; +} + +/*! + Sets the rendering mode of this layer. + + If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by + the parent QCustomPlot instance. This means it may be replotted individually by calling \ref + QCPLayer::replot, without needing to replot all other layers. + + Layers which are set to \ref lmLogical (the default) are used only to define the rendering order + and can't be replotted individually. + + Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the + layers below, above and for the layer itself. This increases the memory consumption and + (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So + you should carefully choose which layers benefit from having their own paint buffer. A typical + example would be a layer which contains certain layerables (e.g. items) that need to be changed + and thus replotted regularly, while all other layerables on other layers stay static. By default, + only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection + rect. + + \see replot +*/ +void QCPLayer::setMode(QCPLayer::LayerMode mode) +{ + if (mMode != mode) + { + mMode = mode; + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } +} + +/*! \internal + + Draws the contents of this layer with the provided \a painter. + + \see replot, drawToPaintBuffer +*/ +void QCPLayer::draw(QCPPainter *painter) +{ + Q_FOREACH (QCPLayerable *child, mChildren) + { + if (child->realVisibility()) + { + painter->save(); + painter->setClipRect(child->clipRect().translated(0, -1)); + child->applyDefaultAntialiasingHint(painter); + child->draw(painter); + painter->restore(); + } + } +} + +/*! \internal + + Draws the contents of this layer into the paint buffer which is associated with this layer. The + association is established by the parent QCustomPlot, which manages all paint buffers (see \ref + QCustomPlot::setupPaintBuffers). + + \see draw +*/ +void QCPLayer::drawToPaintBuffer() +{ + if (!mPaintBuffer.isNull()) + { + if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) + { + if (painter->isActive()) + draw(painter); + else + qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; + delete painter; + mPaintBuffer.data()->donePainting(); + } else + qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; +} + +/*! + If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only + the layerables on this specific layer, without the need to replot all other layers (as a call to + \ref QCustomPlot::replot would do). + + If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on + the parent QCustomPlot instance. + + QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering + has changed since the last full replot and the other paint buffers were thus invalidated. + + \see draw +*/ +void QCPLayer::replot() +{ + if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) + { + if (!mPaintBuffer.isNull()) + { + mPaintBuffer.data()->clear(Qt::transparent); + drawToPaintBuffer(); + mPaintBuffer.data()->setInvalidated(false); + mParentPlot->update(); + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; + } else if (mMode == lmLogical) + mParentPlot->replot(); +} + +/*! \internal + + Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will + be prepended to the list, i.e. be drawn beneath the other layerables already in the list. + + This function does not change the \a mLayer member of \a layerable to this layer. (Use + QCPLayerable::setLayer to change the layer of an object, not this function.) + + \see removeChild +*/ +void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) +{ + if (!mChildren.contains(layerable)) + { + if (prepend) + mChildren.prepend(layerable); + else + mChildren.append(layerable); + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); +} + +/*! \internal + + Removes the \a layerable from the list of this layer. + + This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer + to change the layer of an object, not this function.) + + \see addChild +*/ +void QCPLayer::removeChild(QCPLayerable *layerable) +{ + if (mChildren.removeOne(layerable)) + { + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayerable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayerable + \brief Base class for all drawable objects + + This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid + etc. + + Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking + the layers accordingly. + + For details about the layering mechanism, see the QCPLayer documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const + + Returns the parent layerable of this layerable. The parent layerable is used to provide + visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables + only get drawn if their parent layerables are visible, too. + + Note that a parent layerable is not necessarily also the QObject parent for memory management. + Further, a layerable doesn't always have a parent layerable, so this function may return 0. + + A parent layerable is set implicitly when placed inside layout elements and doesn't need to be + set manually by the user. +*/ + +/* end documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 + \internal + + This function applies the default antialiasing setting to the specified \a painter, using the + function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when + \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing + setting may be specified individually, this function should set the antialiasing state of the + most prominent entity. In this case however, the \ref draw function usually calls the specialized + versions of this function before drawing each entity, effectively overriding the setting of the + default antialiasing hint. + + First example: QCPGraph has multiple entities that have an antialiasing setting: The graph + line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, + QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only + the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's + antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and + QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw + calls the respective specialized applyAntialiasingHint function. + + Second example: QCPItemLine consists only of a line so there is only one antialiasing + setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by + all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the + respective layerable subclass.) Consequently it only has the normal + QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to + care about setting any antialiasing states, because the default antialiasing hint is already set + on the painter when the \ref draw function is called, and that's the state it wants to draw the + line with. +*/ + +/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 + \internal + + This function draws the layerable with the specified \a painter. It is only called by + QCustomPlot, if the layerable is visible (\ref setVisible). + + Before this function is called, the painter's antialiasing state is set via \ref + applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was + set to \ref clipRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); + + This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to + a different layer. + + \see setLayer +*/ + +/* end documentation of signals */ + +/*! + Creates a new QCPLayerable instance. + + Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the + derived classes. + + If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a + targetLayer is an empty string, it places itself on the current layer of the plot (see \ref + QCustomPlot::setCurrentLayer). + + It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later + time with \ref initializeParentPlot. + + The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable + parents are mainly used to control visibility in a hierarchy of layerables. This means a + layerable is only drawn, if all its ancestor layerables are also visible. Note that \a + parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a + plot does. It is not uncommon to set the QObject-parent to something else in the constructors of + QCPLayerable subclasses, to guarantee a working destruction hierarchy. +*/ +QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : + QObject(plot), + mVisible(true), + mParentPlot(plot), + mParentLayerable(parentLayerable), + mLayer(0), + mAntialiased(true) +{ + if (mParentPlot) + { + if (targetLayer.isEmpty()) + setLayer(mParentPlot->currentLayer()); + else if (!setLayer(targetLayer)) + qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; + } +} + +QCPLayerable::~QCPLayerable() +{ + if (mLayer) + { + mLayer->removeChild(this); + mLayer = 0; + } +} + +/*! + Sets the visibility of this layerable object. If an object is not visible, it will not be drawn + on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not + possible. +*/ +void QCPLayerable::setVisible(bool on) +{ + mVisible = on; +} + +/*! + Sets the \a layer of this layerable object. The object will be placed on top of the other objects + already on \a layer. + + If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or + interact/receive events). + + Returns true if the layer of this layerable was successfully changed to \a layer. +*/ +bool QCPLayerable::setLayer(QCPLayer *layer) +{ + return moveToLayer(layer, false); +} + +/*! \overload + Sets the layer of this layerable object by name + + Returns true on success, i.e. if \a layerName is a valid layer name. +*/ +bool QCPLayerable::setLayer(const QString &layerName) +{ + if (!mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (QCPLayer *layer = mParentPlot->layer(layerName)) + { + return setLayer(layer); + } else + { + qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; + return false; + } +} + +/*! + Sets whether this object will be drawn antialiased or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPLayerable::setAntialiased(bool enabled) +{ + mAntialiased = enabled; +} + +/*! + Returns whether this layerable is visible, taking the visibility of the layerable parent and the + visibility of this layerable's layer into account. This is the method that is consulted to decide + whether a layerable shall be drawn or not. + + If this layerable has a direct layerable parent (usually set via hierarchies implemented in + subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this + layerable has its visibility set to true and the parent layerable's \ref realVisibility returns + true. +*/ +bool QCPLayerable::realVisibility() const +{ + return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); +} + +/*! + This function is used to decide whether a click hits a layerable object or not. + + \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the + shortest pixel distance of this point to the object. If the object is either invisible or the + distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the + object is not selectable, -1.0 is returned, too. + + If the object is represented not by single lines but by an area like a \ref QCPItemText or the + bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In + these cases this function thus returns a constant value greater zero but still below the parent + plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). + + Providing a constant value for area objects allows selecting line objects even when they are + obscured by such area objects, by clicking close to the lines (i.e. closer than + 0.99*selectionTolerance). + + The actual setting of the selection state is not done by this function. This is handled by the + parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified + via the \ref selectEvent/\ref deselectEvent methods. + + \a details is an optional output parameter. Every layerable subclass may place any information + in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot + decides on the basis of this selectTest call, that the object was successfully selected. The + subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part + objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked + is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be + placed in \a details. So in the subsequent \ref selectEvent, the decision which part was + selected doesn't have to be done a second time for a single selection operation. + + You may pass 0 as \a details to indicate that you are not interested in those selection details. + + \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions +*/ +double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(pos) + Q_UNUSED(onlySelectable) + Q_UNUSED(details) + return -1.0; +} + +/*! \internal + + Sets the parent plot of this layerable. Use this function once to set the parent plot if you have + passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to + another one. + + Note that, unlike when passing a non-null parent plot in the constructor, this function does not + make \a parentPlot the QObject-parent of this layerable. If you want this, call + QObject::setParent(\a parentPlot) in addition to this function. + + Further, you will probably want to set a layer (\ref setLayer) after calling this function, to + make the layerable appear on the QCustomPlot. + + The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized + so they can react accordingly (e.g. also initialize the parent plot of child layerables, like + QCPLayout does). +*/ +void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) +{ + if (mParentPlot) + { + qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; + return; + } + + if (!parentPlot) + qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; + + mParentPlot = parentPlot; + parentPlotInitialized(mParentPlot); +} + +/*! \internal + + Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not + become the QObject-parent (for memory management) of this layerable. + + The parent layerable has influence on the return value of the \ref realVisibility method. Only + layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be + drawn. + + \see realVisibility +*/ +void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) +{ + mParentLayerable = parentLayerable; +} + +/*! \internal + + Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to + the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is + false, the object will be appended. + + Returns true on success, i.e. if \a layer is a valid layer. +*/ +bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) +{ + if (layer && !mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (layer && layer->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; + return false; + } + + QCPLayer *oldLayer = mLayer; + if (mLayer) + mLayer->removeChild(this); + mLayer = layer; + if (mLayer) + mLayer->addChild(this, prepend); + if (mLayer != oldLayer) + Q_EMIT layerChanged(mLayer); + return true; +} + +/*! \internal + + Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a + localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is + controlled via \a overrideElement. +*/ +void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const +{ + if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(false); + else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(true); + else + painter->setAntialiasing(localAntialiased); +} + +/*! \internal + + This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting + of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the + parent plot is set at a later time. + + For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any + QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level + element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To + propagate the parent plot to all the children of the hierarchy, the top level element then uses + this function to pass the parent plot on to its child elements. + + The default implementation does nothing. + + \see initializeParentPlot +*/ +void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_UNUSED(parentPlot) +} + +/*! \internal + + Returns the selection category this layerable shall belong to. The selection category is used in + conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and + which aren't. + + Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref + QCP::iSelectOther. This is what the default implementation returns. + + \see QCustomPlot::setInteractions +*/ +QCP::Interaction QCPLayerable::selectionCategory() const +{ + return QCP::iSelectOther; +} + +/*! \internal + + Returns the clipping rectangle of this layerable object. By default, this is the viewport of the + parent QCustomPlot. Specific subclasses may reimplement this function to provide different + clipping rects. + + The returned clipping rect is set on the painter before the draw function of the respective + object is called. +*/ +QRect QCPLayerable::clipRect() const +{ + if (mParentPlot) + return mParentPlot->viewport(); + else + return QRect(); +} + +/*! \internal + + This event is called when the layerable shall be selected, as a consequence of a click by the + user. Subclasses should react to it by setting their selection state appropriately. The default + implementation does nothing. + + \a event is the mouse event that caused the selection. \a additive indicates, whether the user + was holding the multi-select-modifier while performing the selection (see \ref + QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled + (i.e. become selected when unselected and unselected when selected). + + Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. + returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). + The \a details data you output from \ref selectTest is fed back via \a details here. You may + use it to transport any kind of information from the selectTest to the possibly subsequent + selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable + that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need + to do the calculation again to find out which part was actually clicked. + + \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must + set the value either to true or false, depending on whether the selection state of this layerable + was actually changed. For layerables that only are selectable as a whole and not in parts, this + is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the + selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the + layerable was previously unselected and now is switched to the selected state. + + \see selectTest, deselectEvent +*/ +void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(additive) + Q_UNUSED(details) + Q_UNUSED(selectionStateChanged) +} + +/*! \internal + + This event is called when the layerable shall be deselected, either as consequence of a user + interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by + unsetting their selection appropriately. + + just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must + return true or false when the selection state of this layerable has changed or not changed, + respectively. + + \see selectTest, selectEvent +*/ +void QCPLayerable::deselectEvent(bool *selectionStateChanged) +{ + Q_UNUSED(selectionStateChanged) +} + +/*! + This event gets called when the user presses a mouse button while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + QCustomPlot uses an event propagation system that works the same as Qt's system. If your + layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in + its reimplementation, the event will be propagated to the next layerable in the stacking order. + + Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and + will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse + interaction (a "mouse interaction" in this context ends with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user moves the mouse while holding a mouse button, after this + layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user releases the mouse button, after this layerable has become + the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user presses the mouse button a second time in a double-click, + while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a + preceding call to \ref selectTest. + + The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the + case of a double-click, the event succession is + pressEvent – releaseEvent – doubleClickEvent – releaseEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, + it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent + and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends + with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent +*/ +void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user turns the mouse scroll wheel while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). + + The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for + single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may + accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has + very smooth steps or none at all, the delta may be smaller. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent +*/ +void QCPLayerable::wheelEvent(QWheelEvent *event) +{ + event->ignore(); +} +/* end of 'src/layer.cpp' */ + + +/* including file 'src/axis/range.cpp', size 12221 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPRange +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPRange + \brief Represents the range an axis is encompassing. + + contains a \a lower and \a upper double value and provides convenience input, output and + modification functions. + + \see QCPAxis::setRange +*/ + +/* start of documentation of inline functions */ + +/*! \fn double QCPRange::size() const + + Returns the size of the range, i.e. \a upper-\a lower +*/ + +/*! \fn double QCPRange::center() const + + Returns the center of the range, i.e. (\a upper+\a lower)*0.5 +*/ + +/*! \fn void QCPRange::normalize() + + Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are + swapped. +*/ + +/*! \fn bool QCPRange::contains(double value) const + + Returns true when \a value lies within or exactly on the borders of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator+=(const double& value) + + Adds \a value to both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator-=(const double& value) + + Subtracts \a value from both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator*=(const double& value) + + Multiplies both boundaries of the range by \a value. +*/ + +/*! \fn QCPRange &QCPRange::operator/=(const double& value) + + Divides both boundaries of the range by \a value. +*/ + +/* end of documentation of inline functions */ + +/*! + Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller + intervals would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a minimum magnitude of roughly 1e-308. + + \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining underflowing ranges. + + \see validRange, maxRange +*/ +const double QCPRange::minRange = 1e-280; + +/*! + Maximum values (negative and positive) the range will accept in range-changing functions. + Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a maximum magnitude of roughly 1e308. + + \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining overflowing ranges. + + \see validRange, minRange +*/ +const double QCPRange::maxRange = 1e250; + +/*! + Constructs a range with \a lower and \a upper set to zero. +*/ +QCPRange::QCPRange() : + lower(0), + upper(0) +{ +} + +/*! \overload + + Constructs a range with the specified \a lower and \a upper values. + + The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically + smaller than \a upper, they will be swapped. +*/ +QCPRange::QCPRange(double lower, double upper) : + lower(lower), + upper(upper) +{ + normalize(); +} + +/*! \overload + + Expands this range such that \a otherRange is contained in the new range. It is assumed that both + this range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, it will be replaced by the respective bound + of \a otherRange. + + If \a otherRange is already inside the current range, this function does nothing. + + \see expanded +*/ +void QCPRange::expand(const QCPRange &otherRange) +{ + if (lower > otherRange.lower || qIsNaN(lower)) + lower = otherRange.lower; + if (upper < otherRange.upper || qIsNaN(upper)) + upper = otherRange.upper; +} + +/*! \overload + + Expands this range such that \a includeCoord is contained in the new range. It is assumed that + this range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the respective bound will be set to \a + includeCoord. + + If \a includeCoord is already inside the current range, this function does nothing. + + \see expand +*/ +void QCPRange::expand(double includeCoord) +{ + if (lower > includeCoord || qIsNaN(lower)) + lower = includeCoord; + if (upper < includeCoord || qIsNaN(upper)) + upper = includeCoord; +} + + +/*! \overload + + Returns an expanded range that contains this and \a otherRange. It is assumed that both this + range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be taken from + \a otherRange. + + \see expand +*/ +QCPRange QCPRange::expanded(const QCPRange &otherRange) const +{ + QCPRange result = *this; + result.expand(otherRange); + return result; +} + +/*! \overload + + Returns an expanded range that includes the specified \a includeCoord. It is assumed that this + range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a + includeCoord. + + \see expand +*/ +QCPRange QCPRange::expanded(double includeCoord) const +{ + QCPRange result = *this; + result.expand(includeCoord); + return result; +} + +/*! + Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a + upperBound. If possible, the size of the current range is preserved in the process. + + If the range shall only be bounded at the lower side, you can set \a upperBound to \ref + QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref + QCPRange::maxRange. +*/ +QCPRange QCPRange::bounded(double lowerBound, double upperBound) const +{ + if (lowerBound > upperBound) + qSwap(lowerBound, upperBound); + + QCPRange result(lower, upper); + if (result.lower < lowerBound) + { + result.lower = lowerBound; + result.upper = lowerBound + size(); + if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.upper = upperBound; + } else if (result.upper > upperBound) + { + result.upper = upperBound; + result.lower = upperBound - size(); + if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.lower = lowerBound; + } + + return result; +} + +/*! + Returns a sanitized version of the range. Sanitized means for logarithmic scales, that + the range won't span the positive and negative sign domain, i.e. contain zero. Further + \a lower will always be numerically smaller (or equal) to \a upper. + + If the original range does span positive and negative sign domains or contains zero, + the returned range will try to approximate the original range as good as possible. + If the positive interval of the original range is wider than the negative interval, the + returned range will only contain the positive interval, with lower bound set to \a rangeFac or + \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval + is wider than the positive interval, this time by changing the \a upper bound. +*/ +QCPRange QCPRange::sanitizedForLogScale() const +{ + double rangeFac = 1e-3; + QCPRange sanitizedRange(lower, upper); + sanitizedRange.normalize(); + // can't have range spanning negative and positive values in log plot, so change range to fix it + //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) + if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) + { + // case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) + else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) + { + // case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) + { + // find out whether negative or positive interval is wider to decide which sign domain will be chosen + if (-sanitizedRange.lower > sanitizedRange.upper) + { + // negative is wider, do same as in case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else + { + // positive is wider, do same as in case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } + } + // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && + upper < maxRange && + qAbs(lower-upper) > minRange && + qAbs(lower-upper) < maxRange && + !(lower > 0 && qIsInf(upper/lower)) && + !(upper < 0 && qIsInf(lower/upper))); +} + +/*! + \overload + Checks, whether the specified range is within valid bounds, which are defined + as QCPRange::maxRange and QCPRange::minRange. + A valid range means: + \li range bounds within -maxRange and maxRange + \li range size above minRange + \li range size below maxRange +*/ +bool QCPRange::validRange(const QCPRange &range) +{ + return (range.lower > -maxRange && + range.upper < maxRange && + qAbs(range.lower-range.upper) > minRange && + qAbs(range.lower-range.upper) < maxRange && + !(range.lower > 0 && qIsInf(range.upper/range.lower)) && + !(range.upper < 0 && qIsInf(range.lower/range.upper))); +} +/* end of 'src/axis/range.cpp' */ + + +/* including file 'src/selection.cpp', size 21906 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataRange +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataRange + \brief Describes a data range given by begin and end index + + QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index + of a contiguous set of data points. The end index points to the data point above the last data point that's part of + the data range, similarly to the nomenclature used in standard iterators. + + Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and + modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is + used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref + QCPDataSelection is thus used. + + Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, + e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref + contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be + used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding + \ref QCPDataSelection. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and + QCPDataRange. + + \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval + in floating point plot coordinates, e.g. the current axis range. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataRange::size() const + + Returns the number of data points described by this data range. This is equal to the end index + minus the begin index. + + \see length +*/ + +/*! \fn int QCPDataRange::length() const + + Returns the number of data points described by this data range. Equivalent to \ref size. +*/ + +/*! \fn void QCPDataRange::setBegin(int begin) + + Sets the begin of this data range. The \a begin index points to the first data point that is part + of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setEnd +*/ + +/*! \fn void QCPDataRange::setEnd(int end) + + Sets the end of this data range. The \a end index points to the data point just above the last + data point that is part of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setBegin +*/ + +/*! \fn bool QCPDataRange::isValid() const + + Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and + an end index greater or equal to the begin index. + + \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods + (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's + methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary + invalid begin/end values while manipulating the range. An invalid range is not necessarily empty + (\ref isEmpty), since its \ref length can be negative and thus non-zero. +*/ + +/*! \fn bool QCPDataRange::isEmpty() const + + Returns whether this range is empty, i.e. whether its begin index equals its end index. + + \see size, length +*/ + +/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const + + Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end + indices, respectively. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataRange, with begin and end set to 0. +*/ +QCPDataRange::QCPDataRange() : + mBegin(0), + mEnd(0) +{ +} + +/*! + Creates a QCPDataRange, initialized with the specified \a begin and \a end. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). +*/ +QCPDataRange::QCPDataRange(int begin, int end) : + mBegin(begin), + mEnd(end) +{ +} + +/*! + Returns a data range that matches this data range, except that parts exceeding \a other are + excluded. + + This method is very similar to \ref intersection, with one distinction: If this range and the \a + other range share no intersection, the returned data range will be empty with begin and end set + to the respective boundary side of \a other, at which this range is residing. (\ref intersection + would just return a range with begin and end set to 0.) +*/ +QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const +{ + QCPDataRange result(intersection(other)); + if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value + { + if (mEnd <= other.mBegin) + result = QCPDataRange(other.mBegin, other.mBegin); + else + result = QCPDataRange(other.mEnd, other.mEnd); + } + return result; +} + +/*! + Returns a data range that contains both this data range as well as \a other. +*/ +QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const +{ + return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); +} + +/*! + Returns the data range which is contained in both this data range and \a other. + + This method is very similar to \ref bounded, with one distinction: If this range and the \a other + range share no intersection, the returned data range will be empty with begin and end set to 0. + (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, + depending on which side this range is on.) + + \see QCPDataSelection::intersection +*/ +QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const +{ + QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); + if (result.isValid()) + return result; + else + return QCPDataRange(); +} + +/*! + Returns whether this data range and \a other share common data points. + + \see intersection, contains +*/ +bool QCPDataRange::intersects(const QCPDataRange &other) const +{ + return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || + (mEnd <= other.mBegin && mEnd < other.mEnd) ); +} + +/*! + Returns whether all data points described by this data range are also in \a other. + + \see intersects +*/ +bool QCPDataRange::contains(const QCPDataRange &other) const +{ + return mBegin <= other.mBegin && mEnd >= other.mEnd; +} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataSelection +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataSelection + \brief Describes a data set by holding multiple QCPDataRange instances + + QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly + disjoint) set of data selection. + + The data selection can be modified with addition and subtraction operators which take + QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and + \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. + + The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange + instances. QCPDataSelection automatically simplifies when using the addition/subtraction + operators. The only case when \ref simplify is left to the user, is when calling \ref + addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data + ranges will be added to the selection successively and the overhead for simplifying after each + iteration shall be avoided. In this case, you should make sure to call \ref simplify after + completing the operation. + + Use \ref enforceType to bring the data selection into a state complying with the constraints for + selections defined in \ref QCP::SelectionType. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and + QCPDataRange. + + \section qcpdataselection-iterating Iterating over a data selection + + As an example, the following code snippet calculates the average value of a graph's data + \ref QCPAbstractPlottable::selection "selection": + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 + +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataSelection::dataRangeCount() const + + Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref + dataRange via their index. + + \see dataRange, dataPointCount +*/ + +/*! \fn QList QCPDataSelection::dataRanges() const + + Returns all data ranges that make up the data selection. If the data selection is simplified (the + usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point + index. + + \see dataRange +*/ + +/*! \fn bool QCPDataSelection::isEmpty() const + + Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection + instance. + + \see dataRangeCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataSelection. +*/ +QCPDataSelection::QCPDataSelection() +{ +} + +/*! + Creates a QCPDataSelection containing the provided \a range. +*/ +QCPDataSelection::QCPDataSelection(const QCPDataRange &range) +{ + mDataRanges.append(range); +} + +/*! + Returns true if this selection is identical (contains the same data ranges with the same begin + and end indices) to \a other. + + Note that both data selections must be in simplified state (the usual state of the selection, see + \ref simplify) for this operator to return correct results. +*/ +bool QCPDataSelection::operator==(const QCPDataSelection &other) const +{ + if (mDataRanges.size() != other.mDataRanges.size()) + return false; + for (int i=0; i= other.end()) + break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this + + if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored + { + if (thisBegin >= other.begin()) // range leading segment is encompassed + { + if (thisEnd <= other.end()) // range fully encompassed, remove completely + { + mDataRanges.removeAt(i); + continue; + } else // only leading segment is encompassed, trim accordingly + mDataRanges[i].setBegin(other.end()); + } else // leading segment is not encompassed + { + if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly + { + mDataRanges[i].setEnd(other.begin()); + } else // other lies inside this range, so split range + { + mDataRanges[i].setEnd(other.begin()); + mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); + break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here + } + } + } + ++i; + } + + return *this; +} + +/*! + Returns the total number of data points contained in all data ranges that make up this data + selection. +*/ +int QCPDataSelection::dataPointCount() const +{ + int result = 0; + for (int i=0; i= 0 && index < mDataRanges.size()) + { + return mDataRanges.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of range:" << index; + return QCPDataRange(); + } +} + +/*! + Returns a \ref QCPDataRange which spans the entire data selection, including possible + intermediate segments which are not part of the original data selection. +*/ +QCPDataRange QCPDataSelection::span() const +{ + if (isEmpty()) + return QCPDataRange(); + else + return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); +} + +/*! + Adds the given \a dataRange to this data selection. This is equivalent to the += operator but + allows disabling immediate simplification by setting \a simplify to false. This can improve + performance if adding a very large amount of data ranges successively. In this case, make sure to + call \ref simplify manually, after the operation. +*/ +void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) +{ + mDataRanges.append(dataRange); + if (simplify) + this->simplify(); +} + +/*! + Removes all data ranges. The data selection then contains no data points. + + \ref isEmpty +*/ +void QCPDataSelection::clear() +{ + mDataRanges.clear(); +} + +/*! + Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent + or overlapping ranges. This can reduce the number of individual data ranges in the selection, and + prevents possible double-counting when iterating over the data points held by the data ranges. + + This method is automatically called when using the addition/subtraction operators. The only case + when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a + simplify explicitly set to false. +*/ +void QCPDataSelection::simplify() +{ + // remove any empty ranges: + for (int i=mDataRanges.size()-1; i>=0; --i) + { + if (mDataRanges.at(i).isEmpty()) + mDataRanges.removeAt(i); + } + if (mDataRanges.isEmpty()) + return; + + // sort ranges by starting value, ascending: + std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); + + // join overlapping/contiguous ranges: + int i = 1; + while (i < mDataRanges.size()) + { + if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list + { + mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); + mDataRanges.removeAt(i); + } else + ++i; + } +} + +/*! + Makes sure this data selection conforms to the specified \a type selection type. Before the type + is enforced, \ref simplify is called. + + Depending on \a type, enforcing means adding new data points that were previously not part of the + selection, or removing data points from the selection. If the current selection already conforms + to \a type, the data selection is not changed. + + \see QCP::SelectionType +*/ +void QCPDataSelection::enforceType(QCP::SelectionType type) +{ + simplify(); + switch (type) + { + case QCP::stNone: + { + mDataRanges.clear(); + break; + } + case QCP::stWhole: + { + // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) + break; + } + case QCP::stSingleData: + { + // reduce all data ranges to the single first data point: + if (!mDataRanges.isEmpty()) + { + if (mDataRanges.size() > 1) + mDataRanges = QList() << mDataRanges.first(); + if (mDataRanges.first().length() > 1) + mDataRanges.first().setEnd(mDataRanges.first().begin()+1); + } + break; + } + case QCP::stDataRange: + { + mDataRanges = QList() << span(); + break; + } + case QCP::stMultipleDataRanges: + { + // this is the selection type that allows all concievable combinations of ranges, so do nothing + break; + } + } +} + +/*! + Returns true if the data selection \a other is contained entirely in this data selection, i.e. + all data point indices that are in \a other are also in this data selection. + + \see QCPDataRange::contains +*/ +bool QCPDataSelection::contains(const QCPDataSelection &other) const +{ + if (other.isEmpty()) return false; + + int otherIndex = 0; + int thisIndex = 0; + while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) + { + if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) + ++otherIndex; + else + ++thisIndex; + } + return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this +} + +/*! + Returns a data selection containing the points which are both in this data selection and in the + data range \a other. + + A common use case is to limit an unknown data selection to the valid range of a data container, + using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned + data selection without exceeding the data container's bounds. +*/ +QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const +{ + QCPDataSelection result; + for (int i=0; iorientation() == Qt::Horizontal) + return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); + else + return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); + } else + { + qDebug() << Q_FUNC_INFO << "called with axis zero"; + return QCPRange(); + } +} + +/*! + Sets the pen that will be used to draw the selection rect outline. + + \see setBrush +*/ +void QCPSelectionRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used to fill the selection rect. By default the selection rect is not + filled, i.e. \a brush is Qt::NoBrush. + + \see setPen +*/ +void QCPSelectionRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + If there is currently a selection interaction going on (\ref isActive), the interaction is + canceled. The selection rect will emit the \ref canceled signal. +*/ +void QCPSelectionRect::cancel() +{ + if (mActive) + { + mActive = false; + Q_EMIT canceled(mRect, 0); + } +} + +/*! \internal + + This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. + The default implementation sets the selection rect to active, initializes the selection rect + geometry and emits the \ref started signal. +*/ +void QCPSelectionRect::startSelection(QMouseEvent *event) +{ + mActive = true; + mRect = QRect(event->pos(), event->pos()); + Q_EMIT started(event); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs + to update its geometry. The default implementation updates the rect and emits the \ref changed + signal. +*/ +void QCPSelectionRect::moveSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + Q_EMIT changed(mRect, event); + layer()->replot(); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has + finished by the user releasing the mouse button. The default implementation deactivates the + selection rect and emits the \ref accepted signal. +*/ +void QCPSelectionRect::endSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + mActive = false; + Q_EMIT accepted(mRect, event); +} + +/*! \internal + + This method is called by QCustomPlot when a key has been pressed by the user while the selection + rect interaction is active. The default implementation allows to \ref cancel the interaction by + hitting the escape key. +*/ +void QCPSelectionRect::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape && mActive) + { + mActive = false; + Q_EMIT canceled(mRect, event); + } +} + +/* inherits documentation from base class */ +void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/*! \internal + + If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. + + \seebaseclassmethod +*/ +void QCPSelectionRect::draw(QCPPainter *painter) +{ + if (mActive) + { + painter->setPen(mPen); + painter->setBrush(mBrush); + painter->drawRect(mRect); + } +} +/* end of 'src/selectionrect.cpp' */ + + +/* including file 'src/layout.cpp', size 79064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPMarginGroup +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPMarginGroup + \brief A margin group allows synchronization of margin sides if working with multiple layout elements. + + QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that + they will all have the same size, based on the largest required margin in the group. + + \n + \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" + \n + + In certain situations it is desirable that margins at specific sides are synchronized across + layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will + provide a cleaner look to the user if the left and right margins of the two axis rects are of the + same size. The left axis of the top axis rect will then be at the same horizontal position as the + left axis of the lower axis rect, making them appear aligned. The same applies for the right + axes. This is what QCPMarginGroup makes possible. + + To add/remove a specific side of a layout element to/from a margin group, use the \ref + QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call + \ref clear, or just delete the margin group. + + \section QCPMarginGroup-example Example + + First create a margin group: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 + Then set this group on the layout element sides: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 + Here, we've used the first two axis rects of the plot and synchronized their left margins with + each other and their right margins with each other. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const + + Returns a list of all layout elements that have their margin \a side associated with this margin + group. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPMarginGroup instance in \a parentPlot. +*/ +QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot) +{ + mChildren.insert(QCP::msLeft, QList()); + mChildren.insert(QCP::msRight, QList()); + mChildren.insert(QCP::msTop, QList()); + mChildren.insert(QCP::msBottom, QList()); +} + +QCPMarginGroup::~QCPMarginGroup() +{ + clear(); +} + +/*! + Returns whether this margin group is empty. If this function returns true, no layout elements use + this margin group to synchronize margin sides. +*/ +bool QCPMarginGroup::isEmpty() const +{ + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + if (!it.value().isEmpty()) + return false; + } + return true; +} + +/*! + Clears this margin group. The synchronization of the margin sides that use this margin group is + lifted and they will use their individual margin sizes again. +*/ +void QCPMarginGroup::clear() +{ + // make all children remove themselves from this margin group: + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + const QList elements = it.value(); + for (int i=elements.size()-1; i>=0; --i) + elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild + } +} + +/*! \internal + + Returns the synchronized common margin for \a side. This is the margin value that will be used by + the layout element on the respective side, if it is part of this margin group. + + The common margin is calculated by requesting the automatic margin (\ref + QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin + group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into + account, too.) +*/ +int QCPMarginGroup::commonMargin(QCP::MarginSide side) const +{ + // query all automatic margins of the layout elements in this margin group side and find maximum: + int result = 0; + const QList elements = mChildren.value(side); + for (int i=0; iautoMargins().testFlag(side)) + continue; + int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); + if (m > result) + result = m; + } + return result; +} + +/*! \internal + + Adds \a element to the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].contains(element)) + mChildren[side].append(element); + else + qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); +} + +/*! \internal + + Removes \a element from the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].removeOne(element)) + qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutElement + \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". + + This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. + + A Layout element is a rectangular object which can be placed in layouts. It has an outer rect + (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference + between outer and inner rect is called its margin. The margin can either be set to automatic or + manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be + set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, + the layout element subclass will control the value itself (via \ref calculateAutoMargin). + + Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level + layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref + QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. + + Thus in QCustomPlot one can divide layout elements into two categories: The ones that are + invisible by themselves, because they don't draw anything. Their only purpose is to manage the + position and size of other layout elements. This category of layout elements usually use + QCPLayout as base class. Then there is the category of layout elements which actually draw + something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does + not necessarily mean that the latter category can't have child layout elements. QCPLegend for + instance, actually derives from QCPLayoutGrid and the individual legend items are child layout + elements in the grid layout. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayout *QCPLayoutElement::layout() const + + Returns the parent layout of this layout element. +*/ + +/*! \fn QRect QCPLayoutElement::rect() const + + Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref + setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). + + In some cases, the area between outer and inner rect is left blank. In other cases the margin + area is used to display peripheral graphics while the main content is in the inner rect. This is + where automatic margin calculation becomes interesting because it allows the layout element to + adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect + draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if + \ref setAutoMargins is enabled) according to the space required by the labels of the axes. + + \see outerRect +*/ + +/*! \fn QRect QCPLayoutElement::outerRect() const + + Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the + margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref + setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. + + \see rect +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutElement and sets default values. +*/ +QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) + mParentLayout(0), + mMinimumSize(), + mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), + mSizeConstraintRect(scrInnerRect), + mRect(0, 0, 0, 0), + mOuterRect(0, 0, 0, 0), + mMargins(0, 0, 0, 0), + mMinimumMargins(0, 0, 0, 0), + mAutoMargins(QCP::msAll) +{ +} + +QCPLayoutElement::~QCPLayoutElement() +{ + setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any + // unregister at layout: + if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor + mParentLayout->take(this); +} + +/*! + Sets the outer rect of this layout element. If the layout element is inside a layout, the layout + sets the position and size of this layout element using this function. + + Calling this function externally has no effect, since the layout will overwrite any changes to + the outer rect upon the next replot. + + The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. + + \see rect +*/ +void QCPLayoutElement::setOuterRect(const QRect &rect) +{ + if (mOuterRect != rect) + { + mOuterRect = rect; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all + sides, this function is used to manually set the margin on those sides. Sides that are still set + to be handled automatically are ignored and may have any value in \a margins. + + The margin is the distance between the outer rect (controlled by the parent layout via \ref + setOuterRect) and the inner \ref rect (which usually contains the main content of this layout + element). + + \see setAutoMargins +*/ +void QCPLayoutElement::setMargins(const QMargins &margins) +{ + if (mMargins != margins) + { + mMargins = margins; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + If \ref setAutoMargins is enabled on some or all margins, this function is used to provide + minimum values for those margins. + + The minimum values are not enforced on margin sides that were set to be under manual control via + \ref setAutoMargins. + + \see setAutoMargins +*/ +void QCPLayoutElement::setMinimumMargins(const QMargins &margins) +{ + if (mMinimumMargins != margins) + { + mMinimumMargins = margins; + } +} + +/*! + Sets on which sides the margin shall be calculated automatically. If a side is calculated + automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is + set to be controlled manually, the value may be specified with \ref setMargins. + + Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref + setMarginGroup), to synchronize (align) it with other layout elements in the plot. + + \see setMinimumMargins, setMargins, QCP::MarginSide +*/ +void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) +{ + mAutoMargins = sides; +} + +/*! + Sets the minimum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + If the parent layout size is not sufficient to satisfy all minimum size constraints of its child + layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot + propagates the layout's size constraints to the outside by setting its own minimum QWidget size + accordingly, so violations of \a size should be exceptions. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(const QSize &size) +{ + if (mMinimumSize != size) + { + mMinimumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the minimum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(int width, int height) +{ + setMinimumSize(QSize(width, height)); +} + +/*! + Sets the maximum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(const QSize &size) +{ + if (mMaximumSize != size) + { + mMaximumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the maximum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(int width, int height) +{ + setMaximumSize(QSize(width, height)); +} + +/*! + Sets to which rect of a layout element the size constraints apply. Size constraints can be set + via \ref setMinimumSize and \ref setMaximumSize. + + The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis + labels), whereas the inner rect (\ref rect) does not. + + \see setMinimumSize, setMaximumSize +*/ +void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) +{ + if (mSizeConstraintRect != constraintRect) + { + mSizeConstraintRect = constraintRect; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! + Sets the margin \a group of the specified margin \a sides. + + Margin groups allow synchronizing specified margins across layout elements, see the documentation + of \ref QCPMarginGroup. + + To unset the margin group of \a sides, set \a group to 0. + + Note that margin groups only work for margin sides that are set to automatic (\ref + setAutoMargins). + + \see QCP::MarginSide +*/ +void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) +{ + QVector sideVector; + if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); + if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); + if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); + if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); + + for (int i=0; iremoveChild(side, this); + + if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there + { + mMarginGroups.remove(side); + } else // setting to a new group + { + mMarginGroups[side] = group; + group->addChild(side, this); + } + } + } +} + +/*! + Updates the layout element and sub-elements. This function is automatically called before every + replot by the parent layout element. It is called multiple times, once for every \ref + UpdatePhase. The phases are run through in the order of the enum values. For details about what + happens at the different phases, see the documentation of \ref UpdatePhase. + + Layout elements that have child elements should call the \ref update method of their child + elements, and pass the current \a phase unchanged. + + The default implementation executes the automatic margin mechanism in the \ref upMargins phase. + Subclasses should make sure to call the base class implementation. +*/ +void QCPLayoutElement::update(UpdatePhase phase) +{ + if (phase == upMargins) + { + if (mAutoMargins != QCP::msNone) + { + // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: + QMargins newMargins = mMargins; + QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; + Q_FOREACH (QCP::MarginSide side, allMarginSides) + { + if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically + { + if (mMarginGroups.contains(side)) + QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group + else + QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly + // apply minimum margin restrictions: + if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) + QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); + } + } + setMargins(newMargins); + } + } +} + +/*! + Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, + if no manual minimum size is set. + + if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size + (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum + allowed size of this layout element. + + A manual minimum size is considered set if it is non-zero. + + The default implementation simply returns the sum of the horizontal margins for the width and the + sum of the vertical margins for the height. Reimplementations may use their detailed knowledge + about the layout element's content to provide size hints. +*/ +QSize QCPLayoutElement::minimumOuterSizeHint() const +{ + return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); +} + +/*! + Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, + if no manual maximum size is set. + + if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned + size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the + maximum allowed size of this layout element. + + A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. + + The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying + no suggested maximum size. Reimplementations may use their detailed knowledge about the layout + element's content to provide size hints. +*/ +QSize QCPLayoutElement::maximumOuterSizeHint() const +{ + return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +} + +/*! + Returns a list of all child elements in this layout element. If \a recursive is true, all + sub-child elements are included in the list, too. + + \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have + empty cells which yield 0 at the respective index.) +*/ +QList QCPLayoutElement::elements(bool recursive) const +{ + Q_UNUSED(recursive) + return QList(); +} + +/*! + Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer + rect, this method returns a value corresponding to 0.99 times the parent plot's selection + tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is + true, -1.0 is returned. + + See \ref QCPLayerable::selectTest for a general explanation of this virtual method. + + QCPLayoutElement subclasses may reimplement this method to provide more specific selection test + behaviour. +*/ +double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + + if (onlySelectable) + return -1; + + if (QRectF(mOuterRect).contains(pos)) + { + if (mParentPlot) + return mParentPlot->selectionTolerance()*0.99; + else + { + qDebug() << Q_FUNC_INFO << "parent plot not defined"; + return -1; + } + } else + return -1; +} + +/*! \internal + + propagates the parent plot initialization to all child elements, by calling \ref + QCPLayerable::initializeParentPlot on them. +*/ +void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_FOREACH (QCPLayoutElement* el, elements(false)) + { + if (!el->parentPlot()) + el->initializeParentPlot(parentPlot); + } +} + +/*! \internal + + Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a + side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the + returned value will not be smaller than the specified minimum margin. + + The default implementation just returns the respective manual margin (\ref setMargins) or the + minimum margin, whichever is larger. +*/ +int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) +{ + return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); +} + +/*! \internal + + This virtual method is called when this layout element was moved to a different QCPLayout, or + when this layout element has changed its logical position (e.g. row and/or column) within the + same QCPLayout. Subclasses may use this to react accordingly. + + Since this method is called after the completion of the move, you can access the new parent + layout via \ref layout(). + + The default implementation does nothing. +*/ +void QCPLayoutElement::layoutChanged() +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayout +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayout + \brief The abstract base class for layouts + + This is an abstract base class for layout elements whose main purpose is to define the position + and size of other child layout elements. In most cases, layouts don't draw anything themselves + (but there are exceptions to this, e.g. QCPLegend). + + QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. + + QCPLayout introduces a common interface for accessing and manipulating the child elements. Those + functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref + simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions + to this interface which are more specialized to the form of the layout. For example, \ref + QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid + more conveniently. + + Since this is an abstract base class, you can't instantiate it directly. Rather use one of its + subclasses like QCPLayoutGrid or QCPLayoutInset. + + For a general introduction to the layout system, see the dedicated documentation page \ref + thelayoutsystem "The Layout System". +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPLayout::elementCount() const = 0 + + Returns the number of elements/cells in the layout. + + \see elements, elementAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 + + Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. + + Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. + QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check + whether a cell is empty or not. + + \see elements, elementCount, takeAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 + + Removes the element with the given \a index from the layout and returns it. + + If the \a index is invalid or the cell with that index is empty, returns 0. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see elementAt, take +*/ + +/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 + + Removes the specified \a element from the layout and returns true on success. + + If the \a element isn't in this layout, returns false. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see takeAt +*/ + +/* end documentation of pure virtual functions */ + +/*! + Creates an instance of QCPLayout and sets default values. Note that since QCPLayout + is an abstract base class, it can't be instantiated directly. +*/ +QCPLayout::QCPLayout() +{ +} + +/*! + If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to + reposition and resize their cells. + + Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". + + For details about this method and the update phases, see the documentation of \ref + QCPLayoutElement::update. +*/ +void QCPLayout::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + // set child element rects according to layout: + if (phase == upLayout) + updateLayout(); + + // propagate update call to child elements: + const int elCount = elementCount(); + for (int i=0; iupdate(phase); + } +} + +/* inherits documentation from base class */ +QList QCPLayout::elements(bool recursive) const +{ + const int c = elementCount(); + QList result; +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(c); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the + default implementation does nothing. + + Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit + simplification while QCPLayoutGrid does. +*/ +void QCPLayout::simplify() +{ +} + +/*! + Removes and deletes the element at the provided \a index. Returns true on success. If \a index is + invalid or points to an empty cell, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the returned element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see remove, takeAt +*/ +bool QCPLayout::removeAt(int index) +{ + if (QCPLayoutElement *el = takeAt(index)) + { + delete el; + return true; + } else + return false; +} + +/*! + Removes and deletes the provided \a element. Returns true on success. If \a element is not in the + layout, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see removeAt, take +*/ +bool QCPLayout::remove(QCPLayoutElement *element) +{ + if (take(element)) + { + delete element; + return true; + } else + return false; +} + +/*! + Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure + all empty cells are collapsed. + + \see remove, removeAt +*/ +void QCPLayout::clear() +{ + for (int i=elementCount()-1; i>=0; --i) + { + if (elementAt(i)) + removeAt(i); + } + simplify(); +} + +/*! + Subclasses call this method to report changed (minimum/maximum) size constraints. + + If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref + sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of + QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, + it may update itself and resize cells accordingly. +*/ +void QCPLayout::sizeConstraintsChanged() const +{ + if (QWidget *w = qobject_cast(parent())) + w->updateGeometry(); + else if (QCPLayout *l = qobject_cast(parent())) + l->sizeConstraintsChanged(); +} + +/*! \internal + + Subclasses reimplement this method to update the position and sizes of the child elements/cells + via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. + + The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay + within that rect. + + \ref getSectionSizes may help with the reimplementation of this function. + + \see update +*/ +void QCPLayout::updateLayout() +{ +} + + +/*! \internal + + Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the + \ref QCPLayerable::parentLayerable and the QObject parent to this layout. + + Further, if \a el didn't previously have a parent plot, calls \ref + QCPLayerable::initializeParentPlot on \a el to set the paret plot. + + This method is used by subclass specific methods that add elements to the layout. Note that this + method only changes properties in \a el. The removal from the old layout and the insertion into + the new layout must be done additionally. +*/ +void QCPLayout::adoptElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = this; + el->setParentLayerable(this); + el->setParent(this); + if (!el->parentPlot()) + el->initializeParentPlot(mParentPlot); + el->layoutChanged(); + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout + and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent + QCustomPlot. + + This method is used by subclass specific methods that remove elements from the layout (e.g. \ref + take or \ref takeAt). Note that this method only changes properties in \a el. The removal from + the old layout must be done additionally. +*/ +void QCPLayout::releaseElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = 0; + el->setParentLayerable(0); + el->setParent(mParentPlot); + // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + This is a helper function for the implementation of \ref updateLayout in subclasses. + + It calculates the sizes of one-dimensional sections with provided constraints on maximum section + sizes, minimum section sizes, relative stretch factors and the final total size of all sections. + + The QVector entries refer to the sections. Thus all QVectors must have the same size. + + \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size + imposed, set all vector values to Qt's QWIDGETSIZE_MAX. + + \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size + imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than + \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, + not exceeding the allowed total size is taken to be more important than not going below minimum + section sizes.) + + \a stretchFactors give the relative proportions of the sections to each other. If all sections + shall be scaled equally, set all values equal. If the first section shall be double the size of + each individual other section, set the first number of \a stretchFactors to double the value of + the other individual values (e.g. {2, 1, 1, 1}). + + \a totalSize is the value that the final section sizes will add up to. Due to rounding, the + actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, + you could distribute the remaining difference on the sections. + + The return value is a QVector containing the section sizes. +*/ +QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const +{ + if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) + { + qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; + return QVector(); + } + if (stretchFactors.isEmpty()) + return QVector(); + int sectionCount = stretchFactors.size(); + QVector sectionSizes(sectionCount); + // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): + int minSizeSum = 0; + for (int i=0; i minimumLockedSections; + QList unfinishedSections; + for (int i=0; i result(sectionCount); + for (int i=0; iminimumOuterSizeHint(); + QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) + if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rwidth() += el->margins().left() + el->margins().right(); + if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; +} + +/*! \internal + + This is a helper function for the implementation of subclasses. + + It returns the maximum size that should finally be used for the outer rect of the passed layout + element \a el. + + It takes into account whether a manual maximum size is set (\ref + QCPLayoutElement::setMaximumSize), which size constraint is set (\ref + QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum + size was set (\ref QCPLayoutElement::maximumOuterSizeHint). +*/ +QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) +{ + QSize maxOuterHint = el->maximumOuterSizeHint(); + QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) + if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rwidth() += el->margins().left() + el->margins().right(); + if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutGrid + \brief A layout that arranges child elements in a grid + + Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, + \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). + + Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or + column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref + hasElement, that element can be retrieved with \ref element. If rows and columns that only have + empty cells shall be removed, call \ref simplify. Removal of elements is either done by just + adding the element to a different layout or by using the QCPLayout interface \ref take or \ref + remove. + + If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a + column, the grid layout will choose the position according to the current \ref setFillOrder and + the wrapping (\ref setWrap). + + Row and column insertion can be performed with \ref insertRow and \ref insertColumn. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPLayoutGrid::rowCount() const + + Returns the number of rows in the layout. + + \see columnCount +*/ + +/*! \fn int QCPLayoutGrid::columnCount() const + + Returns the number of columns in the layout. + + \see rowCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutGrid and sets default values. +*/ +QCPLayoutGrid::QCPLayoutGrid() : + mColumnSpacing(5), + mRowSpacing(5), + mWrap(0), + mFillOrder(foRowsFirst) +{ +} + +QCPLayoutGrid::~QCPLayoutGrid() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the element in the cell in \a row and \a column. + + Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug + message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. + + \see addElement, hasElement +*/ +QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const +{ + if (row >= 0 && row < mElements.size()) + { + if (column >= 0 && column < mElements.first().size()) + { + if (QCPLayoutElement *result = mElements.at(row).at(column)) + return result; + else + qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; + return 0; +} + + +/*! \overload + + Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it + is first removed from there. If \a row or \a column don't exist yet, the layout is expanded + accordingly. + + Returns true if the element was added successfully, i.e. if the cell at \a row and \a column + didn't already have an element. + + Use the overload of this method without explicit row/column index to place the element according + to the configured fill order and wrapping settings. + + \see element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) +{ + if (!hasElement(row, column)) + { + if (element && element->layout()) // remove from old layout first + element->layout()->take(element); + expandTo(row+1, column+1); + mElements[row][column] = element; + if (element) + adoptElement(element); + return true; + } else + qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; + return false; +} + +/*! \overload + + Adds the \a element to the next empty cell according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first + removed from there. If necessary, the layout is expanded to hold the new element. + + Returns true if the element was added successfully. + + \see setFillOrder, setWrap, element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(QCPLayoutElement *element) +{ + int rowIndex = 0; + int colIndex = 0; + if (mFillOrder == foColumnsFirst) + { + while (hasElement(rowIndex, colIndex)) + { + ++colIndex; + if (colIndex >= mWrap && mWrap > 0) + { + colIndex = 0; + ++rowIndex; + } + } + } else + { + while (hasElement(rowIndex, colIndex)) + { + ++rowIndex; + if (rowIndex >= mWrap && mWrap > 0) + { + rowIndex = 0; + ++colIndex; + } + } + } + return addElement(rowIndex, colIndex, element); +} + +/*! + Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't + empty. + + \see element +*/ +bool QCPLayoutGrid::hasElement(int row, int column) +{ + if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) + return mElements.at(row).at(column); + else + return false; +} + +/*! + Sets the stretch \a factor of \a column. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactors, setRowStretchFactor +*/ +void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) +{ + if (column >= 0 && column < columnCount()) + { + if (factor > 0) + mColumnStretchFactors[column] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid column:" << column; +} + +/*! + Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactor, setRowStretchFactors +*/ +void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) +{ + if (factors.size() == mColumnStretchFactors.size()) + { + mColumnStretchFactors = factors; + for (int i=0; i= 0 && row < rowCount()) + { + if (factor > 0) + mRowStretchFactors[row] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid row:" << row; +} + +/*! + Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setRowStretchFactor, setColumnStretchFactors +*/ +void QCPLayoutGrid::setRowStretchFactors(const QList &factors) +{ + if (factors.size() == mRowStretchFactors.size()) + { + mRowStretchFactors = factors; + for (int i=0; i tempElements; + if (rearrange) + { + tempElements.reserve(elCount); + for (int i=0; i()); + mRowStretchFactors.append(1); + } + // go through rows and expand columns as necessary: + int newColCount = qMax(columnCount(), newColumnCount); + for (int i=0; i rowCount()) + newIndex = rowCount(); + + mRowStretchFactors.insert(newIndex, 1); + QList newRow; + for (int col=0; col columnCount()) + newIndex = columnCount(); + + mColumnStretchFactors.insert(newIndex, 1); + for (int row=0; row= 0 && row < rowCount()) + { + if (column >= 0 && column < columnCount()) + { + switch (mFillOrder) + { + case foRowsFirst: return column*rowCount() + row; + case foColumnsFirst: return row*columnCount() + column; + } + } else + qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; + } else + qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; + return 0; +} + +/*! + Converts the linear index to row and column indices and writes the result to \a row and \a + column. + + The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the + indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices + increase top to bottom and then left to right. + + If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. + + For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, + i.e. greater or equal to zero and smaller than the current \ref elementCount. + + \see rowColToIndex +*/ +void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const +{ + row = -1; + column = -1; + const int nCols = columnCount(); + const int nRows = rowCount(); + if (nCols == 0 || nRows == 0) + return; + if (index < 0 || index >= elementCount()) + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return; + } + + switch (mFillOrder) + { + case foRowsFirst: + { + column = index / nRows; + row = index % nRows; + break; + } + case foColumnsFirst: + { + row = index / nCols; + column = index % nCols; + break; + } + } +} + +/* inherits documentation from base class */ +void QCPLayoutGrid::updateLayout() +{ + QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + int totalRowSpacing = (rowCount()-1) * mRowSpacing; + int totalColSpacing = (columnCount()-1) * mColumnSpacing; + QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); + QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); + + // go through cells and set rects accordingly: + int yOffset = mRect.top(); + for (int row=0; row 0) + yOffset += rowHeights.at(row-1)+mRowSpacing; + int xOffset = mRect.left(); + for (int col=0; col 0) + xOffset += colWidths.at(col-1)+mColumnSpacing; + if (mElements.at(row).at(col)) + mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); + } + } +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const +{ + if (index >= 0 && index < elementCount()) + { + int row, col; + indexToRowCol(index, row, col); + return mElements.at(row).at(col); + } else + return 0; +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + int row, col; + indexToRowCol(index, row, col); + mElements[row][col] = 0; + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutGrid::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; i QCPLayoutGrid::elements(bool recursive) const +{ + QList result; + const int elCount = elementCount(); +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(elCount); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing rows and columns which only contain empty cells. +*/ +void QCPLayoutGrid::simplify() +{ + // remove rows with only empty cells: + for (int row=rowCount()-1; row>=0; --row) + { + bool hasElements = false; + for (int col=0; col=0; --col) + { + bool hasElements = false; + for (int row=0; row minColWidths, minRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + QSize result(0, 0); + for (int i=0; i maxColWidths, maxRowHeights; + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + QSize result(0, 0); + for (int i=0; i QWIDGETSIZE_MAX) + result.setHeight(QWIDGETSIZE_MAX); + if (result.width() > QWIDGETSIZE_MAX) + result.setWidth(QWIDGETSIZE_MAX); + return result; +} + +/*! \internal + + Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights + respectively. + + The minimum height of a row is the largest minimum height of any element's outer rect in that + row. The minimum width of a column is the largest minimum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMaximumRowColSizes +*/ +void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const +{ + *minColWidths = QVector(columnCount(), 0); + *minRowHeights = QVector(rowCount(), 0); + for (int row=0; rowat(col) < minSize.width()) + (*minColWidths)[col] = minSize.width(); + if (minRowHeights->at(row) < minSize.height()) + (*minRowHeights)[row] = minSize.height(); + } + } + } +} + +/*! \internal + + Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights + respectively. + + The maximum height of a row is the smallest maximum height of any element's outer rect in that + row. The maximum width of a column is the smallest maximum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMinimumRowColSizes +*/ +void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const +{ + *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); + *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); + for (int row=0; rowat(col) > maxSize.width()) + (*maxColWidths)[col] = maxSize.width(); + if (maxRowHeights->at(row) > maxSize.height()) + (*maxRowHeights)[row] = maxSize.height(); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutInset +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPLayoutInset + \brief A layout that places child elements aligned to the border or arbitrarily positioned + + Elements are placed either aligned to the border or at arbitrary position in the area of the + layout. Which placement applies is controlled with the \ref InsetPlacement (\ref + setInsetPlacement). + + Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or + addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset + placement will default to \ref ipBorderAligned and the element will be aligned according to the + \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at + arbitrary position and size, defined by \a rect. + + The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. + + This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual void QCPLayoutInset::simplify() + + The QCPInsetLayout does not need simplification since it can never have empty cells due to its + linear index structure. This method does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutInset and sets default values. +*/ +QCPLayoutInset::QCPLayoutInset() +{ +} + +QCPLayoutInset::~QCPLayoutInset() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the placement type of the element with the specified \a index. +*/ +QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const +{ + if (elementAt(index)) + return mInsetPlacement.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return ipFree; + } +} + +/*! + Returns the alignment of the element with the specified \a index. The alignment only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. +*/ +Qt::Alignment QCPLayoutInset::insetAlignment(int index) const +{ + if (elementAt(index)) + return mInsetAlignment.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return 0; + } +} + +/*! + Returns the rect of the element with the specified \a index. The rect only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. +*/ +QRectF QCPLayoutInset::insetRect(int index) const +{ + if (elementAt(index)) + return mInsetRect.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return QRectF(); + } +} + +/*! + Sets the inset placement type of the element with the specified \a index to \a placement. + + \see InsetPlacement +*/ +void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) +{ + if (elementAt(index)) + mInsetPlacement[index] = placement; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function + is used to set the alignment of the element with the specified \a index to \a alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. +*/ +void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) +{ + if (elementAt(index)) + mInsetAlignment[index] = alignment; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the + position and size of the element with the specified \a index to \a rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + Note that the minimum and maximum sizes of the embedded element (\ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. +*/ +void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) +{ + if (elementAt(index)) + mInsetRect[index] = rect; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/* inherits documentation from base class */ +void QCPLayoutInset::updateLayout() +{ + for (int i=0; i finalMaxSize.width()) + insetRect.setWidth(finalMaxSize.width()); + if (insetRect.size().height() > finalMaxSize.height()) + insetRect.setHeight(finalMaxSize.height()); + } else if (mInsetPlacement.at(i) == ipBorderAligned) + { + insetRect.setSize(finalMinSize); + Qt::Alignment al = mInsetAlignment.at(i); + if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); + else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); + else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter + if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); + else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); + else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter + } + mElements.at(i)->setOuterRect(insetRect); + } +} + +/* inherits documentation from base class */ +int QCPLayoutInset::elementCount() const +{ + return mElements.size(); +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::elementAt(int index) const +{ + if (index >= 0 && index < mElements.size()) + return mElements.at(index); + else + return 0; +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + mElements.removeAt(index); + mInsetPlacement.removeAt(index); + mInsetAlignment.removeAt(index); + mInsetRect.removeAt(index); + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutInset::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/*! + Adds the specified \a element to the layout as an inset aligned at the border (\ref + setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a + alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. + + \see addElement(QCPLayoutElement *element, const QRectF &rect) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipBorderAligned); + mInsetAlignment.append(alignment); + mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} + +/*! + Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref + setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a + rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipFree); + mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); + mInsetRect.append(rect); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} +/* end of 'src/layout.cpp' */ + + +/* including file 'src/lineending.cpp', size 11536 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLineEnding +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLineEnding + \brief Handles the different ending decorations for line-like items + + \image html QCPLineEnding.png "The various ending styles currently supported" + + For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine + has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. + + The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can + be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of + the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. + For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite + directions, e.g. "outward". This can be changed by \ref setInverted, which would make the + respective arrow point inward. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify a + QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. + \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead +*/ + +/*! + Creates a QCPLineEnding instance with default values (style \ref esNone). +*/ +QCPLineEnding::QCPLineEnding() : + mStyle(esNone), + mWidth(8), + mLength(10), + mInverted(false) +{ +} + +/*! + Creates a QCPLineEnding instance with the specified values. +*/ +QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : + mStyle(style), + mWidth(width), + mLength(length), + mInverted(inverted) +{ +} + +/*! + Sets the style of the ending decoration. +*/ +void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) +{ + mStyle = style; +} + +/*! + Sets the width of the ending decoration, if the style supports it. On arrows, for example, the + width defines the size perpendicular to the arrow's pointing direction. + + \see setLength +*/ +void QCPLineEnding::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the length of the ending decoration, if the style supports it. On arrows, for example, the + length defines the size in pointing direction. + + \see setWidth +*/ +void QCPLineEnding::setLength(double length) +{ + mLength = length; +} + +/*! + Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point + inward when \a inverted is set to true. + + Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or + discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are + affected by it, which can be used to control to which side the half bar points to. +*/ +void QCPLineEnding::setInverted(bool inverted) +{ + mInverted = inverted; +} + +/*! \internal + + Returns the maximum pixel radius the ending decoration might cover, starting from the position + the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). + + This is relevant for clipping. Only omit painting of the decoration when the position where the + decoration is supposed to be drawn is farther away from the clipping rect than the returned + distance. +*/ +double QCPLineEnding::boundingDistance() const +{ + switch (mStyle) + { + case esNone: + return 0; + + case esFlatArrow: + case esSpikeArrow: + case esLineArrow: + case esSkewedBar: + return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length + + case esDisc: + case esSquare: + case esDiamond: + case esBar: + case esHalfBar: + return mWidth*1.42; // items that only have a width -> width*sqrt(2) + + } + return 0; +} + +/*! + Starting from the origin of this line ending (which is style specific), returns the length + covered by the line ending symbol, in backward direction. + + For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if + both have the same \ref setLength value, because the spike arrow has an inward curved back, which + reduces the length along its center axis (the drawing origin for arrows is at the tip). + + This function is used for precise, style specific placement of line endings, for example in + QCPAxes. +*/ +double QCPLineEnding::realLength() const +{ + switch (mStyle) + { + case esNone: + case esLineArrow: + case esSkewedBar: + case esBar: + case esHalfBar: + return 0; + + case esFlatArrow: + return mLength; + + case esDisc: + case esSquare: + case esDiamond: + return mWidth*0.5; + + case esSpikeArrow: + return mLength*0.8; + } + return 0; +} + +/*! \internal + + Draws the line ending with the specified \a painter at the position \a pos. The direction of the + line ending is controlled with \a dir. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const +{ + if (mStyle == esNone) + return; + + QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); + if (lengthVec.isNull()) + lengthVec = QCPVector2D(1, 0); + QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); + + QPen penBackup = painter->pen(); + QBrush brushBackup = painter->brush(); + QPen miterPen = penBackup; + miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey + QBrush brush(painter->pen().color(), Qt::SolidPattern); + switch (mStyle) + { + case esNone: break; + case esFlatArrow: + { + QPointF points[3] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 3); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esSpikeArrow: + { + QPointF points[4] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec*0.8).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esLineArrow: + { + QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), + pos.toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->drawPolyline(points, 3); + painter->setPen(penBackup); + break; + } + case esDisc: + { + painter->setBrush(brush); + painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); + painter->setBrush(brushBackup); + break; + } + case esSquare: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), + (pos-widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esDiamond: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp).toPointF(), + (pos-widthVec).toPointF(), + (pos+widthVecPerp).toPointF(), + (pos+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esBar: + { + painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); + break; + } + case esHalfBar: + { + painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); + break; + } + case esSkewedBar: + { + if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) + { + // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); + } else + { + // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); + } + break; + } + } +} + +/*! \internal + \overload + + Draws the line ending. The direction is controlled with the \a angle parameter in radians. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const +{ + draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); +} +/* end of 'src/lineending.cpp' */ + + +/* including file 'src/axis/axisticker.cpp', size 18664 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTicker +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTicker + \brief The base class tick generator used by QCPAxis to create tick positions and tick labels + + Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions + and tick labels for the current axis range. The ticker of an axis can be set via \ref + QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple + axes can share the same ticker instance. + + This base class generates normal tick coordinates and numeric labels for linear axes. It picks a + reasonable tick step (the separation between ticks) which results in readable tick labels. The + number of ticks that should be approximately generated can be set via \ref setTickCount. + Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either + sacrifices readability to better match the specified tick count (\ref + QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref + QCPAxisTicker::tssReadability), which is the default. + + The following more specialized axis ticker subclasses are available, see details in the + respective class documentation: + +
+ + + + + + + +
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png + \image html axisticker-time2.png
+
+ + \section axisticker-subclassing Creating own axis tickers + + Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and + reimplementing some or all of the available virtual methods. + + In the simplest case you might wish to just generate different tick steps than the other tickers, + so you only reimplement the method \ref getTickStep. If you additionally want control over the + string that will be shown as tick label, reimplement \ref getTickLabel. + + If you wish to have complete control, you can generate the tick vectors and tick label vectors + yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default + implementations use the previously mentioned virtual methods \ref getTickStep and \ref + getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case + of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. + + The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick + placement control is obtained by reimplementing \ref createSubTickVector. + + See the documentation of all these virtual methods in QCPAxisTicker for detailed information + about the parameters and expected return values. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTicker::QCPAxisTicker() : + mTickStepStrategy(tssReadability), + mTickCount(5), + mTickOrigin(0) +{ +} + +QCPAxisTicker::~QCPAxisTicker() +{ + +} + +/*! + Sets which strategy the axis ticker follows when choosing the size of the tick step. For the + available strategies, see \ref TickStepStrategy. +*/ +void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) +{ + mTickStepStrategy = strategy; +} + +/*! + Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count + is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with + the requested number of ticks. + + Whether the readability has priority over meeting the requested \a count can be specified with + \ref setTickStepStrategy. +*/ +void QCPAxisTicker::setTickCount(int count) +{ + if (count > 0) + mTickCount = count; + else + qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; +} + +/*! + Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a + concept and doesn't need to be inside the currently visible axis range. + + By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick + step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be + {-4, 1, 6, 11, 16,...}. +*/ +void QCPAxisTicker::setTickOrigin(double origin) +{ + mTickOrigin = origin; +} + +/*! + This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), + tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). + + The ticks are generated for the specified \a range. The generated labels typically follow the + specified \a locale, \a formatChar and number \a precision, however this might be different (or + even irrelevant) for certain QCPAxisTicker subclasses. + + The output parameter \a ticks is filled with the generated tick positions in axis coordinates. + The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) + and are respectively filled with sub tick coordinates, and tick label strings belonging to \a + ticks by index. +*/ +void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) +{ + // generate (major) ticks: + double tickStep = getTickStep(range); + ticks = createTickVector(tickStep, range); + trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) + + // generate sub ticks between major ticks: + if (subTicks) + { + if (ticks.size() > 0) + { + *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); + trimTicks(range, *subTicks, false); + } else + *subTicks = QVector(); + } + + // finally trim also outliers (no further clipping happens in axis drawing): + trimTicks(range, ticks, false); + // generate labels for visible ticks if requested: + if (tickLabels) + *tickLabels = createLabelVector(ticks, locale, formatChar, precision); +} + +/*! \internal + + Takes the entire currently visible axis range and returns a sensible tick step in + order to provide readable tick labels as well as a reasonable number of tick counts (see \ref + setTickCount, \ref setTickStepStrategy). + + If a QCPAxisTicker subclass only wants a different tick step behaviour than the default + implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper + function. +*/ +double QCPAxisTicker::getTickStep(const QCPRange &range) +{ + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return cleanMantissa(exactStep); +} + +/*! \internal + + Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns + an appropriate number of sub ticks for that specific tick step. + + Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. +*/ +int QCPAxisTicker::getSubTickCount(double tickStep) +{ + int result = 1; // default to 1, if no proper value can be found + + // separate integer and fractional part of mantissa: + double epsilon = 0.01; + double intPartf; + int intPart; + double fracPart = modf(getMantissa(tickStep), &intPartf); + intPart = intPartf; + + // handle cases with (almost) integer mantissa: + if (fracPart < epsilon || 1.0-fracPart < epsilon) + { + if (1.0-fracPart < epsilon) + ++intPart; + switch (intPart) + { + case 1: result = 4; break; // 1.0 -> 0.2 substep + case 2: result = 3; break; // 2.0 -> 0.5 substep + case 3: result = 2; break; // 3.0 -> 1.0 substep + case 4: result = 3; break; // 4.0 -> 1.0 substep + case 5: result = 4; break; // 5.0 -> 1.0 substep + case 6: result = 2; break; // 6.0 -> 2.0 substep + case 7: result = 6; break; // 7.0 -> 1.0 substep + case 8: result = 3; break; // 8.0 -> 2.0 substep + case 9: result = 2; break; // 9.0 -> 3.0 substep + } + } else + { + // handle cases with significantly fractional mantissa: + if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa + { + switch (intPart) + { + case 1: result = 2; break; // 1.5 -> 0.5 substep + case 2: result = 4; break; // 2.5 -> 0.5 substep + case 3: result = 4; break; // 3.5 -> 0.7 substep + case 4: result = 2; break; // 4.5 -> 1.5 substep + case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) + case 6: result = 4; break; // 6.5 -> 1.3 substep + case 7: result = 2; break; // 7.5 -> 2.5 substep + case 8: result = 4; break; // 8.5 -> 1.7 substep + case 9: result = 4; break; // 9.5 -> 1.9 substep + } + } + // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default + } + + return result; +} + +/*! \internal + + This method returns the tick label string as it should be printed under the \a tick coordinate. + If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a + precision. + + If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is + enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will + be formatted accordingly using multiplication symbol and superscript during rendering of the + label automatically. +*/ +QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + return locale.toString(tick, formatChar.toLatin1(), precision); +} + +/*! \internal + + Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a + subTickCount sub ticks between each tick pair given in \a ticks. + + If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should + reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to + base its result on \a subTickCount or \a ticks. +*/ +QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) +{ + QVector result; + if (subTickCount <= 0 || ticks.size() < 2) + return result; + + result.reserve((ticks.size()-1)*subTickCount); + for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result; + // Generate tick positions according to tickStep: + qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision + qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision + int tickcount = lastStep-firstStep+1; + if (tickcount < 0) tickcount = 0; + result.resize(tickcount); + for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) +{ + QVector result; + result.reserve(ticks.size()); + for (int i=0; i &ticks, bool keepOneOutlier) const +{ + bool lowFound = false; + bool highFound = false; + int lowIndex = 0; + int highIndex = -1; + + for (int i=0; i < ticks.size(); ++i) + { + if (ticks.at(i) >= range.lower) + { + lowFound = true; + lowIndex = i; + break; + } + } + for (int i=ticks.size()-1; i >= 0; --i) + { + if (ticks.at(i) <= range.upper) + { + highFound = true; + highIndex = i; + break; + } + } + + if (highFound && lowFound) + { + int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); + int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); + if (trimFront > 0 || trimBack > 0) + ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); + } else // all ticks are either all below or all above the range + ticks.clear(); +} + +/*! \internal + + Returns the coordinate contained in \a candidates which is closest to the provided \a target. + + This method assumes \a candidates is not empty and sorted in ascending order. +*/ +double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const +{ + if (candidates.size() == 1) + return candidates.first(); + QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); + if (it == candidates.constEnd()) + return *(it-1); + else if (it == candidates.constBegin()) + return *it; + else + return target-*(it-1) < *it-target ? *(it-1) : *it; +} + +/*! \internal + + Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also + returns the magnitude of \a input as a power of 10. + + For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. +*/ +double QCPAxisTicker::getMantissa(double input, double *magnitude) const +{ + const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); + if (magnitude) *magnitude = mag; + return input/mag; +} + +/*! \internal + + Returns a number that is close to \a input but has a clean, easier human readable mantissa. How + strongly the mantissa is altered, and thus how strong the result deviates from the original \a + input, depends on the current tick step strategy (see \ref setTickStepStrategy). +*/ +double QCPAxisTicker::cleanMantissa(double input) const +{ + double magnitude; + const double mantissa = getMantissa(input, &magnitude); + switch (mTickStepStrategy) + { + case tssReadability: + { + return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; + } + case tssMeetTickCount: + { + // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 + if (mantissa <= 5.0) + return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 + else + return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 + } + } + return input; +} +/* end of 'src/axis/axisticker.cpp' */ + + +/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerDateTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerDateTime + \brief Specialized axis ticker for calendar dates and times as axis ticks + + \image html axisticker-datetime.png + + This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The + plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 + UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods + with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime + by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey + and \ref keyToDateTime conveniently perform this conversion achieving a precision of one + millisecond on all Qt versions. + + The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. + If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. + + This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day + ticks. For example, if the axis range spans a few years such that there is one tick per year, + ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, + will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in + the image above: even though the number of days varies month by month, this ticker generates + ticks on the same day of each month. + + If you would like to change the date/time that is used as a (mathematical) starting date for the + ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a + QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at + 9:45 of every year. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation + + \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and + milliseconds, and are not interested in the intricacies of real calendar dates with months and + (leap) years, have a look at QCPAxisTickerTime instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerDateTime::QCPAxisTickerDateTime() : + mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), + mDateTimeSpec(Qt::LocalTime), + mDateStrategy(dsNone) +{ + setTickCount(4); +} + +/*! + Sets the format in which dates and times are displayed as tick labels. For details about the \a + format string, see the documentation of QDateTime::toString(). + + Newlines can be inserted with "\n". + + \see setDateTimeSpec +*/ +void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) +{ + mDateTimeFormat = format; +} + +/*! + Sets the time spec that is used for creating the tick labels from corresponding dates/times. + + The default value of QDateTime objects (and also QCPAxisTickerDateTime) is + Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form + of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC + to get the correct axis labels. + + \see setDateTimeFormat +*/ +void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) +{ + mDateTimeSpec = spec; +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, + 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which + directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(double origin) +{ + QCPAxisTicker::setTickOrigin(origin); +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) +{ + setTickOrigin(dateTimeToKey(origin)); +} + +/*! \internal + + Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + Note that this tick step isn't used exactly when generating the tick vector in \ref + createTickVector, but only as a guiding value requiring some correction for each individual tick + interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day + in the month to the last day in the previous month from tick to tick, due to the non-uniform + length of months. The same problem arises with leap years. + + \seebaseclassmethod +*/ +double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + mDateStrategy = dsNone; + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + result = cleanMantissa(result); + } else if (result < 86400*30.4375*12) // below a year + { + result = pickClosest(result, QVector() + << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range + << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range + << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) + if (result > 86400*30.4375-1) // month tick intervals or larger + mDateStrategy = dsUniformDayInMonth; + else if (result > 3600*24-1) // day tick intervals or larger + mDateStrategy = dsUniformTimeInDay; + } else // more than a year, go back to normal clean mantissa algorithm but in units of years + { + const double secondsPerYear = 86400*30.4375*12; // average including leap years + result = cleanMantissa(result/secondsPerYear)*secondsPerYear; + mDateStrategy = dsUniformDayInMonth; + } + return result; +} + +/*! \internal + + Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + \seebaseclassmethod +*/ +int QCPAxisTickerDateTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + case 86400*2: result = 1; break; + case 86400*5: result = 4; break; + case 86400*7: result = 6; break; + case 86400*14: result = 1; break; + case (int)(86400*30.4375+0.5): result = 3; break; + case (int)(86400*30.4375*2+0.5): result = 1; break; + case (int)(86400*30.4375*3+0.5): result = 2; break; + case (int)(86400*30.4375*6+0.5): result = 5; break; + case (int)(86400*30.4375*12+0.5): result = 3; break; + } + return result; +} + +/*! \internal + + Generates a date/time tick label for tick coordinate \a tick, based on the currently set format + (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). + + \seebaseclassmethod +*/ +QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +} + +/*! \internal + + Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain + non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. + + \seebaseclassmethod +*/ +QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result = QCPAxisTicker::createTickVector(tickStep, range); + if (!result.isEmpty()) + { + if (mDateStrategy == dsUniformTimeInDay) + { + QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible + QDateTime tickDateTime; + for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths(-1); + tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); + result[i] = dateTimeToKey(tickDateTime); + } + } + } + return result; +} + +/*! + A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a + QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) + + \see dateTimeToKey +*/ +QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); +# else + return QDateTime::fromMSecsSinceEpoch(key*1000.0); +# endif +} + +/*! \overload + + A convenience method which turns a QDateTime object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return dateTime.toTime_t()+dateTime.time().msec()/1000.0; +# else + return dateTime.toMSecsSinceEpoch()/1000.0; +# endif +} + +/*! \overload + + A convenience method which turns a QDate object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime(date).toTime_t(); +# else + return QDateTime(date).toMSecsSinceEpoch()/1000.0; +# endif +} +/* end of 'src/axis/axistickerdatetime.cpp' */ + + +/* including file 'src/axis/axistickertime.cpp', size 11747 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerTime + \brief Specialized axis ticker for time spans in units of milliseconds to days + + \image html axisticker-time.png + + This QCPAxisTicker subclass generates ticks that corresponds to time intervals. + + The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref + setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate + zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date + and time. + + The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the + largest available unit in the format specified with \ref setTimeFormat, any time spans above will + be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at + coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick + label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour + unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis + zero will carry a leading minus sign. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation + + Here is an example of a time axis providing time information in days, hours and minutes. Due to + the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker + decided to use tick steps of 12 hours: + + \image html axisticker-time2.png + + The format string for this example is + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 + + \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime + instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerTime::QCPAxisTickerTime() : + mTimeFormat(QLatin1String("%h:%m:%s")), + mSmallestUnit(tuSeconds), + mBiggestUnit(tuHours) +{ + setTickCount(4); + mFieldWidth[tuMilliseconds] = 3; + mFieldWidth[tuSeconds] = 2; + mFieldWidth[tuMinutes] = 2; + mFieldWidth[tuHours] = 2; + mFieldWidth[tuDays] = 1; + + mFormatPattern[tuMilliseconds] = QLatin1String("%z"); + mFormatPattern[tuSeconds] = QLatin1String("%s"); + mFormatPattern[tuMinutes] = QLatin1String("%m"); + mFormatPattern[tuHours] = QLatin1String("%h"); + mFormatPattern[tuDays] = QLatin1String("%d"); +} + +/*! + Sets the format that will be used to display time in the tick labels. + + The available patterns are: + - %%z for milliseconds + - %%s for seconds + - %%m for minutes + - %%h for hours + - %%d for days + + The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. + + The largest unit that appears in \a format will carry all the remaining time of a certain tick + coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the + largest unit it might become larger than 59 in order to consume larger time values. If on the + other hand %%h is available, the minutes will wrap around to zero after 59 and the time will + carry to the hour digit. +*/ +void QCPAxisTickerTime::setTimeFormat(const QString &format) +{ + mTimeFormat = format; + + // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest + // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) + mSmallestUnit = tuMilliseconds; + mBiggestUnit = tuMilliseconds; + bool hasSmallest = false; + for (int i = tuMilliseconds; i <= tuDays; ++i) + { + TimeUnit unit = static_cast(i); + if (mTimeFormat.contains(mFormatPattern.value(unit))) + { + if (!hasSmallest) + { + mSmallestUnit = unit; + hasSmallest = true; + } + mBiggestUnit = unit; + } + } +} + +/*! + Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick + label. If the number for the specific unit is shorter than \a width, it will be padded with an + according number of zeros to the left in order to reach the field width. + + \see setTimeFormat +*/ +void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) +{ + mFieldWidth[unit] = qMax(width, 1); +} + +/*! \internal + + Returns the tick step appropriate for time displays, depending on the provided \a range and the + smallest available time unit in the current format (\ref setTimeFormat). For example if the unit + of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) + that require sub-minute precision to be displayed correctly. + + \seebaseclassmethod +*/ +double QCPAxisTickerTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + if (mSmallestUnit == tuMilliseconds) + result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond + else // have no milliseconds available in format, so stick with 1 second tickstep + result = 1.0; + } else if (result < 3600*24) // below a day + { + // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run + QVector availableSteps; + // seconds range: + if (mSmallestUnit <= tuSeconds) + availableSteps << 1; + if (mSmallestUnit == tuMilliseconds) + availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it + else if (mSmallestUnit == tuSeconds) + availableSteps << 2; + if (mSmallestUnit <= tuSeconds) + availableSteps << 5 << 10 << 15 << 30; + // minutes range: + if (mSmallestUnit <= tuMinutes) + availableSteps << 1*60; + if (mSmallestUnit <= tuSeconds) + availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it + else if (mSmallestUnit == tuMinutes) + availableSteps << 2*60; + if (mSmallestUnit <= tuMinutes) + availableSteps << 5*60 << 10*60 << 15*60 << 30*60; + // hours range: + if (mSmallestUnit <= tuHours) + availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; + // pick available step that is most appropriate to approximate ideal step: + result = pickClosest(result, availableSteps); + } else // more than a day, go back to normal clean mantissa algorithm but in units of days + { + const double secondsPerDay = 3600*24; + result = cleanMantissa(result/secondsPerDay)*secondsPerDay; + } + return result; +} + +/*! \internal + + Returns the sub tick count appropriate for the provided \a tickStep and time displays. + + \seebaseclassmethod +*/ +int QCPAxisTickerTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + } + return result; +} + +/*! \internal + + Returns the tick label corresponding to the provided \a tick and the configured format and field + widths (\ref setTimeFormat, \ref setFieldWidth). + + \seebaseclassmethod +*/ +QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + Q_UNUSED(locale) + bool negative = tick < 0; + if (negative) tick *= -1; + double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) + double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time + + restValues[tuMilliseconds] = tick*1000; + values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; + values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; + values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; + values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; + // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) + + QString result = mTimeFormat; + for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) + { + TimeUnit iUnit = static_cast(i); + replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); + } + if (negative) + result.prepend(QLatin1Char('-')); + return result; +} + +/*! \internal + + Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified + \a value, using the field width as specified with \ref setFieldWidth for the \a unit. +*/ +void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const +{ + QString valueStr = QString::number(value); + while (valueStr.size() < mFieldWidth.value(unit)) + valueStr.prepend(QLatin1Char('0')); + + text.replace(mFormatPattern.value(unit), valueStr); +} +/* end of 'src/axis/axistickertime.cpp' */ + + +/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerFixed +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerFixed + \brief Specialized axis ticker with a fixed tick step + + \image html axisticker-fixed.png + + This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It + is also possible to allow integer multiples and integer powers of the specified tick step with + \ref setScaleStrategy. + + A typical application of this ticker is to make an axis only display integers, by setting the + tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. + + Another case is when a certain number has a special meaning and axis ticks should only appear at + multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi + because despite the name it is not limited to only pi symbols/values. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerFixed::QCPAxisTickerFixed() : + mTickStep(1.0), + mScaleStrategy(ssNone) +{ +} + +/*! + Sets the fixed tick interval to \a step. + + The axis ticker will only use this tick step when generating axis ticks. This might cause a very + high tick density and overlapping labels if the axis range is zoomed out. Using \ref + setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a + step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref + setTickCount). +*/ +void QCPAxisTickerFixed::setTickStep(double step) +{ + if (step > 0) + mTickStep = step; + else + qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; +} + +/*! + Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether + modifications may be applied to it before calculating the finally used tick step, such as + permitting multiples or powers. See \ref ScaleStrategy for details. + + The default strategy is \ref ssNone, which means the tick step is absolutely fixed. +*/ +void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) +{ + mScaleStrategy = strategy; +} + +/*! \internal + + Determines the actually used tick step from the specified tick step and scale strategy (\ref + setTickStep, \ref setScaleStrategy). + + This method either returns the specified tick step exactly, or, if the scale strategy is not \ref + ssNone, a modification of it to allow varying the number of ticks in the current axis range. + + \seebaseclassmethod +*/ +double QCPAxisTickerFixed::getTickStep(const QCPRange &range) +{ + switch (mScaleStrategy) + { + case ssNone: + { + return mTickStep; + } + case ssMultiples: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + if (exactStep < mTickStep) + return mTickStep; + else + return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; + } + case ssPowers: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); + } + } + return mTickStep; +} +/* end of 'src/axis/axistickerfixed.cpp' */ + + +/* including file 'src/axis/axistickertext.cpp', size 8653 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerText +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerText + \brief Specialized axis ticker which allows arbitrary labels at specified coordinates + + \image html axisticker-text.png + + This QCPAxisTicker subclass generates ticks which can be directly specified by the user as + coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a + time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks + and modify the tick/label data there. + + This is useful for cases where the axis represents categories rather than numerical values. + + If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on + the axis range), it is a sign that you should probably create an own ticker by subclassing + QCPAxisTicker, instead of using this one. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation +*/ + +/* start of documentation of inline functions */ + +/*! \fn QMap &QCPAxisTickerText::ticks() + + Returns a non-const reference to the internal map which stores the tick coordinates and their + labels. + + You can access the map directly in order to add, remove or manipulate ticks, as an alternative to + using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerText::QCPAxisTickerText() : + mSubTickCount(0) +{ +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis + coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QMap &ticks) +{ + mTicks = ticks; +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis + coordinates, and the entries of \a labels are the respective strings that will appear as tick + labels. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) +{ + clear(); + addTicks(positions, labels); +} + +/*! + Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no + automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this + method. +*/ +void QCPAxisTickerText::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! + Clears all ticks. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see setTicks, addTicks, addTick +*/ +void QCPAxisTickerText::clear() +{ + mTicks.clear(); +} + +/*! + Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a + label. + + \see addTicks, setTicks, clear +*/ +void QCPAxisTickerText::addTick(double position, QString label) +{ + mTicks.insert(position, label); +} + +/*! \overload + + Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to + the axis coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QMap &ticks) +{ + mTicks.unite(ticks); +} + +/*! \overload + + Adds the provided ticks to the ones already existing. The entries of \a positions correspond to + the axis coordinates, and the entries of \a labels are the respective strings that will appear as + tick labels. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) +{ + if (positions.size() != labels.size()) + qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); + int n = qMin(positions.size(), labels.size()); + for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (mTicks.isEmpty()) + return result; + + QMap::const_iterator start = mTicks.lowerBound(range.lower); + QMap::const_iterator end = mTicks.upperBound(range.upper); + // this method should try to give one tick outside of range so proper subticks can be generated: + if (start != mTicks.constBegin()) --start; + if (end != mTicks.constEnd()) ++end; + for (QMap::const_iterator it = start; it != end; ++it) + result.append(it.key()); + + return result; +} +/* end of 'src/axis/axistickertext.cpp' */ + + +/* including file 'src/axis/axistickerpi.cpp', size 11170 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerPi +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerPi + \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi + + \image html axisticker-pi.png + + This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic + constant with a numerical value specified with \ref setPiValue and an appearance in the tick + labels specified with \ref setPiSymbol. + + Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the + tick label can be configured with \ref setFractionStyle. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerPi::QCPAxisTickerPi() : + mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), + mPiValue(M_PI), + mPeriodicity(0), + mFractionStyle(fsUnicodeFractions), + mPiTickStep(0) +{ + setTickCount(4); +} + +/*! + Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick + label. + + If a space shall appear between the number and the symbol, make sure the space is contained in \a + symbol. +*/ +void QCPAxisTickerPi::setPiSymbol(QString symbol) +{ + mPiSymbol = symbol; +} + +/*! + Sets the numerical value that the symbolic constant has. + + This will be used to place the appropriate fractions of the symbol at the respective axis + coordinates. +*/ +void QCPAxisTickerPi::setPiValue(double pi) +{ + mPiValue = pi; +} + +/*! + Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the + symbolic constant. + + To disable periodicity, set \a multiplesOfPi to zero. + + For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. +*/ +void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) +{ + mPeriodicity = qAbs(multiplesOfPi); +} + +/*! + Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick + labels. See \ref FractionStyle for the various options. +*/ +void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) +{ + mFractionStyle = style; +} + +/*! \internal + + Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence + the numerical/fractional part preceding the symbolic constant is made to have a readable + mantissa. + + \seebaseclassmethod +*/ +double QCPAxisTickerPi::getTickStep(const QCPRange &range) +{ + mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mPiTickStep = cleanMantissa(mPiTickStep); + return mPiTickStep*mPiValue; +} + +/*! \internal + + Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In + consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant + reasonably, and not the total tick coordinate. + + \seebaseclassmethod +*/ +int QCPAxisTickerPi::getSubTickCount(double tickStep) +{ + return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); +} + +/*! \internal + + Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The + formatting of the fraction is done according to the specified \ref setFractionStyle. The appended + symbol is specified with \ref setPiSymbol. + + \seebaseclassmethod +*/ +QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + double tickInPis = tick/mPiValue; + if (mPeriodicity > 0) + tickInPis = fmod(tickInPis, mPeriodicity); + + if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) + { + // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above + int denominator = 1000; + int numerator = qRound(tickInPis*denominator); + simplifyFraction(numerator, denominator); + if (qAbs(numerator) == 1 && denominator == 1) + return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else if (numerator == 0) + return QLatin1String("0"); + else + return fractionToString(numerator, denominator) + mPiSymbol; + } else + { + if (qFuzzyIsNull(tickInPis)) + return QLatin1String("0"); + else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) + return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else + return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; + } +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure + the fraction is in irreducible form, i.e. numerator and denominator don't share any common + factors which could be cancelled. +*/ +void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const +{ + if (numerator == 0 || denominator == 0) + return; + + int num = numerator; + int denom = denominator; + while (denom != 0) // euclidean gcd algorithm + { + int oldDenom = denom; + denom = num % denom; + num = oldDenom; + } + // num is now gcd of numerator and denominator + numerator /= num; + denominator /= num; +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and returns a string representation. + The result depends on the configured fraction style (\ref setFractionStyle). + + This method is used to format the numerical/fractional part when generating tick labels. It + simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out + any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). +*/ +QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const +{ + if (denominator == 0) + { + qDebug() << Q_FUNC_INFO << "called with zero denominator"; + return QString(); + } + if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function + { + qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; + return QString::number(numerator/(double)denominator); // failsafe + } + int sign = numerator*denominator < 0 ? -1 : 1; + numerator = qAbs(numerator); + denominator = qAbs(denominator); + + if (denominator == 1) + { + return QString::number(sign*numerator); + } else + { + int integerPart = numerator/denominator; + int remainder = numerator%denominator; + if (remainder == 0) + { + return QString::number(sign*integerPart); + } else + { + if (mFractionStyle == fsAsciiFractions) + { + return QString(QLatin1String("%1%2%3/%4")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) + .arg(remainder) + .arg(denominator); + } else if (mFractionStyle == fsUnicodeFractions) + { + return QString(QLatin1String("%1%2%3")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) + .arg(unicodeFraction(remainder, denominator)); + } + } + } + return QString(); +} + +/*! \internal + + Returns the unicode string representation of the fraction given by \a numerator and \a + denominator. This is the representation used in \ref fractionToString when the fraction style + (\ref setFractionStyle) is \ref fsUnicodeFractions. + + This method doesn't use the single-character common fractions but builds each fraction from a + superscript unicode number, the unicode fraction character, and a subscript unicode number. +*/ +QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const +{ + return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); +} + +/*! \internal + + Returns the unicode string representing \a number as superscript. This is used to build + unicode fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSuperscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2070)); + + QString result; + while (number > 0) + { + const int digit = number%10; + switch (digit) + { + case 1: { result.prepend(QChar(0x00B9)); break; } + case 2: { result.prepend(QChar(0x00B2)); break; } + case 3: { result.prepend(QChar(0x00B3)); break; } + default: { result.prepend(QChar(0x2070+digit)); break; } + } + number /= 10; + } + return result; +} + +/*! \internal + + Returns the unicode string representing \a number as subscript. This is used to build unicode + fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSubscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2080)); + + QString result; + while (number > 0) + { + result.prepend(QChar(0x2080+number%10)); + number /= 10; + } + return result; +} +/* end of 'src/axis/axistickerpi.cpp' */ + + +/* including file 'src/axis/axistickerlog.cpp', size 7106 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerLog +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerLog + \brief Specialized axis ticker suited for logarithmic axes + + \image html axisticker-log.png + + This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic + axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). + + Especially in the case of a log base equal to 10 (the default), it might be desirable to have + tick labels in the form of powers of ten without mantissa display. To achieve this, set the + number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref + QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal + powers, so a format string of "eb". This will result in the following axis tick labels: + + \image html axisticker-log-powers.png + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerLog::QCPAxisTickerLog() : + mLogBase(10.0), + mSubTickCount(8), // generates 10 intervals + mLogBaseLnInv(1.0/qLn(mLogBase)) +{ +} + +/*! + Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer + powers of \a base. +*/ +void QCPAxisTickerLog::setLogBase(double base) +{ + if (base > 0) + { + mLogBase = base; + mLogBaseLnInv = 1.0/qLn(mLogBase); + } else + qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; +} + +/*! + Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced + linearly to provide a better visual guide, so the sub tick density increases toward the higher + tick. + + Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in + the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub + ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, + namely at 20, 30, 40, 50, 60, 70, 80 and 90. +*/ +void QCPAxisTickerLog::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! \internal + + Since logarithmic tick steps are necessarily different for each tick interval, this method does + nothing in the case of QCPAxisTickerLog + + \seebaseclassmethod +*/ +double QCPAxisTickerLog::getTickStep(const QCPRange &range) +{ + // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method + Q_UNUSED(range) + return 1.0; +} + +/*! \internal + + Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no + automatic sub tick count calculation necessary. + + \seebaseclassmethod +*/ +int QCPAxisTickerLog::getSubTickCount(double tickStep) +{ + Q_UNUSED(tickStep) + return mSubTickCount; +} + +/*! \internal + + Creates ticks with a spacing given by the logarithm base and an increasing integer power in the + provided \a range. The step in which the power increases tick by tick is chosen in order to keep + the total number of ticks as close as possible to the tick count (\ref setTickCount). The + parameter \a tickStep is ignored for QCPAxisTickerLog + + \seebaseclassmethod +*/ +QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (range.lower > 0 && range.upper > 0) // positive range + { + double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick *= newLogBase; + result.append(currentTick); + } + } else if (range.lower < 0 && range.upper < 0) // negative range + { + double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick /= newLogBase; + result.append(currentTick); + } + } else // invalid range for logarithmic scale, because lower and upper have different sign + { + qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; + } + + return result; +} +/* end of 'src/axis/axistickerlog.cpp' */ + + +/* including file 'src/axis/axis.cpp', size 99397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGrid + \brief Responsible for drawing the grid of a QCPAxis. + + This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the + grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref + QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. + + The axis and grid drawing was split into two classes to allow them to be placed on different + layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid + in the background and the axes in the foreground, and any plottables/items in between. This + described situation is the default setup, see the QCPLayer documentation. +*/ + +/*! + Creates a QCPGrid instance and sets default values. + + You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. +*/ +QCPGrid::QCPGrid(QCPAxis *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mParentAxis(parentAxis) +{ + // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called + setParent(parentAxis); + setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); + setSubGridVisible(false); + setAntialiased(false); + setAntialiasedSubGrid(false); + setAntialiasedZeroLine(false); +} + +/*! + Sets whether grid lines at sub tick marks are drawn. + + \see setSubGridPen +*/ +void QCPGrid::setSubGridVisible(bool visible) +{ + mSubGridVisible = visible; +} + +/*! + Sets whether sub grid lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedSubGrid(bool enabled) +{ + mAntialiasedSubGrid = enabled; +} + +/*! + Sets whether zero lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedZeroLine(bool enabled) +{ + mAntialiasedZeroLine = enabled; +} + +/*! + Sets the pen with which (major) grid lines are drawn. +*/ +void QCPGrid::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen with which sub grid lines are drawn. +*/ +void QCPGrid::setSubGridPen(const QPen &pen) +{ + mSubGridPen = pen; +} + +/*! + Sets the pen with which zero lines are drawn. + + Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid + lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. +*/ +void QCPGrid::setZeroLinePen(const QPen &pen) +{ + mZeroLinePen = pen; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing the major grid lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); +} + +/*! \internal + + Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning + over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). +*/ +void QCPGrid::draw(QCPPainter *painter) +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + if (mParentAxis->subTicks() && mSubGridVisible) + drawSubGridLines(painter); + drawGridLines(painter); +} + +/*! \internal + + Draws the main grid lines and possibly a zero line with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + const int tickCount = mParentAxis->mTickVector.size(); + double t; // helper variable, result of coordinate-to-pixel transforms + if (mParentAxis->orientation() == Qt::Horizontal) + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + +/*! \internal + + Draws the sub grid lines with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawSubGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); + double t; // helper variable, result of coordinate-to-pixel transforms + painter->setPen(mSubGridPen); + if (mParentAxis->orientation() == Qt::Horizontal) + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxis +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxis + \brief Manages a single axis inside a QCustomPlot. + + Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via + QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and + QCustomPlot::yAxis2 (right). + + Axes are always part of an axis rect, see QCPAxisRect. + \image html AxisNamesOverview.png +
Naming convention of axis parts
+ \n + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line + on the left represents the QCustomPlot widget border.
+ + Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and + tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of + the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the + documentation of QCPAxisTicker. +*/ + +/* start of documentation of inline functions */ + +/*! \fn Qt::Orientation QCPAxis::orientation() const + + Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced + from the axis type (left, top, right or bottom). + + \see orientation(AxisType type), pixelOrientation +*/ + +/*! \fn QCPGrid *QCPAxis::grid() const + + Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the + grid is displayed. +*/ + +/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) + + Returns the orientation of the specified axis type + + \see orientation(), pixelOrientation +*/ + +/*! \fn int QCPAxis::pixelOrientation() const + + Returns which direction points towards higher coordinate values/keys, in pixel space. + + This method returns either 1 or -1. If it returns 1, then going in the positive direction along + the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. + On the other hand, if this method returns -1, going to smaller pixel values corresponds to going + from lower to higher axis coordinates. + + For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, + without having to care about reversed or vertically aligned axes: + + \code + double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); + \endcode + + \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. +*/ + +/*! \fn QSharedPointer QCPAxis::ticker() const + + Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is + responsible for generating the tick positions and tick labels of this axis. You can access the + \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count + (\ref QCPAxisTicker::setTickCount). + + You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see + the documentation there. A new axis ticker can be set with \ref setTicker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see setTicker +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) + + This signal is emitted when the range of this axis has changed. You can connect it to the \ref + setRange slot of another axis to communicate the new range to the other axis, in order for it to + be synchronized. + + You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. + This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper + range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following + slot would limit the x axis to ranges between 0 and 10: + \code + customPlot->xAxis->setRange(newRange.bounded(0, 10)) + \endcode +*/ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) + \overload + + Additionally to the new range, this signal also provides the previous range held by the axis as + \a oldRange. +*/ + +/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the scale type changes, by calls to \ref setScaleType +*/ + +/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) + + This signal is emitted when the selection state of this axis has changed, either by user interaction + or by a direct call to \ref setSelectedParts. +*/ + +/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); + + This signal is emitted when the selectability changes, by calls to \ref setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs an Axis instance of Type \a type for the axis rect \a parent. + + Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create + them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, + create them manually and then inject them also via \ref QCPAxisRect::addAxis. +*/ +QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : + QCPLayerable(parent->parentPlot(), QString(), parent), + // axis base: + mAxisType(type), + mAxisRect(parent), + mPadding(5), + mOrientation(orientation(type)), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + mTickLabels(true), + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedTickPen(QPen(Qt::blue, 2)), + mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedSubTickPen(QPen(Qt::blue, 2)), + // scale and range: + mRange(0, 5), + mRangeReversed(false), + mScaleType(stLinear), + // internal members: + mGrid(new QCPGrid(this)), + mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), + mTicker(new QCPAxisTicker), + mCachedMarginValid(false), + mCachedMargin(0) +{ + setParent(parent); + mGrid->setVisible(false); + setAntialiased(false); + setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again + + if (type == atTop) + { + setTickLabelPadding(3); + setLabelPadding(6); + } else if (type == atRight) + { + setTickLabelPadding(7); + setLabelPadding(12); + } else if (type == atBottom) + { + setTickLabelPadding(3); + setLabelPadding(3); + } else if (type == atLeft) + { + setTickLabelPadding(5); + setLabelPadding(10); + } +} + +QCPAxis::~QCPAxis() +{ + delete mAxisPainter; + delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLabelPadding() const +{ + return mAxisPainter->tickLabelPadding; +} + +/* No documentation as it is a property getter */ +double QCPAxis::tickLabelRotation() const +{ + return mAxisPainter->tickLabelRotation; +} + +/* No documentation as it is a property getter */ +QCPAxis::LabelSide QCPAxis::tickLabelSide() const +{ + return mAxisPainter->tickLabelSide; +} + +/* No documentation as it is a property getter */ +QString QCPAxis::numberFormat() const +{ + QString result; + result.append(mNumberFormatChar); + if (mNumberBeautifulPowers) + { + result.append(QLatin1Char('b')); + if (mAxisPainter->numberMultiplyCross) + result.append(QLatin1Char('c')); + } + return result; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthIn() const +{ + return mAxisPainter->tickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthOut() const +{ + return mAxisPainter->tickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthIn() const +{ + return mAxisPainter->subTickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthOut() const +{ + return mAxisPainter->subTickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::labelPadding() const +{ + return mAxisPainter->labelPadding; +} + +/* No documentation as it is a property getter */ +int QCPAxis::offset() const +{ + return mAxisPainter->offset; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::lowerEnding() const +{ + return mAxisPainter->lowerEnding; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::upperEnding() const +{ + return mAxisPainter->upperEnding; +} + +/*! + Sets whether the axis uses a linear scale or a logarithmic scale. + + Note that this method controls the coordinate transformation. You will likely also want to use a + logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref + QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the + details of logarithmic axis tick creation. + + \ref setNumberPrecision +*/ +void QCPAxis::setScaleType(QCPAxis::ScaleType type) +{ + if (mScaleType != type) + { + mScaleType = type; + if (mScaleType == stLogarithmic) + setRange(mRange.sanitizedForLogScale()); + mCachedMarginValid = false; + Q_EMIT scaleTypeChanged(mScaleType); + } +} + +/*! + Sets the range of the axis. + + This slot may be connected with the \ref rangeChanged signal of another axis so this axis + is always synchronized with the other axis range, when it changes. + + To invert the direction of an axis, use \ref setRangeReversed. +*/ +void QCPAxis::setRange(const QCPRange &range) +{ + if (range.lower == mRange.lower && range.upper == mRange.upper) + return; + + if (!QCPRange::validRange(range)) return; + QCPRange oldRange = mRange; + if (mScaleType == stLogarithmic) + { + mRange = range.sanitizedForLogScale(); + } else + { + mRange = range.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains iSelectAxes.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPAxis::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font. + + The entire selection mechanism for axes is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you + wish to change the selection state manually. + + This function can change the selection state of a part, independent of the \ref setSelectableParts setting. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, + setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor +*/ +void QCPAxis::setSelectedParts(const SelectableParts &selected) +{ + if (mSelectedParts != selected) + { + mSelectedParts = selected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + \overload + + Sets the lower and upper bound of the axis range. + + To invert the direction of an axis, use \ref setRangeReversed. + + There is also a slot to set a range, see \ref setRange(const QCPRange &range). +*/ +void QCPAxis::setRange(double lower, double upper) +{ + if (lower == mRange.lower && upper == mRange.upper) + return; + + if (!QCPRange::validRange(lower, upper)) return; + QCPRange oldRange = mRange; + mRange.lower = lower; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + \overload + + Sets the range of the axis. + + The \a position coordinate indicates together with the \a alignment parameter, where the new + range will be positioned. \a size defines the size of the new axis range. \a alignment may be + Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, + or center of the range to be aligned with \a position. Any other values of \a alignment will + default to Qt::AlignCenter. +*/ +void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) +{ + if (alignment == Qt::AlignLeft) + setRange(position, position+size); + else if (alignment == Qt::AlignRight) + setRange(position-size, position); + else // alignment == Qt::AlignCenter + setRange(position-size/2.0, position+size/2.0); +} + +/*! + Sets the lower bound of the axis range. The upper bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeLower(double lower) +{ + if (mRange.lower == lower) + return; + + QCPRange oldRange = mRange; + mRange.lower = lower; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets the upper bound of the axis range. The lower bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeUpper(double upper) +{ + if (mRange.upper == upper) + return; + + QCPRange oldRange = mRange; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal + axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the + direction of increasing values is inverted. + + Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part + of the \ref setRange interface will still reference the mathematically smaller number than the \a + upper part. +*/ +void QCPAxis::setRangeReversed(bool reversed) +{ + mRangeReversed = reversed; +} + +/*! + The axis ticker is responsible for generating the tick positions and tick labels. See the + documentation of QCPAxisTicker for details on how to work with axis tickers. + + You can change the tick positioning/labeling behaviour of this axis by setting a different + QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis + ticker, access it via \ref ticker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see ticker +*/ +void QCPAxis::setTicker(QSharedPointer ticker) +{ + if (ticker) + mTicker = ticker; + else + qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; + // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector +} + +/*! + Sets whether tick marks are displayed. + + Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve + that, see \ref setTickLabels. + + \see setSubTicks +*/ +void QCPAxis::setTicks(bool show) +{ + if (mTicks != show) + { + mTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. +*/ +void QCPAxis::setTickLabels(bool show) +{ + if (mTickLabels != show) + { + mTickLabels = show; + mCachedMarginValid = false; + if (!mTickLabels) + mTickVectorLabels.clear(); + } +} + +/*! + Sets the distance between the axis base line (including any outward ticks) and the tick labels. + \see setLabelPadding, setPadding +*/ +void QCPAxis::setTickLabelPadding(int padding) +{ + if (mAxisPainter->tickLabelPadding != padding) + { + mAxisPainter->tickLabelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the font of the tick labels. + + \see setTickLabels, setTickLabelColor +*/ +void QCPAxis::setTickLabelFont(const QFont &font) +{ + if (font != mTickLabelFont) + { + mTickLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the tick labels. + + \see setTickLabels, setTickLabelFont +*/ +void QCPAxis::setTickLabelColor(const QColor &color) +{ + mTickLabelColor = color; +} + +/*! + Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, + the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values + from -90 to 90 degrees. + + If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For + other angles, the label is drawn with an offset such that it seems to point toward or away from + the tick mark. +*/ +void QCPAxis::setTickLabelRotation(double degrees) +{ + if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) + { + mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); + mCachedMarginValid = false; + } +} + +/*! + Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. + + The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels + to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels + appear on the inside are additionally clipped to the axis rect. +*/ +void QCPAxis::setTickLabelSide(LabelSide side) +{ + mAxisPainter->tickLabelSide = side; + mCachedMarginValid = false; +} + +/*! + Sets the number format for the numbers in tick labels. This \a formatCode is an extended version + of the format code used e.g. by QString::number() and QLocale::toString(). For reference about + that, see the "Argument Formats" section in the detailed description of the QString class. + + \a formatCode is a string of one, two or three characters. The first character is identical to + the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed + format, 'g'/'G' scientific or fixed, whichever is shorter. + + The second and third characters are optional and specific to QCustomPlot:\n + If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. + "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for + "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 + [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. + If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can + be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the + cross and 183 (0xB7) for the dot. + + Examples for \a formatCode: + \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, + normal scientific format is used + \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with + beautifully typeset decimal powers and a dot as multiplication sign + \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as + multiplication sign + \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal + powers. Format code will be reduced to 'f'. + \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format + code will not be changed. +*/ +void QCPAxis::setNumberFormat(const QString &formatCode) +{ + if (formatCode.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; + return; + } + mCachedMarginValid = false; + + // interpret first char as number format char: + QString allowedFormatChars(QLatin1String("eEfgG")); + if (allowedFormatChars.contains(formatCode.at(0))) + { + mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; + return; + } + if (formatCode.length() < 2) + { + mNumberBeautifulPowers = false; + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret second char as indicator for beautiful decimal powers: + if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) + { + mNumberBeautifulPowers = true; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; + return; + } + if (formatCode.length() < 3) + { + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret third char as indicator for dot or cross multiplication symbol: + if (formatCode.at(2) == QLatin1Char('c')) + { + mAxisPainter->numberMultiplyCross = true; + } else if (formatCode.at(2) == QLatin1Char('d')) + { + mAxisPainter->numberMultiplyCross = false; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; + return; + } +} + +/*! + Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) + for details. The effect of precisions are most notably for number Formats starting with 'e', see + \ref setNumberFormat +*/ +void QCPAxis::setNumberPrecision(int precision) +{ + if (mNumberPrecision != precision) + { + mNumberPrecision = precision; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the + plot and \a outside is the length they will reach outside the plot. If \a outside is greater than + zero, the tick labels and axis label will increase their distance to the axis accordingly, so + they won't collide with the ticks. + + \see setSubTickLength, setTickLengthIn, setTickLengthOut +*/ +void QCPAxis::setTickLength(int inside, int outside) +{ + setTickLengthIn(inside); + setTickLengthOut(outside); +} + +/*! + Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach + inside the plot. + + \see setTickLengthOut, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthIn(int inside) +{ + if (mAxisPainter->tickLengthIn != inside) + { + mAxisPainter->tickLengthIn = inside; + } +} + +/*! + Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach + outside the plot. If \a outside is greater than zero, the tick labels and axis label will + increase their distance to the axis accordingly, so they won't collide with the ticks. + + \see setTickLengthIn, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthOut(int outside) +{ + if (mAxisPainter->tickLengthOut != outside) + { + mAxisPainter->tickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets whether sub tick marks are displayed. + + Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) + + \see setTicks +*/ +void QCPAxis::setSubTicks(bool show) +{ + if (mSubTicks != show) + { + mSubTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside + the plot and \a outside is the length they will reach outside the plot. If \a outside is greater + than zero, the tick labels and axis label will increase their distance to the axis accordingly, + so they won't collide with the ticks. + + \see setTickLength, setSubTickLengthIn, setSubTickLengthOut +*/ +void QCPAxis::setSubTickLength(int inside, int outside) +{ + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); +} + +/*! + Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside + the plot. + + \see setSubTickLengthOut, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthIn(int inside) +{ + if (mAxisPainter->subTickLengthIn != inside) + { + mAxisPainter->subTickLengthIn = inside; + } +} + +/*! + Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach + outside the plot. If \a outside is greater than zero, the tick labels will increase their + distance to the axis accordingly, so they won't collide with the ticks. + + \see setSubTickLengthIn, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthOut(int outside) +{ + if (mAxisPainter->subTickLengthOut != outside) + { + mAxisPainter->subTickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets the pen, the axis base line is drawn with. + + \see setTickPen, setSubTickPen +*/ +void QCPAxis::setBasePen(const QPen &pen) +{ + mBasePen = pen; +} + +/*! + Sets the pen, tick marks will be drawn with. + + \see setTickLength, setBasePen +*/ +void QCPAxis::setTickPen(const QPen &pen) +{ + mTickPen = pen; +} + +/*! + Sets the pen, subtick marks will be drawn with. + + \see setSubTickCount, setSubTickLength, setBasePen +*/ +void QCPAxis::setSubTickPen(const QPen &pen) +{ + mSubTickPen = pen; +} + +/*! + Sets the font of the axis label. + + \see setLabelColor +*/ +void QCPAxis::setLabelFont(const QFont &font) +{ + if (mLabelFont != font) + { + mLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the axis label. + + \see setLabelFont +*/ +void QCPAxis::setLabelColor(const QColor &color) +{ + mLabelColor = color; +} + +/*! + Sets the text of the axis label that will be shown below/above or next to the axis, depending on + its orientation. To disable axis labels, pass an empty string as \a str. +*/ +void QCPAxis::setLabel(const QString &str) +{ + if (mLabel != str) + { + mLabel = str; + mCachedMarginValid = false; + } +} + +/*! + Sets the distance between the tick labels and the axis label. + + \see setTickLabelPadding, setPadding +*/ +void QCPAxis::setLabelPadding(int padding) +{ + if (mAxisPainter->labelPadding != padding) + { + mAxisPainter->labelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the padding of the axis. + + When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, + that is left blank. + + The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. + + \see setLabelPadding, setTickLabelPadding +*/ +void QCPAxis::setPadding(int padding) +{ + if (mPadding != padding) + { + mPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the offset the axis has to its axis rect side. + + If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, + only the offset of the inner most axis has meaning (even if it is set to be invisible). The + offset of the other, outer axes is controlled automatically, to place them at appropriate + positions. +*/ +void QCPAxis::setOffset(int offset) +{ + mAxisPainter->offset = offset; +} + +/*! + Sets the font that is used for tick labels when they are selected. + + \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelFont(const QFont &font) +{ + if (font != mSelectedTickLabelFont) + { + mSelectedTickLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts + } +} + +/*! + Sets the font that is used for the axis label when it is selected. + + \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelFont(const QFont &font) +{ + mSelectedLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts +} + +/*! + Sets the color that is used for tick labels when they are selected. + + \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelColor(const QColor &color) +{ + if (color != mSelectedTickLabelColor) + { + mSelectedTickLabelColor = color; + } +} + +/*! + Sets the color that is used for the axis label when it is selected. + + \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelColor(const QColor &color) +{ + mSelectedLabelColor = color; +} + +/*! + Sets the pen that is used to draw the axis base line when selected. + + \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedBasePen(const QPen &pen) +{ + mSelectedBasePen = pen; +} + +/*! + Sets the pen that is used to draw the (major) ticks when selected. + + \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickPen(const QPen &pen) +{ + mSelectedTickPen = pen; +} + +/*! + Sets the pen that is used to draw the subticks when selected. + + \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedSubTickPen(const QPen &pen) +{ + mSelectedSubTickPen = pen; +} + +/*! + Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setUpperEnding +*/ +void QCPAxis::setLowerEnding(const QCPLineEnding &ending) +{ + mAxisPainter->lowerEnding = ending; +} + +/*! + Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the right ending, for vertical axes the top ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setLowerEnding +*/ +void QCPAxis::setUpperEnding(const QCPLineEnding &ending) +{ + mAxisPainter->upperEnding = ending; +} + +/*! + If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper + bounds of the range. The range is simply moved by \a diff. + + If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This + corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). +*/ +void QCPAxis::moveRange(double diff) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + mRange.lower += diff; + mRange.upper += diff; + } else // mScaleType == stLogarithmic + { + mRange.lower *= diff; + mRange.upper *= diff; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis by \a factor around the center of the current axis range. For + example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis + range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around + the center will have moved symmetrically closer). + + If you wish to scale around a different coordinate than the current axis range center, use the + overload \ref scaleRange(double factor, double center). +*/ +void QCPAxis::scaleRange(double factor) +{ + scaleRange(factor, range().center()); +} + +/*! \overload + + Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a + factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at + coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates + around 1.0 will have moved symmetrically closer to 1.0). + + \see scaleRange(double factor) +*/ +void QCPAxis::scaleRange(double factor, double center) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + QCPRange newRange; + newRange.lower = (mRange.lower-center)*factor + center; + newRange.upper = (mRange.upper-center)*factor + center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLinScale(); + } else // mScaleType == stLogarithmic + { + if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range + { + QCPRange newRange; + newRange.lower = qPow(mRange.lower/center, factor)*center; + newRange.upper = qPow(mRange.upper/center, factor)*center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLogScale(); + } else + qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will + be done around the center of the current axis range. + + For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs + plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the + axis rect has. + + This is an operation that changes the range of this axis once, it doesn't fix the scale ratio + indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent + won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent + will follow. +*/ +void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) +{ + int otherPixelSize, ownPixelSize; + + if (otherAxis->orientation() == Qt::Horizontal) + otherPixelSize = otherAxis->axisRect()->width(); + else + otherPixelSize = otherAxis->axisRect()->height(); + + if (orientation() == Qt::Horizontal) + ownPixelSize = axisRect()->width(); + else + ownPixelSize = axisRect()->height(); + + double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; + setRange(range().center(), newRangeSize, Qt::AlignCenter); +} + +/*! + Changes the axis range such that all plottables associated with this axis are fully visible in + that dimension. + + \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes +*/ +void QCPAxis::rescale(bool onlyVisiblePlottables) +{ + QList p = plottables(); + QCPRange newRange; + bool haveRange = false; + for (int i=0; irealVisibility() && onlyVisiblePlottables) + continue; + QCPRange plottableRange; + bool currentFoundRange; + QCP::SignDomain signDomain = QCP::sdBoth; + if (mScaleType == stLogarithmic) + signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + if (p.at(i)->keyAxis() == this) + plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); + else + plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); + if (currentFoundRange) + { + if (!haveRange) + newRange = plottableRange; + else + newRange.expand(plottableRange); + haveRange = true; + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mScaleType == stLinear) + { + newRange.lower = center-mRange.size()/2.0; + newRange.upper = center+mRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mRange.upper/mRange.lower); + newRange.upper = center*qSqrt(mRange.upper/mRange.lower); + } + } + setRange(newRange); + } +} + +/*! + Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. +*/ +double QCPAxis::pixelToCoord(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; + else + return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; + else + return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; + } + } +} + +/*! + Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. +*/ +double QCPAxis::coordToPixel(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + else + return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; + else + { + if (!mRangeReversed) + return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + else + return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + } + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); + else + return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; + else + { + if (!mRangeReversed) + return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + else + return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + } + } + } +} + +/*! + Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function + is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this + function does not change the current selection state of the axis. + + If the axis is not visible (\ref setVisible), this function always returns \ref spNone. + + \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions +*/ +QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const +{ + if (!mVisible) + return spNone; + + if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) + return spAxis; + else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) + return spTickLabels; + else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) + return spAxisLabel; + else + return spNone; +} + +/* inherits documentation from base class */ +double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) + return -1; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; +} + +/*! + Returns a list of all the plottables that have this axis as key or value axis. + + If you are only interested in plottables of type QCPGraph, see \ref graphs. + + \see graphs, items +*/ +QList QCPAxis::plottables() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that have this axis as key or value axis. + + \see plottables, items +*/ +QList QCPAxis::graphs() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis. An item is considered + associated with an axis if at least one of its positions uses the axis as key or value axis. + + \see plottables, graphs +*/ +QList QCPAxis::items() const +{ + QList result; + if (!mParentPlot) return result; + + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to + QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) +*/ +QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return atLeft; + case QCP::msRight: return atRight; + case QCP::msTop: return atTop; + case QCP::msBottom: return atBottom; + default: break; + } + qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; + return atLeft; +} + +/*! + Returns the axis type that describes the opposite axis of an axis with the specified \a type. +*/ +QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) +{ + switch (type) + { + case atLeft: return atRight; break; + case atRight: return atLeft; break; + case atBottom: return atTop; break; + case atTop: return atBottom; break; + default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; + } +} + +/* inherits documentation from base class */ +void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + SelectablePart part = details.value(); + if (mSelectableParts.testFlag(part)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^part : part); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAxis::deselectEvent(bool *selectionStateChanged) +{ + SelectableParts selBefore = mSelectedParts; + setSelectedParts(mSelectedParts & ~mSelectableParts); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis + (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref + QCPAxisRect::setRangeDragAxes) + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. +*/ +void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || + !mAxisRect->rangeDrag().testFlag(orientation()) || + !mAxisRect->rangeDragAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + mDragStartRange = mRange; + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (mDragging) + { + const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); + const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); + if (mScaleType == QCPAxis::stLinear) + { + const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); + setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); + } else if (mScaleType == QCPAxis::stLogarithmic) + { + const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); + setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); + } + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user zoom individual axes + exclusively, by performing the wheel event on top of the axis. + + For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis + (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref + QCPAxisRect::setRangeZoomAxes) + + \seebaseclassmethod + + \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the + axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. +*/ +void QCPAxis::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || + !mAxisRect->rangeZoom().testFlag(orientation()) || + !mAxisRect->rangeZoomAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); + scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); + mParentPlot->replot(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing axis lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); +} + +/*! \internal + + Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. + + \seebaseclassmethod +*/ +void QCPAxis::draw(QCPPainter *painter) +{ + QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + subTickPositions.reserve(mSubTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->basePen = getBasePen(); + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->labelColor = getLabelColor(); + mAxisPainter->label = mLabel; + mAxisPainter->substituteExponent = mNumberBeautifulPowers; + mAxisPainter->tickPen = getTickPen(); + mAxisPainter->subTickPen = getSubTickPen(); + mAxisPainter->tickLabelFont = getTickLabelFont(); + mAxisPainter->tickLabelColor = getTickLabelColor(); + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; + mAxisPainter->reversedEndings = mRangeReversed; + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + mAxisPainter->subTickPositions = subTickPositions; + mAxisPainter->draw(painter); +} + +/*! \internal + + Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling + QCPAxisTicker::generate on the currently installed ticker. + + If a change in the label text/count is detected, the cached axis margin is invalidated to make + sure the next margin calculation recalculates the label sizes and returns an up-to-date value. +*/ +void QCPAxis::setupTickVectors() +{ + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; + + QVector oldLabels = mTickVectorLabels; + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too +} + +/*! \internal + + Returns the pen that is used to draw the axis base line. Depending on the selection state, this + is either mSelectedBasePen or mBasePen. +*/ +QPen QCPAxis::getBasePen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; +} + +/*! \internal + + Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this + is either mSelectedTickPen or mTickPen. +*/ +QPen QCPAxis::getTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; +} + +/*! \internal + + Returns the pen that is used to draw the subticks. Depending on the selection state, this + is either mSelectedSubTickPen or mSubTickPen. +*/ +QPen QCPAxis::getSubTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; +} + +/*! \internal + + Returns the font that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelFont or mTickLabelFont. +*/ +QFont QCPAxis::getTickLabelFont() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; +} + +/*! \internal + + Returns the font that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelFont or mLabelFont. +*/ +QFont QCPAxis::getLabelFont() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; +} + +/*! \internal + + Returns the color that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelColor or mTickLabelColor. +*/ +QColor QCPAxis::getTickLabelColor() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; +} + +/*! \internal + + Returns the color that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelColor or mLabelColor. +*/ +QColor QCPAxis::getLabelColor() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; +} + +/*! \internal + + Returns the appropriate outward margin for this axis. It is needed if \ref + QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref + atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom + margin and so forth. For the calculation, this function goes through similar steps as \ref draw, + so changing one function likely requires the modification of the other one as well. + + The margin consists of the outward tick length, tick label padding, tick label size, label + padding, label size, and padding. + + The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. + unchanged are very fast. +*/ +int QCPAxis::calculateMargin() +{ + if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis + return 0; + + if (mCachedMarginValid) + return mCachedMargin; + + // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels + int margin = 0; + + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->label = mLabel; + mAxisPainter->tickLabelFont = mTickLabelFont; + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + margin += mAxisPainter->size(); + margin += mPadding; + + mCachedMargin = margin; + mCachedMarginValid = true; + return margin; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAxis::selectionCategory() const +{ + return QCP::iSelectAxes; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisPainterPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisPainterPrivate + + \internal + \brief (Private) + + This is a private class and not part of the public QCustomPlot interface. + + It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and + axis label. It also buffers the labels to reduce replot times. The parameters are configured by + directly accessing the public member variables. +*/ + +/*! + Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every + redraw, to utilize the caching mechanisms. +*/ +QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : + type(QCPAxis::atLeft), + basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + lowerEnding(QCPLineEnding::esNone), + upperEnding(QCPLineEnding::esNone), + labelPadding(0), + tickLabelPadding(0), + tickLabelRotation(0), + tickLabelSide(QCPAxis::lsOutside), + substituteExponent(true), + numberMultiplyCross(false), + tickLengthIn(5), + tickLengthOut(0), + subTickLengthIn(2), + subTickLengthOut(0), + tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + offset(0), + abbreviateDecimalPowers(false), + reversedEndings(false), + mParentPlot(parentPlot), + mLabelCache(16) // cache at most 16 (tick) labels +{ +} + +QCPAxisPainterPrivate::~QCPAxisPainterPrivate() +{ +} + +/*! \internal + + Draws the axis with the specified \a painter. + + The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set + here, too. +*/ +void QCPAxisPainterPrivate::draw(QCPPainter *painter) +{ + QByteArray newHash = generateLabelParameterHash(); + if (newHash != mLabelParameterHash) + { + mLabelCache.clear(); + mLabelParameterHash = newHash; + } + + QPoint origin; + switch (type) + { + case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; + case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; + case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; + case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; + } + + double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) + switch (type) + { + case QCPAxis::atTop: yCor = -1; break; + case QCPAxis::atRight: xCor = 1; break; + default: break; + } + int margin = 0; + // draw baseline: + QLineF baseLine; + painter->setPen(basePen); + if (QCPAxis::orientation(type) == Qt::Horizontal) + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); + else + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); + if (reversedEndings) + baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later + painter->drawLine(baseLine); + + // draw ticks: + if (!tickPositions.isEmpty()) + { + painter->setPen(tickPen); + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); + } + } + + // draw subticks: + if (!subTickPositions.isEmpty()) + { + painter->setPen(subTickPen); + // direction of ticks ("inward" is right for left axis and left for right axis) + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); + } + } + margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // draw axis base endings: + bool antialiasingBackup = painter->antialiasing(); + painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't + painter->setBrush(QBrush(basePen.color())); + QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); + if (lowerEnding.style() != QCPLineEnding::esNone) + lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); + if (upperEnding.style() != QCPLineEnding::esNone) + upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); + painter->setAntialiasing(antialiasingBackup); + + // tick labels: + QRect oldClipRect; + if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect + { + oldClipRect = painter->clipRegion().boundingRect(); + painter->setClipRect(axisRect); + } + QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label + if (!tickLabels.isEmpty()) + { + if (tickLabelSide == QCPAxis::lsOutside) + margin += tickLabelPadding; + painter->setFont(tickLabelFont); + painter->setPen(QPen(tickLabelColor)); + const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); + int distanceToAxis = margin; + if (tickLabelSide == QCPAxis::lsInside) + distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + for (int i=0; isetClipRect(oldClipRect); + + // axis label: + QRect labelBounds; + if (!label.isEmpty()) + { + margin += labelPadding; + painter->setFont(labelFont); + painter->setPen(QPen(labelColor)); + labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); + if (type == QCPAxis::atLeft) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); + painter->rotate(-90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atRight) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); + painter->rotate(90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atTop) + painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + else if (type == QCPAxis::atBottom) + painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + } + + // set selection boxes: + int selectionTolerance = 0; + if (mParentPlot) + selectionTolerance = mParentPlot->selectionTolerance(); + else + qDebug() << Q_FUNC_INFO << "mParentPlot is null"; + int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); + int selAxisInSize = selectionTolerance; + int selTickLabelSize; + int selTickLabelOffset; + if (tickLabelSide == QCPAxis::lsOutside) + { + selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; + } else + { + selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + } + int selLabelSize = labelBounds.height(); + int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; + if (type == QCPAxis::atLeft) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atRight) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atTop) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); + } else if (type == QCPAxis::atBottom) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); + } + mAxisSelectionBox = mAxisSelectionBox.normalized(); + mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); + mLabelSelectionBox = mLabelSelectionBox.normalized(); + // draw hitboxes for debug purposes: + //painter->setBrush(Qt::NoBrush); + //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); +} + +/*! \internal + + Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone + direction) needed to fit the axis. +*/ +int QCPAxisPainterPrivate::size() const +{ + int result = 0; + + // get length of tick marks pointing outwards: + if (!tickPositions.isEmpty()) + result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // calculate size of tick labels: + if (tickLabelSide == QCPAxis::lsOutside) + { + QSize tickLabelsSize(0, 0); + if (!tickLabels.isEmpty()) + { + for (int i=0; ibufferDevicePixelRatio())); + result.append(QByteArray::number(tickLabelRotation)); + result.append(QByteArray::number((int)tickLabelSide)); + result.append(QByteArray::number((int)substituteExponent)); + result.append(QByteArray::number((int)numberMultiplyCross)); + result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); + result.append(tickLabelFont.toString().toLatin1()); + return result; +} + +/*! \internal + + Draws a single tick label with the provided \a painter, utilizing the internal label cache to + significantly speed up drawing of labels that were drawn in previous calls. The tick label is + always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in + pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence + for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), + at which the label should be drawn. + + In order to later draw the axis label in a place that doesn't overlap with the tick labels, the + largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref + drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a + tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently + holds. + + The label is drawn with the font and pen that are currently set on the \a painter. To draw + superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref + getTickLabelData). +*/ +void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) +{ + // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! + if (text.isEmpty()) return; + QSize finalSize; + QPointF labelAnchor; + switch (type) + { + case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; + case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; + case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; + case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; + } + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled + { + CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache + if (!cachedLabel) // no cached label existed, create it + { + cachedLabel = new CachedLabel; + TickLabelData labelData = getTickLabelData(painter->font(), text); + cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); + if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) + { + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif +#endif + } else + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); + cachedLabel->pixmap.fill(Qt::transparent); + QCPPainter cachePainter(&cachedLabel->pixmap); + cachePainter.setPen(painter->pen()); + drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); + } + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); + else + labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } + mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created + } else // label caching disabled, draw text directly on surface: + { + TickLabelData labelData = getTickLabelData(painter->font(), text); + QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); + else + labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); + finalSize = labelData.rotatedTotalBounds.size(); + } + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a + y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to + directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when + QCP::phCacheLabels plotting hint is not set. +*/ +void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const +{ + // backup painter settings that we're about to change: + QTransform oldTransform = painter->transform(); + QFont oldFont = painter->font(); + + // transform painter to position/rotation: + painter->translate(x, y); + if (!qFuzzyIsNull(tickLabelRotation)) + painter->rotate(tickLabelRotation); + + // draw text: + if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); + if (!labelData.suffixPart.isEmpty()) + painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); + painter->setFont(labelData.expFont); + painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); + } else + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); + } + + // reset painter settings to what it was before: + painter->setTransform(oldTransform); + painter->setFont(oldFont); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Transforms the passed \a text and \a font to a tickLabelData structure that can then be further + processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and + exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. +*/ +QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const +{ + TickLabelData result; + + // determine whether beautiful decimal powers should be used + bool useBeautifulPowers = false; + int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart + int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart + if (substituteExponent) + { + ePos = text.indexOf(QLatin1Char('e')); + if (ePos > 0 && text.at(ePos-1).isDigit()) + { + eLast = ePos; + while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) + ++eLast; + if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power + useBeautifulPowers = true; + } + } + + // calculate text bounding rects and do string preparation for beautiful decimal powers: + result.baseFont = font; + if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line + result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding + if (useBeautifulPowers) + { + // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: + result.basePart = text.left(ePos); + result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent + // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: + if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) + result.basePart = QLatin1String("10"); + else + result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); + result.expPart = text.mid(ePos+1, eLast-ePos); + // clip "+" and leading zeros off expPart: + while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' + result.expPart.remove(1, 1); + if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) + result.expPart.remove(0, 1); + // prepare smaller font for exponent: + result.expFont = font; + if (result.expFont.pointSize() > 0) + result.expFont.setPointSize(result.expFont.pointSize()*0.75); + else + result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); + // calculate bounding rects of base part(s), exponent part and total one: + result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); + result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); + if (!result.suffixPart.isEmpty()) + result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); + result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA + } else // useBeautifulPowers == false + { + result.basePart = text; + result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); + } + result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler + + // calculate possibly different bounding rect after rotation: + result.rotatedTotalBounds = result.totalBounds; + if (!qFuzzyIsNull(tickLabelRotation)) + { + QTransform transform; + transform.rotate(tickLabelRotation); + result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); + } + + return result; +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Calculates the offset at which the top left corner of the specified tick label shall be drawn. + The offset is relative to a point right next to the tick the label belongs to. + + This function is thus responsible for e.g. centering tick labels under ticks and positioning them + appropriately when they are rotated. +*/ +QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const +{ + /* + calculate label offset from base point at tick (non-trivial, for best visual appearance): short + explanation for bottom axis: The anchor, i.e. the point in the label that is placed + horizontally under the corresponding tick is always on the label side that is closer to the + axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height + is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text + will be centered under the tick (i.e. displaced horizontally by half its height). At the same + time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick + labels. + */ + bool doRotation = !qFuzzyIsNull(tickLabelRotation); + bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. + double radians = tickLabelRotation/180.0*M_PI; + int x=0, y=0; + if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); + y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = -labelData.totalBounds.width(); + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = 0; + y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = 0; + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; + y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); + } else + { + x = -qSin(-radians)*labelData.totalBounds.height()/2.0; + y = -qCos(-radians)*labelData.totalBounds.height(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = -labelData.totalBounds.height(); + } + } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height()/2.0; + y = 0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; + y = +qSin(-radians)*labelData.totalBounds.width(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = 0; + } + } + + return QPointF(x, y); +} + +/*! \internal + + Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label + to be drawn, depending on number format etc. Since only the largest tick label is wanted for the + margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a + smaller width/height. +*/ +void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const +{ + // note: this function must return the same tick label sizes as the placeTickLabel function. + QSize finalSize; + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label + { + const CachedLabel *cachedLabel = mLabelCache.object(text); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } else // label caching disabled or no label with this text cached: + { + TickLabelData labelData = getTickLabelData(font, text); + finalSize = labelData.rotatedTotalBounds.size(); + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} +/* end of 'src/axis/axis.cpp' */ + + +/* including file 'src/scatterstyle.cpp', size 17450 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPScatterStyle +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPScatterStyle + \brief Represents the visual appearance of scatter points + + This class holds information about shape, color and size of scatter points. In plottables like + QCPGraph it is used to store how scatter points shall be drawn. For example, \ref + QCPGraph::setScatterStyle takes a QCPScatterStyle instance. + + A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a + fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can + be controlled with \ref setSize. + + \section QCPScatterStyle-defining Specifying a scatter style + + You can set all these configurations either by calling the respective functions on an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 + + Or you can use one of the various constructors that take different parameter combinations, making + it easy to specify a scatter style in a single call, like so: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 + + \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable + + There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref + QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref + isPenDefined will return false. It leads to scatter points that inherit the pen from the + plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line + color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes + it very convenient to set up typical scatter settings: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation + + Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works + because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly + into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) + constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref + ScatterShape, where actually a QCPScatterStyle is expected. + + \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps + + QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. + + For custom shapes, you can provide a QPainterPath with the desired shape to the \ref + setCustomPath function or call the constructor that takes a painter path. The scatter shape will + automatically be set to \ref ssCustom. + + For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the + constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. + Note that \ref setSize does not influence the appearance of the pixmap. +*/ + +/* start documentation of inline functions */ + +/*! \fn bool QCPScatterStyle::isNone() const + + Returns whether the scatter shape is \ref ssNone. + + \see setShape +*/ + +/*! \fn bool QCPScatterStyle::isPenDefined() const + + Returns whether a pen has been defined for this scatter style. + + The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those + are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen + is undefined, the pen of the respective plottable will be used for drawing scatters. + + If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call + \ref undefinePen. + + \see setPen +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle() : + mSize(6), + mShape(ssNone), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or + brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : + mSize(size), + mShape(shape), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + and size to \a size. No brush is defined, i.e. the scatter point will not be filled. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(Qt::NoBrush), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + the brush color to \a fill (with a solid pattern), and size to \a size. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(QBrush(fill)), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the + brush to \a brush, and size to \a size. + + \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen + and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n + QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n + doesn't necessarily lead C++ to use this constructor in some cases, but might mistake + Qt::NoPen for a QColor and use the + \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) + constructor instead (which will lead to an unexpected look of the scatter points). To prevent + this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) + instead of just Qt::blue, to clearly point out to the compiler that this constructor is + wanted. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(shape), + mPen(pen), + mBrush(brush), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape + is set to \ref ssPixmap. +*/ +QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : + mSize(5), + mShape(ssPixmap), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPixmap(pixmap), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The + scatter shape is set to \ref ssCustom. + + The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly + different meaning than for built-in scatter points: The custom path will be drawn scaled by a + factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its + original size by default. To for example double the size of the path, set \a size to 12. +*/ +QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(ssCustom), + mPen(pen), + mBrush(brush), + mCustomPath(customPath), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Copies the specified \a properties from the \a other scatter style to this scatter style. +*/ +void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) +{ + if (properties.testFlag(spPen)) + { + setPen(other.pen()); + if (!other.isPenDefined()) + undefinePen(); + } + if (properties.testFlag(spBrush)) + setBrush(other.brush()); + if (properties.testFlag(spSize)) + setSize(other.size()); + if (properties.testFlag(spShape)) + { + setShape(other.shape()); + if (other.shape() == ssPixmap) + setPixmap(other.pixmap()); + else if (other.shape() == ssCustom) + setCustomPath(other.customPath()); + } +} + +/*! + Sets the size (pixel diameter) of the drawn scatter points to \a size. + + \see setShape +*/ +void QCPScatterStyle::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the shape to \a shape. + + Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref + ssPixmap and \ref ssCustom, respectively. + + \see setSize +*/ +void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) +{ + mShape = shape; +} + +/*! + Sets the pen that will be used to draw scatter points to \a pen. + + If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after + a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen + previously by calling this function and now wish to undefine the pen, call \ref undefinePen. + + \see setBrush +*/ +void QCPScatterStyle::setPen(const QPen &pen) +{ + mPenDefined = true; + mPen = pen; +} + +/*! + Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter + shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. + + \see setPen +*/ +void QCPScatterStyle::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the pixmap that will be drawn as scatter point to \a pixmap. + + Note that \ref setSize does not influence the appearance of the pixmap. + + The scatter shape is automatically set to \ref ssPixmap. +*/ +void QCPScatterStyle::setPixmap(const QPixmap &pixmap) +{ + setShape(ssPixmap); + mPixmap = pixmap; +} + +/*! + Sets the custom shape that will be drawn as scatter point to \a customPath. + + The scatter shape is automatically set to \ref ssCustom. +*/ +void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) +{ + setShape(ssCustom); + mCustomPath = customPath; +} + +/*! + Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen + implies). + + A call to \ref setPen will define a pen. +*/ +void QCPScatterStyle::undefinePen() +{ + mPenDefined = false; +} + +/*! + Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an + undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. + + This function is used by plottables (or any class that wants to draw scatters) just before a + number of scatters with this style shall be drawn with the \a painter. + + \see drawShape +*/ +void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const +{ + painter->setPen(mPenDefined ? mPen : defaultPen); + painter->setBrush(mBrush); +} + +/*! + Draws the scatter shape with \a painter at position \a pos. + + This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be + called before scatter points are drawn with \ref drawShape. + + \see applyTo +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const +{ + drawShape(painter, pos.x(), pos.y()); +} + +/*! \overload + Draws the scatter shape with \a painter at position \a x and \a y. +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const +{ + double w = mSize/2.0; + switch (mShape) + { + case ssNone: break; + case ssDot: + { + painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); + break; + } + case ssCross: + { + painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); + painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); + break; + } + case ssPlus: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCircle: + { + painter->drawEllipse(QPointF(x , y), w, w); + break; + } + case ssDisc: + { + QBrush b = painter->brush(); + painter->setBrush(painter->pen().color()); + painter->drawEllipse(QPointF(x , y), w, w); + painter->setBrush(b); + break; + } + case ssSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + break; + } + case ssDiamond: + { + QPointF lineArray[4] = {QPointF(x-w, y), + QPointF( x, y-w), + QPointF(x+w, y), + QPointF( x, y+w)}; + painter->drawPolygon(lineArray, 4); + break; + } + case ssStar: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); + break; + } + case ssTriangle: + { + QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), + QPointF(x+w, y+0.755*w), + QPointF( x, y-0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssTriangleInverted: + { + QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), + QPointF(x+w, y-0.755*w), + QPointF( x, y+0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssCrossSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); + painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); + break; + } + case ssPlusSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCrossCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); + break; + } + case ssPlusCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssPeace: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x, y-w, x, y+w)); + painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); + break; + } + case ssPixmap: + { + const double widthHalf = mPixmap.width()*0.5; + const double heightHalf = mPixmap.height()*0.5; +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) + const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#else + const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#endif + if (clipRect.contains(x, y)) + painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); + break; + } + case ssCustom: + { + QTransform oldTransform = painter->transform(); + painter->translate(x, y); + painter->scale(mSize/6.0, mSize/6.0); + painter->drawPath(mCustomPath); + painter->setTransform(oldTransform); + break; + } + } +} +/* end of 'src/scatterstyle.cpp' */ + +//amalgamation: add datacontainer.cpp + +/* including file 'src/plottable.cpp', size 38845 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecorator +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecorator + \brief Controls how a plottable's data selection is drawn + + Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref + QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. + + The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the + scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref + QCPScatterStyle is itself composed of different properties such as color shape and size, the + decorator allows specifying exactly which of those properties shall be used for the selected data + point, via \ref setUsedScatterProperties. + + A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref + QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance + of selected segments. + + Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is + especially useful since plottables take ownership of the passed selection decorator, and thus the + same decorator instance can not be passed to multiple plottables. + + Selection decorators can also themselves perform drawing operations by reimplementing \ref + drawDecoration, which is called by the plottable's draw method. The base class \ref + QCPSelectionDecorator does not make use of this however. For example, \ref + QCPSelectionDecoratorBracket draws brackets around selected data segments. +*/ + +/*! + Creates a new QCPSelectionDecorator instance with default values +*/ +QCPSelectionDecorator::QCPSelectionDecorator() : + mPen(QColor(80, 80, 255), 2.5), + mBrush(Qt::NoBrush), + mScatterStyle(), + mUsedScatterProperties(QCPScatterStyle::spNone), + mPlottable(0) +{ +} + +QCPSelectionDecorator::~QCPSelectionDecorator() +{ +} + +/*! + Sets the pen that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the scatter style that will be used by the parent plottable to draw scatters in selected + data segments. + + \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the + plottable. The used properties can also be changed via \ref setUsedScatterProperties. +*/ +void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) +{ + mScatterStyle = scatterStyle; + setUsedScatterProperties(usedProperties); +} + +/*! + Use this method to define which properties of the scatter style (set via \ref setScatterStyle) + will be used for selected data segments. All properties of the scatter style that are not + specified in \a properties will remain as specified in the plottable's original scatter style. + + \see QCPScatterStyle::ScatterProperty +*/ +void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) +{ + mUsedScatterProperties = properties; +} + +/*! + Sets the pen of \a painter to the pen of this selection decorator. + + \see applyBrush, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyPen(QCPPainter *painter) const +{ + painter->setPen(mPen); +} + +/*! + Sets the brush of \a painter to the brush of this selection decorator. + + \see applyPen, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const +{ + painter->setBrush(mBrush); +} + +/*! + Returns the scatter style that the parent plottable shall use for selected scatter points. The + plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending + on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this + selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. + + \see applyPen, applyBrush, setScatterStyle +*/ +QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const +{ + QCPScatterStyle result(unselectedStyle); + result.setFromOther(mScatterStyle, mUsedScatterProperties); + + // if style shall inherit pen from plottable (has no own pen defined), give it the selected + // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the + // plottable: + if (!result.isPenDefined()) + result.setPen(mPen); + + return result; +} + +/*! + Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to + this selection decorator. +*/ +void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) +{ + setPen(other->pen()); + setBrush(other->brush()); + setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); +} + +/*! + This method is called by all plottables' draw methods to allow custom selection decorations to be + drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data + selection for which the decoration shall be drawn. + + The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so + this method does nothing. +*/ +void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + Q_UNUSED(painter) + Q_UNUSED(selection) +} + +/*! \internal + + This method is called as soon as a selection decorator is associated with a plottable, by a call + to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access + data points via the \ref QCPAbstractPlottable::interface1D interface). + + If the selection decorator was already added to a different plottable before, this method aborts + the registration and returns false. +*/ +bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottable) + { + mPlottable = plottable; + return true; + } else + { + qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); + return false; + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable + \brief The abstract base class for all data representing objects in a plot. + + It defines a very basic interface like name, pen, brush, visibility etc. Since this class is + abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to + create new ways of displaying data (see "Creating own plottables" below). Plottables that display + one-dimensional data (i.e. data points have a single key dimension and one or multiple values at + each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details + there. + + All further specifics are in the subclasses, for example: + \li A normal graph with possibly a line and/or scatter points \ref QCPGraph + (typically created with \ref QCustomPlot::addGraph) + \li A parametric curve: \ref QCPCurve + \li A bar chart: \ref QCPBars + \li A statistical box plot: \ref QCPStatisticalBox + \li A color encoded two-dimensional map: \ref QCPColorMap + \li An OHLC/Candlestick chart: \ref QCPFinancial + + \section plottables-subclassing Creating own plottables + + Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display + two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) + data dimensions. If you want to display data with only one logical key dimension, you should + rather derive from \ref QCPAbstractPlottable1D. + + If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must + implement: + \li \ref selectTest + \li \ref draw + \li \ref drawLegendIcon + \li \ref getKeyRange + \li \ref getValueRange + + See the documentation of those functions for what they need to do. + + For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot + coordinates to pixel coordinates. This function is quite convenient, because it takes the + orientation of the key and value axes into account for you (x and y are swapped when the key axis + is vertical and the value axis horizontal). If you are worried about performance (i.e. you need + to translate many points in a loop like QCPGraph), you can directly use \ref + QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis + yourself. + + Here are some important members you inherit from QCPAbstractPlottable: + + + + + + + + + + + + + + + + + + + + + + + + + + +
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable + (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable + (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates + to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of + the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. + When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. + Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done + by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
+*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const + + Provides access to the selection decorator of this plottable. The selection decorator controls + how selected data ranges are drawn (e.g. their pen color and fill), see \ref + QCPSelectionDecorator for details. + + If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref + setSelectionDecorator. +*/ + +/*! \fn bool QCPAbstractPlottable::selected() const + + Returns true if there are any data points of the plottable currently selected. Use \ref selection + to retrieve the current \ref QCPDataSelection. +*/ + +/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const + + Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on + this plottable. + + \see selected, setSelection, setSelectable +*/ + +/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() + + If this plottable is a one-dimensional plottable, i.e. it implements the \ref + QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case + of a \ref QCPColorMap) returns zero. + + You can use this method to gain read access to data coordinates while holding a pointer to the + abstract base class only. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of pure virtual functions */ + +/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 + \internal + + called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation + of this plottable inside \a rect, next to the plottable name. + + The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't + appear outside the legend icon border. +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 + + Returns the coordinate range that all data in this plottable span in the key axis dimension. For + logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref + QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only + negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points + will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref + QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could + be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getValueRange +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 + + Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span + in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref + QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign + domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and + all positive points will be ignored for range calculation. For no restriction, just set \a + inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates + whether a range could be found or not. If this is false, you shouldn't use the returned range + (e.g. no points in data). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getKeyRange +*/ + +/* end of documentation of pure virtual functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether + there are any points selected or not. + + \see selectionChanged(const QCPDataSelection &selection) +*/ + +/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selection holds the + currently selected data ranges. + + \see selectionChanged(bool selected) +*/ + +/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); + + This signal is emitted when the selectability of this plottable has changed. + + \see setSelectable +*/ + +/* end of documentation of signals */ + +/*! + Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as + its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance + and have perpendicular orientations. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, + it can't be directly instantiated. + + You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. +*/ +QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), + mName(), + mAntialiasedFill(true), + mAntialiasedScatters(true), + mPen(Qt::black), + mBrush(Qt::NoBrush), + mKeyAxis(keyAxis), + mValueAxis(valueAxis), + mSelectable(QCP::stWhole), + mSelectionDecorator(0) +{ + if (keyAxis->parentPlot() != valueAxis->parentPlot()) + qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; + if (keyAxis->orientation() == valueAxis->orientation()) + qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; + + mParentPlot->registerPlottable(this); + setSelectionDecorator(new QCPSelectionDecorator); +} + +QCPAbstractPlottable::~QCPAbstractPlottable() +{ + if (mSelectionDecorator) + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + The name is the textual representation of this plottable as it is displayed in the legend + (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. +*/ +void QCPAbstractPlottable::setName(const QString &name) +{ + mName = name; +} + +/*! + Sets whether fills of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedFill(bool enabled) +{ + mAntialiasedFill = enabled; +} + +/*! + Sets whether the scatter symbols of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) +{ + mAntialiasedScatters = enabled; +} + +/*! + The pen is used to draw basic lines that make up the plottable representation in the + plot. + + For example, the \ref QCPGraph subclass draws its graph lines with this pen. + + \see setBrush +*/ +void QCPAbstractPlottable::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + The brush is used to draw basic fills of the plottable representation in the + plot. The Fill can be a color, gradient or texture, see the usage of QBrush. + + For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when + it's not set to Qt::NoBrush. + + \see setPen +*/ +void QCPAbstractPlottable::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal + to the plottable's value axis. This function performs no checks to make sure this is the case. + The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the + y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setValueAxis +*/ +void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) +{ + mKeyAxis = axis; +} + +/*! + The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is + orthogonal to the plottable's key axis. This function performs no checks to make sure this is the + case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and + the y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setKeyAxis +*/ +void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) +{ + mValueAxis = axis; +} + + +/*! + Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently + (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref + selectionDecorator). + + The entire selection mechanism for plottables is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when + you wish to change the selection state programmatically. + + Using \ref setSelectable you can further specify for each plottable whether and to which + granularity it is selectable. If \a selection is not compatible with the current \ref + QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted + accordingly (see \ref QCPDataSelection::enforceType). + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractPlottable::setSelection(QCPDataSelection selection) +{ + selection.enforceType(mSelectable); + if (mSelection != selection) + { + mSelection = selection; + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } +} + +/*! + Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to + customize the visual representation of selected data ranges further than by using the default + QCPSelectionDecorator. + + The plottable takes ownership of the \a decorator. + + The currently set decorator can be accessed via \ref selectionDecorator. +*/ +void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) +{ + if (decorator) + { + if (decorator->registerWithPlottable(this)) + { + if (mSelectionDecorator) // delete old decorator if necessary + delete mSelectionDecorator; + mSelectionDecorator = decorator; + } + } else if (mSelectionDecorator) // just clear decorator + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + Sets whether and to which granularity this plottable can be selected. + + A selection can happen by clicking on the QCustomPlot surface (When \ref + QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect + (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by + calling \ref setSelection. + + \see setSelection, QCP::SelectionType +*/ +void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + QCPDataSelection oldSelection = mSelection; + mSelection.enforceType(mSelectable); + Q_EMIT selectableChanged(mSelectable); + if (mSelection != oldSelection) + { + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } + } +} + + +/*! + Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. + + \see pixelsToCoords, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + x = keyAxis->coordToPixel(key); + y = valueAxis->coordToPixel(value); + } else + { + y = keyAxis->coordToPixel(key); + x = valueAxis->coordToPixel(value); + } +} + +/*! \overload + + Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. +*/ +const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); + else + return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); +} + +/*! + Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. + + \see coordsToPixels, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + key = keyAxis->pixelToCoord(x); + value = valueAxis->pixelToCoord(y); + } else + { + key = keyAxis->pixelToCoord(y); + value = valueAxis->pixelToCoord(x); + } +} + +/*! \overload + + Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. +*/ +void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const +{ + pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); +} + +/*! + Rescales the key and value axes associated with this plottable to contain all displayed data, so + the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make + sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. + Instead it will stay in the current sign domain and ignore all parts of the plottable that lie + outside of that domain. + + \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show + multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has + \a onlyEnlarge set to false (the default), and all subsequent set to true. + + \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale +*/ +void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const +{ + rescaleKeyAxis(onlyEnlarge); + rescaleValueAxis(onlyEnlarge); +} + +/*! + Rescales the key axis of the plottable so the whole plottable is visible. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (keyAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getKeyRange(foundRange, signDomain); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(keyAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (keyAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-keyAxis->range().size()/2.0; + newRange.upper = center+keyAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); + newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); + } + } + keyAxis->setRange(newRange); + } +} + +/*! + Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is + set to true, only the data points which are in the currently visible key axis range are + considered. + + Returns true if the axis was actually scaled. This might not be the case if this plottable has an + invalid range, e.g. because it has no data points. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (valueAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(valueAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-valueAxis->range().size()/2.0; + newRange.upper = center+valueAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); + newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); + } + } + valueAxis->setRange(newRange); + } +} + +/*! \overload + + Adds this plottable to the specified \a legend. + + Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. + when the legend exists and a legend item associated with this plottable isn't already in the + legend. + + If the plottable needs a more specialized representation in the legend, you can create a + corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead + of calling this method. + + \see removeFromLegend, QCPLegend::addItem +*/ +bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + if (legend->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; + return false; + } + + if (!legend->hasItemWithPlottable(this)) + { + legend->addItem(new QCPPlottableLegendItem(legend, this)); + return true; + } else + return false; +} + +/*! \overload + + Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). + + \see removeFromLegend +*/ +bool QCPAbstractPlottable::addToLegend() +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return addToLegend(mParentPlot->legend); +} + +/*! \overload + + Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem + that is associated with this plottable is removed. + + Returns true on success, i.e. if the legend exists and a legend item associated with this + plottable was found and removed. + + \see addToLegend, QCPLegend::removeItem +*/ +bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + + if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) + return legend->removeItem(lip); + else + return false; +} + +/*! \overload + + Removes the plottable from the legend of the parent QCustomPlot. + + \see addToLegend +*/ +bool QCPAbstractPlottable::removeFromLegend() const +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return removeFromLegend(mParentPlot->legend); +} + +/* inherits documentation from base class */ +QRect QCPAbstractPlottable::clipRect() const +{ + if (mKeyAxis && mValueAxis) + return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); + else + return QRect(); +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractPlottable::selectionCategory() const +{ + return QCP::iSelectPlottables; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable fills. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable scatter points. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint +*/ +void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + + if (mSelectable != QCP::stNone) + { + QCPDataSelection newSelection = details.value(); + QCPDataSelection selectionBefore = mSelection; + if (additive) + { + if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit + { + if (selected()) + setSelection(QCPDataSelection()); + else + setSelection(newSelection); + } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments + { + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); + else + setSelection(mSelection+newSelection); + } + } else + setSelection(newSelection); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable != QCP::stNone) + { + QCPDataSelection selectionBefore = mSelection; + setSelection(QCPDataSelection()); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} +/* end of 'src/plottable.cpp' */ + + +/* including file 'src/item.cpp', size 49269 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemAnchor +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemAnchor + \brief An anchor of an item to which positions can be attached to. + + An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't + control anything on its item, but provides a way to tie other items via their positions to the + anchor. + + For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. + Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can + attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by + calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the + QCPItemRect. This way the start of the line will now always follow the respective anchor location + on the rect item. + + Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an + anchor to other positions. + + To learn how to provide anchors in your own item subclasses, see the subclassing section of the + QCPAbstractItem documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() + + Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if + it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). + + This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids + dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with + gcc compiler). +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : + mName(name), + mParentPlot(parentPlot), + mParentItem(parentItem), + mAnchorId(anchorId) +{ +} + +QCPItemAnchor::~QCPItemAnchor() +{ + // unregister as parent at children: + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } +} + +/*! + Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. + + The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the + parent item, QCPItemAnchor is just an intermediary. +*/ +QPointF QCPItemAnchor::pixelPosition() const +{ + if (mParentItem) + { + if (mAnchorId > -1) + { + return mParentItem->anchorPixelPosition(mAnchorId); + } else + { + qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; + return QPointF(); + } + } else + { + qDebug() << Q_FUNC_INFO << "no parent item set"; + return QPointF(); + } +} + +/*! \internal + + Adds \a pos to the childX list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.contains(pos)) + mChildrenX.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childX list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + +/*! \internal + + Adds \a pos to the childY list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.contains(pos)) + mChildrenY.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childY list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPosition +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPosition + \brief Manages the position of an item. + + Every item has at least one public QCPItemPosition member pointer which provides ways to position the + item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: + \a topLeft and \a bottomRight. + + QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type + defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel + coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also + possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref + setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y + direction, while following a plot coordinate in the X direction. + + A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie + multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) + are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) + means directly ontop of the parent anchor. For example, You could attach the \a start position of + a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line + always be centered under the text label, no matter where the text is moved to. For more advanced + plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see + \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X + direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B + in Y. + + Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent + anchor for other positions. + + To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This + works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref + setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified + pixel values. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const + + Returns the current position type. + + If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the + type of the X coordinate. In that case rather use \a typeX() and \a typeY(). + + \see setType +*/ + +/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const + + Returns the current parent anchor. + + If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), + this method returns the parent anchor of the Y coordinate. In that case rather use \a + parentAnchorX() and \a parentAnchorY(). + + \see setParentAnchor +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : + QCPItemAnchor(parentPlot, parentItem, name), + mPositionTypeX(ptAbsolute), + mPositionTypeY(ptAbsolute), + mKey(0), + mValue(0), + mParentAnchorX(0), + mParentAnchorY(0) +{ +} + +QCPItemPosition::~QCPItemPosition() +{ + // unregister as parent at children: + // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then + // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } + // unregister as child in parent: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPItemPosition::axisRect() const +{ + return mAxisRect.data(); +} + +/*! + Sets the type of the position. The type defines how the coordinates passed to \ref setCoords + should be handled and how the QCPItemPosition should behave in the plot. + + The possible values for \a type can be separated in two main categories: + + \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords + and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. + By default, the QCustomPlot's x- and yAxis are used. + + \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This + corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref + ptAxisRectRatio. They differ only in the way the absolute position is described, see the + documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify + the axis rect with \ref setAxisRect. By default this is set to the main axis rect. + + Note that the position type \ref ptPlotCoords is only available (and sensible) when the position + has no parent anchor (\ref setParentAnchor). + + If the type is changed, the apparent pixel position on the plot is preserved. This means + the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. + + This method sets the type for both X and Y directions. It is also possible to set different types + for X and Y, see \ref setTypeX, \ref setTypeY. +*/ +void QCPItemPosition::setType(QCPItemPosition::PositionType type) +{ + setTypeX(type); + setTypeY(type); +} + +/*! + This method sets the position type of the X coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeY +*/ +void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) +{ + if (mPositionTypeX != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeX = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + This method sets the position type of the Y coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeX +*/ +void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) +{ + if (mPositionTypeY != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeY = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now + follow any position changes of the anchor. The local coordinate system of positions with a parent + anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence + the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) + + if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved + during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position + will be exactly on top of the parent anchor. + + To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. + + If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is + set to \ref ptAbsolute, to keep the position in a valid state. + + This method sets the parent anchor for both X and Y directions. It is also possible to set + different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. +*/ +bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); + bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); + return successX && successY; +} + +/*! + This method sets the parent anchor of the X coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorY +*/ +bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorX(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) + setTypeX(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildX(this); + mParentAnchorX = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(0, coords().y()); + return true; +} + +/*! + This method sets the parent anchor of the Y coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorX +*/ +bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorY(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) + setTypeY(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildY(this); + mParentAnchorY = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(coords().x(), 0); + return true; +} + +/*! + Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type + (\ref setType, \ref setTypeX, \ref setTypeY). + + For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position + on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the + QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the + plot coordinate system defined by the axes set by \ref setAxes. By default those are the + QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available + coordinate types and their meaning. + + If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a + value must also be provided in the different coordinate systems. Here, the X type refers to \a + key, and the Y type refers to \a value. + + \see setPixelPosition +*/ +void QCPItemPosition::setCoords(double key, double value) +{ + mKey = key; + mValue = value; +} + +/*! \overload + + Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the + meaning of \a value of the \ref setCoords(double key, double value) method. +*/ +void QCPItemPosition::setCoords(const QPointF &pos) +{ + setCoords(pos.x(), pos.y()); +} + +/*! + Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It + includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). + + \see setPixelPosition +*/ +QPointF QCPItemPosition::pixelPosition() const +{ + QPointF result; + + // determine X: + switch (mPositionTypeX) + { + case ptAbsolute: + { + result.rx() = mKey; + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + result.rx() = mKey*mParentPlot->viewport().width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mParentPlot->viewport().left(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.rx() = mKey*mAxisRect.data()->width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mAxisRect.data()->left(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + // determine Y: + switch (mPositionTypeY) + { + case ptAbsolute: + { + result.ry() = mValue; + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + result.ry() = mValue*mParentPlot->viewport().height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mParentPlot->viewport().top(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.ry() = mValue*mAxisRect.data()->height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mAxisRect.data()->top(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + result.ry() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + result.ry() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + return result; +} + +/*! + When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the + coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and + yAxis of the QCustomPlot. +*/ +void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + mKeyAxis = keyAxis; + mValueAxis = valueAxis; +} + +/*! + When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the + coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of + the QCustomPlot. +*/ +void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) +{ + mAxisRect = axisRect; +} + +/*! + Sets the apparent pixel position. This works no matter what type (\ref setType) this + QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed + appropriately, to make the position finally appear at the specified pixel values. + + Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is + identical to that of \ref setCoords. + + \see pixelPosition, setCoords +*/ +void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) +{ + double x = pixelPosition.x(); + double y = pixelPosition.y(); + + switch (mPositionTypeX) + { + case ptAbsolute: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mParentPlot->viewport().left(); + x /= (double)mParentPlot->viewport().width(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mAxisRect.data()->left(); + x /= (double)mAxisRect.data()->width(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + x = mKeyAxis.data()->pixelToCoord(x); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + y = mValueAxis.data()->pixelToCoord(x); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + switch (mPositionTypeY) + { + case ptAbsolute: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mParentPlot->viewport().top(); + y /= (double)mParentPlot->viewport().height(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mAxisRect.data()->top(); + y /= (double)mAxisRect.data()->height(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + x = mKeyAxis.data()->pixelToCoord(y); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + y = mValueAxis.data()->pixelToCoord(y); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + setCoords(x, y); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractItem + \brief The abstract base class for all items in a plot. + + In QCustomPlot, items are supplemental graphical elements that are neither plottables + (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus + plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each + specific item has at least one QCPItemPosition member which controls the positioning. Some items + are defined by more than one coordinate and thus have two or more QCPItemPosition members (For + example, QCPItemRect has \a topLeft and \a bottomRight). + + This abstract base class defines a very basic interface like visibility and clipping. Since this + class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass + yourself to create new items. + + The built-in items are: + + + + + + + + + + +
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
+ + \section items-clipping Clipping + + Items are by default clipped to the main axis rect (they are only visible inside the axis rect). + To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect + "setClipToAxisRect(false)". + + On the other hand if you want the item to be clipped to a different axis rect, specify it via + \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and + in principle is independent of the coordinate axes the item might be tied to via its position + members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping + also contains the axes used for the item positions. + + \section items-using Using items + + First you instantiate the item you want to use and add it to the plot: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 + by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just + set the plot coordinates where the line should start/end: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 + If we don't want the line to be positioned in plot coordinates but a different coordinate system, + e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 + Then we can set the coordinates, this time in pixels: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 + and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 + + For more advanced plots, it is even possible to set different types and parent anchors per X/Y + coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref + QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. + + \section items-subclassing Creating own items + + To create an own item, you implement a subclass of QCPAbstractItem. These are the pure + virtual functions, you must implement: + \li \ref selectTest + \li \ref draw + + See the documentation of those functions for what they need to do. + + \subsection items-positioning Allowing the item to be positioned + + As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall + have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add + a public member of type QCPItemPosition like so: + + \code QCPItemPosition * const myPosition;\endcode + + the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition + instance it points to, can be modified, of course). + The initialization of this pointer is made easy with the \ref createPosition function. Just assign + the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition + takes a string which is the name of the position, typically this is identical to the variable name. + For example, the constructor of QCPItemExample could look like this: + + \code + QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + myPosition(createPosition("myPosition")) + { + // other constructor code + } + \endcode + + \subsection items-drawing The draw function + + To give your item a visual representation, reimplement the \ref draw function and use the passed + QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the + position member(s) via \ref QCPItemPosition::pixelPosition. + + To optimize performance you should calculate a bounding rect first (don't forget to take the pen + width into account), check whether it intersects the \ref clipRect, and only draw the item at all + if this is the case. + + \subsection items-selection The selectTest function + + Your implementation of the \ref selectTest function may use the helpers \ref + QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the + selection test becomes significantly simpler for most items. See the documentation of \ref + selectTest for what the function parameters mean and what the function should return. + + \subsection anchors Providing anchors + + Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public + member, e.g. + + \code QCPItemAnchor * const bottom;\endcode + + and create it in the constructor with the \ref createAnchor function, assigning it a name and an + anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). + Since anchors can be placed anywhere, relative to the item's position(s), your item needs to + provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int + anchorId) function. + + In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel + position when anything attached to the anchor needs to know the coordinates. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QList QCPAbstractItem::positions() const + + Returns all positions of the item in a list. + + \see anchors, position +*/ + +/*! \fn QList QCPAbstractItem::anchors() const + + Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always + also an anchor, the list will also contain the positions of this item. + + \see positions, anchor +*/ + +/* end of documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 + \internal + + Draws this item with the provided \a painter. + + The cliprect of the provided painter is set to the rect returned by \ref clipRect before this + function is called. The clipRect depends on the clipping settings defined by \ref + setClipToAxisRect and \ref setClipAxisRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPAbstractItem::selectionChanged(bool selected) + This signal is emitted when the selection state of this item has changed, either by user interaction + or by a direct call to \ref setSelected. +*/ + +/* end documentation of signals */ + +/*! + Base class constructor which initializes base class members. +*/ +QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), + mClipToAxisRect(false), + mSelectable(true), + mSelected(false) +{ + parentPlot->registerItem(this); + + QList rects = parentPlot->axisRects(); + if (rects.size() > 0) + { + setClipToAxisRect(true); + setClipAxisRect(rects.first()); + } +} + +QCPAbstractItem::~QCPAbstractItem() +{ + // don't delete mPositions because every position is also an anchor and thus in mAnchors + qDeleteAll(mAnchors); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPAbstractItem::clipAxisRect() const +{ + return mClipAxisRect.data(); +} + +/*! + Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the + entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. + + \see setClipAxisRect +*/ +void QCPAbstractItem::setClipToAxisRect(bool clip) +{ + mClipToAxisRect = clip; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref + setClipToAxisRect is set to true. + + \see setClipToAxisRect +*/ +void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) +{ + mClipAxisRect = rect; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) + + However, even when \a selectable was set to false, it is possible to set the selection manually, + by calling \ref setSelected. + + \see QCustomPlot::setInteractions, setSelected +*/ +void QCPAbstractItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this item is selected or not. When selected, it might use a different visual + appearance (e.g. pen and brush), this depends on the specific item though. + + The entire selection mechanism for items is handled automatically when \ref + QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this + function when you wish to change the selection state manually. + + This function can change the selection state even when \ref setSelectable was set to false. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/*! + Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by + that name, returns 0. + + This function provides an alternative way to access item positions. Normally, you access + positions direcly by their member pointers (which typically have the same variable name as \a + name). + + \see positions, anchor +*/ +QCPItemPosition *QCPAbstractItem::position(const QString &name) const +{ + for (int i=0; iname() == name) + return mPositions.at(i); + } + qDebug() << Q_FUNC_INFO << "position with name not found:" << name; + return 0; +} + +/*! + Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by + that name, returns 0. + + This function provides an alternative way to access item anchors. Normally, you access + anchors direcly by their member pointers (which typically have the same variable name as \a + name). + + \see anchors, position +*/ +QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const +{ + for (int i=0; iname() == name) + return mAnchors.at(i); + } + qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; + return 0; +} + +/*! + Returns whether this item has an anchor with the specified \a name. + + Note that you can check for positions with this function, too. This is because every position is + also an anchor (QCPItemPosition inherits from QCPItemAnchor). + + \see anchor, position +*/ +bool QCPAbstractItem::hasAnchor(const QString &name) const +{ + for (int i=0; iname() == name) + return true; + } + return false; +} + +/*! \internal + + Returns the rect the visual representation of this item is clipped to. This depends on the + current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. + + If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. + + \see draw +*/ +QRect QCPAbstractItem::clipRect() const +{ + if (mClipToAxisRect && mClipAxisRect) + return mClipAxisRect.data()->rect(); + else + return mParentPlot->viewport(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing item lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); +} + +/*! \internal + + A convenience function which returns the selectTest value for a specified \a rect and a specified + click position \a pos. \a filledRect defines whether a click inside the rect should also be + considered a hit or whether only the rect border is sensitive to hits. + + This function may be used to help with the implementation of the \ref selectTest function for + specific items. + + For example, if your item consists of four rects, call this function four times, once for each + rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four + returned values. +*/ +double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const +{ + double result = -1; + + // distance to border: + QList lines; + lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) + << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); + double minDistSqr = std::numeric_limits::max(); + for (int i=0; i mParentPlot->selectionTolerance()*0.99) + { + if (rect.contains(pos)) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/*! \internal + + Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in + item subclasses if they want to provide anchors (QCPItemAnchor). + + For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor + ids and returns the respective pixel points of the specified anchor. + + \see createAnchor +*/ +QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const +{ + qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the position + member (This is needed to provide the name-based \ref position access to positions). + + Don't delete positions created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each position member. Don't create QCPItemPositions with \b new yourself, because they + won't be registered with the item properly. + + \see createAnchor +*/ +QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); + mPositions.append(newPosition); + mAnchors.append(newPosition); // every position is also an anchor + newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); + newPosition->setType(QCPItemPosition::ptPlotCoords); + if (mParentPlot->axisRect()) + newPosition->setAxisRect(mParentPlot->axisRect()); + newPosition->setCoords(0, 0); + return newPosition; +} + +/*! \internal + + Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the anchor + member (This is needed to provide the name based \ref anchor access to anchors). + + The \a anchorId must be a number identifying the created anchor. It is recommended to create an + enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor + to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns + the correct pixel coordinates for the passed anchor id. + + Don't delete anchors created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they + won't be registered with the item properly. + + \see createPosition +*/ +QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); + mAnchors.append(newAnchor); + return newAnchor; +} + +/* inherits documentation from base class */ +void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractItem::selectionCategory() const +{ + return QCP::iSelectItems; +} +/* end of 'src/item.cpp' */ + + +/* including file 'src/core.cpp', size 125037 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCustomPlot +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCustomPlot + + \brief The central class of the library. This is the QWidget which displays the plot and + interacts with the user. + + For tutorials on how to use QCustomPlot, see the website\n + http://www.qcustomplot.com/ +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const + + Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used + to handle and draw selection rect interactions (see \ref setSelectionRectMode). + + \see setSelectionRect +*/ + +/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const + + Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just + one cell with the main QCPAxisRect inside. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse double click event. +*/ + +/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse press event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. +*/ + +/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse move event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. + + \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, + because the dragging starting point was saved the moment the mouse was pressed. Thus it only has + a meaning for the range drag axes that were set at that moment. If you want to change the drag + axes, consider doing this in the \ref mousePress signal instead. +*/ + +/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse release event. + + It is emitted before QCustomPlot handles any other mechanisms like object selection. So a + slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or + \ref QCPAbstractPlottable::setSelectable. +*/ + +/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse wheel event. + + It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref + QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. +*/ + +/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableDoubleClick +*/ + +/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is double clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableClick +*/ + +/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemDoubleClick +*/ + +/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is double clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemClick +*/ + +/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisDoubleClick +*/ + +/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is double clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisClick +*/ + +/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendDoubleClick +*/ + +/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is double clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendClick +*/ + +/*! \fn void QCustomPlot::selectionChangedByUser() + + This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by + clicking. It is not emitted when the selection state of an object has changed programmatically by + a direct call to setSelected()/setSelection() on an object or by calling \ref + deselectAll. + + In addition to this signal, selectable objects also provide individual signals, for example \ref + QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals + are emitted even if the selection state is changed programmatically. + + See the documentation of \ref setInteractions for details about the selection mechanism. + + \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends +*/ + +/*! \fn void QCustomPlot::beforeReplot() + + This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, afterReplot +*/ + +/*! \fn void QCustomPlot::afterReplot() + + This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, beforeReplot +*/ + +/* end of documentation of signals */ +/* start of documentation of public members */ + +/*! \var QCPAxis *QCustomPlot::xAxis + + A pointer to the primary x Axis (bottom) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis + + A pointer to the primary y Axis (left) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::xAxis2 + + A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis2 + + A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPLegend *QCustomPlot::legend + + A pointer to the default legend of the main axis rect. The legend is invisible by default. Use + QCPLegend::setVisible to change this. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple legends to the plot, use the layout system interface to + access the new legend. For example, legends can be placed inside an axis rect's \ref + QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If + the default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointer becomes 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/* end of documentation of public members */ + +/*! + Constructs a QCustomPlot and sets reasonable default values. +*/ +QCustomPlot::QCustomPlot(QWidget *parent) : + QWidget(parent), + xAxis(0), + yAxis(0), + xAxis2(0), + yAxis2(0), + legend(0), + mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below + mPlotLayout(0), + mAutoAddPlottableToLegend(true), + mAntialiasedElements(QCP::aeNone), + mNotAntialiasedElements(QCP::aeNone), + mInteractions(0), + mSelectionTolerance(8), + mNoAntialiasingOnDrag(false), + mBackgroundBrush(Qt::white, Qt::SolidPattern), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mCurrentLayer(0), + mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), + mMultiSelectModifier(Qt::ControlModifier), + mSelectionRectMode(QCP::srmNone), + mSelectionRect(0), + mOpenGl(false), + mMouseHasMoved(false), + mMouseEventLayerable(0), + mMouseSignalLayerable(0), + mReplotting(false), + mReplotQueued(false), + mOpenGlMultisamples(16), + mOpenGlAntialiasedElementsBackup(QCP::aeNone), + mOpenGlCacheLabelsBackup(true) +{ + setAttribute(Qt::WA_NoMousePropagation); + setAttribute(Qt::WA_OpaquePaintEvent); + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); + QLocale currentLocale = locale(); + currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); + setLocale(currentLocale); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); +# else + setBufferDevicePixelRatio(QWidget::devicePixelRatio()); +# endif +#endif + + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // create initial layers: + mLayers.append(new QCPLayer(this, QLatin1String("background"))); + mLayers.append(new QCPLayer(this, QLatin1String("grid"))); + mLayers.append(new QCPLayer(this, QLatin1String("main"))); + mLayers.append(new QCPLayer(this, QLatin1String("axes"))); + mLayers.append(new QCPLayer(this, QLatin1String("legend"))); + mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); + updateLayerIndices(); + setCurrentLayer(QLatin1String("main")); + layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); + + // create initial layout, axis rect and legend: + mPlotLayout = new QCPLayoutGrid; + mPlotLayout->initializeParentPlot(this); + mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry + mPlotLayout->setLayer(QLatin1String("main")); + QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); + mPlotLayout->addElement(0, 0, defaultAxisRect); + xAxis = defaultAxisRect->axis(QCPAxis::atBottom); + yAxis = defaultAxisRect->axis(QCPAxis::atLeft); + xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); + yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); + legend = new QCPLegend; + legend->setVisible(false); + defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); + defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); + + defaultAxisRect->setLayer(QLatin1String("background")); + xAxis->setLayer(QLatin1String("axes")); + yAxis->setLayer(QLatin1String("axes")); + xAxis2->setLayer(QLatin1String("axes")); + yAxis2->setLayer(QLatin1String("axes")); + xAxis->grid()->setLayer(QLatin1String("grid")); + yAxis->grid()->setLayer(QLatin1String("grid")); + xAxis2->grid()->setLayer(QLatin1String("grid")); + yAxis2->grid()->setLayer(QLatin1String("grid")); + legend->setLayer(QLatin1String("legend")); + + // create selection rect instance: + mSelectionRect = new QCPSelectionRect(this); + mSelectionRect->setLayer(QLatin1String("overlay")); + + setViewport(rect()); // needs to be called after mPlotLayout has been created + + replot(rpQueuedReplot); +} + +QCustomPlot::~QCustomPlot() +{ + clearPlottables(); + clearItems(); + + if (mPlotLayout) + { + delete mPlotLayout; + mPlotLayout = 0; + } + + mCurrentLayer = 0; + qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed + mLayers.clear(); +} + +/*! + Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is + removed from there. + + \see setNotAntialiasedElements +*/ +void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) +{ + mAntialiasedElements = antialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. + + See \ref setAntialiasedElements for details. + + \see setNotAntialiasedElement +*/ +void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) +{ + if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements &= ~antialiasedElement; + else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements |= antialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets which elements are forcibly drawn not antialiased as an \a or combination of + QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is + removed from there. + + \see setAntialiasedElements +*/ +void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) +{ + mNotAntialiasedElements = notAntialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. + + See \ref setNotAntialiasedElements for details. + + \see setAntialiasedElement +*/ +void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) +{ + if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements &= ~notAntialiasedElement; + else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements |= notAntialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the + plottable to the legend (QCustomPlot::legend). + + \see addGraph, QCPLegend::addItem +*/ +void QCustomPlot::setAutoAddPlottableToLegend(bool on) +{ + mAutoAddPlottableToLegend = on; +} + +/*! + Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction + enums. There are the following types of interactions: + + Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the + respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. + For details how to control which axes the user may drag/zoom and in what orientations, see \ref + QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, + \ref QCPAxisRect::setRangeZoomAxes. + + Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref + QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and + their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the + user can actually select a plottable and its data can further be restricted with the \ref + QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the + special page about the \ref dataselection "data selection mechanism". To retrieve a list of all + currently selected plottables, call \ref selectedPlottables. If you're only interested in + QCPGraphs, you may use the convenience function \ref selectedGraphs. + + Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user + may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find + out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of + all currently selected items, call \ref selectedItems. + + Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user + may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick + labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for + each axis. To retrieve a list of all axes that currently contain selected parts, call \ref + selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). + + Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may + select the legend itself or individual items by clicking on them. What parts exactly are + selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the + legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To + find out which child items are selected, call \ref QCPLegend::selectedItems. + + All other selectable elements The selection of all other selectable objects (e.g. + QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the + user may select those objects by clicking on them. To find out which are currently selected, you + need to check their selected state explicitly. + + If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is + emitted. Each selectable object additionally emits an individual selectionChanged signal whenever + their selection state has changed, i.e. not only by user interaction. + + To allow multiple objects to be selected by holding the selection modifier (\ref + setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. + + \note In addition to the selection mechanism presented here, QCustomPlot always emits + corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and + \ref plottableDoubleClick for example. + + \see setInteraction, setSelectionTolerance +*/ +void QCustomPlot::setInteractions(const QCP::Interactions &interactions) +{ + mInteractions = interactions; +} + +/*! + Sets the single \a interaction of this QCustomPlot to \a enabled. + + For details about the interaction system, see \ref setInteractions. + + \see setInteractions +*/ +void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) +{ + if (!enabled && mInteractions.testFlag(interaction)) + mInteractions &= ~interaction; + else if (enabled && !mInteractions.testFlag(interaction)) + mInteractions |= interaction; +} + +/*! + Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or + not. + + If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a + potential selection when the minimum distance between the click position and the graph line is + smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks + directly inside the area and ignore this selection tolerance. In other words, it only has meaning + for parts of objects that are too thin to exactly hit with a click and thus need such a + tolerance. + + \see setInteractions, QCPLayerable::selectTest +*/ +void QCustomPlot::setSelectionTolerance(int pixels) +{ + mSelectionTolerance = pixels; +} + +/*! + Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes + ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves + performance during dragging. Thus it creates a more responsive user experience. As soon as the + user stops dragging, the last replot is done with normal antialiasing, to restore high image + quality. + + \see setAntialiasedElements, setNotAntialiasedElements +*/ +void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) +{ + mNoAntialiasingOnDrag = enabled; +} + +/*! + Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. + + \see setPlottingHint +*/ +void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) +{ + mPlottingHints = hints; +} + +/*! + Sets the specified plotting \a hint to \a enabled. + + \see setPlottingHints +*/ +void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) +{ + QCP::PlottingHints newHints = mPlottingHints; + if (!enabled) + newHints &= ~hint; + else + newHints |= hint; + + if (newHints != mPlottingHints) + setPlottingHints(newHints); +} + +/*! + Sets the keyboard modifier that will be recognized as multi-select-modifier. + + If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple + objects (or data points) by clicking on them one after the other while holding down \a modifier. + + By default the multi-select-modifier is set to Qt::ControlModifier. + + \see setInteractions +*/ +void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) +{ + mMultiSelectModifier = modifier; +} + +/*! + Sets how QCustomPlot processes mouse click-and-drag interactions by the user. + + If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For + example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref + QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref + selectionRect) becomes activated and allows e.g. rect zooming and data point selection. + + If you wish to provide your user both with axis range dragging and data selection/range zooming, + use this method to switch between the modes just before the interaction is processed, e.g. in + reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether + the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. + + If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the + interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes + will keep the selection rect active. Upon completion of the interaction, the behaviour is as + defined by the currently set \a mode, not the mode that was set when the interaction started. + + \see setInteractions, setSelectionRect, QCPSelectionRect +*/ +void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) +{ + if (mSelectionRect) + { + if (mode == QCP::srmNone) + mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect + + // disconnect old connections: + if (mSelectionRectMode == QCP::srmSelect) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + + // establish new ones: + if (mode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } + + mSelectionRectMode = mode; +} + +/*! + Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref + QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of + the passed \a selectionRect. It can be accessed later via \ref selectionRect. + + This method is useful if you wish to replace the default QCPSelectionRect instance with an + instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. + + \see setSelectionRectMode +*/ +void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) +{ + if (mSelectionRect) + delete mSelectionRect; + + mSelectionRect = selectionRect; + + if (mSelectionRect) + { + // establish connections with new selection rect: + if (mSelectionRectMode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } +} + +/*! + \warning This is still an experimental feature and its performance depends on the system that it + runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering + might cause context conflicts on some systems. + + This method allows to enable OpenGL plot rendering, for increased plotting performance of + graphically demanding plots (thick lines, translucent fills, etc.). + + If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, + continue plotting with hardware acceleration. The parameter \a multisampling controls how many + samples will be used per pixel, it essentially controls the antialiasing quality. If \a + multisampling is set too high for the current graphics hardware, the maximum allowed value will + be used. + + You can test whether switching to OpenGL rendering was successful by checking whether the + according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, + rendering continues with the regular software rasterizer, and an according qDebug output is + generated. + + If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint + "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override + for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a + higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the + OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is + controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching + settings are restored to what they were before OpenGL was enabled, if they weren't altered in the + meantime. + + \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL + defined. This define must be set before including the QCustomPlot header both during compilation + of the QCustomPlot library as well as when compiling your application. It is best to just include + the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. + \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c + QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a + newer OpenGL interface which is already in the "gui" module. +*/ +void QCustomPlot::setOpenGl(bool enabled, int multisampling) +{ + mOpenGlMultisamples = qMax(0, multisampling); +#ifdef QCUSTOMPLOT_USE_OPENGL + mOpenGl = enabled; + if (mOpenGl) + { + if (setupOpenGl()) + { + // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): + setAntialiasedElements(QCP::aeAll); + setPlottingHint(QCP::phCacheLabels, false); + } else + { + qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; + mOpenGl = false; + } + } else + { + // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: + if (mAntialiasedElements == QCP::aeAll) + setAntialiasedElements(mOpenGlAntialiasedElementsBackup); + if (!mPlottingHints.testFlag(QCP::phCacheLabels)) + setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); + freeOpenGl(); + } + // recreate all paint buffers: + mPaintBuffers.clear(); + setupPaintBuffers(); +#else + Q_UNUSED(enabled) + qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; +#endif +} + +/*! + Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the + viewport manually. + + The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take + the viewport to be the outer border of the plot. The viewport normally is the rect() of the + QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. + + Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically + an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger + and contains also the axes themselves, their tick numbers, their labels, or even additional axis + rects, color scales and other layout elements. + + This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref + savePdf, etc. by temporarily changing the viewport size. +*/ +void QCustomPlot::setViewport(const QRect &rect) +{ + mViewport = rect; + if (mPlotLayout) + mPlotLayout->setOuterRect(mViewport); +} + +/*! + Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. + + Normally, this doesn't need to be set manually, because it is initialized with the regular \a + QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal + displays, 2 for High-DPI displays). + + Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called + when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and + leaves the internal buffer device pixel ratio at 1.0. +*/ +void QCustomPlot::setBufferDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBufferDevicePixelRatio = ratio; + for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); + // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mBufferDevicePixelRatio = 1.0; +#endif + } +} + +/*! + Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn + below all other objects in the plot. + + For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is + preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will + first be filled with that brush, before drawing the background pixmap. This can be useful for + background pixmaps with translucent areas. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! + Sets the background brush of the viewport (see \ref setViewport). + + Before drawing everything else, the background is filled with \a brush. If a background pixmap + was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport + before the background pixmap is drawn. This can be useful for background pixmaps with translucent + areas. + + Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be + useful for exporting to image formats which support transparency, e.g. \ref savePng. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the viewport, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is + set to true, control whether and how the aspect ratio of the original pixmap is preserved with + \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the viewport dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCustomPlot::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this + function to define whether and how the aspect ratio of the original pixmap is preserved. + + \see setBackground, setBackgroundScaled +*/ +void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the plottable with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + plottable, see QCustomPlot::plottable() + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + { + return mPlottables.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last plottable that was added to the plot. If there are no plottables in the plot, + returns 0. + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable() +{ + if (!mPlottables.isEmpty()) + { + return mPlottables.last(); + } else + return 0; +} + +/*! + Removes the specified plottable from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). + + Returns true on success. + + \see clearPlottables +*/ +bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); + return false; + } + + // remove plottable from legend: + plottable->removeFromLegend(); + // special handling for QCPGraphs to maintain the simple graph interface: + if (QCPGraph *graph = qobject_cast(plottable)) + mGraphs.removeOne(graph); + // remove plottable: + delete plottable; + mPlottables.removeOne(plottable); + return true; +} + +/*! \overload + + Removes and deletes the plottable by its \a index. +*/ +bool QCustomPlot::removePlottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + return removePlottable(mPlottables[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all plottables from the plot and deletes them. Corresponding legend items are also + removed from the default legend (QCustomPlot::legend). + + Returns the number of plottables removed. + + \see removePlottable +*/ +int QCustomPlot::clearPlottables() +{ + int c = mPlottables.size(); + for (int i=c-1; i >= 0; --i) + removePlottable(mPlottables[i]); + return c; +} + +/*! + Returns the number of currently existing plottables in the plot + + \see plottable +*/ +int QCustomPlot::plottableCount() const +{ + return mPlottables.size(); +} + +/*! + Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. + + There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. + + \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedPlottables() const +{ + QList result; + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (plottable->selected()) + result.append(plottable); + } + return result; +} + +/*! + Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines + (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple + plottables come into consideration, the one closest to \a pos is returned. + + If \a onlySelectable is true, only plottables that are selectable + (QCPAbstractPlottable::setSelectable) are considered. + + If there is no plottable at \a pos, the return value is 0. + + \see itemAt, layoutElementAt +*/ +QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractPlottable *resultPlottable = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable + continue; + if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes + { + double currentDistance = plottable->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultPlottable = plottable; + resultDistance = currentDistance; + } + } + } + + return resultPlottable; +} + +/*! + Returns whether this QCustomPlot instance contains the \a plottable. +*/ +bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const +{ + return mPlottables.contains(plottable); +} + +/*! + Returns the graph with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last created + graph, see QCustomPlot::graph() + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph(int index) const +{ + if (index >= 0 && index < mGraphs.size()) + { + return mGraphs.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, + returns 0. + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph() const +{ + if (!mGraphs.isEmpty()) + { + return mGraphs.last(); + } else + return 0; +} + +/*! + Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the + bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a + keyAxis and \a valueAxis must reside in this QCustomPlot. + + \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically + "y") for the graph. + + Returns a pointer to the newly created graph, or 0 if adding the graph failed. + + \see graph, graphCount, removeGraph, clearGraphs +*/ +QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + if (!keyAxis) keyAxis = xAxis; + if (!valueAxis) valueAxis = yAxis; + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; + return 0; + } + if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; + return 0; + } + + QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); + newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); + return newGraph; +} + +/*! + Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in + the plot have a channel fill set towards the removed graph, the channel fill property of those + graphs is reset to zero (no channel fill). + + Returns true on success. + + \see clearGraphs +*/ +bool QCustomPlot::removeGraph(QCPGraph *graph) +{ + return removePlottable(graph); +} + +/*! \overload + + Removes and deletes the graph by its \a index. +*/ +bool QCustomPlot::removeGraph(int index) +{ + if (index >= 0 && index < mGraphs.size()) + return removeGraph(mGraphs[index]); + else + return false; +} + +/*! + Removes all graphs from the plot and deletes them. Corresponding legend items are also removed + from the default legend (QCustomPlot::legend). + + Returns the number of graphs removed. + + \see removeGraph +*/ +int QCustomPlot::clearGraphs() +{ + int c = mGraphs.size(); + for (int i=c-1; i >= 0; --i) + removeGraph(mGraphs[i]); + return c; +} + +/*! + Returns the number of currently existing graphs in the plot + + \see graph, addGraph +*/ +int QCustomPlot::graphCount() const +{ + return mGraphs.size(); +} + +/*! + Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. + + If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, + etc., use \ref selectedPlottables. + + \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedGraphs() const +{ + QList result; + Q_FOREACH (QCPGraph *graph, mGraphs) + { + if (graph->selected()) + result.append(graph); + } + return result; +} + +/*! + Returns the item with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + item, see QCustomPlot::item() + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item(int index) const +{ + if (index >= 0 && index < mItems.size()) + { + return mItems.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last item that was added to this plot. If there are no items in the plot, + returns 0. + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item() const +{ + if (!mItems.isEmpty()) + { + return mItems.last(); + } else + return 0; +} + +/*! + Removes the specified item from the plot and deletes it. + + Returns true on success. + + \see clearItems +*/ +bool QCustomPlot::removeItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + delete item; + mItems.removeOne(item); + return true; + } else + { + qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); + return false; + } +} + +/*! \overload + + Removes and deletes the item by its \a index. +*/ +bool QCustomPlot::removeItem(int index) +{ + if (index >= 0 && index < mItems.size()) + return removeItem(mItems[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all items from the plot and deletes them. + + Returns the number of items removed. + + \see removeItem +*/ +int QCustomPlot::clearItems() +{ + int c = mItems.size(); + for (int i=c-1; i >= 0; --i) + removeItem(mItems[i]); + return c; +} + +/*! + Returns the number of currently existing items in the plot + + \see item +*/ +int QCustomPlot::itemCount() const +{ + return mItems.size(); +} + +/*! + Returns a list of the selected items. If no items are currently selected, the list is empty. + + \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected +*/ +QList QCustomPlot::selectedItems() const +{ + QList result; + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (item->selected()) + result.append(item); + } + return result; +} + +/*! + Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref + QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref + setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is + returned. + + If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are + considered. + + If there is no item at \a pos, the return value is 0. + + \see plottableAt, layoutElementAt +*/ +QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractItem *resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + continue; + if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it + { + double currentDistance = item->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultItem = item; + resultDistance = currentDistance; + } + } + } + + return resultItem; +} + +/*! + Returns whether this QCustomPlot contains the \a item. + + \see item +*/ +bool QCustomPlot::hasItem(QCPAbstractItem *item) const +{ + return mItems.contains(item); +} + +/*! + Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is + returned. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(const QString &name) const +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + if (layer->name() == name) + return layer; + } + return 0; +} + +/*! \overload + + Returns the layer by \a index. If the index is invalid, 0 is returned. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(int index) const +{ + if (index >= 0 && index < mLayers.size()) + { + return mLayers.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Returns the layer that is set as current layer (see \ref setCurrentLayer). +*/ +QCPLayer *QCustomPlot::currentLayer() const +{ + return mCurrentLayer; +} + +/*! + Sets the layer with the specified \a name to be the current layer. All layerables (\ref + QCPLayerable), e.g. plottables and items, are created on the current layer. + + Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer +*/ +bool QCustomPlot::setCurrentLayer(const QString &name) +{ + if (QCPLayer *newCurrentLayer = layer(name)) + { + return setCurrentLayer(newCurrentLayer); + } else + { + qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; + return false; + } +} + +/*! \overload + + Sets the provided \a layer to be the current layer. + + Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. + + \see addLayer, moveLayer, removeLayer +*/ +bool QCustomPlot::setCurrentLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + + mCurrentLayer = layer; + return true; +} + +/*! + Returns the number of currently existing layers in the plot + + \see layer, addLayer +*/ +int QCustomPlot::layerCount() const +{ + return mLayers.size(); +} + +/*! + Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which + must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. + + Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a + valid layer inside this QCustomPlot. + + If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. + + For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. + + \see layer, moveLayer, removeLayer +*/ +bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!otherLayer) + otherLayer = mLayers.last(); + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + if (layer(name)) + { + qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; + return false; + } + + QCPLayer *newLayer = new QCPLayer(this, name); + mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); + updateLayerIndices(); + setupPaintBuffers(); // associates new layer with the appropriate paint buffer + return true; +} + +/*! + Removes the specified \a layer and returns true on success. + + All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below + \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both + cases, the total rendering order of all layerables in the QCustomPlot is preserved. + + If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom + layer) becomes the new current layer. + + It is not possible to remove the last layer of the plot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::removeLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (mLayers.size() < 2) + { + qDebug() << Q_FUNC_INFO << "can't remove last layer"; + return false; + } + + // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) + int removedIndex = layer->index(); + bool isFirstLayer = removedIndex==0; + QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); + QList children = layer->children(); + if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) + { + for (int i=children.size()-1; i>=0; --i) + children.at(i)->moveToLayer(targetLayer, true); + } else // append normally + { + for (int i=0; imoveToLayer(targetLayer, false); + } + // if removed layer is current layer, change current layer to layer below/above: + if (layer == mCurrentLayer) + setCurrentLayer(targetLayer); + // invalidate the paint buffer that was responsible for this layer: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + // remove layer: + delete layer; + mLayers.removeOne(layer); + updateLayerIndices(); + return true; +} + +/*! + Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or + below is controlled with \a insertMode. + + Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the + QCustomPlot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + + if (layer->index() > otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); + else if (layer->index() < otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); + + // invalidate the paint buffers that are responsible for the layers: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + if (!otherLayer->mPaintBuffer.isNull()) + otherLayer->mPaintBuffer.data()->setInvalidated(); + + updateLayerIndices(); + return true; +} + +/*! + Returns the number of axis rects in the plot. + + All axis rects can be accessed via QCustomPlot::axisRect(). + + Initially, only one axis rect exists in the plot. + + \see axisRect, axisRects +*/ +int QCustomPlot::axisRectCount() const +{ + return axisRects().size(); +} + +/*! + Returns the axis rect with \a index. + + Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were + added, all of them may be accessed with this function in a linear fashion (even when they are + nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). + + \see axisRectCount, axisRects +*/ +QCPAxisRect *QCustomPlot::axisRect(int index) const +{ + const QList rectList = axisRects(); + if (index >= 0 && index < rectList.size()) + { + return rectList.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; + return 0; + } +} + +/*! + Returns all axis rects in the plot. + + \see axisRectCount, axisRect +*/ +QList QCustomPlot::axisRects() const +{ + QList result; + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) + { + if (element) + { + elementStack.push(element); + if (QCPAxisRect *ar = qobject_cast(element)) + result.append(ar); + } + } + } + + return result; +} + +/*! + Returns the layout element at pixel position \a pos. If there is no element at that position, + returns 0. + + Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on + any of its parent elements is set to false, it will not be considered. + + \see itemAt, plottableAt +*/ +QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const +{ + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + break; + } + } + } + return currentElement; +} + +/*! + Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores + other layout elements even if they are visually in front of the axis rect (e.g. a \ref + QCPLegend). If there is no axis rect at that position, returns 0. + + Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or + on any of its parent elements is set to false, it will not be considered. + + \see layoutElementAt +*/ +QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const +{ + QCPAxisRect *result = 0; + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + if (QCPAxisRect *ar = qobject_cast(currentElement)) + result = ar; + break; + } + } + } + return result; +} + +/*! + Returns the axes that currently have selected parts, i.e. whose selection state is not \ref + QCPAxis::spNone. + + \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, + QCPAxis::setSelectableParts +*/ +QList QCustomPlot::selectedAxes() const +{ + QList result, allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + { + if (axis->selectedParts() != QCPAxis::spNone) + result.append(axis); + } + + return result; +} + +/*! + Returns the legends that currently have selected parts, i.e. whose selection state is not \ref + QCPLegend::spNone. + + \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, + QCPLegend::setSelectableParts, QCPLegend::selectedItems +*/ +QList QCustomPlot::selectedLegends() const +{ + QList result; + + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) + { + if (subElement) + { + elementStack.push(subElement); + if (QCPLegend *leg = qobject_cast(subElement)) + { + if (leg->selectedParts() != QCPLegend::spNone) + result.append(leg); + } + } + } + } + + return result; +} + +/*! + Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. + + Since calling this function is not a user interaction, this does not emit the \ref + selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the + objects were previously selected. + + \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends +*/ +void QCustomPlot::deselectAll() +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + layerable->deselectEvent(0); + } +} + +/*! + Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is + refreshed with the new buffer contents. This is the method that must be called to make changes to + the plot, e.g. on the axis ranges or data points of graphs, visible. + + The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example + if your application calls \ref replot very quickly in succession (e.g. multiple independent + functions change some aspects of the plot and each wants to make sure the change gets replotted), + it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the + actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref + replot with this priority will only cause a single replot, avoiding redundant replots and + improving performance. + + Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the + QCustomPlot widget and user interactions (object selection and range dragging/zooming). + + Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref + afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two + signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite + recursion. + + If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to + replot only that specific layer via \ref QCPLayer::replot. See the documentation there for + details. +*/ +void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) +{ + if (refreshPriority == QCustomPlot::rpQueuedReplot) + { + if (!mReplotQueued) + { + mReplotQueued = true; + QTimer::singleShot(0, this, SLOT(replot())); + } + return; + } + + if (mReplotting) // incase signals loop back to replot slot + return; + mReplotting = true; + mReplotQueued = false; + Q_EMIT beforeReplot(); + + updateLayout(); + // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: + setupPaintBuffers(); + Q_FOREACH (QCPLayer *layer, mLayers) + layer->drawToPaintBuffer(); + for (int i=0; isetInvalidated(false); + + if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) + repaint(); + else + update(); + + Q_EMIT afterReplot(); + mReplotting = false; +} + +/*! + Rescales the axes such that all plottables (like graphs) in the plot are fully visible. + + if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true + (QCPLayerable::setVisible), will be used to rescale the axes. + + \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale +*/ +void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) +{ + QList allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + axis->rescale(onlyVisiblePlottables); +} + +/*! + Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale + of texts and lines will be derived from the specified \a width and \a height. This means, the + output will look like the normal on-screen output of a QCustomPlot widget with the corresponding + pixel width and height. If either \a width or \a height is zero, the exported image will have the + same dimensions as the QCustomPlot widget currently has. + + Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when + drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as + a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information + about cosmetic pens, see the QPainter and QPen documentation. + + The objects of the plot will appear in the current selection state. If you don't want any + selected objects to be painted in their selected look, deselect everything with \ref deselectAll + before calling this function. + + Returns true on success. + + \warning + \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it + is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines + (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). + \li If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting + PDF file. + + \note On Android systems, this method does nothing and issues an according qDebug warning + message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. + + \see savePng, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) +{ + bool success = false; +#ifdef QT_NO_PRINTER + Q_UNUSED(fileName) + Q_UNUSED(exportPen) + Q_UNUSED(width) + Q_UNUSED(height) + Q_UNUSED(pdfCreator) + Q_UNUSED(pdfTitle) + qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; +#else + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFileName(fileName); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); + printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + printer.setFullPage(true); + printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); +#else + QPageLayout pageLayout; + pageLayout.setMode(QPageLayout::FullPageMode); + pageLayout.setOrientation(QPageLayout::Portrait); + pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); + pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); + printer.setPageLayout(pageLayout); +#endif + QCPPainter printpainter; + if (printpainter.begin(&printer)) + { + printpainter.setMode(QCPPainter::pmVectorized); + printpainter.setMode(QCPPainter::pmNoCaching); + printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); + printpainter.setWindow(mViewport); + if (mBackgroundBrush.style() != Qt::NoBrush && + mBackgroundBrush.color() != Qt::white && + mBackgroundBrush.color() != Qt::transparent && + mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent + printpainter.fillRect(viewport(), mBackgroundBrush); + draw(&printpainter); + printpainter.end(); + success = true; + } + setViewport(oldViewport); +#endif // QT_NO_PRINTER + return success; +} + +/*! + Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the PNG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) + with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); +} + +/*! + Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the JPEG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveBmp, saveRastered +*/ +bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); +} + +/*! + Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the BMP format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveJpg, saveRastered +*/ +bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); +} + +/*! \internal + + Returns a minimum size hint that corresponds to the minimum size of the top level layout + (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum + size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. + This is especially important, when placed in a QLayout where other components try to take in as + much space as possible (e.g. QMdiArea). +*/ +QSize QCustomPlot::minimumSizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Returns a size hint that is the same as \ref minimumSizeHint. + +*/ +QSize QCustomPlot::sizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but + draws the internal buffer on the widget surface. +*/ +void QCustomPlot::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QCPPainter painter(this); + if (painter.isActive()) + { + painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem + if (mBackgroundBrush.style() != Qt::NoBrush) + painter.fillRect(mViewport, mBackgroundBrush); + drawBackground(&painter); + for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) + mPaintBuffers.at(bufferIndex)->draw(&painter); + } +} + +/*! \internal + + Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect + of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. +*/ +void QCustomPlot::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + // resize and repaint the buffer: + setViewport(rect()); + replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) +} + +/*! \internal + + Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then + determines the layerable under the cursor and forwards the event to it. Finally, emits the + specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref + axisDoubleClick, etc.). + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_EMIT mouseDoubleClick(event); + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + // determine layerable under the cursor (this event is called instead of the second press event in a double-click): + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + + // emit specialized object double click signals: + if (!candidates.isEmpty()) + { + if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) + { + int dataIndex = 0; + if (!details.first().value().isEmpty()) + dataIndex = details.first().value().dataRange().begin(); + Q_EMIT plottableDoubleClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(candidates.first())) + Q_EMIT axisDoubleClick(ax, details.first().value(), event); + else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) + Q_EMIT itemDoubleClick(ai, event); + else if (QCPLegend *lg = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(li->parentLegend(), li, event); + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is pressed. Emits the mousePress signal. + + If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the + selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCustomPlot::mousePressEvent(QMouseEvent *event) +{ + Q_EMIT mousePress(event); + // save some state to tell in releaseEvent whether it was a click: + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + if (mSelectionRect && mSelectionRectMode != QCP::srmNone) + { + if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect + mSelectionRect->startSelection(event); + } else + { + // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + if (!candidates.isEmpty()) + { + mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) + mMouseSignalLayerableDetails = details.first(); + } + // forward event to topmost candidate which accepts the event: + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list + candidates.at(i)->mousePressEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when the cursor is moved. Emits the \ref mouseMove signal. + + If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it + in order to update the rect geometry. + + Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the + layout element before), the mouseMoveEvent is forwarded to that element. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseMoveEvent(QMouseEvent *event) +{ + Q_EMIT mouseMove(event); + + if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) + mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release + + if (mSelectionRect && mSelectionRect->isActive()) + mSelectionRect->moveSelection(event); + else if (mMouseEventLayerable) // call event of affected layerable: + mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. + + If the mouse was moved less than a certain threshold in any direction since the \ref + mousePressEvent, it is considered a click which causes the selection mechanism (if activated via + \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse + click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) + + If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable + before), the \ref mouseReleaseEvent is forwarded to that element. + + \see mousePressEvent, mouseMoveEvent +*/ +void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) +{ + Q_EMIT mouseRelease(event); + + if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click + { + if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here + mSelectionRect->cancel(); + if (event->button() == Qt::LeftButton) + processPointSelection(event); + + // emit specialized click signals of QCustomPlot instance: + if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) + { + int dataIndex = 0; + if (!mMouseSignalLayerableDetails.value().isEmpty()) + dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); + Q_EMIT plottableClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) + Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); + else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) + Q_EMIT itemClick(ai, event); + else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(li->parentLegend(), li, event); + mMouseSignalLayerable = 0; + } + + if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there + { + // finish selection rect, the appropriate action will be taken via signal-slot connection: + mSelectionRect->endSelection(event); + } else + { + // call event of affected layerable: + if (mMouseEventLayerable) + { + mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); + mMouseEventLayerable = 0; + } + } + + if (noAntialiasingOnDrag()) + replot(rpQueuedReplot); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then + determines the affected layerable and forwards the event to it. +*/ +void QCustomPlot::wheelEvent(QWheelEvent *event) +{ + Q_EMIT mouseWheel(event); + // forward event to layerable under cursor: + QList candidates = layerableListAt(event->pos(), false); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->wheelEvent(event); + if (event->isAccepted()) + break; + } + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + This function draws the entire plot, including background pixmap, with the specified \a painter. + It does not make use of the paint buffers like \ref replot, so this is the function typically + used by saving/exporting methods such as \ref savePdf or \ref toPainter. + + Note that it does not fill the background with the background brush (as the user may specify with + \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this + method. +*/ +void QCustomPlot::draw(QCPPainter *painter) +{ + updateLayout(); + + // draw viewport background pixmap: + drawBackground(painter); + + // draw all layered objects (grid, axes, plottables, items, legend,...): + Q_FOREACH (QCPLayer *layer, mLayers) + layer->draw(painter); + + /* Debug code to draw all layout element rects + foreach (QCPLayoutElement* el, findChildren()) + { + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->rect()); + painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->outerRect()); + } + */ +} + +/*! \internal + + Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref + QCPLayoutElement::update on the main plot layout. + + Here, the layout elements calculate their positions and margins, and prepare for the following + draw call. +*/ +void QCustomPlot::updateLayout() +{ + // run through layout phases: + mPlotLayout->update(QCPLayoutElement::upPreparation); + mPlotLayout->update(QCPLayoutElement::upMargins); + mPlotLayout->update(QCPLayoutElement::upLayout); +} + +/*! \internal + + Draws the viewport background pixmap of the plot. + + If a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the viewport with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + Note that this function does not draw a fill with the background brush + (\ref setBackground(const QBrush &brush)) beneath the pixmap. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::drawBackground(QCPPainter *painter) +{ + // Note: background color is handled in individual replot/save functions + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mViewport.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); + } + } +} + +/*! \internal + + Goes through the layers and makes sure this QCustomPlot instance holds the correct number of + paint buffers and that they have the correct configuration (size, pixel ratio, etc.). + Allocations, reallocations and deletions of paint buffers are performed as necessary. It also + associates the paint buffers with the layers, so they draw themselves into the right buffer when + \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref + QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for + layers in \ref QCPLayer::lmBuffered mode. + + This method uses \ref createPaintBuffer to create new paint buffers. + + After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated + (so an attempt to replot only a single buffered layer causes a full replot). + + This method is called in every \ref replot call, prior to actually drawing the layers (into their + associated paint buffer). If the paint buffers don't need changing/reallocating, this method + basically leaves them alone and thus finishes very fast. +*/ +void QCustomPlot::setupPaintBuffers() +{ + int bufferIndex = 0; + if (mPaintBuffers.isEmpty()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + + for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) + { + QCPLayer *layer = mLayers.at(layerIndex); + if (layer->mode() == QCPLayer::lmLogical) + { + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + } else if (layer->mode() == QCPLayer::lmBuffered) + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + } + } + } + // remove unneeded buffers: + while (mPaintBuffers.size()-1 > bufferIndex) + mPaintBuffers.removeLast(); + // resize buffers to viewport size and clear contents: + for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size + mPaintBuffers.at(i)->clear(Qt::transparent); + mPaintBuffers.at(i)->setInvalidated(); + } +} + +/*! \internal + + This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. + + Depending on the current setting of \ref setOpenGl, and the current Qt version, different + backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper + size and device pixel ratio, and returned. +*/ +QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() +{ + if (mOpenGl) + { +#if defined(QCP_OPENGL_FBO) + return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); +#elif defined(QCP_OPENGL_PBUFFER) + return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); +#else + qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +#endif + } else + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +} + +/*! + This method returns whether any of the paint buffers held by this QCustomPlot instance are + invalidated. + + If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always + causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example + the layer order has changed, new layers were added, layers were removed, or layer modes were + changed (\ref QCPLayer::setMode). + + \see QCPAbstractPaintBuffer::setInvalidated +*/ +bool QCustomPlot::hasInvalidatedPaintBuffers() +{ + for (int i=0; iinvalidated()) + return true; + } + return false; +} + +/*! \internal + + When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, + surface, paint device). + + Returns true on success. + + If this method is successful, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref + QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. + + \see freeOpenGl +*/ +bool QCustomPlot::setupOpenGl() +{ +#ifdef QCP_OPENGL_FBO + freeOpenGl(); + QSurfaceFormat proposedSurfaceFormat; + proposedSurfaceFormat.setSamples(mOpenGlMultisamples); +#ifdef QCP_OPENGL_OFFSCREENSURFACE + QOffscreenSurface *surface = new QOffscreenSurface; +#else + QWindow *surface = new QWindow; + surface->setSurfaceType(QSurface::OpenGLSurface); +#endif + surface->setFormat(proposedSurfaceFormat); + surface->create(); + mGlSurface = QSharedPointer(surface); + mGlContext = QSharedPointer(new QOpenGLContext); + mGlContext->setFormat(mGlSurface->format()); + if (!mGlContext->create()) + { + qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device + { + qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + { + qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); + return true; +#elif defined(QCP_OPENGL_PBUFFER) + return QGLFormat::hasOpenGL(); +#else + return false; +#endif +} + +/*! \internal + + When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the + context and frees resources). + + After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref + QCPPaintBufferPixmap) is used for subsequent replots. + + \see setupOpenGl +*/ +void QCustomPlot::freeOpenGl() +{ +#ifdef QCP_OPENGL_FBO + mGlPaintDevice.clear(); + mGlContext.clear(); + mGlSurface.clear(); +#endif +} + +/*! \internal + + This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot + so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. +*/ +void QCustomPlot::axisRemoved(QCPAxis *axis) +{ + if (xAxis == axis) + xAxis = 0; + if (xAxis2 == axis) + xAxis2 = 0; + if (yAxis == axis) + yAxis = 0; + if (yAxis2 == axis) + yAxis2 = 0; + + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers +} + +/*! \internal + + This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so + it may clear its QCustomPlot::legend member accordingly. +*/ +void QCustomPlot::legendRemoved(QCPLegend *legend) +{ + if (this->legend == legend) + this->legend = 0; +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmSelect. + + First, it determines which axis rect was the origin of the selection rect judging by the starting + point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be + precise) associated with that axis rect and finds the data points that are in \a rect. It does + this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. + + Then, the actual selection is done by calling the plottables' \ref + QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details + parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a + rect receive a \ref QCPAbstractPlottable::deselectEvent. + + \see processRectZoom +*/ +void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) +{ + bool selectionStateChanged = false; + + if (mInteractions.testFlag(QCP::iSelectPlottables)) + { + QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size + QRectF rectF(rect.normalized()); + if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) + { + // determine plottables that were hit by the rect and thus are candidates for selection: + Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) + { + if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) + { + QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); + if (!dataSel.isEmpty()) + potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); + } + } + + if (!mInteractions.testFlag(QCP::iMultiSelect)) + { + // only leave plottable with most selected points in map, since we will only select a single plottable: + if (!potentialSelections.isEmpty()) + { + QMap >::iterator it = potentialSelections.begin(); + while (it != potentialSelections.end()-1) // erase all except last element + it = potentialSelections.erase(it); + } + } + + bool additive = event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + // emit deselection except to those plottables who will be selected afterwards: + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + // go through selections in reverse (largest selection first) and emit select events: + QMap >::const_iterator it = potentialSelections.constEnd(); + while (it != potentialSelections.constBegin()) + { + --it; + if (mInteractions.testFlag(it.value().first->selectionCategory())) + { + bool selChanged = false; + it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } else if (mSelectionRect) + mSelectionRect->layer()->replot(); +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmZoom. + + It determines which axis rect was the origin of the selection rect judging by the starting point + of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the + provided \a rect (see \ref QCPAxisRect::zoom). + + \see processRectSelection +*/ +void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) +{ + Q_UNUSED(event) + if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) + { + QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); + affectedAxes.removeAll(static_cast(0)); + axisRect->zoom(QRectF(rect), affectedAxes); + } + replot(rpQueuedReplot); // always replot to make selection rect disappear +} + +/*! \internal + + This method is called when a simple left mouse click was detected on the QCustomPlot surface. + + It first determines the layerable that was hit by the click, and then calls its \ref + QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the + multi-select modifier was pressed, see \ref setMultiSelectModifier). + + In this method the hit layerable is determined a second time using \ref layerableAt (after the + one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This + implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the + clicked layerable determined here. For example, if a non-selectable layerable is in front of a + selectable layerable at the click position, the front layerable will receive mouse events but the + selectable one in the back will receive the \ref QCPLayerable::selectEvent. + + \see processRectSelection, QCPLayerable::selectTest +*/ +void QCustomPlot::processPointSelection(QMouseEvent *event) +{ + QVariant details; + QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); + bool selectionStateChanged = false; + bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) + { + // a layerable was actually clicked, call its selectEvent: + bool selChanged = false; + clickedLayerable->selectEvent(event, additive, details, &selChanged); + selectionStateChanged |= selChanged; + } + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } +} + +/*! \internal + + Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend + is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the + plottable. + + Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of + \a plottable is this QCustomPlot. + + This method is called automatically in the QCPAbstractPlottable base class constructor. +*/ +bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) +{ + if (mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); + return false; + } + if (plottable->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); + return false; + } + + mPlottables.append(plottable); + // possibly add plottable to legend: + if (mAutoAddPlottableToLegend) + plottable->addToLegend(); + if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + plottable->setLayer(currentLayer()); + return true; +} + +/*! \internal + + In order to maintain the simplified graph interface of QCustomPlot, this method is called by the + QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true + on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. + + This graph specific registration happens in addition to the call to \ref registerPlottable by the + QCPAbstractPlottable base class. +*/ +bool QCustomPlot::registerGraph(QCPGraph *graph) +{ + if (!graph) + { + qDebug() << Q_FUNC_INFO << "passed graph is zero"; + return false; + } + if (mGraphs.contains(graph)) + { + qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; + return false; + } + + mGraphs.append(graph); + return true; +} + + +/*! \internal + + Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. + + Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a + item is this QCustomPlot. + + This method is called automatically in the QCPAbstractItem base class constructor. +*/ +bool QCustomPlot::registerItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); + return false; + } + if (item->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); + return false; + } + + mItems.append(item); + if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) + item->setLayer(currentLayer()); + return true; +} + +/*! \internal + + Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called + after every operation that changes the layer indices, like layer removal, layer creation, layer + moving. +*/ +void QCustomPlot::updateLayerIndices() const +{ + for (int i=0; imIndex = i; +} + +/*! \internal + + Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, + only those layerables that are selectable will be considered. (Layerable subclasses communicate + their selectability via the QCPLayerable::selectTest method, by returning -1.) + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableListAt, layoutElementAt, axisRectAt +*/ +QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const +{ + QList details; + QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); + if (selectionDetails && !details.isEmpty()) + *selectionDetails = details.first(); + if (!candidates.isEmpty()) + return candidates.first(); + else + return 0; +} + +/*! \internal + + Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those + layerables that are selectable will be considered. (Layerable subclasses communicate their + selectability via the QCPLayerable::selectTest method, by returning -1.) + + The returned list is sorted by the layerable/drawing order. If you only need to know the top-most + layerable, rather use \ref layerableAt. + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableAt, layoutElementAt, axisRectAt +*/ +QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const +{ + QList result; + for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) + { + const QList layerables = mLayers.at(layerIndex)->children(); + for (int i=layerables.size()-1; i>=0; --i) + { + if (!layerables.at(i)->realVisibility()) + continue; + QVariant details; + double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); + if (dist >= 0 && dist < selectionTolerance()) + { + result.append(layerables.at(i)); + if (selectionDetails) + selectionDetails->append(details); + } + } + } + return result; +} + +/*! + Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is + sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead + to a full resolution file with width 200.) If the \a format supports compression, \a quality may + be between 0 and 100 to control it. + + Returns true on success. If this function fails, most likely the given \a format isn't supported + by the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The \a resolution will be written to the image file header (if the file format supports this) and + has no direct consequence for the quality or the pixel size. However, if opening the image with a + tool which respects the metadata, it will be able to scale the image to match either a given size + in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in + which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted + to the format's expected resolution unit internally. + + \see saveBmp, saveJpg, savePng, savePdf +*/ +bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + QImage buffer = toPixmap(width, height, scale).toImage(); + + int dotsPerMeter = 0; + switch (resolutionUnit) + { + case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; + case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; + case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; + } + buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + if (!buffer.isNull()) + return buffer.save(fileName, format, quality); + else + return false; +} + +/*! + Renders the plot to a pixmap and returns it. + + The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and + scale 2.0 lead to a full resolution pixmap with width 200.) + + \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf +*/ +QPixmap QCustomPlot::toPixmap(int width, int height, double scale) +{ + // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + int scaledWidth = qRound(scale*newWidth); + int scaledHeight = qRound(scale*newHeight); + + QPixmap result(scaledWidth, scaledHeight); + result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later + QCPPainter painter; + painter.begin(&result); + if (painter.isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter.setMode(QCPPainter::pmNoCaching); + if (!qFuzzyCompare(scale, 1.0)) + { + if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales + painter.setMode(QCPPainter::pmNonCosmetic); + painter.scale(scale, scale); + } + if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill + painter.fillRect(mViewport, mBackgroundBrush); + draw(&painter); + setViewport(oldViewport); + painter.end(); + } else // might happen if pixmap has width or height zero + { + qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; + return QPixmap(); + } + return result; +} + +/*! + Renders the plot using the passed \a painter. + + The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will + appear scaled accordingly. + + \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter + on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with + the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. + + \see toPixmap +*/ +void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) +{ + // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + if (painter->isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter->setMode(QCPPainter::pmNoCaching); + if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here + painter->fillRect(mViewport, mBackgroundBrush); + draw(painter); + setViewport(oldViewport); + } else + qDebug() << Q_FUNC_INFO << "Passed painter is not active"; +} +/* end of 'src/core.cpp' */ + +//amalgamation: add plottable1d.cpp + +/* including file 'src/colorgradient.cpp', size 24646 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorGradient +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorGradient + \brief Defines a color gradient for use with e.g. \ref QCPColorMap + + This class describes a color gradient which can be used to encode data with color. For example, + QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which + take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) + with a \a position from 0 to 1. In between these defined color positions, the + color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. + + Alternatively, load one of the preset color gradients shown in the image below, with \ref + loadPreset, or by directly specifying the preset in the constructor. + + Apart from red, green and blue components, the gradient also interpolates the alpha values of the + configured color stops. This allows to display some portions of the data range as transparent in + the plot. + + \image html QCPColorGradient.png + + The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref + GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset + to all the \a setGradient methods, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient + + The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the + color gradient shall be applied periodically (wrapping around) to data values that lie outside + the data range specified on the plottable instance can be controlled with \ref setPeriodic. +*/ + +/*! + Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color + stops with \ref setColorStopAt. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient() : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); +} + +/*! + Constructs a new QCPColorGradient initialized with the colors and color interpolation according + to \a preset. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient(GradientPreset preset) : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); + loadPreset(preset); +} + +/* undocumented operator */ +bool QCPColorGradient::operator==(const QCPColorGradient &other) const +{ + return ((other.mLevelCount == this->mLevelCount) && + (other.mColorInterpolation == this->mColorInterpolation) && + (other.mPeriodic == this->mPeriodic) && + (other.mColorStops == this->mColorStops)); +} + +/*! + Sets the number of discretization levels of the color gradient to \a n. The default is 350 which + is typically enough to create a smooth appearance. The minimum number of levels is 2. + + \image html QCPColorGradient-levelcount.png +*/ +void QCPColorGradient::setLevelCount(int n) +{ + if (n < 2) + { + qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; + n = 2; + } + if (n != mLevelCount) + { + mLevelCount = n; + mColorBufferInvalidated = true; + } +} + +/*! + Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the + colors are the values of the passed QMap \a colorStops. In between these color stops, the color + is interpolated according to \ref setColorInterpolation. + + A more convenient way to create a custom gradient may be to clear all color stops with \ref + clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with + \ref setColorStopAt. + + \see clearColorStops +*/ +void QCPColorGradient::setColorStops(const QMap &colorStops) +{ + mColorStops = colorStops; + mColorBufferInvalidated = true; +} + +/*! + Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between + these color stops, the color is interpolated according to \ref setColorInterpolation. + + \see setColorStops, clearColorStops +*/ +void QCPColorGradient::setColorStopAt(double position, const QColor &color) +{ + mColorStops.insert(position, color); + mColorBufferInvalidated = true; +} + +/*! + Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be + interpolated linearly in RGB or in HSV color space. + + For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, + whereas in HSV space the intermediate color is yellow. +*/ +void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) +{ + if (interpolation != mColorInterpolation) + { + mColorInterpolation = interpolation; + mColorBufferInvalidated = true; + } +} + +/*! + Sets whether data points that are outside the configured data range (e.g. \ref + QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether + they all have the same color, corresponding to the respective gradient boundary color. + + \image html QCPColorGradient-periodic.png + + As shown in the image above, gradients that have the same start and end color are especially + suitable for a periodic gradient mapping, since they produce smooth color transitions throughout + the color map. A preset that has this property is \ref gpHues. + + In practice, using periodic color gradients makes sense when the data corresponds to a periodic + dimension, such as an angle or a phase. If this is not the case, the color encoding might become + ambiguous, because multiple different data values are shown as the same color. +*/ +void QCPColorGradient::setPeriodic(bool enabled) +{ + mPeriodic = enabled; +} + +/*! \overload + + This method is used to quickly convert a \a data array to colors. The colors will be output in + the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this + function. The data range that shall be used for mapping the data value to the gradient is passed + in \a range. \a logarithmic indicates whether the data values shall be mapped to colors + logarithmically. + + if \a data actually contains 2D-data linearized via [row*columnCount + column], you can + set \a dataIndexFactor to columnCount to convert a column instead of a row of the data + array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data + is addressed data[i*dataIndexFactor]. + + Use the overloaded method to additionally provide alpha map data. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } +} + +/*! \overload + + Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which + has the same size and structure as \a data and encodes the alpha information per data point. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!alpha) + { + qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } +} + +/*! \internal + + This method is used to colorize a single data value given in \a position, to colors. The data + range that shall be used for mapping the data value to the gradient is passed in \a range. \a + logarithmic indicates whether the data value shall be mapped to a color logarithmically. + + If an entire array of data values shall be converted, rather use \ref colorize, for better + performance. + + The returned QRgb has its r, g and b components premultiplied with alpha (see + QImage::Format_ARGB32_Premultiplied). +*/ +QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) +{ + // If you change something here, make sure to also adapt ::colorize() + if (mColorBufferInvalidated) + updateColorBuffer(); + int index = 0; + if (!logarithmic) + index = (position-range.lower)*(mLevelCount-1)/range.size(); + else + index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); + if (mPeriodic) + { + index = index % mLevelCount; + if (index < 0) + index += mLevelCount; + } else + { + if (index < 0) + index = 0; + else if (index >= mLevelCount) + index = mLevelCount-1; + } + return mColorBuffer.at(index); +} + +/*! + Clears the current color stops and loads the specified \a preset. A preset consists of predefined + color stops and the corresponding color interpolation method. + + The available presets are: + \image html QCPColorGradient.png +*/ +void QCPColorGradient::loadPreset(GradientPreset preset) +{ + clearColorStops(); + switch (preset) + { + case gpGrayscale: + setColorInterpolation(ciRGB); + setColorStopAt(0, Qt::black); + setColorStopAt(1, Qt::white); + break; + case gpHot: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 0, 0)); + setColorStopAt(0.2, QColor(180, 10, 0)); + setColorStopAt(0.4, QColor(245, 50, 0)); + setColorStopAt(0.6, QColor(255, 150, 10)); + setColorStopAt(0.8, QColor(255, 255, 50)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpCold: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.2, QColor(0, 10, 180)); + setColorStopAt(0.4, QColor(0, 50, 245)); + setColorStopAt(0.6, QColor(10, 150, 255)); + setColorStopAt(0.8, QColor(50, 255, 255)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpNight: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(10, 20, 30)); + setColorStopAt(1, QColor(250, 255, 250)); + break; + case gpCandy: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(0, 0, 255)); + setColorStopAt(1, QColor(255, 250, 250)); + break; + case gpGeography: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(70, 170, 210)); + setColorStopAt(0.20, QColor(90, 160, 180)); + setColorStopAt(0.25, QColor(45, 130, 175)); + setColorStopAt(0.30, QColor(100, 140, 125)); + setColorStopAt(0.5, QColor(100, 140, 100)); + setColorStopAt(0.6, QColor(130, 145, 120)); + setColorStopAt(0.7, QColor(140, 130, 120)); + setColorStopAt(0.9, QColor(180, 190, 190)); + setColorStopAt(1, QColor(210, 210, 230)); + break; + case gpIon: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 10, 10)); + setColorStopAt(0.45, QColor(0, 0, 255)); + setColorStopAt(0.8, QColor(0, 255, 255)); + setColorStopAt(1, QColor(0, 255, 0)); + break; + case gpThermal: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.15, QColor(20, 0, 120)); + setColorStopAt(0.33, QColor(200, 30, 140)); + setColorStopAt(0.6, QColor(255, 100, 0)); + setColorStopAt(0.85, QColor(255, 255, 40)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpPolar: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 255, 255)); + setColorStopAt(0.18, QColor(10, 70, 255)); + setColorStopAt(0.28, QColor(10, 10, 190)); + setColorStopAt(0.5, QColor(0, 0, 0)); + setColorStopAt(0.72, QColor(190, 10, 10)); + setColorStopAt(0.82, QColor(255, 70, 10)); + setColorStopAt(1, QColor(255, 255, 50)); + break; + case gpSpectrum: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 0, 50)); + setColorStopAt(0.15, QColor(0, 0, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.6, QColor(255, 255, 0)); + setColorStopAt(0.75, QColor(255, 30, 0)); + setColorStopAt(1, QColor(50, 0, 0)); + break; + case gpJet: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 100)); + setColorStopAt(0.15, QColor(0, 50, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.65, QColor(255, 255, 0)); + setColorStopAt(0.85, QColor(255, 30, 0)); + setColorStopAt(1, QColor(100, 0, 0)); + break; + case gpHues: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(255, 0, 0)); + setColorStopAt(1.0/3.0, QColor(0, 0, 255)); + setColorStopAt(2.0/3.0, QColor(0, 255, 0)); + setColorStopAt(1, QColor(255, 0, 0)); + break; + } +} + +/*! + Clears all color stops. + + \see setColorStops, setColorStopAt +*/ +void QCPColorGradient::clearColorStops() +{ + mColorStops.clear(); + mColorBufferInvalidated = true; +} + +/*! + Returns an inverted gradient. The inverted gradient has all properties as this \ref + QCPColorGradient, but the order of the color stops is inverted. + + \see setColorStops, setColorStopAt +*/ +QCPColorGradient QCPColorGradient::inverted() const +{ + QCPColorGradient result(*this); + result.clearColorStops(); + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + result.setColorStopAt(1.0-it.key(), it.value()); + return result; +} + +/*! \internal + + Returns true if the color gradient uses transparency, i.e. if any of the configured color stops + has an alpha value below 255. +*/ +bool QCPColorGradient::stopsUseAlpha() const +{ + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + { + if (it.value().alpha() < 255) + return true; + } + return false; +} + +/*! \internal + + Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly + convert positions to colors. This is where the interpolation between color stops is calculated. +*/ +void QCPColorGradient::updateColorBuffer() +{ + if (mColorBuffer.size() != mLevelCount) + mColorBuffer.resize(mLevelCount); + if (mColorStops.size() > 1) + { + double indexToPosFactor = 1.0/(double)(mLevelCount-1); + const bool useAlpha = stopsUseAlpha(); + for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); + if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop + { + mColorBuffer[i] = (it-1).value().rgba(); + } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop + { + mColorBuffer[i] = it.value().rgba(); + } else // position is in between stops (or on an intermediate stop), interpolate color + { + QMap::const_iterator high = it; + QMap::const_iterator low = it-1; + double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 + switch (mColorInterpolation) + { + case ciRGB: + { + if (useAlpha) + { + const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); + const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, + ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, + ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, + alpha); + } else + { + mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), + ((1-t)*low.value().green() + t*high.value().green()), + ((1-t)*low.value().blue() + t*high.value().blue())); + } + break; + } + case ciHSV: + { + QColor lowHsv = low.value().toHsv(); + QColor highHsv = high.value().toHsv(); + double hue = 0; + double hueDiff = highHsv.hueF()-lowHsv.hueF(); + if (hueDiff > 0.5) + hue = lowHsv.hueF() - t*(1.0-hueDiff); + else if (hueDiff < -0.5) + hue = lowHsv.hueF() + t*(1.0+hueDiff); + else + hue = lowHsv.hueF() + t*hueDiff; + if (hue < 0) hue += 1.0; + else if (hue >= 1.0) hue -= 1.0; + if (useAlpha) + { + const QRgb rgb = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); + mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); + } + else + { + mColorBuffer[i] = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + } + break; + } + } + } + } + } else if (mColorStops.size() == 1) + { + const QRgb rgb = mColorStops.constBegin().value().rgb(); + const float alpha = mColorStops.constBegin().value().alphaF(); + mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); + } else // mColorStops is empty, fill color buffer with black + { + mColorBuffer.fill(qRgb(0, 0, 0)); + } + mColorBufferInvalidated = false; +} +/* end of 'src/colorgradient.cpp' */ + + +/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecoratorBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecoratorBracket + \brief A selection decorator which draws brackets around each selected data segment + + Additionally to the regular highlighting of selected segments via color, fill and scatter style, + this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data + segment of the plottable. + + The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and + \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref + setBracketBrush. + + To introduce custom bracket styles, it is only necessary to sublcass \ref + QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the + base class. +*/ + +/*! + Creates a new QCPSelectionDecoratorBracket instance with default values. +*/ +QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : + mBracketPen(QPen(Qt::black)), + mBracketBrush(Qt::NoBrush), + mBracketWidth(5), + mBracketHeight(50), + mBracketStyle(bsSquareBracket), + mTangentToData(false), + mTangentAverage(2) +{ + +} + +QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() +{ +} + +/*! + Sets the pen that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) +{ + mBracketPen = pen; +} + +/*! + Sets the brush that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) +{ + mBracketBrush = brush; +} + +/*! + Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of + the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketWidth(int width) +{ + mBracketWidth = width; +} + +/*! + Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis + of the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketHeight(int height) +{ + mBracketHeight = height; +} + +/*! + Sets the shape that the bracket/marker will have. + + \see setBracketWidth, setBracketHeight +*/ +void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) +{ + mBracketStyle = style; +} + +/*! + Sets whether the brackets will be rotated such that they align with the slope of the data at the + position that they appear in. + + For noisy data, it might be more visually appealing to average the slope over multiple data + points. This can be configured via \ref setTangentAverage. +*/ +void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) +{ + mTangentToData = enabled; +} + +/*! + Controls over how many data points the slope shall be averaged, when brackets shall be aligned + with the data (if \ref setTangentToData is true). + + From the position of the bracket, \a pointCount points towards the selected data range will be + taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to + disabling \ref setTangentToData. +*/ +void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) +{ + mTangentAverage = pointCount; + if (mTangentAverage < 1) + mTangentAverage = 1; +} + +/*! + Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and + indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening + bracket, respectively). + + The passed \a painter already contains all transformations that are necessary to position and + rotate the bracket appropriately. Painting operations can be performed as if drawing upright + brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. + + If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket + shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should + reimplement. +*/ +void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const +{ + switch (mBracketStyle) + { + case bsSquareBracket: + { + painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); + painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + break; + } + case bsHalfEllipse: + { + painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); + break; + } + case bsEllipse: + { + painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); + break; + } + case bsPlus: + { + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); + break; + } + default: + { + qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); + break; + } + } +} + +/*! + Draws the bracket decoration on the data points at the begin and end of each selected data + segment given in \a seletion. + + It uses the method \ref drawBracket to actually draw the shapes. + + \seebaseclassmethod +*/ +void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + if (!mPlottable || selection.isEmpty()) return; + + if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) + { + Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) + { + // determine position and (if tangent mode is enabled) angle of brackets: + int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; + int closeBracketDir = -openBracketDir; + QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); + QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); + double openBracketAngle = 0; + double closeBracketAngle = 0; + if (mTangentToData) + { + openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); + closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); + } + // draw opening bracket: + QTransform oldTransform = painter->transform(); + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(openBracketPos); + painter->rotate(openBracketAngle/M_PI*180.0); + drawBracket(painter, openBracketDir); + painter->setTransform(oldTransform); + // draw closing bracket: + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(closeBracketPos); + painter->rotate(closeBracketAngle/M_PI*180.0); + drawBracket(painter, closeBracketDir); + painter->setTransform(oldTransform); + } + } +} + +/*! \internal + + If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. + This method returns the angle in radians by which a bracket at the given \a dataIndex must be + rotated. + + The parameter \a direction must be set to either -1 or 1, representing whether it is an opening + or closing bracket. Since for slope calculation multiple data points are required, this defines + the direction in which the algorithm walks, starting at \a dataIndex, to average those data + points. (see \ref setTangentToData and \ref setTangentAverage) + + \a interface1d is the interface to the plottable's data which is used to query data coordinates. +*/ +double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const +{ + if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) + return 0; + direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 + + // how many steps we can actually go from index in the given direction without exceeding data bounds: + int averageCount; + if (direction < 0) + averageCount = qMin(mTangentAverage, dataIndex); + else + averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); + qDebug() << averageCount; + // calculate point average of averageCount points: + QVector points(averageCount); + QPointF pointsAverage; + int currentIndex = dataIndex; + for (int i=0; ikeyAxis(); + QCPAxis *valueAxis = mPlottable->valueAxis(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); + else + return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); +} +/* end of 'src/selectiondecorator-bracket.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisRect + \brief Holds multiple axes and arranges them in a rectangular shape. + + This class represents an axis rect, a rectangular area that is bounded on all sides with an + arbitrary number of axes. + + Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the + layout system allows to have multiple axis rects, e.g. arranged in a grid layout + (QCustomPlot::plotLayout). + + By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be + accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. + If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be + invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref + addAxes. To remove an axis, use \ref removeAxis. + + The axis rect layerable itself only draws a background pixmap or color, if specified (\ref + setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an + explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be + placed on other layers, independently of the axis rect. + + Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref + insetLayout and can be used to have other layout elements (or even other layouts with multiple + elements) hovering inside the axis rect. + + If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The + behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel + is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable + via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are + only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref + QCP::iRangeZoom. + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed + line on the far left indicates the viewport/widget border.
+*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const + + Returns the inset layout of this axis rect. It can be used to place other layout elements (or + even layouts with multiple other elements) inside/on top of an axis rect. + + \see QCPLayoutInset +*/ + +/*! \fn int QCPAxisRect::left() const + + Returns the pixel position of the left border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::right() const + + Returns the pixel position of the right border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::top() const + + Returns the pixel position of the top border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::bottom() const + + Returns the pixel position of the bottom border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::width() const + + Returns the pixel width of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::height() const + + Returns the pixel height of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QSize QCPAxisRect::size() const + + Returns the pixel size of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topLeft() const + + Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, + so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topRight() const + + Returns the top right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomLeft() const + + Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomRight() const + + Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::center() const + + Returns the center of this axis rect in pixels. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four + sides, the top and right axes are set invisible initially. +*/ +QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : + QCPLayoutElement(parentPlot), + mBackgroundBrush(Qt::NoBrush), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mInsetLayout(new QCPLayoutInset), + mRangeDrag(Qt::Horizontal|Qt::Vertical), + mRangeZoom(Qt::Horizontal|Qt::Vertical), + mRangeZoomFactorHorz(0.85), + mRangeZoomFactorVert(0.85), + mDragging(false) +{ + mInsetLayout->initializeParentPlot(mParentPlot); + mInsetLayout->setParentLayerable(this); + mInsetLayout->setParent(this); + + setMinimumSize(50, 50); + setMinimumMargins(QMargins(15, 15, 15, 15)); + mAxes.insert(QCPAxis::atLeft, QList()); + mAxes.insert(QCPAxis::atRight, QList()); + mAxes.insert(QCPAxis::atTop, QList()); + mAxes.insert(QCPAxis::atBottom, QList()); + + if (setupDefaultAxes) + { + QCPAxis *xAxis = addAxis(QCPAxis::atBottom); + QCPAxis *yAxis = addAxis(QCPAxis::atLeft); + QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); + QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); + setRangeDragAxes(xAxis, yAxis); + setRangeZoomAxes(xAxis, yAxis); + xAxis2->setVisible(false); + yAxis2->setVisible(false); + xAxis->grid()->setVisible(true); + yAxis->grid()->setVisible(true); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + xAxis2->grid()->setZeroLinePen(Qt::NoPen); + yAxis2->grid()->setZeroLinePen(Qt::NoPen); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + } +} + +QCPAxisRect::~QCPAxisRect() +{ + delete mInsetLayout; + mInsetLayout = 0; + + QList axesList = axes(); + for (int i=0; i ax(mAxes.value(type)); + if (index >= 0 && index < ax.size()) + { + return ax.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; + return 0; + } +} + +/*! + Returns all axes on the axis rect sides specified with \a types. + + \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of + multiple sides. + + \see axis +*/ +QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << mAxes.value(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << mAxes.value(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << mAxes.value(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << mAxes.value(QCPAxis::atBottom); + return result; +} + +/*! \overload + + Returns all axes of this axis rect. +*/ +QList QCPAxisRect::axes() const +{ + QList result; + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + result << it.value(); + } + return result; +} + +/*! + Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a + new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to + remove an axis, use \ref removeAxis instead of deleting it manually. + + You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was + previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership + of the axis, so you may not delete it afterwards. Further, the \a axis must have been created + with this axis rect as parent and with the same axis type as specified in \a type. If this is not + the case, a debug output is generated, the axis is not added, and the method returns 0. + + This method can not be used to move \a axis between axis rects. The same \a axis instance must + not be added multiple times to the same or different axis rects. + + If an axis rect side already contains one or more axes, the lower and upper endings of the new + axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref + QCPLineEnding::esHalfBar. + + \see addAxes, setupFullAxesBox +*/ +QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) +{ + QCPAxis *newAxis = axis; + if (!newAxis) + { + newAxis = new QCPAxis(this, type); + } else // user provided existing axis instance, do some sanity checks + { + if (newAxis->axisType() != type) + { + qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; + return 0; + } + if (newAxis->axisRect() != this) + { + qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; + return 0; + } + if (axes().contains(newAxis)) + { + qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; + return 0; + } + } + if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset + { + bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); + newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); + newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); + } + mAxes[type].append(newAxis); + + // reset convenience axis pointers on parent QCustomPlot if they are unset: + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + switch (type) + { + case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } + case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } + case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } + case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } + } + } + + return newAxis; +} + +/*! + Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an + or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. + + Returns a list of the added axes. + + \see addAxis, setupFullAxesBox +*/ +QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << addAxis(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << addAxis(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << addAxis(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << addAxis(QCPAxis::atBottom); + return result; +} + +/*! + Removes the specified \a axis from the axis rect and deletes it. + + Returns true on success, i.e. if \a axis was a valid axis in this axis rect. + + \see addAxis +*/ +bool QCPAxisRect::removeAxis(QCPAxis *axis) +{ + // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + if (it.value().contains(axis)) + { + if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) + it.value()[1]->setOffset(axis->offset()); + mAxes[it.key()].removeOne(axis); + if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) + parentPlot()->axisRemoved(axis); + delete axis; + return true; + } + } + qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); + return false; +} + +/*! + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom + specific axes, use the overloaded version of this method. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect) +{ + zoom(pixelRect, axes()); +} + +/*! \overload + + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) +{ + Q_FOREACH (QCPAxis *axis, affectedAxes) + { + if (!axis) + { + qDebug() << Q_FUNC_INFO << "a passed axis was zero"; + continue; + } + QCPRange pixelRange; + if (axis->orientation() == Qt::Horizontal) + pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); + else + pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); + axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); + } +} + +/*! + Convenience function to create an axis on each side that doesn't have any axes yet and set their + visibility to true. Further, the top/right axes are assigned the following properties of the + bottom/left axes: + + \li range (\ref QCPAxis::setRange) + \li range reversed (\ref QCPAxis::setRangeReversed) + \li scale type (\ref QCPAxis::setScaleType) + \li tick visibility (\ref QCPAxis::setTicks) + \li number format (\ref QCPAxis::setNumberFormat) + \li number precision (\ref QCPAxis::setNumberPrecision) + \li tick count of ticker (\ref QCPAxisTicker::setTickCount) + \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) + + Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. + + If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom + and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. +*/ +void QCPAxisRect::setupFullAxesBox(bool connectRanges) +{ + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + if (axisCount(QCPAxis::atBottom) == 0) + xAxis = addAxis(QCPAxis::atBottom); + else + xAxis = axis(QCPAxis::atBottom); + + if (axisCount(QCPAxis::atLeft) == 0) + yAxis = addAxis(QCPAxis::atLeft); + else + yAxis = axis(QCPAxis::atLeft); + + if (axisCount(QCPAxis::atTop) == 0) + xAxis2 = addAxis(QCPAxis::atTop); + else + xAxis2 = axis(QCPAxis::atTop); + + if (axisCount(QCPAxis::atRight) == 0) + yAxis2 = addAxis(QCPAxis::atRight); + else + yAxis2 = axis(QCPAxis::atRight); + + xAxis->setVisible(true); + yAxis->setVisible(true); + xAxis2->setVisible(true); + yAxis2->setVisible(true); + xAxis2->setTickLabels(false); + yAxis2->setTickLabels(false); + + xAxis2->setRange(xAxis->range()); + xAxis2->setRangeReversed(xAxis->rangeReversed()); + xAxis2->setScaleType(xAxis->scaleType()); + xAxis2->setTicks(xAxis->ticks()); + xAxis2->setNumberFormat(xAxis->numberFormat()); + xAxis2->setNumberPrecision(xAxis->numberPrecision()); + xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); + xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); + + yAxis2->setRange(yAxis->range()); + yAxis2->setRangeReversed(yAxis->rangeReversed()); + yAxis2->setScaleType(yAxis->scaleType()); + yAxis2->setTicks(yAxis->ticks()); + yAxis2->setNumberFormat(yAxis->numberFormat()); + yAxis2->setNumberPrecision(yAxis->numberPrecision()); + yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); + yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); + + if (connectRanges) + { + connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); + connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); + } +} + +/*! + Returns a list of all the plottables that are associated with this axis rect. + + A plottable is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see graphs, items +*/ +QList QCPAxisRect::plottables() const +{ + // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries + QList result; + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that are associated with this axis rect. + + A graph is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see plottables, items +*/ +QList QCPAxisRect::graphs() const +{ + // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries + QList result; + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis rect. + + An item is considered associated with an axis rect if any of its positions has key or value axis + set to an axis that is in this axis rect, or if any of its positions has \ref + QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref + QCPAbstractItem::setClipAxisRect) is set to this axis rect. + + \see plottables, graphs +*/ +QList QCPAxisRect::items() const +{ + // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries + // and miss those items that have this axis rect as clipAxisRect. + QList result; + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + continue; + } + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdaxisRect() == this || + positions.at(posId)->keyAxis()->axisRect() == this || + positions.at(posId)->valueAxis()->axisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + This method is called automatically upon replot and doesn't need to be called by users of + QCPAxisRect. + + Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), + and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its + QCPInsetLayout::update function. + + \seebaseclassmethod +*/ +void QCPAxisRect::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + switch (phase) + { + case upPreparation: + { + QList allAxes = axes(); + for (int i=0; isetupTickVectors(); + break; + } + case upLayout: + { + mInsetLayout->setOuterRect(rect()); + break; + } + default: break; + } + + // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): + mInsetLayout->update(phase); +} + +/* inherits documentation from base class */ +QList QCPAxisRect::elements(bool recursive) const +{ + QList result; + if (mInsetLayout) + { + result << mInsetLayout; + if (recursive) + result << mInsetLayout->elements(recursive); + } + return result; +} + +/* inherits documentation from base class */ +void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPAxisRect::draw(QCPPainter *painter) +{ + drawBackground(painter); +} + +/*! + Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the + axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect + backgrounds are usually drawn below everything else. + + For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio + is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref + setBackground(const QBrush &brush). + + \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) +*/ +void QCPAxisRect::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! \overload + + Sets \a brush as the background brush. The axis rect background will be filled with this brush. + Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds + are usually drawn below everything else. + + The brush will be drawn before (under) any background pixmap, which may be specified with \ref + setBackground(const QPixmap &pm). + + To disable drawing of a background brush, set \a brush to Qt::NoBrush. + + \see setBackground(const QPixmap &pm) +*/ +void QCPAxisRect::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled + is set to true, you may control whether and how the aspect ratio of the original pixmap is + preserved with \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the axis rect dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to + define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. + \see setBackground, setBackgroundScaled +*/ +void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeDragAxes to retrieve a list with all set axes). + + \see setRangeDragAxes +*/ +QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); + else + return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); +} + +/*! + Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). + + \see setRangeZoomAxes +*/ +QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); + else + return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); +} + +/*! + Returns all range drag axes of the \a orientation provided. + + \see rangeZoomAxis, setRangeZoomAxes +*/ +QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; iQt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeDrag to enable the range dragging interaction. + + \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag +*/ +void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) +{ + mRangeDrag = orientations; +} + +/*! + Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation + corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, + QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical + axis is the left axis (yAxis). + + To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref + QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeZoom to enable the range zooming interaction. + + \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag +*/ +void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) +{ + mRangeZoom = orientations; +} + +/*! \overload + + Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on + the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to dragging interactions. + + \see setRangeZoomAxes +*/ +void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag + orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag + motion, use the overload taking two separate lists for horizontal and vertical dragging. +*/ +void QCPAxisRect::setRangeDragAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical dragging, and + define specifically which axis reacts to which drag orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) +{ + mRangeDragHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeDragVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on + the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. + + The two axes can be zoomed with different strengths, when different factors are passed to \ref + setRangeZoomFactor(double horizontalFactor, double verticalFactor). + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to zooming interactions. + + \see setRangeDragAxes +*/ +void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical range zooming. The + zoom orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom + interaction, use the overload taking two separate lists for horizontal and vertical zooming. +*/ +void QCPAxisRect::setRangeZoomAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical zooming, and + define specifically which axis reacts to which zoom orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) +{ + mRangeZoomHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeZoomVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with + \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to + let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal + and which is vertical, can be set with \ref setRangeZoomAxes. + + When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) + will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the + same scrolling direction will zoom out. +*/ +void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) +{ + mRangeZoomFactorHorz = horizontalFactor; + mRangeZoomFactorVert = verticalFactor; +} + +/*! \overload + + Sets both the horizontal and vertical zoom \a factor. +*/ +void QCPAxisRect::setRangeZoomFactor(double factor) +{ + mRangeZoomFactorHorz = factor; + mRangeZoomFactorVert = factor; +} + +/*! \internal + + Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a + pixmap. + + If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an + according filling inside the axis rect with the provided \a painter. + + Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the axis rect with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::drawBackground(QCPPainter *painter) +{ + // draw background fill: + if (mBackgroundBrush != Qt::NoBrush) + painter->fillRect(mRect, mBackgroundBrush); + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mRect.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); + } + } +} + +/*! \internal + + This function makes sure multiple axes on the side specified with \a type don't collide, but are + distributed according to their respective space requirement (QCPAxis::calculateMargin). + + It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the + one with index zero. + + This function is called by \ref calculateAutoMargin. +*/ +void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) +{ + const QList axesList = mAxes.value(type); + if (axesList.isEmpty()) + return; + + bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false + for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); + if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) + { + if (!isFirstVisible) + offset += axesList.at(i)->tickLengthIn(); + isFirstVisible = false; + } + axesList.at(i)->setOffset(offset); + } +} + +/* inherits documentation from base class */ +int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) +{ + if (!mAutoMargins.testFlag(side)) + qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; + + updateAxesOffset(QCPAxis::marginSideToAxisType(side)); + + // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call + const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); + if (axesList.size() > 0) + return axesList.last()->offset() + axesList.last()->calculateMargin(); + else + return 0; +} + +/*! \internal + + Reacts to a change in layout to potentially set the convenience axis pointers \ref + QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective + axes of this axis rect. This is only done if the respective convenience pointer is currently zero + and if there is no QCPAxisRect at position (0, 0) of the plot layout. + + This automation makes it simpler to replace the main axis rect with a newly created one, without + the need to manually reset the convenience pointers. +*/ +void QCPAxisRect::layoutChanged() +{ + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) + mParentPlot->xAxis = axis(QCPAxis::atBottom); + if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) + mParentPlot->yAxis = axis(QCPAxis::atLeft); + if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) + mParentPlot->xAxis2 = axis(QCPAxis::atTop); + if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) + mParentPlot->yAxis2 = axis(QCPAxis::atRight); + } +} + +/*! \internal + + Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is + pressed, the range dragging interaction is initialized (the actual range manipulation happens in + the \ref mouseMoveEvent). + + The mDragging flag is set to true and some anchor points are set that are needed to determine the + distance the mouse was dragged in the mouse move/release events later. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + mDragStartHorzRange.clear(); + for (int i=0; irange()); + mDragStartVertRange.clear(); + for (int i=0; irange()); + } + } +} + +/*! \internal + + Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a + preceding \ref mousePressEvent, the range is moved accordingly. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + // Mouse range dragging interaction: + if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + + if (mRangeDrag.testFlag(Qt::Horizontal)) + { + for (int i=0; i= mDragStartHorzRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag.testFlag(Qt::Vertical)) + { + for (int i=0; i= mDragStartVertRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot + { + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } + + } +} + +/* inherits documentation from base class */ +void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the + ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of + the scaling operation is the current cursor position inside the axis rect. The scaling factor is + dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural + zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. + + Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse + wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be + multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as + exponent of the range zoom factor. This takes care of the wheel direction automatically, by + inverting the factor, when the wheel step is negative (f^-1 = 1/f). +*/ +void QCPAxisRect::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) + { + if (mRangeZoom != 0) + { + double factor; + double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + if (mRangeZoom.testFlag(Qt::Horizontal)) + { + factor = qPow(mRangeZoomFactorHorz, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); + } + } + if (mRangeZoom.testFlag(Qt::Vertical)) + { + factor = qPow(mRangeZoomFactorVert, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); + } + } + mParentPlot->replot(); + } + } +} +/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractLegendItem + \brief The abstract base class for all entries in a QCPLegend. + + It defines a very basic interface for entries in a QCPLegend. For representing plottables in the + legend, the subclass \ref QCPPlottableLegendItem is more suitable. + + Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry + that's not even associated with a plottable). + + You must implement the following pure virtual functions: + \li \ref draw (from QCPLayerable) + + You inherit the following members you may use: + + + + + + + + +
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
+*/ + +/* start of documentation of signals */ + +/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) + + This signal is emitted when the selection state of this legend item has changed, either by user + interaction or by a direct call to \ref setSelected. +*/ + +/* end of documentation of signals */ + +/*! + Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not + cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. +*/ +QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : + QCPLayoutElement(parent->parentPlot()), + mParentLegend(parent), + mFont(parent->font()), + mTextColor(parent->textColor()), + mSelectedFont(parent->selectedFont()), + mSelectedTextColor(parent->selectedTextColor()), + mSelectable(true), + mSelected(false) +{ + setLayer(QLatin1String("legend")); + setMargins(QMargins(0, 0, 0, 0)); +} + +/*! + Sets the default font of this specific legend item to \a font. + + \see setTextColor, QCPLegend::setFont +*/ +void QCPAbstractLegendItem::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the default text color of this specific legend item to \a color. + + \see setFont, QCPLegend::setTextColor +*/ +void QCPAbstractLegendItem::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + When this legend item is selected, \a font is used to draw generic text, instead of the normal + font set with \ref setFont. + + \see setFont, QCPLegend::setSelectedFont +*/ +void QCPAbstractLegendItem::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + When this legend item is selected, \a color is used to draw generic text, instead of the normal + color set with \ref setTextColor. + + \see setTextColor, QCPLegend::setSelectedTextColor +*/ +void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether this specific legend item is selectable. + + \see setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this specific legend item is selected. + + It is possible to set the selection state of this item by calling this function directly, even if + setSelectable is set to false. + + \see setSelectableParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (!mParentPlot) return -1; + if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) + return -1; + + if (mRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); +} + +/* inherits documentation from base class */ +QRect QCPAbstractLegendItem::clipRect() const +{ + return mOuterRect; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableLegendItem + \brief A legend item representing a plottable with an icon and the plottable name. + + This is the standard legend item for plottables. It displays an icon of the plottable next to the + plottable name. The icon is drawn by the respective plottable itself (\ref + QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. + For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the + middle. + + Legend items of this type are always associated with one plottable (retrievable via the + plottable() function and settable with the constructor). You may change the font of the plottable + name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref + QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. + + The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend + creates/removes legend items of this type. + + Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of + QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout + interface, QCPLegend has specialized functions for handling legend items conveniently, see the + documentation of \ref QCPLegend. +*/ + +/*! + Creates a new legend item associated with \a plottable. + + Once it's created, it can be added to the legend via \ref QCPLegend::addItem. + + A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref + QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. +*/ +QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : + QCPAbstractLegendItem(parent), + mPlottable(plottable) +{ + setAntialiased(false); +} + +/*! \internal + + Returns the pen that shall be used to draw the icon border, taking into account the selection + state of this item. +*/ +QPen QCPPlottableLegendItem::getIconBorderPen() const +{ + return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); +} + +/*! \internal + + Returns the text color that shall be used to draw text, taking into account the selection state + of this item. +*/ +QColor QCPPlottableLegendItem::getTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} + +/*! \internal + + Returns the font that shall be used to draw text, taking into account the selection state of this + item. +*/ +QFont QCPPlottableLegendItem::getFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Draws the item with \a painter. The size and position of the drawn legend item is defined by the + parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref + maximumOuterSizeHint of this legend item. +*/ +void QCPPlottableLegendItem::draw(QCPPainter *painter) +{ + if (!mPlottable) return; + painter->setFont(getFont()); + painter->setPen(QPen(getTextColor())); + QSizeF iconSize = mParentLegend->iconSize(); + QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + QRectF iconRect(mRect.topLeft(), iconSize); + int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops + painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); + // draw icon: + painter->save(); + painter->setClipRect(iconRect, Qt::IntersectClip); + mPlottable->drawLegendIcon(painter, iconRect); + painter->restore(); + // draw icon border: + if (getIconBorderPen().style() != Qt::NoPen) + { + painter->setPen(getIconBorderPen()); + painter->setBrush(Qt::NoBrush); + int halfPen = qCeil(painter->pen().widthF()*0.5)+1; + painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped + painter->drawRect(iconRect); + } +} + +/*! \internal + + Calculates and returns the size of this item. This includes the icon, the text and the padding in + between. + + \seebaseclassmethod +*/ +QSize QCPPlottableLegendItem::minimumOuterSizeHint() const +{ + if (!mPlottable) return QSize(); + QSize result(0, 0); + QRect textRect; + QFontMetrics fontMetrics(getFont()); + QSize iconSize = mParentLegend->iconSize(); + textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); + result.setHeight(qMax(textRect.height(), iconSize.height())); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLegend +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLegend + \brief Manages a legend inside a QCustomPlot. + + A legend is a small box somewhere in the plot which lists plottables with their name and icon. + + A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the + plottable, for which a legend item shall be created. In the case of the main legend (\ref + QCustomPlot::legend), simply adding plottables to the plot while \ref + QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding + legend items. The legend item associated with a certain plottable can be removed with \ref + QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and + manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref + addItem, \ref removeItem, etc. + + Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref + QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement + "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds + an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as + mentioned above. In principle, any other layout elements may also be added to a legend via the + normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout + System\endlink for examples on how to add other elements to the legend and move it outside the axis + rect. + + Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control + in which order (column first or row first) the legend is filled up when calling \ref addItem, and + at which column or row wrapping occurs. + + By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the + inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another + position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend + outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement + interface. +*/ + +/* start of documentation of signals */ + +/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); + + This signal is emitted when the selection state of this legend has changed. + + \see setSelectedParts, setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs a new QCPLegend instance with default values. + + Note that by default, QCustomPlot already contains a legend ready to be used as \ref + QCustomPlot::legend +*/ +QCPLegend::QCPLegend() +{ + setFillOrder(QCPLayoutGrid::foRowsFirst); + setWrap(0); + + setRowSpacing(3); + setColumnSpacing(8); + setMargins(QMargins(7, 5, 7, 4)); + setAntialiased(false); + setIconSize(32, 18); + + setIconTextPadding(7); + + setSelectableParts(spLegendBox | spItems); + setSelectedParts(spNone); + + setBorderPen(QPen(Qt::black, 0)); + setSelectedBorderPen(QPen(Qt::blue, 2)); + setIconBorderPen(Qt::NoPen); + setSelectedIconBorderPen(QPen(Qt::blue, 2)); + setBrush(Qt::white); + setSelectedBrush(Qt::white); + setTextColor(Qt::black); + setSelectedTextColor(Qt::blue); +} + +QCPLegend::~QCPLegend() +{ + clearItems(); + if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) + mParentPlot->legendRemoved(this); +} + +/* no doc for getter, see setSelectedParts */ +QCPLegend::SelectableParts QCPLegend::selectedParts() const +{ + // check whether any legend elements selected, if yes, add spItems to return value + bool hasSelectedItems = false; + for (int i=0; iselected()) + { + hasSelectedItems = true; + break; + } + } + if (hasSelectedItems) + return mSelectedParts | spItems; + else + return mSelectedParts & ~spItems; +} + +/*! + Sets the pen, the border of the entire legend is drawn with. +*/ +void QCPLegend::setBorderPen(const QPen &pen) +{ + mBorderPen = pen; +} + +/*! + Sets the brush of the legend background. +*/ +void QCPLegend::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will + use this font by default. However, a different font can be specified on a per-item-basis by + accessing the specific legend item. + + This function will also set \a font on all already existing legend items. + + \see QCPAbstractLegendItem::setFont +*/ +void QCPLegend::setFont(const QFont &font) +{ + mFont = font; + for (int i=0; isetFont(mFont); + } +} + +/*! + Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) + will use this color by default. However, a different colors can be specified on a per-item-basis + by accessing the specific legend item. + + This function will also set \a color on all already existing legend items. + + \see QCPAbstractLegendItem::setTextColor +*/ +void QCPLegend::setTextColor(const QColor &color) +{ + mTextColor = color; + for (int i=0; isetTextColor(color); + } +} + +/*! + Sets the size of legend icons. Legend items that draw an icon (e.g. a visual + representation of the graph) will use this size by default. +*/ +void QCPLegend::setIconSize(const QSize &size) +{ + mIconSize = size; +} + +/*! \overload +*/ +void QCPLegend::setIconSize(int width, int height) +{ + mIconSize.setWidth(width); + mIconSize.setHeight(height); +} + +/*! + Sets the horizontal space in pixels between the legend icon and the text next to it. + Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the + name of the graph) will use this space by default. +*/ +void QCPLegend::setIconTextPadding(int padding) +{ + mIconTextPadding = padding; +} + +/*! + Sets the pen used to draw a border around each legend icon. Legend items that draw an + icon (e.g. a visual representation of the graph) will use this pen by default. + + If no border is wanted, set this to \a Qt::NoPen. +*/ +void QCPLegend::setIconBorderPen(const QPen &pen) +{ + mIconBorderPen = pen; +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPLegend::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected + doesn't contain \ref spItems, those items become deselected. + + The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions + contains iSelectLegend. You only need to call this function when you wish to change the selection + state manually. + + This function can change the selection state of a part even when \ref setSelectableParts was set to a + value that actually excludes the part. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set + before, because there's no way to specify which exact items to newly select. Do this by calling + \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, + setSelectedFont +*/ +void QCPLegend::setSelectedParts(const SelectableParts &selected) +{ + SelectableParts newSelected = selected; + mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed + + if (mSelectedParts != newSelected) + { + if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) + { + qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; + newSelected &= ~spItems; + } + if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection + { + for (int i=0; isetSelected(false); + } + } + mSelectedParts = newSelected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + When the legend box is selected, this pen is used to draw the border instead of the normal pen + set via \ref setBorderPen. + + \see setSelectedParts, setSelectableParts, setSelectedBrush +*/ +void QCPLegend::setSelectedBorderPen(const QPen &pen) +{ + mSelectedBorderPen = pen; +} + +/*! + Sets the pen legend items will use to draw their icon borders, when they are selected. + + \see setSelectedParts, setSelectableParts, setSelectedFont +*/ +void QCPLegend::setSelectedIconBorderPen(const QPen &pen) +{ + mSelectedIconBorderPen = pen; +} + +/*! + When the legend box is selected, this brush is used to draw the legend background instead of the normal brush + set via \ref setBrush. + + \see setSelectedParts, setSelectableParts, setSelectedBorderPen +*/ +void QCPLegend::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the default font that is used by legend items when they are selected. + + This function will also set \a font on all already existing legend items. + + \see setFont, QCPAbstractLegendItem::setSelectedFont +*/ +void QCPLegend::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; + for (int i=0; isetSelectedFont(font); + } +} + +/*! + Sets the default text color that is used by legend items when they are selected. + + This function will also set \a color on all already existing legend items. + + \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor +*/ +void QCPLegend::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; + for (int i=0; isetSelectedTextColor(color); + } +} + +/*! + Returns the item with index \a i. + + Note that the linear index depends on the current fill order (\ref setFillOrder). + + \see itemCount, addItem, itemWithPlottable +*/ +QCPAbstractLegendItem *QCPLegend::item(int index) const +{ + return qobject_cast(elementAt(index)); +} + +/*! + Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns 0. + + \see hasItemWithPlottable +*/ +QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + for (int i=0; i(item(i))) + { + if (pli->plottable() == plottable) + return pli; + } + } + return 0; +} + +/*! + Returns the number of items currently in the legend. + + Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid + base class which allows creating empty cells), they are included in the returned count. + + \see item +*/ +int QCPLegend::itemCount() const +{ + return elementCount(); +} + +/*! + Returns whether the legend contains \a item. + + \see hasItemWithPlottable +*/ +bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const +{ + for (int i=0; iitem(i)) + return true; + } + return false; +} + +/*! + Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns false. + + \see itemWithPlottable +*/ +bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + return itemWithPlottable(plottable); +} + +/*! + Adds \a item to the legend, if it's not present already. The element is arranged according to the + current fill order (\ref setFillOrder) and wrapping (\ref setWrap). + + Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. + + The legend takes ownership of the item. + + \see removeItem, item, hasItem +*/ +bool QCPLegend::addItem(QCPAbstractLegendItem *item) +{ + return addElement(item); +} + +/*! \overload + + Removes the item with the specified \a index from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes + elements derived from \ref QCPAbstractLegendItem. + + \see itemCount, clearItems +*/ +bool QCPLegend::removeItem(int index) +{ + if (QCPAbstractLegendItem *ali = item(index)) + { + bool success = remove(ali); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; + } else + return false; +} + +/*! \overload + + Removes \a item from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. + + \see clearItems +*/ +bool QCPLegend::removeItem(QCPAbstractLegendItem *item) +{ + bool success = remove(item); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; +} + +/*! + Removes all items from the legend. +*/ +void QCPLegend::clearItems() +{ + for (int i=itemCount()-1; i>=0; --i) + removeItem(i); +} + +/*! + Returns the legend items that are currently selected. If no items are selected, + the list is empty. + + \see QCPAbstractLegendItem::setSelected, setSelectable +*/ +QList QCPLegend::selectedItems() const +{ + QList result; + for (int i=0; iselected()) + result.append(ali); + } + } + return result; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing main legend elements. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); +} + +/*! \internal + + Returns the pen used to paint the border of the legend, taking into account the selection state + of the legend box. +*/ +QPen QCPLegend::getBorderPen() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; +} + +/*! \internal + + Returns the brush used to paint the background of the legend, taking into account the selection + state of the legend box. +*/ +QBrush QCPLegend::getBrush() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; +} + +/*! \internal + + Draws the legend box with the provided \a painter. The individual legend items are layerables + themselves, thus are drawn independently. +*/ +void QCPLegend::draw(QCPPainter *painter) +{ + // draw background rect: + painter->setBrush(getBrush()); + painter->setPen(getBorderPen()); + painter->drawRect(mOuterRect); +} + +/* inherits documentation from base class */ +double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) + return -1; + + if (mOuterRect.contains(pos.toPoint())) + { + if (details) details->setValue(spLegendBox); + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/* inherits documentation from base class */ +void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + mSelectedParts = selectedParts(); // in case item selection has changed + if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPLegend::deselectEvent(bool *selectionStateChanged) +{ + mSelectedParts = selectedParts(); // in case item selection has changed + if (mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(selectedParts() & ~spLegendBox); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPLegend::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractLegendItem::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) +{ + if (parentPlot && !parentPlot->legend) + parentPlot->legend = this; +} +/* end of 'src/layoutelements/layoutelement-legend.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPTextElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPTextElement + \brief A layout element displaying a text + + The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, + \ref setTextColor, and \ref setTextFlags. + + A text element can be added as follows: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation +*/ + +/* start documentation of signals */ + +/*! \fn void QCPTextElement::selectionChanged(bool selected) + + This signal is emitted when the selection state has changed to \a selected, either by user + interaction or by a direct call to \ref setSelected. + + \see setSelected, setSelectable +*/ + +/*! \fn void QCPTextElement::clicked(QMouseEvent *event) + + This signal is emitted when the text element is clicked. + + \see doubleClicked, selectTest +*/ + +/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) + + This signal is emitted when the text element is double clicked. + + \see clicked, selectTest +*/ + +/* end documentation of signals */ + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref + setText). +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mText(), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mFont.setPointSizeF(pointSize); + mSelectedFont = parentPlot->font(); + mSelectedFont.setPointSizeF(pointSize); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize and the specified \a fontFamily. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(fontFamily, pointSize)), + mTextColor(Qt::black), + mSelectedFont(QFont(fontFamily, pointSize)), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with the specified \a font. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(font), + mTextColor(Qt::black), + mSelectedFont(font), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! + Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". + + \see setFont, setTextColor, setTextFlags +*/ +void QCPTextElement::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of + \c Qt::AlignmentFlag and \c Qt::TextFlag enums. + + Possible enums are: + - Qt::AlignLeft + - Qt::AlignRight + - Qt::AlignHCenter + - Qt::AlignJustify + - Qt::AlignTop + - Qt::AlignBottom + - Qt::AlignVCenter + - Qt::AlignCenter + - Qt::TextDontClip + - Qt::TextSingleLine + - Qt::TextExpandTabs + - Qt::TextShowMnemonic + - Qt::TextWordWrap + - Qt::TextIncludeTrailingSpaces +*/ +void QCPTextElement::setTextFlags(int flags) +{ + mTextFlags = flags; +} + +/*! + Sets the \a font of the text. + + \see setTextColor, setSelectedFont +*/ +void QCPTextElement::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the \a color of the text. + + \see setFont, setSelectedTextColor +*/ +void QCPTextElement::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). + + \see setFont +*/ +void QCPTextElement::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). + + \see setTextColor +*/ +void QCPTextElement::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether the user may select this text element. + + Note that even when \a selectable is set to false, the selection state may be changed + programmatically via \ref setSelected. +*/ +void QCPTextElement::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets the selection state of this text element to \a selected. If the selection has changed, \ref + selectionChanged is emitted. + + Note that this function can change the selection state independently of the current \ref + setSelectable state. +*/ +void QCPTextElement::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/* inherits documentation from base class */ +void QCPTextElement::draw(QCPPainter *painter) +{ + painter->setFont(mainFont()); + painter->setPen(QPen(mainTextColor())); + painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); +} + +/* inherits documentation from base class */ +QSize QCPTextElement::minimumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +QSize QCPTextElement::maximumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.setWidth(QWIDGETSIZE_MAX); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPTextElement::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/*! + Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is + within the bounding box of the text element's text. Note that this bounding box is updated in the + draw call. + + If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text + element is not selectable (\ref setSelectable), returns -1. + + \seebaseclassmethod +*/ +double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + if (mTextBoundingRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/*! + Accepts the mouse event in order to emit the according click signal in the \ref + mouseReleaseEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->accept(); +} + +/*! + Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref + mousePressEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) + Q_EMIT clicked(event); +} + +/*! + Emits the \ref doubleClicked signal. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + Q_EMIT doubleClicked(event); +} + +/*! \internal + + Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to + true, else mFont is returned. +*/ +QFont QCPTextElement::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to + true, else mTextColor is returned. +*/ +QColor QCPTextElement::mainTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} +/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScale +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScale + \brief A color scale for use with color coding data such as QCPColorMap + + This layout element can be placed on the plot to correlate a color gradient with data values. It + is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". + + \image html QCPColorScale.png + + The color scale can be either horizontal or vertical, as shown in the image above. The + orientation and the side where the numbers appear is controlled with \ref setType. + + Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are + connected, they share their gradient, data range and data scale type (\ref setGradient, \ref + setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color + scale, to make them all synchronize these properties. + + To have finer control over the number display and axis behaviour, you can directly access the + \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if + you want to change the number of automatically generated ticks, call + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount + + Placing a color scale next to the main axis rect works like with any other layout element: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation + In this case we have placed it to the right of the default axis rect, so it wasn't necessary to + call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color + scale can be set with \ref setLabel. + + For optimum appearance (like in the image above), it may be desirable to line up the axis rect and + the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup + + Color scales are initialized with a non-zero minimum top and bottom margin (\ref + setMinimumMargins), because vertical color scales are most common and the minimum top/bottom + margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a + horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you + might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPAxis *QCPColorScale::axis() const + + Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the + appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its + interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref + setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref + QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on + the QCPColorScale or on its QCPAxis. + + If the type of the color scale is changed with \ref setType, the axis returned by this method + will change, too, to either the left, right, bottom or top axis, depending on which type was set. +*/ + +/* end documentation of signals */ +/* start documentation of signals */ + +/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); + + This signal is emitted when the data range changes. + + \see setDataRange +*/ + +/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the data scale type changes. + + \see setDataScaleType +*/ + +/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); + + This signal is emitted when the gradient changes. + + \see setGradient +*/ + +/* end documentation of signals */ + +/*! + Constructs a new QCPColorScale. +*/ +QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight + mDataScaleType(QCPAxis::stLinear), + mBarWidth(20), + mAxisRect(new QCPColorScaleAxisRectPrivate(this)) +{ + setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) + setType(QCPAxis::atRight); + setDataRange(QCPRange(0, 6)); +} + +QCPColorScale::~QCPColorScale() +{ + delete mAxisRect; +} + +/* undocumented getter */ +QString QCPColorScale::label() const +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return QString(); + } + + return mColorAxis.data()->label(); +} + +/* undocumented getter */ +bool QCPColorScale::rangeDrag() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/* undocumented getter */ +bool QCPColorScale::rangeZoom() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/*! + Sets at which side of the color scale the axis is placed, and thus also its orientation. + + Note that after setting \a type to a different value, the axis returned by \ref axis() will + be a different one. The new axis will adopt the following properties from the previous axis: The + range, scale type, label and ticker (the latter will be shared and not copied). +*/ +void QCPColorScale::setType(QCPAxis::AxisType type) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + if (mType != type) + { + mType = type; + QCPRange rangeTransfer(0, 6); + QString labelTransfer; + QSharedPointer tickerTransfer; + // transfer/revert some settings on old axis if it exists: + bool doTransfer = (bool)mColorAxis; + if (doTransfer) + { + rangeTransfer = mColorAxis.data()->range(); + labelTransfer = mColorAxis.data()->label(); + tickerTransfer = mColorAxis.data()->ticker(); + mColorAxis.data()->setLabel(QString()); + disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; + Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) + { + mAxisRect.data()->axis(atype)->setTicks(atype == mType); + mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); + } + // set new mColorAxis pointer: + mColorAxis = mAxisRect.data()->axis(mType); + // transfer settings to new axis: + if (doTransfer) + { + mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) + mColorAxis.data()->setLabel(labelTransfer); + mColorAxis.data()->setTicker(tickerTransfer); + } + connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); + } +} + +/*! + Sets the range spanned by the color gradient and that is shown by the axis in the color scale. + + It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its range with \ref + QCPAxis::setRange. + + \see setDataScaleType, setGradient, rescaleDataRange +*/ +void QCPColorScale::setDataRange(const QCPRange &dataRange) +{ + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + mDataRange = dataRange; + if (mColorAxis) + mColorAxis.data()->setRange(mDataRange); + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets the scale type of the color scale, i.e. whether values are linearly associated with colors + or logarithmically. + + It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its scale type with \ref + QCPAxis::setScaleType. + + \see setDataRange, setGradient +*/ +void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + if (mColorAxis) + mColorAxis.data()->setScaleType(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + Q_EMIT dataScaleTypeChanged(mDataScaleType); + } +} + +/*! + Sets the color gradient that will be used to represent data values. + + It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. + + \see setDataRange, setDataScaleType +*/ +void QCPColorScale::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + if (mAxisRect) + mAxisRect.data()->mGradientImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on + the internal \ref axis. +*/ +void QCPColorScale::setLabel(const QString &str) +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return; + } + + mColorAxis.data()->setLabel(str); +} + +/*! + Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed + will have. +*/ +void QCPColorScale::setBarWidth(int width) +{ + mBarWidth = width; +} + +/*! + Sets whether the user can drag the data range (\ref setDataRange). + + Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeDrag(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeDrag(0); +} + +/*! + Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. + + Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeZoom(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeZoom(0); +} + +/*! + Returns a list of all the color maps associated with this color scale. +*/ +QList QCPColorScale::colorMaps() const +{ + QList result; + for (int i=0; iplottableCount(); ++i) + { + if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) + if (cm->colorScale() == this) + result.append(cm); + } + return result; +} + +/*! + Changes the data range such that all color maps associated with this color scale are fully mapped + to the gradient in the data dimension. + + \see setDataRange +*/ +void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) +{ + QList maps = colorMaps(); + QCPRange newRange; + bool haveRange = false; + QCP::SignDomain sign = QCP::sdBoth; + if (mDataScaleType == QCPAxis::stLogarithmic) + sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + for (int i=0; irealVisibility() && onlyVisibleMaps) + continue; + QCPRange mapRange; + if (maps.at(i)->colorScale() == this) + { + bool currentFoundRange = true; + mapRange = maps.at(i)->data()->dataBounds(); + if (sign == QCP::sdPositive) + { + if (mapRange.lower <= 0 && mapRange.upper > 0) + mapRange.lower = mapRange.upper*1e-3; + else if (mapRange.lower <= 0 && mapRange.upper <= 0) + currentFoundRange = false; + } else if (sign == QCP::sdNegative) + { + if (mapRange.upper >= 0 && mapRange.lower < 0) + mapRange.upper = mapRange.lower*1e-3; + else if (mapRange.upper >= 0 && mapRange.lower >= 0) + currentFoundRange = false; + } + if (currentFoundRange) + { + if (!haveRange) + newRange = mapRange; + else + newRange.expand(mapRange); + haveRange = true; + } + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mDataScaleType == QCPAxis::stLinear) + { + newRange.lower = center-mDataRange.size()/2.0; + newRange.upper = center+mDataRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); + newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); + } + } + setDataRange(newRange); + } +} + +/* inherits documentation from base class */ +void QCPColorScale::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + mAxisRect.data()->update(phase); + + switch (phase) + { + case upMargins: + { + if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) + { + setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + } else + { + setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); + setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); + } + break; + } + case upLayout: + { + mAxisRect.data()->setOuterRect(rect()); + break; + } + default: break; + } +} + +/* inherits documentation from base class */ +void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mousePressEvent(event, details); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseMoveEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseReleaseEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::wheelEvent(QWheelEvent *event) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->wheelEvent(event); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScaleAxisRectPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScaleAxisRectPrivate + + \internal + \brief An axis rect subclass for use in a QCPColorScale + + This is a private class and not part of the public QCustomPlot interface. + + It provides the axis rect functionality for the QCPColorScale class. +*/ + + +/*! + Creates a new instance, as a child of \a parentColorScale. +*/ +QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : + QCPAxisRect(parentColorScale->parentPlot(), true), + mParentColorScale(parentColorScale), + mGradientImageInvalidated(true) +{ + setParentLayerable(parentColorScale); + setMinimumMargins(QMargins(0, 0, 0, 0)); + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + axis(type)->setVisible(true); + axis(type)->grid()->setVisible(false); + axis(type)->setPadding(0); + connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); + connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); + } + + connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); + + // make layer transfers of color scale transfer to axis rect and axes + // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); +} + +/*! \internal + + Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws + it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. + + \seebaseclassmethod +*/ +void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) +{ + if (mGradientImageInvalidated) + updateGradientImage(); + + bool mirrorHorz = false; + bool mirrorVert = false; + if (mParentColorScale->mColorAxis) + { + mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); + mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); + } + + painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); + QCPAxisRect::draw(painter); +} + +/*! \internal + + Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to + generate a gradient image. This gradient image will be used in the \ref draw method. +*/ +void QCPColorScaleAxisRectPrivate::updateGradientImage() +{ + if (rect().isEmpty()) + return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + int n = mParentColorScale->mGradient.levelCount(); + int w, h; + QVector data(n); + for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) + { + w = n; + h = rect().height(); + mGradientImage = QImage(w, h, format); + QVector pixels; + for (int y=0; y(mGradientImage.scanLine(y))); + mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); + for (int y=1; y(mGradientImage.scanLine(y)); + const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); + for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectedParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); + else + axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); + } + } +} + +/*! \internal + + This slot is connected to the selectableChanged signals of the four axes in the constructor. It + synchronizes the selectability of the axes. +*/ +void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) +{ + // synchronize axis base selectability: + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectableParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); + else + axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); + } + } +} +/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ + + +/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraphData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraphData + \brief Holds the data of one single data point for QCPGraph. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPGraphDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPGraphData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPGraphData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and value set to zero. +*/ +QCPGraphData::QCPGraphData() : + key(0), + value(0) +{ +} + +/*! + Constructs a data point with the specified \a key and \a value. +*/ +QCPGraphData::QCPGraphData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraph +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraph + \brief A plottable representing a graph in a plot. + + \image html QCPGraph.png + + Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be + accessed via QCustomPlot::graph. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPGraphDataContainer. + + Graphs are used to display single-valued data. Single-valued means that there should only be one + data point per unique key coordinate. In other words, the graph can't have \a loops. If you do + want to plot non-single-valued curves, rather use the QCPCurve plottable. + + Gaps in the graph line can be created by adding data points with NaN as value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpgraph-appearance Changing the appearance + + The appearance of the graph is mainly determined by the line style, scatter style, brush and pen + of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). + + \subsection filling Filling under or between graphs + + QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to + the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, + just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. + + By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill + between this graph and another one, call \ref setChannelFillGraph with the other graph as + parameter. + + \see QCustomPlot::addGraph, QCustomPlot::graph +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPGraph::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually + but use QCustomPlot::removePlottable() instead. + + To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. +*/ +QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // special handling for QCPGraphs to maintain the simple graph interface: + mParentPlot->registerGraph(this); + + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setLineStyle(lsLine); + setScatterSkip(0); + setChannelFillGraph(0); + setAdaptiveSampling(true); +} + +QCPGraph::~QCPGraph() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. + Modifying the data in the container will then affect all graphs that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the graph's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 + + \see addData +*/ +void QCPGraph::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to + \ref lsNone and \ref setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPGraph::setLineStyle(LineStyle ls) +{ + mLineStyle = ls; +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points + are drawn (e.g. for line-only-plots with appropriate line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPGraph::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPGraph::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets the target graph for filling the area between this graph and \a targetGraph with the current + brush (\ref setBrush). + + When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To + disable any filling, set the brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) +{ + // prevent setting channel target to this graph itself: + if (targetGraph == this) + { + qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; + mChannelFillGraph = 0; + return; + } + // prevent setting channel target to a graph not in the plot: + if (targetGraph && targetGraph->mParentPlot != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; + mChannelFillGraph = 0; + return; + } + + mChannelFillGraph = targetGraph; +} + +/*! + Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive + sampling technique can drastically improve the replot performance for graphs with a larger number + of points (e.g. above 10,000), without notably changing the appearance of the graph. + + By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive + sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no + disadvantage in almost all cases. + + \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" + + As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are + reproduced reliably, as well as the overall shape of the data set. The replot time reduces + dramatically though. This allows QCustomPlot to display large amounts of data in realtime. + + \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" + + Care must be taken when using high-density scatter plots in combination with adaptive sampling. + The adaptive sampling algorithm treats scatter plots more carefully than line plots which still + gives a significant reduction of replot times, but not quite as much as for line plots. This is + because scatter plots inherently need more data points to be preserved in order to still resemble + the original, non-adaptive-sampling plot. As shown above, the results still aren't quite + identical, as banding occurs for the outer data points. This is in fact intentional, such that + the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, + depends on the point density, i.e. the number of points in the plot. + + For some situations with scatter plots it might thus be desirable to manually turn adaptive + sampling off. For example, when saving the plot to disk. This can be achieved by setting \a + enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled + back to true afterwards. +*/ +void QCPGraph::setAdaptiveSampling(bool enabled) +{ + mAdaptiveSampling = enabled; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(double key, double value) +{ + mDataContainer->add(QCPGraphData(key, value)); +} + +/* inherits documentation from base class */ +double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPGraph::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + if (mLineStyle == lsNone && mScatterStyle.isNone()) return; + + QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + // get line pixel points appropriate to line style: + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) + getLines(&lines, lineDataRange); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPGraphDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } +#endif + + // draw fill of graph: + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + drawFill(painter, &lines); + + // draw line: + if (mLineStyle != lsNone) + { + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + painter->setBrush(Qt::NoBrush); + if (mLineStyle == lsImpulse) + drawImpulsePlot(painter, lines); + else + drawLinePlot(painter, lines); // also step plots can be drawn as a line plot + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i)); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches + out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. + according to the line style of the graph. + + \a lines will be filled with points in pixel coordinates, that can be drawn with the according + draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines + aren't necessarily the original data points. For example, step line styles require additional + points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a + lines vector will be empty. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. + + \see getScatters +*/ +void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const +{ + if (!lines) return; + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + lines->clear(); + return; + } + + QVector lineData; + if (mLineStyle != lsNone) + getOptimizedLineData(&lineData, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) + std::reverse(lineData.begin(), lineData.end()); + + switch (mLineStyle) + { + case lsNone: lines->clear(); break; + case lsLine: *lines = dataToLines(lineData); break; + case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; + case lsStepRight: *lines = dataToStepRightLines(lineData); break; + case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; + case lsImpulse: *lines = dataToImpulseLines(lineData); break; + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then + converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be + passed to \ref drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. +*/ +void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const +{ + if (!scatters) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } + + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + scatters->clear(); + return; + } + + QVector data; + getOptimizedScatterData(&data, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) + std::reverse(data.begin(), data.end()); + + scatters->resize(data.size()); + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } + } else + { + for (int i=0; icoordToPixel(data.at(i).key)); + (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + } +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsLine. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + result[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key)); + result[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepLeft. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepLeftLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(lastValue); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(key); + result[i*2+1].setY(lastValue); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepRight. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepRightLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(value); + result[i*2+0].setY(lastKey); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(value); + result[i*2+1].setY(lastKey); + } + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(lastKey); + result[i*2+0].setY(value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(lastKey); + result[i*2+1].setY(value); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepCenter. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepCenterLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastValue); + result[0].setY(lastKey); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(lastValue); + result[i*2-1].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + } + result[data.size()*2-1].setX(lastValue); + result[data.size()*2-1].setY(lastKey); + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastKey); + result[0].setY(lastValue); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(key); + result[i*2-1].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + } + result[data.size()*2-1].setX(lastKey); + result[data.size()*2-1].setY(lastValue); + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsImpulse. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot +*/ +QVector QCPGraph::dataToImpulseLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(valueAxis->coordToPixel(0)); + result[i*2+0].setY(key); + result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(valueAxis->coordToPixel(0)); + result[i*2+1].setX(key); + result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Draws the fill of the graph using the specified \a painter, with the currently set brush. + + Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref + getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. + + In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), + this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to + operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN + segments of the two involved graphs, before passing the overlapping pairs to \ref + getChannelFillPolygon. + + Pass the points of this graph's line as \a lines, in pixel coordinates. + + \see drawLinePlot, drawImpulsePlot, drawScatterPlot +*/ +void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const +{ + if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot + if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; + + applyFillAntialiasingHint(painter); + QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); + if (!mChannelFillGraph) + { + // draw base fill under graph, fill goes all the way to the zero-value-line: + for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); + } else + { + // draw fill between this graph and mChannelFillGraph: + QVector otherLines; + mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); + if (!otherLines.isEmpty()) + { + QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); + QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); + for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); + } + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawLinePlot, drawImpulsePlot +*/ +void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const +{ + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in + pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines + from the regular graph data points. + + \see drawLinePlot, drawScatterPlot +*/ +void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + QPen oldPen = painter->pen(); + QPen newPen = painter->pen(); + newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line + painter->setPen(newPen); + painter->drawLines(lines); + painter->setPen(oldPen); + } +} + +/*! \internal + + Returns via \a lineData the data points that need to be visualized for this graph when plotting + graph lines, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getLines to retrieve the basic working set of data. + + \see getOptimizedScatterData +*/ +void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const +{ + if (!lineData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (begin == end) return; + + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + QCPGraphDataContainer::const_iterator it = begin; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double lastIntervalEndKey = currentIntervalStartKey; + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary + { + if (it->value < minValue) + minValue = it->value; + else if (it->value > maxValue) + maxValue = it->value; + ++intervalDataCount; + } else // new pixel interval started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + lastIntervalEndKey = (it-1)->key; + minValue = it->value; + maxValue = it->value; + currentIntervalFirstPoint = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + ++it; + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + lineData->resize(dataCount); + std::copy(begin, end, lineData->begin()); + } +} + +/*! \internal + + Returns via \a scatterData the data points that need to be visualized for this graph when + plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getScatters to retrieve the basic working set of data. + + \see getOptimizedLineData +*/ +void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const +{ + if (!scatterData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int beginIndex = begin-mDataContainer->constBegin(); + int endIndex = end-mDataContainer->constBegin(); + while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++beginIndex; + ++begin; + } + if (begin == end) return; + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + double valueMaxRange = valueAxis->range().upper; + double valueMinRange = valueAxis->range().lower; + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator minValueIt = it; + QCPGraphDataContainer::const_iterator maxValueIt = it; + QCPGraphDataContainer::const_iterator currentIntervalStart = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + // main loop over data points: + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary + { + if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) + { + minValue = it->value; + minValueIt = it; + } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) + { + maxValue = it->value; + maxValueIt = it; + } + ++intervalDataCount; + } else // new pixel started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else + intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + minValue = it->value; + maxValue = it->value; + currentIntervalStart = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int intervalItIndex = intervalIt-mDataContainer->constBegin(); + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: + { + intervalItIndex += scatterModulo; + if (intervalItIndex < itIndex) + intervalIt += scatterModulo; + else + { + intervalIt = it; + intervalItIndex = itIndex; + } + } + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + scatterData->reserve(dataCount); + while (it != end) + { + scatterData->append(*it); + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + This method takes into account that the drawing of data lines at the axis rect border always + requires the points just outside the visible axis range. So \a begin and \a end may actually + indicate a range that contains one additional data point to the left and right of the visible + axis range. +*/ +void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + if (rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + } else + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + // get visible data range: + begin = mDataContainer->findBegin(keyAxis->range().lower); + end = mDataContainer->findEnd(keyAxis->range().upper); + // limit lower/upperEnd to rangeRestriction: + mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything + } +} + +/*! \internal + + This method goes through the passed points in \a lineData and returns a list of the segments + which don't contain NaN data points. + + \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check + for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c + Qt::Vertical, the \a x member is checked. + + \see getOverlappingSegments, drawFill +*/ +QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const +{ + QVector result; + const int n = lineData->size(); + + QCPDataRange currentSegment(-1, -1); + int i = 0; + + if (keyOrientation == Qt::Horizontal) + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } else // keyOrientation == Qt::Vertical + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } + return result; +} + +/*! \internal + + This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and + \a otherSegments, and their associated point data \a thisData and \a otherData. + + It returns all pairs of segments (the first from \a thisSegments, the second from \a + otherSegments), which overlap in plot coordinates. + + This method is useful in the case of a channel fill between two graphs, when only those non-NaN + segments which actually overlap in their key coordinate shall be considered for drawing a channel + fill polygon. + + It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and + that the segments don't overlap themselves. The same is assumed for the segments in \a + otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. + + \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon +*/ +QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const +{ + QVector > result; + if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) + return result; + + int thisIndex = 0; + int otherIndex = 0; + const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; + while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) + { + if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++thisIndex; + continue; + } + if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++otherIndex; + continue; + } + double thisLower, thisUpper, otherLower, otherUpper; + if (!verticalKey) + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); + } else + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); + } + + int bPrecedence; + if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) + result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); + + if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment + ++otherIndex; + else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment + ++thisIndex; + } + + return result; +} + +/*! \internal + + Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) + have overlap. + + The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the + \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher + coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if + both segment's upper bounds are identical, 0 is returned as \a bPrecedence. + + It is assumed that the lower bounds always have smaller or equal values than the upper bounds. + + \see getOverlappingSegments +*/ +bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const +{ + bPrecedence = 0; + if (aLower > bUpper) + { + bPrecedence = -1; + return false; + } else if (bLower > aUpper) + { + bPrecedence = 1; + return false; + } else + { + if (aUpper > bUpper) + bPrecedence = -1; + else if (aUpper < bUpper) + bPrecedence = 1; + + return true; + } +} + +/*! \internal + + Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. + The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates + is in positive or negative infinity. So this case is handled separately by just closing the fill + polygon on the axis which lies in the direction towards the zero value. + + \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether + the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or + y value of the returned point, respectively. +*/ +QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + QPointF result; + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + if (keyAxis->orientation() == Qt::Horizontal) + { + result.setX(matchingDataPoint.x()); + result.setY(valueAxis->coordToPixel(0)); + } else // keyAxis->orientation() == Qt::Vertical + { + result.setX(valueAxis->coordToPixel(0)); + result.setY(matchingDataPoint.y()); + } + } else // valueAxis->mScaleType == QCPAxis::stLogarithmic + { + // In logarithmic scaling we can't just draw to value 0 so we just fill all the way + // to the axis which is in the direction towards 0 + if (keyAxis->orientation() == Qt::Vertical) + { + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setX(keyAxis->axisRect()->right()); + else + result.setX(keyAxis->axisRect()->left()); + result.setY(matchingDataPoint.y()); + } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) + { + result.setX(matchingDataPoint.x()); + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setY(keyAxis->axisRect()->top()); + else + result.setY(keyAxis->axisRect()->bottom()); + } + } + return result; +} + +/*! \internal + + Returns the polygon needed for drawing normal fills between this graph and the key axis. + + Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment + which shall be used for the fill. The collection of \a lineData points described by \a segment + must not contain NaN data points (see \ref getNonNanSegments). + + The returned fill polygon will be closed at the key axis (the zero-value line) for linear value + axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect + side (see \ref getFillBasePoint). + + For increased performance (due to implicit sharing), keep the returned QPolygonF const. + + \see drawFill, getNonNanSegments +*/ +const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const +{ + if (segment.size() < 2) + return QPolygonF(); + QPolygonF result(segment.size()+2); + + result[0] = getFillBasePoint(lineData->at(segment.begin())); + std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); + result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); + + return result; +} + +/*! \internal + + Returns the polygon needed for drawing (partial) channel fills between this graph and the graph + specified by \ref setChannelFillGraph. + + The data points of this graph are passed as pixel coordinates via \a thisData, the data of the + other graph as \a otherData. The returned polygon will be calculated for the specified data + segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a + otherData, respectively. + + The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by + \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap + need to be processed here. + + For increased performance due to implicit sharing, keep the returned QPolygonF const. + + \see drawFill, getOverlappingSegments, getNonNanSegments +*/ +const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const +{ + if (!mChannelFillGraph) + return QPolygonF(); + + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } + if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } + + if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) + return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) + + if (thisData->isEmpty()) return QPolygonF(); + QVector thisSegmentData(thisSegment.size()); + QVector otherSegmentData(otherSegment.size()); + std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); + std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); + // pointers to be able to swap them, depending which data range needs cropping: + QVector *staticData = &thisSegmentData; + QVector *croppedData = &otherSegmentData; + + // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): + if (keyAxis->orientation() == Qt::Horizontal) + { + // x is key + // crop lower bound: + if (staticData->first().x() < croppedData->first().x()) // other one must be cropped + qSwap(staticData, croppedData); + const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) + slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); + else + slope = 0; + (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); + (*croppedData)[0].setX(staticData->first().x()); + + // crop upper bound: + if (staticData->last().x() > croppedData->last().x()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveX(croppedData, staticData->last().x()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + const int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) + slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); + else + slope = 0; + (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); + (*croppedData)[li].setX(staticData->last().x()); + } else // mKeyAxis->orientation() == Qt::Vertical + { + // y is key + // crop lower bound: + if (staticData->first().y() < croppedData->first().y()) // other one must be cropped + qSwap(staticData, croppedData); + int lowBound = findIndexBelowY(croppedData, staticData->first().y()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots + slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); + else + slope = 0; + (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); + (*croppedData)[0].setY(staticData->first().y()); + + // crop upper bound: + if (staticData->last().y() > croppedData->last().y()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveY(croppedData, staticData->last().y()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots + slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); + else + slope = 0; + (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); + (*croppedData)[li].setY(staticData->last().y()); + } + + // return joined: + for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted + thisSegmentData << otherSegmentData.at(i); + return QPolygonF(thisSegmentData); +} + +/*! \internal + + Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveX(const QVector *data, double x) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).x() < x) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexBelowX(const QVector *data, double x) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).x() > x) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} + +/*! \internal + + Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is vertical. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveY(const QVector *data, double y) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).y() < y) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Calculates the minimum distance in pixels the graph's representation has from the given \a + pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if + the graph has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the graph line is also taken into account. + + If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. +*/ +double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + // calculate minimum distances to graph data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); + QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); + for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + // line displayed, calculate distance to line segments: + QVector lineData; + getLines(&lineData, QCPDataRange(0, dataCount())); + QCPVector2D p(pixelPoint); + const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected + for (int i=0; i *data, double y) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).y() > y) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} +/* end of 'src/plottables/plottable-graph.cpp' */ + + +/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurveData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurveData + \brief Holds the data of one single data point for QCPCurve. + + The stored data is: + \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) + \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) + \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPCurveDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPCurveData::sortKey() const + + Returns the \a t member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). + All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() + + Since the member \a key is the data point key coordinate and the member \a t is the data ordering + parameter, this method returns false. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPCurveData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a curve data point with t, key and value set to zero. +*/ +QCPCurveData::QCPCurveData() : + t(0), + key(0), + value(0) +{ +} + +/*! + Constructs a curve data point with the specified \a t, \a key and \a value. +*/ +QCPCurveData::QCPCurveData(double t, double key, double value) : + t(t), + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurve + \brief A plottable representing a parametric curve in a plot. + + \image html QCPCurve.png + + Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, + so their visual representation can have \a loops. This is realized by introducing a third + coordinate \a t, which defines the order of the points described by the other two coordinates \a + x and \a y. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the curve's data via the \ref data method, which returns a pointer to the + internal \ref QCPCurveDataContainer. + + Gaps in the curve can be created by adding data points with NaN as key and value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpcurve-appearance Changing the appearance + + The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). + + \section qcpcurve-usage Usage + + Like all data representing objects in QCustomPlot, the QCPCurve is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPCurve::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // modify inherited properties from abstract plottable: + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setScatterStyle(QCPScatterStyle()); + setLineStyle(lsLine); + setScatterSkip(0); +} + +QCPCurve::~QCPCurve() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. + Modifying the data in the container will then affect all curves that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the curve's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 + + \see addData +*/ +void QCPCurve::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a t, \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a t in ascending order, you can + set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(t, keys, values, alreadySorted); +} + + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + \see addData +*/ +void QCPCurve::setData(const QVector &keys, const QVector &values) +{ + mDataContainer->clear(); + addData(keys, values); +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref + QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate + line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPCurve::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPCurve::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets how the single data points are connected in the plot or how they are represented visually + apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref + setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPCurve::setLineStyle(QCPCurve::LineStyle style) +{ + mLineStyle = style; +} + +/*! \overload + + Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (t.size() != keys.size() || t.size() != values.size()) + qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); + const int n = qMin(qMin(t.size(), keys.size()), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = t[i]; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &keys, const QVector &values) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + double tStart; + if (!mDataContainer->isEmpty()) + tStart = (mDataContainer->constEnd()-1)->t + 1.0; + else + tStart = 0; + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = tStart + i; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a t, \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double t, double key, double value) +{ + mDataContainer->add(QCPCurveData(t, key, value)); +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + The t parameter is generated automatically by increments of 1 for each point, starting at the + highest t of previously existing data or 0, if the curve data is empty. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double key, double value) +{ + if (!mDataContainer->isEmpty()) + mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); + else + mDataContainer->add(QCPCurveData(0.0, key, value)); +} + +/* inherits documentation from base class */ +double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPCurve::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + + // allocate line vector: + QVector lines, scatters; + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + + // fill with curve data: + QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width + if (isSelectedSegment && mSelectionDecorator) + finalCurvePen = mSelectionDecorator->pen(); + + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) + getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); + + // check data validity if flag set: + #ifdef QCUSTOMPLOT_CHECK_DATA + for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->t) || + QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } + #endif + + // draw curve fill: + applyFillAntialiasingHint(painter); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) + painter->drawPolygon(QPolygonF(lines)); + + // draw curve line: + if (mLineStyle != lsNone) + { + painter->setPen(finalCurvePen); + painter->setBrush(Qt::NoBrush); + drawCurveLine(painter, lines); + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + Draws lines between the points in \a lines, given in pixel coordinates. + + \see drawScatterPlot, getCurveLines +*/ +void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawCurveLine, getCurveLines +*/ +void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const +{ + // draw scatter point symbols: + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const +{ + if (!lines) return; + lines->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + // add margins to rect to compensate for stroke width + const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety + const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); + const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); + const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); + const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); + QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); + if (itBegin == itEnd) + return; + QCPCurveDataContainer::const_iterator it = itBegin; + QCPCurveDataContainer::const_iterator prevIt = itEnd-1; + int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); + QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) + while (it != itEnd) + { + const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); + if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R + { + if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal + { + QPointF crossA, crossB; + if (prevRegion == 5) // we're coming from R, so add this point optimized + { + lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); + // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } else if (mayTraverse(prevRegion, currentRegion) && + getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) + { + // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: + QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; + getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); + if (it != itBegin) + { + *lines << beforeTraverseCornerPoints; + lines->append(crossA); + lines->append(crossB); + *lines << afterTraverseCornerPoints; + } else + { + lines->append(crossB); + *lines << afterTraverseCornerPoints; + trailingPoints << beforeTraverseCornerPoints << crossA ; + } + } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) + { + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } + } else // segment does end in R, so we add previous point optimized and this point at original position + { + if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end + trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + else + lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); + lines->append(coordsToPixels(it->key, it->value)); + } + } else // region didn't change + { + if (currentRegion == 5) // still in R, keep adding original points + { + lines->append(coordsToPixels(it->key, it->value)); + } else // still outside R, no need to add anything + { + // see how this is not doing anything? That's the main optimization... + } + } + prevIt = it; + prevRegion = currentRegion; + ++it; + } + *lines << trailingPoints; +} + +/*! \internal + + Called by \ref draw to generate points in pixel coordinates which represent the scatters of the + curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly + sparser. + + Scatters that aren't visible in the current axis rect are optimized away. + + \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref + drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. + + \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel + coordinates generated by this function. This is needed here to calculate an accordingly wider + margin around the axis rect when performing the data point reduction. + + \see draw, drawScatterPlot +*/ +void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const +{ + if (!scatters) return; + scatters->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); + if (begin == end) + return; + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int endIndex = end-mDataContainer->constBegin(); + + QCPRange keyRange = keyAxis->range(); + QCPRange valueRange = valueAxis->range(); + // extend range to include width of scatter symbols: + keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); + keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); + valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); + valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); + + QCPCurveDataContainer::const_iterator it = begin; + int itIndex = begin-mDataContainer->constBegin(); + while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++itIndex; + ++it; + } + if (keyAxis->orientation() == Qt::Vertical) + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } else + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + It returns the region of the given point (\a key, \a value) with respect to a rectangle defined + by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. + + The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a + keyMin to \a keyMax): + + + + + +
147
258
369
+ + With the rectangle being region 5, and the outer regions extending infinitely outwards. In the + curve optimization algorithm, region 5 is considered to be the visible portion of the plot. +*/ +int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + if (key < keyMin) // region 123 + { + if (value > valueMax) + return 1; + else if (value < valueMin) + return 3; + else + return 2; + } else if (key > keyMax) // region 789 + { + if (value > valueMax) + return 7; + else if (value < valueMin) + return 9; + else + return 8; + } else // region 456 + { + if (value > valueMax) + return 4; + else if (value < valueMin) + return 6; + else + return 5; + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method is used in case the current segment passes from inside the visible rect (region 5, + see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by + the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). + + It returns the intersection point of the segment with the border of region 5. + + For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or + whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or + leaving it. It is important though that \a otherRegion correctly identifies the other region not + equal to 5. +*/ +QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double otherValuePx = mValueAxis->coordToPixel(otherValue); + const double valuePx = mValueAxis->coordToPixel(value); + const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); + const double keyPx = mKeyAxis->coordToPixel(key); + double intersectKeyPx = keyMinPx; // initial key just a fail-safe + double intersectValuePx = valueMinPx; // initial value just a fail-safe + switch (otherRegion) + { + case 1: // top and left edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 2: // left edge + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 3: // bottom and left edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 4: // top edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 5: + { + break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table + } + case 6: // bottom edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 7: // top and right edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 8: // right edge + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 9: // bottom and right edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + } + if (mKeyAxis->orientation() == Qt::Horizontal) + return QPointF(intersectKeyPx, intersectValuePx); + else + return QPointF(intersectValuePx, intersectKeyPx); +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + In situations where a single segment skips over multiple regions it might become necessary to add + extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment + doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. + This method provides these points that must be added, assuming the original segment doesn't + start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by + \ref getTraverseCornerPoints.) + + For example, consider a segment which directly goes from region 4 to 2 but originally is far out + to the top left such that it doesn't cross region 5. Naively optimizing these points by + projecting them on the top and left borders of region 5 will create a segment that surely crosses + 5, creating a visual artifact in the plot. This method prevents this by providing extra points at + the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without + traversing 5. +*/ +QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + QVector result; + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMax); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } + case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + else + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + break; + } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMin); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); break; } + case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + else + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + break; + } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 6: + { + switch (currentRegion) + { + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 4: { result << coordsToPixels(keyMax, valueMax); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); break; } + case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + else + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + break; + } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 6: { result << coordsToPixels(keyMax, valueMin); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + else + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + break; + } + } + break; + } + } + return result; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref + getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion + nor \a currentRegion is 5 itself. + + If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the + segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref + getTraverse). +*/ +bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 4: + case 7: + case 2: + case 3: return false; + default: return true; + } + } + case 2: + { + switch (currentRegion) + { + case 1: + case 3: return false; + default: return true; + } + } + case 3: + { + switch (currentRegion) + { + case 1: + case 2: + case 6: + case 9: return false; + default: return true; + } + } + case 4: + { + switch (currentRegion) + { + case 1: + case 7: return false; + default: return true; + } + } + case 5: return false; // should never occur + case 6: + { + switch (currentRegion) + { + case 3: + case 9: return false; + default: return true; + } + } + case 7: + { + switch (currentRegion) + { + case 1: + case 4: + case 8: + case 9: return false; + default: return true; + } + } + case 8: + { + switch (currentRegion) + { + case 7: + case 9: return false; + default: return true; + } + } + case 9: + { + switch (currentRegion) + { + case 3: + case 6: + case 8: + case 7: return false; + default: return true; + } + } + default: return true; + } +} + + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref mayTraverse test has returned true, so there is a chance the + segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible + region 5. + + The return value of this method indicates whether the segment actually traverses region 5 or not. + + If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and + exit points of region 5. They will become the optimized points for that segment. +*/ +bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + QList intersections; + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double keyPx = mKeyAxis->coordToPixel(key); + const double valuePx = mValueAxis->coordToPixel(value); + const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); + const double prevValuePx = mValueAxis->coordToPixel(prevValue); + if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); + } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); + } else // line is skewed + { + double gamma; + double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); + // check top of rect: + gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); + // check bottom of rect: + gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); + const double valuePerKeyPx = 1.0/keyPerValuePx; + // check left of rect: + gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); + // check right of rect: + gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); + } + + // handle cases where found points isn't exactly 2: + if (intersections.size() > 2) + { + // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: + double distSqrMax = 0; + QPointF pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = intersections.at(i); + pv2 = intersections.at(k); + distSqrMax = distSqr; + } + } + } + intersections = QList() << pv1 << pv2; + } else if (intersections.size() != 2) + { + // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment + return false; + } + + // possibly re-sort points so optimized point segment has same direction as original segment: + double xDelta = keyPx-prevKeyPx; + double yDelta = valuePx-prevValuePx; + if (mKeyAxis->orientation() != Qt::Horizontal) + qSwap(xDelta, yDelta); + if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction + intersections.move(0, 1); + crossA = intersections.at(0); + crossB = intersections.at(1); + return true; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref getTraverse test has returned true, so the segment definitely + traverses the visible region 5 when going from \a prevRegion to \a currentRegion. + + In certain situations it is not sufficient to merely generate the entry and exit points of the + segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in + addition to traversing region 5, skips another region outside of region 5, which makes it + necessary to add an optimized corner point there (very similar to the job \ref + getOptimizedCornerPoints does for segments that are completely in outside regions and don't + traverse 5). + + As an example, consider a segment going from region 1 to region 6, traversing the lower left + corner of region 5. In this configuration, the segment additionally crosses the border between + region 1 and 2 before entering region 5. This makes it necessary to add an additional point in + the top left corner, before adding the optimized traverse points. So in this case, the output + parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be + empty. + + In some cases, such as when going from region 1 to 9, it may even be necessary to add additional + corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse + return the respective corner points. +*/ +void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: { break; } // shouldn't happen because this method only handles full traverses + case 6: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + } +} + +/*! \internal + + Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a + pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in + \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that + if the curve has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the curve line is also taken into account. + + If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns + -1.0. +*/ +double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + if (mDataContainer->size() == 1) + { + QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); + closestData = mDataContainer->constBegin(); + return QCPVector2D(dataPoint-pixelPoint).length(); + } + + // calculate minimum distances to curve data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + QVector lines; + getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width + for (int i=0; i QCPBarsGroup::bars() const + + Returns all bars currently in this group. + + \see bars(int index) +*/ + +/*! \fn int QCPBarsGroup::size() const + + Returns the number of QCPBars plottables that are part of this group. + +*/ + +/*! \fn bool QCPBarsGroup::isEmpty() const + + Returns whether this bars group is empty. + + \see size +*/ + +/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) + + Returns whether the specified \a bars plottable is part of this group. + +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new bars group for the specified QCustomPlot instance. +*/ +QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot), + mSpacingType(stAbsolute), + mSpacing(4) +{ +} + +QCPBarsGroup::~QCPBarsGroup() +{ + clear(); +} + +/*! + Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. + + The actual spacing can then be specified with \ref setSpacing. + + \see setSpacing +*/ +void QCPBarsGroup::setSpacingType(SpacingType spacingType) +{ + mSpacingType = spacingType; +} + +/*! + Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is + defined by the current \ref SpacingType, which can be set with \ref setSpacingType. + + \see setSpacingType +*/ +void QCPBarsGroup::setSpacing(double spacing) +{ + mSpacing = spacing; +} + +/*! + Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars + exists, returns 0. + + \see bars(), size +*/ +QCPBars *QCPBarsGroup::bars(int index) const +{ + if (index >= 0 && index < mBars.size()) + { + return mBars.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Removes all QCPBars plottables from this group. + + \see isEmpty +*/ +void QCPBarsGroup::clear() +{ + Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay + bars->setBarsGroup(0); // removes itself via removeBars +} + +/*! + Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref + QCPBars::setBarsGroup on the \a bars instance. + + \see insert, remove +*/ +void QCPBarsGroup::append(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + else + qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); +} + +/*! + Inserts the specified \a bars plottable into this group at the specified index position \a i. + This gives you full control over the ordering of the bars. + + \a bars may already be part of this group. In that case, \a bars is just moved to the new index + position. + + \see append, remove +*/ +void QCPBarsGroup::insert(int i, QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + // first append to bars list normally: + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + // then move to according position: + mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); +} + +/*! + Removes the specified \a bars plottable from this group. + + \see contains, clear +*/ +void QCPBarsGroup::remove(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (mBars.contains(bars)) + bars->setBarsGroup(0); + else + qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); +} + +/*! \internal + + Adds the specified \a bars to the internal mBars list of bars. This method does not change the + barsGroup property on \a bars. + + \see unregisterBars +*/ +void QCPBarsGroup::registerBars(QCPBars *bars) +{ + if (!mBars.contains(bars)) + mBars.append(bars); +} + +/*! \internal + + Removes the specified \a bars from the internal mBars list of bars. This method does not change + the barsGroup property on \a bars. + + \see registerBars +*/ +void QCPBarsGroup::unregisterBars(QCPBars *bars) +{ + mBars.removeOne(bars); +} + +/*! \internal + + Returns the pixel offset in the key dimension the specified \a bars plottable should have at the + given key coordinate \a keyCoord. The offset is relative to the pixel position of the key + coordinate \a keyCoord. +*/ +double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) +{ + // find list of all base bars in case some mBars are stacked: + QList baseBars; + Q_FOREACH (const QCPBars *b, mBars) + { + while (b->barBelow()) + b = b->barBelow(); + if (!baseBars.contains(b)) + baseBars.append(b); + } + // find base bar this "bars" is stacked on: + const QCPBars *thisBase = bars; + while (thisBase->barBelow()) + thisBase = thisBase->barBelow(); + + // determine key pixel offset of this base bars considering all other base bars in this barsgroup: + double result = 0; + int index = baseBars.indexOf(thisBase); + if (index >= 0) + { + if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) + { + return result; + } else + { + double lowerPixelWidth, upperPixelWidth; + int startIndex; + int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative + if (baseBars.size() % 2 == 0) // even number of bars + { + startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); + result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing + } else // uneven number of bars + { + startIndex = (baseBars.size()-1)/2+dir; + baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar + result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing + } + for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars + { + baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth); + result += getPixelSpacing(baseBars.at(i), keyCoord); + } + // finally half of our bars width: + baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; + // correct sign of result depending on orientation and direction of key axis: + result *= dir*thisBase->keyAxis()->pixelOrientation(); + } + } + return result; +} + +/*! \internal + + Returns the spacing in pixels which is between this \a bars and the following one, both at the + key coordinate \a keyCoord. + + \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only + needed to get access to the key axis transformation and axis rect for the modes \ref + stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in + \ref stPlotCoords on a logarithmic axis. +*/ +double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) +{ + switch (mSpacingType) + { + case stAbsolute: + { + return mSpacing; + } + case stAxisRectRatio: + { + if (bars->keyAxis()->orientation() == Qt::Horizontal) + return bars->keyAxis()->axisRect()->width()*mSpacing; + else + return bars->keyAxis()->axisRect()->height()*mSpacing; + } + case stPlotCoords: + { + double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); + return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); + } + } + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBarsData + \brief Holds the data of one single data point (one bar) for QCPBars. + + The stored data is: + \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) + \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPBarsDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPBarsData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPBarsData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a bar data point with key and value set to zero. +*/ +QCPBarsData::QCPBarsData() : + key(0), + value(0) +{ +} + +/*! + Constructs a bar data point with the specified \a key and \a value. +*/ +QCPBarsData::QCPBarsData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBars + \brief A plottable representing a bar chart in a plot. + + \image html QCPBars.png + + To plot data, assign it with the \ref setData or \ref addData functions. + + \section qcpbars-appearance Changing the appearance + + The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). + The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. + + Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other + (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear + stacked. + + If you would like to group multiple QCPBars plottables together so they appear side by side as + shown below, use QCPBarsGroup. + + \image html QCPBarsGroup.png + + \section qcpbars-usage Usage + + Like all data representing objects in QCustomPlot, the QCPBars is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/*! \fn QCPBars *QCPBars::barBelow() const + Returns the bars plottable that is directly below this bars plottable. + If there is no such plottable, returns 0. + + \see barAbove, moveBelow, moveAbove +*/ + +/*! \fn QCPBars *QCPBars::barAbove() const + Returns the bars plottable that is directly above this bars plottable. + If there is no such plottable, returns 0. + + \see barBelow, moveBelow, moveAbove +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.75), + mWidthType(wtPlotCoords), + mBarsGroup(0), + mBaseValue(0), + mStackingGap(0) +{ + // modify inherited properties from abstract plottable: + mPen.setColor(Qt::blue); + mPen.setStyle(Qt::SolidLine); + mBrush.setColor(QColor(40, 50, 255, 30)); + mBrush.setStyle(Qt::SolidPattern); + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPBars::~QCPBars() +{ + setBarsGroup(0); + if (mBarBelow || mBarAbove) + connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. + Modifying the data in the container will then affect all bars that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the bar's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 + + \see addData +*/ +void QCPBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets the width of the bars. + + How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), + depends on the currently set width type, see \ref setWidthType and \ref WidthType. +*/ +void QCPBars::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the bars is defined. See the documentation of \ref WidthType for an + explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPBars::setWidthType(QCPBars::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref + QCPBarsGroup::append. + + To remove this QCPBars from any group, set \a barsGroup to 0. +*/ +void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) +{ + // deregister at old group: + if (mBarsGroup) + mBarsGroup->unregisterBars(this); + mBarsGroup = barsGroup; + // register at new group: + if (mBarsGroup) + mBarsGroup->registerBars(this); +} + +/*! + Sets the base value of this bars plottable. + + The base value defines where on the value coordinate the bars start. How far the bars extend from + the base value is given by their individual value data. For example, if the base value is set to + 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at + 3. + + For stacked bars, only the base value of the bottom-most QCPBars has meaning. + + The default base value is 0. +*/ +void QCPBars::setBaseValue(double baseValue) +{ + mBaseValue = baseValue; +} + +/*! + If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method + allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by + the bars below it. +*/ +void QCPBars::setStackingGap(double pixels) +{ + mStackingGap = pixels; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(double key, double value) +{ + mDataContainer->add(QCPBarsData(key, value)); +} + +/*! + Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear + below the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object below itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barAbove, barBelow +*/ +void QCPBars::moveBelow(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar below it: + if (bars) + { + if (bars->mBarBelow) + connectBars(bars->mBarBelow.data(), this); + connectBars(this, bars); + } +} + +/*! + Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear + above the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object above itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barBelow, barAbove +*/ +void QCPBars::moveAbove(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar above it: + if (bars) + { + if (bars->mBarAbove) + connectBars(this, bars->mBarAbove.data()); + connectBars(bars, this); + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getBarRect(it->key, it->value))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getBarRect(it->key, it->value).contains(pos)) + { + if (details) + { + int pointIndex = it-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return mParentPlot->selectionTolerance()*0.99; + } + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in + absolute pixels), using this method to adapt the key axis range to fit the bars into the + currently visible axis range will not work perfectly. Because in the moment the axis range is + changed to the new range, the fixed pixel widths/spacings will represent different coordinate + spans than before, which in turn would require a different key range to perfectly fit, and so on. + The only solution would be to iteratively approach the perfect fitting axis range, but the + mismatch isn't large enough in most applications, to warrant this here. If a user does need a + better fit, he should call the corresponding axis rescale multiple times in a row. + */ + QCPRange range; + range = mDataContainer->keyRange(foundRange, inSignDomain); + + // determine exact range of bars by including bar width and barsgroup offset: + if (foundRange && mKeyAxis) + { + double lowerPixelWidth, upperPixelWidth, keyPixel; + // lower range bound: + getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); + const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) + range.lower = lowerCorrected; + // upper range bound: + getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); + const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) + range.upper = upperCorrected; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + // Note: can't simply use mDataContainer->valueRange here because we need to + // take into account bar base value and possible stacking of multiple bars + QCPRange range; + range.lower = mBaseValue; + range.upper = mBaseValue; + bool haveLower = true; // set to true, because baseValue should always be visible in bar charts + bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts + QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (inKeyRange != QCPRange()) + { + itBegin = mDataContainer->findBegin(inKeyRange.lower); + itEnd = mDataContainer->findEnd(inKeyRange.upper); + } + for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + + foundRange = true; // return true because bar charts always have the 0-line visible + return range; +} + +/* inherits documentation from base class */ +QPointF QCPBars::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); + const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyPixel, valuePixel); + else + return QPointF(valuePixel, keyPixel); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/* inherits documentation from base class */ +void QCPBars::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mDataContainer->isEmpty()) return; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPBarsDataContainer::const_iterator begin = visibleBegin; + QCPBarsDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +#endif + // draw bar: + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyBrush(painter); + mSelectionDecorator->applyPen(painter); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + } + applyDefaultAntialiasingHint(painter); + painter->drawPolygon(getBarRect(it->key, it->value)); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setBrush(mBrush); + painter->setPen(mPen); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + if (mDataContainer->isEmpty()) + { + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + + // get visible data range as QMap iterators + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); + double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); + double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); + bool isVisible = false; + // walk left from begin to find lower bar that actually is completely outside visible pixel range: + QCPBarsDataContainer::const_iterator it = begin; + while (it != mDataContainer->constBegin()) + { + --it; + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); + if (isVisible) + begin = it; + else + break; + } + // walk right from ubound to find upper bar that actually is completely outside visible pixel range: + it = end; + while (it != mDataContainer->constEnd()) + { + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); + if (isVisible) + end = it+1; + else + break; + ++it; + } +} + +/*! \internal + + Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The + rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref + setBaseValue), and to have non-overlapping border lines with the bars stacked below. +*/ +QRectF QCPBars::getBarRect(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double lowerPixelWidth, upperPixelWidth; + getPixelWidth(key, lowerPixelWidth, upperPixelWidth); + double base = getStackedBaseValue(key, value >= 0); + double basePixel = valueAxis->coordToPixel(base); + double valuePixel = valueAxis->coordToPixel(base+value); + double keyPixel = keyAxis->coordToPixel(key); + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, key); + double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); + bottomOffset += mBarBelow ? mStackingGap : 0; + bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); + if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) + bottomOffset = valuePixel-basePixel; + if (keyAxis->orientation() == Qt::Horizontal) + { + return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); + } else + { + return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). + + The output parameters \a lower and \a upper return the number of pixels the bar extends to lower + and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a + lower is negative and \a upper positive). +*/ +void QCPBars::getPixelWidth(double key, double &lower, double &upper) const +{ + lower = 0; + upper = 0; + switch (mWidthType) + { + case wtAbsolute: + { + upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + { + double keyPixel = mKeyAxis.data()->coordToPixel(key); + upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; + // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by + // coordinate transform which includes range direction + } else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } +} + +/*! \internal + + This function is called to find at which value to start drawing the base of a bar at \a key, when + it is stacked on top of another QCPBars (e.g. with \ref moveAbove). + + positive and negative bars are separated per stack (positive are stacked above baseValue upwards, + negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the + bar for which we need the base value is negative, set \a positive to false. +*/ +double QCPBars::getStackedBaseValue(double key, bool positive) const +{ + if (mBarBelow) + { + double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack + // find bars of mBarBelow that are approximately at key and find largest one: + double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point + if (key == 0) + epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); + QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); + QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); + while (it != itEnd) + { + if (it->key > key-epsilon && it->key < key+epsilon) + { + if ((positive && it->value > max) || + (!positive && it->value < max)) + max = it->value; + } + ++it; + } + // recurse down the bar-stack to find the total height: + return max + mBarBelow.data()->getStackedBaseValue(key, positive); + } else + return mBaseValue; +} + +/*! \internal + + Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) + currently above lower and below upper will become disconnected to lower/upper. + + If lower is zero, upper will be disconnected at the bottom. + If upper is zero, lower will be disconnected at the top. +*/ +void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) +{ + if (!lower && !upper) return; + + if (!lower) // disconnect upper at bottom + { + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + upper->mBarBelow = 0; + } else if (!upper) // disconnect lower at top + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + lower->mBarAbove = 0; + } else // connect lower and upper + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + lower->mBarAbove = upper; + upper->mBarBelow = lower; + } +} +/* end of 'src/plottables/plottable-bars.cpp' */ + + +/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBoxData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBoxData + \brief Holds the data of one single data point for QCPStatisticalBox. + + The stored data is: + + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + + \li \a minimum: the position of the lower whisker, typically the minimum measurement of the + sample that's not considered an outlier. + + \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a median: the value of the median mark inside the quartile box. The median separates the + sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) + + \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a maximum: the position of the upper whisker, typically the maximum measurement of the + sample that's not considered an outlier. + + \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key + coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) + + The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a + typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template + parameter. See the documentation there for an explanation regarding the data type's generic + methods. + + \see QCPStatisticalBoxDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPStatisticalBoxData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainValue() const + + Returns the \a median member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const + + Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box + data point, possibly further expanded by outliers. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData() : + key(0), + minimum(0), + lowerQuartile(0), + median(0), + upperQuartile(0), + maximum(0) +{ +} + +/*! + Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a + upperQuartile, \a maximum and optionally a number of \a outliers. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : + key(key), + minimum(minimum), + lowerQuartile(lowerQuartile), + median(median), + upperQuartile(upperQuartile), + maximum(maximum), + outliers(outliers) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBox +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBox + \brief A plottable representing a single statistical box in a plot. + + \image html QCPStatisticalBox.png + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPStatisticalBoxDataContainer. + + Additionally each data point can itself have a list of outliers, drawn as scatter points at the + key coordinate of the respective statistical box data point. They can either be set by using the + respective \ref addData(double,double,double,double,double,double,const QVector&) + "addData" method or accessing the individual data points through \ref data, and setting the + QVector outliers of the data points directly. + + \section qcpstatisticalbox-appearance Changing the appearance + + The appearance of each data point box, ranging from the lower to the upper quartile, is + controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref + setWidth in plot coordinates. + + Each data point's visual representation also consists of two whiskers. Whiskers are the lines + which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. + The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, + \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at + the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set + the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a + few pixels due to the pen cap being not perfectly flat. + + The median indicator line inside the box has its own pen, \ref setMedianPen. + + The outlier data points are drawn as normal scatter points. Their look can be controlled with + \ref setOutlierStyle + + \section qcpstatisticalbox-usage Usage + + Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 +*/ + +/* start documentation of inline functions */ + +/*! \fn QSharedPointer QCPStatisticalBox::data() const + + Returns a shared pointer to the internal data storage of type \ref + QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more + convenient and faster than using the regular \ref setData or \ref addData methods. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its + value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and + not have the same orientation. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not + delete it manually but use QCustomPlot::removePlottable() instead. +*/ +QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.5), + mWhiskerWidth(0.2), + mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), + mWhiskerBarPen(Qt::black), + mWhiskerAntialiased(false), + mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), + mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) +{ + setPen(QPen(Qt::black)); + setBrush(Qt::NoBrush); +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container + safely. Modifying the data in the container will then affect all statistical boxes that share the + container. Sharing can be achieved by simply exchanging the data containers wrapped in shared + pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the statistical box data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 + + \see addData +*/ +void QCPStatisticalBox::setData(QSharedPointer data) +{ + mDataContainer = data; +} +/*! \overload + + Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a + median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the + number of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); +} + +/*! + Sets the width of the boxes in key coordinates. + + \see setWhiskerWidth +*/ +void QCPStatisticalBox::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the width of the whiskers in key coordinates. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWidth +*/ +void QCPStatisticalBox::setWhiskerWidth(double width) +{ + mWhiskerWidth = width; +} + +/*! + Sets the pen used for drawing the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone + line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. + + \see setWhiskerBarPen +*/ +void QCPStatisticalBox::setWhiskerPen(const QPen &pen) +{ + mWhiskerPen = pen; +} + +/*! + Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at + each end of the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWhiskerPen +*/ +void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) +{ + mWhiskerBarPen = pen; +} + +/*! + Sets whether the statistical boxes whiskers are drawn with antialiasing or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) +{ + mWhiskerAntialiased = enabled; +} + +/*! + Sets the pen used for drawing the median indicator line inside the statistical boxes. +*/ +void QCPStatisticalBox::setMedianPen(const QPen &pen) +{ + mMedianPen = pen; +} + +/*! + Sets the appearance of the outlier data points. + + Outliers can be specified with the method + \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +*/ +void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) +{ + mOutlierStyle = style; +} + +/*! \overload + + Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and + \a maximum to the current data. The provided vectors should have equal length. Else, the number + of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || + median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" + << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); + const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->minimum = minimum[i]; + it->lowerQuartile = lowerQuartile[i]; + it->median = median[i]; + it->upperQuartile = upperQuartile[i]; + it->maximum = maximum[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile + and \a maximum to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +{ + mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getQuartileBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + double minDistSqr = std::numeric_limits::max(); + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getQuartileBox(it).contains(pos)) // quartile box + { + double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } else // whiskers + { + const QVector whiskerBackbones(getWhiskerBackboneLines(it)); + for (int i=0; iconstBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return qSqrt(minDistSqr); + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; + QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +# ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->minimum) || + QCP::isInvalidData(it->lowerQuartile, it->median) || + QCP::isInvalidData(it->upperQuartile, it->maximum)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); + for (int i=0; ioutliers.size(); ++i) + if (QCP::isInvalidData(it->outliers.at(i))) + qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +# endif + + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + QCPScatterStyle finalOutlierStyle = mOutlierStyle; + if (isSelectedSegment && mSelectionDecorator) + finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); + drawStatisticalBox(painter, it, finalOutlierStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->setBrush(mBrush); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! + Draws the graphical representation of a single statistical box with the data given by the + iterator \a it with the provided \a painter. + + If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. + + \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const +{ + // draw quartile box: + applyDefaultAntialiasingHint(painter); + const QRectF quartileBox = getQuartileBox(it); + painter->drawRect(quartileBox); + // draw median line with cliprect set to quartile box: + painter->save(); + painter->setClipRect(quartileBox, Qt::IntersectClip); + painter->setPen(mMedianPen); + painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); + painter->restore(); + // draw whisker lines: + applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); + painter->setPen(mWhiskerPen); + painter->drawLines(getWhiskerBackboneLines(it)); + painter->setPen(mWhiskerBarPen); + painter->drawLines(getWhiskerBarLines(it)); + // draw outliers: + applyScattersAntialiasingHint(painter); + outlierStyle.applyTo(painter, mPen); + for (int i=0; ioutliers.size(); ++i) + outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points +} + +/*! \internal + + Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the + value range from the lower to the upper quartile, of the data given by \a it. + + \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QRectF result; + result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); + result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); + return result; +} + +/*! \internal + + Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value + range from the minimum to the lower quartile, and from the upper quartile to the maximum of the + data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines +*/ +QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone + result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone + return result; +} + +/*! \internal + + Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the + end of the whisker backbones, at the minimum and maximum of the data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines +*/ +QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar + result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar + return result; +} +/* end of 'src/plottables/plottable-statisticalbox.cpp' */ + + +/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorMapData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorMapData + \brief Holds the two-dimensional data of a QCPColorMap plottable. + + This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref + QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a + color, depending on the value. + + The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). + Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref + setKeyRange, \ref setValueRange). + + The data cells can be accessed in two ways: They can be directly addressed by an integer index + with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot + coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are + provided by the functions \ref coordToCell and \ref cellToCoord. + + A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if + allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref + fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on + the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. + + This class also buffers the minimum and maximum values that are in the data set, to provide + QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value + that is greater than the current maximum increases this maximum to the new value. However, + setting the cell that currently holds the maximum value to a smaller value doesn't decrease the + maximum again, because finding the true new maximum would require going through the entire data + array, which might be time consuming. The same holds for the data minimum. This functionality is + given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the + true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience + parameter \a recalculateDataBounds which may be set to true to automatically call \ref + recalculateDataBounds internally. +*/ + +/* start of documentation of inline functions */ + +/*! \fn bool QCPColorMapData::isEmpty() const + + Returns whether this instance carries no data. This is equivalent to having a size where at least + one of the dimensions is 0 (see \ref setSize). +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction + and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap + at the coordinates \a keyRange and \a valueRange. + + \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange +*/ +QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : + mKeySize(0), + mValueSize(0), + mKeyRange(keyRange), + mValueRange(valueRange), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + setSize(keySize, valueSize); + fill(0); +} + +QCPColorMapData::~QCPColorMapData() +{ + if (mData) + delete[] mData; + if (mAlpha) + delete[] mAlpha; +} + +/*! + Constructs a new QCPColorMapData instance copying the data and range of \a other. +*/ +QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : + mKeySize(0), + mValueSize(0), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + *this = other; +} + +/*! + Overwrites this color map data instance with the data stored in \a other. The alpha map state is + transferred, too. +*/ +QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) +{ + if (&other != this) + { + const int keySize = other.keySize(); + const int valueSize = other.valueSize(); + if (!other.mAlpha && mAlpha) + clearAlpha(); + setSize(keySize, valueSize); + if (other.mAlpha && !mAlpha) + createAlpha(false); + setRange(other.keyRange(), other.valueRange()); + if (!isEmpty()) + { + memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); + if (mAlpha) + memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); + } + mDataBounds = other.mDataBounds; + mDataModified = true; + } + return *this; +} + +/* undocumented getter */ +double QCPColorMapData::data(double key, double value) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + return mData[valueCell*mKeySize + keyCell]; + else + return 0; +} + +/* undocumented getter */ +double QCPColorMapData::cell(int keyIndex, int valueIndex) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mData[valueIndex*mKeySize + keyIndex]; + else + return 0; +} + +/*! + Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. + + If this color map data doesn't have an alpha map (because \ref setAlpha was never called after + creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. + + \see setAlpha +*/ +unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) +{ + if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mAlpha[valueIndex*mKeySize + keyIndex]; + else + return 255; +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in + the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref + isEmpty returns true. + + \see setRange, setKeySize, setValueSize +*/ +void QCPColorMapData::setSize(int keySize, int valueSize) +{ + if (keySize != mKeySize || valueSize != mValueSize) + { + mKeySize = keySize; + mValueSize = valueSize; + if (mData) + delete[] mData; + mIsEmpty = mKeySize == 0 || mValueSize == 0; + if (!mIsEmpty) + { +#ifdef __EXCEPTIONS + try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message +#endif + mData = new double[mKeySize*mValueSize]; +#ifdef __EXCEPTIONS + } catch (...) { mData = 0; } +#endif + if (mData) + fill(0); + else + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; + } else + mData = 0; + + if (mAlpha) // if we had an alpha map, recreate it with new size + createAlpha(); + + mDataModified = true; + } +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. + + \see setKeyRange, setSize, setValueSize +*/ +void QCPColorMapData::setKeySize(int keySize) +{ + setSize(keySize, mValueSize); +} + +/*! + Resizes the data array to have \a valueSize cells in the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. + + \see setValueRange, setSize, setKeySize +*/ +void QCPColorMapData::setValueSize(int valueSize) +{ + setSize(mKeySize, valueSize); +} + +/*! + Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area + covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setSize +*/ +void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) +{ + setKeyRange(keyRange); + setValueRange(valueRange); +} + +/*! + Sets the coordinate range the data shall be distributed over in the key dimension. Together with + the value range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setRange, setValueRange, setSize +*/ +void QCPColorMapData::setKeyRange(const QCPRange &keyRange) +{ + mKeyRange = keyRange; +} + +/*! + Sets the coordinate range the data shall be distributed over in the value dimension. Together with + the key range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there + will be cells centered on the value coordinates 2, 2.5 and 3. + + \see setRange, setKeyRange, setSize +*/ +void QCPColorMapData::setValueRange(const QCPRange &valueRange) +{ + mValueRange = valueRange; +} + +/*! + Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a + z. + + \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or + value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, + you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to + determine the cell index. Rather directly access the cell index with \ref + QCPColorMapData::setCell. + + \see setCell, setRange +*/ +void QCPColorMapData::setData(double key, double value, double z) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + { + mData[valueCell*mKeySize + keyCell] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } +} + +/*! + Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices + enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see + \ref setSize). + + In the standard plot configuration (horizontal key axis and vertical value axis, both not + range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with + indices (keySize-1, valueSize-1) is in the top right corner of the color map. + + \see setData, setSize +*/ +void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + mData[valueIndex*mKeySize + keyIndex] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value + of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully + opaque cell. + + If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish + to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. + + Note that the cell-wise alpha which can be configured here is independent of any alpha configured + in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise + and gradient alpha, the alpha values will be blended accordingly during rendering of the color + map. + + \see fillAlpha, clearAlpha +*/ +void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + if (mAlpha || createAlpha()) + { + mAlpha[valueIndex*mKeySize + keyIndex] = alpha; + mDataModified = true; + } + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Goes through the data and updates the buffered minimum and maximum data values. + + Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange + and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten + with a smaller or larger value respectively, since the buffered maximum/minimum values have been + updated the last time. Why this is the case is explained in the class description (\ref + QCPColorMapData). + + Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a + recalculateDataBounds for convenience. Setting this to true will call this method for you, before + doing the rescale. +*/ +void QCPColorMapData::recalculateDataBounds() +{ + if (mKeySize > 0 && mValueSize > 0) + { + double minHeight = mData[0]; + double maxHeight = mData[0]; + const int dataCount = mValueSize*mKeySize; + for (int i=0; i maxHeight) + maxHeight = mData[i]; + if (mData[i] < minHeight) + minHeight = mData[i]; + } + mDataBounds.lower = minHeight; + mDataBounds.upper = maxHeight; + } +} + +/*! + Frees the internal data memory. + + This is equivalent to calling \ref setSize "setSize(0, 0)". +*/ +void QCPColorMapData::clear() +{ + setSize(0, 0); +} + +/*! + Frees the internal alpha map. The color map will have full opacity again. +*/ +void QCPColorMapData::clearAlpha() +{ + if (mAlpha) + { + delete[] mAlpha; + mAlpha = 0; + mDataModified = true; + } +} + +/*! + Sets all cells to the value \a z. +*/ +void QCPColorMapData::fill(double z) +{ + const int dataCount = mValueSize*mKeySize; + for (int i=0; i(data); + return; + } + if (copy) + { + *mMapData = *data; + } else + { + delete mMapData; + mMapData = data; + } + mMapImageInvalidated = true; +} + +/*! + Sets the data range of this color map to \a dataRange. The data range defines which data values + are mapped to the color gradient. + + To make the data range span the full range of the data set, use \ref rescaleDataRange. + + \see QCPColorScale::setDataRange +*/ +void QCPColorMap::setDataRange(const QCPRange &dataRange) +{ + if (!QCPRange::validRange(dataRange)) return; + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + if (mDataScaleType == QCPAxis::stLogarithmic) + mDataRange = dataRange.sanitizedForLogScale(); + else + mDataRange = dataRange.sanitizedForLinScale(); + mMapImageInvalidated = true; + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets whether the data is correlated with the color gradient linearly or logarithmically. + + \see QCPColorScale::setDataScaleType +*/ +void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + mMapImageInvalidated = true; + Q_EMIT dataScaleTypeChanged(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + } +} + +/*! + Sets the color gradient that is used to represent the data. For more details on how to create an + own gradient or use one of the preset gradients, see \ref QCPColorGradient. + + The colors defined by the gradient will be used to represent data values in the currently set + data range, see \ref setDataRange. Data points that are outside this data range will either be + colored uniformly with the respective gradient boundary color, or the gradient will repeat, + depending on \ref QCPColorGradient::setPeriodic. + + \see QCPColorScale::setGradient +*/ +void QCPColorMap::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + mMapImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets whether the color map image shall use bicubic interpolation when displaying the color map + shrinked or expanded, and not at a 1:1 pixel-to-data scale. + + \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" +*/ +void QCPColorMap::setInterpolate(bool enabled) +{ + mInterpolate = enabled; + mMapImageInvalidated = true; // because oversampling factors might need to change +} + +/*! + Sets whether the outer most data rows and columns are clipped to the specified key and value + range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). + + if \a enabled is set to false, the data points at the border of the color map are drawn with the + same width and height as all other data points. Since the data points are represented by + rectangles of one color centered on the data coordinate, this means that the shown color map + extends by half a data point over the specified key/value range in each direction. + + \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" +*/ +void QCPColorMap::setTightBoundary(bool enabled) +{ + mTightBoundary = enabled; +} + +/*! + Associates the color scale \a colorScale with this color map. + + This means that both the color scale and the color map synchronize their gradient, data range and + data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps + can be associated with one single color scale. This causes the color maps to also synchronize + those properties, via the mutual color scale. + + This function causes the color map to adopt the current color gradient, data range and data scale + type of \a colorScale. After this call, you may change these properties at either the color map + or the color scale, and the setting will be applied to both. + + Pass 0 as \a colorScale to disconnect the color scale from this color map again. +*/ +void QCPColorMap::setColorScale(QCPColorScale *colorScale) +{ + if (mColorScale) // unconnect signals from old color scale + { + disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + mColorScale = colorScale; + if (mColorScale) // connect signals to new color scale + { + setGradient(mColorScale.data()->gradient()); + setDataRange(mColorScale.data()->dataRange()); + setDataScaleType(mColorScale.data()->dataScaleType()); + connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } +} + +/*! + Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the + current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, + only for the third data dimension of the color map. + + The minimum and maximum values of the data set are buffered in the internal QCPColorMapData + instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref + QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For + performance reasons, however, they are only updated in an expanding fashion. So the buffered + maximum can only increase and the buffered minimum can only decrease. In consequence, changes to + the data that actually lower the maximum of the data set (by overwriting the cell holding the + current maximum with a smaller value), aren't recognized and the buffered maximum overestimates + the true maximum of the data set. The same happens for the buffered minimum. To recalculate the + true minimum and maximum by explicitly looking at each cell, the method + QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a + recalculateDataBounds calls this method before setting the data range to the buffered minimum and + maximum. + + \see setDataRange +*/ +void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) +{ + if (recalculateDataBounds) + mMapData->recalculateDataBounds(); + setDataRange(mMapData->dataBounds()); +} + +/*! + Takes the current appearance of the color map and updates the legend icon, which is used to + represent this color map in the legend (see \ref QCPLegend). + + The \a transformMode specifies whether the rescaling is done by a faster, low quality image + scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm + (Qt::SmoothTransformation). + + The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to + the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured + legend icon size, the thumb will be rescaled during drawing of the legend item. + + \see setDataRange +*/ +void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) +{ + if (mMapImage.isNull() && !data()->isEmpty()) + updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) + + if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again + { + bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); + } +} + +/* inherits documentation from base class */ +double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) + { + if (details) + details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. + return mParentPlot->selectionTolerance()*0.99; + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + foundRange = true; + QCPRange result = mMapData->keyRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (inKeyRange != QCPRange()) + { + if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) + { + foundRange = false; + return QCPRange(); + } + } + + foundRange = true; + QCPRange result = mMapData->valueRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/*! \internal + + Updates the internal map image buffer by going through the internal \ref QCPColorMapData and + turning the data values into color pixels with \ref QCPColorGradient::colorize. + + This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image + has been invalidated for a different reason (e.g. a change of the data range with \ref + setDataRange). + + If the map cell count is low, the image created will be oversampled in order to avoid a + QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images + without smooth transform enabled. Accordingly, oversampling isn't performed if \ref + setInterpolate is true. +*/ +void QCPColorMap::updateMapImage() +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) return; + if (mMapData->isEmpty()) return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + const int keySize = mMapData->keySize(); + const int valueSize = mMapData->valueSize(); + int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + + // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: + if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) + mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); + else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) + mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); + + if (mMapImage.isNull()) + { + qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; + mMapImage = QImage(QSize(10, 10), format); + mMapImage.fill(Qt::black); + } else + { + QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + // resize undersampled map image to actual key/value cell sizes: + if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) + mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); + else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) + mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); + localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image + } else if (!mUndersampledMapImage.isNull()) + mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it + + const double *rawData = mMapData->mData; + const unsigned char *rawAlpha = mMapData->mAlpha; + if (keyAxis->orientation() == Qt::Horizontal) + { + const int lineCount = valueSize; + const int rowCount = keySize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + } + } else // keyAxis->orientation() == Qt::Vertical + { + const int lineCount = keySize; + const int rowCount = valueSize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + } + } + + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + if (keyAxis->orientation() == Qt::Horizontal) + mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + else + mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + } + } + mMapData->mDataModified = false; + mMapImageInvalidated = false; +} + +/* inherits documentation from base class */ +void QCPColorMap::draw(QCPPainter *painter) +{ + if (mMapData->isEmpty()) return; + if (!mKeyAxis || !mValueAxis) return; + applyDefaultAntialiasingHint(painter); + + if (mMapData->mDataModified || mMapImageInvalidated) + updateMapImage(); + + // use buffer if painting vectorized (PDF): + const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); + QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized + QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in + QPixmap mapBuffer; + if (useBuffer) + { + const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps + mapBufferTarget = painter->clipRegion().boundingRect(); + mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); + mapBuffer.fill(Qt::transparent); + localPainter = new QCPPainter(&mapBuffer); + localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); + localPainter->translate(-mapBufferTarget.topLeft()); + } + + QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): + double halfCellWidth = 0; // in pixels + double halfCellHeight = 0; // in pixels + if (keyAxis()->orientation() == Qt::Horizontal) + { + if (mMapData->keySize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); + } else // keyAxis orientation is Qt::Vertical + { + if (mMapData->keySize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); + } + imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); + const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); + QRegion clipBackup; + if (mTightBoundary) + { + clipBackup = localPainter->clipRegion(); + QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + localPainter->setClipRect(tightClipRect, Qt::IntersectClip); + } + localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); + if (mTightBoundary) + localPainter->setClipRegion(clipBackup); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); + + if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter + { + delete localPainter; + painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); + } +} + +/* inherits documentation from base class */ +void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + // draw map thumbnail: + if (!mLegendIcon.isNull()) + { + QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); + QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); + iconRect.moveCenter(rect.center()); + painter->drawPixmap(iconRect.topLeft(), scaledIcon); + } + /* + // draw frame: + painter->setBrush(Qt::NoBrush); + painter->setPen(Qt::black); + painter->drawRect(rect.adjusted(1, 1, 0, 0)); + */ +} +/* end of 'src/plottables/plottable-colormap.cpp' */ + + +/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancialData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancialData + \brief Holds the data of one single data point for QCPFinancial. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a open: The opening value at the data point (this is the \a mainValue) + \li \a high: The high/maximum value at the data point + \li \a low: The low/minimum value at the data point + \li \a close: The closing value at the data point + + The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef + for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPFinancialDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPFinancialData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainValue() const + + Returns the \a open member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPFinancialData::valueRange() const + + Returns a QCPRange spanning from the \a low to the \a high value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPFinancialData::QCPFinancialData() : + key(0), + open(0), + high(0), + low(0), + close(0) +{ +} + +/*! + Constructs a data point with the specified \a key and OHLC values. +*/ +QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : + key(key), + open(open), + high(high), + low(low), + close(close) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancial +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancial + \brief A plottable representing a financial stock chart + + \image html QCPFinancial.png + + This plottable represents time series data binned to certain intervals, mainly used for stock + charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be + set via \ref setChartStyle. + + The data is passed via \ref setData as a set of open/high/low/close values at certain keys + (typically times). This means the data must be already binned appropriately. If data is only + available as a series of values (e.g. \a price against \a time), you can use the static + convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed + to \ref setData. + + The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref + setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and + the width to (or slightly less than) one time bin interval width. + + \section qcpfinancial-appearance Changing the appearance + + Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, + lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). + + If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are + represented with a different pen and brush than negative changes (\a close < \a open). These can + be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref + setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection + however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, + irrespective of whether the chart is single- or two-colored. + + \section qcpfinancial-usage Usage + + Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot + instance takes ownership of the plottable, so do not delete it manually but use + QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 + Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data + series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const + + Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods, in certain situations. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mChartStyle(csCandlestick), + mWidth(0.5), + mWidthType(wtPlotCoords), + mTwoColored(true), + mBrushPositive(QBrush(QColor(50, 160, 0))), + mBrushNegative(QBrush(QColor(180, 0, 15))), + mPenPositive(QPen(QColor(40, 150, 0))), + mPenNegative(QPen(QColor(170, 5, 5))) +{ + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPFinancial::~QCPFinancial() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. + Modifying the data in the container will then affect all financials that share the container. + Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the financial's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a + close. The provided vectors should have equal length. Else, the number of added points will be + the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, open, high, low, close, alreadySorted); +} + +/*! + Sets which representation style shall be used to display the OHLC data. +*/ +void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) +{ + mChartStyle = style; +} + +/*! + Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. + + A typical choice is to set it to (or slightly less than) one bin interval width. +*/ +void QCPFinancial::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for + an explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets whether this chart shall contrast positive from negative trends per data point by using two + separate colors to draw the respective bars/candlesticks. + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setTwoColored(bool twoColored) +{ + mTwoColored = twoColored; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushNegative, setPenPositive, setPenNegative +*/ +void QCPFinancial::setBrushPositive(const QBrush &brush) +{ + mBrushPositive = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushPositive, setPenNegative, setPenPositive +*/ +void QCPFinancial::setBrushNegative(const QBrush &brush) +{ + mBrushNegative = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setPenPositive(const QPen &pen) +{ + mPenPositive = pen; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setBrushNegative, setBrushPositive +*/ +void QCPFinancial::setPenNegative(const QPen &pen) +{ + mPenNegative = pen; +} + +/*! \overload + + Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. + The provided vectors should have equal length. Else, the number of added points will be the size + of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); + const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->open = open[i]; + it->high = high[i]; + it->low = low[i]; + it->close = close[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current + data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(double key, double open, double high, double low, double close) +{ + mDataContainer->add(QCPFinancialData(key, open, high, low, close)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(selectionHitBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + // perform select test according to configured style: + double result = -1; + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + case QCPFinancial::csCandlestick: + result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + } + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } + + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/*! + A convenience function that converts time series data (\a value against \a time) to OHLC binned + data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const + QCPFinancialDataContainer&). + + The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. + For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour + each, set \a timeBinSize to 3600. + + \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The + value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. + It merely defines the mathematical offset/phase of the bins that will be used to process the + data. +*/ +QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) +{ + QCPFinancialDataContainer data; + int count = qMin(time.size(), value.size()); + if (count == 0) + return QCPFinancialDataContainer(); + + QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); + int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); + for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); + if (i == count-1) // last data point is in current bin, finalize bin: + { + currentBinData.close = value.at(i); + currentBinData.key = timeBinOffset+(index)*timeBinSize; + data.add(currentBinData); + } + } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: + { + // finalize current bin: + currentBinData.close = value.at(i-1); + currentBinData.key = timeBinOffset+(index-1)*timeBinSize; + data.add(currentBinData); + // start next bin: + currentBinIndex = index; + currentBinData.open = value.at(i); + currentBinData.high = value.at(i); + currentBinData.low = value.at(i); + } + } + + return data; +} + +/* inherits documentation from base class */ +void QCPFinancial::draw(QCPPainter *painter) +{ + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPFinancialDataContainer::const_iterator begin = visibleBegin; + QCPFinancialDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + // draw data segment according to configured style: + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + drawOhlcPlot(painter, begin, end, isSelectedSegment); break; + case QCPFinancial::csCandlestick: + drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing + if (mChartStyle == csOhlc) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } + } else if (mChartStyle == csCandlestick) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. +*/ +void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); + // draw close: + painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); + } + } else + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); + // draw close: + painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. +*/ +void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + // draw low: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + // draw low: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); + } + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of + \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel + when this function is called). + + It returns the number of pixels the bar extends to higher keys, relative to the \a key + coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed + horizontal axis, the return value is negative. This is important so the open/close flags on the + \ref csOhlc bar are drawn to the correct side. +*/ +double QCPFinancial::getPixelWidth(double key, double keyPixel) const +{ + double result = 0; + switch (mWidthType) + { + case wtAbsolute: + { + if (mKeyAxis) + result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } + return result; +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a + end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + called by the drawing methods to determine which data (key) range is visible at the current key + axis range setting, so only that needs to be processed. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + begin may still be just outside the visible range. + + \a end returns the iterator just above the highest data point that needs to be taken into + account. Same as before, \a end may also lie just outside of the visible range + + if the plottable contains no data, both \a begin and \a end point to \c constEnd. +*/ +void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points +} + +/*! \internal + + Returns the hit box in pixel coordinates that will be used for data selection with the selection + rect (\ref selectTestRect), of the data point given by \a it. +*/ +QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double keyPixel = keyAxis->coordToPixel(it->key); + double highPixel = valueAxis->coordToPixel(it->high); + double lowPixel = valueAxis->coordToPixel(it->low); + double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); + if (keyAxis->orientation() == Qt::Horizontal) + return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); + else + return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); +} +/* end of 'src/plottables/plottable-financial.cpp' */ + + +/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBarsData + \brief Holds the data of one single error bar for QCPErrorBars. + + The stored data is: + \li \a errorMinus: how much the error bar extends towards negative coordinates from the data + point position + \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point + position + + The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a + typedef for QVector<\ref QCPErrorBarsData>. + + \see QCPErrorBarsDataContainer +*/ + +/*! + Constructs an error bar with errors set to zero. +*/ +QCPErrorBarsData::QCPErrorBarsData() : + errorMinus(0), + errorPlus(0) +{ +} + +/*! + Constructs an error bar with equal \a error in both negative and positive direction. +*/ +QCPErrorBarsData::QCPErrorBarsData(double error) : + errorMinus(error), + errorPlus(error) +{ +} + +/*! + Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, + respectively. +*/ +QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : + errorMinus(errorMinus), + errorPlus(errorPlus) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBars + \brief A plottable that adds a set of error bars to other plottables. + + \image html QCPErrorBars.png + + The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref + QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. + + Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the + error bars. The orientation of the error bars can be controlled with \ref setErrorType. + + By using \ref setData, you can supply the actual error data, either as symmetric error or + plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute + key/value position of each error bar will be adopted from the configured data plottable. The + error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points + of the data plottable. You can directly access and manipulate the error bar data via \ref data. + + Set either of the plus/minus errors to NaN (qQNaN() or + std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at + that index. + + \section qcperrorbars-appearance Changing the appearance + + The appearance of the error bars is defined by the pen (\ref setPen), and the width of the + whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data + point center to prevent that error bars are drawn too close to or even through scatter points. + This gap size can be controlled via \ref setSymbolGap. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPErrorBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You + may use it to directly manipulate the error values, which may be more convenient and faster than + using the regular \ref setData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + It is also important that the \a keyAxis and \a valueAxis are the same for the error bars + plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). + + The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not + delete it manually but use \ref QCustomPlot::removePlottable() instead. +*/ +QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QVector), + mErrorType(etValueError), + mWhiskerWidth(9), + mSymbolGap(10) +{ + setPen(QPen(Qt::black, 0)); + setBrush(Qt::NoBrush); +} + +QCPErrorBars::~QCPErrorBars() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data + container safely. Modifying the data in the container will then affect all \ref QCPErrorBars + instances that share the container. Sharing can be achieved by simply exchanging the data + containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, assign the + data containers directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 + (This uses different notation compared with other plottables, because the \ref QCPErrorBars + uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) + + \see addData +*/ +void QCPErrorBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &error) +{ + mDataContainer->clear(); + addData(error); +} + +/*! \overload + + Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) +{ + mDataContainer->clear(); + addData(errorMinus, errorPlus); +} + +/*! + Sets the data plottable to which the error bars will be applied. The error values specified e.g. + via \ref setData will be associated one-to-one by the data point index to the data points of \a + plottable. This means that the error bars will adopt the key/value coordinates of the data point + with the same index. + + The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref + QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either + of these restrictions is violated, a corresponding qDebug output is generated, and the data + plottable of this \ref QCPErrorBars instance is set to zero. + + For proper display, care must also be taken that the key and value axes of the \a plottable match + those configured for this \ref QCPErrorBars instance. +*/ +void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) +{ + if (plottable && qobject_cast(plottable)) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; + return; + } + if (plottable && !plottable->interface1D()) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; + return; + } + + mDataPlottable = plottable; +} + +/*! + Sets in which orientation the error bars shall appear on the data points. If your data needs both + error dimensions, create two \ref QCPErrorBars with different \a type. +*/ +void QCPErrorBars::setErrorType(ErrorType type) +{ + mErrorType = type; +} + +/*! + Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to + \a pixels. +*/ +void QCPErrorBars::setWhiskerWidth(double pixels) +{ + mWhiskerWidth = pixels; +} + +/*! + Sets the gap diameter around the data points that will be left out when drawing the error bar + backbones. This gap prevents that error bars are drawn too close to or even through scatter + points. +*/ +void QCPErrorBars::setSymbolGap(double pixels) +{ + mSymbolGap = pixels; +} + +/*! \overload + + Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &error) +{ + addData(error, error); +} + +/*! \overload + + Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) +{ + if (errorMinus.size() != errorPlus.size()) + qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); + const int n = qMin(errorMinus.size(), errorPlus.size()); + mDataContainer->reserve(n); + for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); +} + +/*! \overload + + Adds a single symmetrical error bar as specified in \a error. The errors will be associated + one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double error) +{ + mDataContainer->append(QCPErrorBarsData(error)); +} + +/*! \overload + + Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors + will be associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double errorMinus, double errorPlus) +{ + mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); +} + +/* inherits documentation from base class */ +int QCPErrorBars::dataCount() const +{ + return mDataContainer->size(); +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataSortKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataSortKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainValue(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainValue(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::dataValueRange(int index) const +{ + if (mDataPlottable) + { + const double value = mDataPlottable->interface1D()->dataMainValue(index); + if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) + return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); + else + return QCPRange(value, value); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QCPRange(); + } +} + +/* inherits documentation from base class */ +QPointF QCPErrorBars::dataPixelPosition(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataPixelPosition(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QPointF(); +} + +/* inherits documentation from base class */ +bool QCPErrorBars::sortKeyIsMainKey() const +{ + if (mDataPlottable) + { + return mDataPlottable->interface1D()->sortKeyIsMainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return true; + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if (!mDataPlottable) + return result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); + + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + backbones.clear(); + whiskers.clear(); + getErrorBarLines(it, backbones, whiskers); + for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); + break; + } + } + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); + if (beginIndex >= mDataContainer->size()) + beginIndex = mDataContainer->size()-1; + return beginIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); + if (endIndex > mDataContainer->size()) + endIndex = mDataContainer->size(); + return endIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mDataPlottable) return -1; + + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +void QCPErrorBars::draw(QCPPainter *painter) +{ + if (!mDataPlottable) return; + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + + // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually + // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): + bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) + qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); + } +#endif + + applyDefaultAntialiasingHint(painter); + painter->setBrush(Qt::NoBrush); + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + QVector backbones, whiskers; + for (int i=0; i= unselectedSegments.size(); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + if (painter->pen().capStyle() == Qt::SquareCap) + { + QPen capFixPen(painter->pen()); + capFixPen.setCapStyle(Qt::FlatCap); + painter->setPen(capFixPen); + } + backbones.clear(); + whiskers.clear(); + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) + getErrorBarLines(it, backbones, whiskers); + } + painter->drawLines(backbones); + painter->drawLines(whiskers); + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) + { + painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); + painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); + painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); + } else + { + painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); + painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); + painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); + } +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (mErrorType == etValueError) + { + // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } else // mErrorType == etKeyError + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(dataKey)) continue; + // plus error: + double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); + itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); + } + for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange) + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) + continue; + } + if (mErrorType == etValueError) + { + const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(dataValue)) continue; + // plus error: + double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } else // mErrorType == etKeyError + { + // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! \internal + + Calculates the lines that make up the error bar belonging to the data point \a it. + + The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so + calling this method with different \a it but the same \a backbones and \a whiskers allows to + accumulate lines for multiple data points. + + This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars + instance and within the bounds of the associated data plottable. +*/ +void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const +{ + if (!mDataPlottable) return; + + int index = it-mDataContainer->constBegin(); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) + return; + QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); + QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); + const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value + const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); + // plus error: + double errorStart, errorEnd; + if (!qIsNaN(it->errorPlus)) + { + errorStart = centerErrorAxisPixel+symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } + // minus error: + if (!qIsNaN(it->errorMinus)) + { + errorStart = centerErrorAxisPixel-symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } +} + +/*! \internal + + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key + coordinates relative to their data point key, this method checks all outer error bars whether + they truly don't reach into the visible portion of the axis rect, by calling \ref + errorBarVisible. On the other hand error bars with type \ref etValueError that are associated + with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype + "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of + error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref + QCPPlottableInterface1D::findEnd). + + If the plottable's sort key is not equal to the main key, this method returns the full data + range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a + point-by-point basis in the \ref draw method. +*/ +void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable || rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) + { + // if the sort key isn't the main key, it's not possible to find a contiguous range of visible + // data points, so this method then only applies the range restriction and otherwise returns + // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing + QCPDataRange dataRange(0, mDataContainer->size()); + dataRange = dataRange.bounded(rangeRestriction); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); + return; + } + + // get visible data range via interface from data plottable, and then restrict to available error data points: + const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); + int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); + int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); + int i = beginIndex; + while (i > 0 && i < n && i > rangeRestriction.begin()) + { + if (errorBarVisible(i)) + beginIndex = i; + --i; + } + i = endIndex; + while (i >= 0 && i < n && i < rangeRestriction.end()) + { + if (errorBarVisible(i)) + endIndex = i+1; + ++i; + } + QCPDataRange dataRange(beginIndex, endIndex); + dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); +} + +/*! \internal + + Calculates the minimum distance in pixels the error bars' representation has from the given \a + pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. +*/ +double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (!mDataPlottable || mDataContainer->isEmpty()) + return -1.0; + if (!mKeyAxis || !mValueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1.0; + } + + QCPErrorBarsDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); + + // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + getErrorBarLines(it, backbones, whiskers); + for (int i=0; i &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! \internal + + Returns whether the error bar at the specified \a index is visible within the current key axis + range. + + This method assumes for performance reasons without checking that the key axis, the value axis, + and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid + bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. +*/ +bool QCPErrorBars::errorBarVisible(int index) const +{ + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + if (qIsNaN(centerKeyPixel)) + return false; + + double keyMin, keyMax; + if (mErrorType == etKeyError) + { + const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); + const double errorPlus = mDataContainer->at(index).errorPlus; + const double errorMinus = mDataContainer->at(index).errorMinus; + keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); + keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); + } else // mErrorType == etValueError + { + keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + } + return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); +} + +/*! \internal + + Returns whether \a line intersects (or is contained in) \a pixelRect. + + \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for + error bar lines. +*/ +bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const +{ + if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) + return false; + else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) + return false; + else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) + return false; + else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) + return false; + else + return true; +} +/* end of 'src/plottables/plottable-errorbar.cpp' */ + + +/* including file 'src/items/item-straightline.cpp', size 7592 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemStraightLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemStraightLine + \brief A straight line that spans infinitely in both directions + + \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a point1 and \a point2, which define the straight line. +*/ + +/*! + Creates a straight line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + point1(createPosition(QLatin1String("point1"))), + point2(createPosition(QLatin1String("point2"))) +{ + point1->setCoords(0, 0); + point2->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemStraightLine::~QCPItemStraightLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemStraightLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemStraightLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); +} + +/* inherits documentation from base class */ +void QCPItemStraightLine::draw(QCPPainter *painter) +{ + QCPVector2D start(point1->pixelPosition()); + QCPVector2D end(point2->pixelPosition()); + // get visible segment of straight line inside clipRect: + double clipPad = mainPen().widthF(); + QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + } +} + +/*! \internal + + Returns the section of the straight line defined by \a base and direction vector \a + vec, that is visible in the specified \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const +{ + double bx, by; + double gamma; + QLineF result; + if (vec.x() == 0 && vec.y() == 0) + return result; + if (qFuzzyIsNull(vec.x())) // line is vertical + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical + } else if (qFuzzyIsNull(vec.y())) // line is horizontal + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal + } else // line is skewed + { + QList pointVectors; + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + // check right of rect: + bx = rect.right(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemStraightLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-straightline.cpp' */ + + +/* including file 'src/items/item-line.cpp', size 8498 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemLine + \brief A line from one point to another + + \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a start and \a end, which define the end points of the line. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. +*/ + +/*! + Creates a line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemLine::~QCPItemLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemLine::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemLine::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); +} + +/* inherits documentation from base class */ +void QCPItemLine::draw(QCPPainter *painter) +{ + QCPVector2D startVec(start->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if (qFuzzyIsNull((startVec-endVec).lengthSquared())) + return; + // get visible segment of straight line inside clipRect: + double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); + clipPad = qMax(clipPad, (double)mainPen().widthF()); + QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, startVec-endVec); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, endVec-startVec); + } +} + +/*! \internal + + Returns the section of the line defined by \a start and \a end, that is visible in the specified + \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const +{ + bool containsStart = rect.contains(start.x(), start.y()); + bool containsEnd = rect.contains(end.x(), end.y()); + if (containsStart && containsEnd) + return QLineF(start.toPointF(), end.toPointF()); + + QCPVector2D base = start; + QCPVector2D vec = end-start; + double bx, by; + double gamma, mu; + QLineF result; + QList pointVectors; + + if (!qFuzzyIsNull(vec.y())) // line is not horizontal + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + } + if (!qFuzzyIsNull(vec.x())) // line is not vertical + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + // check right of rect: + bx = rect.right(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + } + + if (containsStart) + pointVectors.append(start); + if (containsEnd) + pointVectors.append(end); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-line.cpp' */ + + +/* including file 'src/items/item-curve.cpp', size 7159 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemCurve + \brief A curved line from one point to another + + \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." + + It has four positions, \a start and \a end, which define the end points of the line, and two + control points which define the direction the line exits from the start and the direction from + which it approaches the end: \a startDir and \a endDir. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an + arrow. + + Often it is desirable for the control points to stay at fixed relative positions to the start/end + point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, + and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. +*/ + +/*! + Creates a curve item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + startDir(createPosition(QLatin1String("startDir"))), + endDir(createPosition(QLatin1String("endDir"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + startDir->setCoords(0.5, 0); + endDir->setCoords(0, 0.5); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemCurve::~QCPItemCurve() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemCurve::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemCurve::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemCurve::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemCurve::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF startVec(start->pixelPosition()); + QPointF startDirVec(startDir->pixelPosition()); + QPointF endDirVec(endDir->pixelPosition()); + QPointF endVec(end->pixelPosition()); + + QPainterPath cubicPath(startVec); + cubicPath.cubicTo(startDirVec, endDirVec, endVec); + + QPolygonF polygon = cubicPath.toSubpathPolygons().first(); + QCPVector2D p(pos); + double minDistSqr = std::numeric_limits::max(); + for (int i=1; ipixelPosition()); + QCPVector2D startDirVec(startDir->pixelPosition()); + QCPVector2D endDirVec(endDir->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if ((endVec-startVec).length() > 1e10) // too large curves cause crash + return; + + QPainterPath cubicPath(startVec.toPointF()); + cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); + + // paint visible segment, if existent: + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + QRect cubicRect = cubicPath.controlPointRect().toRect(); + if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position + cubicRect.adjust(0, 0, 1, 1); + if (clip.intersects(cubicRect)) + { + painter->setPen(mainPen()); + painter->drawPath(cubicPath); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemCurve::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-curve.cpp' */ + + +/* including file 'src/items/item-rect.cpp', size 6479 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemRect + \brief A rectangle + + \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemRect::~QCPItemRect() +{ +} + +/*! + Sets the pen that will be used to draw the line of the rectangle + + \see setSelectedPen, setBrush +*/ +void QCPItemRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the rectangle when selected + + \see setPen, setSelected +*/ +void QCPItemRect::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemRect::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); +} + +/* inherits documentation from base class */ +void QCPItemRect::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF rect = QRectF(p1, p2).normalized(); + double clipPad = mainPen().widthF(); + QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(rect); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemRect::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemRect::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemRect::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-rect.cpp' */ + + +/* including file 'src/items/item-text.cpp', size 13338 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemText +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemText + \brief A text label + + \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." + + Its position is defined by the member \a position and the setting of \ref setPositionAlignment. + The latter controls which part of the text rect shall be aligned with \a position. + + The text alignment itself (i.e. left, center, right) can be controlled with \ref + setTextAlignment. + + The text may be rotated around the \a position point with \ref setRotation. +*/ + +/*! + Creates a text item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemText::QCPItemText(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mText(QLatin1String("text")), + mPositionAlignment(Qt::AlignCenter), + mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), + mRotation(0) +{ + position->setCoords(0, 0); + + setPen(Qt::NoPen); + setSelectedPen(Qt::NoPen); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setColor(Qt::black); + setSelectedColor(Qt::blue); +} + +QCPItemText::~QCPItemText() +{ +} + +/*! + Sets the color of the text. +*/ +void QCPItemText::setColor(const QColor &color) +{ + mColor = color; +} + +/*! + Sets the color of the text that will be used when the item is selected. +*/ +void QCPItemText::setSelectedColor(const QColor &color) +{ + mSelectedColor = color; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text. To disable the + border, set \a pen to Qt::NoPen. + + \see setSelectedPen, setBrush, setPadding +*/ +void QCPItemText::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text, when the item is + selected. To disable the border, set \a pen to Qt::NoPen. + + \see setPen +*/ +void QCPItemText::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used do fill the background of the text. To disable the + background, set \a brush to Qt::NoBrush. + + \see setSelectedBrush, setPen, setPadding +*/ +void QCPItemText::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the + background, set \a brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemText::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the font of the text. + + \see setSelectedFont, setColor +*/ +void QCPItemText::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the font of the text that will be used when the item is selected. + + \see setFont +*/ +void QCPItemText::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the text that will be displayed. Multi-line texts are supported by inserting a line break + character, e.g. '\n'. + + \see setFont, setColor, setTextAlignment +*/ +void QCPItemText::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets which point of the text rect shall be aligned with \a position. + + Examples: + \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such + that the top of the text rect will be horizontally centered on \a position. + \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the + bottom left corner of the text rect. + + If you want to control the alignment of (multi-lined) text within the text rect, use \ref + setTextAlignment. +*/ +void QCPItemText::setPositionAlignment(Qt::Alignment alignment) +{ + mPositionAlignment = alignment; +} + +/*! + Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). +*/ +void QCPItemText::setTextAlignment(Qt::Alignment alignment) +{ + mTextAlignment = alignment; +} + +/*! + Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated + around \a position. +*/ +void QCPItemText::setRotation(double degrees) +{ + mRotation = degrees; +} + +/*! + Sets the distance between the border of the text rectangle and the text. The appearance (and + visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. +*/ +void QCPItemText::setPadding(const QMargins &padding) +{ + mPadding = padding; +} + +/* inherits documentation from base class */ +double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + // The rect may be rotated, so we transform the actual clicked pos to the rotated + // coordinate system, so we can use the normal rectDistance function for non-rotated rects: + QPointF positionPixels(position->pixelPosition()); + QTransform inputTransform; + inputTransform.translate(positionPixels.x(), positionPixels.y()); + inputTransform.rotate(-mRotation); + inputTransform.translate(-positionPixels.x(), -positionPixels.y()); + QPointF rotatedPos = inputTransform.map(pos); + QFontMetrics fontMetrics(mFont); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); + textBoxRect.moveTopLeft(textPos.toPoint()); + + return rectDistance(textBoxRect, rotatedPos, true); +} + +/* inherits documentation from base class */ +void QCPItemText::draw(QCPPainter *painter) +{ + QPointF pos(position->pixelPosition()); + QTransform transform = painter->transform(); + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + painter->setFont(mainFont()); + QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); + textBoxRect.moveTopLeft(textPos.toPoint()); + double clipPad = mainPen().widthF(); + QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) + { + painter->setTransform(transform); + if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || + (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(textBoxRect); + } + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(mainColor())); + painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemText::anchorPixelPosition(int anchorId) const +{ + // get actual rect points (pretty much copied from draw function): + QPointF pos(position->pixelPosition()); + QTransform transform; + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + QFontMetrics fontMetrics(mainFont()); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textBoxRect.moveTopLeft(textPos.toPoint()); + QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); + + switch (anchorId) + { + case aiTopLeft: return rectPoly.at(0); + case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; + case aiTopRight: return rectPoly.at(1); + case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; + case aiBottomRight: return rectPoly.at(2); + case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; + case aiBottomLeft: return rectPoly.at(3); + case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the point that must be given to the QPainter::drawText function (which expects the top + left point of the text rect), according to the position \a pos, the text bounding box \a rect and + the requested \a positionAlignment. + + For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point + will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally + drawn at that point, the lower left corner of the resulting text rect is at \a pos. +*/ +QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const +{ + if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) + return pos; + + QPointF result = pos; // start at top left + if (positionAlignment.testFlag(Qt::AlignHCenter)) + result.rx() -= rect.width()/2.0; + else if (positionAlignment.testFlag(Qt::AlignRight)) + result.rx() -= rect.width(); + if (positionAlignment.testFlag(Qt::AlignVCenter)) + result.ry() -= rect.height()/2.0; + else if (positionAlignment.testFlag(Qt::AlignBottom)) + result.ry() -= rect.height(); + return result; +} + +/*! \internal + + Returns the font that should be used for drawing text. Returns mFont when the item is not selected + and mSelectedFont when it is. +*/ +QFont QCPItemText::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the color that should be used for drawing text. Returns mColor when the item is not + selected and mSelectedColor when it is. +*/ +QColor QCPItemText::mainColor() const +{ + return mSelected ? mSelectedColor : mColor; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemText::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemText::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-text.cpp' */ + + +/* including file 'src/items/item-ellipse.cpp', size 7863 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemEllipse +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemEllipse + \brief An ellipse + + \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. +*/ + +/*! + Creates an ellipse item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), + left(createAnchor(QLatin1String("left"), aiLeft)), + center(createAnchor(QLatin1String("center"), aiCenter)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemEllipse::~QCPItemEllipse() +{ +} + +/*! + Sets the pen that will be used to draw the line of the ellipse + + \see setSelectedPen, setBrush +*/ +void QCPItemEllipse::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the ellipse when selected + + \see setPen, setSelected +*/ +void QCPItemEllipse::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemEllipse::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemEllipse::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + QPointF center((p1+p2)/2.0); + double a = qAbs(p1.x()-p2.x())/2.0; + double b = qAbs(p1.y()-p2.y())/2.0; + double x = pos.x()-center.x(); + double y = pos.y()-center.y(); + + // distance to border: + double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); + double result = qAbs(c-1)*qSqrt(x*x+y*y); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (x*x/(a*a) + y*y/(b*b) <= 1) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/* inherits documentation from base class */ +void QCPItemEllipse::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF ellipseRect = QRectF(p1, p2).normalized(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); +#ifdef __EXCEPTIONS + try // drawEllipse sometimes throws exceptions if ellipse is too big + { +#endif + painter->drawEllipse(ellipseRect); +#ifdef __EXCEPTIONS + } catch (...) + { + qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; + setVisible(false); + } +#endif + } +} + +/* inherits documentation from base class */ +QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemEllipse::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemEllipse::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-ellipse.cpp' */ + + +/* including file 'src/items/item-pixmap.cpp', size 10615 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPixmap + \brief An arbitrary pixmap + + \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will + be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to + fit the rectangle or be drawn aligned to the topLeft position. + + If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown + on the right side of the example image), the pixmap will be flipped in the respective + orientations. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mScaled(false), + mScaledPixmapInvalidated(true), + mAspectRatioMode(Qt::KeepAspectRatio), + mTransformationMode(Qt::SmoothTransformation) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(Qt::NoPen); + setSelectedPen(QPen(Qt::blue)); +} + +QCPItemPixmap::~QCPItemPixmap() +{ +} + +/*! + Sets the pixmap that will be displayed. +*/ +void QCPItemPixmap::setPixmap(const QPixmap &pixmap) +{ + mPixmap = pixmap; + mScaledPixmapInvalidated = true; + if (mPixmap.isNull()) + qDebug() << Q_FUNC_INFO << "pixmap is null"; +} + +/*! + Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a + bottomRight positions. +*/ +void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) +{ + mScaled = scaled; + mAspectRatioMode = aspectRatioMode; + mTransformationMode = transformationMode; + mScaledPixmapInvalidated = true; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap. + + \see setSelectedPen, setBrush +*/ +void QCPItemPixmap::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap when selected + + \see setPen, setSelected +*/ +void QCPItemPixmap::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return rectDistance(getFinalRect(), pos, true); +} + +/* inherits documentation from base class */ +void QCPItemPixmap::draw(QCPPainter *painter) +{ + bool flipHorz = false; + bool flipVert = false; + QRect rect = getFinalRect(&flipHorz, &flipVert); + double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); + QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) + { + updateScaledPixmap(rect, flipHorz, flipVert); + painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); + QPen pen = mainPen(); + if (pen.style() != Qt::NoPen) + { + painter->setPen(pen); + painter->setBrush(Qt::NoBrush); + painter->drawRect(rect); + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const +{ + bool flipHorz; + bool flipVert; + QRect rect = getFinalRect(&flipHorz, &flipVert); + // we actually want denormal rects (negative width/height) here, so restore + // the flipped state: + if (flipHorz) + rect.adjust(rect.width(), 0, -rect.width(), 0); + if (flipVert) + rect.adjust(0, rect.height(), 0, -rect.height()); + + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The + parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped + horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a + bottomRight.) + + This function only creates the scaled pixmap when the buffered pixmap has a different size than + the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does + not cause expensive rescaling every time. + + If scaling is disabled, sets mScaledPixmap to a null QPixmap. +*/ +void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) +{ + if (mPixmap.isNull()) + return; + + if (mScaled) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + double devicePixelRatio = mPixmap.devicePixelRatio(); +#else + double devicePixelRatio = 1.0; +#endif + if (finalRect.isNull()) + finalRect = getFinalRect(&flipHorz, &flipVert); + if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) + { + mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); + if (flipHorz || flipVert) + mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mScaledPixmap.setDevicePixelRatio(devicePixelRatio); +#endif + } + } else if (!mScaledPixmap.isNull()) + mScaledPixmap = QPixmap(); + mScaledPixmapInvalidated = false; +} + +/*! \internal + + Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions + and scaling settings. + + The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn + flipped horizontally or vertically in the returned rect. (The returned rect itself is always + normalized, i.e. the top left corner of the rect is actually further to the top/left than the + bottom right corner). This is the case when the item position \a topLeft is further to the + bottom/right than \a bottomRight. + + If scaling is disabled, returns a rect with size of the original pixmap and the top left corner + aligned with the item position \a topLeft. The position \a bottomRight is ignored. +*/ +QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const +{ + QRect result; + bool flipHorz = false; + bool flipVert = false; + QPoint p1 = topLeft->pixelPosition().toPoint(); + QPoint p2 = bottomRight->pixelPosition().toPoint(); + if (p1 == p2) + return QRect(p1, QSize(0, 0)); + if (mScaled) + { + QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); + QPoint topLeft = p1; + if (newSize.width() < 0) + { + flipHorz = true; + newSize.rwidth() *= -1; + topLeft.setX(p2.x()); + } + if (newSize.height() < 0) + { + flipVert = true; + newSize.rheight() *= -1; + topLeft.setY(p2.y()); + } + QSize scaledSize = mPixmap.size(); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + scaledSize /= mPixmap.devicePixelRatio(); + scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); +#else + scaledSize.scale(newSize, mAspectRatioMode); +#endif + result = QRect(topLeft, scaledSize); + } else + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); +#else + result = QRect(p1, mPixmap.size()); +#endif + } + if (flippedHorz) + *flippedHorz = flipHorz; + if (flippedVert) + *flippedVert = flipVert; + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemPixmap::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-pixmap.cpp' */ + + +/* including file 'src/items/item-tracer.cpp', size 14624 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemTracer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemTracer + \brief Item that sticks to QCPGraph data points + + \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." + + The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt + the coordinate axes of the graph and update its \a position to be on the graph's data. This means + the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a + QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a + position will have no effect because they will be overriden in the next redraw (this is when the + coordinate update happens). + + If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will + stay at the corresponding end of the graph. + + With \ref setInterpolating you may specify whether the tracer may only stay exactly on data + points or whether it interpolates data points linearly, if given a key that lies between two data + points of the graph. + + The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer + have no own visual appearance (set the style to \ref tsNone), and just connect other item + positions to the tracer \a position (used as an anchor) via \ref + QCPItemPosition::setParentAnchor. + + \note The tracer position is only automatically updated upon redraws. So when the data of the + graph changes and immediately afterwards (without a redraw) the position coordinates of the + tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref + updatePosition must be called manually, prior to reading the tracer coordinates. +*/ + +/*! + Creates a tracer item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + mSize(6), + mStyle(tsCrosshair), + mGraph(0), + mGraphKey(0), + mInterpolating(false) +{ + position->setCoords(0, 0); + + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemTracer::~QCPItemTracer() +{ +} + +/*! + Sets the pen that will be used to draw the line of the tracer + + \see setSelectedPen, setBrush +*/ +void QCPItemTracer::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the tracer when selected + + \see setPen, setSelected +*/ +void QCPItemTracer::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer + + \see setSelectedBrush, setPen +*/ +void QCPItemTracer::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer, when selected. + + \see setBrush, setSelected +*/ +void QCPItemTracer::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare + does, \ref tsCrosshair does not). +*/ +void QCPItemTracer::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the style/visual appearance of the tracer. + + If you only want to use the tracer \a position as an anchor for other items, set \a style to + \ref tsNone. +*/ +void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) +{ + mStyle = style; +} + +/*! + Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type + QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. + + To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed + freely like any other item position. This is the state the tracer will assume when its graph gets + deleted while still attached to it. + + \see setGraphKey +*/ +void QCPItemTracer::setGraph(QCPGraph *graph) +{ + if (graph) + { + if (graph->parentPlot() == mParentPlot) + { + position->setType(QCPItemPosition::ptPlotCoords); + position->setAxes(graph->keyAxis(), graph->valueAxis()); + mGraph = graph; + updatePosition(); + } else + qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; + } else + { + mGraph = 0; + } +} + +/*! + Sets the key of the graph's data point the tracer will be positioned at. This is the only free + coordinate of a tracer when attached to a graph. + + Depending on \ref setInterpolating, the tracer will be either positioned on the data point + closest to \a key, or will stay exactly at \a key and interpolate the value linearly. + + \see setGraph, setInterpolating +*/ +void QCPItemTracer::setGraphKey(double key) +{ + mGraphKey = key; +} + +/*! + Sets whether the value of the graph's data points shall be interpolated, when positioning the + tracer. + + If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on + the data point of the graph which is closest to the key, but which is not necessarily exactly + there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and + the appropriate value will be interpolated from the graph's data points linearly. + + \see setGraph, setGraphKey +*/ +void QCPItemTracer::setInterpolating(bool enabled) +{ + mInterpolating = enabled; +} + +/* inherits documentation from base class */ +double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return -1; + case tsPlus: + { + if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), + QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); + break; + } + case tsCrosshair: + { + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), + QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + // distance to border: + double centerDist = QCPVector2D(center-pos).length(); + double circleLine = w; + double result = qAbs(centerDist-circleLine); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (centerDist <= circleLine) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; + } + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); + } + break; + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemTracer::draw(QCPPainter *painter) +{ + updatePosition(); + if (mStyle == tsNone) + return; + + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return; + case tsPlus: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); + painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); + } + break; + } + case tsCrosshair: + { + if (center.y() > clip.top() && center.y() < clip.bottom()) + painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); + if (center.x() > clip.left() && center.x() < clip.right()) + painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); + break; + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawEllipse(center, w, w); + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); + break; + } + } +} + +/*! + If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a + position to reside on the graph data, depending on the configured key (\ref setGraphKey). + + It is called automatically on every redraw and normally doesn't need to be called manually. One + exception is when you want to read the tracer coordinates via \a position and are not sure that + the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. + In that situation, call this function before accessing \a position, to make sure you don't get + out-of-date coordinates. + + If there is no graph set on this tracer, this function does nothing. +*/ +void QCPItemTracer::updatePosition() +{ + if (mGraph) + { + if (mParentPlot->hasPlottable(mGraph)) + { + if (mGraph->data()->size() > 1) + { + QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); + QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; + if (mGraphKey <= first->key) + position->setCoords(first->key, first->value); + else if (mGraphKey >= last->key) + position->setCoords(last->key, last->value); + else + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); + if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators + { + QCPGraphDataContainer::const_iterator prevIt = it; + ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before + if (mInterpolating) + { + // interpolate between iterators around mGraphKey: + double slope = 0; + if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) + slope = (it->value-prevIt->value)/(it->key-prevIt->key); + position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); + } else + { + // find iterator with key closest to mGraphKey: + if (mGraphKey < (prevIt->key+it->key)*0.5) + position->setCoords(prevIt->key, prevIt->value); + else + position->setCoords(it->key, it->value); + } + } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) + position->setCoords(it->key, it->value); + } + } else if (mGraph->data()->size() == 1) + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); + position->setCoords(it->key, it->value); + } else + qDebug() << Q_FUNC_INFO << "graph has no data"; + } else + qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemTracer::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemTracer::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-tracer.cpp' */ + + +/* including file 'src/items/item-bracket.cpp', size 10687 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemBracket + \brief A bracket for referencing/highlighting certain parts in the plot. + + \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a left and \a right, which define the span of the bracket. If \a left is + actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the + example image. + + The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket + stretches away from the embraced span, can be controlled with \ref setLength. + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+ + It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine + or QCPItemCurve) or a text label (QCPItemText), to the bracket. +*/ + +/*! + Creates a bracket item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + left(createPosition(QLatin1String("left"))), + right(createPosition(QLatin1String("right"))), + center(createAnchor(QLatin1String("center"), aiCenter)), + mLength(8), + mStyle(bsCalligraphic) +{ + left->setCoords(0, 0); + right->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemBracket::~QCPItemBracket() +{ +} + +/*! + Sets the pen that will be used to draw the bracket. + + Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the + stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use + \ref setLength, which has a similar effect. + + \see setSelectedPen +*/ +void QCPItemBracket::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the bracket when selected + + \see setPen, setSelected +*/ +void QCPItemBracket::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the \a length in pixels how far the bracket extends in the direction towards the embraced + span of the bracket (i.e. perpendicular to the left-right-direction) + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+*/ +void QCPItemBracket::setLength(double length) +{ + mLength = length; +} + +/*! + Sets the style of the bracket, i.e. the shape/visual appearance. + + \see setPen +*/ +void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) +{ + mStyle = style; +} + +/* inherits documentation from base class */ +double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QCPVector2D p(pos); + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return -1; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (mStyle) + { + case QCPItemBracket::bsSquare: + case QCPItemBracket::bsRound: + { + double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); + double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); + return qSqrt(qMin(qMin(a, b), c)); + } + case QCPItemBracket::bsCurly: + case QCPItemBracket::bsCalligraphic: + { + double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); + double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); + return qSqrt(qMin(qMin(a, b), qMin(c, d))); + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemBracket::draw(QCPPainter *painter) +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + QPolygon boundingPoly; + boundingPoly << leftVec.toPoint() << rightVec.toPoint() + << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (clip.intersects(boundingPoly.boundingRect())) + { + painter->setPen(mainPen()); + switch (mStyle) + { + case bsSquare: + { + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + break; + } + case bsRound: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCurly: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCalligraphic: + { + painter->setPen(Qt::NoPen); + painter->setBrush(QBrush(mainPen().color())); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); + path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + + painter->drawPath(path); + break; + } + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return leftVec.toPointF(); + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (anchorId) + { + case aiCenter: + return centerVec.toPointF(); + } + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemBracket::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-bracket.cpp' */ + + diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h new file mode 100644 index 00000000..278fbf82 --- /dev/null +++ b/src/qt/qcustomplot.h @@ -0,0 +1,6662 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#ifndef QCUSTOMPLOT_H +#define QCUSTOMPLOT_H + +#include + +// some Qt version/configuration dependent macros to include or exclude certain code paths: +#ifdef QCUSTOMPLOT_USE_OPENGL +# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +# define QCP_OPENGL_PBUFFER +# else +# define QCP_OPENGL_FBO +# endif +# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) +# define QCP_OPENGL_OFFSCREENSURFACE +# endif +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +# define QCP_DEVICEPIXELRATIO_SUPPORTED +# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) +# define QCP_DEVICEPIXELRATIO_FLOAT +# endif +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef QCP_OPENGL_FBO +# include +# include +# ifdef QCP_OPENGL_OFFSCREENSURFACE +# include +# else +# include +# endif +#endif +#ifdef QCP_OPENGL_PBUFFER +# include +#endif +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +# include +# include +# include +# include +#else +# include +# include +# include +#endif + +class QCPPainter; +class QCustomPlot; +class QCPLayerable; +class QCPLayoutElement; +class QCPLayout; +class QCPAxis; +class QCPAxisRect; +class QCPAxisPainterPrivate; +class QCPAbstractPlottable; +class QCPGraph; +class QCPAbstractItem; +class QCPPlottableInterface1D; +class QCPLegend; +class QCPItemPosition; +class QCPLayer; +class QCPAbstractLegendItem; +class QCPSelectionRect; +class QCPColorMap; +class QCPColorScale; +class QCPBars; + +/* including file 'src/global.h', size 16225 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +// decl definitions for shared library compilation/usage: +#if defined(QCUSTOMPLOT_COMPILE_LIBRARY) +# define QCP_LIB_DECL Q_DECL_EXPORT +#elif defined(QCUSTOMPLOT_USE_LIBRARY) +# define QCP_LIB_DECL Q_DECL_IMPORT +#else +# define QCP_LIB_DECL +#endif + +// define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5) +#ifndef Q_DECL_OVERRIDE +# define Q_DECL_OVERRIDE +#endif + +/*! + The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot + library. + + It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. +*/ +#ifndef Q_MOC_RUN +namespace QCP { +#else +class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace + Q_GADGET + Q_ENUMS(ExportPen) + Q_ENUMS(ResolutionUnit) + Q_ENUMS(SignDomain) + Q_ENUMS(MarginSide) + Q_FLAGS(MarginSides) + Q_ENUMS(AntialiasedElement) + Q_FLAGS(AntialiasedElements) + Q_ENUMS(PlottingHint) + Q_FLAGS(PlottingHints) + Q_ENUMS(Interaction) + Q_FLAGS(Interactions) + Q_ENUMS(SelectionRectMode) + Q_ENUMS(SelectionType) +public: +#endif + +/*! + Defines the different units in which the image resolution can be specified in the export + functions. + + \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered +*/ +enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) + ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) + ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) + }; + +/*! + Defines how cosmetic pens (pens with numerical width 0) are handled during export. + + \see QCustomPlot::savePdf +*/ +enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting + ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) + }; + +/*! + Represents negative and positive sign domain, e.g. for passing to \ref + QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange. + + This is primarily needed when working with logarithmic axis scales, since only one of the sign + domains can be visible at a time. +*/ +enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero + ,sdBoth ///< Both sign domains, including zero, i.e. all numbers + ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero + }; + +/*! + Defines the sides of a rectangular entity to which margins can be applied. + + \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins +*/ +enum MarginSide { msLeft = 0x01 ///< 0x01 left margin + ,msRight = 0x02 ///< 0x02 right margin + ,msTop = 0x04 ///< 0x04 top margin + ,msBottom = 0x08 ///< 0x08 bottom margin + ,msAll = 0xFF ///< 0xFF all margins + ,msNone = 0x00 ///< 0x00 no margin + }; +Q_DECLARE_FLAGS(MarginSides, MarginSide) + +/*! + Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is + neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective + element how it is drawn. Typically it provides a \a setAntialiased function for this. + + \c AntialiasedElements is a flag of or-combined elements of this enum type. + + \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements +*/ +enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks + ,aeGrid = 0x0002 ///< 0x0002 Grid lines + ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines + ,aeLegend = 0x0008 ///< 0x0008 Legend box + ,aeLegendItems = 0x0010 ///< 0x0010 Legend items + ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables + ,aeItems = 0x0040 ///< 0x0040 Main lines of items + ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) + ,aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) + ,aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen + ,aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories + ,aeAll = 0xFFFF ///< 0xFFFF All elements + ,aeNone = 0x0000 ///< 0x0000 No elements + }; +Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) + +/*! + Defines plotting hints that control various aspects of the quality and speed of plotting. + + \see QCustomPlot::setPlottingHints +*/ +enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set + ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment + ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. + ,phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. + ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). + ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. + }; +Q_DECLARE_FLAGS(PlottingHints, PlottingHint) + +/*! + Defines the mouse interactions possible with QCustomPlot. + + \c Interactions is a flag of or-combined elements of this enum type. + + \see QCustomPlot::setInteractions +*/ +enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) + ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) + ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking + ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) + ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) + ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) + ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) + ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) + }; +Q_DECLARE_FLAGS(Interactions, Interaction) + +/*! + Defines the behaviour of the selection rect. + + \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect +*/ +enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging + ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. + ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) + ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. + }; + +/*! + Defines the different ways a plottable can be selected. These images show the effect of the + different selection types, when the indicated selection rect was dragged: + +
+ + + + + + + + +
\image html selectiontype-none.png stNone\image html selectiontype-whole.png stWhole\image html selectiontype-singledata.png stSingleData\image html selectiontype-datarange.png stDataRange\image html selectiontype-multipledataranges.png stMultipleDataRanges
+
+ + \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType +*/ +enum SelectionType { stNone ///< The plottable is not selectable + ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. + ,stSingleData ///< One individual data point can be selected at a time + ,stDataRange ///< Multiple contiguous data points (a data range) can be selected + ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected + }; + +/*! \internal + + Returns whether the specified \a value is considered an invalid data value for plottables (i.e. + is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the + compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. +*/ +inline bool isInvalidData(double value) +{ + return qIsNaN(value) || qIsInf(value); +} + +/*! \internal + \overload + + Checks two arguments instead of one. +*/ +inline bool isInvalidData(double value1, double value2) +{ + return isInvalidData(value1) || isInvalidData(value2); +} + +/*! \internal + + Sets the specified \a side of \a margins to \a value + + \see getMarginValue +*/ +inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) +{ + switch (side) + { + case QCP::msLeft: margins.setLeft(value); break; + case QCP::msRight: margins.setRight(value); break; + case QCP::msTop: margins.setTop(value); break; + case QCP::msBottom: margins.setBottom(value); break; + case QCP::msAll: margins = QMargins(value, value, value, value); break; + default: break; + } +} + +/*! \internal + + Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or + \ref QCP::msAll, returns 0. + + \see setMarginValue +*/ +inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return margins.left(); + case QCP::msRight: return margins.right(); + case QCP::msTop: return margins.top(); + case QCP::msBottom: return margins.bottom(); + default: break; + } + return 0; +} + + +extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace + +} // end of namespace QCP +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) +Q_DECLARE_METATYPE(QCP::ExportPen) +Q_DECLARE_METATYPE(QCP::ResolutionUnit) +Q_DECLARE_METATYPE(QCP::SignDomain) +Q_DECLARE_METATYPE(QCP::MarginSide) +Q_DECLARE_METATYPE(QCP::AntialiasedElement) +Q_DECLARE_METATYPE(QCP::PlottingHint) +Q_DECLARE_METATYPE(QCP::Interaction) +Q_DECLARE_METATYPE(QCP::SelectionRectMode) +Q_DECLARE_METATYPE(QCP::SelectionType) + +/* end of 'src/global.h' */ + + +/* including file 'src/vector2d.h', size 4928 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPVector2D +{ +public: + QCPVector2D(); + QCPVector2D(double x, double y); + QCPVector2D(const QPoint &point); + QCPVector2D(const QPointF &point); + + // getters: + double x() const { return mX; } + double y() const { return mY; } + double &rx() { return mX; } + double &ry() { return mY; } + + // setters: + void setX(double x) { mX = x; } + void setY(double y) { mY = y; } + + // non-virtual methods: + double length() const { return qSqrt(mX*mX+mY*mY); } + double lengthSquared() const { return mX*mX+mY*mY; } + QPoint toPoint() const { return QPoint(mX, mY); } + QPointF toPointF() const { return QPointF(mX, mY); } + + bool isNull() const { return qIsNull(mX) && qIsNull(mY); } + void normalize(); + QCPVector2D normalized() const; + QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); } + double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; } + double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const; + double distanceSquaredToLine(const QLineF &line) const; + double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const; + + QCPVector2D &operator*=(double factor); + QCPVector2D &operator/=(double divisor); + QCPVector2D &operator+=(const QCPVector2D &vector); + QCPVector2D &operator-=(const QCPVector2D &vector); + +private: + // property members: + double mX, mY; + + friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec); + friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor); + friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor); + friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2); + friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2); + friend inline const QCPVector2D operator-(const QCPVector2D &vec); +}; +Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE); + +inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } +inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } +inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); } +inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); } +inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); } +inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); } + +/*! \relates QCPVector2D + + Prints \a vec in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPVector2D &vec) +{ + d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; + return d.space(); +} + +/* end of 'src/vector2d.h' */ + + +/* including file 'src/painter.h', size 4035 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPPainter : public QPainter +{ + Q_GADGET +public: + /*! + Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, + depending on whether they are wanted on the respective output device. + */ + enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices + ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. + ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels + ,pmNonCosmetic = 0x04 ///< 0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.) + }; + Q_ENUMS(PainterMode) + Q_FLAGS(PainterModes) + Q_DECLARE_FLAGS(PainterModes, PainterMode) + + QCPPainter(); + explicit QCPPainter(QPaintDevice *device); + + // getters: + bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } + PainterModes modes() const { return mModes; } + + // setters: + void setAntialiasing(bool enabled); + void setMode(PainterMode mode, bool enabled=true); + void setModes(PainterModes modes); + + // methods hiding non-virtual base class functions (QPainter bug workarounds): + bool begin(QPaintDevice *device); + void setPen(const QPen &pen); + void setPen(const QColor &color); + void setPen(Qt::PenStyle penStyle); + void drawLine(const QLineF &line); + void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} + void save(); + void restore(); + + // non-virtual methods: + void makeNonCosmetic(); + +protected: + // property members: + PainterModes mModes; + bool mIsAntialiasing; + + // non-property members: + QStack mAntialiasingStack; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) +Q_DECLARE_METATYPE(QCPPainter::PainterMode) + +/* end of 'src/painter.h' */ + + +/* including file 'src/paintbuffer.h', size 4958 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAbstractPaintBuffer +{ +public: + explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio); + virtual ~QCPAbstractPaintBuffer(); + + // getters: + QSize size() const { return mSize; } + bool invalidated() const { return mInvalidated; } + double devicePixelRatio() const { return mDevicePixelRatio; } + + // setters: + void setSize(const QSize &size); + void setInvalidated(bool invalidated=true); + void setDevicePixelRatio(double ratio); + + // introduced virtual methods: + virtual QCPPainter *startPainting() = 0; + virtual void donePainting() {} + virtual void draw(QCPPainter *painter) const = 0; + virtual void clear(const QColor &color) = 0; + +protected: + // property members: + QSize mSize; + double mDevicePixelRatio; + + // non-property members: + bool mInvalidated; + + // introduced virtual methods: + virtual void reallocateBuffer() = 0; +}; + + +class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio); + virtual ~QCPPaintBufferPixmap(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QPixmap mBuffer; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; + + +#ifdef QCP_OPENGL_PBUFFER +class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples); + virtual ~QCPPaintBufferGlPbuffer(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QGLPixelBuffer *mGlPBuffer; + int mMultisamples; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer +{ +public: + explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice); + virtual ~QCPPaintBufferGlFbo(); + + // reimplemented virtual methods: + virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual void donePainting() Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; + void clear(const QColor &color) Q_DECL_OVERRIDE; + +protected: + // non-property members: + QWeakPointer mGlContext; + QWeakPointer mGlPaintDevice; + QOpenGLFramebufferObject *mGlFrameBuffer; + + // reimplemented virtual methods: + virtual void reallocateBuffer() Q_DECL_OVERRIDE; +}; +#endif // QCP_OPENGL_FBO + +/* end of 'src/paintbuffer.h' */ + + +/* including file 'src/layer.h', size 6885 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPLayer : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) + Q_PROPERTY(QString name READ name) + Q_PROPERTY(int index READ index) + Q_PROPERTY(QList children READ children) + Q_PROPERTY(bool visible READ visible WRITE setVisible) + Q_PROPERTY(LayerMode mode READ mode WRITE setMode) + /// \endcond +public: + + /*! + Defines the different rendering modes of a layer. Depending on the mode, certain layers can be + replotted individually, without the need to replot (possibly complex) layerables on other + layers. + + \see setMode + */ + enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. + ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). + }; + Q_ENUMS(LayerMode) + + QCPLayer(QCustomPlot* parentPlot, const QString &layerName); + virtual ~QCPLayer(); + + // getters: + QCustomPlot *parentPlot() const { return mParentPlot; } + QString name() const { return mName; } + int index() const { return mIndex; } + QList children() const { return mChildren; } + bool visible() const { return mVisible; } + LayerMode mode() const { return mMode; } + + // setters: + void setVisible(bool visible); + void setMode(LayerMode mode); + + // non-virtual methods: + void replot(); + +protected: + // property members: + QCustomPlot *mParentPlot; + QString mName; + int mIndex; + QList mChildren; + bool mVisible; + LayerMode mMode; + + // non-property members: + QWeakPointer mPaintBuffer; + + // non-virtual methods: + void draw(QCPPainter *painter); + void drawToPaintBuffer(); + void addChild(QCPLayerable *layerable, bool prepend); + void removeChild(QCPLayerable *layerable); + +private: + Q_DISABLE_COPY(QCPLayer) + + friend class QCustomPlot; + friend class QCPLayerable; +}; +Q_DECLARE_METATYPE(QCPLayer::LayerMode) + +class QCP_LIB_DECL QCPLayerable : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool visible READ visible WRITE setVisible) + Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) + Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) + Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) + Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) + /// \endcond +public: + QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0); + virtual ~QCPLayerable(); + + // getters: + bool visible() const { return mVisible; } + QCustomPlot *parentPlot() const { return mParentPlot; } + QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } + QCPLayer *layer() const { return mLayer; } + bool antialiased() const { return mAntialiased; } + + // setters: + void setVisible(bool on); + Q_SLOT bool setLayer(QCPLayer *layer); + bool setLayer(const QString &layerName); + void setAntialiased(bool enabled); + + // introduced virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; + + // non-property methods: + bool realVisibility() const; + +signals: + void layerChanged(QCPLayer *newLayer); + +protected: + // property members: + bool mVisible; + QCustomPlot *mParentPlot; + QPointer mParentLayerable; + QCPLayer *mLayer; + bool mAntialiased; + + // introduced virtual methods: + virtual void parentPlotInitialized(QCustomPlot *parentPlot); + virtual QCP::Interaction selectionCategory() const; + virtual QRect clipRect() const; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; + virtual void draw(QCPPainter *painter) = 0; + // selection events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); + virtual void deselectEvent(bool *selectionStateChanged); + // low-level mouse events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details); + virtual void wheelEvent(QWheelEvent *event); + + // non-property methods: + void initializeParentPlot(QCustomPlot *parentPlot); + void setParentLayerable(QCPLayerable* parentLayerable); + bool moveToLayer(QCPLayer *layer, bool prepend); + void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; + +private: + Q_DISABLE_COPY(QCPLayerable) + + friend class QCustomPlot; + friend class QCPLayer; + friend class QCPAxisRect; +}; + +/* end of 'src/layer.h' */ + + +/* including file 'src/axis/range.h', size 5280 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPRange +{ +public: + double lower, upper; + + QCPRange(); + QCPRange(double lower, double upper); + + bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; } + bool operator!=(const QCPRange& other) const { return !(*this == other); } + + QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } + QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } + QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } + QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } + friend inline const QCPRange operator+(const QCPRange&, double); + friend inline const QCPRange operator+(double, const QCPRange&); + friend inline const QCPRange operator-(const QCPRange& range, double value); + friend inline const QCPRange operator*(const QCPRange& range, double value); + friend inline const QCPRange operator*(double value, const QCPRange& range); + friend inline const QCPRange operator/(const QCPRange& range, double value); + + double size() const { return upper-lower; } + double center() const { return (upper+lower)*0.5; } + void normalize() { if (lower > upper) qSwap(lower, upper); } + void expand(const QCPRange &otherRange); + void expand(double includeCoord); + QCPRange expanded(const QCPRange &otherRange) const; + QCPRange expanded(double includeCoord) const; + QCPRange bounded(double lowerBound, double upperBound) const; + QCPRange sanitizedForLogScale() const; + QCPRange sanitizedForLinScale() const; + bool contains(double value) const { return value >= lower && value <= upper; } + + static bool validRange(double lower, double upper); + static bool validRange(const QCPRange &range); + static const double minRange; + static const double maxRange; + +}; +Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); + +/*! \relates QCPRange + + Prints \a range in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPRange &range) +{ + d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; + return d.space(); +} + +/*! + Adds \a value to both boundaries of the range. +*/ +inline const QCPRange operator+(const QCPRange& range, double value) +{ + QCPRange result(range); + result += value; + return result; +} + +/*! + Adds \a value to both boundaries of the range. +*/ +inline const QCPRange operator+(double value, const QCPRange& range) +{ + QCPRange result(range); + result += value; + return result; +} + +/*! + Subtracts \a value from both boundaries of the range. +*/ +inline const QCPRange operator-(const QCPRange& range, double value) +{ + QCPRange result(range); + result -= value; + return result; +} + +/*! + Multiplies both boundaries of the range by \a value. +*/ +inline const QCPRange operator*(const QCPRange& range, double value) +{ + QCPRange result(range); + result *= value; + return result; +} + +/*! + Multiplies both boundaries of the range by \a value. +*/ +inline const QCPRange operator*(double value, const QCPRange& range) +{ + QCPRange result(range); + result *= value; + return result; +} + +/*! + Divides both boundaries of the range by \a value. +*/ +inline const QCPRange operator/(const QCPRange& range, double value) +{ + QCPRange result(range); + result /= value; + return result; +} + +/* end of 'src/axis/range.h' */ + + +/* including file 'src/selection.h', size 8579 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPDataRange +{ +public: + QCPDataRange(); + QCPDataRange(int begin, int end); + + bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; } + bool operator!=(const QCPDataRange& other) const { return !(*this == other); } + + // getters: + int begin() const { return mBegin; } + int end() const { return mEnd; } + int size() const { return mEnd-mBegin; } + int length() const { return size(); } + + // setters: + void setBegin(int begin) { mBegin = begin; } + void setEnd(int end) { mEnd = end; } + + // non-property methods: + bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); } + bool isEmpty() const { return length() == 0; } + QCPDataRange bounded(const QCPDataRange &other) const; + QCPDataRange expanded(const QCPDataRange &other) const; + QCPDataRange intersection(const QCPDataRange &other) const; + QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); } + bool intersects(const QCPDataRange &other) const; + bool contains(const QCPDataRange &other) const; + +private: + // property members: + int mBegin, mEnd; + +}; +Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE); + + +class QCP_LIB_DECL QCPDataSelection +{ +public: + explicit QCPDataSelection(); + explicit QCPDataSelection(const QCPDataRange &range); + + bool operator==(const QCPDataSelection& other) const; + bool operator!=(const QCPDataSelection& other) const { return !(*this == other); } + QCPDataSelection &operator+=(const QCPDataSelection& other); + QCPDataSelection &operator+=(const QCPDataRange& other); + QCPDataSelection &operator-=(const QCPDataSelection& other); + QCPDataSelection &operator-=(const QCPDataRange& other); + friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b); + friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b); + friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b); + + // getters: + int dataRangeCount() const { return mDataRanges.size(); } + int dataPointCount() const; + QCPDataRange dataRange(int index=0) const; + QList dataRanges() const { return mDataRanges; } + QCPDataRange span() const; + + // non-property methods: + void addDataRange(const QCPDataRange &dataRange, bool simplify=true); + void clear(); + bool isEmpty() const { return mDataRanges.isEmpty(); } + void simplify(); + void enforceType(QCP::SelectionType type); + bool contains(const QCPDataSelection &other) const; + QCPDataSelection intersection(const QCPDataRange &other) const; + QCPDataSelection intersection(const QCPDataSelection &other) const; + QCPDataSelection inverse(const QCPDataRange &outerRange) const; + +private: + // property members: + QList mDataRanges; + + inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); } +}; +Q_DECLARE_METATYPE(QCPDataSelection) + + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. + The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). +*/ +inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result += b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! + Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. +*/ +inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b) +{ + QCPDataSelection result(a); + result -= b; + return result; +} + +/*! \relates QCPDataRange + + Prints \a dataRange in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) +{ + d.nospace() << "[" << dataRange.begin() << ".." << dataRange.end()-1 << "]"; + return d.space(); +} + +/*! \relates QCPDataSelection + + Prints \a selection in a human readable format to the qDebug output. +*/ +inline QDebug operator<< (QDebug d, const QCPDataSelection &selection) +{ + d.nospace() << "QCPDataSelection("; + for (int i=0; i elements(QCP::MarginSide side) const { return mChildren.value(side); } + bool isEmpty() const; + void clear(); + +protected: + // non-property members: + QCustomPlot *mParentPlot; + QHash > mChildren; + + // introduced virtual methods: + virtual int commonMargin(QCP::MarginSide side) const; + + // non-virtual methods: + void addChild(QCP::MarginSide side, QCPLayoutElement *element); + void removeChild(QCP::MarginSide side, QCPLayoutElement *element); + +private: + Q_DISABLE_COPY(QCPMarginGroup) + + friend class QCPLayoutElement; +}; + + +class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPLayout* layout READ layout) + Q_PROPERTY(QRect rect READ rect) + Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) + Q_PROPERTY(QMargins margins READ margins WRITE setMargins) + Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) + Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) + Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) + Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect) + /// \endcond +public: + /*! + Defines the phases of the update process, that happens just before a replot. At each phase, + \ref update is called with the according UpdatePhase value. + */ + enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout + ,upMargins ///< Phase in which the margins are calculated and set + ,upLayout ///< Final phase in which the layout system places the rects of the elements + }; + Q_ENUMS(UpdatePhase) + + /*! + Defines to which rect of a layout element the size constraints that can be set via \ref + setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the + margins (e.g. in the case of a QCPAxisRect the axis labels), whereas the inner rect (\ref rect) + does not. + + \see setSizeConstraintRect + */ + enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect + , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins + }; + Q_ENUMS(SizeConstraintRect) + + explicit QCPLayoutElement(QCustomPlot *parentPlot=0); + virtual ~QCPLayoutElement(); + + // getters: + QCPLayout *layout() const { return mParentLayout; } + QRect rect() const { return mRect; } + QRect outerRect() const { return mOuterRect; } + QMargins margins() const { return mMargins; } + QMargins minimumMargins() const { return mMinimumMargins; } + QCP::MarginSides autoMargins() const { return mAutoMargins; } + QSize minimumSize() const { return mMinimumSize; } + QSize maximumSize() const { return mMaximumSize; } + SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; } + QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } + QHash marginGroups() const { return mMarginGroups; } + + // setters: + void setOuterRect(const QRect &rect); + void setMargins(const QMargins &margins); + void setMinimumMargins(const QMargins &margins); + void setAutoMargins(QCP::MarginSides sides); + void setMinimumSize(const QSize &size); + void setMinimumSize(int width, int height); + void setMaximumSize(const QSize &size); + void setMaximumSize(int width, int height); + void setSizeConstraintRect(SizeConstraintRect constraintRect); + void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); + + // introduced virtual methods: + virtual void update(UpdatePhase phase); + virtual QSize minimumOuterSizeHint() const; + virtual QSize maximumOuterSizeHint() const; + virtual QList elements(bool recursive) const; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + +protected: + // property members: + QCPLayout *mParentLayout; + QSize mMinimumSize, mMaximumSize; + SizeConstraintRect mSizeConstraintRect; + QRect mRect, mOuterRect; + QMargins mMargins, mMinimumMargins; + QCP::MarginSides mAutoMargins; + QHash mMarginGroups; + + // introduced virtual methods: + virtual int calculateAutoMargin(QCP::MarginSide side); + virtual void layoutChanged(); + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) } + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) } + virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPLayoutElement) + + friend class QCustomPlot; + friend class QCPLayout; + friend class QCPMarginGroup; +}; +Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase) + + +class QCP_LIB_DECL QCPLayout : public QCPLayoutElement +{ + Q_OBJECT +public: + explicit QCPLayout(); + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual int elementCount() const = 0; + virtual QCPLayoutElement* elementAt(int index) const = 0; + virtual QCPLayoutElement* takeAt(int index) = 0; + virtual bool take(QCPLayoutElement* element) = 0; + virtual void simplify(); + + // non-virtual methods: + bool removeAt(int index); + bool remove(QCPLayoutElement* element); + void clear(); + +protected: + // introduced virtual methods: + virtual void updateLayout(); + + // non-virtual methods: + void sizeConstraintsChanged() const; + void adoptElement(QCPLayoutElement *el); + void releaseElement(QCPLayoutElement *el); + QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const; + static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el); + static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el); + +private: + Q_DISABLE_COPY(QCPLayout) + friend class QCPLayoutElement; +}; + + +class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(int rowCount READ rowCount) + Q_PROPERTY(int columnCount READ columnCount) + Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) + Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder) + Q_PROPERTY(int wrap READ wrap WRITE setWrap) + /// \endcond +public: + + /*! + Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*). + The column/row at which wrapping into the next row/column occurs can be specified with \ref + setWrap. + + \see setFillOrder + */ + enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. + ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. + }; + Q_ENUMS(FillOrder) + + explicit QCPLayoutGrid(); + virtual ~QCPLayoutGrid(); + + // getters: + int rowCount() const { return mElements.size(); } + int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } + QList columnStretchFactors() const { return mColumnStretchFactors; } + QList rowStretchFactors() const { return mRowStretchFactors; } + int columnSpacing() const { return mColumnSpacing; } + int rowSpacing() const { return mRowSpacing; } + int wrap() const { return mWrap; } + FillOrder fillOrder() const { return mFillOrder; } + + // setters: + void setColumnStretchFactor(int column, double factor); + void setColumnStretchFactors(const QList &factors); + void setRowStretchFactor(int row, double factor); + void setRowStretchFactors(const QList &factors); + void setColumnSpacing(int pixels); + void setRowSpacing(int pixels); + void setWrap(int count); + void setFillOrder(FillOrder order, bool rearrange=true); + + // reimplemented virtual methods: + virtual void updateLayout() Q_DECL_OVERRIDE; + virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); } + virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; + virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + virtual void simplify() Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; + + // non-virtual methods: + QCPLayoutElement *element(int row, int column) const; + bool addElement(int row, int column, QCPLayoutElement *element); + bool addElement(QCPLayoutElement *element); + bool hasElement(int row, int column); + void expandTo(int newRowCount, int newColumnCount); + void insertRow(int newIndex); + void insertColumn(int newIndex); + int rowColToIndex(int row, int column) const; + void indexToRowCol(int index, int &row, int &column) const; + +protected: + // property members: + QList > mElements; + QList mColumnStretchFactors; + QList mRowStretchFactors; + int mColumnSpacing, mRowSpacing; + int mWrap; + FillOrder mFillOrder; + + // non-virtual methods: + void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; + void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; + +private: + Q_DISABLE_COPY(QCPLayoutGrid) +}; +Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) + + +class QCP_LIB_DECL QCPLayoutInset : public QCPLayout +{ + Q_OBJECT +public: + /*! + Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. + */ + enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect + ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment + }; + Q_ENUMS(InsetPlacement) + + explicit QCPLayoutInset(); + virtual ~QCPLayoutInset(); + + // getters: + InsetPlacement insetPlacement(int index) const; + Qt::Alignment insetAlignment(int index) const; + QRectF insetRect(int index) const; + + // setters: + void setInsetPlacement(int index, InsetPlacement placement); + void setInsetAlignment(int index, Qt::Alignment alignment); + void setInsetRect(int index, const QRectF &rect); + + // reimplemented virtual methods: + virtual void updateLayout() Q_DECL_OVERRIDE; + virtual int elementCount() const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; + virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; + virtual void simplify() Q_DECL_OVERRIDE {} + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void addElement(QCPLayoutElement *element, Qt::Alignment alignment); + void addElement(QCPLayoutElement *element, const QRectF &rect); + +protected: + // property members: + QList mElements; + QList mInsetPlacement; + QList mInsetAlignment; + QList mInsetRect; + +private: + Q_DISABLE_COPY(QCPLayoutInset) +}; +Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement) + +/* end of 'src/layout.h' */ + + +/* including file 'src/lineending.h', size 4426 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPLineEnding +{ + Q_GADGET +public: + /*! + Defines the type of ending decoration for line-like items, e.g. an arrow. + + \image html QCPLineEnding.png + + The width and length of these decorations can be controlled with the functions \ref setWidth + and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only + support a width, the length property is ignored. + + \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding + */ + enum EndingStyle { esNone ///< No ending decoration + ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) + ,esSpikeArrow ///< A filled arrow head with an indented back + ,esLineArrow ///< A non-filled arrow head with open back + ,esDisc ///< A filled circle + ,esSquare ///< A filled square + ,esDiamond ///< A filled diamond (45 degrees rotated square) + ,esBar ///< A bar perpendicular to the line + ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) + ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) + }; + Q_ENUMS(EndingStyle) + + QCPLineEnding(); + QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); + + // getters: + EndingStyle style() const { return mStyle; } + double width() const { return mWidth; } + double length() const { return mLength; } + bool inverted() const { return mInverted; } + + // setters: + void setStyle(EndingStyle style); + void setWidth(double width); + void setLength(double length); + void setInverted(bool inverted); + + // non-property methods: + double boundingDistance() const; + double realLength() const; + void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const; + void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const; + +protected: + // property members: + EndingStyle mStyle; + double mWidth, mLength; + bool mInverted; +}; +Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle) + +/* end of 'src/lineending.h' */ + + +/* including file 'src/axis/axisticker.h', size 4177 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines the strategies that the axis ticker may follow when choosing the size of the tick step. + + \see setTickStepStrategy + */ + enum TickStepStrategy + { + tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) + ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count + }; + Q_ENUMS(TickStepStrategy) + + QCPAxisTicker(); + virtual ~QCPAxisTicker(); + + // getters: + TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; } + int tickCount() const { return mTickCount; } + double tickOrigin() const { return mTickOrigin; } + + // setters: + void setTickStepStrategy(TickStepStrategy strategy); + void setTickCount(int count); + void setTickOrigin(double origin); + + // introduced virtual methods: + virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels); + +protected: + // property members: + TickStepStrategy mTickStepStrategy; + int mTickCount; + double mTickOrigin; + + // introduced virtual methods: + virtual double getTickStep(const QCPRange &range); + virtual int getSubTickCount(double tickStep); + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision); + virtual QVector createTickVector(double tickStep, const QCPRange &range); + virtual QVector createSubTickVector(int subTickCount, const QVector &ticks); + virtual QVector createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision); + + // non-virtual methods: + void trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const; + double pickClosest(double target, const QVector &candidates) const; + double getMantissa(double input, double *magnitude=0) const; + double cleanMantissa(double input) const; +}; +Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy) +Q_DECLARE_METATYPE(QSharedPointer) + +/* end of 'src/axis/axisticker.h' */ + + +/* including file 'src/axis/axistickerdatetime.h', size 3289 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker +{ +public: + QCPAxisTickerDateTime(); + + // getters: + QString dateTimeFormat() const { return mDateTimeFormat; } + Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } + + // setters: + void setDateTimeFormat(const QString &format); + void setDateTimeSpec(Qt::TimeSpec spec); + void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) + void setTickOrigin(const QDateTime &origin); + + // static methods: + static QDateTime keyToDateTime(double key); + static double dateTimeToKey(const QDateTime dateTime); + static double dateTimeToKey(const QDate date); + +protected: + // property members: + QString mDateTimeFormat; + Qt::TimeSpec mDateTimeSpec; + + // non-property members: + enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; +}; + +/* end of 'src/axis/axistickerdatetime.h' */ + + +/* including file 'src/axis/axistickertime.h', size 3542 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines the logical units in which fractions of time spans can be expressed. + + \see setFieldWidth, setTimeFormat + */ + enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) + ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat) + ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat) + ,tuHours ///< Hours (%%h in \ref setTimeFormat) + ,tuDays ///< Days (%%d in \ref setTimeFormat) + }; + Q_ENUMS(TimeUnit) + + QCPAxisTickerTime(); + + // getters: + QString timeFormat() const { return mTimeFormat; } + int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); } + + // setters: + void setTimeFormat(const QString &format); + void setFieldWidth(TimeUnit unit, int width); + +protected: + // property members: + QString mTimeFormat; + QHash mFieldWidth; + + // non-property members: + TimeUnit mSmallestUnit, mBiggestUnit; + QHash mFormatPattern; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + + // non-virtual methods: + void replaceUnit(QString &text, TimeUnit unit, int value) const; +}; +Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit) + +/* end of 'src/axis/axistickertime.h' */ + + +/* including file 'src/axis/axistickerfixed.h', size 3308 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines how the axis ticker may modify the specified tick step (\ref setTickStep) in order to + control the number of ticks in the axis range. + + \see setScaleStrategy + */ + enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. + ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. + ,ssPowers ///< An integer power of the specified tick step is allowed. + }; + Q_ENUMS(ScaleStrategy) + + QCPAxisTickerFixed(); + + // getters: + double tickStep() const { return mTickStep; } + ScaleStrategy scaleStrategy() const { return mScaleStrategy; } + + // setters: + void setTickStep(double step); + void setScaleStrategy(ScaleStrategy strategy); + +protected: + // property members: + double mTickStep; + ScaleStrategy mScaleStrategy; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; +}; +Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy) + +/* end of 'src/axis/axistickerfixed.h' */ + + +/* including file 'src/axis/axistickertext.h', size 3085 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker +{ +public: + QCPAxisTickerText(); + + // getters: + QMap &ticks() { return mTicks; } + int subTickCount() const { return mSubTickCount; } + + // setters: + void setTicks(const QMap &ticks); + void setTicks(const QVector &positions, const QVector labels); + void setSubTickCount(int subTicks); + + // non-virtual methods: + void clear(); + void addTick(double position, QString label); + void addTicks(const QMap &ticks); + void addTicks(const QVector &positions, const QVector &labels); + +protected: + // property members: + QMap mTicks; + int mSubTickCount; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; + +}; + +/* end of 'src/axis/axistickertext.h' */ + + +/* including file 'src/axis/axistickerpi.h', size 3911 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker +{ + Q_GADGET +public: + /*! + Defines how fractions should be displayed in tick labels. + + \see setFractionStyle + */ + enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". + ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" + ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. + }; + Q_ENUMS(FractionStyle) + + QCPAxisTickerPi(); + + // getters: + QString piSymbol() const { return mPiSymbol; } + double piValue() const { return mPiValue; } + bool periodicity() const { return mPeriodicity; } + FractionStyle fractionStyle() const { return mFractionStyle; } + + // setters: + void setPiSymbol(QString symbol); + void setPiValue(double pi); + void setPeriodicity(int multiplesOfPi); + void setFractionStyle(FractionStyle style); + +protected: + // property members: + QString mPiSymbol; + double mPiValue; + int mPeriodicity; + FractionStyle mFractionStyle; + + // non-property members: + double mPiTickStep; // size of one tick step in units of mPiValue + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; + + // non-virtual methods: + void simplifyFraction(int &numerator, int &denominator) const; + QString fractionToString(int numerator, int denominator) const; + QString unicodeFraction(int numerator, int denominator) const; + QString unicodeSuperscript(int number) const; + QString unicodeSubscript(int number) const; +}; +Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle) + +/* end of 'src/axis/axistickerpi.h' */ + + +/* including file 'src/axis/axistickerlog.h', size 2663 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker +{ +public: + QCPAxisTickerLog(); + + // getters: + double logBase() const { return mLogBase; } + int subTickCount() const { return mSubTickCount; } + + // setters: + void setLogBase(double base); + void setSubTickCount(int subTicks); + +protected: + // property members: + double mLogBase; + int mSubTickCount; + + // non-property members: + double mLogBaseLnInv; + + // reimplemented virtual methods: + virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; + virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; +}; + +/* end of 'src/axis/axistickerlog.h' */ + + +/* including file 'src/axis/axis.h', size 20634 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPGrid :public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) + Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) + Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) + Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) + /// \endcond +public: + explicit QCPGrid(QCPAxis *parentAxis); + + // getters: + bool subGridVisible() const { return mSubGridVisible; } + bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } + bool antialiasedZeroLine() const { return mAntialiasedZeroLine; } + QPen pen() const { return mPen; } + QPen subGridPen() const { return mSubGridPen; } + QPen zeroLinePen() const { return mZeroLinePen; } + + // setters: + void setSubGridVisible(bool visible); + void setAntialiasedSubGrid(bool enabled); + void setAntialiasedZeroLine(bool enabled); + void setPen(const QPen &pen); + void setSubGridPen(const QPen &pen); + void setZeroLinePen(const QPen &pen); + +protected: + // property members: + bool mSubGridVisible; + bool mAntialiasedSubGrid, mAntialiasedZeroLine; + QPen mPen, mSubGridPen, mZeroLinePen; + + // non-property members: + QCPAxis *mParentAxis; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + void drawGridLines(QCPPainter *painter) const; + void drawSubGridLines(QCPPainter *painter) const; + + friend class QCPAxis; +}; + + +class QCP_LIB_DECL QCPAxis : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(AxisType axisType READ axisType) + Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) + Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) + Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) + Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) + Q_PROPERTY(QSharedPointer ticker READ ticker WRITE setTicker) + Q_PROPERTY(bool ticks READ ticks WRITE setTicks) + Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) + Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) + Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) + Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) + Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) + Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide) + Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) + Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) + Q_PROPERTY(QVector tickVector READ tickVector) + Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels) + Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) + Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) + Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks) + Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) + Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) + Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) + Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) + Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) + Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) + Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) + Q_PROPERTY(QString label READ label WRITE setLabel) + Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) + Q_PROPERTY(int padding READ padding WRITE setPadding) + Q_PROPERTY(int offset READ offset WRITE setOffset) + Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) + Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) + Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) + Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) + Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) + Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) + Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) + Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) + Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) + Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) + Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) + Q_PROPERTY(QCPGrid* grid READ grid) + /// \endcond +public: + /*! + Defines at which side of the axis rect the axis will appear. This also affects how the tick + marks are drawn, on which side the labels are placed etc. + */ + enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect + ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect + ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect + ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect + }; + Q_ENUMS(AxisType) + Q_FLAGS(AxisTypes) + Q_DECLARE_FLAGS(AxisTypes, AxisType) + /*! + Defines on which side of the axis the tick labels (numbers) shall appear. + + \see setTickLabelSide + */ + enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect + ,lsOutside ///< Tick labels will be displayed outside the axis rect + }; + Q_ENUMS(LabelSide) + /*! + Defines the scale of an axis. + \see setScaleType + */ + enum ScaleType { stLinear ///< Linear scaling + ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). + }; + Q_ENUMS(ScaleType) + /*! + Defines the selectable parts of an axis. + \see setSelectableParts, setSelectedParts + */ + enum SelectablePart { spNone = 0 ///< None of the selectable parts + ,spAxis = 0x001 ///< The axis backbone and tick marks + ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) + ,spAxisLabel = 0x004 ///< The axis label + }; + Q_ENUMS(SelectablePart) + Q_FLAGS(SelectableParts) + Q_DECLARE_FLAGS(SelectableParts, SelectablePart) + + explicit QCPAxis(QCPAxisRect *parent, AxisType type); + virtual ~QCPAxis(); + + // getters: + AxisType axisType() const { return mAxisType; } + QCPAxisRect *axisRect() const { return mAxisRect; } + ScaleType scaleType() const { return mScaleType; } + const QCPRange range() const { return mRange; } + bool rangeReversed() const { return mRangeReversed; } + QSharedPointer ticker() const { return mTicker; } + bool ticks() const { return mTicks; } + bool tickLabels() const { return mTickLabels; } + int tickLabelPadding() const; + QFont tickLabelFont() const { return mTickLabelFont; } + QColor tickLabelColor() const { return mTickLabelColor; } + double tickLabelRotation() const; + LabelSide tickLabelSide() const; + QString numberFormat() const; + int numberPrecision() const { return mNumberPrecision; } + QVector tickVector() const { return mTickVector; } + QVector tickVectorLabels() const { return mTickVectorLabels; } + int tickLengthIn() const; + int tickLengthOut() const; + bool subTicks() const { return mSubTicks; } + int subTickLengthIn() const; + int subTickLengthOut() const; + QPen basePen() const { return mBasePen; } + QPen tickPen() const { return mTickPen; } + QPen subTickPen() const { return mSubTickPen; } + QFont labelFont() const { return mLabelFont; } + QColor labelColor() const { return mLabelColor; } + QString label() const { return mLabel; } + int labelPadding() const; + int padding() const { return mPadding; } + int offset() const; + SelectableParts selectedParts() const { return mSelectedParts; } + SelectableParts selectableParts() const { return mSelectableParts; } + QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; } + QFont selectedLabelFont() const { return mSelectedLabelFont; } + QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; } + QColor selectedLabelColor() const { return mSelectedLabelColor; } + QPen selectedBasePen() const { return mSelectedBasePen; } + QPen selectedTickPen() const { return mSelectedTickPen; } + QPen selectedSubTickPen() const { return mSelectedSubTickPen; } + QCPLineEnding lowerEnding() const; + QCPLineEnding upperEnding() const; + QCPGrid *grid() const { return mGrid; } + + // setters: + Q_SLOT void setScaleType(QCPAxis::ScaleType type); + Q_SLOT void setRange(const QCPRange &range); + void setRange(double lower, double upper); + void setRange(double position, double size, Qt::AlignmentFlag alignment); + void setRangeLower(double lower); + void setRangeUpper(double upper); + void setRangeReversed(bool reversed); + void setTicker(QSharedPointer ticker); + void setTicks(bool show); + void setTickLabels(bool show); + void setTickLabelPadding(int padding); + void setTickLabelFont(const QFont &font); + void setTickLabelColor(const QColor &color); + void setTickLabelRotation(double degrees); + void setTickLabelSide(LabelSide side); + void setNumberFormat(const QString &formatCode); + void setNumberPrecision(int precision); + void setTickLength(int inside, int outside=0); + void setTickLengthIn(int inside); + void setTickLengthOut(int outside); + void setSubTicks(bool show); + void setSubTickLength(int inside, int outside=0); + void setSubTickLengthIn(int inside); + void setSubTickLengthOut(int outside); + void setBasePen(const QPen &pen); + void setTickPen(const QPen &pen); + void setSubTickPen(const QPen &pen); + void setLabelFont(const QFont &font); + void setLabelColor(const QColor &color); + void setLabel(const QString &str); + void setLabelPadding(int padding); + void setPadding(int padding); + void setOffset(int offset); + void setSelectedTickLabelFont(const QFont &font); + void setSelectedLabelFont(const QFont &font); + void setSelectedTickLabelColor(const QColor &color); + void setSelectedLabelColor(const QColor &color); + void setSelectedBasePen(const QPen &pen); + void setSelectedTickPen(const QPen &pen); + void setSelectedSubTickPen(const QPen &pen); + Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); + void setLowerEnding(const QCPLineEnding &ending); + void setUpperEnding(const QCPLineEnding &ending); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-property methods: + Qt::Orientation orientation() const { return mOrientation; } + int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; } + void moveRange(double diff); + void scaleRange(double factor); + void scaleRange(double factor, double center); + void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); + void rescale(bool onlyVisiblePlottables=false); + double pixelToCoord(double value) const; + double coordToPixel(double value) const; + SelectablePart getPartAt(const QPointF &pos) const; + QList plottables() const; + QList graphs() const; + QList items() const; + + static AxisType marginSideToAxisType(QCP::MarginSide side); + static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } + static AxisType opposite(AxisType type); + +signals: + void rangeChanged(const QCPRange &newRange); + void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); + void scaleTypeChanged(QCPAxis::ScaleType scaleType); + void selectionChanged(const QCPAxis::SelectableParts &parts); + void selectableChanged(const QCPAxis::SelectableParts &parts); + +protected: + // property members: + // axis base: + AxisType mAxisType; + QCPAxisRect *mAxisRect; + //int mOffset; // in QCPAxisPainter + int mPadding; + Qt::Orientation mOrientation; + SelectableParts mSelectableParts, mSelectedParts; + QPen mBasePen, mSelectedBasePen; + //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter + // axis label: + //int mLabelPadding; // in QCPAxisPainter + QString mLabel; + QFont mLabelFont, mSelectedLabelFont; + QColor mLabelColor, mSelectedLabelColor; + // tick labels: + //int mTickLabelPadding; // in QCPAxisPainter + bool mTickLabels; + //double mTickLabelRotation; // in QCPAxisPainter + QFont mTickLabelFont, mSelectedTickLabelFont; + QColor mTickLabelColor, mSelectedTickLabelColor; + int mNumberPrecision; + QLatin1Char mNumberFormatChar; + bool mNumberBeautifulPowers; + //bool mNumberMultiplyCross; // QCPAxisPainter + // ticks and subticks: + bool mTicks; + bool mSubTicks; + //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter + QPen mTickPen, mSelectedTickPen; + QPen mSubTickPen, mSelectedSubTickPen; + // scale and range: + QCPRange mRange; + bool mRangeReversed; + ScaleType mScaleType; + + // non-property members: + QCPGrid *mGrid; + QCPAxisPainterPrivate *mAxisPainter; + QSharedPointer mTicker; + QVector mTickVector; + QVector mTickVectorLabels; + QVector mSubTickVector; + bool mCachedMarginValid; + int mCachedMargin; + bool mDragging; + QCPRange mDragStartRange; + QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; + + // introduced virtual methods: + virtual int calculateMargin(); + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + // mouse events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); + virtual void wheelEvent(QWheelEvent *event); + + // non-virtual methods: + void setupTickVectors(); + QPen getBasePen() const; + QPen getTickPen() const; + QPen getSubTickPen() const; + QFont getTickLabelFont() const; + QFont getLabelFont() const; + QColor getTickLabelColor() const; + QColor getLabelColor() const; + +private: + Q_DISABLE_COPY(QCPAxis) + + friend class QCustomPlot; + friend class QCPGrid; + friend class QCPAxisRect; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) +Q_DECLARE_METATYPE(QCPAxis::AxisType) +Q_DECLARE_METATYPE(QCPAxis::LabelSide) +Q_DECLARE_METATYPE(QCPAxis::ScaleType) +Q_DECLARE_METATYPE(QCPAxis::SelectablePart) + + +class QCPAxisPainterPrivate +{ +public: + explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); + virtual ~QCPAxisPainterPrivate(); + + virtual void draw(QCPPainter *painter); + virtual int size() const; + void clearCache(); + + QRect axisSelectionBox() const { return mAxisSelectionBox; } + QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } + QRect labelSelectionBox() const { return mLabelSelectionBox; } + + // public property members: + QCPAxis::AxisType type; + QPen basePen; + QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters + int labelPadding; // directly accessed by QCPAxis setters/getters + QFont labelFont; + QColor labelColor; + QString label; + int tickLabelPadding; // directly accessed by QCPAxis setters/getters + double tickLabelRotation; // directly accessed by QCPAxis setters/getters + QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters + bool substituteExponent; + bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters + int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters + QPen tickPen, subTickPen; + QFont tickLabelFont; + QColor tickLabelColor; + QRect axisRect, viewportRect; + double offset; // directly accessed by QCPAxis setters/getters + bool abbreviateDecimalPowers; + bool reversedEndings; + + QVector subTickPositions; + QVector tickPositions; + QVector tickLabels; + +protected: + struct CachedLabel + { + QPointF offset; + QPixmap pixmap; + }; + struct TickLabelData + { + QString basePart, expPart, suffixPart; + QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds; + QFont baseFont, expFont; + }; + QCustomPlot *mParentPlot; + QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters + QCache mLabelCache; + QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; + + virtual QByteArray generateLabelParameterHash() const; + + virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); + virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; + virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; + virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; + virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; +}; + +/* end of 'src/axis/axis.h' */ + + +/* including file 'src/scatterstyle.h', size 7275 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPScatterStyle +{ + Q_GADGET +public: + /*! + Represents the various properties of a scatter style instance. For example, this enum is used + to specify which properties of \ref QCPSelectionDecorator::setScatterStyle will be used when + highlighting selected data points. + + Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref + setFromOther. + */ + enum ScatterProperty { spNone = 0x00 ///< 0x00 None + ,spPen = 0x01 ///< 0x01 The pen property, see \ref setPen + ,spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush + ,spSize = 0x04 ///< 0x04 The size property, see \ref setSize + ,spShape = 0x08 ///< 0x08 The shape property, see \ref setShape + ,spAll = 0xFF ///< 0xFF All properties + }; + Q_ENUMS(ScatterProperty) + Q_FLAGS(ScatterProperties) + Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty) + + /*! + Defines the shape used for scatter points. + + On plottables/items that draw scatters, the sizes of these visualizations (with exception of + \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are + drawn with the pen and brush specified with \ref setPen and \ref setBrush. + */ + enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) + ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) + ,ssCross ///< \enumimage{ssCross.png} a cross + ,ssPlus ///< \enumimage{ssPlus.png} a plus + ,ssCircle ///< \enumimage{ssCircle.png} a circle + ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) + ,ssSquare ///< \enumimage{ssSquare.png} a square + ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond + ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus + ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline + ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner + ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside + ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside + ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside + ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside + ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines + ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates + ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) + }; + Q_ENUMS(ScatterShape) + + QCPScatterStyle(); + QCPScatterStyle(ScatterShape shape, double size=6); + QCPScatterStyle(ScatterShape shape, const QColor &color, double size); + QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); + QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); + QCPScatterStyle(const QPixmap &pixmap); + QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); + + // getters: + double size() const { return mSize; } + ScatterShape shape() const { return mShape; } + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QPixmap pixmap() const { return mPixmap; } + QPainterPath customPath() const { return mCustomPath; } + + // setters: + void setFromOther(const QCPScatterStyle &other, ScatterProperties properties); + void setSize(double size); + void setShape(ScatterShape shape); + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setPixmap(const QPixmap &pixmap); + void setCustomPath(const QPainterPath &customPath); + + // non-property methods: + bool isNone() const { return mShape == ssNone; } + bool isPenDefined() const { return mPenDefined; } + void undefinePen(); + void applyTo(QCPPainter *painter, const QPen &defaultPen) const; + void drawShape(QCPPainter *painter, const QPointF &pos) const; + void drawShape(QCPPainter *painter, double x, double y) const; + +protected: + // property members: + double mSize; + ScatterShape mShape; + QPen mPen; + QBrush mBrush; + QPixmap mPixmap; + QPainterPath mCustomPath; + + // non-property members: + bool mPenDefined; +}; +Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties) +Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty) +Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) + +/* end of 'src/scatterstyle.h' */ + + +/* including file 'src/datacontainer.h', size 4596 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +/*! \relates QCPDataContainer + Returns whether the sort key of \a a is less than the sort key of \a b. + + \see QCPDataContainer::sort +*/ +template +inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); } + +template +class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) +{ +public: + typedef typename QVector::const_iterator const_iterator; + typedef typename QVector::iterator iterator; + + QCPDataContainer(); + + // getters: + int size() const { return mData.size()-mPreallocSize; } + bool isEmpty() const { return size() == 0; } + bool autoSqueeze() const { return mAutoSqueeze; } + + // setters: + void setAutoSqueeze(bool enabled); + + // non-virtual methods: + void set(const QCPDataContainer &data); + void set(const QVector &data, bool alreadySorted=false); + void add(const QCPDataContainer &data); + void add(const QVector &data, bool alreadySorted=false); + void add(const DataType &data); + void removeBefore(double sortKey); + void removeAfter(double sortKey); + void remove(double sortKeyFrom, double sortKeyTo); + void remove(double sortKey); + void clear(); + void sort(); + void squeeze(bool preAllocation=true, bool postAllocation=true); + + const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; } + const_iterator constEnd() const { return mData.constEnd(); } + iterator begin() { return mData.begin()+mPreallocSize; } + iterator end() { return mData.end(); } + const_iterator findBegin(double sortKey, bool expandedRange=true) const; + const_iterator findEnd(double sortKey, bool expandedRange=true) const; + const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); } + QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth); + QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()); + QCPDataRange dataRange() const { return QCPDataRange(0, size()); } + void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const; + +protected: + // property members: + bool mAutoSqueeze; + + // non-property memebers: + QVector mData; + int mPreallocSize; + int mPreallocIteration; + + // non-virtual methods: + void preallocateGrow(int minimumPreallocSize); + void performAutoSqueeze(); +}; + +// include implementation in header since it is a class template: + +/* including file 'src/datacontainer.cpp', size 31349 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataContainer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataContainer + \brief The generic data container for one-dimensional plottables + + This class template provides a fast container for data storage of one-dimensional data. The data + type is specified as template parameter (called \a DataType in the following) and must provide + some methods as described in the \ref qcpdatacontainer-datatype "next section". + + The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well + as retrieval of ranges (see \ref findBegin, \ref findEnd, \ref keyRange) using binary search. The + container uses a preallocation and a postallocation scheme, such that appending and prepending + data (with respect to the sort key) is very fast and minimizes reallocations. If data is added + which needs to be inserted between existing keys, the merge usually can be done quickly too, + using the fact that existing data is always sorted. The user can further improve performance by + specifying that added data is already itself sorted by key, if he can guarantee that this is the + case (see for example \ref add(const QVector &data, bool alreadySorted)). + + The data can be accessed with the provided const iterators (\ref constBegin, \ref constEnd). If + it is necessary to alter existing data in-place, the non-const iterators can be used (\ref begin, + \ref end). Changing data members that are not the sort key (for most data types called \a key) is + safe from the container's perspective. + + Great care must be taken however if the sort key is modified through the non-const iterators. For + performance reasons, the iterators don't automatically cause a re-sorting upon their + manipulation. It is thus the responsibility of the user to leave the container in a sorted state + when finished with the data manipulation, before calling any other methods on the container. A + complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling \ref + sort. Failing to do so can not be detected by the container efficiently and will cause both + rendering artifacts and potential data loss. + + Implementing one-dimensional plottables that make use of a \ref QCPDataContainer is usually + done by subclassing from \ref QCPAbstractPlottable1D "QCPAbstractPlottable1D", which + introduces an according \a mDataContainer member and some convenience methods. + + \section qcpdatacontainer-datatype Requirements for the DataType template parameter + + The template parameter DataType is the type of the stored data points. It must be + trivially copyable and have the following public methods, preferably inline: + + \li double sortKey() const\n Returns the member variable of this data point that is the + sort key, defining the ordering in the container. Often this variable is simply called \a key. + + \li static DataType fromSortKey(double sortKey)\n Returns a new instance of the data + type initialized with its sort key set to \a sortKey. + + \li static bool sortKeyIsMainKey()\n Returns true if the sort key is equal to the main + key (see method \c mainKey below). For most plottables this is the case. It is not the case for + example for \ref QCPCurve, which uses \a t as sort key and \a key as main key. This is the reason + why QCPCurve unlike QCPGraph can display parametric curves with loops. + + \li double mainKey() const\n Returns the variable of this data point considered the main + key. This is commonly the variable that is used as the coordinate of this data point on the key + axis of the plottable. This method is used for example when determining the automatic axis + rescaling of key axes (\ref QCPAxis::rescale). + + \li double mainValue() const\n Returns the variable of this data point considered the + main value. This is commonly the variable that is used as the coordinate of this data point on + the value axis of the plottable. + + \li QCPRange valueRange() const\n Returns the range this data point spans in the value + axis coordinate. If the data is single-valued (e.g. QCPGraphData), this is simply a range with + both lower and upper set to the main data point value. However if the data points can represent + multiple values at once (e.g QCPFinancialData with its \a high, \a low, \a open and \a close + values at each \a key) this method should return the range those values span. This method is used + for example when determining the automatic axis rescaling of value axes (\ref + QCPAxis::rescale). +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataContainer::size() const + + Returns the number of data points in the container. +*/ + +/*! \fn bool QCPDataContainer::isEmpty() const + + Returns whether this container holds no data points. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constBegin() const + + Returns a const iterator to the first data point in this container. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constEnd() const + + Returns a const iterator to the element past the last data point in this container. +*/ + +/*! \fn QCPDataContainer::iterator QCPDataContainer::begin() const + + Returns a non-const iterator to the first data point in this container. + + You can manipulate the data points in-place through the non-const iterators, but great care must + be taken when manipulating the sort key of a data point, see \ref sort, or the detailed + description of this class. +*/ + +/*! \fn QCPDataContainer::iterator QCPDataContainer::end() const + + Returns a non-const iterator to the element past the last data point in this container. + + You can manipulate the data points in-place through the non-const iterators, but great care must + be taken when manipulating the sort key of a data point, see \ref sort, or the detailed + description of this class. +*/ + +/*! \fn QCPDataContainer::const_iterator QCPDataContainer::at(int index) const + + Returns a const iterator to the element with the specified \a index. If \a index points beyond + the available elements in this container, returns \ref constEnd, i.e. an iterator past the last + valid element. + + You can use this method to easily obtain iterators from a \ref QCPDataRange, see the \ref + dataselection-accessing "data selection page" for an example. +*/ + +/*! \fn QCPDataRange QCPDataContainer::dataRange() const + + Returns a \ref QCPDataRange encompassing the entire data set of this container. This means the + begin index of the returned range is 0, and the end index is \ref size. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted + data +*/ +template +QCPDataContainer::QCPDataContainer() : + mAutoSqueeze(true), + mPreallocSize(0), + mPreallocIteration(0) +{ +} + +/*! + Sets whether the container automatically decides when to release memory from its post- and + preallocation pools when data points are removed. By default this is enabled and for typical + applications shouldn't be changed. + + If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with + \ref squeeze. +*/ +template +void QCPDataContainer::setAutoSqueeze(bool enabled) +{ + if (mAutoSqueeze != enabled) + { + mAutoSqueeze = enabled; + if (mAutoSqueeze) + performAutoSqueeze(); + } +} + +/*! \overload + + Replaces the current data in this container with the provided \a data. + + \see add, remove +*/ +template +void QCPDataContainer::set(const QCPDataContainer &data) +{ + clear(); + add(data); +} + +/*! \overload + + Replaces the current data in this container with the provided \a data + + If you can guarantee that the data points in \a data have ascending order with respect to the + DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. + + \see add, remove +*/ +template +void QCPDataContainer::set(const QVector &data, bool alreadySorted) +{ + mData = data; + mPreallocSize = 0; + mPreallocIteration = 0; + if (!alreadySorted) + sort(); +} + +/*! \overload + + Adds the provided \a data to the current data in this container. + + \see set, remove +*/ +template +void QCPDataContainer::add(const QCPDataContainer &data) +{ + if (data.isEmpty()) + return; + + const int n = data.size(); + const int oldSize = size(); + + if (oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones + { + if (mPreallocSize < n) + preallocateGrow(n); + mPreallocSize -= n; + std::copy(data.constBegin(), data.constEnd(), begin()); + } else // don't need to prepend, so append and merge if necessary + { + mData.resize(mData.size()+n); + std::copy(data.constBegin(), data.constEnd(), end()-n); + if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + } +} + +/*! + Adds the provided data points in \a data to the current data. + + If you can guarantee that the data points in \a data have ascending order with respect to the + DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. + + \see set, remove +*/ +template +void QCPDataContainer::add(const QVector &data, bool alreadySorted) +{ + if (data.isEmpty()) + return; + if (isEmpty()) + { + set(data, alreadySorted); + return; + } + + const int n = data.size(); + const int oldSize = size(); + + if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones + { + if (mPreallocSize < n) + preallocateGrow(n); + mPreallocSize -= n; + std::copy(data.constBegin(), data.constEnd(), begin()); + } else // don't need to prepend, so append and then sort and merge if necessary + { + mData.resize(mData.size()+n); + std::copy(data.constBegin(), data.constEnd(), end()-n); + if (!alreadySorted) // sort appended subrange if it wasn't already sorted + std::sort(end()-n, end(), qcpLessThanSortKey); + if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + } +} + +/*! \overload + + Adds the provided single data point to the current data. + + \see remove +*/ +template +void QCPDataContainer::add(const DataType &data) +{ + if (isEmpty() || !qcpLessThanSortKey(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones + { + mData.append(data); + } else if (qcpLessThanSortKey(data, *constBegin())) // quickly handle prepends using preallocated space + { + if (mPreallocSize < 1) + preallocateGrow(1); + --mPreallocSize; + *begin() = data; + } else // handle inserts, maintaining sorted keys + { + QCPDataContainer::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey); + mData.insert(insertionPoint, data); + } +} + +/*! + Removes all data points with (sort-)keys smaller than or equal to \a sortKey. + + \see removeAfter, remove, clear +*/ +template +void QCPDataContainer::removeBefore(double sortKey) +{ + QCPDataContainer::iterator it = begin(); + QCPDataContainer::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + mPreallocSize += itEnd-it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points with (sort-)keys greater than or equal to \a sortKey. + + \see removeBefore, remove, clear +*/ +template +void QCPDataContainer::removeAfter(double sortKey) +{ + QCPDataContainer::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + QCPDataContainer::iterator itEnd = end(); + mData.erase(it, itEnd); // typically adds it to the postallocated block + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points with (sort-)keys between \a sortKeyFrom and \a sortKeyTo. if \a + sortKeyFrom is greater or equal to \a sortKeyTo, the function does nothing. To remove a single + data point with known (sort-)key, use \ref remove(double sortKey). + + \see removeBefore, removeAfter, clear +*/ +template +void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) +{ + if (sortKeyFrom >= sortKeyTo || isEmpty()) + return; + + QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey); + QCPDataContainer::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey); + mData.erase(it, itEnd); + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! \overload + + Removes a single data point at \a sortKey. If the position is not known with absolute (binary) + precision, consider using \ref remove(double sortKeyFrom, double sortKeyTo) with a small + fuzziness interval around the suspected position, depeding on the precision with which the + (sort-)key is known. + + \see removeBefore, removeAfter, clear +*/ +template +void QCPDataContainer::remove(double sortKey) +{ + QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (it != end() && it->sortKey() == sortKey) + { + if (it == begin()) + ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + else + mData.erase(it); + } + if (mAutoSqueeze) + performAutoSqueeze(); +} + +/*! + Removes all data points. + + \see remove, removeAfter, removeBefore +*/ +template +void QCPDataContainer::clear() +{ + mData.clear(); + mPreallocIteration = 0; + mPreallocSize = 0; +} + +/*! + Re-sorts all data points in the container by their sort key. + + When setting, adding or removing points using the QCPDataContainer interface (\ref set, \ref add, + \ref remove, etc.), the container makes sure to always stay in a sorted state such that a full + resort is never necessary. However, if you choose to directly manipulate the sort key on data + points by accessing and modifying it through the non-const iterators (\ref begin, \ref end), it + is your responsibility to bring the container back into a sorted state before any other methods + are called on it. This can be achieved by calling this method immediately after finishing the + sort key manipulation. +*/ +template +void QCPDataContainer::sort() +{ + std::sort(begin(), end(), qcpLessThanSortKey); +} + +/*! + Frees all unused memory that is currently in the preallocation and postallocation pools. + + Note that QCPDataContainer automatically decides whether squeezing is necessary, if \ref + setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical + applications. + + The parameters \a preAllocation and \a postAllocation control whether pre- and/or post allocation + should be freed, respectively. +*/ +template +void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation) +{ + if (preAllocation) + { + if (mPreallocSize > 0) + { + std::copy(begin(), end(), mData.begin()); + mData.resize(size()); + mPreallocSize = 0; + } + mPreallocIteration = 0; + } + if (postAllocation) + mData.squeeze(); +} + +/*! + Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just + above \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be + considered, otherwise the one just above. + + This can be used in conjunction with \ref findEnd to iterate over data points within a given key + range, including or excluding the bounding data points that are just beyond the specified range. + + If \a expandedRange is true but there are no data points below \a sortKey, \ref constBegin is + returned. + + If the container is empty, returns \ref constEnd. + + \see findEnd, QCPPlottableInterface1D::findBegin +*/ +template +typename QCPDataContainer::const_iterator QCPDataContainer::findBegin(double sortKey, bool expandedRange) const +{ + if (isEmpty()) + return constEnd(); + + QCPDataContainer::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty + --it; + return it; +} + +/*! + Returns an iterator to the element after the data point with a (sort-)key that is equal to, just + above or just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey + will be considered, otherwise the one just below. + + This can be used in conjunction with \ref findBegin to iterate over data points within a given + key range, including the bounding data points that are just below and above the specified range. + + If \a expandedRange is true but there are no data points above \a sortKey, \ref constEnd is + returned. + + If the container is empty, \ref constEnd is returned. + + \see findBegin, QCPPlottableInterface1D::findEnd +*/ +template +typename QCPDataContainer::const_iterator QCPDataContainer::findEnd(double sortKey, bool expandedRange) const +{ + if (isEmpty()) + return constEnd(); + + QCPDataContainer::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + if (expandedRange && it != constEnd()) + ++it; + return it; +} + +/*! + Returns the range encompassed by the (main-)key coordinate of all data points. The output + parameter \a foundRange indicates whether a sensible range was found. If this is false, you + should not use the returned QCPRange (e.g. the data container is empty or all points have the + same key). + + Use \a signDomain to control which sign of the key coordinates should be considered. This is + relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a + time. + + If the DataType reports that its main key is equal to the sort key (\a sortKeyIsMainKey), as is + the case for most plottables, this method uses this fact and finds the range very quickly. + + \see valueRange +*/ +template +QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain signDomain) +{ + if (isEmpty()) + { + foundRange = false; + return QCPRange(); + } + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + double current; + + QCPDataContainer::const_iterator it = constBegin(); + QCPDataContainer::const_iterator itEnd = constEnd(); + if (signDomain == QCP::sdBoth) // range may be anywhere + { + if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value + { + while (it != itEnd) // find first non-nan going up from left + { + if (!qIsNaN(it->mainValue())) + { + range.lower = it->mainKey(); + haveLower = true; + break; + } + ++it; + } + it = itEnd; + while (it != constBegin()) // find first non-nan going down from right + { + --it; + if (!qIsNaN(it->mainValue())) + { + range.upper = it->mainKey(); + haveUpper = true; + break; + } + } + } else // DataType is not sorted by main key, go through all data points and accordingly expand range + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } + } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if ((current < range.lower || !haveLower) && current < 0) + { + range.lower = current; + haveLower = true; + } + if ((current > range.upper || !haveUpper) && current < 0) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain + { + while (it != itEnd) + { + if (!qIsNaN(it->mainValue())) + { + current = it->mainKey(); + if ((current < range.lower || !haveLower) && current > 0) + { + range.lower = current; + haveLower = true; + } + if ((current > range.upper || !haveUpper) && current > 0) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! + Returns the range encompassed by the value coordinates of the data points in the specified key + range (\a inKeyRange), using the full \a DataType::valueRange reported by the data points. The + output parameter \a foundRange indicates whether a sensible range was found. If this is false, + you should not use the returned QCPRange (e.g. the data container is empty or all points have the + same value). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Use \a signDomain to control which sign of the value coordinates should be considered. This is + relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a + time. + + \see keyRange +*/ +template +QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange) +{ + if (isEmpty()) + { + foundRange = false; + return QCPRange(); + } + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPRange current; + QCPDataContainer::const_iterator itBegin = constBegin(); + QCPDataContainer::const_iterator itEnd = constEnd(); + if (DataType::sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = findBegin(inKeyRange.lower); + itEnd = findEnd(inKeyRange.upper); + } + if (signDomain == QCP::sdBoth) // range may be anywhere + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain + { + for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + continue; + current = it->valueRange(); + if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper)) + { + range.upper = current.upper; + haveUpper = true; + } + } + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! + Makes sure \a begin and \a end mark a data range that is both within the bounds of this data + container's data, as well as within the specified \a dataRange. The initial range described by + the passed iterators \a begin and \a end is never expanded, only contracted if necessary. + + This function doesn't require for \a dataRange to be within the bounds of this data container's + valid range. +*/ +template +void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const +{ + QCPDataRange iteratorRange(begin-constBegin(), end-constBegin()); + iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); + begin = constBegin()+iteratorRange.begin(); + end = constBegin()+iteratorRange.end(); +} + +/*! \internal + + Increases the preallocation pool to have a size of at least \a minimumPreallocSize. Depending on + the preallocation history, the container will grow by more than requested, to speed up future + consecutive size increases. + + if \a minimumPreallocSize is smaller than or equal to the current preallocation pool size, this + method does nothing. +*/ +template +void QCPDataContainer::preallocateGrow(int minimumPreallocSize) +{ + if (minimumPreallocSize <= mPreallocSize) + return; + + int newPreallocSize = minimumPreallocSize; + newPreallocSize += (1u< +void QCPDataContainer::performAutoSqueeze() +{ + const int totalAlloc = mData.capacity(); + const int postAllocSize = totalAlloc-mData.size(); + const int usedSize = size(); + bool shrinkPostAllocation = false; + bool shrinkPreAllocation = false; + if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size + { + shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! + shrinkPreAllocation = mPreallocSize*10 > usedSize; + } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother + { + shrinkPostAllocation = postAllocSize > usedSize*5; + shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller + } + + if (shrinkPreAllocation || shrinkPostAllocation) + squeeze(shrinkPreAllocation, shrinkPostAllocation); +} +/* end of 'src/datacontainer.cpp' */ + + +/* end of 'src/datacontainer.h' */ + + +/* including file 'src/plottable.h', size 8312 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPSelectionDecorator +{ + Q_GADGET +public: + QCPSelectionDecorator(); + virtual ~QCPSelectionDecorator(); + + // getters: + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; } + + // setters: + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen); + void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties); + + // non-virtual methods: + void applyPen(QCPPainter *painter) const; + void applyBrush(QCPPainter *painter) const; + QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const; + + // introduced virtual methods: + virtual void copyFrom(const QCPSelectionDecorator *other); + virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection); + +protected: + // property members: + QPen mPen; + QBrush mBrush; + QCPScatterStyle mScatterStyle; + QCPScatterStyle::ScatterProperties mUsedScatterProperties; + // non-property members: + QCPAbstractPlottable *mPlottable; + + // introduced virtual methods: + virtual bool registerWithPlottable(QCPAbstractPlottable *plottable); + +private: + Q_DISABLE_COPY(QCPSelectionDecorator) + friend class QCPAbstractPlottable; +}; +Q_DECLARE_METATYPE(QCPSelectionDecorator*) + + +class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) + Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) + Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) + Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged) + Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator) + /// \endcond +public: + QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPAbstractPlottable(); + + // getters: + QString name() const { return mName; } + bool antialiasedFill() const { return mAntialiasedFill; } + bool antialiasedScatters() const { return mAntialiasedScatters; } + QPen pen() const { return mPen; } + QBrush brush() const { return mBrush; } + QCPAxis *keyAxis() const { return mKeyAxis.data(); } + QCPAxis *valueAxis() const { return mValueAxis.data(); } + QCP::SelectionType selectable() const { return mSelectable; } + bool selected() const { return !mSelection.isEmpty(); } + QCPDataSelection selection() const { return mSelection; } + QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; } + + // setters: + void setName(const QString &name); + void setAntialiasedFill(bool enabled); + void setAntialiasedScatters(bool enabled); + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setKeyAxis(QCPAxis *axis); + void setValueAxis(QCPAxis *axis); + Q_SLOT void setSelectable(QCP::SelectionType selectable); + Q_SLOT void setSelection(QCPDataSelection selection); + void setSelectionDecorator(QCPSelectionDecorator *decorator); + + // introduced virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; + virtual QCPPlottableInterface1D *interface1D() { return 0; } + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0; + + // non-property methods: + void coordsToPixels(double key, double value, double &x, double &y) const; + const QPointF coordsToPixels(double key, double value) const; + void pixelsToCoords(double x, double y, double &key, double &value) const; + void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; + void rescaleAxes(bool onlyEnlarge=false) const; + void rescaleKeyAxis(bool onlyEnlarge=false) const; + void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const; + bool addToLegend(QCPLegend *legend); + bool addToLegend(); + bool removeFromLegend(QCPLegend *legend) const; + bool removeFromLegend() const; + +signals: + void selectionChanged(bool selected); + void selectionChanged(const QCPDataSelection &selection); + void selectableChanged(QCP::SelectionType selectable); + +protected: + // property members: + QString mName; + bool mAntialiasedFill, mAntialiasedScatters; + QPen mPen; + QBrush mBrush; + QPointer mKeyAxis, mValueAxis; + QCP::SelectionType mSelectable; + QCPDataSelection mSelection; + QCPSelectionDecorator *mSelectionDecorator; + + // reimplemented virtual methods: + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; + + // non-virtual methods: + void applyFillAntialiasingHint(QCPPainter *painter) const; + void applyScattersAntialiasingHint(QCPPainter *painter) const; + +private: + Q_DISABLE_COPY(QCPAbstractPlottable) + + friend class QCustomPlot; + friend class QCPAxis; + friend class QCPPlottableLegendItem; +}; + + +/* end of 'src/plottable.h' */ + + +/* including file 'src/item.h', size 9384 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemAnchor +{ + Q_GADGET +public: + QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1); + virtual ~QCPItemAnchor(); + + // getters: + QString name() const { return mName; } + virtual QPointF pixelPosition() const; + +protected: + // property members: + QString mName; + + // non-property members: + QCustomPlot *mParentPlot; + QCPAbstractItem *mParentItem; + int mAnchorId; + QSet mChildrenX, mChildrenY; + + // introduced virtual methods: + virtual QCPItemPosition *toQCPItemPosition() { return 0; } + + // non-virtual methods: + void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent + void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted + void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent + void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted + +private: + Q_DISABLE_COPY(QCPItemAnchor) + + friend class QCPItemPosition; +}; + + + +class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor +{ + Q_GADGET +public: + /*! + Defines the ways an item position can be specified. Thus it defines what the numbers passed to + \ref setCoords actually mean. + + \see setType + */ + enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. + ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the viewport/widget, etc. + ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. + ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). + }; + Q_ENUMS(PositionType) + + QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name); + virtual ~QCPItemPosition(); + + // getters: + PositionType type() const { return typeX(); } + PositionType typeX() const { return mPositionTypeX; } + PositionType typeY() const { return mPositionTypeY; } + QCPItemAnchor *parentAnchor() const { return parentAnchorX(); } + QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; } + QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; } + double key() const { return mKey; } + double value() const { return mValue; } + QPointF coords() const { return QPointF(mKey, mValue); } + QCPAxis *keyAxis() const { return mKeyAxis.data(); } + QCPAxis *valueAxis() const { return mValueAxis.data(); } + QCPAxisRect *axisRect() const; + virtual QPointF pixelPosition() const Q_DECL_OVERRIDE; + + // setters: + void setType(PositionType type); + void setTypeX(PositionType type); + void setTypeY(PositionType type); + bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); + void setCoords(double key, double value); + void setCoords(const QPointF &coords); + void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); + void setAxisRect(QCPAxisRect *axisRect); + void setPixelPosition(const QPointF &pixelPosition); + +protected: + // property members: + PositionType mPositionTypeX, mPositionTypeY; + QPointer mKeyAxis, mValueAxis; + QPointer mAxisRect; + double mKey, mValue; + QCPItemAnchor *mParentAnchorX, *mParentAnchorY; + + // reimplemented virtual methods: + virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } + +private: + Q_DISABLE_COPY(QCPItemPosition) + +}; +Q_DECLARE_METATYPE(QCPItemPosition::PositionType) + + +class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) + Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + /// \endcond +public: + explicit QCPAbstractItem(QCustomPlot *parentPlot); + virtual ~QCPAbstractItem(); + + // getters: + bool clipToAxisRect() const { return mClipToAxisRect; } + QCPAxisRect *clipAxisRect() const; + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setClipToAxisRect(bool clip); + void setClipAxisRect(QCPAxisRect *rect); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; + + // non-virtual methods: + QList positions() const { return mPositions; } + QList anchors() const { return mAnchors; } + QCPItemPosition *position(const QString &name) const; + QCPItemAnchor *anchor(const QString &name) const; + bool hasAnchor(const QString &name) const; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + +protected: + // property members: + bool mClipToAxisRect; + QPointer mClipAxisRect; + QList mPositions; + QList mAnchors; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual QPointF anchorPixelPosition(int anchorId) const; + + // non-virtual methods: + double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const; + QCPItemPosition *createPosition(const QString &name); + QCPItemAnchor *createAnchor(const QString &name, int anchorId); + +private: + Q_DISABLE_COPY(QCPAbstractItem) + + friend class QCustomPlot; + friend class QCPItemAnchor; +}; + +/* end of 'src/item.h' */ + + +/* including file 'src/core.h', size 14886 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCustomPlot : public QWidget +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) + Q_PROPERTY(QPixmap background READ background WRITE setBackground) + Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) + Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) + Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) + Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) + Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) + Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) + Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) + Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl) + /// \endcond +public: + /*! + Defines how a layer should be inserted relative to an other layer. + + \see addLayer, moveLayer + */ + enum LayerInsertMode { limBelow ///< Layer is inserted below other layer + ,limAbove ///< Layer is inserted above other layer + }; + Q_ENUMS(LayerInsertMode) + + /*! + Defines with what timing the QCustomPlot surface is refreshed after a replot. + + \see replot + */ + enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot + ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. + ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. + ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. + }; + Q_ENUMS(RefreshPriority) + + explicit QCustomPlot(QWidget *parent = 0); + virtual ~QCustomPlot(); + + // getters: + QRect viewport() const { return mViewport; } + double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; } + QPixmap background() const { return mBackgroundPixmap; } + bool backgroundScaled() const { return mBackgroundScaled; } + Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } + QCPLayoutGrid *plotLayout() const { return mPlotLayout; } + QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } + QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } + bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } + const QCP::Interactions interactions() const { return mInteractions; } + int selectionTolerance() const { return mSelectionTolerance; } + bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; } + QCP::PlottingHints plottingHints() const { return mPlottingHints; } + Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } + QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; } + QCPSelectionRect *selectionRect() const { return mSelectionRect; } + bool openGl() const { return mOpenGl; } + + // setters: + void setViewport(const QRect &rect); + void setBufferDevicePixelRatio(double ratio); + void setBackground(const QPixmap &pm); + void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); + void setBackground(const QBrush &brush); + void setBackgroundScaled(bool scaled); + void setBackgroundScaledMode(Qt::AspectRatioMode mode); + void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); + void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); + void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); + void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); + void setAutoAddPlottableToLegend(bool on); + void setInteractions(const QCP::Interactions &interactions); + void setInteraction(const QCP::Interaction &interaction, bool enabled=true); + void setSelectionTolerance(int pixels); + void setNoAntialiasingOnDrag(bool enabled); + void setPlottingHints(const QCP::PlottingHints &hints); + void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); + void setMultiSelectModifier(Qt::KeyboardModifier modifier); + void setSelectionRectMode(QCP::SelectionRectMode mode); + void setSelectionRect(QCPSelectionRect *selectionRect); + void setOpenGl(bool enabled, int multisampling=16); + + // non-property methods: + // plottable interface: + QCPAbstractPlottable *plottable(int index); + QCPAbstractPlottable *plottable(); + bool removePlottable(QCPAbstractPlottable *plottable); + bool removePlottable(int index); + int clearPlottables(); + int plottableCount() const; + QList selectedPlottables() const; + QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; + bool hasPlottable(QCPAbstractPlottable *plottable) const; + + // specialized interface for QCPGraph: + QCPGraph *graph(int index) const; + QCPGraph *graph() const; + QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); + bool removeGraph(QCPGraph *graph); + bool removeGraph(int index); + int clearGraphs(); + int graphCount() const; + QList selectedGraphs() const; + + // item interface: + QCPAbstractItem *item(int index) const; + QCPAbstractItem *item() const; + bool removeItem(QCPAbstractItem *item); + bool removeItem(int index); + int clearItems(); + int itemCount() const; + QList selectedItems() const; + QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; + bool hasItem(QCPAbstractItem *item) const; + + // layer interface: + QCPLayer *layer(const QString &name) const; + QCPLayer *layer(int index) const; + QCPLayer *currentLayer() const; + bool setCurrentLayer(const QString &name); + bool setCurrentLayer(QCPLayer *layer); + int layerCount() const; + bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); + bool removeLayer(QCPLayer *layer); + bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); + + // axis rect/layout interface: + int axisRectCount() const; + QCPAxisRect* axisRect(int index=0) const; + QList axisRects() const; + QCPLayoutElement* layoutElementAt(const QPointF &pos) const; + QCPAxisRect* axisRectAt(const QPointF &pos) const; + Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); + + QList selectedAxes() const; + QList selectedLegends() const; + Q_SLOT void deselectAll(); + + bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); + bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); + QPixmap toPixmap(int width=0, int height=0, double scale=1.0); + void toPainter(QCPPainter *painter, int width=0, int height=0); + Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); + + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + QCPLegend *legend; + +signals: + void mouseDoubleClick(QMouseEvent *event); + void mousePress(QMouseEvent *event); + void mouseMove(QMouseEvent *event); + void mouseRelease(QMouseEvent *event); + void mouseWheel(QWheelEvent *event); + + void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); + void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); + void itemClick(QCPAbstractItem *item, QMouseEvent *event); + void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); + void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); + void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); + void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); + void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); + + void selectionChangedByUser(); + void beforeReplot(); + void afterReplot(); + +protected: + // property members: + QRect mViewport; + double mBufferDevicePixelRatio; + QCPLayoutGrid *mPlotLayout; + bool mAutoAddPlottableToLegend; + QList mPlottables; + QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph + QList mItems; + QList mLayers; + QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; + QCP::Interactions mInteractions; + int mSelectionTolerance; + bool mNoAntialiasingOnDrag; + QBrush mBackgroundBrush; + QPixmap mBackgroundPixmap; + QPixmap mScaledBackgroundPixmap; + bool mBackgroundScaled; + Qt::AspectRatioMode mBackgroundScaledMode; + QCPLayer *mCurrentLayer; + QCP::PlottingHints mPlottingHints; + Qt::KeyboardModifier mMultiSelectModifier; + QCP::SelectionRectMode mSelectionRectMode; + QCPSelectionRect *mSelectionRect; + bool mOpenGl; + + // non-property members: + QList > mPaintBuffers; + QPoint mMousePressPos; + bool mMouseHasMoved; + QPointer mMouseEventLayerable; + QPointer mMouseSignalLayerable; + QVariant mMouseEventLayerableDetails; + QVariant mMouseSignalLayerableDetails; + bool mReplotting; + bool mReplotQueued; + int mOpenGlMultisamples; + QCP::AntialiasedElements mOpenGlAntialiasedElementsBackup; + bool mOpenGlCacheLabelsBackup; +#ifdef QCP_OPENGL_FBO + QSharedPointer mGlContext; + QSharedPointer mGlSurface; + QSharedPointer mGlPaintDevice; +#endif + + // reimplemented virtual methods: + virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; + virtual QSize sizeHint() const Q_DECL_OVERRIDE; + virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void draw(QCPPainter *painter); + virtual void updateLayout(); + virtual void axisRemoved(QCPAxis *axis); + virtual void legendRemoved(QCPLegend *legend); + Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); + Q_SLOT virtual void processPointSelection(QMouseEvent *event); + + // non-virtual methods: + bool registerPlottable(QCPAbstractPlottable *plottable); + bool registerGraph(QCPGraph *graph); + bool registerItem(QCPAbstractItem* item); + void updateLayerIndices() const; + QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; + QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=0) const; + void drawBackground(QCPPainter *painter); + void setupPaintBuffers(); + QCPAbstractPaintBuffer *createPaintBuffer(); + bool hasInvalidatedPaintBuffers(); + bool setupOpenGl(); + void freeOpenGl(); + + friend class QCPLegend; + friend class QCPAxis; + friend class QCPLayer; + friend class QCPAxisRect; + friend class QCPAbstractPlottable; + friend class QCPGraph; + friend class QCPAbstractItem; +}; +Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode) +Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority) + +/* end of 'src/core.h' */ + + +/* including file 'src/plottable1d.h', size 4544 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCPPlottableInterface1D +{ +public: + virtual ~QCPPlottableInterface1D() {} + // introduced pure virtual methods: + virtual int dataCount() const = 0; + virtual double dataMainKey(int index) const = 0; + virtual double dataSortKey(int index) const = 0; + virtual double dataMainValue(int index) const = 0; + virtual QCPRange dataValueRange(int index) const = 0; + virtual QPointF dataPixelPosition(int index) const = 0; + virtual bool sortKeyIsMainKey() const = 0; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; + virtual int findBegin(double sortKey, bool expandedRange=true) const = 0; + virtual int findEnd(double sortKey, bool expandedRange=true) const = 0; +}; + +template +class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) +{ + // No Q_OBJECT macro due to template class + +public: + QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPAbstractPlottable1D(); + + // virtual methods of 1d plottable interface: + virtual int dataCount() const Q_DECL_OVERRIDE; + virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; + virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; + virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } + +protected: + // property members: + QSharedPointer > mDataContainer; + + // helpers for subclasses: + void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; + void drawPolyline(QCPPainter *painter, const QVector &lineData) const; + +private: + Q_DISABLE_COPY(QCPAbstractPlottable1D) + +}; + +// include implementation in header since it is a class template: + +/* including file 'src/plottable1d.cpp', size 22240 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableInterface1D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableInterface1D + \brief Defines an abstract interface for one-dimensional plottables + + This class contains only pure virtual methods which define a common interface to the data + of one-dimensional plottables. + + For example, it is implemented by the template class \ref QCPAbstractPlottable1D (the preferred + base class for one-dimensional plottables). So if you use that template class as base class of + your one-dimensional plottable, you won't have to care about implementing the 1d interface + yourself. + + If your plottable doesn't derive from \ref QCPAbstractPlottable1D but still wants to provide a 1d + interface (e.g. like \ref QCPErrorBars does), you should inherit from both \ref + QCPAbstractPlottable and \ref QCPPlottableInterface1D and accordingly reimplement the pure + virtual methods of the 1d interface, matching your data container. Also, reimplement \ref + QCPAbstractPlottable::interface1D to return the \c this pointer. + + If you have a \ref QCPAbstractPlottable pointer, you can check whether it implements this + interface by calling \ref QCPAbstractPlottable::interface1D and testing it for a non-zero return + value. If it indeed implements this interface, you may use it to access the plottable's data + without needing to know the exact type of the plottable or its data point type. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPPlottableInterface1D::dataCount() const = 0; + + Returns the number of data points of the plottable. +*/ + +/*! \fn virtual QCPDataSelection QCPPlottableInterface1D::selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; + + Returns a data selection containing all the data points of this plottable which are contained (or + hit by) \a rect. This is used mainly in the selection rect interaction for data selection (\ref + dataselection "data selection mechanism"). + + If \a onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not + selectable (i.e. if \ref QCPAbstractPlottable::setSelectable is \ref QCP::stNone). + + \note \a rect must be a normalized rect (positive or zero width and height). This is especially + important when using the rect of \ref QCPSelectionRect::accepted, which is not necessarily + normalized. Use QRect::normalized() when passing a rect which might not be normalized. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataMainKey(int index) const = 0 + + Returns the main key of the data point at the given \a index. + + What the main key is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataSortKey(int index) const = 0 + + Returns the sort key of the data point at the given \a index. + + What the sort key is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual double QCPPlottableInterface1D::dataMainValue(int index) const = 0 + + Returns the main value of the data point at the given \a index. + + What the main value is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual QCPRange QCPPlottableInterface1D::dataValueRange(int index) const = 0 + + Returns the value range of the data point at the given \a index. + + What the value range is, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual QPointF QCPPlottableInterface1D::dataPixelPosition(int index) const = 0 + + Returns the pixel position on the widget surface at which the data point at the given \a index + appears. + + Usually this corresponds to the point of \ref dataMainKey/\ref dataMainValue, in pixel + coordinates. However, depending on the plottable, this might be a different apparent position + than just a coord-to-pixel transform of those values. For example, \ref QCPBars apparent data + values can be shifted depending on their stacking, bar grouping or configured base value. +*/ + +/*! \fn virtual bool QCPPlottableInterface1D::sortKeyIsMainKey() const = 0 + + Returns whether the sort key (\ref dataSortKey) is identical to the main key (\ref dataMainKey). + + What the sort and main keys are, is defined by the plottable's data type. See the \ref + qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming + convention. +*/ + +/*! \fn virtual int QCPPlottableInterface1D::findBegin(double sortKey, bool expandedRange) const = 0 + + Returns the index of the data point with a (sort-)key that is equal to, just below, or just above + \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be considered, + otherwise the one just above. + + This can be used in conjunction with \ref findEnd to iterate over data points within a given key + range, including or excluding the bounding data points that are just beyond the specified range. + + If \a expandedRange is true but there are no data points below \a sortKey, 0 is returned. + + If the container is empty, returns 0 (in that case, \ref findEnd will also return 0, so a loop + using these methods will not iterate over the index 0). + + \see findEnd, QCPDataContainer::findBegin +*/ + +/*! \fn virtual int QCPPlottableInterface1D::findEnd(double sortKey, bool expandedRange) const = 0 + + Returns the index one after the data point with a (sort-)key that is equal to, just above, or + just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey will be + considered, otherwise the one just below. + + This can be used in conjunction with \ref findBegin to iterate over data points within a given + key range, including the bounding data points that are just below and above the specified range. + + If \a expandedRange is true but there are no data points above \a sortKey, the index just above the + highest data point is returned. + + If the container is empty, returns 0. + + \see findBegin, QCPDataContainer::findEnd +*/ + +/* end documentation of pure virtual functions */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable1D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable1D + \brief A template base class for plottables with one-dimensional data + + This template class derives from \ref QCPAbstractPlottable and from the abstract interface \ref + QCPPlottableInterface1D. It serves as a base class for all one-dimensional data (i.e. data with + one key dimension), such as \ref QCPGraph and QCPCurve. + + The template parameter \a DataType is the type of the data points of this plottable (e.g. \ref + QCPGraphData or \ref QCPCurveData). The main purpose of this base class is to provide the member + \a mDataContainer (a shared pointer to a \ref QCPDataContainer "QCPDataContainer") and + implement the according virtual methods of the \ref QCPPlottableInterface1D, such that most + subclassed plottables don't need to worry about this anymore. + + Further, it provides a convenience method for retrieving selected/unselected data segments via + \ref getDataSegments. This is useful when subclasses implement their \ref draw method and need to + draw selected segments with a different pen/brush than unselected segments (also see \ref + QCPSelectionDecorator). + + This class implements basic functionality of \ref QCPAbstractPlottable::selectTest and \ref + QCPPlottableInterface1D::selectTestRect, assuming point-like data points, based on the 1D data + interface. In spite of that, most plottable subclasses will want to reimplement those methods + again, to provide a more accurate hit test based on their specific data visualization geometry. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPPlottableInterface1D *QCPAbstractPlottable1D::interface1D() + + Returns a \ref QCPPlottableInterface1D pointer to this plottable, providing access to its 1D + interface. + + \seebaseclassmethod +*/ + +/* end documentation of inline functions */ + +/*! + Forwards \a keyAxis and \a valueAxis to the \ref QCPAbstractPlottable::QCPAbstractPlottable + "QCPAbstractPlottable" constructor and allocates the \a mDataContainer. +*/ +template +QCPAbstractPlottable1D::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QCPDataContainer) +{ +} + +template +QCPAbstractPlottable1D::~QCPAbstractPlottable1D() +{ +} + +/*! + \copydoc QCPPlottableInterface1D::dataCount +*/ +template +int QCPAbstractPlottable1D::dataCount() const +{ + return mDataContainer->size(); +} + +/*! + \copydoc QCPPlottableInterface1D::dataMainKey +*/ +template +double QCPAbstractPlottable1D::dataMainKey(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->mainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataSortKey +*/ +template +double QCPAbstractPlottable1D::dataSortKey(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->sortKey(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataMainValue +*/ +template +double QCPAbstractPlottable1D::dataMainValue(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->mainValue(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return 0; + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataValueRange +*/ +template +QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + return (mDataContainer->constBegin()+index)->valueRange(); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QCPRange(0, 0); + } +} + +/*! + \copydoc QCPPlottableInterface1D::dataPixelPosition +*/ +template +QPointF QCPAbstractPlottable1D::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + return coordsToPixels(it->mainKey(), it->mainValue()); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/*! + \copydoc QCPPlottableInterface1D::sortKeyIsMainKey +*/ +template +bool QCPAbstractPlottable1D::sortKeyIsMainKey() const +{ + return DataType::sortKeyIsMainKey(); +} + +/*! + Implements a rect-selection algorithm assuming the data (accessed via the 1D data interface) is + point-like. Most subclasses will want to reimplement this method again, to provide a more + accurate hit test based on the true data visualization geometry. + + \seebaseclassmethod +*/ +template +QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + // convert rect given in pixels to ranges given in plot coordinates: + double key1, value1, key2, value2; + pixelsToCoords(rect.topLeft(), key1, value1); + pixelsToCoords(rect.bottomRight(), key2, value2); + QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 + QCPRange valueRange(value1, value2); + typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); + typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); + if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + { + begin = mDataContainer->findBegin(keyRange.lower, false); + end = mDataContainer->findEnd(keyRange.upper, false); + } + if (begin == end) + return result; + + int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect + for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (currentSegmentBegin == -1) + { + if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment + currentSegmentBegin = it-mDataContainer->constBegin(); + } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended + { + result.addDataRange(QCPDataRange(currentSegmentBegin, it-mDataContainer->constBegin()), false); + currentSegmentBegin = -1; + } + } + // process potential last segment: + if (currentSegmentBegin != -1) + result.addDataRange(QCPDataRange(currentSegmentBegin, end-mDataContainer->constBegin()), false); + + result.simplify(); + return result; +} + +/*! + \copydoc QCPPlottableInterface1D::findBegin +*/ +template +int QCPAbstractPlottable1D::findBegin(double sortKey, bool expandedRange) const +{ + return mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin(); +} + +/*! + \copydoc QCPPlottableInterface1D::findEnd +*/ +template +int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange) const +{ + return mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin(); +} + +/*! + Implements a point-selection algorithm assuming the data (accessed via the 1D data interface) is + point-like. Most subclasses will want to reimplement this method again, to provide a more + accurate hit test based on the true data visualization geometry. + + \seebaseclassmethod +*/ +template +double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + QCPDataSelection selectionResult; + double minDistSqr = std::numeric_limits::max(); + int minDistIndex = mDataContainer->size(); + + typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); + typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); + if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + { + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + begin = mDataContainer->findBegin(posKeyMin, true); + end = mDataContainer->findEnd(posKeyMax, true); + } + if (begin == end) + return -1; + QCPRange keyRange(mKeyAxis->range()); + QCPRange valueRange(mValueAxis->range()); + for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double mainKey = it->mainKey(); + const double mainValue = it->mainValue(); + if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points + { + const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + minDistIndex = it-mDataContainer->constBegin(); + } + } + } + if (minDistIndex != mDataContainer->size()) + selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false); + + selectionResult.simplify(); + if (details) + details->setValue(selectionResult); + return qSqrt(minDistSqr); +} + +/*! + Splits all data into selected and unselected segments and outputs them via \a selectedSegments + and \a unselectedSegments, respectively. + + This is useful when subclasses implement their \ref draw method and need to draw selected + segments with a different pen/brush than unselected segments (also see \ref + QCPSelectionDecorator). + + \see setSelection +*/ +template +void QCPAbstractPlottable1D::getDataSegments(QList &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! + A helper method which draws a line with the passed \a painter, according to the pixel data in \a + lineData. NaN points create gaps in the line, as expected from QCustomPlot's plottables (this is + the main difference to QPainter's regular drawPolyline, which handles NaNs by lagging or + crashing). + + Further it uses a faster line drawing technique based on \ref QCPPainter::drawLine rather than \c + QPainter::drawPolyline if the configured \ref QCustomPlot::setPlottingHints() and \a painter + style allows. +*/ +template +void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const +{ + // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: + if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && + painter->pen().style() == Qt::SolidLine && + !painter->modes().testFlag(QCPPainter::pmVectorized) && + !painter->modes().testFlag(QCPPainter::pmNoCaching)) + { + int i = 0; + bool lastIsNan = false; + const int lineDataSize = lineData.size(); + while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN + ++i; + ++i; // because drawing works in 1 point retrospect + while (i < lineDataSize) + { + if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line + { + if (!lastIsNan) + painter->drawLine(lineData.at(i-1), lineData.at(i)); + else + lastIsNan = false; + } else + lastIsNan = true; + ++i; + } + } else + { + int segmentStart = 0; + int i = 0; + const int lineDataSize = lineData.size(); + while (i < lineDataSize) + { + if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block + { + painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point + segmentStart = i+1; + } + ++i; + } + // draw last segment: + painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart); + } +} +/* end of 'src/plottable1d.cpp' */ + + +/* end of 'src/plottable1d.h' */ + + +/* including file 'src/colorgradient.h', size 6243 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPColorGradient +{ + Q_GADGET +public: + /*! + Defines the color spaces in which color interpolation between gradient stops can be performed. + + \see setColorInterpolation + */ + enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated + ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) + }; + Q_ENUMS(ColorInterpolation) + + /*! + Defines the available presets that can be loaded with \ref loadPreset. See the documentation + there for an image of the presets. + */ + enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) + ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) + ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) + ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) + ,gpCandy ///< Blue over pink to white + ,gpGeography ///< Colors suitable to represent different elevations on geographical maps + ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) + ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white + ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values + ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) + ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) + ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) + }; + Q_ENUMS(GradientPreset) + + QCPColorGradient(); + QCPColorGradient(GradientPreset preset); + bool operator==(const QCPColorGradient &other) const; + bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } + + // getters: + int levelCount() const { return mLevelCount; } + QMap colorStops() const { return mColorStops; } + ColorInterpolation colorInterpolation() const { return mColorInterpolation; } + bool periodic() const { return mPeriodic; } + + // setters: + void setLevelCount(int n); + void setColorStops(const QMap &colorStops); + void setColorStopAt(double position, const QColor &color); + void setColorInterpolation(ColorInterpolation interpolation); + void setPeriodic(bool enabled); + + // non-property methods: + void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); + void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); + QRgb color(double position, const QCPRange &range, bool logarithmic=false); + void loadPreset(GradientPreset preset); + void clearColorStops(); + QCPColorGradient inverted() const; + +protected: + // property members: + int mLevelCount; + QMap mColorStops; + ColorInterpolation mColorInterpolation; + bool mPeriodic; + + // non-property members: + QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) + bool mColorBufferInvalidated; + + // non-virtual methods: + bool stopsUseAlpha() const; + void updateColorBuffer(); +}; +Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) +Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) + +/* end of 'src/colorgradient.h' */ + + +/* including file 'src/selectiondecorator-bracket.h', size 4442 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator +{ + Q_GADGET +public: + + /*! + Defines which shape is drawn at the boundaries of selected data ranges. + + Some of the bracket styles further allow specifying a height and/or width, see \ref + setBracketHeight and \ref setBracketWidth. + */ + enum BracketStyle { bsSquareBracket ///< A square bracket is drawn. + ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + ,bsPlus ///< A plus is drawn. + ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. + }; + Q_ENUMS(BracketStyle) + + QCPSelectionDecoratorBracket(); + virtual ~QCPSelectionDecoratorBracket(); + + // getters: + QPen bracketPen() const { return mBracketPen; } + QBrush bracketBrush() const { return mBracketBrush; } + int bracketWidth() const { return mBracketWidth; } + int bracketHeight() const { return mBracketHeight; } + BracketStyle bracketStyle() const { return mBracketStyle; } + bool tangentToData() const { return mTangentToData; } + int tangentAverage() const { return mTangentAverage; } + + // setters: + void setBracketPen(const QPen &pen); + void setBracketBrush(const QBrush &brush); + void setBracketWidth(int width); + void setBracketHeight(int height); + void setBracketStyle(BracketStyle style); + void setTangentToData(bool enabled); + void setTangentAverage(int pointCount); + + // introduced virtual methods: + virtual void drawBracket(QCPPainter *painter, int direction) const; + + // virtual methods: + virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE; + +protected: + // property members: + QPen mBracketPen; + QBrush mBracketBrush; + int mBracketWidth; + int mBracketHeight; + BracketStyle mBracketStyle; + bool mTangentToData; + int mTangentAverage; + + // non-virtual methods: + double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const; + QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const; + +}; +Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle) + +/* end of 'src/selectiondecorator-bracket.h' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.h', size 7507 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPixmap background READ background WRITE setBackground) + Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) + Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) + Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) + Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) + /// \endcond +public: + explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); + virtual ~QCPAxisRect(); + + // getters: + QPixmap background() const { return mBackgroundPixmap; } + QBrush backgroundBrush() const { return mBackgroundBrush; } + bool backgroundScaled() const { return mBackgroundScaled; } + Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } + Qt::Orientations rangeDrag() const { return mRangeDrag; } + Qt::Orientations rangeZoom() const { return mRangeZoom; } + QCPAxis *rangeDragAxis(Qt::Orientation orientation); + QCPAxis *rangeZoomAxis(Qt::Orientation orientation); + QList rangeDragAxes(Qt::Orientation orientation); + QList rangeZoomAxes(Qt::Orientation orientation); + double rangeZoomFactor(Qt::Orientation orientation); + + // setters: + void setBackground(const QPixmap &pm); + void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); + void setBackground(const QBrush &brush); + void setBackgroundScaled(bool scaled); + void setBackgroundScaledMode(Qt::AspectRatioMode mode); + void setRangeDrag(Qt::Orientations orientations); + void setRangeZoom(Qt::Orientations orientations); + void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); + void setRangeDragAxes(QList axes); + void setRangeDragAxes(QList horizontal, QList vertical); + void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); + void setRangeZoomAxes(QList axes); + void setRangeZoomAxes(QList horizontal, QList vertical); + void setRangeZoomFactor(double horizontalFactor, double verticalFactor); + void setRangeZoomFactor(double factor); + + // non-property methods: + int axisCount(QCPAxis::AxisType type) const; + QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; + QList axes(QCPAxis::AxisTypes types) const; + QList axes() const; + QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0); + QList addAxes(QCPAxis::AxisTypes types); + bool removeAxis(QCPAxis *axis); + QCPLayoutInset *insetLayout() const { return mInsetLayout; } + + void zoom(const QRectF &pixelRect); + void zoom(const QRectF &pixelRect, const QList &affectedAxes); + void setupFullAxesBox(bool connectRanges=false); + QList plottables() const; + QList graphs() const; + QList items() const; + + // read-only interface imitating a QRect: + int left() const { return mRect.left(); } + int right() const { return mRect.right(); } + int top() const { return mRect.top(); } + int bottom() const { return mRect.bottom(); } + int width() const { return mRect.width(); } + int height() const { return mRect.height(); } + QSize size() const { return mRect.size(); } + QPoint topLeft() const { return mRect.topLeft(); } + QPoint topRight() const { return mRect.topRight(); } + QPoint bottomLeft() const { return mRect.bottomLeft(); } + QPoint bottomRight() const { return mRect.bottomRight(); } + QPoint center() const { return mRect.center(); } + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + +protected: + // property members: + QBrush mBackgroundBrush; + QPixmap mBackgroundPixmap; + QPixmap mScaledBackgroundPixmap; + bool mBackgroundScaled; + Qt::AspectRatioMode mBackgroundScaledMode; + QCPLayoutInset *mInsetLayout; + Qt::Orientations mRangeDrag, mRangeZoom; + QList > mRangeDragHorzAxis, mRangeDragVertAxis; + QList > mRangeZoomHorzAxis, mRangeZoomVertAxis; + double mRangeZoomFactorHorz, mRangeZoomFactorVert; + + // non-property members: + QList mDragStartHorzRange, mDragStartVertRange; + QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; + bool mDragging; + QHash > mAxes; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE; + virtual void layoutChanged() Q_DECL_OVERRIDE; + // events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + + // non-property methods: + void drawBackground(QCPPainter *painter); + void updateAxesOffset(QCPAxis::AxisType type); + +private: + Q_DISABLE_COPY(QCPAxisRect) + + friend class QCustomPlot; +}; + + +/* end of 'src/layoutelements/layoutelement-axisrect.h' */ + + +/* including file 'src/layoutelements/layoutelement-legend.h', size 10397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) + /// \endcond +public: + explicit QCPAbstractLegendItem(QCPLegend *parent); + + // getters: + QCPLegend *parentLegend() const { return mParentLegend; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + +protected: + // property members: + QCPLegend *mParentLegend; + QFont mFont; + QColor mTextColor; + QFont mSelectedFont; + QColor mSelectedTextColor; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual QRect clipRect() const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPAbstractLegendItem) + + friend class QCPLegend; +}; + + +class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem +{ + Q_OBJECT +public: + QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); + + // getters: + QCPAbstractPlottable *plottable() { return mPlottable; } + +protected: + // property members: + QCPAbstractPlottable *mPlottable; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen getIconBorderPen() const; + QColor getTextColor() const; + QFont getFont() const; +}; + + +class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) + Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) + Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) + Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) + Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) + Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) + Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + /// \endcond +public: + /*! + Defines the selectable parts of a legend + + \see setSelectedParts, setSelectableParts + */ + enum SelectablePart { spNone = 0x000 ///< 0x000 None + ,spLegendBox = 0x001 ///< 0x001 The legend box (frame) + ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) + }; + Q_ENUMS(SelectablePart) + Q_FLAGS(SelectableParts) + Q_DECLARE_FLAGS(SelectableParts, SelectablePart) + + explicit QCPLegend(); + virtual ~QCPLegend(); + + // getters: + QPen borderPen() const { return mBorderPen; } + QBrush brush() const { return mBrush; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QSize iconSize() const { return mIconSize; } + int iconTextPadding() const { return mIconTextPadding; } + QPen iconBorderPen() const { return mIconBorderPen; } + SelectableParts selectableParts() const { return mSelectableParts; } + SelectableParts selectedParts() const; + QPen selectedBorderPen() const { return mSelectedBorderPen; } + QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; } + QBrush selectedBrush() const { return mSelectedBrush; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + + // setters: + void setBorderPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setIconSize(const QSize &size); + void setIconSize(int width, int height); + void setIconTextPadding(int padding); + void setIconBorderPen(const QPen &pen); + Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); + void setSelectedBorderPen(const QPen &pen); + void setSelectedIconBorderPen(const QPen &pen); + void setSelectedBrush(const QBrush &brush); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QCPAbstractLegendItem *item(int index) const; + QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; + int itemCount() const; + bool hasItem(QCPAbstractLegendItem *item) const; + bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; + bool addItem(QCPAbstractLegendItem *item); + bool removeItem(int index); + bool removeItem(QCPAbstractLegendItem *item); + void clearItems(); + QList selectedItems() const; + +signals: + void selectionChanged(QCPLegend::SelectableParts parts); + void selectableChanged(QCPLegend::SelectableParts parts); + +protected: + // property members: + QPen mBorderPen, mIconBorderPen; + QBrush mBrush; + QFont mFont; + QColor mTextColor; + QSize mIconSize; + int mIconTextPadding; + SelectableParts mSelectedParts, mSelectableParts; + QPen mSelectedBorderPen, mSelectedIconBorderPen; + QBrush mSelectedBrush; + QFont mSelectedFont; + QColor mSelectedTextColor; + + // reimplemented virtual methods: + virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen getBorderPen() const; + QBrush getBrush() const; + +private: + Q_DISABLE_COPY(QCPLegend) + + friend class QCustomPlot; + friend class QCPAbstractLegendItem; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) +Q_DECLARE_METATYPE(QCPLegend::SelectablePart) + +/* end of 'src/layoutelements/layoutelement-legend.h' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.h', size 5353 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + /// \endcond +public: + explicit QCPTextElement(QCustomPlot *parentPlot); + QCPTextElement(QCustomPlot *parentPlot, const QString &text); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize); + QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font); + + // getters: + QString text() const { return mText; } + int textFlags() const { return mTextFlags; } + QFont font() const { return mFont; } + QColor textColor() const { return mTextColor; } + QFont selectedFont() const { return mSelectedFont; } + QColor selectedTextColor() const { return mSelectedTextColor; } + bool selectable() const { return mSelectable; } + bool selected() const { return mSelected; } + + // setters: + void setText(const QString &text); + void setTextFlags(int flags); + void setFont(const QFont &font); + void setTextColor(const QColor &color); + void setSelectedFont(const QFont &font); + void setSelectedTextColor(const QColor &color); + Q_SLOT void setSelectable(bool selectable); + Q_SLOT void setSelected(bool selected); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + +signals: + void selectionChanged(bool selected); + void selectableChanged(bool selectable); + void clicked(QMouseEvent *event); + void doubleClicked(QMouseEvent *event); + +protected: + // property members: + QString mText; + int mTextFlags; + QFont mFont; + QColor mTextColor; + QFont mSelectedFont; + QColor mSelectedTextColor; + QRect mTextBoundingRect; + bool mSelectable, mSelected; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; + virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; + // events: + virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + + // non-virtual methods: + QFont mainFont() const; + QColor mainTextColor() const; + +private: + Q_DISABLE_COPY(QCPTextElement) +}; + + + +/* end of 'src/layoutelements/layoutelement-textelement.h' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.h', size 5923 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +class QCPColorScaleAxisRectPrivate : public QCPAxisRect +{ + Q_OBJECT +public: + explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); +protected: + QCPColorScale *mParentColorScale; + QImage mGradientImage; + bool mGradientImageInvalidated; + // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale + using QCPAxisRect::calculateAutoMargin; + using QCPAxisRect::mousePressEvent; + using QCPAxisRect::mouseMoveEvent; + using QCPAxisRect::mouseReleaseEvent; + using QCPAxisRect::wheelEvent; + using QCPAxisRect::update; + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + void updateGradientImage(); + Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); + Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); + friend class QCPColorScale; +}; + + +class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) + Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) + Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) + Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) + Q_PROPERTY(QString label READ label WRITE setLabel) + Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) + Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) + Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) + /// \endcond +public: + explicit QCPColorScale(QCustomPlot *parentPlot); + virtual ~QCPColorScale(); + + // getters: + QCPAxis *axis() const { return mColorAxis.data(); } + QCPAxis::AxisType type() const { return mType; } + QCPRange dataRange() const { return mDataRange; } + QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } + QCPColorGradient gradient() const { return mGradient; } + QString label() const; + int barWidth () const { return mBarWidth; } + bool rangeDrag() const; + bool rangeZoom() const; + + // setters: + void setType(QCPAxis::AxisType type); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); + void setLabel(const QString &str); + void setBarWidth(int width); + void setRangeDrag(bool enabled); + void setRangeZoom(bool enabled); + + // non-property methods: + QList colorMaps() const; + void rescaleDataRange(bool onlyVisibleMaps); + + // reimplemented virtual methods: + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + +signals: + void dataRangeChanged(const QCPRange &newRange); + void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + void gradientChanged(const QCPColorGradient &newGradient); + +protected: + // property members: + QCPAxis::AxisType mType; + QCPRange mDataRange; + QCPAxis::ScaleType mDataScaleType; + QCPColorGradient mGradient; + int mBarWidth; + + // non-property members: + QPointer mAxisRect; + QPointer mColorAxis; + + // reimplemented virtual methods: + virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + // events: + virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QCPColorScale) + + friend class QCPColorScaleAxisRectPrivate; +}; + + +/* end of 'src/layoutelements/layoutelement-colorscale.h' */ + + +/* including file 'src/plottables/plottable-graph.h', size 9294 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPGraphData +{ +public: + QCPGraphData(); + QCPGraphData(double key, double value); + + inline double sortKey() const { return key; } + inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } + + double key, value; +}; +Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPGraphDataContainer + + Container for storing \ref QCPGraphData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPGraph holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPGraphData, QCPGraph::setData +*/ +typedef QCPDataContainer QCPGraphDataContainer; + +class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) + Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) + Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) + Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) + Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) + /// \endcond +public: + /*! + Defines how the graph's line is represented visually in the plot. The line is drawn with the + current pen of the graph (\ref setPen). + \see setLineStyle + */ + enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented + ///< with symbols according to the scatter style, see \ref setScatterStyle) + ,lsLine ///< data points are connected by a straight line + ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point + ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point + ,lsStepCenter ///< line is drawn as steps where the step is in between two data points + ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line + }; + Q_ENUMS(LineStyle) + + explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPGraph(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + LineStyle lineStyle() const { return mLineStyle; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + int scatterSkip() const { return mScatterSkip; } + QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } + bool adaptiveSampling() const { return mAdaptiveSampling; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void setLineStyle(LineStyle ls); + void setScatterStyle(const QCPScatterStyle &style); + void setScatterSkip(int skip); + void setChannelFillGraph(QCPGraph *targetGraph); + void setAdaptiveSampling(bool enabled); + + // non-property methods: + void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(double key, double value); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + LineStyle mLineStyle; + QCPScatterStyle mScatterStyle; + int mScatterSkip; + QPointer mChannelFillGraph; + bool mAdaptiveSampling; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawFill(QCPPainter *painter, QVector *lines) const; + virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; + virtual void drawLinePlot(QCPPainter *painter, const QVector &lines) const; + virtual void drawImpulsePlot(QCPPainter *painter, const QVector &lines) const; + + virtual void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; + virtual void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; + + // non-virtual methods: + void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; + void getLines(QVector *lines, const QCPDataRange &dataRange) const; + void getScatters(QVector *scatters, const QCPDataRange &dataRange) const; + QVector dataToLines(const QVector &data) const; + QVector dataToStepLeftLines(const QVector &data) const; + QVector dataToStepRightLines(const QVector &data) const; + QVector dataToStepCenterLines(const QVector &data) const; + QVector dataToImpulseLines(const QVector &data) const; + QVector getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const; + QVector > getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const; + bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const; + QPointF getFillBasePoint(QPointF matchingDataPoint) const; + const QPolygonF getFillPolygon(const QVector *lineData, QCPDataRange segment) const; + const QPolygonF getChannelFillPolygon(const QVector *lineData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const; + int findIndexBelowX(const QVector *data, double x) const; + int findIndexAboveX(const QVector *data, double x) const; + int findIndexBelowY(const QVector *data, double y) const; + int findIndexAboveY(const QVector *data, double y) const; + double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPGraph::LineStyle) + +/* end of 'src/plottables/plottable-graph.h' */ + + +/* including file 'src/plottables/plottable-curve.h', size 7409 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPCurveData +{ +public: + QCPCurveData(); + QCPCurveData(double t, double key, double value); + + inline double sortKey() const { return t; } + inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); } + inline static bool sortKeyIsMainKey() { return false; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } + + double t, key, value; +}; +Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPCurveDataContainer + + Container for storing \ref QCPCurveData points. The data is stored sorted by \a t, so the \a + sortKey() (returning \a t) is different from \a mainKey() (returning \a key). + + This template instantiation is the container in which QCPCurve holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPCurveData, QCPCurve::setData +*/ +typedef QCPDataContainer QCPCurveDataContainer; + +class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) + Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) + Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) + /// \endcond +public: + /*! + Defines how the curve's line is represented visually in the plot. The line is drawn with the + current pen of the curve (\ref setPen). + \see setLineStyle + */ + enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) + ,lsLine ///< Data points are connected with a straight line + }; + Q_ENUMS(LineStyle) + + explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPCurve(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + QCPScatterStyle scatterStyle() const { return mScatterStyle; } + int scatterSkip() const { return mScatterSkip; } + LineStyle lineStyle() const { return mLineStyle; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); + void setData(const QVector &keys, const QVector &values); + void setScatterStyle(const QCPScatterStyle &style); + void setScatterSkip(int skip); + void setLineStyle(LineStyle style); + + // non-property methods: + void addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(const QVector &keys, const QVector &values); + void addData(double t, double key, double value); + void addData(double key, double value); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + QCPScatterStyle mScatterStyle; + int mScatterSkip; + LineStyle mLineStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawCurveLine(QCPPainter *painter, const QVector &lines) const; + virtual void drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const; + + // non-virtual methods: + void getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const; + void getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const; + int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + QVector getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; + bool mayTraverse(int prevRegion, int currentRegion) const; + bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const; + void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const; + double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPCurve::LineStyle) + +/* end of 'src/plottables/plottable-curve.h' */ + + +/* including file 'src/plottables/plottable-bars.h', size 8924 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPBarsGroup : public QObject +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType) + Q_PROPERTY(double spacing READ spacing WRITE setSpacing) + /// \endcond +public: + /*! + Defines the ways the spacing between bars in the group can be specified. Thus it defines what + the number passed to \ref setSpacing actually means. + + \see setSpacingType, setSpacing + */ + enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels + ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size + ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(SpacingType) + + QCPBarsGroup(QCustomPlot *parentPlot); + virtual ~QCPBarsGroup(); + + // getters: + SpacingType spacingType() const { return mSpacingType; } + double spacing() const { return mSpacing; } + + // setters: + void setSpacingType(SpacingType spacingType); + void setSpacing(double spacing); + + // non-virtual methods: + QList bars() const { return mBars; } + QCPBars* bars(int index) const; + int size() const { return mBars.size(); } + bool isEmpty() const { return mBars.isEmpty(); } + void clear(); + bool contains(QCPBars *bars) const { return mBars.contains(bars); } + void append(QCPBars *bars); + void insert(int i, QCPBars *bars); + void remove(QCPBars *bars); + +protected: + // non-property members: + QCustomPlot *mParentPlot; + SpacingType mSpacingType; + double mSpacing; + QList mBars; + + // non-virtual methods: + void registerBars(QCPBars *bars); + void unregisterBars(QCPBars *bars); + + // virtual methods: + double keyPixelOffset(const QCPBars *bars, double keyCoord); + double getPixelSpacing(const QCPBars *bars, double keyCoord); + +private: + Q_DISABLE_COPY(QCPBarsGroup) + + friend class QCPBars; +}; +Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType) + + +class QCP_LIB_DECL QCPBarsData +{ +public: + QCPBarsData(); + QCPBarsData(double key, double value); + + inline double sortKey() const { return key; } + inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return value; } + + inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here + + double key, value; +}; +Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPBarsDataContainer + + Container for storing \ref QCPBarsData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPBars holds its data. For details about + the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPBarsData, QCPBars::setData +*/ +typedef QCPDataContainer QCPBarsDataContainer; + +class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) + Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup) + Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue) + Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap) + Q_PROPERTY(QCPBars* barBelow READ barBelow) + Q_PROPERTY(QCPBars* barAbove READ barAbove) + /// \endcond +public: + /*! + Defines the ways the width of the bar can be specified. Thus it defines what the number passed + to \ref setWidth actually means. + + \see setWidthType, setWidth + */ + enum WidthType { wtAbsolute ///< Bar width is in absolute pixels + ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size + ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(WidthType) + + explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPBars(); + + // getters: + double width() const { return mWidth; } + WidthType widthType() const { return mWidthType; } + QCPBarsGroup *barsGroup() const { return mBarsGroup; } + double baseValue() const { return mBaseValue; } + double stackingGap() const { return mStackingGap; } + QCPBars *barBelow() const { return mBarBelow.data(); } + QCPBars *barAbove() const { return mBarAbove.data(); } + QSharedPointer data() const { return mDataContainer; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void setWidth(double width); + void setWidthType(WidthType widthType); + void setBarsGroup(QCPBarsGroup *barsGroup); + void setBaseValue(double baseValue); + void setStackingGap(double pixels); + + // non-property methods: + void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(double key, double value); + void moveBelow(QCPBars *bars); + void moveAbove(QCPBars *bars); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + +protected: + // property members: + double mWidth; + WidthType mWidthType; + QCPBarsGroup *mBarsGroup; + double mBaseValue; + double mStackingGap; + QPointer mBarBelow, mBarAbove; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const; + QRectF getBarRect(double key, double value) const; + void getPixelWidth(double key, double &lower, double &upper) const; + double getStackedBaseValue(double key, bool positive) const; + static void connectBars(QCPBars* lower, QCPBars* upper); + + friend class QCustomPlot; + friend class QCPLegend; + friend class QCPBarsGroup; +}; +Q_DECLARE_METATYPE(QCPBars::WidthType) + +/* end of 'src/plottables/plottable-bars.h' */ + + +/* including file 'src/plottables/plottable-statisticalbox.h', size 7516 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPStatisticalBoxData +{ +public: + QCPStatisticalBoxData(); + QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers=QVector()); + + inline double sortKey() const { return key; } + inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return median; } + + inline QCPRange valueRange() const + { + QCPRange result(minimum, maximum); + for (QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it) + result.expand(*it); + return result; + } + + double key, minimum, lowerQuartile, median, upperQuartile, maximum; + QVector outliers; +}; +Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE); + + +/*! \typedef QCPStatisticalBoxDataContainer + + Container for storing \ref QCPStatisticalBoxData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPStatisticalBox holds its data. For + details about the generic container, see the documentation of the class template \ref + QCPDataContainer. + + \see QCPStatisticalBoxData, QCPStatisticalBox::setData +*/ +typedef QCPDataContainer QCPStatisticalBoxDataContainer; + +class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) + Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen) + Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen) + Q_PROPERTY(bool whiskerAntialiased READ whiskerAntialiased WRITE setWhiskerAntialiased) + Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen) + Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle) + /// \endcond +public: + explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis); + + // getters: + QSharedPointer data() const { return mDataContainer; } + double width() const { return mWidth; } + double whiskerWidth() const { return mWhiskerWidth; } + QPen whiskerPen() const { return mWhiskerPen; } + QPen whiskerBarPen() const { return mWhiskerBarPen; } + bool whiskerAntialiased() const { return mWhiskerAntialiased; } + QPen medianPen() const { return mMedianPen; } + QCPScatterStyle outlierStyle() const { return mOutlierStyle; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); + void setWidth(double width); + void setWhiskerWidth(double width); + void setWhiskerPen(const QPen &pen); + void setWhiskerBarPen(const QPen &pen); + void setWhiskerAntialiased(bool enabled); + void setMedianPen(const QPen &pen); + void setOutlierStyle(const QCPScatterStyle &style); + + // non-property methods: + void addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); + void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers=QVector()); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +protected: + // property members: + double mWidth; + double mWhiskerWidth; + QPen mWhiskerPen, mWhiskerBarPen; + bool mWhiskerAntialiased; + QPen mMedianPen; + QCPScatterStyle mOutlierStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // introduced virtual methods: + virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const; + + // non-virtual methods: + void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const; + QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const; + QVector getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const; + QVector getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-statisticalbox.h' */ + + +/* including file 'src/plottables/plottable-colormap.h', size 7070 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPColorMapData +{ +public: + QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); + ~QCPColorMapData(); + QCPColorMapData(const QCPColorMapData &other); + QCPColorMapData &operator=(const QCPColorMapData &other); + + // getters: + int keySize() const { return mKeySize; } + int valueSize() const { return mValueSize; } + QCPRange keyRange() const { return mKeyRange; } + QCPRange valueRange() const { return mValueRange; } + QCPRange dataBounds() const { return mDataBounds; } + double data(double key, double value); + double cell(int keyIndex, int valueIndex); + unsigned char alpha(int keyIndex, int valueIndex); + + // setters: + void setSize(int keySize, int valueSize); + void setKeySize(int keySize); + void setValueSize(int valueSize); + void setRange(const QCPRange &keyRange, const QCPRange &valueRange); + void setKeyRange(const QCPRange &keyRange); + void setValueRange(const QCPRange &valueRange); + void setData(double key, double value, double z); + void setCell(int keyIndex, int valueIndex, double z); + void setAlpha(int keyIndex, int valueIndex, unsigned char alpha); + + // non-property methods: + void recalculateDataBounds(); + void clear(); + void clearAlpha(); + void fill(double z); + void fillAlpha(unsigned char alpha); + bool isEmpty() const { return mIsEmpty; } + void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; + void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; + +protected: + // property members: + int mKeySize, mValueSize; + QCPRange mKeyRange, mValueRange; + bool mIsEmpty; + + // non-property members: + double *mData; + unsigned char *mAlpha; + QCPRange mDataBounds; + bool mDataModified; + + bool createAlpha(bool initializeOpaque=true); + + friend class QCPColorMap; +}; + + +class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) + Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) + Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) + Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) + Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) + Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) + /// \endcond +public: + explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPColorMap(); + + // getters: + QCPColorMapData *data() const { return mMapData; } + QCPRange dataRange() const { return mDataRange; } + QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } + bool interpolate() const { return mInterpolate; } + bool tightBoundary() const { return mTightBoundary; } + QCPColorGradient gradient() const { return mGradient; } + QCPColorScale *colorScale() const { return mColorScale.data(); } + + // setters: + void setData(QCPColorMapData *data, bool copy=false); + Q_SLOT void setDataRange(const QCPRange &dataRange); + Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); + Q_SLOT void setGradient(const QCPColorGradient &gradient); + void setInterpolate(bool enabled); + void setTightBoundary(bool enabled); + void setColorScale(QCPColorScale *colorScale); + + // non-property methods: + void rescaleDataRange(bool recalculateDataBounds=false); + Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + +signals: + void dataRangeChanged(const QCPRange &newRange); + void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + void gradientChanged(const QCPColorGradient &newGradient); + +protected: + // property members: + QCPRange mDataRange; + QCPAxis::ScaleType mDataScaleType; + QCPColorMapData *mMapData; + QCPColorGradient mGradient; + bool mInterpolate; + bool mTightBoundary; + QPointer mColorScale; + + // non-property members: + QImage mMapImage, mUndersampledMapImage; + QPixmap mLegendIcon; + bool mMapImageInvalidated; + + // introduced virtual methods: + virtual void updateMapImage(); + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-colormap.h' */ + + +/* including file 'src/plottables/plottable-financial.h', size 8622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPFinancialData +{ +public: + QCPFinancialData(); + QCPFinancialData(double key, double open, double high, double low, double close); + + inline double sortKey() const { return key; } + inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); } + inline static bool sortKeyIsMainKey() { return true; } + + inline double mainKey() const { return key; } + inline double mainValue() const { return open; } + + inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them + + double key, open, high, low, close; +}; +Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPFinancialDataContainer + + Container for storing \ref QCPFinancialData points. The data is stored sorted by \a key. + + This template instantiation is the container in which QCPFinancial holds its data. For details + about the generic container, see the documentation of the class template \ref QCPDataContainer. + + \see QCPFinancialData, QCPFinancial::setData +*/ +typedef QCPDataContainer QCPFinancialDataContainer; + +class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle) + Q_PROPERTY(double width READ width WRITE setWidth) + Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) + Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored) + Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive) + Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative) + Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive) + Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative) + /// \endcond +public: + /*! + Defines the ways the width of the financial bar can be specified. Thus it defines what the + number passed to \ref setWidth actually means. + + \see setWidthType, setWidth + */ + enum WidthType { wtAbsolute ///< width is in absolute pixels + ,wtAxisRectRatio ///< width is given by a fraction of the axis rect size + ,wtPlotCoords ///< width is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS(WidthType) + + /*! + Defines the possible representations of OHLC data in the plot. + + \see setChartStyle + */ + enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation + ,csCandlestick ///< Candlestick representation + }; + Q_ENUMS(ChartStyle) + + explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPFinancial(); + + // getters: + QSharedPointer data() const { return mDataContainer; } + ChartStyle chartStyle() const { return mChartStyle; } + double width() const { return mWidth; } + WidthType widthType() const { return mWidthType; } + bool twoColored() const { return mTwoColored; } + QBrush brushPositive() const { return mBrushPositive; } + QBrush brushNegative() const { return mBrushNegative; } + QPen penPositive() const { return mPenPositive; } + QPen penNegative() const { return mPenNegative; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); + void setChartStyle(ChartStyle style); + void setWidth(double width); + void setWidthType(WidthType widthType); + void setTwoColored(bool twoColored); + void setBrushPositive(const QBrush &brush); + void setBrushNegative(const QBrush &brush); + void setPenPositive(const QPen &pen); + void setPenNegative(const QPen &pen); + + // non-property methods: + void addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); + void addData(double key, double open, double high, double low, double close); + + // reimplemented virtual methods: + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + + // static methods: + static QCPFinancialDataContainer timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset = 0); + +protected: + // property members: + ChartStyle mChartStyle; + double mWidth; + WidthType mWidthType; + bool mTwoColored; + QBrush mBrushPositive, mBrushNegative; + QPen mPenPositive, mPenNegative; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); + void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); + double getPixelWidth(double key, double keyPixel) const; + double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; + double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; + void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const; + QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; +Q_DECLARE_METATYPE(QCPFinancial::ChartStyle) + +/* end of 'src/plottables/plottable-financial.h' */ + + +/* including file 'src/plottables/plottable-errorbar.h', size 7727 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPErrorBarsData +{ +public: + QCPErrorBarsData(); + explicit QCPErrorBarsData(double error); + QCPErrorBarsData(double errorMinus, double errorPlus); + + double errorMinus, errorPlus; +}; +Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE); + + +/*! \typedef QCPErrorBarsDataContainer + + Container for storing \ref QCPErrorBarsData points. It is a typedef for QVector<\ref + QCPErrorBarsData>. + + This is the container in which \ref QCPErrorBars holds its data. Unlike most other data + containers for plottables, it is not based on \ref QCPDataContainer. This is because the error + bars plottable is special in that it doesn't store its own key and value coordinate per error + bar. It adopts the key and value from the plottable to which the error bars shall be applied + (\ref QCPErrorBars::setDataPlottable). So the stored \ref QCPErrorBarsData doesn't need a + sortable key, but merely an index (as \c QVector provides), which maps one-to-one to the indices + of the other plottable's data. + + \see QCPErrorBarsData, QCPErrorBars::setData +*/ +typedef QVector QCPErrorBarsDataContainer; + +class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottableInterface1D +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QSharedPointer data READ data WRITE setData) + Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable) + Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) + Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) + Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap) + /// \endcond +public: + + /*! + Defines in which orientation the error bars shall appear. If your data needs both error + dimensions, create two \ref QCPErrorBars with different \ref ErrorType. + + \see setErrorType + */ + enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) + ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) + }; + Q_ENUMS(ErrorType) + + explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + virtual ~QCPErrorBars(); + // getters: + QSharedPointer data() const { return mDataContainer; } + QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); } + ErrorType errorType() const { return mErrorType; } + double whiskerWidth() const { return mWhiskerWidth; } + double symbolGap() const { return mSymbolGap; } + + // setters: + void setData(QSharedPointer data); + void setData(const QVector &error); + void setData(const QVector &errorMinus, const QVector &errorPlus); + void setDataPlottable(QCPAbstractPlottable* plottable); + void setErrorType(ErrorType type); + void setWhiskerWidth(double pixels); + void setSymbolGap(double pixels); + + // non-property methods: + void addData(const QVector &error); + void addData(const QVector &errorMinus, const QVector &errorPlus); + void addData(double error); + void addData(double errorMinus, double errorPlus); + + // virtual methods of 1d plottable interface: + virtual int dataCount() const Q_DECL_OVERRIDE; + virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; + virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; + virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; + virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; + virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } + +protected: + // property members: + QSharedPointer mDataContainer; + QPointer mDataPlottable; + ErrorType mErrorType; + double mWhiskerWidth; + double mSymbolGap; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const; + void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; + double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const; + // helpers: + void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; + bool errorBarVisible(int index) const; + bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const; + + friend class QCustomPlot; + friend class QCPLegend; +}; + +/* end of 'src/plottables/plottable-errorbar.h' */ + + +/* including file 'src/items/item-straightline.h', size 3117 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + /// \endcond +public: + explicit QCPItemStraightLine(QCustomPlot *parentPlot); + virtual ~QCPItemStraightLine(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const point1; + QCPItemPosition * const point2; + +protected: + // property members: + QPen mPen, mSelectedPen; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QLineF getRectClippedStraightLine(const QCPVector2D &point1, const QCPVector2D &vec, const QRect &rect) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-straightline.h' */ + + +/* including file 'src/items/item-line.h', size 3407 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) + Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + /// \endcond +public: + explicit QCPItemLine(QCustomPlot *parentPlot); + virtual ~QCPItemLine(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QCPLineEnding head() const { return mHead; } + QCPLineEnding tail() const { return mTail; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setHead(const QCPLineEnding &head); + void setTail(const QCPLineEnding &tail); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const start; + QCPItemPosition * const end; + +protected: + // property members: + QPen mPen, mSelectedPen; + QCPLineEnding mHead, mTail; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-line.h' */ + + +/* including file 'src/items/item-curve.h', size 3379 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) + Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + /// \endcond +public: + explicit QCPItemCurve(QCustomPlot *parentPlot); + virtual ~QCPItemCurve(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QCPLineEnding head() const { return mHead; } + QCPLineEnding tail() const { return mTail; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setHead(const QCPLineEnding &head); + void setTail(const QCPLineEnding &tail); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const start; + QCPItemPosition * const startDir; + QCPItemPosition * const endDir; + QCPItemPosition * const end; + +protected: + // property members: + QPen mPen, mSelectedPen; + QCPLineEnding mHead, mTail; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; +}; + +/* end of 'src/items/item-curve.h' */ + + +/* including file 'src/items/item-rect.h', size 3688 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + /// \endcond +public: + explicit QCPItemRect(QCustomPlot *parentPlot); + virtual ~QCPItemRect(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-rect.h' */ + + +/* including file 'src/items/item-text.h', size 5554 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemText : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) + Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) + Q_PROPERTY(double rotation READ rotation WRITE setRotation) + Q_PROPERTY(QMargins padding READ padding WRITE setPadding) + /// \endcond +public: + explicit QCPItemText(QCustomPlot *parentPlot); + virtual ~QCPItemText(); + + // getters: + QColor color() const { return mColor; } + QColor selectedColor() const { return mSelectedColor; } + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + QFont font() const { return mFont; } + QFont selectedFont() const { return mSelectedFont; } + QString text() const { return mText; } + Qt::Alignment positionAlignment() const { return mPositionAlignment; } + Qt::Alignment textAlignment() const { return mTextAlignment; } + double rotation() const { return mRotation; } + QMargins padding() const { return mPadding; } + + // setters; + void setColor(const QColor &color); + void setSelectedColor(const QColor &color); + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + void setFont(const QFont &font); + void setSelectedFont(const QFont &font); + void setText(const QString &text); + void setPositionAlignment(Qt::Alignment alignment); + void setTextAlignment(Qt::Alignment alignment); + void setRotation(double degrees); + void setPadding(const QMargins &padding); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const position; + QCPItemAnchor * const topLeft; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottomRight; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QColor mColor, mSelectedColor; + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + QFont mFont, mSelectedFont; + QString mText; + Qt::Alignment mPositionAlignment; + Qt::Alignment mTextAlignment; + double mRotation; + QMargins mPadding; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; + QFont mainFont() const; + QColor mainColor() const; + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-text.h' */ + + +/* including file 'src/items/item-ellipse.h', size 3868 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + /// \endcond +public: + explicit QCPItemEllipse(QCustomPlot *parentPlot); + virtual ~QCPItemEllipse(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const topLeftRim; + QCPItemAnchor * const top; + QCPItemAnchor * const topRightRim; + QCPItemAnchor * const right; + QCPItemAnchor * const bottomRightRim; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeftRim; + QCPItemAnchor * const left; + QCPItemAnchor * const center; + +protected: + enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; + + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; + +/* end of 'src/items/item-ellipse.h' */ + + +/* including file 'src/items/item-pixmap.h', size 4373 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) + Q_PROPERTY(bool scaled READ scaled WRITE setScaled) + Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) + Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode) + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + /// \endcond +public: + explicit QCPItemPixmap(QCustomPlot *parentPlot); + virtual ~QCPItemPixmap(); + + // getters: + QPixmap pixmap() const { return mPixmap; } + bool scaled() const { return mScaled; } + Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; } + Qt::TransformationMode transformationMode() const { return mTransformationMode; } + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + + // setters; + void setPixmap(const QPixmap &pixmap); + void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation); + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const topLeft; + QCPItemPosition * const bottomRight; + QCPItemAnchor * const top; + QCPItemAnchor * const topRight; + QCPItemAnchor * const right; + QCPItemAnchor * const bottom; + QCPItemAnchor * const bottomLeft; + QCPItemAnchor * const left; + +protected: + enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; + + // property members: + QPixmap mPixmap; + QPixmap mScaledPixmap; + bool mScaled; + bool mScaledPixmapInvalidated; + Qt::AspectRatioMode mAspectRatioMode; + Qt::TransformationMode mTransformationMode; + QPen mPen, mSelectedPen; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); + QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; + QPen mainPen() const; +}; + +/* end of 'src/items/item-pixmap.h' */ + + +/* including file 'src/items/item-tracer.h', size 4762 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) + Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY(double size READ size WRITE setSize) + Q_PROPERTY(TracerStyle style READ style WRITE setStyle) + Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) + Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) + Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) + /// \endcond +public: + /*! + The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize. + + \see setStyle + */ + enum TracerStyle { tsNone ///< The tracer is not visible + ,tsPlus ///< A plus shaped crosshair with limited size + ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect + ,tsCircle ///< A circle + ,tsSquare ///< A square + }; + Q_ENUMS(TracerStyle) + + explicit QCPItemTracer(QCustomPlot *parentPlot); + virtual ~QCPItemTracer(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + QBrush brush() const { return mBrush; } + QBrush selectedBrush() const { return mSelectedBrush; } + double size() const { return mSize; } + TracerStyle style() const { return mStyle; } + QCPGraph *graph() const { return mGraph; } + double graphKey() const { return mGraphKey; } + bool interpolating() const { return mInterpolating; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setSelectedBrush(const QBrush &brush); + void setSize(double size); + void setStyle(TracerStyle style); + void setGraph(QCPGraph *graph); + void setGraphKey(double key); + void setInterpolating(bool enabled); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + // non-virtual methods: + void updatePosition(); + + QCPItemPosition * const position; + +protected: + // property members: + QPen mPen, mSelectedPen; + QBrush mBrush, mSelectedBrush; + double mSize; + TracerStyle mStyle; + QCPGraph *mGraph; + double mGraphKey; + bool mInterpolating; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; + QBrush mainBrush() const; +}; +Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle) + +/* end of 'src/items/item-tracer.h' */ + + +/* including file 'src/items/item-bracket.h', size 3969 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem +{ + Q_OBJECT + /// \cond INCLUDE_QPROPERTIES + Q_PROPERTY(QPen pen READ pen WRITE setPen) + Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY(double length READ length WRITE setLength) + Q_PROPERTY(BracketStyle style READ style WRITE setStyle) + /// \endcond +public: + /*! + Defines the various visual shapes of the bracket item. The appearance can be further modified + by \ref setLength and \ref setPen. + + \see setStyle + */ + enum BracketStyle { bsSquare ///< A brace with angled edges + ,bsRound ///< A brace with round edges + ,bsCurly ///< A curly brace + ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression + }; + Q_ENUMS(BracketStyle) + + explicit QCPItemBracket(QCustomPlot *parentPlot); + virtual ~QCPItemBracket(); + + // getters: + QPen pen() const { return mPen; } + QPen selectedPen() const { return mSelectedPen; } + double length() const { return mLength; } + BracketStyle style() const { return mStyle; } + + // setters; + void setPen(const QPen &pen); + void setSelectedPen(const QPen &pen); + void setLength(double length); + void setStyle(BracketStyle style); + + // reimplemented virtual methods: + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + + QCPItemPosition * const left; + QCPItemPosition * const right; + QCPItemAnchor * const center; + +protected: + // property members: + enum AnchorIndex {aiCenter}; + QPen mPen, mSelectedPen; + double mLength; + BracketStyle mStyle; + + // reimplemented virtual methods: + virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; + + // non-virtual methods: + QPen mainPen() const; +}; +Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) + +/* end of 'src/items/item-bracket.h' */ + + +#endif // QCUSTOMPLOT_H + diff --git a/src/qt/statistics.cpp b/src/qt/statistics.cpp new file mode 100644 index 00000000..50eb5373 --- /dev/null +++ b/src/qt/statistics.cpp @@ -0,0 +1,46 @@ +#include "statistics.h" + +Statistics::Statistics() +{ + +} + +void Statistics::setLikesNumber(unsigned int number) +{ + likesNumber = number; +} + +void Statistics::setFriendsNumber(unsigned int number) +{ + friendsNumber = number; +} + +void Statistics::setPostsNumber(unsigned int number) +{ + postsNumber = number; +} + +void Statistics::setUserID(unsigned int number) +{ + userID = number; +} + +unsigned int Statistics::getLikesNumber() +{ + return likesNumber; +} + +unsigned int Statistics::getPostsNumber() +{ + return postsNumber; +} + +unsigned int Statistics::getFriendsNumber() +{ + return friendsNumber; +} + +unsigned int Statistics::getUserID() +{ + return userID; +} diff --git a/src/qt/statistics.h b/src/qt/statistics.h new file mode 100644 index 00000000..bbb5f472 --- /dev/null +++ b/src/qt/statistics.h @@ -0,0 +1,37 @@ +#ifndef STATISTICS_H +#define STATISTICS_H +#include "QString" + +class Statistics +{ +public: + Statistics(); + + void setLikesNumber(unsigned int number); + + void setFriendsNumber(unsigned int number); + + void setPostsNumber(unsigned int number); + + void setUserID(unsigned int number); + + unsigned int getLikesNumber(); + + unsigned int getPostsNumber(); + + unsigned int getFriendsNumber(); + + unsigned int getUserID(); + + +private: + unsigned int userID; + + unsigned int likesNumber; + + unsigned int friendsNumber; + + unsigned int postsNumber; +}; + +#endif // STATISTICS_H diff --git a/src/qt/user.cpp b/src/qt/user.cpp new file mode 100644 index 00000000..1934e769 --- /dev/null +++ b/src/qt/user.cpp @@ -0,0 +1,35 @@ +#include "user.h" + +user::user() +{ + userName=""; + id=0; +} + +user::user(QString passWord, QString email,QString name,int userID) +{ + userName=name; + userFileManipulator.name=name; + userFileManipulator.createFile(passWord,email,name,creationDate.getDateNow()); + id=userID; +} + +void user :: setUsersList(user A) +{ + usersList.append(A); +} + +QString user:: getUserName(int id) +{ + return usersList[id].userName; +} + + bool user:: usersEmpty() + { + return (usersList.size()==0); + } + +int user:: getUsersSize() +{ + return usersList.count(); +} diff --git a/src/qt/user.h b/src/qt/user.h new file mode 100644 index 00000000..35a000b0 --- /dev/null +++ b/src/qt/user.h @@ -0,0 +1,26 @@ +#ifndef USER_H +#define USER_H +#include "posts.h" +#include "fileman.h" +#include +#include +class user +{ +public: + QString userName; + int id; + Post userPost; + fileman userFileManipulator; + Date creationDate; + user(); + user(QString passWord, QString email, QString name,int userID); + void setUsersList( user A ); + QString getUserName(int id); + bool usersEmpty(); + int getUsersSize(); + +private: + QList usersList; +}; + +#endif // USER_H From 13975723d121a152e4d987c0ee25aebe235d3e2e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:32:18 -0400 Subject: [PATCH 0769/1324] Update addcomment.cpp --- src/qt/addcomment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp index fde45cd1..0fef6054 100644 --- a/src/qt/addcomment.cpp +++ b/src/qt/addcomment.cpp @@ -7,7 +7,7 @@ AddComment::AddComment(QWidget *parent) : { ui->setupUi(this); commentBody = ""; - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/chat.png")); } AddComment::~AddComment() From 4d411c40665198abb2e338b1eaab5bea3505d354 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:32:47 -0400 Subject: [PATCH 0770/1324] Update adminwindow.cpp --- src/qt/adminwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp index 4d6b37a6..0a8e4f58 100644 --- a/src/qt/adminwindow.cpp +++ b/src/qt/adminwindow.cpp @@ -7,7 +7,7 @@ AdminWindow::AdminWindow(QWidget *parent) : ui(new Ui::AdminWindow) { ui->setupUi(this); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/about.png")); this->showMaximized(); this->setWindowTitle("Social Network"); From 95a232b7583bf43617095fa4bc5f3ed74ec80a92 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:34:20 -0400 Subject: [PATCH 0771/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index bf45b4d9..b576bda0 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -33,7 +33,7 @@ HomePage::HomePage(QWidget *parent) : shownPostsNumber = 0; ui->comboBox->setVisible(false); pagePosts = new QList; - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/about.png")); this->showMaximized(); this->setWindowTitle("Social Network"); From 211731a921ef74790f1bb65b8aff87bba81ff8dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:34:45 -0400 Subject: [PATCH 0772/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 3699f475..dbd0c644 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -15,7 +15,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); - QPixmap pix(":/resources/img/login-icon.png"); + QPixmap pix(":/icons/chat.png"); int w = ui->label_pic->width(); int h = ui->label_pic->height(); ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); @@ -41,4 +41,4 @@ void MainWindow::on_pushButton_Login_clicked() else { QMessageBox::warning(this,"Login", "Username and password is not correct"); } -} \ No newline at end of file +} From 5acb11c57634fea52376baf6bc7063ea906e9488 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:35:05 -0400 Subject: [PATCH 0773/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 89c986e8..47e25a28 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -9,7 +9,7 @@ newAccount::newAccount(QWidget *parent) : ui->setupUi(this); user check; id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/about.png")); this->setWindowTitle("Social Network"); } From 00391dbef4f1974a06701e63c6ace93bbe4ea6ea Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:35:41 -0400 Subject: [PATCH 0774/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 581314ea..b7b7deed 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -34,7 +34,7 @@ ProfilePage::ProfilePage(QWidget *parent) : shownPostsNumber = 0; //pagePosts = makePosts(); // viewPosts(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/about.png")); this->showMaximized(); this->setWindowTitle("Social Network"); } From 40ef8275f386054def77f1055940d84b64114acb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:46:20 -0400 Subject: [PATCH 0775/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7ba2ebe6..4a367c48 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,6 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +#include "mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -142,6 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), + socialAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -614,6 +616,13 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); + + // HTH Chat + socialAction = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + socialAction->setStatusTip(tr("HTH World Social Media")); + // HTHW Chat + connect(socialAction, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -702,11 +711,7 @@ void BitcoinGUI::createMenuBar() tools->addSeparator(); tools->addAction(openConfEditorAction); tools->addAction(showBackupsAction); - - QMenu *governance = appMenuBar->addMenu(tr("&Proposals")); - governance->addAction(governanceAction); - - + } QMenu *help = appMenuBar->addMenu(tr("&Help")); @@ -718,6 +723,9 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); + + QMenu *social = appMenuBar->addMenu(tr("&HTH World")); + social->addAction(socialAction); } @@ -1045,6 +1053,11 @@ void BitcoinGUI::openClicked() } } +void BitcoinGUI::gotoMainWindow() +{ + socialAction->setChecked(true); + if (walletFrame) walletFrame->gotoMainWindow(); +} void BitcoinGUI::gotoGovernancePage() { From e09eccbd0525c16c3017ba02ab730c593e5714e4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:48:29 -0400 Subject: [PATCH 0776/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a1817f84..98989a0c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -38,6 +38,7 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; +class MainWindow; class CWallet; @@ -103,7 +104,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - + QAction* MainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -231,6 +232,9 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET + /** Switch to social media page */ + void gotoMainWindow(); + /** Switch to masternode page */ void gotoGovernancePage(); From ea3891d0217139e5bd336342e5525fac566bc6f1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:49:26 -0400 Subject: [PATCH 0777/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 6783019e..abf30d21 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,6 +108,14 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } +void WalletFrame::gotoMainWindow() +{ + + QMap::const_iterator i; + for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) + i.value()->gotoMainWindow(); +} + void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; From f49294f9cb79af6ef67712f11ef6f8134b93aacd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:49:58 -0400 Subject: [PATCH 0778/1324] Update walletframe.h --- src/qt/walletframe.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index dbb28330..555bf8cf 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,8 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to governance page */ - void gotoGovernancePage(); + /** Switch to social media page */ + void gotoMainWindow(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From d10b9546091afaea2ebd82955c674618349f6010 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:51:33 -0400 Subject: [PATCH 0779/1324] Update walletview.cpp --- src/qt/walletview.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index cba3948d..581d2805 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,7 +85,10 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); + addWidget(privateSendPage); + + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -233,6 +236,11 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } +void WalletView::gotoMainWindow() +{ + setCurrentWidget(mainWindow); +} + void WalletView::gotoGovernancePage() { QSettings settings; From 65c5f061c09037df6ae43feb8e47119102010beb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 22:52:54 -0400 Subject: [PATCH 0780/1324] Update walletview.h --- src/qt/walletview.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 56483b23..6acaf1dd 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,6 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" +#inlcude "mainwindow.h" #include @@ -24,6 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; +class MainWindow; @@ -73,7 +75,8 @@ class WalletView : public QStackedWidget AddressBookPage *usedReceivingAddressesPage; MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; - GovernanceList *governanceListPage; + GovernanceList *governanceListPage; + MainWindow *mainWindow; TransactionView *transactionView; @@ -83,6 +86,8 @@ class WalletView : public QStackedWidget public Q_SLOTS: + /** Switch to social media page */ + void gotoMainWindow(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 7879d4bd48efd7e6f823a71df11bbd384131c5dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:05:02 -0400 Subject: [PATCH 0781/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 61 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index faa4d1cc..8f695fd0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -52,7 +52,16 @@ QT_FORMS_UI = \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ - qt/forms/transactiondescdialog.ui + qt/forms/transactiondescdialog.ui \ + qt/forms/activity.ui \ + qt/forms/addcomment.ui \ + qt/forms/adminwindow.ui \ + qt/forms/dialog.ui \ + qt/forms/form.ui \ + qt/forms/homepage.ui \ + qt/forms/mainwindow.ui \ + qt/forms/newaccount.ui \ + qt/forms/profilepage.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -104,7 +113,23 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp + qt/moc_walletview.cpp \ + qt/moc_activity.cpp \ + qt/moc_addcomment.cpp \ + qt/moc_adminwindow.cpp \ + qt/moc_comment.cpp \ + qt/moc_dialog.cpp \ + qt/moc_fileman.cpp \ + qt/moc_form.cpp \ + qt/moc_homepage.cpp \ + qt/moc_main.cpp \ + qt/moc_mainwindow.cpp \ + qt/moc_newaccount.cpp \ + qt/moc_posts.cpp \ + qt/moc_profilepage.cpp \ + qt/moc_qcustomplot.cpp \ + qt/moc_statistics.cpp \ + qt/moc_user.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -187,7 +212,21 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h + qt/winshutdownmonitor.h \ + qt/activity.h \ + qt/addcomment.h \ + qt/adminwindow.h \ + qt/comment.h \ + qt/fileman.h \ + qt/form.h \ + qt/homepage.h \ + qt/mainwindow.h \ + qt/newaccount.h \ + qt/posts.h \ + qt/profilepage.h \ + qt/qcustomplot.h \ + qt/statistics.h \ + qt/user.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -525,7 +564,21 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp + qt/walletview.cpp \ + qt/activity.cpp \ + qt/addcomment.cpp \ + qt/adminwindow.cpp \ + qt/comment.cpp \ + qt/fileman.cpp \ + qt/form.cpp \ + qt/homepage.cpp \ + qt/mainwindow.cpp \ + qt/newaccount.cpp \ + qt/posts.cpp \ + qt/profilepage.cpp \ + qt/qcustomplot.cpp \ + qt/statistics.cpp \ + qt/user.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 209b8aa049f5d5b0f0ec37d67af3cdf7c0562aeb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:11:12 -0400 Subject: [PATCH 0782/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 8f695fd0..bb0481d0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -53,7 +53,6 @@ QT_FORMS_UI = \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ qt/forms/transactiondescdialog.ui \ - qt/forms/activity.ui \ qt/forms/addcomment.ui \ qt/forms/adminwindow.ui \ qt/forms/dialog.ui \ From ed92a3fd33ad40c3916d9c06038cfd47d56300c0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:12:28 -0400 Subject: [PATCH 0783/1324] Add files via upload --- src/qt/forms/addcomment.ui | 107 +++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/qt/forms/addcomment.ui diff --git a/src/qt/forms/addcomment.ui b/src/qt/forms/addcomment.ui new file mode 100644 index 00000000..c670061d --- /dev/null +++ b/src/qt/forms/addcomment.ui @@ -0,0 +1,107 @@ + + + AddComment + + + + 0 + 0 + 348 + 222 + + + + Dialog + + + + + 11 + 183 + 193 + 28 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 75 + 15 + 262 + 151 + + + + + + + 10 + 70 + 57 + 41 + + + + + + + Add + + + Qt::AlignCenter + + + + + + + Comment + + + + + + + + + + buttonBox + accepted() + AddComment + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddComment + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From 771eb3371305a81fb51eb2c58892c5dfb81f9c69 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:14:07 -0400 Subject: [PATCH 0784/1324] Update and rename Activity.cpp to activity.cpp --- src/qt/{Activity.cpp => activity.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/qt/{Activity.cpp => activity.cpp} (89%) diff --git a/src/qt/Activity.cpp b/src/qt/activity.cpp similarity index 89% rename from src/qt/Activity.cpp rename to src/qt/activity.cpp index eb388cc8..3d7ef1f8 100644 --- a/src/qt/Activity.cpp +++ b/src/qt/activity.cpp @@ -1,4 +1,4 @@ -#include "Activity.h" +#include "activity.h" #include #include "posts.h" #include"vector" From 24f299e0e373a2974f97510a46e170a256f84517 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:14:21 -0400 Subject: [PATCH 0785/1324] Rename Activity.h to activity.h --- src/qt/{Activity.h => activity.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{Activity.h => activity.h} (100%) diff --git a/src/qt/Activity.h b/src/qt/activity.h similarity index 100% rename from src/qt/Activity.h rename to src/qt/activity.h From 3be2f6d404c1732e3c79c71b14f3b0d7eff6a839 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:15:23 -0400 Subject: [PATCH 0786/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index bb0481d0..b61ddfec 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -121,7 +121,6 @@ QT_MOC_CPP = \ qt/moc_fileman.cpp \ qt/moc_form.cpp \ qt/moc_homepage.cpp \ - qt/moc_main.cpp \ qt/moc_mainwindow.cpp \ qt/moc_newaccount.cpp \ qt/moc_posts.cpp \ @@ -571,6 +570,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/fileman.cpp \ qt/form.cpp \ qt/homepage.cpp \ + qt/main.cpp \ qt/mainwindow.cpp \ qt/newaccount.cpp \ qt/posts.cpp \ From 23cf47da5307dc7dc35ce1c2f8c7ce2d78eb7907 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:16:08 -0400 Subject: [PATCH 0787/1324] Update addcomment.h --- src/qt/addcomment.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h index bb61bc05..78fc9e25 100644 --- a/src/qt/addcomment.h +++ b/src/qt/addcomment.h @@ -16,11 +16,11 @@ class AddComment : public QDialog ~AddComment(); -public slots: +public Q_SLOTS: QString getCommentBody(); -private slots: +private Q_SLOTS: void on_AddComment_accepted(); From 8265d5ece7c4540440d174e40f443c0b050b0b33 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:16:24 -0400 Subject: [PATCH 0788/1324] Update adminwindow.h --- src/qt/adminwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h index 308af0fe..3fb32a8a 100644 --- a/src/qt/adminwindow.h +++ b/src/qt/adminwindow.h @@ -15,7 +15,7 @@ class AdminWindow : public QMainWindow explicit AdminWindow(QWidget *parent = 0); ~AdminWindow(); -private slots: +private Q_SLOTS: void on_showStatistics_clicked(); void makePlot(QVector *plotData); From c0d0cbb1746cbb23fa1ac05d7114178a11016b08 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:16:51 -0400 Subject: [PATCH 0789/1324] Update fileman.h --- src/qt/fileman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/fileman.h b/src/qt/fileman.h index 3e434553..901e5f57 100644 --- a/src/qt/fileman.h +++ b/src/qt/fileman.h @@ -40,7 +40,7 @@ class fileman{ void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); QList * getPosts_new(QString email); -public slots: +public Q_SLOTS: void addLikeByPostDate(QString email, QString Date, QString likePerson); QString getPassword(QString email); }; From db7ce260095049a782b0be3f0b2306ae862302db Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:17:23 -0400 Subject: [PATCH 0790/1324] Update homepage.h --- src/qt/homepage.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index 01dc23e8..15a070a1 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -27,7 +27,7 @@ class HomePage : public QMainWindow ~HomePage(); -public slots: +public Q_SLOTS: QList search(QString x, QList& myList); void internalSearch(QString x, QList &myList, int begin, int end, QList &temp); @@ -51,7 +51,7 @@ public slots: user *currentSessionUser; -private slots: +private Q_SLOTS: void viewPosts(); From a9109585466b31af4299309d50cbf23389cc34ad Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:17:39 -0400 Subject: [PATCH 0791/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index ed46f860..57058721 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -15,7 +15,7 @@ class MainWindow : public QMainWindow explicit MainWindow(QWidget *parent = 0); ~MainWindow(); -private slots: +private Q_SLOTS: void on_signUpButton_clicked(); void on_logInButton_clicked(); From 621faebb82b9c6dddc42ed7c66acbf582272eda2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:17:59 -0400 Subject: [PATCH 0792/1324] Update newaccount.h --- src/qt/newaccount.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index 9114dcdd..b69d4800 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -17,11 +17,11 @@ class newAccount : public QMainWindow int id; -public slots: +public Q_SLOTS: void setLoginPtr(MainWindow *ptr); -private slots: +private Q_SLOTS: void on_pushButton_clicked(); void on_pushButton_2_clicked(); From bfe0cc4ecdbec803fb3e402f4ecd82aea9a89bb3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:18:32 -0400 Subject: [PATCH 0793/1324] Update profilepage.h --- src/qt/profilepage.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index 00222ec0..a480b3dd 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -20,7 +20,7 @@ class ProfilePage : public QMainWindow ProfilePage(int userID,QString userFile); -private slots: +private Q_SLOTS: void on_pushButton_2_clicked(); void viewPosts(); @@ -36,7 +36,7 @@ private slots: void on_actionLog_out_triggered(); -public slots: +public Q_SLOTS: void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); void on_Post_btn_clicked(); From d2fb191896e1c4edb140441928319be6402be69e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:27:04 -0400 Subject: [PATCH 0794/1324] Update qcustomplot.h --- src/qt/qcustomplot.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index 278fbf82..916c3522 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -722,7 +722,7 @@ class QCP_LIB_DECL QCPLayerable : public QObject // non-property methods: bool realVisibility() const; -signals: +QSIGNALS: void layerChanged(QCPLayer *newLayer); protected: @@ -1112,7 +1112,7 @@ class QCP_LIB_DECL QCPSelectionRect : public QCPLayerable // non-property methods: Q_SLOT void cancel(); -signals: +QSIGNALS: void started(QMouseEvent *event); void changed(const QRect &rect, QMouseEvent *event); void canceled(const QRect &rect, QInputEvent *event); @@ -2115,7 +2115,7 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } static AxisType opposite(AxisType type); -signals: +QSIGNALS: void rangeChanged(const QCPRange &newRange); void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); void scaleTypeChanged(QCPAxis::ScaleType scaleType); @@ -3347,7 +3347,7 @@ class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable bool removeFromLegend(QCPLegend *legend) const; bool removeFromLegend() const; -signals: +QSIGNALS: void selectionChanged(bool selected); void selectionChanged(const QCPDataSelection &selection); void selectableChanged(QCP::SelectionType selectable); @@ -3537,7 +3537,7 @@ class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable QCPItemAnchor *anchor(const QString &name) const; bool hasAnchor(const QString &name) const; -signals: +QSIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -3731,7 +3731,7 @@ class QCP_LIB_DECL QCustomPlot : public QWidget QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; QCPLegend *legend; -signals: +QSIGNALS: void mouseDoubleClick(QMouseEvent *event); void mousePress(QMouseEvent *event); void mouseMove(QMouseEvent *event); @@ -4740,7 +4740,7 @@ class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; -signals: +QSIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -4877,7 +4877,7 @@ class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid void clearItems(); QList selectedItems() const; -signals: +QSIGNALS: void selectionChanged(QCPLegend::SelectableParts parts); void selectableChanged(QCPLegend::SelectableParts parts); @@ -5080,7 +5080,7 @@ class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement // reimplemented virtual methods: virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; -signals: +QSIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); @@ -5776,7 +5776,7 @@ class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; -signals: +QSIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); From e6d80bdb7b505e040f1b638a2a4fda6e5a75cc6b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:27:23 -0400 Subject: [PATCH 0795/1324] Delete qcustomplot.cpp --- src/qt/qcustomplot.cpp | 30121 --------------------------------------- 1 file changed, 30121 deletions(-) delete mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp deleted file mode 100644 index e59374ab..00000000 --- a/src/qt/qcustomplot.cpp +++ /dev/null @@ -1,30121 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#include "qcustomplot.h" - - -/* including file 'src/vector2d.cpp', size 7340 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPVector2D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPVector2D - \brief Represents two doubles as a mathematical 2D vector - - This class acts as a replacement for QVector2D with the advantage of double precision instead of - single, and some convenience methods tailored for the QCustomPlot library. -*/ - -/* start documentation of inline functions */ - -/*! \fn void QCPVector2D::setX(double x) - - Sets the x coordinate of this vector to \a x. - - \see setY -*/ - -/*! \fn void QCPVector2D::setY(double y) - - Sets the y coordinate of this vector to \a y. - - \see setX -*/ - -/*! \fn double QCPVector2D::length() const - - Returns the length of this vector. - - \see lengthSquared -*/ - -/*! \fn double QCPVector2D::lengthSquared() const - - Returns the squared length of this vector. In some situations, e.g. when just trying to find the - shortest vector of a group, this is faster than calculating \ref length, because it avoids - calculation of a square root. - - \see length -*/ - -/*! \fn QPoint QCPVector2D::toPoint() const - - Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point - information. - - \see toPointF -*/ - -/*! \fn QPointF QCPVector2D::toPointF() const - - Returns a QPointF which has the x and y coordinates of this vector. - - \see toPoint -*/ - -/*! \fn bool QCPVector2D::isNull() const - - Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y - coordinates, i.e. if both are binary equal to 0. -*/ - -/*! \fn QCPVector2D QCPVector2D::perpendicular() const - - Returns a vector perpendicular to this vector, with the same length. -*/ - -/*! \fn double QCPVector2D::dot() const - - Returns the dot/scalar product of this vector with the specified vector \a vec. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates to 0. -*/ -QCPVector2D::QCPVector2D() : - mX(0), - mY(0) -{ -} - -/*! - Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified - values. -*/ -QCPVector2D::QCPVector2D(double x, double y) : - mX(x), - mY(y) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPoint &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPointF &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Normalizes this vector. After this operation, the length of the vector is equal to 1. - - \see normalized, length, lengthSquared -*/ -void QCPVector2D::normalize() -{ - double len = length(); - mX /= len; - mY /= len; -} - -/*! - Returns a normalized version of this vector. The length of the returned vector is equal to 1. - - \see normalize, length, lengthSquared -*/ -QCPVector2D QCPVector2D::normalized() const -{ - QCPVector2D result(mX, mY); - result.normalize(); - return result; -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a start and \a end. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const -{ - QCPVector2D v(end-start); - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = v.dot(*this-start)/vLengthSqr; - if (mu < 0) - return (*this-start).lengthSquared(); - else if (mu > 1) - return (*this-end).lengthSquared(); - else - return ((start + mu*v)-*this).lengthSquared(); - } else - return (*this-start).lengthSquared(); -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a line. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QLineF &line) const -{ - return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); -} - -/*! - Returns the shortest distance of this vector (interpreted as a point) to the infinite straight - line given by a \a base point and a \a direction vector. - - \see distanceSquaredToLine -*/ -double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const -{ - return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); -} - -/*! - Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a - factor. -*/ -QCPVector2D &QCPVector2D::operator*=(double factor) -{ - mX *= factor; - mY *= factor; - return *this; -} - -/*! - Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a - divisor. -*/ -QCPVector2D &QCPVector2D::operator/=(double divisor) -{ - mX /= divisor; - mY /= divisor; - return *this; -} - -/*! - Adds the given \a vector to this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) -{ - mX += vector.mX; - mY += vector.mY; - return *this; -} - -/*! - subtracts the given \a vector from this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) -{ - mX -= vector.mX; - mY -= vector.mY; - return *this; -} -/* end of 'src/vector2d.cpp' */ - - -/* including file 'src/painter.cpp', size 8670 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPainter -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPainter - \brief QPainter subclass used internally - - This QPainter subclass is used to provide some extended functionality e.g. for tweaking position - consistency between antialiased and non-antialiased painting. Further it provides workarounds - for QPainter quirks. - - \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and - restore. So while it is possible to pass a QCPPainter instance to a function that expects a - QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because - it will call the base class implementations of the functions actually hidden by QCPPainter). -*/ - -/*! - Creates a new QCPPainter instance and sets default values -*/ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) -{ - // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and - // a call to begin() will follow -} - -/*! - Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just - like the analogous QPainter constructor, begins painting on \a device immediately. - - Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. -*/ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif -} - -/*! - Sets the pen of the painter and applies certain fixes to it, depending on the mode of this - QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QPen &pen) -{ - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QColor &color) -{ - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(Qt::PenStyle penStyle) -{ - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when - antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to - integer coordinates and then passes it to the original drawLine. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::drawLine(const QLineF &line) -{ - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); - else - QPainter::drawLine(line.toLine()); -} - -/*! - Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint - with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between - antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for - AA/Non-AA painting). -*/ -void QCPPainter::setAntialiasing(bool enabled) -{ - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) - { - mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs - { - if (mIsAntialiasing) - translate(0.5, 0.5); - else - translate(-0.5, -0.5); - } - } -} - -/*! - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setModes(QCPPainter::PainterModes modes) -{ - mModes = modes; -} - -/*! - Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a - device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, - all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that - behaviour. - - The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets - the render hint as appropriate. - - \note this function hides the non-virtual base class implementation. -*/ -bool QCPPainter::begin(QPaintDevice *device) -{ - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif - return result; -} - -/*! \overload - - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) -{ - if (!enabled && mModes.testFlag(mode)) - mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) - mModes |= mode; -} - -/*! - Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see restore -*/ -void QCPPainter::save() -{ - mAntialiasingStack.push(mIsAntialiasing); - QPainter::save(); -} - -/*! - Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see save -*/ -void QCPPainter::restore() -{ - if (!mAntialiasingStack.isEmpty()) - mIsAntialiasing = mAntialiasingStack.pop(); - else - qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; - QPainter::restore(); -} - -/*! - Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen - overrides when the \ref pmNonCosmetic mode is set. -*/ -void QCPPainter::makeNonCosmetic() -{ - if (qFuzzyIsNull(pen().widthF())) - { - QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); - } -} -/* end of 'src/painter.cpp' */ - - -/* including file 'src/paintbuffer.cpp', size 18502 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPaintBuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPaintBuffer - \brief The abstract base class for paint buffers, which define the rendering backend - - This abstract base class defines the basic interface that a paint buffer needs to provide in - order to be usable by QCustomPlot. - - A paint buffer manages both a surface to draw onto, and the matching paint device. The size of - the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref - QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the - painting is complete, \ref donePainting is called, so the paint buffer implementation can do - clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color - using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the - previous frame. - - The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular - software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and - frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. - They are used automatically if \ref QCustomPlot::setOpenGl is enabled. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 - - Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the - responsibility to delete the painter after the painting operations are complete is given to the - caller of this method. - - Once you are done using the painter, delete the painter and call \ref donePainting. - - While a painter generated with this method is active, you must not call \ref setSize, \ref - setDevicePixelRatio or \ref clear. - - This method may return 0, if a painter couldn't be activated on the buffer. This usually - indicates a problem with the respective painting backend. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 - - Draws the contents of this buffer with the provided \a painter. This is the method that is used - to finally join all paint buffers and draw them onto the screen. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 - - Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the - named color \c Qt::transparent. - - This method must not be called if there is currently a painter (acquired with \ref startPainting) - active. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 - - Reallocates the internal buffer with the currently configured size (\ref setSize) and device - pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those - properties are changed on this paint buffer. - - \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method - in their constructor, to perform the first allocation (this can not be done by the base class - because calling pure virtual methods in base class constructors is not possible). -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of inline functions */ - -/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() - - If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, - call this method as soon as you are done with the painting operations and have deleted the - painter. - - paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The - default implementation does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. - - Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. -*/ -QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : - mSize(size), - mDevicePixelRatio(devicePixelRatio), - mInvalidated(true) -{ -} - -QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() -{ -} - -/*! - Sets the paint buffer size. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - If \a size is already the current buffer size, this method does nothing. -*/ -void QCPAbstractPaintBuffer::setSize(const QSize &size) -{ - if (mSize != size) - { - mSize = size; - reallocateBuffer(); - } -} - -/*! - Sets the invalidated flag to \a invalidated. - - This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer - instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered - layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, - QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also - replots them, instead of only the layer on which the replot was called. - - The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers - were added or removed from this buffer, or if they were reordered. It is set to false as soon as - all associated \ref QCPLayer instances are drawn onto the buffer. - - Under normal circumstances, it is not necessary to manually call this method. -*/ -void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) -{ - mInvalidated = invalidated; -} - -/*! - Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. - The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - \note This method is only available for Qt versions 5.4 and higher. -*/ -void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mDevicePixelRatio = ratio; - reallocateBuffer(); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; -#endif - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferPixmap - \brief A paint buffer based on QPixmap, using software raster rendering - - This paint buffer is the default and fall-back paint buffer which uses software rendering and - QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. -*/ - -/*! - Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if - applicable. -*/ -QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : - QCPAbstractPaintBuffer(size, devicePixelRatio) -{ - QCPPaintBufferPixmap::reallocateBuffer(); -} - -QCPPaintBufferPixmap::~QCPPaintBufferPixmap() -{ -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferPixmap::startPainting() -{ - QCPPainter *result = new QCPPainter(&mBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::draw(QCPPainter *painter) const -{ - if (painter && painter->isActive()) - painter->drawPixmap(0, 0, mBuffer); - else - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::clear(const QColor &color) -{ - mBuffer.fill(color); -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::reallocateBuffer() -{ - setInvalidated(); - if (!qFuzzyCompare(1.0, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBuffer = QPixmap(mSize*mDevicePixelRatio); - mBuffer.setDevicePixelRatio(mDevicePixelRatio); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; - mBuffer = QPixmap(mSize); -#endif - } else - { - mBuffer = QPixmap(mSize); - } -} - - -#ifdef QCP_OPENGL_PBUFFER -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlPbuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlPbuffer - \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. - (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a - devicePixelRatio, if applicable. - - The parameter \a multisamples defines how many samples are used per pixel. Higher values thus - result in higher quality antialiasing. If the specified \a multisamples value exceeds the - capability of the graphics hardware, the highest supported multisampling is used. -*/ -QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlPBuffer(0), - mMultisamples(qMax(0, multisamples)) -{ - QCPPaintBufferGlPbuffer::reallocateBuffer(); -} - -QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlPbuffer::startPainting() -{ - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - QCPPainter *result = new QCPPainter(mGlPBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlPBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::clear(const QColor &color) -{ - if (mGlPBuffer->isValid()) - { - mGlPBuffer->makeCurrent(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlPBuffer->doneCurrent(); - } else - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::reallocateBuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; - - QGLFormat format; - format.setAlpha(true); - format.setSamples(mMultisamples); - mGlPBuffer = new QGLPixelBuffer(mSize, format); -} -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlFbo -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlFbo - \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and - higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, - if applicable. - - All frame buffer objects shall share one OpenGL context and paint device, which need to be set up - externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref - QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot - instance. -*/ -QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlContext(glContext), - mGlPaintDevice(glPaintDevice), - mGlFrameBuffer(0) -{ - QCPPaintBufferGlFbo::reallocateBuffer(); -} - -QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() -{ - if (mGlFrameBuffer) - delete mGlFrameBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlFbo::startPainting() -{ - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return 0; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::donePainting() -{ - if (mGlFrameBuffer && mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - else - qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlFrameBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::clear(const QColor &color) -{ - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlFrameBuffer->release(); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::reallocateBuffer() -{ - // release and delete possibly existing framebuffer: - if (mGlFrameBuffer) - { - if (mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - delete mGlFrameBuffer; - mGlFrameBuffer = 0; - } - - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return; - } - - // create new fbo with appropriate size: - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples(mGlContext.data()->format().samples()); - frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); - if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) - mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); -#endif -} -#endif // QCP_OPENGL_FBO -/* end of 'src/paintbuffer.cpp' */ - - -/* including file 'src/layer.cpp', size 37064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayer - \brief A layer that may contain objects, to control the rendering order - - The Layering system of QCustomPlot is the mechanism to control the rendering order of the - elements inside the plot. - - It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of - one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, - QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers - bottom to top and successively draws the layerables of the layers into the paint buffer(s). - - A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base - class from which almost all visible objects derive, like axes, grids, graphs, items, etc. - - \section qcplayer-defaultlayers Default layers - - Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and - "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's - selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain - the default axes and legend, so they will be drawn above plottables. In the middle, there is the - "main" layer. It is initially empty and set as the current layer (see - QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this - layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong - tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind - everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of - course, the layer affiliation of the individual objects can be changed as required (\ref - QCPLayerable::setLayer). - - \section qcplayer-ordering Controlling the rendering order via layers - - Controlling the ordering of layerables in the plot is easy: Create a new layer in the position - you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the - current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the - objects normally. They will be placed on the new layer automatically, due to the current layer - setting. Alternatively you could have also ignored the current layer setting and just moved the - objects with \ref QCPLayerable::setLayer to the desired layer after creating them. - - It is also possible to move whole layers. For example, If you want the grid to be shown in front - of all plottables/items on the "main" layer, just move it above "main" with - QCustomPlot::moveLayer. - - The rendering order within one layer is simply by order of creation or insertion. The item - created last (or added last to the layer), is drawn on top of all other objects on that layer. - - When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below - the deleted layer, see QCustomPlot::removeLayer. - - \section qcplayer-buffering Replotting only a specific layer - - If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific - layer by calling \ref replot. In certain situations this can provide better replot performance, - compared with a full replot of all layers. Upon creation of a new layer, the layer mode is - initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref - QCustomPlot instance is the "overlay" layer, containing the selection rect. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPLayer::children() const - - Returns a list of all layerables on this layer. The order corresponds to the rendering order: - layerables with higher indices are drawn above layerables with lower indices. -*/ - -/*! \fn int QCPLayer::index() const - - Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be - accessed via \ref QCustomPlot::layer. - - Layers with higher indices will be drawn above layers with lower indices. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPLayer instance. - - Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. - - \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. - This check is only performed by \ref QCustomPlot::addLayer. -*/ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true), - mMode(lmLogical) -{ - // Note: no need to make sure layerName is unique, because layer - // management is done with QCustomPlot functions. -} - -QCPLayer::~QCPLayer() -{ - // If child layerables are still on this layer, detach them, so they don't try to reach back to this - // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted - // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to - // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) - qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; -} - -/*! - Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this - layer will be invisible. - - This function doesn't change the visibility property of the layerables (\ref - QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the - visibility of the parent layer into account. -*/ -void QCPLayer::setVisible(bool visible) -{ - mVisible = visible; -} - -/*! - Sets the rendering mode of this layer. - - If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by - the parent QCustomPlot instance. This means it may be replotted individually by calling \ref - QCPLayer::replot, without needing to replot all other layers. - - Layers which are set to \ref lmLogical (the default) are used only to define the rendering order - and can't be replotted individually. - - Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the - layers below, above and for the layer itself. This increases the memory consumption and - (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So - you should carefully choose which layers benefit from having their own paint buffer. A typical - example would be a layer which contains certain layerables (e.g. items) that need to be changed - and thus replotted regularly, while all other layerables on other layers stay static. By default, - only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection - rect. - - \see replot -*/ -void QCPLayer::setMode(QCPLayer::LayerMode mode) -{ - if (mMode != mode) - { - mMode = mode; - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } -} - -/*! \internal - - Draws the contents of this layer with the provided \a painter. - - \see replot, drawToPaintBuffer -*/ -void QCPLayer::draw(QCPPainter *painter) -{ - Q_FOREACH (QCPLayerable *child, mChildren) - { - if (child->realVisibility()) - { - painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); - painter->restore(); - } - } -} - -/*! \internal - - Draws the contents of this layer into the paint buffer which is associated with this layer. The - association is established by the parent QCustomPlot, which manages all paint buffers (see \ref - QCustomPlot::setupPaintBuffers). - - \see draw -*/ -void QCPLayer::drawToPaintBuffer() -{ - if (!mPaintBuffer.isNull()) - { - if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) - { - if (painter->isActive()) - draw(painter); - else - qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; - delete painter; - mPaintBuffer.data()->donePainting(); - } else - qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; -} - -/*! - If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only - the layerables on this specific layer, without the need to replot all other layers (as a call to - \ref QCustomPlot::replot would do). - - If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on - the parent QCustomPlot instance. - - QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering - has changed since the last full replot and the other paint buffers were thus invalidated. - - \see draw -*/ -void QCPLayer::replot() -{ - if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) - { - if (!mPaintBuffer.isNull()) - { - mPaintBuffer.data()->clear(Qt::transparent); - drawToPaintBuffer(); - mPaintBuffer.data()->setInvalidated(false); - mParentPlot->update(); - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } else if (mMode == lmLogical) - mParentPlot->replot(); -} - -/*! \internal - - Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will - be prepended to the list, i.e. be drawn beneath the other layerables already in the list. - - This function does not change the \a mLayer member of \a layerable to this layer. (Use - QCPLayerable::setLayer to change the layer of an object, not this function.) - - \see removeChild -*/ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) -{ - if (!mChildren.contains(layerable)) - { - if (prepend) - mChildren.prepend(layerable); - else - mChildren.append(layerable); - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); -} - -/*! \internal - - Removes the \a layerable from the list of this layer. - - This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer - to change the layer of an object, not this function.) - - \see addChild -*/ -void QCPLayer::removeChild(QCPLayerable *layerable) -{ - if (mChildren.removeOne(layerable)) - { - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayerable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayerable - \brief Base class for all drawable objects - - This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid - etc. - - Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking - the layers accordingly. - - For details about the layering mechanism, see the QCPLayer documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const - - Returns the parent layerable of this layerable. The parent layerable is used to provide - visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables - only get drawn if their parent layerables are visible, too. - - Note that a parent layerable is not necessarily also the QObject parent for memory management. - Further, a layerable doesn't always have a parent layerable, so this function may return 0. - - A parent layerable is set implicitly when placed inside layout elements and doesn't need to be - set manually by the user. -*/ - -/* end documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 - \internal - - This function applies the default antialiasing setting to the specified \a painter, using the - function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when - \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing - setting may be specified individually, this function should set the antialiasing state of the - most prominent entity. In this case however, the \ref draw function usually calls the specialized - versions of this function before drawing each entity, effectively overriding the setting of the - default antialiasing hint. - - First example: QCPGraph has multiple entities that have an antialiasing setting: The graph - line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, - QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only - the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's - antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and - QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw - calls the respective specialized applyAntialiasingHint function. - - Second example: QCPItemLine consists only of a line so there is only one antialiasing - setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by - all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the - respective layerable subclass.) Consequently it only has the normal - QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to - care about setting any antialiasing states, because the default antialiasing hint is already set - on the painter when the \ref draw function is called, and that's the state it wants to draw the - line with. -*/ - -/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 - \internal - - This function draws the layerable with the specified \a painter. It is only called by - QCustomPlot, if the layerable is visible (\ref setVisible). - - Before this function is called, the painter's antialiasing state is set via \ref - applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was - set to \ref clipRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); - - This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to - a different layer. - - \see setLayer -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPLayerable instance. - - Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the - derived classes. - - If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a - targetLayer is an empty string, it places itself on the current layer of the plot (see \ref - QCustomPlot::setCurrentLayer). - - It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later - time with \ref initializeParentPlot. - - The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable - parents are mainly used to control visibility in a hierarchy of layerables. This means a - layerable is only drawn, if all its ancestor layerables are also visible. Note that \a - parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a - plot does. It is not uncommon to set the QObject-parent to something else in the constructors of - QCPLayerable subclasses, to guarantee a working destruction hierarchy. -*/ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) -{ - if (mParentPlot) - { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) - qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; - } -} - -QCPLayerable::~QCPLayerable() -{ - if (mLayer) - { - mLayer->removeChild(this); - mLayer = 0; - } -} - -/*! - Sets the visibility of this layerable object. If an object is not visible, it will not be drawn - on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not - possible. -*/ -void QCPLayerable::setVisible(bool on) -{ - mVisible = on; -} - -/*! - Sets the \a layer of this layerable object. The object will be placed on top of the other objects - already on \a layer. - - If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or - interact/receive events). - - Returns true if the layer of this layerable was successfully changed to \a layer. -*/ -bool QCPLayerable::setLayer(QCPLayer *layer) -{ - return moveToLayer(layer, false); -} - -/*! \overload - Sets the layer of this layerable object by name - - Returns true on success, i.e. if \a layerName is a valid layer name. -*/ -bool QCPLayerable::setLayer(const QString &layerName) -{ - if (!mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (QCPLayer *layer = mParentPlot->layer(layerName)) - { - return setLayer(layer); - } else - { - qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; - return false; - } -} - -/*! - Sets whether this object will be drawn antialiased or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPLayerable::setAntialiased(bool enabled) -{ - mAntialiased = enabled; -} - -/*! - Returns whether this layerable is visible, taking the visibility of the layerable parent and the - visibility of this layerable's layer into account. This is the method that is consulted to decide - whether a layerable shall be drawn or not. - - If this layerable has a direct layerable parent (usually set via hierarchies implemented in - subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this - layerable has its visibility set to true and the parent layerable's \ref realVisibility returns - true. -*/ -bool QCPLayerable::realVisibility() const -{ - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); -} - -/*! - This function is used to decide whether a click hits a layerable object or not. - - \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the - shortest pixel distance of this point to the object. If the object is either invisible or the - distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the - object is not selectable, -1.0 is returned, too. - - If the object is represented not by single lines but by an area like a \ref QCPItemText or the - bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In - these cases this function thus returns a constant value greater zero but still below the parent - plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). - - Providing a constant value for area objects allows selecting line objects even when they are - obscured by such area objects, by clicking close to the lines (i.e. closer than - 0.99*selectionTolerance). - - The actual setting of the selection state is not done by this function. This is handled by the - parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified - via the \ref selectEvent/\ref deselectEvent methods. - - \a details is an optional output parameter. Every layerable subclass may place any information - in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot - decides on the basis of this selectTest call, that the object was successfully selected. The - subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part - objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked - is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be - placed in \a details. So in the subsequent \ref selectEvent, the decision which part was - selected doesn't have to be done a second time for a single selection operation. - - You may pass 0 as \a details to indicate that you are not interested in those selection details. - - \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions -*/ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) - return -1.0; -} - -/*! \internal - - Sets the parent plot of this layerable. Use this function once to set the parent plot if you have - passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to - another one. - - Note that, unlike when passing a non-null parent plot in the constructor, this function does not - make \a parentPlot the QObject-parent of this layerable. If you want this, call - QObject::setParent(\a parentPlot) in addition to this function. - - Further, you will probably want to set a layer (\ref setLayer) after calling this function, to - make the layerable appear on the QCustomPlot. - - The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized - so they can react accordingly (e.g. also initialize the parent plot of child layerables, like - QCPLayout does). -*/ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) -{ - if (mParentPlot) - { - qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; - return; - } - - if (!parentPlot) - qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - - mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); -} - -/*! \internal - - Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not - become the QObject-parent (for memory management) of this layerable. - - The parent layerable has influence on the return value of the \ref realVisibility method. Only - layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be - drawn. - - \see realVisibility -*/ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) -{ - mParentLayerable = parentLayerable; -} - -/*! \internal - - Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to - the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is - false, the object will be appended. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) -{ - if (layer && !mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (layer && layer->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; - return false; - } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); - mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - Q_EMIT layerChanged(mLayer); - return true; -} - -/*! \internal - - Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a - localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is - controlled via \a overrideElement. -*/ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const -{ - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); - else - painter->setAntialiasing(localAntialiased); -} - -/*! \internal - - This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting - of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the - parent plot is set at a later time. - - For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any - QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level - element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To - propagate the parent plot to all the children of the hierarchy, the top level element then uses - this function to pass the parent plot on to its child elements. - - The default implementation does nothing. - - \see initializeParentPlot -*/ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - -/*! \internal - - Returns the selection category this layerable shall belong to. The selection category is used in - conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and - which aren't. - - Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref - QCP::iSelectOther. This is what the default implementation returns. - - \see QCustomPlot::setInteractions -*/ -QCP::Interaction QCPLayerable::selectionCategory() const -{ - return QCP::iSelectOther; -} - -/*! \internal - - Returns the clipping rectangle of this layerable object. By default, this is the viewport of the - parent QCustomPlot. Specific subclasses may reimplement this function to provide different - clipping rects. - - The returned clipping rect is set on the painter before the draw function of the respective - object is called. -*/ -QRect QCPLayerable::clipRect() const -{ - if (mParentPlot) - return mParentPlot->viewport(); - else - return QRect(); -} - -/*! \internal - - This event is called when the layerable shall be selected, as a consequence of a click by the - user. Subclasses should react to it by setting their selection state appropriately. The default - implementation does nothing. - - \a event is the mouse event that caused the selection. \a additive indicates, whether the user - was holding the multi-select-modifier while performing the selection (see \ref - QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled - (i.e. become selected when unselected and unselected when selected). - - Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. - returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). - The \a details data you output from \ref selectTest is fed back via \a details here. You may - use it to transport any kind of information from the selectTest to the possibly subsequent - selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable - that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need - to do the calculation again to find out which part was actually clicked. - - \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must - set the value either to true or false, depending on whether the selection state of this layerable - was actually changed. For layerables that only are selectable as a whole and not in parts, this - is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the - selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the - layerable was previously unselected and now is switched to the selected state. - - \see selectTest, deselectEvent -*/ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) -} - -/*! \internal - - This event is called when the layerable shall be deselected, either as consequence of a user - interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by - unsetting their selection appropriately. - - just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must - return true or false when the selection state of this layerable has changed or not changed, - respectively. - - \see selectTest, selectEvent -*/ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) -{ - Q_UNUSED(selectionStateChanged) -} - -/*! - This event gets called when the user presses a mouse button while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - QCustomPlot uses an event propagation system that works the same as Qt's system. If your - layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in - its reimplementation, the event will be propagated to the next layerable in the stacking order. - - Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and - will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse - interaction (a "mouse interaction" in this context ends with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user moves the mouse while holding a mouse button, after this - layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user releases the mouse button, after this layerable has become - the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user presses the mouse button a second time in a double-click, - while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a - preceding call to \ref selectTest. - - The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the - case of a double-click, the event succession is - pressEvent – releaseEvent – doubleClickEvent – releaseEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, - it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent - and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends - with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent -*/ -void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user turns the mouse scroll wheel while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). - - The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for - single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may - accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has - very smooth steps or none at all, the delta may be smaller. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent -*/ -void QCPLayerable::wheelEvent(QWheelEvent *event) -{ - event->ignore(); -} -/* end of 'src/layer.cpp' */ - - -/* including file 'src/axis/range.cpp', size 12221 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPRange -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPRange - \brief Represents the range an axis is encompassing. - - contains a \a lower and \a upper double value and provides convenience input, output and - modification functions. - - \see QCPAxis::setRange -*/ - -/* start of documentation of inline functions */ - -/*! \fn double QCPRange::size() const - - Returns the size of the range, i.e. \a upper-\a lower -*/ - -/*! \fn double QCPRange::center() const - - Returns the center of the range, i.e. (\a upper+\a lower)*0.5 -*/ - -/*! \fn void QCPRange::normalize() - - Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are - swapped. -*/ - -/*! \fn bool QCPRange::contains(double value) const - - Returns true when \a value lies within or exactly on the borders of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator+=(const double& value) - - Adds \a value to both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator-=(const double& value) - - Subtracts \a value from both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator*=(const double& value) - - Multiplies both boundaries of the range by \a value. -*/ - -/*! \fn QCPRange &QCPRange::operator/=(const double& value) - - Divides both boundaries of the range by \a value. -*/ - -/* end of documentation of inline functions */ - -/*! - Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller - intervals would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a minimum magnitude of roughly 1e-308. - - \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining underflowing ranges. - - \see validRange, maxRange -*/ -const double QCPRange::minRange = 1e-280; - -/*! - Maximum values (negative and positive) the range will accept in range-changing functions. - Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a maximum magnitude of roughly 1e308. - - \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining overflowing ranges. - - \see validRange, minRange -*/ -const double QCPRange::maxRange = 1e250; - -/*! - Constructs a range with \a lower and \a upper set to zero. -*/ -QCPRange::QCPRange() : - lower(0), - upper(0) -{ -} - -/*! \overload - - Constructs a range with the specified \a lower and \a upper values. - - The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically - smaller than \a upper, they will be swapped. -*/ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) -{ - normalize(); -} - -/*! \overload - - Expands this range such that \a otherRange is contained in the new range. It is assumed that both - this range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, it will be replaced by the respective bound - of \a otherRange. - - If \a otherRange is already inside the current range, this function does nothing. - - \see expanded -*/ -void QCPRange::expand(const QCPRange &otherRange) -{ - if (lower > otherRange.lower || qIsNaN(lower)) - lower = otherRange.lower; - if (upper < otherRange.upper || qIsNaN(upper)) - upper = otherRange.upper; -} - -/*! \overload - - Expands this range such that \a includeCoord is contained in the new range. It is assumed that - this range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the respective bound will be set to \a - includeCoord. - - If \a includeCoord is already inside the current range, this function does nothing. - - \see expand -*/ -void QCPRange::expand(double includeCoord) -{ - if (lower > includeCoord || qIsNaN(lower)) - lower = includeCoord; - if (upper < includeCoord || qIsNaN(upper)) - upper = includeCoord; -} - - -/*! \overload - - Returns an expanded range that contains this and \a otherRange. It is assumed that both this - range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be taken from - \a otherRange. - - \see expand -*/ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const -{ - QCPRange result = *this; - result.expand(otherRange); - return result; -} - -/*! \overload - - Returns an expanded range that includes the specified \a includeCoord. It is assumed that this - range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a - includeCoord. - - \see expand -*/ -QCPRange QCPRange::expanded(double includeCoord) const -{ - QCPRange result = *this; - result.expand(includeCoord); - return result; -} - -/*! - Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a - upperBound. If possible, the size of the current range is preserved in the process. - - If the range shall only be bounded at the lower side, you can set \a upperBound to \ref - QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref - QCPRange::maxRange. -*/ -QCPRange QCPRange::bounded(double lowerBound, double upperBound) const -{ - if (lowerBound > upperBound) - qSwap(lowerBound, upperBound); - - QCPRange result(lower, upper); - if (result.lower < lowerBound) - { - result.lower = lowerBound; - result.upper = lowerBound + size(); - if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.upper = upperBound; - } else if (result.upper > upperBound) - { - result.upper = upperBound; - result.lower = upperBound - size(); - if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.lower = lowerBound; - } - - return result; -} - -/*! - Returns a sanitized version of the range. Sanitized means for logarithmic scales, that - the range won't span the positive and negative sign domain, i.e. contain zero. Further - \a lower will always be numerically smaller (or equal) to \a upper. - - If the original range does span positive and negative sign domains or contains zero, - the returned range will try to approximate the original range as good as possible. - If the positive interval of the original range is wider than the negative interval, the - returned range will only contain the positive interval, with lower bound set to \a rangeFac or - \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval - is wider than the positive interval, this time by changing the \a upper bound. -*/ -QCPRange QCPRange::sanitizedForLogScale() const -{ - double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - // can't have range spanning negative and positive values in log plot, so change range to fix it - //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) - { - // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) - { - // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) - { - // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) - { - // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else - { - // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } - } - // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange && - !(lower > 0 && qIsInf(upper/lower)) && - !(upper < 0 && qIsInf(lower/upper))); -} - -/*! - \overload - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(const QCPRange &range) -{ - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - !(range.lower > 0 && qIsInf(range.upper/range.lower)) && - !(range.upper < 0 && qIsInf(range.lower/range.upper))); -} -/* end of 'src/axis/range.cpp' */ - - -/* including file 'src/selection.cpp', size 21906 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataRange -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataRange - \brief Describes a data range given by begin and end index - - QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index - of a contiguous set of data points. The end index points to the data point above the last data point that's part of - the data range, similarly to the nomenclature used in standard iterators. - - Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and - modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is - used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref - QCPDataSelection is thus used. - - Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, - e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref - contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be - used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding - \ref QCPDataSelection. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and - QCPDataRange. - - \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval - in floating point plot coordinates, e.g. the current axis range. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataRange::size() const - - Returns the number of data points described by this data range. This is equal to the end index - minus the begin index. - - \see length -*/ - -/*! \fn int QCPDataRange::length() const - - Returns the number of data points described by this data range. Equivalent to \ref size. -*/ - -/*! \fn void QCPDataRange::setBegin(int begin) - - Sets the begin of this data range. The \a begin index points to the first data point that is part - of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setEnd -*/ - -/*! \fn void QCPDataRange::setEnd(int end) - - Sets the end of this data range. The \a end index points to the data point just above the last - data point that is part of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setBegin -*/ - -/*! \fn bool QCPDataRange::isValid() const - - Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and - an end index greater or equal to the begin index. - - \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods - (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's - methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary - invalid begin/end values while manipulating the range. An invalid range is not necessarily empty - (\ref isEmpty), since its \ref length can be negative and thus non-zero. -*/ - -/*! \fn bool QCPDataRange::isEmpty() const - - Returns whether this range is empty, i.e. whether its begin index equals its end index. - - \see size, length -*/ - -/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const - - Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end - indices, respectively. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataRange, with begin and end set to 0. -*/ -QCPDataRange::QCPDataRange() : - mBegin(0), - mEnd(0) -{ -} - -/*! - Creates a QCPDataRange, initialized with the specified \a begin and \a end. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). -*/ -QCPDataRange::QCPDataRange(int begin, int end) : - mBegin(begin), - mEnd(end) -{ -} - -/*! - Returns a data range that matches this data range, except that parts exceeding \a other are - excluded. - - This method is very similar to \ref intersection, with one distinction: If this range and the \a - other range share no intersection, the returned data range will be empty with begin and end set - to the respective boundary side of \a other, at which this range is residing. (\ref intersection - would just return a range with begin and end set to 0.) -*/ -QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const -{ - QCPDataRange result(intersection(other)); - if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value - { - if (mEnd <= other.mBegin) - result = QCPDataRange(other.mBegin, other.mBegin); - else - result = QCPDataRange(other.mEnd, other.mEnd); - } - return result; -} - -/*! - Returns a data range that contains both this data range as well as \a other. -*/ -QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const -{ - return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); -} - -/*! - Returns the data range which is contained in both this data range and \a other. - - This method is very similar to \ref bounded, with one distinction: If this range and the \a other - range share no intersection, the returned data range will be empty with begin and end set to 0. - (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, - depending on which side this range is on.) - - \see QCPDataSelection::intersection -*/ -QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const -{ - QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); - if (result.isValid()) - return result; - else - return QCPDataRange(); -} - -/*! - Returns whether this data range and \a other share common data points. - - \see intersection, contains -*/ -bool QCPDataRange::intersects(const QCPDataRange &other) const -{ - return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || - (mEnd <= other.mBegin && mEnd < other.mEnd) ); -} - -/*! - Returns whether all data points described by this data range are also in \a other. - - \see intersects -*/ -bool QCPDataRange::contains(const QCPDataRange &other) const -{ - return mBegin <= other.mBegin && mEnd >= other.mEnd; -} - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataSelection -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataSelection - \brief Describes a data set by holding multiple QCPDataRange instances - - QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly - disjoint) set of data selection. - - The data selection can be modified with addition and subtraction operators which take - QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and - \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. - - The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange - instances. QCPDataSelection automatically simplifies when using the addition/subtraction - operators. The only case when \ref simplify is left to the user, is when calling \ref - addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data - ranges will be added to the selection successively and the overhead for simplifying after each - iteration shall be avoided. In this case, you should make sure to call \ref simplify after - completing the operation. - - Use \ref enforceType to bring the data selection into a state complying with the constraints for - selections defined in \ref QCP::SelectionType. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and - QCPDataRange. - - \section qcpdataselection-iterating Iterating over a data selection - - As an example, the following code snippet calculates the average value of a graph's data - \ref QCPAbstractPlottable::selection "selection": - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 - -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataSelection::dataRangeCount() const - - Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref - dataRange via their index. - - \see dataRange, dataPointCount -*/ - -/*! \fn QList QCPDataSelection::dataRanges() const - - Returns all data ranges that make up the data selection. If the data selection is simplified (the - usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point - index. - - \see dataRange -*/ - -/*! \fn bool QCPDataSelection::isEmpty() const - - Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection - instance. - - \see dataRangeCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataSelection. -*/ -QCPDataSelection::QCPDataSelection() -{ -} - -/*! - Creates a QCPDataSelection containing the provided \a range. -*/ -QCPDataSelection::QCPDataSelection(const QCPDataRange &range) -{ - mDataRanges.append(range); -} - -/*! - Returns true if this selection is identical (contains the same data ranges with the same begin - and end indices) to \a other. - - Note that both data selections must be in simplified state (the usual state of the selection, see - \ref simplify) for this operator to return correct results. -*/ -bool QCPDataSelection::operator==(const QCPDataSelection &other) const -{ - if (mDataRanges.size() != other.mDataRanges.size()) - return false; - for (int i=0; i= other.end()) - break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this - - if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored - { - if (thisBegin >= other.begin()) // range leading segment is encompassed - { - if (thisEnd <= other.end()) // range fully encompassed, remove completely - { - mDataRanges.removeAt(i); - continue; - } else // only leading segment is encompassed, trim accordingly - mDataRanges[i].setBegin(other.end()); - } else // leading segment is not encompassed - { - if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly - { - mDataRanges[i].setEnd(other.begin()); - } else // other lies inside this range, so split range - { - mDataRanges[i].setEnd(other.begin()); - mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); - break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here - } - } - } - ++i; - } - - return *this; -} - -/*! - Returns the total number of data points contained in all data ranges that make up this data - selection. -*/ -int QCPDataSelection::dataPointCount() const -{ - int result = 0; - for (int i=0; i= 0 && index < mDataRanges.size()) - { - return mDataRanges.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of range:" << index; - return QCPDataRange(); - } -} - -/*! - Returns a \ref QCPDataRange which spans the entire data selection, including possible - intermediate segments which are not part of the original data selection. -*/ -QCPDataRange QCPDataSelection::span() const -{ - if (isEmpty()) - return QCPDataRange(); - else - return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); -} - -/*! - Adds the given \a dataRange to this data selection. This is equivalent to the += operator but - allows disabling immediate simplification by setting \a simplify to false. This can improve - performance if adding a very large amount of data ranges successively. In this case, make sure to - call \ref simplify manually, after the operation. -*/ -void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) -{ - mDataRanges.append(dataRange); - if (simplify) - this->simplify(); -} - -/*! - Removes all data ranges. The data selection then contains no data points. - - \ref isEmpty -*/ -void QCPDataSelection::clear() -{ - mDataRanges.clear(); -} - -/*! - Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent - or overlapping ranges. This can reduce the number of individual data ranges in the selection, and - prevents possible double-counting when iterating over the data points held by the data ranges. - - This method is automatically called when using the addition/subtraction operators. The only case - when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a - simplify explicitly set to false. -*/ -void QCPDataSelection::simplify() -{ - // remove any empty ranges: - for (int i=mDataRanges.size()-1; i>=0; --i) - { - if (mDataRanges.at(i).isEmpty()) - mDataRanges.removeAt(i); - } - if (mDataRanges.isEmpty()) - return; - - // sort ranges by starting value, ascending: - std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); - - // join overlapping/contiguous ranges: - int i = 1; - while (i < mDataRanges.size()) - { - if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list - { - mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); - mDataRanges.removeAt(i); - } else - ++i; - } -} - -/*! - Makes sure this data selection conforms to the specified \a type selection type. Before the type - is enforced, \ref simplify is called. - - Depending on \a type, enforcing means adding new data points that were previously not part of the - selection, or removing data points from the selection. If the current selection already conforms - to \a type, the data selection is not changed. - - \see QCP::SelectionType -*/ -void QCPDataSelection::enforceType(QCP::SelectionType type) -{ - simplify(); - switch (type) - { - case QCP::stNone: - { - mDataRanges.clear(); - break; - } - case QCP::stWhole: - { - // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) - break; - } - case QCP::stSingleData: - { - // reduce all data ranges to the single first data point: - if (!mDataRanges.isEmpty()) - { - if (mDataRanges.size() > 1) - mDataRanges = QList() << mDataRanges.first(); - if (mDataRanges.first().length() > 1) - mDataRanges.first().setEnd(mDataRanges.first().begin()+1); - } - break; - } - case QCP::stDataRange: - { - mDataRanges = QList() << span(); - break; - } - case QCP::stMultipleDataRanges: - { - // this is the selection type that allows all concievable combinations of ranges, so do nothing - break; - } - } -} - -/*! - Returns true if the data selection \a other is contained entirely in this data selection, i.e. - all data point indices that are in \a other are also in this data selection. - - \see QCPDataRange::contains -*/ -bool QCPDataSelection::contains(const QCPDataSelection &other) const -{ - if (other.isEmpty()) return false; - - int otherIndex = 0; - int thisIndex = 0; - while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) - { - if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) - ++otherIndex; - else - ++thisIndex; - } - return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this -} - -/*! - Returns a data selection containing the points which are both in this data selection and in the - data range \a other. - - A common use case is to limit an unknown data selection to the valid range of a data container, - using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned - data selection without exceeding the data container's bounds. -*/ -QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const -{ - QCPDataSelection result; - for (int i=0; iorientation() == Qt::Horizontal) - return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); - else - return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); - } else - { - qDebug() << Q_FUNC_INFO << "called with axis zero"; - return QCPRange(); - } -} - -/*! - Sets the pen that will be used to draw the selection rect outline. - - \see setBrush -*/ -void QCPSelectionRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used to fill the selection rect. By default the selection rect is not - filled, i.e. \a brush is Qt::NoBrush. - - \see setPen -*/ -void QCPSelectionRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - If there is currently a selection interaction going on (\ref isActive), the interaction is - canceled. The selection rect will emit the \ref canceled signal. -*/ -void QCPSelectionRect::cancel() -{ - if (mActive) - { - mActive = false; - Q_EMIT canceled(mRect, 0); - } -} - -/*! \internal - - This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. - The default implementation sets the selection rect to active, initializes the selection rect - geometry and emits the \ref started signal. -*/ -void QCPSelectionRect::startSelection(QMouseEvent *event) -{ - mActive = true; - mRect = QRect(event->pos(), event->pos()); - Q_EMIT started(event); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs - to update its geometry. The default implementation updates the rect and emits the \ref changed - signal. -*/ -void QCPSelectionRect::moveSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - Q_EMIT changed(mRect, event); - layer()->replot(); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has - finished by the user releasing the mouse button. The default implementation deactivates the - selection rect and emits the \ref accepted signal. -*/ -void QCPSelectionRect::endSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - mActive = false; - Q_EMIT accepted(mRect, event); -} - -/*! \internal - - This method is called by QCustomPlot when a key has been pressed by the user while the selection - rect interaction is active. The default implementation allows to \ref cancel the interaction by - hitting the escape key. -*/ -void QCPSelectionRect::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape && mActive) - { - mActive = false; - Q_EMIT canceled(mRect, event); - } -} - -/* inherits documentation from base class */ -void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/*! \internal - - If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. - - \seebaseclassmethod -*/ -void QCPSelectionRect::draw(QCPPainter *painter) -{ - if (mActive) - { - painter->setPen(mPen); - painter->setBrush(mBrush); - painter->drawRect(mRect); - } -} -/* end of 'src/selectionrect.cpp' */ - - -/* including file 'src/layout.cpp', size 79064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPMarginGroup -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPMarginGroup - \brief A margin group allows synchronization of margin sides if working with multiple layout elements. - - QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that - they will all have the same size, based on the largest required margin in the group. - - \n - \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" - \n - - In certain situations it is desirable that margins at specific sides are synchronized across - layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will - provide a cleaner look to the user if the left and right margins of the two axis rects are of the - same size. The left axis of the top axis rect will then be at the same horizontal position as the - left axis of the lower axis rect, making them appear aligned. The same applies for the right - axes. This is what QCPMarginGroup makes possible. - - To add/remove a specific side of a layout element to/from a margin group, use the \ref - QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call - \ref clear, or just delete the margin group. - - \section QCPMarginGroup-example Example - - First create a margin group: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 - Then set this group on the layout element sides: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 - Here, we've used the first two axis rects of the plot and synchronized their left margins with - each other and their right margins with each other. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const - - Returns a list of all layout elements that have their margin \a side associated with this margin - group. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPMarginGroup instance in \a parentPlot. -*/ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) -{ - mChildren.insert(QCP::msLeft, QList()); - mChildren.insert(QCP::msRight, QList()); - mChildren.insert(QCP::msTop, QList()); - mChildren.insert(QCP::msBottom, QList()); -} - -QCPMarginGroup::~QCPMarginGroup() -{ - clear(); -} - -/*! - Returns whether this margin group is empty. If this function returns true, no layout elements use - this margin group to synchronize margin sides. -*/ -bool QCPMarginGroup::isEmpty() const -{ - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - if (!it.value().isEmpty()) - return false; - } - return true; -} - -/*! - Clears this margin group. The synchronization of the margin sides that use this margin group is - lifted and they will use their individual margin sizes again. -*/ -void QCPMarginGroup::clear() -{ - // make all children remove themselves from this margin group: - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - const QList elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild - } -} - -/*! \internal - - Returns the synchronized common margin for \a side. This is the margin value that will be used by - the layout element on the respective side, if it is part of this margin group. - - The common margin is calculated by requesting the automatic margin (\ref - QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin - group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into - account, too.) -*/ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const -{ - // query all automatic margins of the layout elements in this margin group side and find maximum: - int result = 0; - const QList elements = mChildren.value(side); - for (int i=0; iautoMargins().testFlag(side)) - continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) - result = m; - } - return result; -} - -/*! \internal - - Adds \a element to the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].contains(element)) - mChildren[side].append(element); - else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); -} - -/*! \internal - - Removes \a element from the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutElement - \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". - - This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. - - A Layout element is a rectangular object which can be placed in layouts. It has an outer rect - (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference - between outer and inner rect is called its margin. The margin can either be set to automatic or - manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be - set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, - the layout element subclass will control the value itself (via \ref calculateAutoMargin). - - Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level - layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref - QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. - - Thus in QCustomPlot one can divide layout elements into two categories: The ones that are - invisible by themselves, because they don't draw anything. Their only purpose is to manage the - position and size of other layout elements. This category of layout elements usually use - QCPLayout as base class. Then there is the category of layout elements which actually draw - something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does - not necessarily mean that the latter category can't have child layout elements. QCPLegend for - instance, actually derives from QCPLayoutGrid and the individual legend items are child layout - elements in the grid layout. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayout *QCPLayoutElement::layout() const - - Returns the parent layout of this layout element. -*/ - -/*! \fn QRect QCPLayoutElement::rect() const - - Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref - setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). - - In some cases, the area between outer and inner rect is left blank. In other cases the margin - area is used to display peripheral graphics while the main content is in the inner rect. This is - where automatic margin calculation becomes interesting because it allows the layout element to - adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect - draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if - \ref setAutoMargins is enabled) according to the space required by the labels of the axes. - - \see outerRect -*/ - -/*! \fn QRect QCPLayoutElement::outerRect() const - - Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the - margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref - setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. - - \see rect -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutElement and sets default values. -*/ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mSizeConstraintRect(scrInnerRect), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) -{ -} - -QCPLayoutElement::~QCPLayoutElement() -{ - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any - // unregister at layout: - if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); -} - -/*! - Sets the outer rect of this layout element. If the layout element is inside a layout, the layout - sets the position and size of this layout element using this function. - - Calling this function externally has no effect, since the layout will overwrite any changes to - the outer rect upon the next replot. - - The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. - - \see rect -*/ -void QCPLayoutElement::setOuterRect(const QRect &rect) -{ - if (mOuterRect != rect) - { - mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all - sides, this function is used to manually set the margin on those sides. Sides that are still set - to be handled automatically are ignored and may have any value in \a margins. - - The margin is the distance between the outer rect (controlled by the parent layout via \ref - setOuterRect) and the inner \ref rect (which usually contains the main content of this layout - element). - - \see setAutoMargins -*/ -void QCPLayoutElement::setMargins(const QMargins &margins) -{ - if (mMargins != margins) - { - mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - If \ref setAutoMargins is enabled on some or all margins, this function is used to provide - minimum values for those margins. - - The minimum values are not enforced on margin sides that were set to be under manual control via - \ref setAutoMargins. - - \see setAutoMargins -*/ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) -{ - if (mMinimumMargins != margins) - { - mMinimumMargins = margins; - } -} - -/*! - Sets on which sides the margin shall be calculated automatically. If a side is calculated - automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is - set to be controlled manually, the value may be specified with \ref setMargins. - - Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref - setMarginGroup), to synchronize (align) it with other layout elements in the plot. - - \see setMinimumMargins, setMargins, QCP::MarginSide -*/ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) -{ - mAutoMargins = sides; -} - -/*! - Sets the minimum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - If the parent layout size is not sufficient to satisfy all minimum size constraints of its child - layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot - propagates the layout's size constraints to the outside by setting its own minimum QWidget size - accordingly, so violations of \a size should be exceptions. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(const QSize &size) -{ - if (mMinimumSize != size) - { - mMinimumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the minimum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(int width, int height) -{ - setMinimumSize(QSize(width, height)); -} - -/*! - Sets the maximum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(const QSize &size) -{ - if (mMaximumSize != size) - { - mMaximumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the maximum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(int width, int height) -{ - setMaximumSize(QSize(width, height)); -} - -/*! - Sets to which rect of a layout element the size constraints apply. Size constraints can be set - via \ref setMinimumSize and \ref setMaximumSize. - - The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis - labels), whereas the inner rect (\ref rect) does not. - - \see setMinimumSize, setMaximumSize -*/ -void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) -{ - if (mSizeConstraintRect != constraintRect) - { - mSizeConstraintRect = constraintRect; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! - Sets the margin \a group of the specified margin \a sides. - - Margin groups allow synchronizing specified margins across layout elements, see the documentation - of \ref QCPMarginGroup. - - To unset the margin group of \a sides, set \a group to 0. - - Note that margin groups only work for margin sides that are set to automatic (\ref - setAutoMargins). - - \see QCP::MarginSide -*/ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) -{ - QVector sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; iremoveChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there - { - mMarginGroups.remove(side); - } else // setting to a new group - { - mMarginGroups[side] = group; - group->addChild(side, this); - } - } - } -} - -/*! - Updates the layout element and sub-elements. This function is automatically called before every - replot by the parent layout element. It is called multiple times, once for every \ref - UpdatePhase. The phases are run through in the order of the enum values. For details about what - happens at the different phases, see the documentation of \ref UpdatePhase. - - Layout elements that have child elements should call the \ref update method of their child - elements, and pass the current \a phase unchanged. - - The default implementation executes the automatic margin mechanism in the \ref upMargins phase. - Subclasses should make sure to call the base class implementation. -*/ -void QCPLayoutElement::update(UpdatePhase phase) -{ - if (phase == upMargins) - { - if (mAutoMargins != QCP::msNone) - { - // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: - QMargins newMargins = mMargins; - QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; - Q_FOREACH (QCP::MarginSide side, allMarginSides) - { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically - { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group - else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly - // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); - } - } - setMargins(newMargins); - } - } -} - -/*! - Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, - if no manual minimum size is set. - - if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size - (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum - allowed size of this layout element. - - A manual minimum size is considered set if it is non-zero. - - The default implementation simply returns the sum of the horizontal margins for the width and the - sum of the vertical margins for the height. Reimplementations may use their detailed knowledge - about the layout element's content to provide size hints. -*/ -QSize QCPLayoutElement::minimumOuterSizeHint() const -{ - return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); -} - -/*! - Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, - if no manual maximum size is set. - - if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned - size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the - maximum allowed size of this layout element. - - A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. - - The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying - no suggested maximum size. Reimplementations may use their detailed knowledge about the layout - element's content to provide size hints. -*/ -QSize QCPLayoutElement::maximumOuterSizeHint() const -{ - return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); -} - -/*! - Returns a list of all child elements in this layout element. If \a recursive is true, all - sub-child elements are included in the list, too. - - \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have - empty cells which yield 0 at the respective index.) -*/ -QList QCPLayoutElement::elements(bool recursive) const -{ - Q_UNUSED(recursive) - return QList(); -} - -/*! - Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer - rect, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is - true, -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. - - QCPLayoutElement subclasses may reimplement this method to provide more specific selection test - behaviour. -*/ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - - if (onlySelectable) - return -1; - - if (QRectF(mOuterRect).contains(pos)) - { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; - else - { - qDebug() << Q_FUNC_INFO << "parent plot not defined"; - return -1; - } - } else - return -1; -} - -/*! \internal - - propagates the parent plot initialization to all child elements, by calling \ref - QCPLayerable::initializeParentPlot on them. -*/ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_FOREACH (QCPLayoutElement* el, elements(false)) - { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); - } -} - -/*! \internal - - Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a - side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the - returned value will not be smaller than the specified minimum margin. - - The default implementation just returns the respective manual margin (\ref setMargins) or the - minimum margin, whichever is larger. -*/ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) -{ - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); -} - -/*! \internal - - This virtual method is called when this layout element was moved to a different QCPLayout, or - when this layout element has changed its logical position (e.g. row and/or column) within the - same QCPLayout. Subclasses may use this to react accordingly. - - Since this method is called after the completion of the move, you can access the new parent - layout via \ref layout(). - - The default implementation does nothing. -*/ -void QCPLayoutElement::layoutChanged() -{ -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayout -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayout - \brief The abstract base class for layouts - - This is an abstract base class for layout elements whose main purpose is to define the position - and size of other child layout elements. In most cases, layouts don't draw anything themselves - (but there are exceptions to this, e.g. QCPLegend). - - QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. - - QCPLayout introduces a common interface for accessing and manipulating the child elements. Those - functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref - simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions - to this interface which are more specialized to the form of the layout. For example, \ref - QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid - more conveniently. - - Since this is an abstract base class, you can't instantiate it directly. Rather use one of its - subclasses like QCPLayoutGrid or QCPLayoutInset. - - For a general introduction to the layout system, see the dedicated documentation page \ref - thelayoutsystem "The Layout System". -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPLayout::elementCount() const = 0 - - Returns the number of elements/cells in the layout. - - \see elements, elementAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 - - Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. - - Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. - QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check - whether a cell is empty or not. - - \see elements, elementCount, takeAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 - - Removes the element with the given \a index from the layout and returns it. - - If the \a index is invalid or the cell with that index is empty, returns 0. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see elementAt, take -*/ - -/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 - - Removes the specified \a element from the layout and returns true on success. - - If the \a element isn't in this layout, returns false. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see takeAt -*/ - -/* end documentation of pure virtual functions */ - -/*! - Creates an instance of QCPLayout and sets default values. Note that since QCPLayout - is an abstract base class, it can't be instantiated directly. -*/ -QCPLayout::QCPLayout() -{ -} - -/*! - If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to - reposition and resize their cells. - - Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". - - For details about this method and the update phases, see the documentation of \ref - QCPLayoutElement::update. -*/ -void QCPLayout::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - // set child element rects according to layout: - if (phase == upLayout) - updateLayout(); - - // propagate update call to child elements: - const int elCount = elementCount(); - for (int i=0; iupdate(phase); - } -} - -/* inherits documentation from base class */ -QList QCPLayout::elements(bool recursive) const -{ - const int c = elementCount(); - QList result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the - default implementation does nothing. - - Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit - simplification while QCPLayoutGrid does. -*/ -void QCPLayout::simplify() -{ -} - -/*! - Removes and deletes the element at the provided \a index. Returns true on success. If \a index is - invalid or points to an empty cell, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the returned element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see remove, takeAt -*/ -bool QCPLayout::removeAt(int index) -{ - if (QCPLayoutElement *el = takeAt(index)) - { - delete el; - return true; - } else - return false; -} - -/*! - Removes and deletes the provided \a element. Returns true on success. If \a element is not in the - layout, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see removeAt, take -*/ -bool QCPLayout::remove(QCPLayoutElement *element) -{ - if (take(element)) - { - delete element; - return true; - } else - return false; -} - -/*! - Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure - all empty cells are collapsed. - - \see remove, removeAt -*/ -void QCPLayout::clear() -{ - for (int i=elementCount()-1; i>=0; --i) - { - if (elementAt(i)) - removeAt(i); - } - simplify(); -} - -/*! - Subclasses call this method to report changed (minimum/maximum) size constraints. - - If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref - sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of - QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, - it may update itself and resize cells accordingly. -*/ -void QCPLayout::sizeConstraintsChanged() const -{ - if (QWidget *w = qobject_cast(parent())) - w->updateGeometry(); - else if (QCPLayout *l = qobject_cast(parent())) - l->sizeConstraintsChanged(); -} - -/*! \internal - - Subclasses reimplement this method to update the position and sizes of the child elements/cells - via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. - - The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay - within that rect. - - \ref getSectionSizes may help with the reimplementation of this function. - - \see update -*/ -void QCPLayout::updateLayout() -{ -} - - -/*! \internal - - Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the - \ref QCPLayerable::parentLayerable and the QObject parent to this layout. - - Further, if \a el didn't previously have a parent plot, calls \ref - QCPLayerable::initializeParentPlot on \a el to set the paret plot. - - This method is used by subclass specific methods that add elements to the layout. Note that this - method only changes properties in \a el. The removal from the old layout and the insertion into - the new layout must be done additionally. -*/ -void QCPLayout::adoptElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); - el->layoutChanged(); - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout - and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent - QCustomPlot. - - This method is used by subclass specific methods that remove elements from the layout (e.g. \ref - take or \ref takeAt). Note that this method only changes properties in \a el. The removal from - the old layout must be done additionally. -*/ -void QCPLayout::releaseElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); - // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - This is a helper function for the implementation of \ref updateLayout in subclasses. - - It calculates the sizes of one-dimensional sections with provided constraints on maximum section - sizes, minimum section sizes, relative stretch factors and the final total size of all sections. - - The QVector entries refer to the sections. Thus all QVectors must have the same size. - - \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size - imposed, set all vector values to Qt's QWIDGETSIZE_MAX. - - \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size - imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than - \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, - not exceeding the allowed total size is taken to be more important than not going below minimum - section sizes.) - - \a stretchFactors give the relative proportions of the sections to each other. If all sections - shall be scaled equally, set all values equal. If the first section shall be double the size of - each individual other section, set the first number of \a stretchFactors to double the value of - the other individual values (e.g. {2, 1, 1, 1}). - - \a totalSize is the value that the final section sizes will add up to. Due to rounding, the - actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, - you could distribute the remaining difference on the sections. - - The return value is a QVector containing the section sizes. -*/ -QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const -{ - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) - { - qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; - return QVector(); - } - if (stretchFactors.isEmpty()) - return QVector(); - int sectionCount = stretchFactors.size(); - QVector sectionSizes(sectionCount); - // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): - int minSizeSum = 0; - for (int i=0; i minimumLockedSections; - QList unfinishedSections; - for (int i=0; i result(sectionCount); - for (int i=0; iminimumOuterSizeHint(); - QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) - if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rwidth() += el->margins().left() + el->margins().right(); - if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; -} - -/*! \internal - - This is a helper function for the implementation of subclasses. - - It returns the maximum size that should finally be used for the outer rect of the passed layout - element \a el. - - It takes into account whether a manual maximum size is set (\ref - QCPLayoutElement::setMaximumSize), which size constraint is set (\ref - QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum - size was set (\ref QCPLayoutElement::maximumOuterSizeHint). -*/ -QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) -{ - QSize maxOuterHint = el->maximumOuterSizeHint(); - QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) - if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rwidth() += el->margins().left() + el->margins().right(); - if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutGrid - \brief A layout that arranges child elements in a grid - - Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, - \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). - - Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or - column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref - hasElement, that element can be retrieved with \ref element. If rows and columns that only have - empty cells shall be removed, call \ref simplify. Removal of elements is either done by just - adding the element to a different layout or by using the QCPLayout interface \ref take or \ref - remove. - - If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a - column, the grid layout will choose the position according to the current \ref setFillOrder and - the wrapping (\ref setWrap). - - Row and column insertion can be performed with \ref insertRow and \ref insertColumn. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPLayoutGrid::rowCount() const - - Returns the number of rows in the layout. - - \see columnCount -*/ - -/*! \fn int QCPLayoutGrid::columnCount() const - - Returns the number of columns in the layout. - - \see rowCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutGrid and sets default values. -*/ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5), - mWrap(0), - mFillOrder(foRowsFirst) -{ -} - -QCPLayoutGrid::~QCPLayoutGrid() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the element in the cell in \a row and \a column. - - Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug - message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. - - \see addElement, hasElement -*/ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const -{ - if (row >= 0 && row < mElements.size()) - { - if (column >= 0 && column < mElements.first().size()) - { - if (QCPLayoutElement *result = mElements.at(row).at(column)) - return result; - else - qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; - return 0; -} - - -/*! \overload - - Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it - is first removed from there. If \a row or \a column don't exist yet, the layout is expanded - accordingly. - - Returns true if the element was added successfully, i.e. if the cell at \a row and \a column - didn't already have an element. - - Use the overload of this method without explicit row/column index to place the element according - to the configured fill order and wrapping settings. - - \see element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) -{ - if (!hasElement(row, column)) - { - if (element && element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); - mElements[row][column] = element; - if (element) - adoptElement(element); - return true; - } else - qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; - return false; -} - -/*! \overload - - Adds the \a element to the next empty cell according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first - removed from there. If necessary, the layout is expanded to hold the new element. - - Returns true if the element was added successfully. - - \see setFillOrder, setWrap, element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(QCPLayoutElement *element) -{ - int rowIndex = 0; - int colIndex = 0; - if (mFillOrder == foColumnsFirst) - { - while (hasElement(rowIndex, colIndex)) - { - ++colIndex; - if (colIndex >= mWrap && mWrap > 0) - { - colIndex = 0; - ++rowIndex; - } - } - } else - { - while (hasElement(rowIndex, colIndex)) - { - ++rowIndex; - if (rowIndex >= mWrap && mWrap > 0) - { - rowIndex = 0; - ++colIndex; - } - } - } - return addElement(rowIndex, colIndex, element); -} - -/*! - Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't - empty. - - \see element -*/ -bool QCPLayoutGrid::hasElement(int row, int column) -{ - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); - else - return false; -} - -/*! - Sets the stretch \a factor of \a column. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) -{ - if (column >= 0 && column < columnCount()) - { - if (factor > 0) - mColumnStretchFactors[column] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid column:" << column; -} - -/*! - Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactor, setRowStretchFactors -*/ -void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) -{ - if (factors.size() == mColumnStretchFactors.size()) - { - mColumnStretchFactors = factors; - for (int i=0; i= 0 && row < rowCount()) - { - if (factor > 0) - mRowStretchFactors[row] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid row:" << row; -} - -/*! - Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setRowStretchFactor, setColumnStretchFactors -*/ -void QCPLayoutGrid::setRowStretchFactors(const QList &factors) -{ - if (factors.size() == mRowStretchFactors.size()) - { - mRowStretchFactors = factors; - for (int i=0; i tempElements; - if (rearrange) - { - tempElements.reserve(elCount); - for (int i=0; i()); - mRowStretchFactors.append(1); - } - // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i rowCount()) - newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); - QList newRow; - for (int col=0; col columnCount()) - newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row= 0 && row < rowCount()) - { - if (column >= 0 && column < columnCount()) - { - switch (mFillOrder) - { - case foRowsFirst: return column*rowCount() + row; - case foColumnsFirst: return row*columnCount() + column; - } - } else - qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; - } else - qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; - return 0; -} - -/*! - Converts the linear index to row and column indices and writes the result to \a row and \a - column. - - The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the - indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices - increase top to bottom and then left to right. - - If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. - - For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, - i.e. greater or equal to zero and smaller than the current \ref elementCount. - - \see rowColToIndex -*/ -void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const -{ - row = -1; - column = -1; - const int nCols = columnCount(); - const int nRows = rowCount(); - if (nCols == 0 || nRows == 0) - return; - if (index < 0 || index >= elementCount()) - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return; - } - - switch (mFillOrder) - { - case foRowsFirst: - { - column = index / nRows; - row = index % nRows; - break; - } - case foColumnsFirst: - { - row = index / nCols; - column = index % nCols; - break; - } - } -} - -/* inherits documentation from base class */ -void QCPLayoutGrid::updateLayout() -{ - QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - - // go through cells and set rects accordingly: - int yOffset = mRect.top(); - for (int row=0; row 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; - int xOffset = mRect.left(); - for (int col=0; col 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); - } - } -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const -{ - if (index >= 0 && index < elementCount()) - { - int row, col; - indexToRowCol(index, row, col); - return mElements.at(row).at(col); - } else - return 0; -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - int row, col; - indexToRowCol(index, row, col); - mElements[row][col] = 0; - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i QCPLayoutGrid::elements(bool recursive) const -{ - QList result; - const int elCount = elementCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(elCount); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing rows and columns which only contain empty cells. -*/ -void QCPLayoutGrid::simplify() -{ - // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) - { - bool hasElements = false; - for (int col=0; col=0; --col) - { - bool hasElements = false; - for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i QWIDGETSIZE_MAX) - result.setHeight(QWIDGETSIZE_MAX); - if (result.width() > QWIDGETSIZE_MAX) - result.setWidth(QWIDGETSIZE_MAX); - return result; -} - -/*! \internal - - Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights - respectively. - - The minimum height of a row is the largest minimum height of any element's outer rect in that - row. The minimum width of a column is the largest minimum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMaximumRowColSizes -*/ -void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const -{ - *minColWidths = QVector(columnCount(), 0); - *minRowHeights = QVector(rowCount(), 0); - for (int row=0; rowat(col) < minSize.width()) - (*minColWidths)[col] = minSize.width(); - if (minRowHeights->at(row) < minSize.height()) - (*minRowHeights)[row] = minSize.height(); - } - } - } -} - -/*! \internal - - Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights - respectively. - - The maximum height of a row is the smallest maximum height of any element's outer rect in that - row. The maximum width of a column is the smallest maximum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMinimumRowColSizes -*/ -void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const -{ - *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; rowat(col) > maxSize.width()) - (*maxColWidths)[col] = maxSize.width(); - if (maxRowHeights->at(row) > maxSize.height()) - (*maxRowHeights)[row] = maxSize.height(); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutInset -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPLayoutInset - \brief A layout that places child elements aligned to the border or arbitrarily positioned - - Elements are placed either aligned to the border or at arbitrary position in the area of the - layout. Which placement applies is controlled with the \ref InsetPlacement (\ref - setInsetPlacement). - - Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or - addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset - placement will default to \ref ipBorderAligned and the element will be aligned according to the - \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at - arbitrary position and size, defined by \a rect. - - The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. - - This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual void QCPLayoutInset::simplify() - - The QCPInsetLayout does not need simplification since it can never have empty cells due to its - linear index structure. This method does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutInset and sets default values. -*/ -QCPLayoutInset::QCPLayoutInset() -{ -} - -QCPLayoutInset::~QCPLayoutInset() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the placement type of the element with the specified \a index. -*/ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const -{ - if (elementAt(index)) - return mInsetPlacement.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return ipFree; - } -} - -/*! - Returns the alignment of the element with the specified \a index. The alignment only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. -*/ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const -{ - if (elementAt(index)) - return mInsetAlignment.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return 0; - } -} - -/*! - Returns the rect of the element with the specified \a index. The rect only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. -*/ -QRectF QCPLayoutInset::insetRect(int index) const -{ - if (elementAt(index)) - return mInsetRect.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return QRectF(); - } -} - -/*! - Sets the inset placement type of the element with the specified \a index to \a placement. - - \see InsetPlacement -*/ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) -{ - if (elementAt(index)) - mInsetPlacement[index] = placement; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function - is used to set the alignment of the element with the specified \a index to \a alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. -*/ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) -{ - if (elementAt(index)) - mInsetAlignment[index] = alignment; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the - position and size of the element with the specified \a index to \a rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - Note that the minimum and maximum sizes of the embedded element (\ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. -*/ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) -{ - if (elementAt(index)) - mInsetRect[index] = rect; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/* inherits documentation from base class */ -void QCPLayoutInset::updateLayout() -{ - for (int i=0; i finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter - } - mElements.at(i)->setOuterRect(insetRect); - } -} - -/* inherits documentation from base class */ -int QCPLayoutInset::elementCount() const -{ - return mElements.size(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const -{ - if (index >= 0 && index < mElements.size()) - return mElements.at(index); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! - Adds the specified \a element to the layout as an inset aligned at the border (\ref - setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a - alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. - - \see addElement(QCPLayoutElement *element, const QRectF &rect) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - -/*! - Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref - setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a - rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} -/* end of 'src/layout.cpp' */ - - -/* including file 'src/lineending.cpp', size 11536 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLineEnding -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLineEnding - \brief Handles the different ending decorations for line-like items - - \image html QCPLineEnding.png "The various ending styles currently supported" - - For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine - has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. - - The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can - be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of - the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. - For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite - directions, e.g. "outward". This can be changed by \ref setInverted, which would make the - respective arrow point inward. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify a - QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. - \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead -*/ - -/*! - Creates a QCPLineEnding instance with default values (style \ref esNone). -*/ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) -{ -} - -/*! - Creates a QCPLineEnding instance with the specified values. -*/ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) -{ -} - -/*! - Sets the style of the ending decoration. -*/ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) -{ - mStyle = style; -} - -/*! - Sets the width of the ending decoration, if the style supports it. On arrows, for example, the - width defines the size perpendicular to the arrow's pointing direction. - - \see setLength -*/ -void QCPLineEnding::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the length of the ending decoration, if the style supports it. On arrows, for example, the - length defines the size in pointing direction. - - \see setWidth -*/ -void QCPLineEnding::setLength(double length) -{ - mLength = length; -} - -/*! - Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point - inward when \a inverted is set to true. - - Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or - discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are - affected by it, which can be used to control to which side the half bar points to. -*/ -void QCPLineEnding::setInverted(bool inverted) -{ - mInverted = inverted; -} - -/*! \internal - - Returns the maximum pixel radius the ending decoration might cover, starting from the position - the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). - - This is relevant for clipping. Only omit painting of the decoration when the position where the - decoration is supposed to be drawn is farther away from the clipping rect than the returned - distance. -*/ -double QCPLineEnding::boundingDistance() const -{ - switch (mStyle) - { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) - - } - return 0; -} - -/*! - Starting from the origin of this line ending (which is style specific), returns the length - covered by the line ending symbol, in backward direction. - - For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if - both have the same \ref setLength value, because the spike arrow has an inward curved back, which - reduces the length along its center axis (the drawing origin for arrows is at the tip). - - This function is used for precise, style specific placement of line endings, for example in - QCPAxes. -*/ -double QCPLineEnding::realLength() const -{ - switch (mStyle) - { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; - } - return 0; -} - -/*! \internal - - Draws the line ending with the specified \a painter at the position \a pos. The direction of the - line ending is controlled with \a dir. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const -{ - if (mStyle == esNone) - return; - - QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); - if (lengthVec.isNull()) - lengthVec = QCPVector2D(1, 0); - QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); - - QPen penBackup = painter->pen(); - QBrush brushBackup = painter->brush(); - QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) - { - case esNone: break; - case esFlatArrow: - { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esSpikeArrow: - { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; - } - } -} - -/*! \internal - \overload - - Draws the line ending. The direction is controlled with the \a angle parameter in radians. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const -{ - draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); -} -/* end of 'src/lineending.cpp' */ - - -/* including file 'src/axis/axisticker.cpp', size 18664 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTicker -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTicker - \brief The base class tick generator used by QCPAxis to create tick positions and tick labels - - Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions - and tick labels for the current axis range. The ticker of an axis can be set via \ref - QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple - axes can share the same ticker instance. - - This base class generates normal tick coordinates and numeric labels for linear axes. It picks a - reasonable tick step (the separation between ticks) which results in readable tick labels. The - number of ticks that should be approximately generated can be set via \ref setTickCount. - Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either - sacrifices readability to better match the specified tick count (\ref - QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref - QCPAxisTicker::tssReadability), which is the default. - - The following more specialized axis ticker subclasses are available, see details in the - respective class documentation: - -
- - - - - - - -
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png - \image html axisticker-time2.png
-
- - \section axisticker-subclassing Creating own axis tickers - - Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and - reimplementing some or all of the available virtual methods. - - In the simplest case you might wish to just generate different tick steps than the other tickers, - so you only reimplement the method \ref getTickStep. If you additionally want control over the - string that will be shown as tick label, reimplement \ref getTickLabel. - - If you wish to have complete control, you can generate the tick vectors and tick label vectors - yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default - implementations use the previously mentioned virtual methods \ref getTickStep and \ref - getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case - of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. - - The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick - placement control is obtained by reimplementing \ref createSubTickVector. - - See the documentation of all these virtual methods in QCPAxisTicker for detailed information - about the parameters and expected return values. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTicker::QCPAxisTicker() : - mTickStepStrategy(tssReadability), - mTickCount(5), - mTickOrigin(0) -{ -} - -QCPAxisTicker::~QCPAxisTicker() -{ - -} - -/*! - Sets which strategy the axis ticker follows when choosing the size of the tick step. For the - available strategies, see \ref TickStepStrategy. -*/ -void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) -{ - mTickStepStrategy = strategy; -} - -/*! - Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count - is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with - the requested number of ticks. - - Whether the readability has priority over meeting the requested \a count can be specified with - \ref setTickStepStrategy. -*/ -void QCPAxisTicker::setTickCount(int count) -{ - if (count > 0) - mTickCount = count; - else - qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; -} - -/*! - Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a - concept and doesn't need to be inside the currently visible axis range. - - By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick - step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be - {-4, 1, 6, 11, 16,...}. -*/ -void QCPAxisTicker::setTickOrigin(double origin) -{ - mTickOrigin = origin; -} - -/*! - This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), - tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). - - The ticks are generated for the specified \a range. The generated labels typically follow the - specified \a locale, \a formatChar and number \a precision, however this might be different (or - even irrelevant) for certain QCPAxisTicker subclasses. - - The output parameter \a ticks is filled with the generated tick positions in axis coordinates. - The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) - and are respectively filled with sub tick coordinates, and tick label strings belonging to \a - ticks by index. -*/ -void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) -{ - // generate (major) ticks: - double tickStep = getTickStep(range); - ticks = createTickVector(tickStep, range); - trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) - - // generate sub ticks between major ticks: - if (subTicks) - { - if (ticks.size() > 0) - { - *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); - trimTicks(range, *subTicks, false); - } else - *subTicks = QVector(); - } - - // finally trim also outliers (no further clipping happens in axis drawing): - trimTicks(range, ticks, false); - // generate labels for visible ticks if requested: - if (tickLabels) - *tickLabels = createLabelVector(ticks, locale, formatChar, precision); -} - -/*! \internal - - Takes the entire currently visible axis range and returns a sensible tick step in - order to provide readable tick labels as well as a reasonable number of tick counts (see \ref - setTickCount, \ref setTickStepStrategy). - - If a QCPAxisTicker subclass only wants a different tick step behaviour than the default - implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper - function. -*/ -double QCPAxisTicker::getTickStep(const QCPRange &range) -{ - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return cleanMantissa(exactStep); -} - -/*! \internal - - Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns - an appropriate number of sub ticks for that specific tick step. - - Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. -*/ -int QCPAxisTicker::getSubTickCount(double tickStep) -{ - int result = 1; // default to 1, if no proper value can be found - - // separate integer and fractional part of mantissa: - double epsilon = 0.01; - double intPartf; - int intPart; - double fracPart = modf(getMantissa(tickStep), &intPartf); - intPart = intPartf; - - // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) - { - if (1.0-fracPart < epsilon) - ++intPart; - switch (intPart) - { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep - } - } else - { - // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa - { - switch (intPart) - { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep - } - } - // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default - } - - return result; -} - -/*! \internal - - This method returns the tick label string as it should be printed under the \a tick coordinate. - If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a - precision. - - If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is - enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will - be formatted accordingly using multiplication symbol and superscript during rendering of the - label automatically. -*/ -QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - return locale.toString(tick, formatChar.toLatin1(), precision); -} - -/*! \internal - - Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a - subTickCount sub ticks between each tick pair given in \a ticks. - - If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should - reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to - base its result on \a subTickCount or \a ticks. -*/ -QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) -{ - QVector result; - if (subTickCount <= 0 || ticks.size() < 2) - return result; - - result.reserve((ticks.size()-1)*subTickCount); - for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result; - // Generate tick positions according to tickStep: - qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - result.resize(tickcount); - for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) -{ - QVector result; - result.reserve(ticks.size()); - for (int i=0; i &ticks, bool keepOneOutlier) const -{ - bool lowFound = false; - bool highFound = false; - int lowIndex = 0; - int highIndex = -1; - - for (int i=0; i < ticks.size(); ++i) - { - if (ticks.at(i) >= range.lower) - { - lowFound = true; - lowIndex = i; - break; - } - } - for (int i=ticks.size()-1; i >= 0; --i) - { - if (ticks.at(i) <= range.upper) - { - highFound = true; - highIndex = i; - break; - } - } - - if (highFound && lowFound) - { - int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); - int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); - if (trimFront > 0 || trimBack > 0) - ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); - } else // all ticks are either all below or all above the range - ticks.clear(); -} - -/*! \internal - - Returns the coordinate contained in \a candidates which is closest to the provided \a target. - - This method assumes \a candidates is not empty and sorted in ascending order. -*/ -double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const -{ - if (candidates.size() == 1) - return candidates.first(); - QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); - if (it == candidates.constEnd()) - return *(it-1); - else if (it == candidates.constBegin()) - return *it; - else - return target-*(it-1) < *it-target ? *(it-1) : *it; -} - -/*! \internal - - Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also - returns the magnitude of \a input as a power of 10. - - For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. -*/ -double QCPAxisTicker::getMantissa(double input, double *magnitude) const -{ - const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); - if (magnitude) *magnitude = mag; - return input/mag; -} - -/*! \internal - - Returns a number that is close to \a input but has a clean, easier human readable mantissa. How - strongly the mantissa is altered, and thus how strong the result deviates from the original \a - input, depends on the current tick step strategy (see \ref setTickStepStrategy). -*/ -double QCPAxisTicker::cleanMantissa(double input) const -{ - double magnitude; - const double mantissa = getMantissa(input, &magnitude); - switch (mTickStepStrategy) - { - case tssReadability: - { - return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; - } - case tssMeetTickCount: - { - // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 - if (mantissa <= 5.0) - return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 - else - return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 - } - } - return input; -} -/* end of 'src/axis/axisticker.cpp' */ - - -/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerDateTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerDateTime - \brief Specialized axis ticker for calendar dates and times as axis ticks - - \image html axisticker-datetime.png - - This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The - plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 - UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods - with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime - by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey - and \ref keyToDateTime conveniently perform this conversion achieving a precision of one - millisecond on all Qt versions. - - The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. - If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. - - This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day - ticks. For example, if the axis range spans a few years such that there is one tick per year, - ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, - will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in - the image above: even though the number of days varies month by month, this ticker generates - ticks on the same day of each month. - - If you would like to change the date/time that is used as a (mathematical) starting date for the - ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a - QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at - 9:45 of every year. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation - - \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and - milliseconds, and are not interested in the intricacies of real calendar dates with months and - (leap) years, have a look at QCPAxisTickerTime instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerDateTime::QCPAxisTickerDateTime() : - mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), - mDateTimeSpec(Qt::LocalTime), - mDateStrategy(dsNone) -{ - setTickCount(4); -} - -/*! - Sets the format in which dates and times are displayed as tick labels. For details about the \a - format string, see the documentation of QDateTime::toString(). - - Newlines can be inserted with "\n". - - \see setDateTimeSpec -*/ -void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) -{ - mDateTimeFormat = format; -} - -/*! - Sets the time spec that is used for creating the tick labels from corresponding dates/times. - - The default value of QDateTime objects (and also QCPAxisTickerDateTime) is - Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form - of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC - to get the correct axis labels. - - \see setDateTimeFormat -*/ -void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) -{ - mDateTimeSpec = spec; -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, - 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which - directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(double origin) -{ - QCPAxisTicker::setTickOrigin(origin); -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) -{ - setTickOrigin(dateTimeToKey(origin)); -} - -/*! \internal - - Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - Note that this tick step isn't used exactly when generating the tick vector in \ref - createTickVector, but only as a guiding value requiring some correction for each individual tick - interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day - in the month to the last day in the previous month from tick to tick, due to the non-uniform - length of months. The same problem arises with leap years. - - \seebaseclassmethod -*/ -double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - mDateStrategy = dsNone; - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - result = cleanMantissa(result); - } else if (result < 86400*30.4375*12) // below a year - { - result = pickClosest(result, QVector() - << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range - << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range - << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) - if (result > 86400*30.4375-1) // month tick intervals or larger - mDateStrategy = dsUniformDayInMonth; - else if (result > 3600*24-1) // day tick intervals or larger - mDateStrategy = dsUniformTimeInDay; - } else // more than a year, go back to normal clean mantissa algorithm but in units of years - { - const double secondsPerYear = 86400*30.4375*12; // average including leap years - result = cleanMantissa(result/secondsPerYear)*secondsPerYear; - mDateStrategy = dsUniformDayInMonth; - } - return result; -} - -/*! \internal - - Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - \seebaseclassmethod -*/ -int QCPAxisTickerDateTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - case 86400*2: result = 1; break; - case 86400*5: result = 4; break; - case 86400*7: result = 6; break; - case 86400*14: result = 1; break; - case (int)(86400*30.4375+0.5): result = 3; break; - case (int)(86400*30.4375*2+0.5): result = 1; break; - case (int)(86400*30.4375*3+0.5): result = 2; break; - case (int)(86400*30.4375*6+0.5): result = 5; break; - case (int)(86400*30.4375*12+0.5): result = 3; break; - } - return result; -} - -/*! \internal - - Generates a date/time tick label for tick coordinate \a tick, based on the currently set format - (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). - - \seebaseclassmethod -*/ -QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -} - -/*! \internal - - Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain - non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. - - \seebaseclassmethod -*/ -QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result = QCPAxisTicker::createTickVector(tickStep, range); - if (!result.isEmpty()) - { - if (mDateStrategy == dsUniformTimeInDay) - { - QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible - QDateTime tickDateTime; - for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day - tickDateTime = tickDateTime.addMonths(-1); - tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); - result[i] = dateTimeToKey(tickDateTime); - } - } - } - return result; -} - -/*! - A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a - QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) - - \see dateTimeToKey -*/ -QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); -# else - return QDateTime::fromMSecsSinceEpoch(key*1000.0); -# endif -} - -/*! \overload - - A convenience method which turns a QDateTime object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return dateTime.toTime_t()+dateTime.time().msec()/1000.0; -# else - return dateTime.toMSecsSinceEpoch()/1000.0; -# endif -} - -/*! \overload - - A convenience method which turns a QDate object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime(date).toTime_t(); -# else - return QDateTime(date).toMSecsSinceEpoch()/1000.0; -# endif -} -/* end of 'src/axis/axistickerdatetime.cpp' */ - - -/* including file 'src/axis/axistickertime.cpp', size 11747 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerTime - \brief Specialized axis ticker for time spans in units of milliseconds to days - - \image html axisticker-time.png - - This QCPAxisTicker subclass generates ticks that corresponds to time intervals. - - The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref - setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate - zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date - and time. - - The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the - largest available unit in the format specified with \ref setTimeFormat, any time spans above will - be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at - coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick - label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour - unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis - zero will carry a leading minus sign. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation - - Here is an example of a time axis providing time information in days, hours and minutes. Due to - the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker - decided to use tick steps of 12 hours: - - \image html axisticker-time2.png - - The format string for this example is - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 - - \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime - instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerTime::QCPAxisTickerTime() : - mTimeFormat(QLatin1String("%h:%m:%s")), - mSmallestUnit(tuSeconds), - mBiggestUnit(tuHours) -{ - setTickCount(4); - mFieldWidth[tuMilliseconds] = 3; - mFieldWidth[tuSeconds] = 2; - mFieldWidth[tuMinutes] = 2; - mFieldWidth[tuHours] = 2; - mFieldWidth[tuDays] = 1; - - mFormatPattern[tuMilliseconds] = QLatin1String("%z"); - mFormatPattern[tuSeconds] = QLatin1String("%s"); - mFormatPattern[tuMinutes] = QLatin1String("%m"); - mFormatPattern[tuHours] = QLatin1String("%h"); - mFormatPattern[tuDays] = QLatin1String("%d"); -} - -/*! - Sets the format that will be used to display time in the tick labels. - - The available patterns are: - - %%z for milliseconds - - %%s for seconds - - %%m for minutes - - %%h for hours - - %%d for days - - The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. - - The largest unit that appears in \a format will carry all the remaining time of a certain tick - coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the - largest unit it might become larger than 59 in order to consume larger time values. If on the - other hand %%h is available, the minutes will wrap around to zero after 59 and the time will - carry to the hour digit. -*/ -void QCPAxisTickerTime::setTimeFormat(const QString &format) -{ - mTimeFormat = format; - - // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest - // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) - mSmallestUnit = tuMilliseconds; - mBiggestUnit = tuMilliseconds; - bool hasSmallest = false; - for (int i = tuMilliseconds; i <= tuDays; ++i) - { - TimeUnit unit = static_cast(i); - if (mTimeFormat.contains(mFormatPattern.value(unit))) - { - if (!hasSmallest) - { - mSmallestUnit = unit; - hasSmallest = true; - } - mBiggestUnit = unit; - } - } -} - -/*! - Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick - label. If the number for the specific unit is shorter than \a width, it will be padded with an - according number of zeros to the left in order to reach the field width. - - \see setTimeFormat -*/ -void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) -{ - mFieldWidth[unit] = qMax(width, 1); -} - -/*! \internal - - Returns the tick step appropriate for time displays, depending on the provided \a range and the - smallest available time unit in the current format (\ref setTimeFormat). For example if the unit - of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) - that require sub-minute precision to be displayed correctly. - - \seebaseclassmethod -*/ -double QCPAxisTickerTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - if (mSmallestUnit == tuMilliseconds) - result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond - else // have no milliseconds available in format, so stick with 1 second tickstep - result = 1.0; - } else if (result < 3600*24) // below a day - { - // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run - QVector availableSteps; - // seconds range: - if (mSmallestUnit <= tuSeconds) - availableSteps << 1; - if (mSmallestUnit == tuMilliseconds) - availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it - else if (mSmallestUnit == tuSeconds) - availableSteps << 2; - if (mSmallestUnit <= tuSeconds) - availableSteps << 5 << 10 << 15 << 30; - // minutes range: - if (mSmallestUnit <= tuMinutes) - availableSteps << 1*60; - if (mSmallestUnit <= tuSeconds) - availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it - else if (mSmallestUnit == tuMinutes) - availableSteps << 2*60; - if (mSmallestUnit <= tuMinutes) - availableSteps << 5*60 << 10*60 << 15*60 << 30*60; - // hours range: - if (mSmallestUnit <= tuHours) - availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; - // pick available step that is most appropriate to approximate ideal step: - result = pickClosest(result, availableSteps); - } else // more than a day, go back to normal clean mantissa algorithm but in units of days - { - const double secondsPerDay = 3600*24; - result = cleanMantissa(result/secondsPerDay)*secondsPerDay; - } - return result; -} - -/*! \internal - - Returns the sub tick count appropriate for the provided \a tickStep and time displays. - - \seebaseclassmethod -*/ -int QCPAxisTickerTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - } - return result; -} - -/*! \internal - - Returns the tick label corresponding to the provided \a tick and the configured format and field - widths (\ref setTimeFormat, \ref setFieldWidth). - - \seebaseclassmethod -*/ -QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - Q_UNUSED(locale) - bool negative = tick < 0; - if (negative) tick *= -1; - double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) - double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time - - restValues[tuMilliseconds] = tick*1000; - values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; - values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; - values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; - values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; - // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) - - QString result = mTimeFormat; - for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) - { - TimeUnit iUnit = static_cast(i); - replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); - } - if (negative) - result.prepend(QLatin1Char('-')); - return result; -} - -/*! \internal - - Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified - \a value, using the field width as specified with \ref setFieldWidth for the \a unit. -*/ -void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const -{ - QString valueStr = QString::number(value); - while (valueStr.size() < mFieldWidth.value(unit)) - valueStr.prepend(QLatin1Char('0')); - - text.replace(mFormatPattern.value(unit), valueStr); -} -/* end of 'src/axis/axistickertime.cpp' */ - - -/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerFixed -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerFixed - \brief Specialized axis ticker with a fixed tick step - - \image html axisticker-fixed.png - - This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It - is also possible to allow integer multiples and integer powers of the specified tick step with - \ref setScaleStrategy. - - A typical application of this ticker is to make an axis only display integers, by setting the - tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. - - Another case is when a certain number has a special meaning and axis ticks should only appear at - multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi - because despite the name it is not limited to only pi symbols/values. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerFixed::QCPAxisTickerFixed() : - mTickStep(1.0), - mScaleStrategy(ssNone) -{ -} - -/*! - Sets the fixed tick interval to \a step. - - The axis ticker will only use this tick step when generating axis ticks. This might cause a very - high tick density and overlapping labels if the axis range is zoomed out. Using \ref - setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a - step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref - setTickCount). -*/ -void QCPAxisTickerFixed::setTickStep(double step) -{ - if (step > 0) - mTickStep = step; - else - qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; -} - -/*! - Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether - modifications may be applied to it before calculating the finally used tick step, such as - permitting multiples or powers. See \ref ScaleStrategy for details. - - The default strategy is \ref ssNone, which means the tick step is absolutely fixed. -*/ -void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) -{ - mScaleStrategy = strategy; -} - -/*! \internal - - Determines the actually used tick step from the specified tick step and scale strategy (\ref - setTickStep, \ref setScaleStrategy). - - This method either returns the specified tick step exactly, or, if the scale strategy is not \ref - ssNone, a modification of it to allow varying the number of ticks in the current axis range. - - \seebaseclassmethod -*/ -double QCPAxisTickerFixed::getTickStep(const QCPRange &range) -{ - switch (mScaleStrategy) - { - case ssNone: - { - return mTickStep; - } - case ssMultiples: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - if (exactStep < mTickStep) - return mTickStep; - else - return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; - } - case ssPowers: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); - } - } - return mTickStep; -} -/* end of 'src/axis/axistickerfixed.cpp' */ - - -/* including file 'src/axis/axistickertext.cpp', size 8653 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerText -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerText - \brief Specialized axis ticker which allows arbitrary labels at specified coordinates - - \image html axisticker-text.png - - This QCPAxisTicker subclass generates ticks which can be directly specified by the user as - coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a - time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks - and modify the tick/label data there. - - This is useful for cases where the axis represents categories rather than numerical values. - - If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on - the axis range), it is a sign that you should probably create an own ticker by subclassing - QCPAxisTicker, instead of using this one. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation -*/ - -/* start of documentation of inline functions */ - -/*! \fn QMap &QCPAxisTickerText::ticks() - - Returns a non-const reference to the internal map which stores the tick coordinates and their - labels. - - You can access the map directly in order to add, remove or manipulate ticks, as an alternative to - using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerText::QCPAxisTickerText() : - mSubTickCount(0) -{ -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis - coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QMap &ticks) -{ - mTicks = ticks; -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis - coordinates, and the entries of \a labels are the respective strings that will appear as tick - labels. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) -{ - clear(); - addTicks(positions, labels); -} - -/*! - Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no - automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this - method. -*/ -void QCPAxisTickerText::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! - Clears all ticks. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see setTicks, addTicks, addTick -*/ -void QCPAxisTickerText::clear() -{ - mTicks.clear(); -} - -/*! - Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a - label. - - \see addTicks, setTicks, clear -*/ -void QCPAxisTickerText::addTick(double position, QString label) -{ - mTicks.insert(position, label); -} - -/*! \overload - - Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to - the axis coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QMap &ticks) -{ - mTicks.unite(ticks); -} - -/*! \overload - - Adds the provided ticks to the ones already existing. The entries of \a positions correspond to - the axis coordinates, and the entries of \a labels are the respective strings that will appear as - tick labels. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) -{ - if (positions.size() != labels.size()) - qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); - int n = qMin(positions.size(), labels.size()); - for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (mTicks.isEmpty()) - return result; - - QMap::const_iterator start = mTicks.lowerBound(range.lower); - QMap::const_iterator end = mTicks.upperBound(range.upper); - // this method should try to give one tick outside of range so proper subticks can be generated: - if (start != mTicks.constBegin()) --start; - if (end != mTicks.constEnd()) ++end; - for (QMap::const_iterator it = start; it != end; ++it) - result.append(it.key()); - - return result; -} -/* end of 'src/axis/axistickertext.cpp' */ - - -/* including file 'src/axis/axistickerpi.cpp', size 11170 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerPi -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerPi - \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi - - \image html axisticker-pi.png - - This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic - constant with a numerical value specified with \ref setPiValue and an appearance in the tick - labels specified with \ref setPiSymbol. - - Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the - tick label can be configured with \ref setFractionStyle. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerPi::QCPAxisTickerPi() : - mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), - mPiValue(M_PI), - mPeriodicity(0), - mFractionStyle(fsUnicodeFractions), - mPiTickStep(0) -{ - setTickCount(4); -} - -/*! - Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick - label. - - If a space shall appear between the number and the symbol, make sure the space is contained in \a - symbol. -*/ -void QCPAxisTickerPi::setPiSymbol(QString symbol) -{ - mPiSymbol = symbol; -} - -/*! - Sets the numerical value that the symbolic constant has. - - This will be used to place the appropriate fractions of the symbol at the respective axis - coordinates. -*/ -void QCPAxisTickerPi::setPiValue(double pi) -{ - mPiValue = pi; -} - -/*! - Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the - symbolic constant. - - To disable periodicity, set \a multiplesOfPi to zero. - - For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. -*/ -void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) -{ - mPeriodicity = qAbs(multiplesOfPi); -} - -/*! - Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick - labels. See \ref FractionStyle for the various options. -*/ -void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) -{ - mFractionStyle = style; -} - -/*! \internal - - Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence - the numerical/fractional part preceding the symbolic constant is made to have a readable - mantissa. - - \seebaseclassmethod -*/ -double QCPAxisTickerPi::getTickStep(const QCPRange &range) -{ - mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - mPiTickStep = cleanMantissa(mPiTickStep); - return mPiTickStep*mPiValue; -} - -/*! \internal - - Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In - consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant - reasonably, and not the total tick coordinate. - - \seebaseclassmethod -*/ -int QCPAxisTickerPi::getSubTickCount(double tickStep) -{ - return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); -} - -/*! \internal - - Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The - formatting of the fraction is done according to the specified \ref setFractionStyle. The appended - symbol is specified with \ref setPiSymbol. - - \seebaseclassmethod -*/ -QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - double tickInPis = tick/mPiValue; - if (mPeriodicity > 0) - tickInPis = fmod(tickInPis, mPeriodicity); - - if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) - { - // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above - int denominator = 1000; - int numerator = qRound(tickInPis*denominator); - simplifyFraction(numerator, denominator); - if (qAbs(numerator) == 1 && denominator == 1) - return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else if (numerator == 0) - return QLatin1String("0"); - else - return fractionToString(numerator, denominator) + mPiSymbol; - } else - { - if (qFuzzyIsNull(tickInPis)) - return QLatin1String("0"); - else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) - return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else - return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; - } -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure - the fraction is in irreducible form, i.e. numerator and denominator don't share any common - factors which could be cancelled. -*/ -void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const -{ - if (numerator == 0 || denominator == 0) - return; - - int num = numerator; - int denom = denominator; - while (denom != 0) // euclidean gcd algorithm - { - int oldDenom = denom; - denom = num % denom; - num = oldDenom; - } - // num is now gcd of numerator and denominator - numerator /= num; - denominator /= num; -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and returns a string representation. - The result depends on the configured fraction style (\ref setFractionStyle). - - This method is used to format the numerical/fractional part when generating tick labels. It - simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out - any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). -*/ -QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const -{ - if (denominator == 0) - { - qDebug() << Q_FUNC_INFO << "called with zero denominator"; - return QString(); - } - if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function - { - qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; - return QString::number(numerator/(double)denominator); // failsafe - } - int sign = numerator*denominator < 0 ? -1 : 1; - numerator = qAbs(numerator); - denominator = qAbs(denominator); - - if (denominator == 1) - { - return QString::number(sign*numerator); - } else - { - int integerPart = numerator/denominator; - int remainder = numerator%denominator; - if (remainder == 0) - { - return QString::number(sign*integerPart); - } else - { - if (mFractionStyle == fsAsciiFractions) - { - return QString(QLatin1String("%1%2%3/%4")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) - .arg(remainder) - .arg(denominator); - } else if (mFractionStyle == fsUnicodeFractions) - { - return QString(QLatin1String("%1%2%3")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) - .arg(unicodeFraction(remainder, denominator)); - } - } - } - return QString(); -} - -/*! \internal - - Returns the unicode string representation of the fraction given by \a numerator and \a - denominator. This is the representation used in \ref fractionToString when the fraction style - (\ref setFractionStyle) is \ref fsUnicodeFractions. - - This method doesn't use the single-character common fractions but builds each fraction from a - superscript unicode number, the unicode fraction character, and a subscript unicode number. -*/ -QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const -{ - return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); -} - -/*! \internal - - Returns the unicode string representing \a number as superscript. This is used to build - unicode fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSuperscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2070)); - - QString result; - while (number > 0) - { - const int digit = number%10; - switch (digit) - { - case 1: { result.prepend(QChar(0x00B9)); break; } - case 2: { result.prepend(QChar(0x00B2)); break; } - case 3: { result.prepend(QChar(0x00B3)); break; } - default: { result.prepend(QChar(0x2070+digit)); break; } - } - number /= 10; - } - return result; -} - -/*! \internal - - Returns the unicode string representing \a number as subscript. This is used to build unicode - fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSubscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2080)); - - QString result; - while (number > 0) - { - result.prepend(QChar(0x2080+number%10)); - number /= 10; - } - return result; -} -/* end of 'src/axis/axistickerpi.cpp' */ - - -/* including file 'src/axis/axistickerlog.cpp', size 7106 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerLog -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerLog - \brief Specialized axis ticker suited for logarithmic axes - - \image html axisticker-log.png - - This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic - axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). - - Especially in the case of a log base equal to 10 (the default), it might be desirable to have - tick labels in the form of powers of ten without mantissa display. To achieve this, set the - number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref - QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal - powers, so a format string of "eb". This will result in the following axis tick labels: - - \image html axisticker-log-powers.png - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerLog::QCPAxisTickerLog() : - mLogBase(10.0), - mSubTickCount(8), // generates 10 intervals - mLogBaseLnInv(1.0/qLn(mLogBase)) -{ -} - -/*! - Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer - powers of \a base. -*/ -void QCPAxisTickerLog::setLogBase(double base) -{ - if (base > 0) - { - mLogBase = base; - mLogBaseLnInv = 1.0/qLn(mLogBase); - } else - qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; -} - -/*! - Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced - linearly to provide a better visual guide, so the sub tick density increases toward the higher - tick. - - Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in - the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub - ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, - namely at 20, 30, 40, 50, 60, 70, 80 and 90. -*/ -void QCPAxisTickerLog::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! \internal - - Since logarithmic tick steps are necessarily different for each tick interval, this method does - nothing in the case of QCPAxisTickerLog - - \seebaseclassmethod -*/ -double QCPAxisTickerLog::getTickStep(const QCPRange &range) -{ - // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method - Q_UNUSED(range) - return 1.0; -} - -/*! \internal - - Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no - automatic sub tick count calculation necessary. - - \seebaseclassmethod -*/ -int QCPAxisTickerLog::getSubTickCount(double tickStep) -{ - Q_UNUSED(tickStep) - return mSubTickCount; -} - -/*! \internal - - Creates ticks with a spacing given by the logarithm base and an increasing integer power in the - provided \a range. The step in which the power increases tick by tick is chosen in order to keep - the total number of ticks as close as possible to the tick count (\ref setTickCount). The - parameter \a tickStep is ignored for QCPAxisTickerLog - - \seebaseclassmethod -*/ -QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (range.lower > 0 && range.upper > 0) // positive range - { - double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick *= newLogBase; - result.append(currentTick); - } - } else if (range.lower < 0 && range.upper < 0) // negative range - { - double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick /= newLogBase; - result.append(currentTick); - } - } else // invalid range for logarithmic scale, because lower and upper have different sign - { - qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; - } - - return result; -} -/* end of 'src/axis/axistickerlog.cpp' */ - - -/* including file 'src/axis/axis.cpp', size 99397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGrid - \brief Responsible for drawing the grid of a QCPAxis. - - This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the - grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref - QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. - - The axis and grid drawing was split into two classes to allow them to be placed on different - layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid - in the background and the axes in the foreground, and any plottables/items in between. This - described situation is the default setup, see the QCPLayer documentation. -*/ - -/*! - Creates a QCPGrid instance and sets default values. - - You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. -*/ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), - mParentAxis(parentAxis) -{ - // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); -} - -/*! - Sets whether grid lines at sub tick marks are drawn. - - \see setSubGridPen -*/ -void QCPGrid::setSubGridVisible(bool visible) -{ - mSubGridVisible = visible; -} - -/*! - Sets whether sub grid lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedSubGrid(bool enabled) -{ - mAntialiasedSubGrid = enabled; -} - -/*! - Sets whether zero lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedZeroLine(bool enabled) -{ - mAntialiasedZeroLine = enabled; -} - -/*! - Sets the pen with which (major) grid lines are drawn. -*/ -void QCPGrid::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen with which sub grid lines are drawn. -*/ -void QCPGrid::setSubGridPen(const QPen &pen) -{ - mSubGridPen = pen; -} - -/*! - Sets the pen with which zero lines are drawn. - - Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid - lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. -*/ -void QCPGrid::setZeroLinePen(const QPen &pen) -{ - mZeroLinePen = pen; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing the major grid lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); -} - -/*! \internal - - Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning - over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). -*/ -void QCPGrid::draw(QCPPainter *painter) -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mParentAxis->subTicks() && mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); -} - -/*! \internal - - Draws the main grid lines and possibly a zero line with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - const int tickCount = mParentAxis->mTickVector.size(); - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - -/*! \internal - - Draws the sub grid lines with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxis -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxis - \brief Manages a single axis inside a QCustomPlot. - - Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via - QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and - QCustomPlot::yAxis2 (right). - - Axes are always part of an axis rect, see QCPAxisRect. - \image html AxisNamesOverview.png -
Naming convention of axis parts
- \n - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line - on the left represents the QCustomPlot widget border.
- - Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and - tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of - the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the - documentation of QCPAxisTicker. -*/ - -/* start of documentation of inline functions */ - -/*! \fn Qt::Orientation QCPAxis::orientation() const - - Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced - from the axis type (left, top, right or bottom). - - \see orientation(AxisType type), pixelOrientation -*/ - -/*! \fn QCPGrid *QCPAxis::grid() const - - Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the - grid is displayed. -*/ - -/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) - - Returns the orientation of the specified axis type - - \see orientation(), pixelOrientation -*/ - -/*! \fn int QCPAxis::pixelOrientation() const - - Returns which direction points towards higher coordinate values/keys, in pixel space. - - This method returns either 1 or -1. If it returns 1, then going in the positive direction along - the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. - On the other hand, if this method returns -1, going to smaller pixel values corresponds to going - from lower to higher axis coordinates. - - For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, - without having to care about reversed or vertically aligned axes: - - \code - double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); - \endcode - - \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. -*/ - -/*! \fn QSharedPointer QCPAxis::ticker() const - - Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is - responsible for generating the tick positions and tick labels of this axis. You can access the - \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count - (\ref QCPAxisTicker::setTickCount). - - You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see - the documentation there. A new axis ticker can be set with \ref setTicker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see setTicker -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) - - This signal is emitted when the range of this axis has changed. You can connect it to the \ref - setRange slot of another axis to communicate the new range to the other axis, in order for it to - be synchronized. - - You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. - This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper - range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following - slot would limit the x axis to ranges between 0 and 10: - \code - customPlot->xAxis->setRange(newRange.bounded(0, 10)) - \endcode -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) - \overload - - Additionally to the new range, this signal also provides the previous range held by the axis as - \a oldRange. -*/ - -/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the scale type changes, by calls to \ref setScaleType -*/ - -/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) - - This signal is emitted when the selection state of this axis has changed, either by user interaction - or by a direct call to \ref setSelectedParts. -*/ - -/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); - - This signal is emitted when the selectability changes, by calls to \ref setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs an Axis instance of Type \a type for the axis rect \a parent. - - Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create - them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, - create them manually and then inject them also via \ref QCPAxisRect::addAxis. -*/ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), QString(), parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mTicker(new QCPAxisTicker), - mCachedMarginValid(false), - mCachedMargin(0) -{ - setParent(parent); - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) - { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) - { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) - { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) - { - setTickLabelPadding(5); - setLabelPadding(10); - } -} - -QCPAxis::~QCPAxis() -{ - delete mAxisPainter; - delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLabelPadding() const -{ - return mAxisPainter->tickLabelPadding; -} - -/* No documentation as it is a property getter */ -double QCPAxis::tickLabelRotation() const -{ - return mAxisPainter->tickLabelRotation; -} - -/* No documentation as it is a property getter */ -QCPAxis::LabelSide QCPAxis::tickLabelSide() const -{ - return mAxisPainter->tickLabelSide; -} - -/* No documentation as it is a property getter */ -QString QCPAxis::numberFormat() const -{ - QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) - { - result.append(QLatin1Char('b')); - if (mAxisPainter->numberMultiplyCross) - result.append(QLatin1Char('c')); - } - return result; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthIn() const -{ - return mAxisPainter->tickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthOut() const -{ - return mAxisPainter->tickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthIn() const -{ - return mAxisPainter->subTickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthOut() const -{ - return mAxisPainter->subTickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::labelPadding() const -{ - return mAxisPainter->labelPadding; -} - -/* No documentation as it is a property getter */ -int QCPAxis::offset() const -{ - return mAxisPainter->offset; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::lowerEnding() const -{ - return mAxisPainter->lowerEnding; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::upperEnding() const -{ - return mAxisPainter->upperEnding; -} - -/*! - Sets whether the axis uses a linear scale or a logarithmic scale. - - Note that this method controls the coordinate transformation. You will likely also want to use a - logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref - QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the - details of logarithmic axis tick creation. - - \ref setNumberPrecision -*/ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) -{ - if (mScaleType != type) - { - mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); - mCachedMarginValid = false; - Q_EMIT scaleTypeChanged(mScaleType); - } -} - -/*! - Sets the range of the axis. - - This slot may be connected with the \ref rangeChanged signal of another axis so this axis - is always synchronized with the other axis range, when it changes. - - To invert the direction of an axis, use \ref setRangeReversed. -*/ -void QCPAxis::setRange(const QCPRange &range) -{ - if (range.lower == mRange.lower && range.upper == mRange.upper) - return; - - if (!QCPRange::validRange(range)) return; - QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) - { - mRange = range.sanitizedForLogScale(); - } else - { - mRange = range.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectAxes.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font. - - The entire selection mechanism for axes is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you - wish to change the selection state manually. - - This function can change the selection state of a part, independent of the \ref setSelectableParts setting. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, - setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor -*/ -void QCPAxis::setSelectedParts(const SelectableParts &selected) -{ - if (mSelectedParts != selected) - { - mSelectedParts = selected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - \overload - - Sets the lower and upper bound of the axis range. - - To invert the direction of an axis, use \ref setRangeReversed. - - There is also a slot to set a range, see \ref setRange(const QCPRange &range). -*/ -void QCPAxis::setRange(double lower, double upper) -{ - if (lower == mRange.lower && upper == mRange.upper) - return; - - if (!QCPRange::validRange(lower, upper)) return; - QCPRange oldRange = mRange; - mRange.lower = lower; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - \overload - - Sets the range of the axis. - - The \a position coordinate indicates together with the \a alignment parameter, where the new - range will be positioned. \a size defines the size of the new axis range. \a alignment may be - Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, - or center of the range to be aligned with \a position. Any other values of \a alignment will - default to Qt::AlignCenter. -*/ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) -{ - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); -} - -/*! - Sets the lower bound of the axis range. The upper bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeLower(double lower) -{ - if (mRange.lower == lower) - return; - - QCPRange oldRange = mRange; - mRange.lower = lower; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets the upper bound of the axis range. The lower bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeUpper(double upper) -{ - if (mRange.upper == upper) - return; - - QCPRange oldRange = mRange; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal - axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the - direction of increasing values is inverted. - - Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part - of the \ref setRange interface will still reference the mathematically smaller number than the \a - upper part. -*/ -void QCPAxis::setRangeReversed(bool reversed) -{ - mRangeReversed = reversed; -} - -/*! - The axis ticker is responsible for generating the tick positions and tick labels. See the - documentation of QCPAxisTicker for details on how to work with axis tickers. - - You can change the tick positioning/labeling behaviour of this axis by setting a different - QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis - ticker, access it via \ref ticker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see ticker -*/ -void QCPAxis::setTicker(QSharedPointer ticker) -{ - if (ticker) - mTicker = ticker; - else - qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; - // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector -} - -/*! - Sets whether tick marks are displayed. - - Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve - that, see \ref setTickLabels. - - \see setSubTicks -*/ -void QCPAxis::setTicks(bool show) -{ - if (mTicks != show) - { - mTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. -*/ -void QCPAxis::setTickLabels(bool show) -{ - if (mTickLabels != show) - { - mTickLabels = show; - mCachedMarginValid = false; - if (!mTickLabels) - mTickVectorLabels.clear(); - } -} - -/*! - Sets the distance between the axis base line (including any outward ticks) and the tick labels. - \see setLabelPadding, setPadding -*/ -void QCPAxis::setTickLabelPadding(int padding) -{ - if (mAxisPainter->tickLabelPadding != padding) - { - mAxisPainter->tickLabelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the font of the tick labels. - - \see setTickLabels, setTickLabelColor -*/ -void QCPAxis::setTickLabelFont(const QFont &font) -{ - if (font != mTickLabelFont) - { - mTickLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the tick labels. - - \see setTickLabels, setTickLabelFont -*/ -void QCPAxis::setTickLabelColor(const QColor &color) -{ - mTickLabelColor = color; -} - -/*! - Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, - the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values - from -90 to 90 degrees. - - If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For - other angles, the label is drawn with an offset such that it seems to point toward or away from - the tick mark. -*/ -void QCPAxis::setTickLabelRotation(double degrees) -{ - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) - { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. - - The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels - to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels - appear on the inside are additionally clipped to the axis rect. -*/ -void QCPAxis::setTickLabelSide(LabelSide side) -{ - mAxisPainter->tickLabelSide = side; - mCachedMarginValid = false; -} - -/*! - Sets the number format for the numbers in tick labels. This \a formatCode is an extended version - of the format code used e.g. by QString::number() and QLocale::toString(). For reference about - that, see the "Argument Formats" section in the detailed description of the QString class. - - \a formatCode is a string of one, two or three characters. The first character is identical to - the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed - format, 'g'/'G' scientific or fixed, whichever is shorter. - - The second and third characters are optional and specific to QCustomPlot:\n - If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. - "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for - "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 - [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. - If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can - be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the - cross and 183 (0xB7) for the dot. - - Examples for \a formatCode: - \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, - normal scientific format is used - \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with - beautifully typeset decimal powers and a dot as multiplication sign - \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as - multiplication sign - \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal - powers. Format code will be reduced to 'f'. - \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format - code will not be changed. -*/ -void QCPAxis::setNumberFormat(const QString &formatCode) -{ - if (formatCode.isEmpty()) - { - qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; - return; - } - mCachedMarginValid = false; - - // interpret first char as number format char: - QString allowedFormatChars(QLatin1String("eEfgG")); - if (allowedFormatChars.contains(formatCode.at(0))) - { - mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; - return; - } - if (formatCode.length() < 2) - { - mNumberBeautifulPowers = false; - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) - { - mNumberBeautifulPowers = true; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - return; - } - if (formatCode.length() < 3) - { - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == QLatin1Char('c')) - { - mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == QLatin1Char('d')) - { - mAxisPainter->numberMultiplyCross = false; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; - return; - } -} - -/*! - Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) - for details. The effect of precisions are most notably for number Formats starting with 'e', see - \ref setNumberFormat -*/ -void QCPAxis::setNumberPrecision(int precision) -{ - if (mNumberPrecision != precision) - { - mNumberPrecision = precision; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the - plot and \a outside is the length they will reach outside the plot. If \a outside is greater than - zero, the tick labels and axis label will increase their distance to the axis accordingly, so - they won't collide with the ticks. - - \see setSubTickLength, setTickLengthIn, setTickLengthOut -*/ -void QCPAxis::setTickLength(int inside, int outside) -{ - setTickLengthIn(inside); - setTickLengthOut(outside); -} - -/*! - Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach - inside the plot. - - \see setTickLengthOut, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthIn(int inside) -{ - if (mAxisPainter->tickLengthIn != inside) - { - mAxisPainter->tickLengthIn = inside; - } -} - -/*! - Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach - outside the plot. If \a outside is greater than zero, the tick labels and axis label will - increase their distance to the axis accordingly, so they won't collide with the ticks. - - \see setTickLengthIn, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthOut(int outside) -{ - if (mAxisPainter->tickLengthOut != outside) - { - mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets whether sub tick marks are displayed. - - Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) - - \see setTicks -*/ -void QCPAxis::setSubTicks(bool show) -{ - if (mSubTicks != show) - { - mSubTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside - the plot and \a outside is the length they will reach outside the plot. If \a outside is greater - than zero, the tick labels and axis label will increase their distance to the axis accordingly, - so they won't collide with the ticks. - - \see setTickLength, setSubTickLengthIn, setSubTickLengthOut -*/ -void QCPAxis::setSubTickLength(int inside, int outside) -{ - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); -} - -/*! - Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside - the plot. - - \see setSubTickLengthOut, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthIn(int inside) -{ - if (mAxisPainter->subTickLengthIn != inside) - { - mAxisPainter->subTickLengthIn = inside; - } -} - -/*! - Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach - outside the plot. If \a outside is greater than zero, the tick labels will increase their - distance to the axis accordingly, so they won't collide with the ticks. - - \see setSubTickLengthIn, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthOut(int outside) -{ - if (mAxisPainter->subTickLengthOut != outside) - { - mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the pen, the axis base line is drawn with. - - \see setTickPen, setSubTickPen -*/ -void QCPAxis::setBasePen(const QPen &pen) -{ - mBasePen = pen; -} - -/*! - Sets the pen, tick marks will be drawn with. - - \see setTickLength, setBasePen -*/ -void QCPAxis::setTickPen(const QPen &pen) -{ - mTickPen = pen; -} - -/*! - Sets the pen, subtick marks will be drawn with. - - \see setSubTickCount, setSubTickLength, setBasePen -*/ -void QCPAxis::setSubTickPen(const QPen &pen) -{ - mSubTickPen = pen; -} - -/*! - Sets the font of the axis label. - - \see setLabelColor -*/ -void QCPAxis::setLabelFont(const QFont &font) -{ - if (mLabelFont != font) - { - mLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the axis label. - - \see setLabelFont -*/ -void QCPAxis::setLabelColor(const QColor &color) -{ - mLabelColor = color; -} - -/*! - Sets the text of the axis label that will be shown below/above or next to the axis, depending on - its orientation. To disable axis labels, pass an empty string as \a str. -*/ -void QCPAxis::setLabel(const QString &str) -{ - if (mLabel != str) - { - mLabel = str; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the tick labels and the axis label. - - \see setTickLabelPadding, setPadding -*/ -void QCPAxis::setLabelPadding(int padding) -{ - if (mAxisPainter->labelPadding != padding) - { - mAxisPainter->labelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the padding of the axis. - - When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, - that is left blank. - - The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. - - \see setLabelPadding, setTickLabelPadding -*/ -void QCPAxis::setPadding(int padding) -{ - if (mPadding != padding) - { - mPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the offset the axis has to its axis rect side. - - If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, - only the offset of the inner most axis has meaning (even if it is set to be invisible). The - offset of the other, outer axes is controlled automatically, to place them at appropriate - positions. -*/ -void QCPAxis::setOffset(int offset) -{ - mAxisPainter->offset = offset; -} - -/*! - Sets the font that is used for tick labels when they are selected. - - \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) -{ - if (font != mSelectedTickLabelFont) - { - mSelectedTickLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts - } -} - -/*! - Sets the font that is used for the axis label when it is selected. - - \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelFont(const QFont &font) -{ - mSelectedLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts -} - -/*! - Sets the color that is used for tick labels when they are selected. - - \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) -{ - if (color != mSelectedTickLabelColor) - { - mSelectedTickLabelColor = color; - } -} - -/*! - Sets the color that is used for the axis label when it is selected. - - \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelColor(const QColor &color) -{ - mSelectedLabelColor = color; -} - -/*! - Sets the pen that is used to draw the axis base line when selected. - - \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedBasePen(const QPen &pen) -{ - mSelectedBasePen = pen; -} - -/*! - Sets the pen that is used to draw the (major) ticks when selected. - - \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickPen(const QPen &pen) -{ - mSelectedTickPen = pen; -} - -/*! - Sets the pen that is used to draw the subticks when selected. - - \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) -{ - mSelectedSubTickPen = pen; -} - -/*! - Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setUpperEnding -*/ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) -{ - mAxisPainter->lowerEnding = ending; -} - -/*! - Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the right ending, for vertical axes the top ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setLowerEnding -*/ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) -{ - mAxisPainter->upperEnding = ending; -} - -/*! - If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper - bounds of the range. The range is simply moved by \a diff. - - If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This - corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). -*/ -void QCPAxis::moveRange(double diff) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - mRange.lower += diff; - mRange.upper += diff; - } else // mScaleType == stLogarithmic - { - mRange.lower *= diff; - mRange.upper *= diff; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis by \a factor around the center of the current axis range. For - example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis - range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around - the center will have moved symmetrically closer). - - If you wish to scale around a different coordinate than the current axis range center, use the - overload \ref scaleRange(double factor, double center). -*/ -void QCPAxis::scaleRange(double factor) -{ - scaleRange(factor, range().center()); -} - -/*! \overload - - Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a - factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at - coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates - around 1.0 will have moved symmetrically closer to 1.0). - - \see scaleRange(double factor) -*/ -void QCPAxis::scaleRange(double factor, double center) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic - { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range - { - QCPRange newRange; - newRange.lower = qPow(mRange.lower/center, factor)*center; - newRange.upper = qPow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLogScale(); - } else - qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will - be done around the center of the current axis range. - - For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs - plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the - axis rect has. - - This is an operation that changes the range of this axis once, it doesn't fix the scale ratio - indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent - won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent - will follow. -*/ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) -{ - int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) - otherPixelSize = otherAxis->axisRect()->width(); - else - otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) - ownPixelSize = axisRect()->width(); - else - ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); -} - -/*! - Changes the axis range such that all plottables associated with this axis are fully visible in - that dimension. - - \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPAxis::rescale(bool onlyVisiblePlottables) -{ - QList p = plottables(); - QCPRange newRange; - bool haveRange = false; - for (int i=0; irealVisibility() && onlyVisiblePlottables) - continue; - QCPRange plottableRange; - bool currentFoundRange; - QCP::SignDomain signDomain = QCP::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); - else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) - { - if (!haveRange) - newRange = plottableRange; - else - newRange.expand(plottableRange); - haveRange = true; - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) - { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); - } - } - setRange(newRange); - } -} - -/*! - Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. -*/ -double QCPAxis::pixelToCoord(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; - else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; - else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; - } - } -} - -/*! - Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. -*/ -double QCPAxis::coordToPixel(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; - else - { - if (!mRangeReversed) - return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - else - return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - } - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); - else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; - else - { - if (!mRangeReversed) - return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - else - return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - } - } - } -} - -/*! - Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function - is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this - function does not change the current selection state of the axis. - - If the axis is not visible (\ref setVisible), this function always returns \ref spNone. - - \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions -*/ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const -{ - if (!mVisible) - return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) - return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) - return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) - return spAxisLabel; - else - return spNone; -} - -/* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) - return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; -} - -/*! - Returns a list of all the plottables that have this axis as key or value axis. - - If you are only interested in plottables of type QCPGraph, see \ref graphs. - - \see graphs, items -*/ -QList QCPAxis::plottables() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that have this axis as key or value axis. - - \see plottables, items -*/ -QList QCPAxis::graphs() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis. An item is considered - associated with an axis if at least one of its positions uses the axis as key or value axis. - - \see plottables, graphs -*/ -QList QCPAxis::items() const -{ - QList result; - if (!mParentPlot) return result; - - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to - QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) -*/ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; - } - qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; - return atLeft; -} - -/*! - Returns the axis type that describes the opposite axis of an axis with the specified \a type. -*/ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) -{ - switch (type) - { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; - } -} - -/* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - SelectablePart part = details.value(); - if (mSelectableParts.testFlag(part)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) -{ - SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis - (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref - QCPAxisRect::setRangeDragAxes) - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. -*/ -void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || - !mAxisRect->rangeDrag().testFlag(orientation()) || - !mAxisRect->rangeDragAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - mDragStartRange = mRange; - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (mDragging) - { - const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); - const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); - if (mScaleType == QCPAxis::stLinear) - { - const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); - setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); - } else if (mScaleType == QCPAxis::stLogarithmic) - { - const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); - setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); - } - - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user zoom individual axes - exclusively, by performing the wheel event on top of the axis. - - For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis - (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref - QCPAxisRect::setRangeZoomAxes) - - \seebaseclassmethod - - \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the - axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. -*/ -void QCPAxis::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || - !mAxisRect->rangeZoom().testFlag(orientation()) || - !mAxisRect->rangeZoomAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); - scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); - mParentPlot->replot(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing axis lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); -} - -/*! \internal - - Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. - - \seebaseclassmethod -*/ -void QCPAxis::draw(QCPPainter *painter) -{ - QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->basePen = getBasePen(); - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->labelColor = getLabelColor(); - mAxisPainter->label = mLabel; - mAxisPainter->substituteExponent = mNumberBeautifulPowers; - mAxisPainter->tickPen = getTickPen(); - mAxisPainter->subTickPen = getSubTickPen(); - mAxisPainter->tickLabelFont = getTickLabelFont(); - mAxisPainter->tickLabelColor = getTickLabelColor(); - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; - mAxisPainter->reversedEndings = mRangeReversed; - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); -} - -/*! \internal - - Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling - QCPAxisTicker::generate on the currently installed ticker. - - If a change in the label text/count is detected, the cached axis margin is invalidated to make - sure the next margin calculation recalculates the label sizes and returns an up-to-date value. -*/ -void QCPAxis::setupTickVectors() -{ - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - - QVector oldLabels = mTickVectorLabels; - mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too -} - -/*! \internal - - Returns the pen that is used to draw the axis base line. Depending on the selection state, this - is either mSelectedBasePen or mBasePen. -*/ -QPen QCPAxis::getBasePen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; -} - -/*! \internal - - Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this - is either mSelectedTickPen or mTickPen. -*/ -QPen QCPAxis::getTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; -} - -/*! \internal - - Returns the pen that is used to draw the subticks. Depending on the selection state, this - is either mSelectedSubTickPen or mSubTickPen. -*/ -QPen QCPAxis::getSubTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; -} - -/*! \internal - - Returns the font that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelFont or mTickLabelFont. -*/ -QFont QCPAxis::getTickLabelFont() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; -} - -/*! \internal - - Returns the font that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelFont or mLabelFont. -*/ -QFont QCPAxis::getLabelFont() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; -} - -/*! \internal - - Returns the color that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelColor or mTickLabelColor. -*/ -QColor QCPAxis::getTickLabelColor() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; -} - -/*! \internal - - Returns the color that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelColor or mLabelColor. -*/ -QColor QCPAxis::getLabelColor() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; -} - -/*! \internal - - Returns the appropriate outward margin for this axis. It is needed if \ref - QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref - atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom - margin and so forth. For the calculation, this function goes through similar steps as \ref draw, - so changing one function likely requires the modification of the other one as well. - - The margin consists of the outward tick length, tick label padding, tick label size, label - padding, label size, and padding. - - The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. - unchanged are very fast. -*/ -int QCPAxis::calculateMargin() -{ - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis - return 0; - - if (mCachedMarginValid) - return mCachedMargin; - - // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels - int margin = 0; - - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->label = mLabel; - mAxisPainter->tickLabelFont = mTickLabelFont; - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - margin += mAxisPainter->size(); - margin += mPadding; - - mCachedMargin = margin; - mCachedMarginValid = true; - return margin; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAxis::selectionCategory() const -{ - return QCP::iSelectAxes; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisPainterPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisPainterPrivate - - \internal - \brief (Private) - - This is a private class and not part of the public QCustomPlot interface. - - It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and - axis label. It also buffers the labels to reduce replot times. The parameters are configured by - directly accessing the public member variables. -*/ - -/*! - Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every - redraw, to utilize the caching mechanisms. -*/ -QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : - type(QCPAxis::atLeft), - basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - lowerEnding(QCPLineEnding::esNone), - upperEnding(QCPLineEnding::esNone), - labelPadding(0), - tickLabelPadding(0), - tickLabelRotation(0), - tickLabelSide(QCPAxis::lsOutside), - substituteExponent(true), - numberMultiplyCross(false), - tickLengthIn(5), - tickLengthOut(0), - subTickLengthIn(2), - subTickLengthOut(0), - tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - offset(0), - abbreviateDecimalPowers(false), - reversedEndings(false), - mParentPlot(parentPlot), - mLabelCache(16) // cache at most 16 (tick) labels -{ -} - -QCPAxisPainterPrivate::~QCPAxisPainterPrivate() -{ -} - -/*! \internal - - Draws the axis with the specified \a painter. - - The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set - here, too. -*/ -void QCPAxisPainterPrivate::draw(QCPPainter *painter) -{ - QByteArray newHash = generateLabelParameterHash(); - if (newHash != mLabelParameterHash) - { - mLabelCache.clear(); - mLabelParameterHash = newHash; - } - - QPoint origin; - switch (type) - { - case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; - case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; - case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; - case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; - } - - double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) - switch (type) - { - case QCPAxis::atTop: yCor = -1; break; - case QCPAxis::atRight: xCor = 1; break; - default: break; - } - int margin = 0; - // draw baseline: - QLineF baseLine; - painter->setPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); - else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - - // draw ticks: - if (!tickPositions.isEmpty()) - { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); - } - } - - // draw subticks: - if (!subTickPositions.isEmpty()) - { - painter->setPen(subTickPen); - // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); - } - } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // draw axis base endings: - bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - - // tick labels: - QRect oldClipRect; - if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect - { - oldClipRect = painter->clipRegion().boundingRect(); - painter->setClipRect(axisRect); - } - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) - { - if (tickLabelSide == QCPAxis::lsOutside) - margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); - int distanceToAxis = margin; - if (tickLabelSide == QCPAxis::lsInside) - distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - for (int i=0; isetClipRect(oldClipRect); - - // axis label: - QRect labelBounds; - if (!label.isEmpty()) - { - margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atRight) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); - painter->rotate(90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - } - - // set selection boxes: - int selectionTolerance = 0; - if (mParentPlot) - selectionTolerance = mParentPlot->selectionTolerance(); - else - qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); - int selAxisInSize = selectionTolerance; - int selTickLabelSize; - int selTickLabelOffset; - if (tickLabelSide == QCPAxis::lsOutside) - { - selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - } else - { - selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - } - int selLabelSize = labelBounds.height(); - int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; - if (type == QCPAxis::atLeft) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atRight) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atTop) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); - } - mAxisSelectionBox = mAxisSelectionBox.normalized(); - mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); - mLabelSelectionBox = mLabelSelectionBox.normalized(); - // draw hitboxes for debug purposes: - //painter->setBrush(Qt::NoBrush); - //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); -} - -/*! \internal - - Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone - direction) needed to fit the axis. -*/ -int QCPAxisPainterPrivate::size() const -{ - int result = 0; - - // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // calculate size of tick labels: - if (tickLabelSide == QCPAxis::lsOutside) - { - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) - { - for (int i=0; ibufferDevicePixelRatio())); - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)tickLabelSide)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString().toLatin1()); - return result; -} - -/*! \internal - - Draws a single tick label with the provided \a painter, utilizing the internal label cache to - significantly speed up drawing of labels that were drawn in previous calls. The tick label is - always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in - pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence - for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), - at which the label should be drawn. - - In order to later draw the axis label in a place that doesn't overlap with the tick labels, the - largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref - drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a - tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently - holds. - - The label is drawn with the font and pen that are currently set on the \a painter. To draw - superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref - getTickLabelData). -*/ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) -{ - // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; - QSize finalSize; - QPointF labelAnchor; - switch (type) - { - case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; - } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled - { - CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache - if (!cachedLabel) // no cached label existed, create it - { - cachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); - if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) - { - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); -# else - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); -# endif -#endif - } else - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - cachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&cachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); - } - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); - else - labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } - mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created - } else // label caching disabled, draw text directly on surface: - { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); - else - labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); - finalSize = labelData.rotatedTotalBounds.size(); - } - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a - y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to - directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when - QCP::phCacheLabels plotting hint is not set. -*/ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const -{ - // backup painter settings that we're about to change: - QTransform oldTransform = painter->transform(); - QFont oldFont = painter->font(); - - // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - - // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - if (!labelData.suffixPart.isEmpty()) - painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); - } - - // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Transforms the passed \a text and \a font to a tickLabelData structure that can then be further - processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and - exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. -*/ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const -{ - TickLabelData result; - - // determine whether beautiful decimal powers should be used - bool useBeautifulPowers = false; - int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart - int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart - if (substituteExponent) - { - ePos = text.indexOf(QLatin1Char('e')); - if (ePos > 0 && text.at(ePos-1).isDigit()) - { - eLast = ePos; - while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) - ++eLast; - if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power - useBeautifulPowers = true; - } - } - - // calculate text bounding rects and do string preparation for beautiful decimal powers: - result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) - { - // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent - // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) - result.basePart = QLatin1String("10"); - else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); - result.expPart = text.mid(ePos+1, eLast-ePos); - // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) - result.expPart.remove(0, 1); - // prepare smaller font for exponent: - result.expFont = font; - if (result.expFont.pointSize() > 0) - result.expFont.setPointSize(result.expFont.pointSize()*0.75); - else - result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); - // calculate bounding rects of base part(s), exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - if (!result.suffixPart.isEmpty()) - result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false - { - result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); - } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - - // calculate possibly different bounding rect after rotation: - result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) - { - QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); - } - - return result; -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Calculates the offset at which the top left corner of the specified tick label shall be drawn. - The offset is relative to a point right next to the tick the label belongs to. - - This function is thus responsible for e.g. centering tick labels under ticks and positioning them - appropriately when they are rotated. -*/ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const -{ - /* - calculate label offset from base point at tick (non-trivial, for best visual appearance): short - explanation for bottom axis: The anchor, i.e. the point in the label that is placed - horizontally under the corresponding tick is always on the label side that is closer to the - axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height - is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text - will be centered under the tick (i.e. displaced horizontally by half its height). At the same - time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick - labels. - */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = 0; - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = -labelData.totalBounds.height(); - } - } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; - y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = 0; - } - } - - return QPointF(x, y); -} - -/*! \internal - - Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label - to be drawn, depending on number format etc. Since only the largest tick label is wanted for the - margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a - smaller width/height. -*/ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const -{ - // note: this function must return the same tick label sizes as the placeTickLabel function. - QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label - { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } else // label caching disabled or no label with this text cached: - { - TickLabelData labelData = getTickLabelData(font, text); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} -/* end of 'src/axis/axis.cpp' */ - - -/* including file 'src/scatterstyle.cpp', size 17450 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPScatterStyle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPScatterStyle - \brief Represents the visual appearance of scatter points - - This class holds information about shape, color and size of scatter points. In plottables like - QCPGraph it is used to store how scatter points shall be drawn. For example, \ref - QCPGraph::setScatterStyle takes a QCPScatterStyle instance. - - A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a - fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can - be controlled with \ref setSize. - - \section QCPScatterStyle-defining Specifying a scatter style - - You can set all these configurations either by calling the respective functions on an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 - - Or you can use one of the various constructors that take different parameter combinations, making - it easy to specify a scatter style in a single call, like so: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 - - \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable - - There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref - QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref - isPenDefined will return false. It leads to scatter points that inherit the pen from the - plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line - color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes - it very convenient to set up typical scatter settings: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation - - Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works - because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly - into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) - constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref - ScatterShape, where actually a QCPScatterStyle is expected. - - \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps - - QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. - - For custom shapes, you can provide a QPainterPath with the desired shape to the \ref - setCustomPath function or call the constructor that takes a painter path. The scatter shape will - automatically be set to \ref ssCustom. - - For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the - constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. - Note that \ref setSize does not influence the appearance of the pixmap. -*/ - -/* start documentation of inline functions */ - -/*! \fn bool QCPScatterStyle::isNone() const - - Returns whether the scatter shape is \ref ssNone. - - \see setShape -*/ - -/*! \fn bool QCPScatterStyle::isPenDefined() const - - Returns whether a pen has been defined for this scatter style. - - The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those - are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen - is undefined, the pen of the respective plottable will be used for drawing scatters. - - If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call - \ref undefinePen. - - \see setPen -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or - brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - and size to \a size. No brush is defined, i.e. the scatter point will not be filled. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - the brush color to \a fill (with a solid pattern), and size to \a size. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the - brush to \a brush, and size to \a size. - - \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen - and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n - QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n - doesn't necessarily lead C++ to use this constructor in some cases, but might mistake - Qt::NoPen for a QColor and use the - \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) - constructor instead (which will lead to an unexpected look of the scatter points). To prevent - this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) - instead of just Qt::blue, to clearly point out to the compiler that this constructor is - wanted. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape - is set to \ref ssPixmap. -*/ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The - scatter shape is set to \ref ssCustom. - - The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly - different meaning than for built-in scatter points: The custom path will be drawn scaled by a - factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its - original size by default. To for example double the size of the path, set \a size to 12. -*/ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Copies the specified \a properties from the \a other scatter style to this scatter style. -*/ -void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) -{ - if (properties.testFlag(spPen)) - { - setPen(other.pen()); - if (!other.isPenDefined()) - undefinePen(); - } - if (properties.testFlag(spBrush)) - setBrush(other.brush()); - if (properties.testFlag(spSize)) - setSize(other.size()); - if (properties.testFlag(spShape)) - { - setShape(other.shape()); - if (other.shape() == ssPixmap) - setPixmap(other.pixmap()); - else if (other.shape() == ssCustom) - setCustomPath(other.customPath()); - } -} - -/*! - Sets the size (pixel diameter) of the drawn scatter points to \a size. - - \see setShape -*/ -void QCPScatterStyle::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the shape to \a shape. - - Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref - ssPixmap and \ref ssCustom, respectively. - - \see setSize -*/ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) -{ - mShape = shape; -} - -/*! - Sets the pen that will be used to draw scatter points to \a pen. - - If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after - a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen - previously by calling this function and now wish to undefine the pen, call \ref undefinePen. - - \see setBrush -*/ -void QCPScatterStyle::setPen(const QPen &pen) -{ - mPenDefined = true; - mPen = pen; -} - -/*! - Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter - shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. - - \see setPen -*/ -void QCPScatterStyle::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the pixmap that will be drawn as scatter point to \a pixmap. - - Note that \ref setSize does not influence the appearance of the pixmap. - - The scatter shape is automatically set to \ref ssPixmap. -*/ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) -{ - setShape(ssPixmap); - mPixmap = pixmap; -} - -/*! - Sets the custom shape that will be drawn as scatter point to \a customPath. - - The scatter shape is automatically set to \ref ssCustom. -*/ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) -{ - setShape(ssCustom); - mCustomPath = customPath; -} - -/*! - Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen - implies). - - A call to \ref setPen will define a pen. -*/ -void QCPScatterStyle::undefinePen() -{ - mPenDefined = false; -} - -/*! - Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an - undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. - - This function is used by plottables (or any class that wants to draw scatters) just before a - number of scatters with this style shall be drawn with the \a painter. - - \see drawShape -*/ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const -{ - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); -} - -/*! - Draws the scatter shape with \a painter at position \a pos. - - This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be - called before scatter points are drawn with \ref drawShape. - - \see applyTo -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const -{ - drawShape(painter, pos.x(), pos.y()); -} - -/*! \overload - Draws the scatter shape with \a painter at position \a x and \a y. -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const -{ - double w = mSize/2.0; - switch (mShape) - { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - QPointF lineArray[4] = {QPointF(x-w, y), - QPointF( x, y-w), - QPointF(x+w, y), - QPointF( x, y+w)}; - painter->drawPolygon(lineArray, 4); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), - QPointF(x+w, y+0.755*w), - QPointF( x, y-0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssTriangleInverted: - { - QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), - QPointF(x+w, y-0.755*w), - QPointF( x, y+0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssCrossSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - break; - } - case ssPlusSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCrossCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - break; - } - case ssPlusCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssPeace: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - break; - } - case ssPixmap: - { - const double widthHalf = mPixmap.width()*0.5; - const double heightHalf = mPixmap.height()*0.5; -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) - const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#else - const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#endif - if (clipRect.contains(x, y)) - painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } - } -} -/* end of 'src/scatterstyle.cpp' */ - -//amalgamation: add datacontainer.cpp - -/* including file 'src/plottable.cpp', size 38845 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecorator -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecorator - \brief Controls how a plottable's data selection is drawn - - Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref - QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. - - The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the - scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref - QCPScatterStyle is itself composed of different properties such as color shape and size, the - decorator allows specifying exactly which of those properties shall be used for the selected data - point, via \ref setUsedScatterProperties. - - A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref - QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance - of selected segments. - - Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is - especially useful since plottables take ownership of the passed selection decorator, and thus the - same decorator instance can not be passed to multiple plottables. - - Selection decorators can also themselves perform drawing operations by reimplementing \ref - drawDecoration, which is called by the plottable's draw method. The base class \ref - QCPSelectionDecorator does not make use of this however. For example, \ref - QCPSelectionDecoratorBracket draws brackets around selected data segments. -*/ - -/*! - Creates a new QCPSelectionDecorator instance with default values -*/ -QCPSelectionDecorator::QCPSelectionDecorator() : - mPen(QColor(80, 80, 255), 2.5), - mBrush(Qt::NoBrush), - mScatterStyle(), - mUsedScatterProperties(QCPScatterStyle::spNone), - mPlottable(0) -{ -} - -QCPSelectionDecorator::~QCPSelectionDecorator() -{ -} - -/*! - Sets the pen that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the scatter style that will be used by the parent plottable to draw scatters in selected - data segments. - - \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the - plottable. The used properties can also be changed via \ref setUsedScatterProperties. -*/ -void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) -{ - mScatterStyle = scatterStyle; - setUsedScatterProperties(usedProperties); -} - -/*! - Use this method to define which properties of the scatter style (set via \ref setScatterStyle) - will be used for selected data segments. All properties of the scatter style that are not - specified in \a properties will remain as specified in the plottable's original scatter style. - - \see QCPScatterStyle::ScatterProperty -*/ -void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) -{ - mUsedScatterProperties = properties; -} - -/*! - Sets the pen of \a painter to the pen of this selection decorator. - - \see applyBrush, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyPen(QCPPainter *painter) const -{ - painter->setPen(mPen); -} - -/*! - Sets the brush of \a painter to the brush of this selection decorator. - - \see applyPen, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const -{ - painter->setBrush(mBrush); -} - -/*! - Returns the scatter style that the parent plottable shall use for selected scatter points. The - plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending - on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this - selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. - - \see applyPen, applyBrush, setScatterStyle -*/ -QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const -{ - QCPScatterStyle result(unselectedStyle); - result.setFromOther(mScatterStyle, mUsedScatterProperties); - - // if style shall inherit pen from plottable (has no own pen defined), give it the selected - // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the - // plottable: - if (!result.isPenDefined()) - result.setPen(mPen); - - return result; -} - -/*! - Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to - this selection decorator. -*/ -void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) -{ - setPen(other->pen()); - setBrush(other->brush()); - setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); -} - -/*! - This method is called by all plottables' draw methods to allow custom selection decorations to be - drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data - selection for which the decoration shall be drawn. - - The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so - this method does nothing. -*/ -void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - Q_UNUSED(painter) - Q_UNUSED(selection) -} - -/*! \internal - - This method is called as soon as a selection decorator is associated with a plottable, by a call - to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access - data points via the \ref QCPAbstractPlottable::interface1D interface). - - If the selection decorator was already added to a different plottable before, this method aborts - the registration and returns false. -*/ -bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottable) - { - mPlottable = plottable; - return true; - } else - { - qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); - return false; - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable - \brief The abstract base class for all data representing objects in a plot. - - It defines a very basic interface like name, pen, brush, visibility etc. Since this class is - abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to - create new ways of displaying data (see "Creating own plottables" below). Plottables that display - one-dimensional data (i.e. data points have a single key dimension and one or multiple values at - each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details - there. - - All further specifics are in the subclasses, for example: - \li A normal graph with possibly a line and/or scatter points \ref QCPGraph - (typically created with \ref QCustomPlot::addGraph) - \li A parametric curve: \ref QCPCurve - \li A bar chart: \ref QCPBars - \li A statistical box plot: \ref QCPStatisticalBox - \li A color encoded two-dimensional map: \ref QCPColorMap - \li An OHLC/Candlestick chart: \ref QCPFinancial - - \section plottables-subclassing Creating own plottables - - Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display - two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) - data dimensions. If you want to display data with only one logical key dimension, you should - rather derive from \ref QCPAbstractPlottable1D. - - If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must - implement: - \li \ref selectTest - \li \ref draw - \li \ref drawLegendIcon - \li \ref getKeyRange - \li \ref getValueRange - - See the documentation of those functions for what they need to do. - - For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot - coordinates to pixel coordinates. This function is quite convenient, because it takes the - orientation of the key and value axes into account for you (x and y are swapped when the key axis - is vertical and the value axis horizontal). If you are worried about performance (i.e. you need - to translate many points in a loop like QCPGraph), you can directly use \ref - QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis - yourself. - - Here are some important members you inherit from QCPAbstractPlottable: - - - - - - - - - - - - - - - - - - - - - - - - - - -
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable - (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable - (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates - to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of - the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. - When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. - Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done - by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
-*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const - - Provides access to the selection decorator of this plottable. The selection decorator controls - how selected data ranges are drawn (e.g. their pen color and fill), see \ref - QCPSelectionDecorator for details. - - If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref - setSelectionDecorator. -*/ - -/*! \fn bool QCPAbstractPlottable::selected() const - - Returns true if there are any data points of the plottable currently selected. Use \ref selection - to retrieve the current \ref QCPDataSelection. -*/ - -/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const - - Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on - this plottable. - - \see selected, setSelection, setSelectable -*/ - -/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() - - If this plottable is a one-dimensional plottable, i.e. it implements the \ref - QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case - of a \ref QCPColorMap) returns zero. - - You can use this method to gain read access to data coordinates while holding a pointer to the - abstract base class only. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of pure virtual functions */ - -/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 - \internal - - called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation - of this plottable inside \a rect, next to the plottable name. - - The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't - appear outside the legend icon border. -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 - - Returns the coordinate range that all data in this plottable span in the key axis dimension. For - logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref - QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only - negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points - will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref - QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could - be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getValueRange -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 - - Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span - in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref - QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign - domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and - all positive points will be ignored for range calculation. For no restriction, just set \a - inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates - whether a range could be found or not. If this is false, you shouldn't use the returned range - (e.g. no points in data). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getKeyRange -*/ - -/* end of documentation of pure virtual functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether - there are any points selected or not. - - \see selectionChanged(const QCPDataSelection &selection) -*/ - -/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selection holds the - currently selected data ranges. - - \see selectionChanged(bool selected) -*/ - -/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); - - This signal is emitted when the selectability of this plottable has changed. - - \see setSelectable -*/ - -/* end of documentation of signals */ - -/*! - Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as - its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance - and have perpendicular orientations. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, - it can't be directly instantiated. - - You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. -*/ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), - mName(), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mPen(Qt::black), - mBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(QCP::stWhole), - mSelectionDecorator(0) -{ - if (keyAxis->parentPlot() != valueAxis->parentPlot()) - qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) - qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; - - mParentPlot->registerPlottable(this); - setSelectionDecorator(new QCPSelectionDecorator); -} - -QCPAbstractPlottable::~QCPAbstractPlottable() -{ - if (mSelectionDecorator) - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - The name is the textual representation of this plottable as it is displayed in the legend - (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. -*/ -void QCPAbstractPlottable::setName(const QString &name) -{ - mName = name; -} - -/*! - Sets whether fills of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) -{ - mAntialiasedFill = enabled; -} - -/*! - Sets whether the scatter symbols of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) -{ - mAntialiasedScatters = enabled; -} - -/*! - The pen is used to draw basic lines that make up the plottable representation in the - plot. - - For example, the \ref QCPGraph subclass draws its graph lines with this pen. - - \see setBrush -*/ -void QCPAbstractPlottable::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - The brush is used to draw basic fills of the plottable representation in the - plot. The Fill can be a color, gradient or texture, see the usage of QBrush. - - For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when - it's not set to Qt::NoBrush. - - \see setPen -*/ -void QCPAbstractPlottable::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal - to the plottable's value axis. This function performs no checks to make sure this is the case. - The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the - y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setValueAxis -*/ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) -{ - mKeyAxis = axis; -} - -/*! - The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is - orthogonal to the plottable's key axis. This function performs no checks to make sure this is the - case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and - the y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setKeyAxis -*/ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) -{ - mValueAxis = axis; -} - - -/*! - Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently - (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref - selectionDecorator). - - The entire selection mechanism for plottables is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when - you wish to change the selection state programmatically. - - Using \ref setSelectable you can further specify for each plottable whether and to which - granularity it is selectable. If \a selection is not compatible with the current \ref - QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted - accordingly (see \ref QCPDataSelection::enforceType). - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractPlottable::setSelection(QCPDataSelection selection) -{ - selection.enforceType(mSelectable); - if (mSelection != selection) - { - mSelection = selection; - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } -} - -/*! - Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to - customize the visual representation of selected data ranges further than by using the default - QCPSelectionDecorator. - - The plottable takes ownership of the \a decorator. - - The currently set decorator can be accessed via \ref selectionDecorator. -*/ -void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) -{ - if (decorator) - { - if (decorator->registerWithPlottable(this)) - { - if (mSelectionDecorator) // delete old decorator if necessary - delete mSelectionDecorator; - mSelectionDecorator = decorator; - } - } else if (mSelectionDecorator) // just clear decorator - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - Sets whether and to which granularity this plottable can be selected. - - A selection can happen by clicking on the QCustomPlot surface (When \ref - QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect - (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by - calling \ref setSelection. - - \see setSelection, QCP::SelectionType -*/ -void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - QCPDataSelection oldSelection = mSelection; - mSelection.enforceType(mSelectable); - Q_EMIT selectableChanged(mSelectable); - if (mSelection != oldSelection) - { - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } - } -} - - -/*! - Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. - - \see pixelsToCoords, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else - { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); - } -} - -/*! \overload - - Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. -*/ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); - else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); -} - -/*! - Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. - - \see coordsToPixels, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else - { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); - } -} - -/*! \overload - - Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. -*/ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const -{ - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); -} - -/*! - Rescales the key and value axes associated with this plottable to contain all displayed data, so - the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make - sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. - Instead it will stay in the current sign domain and ignore all parts of the plottable that lie - outside of that domain. - - \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show - multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has - \a onlyEnlarge set to false (the default), and all subsequent set to true. - - \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale -*/ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const -{ - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); -} - -/*! - Rescales the key axis of the plottable so the whole plottable is visible. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); - } - } - keyAxis->setRange(newRange); - } -} - -/*! - Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is - set to true, only the data points which are in the currently visible key axis range are - considered. - - Returns true if the axis was actually scaled. This might not be the case if this plottable has an - invalid range, e.g. because it has no data points. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); - } - } - valueAxis->setRange(newRange); - } -} - -/*! \overload - - Adds this plottable to the specified \a legend. - - Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. - when the legend exists and a legend item associated with this plottable isn't already in the - legend. - - If the plottable needs a more specialized representation in the legend, you can create a - corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead - of calling this method. - - \see removeFromLegend, QCPLegend::addItem -*/ -bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - if (legend->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; - return false; - } - - if (!legend->hasItemWithPlottable(this)) - { - legend->addItem(new QCPPlottableLegendItem(legend, this)); - return true; - } else - return false; -} - -/*! \overload - - Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). - - \see removeFromLegend -*/ -bool QCPAbstractPlottable::addToLegend() -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return addToLegend(mParentPlot->legend); -} - -/*! \overload - - Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem - that is associated with this plottable is removed. - - Returns true on success, i.e. if the legend exists and a legend item associated with this - plottable was found and removed. - - \see addToLegend, QCPLegend::removeItem -*/ -bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - - if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) - return legend->removeItem(lip); - else - return false; -} - -/*! \overload - - Removes the plottable from the legend of the parent QCustomPlot. - - \see addToLegend -*/ -bool QCPAbstractPlottable::removeFromLegend() const -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return removeFromLegend(mParentPlot->legend); -} - -/* inherits documentation from base class */ -QRect QCPAbstractPlottable::clipRect() const -{ - if (mKeyAxis && mValueAxis) - return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - else - return QRect(); -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractPlottable::selectionCategory() const -{ - return QCP::iSelectPlottables; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable fills. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable scatter points. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint -*/ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - - if (mSelectable != QCP::stNone) - { - QCPDataSelection newSelection = details.value(); - QCPDataSelection selectionBefore = mSelection; - if (additive) - { - if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit - { - if (selected()) - setSelection(QCPDataSelection()); - else - setSelection(newSelection); - } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments - { - if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection - setSelection(mSelection-newSelection); - else - setSelection(mSelection+newSelection); - } - } else - setSelection(newSelection); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable != QCP::stNone) - { - QCPDataSelection selectionBefore = mSelection; - setSelection(QCPDataSelection()); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} -/* end of 'src/plottable.cpp' */ - - -/* including file 'src/item.cpp', size 49269 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemAnchor -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemAnchor - \brief An anchor of an item to which positions can be attached to. - - An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't - control anything on its item, but provides a way to tie other items via their positions to the - anchor. - - For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. - Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can - attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by - calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the - QCPItemRect. This way the start of the line will now always follow the respective anchor location - on the rect item. - - Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an - anchor to other positions. - - To learn how to provide anchors in your own item subclasses, see the subclassing section of the - QCPAbstractItem documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() - - Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if - it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). - - This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids - dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with - gcc compiler). -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) -{ -} - -QCPItemAnchor::~QCPItemAnchor() -{ - // unregister as parent at children: - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } -} - -/*! - Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. - - The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the - parent item, QCPItemAnchor is just an intermediary. -*/ -QPointF QCPItemAnchor::pixelPosition() const -{ - if (mParentItem) - { - if (mAnchorId > -1) - { - return mParentItem->anchorPixelPosition(mAnchorId); - } else - { - qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; - return QPointF(); - } - } else - { - qDebug() << Q_FUNC_INFO << "no parent item set"; - return QPointF(); - } -} - -/*! \internal - - Adds \a pos to the childX list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.contains(pos)) - mChildrenX.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childX list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - -/*! \internal - - Adds \a pos to the childY list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.contains(pos)) - mChildrenY.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childY list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPosition -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPosition - \brief Manages the position of an item. - - Every item has at least one public QCPItemPosition member pointer which provides ways to position the - item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: - \a topLeft and \a bottomRight. - - QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type - defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel - coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also - possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref - setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y - direction, while following a plot coordinate in the X direction. - - A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie - multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) - are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) - means directly ontop of the parent anchor. For example, You could attach the \a start position of - a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line - always be centered under the text label, no matter where the text is moved to. For more advanced - plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see - \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X - direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B - in Y. - - Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent - anchor for other positions. - - To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This - works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref - setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified - pixel values. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const - - Returns the current position type. - - If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the - type of the X coordinate. In that case rather use \a typeX() and \a typeY(). - - \see setType -*/ - -/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const - - Returns the current parent anchor. - - If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), - this method returns the parent anchor of the Y coordinate. In that case rather use \a - parentAnchorX() and \a parentAnchorY(). - - \see setParentAnchor -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionTypeX(ptAbsolute), - mPositionTypeY(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchorX(0), - mParentAnchorY(0) -{ -} - -QCPItemPosition::~QCPItemPosition() -{ - // unregister as parent at children: - // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then - // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } - // unregister as child in parent: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const -{ - return mAxisRect.data(); -} - -/*! - Sets the type of the position. The type defines how the coordinates passed to \ref setCoords - should be handled and how the QCPItemPosition should behave in the plot. - - The possible values for \a type can be separated in two main categories: - - \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords - and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. - By default, the QCustomPlot's x- and yAxis are used. - - \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This - corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref - ptAxisRectRatio. They differ only in the way the absolute position is described, see the - documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify - the axis rect with \ref setAxisRect. By default this is set to the main axis rect. - - Note that the position type \ref ptPlotCoords is only available (and sensible) when the position - has no parent anchor (\ref setParentAnchor). - - If the type is changed, the apparent pixel position on the plot is preserved. This means - the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. - - This method sets the type for both X and Y directions. It is also possible to set different types - for X and Y, see \ref setTypeX, \ref setTypeY. -*/ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) -{ - setTypeX(type); - setTypeY(type); -} - -/*! - This method sets the position type of the X coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeY -*/ -void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) -{ - if (mPositionTypeX != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeX = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - This method sets the position type of the Y coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeX -*/ -void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) -{ - if (mPositionTypeY != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeY = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now - follow any position changes of the anchor. The local coordinate system of positions with a parent - anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence - the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) - - if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved - during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position - will be exactly on top of the parent anchor. - - To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. - - If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is - set to \ref ptAbsolute, to keep the position in a valid state. - - This method sets the parent anchor for both X and Y directions. It is also possible to set - different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. -*/ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); - bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); - return successX && successY; -} - -/*! - This method sets the parent anchor of the X coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorY -*/ -bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorX(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) - setTypeX(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildX(this); - mParentAnchorX = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(0, coords().y()); - return true; -} - -/*! - This method sets the parent anchor of the Y coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorX -*/ -bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorY(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) - setTypeY(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildY(this); - mParentAnchorY = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(coords().x(), 0); - return true; -} - -/*! - Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type - (\ref setType, \ref setTypeX, \ref setTypeY). - - For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position - on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the - QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the - plot coordinate system defined by the axes set by \ref setAxes. By default those are the - QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available - coordinate types and their meaning. - - If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a - value must also be provided in the different coordinate systems. Here, the X type refers to \a - key, and the Y type refers to \a value. - - \see setPixelPosition -*/ -void QCPItemPosition::setCoords(double key, double value) -{ - mKey = key; - mValue = value; -} - -/*! \overload - - Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the - meaning of \a value of the \ref setCoords(double key, double value) method. -*/ -void QCPItemPosition::setCoords(const QPointF &pos) -{ - setCoords(pos.x(), pos.y()); -} - -/*! - Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It - includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). - - \see setPixelPosition -*/ -QPointF QCPItemPosition::pixelPosition() const -{ - QPointF result; - - // determine X: - switch (mPositionTypeX) - { - case ptAbsolute: - { - result.rx() = mKey; - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - result.rx() = mKey*mParentPlot->viewport().width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mParentPlot->viewport().left(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.rx() = mKey*mAxisRect.data()->width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mAxisRect.data()->left(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - // determine Y: - switch (mPositionTypeY) - { - case ptAbsolute: - { - result.ry() = mValue; - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - result.ry() = mValue*mParentPlot->viewport().height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mParentPlot->viewport().top(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.ry() = mValue*mAxisRect.data()->height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mAxisRect.data()->top(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - result.ry() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - result.ry() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - return result; -} - -/*! - When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the - coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and - yAxis of the QCustomPlot. -*/ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - mKeyAxis = keyAxis; - mValueAxis = valueAxis; -} - -/*! - When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the - coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of - the QCustomPlot. -*/ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) -{ - mAxisRect = axisRect; -} - -/*! - Sets the apparent pixel position. This works no matter what type (\ref setType) this - QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed - appropriately, to make the position finally appear at the specified pixel values. - - Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is - identical to that of \ref setCoords. - - \see pixelPosition, setCoords -*/ -void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) -{ - double x = pixelPosition.x(); - double y = pixelPosition.y(); - - switch (mPositionTypeX) - { - case ptAbsolute: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mParentPlot->viewport().left(); - x /= (double)mParentPlot->viewport().width(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mAxisRect.data()->left(); - x /= (double)mAxisRect.data()->width(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - x = mKeyAxis.data()->pixelToCoord(x); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - y = mValueAxis.data()->pixelToCoord(x); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - switch (mPositionTypeY) - { - case ptAbsolute: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mParentPlot->viewport().top(); - y /= (double)mParentPlot->viewport().height(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mAxisRect.data()->top(); - y /= (double)mAxisRect.data()->height(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - x = mKeyAxis.data()->pixelToCoord(y); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - y = mValueAxis.data()->pixelToCoord(y); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - setCoords(x, y); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractItem - \brief The abstract base class for all items in a plot. - - In QCustomPlot, items are supplemental graphical elements that are neither plottables - (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus - plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each - specific item has at least one QCPItemPosition member which controls the positioning. Some items - are defined by more than one coordinate and thus have two or more QCPItemPosition members (For - example, QCPItemRect has \a topLeft and \a bottomRight). - - This abstract base class defines a very basic interface like visibility and clipping. Since this - class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass - yourself to create new items. - - The built-in items are: - - - - - - - - - - -
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
- - \section items-clipping Clipping - - Items are by default clipped to the main axis rect (they are only visible inside the axis rect). - To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect - "setClipToAxisRect(false)". - - On the other hand if you want the item to be clipped to a different axis rect, specify it via - \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and - in principle is independent of the coordinate axes the item might be tied to via its position - members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping - also contains the axes used for the item positions. - - \section items-using Using items - - First you instantiate the item you want to use and add it to the plot: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 - by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just - set the plot coordinates where the line should start/end: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 - If we don't want the line to be positioned in plot coordinates but a different coordinate system, - e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 - Then we can set the coordinates, this time in pixels: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 - and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 - - For more advanced plots, it is even possible to set different types and parent anchors per X/Y - coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref - QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. - - \section items-subclassing Creating own items - - To create an own item, you implement a subclass of QCPAbstractItem. These are the pure - virtual functions, you must implement: - \li \ref selectTest - \li \ref draw - - See the documentation of those functions for what they need to do. - - \subsection items-positioning Allowing the item to be positioned - - As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall - have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add - a public member of type QCPItemPosition like so: - - \code QCPItemPosition * const myPosition;\endcode - - the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition - instance it points to, can be modified, of course). - The initialization of this pointer is made easy with the \ref createPosition function. Just assign - the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition - takes a string which is the name of the position, typically this is identical to the variable name. - For example, the constructor of QCPItemExample could look like this: - - \code - QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - myPosition(createPosition("myPosition")) - { - // other constructor code - } - \endcode - - \subsection items-drawing The draw function - - To give your item a visual representation, reimplement the \ref draw function and use the passed - QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the - position member(s) via \ref QCPItemPosition::pixelPosition. - - To optimize performance you should calculate a bounding rect first (don't forget to take the pen - width into account), check whether it intersects the \ref clipRect, and only draw the item at all - if this is the case. - - \subsection items-selection The selectTest function - - Your implementation of the \ref selectTest function may use the helpers \ref - QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the - selection test becomes significantly simpler for most items. See the documentation of \ref - selectTest for what the function parameters mean and what the function should return. - - \subsection anchors Providing anchors - - Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public - member, e.g. - - \code QCPItemAnchor * const bottom;\endcode - - and create it in the constructor with the \ref createAnchor function, assigning it a name and an - anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). - Since anchors can be placed anywhere, relative to the item's position(s), your item needs to - provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int - anchorId) function. - - In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel - position when anything attached to the anchor needs to know the coordinates. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QList QCPAbstractItem::positions() const - - Returns all positions of the item in a list. - - \see anchors, position -*/ - -/*! \fn QList QCPAbstractItem::anchors() const - - Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always - also an anchor, the list will also contain the positions of this item. - - \see positions, anchor -*/ - -/* end of documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 - \internal - - Draws this item with the provided \a painter. - - The cliprect of the provided painter is set to the rect returned by \ref clipRect before this - function is called. The clipRect depends on the clipping settings defined by \ref - setClipToAxisRect and \ref setClipAxisRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPAbstractItem::selectionChanged(bool selected) - This signal is emitted when the selection state of this item has changed, either by user interaction - or by a direct call to \ref setSelected. -*/ - -/* end documentation of signals */ - -/*! - Base class constructor which initializes base class members. -*/ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) -{ - parentPlot->registerItem(this); - - QList rects = parentPlot->axisRects(); - if (rects.size() > 0) - { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); - } -} - -QCPAbstractItem::~QCPAbstractItem() -{ - // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const -{ - return mClipAxisRect.data(); -} - -/*! - Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the - entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. - - \see setClipAxisRect -*/ -void QCPAbstractItem::setClipToAxisRect(bool clip) -{ - mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref - setClipToAxisRect is set to true. - - \see setClipToAxisRect -*/ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) -{ - mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected. - - \see QCustomPlot::setInteractions, setSelected -*/ -void QCPAbstractItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this item is selected or not. When selected, it might use a different visual - appearance (e.g. pen and brush), this depends on the specific item though. - - The entire selection mechanism for items is handled automatically when \ref - QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this - function when you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/*! - Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by - that name, returns 0. - - This function provides an alternative way to access item positions. Normally, you access - positions direcly by their member pointers (which typically have the same variable name as \a - name). - - \see positions, anchor -*/ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const -{ - for (int i=0; iname() == name) - return mPositions.at(i); - } - qDebug() << Q_FUNC_INFO << "position with name not found:" << name; - return 0; -} - -/*! - Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by - that name, returns 0. - - This function provides an alternative way to access item anchors. Normally, you access - anchors direcly by their member pointers (which typically have the same variable name as \a - name). - - \see anchors, position -*/ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const -{ - for (int i=0; iname() == name) - return mAnchors.at(i); - } - qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; - return 0; -} - -/*! - Returns whether this item has an anchor with the specified \a name. - - Note that you can check for positions with this function, too. This is because every position is - also an anchor (QCPItemPosition inherits from QCPItemAnchor). - - \see anchor, position -*/ -bool QCPAbstractItem::hasAnchor(const QString &name) const -{ - for (int i=0; iname() == name) - return true; - } - return false; -} - -/*! \internal - - Returns the rect the visual representation of this item is clipped to. This depends on the - current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. - - If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. - - \see draw -*/ -QRect QCPAbstractItem::clipRect() const -{ - if (mClipToAxisRect && mClipAxisRect) - return mClipAxisRect.data()->rect(); - else - return mParentPlot->viewport(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing item lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); -} - -/*! \internal - - A convenience function which returns the selectTest value for a specified \a rect and a specified - click position \a pos. \a filledRect defines whether a click inside the rect should also be - considered a hit or whether only the rect border is sensitive to hits. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - For example, if your item consists of four rects, call this function four times, once for each - rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four - returned values. -*/ -double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const -{ - double result = -1; - - // distance to border: - QList lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = std::numeric_limits::max(); - for (int i=0; i mParentPlot->selectionTolerance()*0.99) - { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/*! \internal - - Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in - item subclasses if they want to provide anchors (QCPItemAnchor). - - For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor - ids and returns the respective pixel points of the specified anchor. - - \see createAnchor -*/ -QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const -{ - qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the position - member (This is needed to provide the name-based \ref position access to positions). - - Don't delete positions created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each position member. Don't create QCPItemPositions with \b new yourself, because they - won't be registered with the item properly. - - \see createAnchor -*/ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); - return newPosition; -} - -/*! \internal - - Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the anchor - member (This is needed to provide the name based \ref anchor access to anchors). - - The \a anchorId must be a number identifying the created anchor. It is recommended to create an - enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor - to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns - the correct pixel coordinates for the passed anchor id. - - Don't delete anchors created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they - won't be registered with the item properly. - - \see createPosition -*/ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); - return newAnchor; -} - -/* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractItem::selectionCategory() const -{ - return QCP::iSelectItems; -} -/* end of 'src/item.cpp' */ - - -/* including file 'src/core.cpp', size 125037 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCustomPlot -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCustomPlot - - \brief The central class of the library. This is the QWidget which displays the plot and - interacts with the user. - - For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const - - Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used - to handle and draw selection rect interactions (see \ref setSelectionRectMode). - - \see setSelectionRect -*/ - -/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const - - Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just - one cell with the main QCPAxisRect inside. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse double click event. -*/ - -/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse press event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. -*/ - -/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse move event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. - - \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, - because the dragging starting point was saved the moment the mouse was pressed. Thus it only has - a meaning for the range drag axes that were set at that moment. If you want to change the drag - axes, consider doing this in the \ref mousePress signal instead. -*/ - -/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse release event. - - It is emitted before QCustomPlot handles any other mechanisms like object selection. So a - slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or - \ref QCPAbstractPlottable::setSelectable. -*/ - -/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse wheel event. - - It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref - QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. -*/ - -/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableDoubleClick -*/ - -/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is double clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableClick -*/ - -/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemDoubleClick -*/ - -/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is double clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemClick -*/ - -/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisDoubleClick -*/ - -/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is double clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisClick -*/ - -/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendDoubleClick -*/ - -/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is double clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendClick -*/ - -/*! \fn void QCustomPlot::selectionChangedByUser() - - This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by - clicking. It is not emitted when the selection state of an object has changed programmatically by - a direct call to setSelected()/setSelection() on an object or by calling \ref - deselectAll. - - In addition to this signal, selectable objects also provide individual signals, for example \ref - QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals - are emitted even if the selection state is changed programmatically. - - See the documentation of \ref setInteractions for details about the selection mechanism. - - \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends -*/ - -/*! \fn void QCustomPlot::beforeReplot() - - This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, afterReplot -*/ - -/*! \fn void QCustomPlot::afterReplot() - - This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, beforeReplot -*/ - -/* end of documentation of signals */ -/* start of documentation of public members */ - -/*! \var QCPAxis *QCustomPlot::xAxis - - A pointer to the primary x Axis (bottom) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis - - A pointer to the primary y Axis (left) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::xAxis2 - - A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis2 - - A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPLegend *QCustomPlot::legend - - A pointer to the default legend of the main axis rect. The legend is invisible by default. Use - QCPLegend::setVisible to change this. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple legends to the plot, use the layout system interface to - access the new legend. For example, legends can be placed inside an axis rect's \ref - QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If - the default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointer becomes 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/* end of documentation of public members */ - -/*! - Constructs a QCustomPlot and sets reasonable default values. -*/ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), - mMultiSelectModifier(Qt::ControlModifier), - mSelectionRectMode(QCP::srmNone), - mSelectionRect(0), - mOpenGl(false), - mMouseHasMoved(false), - mMouseEventLayerable(0), - mMouseSignalLayerable(0), - mReplotting(false), - mReplotQueued(false), - mOpenGlMultisamples(16), - mOpenGlAntialiasedElementsBackup(QCP::aeNone), - mOpenGlCacheLabelsBackup(true) -{ - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); -# else - setBufferDevicePixelRatio(QWidget::devicePixelRatio()); -# endif -#endif - - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // create initial layers: - mLayers.append(new QCPLayer(this, QLatin1String("background"))); - mLayers.append(new QCPLayer(this, QLatin1String("grid"))); - mLayers.append(new QCPLayer(this, QLatin1String("main"))); - mLayers.append(new QCPLayer(this, QLatin1String("axes"))); - mLayers.append(new QCPLayer(this, QLatin1String("legend"))); - mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); - updateLayerIndices(); - setCurrentLayer(QLatin1String("main")); - layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); - - // create initial layout, axis rect and legend: - mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer(QLatin1String("main")); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); - legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer(QLatin1String("background")); - xAxis->setLayer(QLatin1String("axes")); - yAxis->setLayer(QLatin1String("axes")); - xAxis2->setLayer(QLatin1String("axes")); - yAxis2->setLayer(QLatin1String("axes")); - xAxis->grid()->setLayer(QLatin1String("grid")); - yAxis->grid()->setLayer(QLatin1String("grid")); - xAxis2->grid()->setLayer(QLatin1String("grid")); - yAxis2->grid()->setLayer(QLatin1String("grid")); - legend->setLayer(QLatin1String("legend")); - - // create selection rect instance: - mSelectionRect = new QCPSelectionRect(this); - mSelectionRect->setLayer(QLatin1String("overlay")); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(rpQueuedReplot); -} - -QCustomPlot::~QCustomPlot() -{ - clearPlottables(); - clearItems(); - - if (mPlotLayout) - { - delete mPlotLayout; - mPlotLayout = 0; - } - - mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed - mLayers.clear(); -} - -/*! - Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is - removed from there. - - \see setNotAntialiasedElements -*/ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) -{ - mAntialiasedElements = antialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. - - See \ref setAntialiasedElements for details. - - \see setNotAntialiasedElement -*/ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) -{ - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements |= antialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets which elements are forcibly drawn not antialiased as an \a or combination of - QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is - removed from there. - - \see setAntialiasedElements -*/ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) -{ - mNotAntialiasedElements = notAntialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. - - See \ref setNotAntialiasedElements for details. - - \see setAntialiasedElement -*/ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) -{ - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements |= notAntialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the - plottable to the legend (QCustomPlot::legend). - - \see addGraph, QCPLegend::addItem -*/ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) -{ - mAutoAddPlottableToLegend = on; -} - -/*! - Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction - enums. There are the following types of interactions: - - Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the - respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. - For details how to control which axes the user may drag/zoom and in what orientations, see \ref - QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, - \ref QCPAxisRect::setRangeZoomAxes. - - Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref - QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and - their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the - user can actually select a plottable and its data can further be restricted with the \ref - QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the - special page about the \ref dataselection "data selection mechanism". To retrieve a list of all - currently selected plottables, call \ref selectedPlottables. If you're only interested in - QCPGraphs, you may use the convenience function \ref selectedGraphs. - - Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user - may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find - out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of - all currently selected items, call \ref selectedItems. - - Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user - may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick - labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for - each axis. To retrieve a list of all axes that currently contain selected parts, call \ref - selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). - - Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may - select the legend itself or individual items by clicking on them. What parts exactly are - selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the - legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To - find out which child items are selected, call \ref QCPLegend::selectedItems. - - All other selectable elements The selection of all other selectable objects (e.g. - QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the - user may select those objects by clicking on them. To find out which are currently selected, you - need to check their selected state explicitly. - - If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is - emitted. Each selectable object additionally emits an individual selectionChanged signal whenever - their selection state has changed, i.e. not only by user interaction. - - To allow multiple objects to be selected by holding the selection modifier (\ref - setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. - - \note In addition to the selection mechanism presented here, QCustomPlot always emits - corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and - \ref plottableDoubleClick for example. - - \see setInteraction, setSelectionTolerance -*/ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) -{ - mInteractions = interactions; -} - -/*! - Sets the single \a interaction of this QCustomPlot to \a enabled. - - For details about the interaction system, see \ref setInteractions. - - \see setInteractions -*/ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) -{ - if (!enabled && mInteractions.testFlag(interaction)) - mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) - mInteractions |= interaction; -} - -/*! - Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or - not. - - If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a - potential selection when the minimum distance between the click position and the graph line is - smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks - directly inside the area and ignore this selection tolerance. In other words, it only has meaning - for parts of objects that are too thin to exactly hit with a click and thus need such a - tolerance. - - \see setInteractions, QCPLayerable::selectTest -*/ -void QCustomPlot::setSelectionTolerance(int pixels) -{ - mSelectionTolerance = pixels; -} - -/*! - Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes - ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves - performance during dragging. Thus it creates a more responsive user experience. As soon as the - user stops dragging, the last replot is done with normal antialiasing, to restore high image - quality. - - \see setAntialiasedElements, setNotAntialiasedElements -*/ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) -{ - mNoAntialiasingOnDrag = enabled; -} - -/*! - Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. - - \see setPlottingHint -*/ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) -{ - mPlottingHints = hints; -} - -/*! - Sets the specified plotting \a hint to \a enabled. - - \see setPlottingHints -*/ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) -{ - QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) - newHints &= ~hint; - else - newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); -} - -/*! - Sets the keyboard modifier that will be recognized as multi-select-modifier. - - If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple - objects (or data points) by clicking on them one after the other while holding down \a modifier. - - By default the multi-select-modifier is set to Qt::ControlModifier. - - \see setInteractions -*/ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) -{ - mMultiSelectModifier = modifier; -} - -/*! - Sets how QCustomPlot processes mouse click-and-drag interactions by the user. - - If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For - example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref - QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref - selectionRect) becomes activated and allows e.g. rect zooming and data point selection. - - If you wish to provide your user both with axis range dragging and data selection/range zooming, - use this method to switch between the modes just before the interaction is processed, e.g. in - reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether - the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. - - If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the - interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes - will keep the selection rect active. Upon completion of the interaction, the behaviour is as - defined by the currently set \a mode, not the mode that was set when the interaction started. - - \see setInteractions, setSelectionRect, QCPSelectionRect -*/ -void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) -{ - if (mSelectionRect) - { - if (mode == QCP::srmNone) - mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect - - // disconnect old connections: - if (mSelectionRectMode == QCP::srmSelect) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - - // establish new ones: - if (mode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } - - mSelectionRectMode = mode; -} - -/*! - Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref - QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of - the passed \a selectionRect. It can be accessed later via \ref selectionRect. - - This method is useful if you wish to replace the default QCPSelectionRect instance with an - instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. - - \see setSelectionRectMode -*/ -void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) -{ - if (mSelectionRect) - delete mSelectionRect; - - mSelectionRect = selectionRect; - - if (mSelectionRect) - { - // establish connections with new selection rect: - if (mSelectionRectMode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } -} - -/*! - \warning This is still an experimental feature and its performance depends on the system that it - runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering - might cause context conflicts on some systems. - - This method allows to enable OpenGL plot rendering, for increased plotting performance of - graphically demanding plots (thick lines, translucent fills, etc.). - - If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, - continue plotting with hardware acceleration. The parameter \a multisampling controls how many - samples will be used per pixel, it essentially controls the antialiasing quality. If \a - multisampling is set too high for the current graphics hardware, the maximum allowed value will - be used. - - You can test whether switching to OpenGL rendering was successful by checking whether the - according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, - rendering continues with the regular software rasterizer, and an according qDebug output is - generated. - - If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint - "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override - for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a - higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the - OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is - controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching - settings are restored to what they were before OpenGL was enabled, if they weren't altered in the - meantime. - - \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL - defined. This define must be set before including the QCustomPlot header both during compilation - of the QCustomPlot library as well as when compiling your application. It is best to just include - the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. - \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c - QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a - newer OpenGL interface which is already in the "gui" module. -*/ -void QCustomPlot::setOpenGl(bool enabled, int multisampling) -{ - mOpenGlMultisamples = qMax(0, multisampling); -#ifdef QCUSTOMPLOT_USE_OPENGL - mOpenGl = enabled; - if (mOpenGl) - { - if (setupOpenGl()) - { - // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): - setAntialiasedElements(QCP::aeAll); - setPlottingHint(QCP::phCacheLabels, false); - } else - { - qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; - mOpenGl = false; - } - } else - { - // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: - if (mAntialiasedElements == QCP::aeAll) - setAntialiasedElements(mOpenGlAntialiasedElementsBackup); - if (!mPlottingHints.testFlag(QCP::phCacheLabels)) - setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); - freeOpenGl(); - } - // recreate all paint buffers: - mPaintBuffers.clear(); - setupPaintBuffers(); -#else - Q_UNUSED(enabled) - qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; -#endif -} - -/*! - Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the - viewport manually. - - The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take - the viewport to be the outer border of the plot. The viewport normally is the rect() of the - QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. - - Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically - an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger - and contains also the axes themselves, their tick numbers, their labels, or even additional axis - rects, color scales and other layout elements. - - This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref - savePdf, etc. by temporarily changing the viewport size. -*/ -void QCustomPlot::setViewport(const QRect &rect) -{ - mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); -} - -/*! - Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. - - Normally, this doesn't need to be set manually, because it is initialized with the regular \a - QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal - displays, 2 for High-DPI displays). - - Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called - when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and - leaves the internal buffer device pixel ratio at 1.0. -*/ -void QCustomPlot::setBufferDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBufferDevicePixelRatio = ratio; - for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mBufferDevicePixelRatio = 1.0; -#endif - } -} - -/*! - Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn - below all other objects in the plot. - - For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is - preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will - first be filled with that brush, before drawing the background pixmap. This can be useful for - background pixmaps with translucent areas. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! - Sets the background brush of the viewport (see \ref setViewport). - - Before drawing everything else, the background is filled with \a brush. If a background pixmap - was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport - before the background pixmap is drawn. This can be useful for background pixmaps with translucent - areas. - - Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be - useful for exporting to image formats which support transparency, e.g. \ref savePng. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the viewport, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is - set to true, control whether and how the aspect ratio of the original pixmap is preserved with - \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the viewport dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCustomPlot::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this - function to define whether and how the aspect ratio of the original pixmap is preserved. - - \see setBackground, setBackgroundScaled -*/ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the plottable with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - plottable, see QCustomPlot::plottable() - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - { - return mPlottables.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last plottable that was added to the plot. If there are no plottables in the plot, - returns 0. - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable() -{ - if (!mPlottables.isEmpty()) - { - return mPlottables.last(); - } else - return 0; -} - -/*! - Removes the specified plottable from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). - - Returns true on success. - - \see clearPlottables -*/ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); - return false; - } - - // remove plottable from legend: - plottable->removeFromLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast(plottable)) - mGraphs.removeOne(graph); - // remove plottable: - delete plottable; - mPlottables.removeOne(plottable); - return true; -} - -/*! \overload - - Removes and deletes the plottable by its \a index. -*/ -bool QCustomPlot::removePlottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all plottables from the plot and deletes them. Corresponding legend items are also - removed from the default legend (QCustomPlot::legend). - - Returns the number of plottables removed. - - \see removePlottable -*/ -int QCustomPlot::clearPlottables() -{ - int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); - return c; -} - -/*! - Returns the number of currently existing plottables in the plot - - \see plottable -*/ -int QCustomPlot::plottableCount() const -{ - return mPlottables.size(); -} - -/*! - Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. - - There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. - - \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedPlottables() const -{ - QList result; - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (plottable->selected()) - result.append(plottable); - } - return result; -} - -/*! - Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines - (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple - plottables come into consideration, the one closest to \a pos is returned. - - If \a onlySelectable is true, only plottables that are selectable - (QCPAbstractPlottable::setSelectable) are considered. - - If there is no plottable at \a pos, the return value is 0. - - \see itemAt, layoutElementAt -*/ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable - continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes - { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultPlottable = plottable; - resultDistance = currentDistance; - } - } - } - - return resultPlottable; -} - -/*! - Returns whether this QCustomPlot instance contains the \a plottable. -*/ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const -{ - return mPlottables.contains(plottable); -} - -/*! - Returns the graph with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last created - graph, see QCustomPlot::graph() - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph(int index) const -{ - if (index >= 0 && index < mGraphs.size()) - { - return mGraphs.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, - returns 0. - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph() const -{ - if (!mGraphs.isEmpty()) - { - return mGraphs.last(); - } else - return 0; -} - -/*! - Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the - bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a - keyAxis and \a valueAxis must reside in this QCustomPlot. - - \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically - "y") for the graph. - - Returns a pointer to the newly created graph, or 0 if adding the graph failed. - - \see graph, graphCount, removeGraph, clearGraphs -*/ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; - return 0; - } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; - return 0; - } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); - return newGraph; -} - -/*! - Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in - the plot have a channel fill set towards the removed graph, the channel fill property of those - graphs is reset to zero (no channel fill). - - Returns true on success. - - \see clearGraphs -*/ -bool QCustomPlot::removeGraph(QCPGraph *graph) -{ - return removePlottable(graph); -} - -/*! \overload - - Removes and deletes the graph by its \a index. -*/ -bool QCustomPlot::removeGraph(int index) -{ - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); - else - return false; -} - -/*! - Removes all graphs from the plot and deletes them. Corresponding legend items are also removed - from the default legend (QCustomPlot::legend). - - Returns the number of graphs removed. - - \see removeGraph -*/ -int QCustomPlot::clearGraphs() -{ - int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); - return c; -} - -/*! - Returns the number of currently existing graphs in the plot - - \see graph, addGraph -*/ -int QCustomPlot::graphCount() const -{ - return mGraphs.size(); -} - -/*! - Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. - - If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, - etc., use \ref selectedPlottables. - - \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedGraphs() const -{ - QList result; - Q_FOREACH (QCPGraph *graph, mGraphs) - { - if (graph->selected()) - result.append(graph); - } - return result; -} - -/*! - Returns the item with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - item, see QCustomPlot::item() - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item(int index) const -{ - if (index >= 0 && index < mItems.size()) - { - return mItems.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last item that was added to this plot. If there are no items in the plot, - returns 0. - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item() const -{ - if (!mItems.isEmpty()) - { - return mItems.last(); - } else - return 0; -} - -/*! - Removes the specified item from the plot and deletes it. - - Returns true on success. - - \see clearItems -*/ -bool QCustomPlot::removeItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - delete item; - mItems.removeOne(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); - return false; - } -} - -/*! \overload - - Removes and deletes the item by its \a index. -*/ -bool QCustomPlot::removeItem(int index) -{ - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all items from the plot and deletes them. - - Returns the number of items removed. - - \see removeItem -*/ -int QCustomPlot::clearItems() -{ - int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); - return c; -} - -/*! - Returns the number of currently existing items in the plot - - \see item -*/ -int QCustomPlot::itemCount() const -{ - return mItems.size(); -} - -/*! - Returns a list of the selected items. If no items are currently selected, the list is empty. - - \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected -*/ -QList QCustomPlot::selectedItems() const -{ - QList result; - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (item->selected()) - result.append(item); - } - return result; -} - -/*! - Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref - QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref - setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is - returned. - - If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are - considered. - - If there is no item at \a pos, the return value is 0. - - \see plottableAt, layoutElementAt -*/ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable - continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it - { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultItem = item; - resultDistance = currentDistance; - } - } - } - - return resultItem; -} - -/*! - Returns whether this QCustomPlot contains the \a item. - - \see item -*/ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const -{ - return mItems.contains(item); -} - -/*! - Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is - returned. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(const QString &name) const -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - if (layer->name() == name) - return layer; - } - return 0; -} - -/*! \overload - - Returns the layer by \a index. If the index is invalid, 0 is returned. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(int index) const -{ - if (index >= 0 && index < mLayers.size()) - { - return mLayers.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Returns the layer that is set as current layer (see \ref setCurrentLayer). -*/ -QCPLayer *QCustomPlot::currentLayer() const -{ - return mCurrentLayer; -} - -/*! - Sets the layer with the specified \a name to be the current layer. All layerables (\ref - QCPLayerable), e.g. plottables and items, are created on the current layer. - - Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer -*/ -bool QCustomPlot::setCurrentLayer(const QString &name) -{ - if (QCPLayer *newCurrentLayer = layer(name)) - { - return setCurrentLayer(newCurrentLayer); - } else - { - qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; - return false; - } -} - -/*! \overload - - Sets the provided \a layer to be the current layer. - - Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. - - \see addLayer, moveLayer, removeLayer -*/ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - - mCurrentLayer = layer; - return true; -} - -/*! - Returns the number of currently existing layers in the plot - - \see layer, addLayer -*/ -int QCustomPlot::layerCount() const -{ - return mLayers.size(); -} - -/*! - Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which - must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. - - Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a - valid layer inside this QCustomPlot. - - If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. - - For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. - - \see layer, moveLayer, removeLayer -*/ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!otherLayer) - otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - if (layer(name)) - { - qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; - return false; - } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); - updateLayerIndices(); - setupPaintBuffers(); // associates new layer with the appropriate paint buffer - return true; -} - -/*! - Removes the specified \a layer and returns true on success. - - All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below - \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both - cases, the total rendering order of all layerables in the QCustomPlot is preserved. - - If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom - layer) becomes the new current layer. - - It is not possible to remove the last layer of the plot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::removeLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (mLayers.size() < 2) - { - qDebug() << Q_FUNC_INFO << "can't remove last layer"; - return false; - } - - // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) - int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); - QList children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) - { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally - { - for (int i=0; imoveToLayer(targetLayer, false); - } - // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); - // invalidate the paint buffer that was responsible for this layer: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - // remove layer: - delete layer; - mLayers.removeOne(layer); - updateLayerIndices(); - return true; -} - -/*! - Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or - below is controlled with \a insertMode. - - Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the - QCustomPlot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - - if (layer->index() > otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - else if (layer->index() < otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); - - // invalidate the paint buffers that are responsible for the layers: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - if (!otherLayer->mPaintBuffer.isNull()) - otherLayer->mPaintBuffer.data()->setInvalidated(); - - updateLayerIndices(); - return true; -} - -/*! - Returns the number of axis rects in the plot. - - All axis rects can be accessed via QCustomPlot::axisRect(). - - Initially, only one axis rect exists in the plot. - - \see axisRect, axisRects -*/ -int QCustomPlot::axisRectCount() const -{ - return axisRects().size(); -} - -/*! - Returns the axis rect with \a index. - - Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were - added, all of them may be accessed with this function in a linear fashion (even when they are - nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). - - \see axisRectCount, axisRects -*/ -QCPAxisRect *QCustomPlot::axisRect(int index) const -{ - const QList rectList = axisRects(); - if (index >= 0 && index < rectList.size()) - { - return rectList.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; - return 0; - } -} - -/*! - Returns all axis rects in the plot. - - \see axisRectCount, axisRect -*/ -QList QCustomPlot::axisRects() const -{ - QList result; - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) - { - if (element) - { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast(element)) - result.append(ar); - } - } - } - - return result; -} - -/*! - Returns the layout element at pixel position \a pos. If there is no element at that position, - returns 0. - - Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on - any of its parent elements is set to false, it will not be considered. - - \see itemAt, plottableAt -*/ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const -{ - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - break; - } - } - } - return currentElement; -} - -/*! - Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores - other layout elements even if they are visually in front of the axis rect (e.g. a \ref - QCPLegend). If there is no axis rect at that position, returns 0. - - Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or - on any of its parent elements is set to false, it will not be considered. - - \see layoutElementAt -*/ -QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const -{ - QCPAxisRect *result = 0; - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - if (QCPAxisRect *ar = qobject_cast(currentElement)) - result = ar; - break; - } - } - } - return result; -} - -/*! - Returns the axes that currently have selected parts, i.e. whose selection state is not \ref - QCPAxis::spNone. - - \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, - QCPAxis::setSelectableParts -*/ -QList QCustomPlot::selectedAxes() const -{ - QList result, allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); - } - - return result; -} - -/*! - Returns the legends that currently have selected parts, i.e. whose selection state is not \ref - QCPLegend::spNone. - - \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, - QCPLegend::setSelectableParts, QCPLegend::selectedItems -*/ -QList QCustomPlot::selectedLegends() const -{ - QList result; - - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) - { - if (subElement) - { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast(subElement)) - { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); - } - } - } - } - - return result; -} - -/*! - Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. - - Since calling this function is not a user interaction, this does not emit the \ref - selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the - objects were previously selected. - - \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends -*/ -void QCustomPlot::deselectAll() -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); - } -} - -/*! - Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is - refreshed with the new buffer contents. This is the method that must be called to make changes to - the plot, e.g. on the axis ranges or data points of graphs, visible. - - The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example - if your application calls \ref replot very quickly in succession (e.g. multiple independent - functions change some aspects of the plot and each wants to make sure the change gets replotted), - it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the - actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref - replot with this priority will only cause a single replot, avoiding redundant replots and - improving performance. - - Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the - QCustomPlot widget and user interactions (object selection and range dragging/zooming). - - Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref - afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two - signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite - recursion. - - If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to - replot only that specific layer via \ref QCPLayer::replot. See the documentation there for - details. -*/ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) -{ - if (refreshPriority == QCustomPlot::rpQueuedReplot) - { - if (!mReplotQueued) - { - mReplotQueued = true; - QTimer::singleShot(0, this, SLOT(replot())); - } - return; - } - - if (mReplotting) // incase signals loop back to replot slot - return; - mReplotting = true; - mReplotQueued = false; - Q_EMIT beforeReplot(); - - updateLayout(); - // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: - setupPaintBuffers(); - Q_FOREACH (QCPLayer *layer, mLayers) - layer->drawToPaintBuffer(); - for (int i=0; isetInvalidated(false); - - if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) - repaint(); - else - update(); - - Q_EMIT afterReplot(); - mReplotting = false; -} - -/*! - Rescales the axes such that all plottables (like graphs) in the plot are fully visible. - - if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true - (QCPLayerable::setVisible), will be used to rescale the axes. - - \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale -*/ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) -{ - QList allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); -} - -/*! - Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale - of texts and lines will be derived from the specified \a width and \a height. This means, the - output will look like the normal on-screen output of a QCustomPlot widget with the corresponding - pixel width and height. If either \a width or \a height is zero, the exported image will have the - same dimensions as the QCustomPlot widget currently has. - - Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when - drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as - a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information - about cosmetic pens, see the QPainter and QPen documentation. - - The objects of the plot will appear in the current selection state. If you don't want any - selected objects to be painted in their selected look, deselect everything with \ref deselectAll - before calling this function. - - Returns true on success. - - \warning - \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it - is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines - (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). - \li If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting - PDF file. - - \note On Android systems, this method does nothing and issues an according qDebug warning - message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. - - \see savePng, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) -{ - bool success = false; -#ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(exportPen) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(pdfCreator) - Q_UNUSED(pdfTitle) - qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; -#else - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); -#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) - printer.setFullPage(true); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); -#else - QPageLayout pageLayout; - pageLayout.setMode(QPageLayout::FullPageMode); - pageLayout.setOrientation(QPageLayout::Portrait); - pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); - pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); - printer.setPageLayout(pageLayout); -#endif - QCPPainter printpainter; - if (printpainter.begin(&printer)) - { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && - mBackgroundBrush.color() != Qt::white && - mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); - printpainter.end(); - success = true; - } - setViewport(oldViewport); -#endif // QT_NO_PRINTER - return success; -} - -/*! - Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the PNG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) - with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); -} - -/*! - Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the JPEG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveBmp, saveRastered -*/ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); -} - -/*! - Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the BMP format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveJpg, saveRastered -*/ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); -} - -/*! \internal - - Returns a minimum size hint that corresponds to the minimum size of the top level layout - (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum - size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. - This is especially important, when placed in a QLayout where other components try to take in as - much space as possible (e.g. QMdiArea). -*/ -QSize QCustomPlot::minimumSizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Returns a size hint that is the same as \ref minimumSizeHint. - -*/ -QSize QCustomPlot::sizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but - draws the internal buffer on the widget surface. -*/ -void QCustomPlot::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - QCPPainter painter(this); - if (painter.isActive()) - { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - drawBackground(&painter); - for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) - mPaintBuffers.at(bufferIndex)->draw(&painter); - } -} - -/*! \internal - - Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect - of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. -*/ -void QCustomPlot::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event) - // resize and repaint the buffer: - setViewport(rect()); - replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) -} - -/*! \internal - - Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then - determines the layerable under the cursor and forwards the event to it. Finally, emits the - specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref - axisDoubleClick, etc.). - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_EMIT mouseDoubleClick(event); - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - // determine layerable under the cursor (this event is called instead of the second press event in a double-click): - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - - // emit specialized object double click signals: - if (!candidates.isEmpty()) - { - if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) - { - int dataIndex = 0; - if (!details.first().value().isEmpty()) - dataIndex = details.first().value().dataRange().begin(); - Q_EMIT plottableDoubleClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(candidates.first())) - Q_EMIT axisDoubleClick(ax, details.first().value(), event); - else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) - Q_EMIT itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(li->parentLegend(), li, event); - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is pressed. Emits the mousePress signal. - - If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the - selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCustomPlot::mousePressEvent(QMouseEvent *event) -{ - Q_EMIT mousePress(event); - // save some state to tell in releaseEvent whether it was a click: - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - if (mSelectionRect && mSelectionRectMode != QCP::srmNone) - { - if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect - mSelectionRect->startSelection(event); - } else - { - // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - if (!candidates.isEmpty()) - { - mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) - mMouseSignalLayerableDetails = details.first(); - } - // forward event to topmost candidate which accepts the event: - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list - candidates.at(i)->mousePressEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when the cursor is moved. Emits the \ref mouseMove signal. - - If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it - in order to update the rect geometry. - - Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the - layout element before), the mouseMoveEvent is forwarded to that element. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) -{ - Q_EMIT mouseMove(event); - - if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) - mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release - - if (mSelectionRect && mSelectionRect->isActive()) - mSelectionRect->moveSelection(event); - else if (mMouseEventLayerable) // call event of affected layerable: - mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. - - If the mouse was moved less than a certain threshold in any direction since the \ref - mousePressEvent, it is considered a click which causes the selection mechanism (if activated via - \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse - click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) - - If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable - before), the \ref mouseReleaseEvent is forwarded to that element. - - \see mousePressEvent, mouseMoveEvent -*/ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) -{ - Q_EMIT mouseRelease(event); - - if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click - { - if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here - mSelectionRect->cancel(); - if (event->button() == Qt::LeftButton) - processPointSelection(event); - - // emit specialized click signals of QCustomPlot instance: - if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) - { - int dataIndex = 0; - if (!mMouseSignalLayerableDetails.value().isEmpty()) - dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); - Q_EMIT plottableClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) - Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); - else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) - Q_EMIT itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(li->parentLegend(), li, event); - mMouseSignalLayerable = 0; - } - - if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there - { - // finish selection rect, the appropriate action will be taken via signal-slot connection: - mSelectionRect->endSelection(event); - } else - { - // call event of affected layerable: - if (mMouseEventLayerable) - { - mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); - mMouseEventLayerable = 0; - } - } - - if (noAntialiasingOnDrag()) - replot(rpQueuedReplot); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then - determines the affected layerable and forwards the event to it. -*/ -void QCustomPlot::wheelEvent(QWheelEvent *event) -{ - Q_EMIT mouseWheel(event); - // forward event to layerable under cursor: - QList candidates = layerableListAt(event->pos(), false); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->wheelEvent(event); - if (event->isAccepted()) - break; - } - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - This function draws the entire plot, including background pixmap, with the specified \a painter. - It does not make use of the paint buffers like \ref replot, so this is the function typically - used by saving/exporting methods such as \ref savePdf or \ref toPainter. - - Note that it does not fill the background with the background brush (as the user may specify with - \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this - method. -*/ -void QCustomPlot::draw(QCPPainter *painter) -{ - updateLayout(); - - // draw viewport background pixmap: - drawBackground(painter); - - // draw all layered objects (grid, axes, plottables, items, legend,...): - Q_FOREACH (QCPLayer *layer, mLayers) - layer->draw(painter); - - /* Debug code to draw all layout element rects - foreach (QCPLayoutElement* el, findChildren()) - { - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->rect()); - painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->outerRect()); - } - */ -} - -/*! \internal - - Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref - QCPLayoutElement::update on the main plot layout. - - Here, the layout elements calculate their positions and margins, and prepare for the following - draw call. -*/ -void QCustomPlot::updateLayout() -{ - // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); -} - -/*! \internal - - Draws the viewport background pixmap of the plot. - - If a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the viewport with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - Note that this function does not draw a fill with the background brush - (\ref setBackground(const QBrush &brush)) beneath the pixmap. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::drawBackground(QCPPainter *painter) -{ - // Note: background color is handled in individual replot/save functions - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); - } - } -} - -/*! \internal - - Goes through the layers and makes sure this QCustomPlot instance holds the correct number of - paint buffers and that they have the correct configuration (size, pixel ratio, etc.). - Allocations, reallocations and deletions of paint buffers are performed as necessary. It also - associates the paint buffers with the layers, so they draw themselves into the right buffer when - \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref - QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for - layers in \ref QCPLayer::lmBuffered mode. - - This method uses \ref createPaintBuffer to create new paint buffers. - - After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated - (so an attempt to replot only a single buffered layer causes a full replot). - - This method is called in every \ref replot call, prior to actually drawing the layers (into their - associated paint buffer). If the paint buffers don't need changing/reallocating, this method - basically leaves them alone and thus finishes very fast. -*/ -void QCustomPlot::setupPaintBuffers() -{ - int bufferIndex = 0; - if (mPaintBuffers.isEmpty()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - - for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) - { - QCPLayer *layer = mLayers.at(layerIndex); - if (layer->mode() == QCPLayer::lmLogical) - { - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - } else if (layer->mode() == QCPLayer::lmBuffered) - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - } - } - } - // remove unneeded buffers: - while (mPaintBuffers.size()-1 > bufferIndex) - mPaintBuffers.removeLast(); - // resize buffers to viewport size and clear contents: - for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size - mPaintBuffers.at(i)->clear(Qt::transparent); - mPaintBuffers.at(i)->setInvalidated(); - } -} - -/*! \internal - - This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. - - Depending on the current setting of \ref setOpenGl, and the current Qt version, different - backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper - size and device pixel ratio, and returned. -*/ -QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() -{ - if (mOpenGl) - { -#if defined(QCP_OPENGL_FBO) - return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); -#elif defined(QCP_OPENGL_PBUFFER) - return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); -#else - qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -#endif - } else - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -} - -/*! - This method returns whether any of the paint buffers held by this QCustomPlot instance are - invalidated. - - If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always - causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example - the layer order has changed, new layers were added, layers were removed, or layer modes were - changed (\ref QCPLayer::setMode). - - \see QCPAbstractPaintBuffer::setInvalidated -*/ -bool QCustomPlot::hasInvalidatedPaintBuffers() -{ - for (int i=0; iinvalidated()) - return true; - } - return false; -} - -/*! \internal - - When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, - surface, paint device). - - Returns true on success. - - If this method is successful, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref - QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. - - \see freeOpenGl -*/ -bool QCustomPlot::setupOpenGl() -{ -#ifdef QCP_OPENGL_FBO - freeOpenGl(); - QSurfaceFormat proposedSurfaceFormat; - proposedSurfaceFormat.setSamples(mOpenGlMultisamples); -#ifdef QCP_OPENGL_OFFSCREENSURFACE - QOffscreenSurface *surface = new QOffscreenSurface; -#else - QWindow *surface = new QWindow; - surface->setSurfaceType(QSurface::OpenGLSurface); -#endif - surface->setFormat(proposedSurfaceFormat); - surface->create(); - mGlSurface = QSharedPointer(surface); - mGlContext = QSharedPointer(new QOpenGLContext); - mGlContext->setFormat(mGlSurface->format()); - if (!mGlContext->create()) - { - qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device - { - qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - { - qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); - return true; -#elif defined(QCP_OPENGL_PBUFFER) - return QGLFormat::hasOpenGL(); -#else - return false; -#endif -} - -/*! \internal - - When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the - context and frees resources). - - After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref - QCPPaintBufferPixmap) is used for subsequent replots. - - \see setupOpenGl -*/ -void QCustomPlot::freeOpenGl() -{ -#ifdef QCP_OPENGL_FBO - mGlPaintDevice.clear(); - mGlContext.clear(); - mGlSurface.clear(); -#endif -} - -/*! \internal - - This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot - so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. -*/ -void QCustomPlot::axisRemoved(QCPAxis *axis) -{ - if (xAxis == axis) - xAxis = 0; - if (xAxis2 == axis) - xAxis2 = 0; - if (yAxis == axis) - yAxis = 0; - if (yAxis2 == axis) - yAxis2 = 0; - - // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers -} - -/*! \internal - - This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so - it may clear its QCustomPlot::legend member accordingly. -*/ -void QCustomPlot::legendRemoved(QCPLegend *legend) -{ - if (this->legend == legend) - this->legend = 0; -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmSelect. - - First, it determines which axis rect was the origin of the selection rect judging by the starting - point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be - precise) associated with that axis rect and finds the data points that are in \a rect. It does - this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. - - Then, the actual selection is done by calling the plottables' \ref - QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details - parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a - rect receive a \ref QCPAbstractPlottable::deselectEvent. - - \see processRectZoom -*/ -void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) -{ - bool selectionStateChanged = false; - - if (mInteractions.testFlag(QCP::iSelectPlottables)) - { - QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size - QRectF rectF(rect.normalized()); - if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) - { - // determine plottables that were hit by the rect and thus are candidates for selection: - Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) - { - if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) - { - QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); - if (!dataSel.isEmpty()) - potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); - } - } - - if (!mInteractions.testFlag(QCP::iMultiSelect)) - { - // only leave plottable with most selected points in map, since we will only select a single plottable: - if (!potentialSelections.isEmpty()) - { - QMap >::iterator it = potentialSelections.begin(); - while (it != potentialSelections.end()-1) // erase all except last element - it = potentialSelections.erase(it); - } - } - - bool additive = event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - // emit deselection except to those plottables who will be selected afterwards: - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - // go through selections in reverse (largest selection first) and emit select events: - QMap >::const_iterator it = potentialSelections.constEnd(); - while (it != potentialSelections.constBegin()) - { - --it; - if (mInteractions.testFlag(it.value().first->selectionCategory())) - { - bool selChanged = false; - it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } else if (mSelectionRect) - mSelectionRect->layer()->replot(); -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmZoom. - - It determines which axis rect was the origin of the selection rect judging by the starting point - of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the - provided \a rect (see \ref QCPAxisRect::zoom). - - \see processRectSelection -*/ -void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) -{ - Q_UNUSED(event) - if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) - { - QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); - affectedAxes.removeAll(static_cast(0)); - axisRect->zoom(QRectF(rect), affectedAxes); - } - replot(rpQueuedReplot); // always replot to make selection rect disappear -} - -/*! \internal - - This method is called when a simple left mouse click was detected on the QCustomPlot surface. - - It first determines the layerable that was hit by the click, and then calls its \ref - QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the - multi-select modifier was pressed, see \ref setMultiSelectModifier). - - In this method the hit layerable is determined a second time using \ref layerableAt (after the - one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This - implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the - clicked layerable determined here. For example, if a non-selectable layerable is in front of a - selectable layerable at the click position, the front layerable will receive mouse events but the - selectable one in the back will receive the \ref QCPLayerable::selectEvent. - - \see processRectSelection, QCPLayerable::selectTest -*/ -void QCustomPlot::processPointSelection(QMouseEvent *event) -{ - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); - bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) - { - // a layerable was actually clicked, call its selectEvent: - bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); - selectionStateChanged |= selChanged; - } - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } -} - -/*! \internal - - Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend - is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the - plottable. - - Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of - \a plottable is this QCustomPlot. - - This method is called automatically in the QCPAbstractPlottable base class constructor. -*/ -bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) -{ - if (mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); - return false; - } - if (plottable->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); - return false; - } - - mPlottables.append(plottable); - // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) - plottable->addToLegend(); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); - return true; -} - -/*! \internal - - In order to maintain the simplified graph interface of QCustomPlot, this method is called by the - QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true - on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. - - This graph specific registration happens in addition to the call to \ref registerPlottable by the - QCPAbstractPlottable base class. -*/ -bool QCustomPlot::registerGraph(QCPGraph *graph) -{ - if (!graph) - { - qDebug() << Q_FUNC_INFO << "passed graph is zero"; - return false; - } - if (mGraphs.contains(graph)) - { - qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; - return false; - } - - mGraphs.append(graph); - return true; -} - - -/*! \internal - - Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. - - Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a - item is this QCustomPlot. - - This method is called automatically in the QCPAbstractItem base class constructor. -*/ -bool QCustomPlot::registerItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); - return false; - } - if (item->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); - return false; - } - - mItems.append(item); - if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) - item->setLayer(currentLayer()); - return true; -} - -/*! \internal - - Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called - after every operation that changes the layer indices, like layer removal, layer creation, layer - moving. -*/ -void QCustomPlot::updateLayerIndices() const -{ - for (int i=0; imIndex = i; -} - -/*! \internal - - Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, - only those layerables that are selectable will be considered. (Layerable subclasses communicate - their selectability via the QCPLayerable::selectTest method, by returning -1.) - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableListAt, layoutElementAt, axisRectAt -*/ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const -{ - QList details; - QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); - if (selectionDetails && !details.isEmpty()) - *selectionDetails = details.first(); - if (!candidates.isEmpty()) - return candidates.first(); - else - return 0; -} - -/*! \internal - - Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those - layerables that are selectable will be considered. (Layerable subclasses communicate their - selectability via the QCPLayerable::selectTest method, by returning -1.) - - The returned list is sorted by the layerable/drawing order. If you only need to know the top-most - layerable, rather use \ref layerableAt. - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableAt, layoutElementAt, axisRectAt -*/ -QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const -{ - QList result; - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) - { - const QList layerables = mLayers.at(layerIndex)->children(); - for (int i=layerables.size()-1; i>=0; --i) - { - if (!layerables.at(i)->realVisibility()) - continue; - QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); - if (dist >= 0 && dist < selectionTolerance()) - { - result.append(layerables.at(i)); - if (selectionDetails) - selectionDetails->append(details); - } - } - } - return result; -} - -/*! - Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is - sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead - to a full resolution file with width 200.) If the \a format supports compression, \a quality may - be between 0 and 100 to control it. - - Returns true on success. If this function fails, most likely the given \a format isn't supported - by the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The \a resolution will be written to the image file header (if the file format supports this) and - has no direct consequence for the quality or the pixel size. However, if opening the image with a - tool which respects the metadata, it will be able to scale the image to match either a given size - in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in - which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted - to the format's expected resolution unit internally. - - \see saveBmp, saveJpg, savePng, savePdf -*/ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - QImage buffer = toPixmap(width, height, scale).toImage(); - - int dotsPerMeter = 0; - switch (resolutionUnit) - { - case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; - case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; - case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; - } - buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); - else - return false; -} - -/*! - Renders the plot to a pixmap and returns it. - - The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and - scale 2.0 lead to a full resolution pixmap with width 200.) - - \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf -*/ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) -{ - // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); - - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later - QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) - { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); - } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); - painter.end(); - } else // might happen if pixmap has width or height zero - { - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; - return QPixmap(); - } - return result; -} - -/*! - Renders the plot using the passed \a painter. - - The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will - appear scaled accordingly. - - \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter - on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with - the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. - - \see toPixmap -*/ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) -{ - // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - if (painter->isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else - qDebug() << Q_FUNC_INFO << "Passed painter is not active"; -} -/* end of 'src/core.cpp' */ - -//amalgamation: add plottable1d.cpp - -/* including file 'src/colorgradient.cpp', size 24646 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorGradient -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorGradient - \brief Defines a color gradient for use with e.g. \ref QCPColorMap - - This class describes a color gradient which can be used to encode data with color. For example, - QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which - take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) - with a \a position from 0 to 1. In between these defined color positions, the - color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. - - Alternatively, load one of the preset color gradients shown in the image below, with \ref - loadPreset, or by directly specifying the preset in the constructor. - - Apart from red, green and blue components, the gradient also interpolates the alpha values of the - configured color stops. This allows to display some portions of the data range as transparent in - the plot. - - \image html QCPColorGradient.png - - The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref - GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset - to all the \a setGradient methods, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient - - The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the - color gradient shall be applied periodically (wrapping around) to data values that lie outside - the data range specified on the plottable instance can be controlled with \ref setPeriodic. -*/ - -/*! - Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color - stops with \ref setColorStopAt. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient() : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); -} - -/*! - Constructs a new QCPColorGradient initialized with the colors and color interpolation according - to \a preset. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); -} - -/* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const -{ - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); -} - -/*! - Sets the number of discretization levels of the color gradient to \a n. The default is 350 which - is typically enough to create a smooth appearance. The minimum number of levels is 2. - - \image html QCPColorGradient-levelcount.png -*/ -void QCPColorGradient::setLevelCount(int n) -{ - if (n < 2) - { - qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; - n = 2; - } - if (n != mLevelCount) - { - mLevelCount = n; - mColorBufferInvalidated = true; - } -} - -/*! - Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the - colors are the values of the passed QMap \a colorStops. In between these color stops, the color - is interpolated according to \ref setColorInterpolation. - - A more convenient way to create a custom gradient may be to clear all color stops with \ref - clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with - \ref setColorStopAt. - - \see clearColorStops -*/ -void QCPColorGradient::setColorStops(const QMap &colorStops) -{ - mColorStops = colorStops; - mColorBufferInvalidated = true; -} - -/*! - Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between - these color stops, the color is interpolated according to \ref setColorInterpolation. - - \see setColorStops, clearColorStops -*/ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) -{ - mColorStops.insert(position, color); - mColorBufferInvalidated = true; -} - -/*! - Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be - interpolated linearly in RGB or in HSV color space. - - For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, - whereas in HSV space the intermediate color is yellow. -*/ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) -{ - if (interpolation != mColorInterpolation) - { - mColorInterpolation = interpolation; - mColorBufferInvalidated = true; - } -} - -/*! - Sets whether data points that are outside the configured data range (e.g. \ref - QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether - they all have the same color, corresponding to the respective gradient boundary color. - - \image html QCPColorGradient-periodic.png - - As shown in the image above, gradients that have the same start and end color are especially - suitable for a periodic gradient mapping, since they produce smooth color transitions throughout - the color map. A preset that has this property is \ref gpHues. - - In practice, using periodic color gradients makes sense when the data corresponds to a periodic - dimension, such as an angle or a phase. If this is not the case, the color encoding might become - ambiguous, because multiple different data values are shown as the same color. -*/ -void QCPColorGradient::setPeriodic(bool enabled) -{ - mPeriodic = enabled; -} - -/*! \overload - - This method is used to quickly convert a \a data array to colors. The colors will be output in - the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this - function. The data range that shall be used for mapping the data value to the gradient is passed - in \a range. \a logarithmic indicates whether the data values shall be mapped to colors - logarithmically. - - if \a data actually contains 2D-data linearized via [row*columnCount + column], you can - set \a dataIndexFactor to columnCount to convert a column instead of a row of the data - array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data - is addressed data[i*dataIndexFactor]. - - Use the overloaded method to additionally provide alpha map data. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } -} - -/*! \overload - - Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which - has the same size and structure as \a data and encodes the alpha information per data point. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!alpha) - { - qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } -} - -/*! \internal - - This method is used to colorize a single data value given in \a position, to colors. The data - range that shall be used for mapping the data value to the gradient is passed in \a range. \a - logarithmic indicates whether the data value shall be mapped to a color logarithmically. - - If an entire array of data values shall be converted, rather use \ref colorize, for better - performance. - - The returned QRgb has its r, g and b components premultiplied with alpha (see - QImage::Format_ARGB32_Premultiplied). -*/ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) - updateColorBuffer(); - int index = 0; - if (!logarithmic) - index = (position-range.lower)*(mLevelCount-1)/range.size(); - else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); - if (mPeriodic) - { - index = index % mLevelCount; - if (index < 0) - index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - } - return mColorBuffer.at(index); -} - -/*! - Clears the current color stops and loads the specified \a preset. A preset consists of predefined - color stops and the corresponding color interpolation method. - - The available presets are: - \image html QCPColorGradient.png -*/ -void QCPColorGradient::loadPreset(GradientPreset preset) -{ - clearColorStops(); - switch (preset) - { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; - } -} - -/*! - Clears all color stops. - - \see setColorStops, setColorStopAt -*/ -void QCPColorGradient::clearColorStops() -{ - mColorStops.clear(); - mColorBufferInvalidated = true; -} - -/*! - Returns an inverted gradient. The inverted gradient has all properties as this \ref - QCPColorGradient, but the order of the color stops is inverted. - - \see setColorStops, setColorStopAt -*/ -QCPColorGradient QCPColorGradient::inverted() const -{ - QCPColorGradient result(*this); - result.clearColorStops(); - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); - return result; -} - -/*! \internal - - Returns true if the color gradient uses transparency, i.e. if any of the configured color stops - has an alpha value below 255. -*/ -bool QCPColorGradient::stopsUseAlpha() const -{ - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - { - if (it.value().alpha() < 255) - return true; - } - return false; -} - -/*! \internal - - Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly - convert positions to colors. This is where the interpolation between color stops is calculated. -*/ -void QCPColorGradient::updateColorBuffer() -{ - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) - { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); - const bool useAlpha = stopsUseAlpha(); - for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop - { - mColorBuffer[i] = (it-1).value().rgba(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop - { - mColorBuffer[i] = it.value().rgba(); - } else // position is in between stops (or on an intermediate stop), interpolate color - { - QMap::const_iterator high = it; - QMap::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) - { - case ciRGB: - { - if (useAlpha) - { - const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); - const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, - ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, - ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, - alpha); - } else - { - mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), - ((1-t)*low.value().green() + t*high.value().green()), - ((1-t)*low.value().blue() + t*high.value().blue())); - } - break; - } - case ciHSV: - { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - if (useAlpha) - { - const QRgb rgb = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); - mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); - } - else - { - mColorBuffer[i] = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - } - break; - } - } - } - } - } else if (mColorStops.size() == 1) - { - const QRgb rgb = mColorStops.constBegin().value().rgb(); - const float alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); - } else // mColorStops is empty, fill color buffer with black - { - mColorBuffer.fill(qRgb(0, 0, 0)); - } - mColorBufferInvalidated = false; -} -/* end of 'src/colorgradient.cpp' */ - - -/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecoratorBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecoratorBracket - \brief A selection decorator which draws brackets around each selected data segment - - Additionally to the regular highlighting of selected segments via color, fill and scatter style, - this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data - segment of the plottable. - - The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and - \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref - setBracketBrush. - - To introduce custom bracket styles, it is only necessary to sublcass \ref - QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the - base class. -*/ - -/*! - Creates a new QCPSelectionDecoratorBracket instance with default values. -*/ -QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : - mBracketPen(QPen(Qt::black)), - mBracketBrush(Qt::NoBrush), - mBracketWidth(5), - mBracketHeight(50), - mBracketStyle(bsSquareBracket), - mTangentToData(false), - mTangentAverage(2) -{ - -} - -QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() -{ -} - -/*! - Sets the pen that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) -{ - mBracketPen = pen; -} - -/*! - Sets the brush that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) -{ - mBracketBrush = brush; -} - -/*! - Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of - the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketWidth(int width) -{ - mBracketWidth = width; -} - -/*! - Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis - of the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketHeight(int height) -{ - mBracketHeight = height; -} - -/*! - Sets the shape that the bracket/marker will have. - - \see setBracketWidth, setBracketHeight -*/ -void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) -{ - mBracketStyle = style; -} - -/*! - Sets whether the brackets will be rotated such that they align with the slope of the data at the - position that they appear in. - - For noisy data, it might be more visually appealing to average the slope over multiple data - points. This can be configured via \ref setTangentAverage. -*/ -void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) -{ - mTangentToData = enabled; -} - -/*! - Controls over how many data points the slope shall be averaged, when brackets shall be aligned - with the data (if \ref setTangentToData is true). - - From the position of the bracket, \a pointCount points towards the selected data range will be - taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to - disabling \ref setTangentToData. -*/ -void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) -{ - mTangentAverage = pointCount; - if (mTangentAverage < 1) - mTangentAverage = 1; -} - -/*! - Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and - indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening - bracket, respectively). - - The passed \a painter already contains all transformations that are necessary to position and - rotate the bracket appropriately. Painting operations can be performed as if drawing upright - brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. - - If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket - shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should - reimplement. -*/ -void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const -{ - switch (mBracketStyle) - { - case bsSquareBracket: - { - painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); - painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - break; - } - case bsHalfEllipse: - { - painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); - break; - } - case bsEllipse: - { - painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); - break; - } - case bsPlus: - { - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); - break; - } - default: - { - qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); - break; - } - } -} - -/*! - Draws the bracket decoration on the data points at the begin and end of each selected data - segment given in \a seletion. - - It uses the method \ref drawBracket to actually draw the shapes. - - \seebaseclassmethod -*/ -void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - if (!mPlottable || selection.isEmpty()) return; - - if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) - { - Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) - { - // determine position and (if tangent mode is enabled) angle of brackets: - int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; - int closeBracketDir = -openBracketDir; - QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); - QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); - double openBracketAngle = 0; - double closeBracketAngle = 0; - if (mTangentToData) - { - openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); - closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); - } - // draw opening bracket: - QTransform oldTransform = painter->transform(); - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(openBracketPos); - painter->rotate(openBracketAngle/M_PI*180.0); - drawBracket(painter, openBracketDir); - painter->setTransform(oldTransform); - // draw closing bracket: - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(closeBracketPos); - painter->rotate(closeBracketAngle/M_PI*180.0); - drawBracket(painter, closeBracketDir); - painter->setTransform(oldTransform); - } - } -} - -/*! \internal - - If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. - This method returns the angle in radians by which a bracket at the given \a dataIndex must be - rotated. - - The parameter \a direction must be set to either -1 or 1, representing whether it is an opening - or closing bracket. Since for slope calculation multiple data points are required, this defines - the direction in which the algorithm walks, starting at \a dataIndex, to average those data - points. (see \ref setTangentToData and \ref setTangentAverage) - - \a interface1d is the interface to the plottable's data which is used to query data coordinates. -*/ -double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const -{ - if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) - return 0; - direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 - - // how many steps we can actually go from index in the given direction without exceeding data bounds: - int averageCount; - if (direction < 0) - averageCount = qMin(mTangentAverage, dataIndex); - else - averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); - qDebug() << averageCount; - // calculate point average of averageCount points: - QVector points(averageCount); - QPointF pointsAverage; - int currentIndex = dataIndex; - for (int i=0; ikeyAxis(); - QCPAxis *valueAxis = mPlottable->valueAxis(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); - else - return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); -} -/* end of 'src/selectiondecorator-bracket.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisRect - \brief Holds multiple axes and arranges them in a rectangular shape. - - This class represents an axis rect, a rectangular area that is bounded on all sides with an - arbitrary number of axes. - - Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the - layout system allows to have multiple axis rects, e.g. arranged in a grid layout - (QCustomPlot::plotLayout). - - By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be - accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. - If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be - invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref - addAxes. To remove an axis, use \ref removeAxis. - - The axis rect layerable itself only draws a background pixmap or color, if specified (\ref - setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an - explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be - placed on other layers, independently of the axis rect. - - Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref - insetLayout and can be used to have other layout elements (or even other layouts with multiple - elements) hovering inside the axis rect. - - If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The - behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel - is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable - via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are - only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref - QCP::iRangeZoom. - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed - line on the far left indicates the viewport/widget border.
-*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const - - Returns the inset layout of this axis rect. It can be used to place other layout elements (or - even layouts with multiple other elements) inside/on top of an axis rect. - - \see QCPLayoutInset -*/ - -/*! \fn int QCPAxisRect::left() const - - Returns the pixel position of the left border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::right() const - - Returns the pixel position of the right border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::top() const - - Returns the pixel position of the top border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::bottom() const - - Returns the pixel position of the bottom border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::width() const - - Returns the pixel width of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::height() const - - Returns the pixel height of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QSize QCPAxisRect::size() const - - Returns the pixel size of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topLeft() const - - Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, - so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topRight() const - - Returns the top right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomLeft() const - - Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomRight() const - - Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::center() const - - Returns the center of this axis rect in pixels. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four - sides, the top and right axes are set invisible initially. -*/ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) -{ - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList()); - mAxes.insert(QCPAxis::atRight, QList()); - mAxes.insert(QCPAxis::atTop, QList()); - mAxes.insert(QCPAxis::atBottom, QList()); - - if (setupDefaultAxes) - { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - } -} - -QCPAxisRect::~QCPAxisRect() -{ - delete mInsetLayout; - mInsetLayout = 0; - - QList axesList = axes(); - for (int i=0; i ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) - { - return ax.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; - return 0; - } -} - -/*! - Returns all axes on the axis rect sides specified with \a types. - - \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of - multiple sides. - - \see axis -*/ -QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); - return result; -} - -/*! \overload - - Returns all axes of this axis rect. -*/ -QList QCPAxisRect::axes() const -{ - QList result; - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - result << it.value(); - } - return result; -} - -/*! - Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a - new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to - remove an axis, use \ref removeAxis instead of deleting it manually. - - You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was - previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership - of the axis, so you may not delete it afterwards. Further, the \a axis must have been created - with this axis rect as parent and with the same axis type as specified in \a type. If this is not - the case, a debug output is generated, the axis is not added, and the method returns 0. - - This method can not be used to move \a axis between axis rects. The same \a axis instance must - not be added multiple times to the same or different axis rects. - - If an axis rect side already contains one or more axes, the lower and upper endings of the new - axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref - QCPLineEnding::esHalfBar. - - \see addAxes, setupFullAxesBox -*/ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) -{ - QCPAxis *newAxis = axis; - if (!newAxis) - { - newAxis = new QCPAxis(this, type); - } else // user provided existing axis instance, do some sanity checks - { - if (newAxis->axisType() != type) - { - qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; - return 0; - } - if (newAxis->axisRect() != this) - { - qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; - return 0; - } - if (axes().contains(newAxis)) - { - qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; - return 0; - } - } - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset - { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); - } - mAxes[type].append(newAxis); - - // reset convenience axis pointers on parent QCustomPlot if they are unset: - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - switch (type) - { - case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } - case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } - case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } - case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } - } - } - - return newAxis; -} - -/*! - Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an - or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. - - Returns a list of the added axes. - - \see addAxis, setupFullAxesBox -*/ -QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); - return result; -} - -/*! - Removes the specified \a axis from the axis rect and deletes it. - - Returns true on success, i.e. if \a axis was a valid axis in this axis rect. - - \see addAxis -*/ -bool QCPAxisRect::removeAxis(QCPAxis *axis) -{ - // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(axis)) - { - if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) - it.value()[1]->setOffset(axis->offset()); - mAxes[it.key()].removeOne(axis); - if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); - delete axis; - return true; - } - } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); - return false; -} - -/*! - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom - specific axes, use the overloaded version of this method. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect) -{ - zoom(pixelRect, axes()); -} - -/*! \overload - - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) -{ - Q_FOREACH (QCPAxis *axis, affectedAxes) - { - if (!axis) - { - qDebug() << Q_FUNC_INFO << "a passed axis was zero"; - continue; - } - QCPRange pixelRange; - if (axis->orientation() == Qt::Horizontal) - pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); - else - pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); - axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); - } -} - -/*! - Convenience function to create an axis on each side that doesn't have any axes yet and set their - visibility to true. Further, the top/right axes are assigned the following properties of the - bottom/left axes: - - \li range (\ref QCPAxis::setRange) - \li range reversed (\ref QCPAxis::setRangeReversed) - \li scale type (\ref QCPAxis::setScaleType) - \li tick visibility (\ref QCPAxis::setTicks) - \li number format (\ref QCPAxis::setNumberFormat) - \li number precision (\ref QCPAxis::setNumberPrecision) - \li tick count of ticker (\ref QCPAxisTicker::setTickCount) - \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) - - Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. - - If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom - and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. -*/ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) -{ - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); - else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); - else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); - else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); - else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); - xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); - yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); - - if (connectRanges) - { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); - } -} - -/*! - Returns a list of all the plottables that are associated with this axis rect. - - A plottable is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see graphs, items -*/ -QList QCPAxisRect::plottables() const -{ - // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries - QList result; - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that are associated with this axis rect. - - A graph is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see plottables, items -*/ -QList QCPAxisRect::graphs() const -{ - // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries - QList result; - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis rect. - - An item is considered associated with an axis rect if any of its positions has key or value axis - set to an axis that is in this axis rect, or if any of its positions has \ref - QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref - QCPAbstractItem::setClipAxisRect) is set to this axis rect. - - \see plottables, graphs -*/ -QList QCPAxisRect::items() const -{ - // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries - // and miss those items that have this axis rect as clipAxisRect. - QList result; - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - continue; - } - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdaxisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - This method is called automatically upon replot and doesn't need to be called by users of - QCPAxisRect. - - Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), - and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its - QCPInsetLayout::update function. - - \seebaseclassmethod -*/ -void QCPAxisRect::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - switch (phase) - { - case upPreparation: - { - QList allAxes = axes(); - for (int i=0; isetupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; - } - - // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); -} - -/* inherits documentation from base class */ -QList QCPAxisRect::elements(bool recursive) const -{ - QList result; - if (mInsetLayout) - { - result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); - } - return result; -} - -/* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) -{ - drawBackground(painter); -} - -/*! - Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the - axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect - backgrounds are usually drawn below everything else. - - For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio - is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref - setBackground(const QBrush &brush). - - \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) -*/ -void QCPAxisRect::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! \overload - - Sets \a brush as the background brush. The axis rect background will be filled with this brush. - Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds - are usually drawn below everything else. - - The brush will be drawn before (under) any background pixmap, which may be specified with \ref - setBackground(const QPixmap &pm). - - To disable drawing of a background brush, set \a brush to Qt::NoBrush. - - \see setBackground(const QPixmap &pm) -*/ -void QCPAxisRect::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled - is set to true, you may control whether and how the aspect ratio of the original pixmap is - preserved with \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the axis rect dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to - define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. - \see setBackground, setBackgroundScaled -*/ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeDragAxes to retrieve a list with all set axes). - - \see setRangeDragAxes -*/ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); - else - return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); -} - -/*! - Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). - - \see setRangeZoomAxes -*/ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); - else - return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); -} - -/*! - Returns all range drag axes of the \a orientation provided. - - \see rangeZoomAxis, setRangeZoomAxes -*/ -QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; iQt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeDrag to enable the range dragging interaction. - - \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag -*/ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) -{ - mRangeDrag = orientations; -} - -/*! - Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation - corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, - QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical - axis is the left axis (yAxis). - - To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref - QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeZoom to enable the range zooming interaction. - - \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag -*/ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) -{ - mRangeZoom = orientations; -} - -/*! \overload - - Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on - the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to dragging interactions. - - \see setRangeZoomAxes -*/ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag - orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag - motion, use the overload taking two separate lists for horizontal and vertical dragging. -*/ -void QCPAxisRect::setRangeDragAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical dragging, and - define specifically which axis reacts to which drag orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) -{ - mRangeDragHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeDragVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on - the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. - - The two axes can be zoomed with different strengths, when different factors are passed to \ref - setRangeZoomFactor(double horizontalFactor, double verticalFactor). - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to zooming interactions. - - \see setRangeDragAxes -*/ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical range zooming. The - zoom orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom - interaction, use the overload taking two separate lists for horizontal and vertical zooming. -*/ -void QCPAxisRect::setRangeZoomAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical zooming, and - define specifically which axis reacts to which zoom orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) -{ - mRangeZoomHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeZoomVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with - \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to - let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal - and which is vertical, can be set with \ref setRangeZoomAxes. - - When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) - will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the - same scrolling direction will zoom out. -*/ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) -{ - mRangeZoomFactorHorz = horizontalFactor; - mRangeZoomFactorVert = verticalFactor; -} - -/*! \overload - - Sets both the horizontal and vertical zoom \a factor. -*/ -void QCPAxisRect::setRangeZoomFactor(double factor) -{ - mRangeZoomFactorHorz = factor; - mRangeZoomFactorVert = factor; -} - -/*! \internal - - Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a - pixmap. - - If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an - according filling inside the axis rect with the provided \a painter. - - Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the axis rect with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::drawBackground(QCPPainter *painter) -{ - // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); - } - } -} - -/*! \internal - - This function makes sure multiple axes on the side specified with \a type don't collide, but are - distributed according to their respective space requirement (QCPAxis::calculateMargin). - - It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the - one with index zero. - - This function is called by \ref calculateAutoMargin. -*/ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) -{ - const QList axesList = mAxes.value(type); - if (axesList.isEmpty()) - return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) - { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); - isFirstVisible = false; - } - axesList.at(i)->setOffset(offset); - } -} - -/* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) -{ - if (!mAutoMargins.testFlag(side)) - qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - - // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) - return axesList.last()->offset() + axesList.last()->calculateMargin(); - else - return 0; -} - -/*! \internal - - Reacts to a change in layout to potentially set the convenience axis pointers \ref - QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective - axes of this axis rect. This is only done if the respective convenience pointer is currently zero - and if there is no QCPAxisRect at position (0, 0) of the plot layout. - - This automation makes it simpler to replace the main axis rect with a newly created one, without - the need to manually reset the convenience pointers. -*/ -void QCPAxisRect::layoutChanged() -{ - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) - mParentPlot->xAxis = axis(QCPAxis::atBottom); - if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) - mParentPlot->yAxis = axis(QCPAxis::atLeft); - if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) - mParentPlot->xAxis2 = axis(QCPAxis::atTop); - if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) - mParentPlot->yAxis2 = axis(QCPAxis::atRight); - } -} - -/*! \internal - - Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is - pressed, the range dragging interaction is initialized (the actual range manipulation happens in - the \ref mouseMoveEvent). - - The mDragging flag is set to true and some anchor points are set that are needed to determine the - distance the mouse was dragged in the mouse move/release events later. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - mDragStartHorzRange.clear(); - for (int i=0; irange()); - mDragStartVertRange.clear(); - for (int i=0; irange()); - } - } -} - -/*! \internal - - Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a - preceding \ref mousePressEvent, the range is moved accordingly. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - - if (mRangeDrag.testFlag(Qt::Horizontal)) - { - for (int i=0; i= mDragStartHorzRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag.testFlag(Qt::Vertical)) - { - for (int i=0; i= mDragStartVertRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot - { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } - - } -} - -/* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the - ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of - the scaling operation is the current cursor position inside the axis rect. The scaling factor is - dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural - zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. - - Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse - wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be - multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as - exponent of the range zoom factor. This takes care of the wheel direction automatically, by - inverting the factor, when the wheel step is negative (f^-1 = 1/f). -*/ -void QCPAxisRect::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) - { - if (mRangeZoom != 0) - { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) - { - factor = qPow(mRangeZoomFactorHorz, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); - } - } - if (mRangeZoom.testFlag(Qt::Vertical)) - { - factor = qPow(mRangeZoomFactorVert, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); - } - } - mParentPlot->replot(); - } - } -} -/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractLegendItem - \brief The abstract base class for all entries in a QCPLegend. - - It defines a very basic interface for entries in a QCPLegend. For representing plottables in the - legend, the subclass \ref QCPPlottableLegendItem is more suitable. - - Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry - that's not even associated with a plottable). - - You must implement the following pure virtual functions: - \li \ref draw (from QCPLayerable) - - You inherit the following members you may use: - - - - - - - - -
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
-*/ - -/* start of documentation of signals */ - -/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) - - This signal is emitted when the selection state of this legend item has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/* end of documentation of signals */ - -/*! - Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not - cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. -*/ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) -{ - setLayer(QLatin1String("legend")); - setMargins(QMargins(0, 0, 0, 0)); -} - -/*! - Sets the default font of this specific legend item to \a font. - - \see setTextColor, QCPLegend::setFont -*/ -void QCPAbstractLegendItem::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the default text color of this specific legend item to \a color. - - \see setFont, QCPLegend::setTextColor -*/ -void QCPAbstractLegendItem::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - When this legend item is selected, \a font is used to draw generic text, instead of the normal - font set with \ref setFont. - - \see setFont, QCPLegend::setSelectedFont -*/ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - When this legend item is selected, \a color is used to draw generic text, instead of the normal - color set with \ref setTextColor. - - \see setTextColor, QCPLegend::setSelectedTextColor -*/ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether this specific legend item is selectable. - - \see setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this specific legend item is selected. - - It is possible to set the selection state of this item by calling this function directly, even if - setSelectable is set to false. - - \see setSelectableParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) - return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); -} - -/* inherits documentation from base class */ -QRect QCPAbstractLegendItem::clipRect() const -{ - return mOuterRect; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableLegendItem - \brief A legend item representing a plottable with an icon and the plottable name. - - This is the standard legend item for plottables. It displays an icon of the plottable next to the - plottable name. The icon is drawn by the respective plottable itself (\ref - QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. - For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the - middle. - - Legend items of this type are always associated with one plottable (retrievable via the - plottable() function and settable with the constructor). You may change the font of the plottable - name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref - QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. - - The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend - creates/removes legend items of this type. - - Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of - QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout - interface, QCPLegend has specialized functions for handling legend items conveniently, see the - documentation of \ref QCPLegend. -*/ - -/*! - Creates a new legend item associated with \a plottable. - - Once it's created, it can be added to the legend via \ref QCPLegend::addItem. - - A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref - QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. -*/ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) -{ - setAntialiased(false); -} - -/*! \internal - - Returns the pen that shall be used to draw the icon border, taking into account the selection - state of this item. -*/ -QPen QCPPlottableLegendItem::getIconBorderPen() const -{ - return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); -} - -/*! \internal - - Returns the text color that shall be used to draw text, taking into account the selection state - of this item. -*/ -QColor QCPPlottableLegendItem::getTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - -/*! \internal - - Returns the font that shall be used to draw text, taking into account the selection state of this - item. -*/ -QFont QCPPlottableLegendItem::getFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Draws the item with \a painter. The size and position of the drawn legend item is defined by the - parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref - maximumOuterSizeHint of this legend item. -*/ -void QCPPlottableLegendItem::draw(QCPPainter *painter) -{ - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); - QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); - // draw icon: - painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); - painter->restore(); - // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) - { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - int halfPen = qCeil(painter->pen().widthF()*0.5)+1; - painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped - painter->drawRect(iconRect); - } -} - -/*! \internal - - Calculates and returns the size of this item. This includes the icon, the text and the padding in - between. - - \seebaseclassmethod -*/ -QSize QCPPlottableLegendItem::minimumOuterSizeHint() const -{ - if (!mPlottable) return QSize(); - QSize result(0, 0); - QRect textRect; - QFontMetrics fontMetrics(getFont()); - QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); - result.setHeight(qMax(textRect.height(), iconSize.height())); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLegend -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLegend - \brief Manages a legend inside a QCustomPlot. - - A legend is a small box somewhere in the plot which lists plottables with their name and icon. - - A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the - plottable, for which a legend item shall be created. In the case of the main legend (\ref - QCustomPlot::legend), simply adding plottables to the plot while \ref - QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding - legend items. The legend item associated with a certain plottable can be removed with \ref - QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and - manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref - addItem, \ref removeItem, etc. - - Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref - QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement - "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds - an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as - mentioned above. In principle, any other layout elements may also be added to a legend via the - normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout - System\endlink for examples on how to add other elements to the legend and move it outside the axis - rect. - - Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control - in which order (column first or row first) the legend is filled up when calling \ref addItem, and - at which column or row wrapping occurs. - - By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the - inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another - position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend - outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement - interface. -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); - - This signal is emitted when the selection state of this legend has changed. - - \see setSelectedParts, setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs a new QCPLegend instance with default values. - - Note that by default, QCustomPlot already contains a legend ready to be used as \ref - QCustomPlot::legend -*/ -QCPLegend::QCPLegend() -{ - setFillOrder(QCPLayoutGrid::foRowsFirst); - setWrap(0); - - setRowSpacing(3); - setColumnSpacing(8); - setMargins(QMargins(7, 5, 7, 4)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black, 0)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); -} - -QCPLegend::~QCPLegend() -{ - clearItems(); - if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) - mParentPlot->legendRemoved(this); -} - -/* no doc for getter, see setSelectedParts */ -QCPLegend::SelectableParts QCPLegend::selectedParts() const -{ - // check whether any legend elements selected, if yes, add spItems to return value - bool hasSelectedItems = false; - for (int i=0; iselected()) - { - hasSelectedItems = true; - break; - } - } - if (hasSelectedItems) - return mSelectedParts | spItems; - else - return mSelectedParts & ~spItems; -} - -/*! - Sets the pen, the border of the entire legend is drawn with. -*/ -void QCPLegend::setBorderPen(const QPen &pen) -{ - mBorderPen = pen; -} - -/*! - Sets the brush of the legend background. -*/ -void QCPLegend::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will - use this font by default. However, a different font can be specified on a per-item-basis by - accessing the specific legend item. - - This function will also set \a font on all already existing legend items. - - \see QCPAbstractLegendItem::setFont -*/ -void QCPLegend::setFont(const QFont &font) -{ - mFont = font; - for (int i=0; isetFont(mFont); - } -} - -/*! - Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) - will use this color by default. However, a different colors can be specified on a per-item-basis - by accessing the specific legend item. - - This function will also set \a color on all already existing legend items. - - \see QCPAbstractLegendItem::setTextColor -*/ -void QCPLegend::setTextColor(const QColor &color) -{ - mTextColor = color; - for (int i=0; isetTextColor(color); - } -} - -/*! - Sets the size of legend icons. Legend items that draw an icon (e.g. a visual - representation of the graph) will use this size by default. -*/ -void QCPLegend::setIconSize(const QSize &size) -{ - mIconSize = size; -} - -/*! \overload -*/ -void QCPLegend::setIconSize(int width, int height) -{ - mIconSize.setWidth(width); - mIconSize.setHeight(height); -} - -/*! - Sets the horizontal space in pixels between the legend icon and the text next to it. - Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the - name of the graph) will use this space by default. -*/ -void QCPLegend::setIconTextPadding(int padding) -{ - mIconTextPadding = padding; -} - -/*! - Sets the pen used to draw a border around each legend icon. Legend items that draw an - icon (e.g. a visual representation of the graph) will use this pen by default. - - If no border is wanted, set this to \a Qt::NoPen. -*/ -void QCPLegend::setIconBorderPen(const QPen &pen) -{ - mIconBorderPen = pen; -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected - doesn't contain \ref spItems, those items become deselected. - - The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions - contains iSelectLegend. You only need to call this function when you wish to change the selection - state manually. - - This function can change the selection state of a part even when \ref setSelectableParts was set to a - value that actually excludes the part. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set - before, because there's no way to specify which exact items to newly select. Do this by calling - \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, - setSelectedFont -*/ -void QCPLegend::setSelectedParts(const SelectableParts &selected) -{ - SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - - if (mSelectedParts != newSelected) - { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) - { - qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; - newSelected &= ~spItems; - } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection - { - for (int i=0; isetSelected(false); - } - } - mSelectedParts = newSelected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - When the legend box is selected, this pen is used to draw the border instead of the normal pen - set via \ref setBorderPen. - - \see setSelectedParts, setSelectableParts, setSelectedBrush -*/ -void QCPLegend::setSelectedBorderPen(const QPen &pen) -{ - mSelectedBorderPen = pen; -} - -/*! - Sets the pen legend items will use to draw their icon borders, when they are selected. - - \see setSelectedParts, setSelectableParts, setSelectedFont -*/ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) -{ - mSelectedIconBorderPen = pen; -} - -/*! - When the legend box is selected, this brush is used to draw the legend background instead of the normal brush - set via \ref setBrush. - - \see setSelectedParts, setSelectableParts, setSelectedBorderPen -*/ -void QCPLegend::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the default font that is used by legend items when they are selected. - - This function will also set \a font on all already existing legend items. - - \see setFont, QCPAbstractLegendItem::setSelectedFont -*/ -void QCPLegend::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; - for (int i=0; isetSelectedFont(font); - } -} - -/*! - Sets the default text color that is used by legend items when they are selected. - - This function will also set \a color on all already existing legend items. - - \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor -*/ -void QCPLegend::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; - for (int i=0; isetSelectedTextColor(color); - } -} - -/*! - Returns the item with index \a i. - - Note that the linear index depends on the current fill order (\ref setFillOrder). - - \see itemCount, addItem, itemWithPlottable -*/ -QCPAbstractLegendItem *QCPLegend::item(int index) const -{ - return qobject_cast(elementAt(index)); -} - -/*! - Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns 0. - - \see hasItemWithPlottable -*/ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - for (int i=0; i(item(i))) - { - if (pli->plottable() == plottable) - return pli; - } - } - return 0; -} - -/*! - Returns the number of items currently in the legend. - - Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid - base class which allows creating empty cells), they are included in the returned count. - - \see item -*/ -int QCPLegend::itemCount() const -{ - return elementCount(); -} - -/*! - Returns whether the legend contains \a item. - - \see hasItemWithPlottable -*/ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const -{ - for (int i=0; iitem(i)) - return true; - } - return false; -} - -/*! - Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns false. - - \see itemWithPlottable -*/ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - return itemWithPlottable(plottable); -} - -/*! - Adds \a item to the legend, if it's not present already. The element is arranged according to the - current fill order (\ref setFillOrder) and wrapping (\ref setWrap). - - Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. - - The legend takes ownership of the item. - - \see removeItem, item, hasItem -*/ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) -{ - return addElement(item); -} - -/*! \overload - - Removes the item with the specified \a index from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes - elements derived from \ref QCPAbstractLegendItem. - - \see itemCount, clearItems -*/ -bool QCPLegend::removeItem(int index) -{ - if (QCPAbstractLegendItem *ali = item(index)) - { - bool success = remove(ali); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; - } else - return false; -} - -/*! \overload - - Removes \a item from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. - - \see clearItems -*/ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) -{ - bool success = remove(item); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; -} - -/*! - Removes all items from the legend. -*/ -void QCPLegend::clearItems() -{ - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); -} - -/*! - Returns the legend items that are currently selected. If no items are selected, - the list is empty. - - \see QCPAbstractLegendItem::setSelected, setSelectable -*/ -QList QCPLegend::selectedItems() const -{ - QList result; - for (int i=0; iselected()) - result.append(ali); - } - } - return result; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing main legend elements. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); -} - -/*! \internal - - Returns the pen used to paint the border of the legend, taking into account the selection state - of the legend box. -*/ -QPen QCPLegend::getBorderPen() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; -} - -/*! \internal - - Returns the brush used to paint the background of the legend, taking into account the selection - state of the legend box. -*/ -QBrush QCPLegend::getBrush() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; -} - -/*! \internal - - Draws the legend box with the provided \a painter. The individual legend items are layerables - themselves, thus are drawn independently. -*/ -void QCPLegend::draw(QCPPainter *painter) -{ - // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); -} - -/* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) - return -1; - - if (mOuterRect.contains(pos.toPoint())) - { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) -{ - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPLegend::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractLegendItem::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) -{ - if (parentPlot && !parentPlot->legend) - parentPlot->legend = this; -} -/* end of 'src/layoutelements/layoutelement-legend.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPTextElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPTextElement - \brief A layout element displaying a text - - The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, - \ref setTextColor, and \ref setTextFlags. - - A text element can be added as follows: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation -*/ - -/* start documentation of signals */ - -/*! \fn void QCPTextElement::selectionChanged(bool selected) - - This signal is emitted when the selection state has changed to \a selected, either by user - interaction or by a direct call to \ref setSelected. - - \see setSelected, setSelectable -*/ - -/*! \fn void QCPTextElement::clicked(QMouseEvent *event) - - This signal is emitted when the text element is clicked. - - \see doubleClicked, selectTest -*/ - -/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) - - This signal is emitted when the text element is double clicked. - - \see clicked, selectTest -*/ - -/* end documentation of signals */ - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref - setText). -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mText(), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mFont.setPointSizeF(pointSize); - mSelectedFont = parentPlot->font(); - mSelectedFont.setPointSizeF(pointSize); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize and the specified \a fontFamily. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(fontFamily, pointSize)), - mTextColor(Qt::black), - mSelectedFont(QFont(fontFamily, pointSize)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with the specified \a font. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(font), - mTextColor(Qt::black), - mSelectedFont(font), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! - Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". - - \see setFont, setTextColor, setTextFlags -*/ -void QCPTextElement::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of - \c Qt::AlignmentFlag and \c Qt::TextFlag enums. - - Possible enums are: - - Qt::AlignLeft - - Qt::AlignRight - - Qt::AlignHCenter - - Qt::AlignJustify - - Qt::AlignTop - - Qt::AlignBottom - - Qt::AlignVCenter - - Qt::AlignCenter - - Qt::TextDontClip - - Qt::TextSingleLine - - Qt::TextExpandTabs - - Qt::TextShowMnemonic - - Qt::TextWordWrap - - Qt::TextIncludeTrailingSpaces -*/ -void QCPTextElement::setTextFlags(int flags) -{ - mTextFlags = flags; -} - -/*! - Sets the \a font of the text. - - \see setTextColor, setSelectedFont -*/ -void QCPTextElement::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the \a color of the text. - - \see setFont, setSelectedTextColor -*/ -void QCPTextElement::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). - - \see setFont -*/ -void QCPTextElement::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). - - \see setTextColor -*/ -void QCPTextElement::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether the user may select this text element. - - Note that even when \a selectable is set to false, the selection state may be changed - programmatically via \ref setSelected. -*/ -void QCPTextElement::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets the selection state of this text element to \a selected. If the selection has changed, \ref - selectionChanged is emitted. - - Note that this function can change the selection state independently of the current \ref - setSelectable state. -*/ -void QCPTextElement::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/* inherits documentation from base class */ -void QCPTextElement::draw(QCPPainter *painter) -{ - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); -} - -/* inherits documentation from base class */ -QSize QCPTextElement::minimumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPTextElement::maximumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.setWidth(QWIDGETSIZE_MAX); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPTextElement::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/*! - Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is - within the bounding box of the text element's text. Note that this bounding box is updated in the - draw call. - - If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text - element is not selectable (\ref setSelectable), returns -1. - - \seebaseclassmethod -*/ -double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/*! - Accepts the mouse event in order to emit the according click signal in the \ref - mouseReleaseEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->accept(); -} - -/*! - Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref - mousePressEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) - Q_EMIT clicked(event); -} - -/*! - Emits the \ref doubleClicked signal. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - Q_EMIT doubleClicked(event); -} - -/*! \internal - - Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to - true, else mFont is returned. -*/ -QFont QCPTextElement::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to - true, else mTextColor is returned. -*/ -QColor QCPTextElement::mainTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} -/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScale -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScale - \brief A color scale for use with color coding data such as QCPColorMap - - This layout element can be placed on the plot to correlate a color gradient with data values. It - is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". - - \image html QCPColorScale.png - - The color scale can be either horizontal or vertical, as shown in the image above. The - orientation and the side where the numbers appear is controlled with \ref setType. - - Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are - connected, they share their gradient, data range and data scale type (\ref setGradient, \ref - setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color - scale, to make them all synchronize these properties. - - To have finer control over the number display and axis behaviour, you can directly access the - \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if - you want to change the number of automatically generated ticks, call - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount - - Placing a color scale next to the main axis rect works like with any other layout element: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation - In this case we have placed it to the right of the default axis rect, so it wasn't necessary to - call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color - scale can be set with \ref setLabel. - - For optimum appearance (like in the image above), it may be desirable to line up the axis rect and - the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup - - Color scales are initialized with a non-zero minimum top and bottom margin (\ref - setMinimumMargins), because vertical color scales are most common and the minimum top/bottom - margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a - horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you - might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPAxis *QCPColorScale::axis() const - - Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the - appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its - interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref - setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref - QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on - the QCPColorScale or on its QCPAxis. - - If the type of the color scale is changed with \ref setType, the axis returned by this method - will change, too, to either the left, right, bottom or top axis, depending on which type was set. -*/ - -/* end documentation of signals */ -/* start documentation of signals */ - -/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a new QCPColorScale. -*/ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) -{ - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); -} - -QCPColorScale::~QCPColorScale() -{ - delete mAxisRect; -} - -/* undocumented getter */ -QString QCPColorScale::label() const -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return QString(); - } - - return mColorAxis.data()->label(); -} - -/* undocumented getter */ -bool QCPColorScale::rangeDrag() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/* undocumented getter */ -bool QCPColorScale::rangeZoom() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/*! - Sets at which side of the color scale the axis is placed, and thus also its orientation. - - Note that after setting \a type to a different value, the axis returned by \ref axis() will - be a different one. The new axis will adopt the following properties from the previous axis: The - range, scale type, label and ticker (the latter will be shared and not copied). -*/ -void QCPColorScale::setType(QCPAxis::AxisType type) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - if (mType != type) - { - mType = type; - QCPRange rangeTransfer(0, 6); - QString labelTransfer; - QSharedPointer tickerTransfer; - // transfer/revert some settings on old axis if it exists: - bool doTransfer = (bool)mColorAxis; - if (doTransfer) - { - rangeTransfer = mColorAxis.data()->range(); - labelTransfer = mColorAxis.data()->label(); - tickerTransfer = mColorAxis.data()->ticker(); - mColorAxis.data()->setLabel(QString()); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; - Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) - { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); - } - // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); - // transfer settings to new axis: - if (doTransfer) - { - mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setTicker(tickerTransfer); - } - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); - } -} - -/*! - Sets the range spanned by the color gradient and that is shown by the axis in the color scale. - - It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its range with \ref - QCPAxis::setRange. - - \see setDataScaleType, setGradient, rescaleDataRange -*/ -void QCPColorScale::setDataRange(const QCPRange &dataRange) -{ - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets the scale type of the color scale, i.e. whether values are linearly associated with colors - or logarithmically. - - It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its scale type with \ref - QCPAxis::setScaleType. - - \see setDataRange, setGradient -*/ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - Q_EMIT dataScaleTypeChanged(mDataScaleType); - } -} - -/*! - Sets the color gradient that will be used to represent data values. - - It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. - - \see setDataRange, setDataScaleType -*/ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - if (mAxisRect) - mAxisRect.data()->mGradientImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on - the internal \ref axis. -*/ -void QCPColorScale::setLabel(const QString &str) -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return; - } - - mColorAxis.data()->setLabel(str); -} - -/*! - Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed - will have. -*/ -void QCPColorScale::setBarWidth(int width) -{ - mBarWidth = width; -} - -/*! - Sets whether the user can drag the data range (\ref setDataRange). - - Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeDrag(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeDrag(0); -} - -/*! - Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. - - Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeZoom(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeZoom(0); -} - -/*! - Returns a list of all the color maps associated with this color scale. -*/ -QList QCPColorScale::colorMaps() const -{ - QList result; - for (int i=0; iplottableCount(); ++i) - { - if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); - } - return result; -} - -/*! - Changes the data range such that all color maps associated with this color scale are fully mapped - to the gradient in the data dimension. - - \see setDataRange -*/ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) -{ - QList maps = colorMaps(); - QCPRange newRange; - bool haveRange = false; - QCP::SignDomain sign = QCP::sdBoth; - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - for (int i=0; irealVisibility() && onlyVisibleMaps) - continue; - QCPRange mapRange; - if (maps.at(i)->colorScale() == this) - { - bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == QCP::sdPositive) - { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == QCP::sdNegative) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) - currentFoundRange = false; - } - if (currentFoundRange) - { - if (!haveRange) - newRange = mapRange; - else - newRange.expand(mapRange); - haveRange = true; - } - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) - { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); - } - } - setDataRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - mAxisRect.data()->update(phase); - - switch (phase) - { - case upMargins: - { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); - } - break; - } - case upLayout: - { - mAxisRect.data()->setOuterRect(rect()); - break; - } - default: break; - } -} - -/* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mousePressEvent(event, details); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseMoveEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseReleaseEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->wheelEvent(event); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScaleAxisRectPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScaleAxisRectPrivate - - \internal - \brief An axis rect subclass for use in a QCPColorScale - - This is a private class and not part of the public QCustomPlot interface. - - It provides the axis rect functionality for the QCPColorScale class. -*/ - - -/*! - Creates a new instance, as a child of \a parentColorScale. -*/ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) -{ - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); - } - - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - - // make layer transfers of color scale transfer to axis rect and axes - // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); -} - -/*! \internal - - Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws - it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. - - \seebaseclassmethod -*/ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) -{ - if (mGradientImageInvalidated) - updateGradientImage(); - - bool mirrorHorz = false; - bool mirrorVert = false; - if (mParentColorScale->mColorAxis) - { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); - } - - painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); -} - -/*! \internal - - Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to - generate a gradient image. This gradient image will be used in the \ref draw method. -*/ -void QCPColorScaleAxisRectPrivate::updateGradientImage() -{ - if (rect().isEmpty()) - return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - int n = mParentColorScale->mGradient.levelCount(); - int w, h; - QVector data(n); - for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) - { - w = n; - h = rect().height(); - mGradientImage = QImage(w, h, format); - QVector pixels; - for (int y=0; y(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); - else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); - } - } -} - -/*! \internal - - This slot is connected to the selectableChanged signals of the four axes in the constructor. It - synchronizes the selectability of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) -{ - // synchronize axis base selectability: - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); - else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); - } - } -} -/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ - - -/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraphData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraphData - \brief Holds the data of one single data point for QCPGraph. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPGraphDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPGraphData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPGraphData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and value set to zero. -*/ -QCPGraphData::QCPGraphData() : - key(0), - value(0) -{ -} - -/*! - Constructs a data point with the specified \a key and \a value. -*/ -QCPGraphData::QCPGraphData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraph -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraph - \brief A plottable representing a graph in a plot. - - \image html QCPGraph.png - - Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be - accessed via QCustomPlot::graph. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPGraphDataContainer. - - Graphs are used to display single-valued data. Single-valued means that there should only be one - data point per unique key coordinate. In other words, the graph can't have \a loops. If you do - want to plot non-single-valued curves, rather use the QCPCurve plottable. - - Gaps in the graph line can be created by adding data points with NaN as value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpgraph-appearance Changing the appearance - - The appearance of the graph is mainly determined by the line style, scatter style, brush and pen - of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). - - \subsection filling Filling under or between graphs - - QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to - the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, - just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. - - By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill - between this graph and another one, call \ref setChannelFillGraph with the other graph as - parameter. - - \see QCustomPlot::addGraph, QCustomPlot::graph -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPGraph::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually - but use QCustomPlot::removePlottable() instead. - - To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. -*/ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // special handling for QCPGraphs to maintain the simple graph interface: - mParentPlot->registerGraph(this); - - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setScatterSkip(0); - setChannelFillGraph(0); - setAdaptiveSampling(true); -} - -QCPGraph::~QCPGraph() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. - Modifying the data in the container will then affect all graphs that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the graph's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 - - \see addData -*/ -void QCPGraph::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to - \ref lsNone and \ref setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPGraph::setLineStyle(LineStyle ls) -{ - mLineStyle = ls; -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points - are drawn (e.g. for line-only-plots with appropriate line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPGraph::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets the target graph for filling the area between this graph and \a targetGraph with the current - brush (\ref setBrush). - - When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To - disable any filling, set the brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) -{ - // prevent setting channel target to this graph itself: - if (targetGraph == this) - { - qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; - mChannelFillGraph = 0; - return; - } - // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; - mChannelFillGraph = 0; - return; - } - - mChannelFillGraph = targetGraph; -} - -/*! - Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive - sampling technique can drastically improve the replot performance for graphs with a larger number - of points (e.g. above 10,000), without notably changing the appearance of the graph. - - By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive - sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no - disadvantage in almost all cases. - - \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" - - As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are - reproduced reliably, as well as the overall shape of the data set. The replot time reduces - dramatically though. This allows QCustomPlot to display large amounts of data in realtime. - - \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" - - Care must be taken when using high-density scatter plots in combination with adaptive sampling. - The adaptive sampling algorithm treats scatter plots more carefully than line plots which still - gives a significant reduction of replot times, but not quite as much as for line plots. This is - because scatter plots inherently need more data points to be preserved in order to still resemble - the original, non-adaptive-sampling plot. As shown above, the results still aren't quite - identical, as banding occurs for the outer data points. This is in fact intentional, such that - the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, - depends on the point density, i.e. the number of points in the plot. - - For some situations with scatter plots it might thus be desirable to manually turn adaptive - sampling off. For example, when saving the plot to disk. This can be achieved by setting \a - enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled - back to true afterwards. -*/ -void QCPGraph::setAdaptiveSampling(bool enabled) -{ - mAdaptiveSampling = enabled; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(double key, double value) -{ - mDataContainer->add(QCPGraphData(key, value)); -} - -/* inherits documentation from base class */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - // get line pixel points appropriate to line style: - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) - getLines(&lines, lineDataRange); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPGraphDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw fill of graph: - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - drawFill(painter, &lines); - - // draw line: - if (mLineStyle != lsNone) - { - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - painter->setBrush(Qt::NoBrush); - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lines); - else - drawLinePlot(painter, lines); // also step plots can be drawn as a line plot - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i)); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches - out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. - according to the line style of the graph. - - \a lines will be filled with points in pixel coordinates, that can be drawn with the according - draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines - aren't necessarily the original data points. For example, step line styles require additional - points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a - lines vector will be empty. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. - - \see getScatters -*/ -void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const -{ - if (!lines) return; - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - lines->clear(); - return; - } - - QVector lineData; - if (mLineStyle != lsNone) - getOptimizedLineData(&lineData, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) - std::reverse(lineData.begin(), lineData.end()); - - switch (mLineStyle) - { - case lsNone: lines->clear(); break; - case lsLine: *lines = dataToLines(lineData); break; - case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; - case lsStepRight: *lines = dataToStepRightLines(lineData); break; - case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; - case lsImpulse: *lines = dataToImpulseLines(lineData); break; - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then - converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be - passed to \ref drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. -*/ -void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const -{ - if (!scatters) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } - - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - scatters->clear(); - return; - } - - QVector data; - getOptimizedScatterData(&data, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) - std::reverse(data.begin(), data.end()); - - scatters->resize(data.size()); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } - } else - { - for (int i=0; icoordToPixel(data.at(i).key)); - (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - } -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsLine. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - result[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key)); - result[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepLeft. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepLeftLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(lastValue); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(key); - result[i*2+1].setY(lastValue); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepRight. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepRightLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(value); - result[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(value); - result[i*2+1].setY(lastKey); - } - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(lastKey); - result[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(lastKey); - result[i*2+1].setY(value); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepCenter. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepCenterLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastValue); - result[0].setY(lastKey); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(lastValue); - result[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - } - result[data.size()*2-1].setX(lastValue); - result[data.size()*2-1].setY(lastKey); - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastKey); - result[0].setY(lastValue); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(key); - result[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - } - result[data.size()*2-1].setX(lastKey); - result[data.size()*2-1].setY(lastValue); - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsImpulse. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot -*/ -QVector QCPGraph::dataToImpulseLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(valueAxis->coordToPixel(0)); - result[i*2+0].setY(key); - result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(valueAxis->coordToPixel(0)); - result[i*2+1].setX(key); - result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Draws the fill of the graph using the specified \a painter, with the currently set brush. - - Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref - getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. - - In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), - this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to - operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN - segments of the two involved graphs, before passing the overlapping pairs to \ref - getChannelFillPolygon. - - Pass the points of this graph's line as \a lines, in pixel coordinates. - - \see drawLinePlot, drawImpulsePlot, drawScatterPlot -*/ -void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const -{ - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); - if (!mChannelFillGraph) - { - // draw base fill under graph, fill goes all the way to the zero-value-line: - for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); - } else - { - // draw fill between this graph and mChannelFillGraph: - QVector otherLines; - mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); - if (!otherLines.isEmpty()) - { - QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); - QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); - for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); - } - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawLinePlot, drawImpulsePlot -*/ -void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const -{ - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in - pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines - from the regular graph data points. - - \see drawLinePlot, drawScatterPlot -*/ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - QPen oldPen = painter->pen(); - QPen newPen = painter->pen(); - newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(newPen); - painter->drawLines(lines); - painter->setPen(oldPen); - } -} - -/*! \internal - - Returns via \a lineData the data points that need to be visualized for this graph when plotting - graph lines, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getLines to retrieve the basic working set of data. - - \see getOptimizedScatterData -*/ -void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const -{ - if (!lineData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (begin == end) return; - - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - QCPGraphDataContainer::const_iterator it = begin; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary - { - if (it->value < minValue) - minValue = it->value; - else if (it->value > maxValue) - maxValue = it->value; - ++intervalDataCount; - } else // new pixel interval started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - lastIntervalEndKey = (it-1)->key; - minValue = it->value; - maxValue = it->value; - currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - lineData->resize(dataCount); - std::copy(begin, end, lineData->begin()); - } -} - -/*! \internal - - Returns via \a scatterData the data points that need to be visualized for this graph when - plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getScatters to retrieve the basic working set of data. - - \see getOptimizedLineData -*/ -void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const -{ - if (!scatterData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int beginIndex = begin-mDataContainer->constBegin(); - int endIndex = end-mDataContainer->constBegin(); - while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++beginIndex; - ++begin; - } - if (begin == end) return; - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - double valueMaxRange = valueAxis->range().upper; - double valueMinRange = valueAxis->range().lower; - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator minValueIt = it; - QCPGraphDataContainer::const_iterator maxValueIt = it; - QCPGraphDataContainer::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - // main loop over data points: - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary - { - if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) - { - minValue = it->value; - minValueIt = it; - } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) - { - maxValue = it->value; - maxValueIt = it; - } - ++intervalDataCount; - } else // new pixel started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else - intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - minValue = it->value; - maxValue = it->value; - currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int intervalItIndex = intervalIt-mDataContainer->constBegin(); - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: - { - intervalItIndex += scatterModulo; - if (intervalItIndex < itIndex) - intervalIt += scatterModulo; - else - { - intervalIt = it; - intervalItIndex = itIndex; - } - } - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - scatterData->reserve(dataCount); - while (it != end) - { - scatterData->append(*it); - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - This method takes into account that the drawing of data lines at the axis rect border always - requires the points just outside the visible axis range. So \a begin and \a end may actually - indicate a range that contains one additional data point to the left and right of the visible - axis range. -*/ -void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - if (rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - } else - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - // get visible data range: - begin = mDataContainer->findBegin(keyAxis->range().lower); - end = mDataContainer->findEnd(keyAxis->range().upper); - // limit lower/upperEnd to rangeRestriction: - mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything - } -} - -/*! \internal - - This method goes through the passed points in \a lineData and returns a list of the segments - which don't contain NaN data points. - - \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check - for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c - Qt::Vertical, the \a x member is checked. - - \see getOverlappingSegments, drawFill -*/ -QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const -{ - QVector result; - const int n = lineData->size(); - - QCPDataRange currentSegment(-1, -1); - int i = 0; - - if (keyOrientation == Qt::Horizontal) - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } else // keyOrientation == Qt::Vertical - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } - return result; -} - -/*! \internal - - This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and - \a otherSegments, and their associated point data \a thisData and \a otherData. - - It returns all pairs of segments (the first from \a thisSegments, the second from \a - otherSegments), which overlap in plot coordinates. - - This method is useful in the case of a channel fill between two graphs, when only those non-NaN - segments which actually overlap in their key coordinate shall be considered for drawing a channel - fill polygon. - - It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and - that the segments don't overlap themselves. The same is assumed for the segments in \a - otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. - - \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon -*/ -QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const -{ - QVector > result; - if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) - return result; - - int thisIndex = 0; - int otherIndex = 0; - const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; - while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) - { - if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++thisIndex; - continue; - } - if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++otherIndex; - continue; - } - double thisLower, thisUpper, otherLower, otherUpper; - if (!verticalKey) - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); - } else - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); - } - - int bPrecedence; - if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) - result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); - - if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment - ++otherIndex; - else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment - ++thisIndex; - } - - return result; -} - -/*! \internal - - Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) - have overlap. - - The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the - \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher - coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if - both segment's upper bounds are identical, 0 is returned as \a bPrecedence. - - It is assumed that the lower bounds always have smaller or equal values than the upper bounds. - - \see getOverlappingSegments -*/ -bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const -{ - bPrecedence = 0; - if (aLower > bUpper) - { - bPrecedence = -1; - return false; - } else if (bLower > aUpper) - { - bPrecedence = 1; - return false; - } else - { - if (aUpper > bUpper) - bPrecedence = -1; - else if (aUpper < bUpper) - bPrecedence = 1; - - return true; - } -} - -/*! \internal - - Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. - The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates - is in positive or negative infinity. So this case is handled separately by just closing the fill - polygon on the axis which lies in the direction towards the zero value. - - \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether - the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or - y value of the returned point, respectively. -*/ -QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF result; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->orientation() == Qt::Horizontal) - { - result.setX(matchingDataPoint.x()); - result.setY(valueAxis->coordToPixel(0)); - } else // keyAxis->orientation() == Qt::Vertical - { - result.setX(valueAxis->coordToPixel(0)); - result.setY(matchingDataPoint.y()); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value 0 so we just fill all the way - // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setX(keyAxis->axisRect()->right()); - else - result.setX(keyAxis->axisRect()->left()); - result.setY(matchingDataPoint.y()); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - result.setX(matchingDataPoint.x()); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setY(keyAxis->axisRect()->top()); - else - result.setY(keyAxis->axisRect()->bottom()); - } - } - return result; -} - -/*! \internal - - Returns the polygon needed for drawing normal fills between this graph and the key axis. - - Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment - which shall be used for the fill. The collection of \a lineData points described by \a segment - must not contain NaN data points (see \ref getNonNanSegments). - - The returned fill polygon will be closed at the key axis (the zero-value line) for linear value - axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect - side (see \ref getFillBasePoint). - - For increased performance (due to implicit sharing), keep the returned QPolygonF const. - - \see drawFill, getNonNanSegments -*/ -const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const -{ - if (segment.size() < 2) - return QPolygonF(); - QPolygonF result(segment.size()+2); - - result[0] = getFillBasePoint(lineData->at(segment.begin())); - std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); - result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); - - return result; -} - -/*! \internal - - Returns the polygon needed for drawing (partial) channel fills between this graph and the graph - specified by \ref setChannelFillGraph. - - The data points of this graph are passed as pixel coordinates via \a thisData, the data of the - other graph as \a otherData. The returned polygon will be calculated for the specified data - segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a - otherData, respectively. - - The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by - \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap - need to be processed here. - - For increased performance due to implicit sharing, keep the returned QPolygonF const. - - \see drawFill, getOverlappingSegments, getNonNanSegments -*/ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const -{ - if (!mChannelFillGraph) - return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (thisData->isEmpty()) return QPolygonF(); - QVector thisSegmentData(thisSegment.size()); - QVector otherSegmentData(otherSegment.size()); - std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); - std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); - // pointers to be able to swap them, depending which data range needs cropping: - QVector *staticData = &thisSegmentData; - QVector *croppedData = &otherSegmentData; - - // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) - { - // x is key - // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); - else - slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - - // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - const int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); - else - slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical - { - // y is key - // crop lower bound: - if (staticData->first().y() < croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); - else - slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - - // crop upper bound: - if (staticData->last().y() > croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); - else - slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); - } - - // return joined: - for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisSegmentData << otherSegmentData.at(i); - return QPolygonF(thisSegmentData); -} - -/*! \internal - - Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveX(const QVector *data, double x) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).x() < x) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowX(const QVector *data, double x) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).x() > x) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is vertical. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveY(const QVector *data, double y) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).y() < y) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Calculates the minimum distance in pixels the graph's representation has from the given \a - pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if - the graph has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the graph line is also taken into account. - - If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. -*/ -double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - // calculate minimum distances to graph data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); - QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); - for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - // line displayed, calculate distance to line segments: - QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); - QCPVector2D p(pixelPoint); - const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected - for (int i=0; i *data, double y) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).y() > y) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} -/* end of 'src/plottables/plottable-graph.cpp' */ - - -/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurveData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurveData - \brief Holds the data of one single data point for QCPCurve. - - The stored data is: - \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) - \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) - \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPCurveDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPCurveData::sortKey() const - - Returns the \a t member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). - All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() - - Since the member \a key is the data point key coordinate and the member \a t is the data ordering - parameter, this method returns false. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPCurveData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a curve data point with t, key and value set to zero. -*/ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) -{ -} - -/*! - Constructs a curve data point with the specified \a t, \a key and \a value. -*/ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurve - \brief A plottable representing a parametric curve in a plot. - - \image html QCPCurve.png - - Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, - so their visual representation can have \a loops. This is realized by introducing a third - coordinate \a t, which defines the order of the points described by the other two coordinates \a - x and \a y. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the curve's data via the \ref data method, which returns a pointer to the - internal \ref QCPCurveDataContainer. - - Gaps in the curve can be created by adding data points with NaN as key and value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpcurve-appearance Changing the appearance - - The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). - - \section qcpcurve-usage Usage - - Like all data representing objects in QCustomPlot, the QCPCurve is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPCurve::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // modify inherited properties from abstract plottable: - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); - setScatterSkip(0); -} - -QCPCurve::~QCPCurve() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. - Modifying the data in the container will then affect all curves that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the curve's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 - - \see addData -*/ -void QCPCurve::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a t, \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a t in ascending order, you can - set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(t, keys, values, alreadySorted); -} - - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - \see addData -*/ -void QCPCurve::setData(const QVector &keys, const QVector &values) -{ - mDataContainer->clear(); - addData(keys, values); -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref - QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate - line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPCurve::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets how the single data points are connected in the plot or how they are represented visually - apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref - setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) -{ - mLineStyle = style; -} - -/*! \overload - - Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (t.size() != keys.size() || t.size() != values.size()) - qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); - const int n = qMin(qMin(t.size(), keys.size()), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = t[i]; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &keys, const QVector &values) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - double tStart; - if (!mDataContainer->isEmpty()) - tStart = (mDataContainer->constEnd()-1)->t + 1.0; - else - tStart = 0; - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = tStart + i; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a t, \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double t, double key, double value) -{ - mDataContainer->add(QCPCurveData(t, key, value)); -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - The t parameter is generated automatically by increments of 1 for each point, starting at the - highest t of previously existing data or 0, if the curve data is empty. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double key, double value) -{ - if (!mDataContainer->isEmpty()) - mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); - else - mDataContainer->add(QCPCurveData(0.0, key, value)); -} - -/* inherits documentation from base class */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - - // allocate line vector: - QVector lines, scatters; - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - - // fill with curve data: - QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width - if (isSelectedSegment && mSelectionDecorator) - finalCurvePen = mSelectionDecorator->pen(); - - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) - getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); - - // check data validity if flag set: - #ifdef QCUSTOMPLOT_CHECK_DATA - for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->t) || - QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } - #endif - - // draw curve fill: - applyFillAntialiasingHint(painter); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) - painter->drawPolygon(QPolygonF(lines)); - - // draw curve line: - if (mLineStyle != lsNone) - { - painter->setPen(finalCurvePen); - painter->setBrush(Qt::NoBrush); - drawCurveLine(painter, lines); - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - Draws lines between the points in \a lines, given in pixel coordinates. - - \see drawScatterPlot, getCurveLines -*/ -void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawCurveLine, getCurveLines -*/ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const -{ - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const -{ - if (!lines) return; - lines->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // add margins to rect to compensate for stroke width - const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety - const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); - const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); - const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); - const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); - QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); - if (itBegin == itEnd) - return; - QCPCurveDataContainer::const_iterator it = itBegin; - QCPCurveDataContainer::const_iterator prevIt = itEnd-1; - int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); - QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) - while (it != itEnd) - { - const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); - if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R - { - if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal - { - QPointF crossA, crossB; - if (prevRegion == 5) // we're coming from R, so add this point optimized - { - lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); - // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } else if (mayTraverse(prevRegion, currentRegion) && - getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) - { - // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: - QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; - getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); - if (it != itBegin) - { - *lines << beforeTraverseCornerPoints; - lines->append(crossA); - lines->append(crossB); - *lines << afterTraverseCornerPoints; - } else - { - lines->append(crossB); - *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA ; - } - } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) - { - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } - } else // segment does end in R, so we add previous point optimized and this point at original position - { - if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end - trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - else - lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); - lines->append(coordsToPixels(it->key, it->value)); - } - } else // region didn't change - { - if (currentRegion == 5) // still in R, keep adding original points - { - lines->append(coordsToPixels(it->key, it->value)); - } else // still outside R, no need to add anything - { - // see how this is not doing anything? That's the main optimization... - } - } - prevIt = it; - prevRegion = currentRegion; - ++it; - } - *lines << trailingPoints; -} - -/*! \internal - - Called by \ref draw to generate points in pixel coordinates which represent the scatters of the - curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly - sparser. - - Scatters that aren't visible in the current axis rect are optimized away. - - \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref - drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. - - \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel - coordinates generated by this function. This is needed here to calculate an accordingly wider - margin around the axis rect when performing the data point reduction. - - \see draw, drawScatterPlot -*/ -void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const -{ - if (!scatters) return; - scatters->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); - if (begin == end) - return; - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int endIndex = end-mDataContainer->constBegin(); - - QCPRange keyRange = keyAxis->range(); - QCPRange valueRange = valueAxis->range(); - // extend range to include width of scatter symbols: - keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); - keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); - valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); - valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); - - QCPCurveDataContainer::const_iterator it = begin; - int itIndex = begin-mDataContainer->constBegin(); - while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++itIndex; - ++it; - } - if (keyAxis->orientation() == Qt::Vertical) - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } else - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - It returns the region of the given point (\a key, \a value) with respect to a rectangle defined - by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. - - The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a - keyMin to \a keyMax): - - - - - -
147
258
369
- - With the rectangle being region 5, and the outer regions extending infinitely outwards. In the - curve optimization algorithm, region 5 is considered to be the visible portion of the plot. -*/ -int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - if (key < keyMin) // region 123 - { - if (value > valueMax) - return 1; - else if (value < valueMin) - return 3; - else - return 2; - } else if (key > keyMax) // region 789 - { - if (value > valueMax) - return 7; - else if (value < valueMin) - return 9; - else - return 8; - } else // region 456 - { - if (value > valueMax) - return 4; - else if (value < valueMin) - return 6; - else - return 5; - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method is used in case the current segment passes from inside the visible rect (region 5, - see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by - the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). - - It returns the intersection point of the segment with the border of region 5. - - For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or - whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or - leaving it. It is important though that \a otherRegion correctly identifies the other region not - equal to 5. -*/ -QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double otherValuePx = mValueAxis->coordToPixel(otherValue); - const double valuePx = mValueAxis->coordToPixel(value); - const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); - const double keyPx = mKeyAxis->coordToPixel(key); - double intersectKeyPx = keyMinPx; // initial key just a fail-safe - double intersectValuePx = valueMinPx; // initial value just a fail-safe - switch (otherRegion) - { - case 1: // top and left edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 2: // left edge - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 3: // bottom and left edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 4: // top edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 5: - { - break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table - } - case 6: // bottom edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 7: // top and right edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 8: // right edge - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 9: // bottom and right edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - } - if (mKeyAxis->orientation() == Qt::Horizontal) - return QPointF(intersectKeyPx, intersectValuePx); - else - return QPointF(intersectValuePx, intersectKeyPx); -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - In situations where a single segment skips over multiple regions it might become necessary to add - extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment - doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. - This method provides these points that must be added, assuming the original segment doesn't - start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by - \ref getTraverseCornerPoints.) - - For example, consider a segment which directly goes from region 4 to 2 but originally is far out - to the top left such that it doesn't cross region 5. Naively optimizing these points by - projecting them on the top and left borders of region 5 will create a segment that surely crosses - 5, creating a visual artifact in the plot. This method prevents this by providing extra points at - the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without - traversing 5. -*/ -QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - QVector result; - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMax); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } - case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - else - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - break; - } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMin); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); break; } - case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - else - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - break; - } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 6: - { - switch (currentRegion) - { - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 4: { result << coordsToPixels(keyMax, valueMax); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); break; } - case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - else - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - break; - } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 6: { result << coordsToPixels(keyMax, valueMin); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - else - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - break; - } - } - break; - } - } - return result; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref - getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion - nor \a currentRegion is 5 itself. - - If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the - segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref - getTraverse). -*/ -bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 4: - case 7: - case 2: - case 3: return false; - default: return true; - } - } - case 2: - { - switch (currentRegion) - { - case 1: - case 3: return false; - default: return true; - } - } - case 3: - { - switch (currentRegion) - { - case 1: - case 2: - case 6: - case 9: return false; - default: return true; - } - } - case 4: - { - switch (currentRegion) - { - case 1: - case 7: return false; - default: return true; - } - } - case 5: return false; // should never occur - case 6: - { - switch (currentRegion) - { - case 3: - case 9: return false; - default: return true; - } - } - case 7: - { - switch (currentRegion) - { - case 1: - case 4: - case 8: - case 9: return false; - default: return true; - } - } - case 8: - { - switch (currentRegion) - { - case 7: - case 9: return false; - default: return true; - } - } - case 9: - { - switch (currentRegion) - { - case 3: - case 6: - case 8: - case 7: return false; - default: return true; - } - } - default: return true; - } -} - - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref mayTraverse test has returned true, so there is a chance the - segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible - region 5. - - The return value of this method indicates whether the segment actually traverses region 5 or not. - - If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and - exit points of region 5. They will become the optimized points for that segment. -*/ -bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - QList intersections; - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double keyPx = mKeyAxis->coordToPixel(key); - const double valuePx = mValueAxis->coordToPixel(value); - const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); - const double prevValuePx = mValueAxis->coordToPixel(prevValue); - if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); - } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); - } else // line is skewed - { - double gamma; - double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); - // check top of rect: - gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); - // check bottom of rect: - gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); - const double valuePerKeyPx = 1.0/keyPerValuePx; - // check left of rect: - gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); - // check right of rect: - gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); - } - - // handle cases where found points isn't exactly 2: - if (intersections.size() > 2) - { - // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: - double distSqrMax = 0; - QPointF pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = intersections.at(i); - pv2 = intersections.at(k); - distSqrMax = distSqr; - } - } - } - intersections = QList() << pv1 << pv2; - } else if (intersections.size() != 2) - { - // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment - return false; - } - - // possibly re-sort points so optimized point segment has same direction as original segment: - double xDelta = keyPx-prevKeyPx; - double yDelta = valuePx-prevValuePx; - if (mKeyAxis->orientation() != Qt::Horizontal) - qSwap(xDelta, yDelta); - if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction - intersections.move(0, 1); - crossA = intersections.at(0); - crossB = intersections.at(1); - return true; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref getTraverse test has returned true, so the segment definitely - traverses the visible region 5 when going from \a prevRegion to \a currentRegion. - - In certain situations it is not sufficient to merely generate the entry and exit points of the - segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in - addition to traversing region 5, skips another region outside of region 5, which makes it - necessary to add an optimized corner point there (very similar to the job \ref - getOptimizedCornerPoints does for segments that are completely in outside regions and don't - traverse 5). - - As an example, consider a segment going from region 1 to region 6, traversing the lower left - corner of region 5. In this configuration, the segment additionally crosses the border between - region 1 and 2 before entering region 5. This makes it necessary to add an additional point in - the top left corner, before adding the optimized traverse points. So in this case, the output - parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be - empty. - - In some cases, such as when going from region 1 to 9, it may even be necessary to add additional - corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse - return the respective corner points. -*/ -void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: { break; } // shouldn't happen because this method only handles full traverses - case 6: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - } -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in - \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that - if the curve has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the curve line is also taken into account. - - If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns - -1.0. -*/ -double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - if (mDataContainer->size() == 1) - { - QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); - closestData = mDataContainer->constBegin(); - return QCPVector2D(dataPoint-pixelPoint).length(); - } - - // calculate minimum distances to curve data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - QVector lines; - getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width - for (int i=0; i QCPBarsGroup::bars() const - - Returns all bars currently in this group. - - \see bars(int index) -*/ - -/*! \fn int QCPBarsGroup::size() const - - Returns the number of QCPBars plottables that are part of this group. - -*/ - -/*! \fn bool QCPBarsGroup::isEmpty() const - - Returns whether this bars group is empty. - - \see size -*/ - -/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) - - Returns whether the specified \a bars plottable is part of this group. - -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new bars group for the specified QCustomPlot instance. -*/ -QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot), - mSpacingType(stAbsolute), - mSpacing(4) -{ -} - -QCPBarsGroup::~QCPBarsGroup() -{ - clear(); -} - -/*! - Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. - - The actual spacing can then be specified with \ref setSpacing. - - \see setSpacing -*/ -void QCPBarsGroup::setSpacingType(SpacingType spacingType) -{ - mSpacingType = spacingType; -} - -/*! - Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is - defined by the current \ref SpacingType, which can be set with \ref setSpacingType. - - \see setSpacingType -*/ -void QCPBarsGroup::setSpacing(double spacing) -{ - mSpacing = spacing; -} - -/*! - Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars - exists, returns 0. - - \see bars(), size -*/ -QCPBars *QCPBarsGroup::bars(int index) const -{ - if (index >= 0 && index < mBars.size()) - { - return mBars.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Removes all QCPBars plottables from this group. - - \see isEmpty -*/ -void QCPBarsGroup::clear() -{ - Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay - bars->setBarsGroup(0); // removes itself via removeBars -} - -/*! - Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref - QCPBars::setBarsGroup on the \a bars instance. - - \see insert, remove -*/ -void QCPBarsGroup::append(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - else - qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); -} - -/*! - Inserts the specified \a bars plottable into this group at the specified index position \a i. - This gives you full control over the ordering of the bars. - - \a bars may already be part of this group. In that case, \a bars is just moved to the new index - position. - - \see append, remove -*/ -void QCPBarsGroup::insert(int i, QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - // first append to bars list normally: - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - // then move to according position: - mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); -} - -/*! - Removes the specified \a bars plottable from this group. - - \see contains, clear -*/ -void QCPBarsGroup::remove(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (mBars.contains(bars)) - bars->setBarsGroup(0); - else - qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); -} - -/*! \internal - - Adds the specified \a bars to the internal mBars list of bars. This method does not change the - barsGroup property on \a bars. - - \see unregisterBars -*/ -void QCPBarsGroup::registerBars(QCPBars *bars) -{ - if (!mBars.contains(bars)) - mBars.append(bars); -} - -/*! \internal - - Removes the specified \a bars from the internal mBars list of bars. This method does not change - the barsGroup property on \a bars. - - \see registerBars -*/ -void QCPBarsGroup::unregisterBars(QCPBars *bars) -{ - mBars.removeOne(bars); -} - -/*! \internal - - Returns the pixel offset in the key dimension the specified \a bars plottable should have at the - given key coordinate \a keyCoord. The offset is relative to the pixel position of the key - coordinate \a keyCoord. -*/ -double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) -{ - // find list of all base bars in case some mBars are stacked: - QList baseBars; - Q_FOREACH (const QCPBars *b, mBars) - { - while (b->barBelow()) - b = b->barBelow(); - if (!baseBars.contains(b)) - baseBars.append(b); - } - // find base bar this "bars" is stacked on: - const QCPBars *thisBase = bars; - while (thisBase->barBelow()) - thisBase = thisBase->barBelow(); - - // determine key pixel offset of this base bars considering all other base bars in this barsgroup: - double result = 0; - int index = baseBars.indexOf(thisBase); - if (index >= 0) - { - if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) - { - return result; - } else - { - double lowerPixelWidth, upperPixelWidth; - int startIndex; - int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative - if (baseBars.size() % 2 == 0) // even number of bars - { - startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); - result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing - } else // uneven number of bars - { - startIndex = (baseBars.size()-1)/2+dir; - baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar - result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing - } - for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars - { - baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth); - result += getPixelSpacing(baseBars.at(i), keyCoord); - } - // finally half of our bars width: - baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; - // correct sign of result depending on orientation and direction of key axis: - result *= dir*thisBase->keyAxis()->pixelOrientation(); - } - } - return result; -} - -/*! \internal - - Returns the spacing in pixels which is between this \a bars and the following one, both at the - key coordinate \a keyCoord. - - \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only - needed to get access to the key axis transformation and axis rect for the modes \ref - stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in - \ref stPlotCoords on a logarithmic axis. -*/ -double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) -{ - switch (mSpacingType) - { - case stAbsolute: - { - return mSpacing; - } - case stAxisRectRatio: - { - if (bars->keyAxis()->orientation() == Qt::Horizontal) - return bars->keyAxis()->axisRect()->width()*mSpacing; - else - return bars->keyAxis()->axisRect()->height()*mSpacing; - } - case stPlotCoords: - { - double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); - return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); - } - } - return 0; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBarsData - \brief Holds the data of one single data point (one bar) for QCPBars. - - The stored data is: - \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) - \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPBarsDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPBarsData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPBarsData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a bar data point with key and value set to zero. -*/ -QCPBarsData::QCPBarsData() : - key(0), - value(0) -{ -} - -/*! - Constructs a bar data point with the specified \a key and \a value. -*/ -QCPBarsData::QCPBarsData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBars - \brief A plottable representing a bar chart in a plot. - - \image html QCPBars.png - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section qcpbars-appearance Changing the appearance - - The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). - The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. - - Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other - (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear - stacked. - - If you would like to group multiple QCPBars plottables together so they appear side by side as - shown below, use QCPBarsGroup. - - \image html QCPBarsGroup.png - - \section qcpbars-usage Usage - - Like all data representing objects in QCustomPlot, the QCPBars is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/*! \fn QCPBars *QCPBars::barBelow() const - Returns the bars plottable that is directly below this bars plottable. - If there is no such plottable, returns 0. - - \see barAbove, moveBelow, moveAbove -*/ - -/*! \fn QCPBars *QCPBars::barAbove() const - Returns the bars plottable that is directly above this bars plottable. - If there is no such plottable, returns 0. - - \see barBelow, moveBelow, moveAbove -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.75), - mWidthType(wtPlotCoords), - mBarsGroup(0), - mBaseValue(0), - mStackingGap(0) -{ - // modify inherited properties from abstract plottable: - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPBars::~QCPBars() -{ - setBarsGroup(0); - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. - Modifying the data in the container will then affect all bars that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the bar's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 - - \see addData -*/ -void QCPBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets the width of the bars. - - How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), - depends on the currently set width type, see \ref setWidthType and \ref WidthType. -*/ -void QCPBars::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the bars is defined. See the documentation of \ref WidthType for an - explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPBars::setWidthType(QCPBars::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref - QCPBarsGroup::append. - - To remove this QCPBars from any group, set \a barsGroup to 0. -*/ -void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) -{ - // deregister at old group: - if (mBarsGroup) - mBarsGroup->unregisterBars(this); - mBarsGroup = barsGroup; - // register at new group: - if (mBarsGroup) - mBarsGroup->registerBars(this); -} - -/*! - Sets the base value of this bars plottable. - - The base value defines where on the value coordinate the bars start. How far the bars extend from - the base value is given by their individual value data. For example, if the base value is set to - 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at - 3. - - For stacked bars, only the base value of the bottom-most QCPBars has meaning. - - The default base value is 0. -*/ -void QCPBars::setBaseValue(double baseValue) -{ - mBaseValue = baseValue; -} - -/*! - If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method - allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by - the bars below it. -*/ -void QCPBars::setStackingGap(double pixels) -{ - mStackingGap = pixels; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(double key, double value) -{ - mDataContainer->add(QCPBarsData(key, value)); -} - -/*! - Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear - below the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barAbove, barBelow -*/ -void QCPBars::moveBelow(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar below it: - if (bars) - { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); - } -} - -/*! - Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear - above the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object above itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barBelow, barAbove -*/ -void QCPBars::moveAbove(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar above it: - if (bars) - { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getBarRect(it->key, it->value))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getBarRect(it->key, it->value).contains(pos)) - { - if (details) - { - int pointIndex = it-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return mParentPlot->selectionTolerance()*0.99; - } - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in - absolute pixels), using this method to adapt the key axis range to fit the bars into the - currently visible axis range will not work perfectly. Because in the moment the axis range is - changed to the new range, the fixed pixel widths/spacings will represent different coordinate - spans than before, which in turn would require a different key range to perfectly fit, and so on. - The only solution would be to iteratively approach the perfect fitting axis range, but the - mismatch isn't large enough in most applications, to warrant this here. If a user does need a - better fit, he should call the corresponding axis rescale multiple times in a row. - */ - QCPRange range; - range = mDataContainer->keyRange(foundRange, inSignDomain); - - // determine exact range of bars by including bar width and barsgroup offset: - if (foundRange && mKeyAxis) - { - double lowerPixelWidth, upperPixelWidth, keyPixel; - // lower range bound: - getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); - const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) - range.lower = lowerCorrected; - // upper range bound: - getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); - const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) - range.upper = upperCorrected; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - // Note: can't simply use mDataContainer->valueRange here because we need to - // take into account bar base value and possible stacking of multiple bars - QCPRange range; - range.lower = mBaseValue; - range.upper = mBaseValue; - bool haveLower = true; // set to true, because baseValue should always be visible in bar charts - bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts - QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (inKeyRange != QCPRange()) - { - itBegin = mDataContainer->findBegin(inKeyRange.lower); - itEnd = mDataContainer->findEnd(inKeyRange.upper); - } - for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - - foundRange = true; // return true because bar charts always have the 0-line visible - return range; -} - -/* inherits documentation from base class */ -QPointF QCPBars::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); - const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyPixel, valuePixel); - else - return QPointF(valuePixel, keyPixel); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mDataContainer->isEmpty()) return; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPBarsDataContainer::const_iterator begin = visibleBegin; - QCPBarsDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -#endif - // draw bar: - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyBrush(painter); - mSelectionDecorator->applyPen(painter); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - } - applyDefaultAntialiasingHint(painter); - painter->drawPolygon(getBarRect(it->key, it->value)); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - if (mDataContainer->isEmpty()) - { - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - - // get visible data range as QMap iterators - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); - double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); - double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); - bool isVisible = false; - // walk left from begin to find lower bar that actually is completely outside visible pixel range: - QCPBarsDataContainer::const_iterator it = begin; - while (it != mDataContainer->constBegin()) - { - --it; - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); - if (isVisible) - begin = it; - else - break; - } - // walk right from ubound to find upper bar that actually is completely outside visible pixel range: - it = end; - while (it != mDataContainer->constEnd()) - { - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); - if (isVisible) - end = it+1; - else - break; - ++it; - } -} - -/*! \internal - - Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The - rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref - setBaseValue), and to have non-overlapping border lines with the bars stacked below. -*/ -QRectF QCPBars::getBarRect(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double lowerPixelWidth, upperPixelWidth; - getPixelWidth(key, lowerPixelWidth, upperPixelWidth); - double base = getStackedBaseValue(key, value >= 0); - double basePixel = valueAxis->coordToPixel(base); - double valuePixel = valueAxis->coordToPixel(base+value); - double keyPixel = keyAxis->coordToPixel(key); - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, key); - double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); - bottomOffset += mBarBelow ? mStackingGap : 0; - bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); - if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) - bottomOffset = valuePixel-basePixel; - if (keyAxis->orientation() == Qt::Horizontal) - { - return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); - } else - { - return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). - - The output parameters \a lower and \a upper return the number of pixels the bar extends to lower - and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a - lower is negative and \a upper positive). -*/ -void QCPBars::getPixelWidth(double key, double &lower, double &upper) const -{ - lower = 0; - upper = 0; - switch (mWidthType) - { - case wtAbsolute: - { - upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - { - double keyPixel = mKeyAxis.data()->coordToPixel(key); - upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; - // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by - // coordinate transform which includes range direction - } else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } -} - -/*! \internal - - This function is called to find at which value to start drawing the base of a bar at \a key, when - it is stacked on top of another QCPBars (e.g. with \ref moveAbove). - - positive and negative bars are separated per stack (positive are stacked above baseValue upwards, - negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the - bar for which we need the base value is negative, set \a positive to false. -*/ -double QCPBars::getStackedBaseValue(double key, bool positive) const -{ - if (mBarBelow) - { - double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack - // find bars of mBarBelow that are approximately at key and find largest one: - double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point - if (key == 0) - epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); - QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); - QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); - while (it != itEnd) - { - if (it->key > key-epsilon && it->key < key+epsilon) - { - if ((positive && it->value > max) || - (!positive && it->value < max)) - max = it->value; - } - ++it; - } - // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getStackedBaseValue(key, positive); - } else - return mBaseValue; -} - -/*! \internal - - Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) - currently above lower and below upper will become disconnected to lower/upper. - - If lower is zero, upper will be disconnected at the bottom. - If upper is zero, lower will be disconnected at the top. -*/ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) -{ - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom - { - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - lower->mBarAbove = 0; - } else // connect lower and upper - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - lower->mBarAbove = upper; - upper->mBarBelow = lower; - } -} -/* end of 'src/plottables/plottable-bars.cpp' */ - - -/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBoxData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBoxData - \brief Holds the data of one single data point for QCPStatisticalBox. - - The stored data is: - - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - - \li \a minimum: the position of the lower whisker, typically the minimum measurement of the - sample that's not considered an outlier. - - \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a median: the value of the median mark inside the quartile box. The median separates the - sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) - - \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a maximum: the position of the upper whisker, typically the maximum measurement of the - sample that's not considered an outlier. - - \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key - coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) - - The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a - typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template - parameter. See the documentation there for an explanation regarding the data type's generic - methods. - - \see QCPStatisticalBoxDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPStatisticalBoxData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainValue() const - - Returns the \a median member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const - - Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box - data point, possibly further expanded by outliers. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData() : - key(0), - minimum(0), - lowerQuartile(0), - median(0), - upperQuartile(0), - maximum(0) -{ -} - -/*! - Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a - upperQuartile, \a maximum and optionally a number of \a outliers. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : - key(key), - minimum(minimum), - lowerQuartile(lowerQuartile), - median(median), - upperQuartile(upperQuartile), - maximum(maximum), - outliers(outliers) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBox -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBox - \brief A plottable representing a single statistical box in a plot. - - \image html QCPStatisticalBox.png - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPStatisticalBoxDataContainer. - - Additionally each data point can itself have a list of outliers, drawn as scatter points at the - key coordinate of the respective statistical box data point. They can either be set by using the - respective \ref addData(double,double,double,double,double,double,const QVector&) - "addData" method or accessing the individual data points through \ref data, and setting the - QVector outliers of the data points directly. - - \section qcpstatisticalbox-appearance Changing the appearance - - The appearance of each data point box, ranging from the lower to the upper quartile, is - controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref - setWidth in plot coordinates. - - Each data point's visual representation also consists of two whiskers. Whiskers are the lines - which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. - The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, - \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at - the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set - the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a - few pixels due to the pen cap being not perfectly flat. - - The median indicator line inside the box has its own pen, \ref setMedianPen. - - The outlier data points are drawn as normal scatter points. Their look can be controlled with - \ref setOutlierStyle - - \section qcpstatisticalbox-usage Usage - - Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 -*/ - -/* start documentation of inline functions */ - -/*! \fn QSharedPointer QCPStatisticalBox::data() const - - Returns a shared pointer to the internal data storage of type \ref - QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more - convenient and faster than using the regular \ref setData or \ref addData methods. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its - value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and - not have the same orientation. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not - delete it manually but use QCustomPlot::removePlottable() instead. -*/ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.5), - mWhiskerWidth(0.2), - mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), - mWhiskerBarPen(Qt::black), - mWhiskerAntialiased(false), - mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), - mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) -{ - setPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container - safely. Modifying the data in the container will then affect all statistical boxes that share the - container. Sharing can be achieved by simply exchanging the data containers wrapped in shared - pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the statistical box data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 - - \see addData -*/ -void QCPStatisticalBox::setData(QSharedPointer data) -{ - mDataContainer = data; -} -/*! \overload - - Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a - median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the - number of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); -} - -/*! - Sets the width of the boxes in key coordinates. - - \see setWhiskerWidth -*/ -void QCPStatisticalBox::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the width of the whiskers in key coordinates. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWidth -*/ -void QCPStatisticalBox::setWhiskerWidth(double width) -{ - mWhiskerWidth = width; -} - -/*! - Sets the pen used for drawing the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone - line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. - - \see setWhiskerBarPen -*/ -void QCPStatisticalBox::setWhiskerPen(const QPen &pen) -{ - mWhiskerPen = pen; -} - -/*! - Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at - each end of the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWhiskerPen -*/ -void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) -{ - mWhiskerBarPen = pen; -} - -/*! - Sets whether the statistical boxes whiskers are drawn with antialiasing or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) -{ - mWhiskerAntialiased = enabled; -} - -/*! - Sets the pen used for drawing the median indicator line inside the statistical boxes. -*/ -void QCPStatisticalBox::setMedianPen(const QPen &pen) -{ - mMedianPen = pen; -} - -/*! - Sets the appearance of the outlier data points. - - Outliers can be specified with the method - \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -*/ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) -{ - mOutlierStyle = style; -} - -/*! \overload - - Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and - \a maximum to the current data. The provided vectors should have equal length. Else, the number - of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || - median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" - << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); - const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->minimum = minimum[i]; - it->lowerQuartile = lowerQuartile[i]; - it->median = median[i]; - it->upperQuartile = upperQuartile[i]; - it->maximum = maximum[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile - and \a maximum to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -{ - mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getQuartileBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - double minDistSqr = std::numeric_limits::max(); - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getQuartileBox(it).contains(pos)) // quartile box - { - double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } else // whiskers - { - const QVector whiskerBackbones(getWhiskerBackboneLines(it)); - for (int i=0; iconstBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return qSqrt(minDistSqr); - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; - QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -# ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->minimum) || - QCP::isInvalidData(it->lowerQuartile, it->median) || - QCP::isInvalidData(it->upperQuartile, it->maximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; ioutliers.size(); ++i) - if (QCP::isInvalidData(it->outliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -# endif - - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - QCPScatterStyle finalOutlierStyle = mOutlierStyle; - if (isSelectedSegment && mSelectionDecorator) - finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); - drawStatisticalBox(painter, it, finalOutlierStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! - Draws the graphical representation of a single statistical box with the data given by the - iterator \a it with the provided \a painter. - - If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. - - \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const -{ - // draw quartile box: - applyDefaultAntialiasingHint(painter); - const QRectF quartileBox = getQuartileBox(it); - painter->drawRect(quartileBox); - // draw median line with cliprect set to quartile box: - painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - painter->setPen(mMedianPen); - painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); - painter->restore(); - // draw whisker lines: - applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); - painter->setPen(mWhiskerPen); - painter->drawLines(getWhiskerBackboneLines(it)); - painter->setPen(mWhiskerBarPen); - painter->drawLines(getWhiskerBarLines(it)); - // draw outliers: - applyScattersAntialiasingHint(painter); - outlierStyle.applyTo(painter, mPen); - for (int i=0; ioutliers.size(); ++i) - outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points -} - -/*! \internal - - Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the - value range from the lower to the upper quartile, of the data given by \a it. - - \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QRectF result; - result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); - result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); - return result; -} - -/*! \internal - - Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value - range from the minimum to the lower quartile, and from the upper quartile to the maximum of the - data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines -*/ -QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone - result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone - return result; -} - -/*! \internal - - Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the - end of the whisker backbones, at the minimum and maximum of the data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines -*/ -QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar - result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar - return result; -} -/* end of 'src/plottables/plottable-statisticalbox.cpp' */ - - -/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMapData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMapData - \brief Holds the two-dimensional data of a QCPColorMap plottable. - - This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref - QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a - color, depending on the value. - - The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). - Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref - setKeyRange, \ref setValueRange). - - The data cells can be accessed in two ways: They can be directly addressed by an integer index - with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot - coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are - provided by the functions \ref coordToCell and \ref cellToCoord. - - A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if - allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref - fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on - the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. - - This class also buffers the minimum and maximum values that are in the data set, to provide - QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value - that is greater than the current maximum increases this maximum to the new value. However, - setting the cell that currently holds the maximum value to a smaller value doesn't decrease the - maximum again, because finding the true new maximum would require going through the entire data - array, which might be time consuming. The same holds for the data minimum. This functionality is - given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the - true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience - parameter \a recalculateDataBounds which may be set to true to automatically call \ref - recalculateDataBounds internally. -*/ - -/* start of documentation of inline functions */ - -/*! \fn bool QCPColorMapData::isEmpty() const - - Returns whether this instance carries no data. This is equivalent to having a size where at least - one of the dimensions is 0 (see \ref setSize). -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction - and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap - at the coordinates \a keyRange and \a valueRange. - - \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange -*/ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - setSize(keySize, valueSize); - fill(0); -} - -QCPColorMapData::~QCPColorMapData() -{ - if (mData) - delete[] mData; - if (mAlpha) - delete[] mAlpha; -} - -/*! - Constructs a new QCPColorMapData instance copying the data and range of \a other. -*/ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - *this = other; -} - -/*! - Overwrites this color map data instance with the data stored in \a other. The alpha map state is - transferred, too. -*/ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) -{ - if (&other != this) - { - const int keySize = other.keySize(); - const int valueSize = other.valueSize(); - if (!other.mAlpha && mAlpha) - clearAlpha(); - setSize(keySize, valueSize); - if (other.mAlpha && !mAlpha) - createAlpha(false); - setRange(other.keyRange(), other.valueRange()); - if (!isEmpty()) - { - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - if (mAlpha) - memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); - } - mDataBounds = other.mDataBounds; - mDataModified = true; - } - return *this; -} - -/* undocumented getter */ -double QCPColorMapData::data(double key, double value) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; - else - return 0; -} - -/* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; - else - return 0; -} - -/*! - Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. - - If this color map data doesn't have an alpha map (because \ref setAlpha was never called after - creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. - - \see setAlpha -*/ -unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) -{ - if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mAlpha[valueIndex*mKeySize + keyIndex]; - else - return 255; -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in - the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref - isEmpty returns true. - - \see setRange, setKeySize, setValueSize -*/ -void QCPColorMapData::setSize(int keySize, int valueSize) -{ - if (keySize != mKeySize || valueSize != mValueSize) - { - mKeySize = keySize; - mValueSize = valueSize; - if (mData) - delete[] mData; - mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) - { -#ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message -#endif - mData = new double[mKeySize*mValueSize]; -#ifdef __EXCEPTIONS - } catch (...) { mData = 0; } -#endif - if (mData) - fill(0); - else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else - mData = 0; - - if (mAlpha) // if we had an alpha map, recreate it with new size - createAlpha(); - - mDataModified = true; - } -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. - - \see setKeyRange, setSize, setValueSize -*/ -void QCPColorMapData::setKeySize(int keySize) -{ - setSize(keySize, mValueSize); -} - -/*! - Resizes the data array to have \a valueSize cells in the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. - - \see setValueRange, setSize, setKeySize -*/ -void QCPColorMapData::setValueSize(int valueSize) -{ - setSize(mKeySize, valueSize); -} - -/*! - Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area - covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setSize -*/ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) -{ - setKeyRange(keyRange); - setValueRange(valueRange); -} - -/*! - Sets the coordinate range the data shall be distributed over in the key dimension. Together with - the value range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setRange, setValueRange, setSize -*/ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) -{ - mKeyRange = keyRange; -} - -/*! - Sets the coordinate range the data shall be distributed over in the value dimension. Together with - the key range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there - will be cells centered on the value coordinates 2, 2.5 and 3. - - \see setRange, setKeyRange, setSize -*/ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) -{ - mValueRange = valueRange; -} - -/*! - Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a - z. - - \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or - value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, - you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to - determine the cell index. Rather directly access the cell index with \ref - QCPColorMapData::setCell. - - \see setCell, setRange -*/ -void QCPColorMapData::setData(double key, double value, double z) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices - enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see - \ref setSize). - - In the standard plot configuration (horizontal key axis and vertical value axis, both not - range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with - indices (keySize-1, valueSize-1) is in the top right corner of the color map. - - \see setData, setSize -*/ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value - of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully - opaque cell. - - If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish - to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. - - Note that the cell-wise alpha which can be configured here is independent of any alpha configured - in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise - and gradient alpha, the alpha values will be blended accordingly during rendering of the color - map. - - \see fillAlpha, clearAlpha -*/ -void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - if (mAlpha || createAlpha()) - { - mAlpha[valueIndex*mKeySize + keyIndex] = alpha; - mDataModified = true; - } - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Goes through the data and updates the buffered minimum and maximum data values. - - Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange - and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten - with a smaller or larger value respectively, since the buffered maximum/minimum values have been - updated the last time. Why this is the case is explained in the class description (\ref - QCPColorMapData). - - Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a - recalculateDataBounds for convenience. Setting this to true will call this method for you, before - doing the rescale. -*/ -void QCPColorMapData::recalculateDataBounds() -{ - if (mKeySize > 0 && mValueSize > 0) - { - double minHeight = mData[0]; - double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i maxHeight) - maxHeight = mData[i]; - if (mData[i] < minHeight) - minHeight = mData[i]; - } - mDataBounds.lower = minHeight; - mDataBounds.upper = maxHeight; - } -} - -/*! - Frees the internal data memory. - - This is equivalent to calling \ref setSize "setSize(0, 0)". -*/ -void QCPColorMapData::clear() -{ - setSize(0, 0); -} - -/*! - Frees the internal alpha map. The color map will have full opacity again. -*/ -void QCPColorMapData::clearAlpha() -{ - if (mAlpha) - { - delete[] mAlpha; - mAlpha = 0; - mDataModified = true; - } -} - -/*! - Sets all cells to the value \a z. -*/ -void QCPColorMapData::fill(double z) -{ - const int dataCount = mValueSize*mKeySize; - for (int i=0; i(data); - return; - } - if (copy) - { - *mMapData = *data; - } else - { - delete mMapData; - mMapData = data; - } - mMapImageInvalidated = true; -} - -/*! - Sets the data range of this color map to \a dataRange. The data range defines which data values - are mapped to the color gradient. - - To make the data range span the full range of the data set, use \ref rescaleDataRange. - - \see QCPColorScale::setDataRange -*/ -void QCPColorMap::setDataRange(const QCPRange &dataRange) -{ - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - if (mDataScaleType == QCPAxis::stLogarithmic) - mDataRange = dataRange.sanitizedForLogScale(); - else - mDataRange = dataRange.sanitizedForLinScale(); - mMapImageInvalidated = true; - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets whether the data is correlated with the color gradient linearly or logarithmically. - - \see QCPColorScale::setDataScaleType -*/ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - mMapImageInvalidated = true; - Q_EMIT dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - } -} - -/*! - Sets the color gradient that is used to represent the data. For more details on how to create an - own gradient or use one of the preset gradients, see \ref QCPColorGradient. - - The colors defined by the gradient will be used to represent data values in the currently set - data range, see \ref setDataRange. Data points that are outside this data range will either be - colored uniformly with the respective gradient boundary color, or the gradient will repeat, - depending on \ref QCPColorGradient::setPeriodic. - - \see QCPColorScale::setGradient -*/ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - mMapImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets whether the color map image shall use bicubic interpolation when displaying the color map - shrinked or expanded, and not at a 1:1 pixel-to-data scale. - - \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" -*/ -void QCPColorMap::setInterpolate(bool enabled) -{ - mInterpolate = enabled; - mMapImageInvalidated = true; // because oversampling factors might need to change -} - -/*! - Sets whether the outer most data rows and columns are clipped to the specified key and value - range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). - - if \a enabled is set to false, the data points at the border of the color map are drawn with the - same width and height as all other data points. Since the data points are represented by - rectangles of one color centered on the data coordinate, this means that the shown color map - extends by half a data point over the specified key/value range in each direction. - - \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" -*/ -void QCPColorMap::setTightBoundary(bool enabled) -{ - mTightBoundary = enabled; -} - -/*! - Associates the color scale \a colorScale with this color map. - - This means that both the color scale and the color map synchronize their gradient, data range and - data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps - can be associated with one single color scale. This causes the color maps to also synchronize - those properties, via the mutual color scale. - - This function causes the color map to adopt the current color gradient, data range and data scale - type of \a colorScale. After this call, you may change these properties at either the color map - or the color scale, and the setting will be applied to both. - - Pass 0 as \a colorScale to disconnect the color scale from this color map again. -*/ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) -{ - if (mColorScale) // unconnect signals from old color scale - { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale - { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } -} - -/*! - Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the - current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, - only for the third data dimension of the color map. - - The minimum and maximum values of the data set are buffered in the internal QCPColorMapData - instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref - QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For - performance reasons, however, they are only updated in an expanding fashion. So the buffered - maximum can only increase and the buffered minimum can only decrease. In consequence, changes to - the data that actually lower the maximum of the data set (by overwriting the cell holding the - current maximum with a smaller value), aren't recognized and the buffered maximum overestimates - the true maximum of the data set. The same happens for the buffered minimum. To recalculate the - true minimum and maximum by explicitly looking at each cell, the method - QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a - recalculateDataBounds calls this method before setting the data range to the buffered minimum and - maximum. - - \see setDataRange -*/ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) -{ - if (recalculateDataBounds) - mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); -} - -/*! - Takes the current appearance of the color map and updates the legend icon, which is used to - represent this color map in the legend (see \ref QCPLegend). - - The \a transformMode specifies whether the rescaling is done by a faster, low quality image - scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm - (Qt::SmoothTransformation). - - The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to - the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured - legend icon size, the thumb will be rescaled during drawing of the legend item. - - \see setDataRange -*/ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) -{ - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again - { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); - } -} - -/* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) - { - if (details) - details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. - return mParentPlot->selectionTolerance()*0.99; - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->keyRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (inKeyRange != QCPRange()) - { - if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) - { - foundRange = false; - return QCPRange(); - } - } - - foundRange = true; - QCPRange result = mMapData->valueRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/*! \internal - - Updates the internal map image buffer by going through the internal \ref QCPColorMapData and - turning the data values into color pixels with \ref QCPColorGradient::colorize. - - This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image - has been invalidated for a different reason (e.g. a change of the data range with \ref - setDataRange). - - If the map cell count is low, the image created will be oversampled in order to avoid a - QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images - without smooth transform enabled. Accordingly, oversampling isn't performed if \ref - setInterpolate is true. -*/ -void QCPColorMap::updateMapImage() -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - if (mMapData->isEmpty()) return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - const int keySize = mMapData->keySize(); - const int valueSize = mMapData->valueSize(); - int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - - // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) - mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) - mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); - - if (mMapImage.isNull()) - { - qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; - mMapImage = QImage(QSize(10, 10), format); - mMapImage.fill(Qt::black); - } else - { - QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - // resize undersampled map image to actual key/value cell sizes: - if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) - mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); - else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) - mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); - localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image - } else if (!mUndersampledMapImage.isNull()) - mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it - - const double *rawData = mMapData->mData; - const unsigned char *rawAlpha = mMapData->mAlpha; - if (keyAxis->orientation() == Qt::Horizontal) - { - const int lineCount = valueSize; - const int rowCount = keySize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - } - } else // keyAxis->orientation() == Qt::Vertical - { - const int lineCount = keySize; - const int rowCount = valueSize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - } - } - - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - if (keyAxis->orientation() == Qt::Horizontal) - mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - else - mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - } - } - mMapData->mDataModified = false; - mMapImageInvalidated = false; -} - -/* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) -{ - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) - updateMapImage(); - - // use buffer if painting vectorized (PDF): - const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); - QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized - QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in - QPixmap mapBuffer; - if (useBuffer) - { - const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps - mapBufferTarget = painter->clipRegion().boundingRect(); - mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); - mapBuffer.fill(Qt::transparent); - localPainter = new QCPPainter(&mapBuffer); - localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); - localPainter->translate(-mapBufferTarget.topLeft()); - } - - QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): - double halfCellWidth = 0; // in pixels - double halfCellHeight = 0; // in pixels - if (keyAxis()->orientation() == Qt::Horizontal) - { - if (mMapData->keySize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); - } else // keyAxis orientation is Qt::Vertical - { - if (mMapData->keySize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); - } - imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); - const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); - QRegion clipBackup; - if (mTightBoundary) - { - clipBackup = localPainter->clipRegion(); - QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - localPainter->setClipRect(tightClipRect, Qt::IntersectClip); - } - localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - localPainter->setClipRegion(clipBackup); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); - - if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter - { - delete localPainter; - painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); - } -} - -/* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - // draw map thumbnail: - if (!mLegendIcon.isNull()) - { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); - } - /* - // draw frame: - painter->setBrush(Qt::NoBrush); - painter->setPen(Qt::black); - painter->drawRect(rect.adjusted(1, 1, 0, 0)); - */ -} -/* end of 'src/plottables/plottable-colormap.cpp' */ - - -/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancialData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancialData - \brief Holds the data of one single data point for QCPFinancial. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a open: The opening value at the data point (this is the \a mainValue) - \li \a high: The high/maximum value at the data point - \li \a low: The low/minimum value at the data point - \li \a close: The closing value at the data point - - The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef - for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPFinancialDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPFinancialData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainValue() const - - Returns the \a open member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPFinancialData::valueRange() const - - Returns a QCPRange spanning from the \a low to the \a high value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPFinancialData::QCPFinancialData() : - key(0), - open(0), - high(0), - low(0), - close(0) -{ -} - -/*! - Constructs a data point with the specified \a key and OHLC values. -*/ -QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : - key(key), - open(open), - high(high), - low(low), - close(close) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancial -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancial - \brief A plottable representing a financial stock chart - - \image html QCPFinancial.png - - This plottable represents time series data binned to certain intervals, mainly used for stock - charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be - set via \ref setChartStyle. - - The data is passed via \ref setData as a set of open/high/low/close values at certain keys - (typically times). This means the data must be already binned appropriately. If data is only - available as a series of values (e.g. \a price against \a time), you can use the static - convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed - to \ref setData. - - The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref - setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and - the width to (or slightly less than) one time bin interval width. - - \section qcpfinancial-appearance Changing the appearance - - Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, - lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). - - If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are - represented with a different pen and brush than negative changes (\a close < \a open). These can - be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref - setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection - however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, - irrespective of whether the chart is single- or two-colored. - - \section qcpfinancial-usage Usage - - Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot - instance takes ownership of the plottable, so do not delete it manually but use - QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 - Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data - series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const - - Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods, in certain situations. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mChartStyle(csCandlestick), - mWidth(0.5), - mWidthType(wtPlotCoords), - mTwoColored(true), - mBrushPositive(QBrush(QColor(50, 160, 0))), - mBrushNegative(QBrush(QColor(180, 0, 15))), - mPenPositive(QPen(QColor(40, 150, 0))), - mPenNegative(QPen(QColor(170, 5, 5))) -{ - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPFinancial::~QCPFinancial() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. - Modifying the data in the container will then affect all financials that share the container. - Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the financial's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a - close. The provided vectors should have equal length. Else, the number of added points will be - the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, open, high, low, close, alreadySorted); -} - -/*! - Sets which representation style shall be used to display the OHLC data. -*/ -void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) -{ - mChartStyle = style; -} - -/*! - Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. - - A typical choice is to set it to (or slightly less than) one bin interval width. -*/ -void QCPFinancial::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for - an explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets whether this chart shall contrast positive from negative trends per data point by using two - separate colors to draw the respective bars/candlesticks. - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setTwoColored(bool twoColored) -{ - mTwoColored = twoColored; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushNegative, setPenPositive, setPenNegative -*/ -void QCPFinancial::setBrushPositive(const QBrush &brush) -{ - mBrushPositive = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushPositive, setPenNegative, setPenPositive -*/ -void QCPFinancial::setBrushNegative(const QBrush &brush) -{ - mBrushNegative = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setPenPositive(const QPen &pen) -{ - mPenPositive = pen; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setBrushNegative, setBrushPositive -*/ -void QCPFinancial::setPenNegative(const QPen &pen) -{ - mPenNegative = pen; -} - -/*! \overload - - Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. - The provided vectors should have equal length. Else, the number of added points will be the size - of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); - const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->open = open[i]; - it->high = high[i]; - it->low = low[i]; - it->close = close[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current - data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(double key, double open, double high, double low, double close) -{ - mDataContainer->add(QCPFinancialData(key, open, high, low, close)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(selectionHitBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - // perform select test according to configured style: - double result = -1; - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - case QCPFinancial::csCandlestick: - result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - } - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } - - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/*! - A convenience function that converts time series data (\a value against \a time) to OHLC binned - data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const - QCPFinancialDataContainer&). - - The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. - For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour - each, set \a timeBinSize to 3600. - - \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The - value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. - It merely defines the mathematical offset/phase of the bins that will be used to process the - data. -*/ -QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) -{ - QCPFinancialDataContainer data; - int count = qMin(time.size(), value.size()); - if (count == 0) - return QCPFinancialDataContainer(); - - QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); - int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); - for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); - if (i == count-1) // last data point is in current bin, finalize bin: - { - currentBinData.close = value.at(i); - currentBinData.key = timeBinOffset+(index)*timeBinSize; - data.add(currentBinData); - } - } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: - { - // finalize current bin: - currentBinData.close = value.at(i-1); - currentBinData.key = timeBinOffset+(index-1)*timeBinSize; - data.add(currentBinData); - // start next bin: - currentBinIndex = index; - currentBinData.open = value.at(i); - currentBinData.high = value.at(i); - currentBinData.low = value.at(i); - } - } - - return data; -} - -/* inherits documentation from base class */ -void QCPFinancial::draw(QCPPainter *painter) -{ - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPFinancialDataContainer::const_iterator begin = visibleBegin; - QCPFinancialDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - // draw data segment according to configured style: - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - drawOhlcPlot(painter, begin, end, isSelectedSegment); break; - case QCPFinancial::csCandlestick: - drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing - if (mChartStyle == csOhlc) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } - } else if (mChartStyle == csCandlestick) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. -*/ -void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); - // draw close: - painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); - } - } else - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); - // draw close: - painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. -*/ -void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - // draw low: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - // draw low: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); - } - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of - \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel - when this function is called). - - It returns the number of pixels the bar extends to higher keys, relative to the \a key - coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed - horizontal axis, the return value is negative. This is important so the open/close flags on the - \ref csOhlc bar are drawn to the correct side. -*/ -double QCPFinancial::getPixelWidth(double key, double keyPixel) const -{ - double result = 0; - switch (mWidthType) - { - case wtAbsolute: - { - if (mKeyAxis) - result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } - return result; -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a - end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - called by the drawing methods to determine which data (key) range is visible at the current key - axis range setting, so only that needs to be processed. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - begin may still be just outside the visible range. - - \a end returns the iterator just above the highest data point that needs to be taken into - account. Same as before, \a end may also lie just outside of the visible range - - if the plottable contains no data, both \a begin and \a end point to \c constEnd. -*/ -void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points -} - -/*! \internal - - Returns the hit box in pixel coordinates that will be used for data selection with the selection - rect (\ref selectTestRect), of the data point given by \a it. -*/ -QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double keyPixel = keyAxis->coordToPixel(it->key); - double highPixel = valueAxis->coordToPixel(it->high); - double lowPixel = valueAxis->coordToPixel(it->low); - double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); - if (keyAxis->orientation() == Qt::Horizontal) - return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); - else - return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); -} -/* end of 'src/plottables/plottable-financial.cpp' */ - - -/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBarsData - \brief Holds the data of one single error bar for QCPErrorBars. - - The stored data is: - \li \a errorMinus: how much the error bar extends towards negative coordinates from the data - point position - \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point - position - - The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a - typedef for QVector<\ref QCPErrorBarsData>. - - \see QCPErrorBarsDataContainer -*/ - -/*! - Constructs an error bar with errors set to zero. -*/ -QCPErrorBarsData::QCPErrorBarsData() : - errorMinus(0), - errorPlus(0) -{ -} - -/*! - Constructs an error bar with equal \a error in both negative and positive direction. -*/ -QCPErrorBarsData::QCPErrorBarsData(double error) : - errorMinus(error), - errorPlus(error) -{ -} - -/*! - Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, - respectively. -*/ -QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : - errorMinus(errorMinus), - errorPlus(errorPlus) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBars - \brief A plottable that adds a set of error bars to other plottables. - - \image html QCPErrorBars.png - - The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref - QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. - - Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the - error bars. The orientation of the error bars can be controlled with \ref setErrorType. - - By using \ref setData, you can supply the actual error data, either as symmetric error or - plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute - key/value position of each error bar will be adopted from the configured data plottable. The - error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points - of the data plottable. You can directly access and manipulate the error bar data via \ref data. - - Set either of the plus/minus errors to NaN (qQNaN() or - std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at - that index. - - \section qcperrorbars-appearance Changing the appearance - - The appearance of the error bars is defined by the pen (\ref setPen), and the width of the - whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data - point center to prevent that error bars are drawn too close to or even through scatter points. - This gap size can be controlled via \ref setSymbolGap. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPErrorBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You - may use it to directly manipulate the error values, which may be more convenient and faster than - using the regular \ref setData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - It is also important that the \a keyAxis and \a valueAxis are the same for the error bars - plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). - - The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not - delete it manually but use \ref QCustomPlot::removePlottable() instead. -*/ -QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QVector), - mErrorType(etValueError), - mWhiskerWidth(9), - mSymbolGap(10) -{ - setPen(QPen(Qt::black, 0)); - setBrush(Qt::NoBrush); -} - -QCPErrorBars::~QCPErrorBars() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data - container safely. Modifying the data in the container will then affect all \ref QCPErrorBars - instances that share the container. Sharing can be achieved by simply exchanging the data - containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, assign the - data containers directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 - (This uses different notation compared with other plottables, because the \ref QCPErrorBars - uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) - - \see addData -*/ -void QCPErrorBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &error) -{ - mDataContainer->clear(); - addData(error); -} - -/*! \overload - - Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) -{ - mDataContainer->clear(); - addData(errorMinus, errorPlus); -} - -/*! - Sets the data plottable to which the error bars will be applied. The error values specified e.g. - via \ref setData will be associated one-to-one by the data point index to the data points of \a - plottable. This means that the error bars will adopt the key/value coordinates of the data point - with the same index. - - The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref - QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either - of these restrictions is violated, a corresponding qDebug output is generated, and the data - plottable of this \ref QCPErrorBars instance is set to zero. - - For proper display, care must also be taken that the key and value axes of the \a plottable match - those configured for this \ref QCPErrorBars instance. -*/ -void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) -{ - if (plottable && qobject_cast(plottable)) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; - return; - } - if (plottable && !plottable->interface1D()) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; - return; - } - - mDataPlottable = plottable; -} - -/*! - Sets in which orientation the error bars shall appear on the data points. If your data needs both - error dimensions, create two \ref QCPErrorBars with different \a type. -*/ -void QCPErrorBars::setErrorType(ErrorType type) -{ - mErrorType = type; -} - -/*! - Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to - \a pixels. -*/ -void QCPErrorBars::setWhiskerWidth(double pixels) -{ - mWhiskerWidth = pixels; -} - -/*! - Sets the gap diameter around the data points that will be left out when drawing the error bar - backbones. This gap prevents that error bars are drawn too close to or even through scatter - points. -*/ -void QCPErrorBars::setSymbolGap(double pixels) -{ - mSymbolGap = pixels; -} - -/*! \overload - - Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &error) -{ - addData(error, error); -} - -/*! \overload - - Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) -{ - if (errorMinus.size() != errorPlus.size()) - qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); - const int n = qMin(errorMinus.size(), errorPlus.size()); - mDataContainer->reserve(n); - for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); -} - -/*! \overload - - Adds a single symmetrical error bar as specified in \a error. The errors will be associated - one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double error) -{ - mDataContainer->append(QCPErrorBarsData(error)); -} - -/*! \overload - - Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors - will be associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double errorMinus, double errorPlus) -{ - mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); -} - -/* inherits documentation from base class */ -int QCPErrorBars::dataCount() const -{ - return mDataContainer->size(); -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataSortKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataSortKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainValue(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainValue(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::dataValueRange(int index) const -{ - if (mDataPlottable) - { - const double value = mDataPlottable->interface1D()->dataMainValue(index); - if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) - return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); - else - return QCPRange(value, value); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QCPRange(); - } -} - -/* inherits documentation from base class */ -QPointF QCPErrorBars::dataPixelPosition(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataPixelPosition(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QPointF(); -} - -/* inherits documentation from base class */ -bool QCPErrorBars::sortKeyIsMainKey() const -{ - if (mDataPlottable) - { - return mDataPlottable->interface1D()->sortKeyIsMainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return true; - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if (!mDataPlottable) - return result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); - - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - backbones.clear(); - whiskers.clear(); - getErrorBarLines(it, backbones, whiskers); - for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); - break; - } - } - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); - if (beginIndex >= mDataContainer->size()) - beginIndex = mDataContainer->size()-1; - return beginIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); - if (endIndex > mDataContainer->size()) - endIndex = mDataContainer->size(); - return endIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mDataPlottable) return -1; - - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -void QCPErrorBars::draw(QCPPainter *painter) -{ - if (!mDataPlottable) return; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - - // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually - // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): - bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); - } -#endif - - applyDefaultAntialiasingHint(painter); - painter->setBrush(Qt::NoBrush); - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - QVector backbones, whiskers; - for (int i=0; i= unselectedSegments.size(); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - if (painter->pen().capStyle() == Qt::SquareCap) - { - QPen capFixPen(painter->pen()); - capFixPen.setCapStyle(Qt::FlatCap); - painter->setPen(capFixPen); - } - backbones.clear(); - whiskers.clear(); - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) - getErrorBarLines(it, backbones, whiskers); - } - painter->drawLines(backbones); - painter->drawLines(whiskers); - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) - { - painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); - painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); - painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); - } else - { - painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); - painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); - painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); - } -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (mErrorType == etValueError) - { - // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } else // mErrorType == etKeyError - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(dataKey)) continue; - // plus error: - double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); - itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); - } - for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange) - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) - continue; - } - if (mErrorType == etValueError) - { - const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(dataValue)) continue; - // plus error: - double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } else // mErrorType == etKeyError - { - // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! \internal - - Calculates the lines that make up the error bar belonging to the data point \a it. - - The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so - calling this method with different \a it but the same \a backbones and \a whiskers allows to - accumulate lines for multiple data points. - - This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars - instance and within the bounds of the associated data plottable. -*/ -void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const -{ - if (!mDataPlottable) return; - - int index = it-mDataContainer->constBegin(); - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) - return; - QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); - QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); - const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value - const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); - // plus error: - double errorStart, errorEnd; - if (!qIsNaN(it->errorPlus)) - { - errorStart = centerErrorAxisPixel+symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } - // minus error: - if (!qIsNaN(it->errorMinus)) - { - errorStart = centerErrorAxisPixel-symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } -} - -/*! \internal - - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key - coordinates relative to their data point key, this method checks all outer error bars whether - they truly don't reach into the visible portion of the axis rect, by calling \ref - errorBarVisible. On the other hand error bars with type \ref etValueError that are associated - with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype - "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of - error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref - QCPPlottableInterface1D::findEnd). - - If the plottable's sort key is not equal to the main key, this method returns the full data - range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a - point-by-point basis in the \ref draw method. -*/ -void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable || rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) - { - // if the sort key isn't the main key, it's not possible to find a contiguous range of visible - // data points, so this method then only applies the range restriction and otherwise returns - // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing - QCPDataRange dataRange(0, mDataContainer->size()); - dataRange = dataRange.bounded(rangeRestriction); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); - return; - } - - // get visible data range via interface from data plottable, and then restrict to available error data points: - const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); - int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); - int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); - int i = beginIndex; - while (i > 0 && i < n && i > rangeRestriction.begin()) - { - if (errorBarVisible(i)) - beginIndex = i; - --i; - } - i = endIndex; - while (i >= 0 && i < n && i < rangeRestriction.end()) - { - if (errorBarVisible(i)) - endIndex = i+1; - ++i; - } - QCPDataRange dataRange(beginIndex, endIndex); - dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); -} - -/*! \internal - - Calculates the minimum distance in pixels the error bars' representation has from the given \a - pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. -*/ -double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (!mDataPlottable || mDataContainer->isEmpty()) - return -1.0; - if (!mKeyAxis || !mValueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return -1.0; - } - - QCPErrorBarsDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); - - // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - getErrorBarLines(it, backbones, whiskers); - for (int i=0; i &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! \internal - - Returns whether the error bar at the specified \a index is visible within the current key axis - range. - - This method assumes for performance reasons without checking that the key axis, the value axis, - and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid - bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. -*/ -bool QCPErrorBars::errorBarVisible(int index) const -{ - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - if (qIsNaN(centerKeyPixel)) - return false; - - double keyMin, keyMax; - if (mErrorType == etKeyError) - { - const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); - const double errorPlus = mDataContainer->at(index).errorPlus; - const double errorMinus = mDataContainer->at(index).errorMinus; - keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); - keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); - } else // mErrorType == etValueError - { - keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - } - return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); -} - -/*! \internal - - Returns whether \a line intersects (or is contained in) \a pixelRect. - - \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for - error bar lines. -*/ -bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const -{ - if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) - return false; - else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) - return false; - else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) - return false; - else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) - return false; - else - return true; -} -/* end of 'src/plottables/plottable-errorbar.cpp' */ - - -/* including file 'src/items/item-straightline.cpp', size 7592 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemStraightLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemStraightLine - \brief A straight line that spans infinitely in both directions - - \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a point1 and \a point2, which define the straight line. -*/ - -/*! - Creates a straight line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition(QLatin1String("point1"))), - point2(createPosition(QLatin1String("point2"))) -{ - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemStraightLine::~QCPItemStraightLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemStraightLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); -} - -/* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) -{ - QCPVector2D start(point1->pixelPosition()); - QCPVector2D end(point2->pixelPosition()); - // get visible segment of straight line inside clipRect: - double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - } -} - -/*! \internal - - Returns the section of the straight line defined by \a base and direction vector \a - vec, that is visible in the specified \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const -{ - double bx, by; - double gamma; - QLineF result; - if (vec.x() == 0 && vec.y() == 0) - return result; - if (qFuzzyIsNull(vec.x())) // line is vertical - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed - { - QList pointVectors; - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - // check right of rect: - bx = rect.right(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemStraightLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-straightline.cpp' */ - - -/* including file 'src/items/item-line.cpp', size 8498 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemLine - \brief A line from one point to another - - \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a start and \a end, which define the end points of the line. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. -*/ - -/*! - Creates a line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemLine::~QCPItemLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemLine::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemLine::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); -} - -/* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) -{ - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if (qFuzzyIsNull((startVec-endVec).lengthSquared())) - return; - // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); - } -} - -/*! \internal - - Returns the section of the line defined by \a start and \a end, that is visible in the specified - \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const -{ - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - - QCPVector2D base = start; - QCPVector2D vec = end-start; - double bx, by; - double gamma, mu; - QLineF result; - QList pointVectors; - - if (!qFuzzyIsNull(vec.y())) // line is not horizontal - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - } - if (!qFuzzyIsNull(vec.x())) // line is not vertical - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - // check right of rect: - bx = rect.right(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-line.cpp' */ - - -/* including file 'src/items/item-curve.cpp', size 7159 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemCurve - \brief A curved line from one point to another - - \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." - - It has four positions, \a start and \a end, which define the end points of the line, and two - control points which define the direction the line exits from the start and the direction from - which it approaches the end: \a startDir and \a endDir. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an - arrow. - - Often it is desirable for the control points to stay at fixed relative positions to the start/end - point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, - and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. -*/ - -/*! - Creates a curve item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - startDir(createPosition(QLatin1String("startDir"))), - endDir(createPosition(QLatin1String("endDir"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemCurve::~QCPItemCurve() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemCurve::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemCurve::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemCurve::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemCurve::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF startVec(start->pixelPosition()); - QPointF startDirVec(startDir->pixelPosition()); - QPointF endDirVec(endDir->pixelPosition()); - QPointF endVec(end->pixelPosition()); - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - QPolygonF polygon = cubicPath.toSubpathPolygons().first(); - QCPVector2D p(pos); - double minDistSqr = std::numeric_limits::max(); - for (int i=1; ipixelPosition()); - QCPVector2D startDirVec(startDir->pixelPosition()); - QCPVector2D endDirVec(endDir->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if ((endVec-startVec).length() > 1e10) // too large curves cause crash - return; - - QPainterPath cubicPath(startVec.toPointF()); - cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); - - // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) - { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemCurve::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-curve.cpp' */ - - -/* including file 'src/items/item-rect.cpp', size 6479 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemRect - \brief A rectangle - - \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemRect::~QCPItemRect() -{ -} - -/*! - Sets the pen that will be used to draw the line of the rectangle - - \see setSelectedPen, setBrush -*/ -void QCPItemRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the rectangle when selected - - \see setPen, setSelected -*/ -void QCPItemRect::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemRect::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); -} - -/* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF rect = QRectF(p1, p2).normalized(); - double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemRect::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemRect::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-rect.cpp' */ - - -/* including file 'src/items/item-text.cpp', size 13338 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemText -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemText - \brief A text label - - \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." - - Its position is defined by the member \a position and the setting of \ref setPositionAlignment. - The latter controls which part of the text rect shall be aligned with \a position. - - The text alignment itself (i.e. left, center, right) can be controlled with \ref - setTextAlignment. - - The text may be rotated around the \a position point with \ref setRotation. -*/ - -/*! - Creates a text item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mText(QLatin1String("text")), - mPositionAlignment(Qt::AlignCenter), - mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), - mRotation(0) -{ - position->setCoords(0, 0); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); -} - -QCPItemText::~QCPItemText() -{ -} - -/*! - Sets the color of the text. -*/ -void QCPItemText::setColor(const QColor &color) -{ - mColor = color; -} - -/*! - Sets the color of the text that will be used when the item is selected. -*/ -void QCPItemText::setSelectedColor(const QColor &color) -{ - mSelectedColor = color; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text. To disable the - border, set \a pen to Qt::NoPen. - - \see setSelectedPen, setBrush, setPadding -*/ -void QCPItemText::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text, when the item is - selected. To disable the border, set \a pen to Qt::NoPen. - - \see setPen -*/ -void QCPItemText::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used do fill the background of the text. To disable the - background, set \a brush to Qt::NoBrush. - - \see setSelectedBrush, setPen, setPadding -*/ -void QCPItemText::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the - background, set \a brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemText::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the font of the text. - - \see setSelectedFont, setColor -*/ -void QCPItemText::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the font of the text that will be used when the item is selected. - - \see setFont -*/ -void QCPItemText::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the text that will be displayed. Multi-line texts are supported by inserting a line break - character, e.g. '\n'. - - \see setFont, setColor, setTextAlignment -*/ -void QCPItemText::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets which point of the text rect shall be aligned with \a position. - - Examples: - \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such - that the top of the text rect will be horizontally centered on \a position. - \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the - bottom left corner of the text rect. - - If you want to control the alignment of (multi-lined) text within the text rect, use \ref - setTextAlignment. -*/ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) -{ - mPositionAlignment = alignment; -} - -/*! - Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). -*/ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) -{ - mTextAlignment = alignment; -} - -/*! - Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated - around \a position. -*/ -void QCPItemText::setRotation(double degrees) -{ - mRotation = degrees; -} - -/*! - Sets the distance between the border of the text rectangle and the text. The appearance (and - visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. -*/ -void QCPItemText::setPadding(const QMargins &padding) -{ - mPadding = padding; -} - -/* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - // The rect may be rotated, so we transform the actual clicked pos to the rotated - // coordinate system, so we can use the normal rectDistance function for non-rotated rects: - QPointF positionPixels(position->pixelPosition()); - QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); - - return rectDistance(textBoxRect, rotatedPos, true); -} - -/* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) -{ - QPointF pos(position->pixelPosition()); - QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); - double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) - { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); - } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPosition(int anchorId) const -{ - // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPosition()); - QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) - { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the point that must be given to the QPainter::drawText function (which expects the top - left point of the text rect), according to the position \a pos, the text bounding box \a rect and - the requested \a positionAlignment. - - For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point - will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally - drawn at that point, the lower left corner of the resulting text rect is at \a pos. -*/ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const -{ - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) - return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) - result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) - result.ry() -= rect.height(); - return result; -} - -/*! \internal - - Returns the font that should be used for drawing text. Returns mFont when the item is not selected - and mSelectedFont when it is. -*/ -QFont QCPItemText::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the color that should be used for drawing text. Returns mColor when the item is not - selected and mSelectedColor when it is. -*/ -QColor QCPItemText::mainColor() const -{ - return mSelected ? mSelectedColor : mColor; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemText::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemText::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-text.cpp' */ - - -/* including file 'src/items/item-ellipse.cpp', size 7863 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemEllipse -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemEllipse - \brief An ellipse - - \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. -*/ - -/*! - Creates an ellipse item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), - left(createAnchor(QLatin1String("left"), aiLeft)), - center(createAnchor(QLatin1String("center"), aiCenter)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemEllipse::~QCPItemEllipse() -{ -} - -/*! - Sets the pen that will be used to draw the line of the ellipse - - \see setSelectedPen, setBrush -*/ -void QCPItemEllipse::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the ellipse when selected - - \see setPen, setSelected -*/ -void QCPItemEllipse::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemEllipse::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - - // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - double result = qAbs(c-1)*qSqrt(x*x+y*y); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); -#ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big - { -#endif - painter->drawEllipse(ellipseRect); -#ifdef __EXCEPTIONS - } catch (...) - { - qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); - } -#endif - } -} - -/* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemEllipse::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemEllipse::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-ellipse.cpp' */ - - -/* including file 'src/items/item-pixmap.cpp', size 10615 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPixmap - \brief An arbitrary pixmap - - \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will - be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to - fit the rectangle or be drawn aligned to the topLeft position. - - If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown - on the right side of the example image), the pixmap will be flipped in the respective - orientations. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mScaled(false), - mScaledPixmapInvalidated(true), - mAspectRatioMode(Qt::KeepAspectRatio), - mTransformationMode(Qt::SmoothTransformation) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); -} - -QCPItemPixmap::~QCPItemPixmap() -{ -} - -/*! - Sets the pixmap that will be displayed. -*/ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) -{ - mPixmap = pixmap; - mScaledPixmapInvalidated = true; - if (mPixmap.isNull()) - qDebug() << Q_FUNC_INFO << "pixmap is null"; -} - -/*! - Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a - bottomRight positions. -*/ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) -{ - mScaled = scaled; - mAspectRatioMode = aspectRatioMode; - mTransformationMode = transformationMode; - mScaledPixmapInvalidated = true; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap. - - \see setSelectedPen, setBrush -*/ -void QCPItemPixmap::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap when selected - - \see setPen, setSelected -*/ -void QCPItemPixmap::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return rectDistance(getFinalRect(), pos, true); -} - -/* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) -{ - bool flipHorz = false; - bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); - double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) - { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); - QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) - { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const -{ - bool flipHorz; - bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); - // we actually want denormal rects (negative width/height) here, so restore - // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The - parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped - horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a - bottomRight.) - - This function only creates the scaled pixmap when the buffered pixmap has a different size than - the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does - not cause expensive rescaling every time. - - If scaling is disabled, sets mScaledPixmap to a null QPixmap. -*/ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) -{ - if (mPixmap.isNull()) - return; - - if (mScaled) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - double devicePixelRatio = mPixmap.devicePixelRatio(); -#else - double devicePixelRatio = 1.0; -#endif - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) - { - mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mScaledPixmap.setDevicePixelRatio(devicePixelRatio); -#endif - } - } else if (!mScaledPixmap.isNull()) - mScaledPixmap = QPixmap(); - mScaledPixmapInvalidated = false; -} - -/*! \internal - - Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions - and scaling settings. - - The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn - flipped horizontally or vertically in the returned rect. (The returned rect itself is always - normalized, i.e. the top left corner of the rect is actually further to the top/left than the - bottom right corner). This is the case when the item position \a topLeft is further to the - bottom/right than \a bottomRight. - - If scaling is disabled, returns a rect with size of the original pixmap and the top left corner - aligned with the item position \a topLeft. The position \a bottomRight is ignored. -*/ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const -{ - QRect result; - bool flipHorz = false; - bool flipVert = false; - QPoint p1 = topLeft->pixelPosition().toPoint(); - QPoint p2 = bottomRight->pixelPosition().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) - { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); - QPoint topLeft = p1; - if (newSize.width() < 0) - { - flipHorz = true; - newSize.rwidth() *= -1; - topLeft.setX(p2.x()); - } - if (newSize.height() < 0) - { - flipVert = true; - newSize.rheight() *= -1; - topLeft.setY(p2.y()); - } - QSize scaledSize = mPixmap.size(); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - scaledSize /= mPixmap.devicePixelRatio(); - scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); -#else - scaledSize.scale(newSize, mAspectRatioMode); -#endif - result = QRect(topLeft, scaledSize); - } else - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); -#else - result = QRect(p1, mPixmap.size()); -#endif - } - if (flippedHorz) - *flippedHorz = flipHorz; - if (flippedVert) - *flippedVert = flipVert; - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemPixmap::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-pixmap.cpp' */ - - -/* including file 'src/items/item-tracer.cpp', size 14624 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemTracer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemTracer - \brief Item that sticks to QCPGraph data points - - \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." - - The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt - the coordinate axes of the graph and update its \a position to be on the graph's data. This means - the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a - QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a - position will have no effect because they will be overriden in the next redraw (this is when the - coordinate update happens). - - If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will - stay at the corresponding end of the graph. - - With \ref setInterpolating you may specify whether the tracer may only stay exactly on data - points or whether it interpolates data points linearly, if given a key that lies between two data - points of the graph. - - The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer - have no own visual appearance (set the style to \ref tsNone), and just connect other item - positions to the tracer \a position (used as an anchor) via \ref - QCPItemPosition::setParentAnchor. - - \note The tracer position is only automatically updated upon redraws. So when the data of the - graph changes and immediately afterwards (without a redraw) the position coordinates of the - tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref - updatePosition must be called manually, prior to reading the tracer coordinates. -*/ - -/*! - Creates a tracer item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - mSize(6), - mStyle(tsCrosshair), - mGraph(0), - mGraphKey(0), - mInterpolating(false) -{ - position->setCoords(0, 0); - - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemTracer::~QCPItemTracer() -{ -} - -/*! - Sets the pen that will be used to draw the line of the tracer - - \see setSelectedPen, setBrush -*/ -void QCPItemTracer::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the tracer when selected - - \see setPen, setSelected -*/ -void QCPItemTracer::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer - - \see setSelectedBrush, setPen -*/ -void QCPItemTracer::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer, when selected. - - \see setBrush, setSelected -*/ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare - does, \ref tsCrosshair does not). -*/ -void QCPItemTracer::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the style/visual appearance of the tracer. - - If you only want to use the tracer \a position as an anchor for other items, set \a style to - \ref tsNone. -*/ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) -{ - mStyle = style; -} - -/*! - Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type - QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. - - To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed - freely like any other item position. This is the state the tracer will assume when its graph gets - deleted while still attached to it. - - \see setGraphKey -*/ -void QCPItemTracer::setGraph(QCPGraph *graph) -{ - if (graph) - { - if (graph->parentPlot() == mParentPlot) - { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); - mGraph = graph; - updatePosition(); - } else - qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else - { - mGraph = 0; - } -} - -/*! - Sets the key of the graph's data point the tracer will be positioned at. This is the only free - coordinate of a tracer when attached to a graph. - - Depending on \ref setInterpolating, the tracer will be either positioned on the data point - closest to \a key, or will stay exactly at \a key and interpolate the value linearly. - - \see setGraph, setInterpolating -*/ -void QCPItemTracer::setGraphKey(double key) -{ - mGraphKey = key; -} - -/*! - Sets whether the value of the graph's data points shall be interpolated, when positioning the - tracer. - - If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on - the data point of the graph which is closest to the key, but which is not necessarily exactly - there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and - the appropriate value will be interpolated from the graph's data points linearly. - - \see setGraph, setGraphKey -*/ -void QCPItemTracer::setInterpolating(bool enabled) -{ - mInterpolating = enabled; -} - -/* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return -1; - case tsPlus: - { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), - QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), - QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - // distance to border: - double centerDist = QCPVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; - } - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); - } - break; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) -{ - updatePosition(); - if (mStyle == tsNone) - return; - - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return; - case tsPlus: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; - } - } -} - -/*! - If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a - position to reside on the graph data, depending on the configured key (\ref setGraphKey). - - It is called automatically on every redraw and normally doesn't need to be called manually. One - exception is when you want to read the tracer coordinates via \a position and are not sure that - the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. - In that situation, call this function before accessing \a position, to make sure you don't get - out-of-date coordinates. - - If there is no graph set on this tracer, this function does nothing. -*/ -void QCPItemTracer::updatePosition() -{ - if (mGraph) - { - if (mParentPlot->hasPlottable(mGraph)) - { - if (mGraph->data()->size() > 1) - { - QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); - QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey <= first->key) - position->setCoords(first->key, first->value); - else if (mGraphKey >= last->key) - position->setCoords(last->key, last->value); - else - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); - if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators - { - QCPGraphDataContainer::const_iterator prevIt = it; - ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before - if (mInterpolating) - { - // interpolate between iterators around mGraphKey: - double slope = 0; - if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) - slope = (it->value-prevIt->value)/(it->key-prevIt->key); - position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); - } else - { - // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt->key+it->key)*0.5) - position->setCoords(prevIt->key, prevIt->value); - else - position->setCoords(it->key, it->value); - } - } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) - position->setCoords(it->key, it->value); - } - } else if (mGraph->data()->size() == 1) - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it->key, it->value); - } else - qDebug() << Q_FUNC_INFO << "graph has no data"; - } else - qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemTracer::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemTracer::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-tracer.cpp' */ - - -/* including file 'src/items/item-bracket.cpp', size 10687 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemBracket - \brief A bracket for referencing/highlighting certain parts in the plot. - - \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a left and \a right, which define the span of the bracket. If \a left is - actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the - example image. - - The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket - stretches away from the embraced span, can be controlled with \ref setLength. - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
- - It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine - or QCPItemCurve) or a text label (QCPItemText), to the bracket. -*/ - -/*! - Creates a bracket item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition(QLatin1String("left"))), - right(createPosition(QLatin1String("right"))), - center(createAnchor(QLatin1String("center"), aiCenter)), - mLength(8), - mStyle(bsCalligraphic) -{ - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemBracket::~QCPItemBracket() -{ -} - -/*! - Sets the pen that will be used to draw the bracket. - - Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the - stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use - \ref setLength, which has a similar effect. - - \see setSelectedPen -*/ -void QCPItemBracket::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the bracket when selected - - \see setPen, setSelected -*/ -void QCPItemBracket::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the \a length in pixels how far the bracket extends in the direction towards the embraced - span of the bracket (i.e. perpendicular to the left-right-direction) - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
-*/ -void QCPItemBracket::setLength(double length) -{ - mLength = length; -} - -/*! - Sets the style of the bracket, i.e. the shape/visual appearance. - - \see setPen -*/ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) -{ - mStyle = style; -} - -/* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QCPVector2D p(pos); - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return -1; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (mStyle) - { - case QCPItemBracket::bsSquare: - case QCPItemBracket::bsRound: - { - double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); - double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); - return qSqrt(qMin(qMin(a, b), c)); - } - case QCPItemBracket::bsCurly: - case QCPItemBracket::bsCalligraphic: - { - double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); - double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); - return qSqrt(qMin(qMin(a, b), qMin(c, d))); - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - QPolygon boundingPoly; - boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) - { - painter->setPen(mainPen()); - switch (mStyle) - { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); - path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return leftVec.toPointF(); - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (anchorId) - { - case aiCenter: - return centerVec.toPointF(); - } - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemBracket::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-bracket.cpp' */ - - From de87c3775b5599a71fe1da7a53081afa000f4ed5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:29:04 -0400 Subject: [PATCH 0796/1324] Add files via upload --- src/qt/qcustomplot.cpp | 30121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 30121 insertions(+) create mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp new file mode 100644 index 00000000..e59374ab --- /dev/null +++ b/src/qt/qcustomplot.cpp @@ -0,0 +1,30121 @@ +/*************************************************************************** +** ** +** QCustomPlot, an easy to use, modern plotting widget for Qt ** +** Copyright (C) 2011-2017 Emanuel Eichhammer ** +** ** +** This program is free software: you can redistribute it and/or modify ** +** it under the terms of the GNU General Public License as published by ** +** the Free Software Foundation, either version 3 of the License, or ** +** (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, ** +** but WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see http://www.gnu.org/licenses/. ** +** ** +**************************************************************************** +** Author: Emanuel Eichhammer ** +** Website/Contact: http://www.qcustomplot.com/ ** +** Date: 04.09.17 ** +** Version: 2.0.0 ** +****************************************************************************/ + +#include "qcustomplot.h" + + +/* including file 'src/vector2d.cpp', size 7340 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPVector2D +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPVector2D + \brief Represents two doubles as a mathematical 2D vector + + This class acts as a replacement for QVector2D with the advantage of double precision instead of + single, and some convenience methods tailored for the QCustomPlot library. +*/ + +/* start documentation of inline functions */ + +/*! \fn void QCPVector2D::setX(double x) + + Sets the x coordinate of this vector to \a x. + + \see setY +*/ + +/*! \fn void QCPVector2D::setY(double y) + + Sets the y coordinate of this vector to \a y. + + \see setX +*/ + +/*! \fn double QCPVector2D::length() const + + Returns the length of this vector. + + \see lengthSquared +*/ + +/*! \fn double QCPVector2D::lengthSquared() const + + Returns the squared length of this vector. In some situations, e.g. when just trying to find the + shortest vector of a group, this is faster than calculating \ref length, because it avoids + calculation of a square root. + + \see length +*/ + +/*! \fn QPoint QCPVector2D::toPoint() const + + Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point + information. + + \see toPointF +*/ + +/*! \fn QPointF QCPVector2D::toPointF() const + + Returns a QPointF which has the x and y coordinates of this vector. + + \see toPoint +*/ + +/*! \fn bool QCPVector2D::isNull() const + + Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y + coordinates, i.e. if both are binary equal to 0. +*/ + +/*! \fn QCPVector2D QCPVector2D::perpendicular() const + + Returns a vector perpendicular to this vector, with the same length. +*/ + +/*! \fn double QCPVector2D::dot() const + + Returns the dot/scalar product of this vector with the specified vector \a vec. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates to 0. +*/ +QCPVector2D::QCPVector2D() : + mX(0), + mY(0) +{ +} + +/*! + Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified + values. +*/ +QCPVector2D::QCPVector2D(double x, double y) : + mX(x), + mY(y) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPoint &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of + the specified \a point. +*/ +QCPVector2D::QCPVector2D(const QPointF &point) : + mX(point.x()), + mY(point.y()) +{ +} + +/*! + Normalizes this vector. After this operation, the length of the vector is equal to 1. + + \see normalized, length, lengthSquared +*/ +void QCPVector2D::normalize() +{ + double len = length(); + mX /= len; + mY /= len; +} + +/*! + Returns a normalized version of this vector. The length of the returned vector is equal to 1. + + \see normalize, length, lengthSquared +*/ +QCPVector2D QCPVector2D::normalized() const +{ + QCPVector2D result(mX, mY); + result.normalize(); + return result; +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a start and \a end. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const +{ + QCPVector2D v(end-start); + double vLengthSqr = v.lengthSquared(); + if (!qFuzzyIsNull(vLengthSqr)) + { + double mu = v.dot(*this-start)/vLengthSqr; + if (mu < 0) + return (*this-start).lengthSquared(); + else if (mu > 1) + return (*this-end).lengthSquared(); + else + return ((start + mu*v)-*this).lengthSquared(); + } else + return (*this-start).lengthSquared(); +} + +/*! \overload + + Returns the squared shortest distance of this vector (interpreted as a point) to the finite line + segment given by \a line. + + \see distanceToStraightLine +*/ +double QCPVector2D::distanceSquaredToLine(const QLineF &line) const +{ + return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); +} + +/*! + Returns the shortest distance of this vector (interpreted as a point) to the infinite straight + line given by a \a base point and a \a direction vector. + + \see distanceSquaredToLine +*/ +double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const +{ + return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); +} + +/*! + Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a + factor. +*/ +QCPVector2D &QCPVector2D::operator*=(double factor) +{ + mX *= factor; + mY *= factor; + return *this; +} + +/*! + Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a + divisor. +*/ +QCPVector2D &QCPVector2D::operator/=(double divisor) +{ + mX /= divisor; + mY /= divisor; + return *this; +} + +/*! + Adds the given \a vector to this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) +{ + mX += vector.mX; + mY += vector.mY; + return *this; +} + +/*! + subtracts the given \a vector from this vector component-wise. +*/ +QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) +{ + mX -= vector.mX; + mY -= vector.mY; + return *this; +} +/* end of 'src/vector2d.cpp' */ + + +/* including file 'src/painter.cpp', size 8670 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPainter +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPainter + \brief QPainter subclass used internally + + This QPainter subclass is used to provide some extended functionality e.g. for tweaking position + consistency between antialiased and non-antialiased painting. Further it provides workarounds + for QPainter quirks. + + \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and + restore. So while it is possible to pass a QCPPainter instance to a function that expects a + QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because + it will call the base class implementations of the functions actually hidden by QCPPainter). +*/ + +/*! + Creates a new QCPPainter instance and sets default values +*/ +QCPPainter::QCPPainter() : + QPainter(), + mModes(pmDefault), + mIsAntialiasing(false) +{ + // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and + // a call to begin() will follow +} + +/*! + Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just + like the analogous QPainter constructor, begins painting on \a device immediately. + + Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. +*/ +QCPPainter::QCPPainter(QPaintDevice *device) : + QPainter(device), + mModes(pmDefault), + mIsAntialiasing(false) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (isActive()) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif +} + +/*! + Sets the pen of the painter and applies certain fixes to it, depending on the mode of this + QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QPen &pen) +{ + QPainter::setPen(pen); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(const QColor &color) +{ + QPainter::setPen(color); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of + this QCPPainter. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::setPen(Qt::PenStyle penStyle) +{ + QPainter::setPen(penStyle); + if (mModes.testFlag(pmNonCosmetic)) + makeNonCosmetic(); +} + +/*! \overload + + Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when + antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to + integer coordinates and then passes it to the original drawLine. + + \note this function hides the non-virtual base class implementation. +*/ +void QCPPainter::drawLine(const QLineF &line) +{ + if (mIsAntialiasing || mModes.testFlag(pmVectorized)) + QPainter::drawLine(line); + else + QPainter::drawLine(line.toLine()); +} + +/*! + Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint + with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between + antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for + AA/Non-AA painting). +*/ +void QCPPainter::setAntialiasing(bool enabled) +{ + setRenderHint(QPainter::Antialiasing, enabled); + if (mIsAntialiasing != enabled) + { + mIsAntialiasing = enabled; + if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs + { + if (mIsAntialiasing) + translate(0.5, 0.5); + else + translate(-0.5, -0.5); + } + } +} + +/*! + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setModes(QCPPainter::PainterModes modes) +{ + mModes = modes; +} + +/*! + Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a + device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, + all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that + behaviour. + + The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets + the render hint as appropriate. + + \note this function hides the non-virtual base class implementation. +*/ +bool QCPPainter::begin(QPaintDevice *device) +{ + bool result = QPainter::begin(device); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if (result) + setRenderHint(QPainter::NonCosmeticDefaultPen); +#endif + return result; +} + +/*! \overload + + Sets the mode of the painter. This controls whether the painter shall adjust its + fixes/workarounds optimized for certain output devices. +*/ +void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) +{ + if (!enabled && mModes.testFlag(mode)) + mModes &= ~mode; + else if (enabled && !mModes.testFlag(mode)) + mModes |= mode; +} + +/*! + Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see restore +*/ +void QCPPainter::save() +{ + mAntialiasingStack.push(mIsAntialiasing); + QPainter::save(); +} + +/*! + Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to + QPainter, the save/restore functions are reimplemented to also save/restore those members. + + \note this function hides the non-virtual base class implementation. + + \see save +*/ +void QCPPainter::restore() +{ + if (!mAntialiasingStack.isEmpty()) + mIsAntialiasing = mAntialiasingStack.pop(); + else + qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; + QPainter::restore(); +} + +/*! + Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen + overrides when the \ref pmNonCosmetic mode is set. +*/ +void QCPPainter::makeNonCosmetic() +{ + if (qFuzzyIsNull(pen().widthF())) + { + QPen p = pen(); + p.setWidth(1); + QPainter::setPen(p); + } +} +/* end of 'src/painter.cpp' */ + + +/* including file 'src/paintbuffer.cpp', size 18502 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPaintBuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPaintBuffer + \brief The abstract base class for paint buffers, which define the rendering backend + + This abstract base class defines the basic interface that a paint buffer needs to provide in + order to be usable by QCustomPlot. + + A paint buffer manages both a surface to draw onto, and the matching paint device. The size of + the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref + QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the + painting is complete, \ref donePainting is called, so the paint buffer implementation can do + clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color + using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the + previous frame. + + The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular + software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and + frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. + They are used automatically if \ref QCustomPlot::setOpenGl is enabled. +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 + + Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the + responsibility to delete the painter after the painting operations are complete is given to the + caller of this method. + + Once you are done using the painter, delete the painter and call \ref donePainting. + + While a painter generated with this method is active, you must not call \ref setSize, \ref + setDevicePixelRatio or \ref clear. + + This method may return 0, if a painter couldn't be activated on the buffer. This usually + indicates a problem with the respective painting backend. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 + + Draws the contents of this buffer with the provided \a painter. This is the method that is used + to finally join all paint buffers and draw them onto the screen. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 + + Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the + named color \c Qt::transparent. + + This method must not be called if there is currently a painter (acquired with \ref startPainting) + active. +*/ + +/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 + + Reallocates the internal buffer with the currently configured size (\ref setSize) and device + pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those + properties are changed on this paint buffer. + + \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method + in their constructor, to perform the first allocation (this can not be done by the base class + because calling pure virtual methods in base class constructors is not possible). +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of inline functions */ + +/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() + + If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, + call this method as soon as you are done with the painting operations and have deleted the + painter. + + paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The + default implementation does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. + + Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. +*/ +QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : + mSize(size), + mDevicePixelRatio(devicePixelRatio), + mInvalidated(true) +{ +} + +QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() +{ +} + +/*! + Sets the paint buffer size. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + If \a size is already the current buffer size, this method does nothing. +*/ +void QCPAbstractPaintBuffer::setSize(const QSize &size) +{ + if (mSize != size) + { + mSize = size; + reallocateBuffer(); + } +} + +/*! + Sets the invalidated flag to \a invalidated. + + This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer + instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered + layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, + QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also + replots them, instead of only the layer on which the replot was called. + + The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers + were added or removed from this buffer, or if they were reordered. It is set to false as soon as + all associated \ref QCPLayer instances are drawn onto the buffer. + + Under normal circumstances, it is not necessary to manually call this method. +*/ +void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) +{ + mInvalidated = invalidated; +} + +/*! + Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. + The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. + + The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained + by \ref startPainting are invalidated and must not be used after calling this method. + + \note This method is only available for Qt versions 5.4 and higher. +*/ +void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mDevicePixelRatio = ratio; + reallocateBuffer(); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; +#endif + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferPixmap + \brief A paint buffer based on QPixmap, using software raster rendering + + This paint buffer is the default and fall-back paint buffer which uses software rendering and + QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. +*/ + +/*! + Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if + applicable. +*/ +QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : + QCPAbstractPaintBuffer(size, devicePixelRatio) +{ + QCPPaintBufferPixmap::reallocateBuffer(); +} + +QCPPaintBufferPixmap::~QCPPaintBufferPixmap() +{ +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferPixmap::startPainting() +{ + QCPPainter *result = new QCPPainter(&mBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::draw(QCPPainter *painter) const +{ + if (painter && painter->isActive()) + painter->drawPixmap(0, 0, mBuffer); + else + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::clear(const QColor &color) +{ + mBuffer.fill(color); +} + +/* inherits documentation from base class */ +void QCPPaintBufferPixmap::reallocateBuffer() +{ + setInvalidated(); + if (!qFuzzyCompare(1.0, mDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBuffer = QPixmap(mSize*mDevicePixelRatio); + mBuffer.setDevicePixelRatio(mDevicePixelRatio); +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mDevicePixelRatio = 1.0; + mBuffer = QPixmap(mSize); +#endif + } else + { + mBuffer = QPixmap(mSize); + } +} + + +#ifdef QCP_OPENGL_PBUFFER +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlPbuffer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlPbuffer + \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. + (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a + devicePixelRatio, if applicable. + + The parameter \a multisamples defines how many samples are used per pixel. Higher values thus + result in higher quality antialiasing. If the specified \a multisamples value exceeds the + capability of the graphics hardware, the highest supported multisampling is used. +*/ +QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlPBuffer(0), + mMultisamples(qMax(0, multisamples)) +{ + QCPPaintBufferGlPbuffer::reallocateBuffer(); +} + +QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlPbuffer::startPainting() +{ + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + QCPPainter *result = new QCPPainter(mGlPBuffer); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlPBuffer->isValid()) + { + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlPBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::clear(const QColor &color) +{ + if (mGlPBuffer->isValid()) + { + mGlPBuffer->makeCurrent(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlPBuffer->doneCurrent(); + } else + qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlPbuffer::reallocateBuffer() +{ + if (mGlPBuffer) + delete mGlPBuffer; + + QGLFormat format; + format.setAlpha(true); + format.setSamples(mMultisamples); + mGlPBuffer = new QGLPixelBuffer(mSize, format); +} +#endif // QCP_OPENGL_PBUFFER + + +#ifdef QCP_OPENGL_FBO +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPaintBufferGlFbo +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPaintBufferGlFbo + \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering + + This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot + rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and + higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) + + The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are + supported by the system. +*/ + +/*! + Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, + if applicable. + + All frame buffer objects shall share one OpenGL context and paint device, which need to be set up + externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref + QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot + instance. +*/ +QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : + QCPAbstractPaintBuffer(size, devicePixelRatio), + mGlContext(glContext), + mGlPaintDevice(glPaintDevice), + mGlFrameBuffer(0) +{ + QCPPaintBufferGlFbo::reallocateBuffer(); +} + +QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() +{ + if (mGlFrameBuffer) + delete mGlFrameBuffer; +} + +/* inherits documentation from base class */ +QCPPainter *QCPPaintBufferGlFbo::startPainting() +{ + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return 0; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return 0; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); + result->setRenderHint(QPainter::HighQualityAntialiasing); + return result; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::donePainting() +{ + if (mGlFrameBuffer && mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + else + qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const +{ + if (!painter || !painter->isActive()) + { + qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + painter->drawImage(0, 0, mGlFrameBuffer->toImage()); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::clear(const QColor &color) +{ + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (!mGlFrameBuffer) + { + qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; + return; + } + + if (QOpenGLContext::currentContext() != mGlContext.data()) + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlFrameBuffer->bind(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + mGlFrameBuffer->release(); +} + +/* inherits documentation from base class */ +void QCPPaintBufferGlFbo::reallocateBuffer() +{ + // release and delete possibly existing framebuffer: + if (mGlFrameBuffer) + { + if (mGlFrameBuffer->isBound()) + mGlFrameBuffer->release(); + delete mGlFrameBuffer; + mGlFrameBuffer = 0; + } + + if (mGlContext.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; + return; + } + if (mGlPaintDevice.isNull()) + { + qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; + return; + } + + // create new fbo with appropriate size: + mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + QOpenGLFramebufferObjectFormat frameBufferFormat; + frameBufferFormat.setSamples(mGlContext.data()->format().samples()); + frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); + if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) + mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); +#endif +} +#endif // QCP_OPENGL_FBO +/* end of 'src/paintbuffer.cpp' */ + + +/* including file 'src/layer.cpp', size 37064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayer + \brief A layer that may contain objects, to control the rendering order + + The Layering system of QCustomPlot is the mechanism to control the rendering order of the + elements inside the plot. + + It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of + one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, + QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers + bottom to top and successively draws the layerables of the layers into the paint buffer(s). + + A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base + class from which almost all visible objects derive, like axes, grids, graphs, items, etc. + + \section qcplayer-defaultlayers Default layers + + Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and + "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's + selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain + the default axes and legend, so they will be drawn above plottables. In the middle, there is the + "main" layer. It is initially empty and set as the current layer (see + QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this + layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong + tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind + everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of + course, the layer affiliation of the individual objects can be changed as required (\ref + QCPLayerable::setLayer). + + \section qcplayer-ordering Controlling the rendering order via layers + + Controlling the ordering of layerables in the plot is easy: Create a new layer in the position + you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the + current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the + objects normally. They will be placed on the new layer automatically, due to the current layer + setting. Alternatively you could have also ignored the current layer setting and just moved the + objects with \ref QCPLayerable::setLayer to the desired layer after creating them. + + It is also possible to move whole layers. For example, If you want the grid to be shown in front + of all plottables/items on the "main" layer, just move it above "main" with + QCustomPlot::moveLayer. + + The rendering order within one layer is simply by order of creation or insertion. The item + created last (or added last to the layer), is drawn on top of all other objects on that layer. + + When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below + the deleted layer, see QCustomPlot::removeLayer. + + \section qcplayer-buffering Replotting only a specific layer + + If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific + layer by calling \ref replot. In certain situations this can provide better replot performance, + compared with a full replot of all layers. Upon creation of a new layer, the layer mode is + initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref + QCustomPlot instance is the "overlay" layer, containing the selection rect. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPLayer::children() const + + Returns a list of all layerables on this layer. The order corresponds to the rendering order: + layerables with higher indices are drawn above layerables with lower indices. +*/ + +/*! \fn int QCPLayer::index() const + + Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be + accessed via \ref QCustomPlot::layer. + + Layers with higher indices will be drawn above layers with lower indices. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPLayer instance. + + Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. + + \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. + This check is only performed by \ref QCustomPlot::addLayer. +*/ +QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : + QObject(parentPlot), + mParentPlot(parentPlot), + mName(layerName), + mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function + mVisible(true), + mMode(lmLogical) +{ + // Note: no need to make sure layerName is unique, because layer + // management is done with QCustomPlot functions. +} + +QCPLayer::~QCPLayer() +{ + // If child layerables are still on this layer, detach them, so they don't try to reach back to this + // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted + // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to + // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) + + while (!mChildren.isEmpty()) + mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() + + if (mParentPlot->currentLayer() == this) + qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; +} + +/*! + Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this + layer will be invisible. + + This function doesn't change the visibility property of the layerables (\ref + QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the + visibility of the parent layer into account. +*/ +void QCPLayer::setVisible(bool visible) +{ + mVisible = visible; +} + +/*! + Sets the rendering mode of this layer. + + If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by + the parent QCustomPlot instance. This means it may be replotted individually by calling \ref + QCPLayer::replot, without needing to replot all other layers. + + Layers which are set to \ref lmLogical (the default) are used only to define the rendering order + and can't be replotted individually. + + Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the + layers below, above and for the layer itself. This increases the memory consumption and + (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So + you should carefully choose which layers benefit from having their own paint buffer. A typical + example would be a layer which contains certain layerables (e.g. items) that need to be changed + and thus replotted regularly, while all other layerables on other layers stay static. By default, + only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection + rect. + + \see replot +*/ +void QCPLayer::setMode(QCPLayer::LayerMode mode) +{ + if (mMode != mode) + { + mMode = mode; + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } +} + +/*! \internal + + Draws the contents of this layer with the provided \a painter. + + \see replot, drawToPaintBuffer +*/ +void QCPLayer::draw(QCPPainter *painter) +{ + Q_FOREACH (QCPLayerable *child, mChildren) + { + if (child->realVisibility()) + { + painter->save(); + painter->setClipRect(child->clipRect().translated(0, -1)); + child->applyDefaultAntialiasingHint(painter); + child->draw(painter); + painter->restore(); + } + } +} + +/*! \internal + + Draws the contents of this layer into the paint buffer which is associated with this layer. The + association is established by the parent QCustomPlot, which manages all paint buffers (see \ref + QCustomPlot::setupPaintBuffers). + + \see draw +*/ +void QCPLayer::drawToPaintBuffer() +{ + if (!mPaintBuffer.isNull()) + { + if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) + { + if (painter->isActive()) + draw(painter); + else + qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; + delete painter; + mPaintBuffer.data()->donePainting(); + } else + qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; +} + +/*! + If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only + the layerables on this specific layer, without the need to replot all other layers (as a call to + \ref QCustomPlot::replot would do). + + If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on + the parent QCustomPlot instance. + + QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering + has changed since the last full replot and the other paint buffers were thus invalidated. + + \see draw +*/ +void QCPLayer::replot() +{ + if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) + { + if (!mPaintBuffer.isNull()) + { + mPaintBuffer.data()->clear(Qt::transparent); + drawToPaintBuffer(); + mPaintBuffer.data()->setInvalidated(false); + mParentPlot->update(); + } else + qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; + } else if (mMode == lmLogical) + mParentPlot->replot(); +} + +/*! \internal + + Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will + be prepended to the list, i.e. be drawn beneath the other layerables already in the list. + + This function does not change the \a mLayer member of \a layerable to this layer. (Use + QCPLayerable::setLayer to change the layer of an object, not this function.) + + \see removeChild +*/ +void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) +{ + if (!mChildren.contains(layerable)) + { + if (prepend) + mChildren.prepend(layerable); + else + mChildren.append(layerable); + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); +} + +/*! \internal + + Removes the \a layerable from the list of this layer. + + This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer + to change the layer of an object, not this function.) + + \see addChild +*/ +void QCPLayer::removeChild(QCPLayerable *layerable) +{ + if (mChildren.removeOne(layerable)) + { + if (!mPaintBuffer.isNull()) + mPaintBuffer.data()->setInvalidated(); + } else + qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayerable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayerable + \brief Base class for all drawable objects + + This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid + etc. + + Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking + the layers accordingly. + + For details about the layering mechanism, see the QCPLayer documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const + + Returns the parent layerable of this layerable. The parent layerable is used to provide + visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables + only get drawn if their parent layerables are visible, too. + + Note that a parent layerable is not necessarily also the QObject parent for memory management. + Further, a layerable doesn't always have a parent layerable, so this function may return 0. + + A parent layerable is set implicitly when placed inside layout elements and doesn't need to be + set manually by the user. +*/ + +/* end documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 + \internal + + This function applies the default antialiasing setting to the specified \a painter, using the + function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when + \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing + setting may be specified individually, this function should set the antialiasing state of the + most prominent entity. In this case however, the \ref draw function usually calls the specialized + versions of this function before drawing each entity, effectively overriding the setting of the + default antialiasing hint. + + First example: QCPGraph has multiple entities that have an antialiasing setting: The graph + line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, + QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only + the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's + antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and + QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw + calls the respective specialized applyAntialiasingHint function. + + Second example: QCPItemLine consists only of a line so there is only one antialiasing + setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by + all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the + respective layerable subclass.) Consequently it only has the normal + QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to + care about setting any antialiasing states, because the default antialiasing hint is already set + on the painter when the \ref draw function is called, and that's the state it wants to draw the + line with. +*/ + +/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 + \internal + + This function draws the layerable with the specified \a painter. It is only called by + QCustomPlot, if the layerable is visible (\ref setVisible). + + Before this function is called, the painter's antialiasing state is set via \ref + applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was + set to \ref clipRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); + + This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to + a different layer. + + \see setLayer +*/ + +/* end documentation of signals */ + +/*! + Creates a new QCPLayerable instance. + + Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the + derived classes. + + If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a + targetLayer is an empty string, it places itself on the current layer of the plot (see \ref + QCustomPlot::setCurrentLayer). + + It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later + time with \ref initializeParentPlot. + + The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable + parents are mainly used to control visibility in a hierarchy of layerables. This means a + layerable is only drawn, if all its ancestor layerables are also visible. Note that \a + parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a + plot does. It is not uncommon to set the QObject-parent to something else in the constructors of + QCPLayerable subclasses, to guarantee a working destruction hierarchy. +*/ +QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : + QObject(plot), + mVisible(true), + mParentPlot(plot), + mParentLayerable(parentLayerable), + mLayer(0), + mAntialiased(true) +{ + if (mParentPlot) + { + if (targetLayer.isEmpty()) + setLayer(mParentPlot->currentLayer()); + else if (!setLayer(targetLayer)) + qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; + } +} + +QCPLayerable::~QCPLayerable() +{ + if (mLayer) + { + mLayer->removeChild(this); + mLayer = 0; + } +} + +/*! + Sets the visibility of this layerable object. If an object is not visible, it will not be drawn + on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not + possible. +*/ +void QCPLayerable::setVisible(bool on) +{ + mVisible = on; +} + +/*! + Sets the \a layer of this layerable object. The object will be placed on top of the other objects + already on \a layer. + + If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or + interact/receive events). + + Returns true if the layer of this layerable was successfully changed to \a layer. +*/ +bool QCPLayerable::setLayer(QCPLayer *layer) +{ + return moveToLayer(layer, false); +} + +/*! \overload + Sets the layer of this layerable object by name + + Returns true on success, i.e. if \a layerName is a valid layer name. +*/ +bool QCPLayerable::setLayer(const QString &layerName) +{ + if (!mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (QCPLayer *layer = mParentPlot->layer(layerName)) + { + return setLayer(layer); + } else + { + qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; + return false; + } +} + +/*! + Sets whether this object will be drawn antialiased or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPLayerable::setAntialiased(bool enabled) +{ + mAntialiased = enabled; +} + +/*! + Returns whether this layerable is visible, taking the visibility of the layerable parent and the + visibility of this layerable's layer into account. This is the method that is consulted to decide + whether a layerable shall be drawn or not. + + If this layerable has a direct layerable parent (usually set via hierarchies implemented in + subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this + layerable has its visibility set to true and the parent layerable's \ref realVisibility returns + true. +*/ +bool QCPLayerable::realVisibility() const +{ + return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); +} + +/*! + This function is used to decide whether a click hits a layerable object or not. + + \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the + shortest pixel distance of this point to the object. If the object is either invisible or the + distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the + object is not selectable, -1.0 is returned, too. + + If the object is represented not by single lines but by an area like a \ref QCPItemText or the + bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In + these cases this function thus returns a constant value greater zero but still below the parent + plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). + + Providing a constant value for area objects allows selecting line objects even when they are + obscured by such area objects, by clicking close to the lines (i.e. closer than + 0.99*selectionTolerance). + + The actual setting of the selection state is not done by this function. This is handled by the + parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified + via the \ref selectEvent/\ref deselectEvent methods. + + \a details is an optional output parameter. Every layerable subclass may place any information + in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot + decides on the basis of this selectTest call, that the object was successfully selected. The + subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part + objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked + is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be + placed in \a details. So in the subsequent \ref selectEvent, the decision which part was + selected doesn't have to be done a second time for a single selection operation. + + You may pass 0 as \a details to indicate that you are not interested in those selection details. + + \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions +*/ +double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(pos) + Q_UNUSED(onlySelectable) + Q_UNUSED(details) + return -1.0; +} + +/*! \internal + + Sets the parent plot of this layerable. Use this function once to set the parent plot if you have + passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to + another one. + + Note that, unlike when passing a non-null parent plot in the constructor, this function does not + make \a parentPlot the QObject-parent of this layerable. If you want this, call + QObject::setParent(\a parentPlot) in addition to this function. + + Further, you will probably want to set a layer (\ref setLayer) after calling this function, to + make the layerable appear on the QCustomPlot. + + The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized + so they can react accordingly (e.g. also initialize the parent plot of child layerables, like + QCPLayout does). +*/ +void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) +{ + if (mParentPlot) + { + qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; + return; + } + + if (!parentPlot) + qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; + + mParentPlot = parentPlot; + parentPlotInitialized(mParentPlot); +} + +/*! \internal + + Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not + become the QObject-parent (for memory management) of this layerable. + + The parent layerable has influence on the return value of the \ref realVisibility method. Only + layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be + drawn. + + \see realVisibility +*/ +void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) +{ + mParentLayerable = parentLayerable; +} + +/*! \internal + + Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to + the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is + false, the object will be appended. + + Returns true on success, i.e. if \a layer is a valid layer. +*/ +bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) +{ + if (layer && !mParentPlot) + { + qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; + return false; + } + if (layer && layer->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; + return false; + } + + QCPLayer *oldLayer = mLayer; + if (mLayer) + mLayer->removeChild(this); + mLayer = layer; + if (mLayer) + mLayer->addChild(this, prepend); + if (mLayer != oldLayer) + Q_EMIT layerChanged(mLayer); + return true; +} + +/*! \internal + + Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a + localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is + controlled via \a overrideElement. +*/ +void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const +{ + if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(false); + else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) + painter->setAntialiasing(true); + else + painter->setAntialiasing(localAntialiased); +} + +/*! \internal + + This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting + of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the + parent plot is set at a later time. + + For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any + QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level + element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To + propagate the parent plot to all the children of the hierarchy, the top level element then uses + this function to pass the parent plot on to its child elements. + + The default implementation does nothing. + + \see initializeParentPlot +*/ +void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_UNUSED(parentPlot) +} + +/*! \internal + + Returns the selection category this layerable shall belong to. The selection category is used in + conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and + which aren't. + + Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref + QCP::iSelectOther. This is what the default implementation returns. + + \see QCustomPlot::setInteractions +*/ +QCP::Interaction QCPLayerable::selectionCategory() const +{ + return QCP::iSelectOther; +} + +/*! \internal + + Returns the clipping rectangle of this layerable object. By default, this is the viewport of the + parent QCustomPlot. Specific subclasses may reimplement this function to provide different + clipping rects. + + The returned clipping rect is set on the painter before the draw function of the respective + object is called. +*/ +QRect QCPLayerable::clipRect() const +{ + if (mParentPlot) + return mParentPlot->viewport(); + else + return QRect(); +} + +/*! \internal + + This event is called when the layerable shall be selected, as a consequence of a click by the + user. Subclasses should react to it by setting their selection state appropriately. The default + implementation does nothing. + + \a event is the mouse event that caused the selection. \a additive indicates, whether the user + was holding the multi-select-modifier while performing the selection (see \ref + QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled + (i.e. become selected when unselected and unselected when selected). + + Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. + returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). + The \a details data you output from \ref selectTest is fed back via \a details here. You may + use it to transport any kind of information from the selectTest to the possibly subsequent + selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable + that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need + to do the calculation again to find out which part was actually clicked. + + \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must + set the value either to true or false, depending on whether the selection state of this layerable + was actually changed. For layerables that only are selectable as a whole and not in parts, this + is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the + selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the + layerable was previously unselected and now is switched to the selected state. + + \see selectTest, deselectEvent +*/ +void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(additive) + Q_UNUSED(details) + Q_UNUSED(selectionStateChanged) +} + +/*! \internal + + This event is called when the layerable shall be deselected, either as consequence of a user + interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by + unsetting their selection appropriately. + + just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must + return true or false when the selection state of this layerable has changed or not changed, + respectively. + + \see selectTest, selectEvent +*/ +void QCPLayerable::deselectEvent(bool *selectionStateChanged) +{ + Q_UNUSED(selectionStateChanged) +} + +/*! + This event gets called when the user presses a mouse button while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + QCustomPlot uses an event propagation system that works the same as Qt's system. If your + layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in + its reimplementation, the event will be propagated to the next layerable in the stacking order. + + Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and + will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse + interaction (a "mouse interaction" in this context ends with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user moves the mouse while holding a mouse button, after this + layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user releases the mouse button, after this layerable has become + the mouse grabber by accepting the preceding \ref mousePressEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a startPos indicates the position where the initial \ref + mousePressEvent occured, that started the mouse interaction. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent +*/ +void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + event->ignore(); +} + +/*! + This event gets called when the user presses the mouse button a second time in a double-click, + while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a + preceding call to \ref selectTest. + + The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the + case of a double-click, the event succession is + pressEvent – releaseEvent – doubleClickEvent – releaseEvent. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). The parameter \a details contains layerable-specific details about the hit, which + were generated in the previous call to \ref selectTest. For example, One-dimensional plottables + like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as + \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c + SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). + + Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, + it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent + and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends + with the release). + + The default implementation does nothing except explicitly ignoring the event with \c + event->ignore(). + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent +*/ +void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->ignore(); +} + +/*! + This event gets called when the user turns the mouse scroll wheel while the cursor is over the + layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref + selectTest. + + The current pixel position of the cursor on the QCustomPlot widget is accessible via \c + event->pos(). + + The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for + single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may + accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has + very smooth steps or none at all, the delta may be smaller. + + The default implementation does nothing. + + \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent +*/ +void QCPLayerable::wheelEvent(QWheelEvent *event) +{ + event->ignore(); +} +/* end of 'src/layer.cpp' */ + + +/* including file 'src/axis/range.cpp', size 12221 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPRange +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPRange + \brief Represents the range an axis is encompassing. + + contains a \a lower and \a upper double value and provides convenience input, output and + modification functions. + + \see QCPAxis::setRange +*/ + +/* start of documentation of inline functions */ + +/*! \fn double QCPRange::size() const + + Returns the size of the range, i.e. \a upper-\a lower +*/ + +/*! \fn double QCPRange::center() const + + Returns the center of the range, i.e. (\a upper+\a lower)*0.5 +*/ + +/*! \fn void QCPRange::normalize() + + Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are + swapped. +*/ + +/*! \fn bool QCPRange::contains(double value) const + + Returns true when \a value lies within or exactly on the borders of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator+=(const double& value) + + Adds \a value to both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator-=(const double& value) + + Subtracts \a value from both boundaries of the range. +*/ + +/*! \fn QCPRange &QCPRange::operator*=(const double& value) + + Multiplies both boundaries of the range by \a value. +*/ + +/*! \fn QCPRange &QCPRange::operator/=(const double& value) + + Divides both boundaries of the range by \a value. +*/ + +/* end of documentation of inline functions */ + +/*! + Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller + intervals would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a minimum magnitude of roughly 1e-308. + + \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining underflowing ranges. + + \see validRange, maxRange +*/ +const double QCPRange::minRange = 1e-280; + +/*! + Maximum values (negative and positive) the range will accept in range-changing functions. + Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, + corresponding to a maximum magnitude of roughly 1e308. + + \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as + values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to + prevent axis ranges from obtaining overflowing ranges. + + \see validRange, minRange +*/ +const double QCPRange::maxRange = 1e250; + +/*! + Constructs a range with \a lower and \a upper set to zero. +*/ +QCPRange::QCPRange() : + lower(0), + upper(0) +{ +} + +/*! \overload + + Constructs a range with the specified \a lower and \a upper values. + + The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically + smaller than \a upper, they will be swapped. +*/ +QCPRange::QCPRange(double lower, double upper) : + lower(lower), + upper(upper) +{ + normalize(); +} + +/*! \overload + + Expands this range such that \a otherRange is contained in the new range. It is assumed that both + this range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, it will be replaced by the respective bound + of \a otherRange. + + If \a otherRange is already inside the current range, this function does nothing. + + \see expanded +*/ +void QCPRange::expand(const QCPRange &otherRange) +{ + if (lower > otherRange.lower || qIsNaN(lower)) + lower = otherRange.lower; + if (upper < otherRange.upper || qIsNaN(upper)) + upper = otherRange.upper; +} + +/*! \overload + + Expands this range such that \a includeCoord is contained in the new range. It is assumed that + this range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the respective bound will be set to \a + includeCoord. + + If \a includeCoord is already inside the current range, this function does nothing. + + \see expand +*/ +void QCPRange::expand(double includeCoord) +{ + if (lower > includeCoord || qIsNaN(lower)) + lower = includeCoord; + if (upper < includeCoord || qIsNaN(upper)) + upper = includeCoord; +} + + +/*! \overload + + Returns an expanded range that contains this and \a otherRange. It is assumed that both this + range and \a otherRange are normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be taken from + \a otherRange. + + \see expand +*/ +QCPRange QCPRange::expanded(const QCPRange &otherRange) const +{ + QCPRange result = *this; + result.expand(otherRange); + return result; +} + +/*! \overload + + Returns an expanded range that includes the specified \a includeCoord. It is assumed that this + range is normalized (see \ref normalize). + + If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a + includeCoord. + + \see expand +*/ +QCPRange QCPRange::expanded(double includeCoord) const +{ + QCPRange result = *this; + result.expand(includeCoord); + return result; +} + +/*! + Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a + upperBound. If possible, the size of the current range is preserved in the process. + + If the range shall only be bounded at the lower side, you can set \a upperBound to \ref + QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref + QCPRange::maxRange. +*/ +QCPRange QCPRange::bounded(double lowerBound, double upperBound) const +{ + if (lowerBound > upperBound) + qSwap(lowerBound, upperBound); + + QCPRange result(lower, upper); + if (result.lower < lowerBound) + { + result.lower = lowerBound; + result.upper = lowerBound + size(); + if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.upper = upperBound; + } else if (result.upper > upperBound) + { + result.upper = upperBound; + result.lower = upperBound - size(); + if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) + result.lower = lowerBound; + } + + return result; +} + +/*! + Returns a sanitized version of the range. Sanitized means for logarithmic scales, that + the range won't span the positive and negative sign domain, i.e. contain zero. Further + \a lower will always be numerically smaller (or equal) to \a upper. + + If the original range does span positive and negative sign domains or contains zero, + the returned range will try to approximate the original range as good as possible. + If the positive interval of the original range is wider than the negative interval, the + returned range will only contain the positive interval, with lower bound set to \a rangeFac or + \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval + is wider than the positive interval, this time by changing the \a upper bound. +*/ +QCPRange QCPRange::sanitizedForLogScale() const +{ + double rangeFac = 1e-3; + QCPRange sanitizedRange(lower, upper); + sanitizedRange.normalize(); + // can't have range spanning negative and positive values in log plot, so change range to fix it + //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) + if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) + { + // case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) + else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) + { + // case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) + { + // find out whether negative or positive interval is wider to decide which sign domain will be chosen + if (-sanitizedRange.lower > sanitizedRange.upper) + { + // negative is wider, do same as in case upper is 0 + if (-rangeFac > sanitizedRange.lower*rangeFac) + sanitizedRange.upper = -rangeFac; + else + sanitizedRange.upper = sanitizedRange.lower*rangeFac; + } else + { + // positive is wider, do same as in case lower is 0 + if (rangeFac < sanitizedRange.upper*rangeFac) + sanitizedRange.lower = rangeFac; + else + sanitizedRange.lower = sanitizedRange.upper*rangeFac; + } + } + // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && + upper < maxRange && + qAbs(lower-upper) > minRange && + qAbs(lower-upper) < maxRange && + !(lower > 0 && qIsInf(upper/lower)) && + !(upper < 0 && qIsInf(lower/upper))); +} + +/*! + \overload + Checks, whether the specified range is within valid bounds, which are defined + as QCPRange::maxRange and QCPRange::minRange. + A valid range means: + \li range bounds within -maxRange and maxRange + \li range size above minRange + \li range size below maxRange +*/ +bool QCPRange::validRange(const QCPRange &range) +{ + return (range.lower > -maxRange && + range.upper < maxRange && + qAbs(range.lower-range.upper) > minRange && + qAbs(range.lower-range.upper) < maxRange && + !(range.lower > 0 && qIsInf(range.upper/range.lower)) && + !(range.upper < 0 && qIsInf(range.lower/range.upper))); +} +/* end of 'src/axis/range.cpp' */ + + +/* including file 'src/selection.cpp', size 21906 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataRange +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataRange + \brief Describes a data range given by begin and end index + + QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index + of a contiguous set of data points. The end index points to the data point above the last data point that's part of + the data range, similarly to the nomenclature used in standard iterators. + + Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and + modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is + used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref + QCPDataSelection is thus used. + + Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, + e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref + contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be + used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding + \ref QCPDataSelection. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and + QCPDataRange. + + \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval + in floating point plot coordinates, e.g. the current axis range. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataRange::size() const + + Returns the number of data points described by this data range. This is equal to the end index + minus the begin index. + + \see length +*/ + +/*! \fn int QCPDataRange::length() const + + Returns the number of data points described by this data range. Equivalent to \ref size. +*/ + +/*! \fn void QCPDataRange::setBegin(int begin) + + Sets the begin of this data range. The \a begin index points to the first data point that is part + of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setEnd +*/ + +/*! \fn void QCPDataRange::setEnd(int end) + + Sets the end of this data range. The \a end index points to the data point just above the last + data point that is part of the data range. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). + + \see setBegin +*/ + +/*! \fn bool QCPDataRange::isValid() const + + Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and + an end index greater or equal to the begin index. + + \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods + (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's + methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary + invalid begin/end values while manipulating the range. An invalid range is not necessarily empty + (\ref isEmpty), since its \ref length can be negative and thus non-zero. +*/ + +/*! \fn bool QCPDataRange::isEmpty() const + + Returns whether this range is empty, i.e. whether its begin index equals its end index. + + \see size, length +*/ + +/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const + + Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end + indices, respectively. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataRange, with begin and end set to 0. +*/ +QCPDataRange::QCPDataRange() : + mBegin(0), + mEnd(0) +{ +} + +/*! + Creates a QCPDataRange, initialized with the specified \a begin and \a end. + + No checks or corrections are made to ensure the resulting range is valid (\ref isValid). +*/ +QCPDataRange::QCPDataRange(int begin, int end) : + mBegin(begin), + mEnd(end) +{ +} + +/*! + Returns a data range that matches this data range, except that parts exceeding \a other are + excluded. + + This method is very similar to \ref intersection, with one distinction: If this range and the \a + other range share no intersection, the returned data range will be empty with begin and end set + to the respective boundary side of \a other, at which this range is residing. (\ref intersection + would just return a range with begin and end set to 0.) +*/ +QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const +{ + QCPDataRange result(intersection(other)); + if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value + { + if (mEnd <= other.mBegin) + result = QCPDataRange(other.mBegin, other.mBegin); + else + result = QCPDataRange(other.mEnd, other.mEnd); + } + return result; +} + +/*! + Returns a data range that contains both this data range as well as \a other. +*/ +QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const +{ + return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); +} + +/*! + Returns the data range which is contained in both this data range and \a other. + + This method is very similar to \ref bounded, with one distinction: If this range and the \a other + range share no intersection, the returned data range will be empty with begin and end set to 0. + (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, + depending on which side this range is on.) + + \see QCPDataSelection::intersection +*/ +QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const +{ + QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); + if (result.isValid()) + return result; + else + return QCPDataRange(); +} + +/*! + Returns whether this data range and \a other share common data points. + + \see intersection, contains +*/ +bool QCPDataRange::intersects(const QCPDataRange &other) const +{ + return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || + (mEnd <= other.mBegin && mEnd < other.mEnd) ); +} + +/*! + Returns whether all data points described by this data range are also in \a other. + + \see intersects +*/ +bool QCPDataRange::contains(const QCPDataRange &other) const +{ + return mBegin <= other.mBegin && mEnd >= other.mEnd; +} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPDataSelection +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPDataSelection + \brief Describes a data set by holding multiple QCPDataRange instances + + QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly + disjoint) set of data selection. + + The data selection can be modified with addition and subtraction operators which take + QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and + \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. + + The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange + instances. QCPDataSelection automatically simplifies when using the addition/subtraction + operators. The only case when \ref simplify is left to the user, is when calling \ref + addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data + ranges will be added to the selection successively and the overhead for simplifying after each + iteration shall be avoided. In this case, you should make sure to call \ref simplify after + completing the operation. + + Use \ref enforceType to bring the data selection into a state complying with the constraints for + selections defined in \ref QCP::SelectionType. + + %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and + QCPDataRange. + + \section qcpdataselection-iterating Iterating over a data selection + + As an example, the following code snippet calculates the average value of a graph's data + \ref QCPAbstractPlottable::selection "selection": + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 + +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPDataSelection::dataRangeCount() const + + Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref + dataRange via their index. + + \see dataRange, dataPointCount +*/ + +/*! \fn QList QCPDataSelection::dataRanges() const + + Returns all data ranges that make up the data selection. If the data selection is simplified (the + usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point + index. + + \see dataRange +*/ + +/*! \fn bool QCPDataSelection::isEmpty() const + + Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection + instance. + + \see dataRangeCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an empty QCPDataSelection. +*/ +QCPDataSelection::QCPDataSelection() +{ +} + +/*! + Creates a QCPDataSelection containing the provided \a range. +*/ +QCPDataSelection::QCPDataSelection(const QCPDataRange &range) +{ + mDataRanges.append(range); +} + +/*! + Returns true if this selection is identical (contains the same data ranges with the same begin + and end indices) to \a other. + + Note that both data selections must be in simplified state (the usual state of the selection, see + \ref simplify) for this operator to return correct results. +*/ +bool QCPDataSelection::operator==(const QCPDataSelection &other) const +{ + if (mDataRanges.size() != other.mDataRanges.size()) + return false; + for (int i=0; i= other.end()) + break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this + + if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored + { + if (thisBegin >= other.begin()) // range leading segment is encompassed + { + if (thisEnd <= other.end()) // range fully encompassed, remove completely + { + mDataRanges.removeAt(i); + continue; + } else // only leading segment is encompassed, trim accordingly + mDataRanges[i].setBegin(other.end()); + } else // leading segment is not encompassed + { + if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly + { + mDataRanges[i].setEnd(other.begin()); + } else // other lies inside this range, so split range + { + mDataRanges[i].setEnd(other.begin()); + mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); + break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here + } + } + } + ++i; + } + + return *this; +} + +/*! + Returns the total number of data points contained in all data ranges that make up this data + selection. +*/ +int QCPDataSelection::dataPointCount() const +{ + int result = 0; + for (int i=0; i= 0 && index < mDataRanges.size()) + { + return mDataRanges.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of range:" << index; + return QCPDataRange(); + } +} + +/*! + Returns a \ref QCPDataRange which spans the entire data selection, including possible + intermediate segments which are not part of the original data selection. +*/ +QCPDataRange QCPDataSelection::span() const +{ + if (isEmpty()) + return QCPDataRange(); + else + return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); +} + +/*! + Adds the given \a dataRange to this data selection. This is equivalent to the += operator but + allows disabling immediate simplification by setting \a simplify to false. This can improve + performance if adding a very large amount of data ranges successively. In this case, make sure to + call \ref simplify manually, after the operation. +*/ +void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) +{ + mDataRanges.append(dataRange); + if (simplify) + this->simplify(); +} + +/*! + Removes all data ranges. The data selection then contains no data points. + + \ref isEmpty +*/ +void QCPDataSelection::clear() +{ + mDataRanges.clear(); +} + +/*! + Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent + or overlapping ranges. This can reduce the number of individual data ranges in the selection, and + prevents possible double-counting when iterating over the data points held by the data ranges. + + This method is automatically called when using the addition/subtraction operators. The only case + when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a + simplify explicitly set to false. +*/ +void QCPDataSelection::simplify() +{ + // remove any empty ranges: + for (int i=mDataRanges.size()-1; i>=0; --i) + { + if (mDataRanges.at(i).isEmpty()) + mDataRanges.removeAt(i); + } + if (mDataRanges.isEmpty()) + return; + + // sort ranges by starting value, ascending: + std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); + + // join overlapping/contiguous ranges: + int i = 1; + while (i < mDataRanges.size()) + { + if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list + { + mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); + mDataRanges.removeAt(i); + } else + ++i; + } +} + +/*! + Makes sure this data selection conforms to the specified \a type selection type. Before the type + is enforced, \ref simplify is called. + + Depending on \a type, enforcing means adding new data points that were previously not part of the + selection, or removing data points from the selection. If the current selection already conforms + to \a type, the data selection is not changed. + + \see QCP::SelectionType +*/ +void QCPDataSelection::enforceType(QCP::SelectionType type) +{ + simplify(); + switch (type) + { + case QCP::stNone: + { + mDataRanges.clear(); + break; + } + case QCP::stWhole: + { + // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) + break; + } + case QCP::stSingleData: + { + // reduce all data ranges to the single first data point: + if (!mDataRanges.isEmpty()) + { + if (mDataRanges.size() > 1) + mDataRanges = QList() << mDataRanges.first(); + if (mDataRanges.first().length() > 1) + mDataRanges.first().setEnd(mDataRanges.first().begin()+1); + } + break; + } + case QCP::stDataRange: + { + mDataRanges = QList() << span(); + break; + } + case QCP::stMultipleDataRanges: + { + // this is the selection type that allows all concievable combinations of ranges, so do nothing + break; + } + } +} + +/*! + Returns true if the data selection \a other is contained entirely in this data selection, i.e. + all data point indices that are in \a other are also in this data selection. + + \see QCPDataRange::contains +*/ +bool QCPDataSelection::contains(const QCPDataSelection &other) const +{ + if (other.isEmpty()) return false; + + int otherIndex = 0; + int thisIndex = 0; + while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) + { + if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) + ++otherIndex; + else + ++thisIndex; + } + return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this +} + +/*! + Returns a data selection containing the points which are both in this data selection and in the + data range \a other. + + A common use case is to limit an unknown data selection to the valid range of a data container, + using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned + data selection without exceeding the data container's bounds. +*/ +QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const +{ + QCPDataSelection result; + for (int i=0; iorientation() == Qt::Horizontal) + return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); + else + return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); + } else + { + qDebug() << Q_FUNC_INFO << "called with axis zero"; + return QCPRange(); + } +} + +/*! + Sets the pen that will be used to draw the selection rect outline. + + \see setBrush +*/ +void QCPSelectionRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used to fill the selection rect. By default the selection rect is not + filled, i.e. \a brush is Qt::NoBrush. + + \see setPen +*/ +void QCPSelectionRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + If there is currently a selection interaction going on (\ref isActive), the interaction is + canceled. The selection rect will emit the \ref canceled signal. +*/ +void QCPSelectionRect::cancel() +{ + if (mActive) + { + mActive = false; + Q_EMIT canceled(mRect, 0); + } +} + +/*! \internal + + This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. + The default implementation sets the selection rect to active, initializes the selection rect + geometry and emits the \ref started signal. +*/ +void QCPSelectionRect::startSelection(QMouseEvent *event) +{ + mActive = true; + mRect = QRect(event->pos(), event->pos()); + Q_EMIT started(event); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs + to update its geometry. The default implementation updates the rect and emits the \ref changed + signal. +*/ +void QCPSelectionRect::moveSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + Q_EMIT changed(mRect, event); + layer()->replot(); +} + +/*! \internal + + This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has + finished by the user releasing the mouse button. The default implementation deactivates the + selection rect and emits the \ref accepted signal. +*/ +void QCPSelectionRect::endSelection(QMouseEvent *event) +{ + mRect.setBottomRight(event->pos()); + mActive = false; + Q_EMIT accepted(mRect, event); +} + +/*! \internal + + This method is called by QCustomPlot when a key has been pressed by the user while the selection + rect interaction is active. The default implementation allows to \ref cancel the interaction by + hitting the escape key. +*/ +void QCPSelectionRect::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape && mActive) + { + mActive = false; + Q_EMIT canceled(mRect, event); + } +} + +/* inherits documentation from base class */ +void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/*! \internal + + If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. + + \seebaseclassmethod +*/ +void QCPSelectionRect::draw(QCPPainter *painter) +{ + if (mActive) + { + painter->setPen(mPen); + painter->setBrush(mBrush); + painter->drawRect(mRect); + } +} +/* end of 'src/selectionrect.cpp' */ + + +/* including file 'src/layout.cpp', size 79064 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPMarginGroup +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPMarginGroup + \brief A margin group allows synchronization of margin sides if working with multiple layout elements. + + QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that + they will all have the same size, based on the largest required margin in the group. + + \n + \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" + \n + + In certain situations it is desirable that margins at specific sides are synchronized across + layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will + provide a cleaner look to the user if the left and right margins of the two axis rects are of the + same size. The left axis of the top axis rect will then be at the same horizontal position as the + left axis of the lower axis rect, making them appear aligned. The same applies for the right + axes. This is what QCPMarginGroup makes possible. + + To add/remove a specific side of a layout element to/from a margin group, use the \ref + QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call + \ref clear, or just delete the margin group. + + \section QCPMarginGroup-example Example + + First create a margin group: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 + Then set this group on the layout element sides: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 + Here, we've used the first two axis rects of the plot and synchronized their left margins with + each other and their right margins with each other. +*/ + +/* start documentation of inline functions */ + +/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const + + Returns a list of all layout elements that have their margin \a side associated with this margin + group. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPMarginGroup instance in \a parentPlot. +*/ +QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot) +{ + mChildren.insert(QCP::msLeft, QList()); + mChildren.insert(QCP::msRight, QList()); + mChildren.insert(QCP::msTop, QList()); + mChildren.insert(QCP::msBottom, QList()); +} + +QCPMarginGroup::~QCPMarginGroup() +{ + clear(); +} + +/*! + Returns whether this margin group is empty. If this function returns true, no layout elements use + this margin group to synchronize margin sides. +*/ +bool QCPMarginGroup::isEmpty() const +{ + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + if (!it.value().isEmpty()) + return false; + } + return true; +} + +/*! + Clears this margin group. The synchronization of the margin sides that use this margin group is + lifted and they will use their individual margin sizes again. +*/ +void QCPMarginGroup::clear() +{ + // make all children remove themselves from this margin group: + QHashIterator > it(mChildren); + while (it.hasNext()) + { + it.next(); + const QList elements = it.value(); + for (int i=elements.size()-1; i>=0; --i) + elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild + } +} + +/*! \internal + + Returns the synchronized common margin for \a side. This is the margin value that will be used by + the layout element on the respective side, if it is part of this margin group. + + The common margin is calculated by requesting the automatic margin (\ref + QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin + group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into + account, too.) +*/ +int QCPMarginGroup::commonMargin(QCP::MarginSide side) const +{ + // query all automatic margins of the layout elements in this margin group side and find maximum: + int result = 0; + const QList elements = mChildren.value(side); + for (int i=0; iautoMargins().testFlag(side)) + continue; + int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); + if (m > result) + result = m; + } + return result; +} + +/*! \internal + + Adds \a element to the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].contains(element)) + mChildren[side].append(element); + else + qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); +} + +/*! \internal + + Removes \a element from the internal list of child elements, for the margin \a side. + + This function does not modify the margin group property of \a element. +*/ +void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) +{ + if (!mChildren[side].removeOne(element)) + qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutElement + \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". + + This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. + + A Layout element is a rectangular object which can be placed in layouts. It has an outer rect + (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference + between outer and inner rect is called its margin. The margin can either be set to automatic or + manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be + set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, + the layout element subclass will control the value itself (via \ref calculateAutoMargin). + + Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level + layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref + QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. + + Thus in QCustomPlot one can divide layout elements into two categories: The ones that are + invisible by themselves, because they don't draw anything. Their only purpose is to manage the + position and size of other layout elements. This category of layout elements usually use + QCPLayout as base class. Then there is the category of layout elements which actually draw + something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does + not necessarily mean that the latter category can't have child layout elements. QCPLegend for + instance, actually derives from QCPLayoutGrid and the individual legend items are child layout + elements in the grid layout. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayout *QCPLayoutElement::layout() const + + Returns the parent layout of this layout element. +*/ + +/*! \fn QRect QCPLayoutElement::rect() const + + Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref + setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). + + In some cases, the area between outer and inner rect is left blank. In other cases the margin + area is used to display peripheral graphics while the main content is in the inner rect. This is + where automatic margin calculation becomes interesting because it allows the layout element to + adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect + draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if + \ref setAutoMargins is enabled) according to the space required by the labels of the axes. + + \see outerRect +*/ + +/*! \fn QRect QCPLayoutElement::outerRect() const + + Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the + margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref + setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. + + \see rect +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutElement and sets default values. +*/ +QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) + mParentLayout(0), + mMinimumSize(), + mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), + mSizeConstraintRect(scrInnerRect), + mRect(0, 0, 0, 0), + mOuterRect(0, 0, 0, 0), + mMargins(0, 0, 0, 0), + mMinimumMargins(0, 0, 0, 0), + mAutoMargins(QCP::msAll) +{ +} + +QCPLayoutElement::~QCPLayoutElement() +{ + setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any + // unregister at layout: + if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor + mParentLayout->take(this); +} + +/*! + Sets the outer rect of this layout element. If the layout element is inside a layout, the layout + sets the position and size of this layout element using this function. + + Calling this function externally has no effect, since the layout will overwrite any changes to + the outer rect upon the next replot. + + The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. + + \see rect +*/ +void QCPLayoutElement::setOuterRect(const QRect &rect) +{ + if (mOuterRect != rect) + { + mOuterRect = rect; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all + sides, this function is used to manually set the margin on those sides. Sides that are still set + to be handled automatically are ignored and may have any value in \a margins. + + The margin is the distance between the outer rect (controlled by the parent layout via \ref + setOuterRect) and the inner \ref rect (which usually contains the main content of this layout + element). + + \see setAutoMargins +*/ +void QCPLayoutElement::setMargins(const QMargins &margins) +{ + if (mMargins != margins) + { + mMargins = margins; + mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + } +} + +/*! + If \ref setAutoMargins is enabled on some or all margins, this function is used to provide + minimum values for those margins. + + The minimum values are not enforced on margin sides that were set to be under manual control via + \ref setAutoMargins. + + \see setAutoMargins +*/ +void QCPLayoutElement::setMinimumMargins(const QMargins &margins) +{ + if (mMinimumMargins != margins) + { + mMinimumMargins = margins; + } +} + +/*! + Sets on which sides the margin shall be calculated automatically. If a side is calculated + automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is + set to be controlled manually, the value may be specified with \ref setMargins. + + Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref + setMarginGroup), to synchronize (align) it with other layout elements in the plot. + + \see setMinimumMargins, setMargins, QCP::MarginSide +*/ +void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) +{ + mAutoMargins = sides; +} + +/*! + Sets the minimum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + If the parent layout size is not sufficient to satisfy all minimum size constraints of its child + layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot + propagates the layout's size constraints to the outside by setting its own minimum QWidget size + accordingly, so violations of \a size should be exceptions. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(const QSize &size) +{ + if (mMinimumSize != size) + { + mMinimumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the minimum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMinimumSize(int width, int height) +{ + setMinimumSize(QSize(width, height)); +} + +/*! + Sets the maximum size of this layout element. A parent layout tries to respect the \a size here + by changing row/column sizes in the layout accordingly. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(const QSize &size) +{ + if (mMaximumSize != size) + { + mMaximumSize = size; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! \overload + + Sets the maximum size of this layout element. + + Whether this constraint applies to the inner or the outer rect can be specified with \ref + setSizeConstraintRect (see \ref rect and \ref outerRect). +*/ +void QCPLayoutElement::setMaximumSize(int width, int height) +{ + setMaximumSize(QSize(width, height)); +} + +/*! + Sets to which rect of a layout element the size constraints apply. Size constraints can be set + via \ref setMinimumSize and \ref setMaximumSize. + + The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis + labels), whereas the inner rect (\ref rect) does not. + + \see setMinimumSize, setMaximumSize +*/ +void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) +{ + if (mSizeConstraintRect != constraintRect) + { + mSizeConstraintRect = constraintRect; + if (mParentLayout) + mParentLayout->sizeConstraintsChanged(); + } +} + +/*! + Sets the margin \a group of the specified margin \a sides. + + Margin groups allow synchronizing specified margins across layout elements, see the documentation + of \ref QCPMarginGroup. + + To unset the margin group of \a sides, set \a group to 0. + + Note that margin groups only work for margin sides that are set to automatic (\ref + setAutoMargins). + + \see QCP::MarginSide +*/ +void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) +{ + QVector sideVector; + if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); + if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); + if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); + if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); + + for (int i=0; iremoveChild(side, this); + + if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there + { + mMarginGroups.remove(side); + } else // setting to a new group + { + mMarginGroups[side] = group; + group->addChild(side, this); + } + } + } +} + +/*! + Updates the layout element and sub-elements. This function is automatically called before every + replot by the parent layout element. It is called multiple times, once for every \ref + UpdatePhase. The phases are run through in the order of the enum values. For details about what + happens at the different phases, see the documentation of \ref UpdatePhase. + + Layout elements that have child elements should call the \ref update method of their child + elements, and pass the current \a phase unchanged. + + The default implementation executes the automatic margin mechanism in the \ref upMargins phase. + Subclasses should make sure to call the base class implementation. +*/ +void QCPLayoutElement::update(UpdatePhase phase) +{ + if (phase == upMargins) + { + if (mAutoMargins != QCP::msNone) + { + // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: + QMargins newMargins = mMargins; + QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; + Q_FOREACH (QCP::MarginSide side, allMarginSides) + { + if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically + { + if (mMarginGroups.contains(side)) + QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group + else + QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly + // apply minimum margin restrictions: + if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) + QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); + } + } + setMargins(newMargins); + } + } +} + +/*! + Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, + if no manual minimum size is set. + + if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size + (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum + allowed size of this layout element. + + A manual minimum size is considered set if it is non-zero. + + The default implementation simply returns the sum of the horizontal margins for the width and the + sum of the vertical margins for the height. Reimplementations may use their detailed knowledge + about the layout element's content to provide size hints. +*/ +QSize QCPLayoutElement::minimumOuterSizeHint() const +{ + return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); +} + +/*! + Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, + if no manual maximum size is set. + + if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned + size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the + maximum allowed size of this layout element. + + A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. + + The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying + no suggested maximum size. Reimplementations may use their detailed knowledge about the layout + element's content to provide size hints. +*/ +QSize QCPLayoutElement::maximumOuterSizeHint() const +{ + return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +} + +/*! + Returns a list of all child elements in this layout element. If \a recursive is true, all + sub-child elements are included in the list, too. + + \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have + empty cells which yield 0 at the respective index.) +*/ +QList QCPLayoutElement::elements(bool recursive) const +{ + Q_UNUSED(recursive) + return QList(); +} + +/*! + Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer + rect, this method returns a value corresponding to 0.99 times the parent plot's selection + tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is + true, -1.0 is returned. + + See \ref QCPLayerable::selectTest for a general explanation of this virtual method. + + QCPLayoutElement subclasses may reimplement this method to provide more specific selection test + behaviour. +*/ +double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + + if (onlySelectable) + return -1; + + if (QRectF(mOuterRect).contains(pos)) + { + if (mParentPlot) + return mParentPlot->selectionTolerance()*0.99; + else + { + qDebug() << Q_FUNC_INFO << "parent plot not defined"; + return -1; + } + } else + return -1; +} + +/*! \internal + + propagates the parent plot initialization to all child elements, by calling \ref + QCPLayerable::initializeParentPlot on them. +*/ +void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) +{ + Q_FOREACH (QCPLayoutElement* el, elements(false)) + { + if (!el->parentPlot()) + el->initializeParentPlot(parentPlot); + } +} + +/*! \internal + + Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a + side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the + returned value will not be smaller than the specified minimum margin. + + The default implementation just returns the respective manual margin (\ref setMargins) or the + minimum margin, whichever is larger. +*/ +int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) +{ + return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); +} + +/*! \internal + + This virtual method is called when this layout element was moved to a different QCPLayout, or + when this layout element has changed its logical position (e.g. row and/or column) within the + same QCPLayout. Subclasses may use this to react accordingly. + + Since this method is called after the completion of the move, you can access the new parent + layout via \ref layout(). + + The default implementation does nothing. +*/ +void QCPLayoutElement::layoutChanged() +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayout +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayout + \brief The abstract base class for layouts + + This is an abstract base class for layout elements whose main purpose is to define the position + and size of other child layout elements. In most cases, layouts don't draw anything themselves + (but there are exceptions to this, e.g. QCPLegend). + + QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. + + QCPLayout introduces a common interface for accessing and manipulating the child elements. Those + functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref + simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions + to this interface which are more specialized to the form of the layout. For example, \ref + QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid + more conveniently. + + Since this is an abstract base class, you can't instantiate it directly. Rather use one of its + subclasses like QCPLayoutGrid or QCPLayoutInset. + + For a general introduction to the layout system, see the dedicated documentation page \ref + thelayoutsystem "The Layout System". +*/ + +/* start documentation of pure virtual functions */ + +/*! \fn virtual int QCPLayout::elementCount() const = 0 + + Returns the number of elements/cells in the layout. + + \see elements, elementAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 + + Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. + + Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. + QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check + whether a cell is empty or not. + + \see elements, elementCount, takeAt +*/ + +/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 + + Removes the element with the given \a index from the layout and returns it. + + If the \a index is invalid or the cell with that index is empty, returns 0. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see elementAt, take +*/ + +/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 + + Removes the specified \a element from the layout and returns true on success. + + If the \a element isn't in this layout, returns false. + + Note that some layouts don't remove the respective cell right away but leave an empty cell after + successful removal of the layout element. To collapse empty cells, use \ref simplify. + + \see takeAt +*/ + +/* end documentation of pure virtual functions */ + +/*! + Creates an instance of QCPLayout and sets default values. Note that since QCPLayout + is an abstract base class, it can't be instantiated directly. +*/ +QCPLayout::QCPLayout() +{ +} + +/*! + If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to + reposition and resize their cells. + + Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". + + For details about this method and the update phases, see the documentation of \ref + QCPLayoutElement::update. +*/ +void QCPLayout::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + // set child element rects according to layout: + if (phase == upLayout) + updateLayout(); + + // propagate update call to child elements: + const int elCount = elementCount(); + for (int i=0; iupdate(phase); + } +} + +/* inherits documentation from base class */ +QList QCPLayout::elements(bool recursive) const +{ + const int c = elementCount(); + QList result; +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(c); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the + default implementation does nothing. + + Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit + simplification while QCPLayoutGrid does. +*/ +void QCPLayout::simplify() +{ +} + +/*! + Removes and deletes the element at the provided \a index. Returns true on success. If \a index is + invalid or points to an empty cell, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the returned element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see remove, takeAt +*/ +bool QCPLayout::removeAt(int index) +{ + if (QCPLayoutElement *el = takeAt(index)) + { + delete el; + return true; + } else + return false; +} + +/*! + Removes and deletes the provided \a element. Returns true on success. If \a element is not in the + layout, returns false. + + This function internally uses \ref takeAt to remove the element from the layout and then deletes + the element. Note that some layouts don't remove the respective cell right away but leave an + empty cell after successful removal of the layout element. To collapse empty cells, use \ref + simplify. + + \see removeAt, take +*/ +bool QCPLayout::remove(QCPLayoutElement *element) +{ + if (take(element)) + { + delete element; + return true; + } else + return false; +} + +/*! + Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure + all empty cells are collapsed. + + \see remove, removeAt +*/ +void QCPLayout::clear() +{ + for (int i=elementCount()-1; i>=0; --i) + { + if (elementAt(i)) + removeAt(i); + } + simplify(); +} + +/*! + Subclasses call this method to report changed (minimum/maximum) size constraints. + + If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref + sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of + QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, + it may update itself and resize cells accordingly. +*/ +void QCPLayout::sizeConstraintsChanged() const +{ + if (QWidget *w = qobject_cast(parent())) + w->updateGeometry(); + else if (QCPLayout *l = qobject_cast(parent())) + l->sizeConstraintsChanged(); +} + +/*! \internal + + Subclasses reimplement this method to update the position and sizes of the child elements/cells + via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. + + The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay + within that rect. + + \ref getSectionSizes may help with the reimplementation of this function. + + \see update +*/ +void QCPLayout::updateLayout() +{ +} + + +/*! \internal + + Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the + \ref QCPLayerable::parentLayerable and the QObject parent to this layout. + + Further, if \a el didn't previously have a parent plot, calls \ref + QCPLayerable::initializeParentPlot on \a el to set the paret plot. + + This method is used by subclass specific methods that add elements to the layout. Note that this + method only changes properties in \a el. The removal from the old layout and the insertion into + the new layout must be done additionally. +*/ +void QCPLayout::adoptElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = this; + el->setParentLayerable(this); + el->setParent(this); + if (!el->parentPlot()) + el->initializeParentPlot(mParentPlot); + el->layoutChanged(); + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout + and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent + QCustomPlot. + + This method is used by subclass specific methods that remove elements from the layout (e.g. \ref + take or \ref takeAt). Note that this method only changes properties in \a el. The removal from + the old layout must be done additionally. +*/ +void QCPLayout::releaseElement(QCPLayoutElement *el) +{ + if (el) + { + el->mParentLayout = 0; + el->setParentLayerable(0); + el->setParent(mParentPlot); + // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot + } else + qDebug() << Q_FUNC_INFO << "Null element passed"; +} + +/*! \internal + + This is a helper function for the implementation of \ref updateLayout in subclasses. + + It calculates the sizes of one-dimensional sections with provided constraints on maximum section + sizes, minimum section sizes, relative stretch factors and the final total size of all sections. + + The QVector entries refer to the sections. Thus all QVectors must have the same size. + + \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size + imposed, set all vector values to Qt's QWIDGETSIZE_MAX. + + \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size + imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than + \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, + not exceeding the allowed total size is taken to be more important than not going below minimum + section sizes.) + + \a stretchFactors give the relative proportions of the sections to each other. If all sections + shall be scaled equally, set all values equal. If the first section shall be double the size of + each individual other section, set the first number of \a stretchFactors to double the value of + the other individual values (e.g. {2, 1, 1, 1}). + + \a totalSize is the value that the final section sizes will add up to. Due to rounding, the + actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, + you could distribute the remaining difference on the sections. + + The return value is a QVector containing the section sizes. +*/ +QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const +{ + if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) + { + qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; + return QVector(); + } + if (stretchFactors.isEmpty()) + return QVector(); + int sectionCount = stretchFactors.size(); + QVector sectionSizes(sectionCount); + // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): + int minSizeSum = 0; + for (int i=0; i minimumLockedSections; + QList unfinishedSections; + for (int i=0; i result(sectionCount); + for (int i=0; iminimumOuterSizeHint(); + QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) + if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rwidth() += el->margins().left() + el->margins().right(); + if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + minOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; +} + +/*! \internal + + This is a helper function for the implementation of subclasses. + + It returns the maximum size that should finally be used for the outer rect of the passed layout + element \a el. + + It takes into account whether a manual maximum size is set (\ref + QCPLayoutElement::setMaximumSize), which size constraint is set (\ref + QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum + size was set (\ref QCPLayoutElement::maximumOuterSizeHint). +*/ +QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) +{ + QSize maxOuterHint = el->maximumOuterSizeHint(); + QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) + if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rwidth() += el->margins().left() + el->margins().right(); + if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + maxOuter.rheight() += el->margins().top() + el->margins().bottom(); + + return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLayoutGrid + \brief A layout that arranges child elements in a grid + + Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, + \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). + + Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or + column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref + hasElement, that element can be retrieved with \ref element. If rows and columns that only have + empty cells shall be removed, call \ref simplify. Removal of elements is either done by just + adding the element to a different layout or by using the QCPLayout interface \ref take or \ref + remove. + + If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a + column, the grid layout will choose the position according to the current \ref setFillOrder and + the wrapping (\ref setWrap). + + Row and column insertion can be performed with \ref insertRow and \ref insertColumn. +*/ + +/* start documentation of inline functions */ + +/*! \fn int QCPLayoutGrid::rowCount() const + + Returns the number of rows in the layout. + + \see columnCount +*/ + +/*! \fn int QCPLayoutGrid::columnCount() const + + Returns the number of columns in the layout. + + \see rowCount +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutGrid and sets default values. +*/ +QCPLayoutGrid::QCPLayoutGrid() : + mColumnSpacing(5), + mRowSpacing(5), + mWrap(0), + mFillOrder(foRowsFirst) +{ +} + +QCPLayoutGrid::~QCPLayoutGrid() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the element in the cell in \a row and \a column. + + Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug + message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. + + \see addElement, hasElement +*/ +QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const +{ + if (row >= 0 && row < mElements.size()) + { + if (column >= 0 && column < mElements.first().size()) + { + if (QCPLayoutElement *result = mElements.at(row).at(column)) + return result; + else + qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; + } else + qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; + return 0; +} + + +/*! \overload + + Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it + is first removed from there. If \a row or \a column don't exist yet, the layout is expanded + accordingly. + + Returns true if the element was added successfully, i.e. if the cell at \a row and \a column + didn't already have an element. + + Use the overload of this method without explicit row/column index to place the element according + to the configured fill order and wrapping settings. + + \see element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) +{ + if (!hasElement(row, column)) + { + if (element && element->layout()) // remove from old layout first + element->layout()->take(element); + expandTo(row+1, column+1); + mElements[row][column] = element; + if (element) + adoptElement(element); + return true; + } else + qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; + return false; +} + +/*! \overload + + Adds the \a element to the next empty cell according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first + removed from there. If necessary, the layout is expanded to hold the new element. + + Returns true if the element was added successfully. + + \see setFillOrder, setWrap, element, hasElement, take, remove +*/ +bool QCPLayoutGrid::addElement(QCPLayoutElement *element) +{ + int rowIndex = 0; + int colIndex = 0; + if (mFillOrder == foColumnsFirst) + { + while (hasElement(rowIndex, colIndex)) + { + ++colIndex; + if (colIndex >= mWrap && mWrap > 0) + { + colIndex = 0; + ++rowIndex; + } + } + } else + { + while (hasElement(rowIndex, colIndex)) + { + ++rowIndex; + if (rowIndex >= mWrap && mWrap > 0) + { + rowIndex = 0; + ++colIndex; + } + } + } + return addElement(rowIndex, colIndex, element); +} + +/*! + Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't + empty. + + \see element +*/ +bool QCPLayoutGrid::hasElement(int row, int column) +{ + if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) + return mElements.at(row).at(column); + else + return false; +} + +/*! + Sets the stretch \a factor of \a column. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactors, setRowStretchFactor +*/ +void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) +{ + if (column >= 0 && column < columnCount()) + { + if (factor > 0) + mColumnStretchFactors[column] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid column:" << column; +} + +/*! + Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setColumnStretchFactor, setRowStretchFactors +*/ +void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) +{ + if (factors.size() == mColumnStretchFactors.size()) + { + mColumnStretchFactors = factors; + for (int i=0; i= 0 && row < rowCount()) + { + if (factor > 0) + mRowStretchFactors[row] = factor; + else + qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; + } else + qDebug() << Q_FUNC_INFO << "Invalid row:" << row; +} + +/*! + Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. + + Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond + their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref + QCPLayoutElement::setSizeConstraintRect.) + + The default stretch factor of newly created rows/columns is 1. + + \see setRowStretchFactor, setColumnStretchFactors +*/ +void QCPLayoutGrid::setRowStretchFactors(const QList &factors) +{ + if (factors.size() == mRowStretchFactors.size()) + { + mRowStretchFactors = factors; + for (int i=0; i tempElements; + if (rearrange) + { + tempElements.reserve(elCount); + for (int i=0; i()); + mRowStretchFactors.append(1); + } + // go through rows and expand columns as necessary: + int newColCount = qMax(columnCount(), newColumnCount); + for (int i=0; i rowCount()) + newIndex = rowCount(); + + mRowStretchFactors.insert(newIndex, 1); + QList newRow; + for (int col=0; col columnCount()) + newIndex = columnCount(); + + mColumnStretchFactors.insert(newIndex, 1); + for (int row=0; row= 0 && row < rowCount()) + { + if (column >= 0 && column < columnCount()) + { + switch (mFillOrder) + { + case foRowsFirst: return column*rowCount() + row; + case foColumnsFirst: return row*columnCount() + column; + } + } else + qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; + } else + qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; + return 0; +} + +/*! + Converts the linear index to row and column indices and writes the result to \a row and \a + column. + + The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the + indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices + increase top to bottom and then left to right. + + If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. + + For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, + i.e. greater or equal to zero and smaller than the current \ref elementCount. + + \see rowColToIndex +*/ +void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const +{ + row = -1; + column = -1; + const int nCols = columnCount(); + const int nRows = rowCount(); + if (nCols == 0 || nRows == 0) + return; + if (index < 0 || index >= elementCount()) + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return; + } + + switch (mFillOrder) + { + case foRowsFirst: + { + column = index / nRows; + row = index % nRows; + break; + } + case foColumnsFirst: + { + row = index / nCols; + column = index % nCols; + break; + } + } +} + +/* inherits documentation from base class */ +void QCPLayoutGrid::updateLayout() +{ + QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + int totalRowSpacing = (rowCount()-1) * mRowSpacing; + int totalColSpacing = (columnCount()-1) * mColumnSpacing; + QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); + QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); + + // go through cells and set rects accordingly: + int yOffset = mRect.top(); + for (int row=0; row 0) + yOffset += rowHeights.at(row-1)+mRowSpacing; + int xOffset = mRect.left(); + for (int col=0; col 0) + xOffset += colWidths.at(col-1)+mColumnSpacing; + if (mElements.at(row).at(col)) + mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); + } + } +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const +{ + if (index >= 0 && index < elementCount()) + { + int row, col; + indexToRowCol(index, row, col); + return mElements.at(row).at(col); + } else + return 0; +} + +/*! + \seebaseclassmethod + + Note that the association of the linear \a index to the row/column based cells depends on the + current setting of \ref setFillOrder. + + \see rowColToIndex +*/ +QCPLayoutElement *QCPLayoutGrid::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + int row, col; + indexToRowCol(index, row, col); + mElements[row][col] = 0; + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutGrid::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; i QCPLayoutGrid::elements(bool recursive) const +{ + QList result; + const int elCount = elementCount(); +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + result.reserve(elCount); +#endif + for (int i=0; ielements(recursive); + } + } + return result; +} + +/*! + Simplifies the layout by collapsing rows and columns which only contain empty cells. +*/ +void QCPLayoutGrid::simplify() +{ + // remove rows with only empty cells: + for (int row=rowCount()-1; row>=0; --row) + { + bool hasElements = false; + for (int col=0; col=0; --col) + { + bool hasElements = false; + for (int row=0; row minColWidths, minRowHeights; + getMinimumRowColSizes(&minColWidths, &minRowHeights); + QSize result(0, 0); + for (int i=0; i maxColWidths, maxRowHeights; + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + QSize result(0, 0); + for (int i=0; i QWIDGETSIZE_MAX) + result.setHeight(QWIDGETSIZE_MAX); + if (result.width() > QWIDGETSIZE_MAX) + result.setWidth(QWIDGETSIZE_MAX); + return result; +} + +/*! \internal + + Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights + respectively. + + The minimum height of a row is the largest minimum height of any element's outer rect in that + row. The minimum width of a column is the largest minimum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMaximumRowColSizes +*/ +void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const +{ + *minColWidths = QVector(columnCount(), 0); + *minRowHeights = QVector(rowCount(), 0); + for (int row=0; rowat(col) < minSize.width()) + (*minColWidths)[col] = minSize.width(); + if (minRowHeights->at(row) < minSize.height()) + (*minRowHeights)[row] = minSize.height(); + } + } + } +} + +/*! \internal + + Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights + respectively. + + The maximum height of a row is the smallest maximum height of any element's outer rect in that + row. The maximum width of a column is the smallest maximum width of any element's outer rect in + that column. + + This is a helper function for \ref updateLayout. + + \see getMinimumRowColSizes +*/ +void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const +{ + *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); + *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); + for (int row=0; rowat(col) > maxSize.width()) + (*maxColWidths)[col] = maxSize.width(); + if (maxRowHeights->at(row) > maxSize.height()) + (*maxRowHeights)[row] = maxSize.height(); + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLayoutInset +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPLayoutInset + \brief A layout that places child elements aligned to the border or arbitrarily positioned + + Elements are placed either aligned to the border or at arbitrary position in the area of the + layout. Which placement applies is controlled with the \ref InsetPlacement (\ref + setInsetPlacement). + + Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or + addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset + placement will default to \ref ipBorderAligned and the element will be aligned according to the + \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at + arbitrary position and size, defined by \a rect. + + The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. + + This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual void QCPLayoutInset::simplify() + + The QCPInsetLayout does not need simplification since it can never have empty cells due to its + linear index structure. This method does nothing. +*/ + +/* end documentation of inline functions */ + +/*! + Creates an instance of QCPLayoutInset and sets default values. +*/ +QCPLayoutInset::QCPLayoutInset() +{ +} + +QCPLayoutInset::~QCPLayoutInset() +{ + // clear all child layout elements. This is important because only the specific layouts know how + // to handle removing elements (clear calls virtual removeAt method to do that). + clear(); +} + +/*! + Returns the placement type of the element with the specified \a index. +*/ +QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const +{ + if (elementAt(index)) + return mInsetPlacement.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return ipFree; + } +} + +/*! + Returns the alignment of the element with the specified \a index. The alignment only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. +*/ +Qt::Alignment QCPLayoutInset::insetAlignment(int index) const +{ + if (elementAt(index)) + return mInsetAlignment.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return 0; + } +} + +/*! + Returns the rect of the element with the specified \a index. The rect only has a + meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. +*/ +QRectF QCPLayoutInset::insetRect(int index) const +{ + if (elementAt(index)) + return mInsetRect.at(index); + else + { + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; + return QRectF(); + } +} + +/*! + Sets the inset placement type of the element with the specified \a index to \a placement. + + \see InsetPlacement +*/ +void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) +{ + if (elementAt(index)) + mInsetPlacement[index] = placement; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function + is used to set the alignment of the element with the specified \a index to \a alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. +*/ +void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) +{ + if (elementAt(index)) + mInsetAlignment[index] = alignment; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/*! + If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the + position and size of the element with the specified \a index to \a rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + Note that the minimum and maximum sizes of the embedded element (\ref + QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. +*/ +void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) +{ + if (elementAt(index)) + mInsetRect[index] = rect; + else + qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; +} + +/* inherits documentation from base class */ +void QCPLayoutInset::updateLayout() +{ + for (int i=0; i finalMaxSize.width()) + insetRect.setWidth(finalMaxSize.width()); + if (insetRect.size().height() > finalMaxSize.height()) + insetRect.setHeight(finalMaxSize.height()); + } else if (mInsetPlacement.at(i) == ipBorderAligned) + { + insetRect.setSize(finalMinSize); + Qt::Alignment al = mInsetAlignment.at(i); + if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); + else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); + else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter + if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); + else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); + else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter + } + mElements.at(i)->setOuterRect(insetRect); + } +} + +/* inherits documentation from base class */ +int QCPLayoutInset::elementCount() const +{ + return mElements.size(); +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::elementAt(int index) const +{ + if (index >= 0 && index < mElements.size()) + return mElements.at(index); + else + return 0; +} + +/* inherits documentation from base class */ +QCPLayoutElement *QCPLayoutInset::takeAt(int index) +{ + if (QCPLayoutElement *el = elementAt(index)) + { + releaseElement(el); + mElements.removeAt(index); + mInsetPlacement.removeAt(index); + mInsetAlignment.removeAt(index); + mInsetRect.removeAt(index); + return el; + } else + { + qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; + return 0; + } +} + +/* inherits documentation from base class */ +bool QCPLayoutInset::take(QCPLayoutElement *element) +{ + if (element) + { + for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/*! + Adds the specified \a element to the layout as an inset aligned at the border (\ref + setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a + alignment. + + \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, + Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other + alignment flags will be ignored. + + \see addElement(QCPLayoutElement *element, const QRectF &rect) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipBorderAligned); + mInsetAlignment.append(alignment); + mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} + +/*! + Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref + setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a + rect. + + \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) + will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right + corner of the layout, with 35% width and height of the parent layout. + + \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) +*/ +void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) +{ + if (element) + { + if (element->layout()) // remove from old layout first + element->layout()->take(element); + mElements.append(element); + mInsetPlacement.append(ipFree); + mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); + mInsetRect.append(rect); + adoptElement(element); + } else + qDebug() << Q_FUNC_INFO << "Can't add null element"; +} +/* end of 'src/layout.cpp' */ + + +/* including file 'src/lineending.cpp', size 11536 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLineEnding +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLineEnding + \brief Handles the different ending decorations for line-like items + + \image html QCPLineEnding.png "The various ending styles currently supported" + + For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine + has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. + + The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can + be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of + the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. + For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite + directions, e.g. "outward". This can be changed by \ref setInverted, which would make the + respective arrow point inward. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify a + QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. + \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead +*/ + +/*! + Creates a QCPLineEnding instance with default values (style \ref esNone). +*/ +QCPLineEnding::QCPLineEnding() : + mStyle(esNone), + mWidth(8), + mLength(10), + mInverted(false) +{ +} + +/*! + Creates a QCPLineEnding instance with the specified values. +*/ +QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : + mStyle(style), + mWidth(width), + mLength(length), + mInverted(inverted) +{ +} + +/*! + Sets the style of the ending decoration. +*/ +void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) +{ + mStyle = style; +} + +/*! + Sets the width of the ending decoration, if the style supports it. On arrows, for example, the + width defines the size perpendicular to the arrow's pointing direction. + + \see setLength +*/ +void QCPLineEnding::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the length of the ending decoration, if the style supports it. On arrows, for example, the + length defines the size in pointing direction. + + \see setWidth +*/ +void QCPLineEnding::setLength(double length) +{ + mLength = length; +} + +/*! + Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point + inward when \a inverted is set to true. + + Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or + discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are + affected by it, which can be used to control to which side the half bar points to. +*/ +void QCPLineEnding::setInverted(bool inverted) +{ + mInverted = inverted; +} + +/*! \internal + + Returns the maximum pixel radius the ending decoration might cover, starting from the position + the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). + + This is relevant for clipping. Only omit painting of the decoration when the position where the + decoration is supposed to be drawn is farther away from the clipping rect than the returned + distance. +*/ +double QCPLineEnding::boundingDistance() const +{ + switch (mStyle) + { + case esNone: + return 0; + + case esFlatArrow: + case esSpikeArrow: + case esLineArrow: + case esSkewedBar: + return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length + + case esDisc: + case esSquare: + case esDiamond: + case esBar: + case esHalfBar: + return mWidth*1.42; // items that only have a width -> width*sqrt(2) + + } + return 0; +} + +/*! + Starting from the origin of this line ending (which is style specific), returns the length + covered by the line ending symbol, in backward direction. + + For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if + both have the same \ref setLength value, because the spike arrow has an inward curved back, which + reduces the length along its center axis (the drawing origin for arrows is at the tip). + + This function is used for precise, style specific placement of line endings, for example in + QCPAxes. +*/ +double QCPLineEnding::realLength() const +{ + switch (mStyle) + { + case esNone: + case esLineArrow: + case esSkewedBar: + case esBar: + case esHalfBar: + return 0; + + case esFlatArrow: + return mLength; + + case esDisc: + case esSquare: + case esDiamond: + return mWidth*0.5; + + case esSpikeArrow: + return mLength*0.8; + } + return 0; +} + +/*! \internal + + Draws the line ending with the specified \a painter at the position \a pos. The direction of the + line ending is controlled with \a dir. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const +{ + if (mStyle == esNone) + return; + + QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); + if (lengthVec.isNull()) + lengthVec = QCPVector2D(1, 0); + QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); + + QPen penBackup = painter->pen(); + QBrush brushBackup = painter->brush(); + QPen miterPen = penBackup; + miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey + QBrush brush(painter->pen().color(), Qt::SolidPattern); + switch (mStyle) + { + case esNone: break; + case esFlatArrow: + { + QPointF points[3] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 3); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esSpikeArrow: + { + QPointF points[4] = {pos.toPointF(), + (pos-lengthVec+widthVec).toPointF(), + (pos-lengthVec*0.8).toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esLineArrow: + { + QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), + pos.toPointF(), + (pos-lengthVec-widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->drawPolyline(points, 3); + painter->setPen(penBackup); + break; + } + case esDisc: + { + painter->setBrush(brush); + painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); + painter->setBrush(brushBackup); + break; + } + case esSquare: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), + (pos-widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp-widthVec).toPointF(), + (pos+widthVecPerp+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esDiamond: + { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = {(pos-widthVecPerp).toPointF(), + (pos-widthVec).toPointF(), + (pos+widthVecPerp).toPointF(), + (pos+widthVec).toPointF() + }; + painter->setPen(miterPen); + painter->setBrush(brush); + painter->drawConvexPolygon(points, 4); + painter->setBrush(brushBackup); + painter->setPen(penBackup); + break; + } + case esBar: + { + painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); + break; + } + case esHalfBar: + { + painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); + break; + } + case esSkewedBar: + { + if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) + { + // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); + } else + { + // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly + painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); + } + break; + } + } +} + +/*! \internal + \overload + + Draws the line ending. The direction is controlled with the \a angle parameter in radians. +*/ +void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const +{ + draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); +} +/* end of 'src/lineending.cpp' */ + + +/* including file 'src/axis/axisticker.cpp', size 18664 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTicker +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTicker + \brief The base class tick generator used by QCPAxis to create tick positions and tick labels + + Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions + and tick labels for the current axis range. The ticker of an axis can be set via \ref + QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple + axes can share the same ticker instance. + + This base class generates normal tick coordinates and numeric labels for linear axes. It picks a + reasonable tick step (the separation between ticks) which results in readable tick labels. The + number of ticks that should be approximately generated can be set via \ref setTickCount. + Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either + sacrifices readability to better match the specified tick count (\ref + QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref + QCPAxisTicker::tssReadability), which is the default. + + The following more specialized axis ticker subclasses are available, see details in the + respective class documentation: + +
+ + + + + + + +
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png + \image html axisticker-time2.png
+
+ + \section axisticker-subclassing Creating own axis tickers + + Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and + reimplementing some or all of the available virtual methods. + + In the simplest case you might wish to just generate different tick steps than the other tickers, + so you only reimplement the method \ref getTickStep. If you additionally want control over the + string that will be shown as tick label, reimplement \ref getTickLabel. + + If you wish to have complete control, you can generate the tick vectors and tick label vectors + yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default + implementations use the previously mentioned virtual methods \ref getTickStep and \ref + getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case + of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. + + The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick + placement control is obtained by reimplementing \ref createSubTickVector. + + See the documentation of all these virtual methods in QCPAxisTicker for detailed information + about the parameters and expected return values. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTicker::QCPAxisTicker() : + mTickStepStrategy(tssReadability), + mTickCount(5), + mTickOrigin(0) +{ +} + +QCPAxisTicker::~QCPAxisTicker() +{ + +} + +/*! + Sets which strategy the axis ticker follows when choosing the size of the tick step. For the + available strategies, see \ref TickStepStrategy. +*/ +void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) +{ + mTickStepStrategy = strategy; +} + +/*! + Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count + is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with + the requested number of ticks. + + Whether the readability has priority over meeting the requested \a count can be specified with + \ref setTickStepStrategy. +*/ +void QCPAxisTicker::setTickCount(int count) +{ + if (count > 0) + mTickCount = count; + else + qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; +} + +/*! + Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a + concept and doesn't need to be inside the currently visible axis range. + + By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick + step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be + {-4, 1, 6, 11, 16,...}. +*/ +void QCPAxisTicker::setTickOrigin(double origin) +{ + mTickOrigin = origin; +} + +/*! + This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), + tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). + + The ticks are generated for the specified \a range. The generated labels typically follow the + specified \a locale, \a formatChar and number \a precision, however this might be different (or + even irrelevant) for certain QCPAxisTicker subclasses. + + The output parameter \a ticks is filled with the generated tick positions in axis coordinates. + The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) + and are respectively filled with sub tick coordinates, and tick label strings belonging to \a + ticks by index. +*/ +void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) +{ + // generate (major) ticks: + double tickStep = getTickStep(range); + ticks = createTickVector(tickStep, range); + trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) + + // generate sub ticks between major ticks: + if (subTicks) + { + if (ticks.size() > 0) + { + *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); + trimTicks(range, *subTicks, false); + } else + *subTicks = QVector(); + } + + // finally trim also outliers (no further clipping happens in axis drawing): + trimTicks(range, ticks, false); + // generate labels for visible ticks if requested: + if (tickLabels) + *tickLabels = createLabelVector(ticks, locale, formatChar, precision); +} + +/*! \internal + + Takes the entire currently visible axis range and returns a sensible tick step in + order to provide readable tick labels as well as a reasonable number of tick counts (see \ref + setTickCount, \ref setTickStepStrategy). + + If a QCPAxisTicker subclass only wants a different tick step behaviour than the default + implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper + function. +*/ +double QCPAxisTicker::getTickStep(const QCPRange &range) +{ + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return cleanMantissa(exactStep); +} + +/*! \internal + + Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns + an appropriate number of sub ticks for that specific tick step. + + Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. +*/ +int QCPAxisTicker::getSubTickCount(double tickStep) +{ + int result = 1; // default to 1, if no proper value can be found + + // separate integer and fractional part of mantissa: + double epsilon = 0.01; + double intPartf; + int intPart; + double fracPart = modf(getMantissa(tickStep), &intPartf); + intPart = intPartf; + + // handle cases with (almost) integer mantissa: + if (fracPart < epsilon || 1.0-fracPart < epsilon) + { + if (1.0-fracPart < epsilon) + ++intPart; + switch (intPart) + { + case 1: result = 4; break; // 1.0 -> 0.2 substep + case 2: result = 3; break; // 2.0 -> 0.5 substep + case 3: result = 2; break; // 3.0 -> 1.0 substep + case 4: result = 3; break; // 4.0 -> 1.0 substep + case 5: result = 4; break; // 5.0 -> 1.0 substep + case 6: result = 2; break; // 6.0 -> 2.0 substep + case 7: result = 6; break; // 7.0 -> 1.0 substep + case 8: result = 3; break; // 8.0 -> 2.0 substep + case 9: result = 2; break; // 9.0 -> 3.0 substep + } + } else + { + // handle cases with significantly fractional mantissa: + if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa + { + switch (intPart) + { + case 1: result = 2; break; // 1.5 -> 0.5 substep + case 2: result = 4; break; // 2.5 -> 0.5 substep + case 3: result = 4; break; // 3.5 -> 0.7 substep + case 4: result = 2; break; // 4.5 -> 1.5 substep + case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) + case 6: result = 4; break; // 6.5 -> 1.3 substep + case 7: result = 2; break; // 7.5 -> 2.5 substep + case 8: result = 4; break; // 8.5 -> 1.7 substep + case 9: result = 4; break; // 9.5 -> 1.9 substep + } + } + // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default + } + + return result; +} + +/*! \internal + + This method returns the tick label string as it should be printed under the \a tick coordinate. + If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a + precision. + + If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is + enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will + be formatted accordingly using multiplication symbol and superscript during rendering of the + label automatically. +*/ +QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + return locale.toString(tick, formatChar.toLatin1(), precision); +} + +/*! \internal + + Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a + subTickCount sub ticks between each tick pair given in \a ticks. + + If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should + reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to + base its result on \a subTickCount or \a ticks. +*/ +QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) +{ + QVector result; + if (subTickCount <= 0 || ticks.size() < 2) + return result; + + result.reserve((ticks.size()-1)*subTickCount); + for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result; + // Generate tick positions according to tickStep: + qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision + qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision + int tickcount = lastStep-firstStep+1; + if (tickcount < 0) tickcount = 0; + result.resize(tickcount); + for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) +{ + QVector result; + result.reserve(ticks.size()); + for (int i=0; i &ticks, bool keepOneOutlier) const +{ + bool lowFound = false; + bool highFound = false; + int lowIndex = 0; + int highIndex = -1; + + for (int i=0; i < ticks.size(); ++i) + { + if (ticks.at(i) >= range.lower) + { + lowFound = true; + lowIndex = i; + break; + } + } + for (int i=ticks.size()-1; i >= 0; --i) + { + if (ticks.at(i) <= range.upper) + { + highFound = true; + highIndex = i; + break; + } + } + + if (highFound && lowFound) + { + int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); + int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); + if (trimFront > 0 || trimBack > 0) + ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); + } else // all ticks are either all below or all above the range + ticks.clear(); +} + +/*! \internal + + Returns the coordinate contained in \a candidates which is closest to the provided \a target. + + This method assumes \a candidates is not empty and sorted in ascending order. +*/ +double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const +{ + if (candidates.size() == 1) + return candidates.first(); + QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); + if (it == candidates.constEnd()) + return *(it-1); + else if (it == candidates.constBegin()) + return *it; + else + return target-*(it-1) < *it-target ? *(it-1) : *it; +} + +/*! \internal + + Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also + returns the magnitude of \a input as a power of 10. + + For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. +*/ +double QCPAxisTicker::getMantissa(double input, double *magnitude) const +{ + const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); + if (magnitude) *magnitude = mag; + return input/mag; +} + +/*! \internal + + Returns a number that is close to \a input but has a clean, easier human readable mantissa. How + strongly the mantissa is altered, and thus how strong the result deviates from the original \a + input, depends on the current tick step strategy (see \ref setTickStepStrategy). +*/ +double QCPAxisTicker::cleanMantissa(double input) const +{ + double magnitude; + const double mantissa = getMantissa(input, &magnitude); + switch (mTickStepStrategy) + { + case tssReadability: + { + return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; + } + case tssMeetTickCount: + { + // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 + if (mantissa <= 5.0) + return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 + else + return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 + } + } + return input; +} +/* end of 'src/axis/axisticker.cpp' */ + + +/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerDateTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerDateTime + \brief Specialized axis ticker for calendar dates and times as axis ticks + + \image html axisticker-datetime.png + + This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The + plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 + UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods + with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime + by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey + and \ref keyToDateTime conveniently perform this conversion achieving a precision of one + millisecond on all Qt versions. + + The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. + If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. + + This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day + ticks. For example, if the axis range spans a few years such that there is one tick per year, + ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, + will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in + the image above: even though the number of days varies month by month, this ticker generates + ticks on the same day of each month. + + If you would like to change the date/time that is used as a (mathematical) starting date for the + ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a + QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at + 9:45 of every year. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation + + \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and + milliseconds, and are not interested in the intricacies of real calendar dates with months and + (leap) years, have a look at QCPAxisTickerTime instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerDateTime::QCPAxisTickerDateTime() : + mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), + mDateTimeSpec(Qt::LocalTime), + mDateStrategy(dsNone) +{ + setTickCount(4); +} + +/*! + Sets the format in which dates and times are displayed as tick labels. For details about the \a + format string, see the documentation of QDateTime::toString(). + + Newlines can be inserted with "\n". + + \see setDateTimeSpec +*/ +void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) +{ + mDateTimeFormat = format; +} + +/*! + Sets the time spec that is used for creating the tick labels from corresponding dates/times. + + The default value of QDateTime objects (and also QCPAxisTickerDateTime) is + Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form + of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC + to get the correct axis labels. + + \see setDateTimeFormat +*/ +void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) +{ + mDateTimeSpec = spec; +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, + 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which + directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(double origin) +{ + QCPAxisTicker::setTickOrigin(origin); +} + +/*! + Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. + + This is useful to define the month/day/time recurring at greater tick interval steps. For + example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick + per year, the ticks will end up on 15. July at 9:45 of every year. +*/ +void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) +{ + setTickOrigin(dateTimeToKey(origin)); +} + +/*! \internal + + Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + Note that this tick step isn't used exactly when generating the tick vector in \ref + createTickVector, but only as a guiding value requiring some correction for each individual tick + interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day + in the month to the last day in the previous month from tick to tick, due to the non-uniform + length of months. The same problem arises with leap years. + + \seebaseclassmethod +*/ +double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + mDateStrategy = dsNone; + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + result = cleanMantissa(result); + } else if (result < 86400*30.4375*12) // below a year + { + result = pickClosest(result, QVector() + << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range + << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range + << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) + if (result > 86400*30.4375-1) // month tick intervals or larger + mDateStrategy = dsUniformDayInMonth; + else if (result > 3600*24-1) // day tick intervals or larger + mDateStrategy = dsUniformTimeInDay; + } else // more than a year, go back to normal clean mantissa algorithm but in units of years + { + const double secondsPerYear = 86400*30.4375*12; // average including leap years + result = cleanMantissa(result/secondsPerYear)*secondsPerYear; + mDateStrategy = dsUniformDayInMonth; + } + return result; +} + +/*! \internal + + Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, + monthly, bi-monthly, etc. + + \seebaseclassmethod +*/ +int QCPAxisTickerDateTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + case 86400*2: result = 1; break; + case 86400*5: result = 4; break; + case 86400*7: result = 6; break; + case 86400*14: result = 1; break; + case (int)(86400*30.4375+0.5): result = 3; break; + case (int)(86400*30.4375*2+0.5): result = 1; break; + case (int)(86400*30.4375*3+0.5): result = 2; break; + case (int)(86400*30.4375*6+0.5): result = 5; break; + case (int)(86400*30.4375*12+0.5): result = 3; break; + } + return result; +} + +/*! \internal + + Generates a date/time tick label for tick coordinate \a tick, based on the currently set format + (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). + + \seebaseclassmethod +*/ +QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +} + +/*! \internal + + Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain + non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. + + \seebaseclassmethod +*/ +QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) +{ + QVector result = QCPAxisTicker::createTickVector(tickStep, range); + if (!result.isEmpty()) + { + if (mDateStrategy == dsUniformTimeInDay) + { + QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible + QDateTime tickDateTime; + for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths(-1); + tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); + result[i] = dateTimeToKey(tickDateTime); + } + } + } + return result; +} + +/*! + A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a + QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) + + \see dateTimeToKey +*/ +QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); +# else + return QDateTime::fromMSecsSinceEpoch(key*1000.0); +# endif +} + +/*! \overload + + A convenience method which turns a QDateTime object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it + works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return dateTime.toTime_t()+dateTime.time().msec()/1000.0; +# else + return dateTime.toMSecsSinceEpoch()/1000.0; +# endif +} + +/*! \overload + + A convenience method which turns a QDate object into a double value that corresponds to + seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by + QCPAxisTickerDateTime. + + \see keyToDateTime +*/ +double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) +{ +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime(date).toTime_t(); +# else + return QDateTime(date).toMSecsSinceEpoch()/1000.0; +# endif +} +/* end of 'src/axis/axistickerdatetime.cpp' */ + + +/* including file 'src/axis/axistickertime.cpp', size 11747 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerTime +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerTime + \brief Specialized axis ticker for time spans in units of milliseconds to days + + \image html axisticker-time.png + + This QCPAxisTicker subclass generates ticks that corresponds to time intervals. + + The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref + setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate + zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date + and time. + + The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the + largest available unit in the format specified with \ref setTimeFormat, any time spans above will + be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at + coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick + label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour + unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis + zero will carry a leading minus sign. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation + + Here is an example of a time axis providing time information in days, hours and minutes. Due to + the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker + decided to use tick steps of 12 hours: + + \image html axisticker-time2.png + + The format string for this example is + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 + + \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime + instead. +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerTime::QCPAxisTickerTime() : + mTimeFormat(QLatin1String("%h:%m:%s")), + mSmallestUnit(tuSeconds), + mBiggestUnit(tuHours) +{ + setTickCount(4); + mFieldWidth[tuMilliseconds] = 3; + mFieldWidth[tuSeconds] = 2; + mFieldWidth[tuMinutes] = 2; + mFieldWidth[tuHours] = 2; + mFieldWidth[tuDays] = 1; + + mFormatPattern[tuMilliseconds] = QLatin1String("%z"); + mFormatPattern[tuSeconds] = QLatin1String("%s"); + mFormatPattern[tuMinutes] = QLatin1String("%m"); + mFormatPattern[tuHours] = QLatin1String("%h"); + mFormatPattern[tuDays] = QLatin1String("%d"); +} + +/*! + Sets the format that will be used to display time in the tick labels. + + The available patterns are: + - %%z for milliseconds + - %%s for seconds + - %%m for minutes + - %%h for hours + - %%d for days + + The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. + + The largest unit that appears in \a format will carry all the remaining time of a certain tick + coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the + largest unit it might become larger than 59 in order to consume larger time values. If on the + other hand %%h is available, the minutes will wrap around to zero after 59 and the time will + carry to the hour digit. +*/ +void QCPAxisTickerTime::setTimeFormat(const QString &format) +{ + mTimeFormat = format; + + // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest + // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) + mSmallestUnit = tuMilliseconds; + mBiggestUnit = tuMilliseconds; + bool hasSmallest = false; + for (int i = tuMilliseconds; i <= tuDays; ++i) + { + TimeUnit unit = static_cast(i); + if (mTimeFormat.contains(mFormatPattern.value(unit))) + { + if (!hasSmallest) + { + mSmallestUnit = unit; + hasSmallest = true; + } + mBiggestUnit = unit; + } + } +} + +/*! + Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick + label. If the number for the specific unit is shorter than \a width, it will be padded with an + according number of zeros to the left in order to reach the field width. + + \see setTimeFormat +*/ +void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) +{ + mFieldWidth[unit] = qMax(width, 1); +} + +/*! \internal + + Returns the tick step appropriate for time displays, depending on the provided \a range and the + smallest available time unit in the current format (\ref setTimeFormat). For example if the unit + of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) + that require sub-minute precision to be displayed correctly. + + \seebaseclassmethod +*/ +double QCPAxisTickerTime::getTickStep(const QCPRange &range) +{ + double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + { + if (mSmallestUnit == tuMilliseconds) + result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond + else // have no milliseconds available in format, so stick with 1 second tickstep + result = 1.0; + } else if (result < 3600*24) // below a day + { + // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run + QVector availableSteps; + // seconds range: + if (mSmallestUnit <= tuSeconds) + availableSteps << 1; + if (mSmallestUnit == tuMilliseconds) + availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it + else if (mSmallestUnit == tuSeconds) + availableSteps << 2; + if (mSmallestUnit <= tuSeconds) + availableSteps << 5 << 10 << 15 << 30; + // minutes range: + if (mSmallestUnit <= tuMinutes) + availableSteps << 1*60; + if (mSmallestUnit <= tuSeconds) + availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it + else if (mSmallestUnit == tuMinutes) + availableSteps << 2*60; + if (mSmallestUnit <= tuMinutes) + availableSteps << 5*60 << 10*60 << 15*60 << 30*60; + // hours range: + if (mSmallestUnit <= tuHours) + availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; + // pick available step that is most appropriate to approximate ideal step: + result = pickClosest(result, availableSteps); + } else // more than a day, go back to normal clean mantissa algorithm but in units of days + { + const double secondsPerDay = 3600*24; + result = cleanMantissa(result/secondsPerDay)*secondsPerDay; + } + return result; +} + +/*! \internal + + Returns the sub tick count appropriate for the provided \a tickStep and time displays. + + \seebaseclassmethod +*/ +int QCPAxisTickerTime::getSubTickCount(double tickStep) +{ + int result = QCPAxisTicker::getSubTickCount(tickStep); + switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) + { + case 5*60: result = 4; break; + case 10*60: result = 1; break; + case 15*60: result = 2; break; + case 30*60: result = 1; break; + case 60*60: result = 3; break; + case 3600*2: result = 3; break; + case 3600*3: result = 2; break; + case 3600*6: result = 1; break; + case 3600*12: result = 3; break; + case 3600*24: result = 3; break; + } + return result; +} + +/*! \internal + + Returns the tick label corresponding to the provided \a tick and the configured format and field + widths (\ref setTimeFormat, \ref setFieldWidth). + + \seebaseclassmethod +*/ +QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + Q_UNUSED(precision) + Q_UNUSED(formatChar) + Q_UNUSED(locale) + bool negative = tick < 0; + if (negative) tick *= -1; + double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) + double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time + + restValues[tuMilliseconds] = tick*1000; + values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; + values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; + values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; + values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; + // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) + + QString result = mTimeFormat; + for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) + { + TimeUnit iUnit = static_cast(i); + replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); + } + if (negative) + result.prepend(QLatin1Char('-')); + return result; +} + +/*! \internal + + Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified + \a value, using the field width as specified with \ref setFieldWidth for the \a unit. +*/ +void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const +{ + QString valueStr = QString::number(value); + while (valueStr.size() < mFieldWidth.value(unit)) + valueStr.prepend(QLatin1Char('0')); + + text.replace(mFormatPattern.value(unit), valueStr); +} +/* end of 'src/axis/axistickertime.cpp' */ + + +/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerFixed +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerFixed + \brief Specialized axis ticker with a fixed tick step + + \image html axisticker-fixed.png + + This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It + is also possible to allow integer multiples and integer powers of the specified tick step with + \ref setScaleStrategy. + + A typical application of this ticker is to make an axis only display integers, by setting the + tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. + + Another case is when a certain number has a special meaning and axis ticks should only appear at + multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi + because despite the name it is not limited to only pi symbols/values. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerFixed::QCPAxisTickerFixed() : + mTickStep(1.0), + mScaleStrategy(ssNone) +{ +} + +/*! + Sets the fixed tick interval to \a step. + + The axis ticker will only use this tick step when generating axis ticks. This might cause a very + high tick density and overlapping labels if the axis range is zoomed out. Using \ref + setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a + step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref + setTickCount). +*/ +void QCPAxisTickerFixed::setTickStep(double step) +{ + if (step > 0) + mTickStep = step; + else + qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; +} + +/*! + Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether + modifications may be applied to it before calculating the finally used tick step, such as + permitting multiples or powers. See \ref ScaleStrategy for details. + + The default strategy is \ref ssNone, which means the tick step is absolutely fixed. +*/ +void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) +{ + mScaleStrategy = strategy; +} + +/*! \internal + + Determines the actually used tick step from the specified tick step and scale strategy (\ref + setTickStep, \ref setScaleStrategy). + + This method either returns the specified tick step exactly, or, if the scale strategy is not \ref + ssNone, a modification of it to allow varying the number of ticks in the current axis range. + + \seebaseclassmethod +*/ +double QCPAxisTickerFixed::getTickStep(const QCPRange &range) +{ + switch (mScaleStrategy) + { + case ssNone: + { + return mTickStep; + } + case ssMultiples: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + if (exactStep < mTickStep) + return mTickStep; + else + return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; + } + case ssPowers: + { + double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); + } + } + return mTickStep; +} +/* end of 'src/axis/axistickerfixed.cpp' */ + + +/* including file 'src/axis/axistickertext.cpp', size 8653 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerText +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerText + \brief Specialized axis ticker which allows arbitrary labels at specified coordinates + + \image html axisticker-text.png + + This QCPAxisTicker subclass generates ticks which can be directly specified by the user as + coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a + time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks + and modify the tick/label data there. + + This is useful for cases where the axis represents categories rather than numerical values. + + If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on + the axis range), it is a sign that you should probably create an own ticker by subclassing + QCPAxisTicker, instead of using this one. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation +*/ + +/* start of documentation of inline functions */ + +/*! \fn QMap &QCPAxisTickerText::ticks() + + Returns a non-const reference to the internal map which stores the tick coordinates and their + labels. + + You can access the map directly in order to add, remove or manipulate ticks, as an alternative to + using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerText::QCPAxisTickerText() : + mSubTickCount(0) +{ +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis + coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QMap &ticks) +{ + mTicks = ticks; +} + +/*! \overload + + Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis + coordinates, and the entries of \a labels are the respective strings that will appear as tick + labels. + + \see addTicks, addTick, clear +*/ +void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) +{ + clear(); + addTicks(positions, labels); +} + +/*! + Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no + automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this + method. +*/ +void QCPAxisTickerText::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! + Clears all ticks. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see setTicks, addTicks, addTick +*/ +void QCPAxisTickerText::clear() +{ + mTicks.clear(); +} + +/*! + Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a + label. + + \see addTicks, setTicks, clear +*/ +void QCPAxisTickerText::addTick(double position, QString label) +{ + mTicks.insert(position, label); +} + +/*! \overload + + Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to + the axis coordinate, and the map value is the string that will appear as tick label. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QMap &ticks) +{ + mTicks.unite(ticks); +} + +/*! \overload + + Adds the provided ticks to the ones already existing. The entries of \a positions correspond to + the axis coordinates, and the entries of \a labels are the respective strings that will appear as + tick labels. + + An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks + getter. + + \see addTick, setTicks, clear +*/ +void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) +{ + if (positions.size() != labels.size()) + qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); + int n = qMin(positions.size(), labels.size()); + for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (mTicks.isEmpty()) + return result; + + QMap::const_iterator start = mTicks.lowerBound(range.lower); + QMap::const_iterator end = mTicks.upperBound(range.upper); + // this method should try to give one tick outside of range so proper subticks can be generated: + if (start != mTicks.constBegin()) --start; + if (end != mTicks.constEnd()) ++end; + for (QMap::const_iterator it = start; it != end; ++it) + result.append(it.key()); + + return result; +} +/* end of 'src/axis/axistickertext.cpp' */ + + +/* including file 'src/axis/axistickerpi.cpp', size 11170 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerPi +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerPi + \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi + + \image html axisticker-pi.png + + This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic + constant with a numerical value specified with \ref setPiValue and an appearance in the tick + labels specified with \ref setPiSymbol. + + Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the + tick label can be configured with \ref setFractionStyle. + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerPi::QCPAxisTickerPi() : + mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), + mPiValue(M_PI), + mPeriodicity(0), + mFractionStyle(fsUnicodeFractions), + mPiTickStep(0) +{ + setTickCount(4); +} + +/*! + Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick + label. + + If a space shall appear between the number and the symbol, make sure the space is contained in \a + symbol. +*/ +void QCPAxisTickerPi::setPiSymbol(QString symbol) +{ + mPiSymbol = symbol; +} + +/*! + Sets the numerical value that the symbolic constant has. + + This will be used to place the appropriate fractions of the symbol at the respective axis + coordinates. +*/ +void QCPAxisTickerPi::setPiValue(double pi) +{ + mPiValue = pi; +} + +/*! + Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the + symbolic constant. + + To disable periodicity, set \a multiplesOfPi to zero. + + For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. +*/ +void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) +{ + mPeriodicity = qAbs(multiplesOfPi); +} + +/*! + Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick + labels. See \ref FractionStyle for the various options. +*/ +void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) +{ + mFractionStyle = style; +} + +/*! \internal + + Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence + the numerical/fractional part preceding the symbolic constant is made to have a readable + mantissa. + + \seebaseclassmethod +*/ +double QCPAxisTickerPi::getTickStep(const QCPRange &range) +{ + mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mPiTickStep = cleanMantissa(mPiTickStep); + return mPiTickStep*mPiValue; +} + +/*! \internal + + Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In + consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant + reasonably, and not the total tick coordinate. + + \seebaseclassmethod +*/ +int QCPAxisTickerPi::getSubTickCount(double tickStep) +{ + return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); +} + +/*! \internal + + Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The + formatting of the fraction is done according to the specified \ref setFractionStyle. The appended + symbol is specified with \ref setPiSymbol. + + \seebaseclassmethod +*/ +QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +{ + double tickInPis = tick/mPiValue; + if (mPeriodicity > 0) + tickInPis = fmod(tickInPis, mPeriodicity); + + if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) + { + // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above + int denominator = 1000; + int numerator = qRound(tickInPis*denominator); + simplifyFraction(numerator, denominator); + if (qAbs(numerator) == 1 && denominator == 1) + return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else if (numerator == 0) + return QLatin1String("0"); + else + return fractionToString(numerator, denominator) + mPiSymbol; + } else + { + if (qFuzzyIsNull(tickInPis)) + return QLatin1String("0"); + else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) + return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + else + return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; + } +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure + the fraction is in irreducible form, i.e. numerator and denominator don't share any common + factors which could be cancelled. +*/ +void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const +{ + if (numerator == 0 || denominator == 0) + return; + + int num = numerator; + int denom = denominator; + while (denom != 0) // euclidean gcd algorithm + { + int oldDenom = denom; + denom = num % denom; + num = oldDenom; + } + // num is now gcd of numerator and denominator + numerator /= num; + denominator /= num; +} + +/*! \internal + + Takes the fraction given by \a numerator and \a denominator and returns a string representation. + The result depends on the configured fraction style (\ref setFractionStyle). + + This method is used to format the numerical/fractional part when generating tick labels. It + simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out + any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). +*/ +QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const +{ + if (denominator == 0) + { + qDebug() << Q_FUNC_INFO << "called with zero denominator"; + return QString(); + } + if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function + { + qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; + return QString::number(numerator/(double)denominator); // failsafe + } + int sign = numerator*denominator < 0 ? -1 : 1; + numerator = qAbs(numerator); + denominator = qAbs(denominator); + + if (denominator == 1) + { + return QString::number(sign*numerator); + } else + { + int integerPart = numerator/denominator; + int remainder = numerator%denominator; + if (remainder == 0) + { + return QString::number(sign*integerPart); + } else + { + if (mFractionStyle == fsAsciiFractions) + { + return QString(QLatin1String("%1%2%3/%4")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) + .arg(remainder) + .arg(denominator); + } else if (mFractionStyle == fsUnicodeFractions) + { + return QString(QLatin1String("%1%2%3")) + .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) + .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) + .arg(unicodeFraction(remainder, denominator)); + } + } + } + return QString(); +} + +/*! \internal + + Returns the unicode string representation of the fraction given by \a numerator and \a + denominator. This is the representation used in \ref fractionToString when the fraction style + (\ref setFractionStyle) is \ref fsUnicodeFractions. + + This method doesn't use the single-character common fractions but builds each fraction from a + superscript unicode number, the unicode fraction character, and a subscript unicode number. +*/ +QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const +{ + return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); +} + +/*! \internal + + Returns the unicode string representing \a number as superscript. This is used to build + unicode fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSuperscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2070)); + + QString result; + while (number > 0) + { + const int digit = number%10; + switch (digit) + { + case 1: { result.prepend(QChar(0x00B9)); break; } + case 2: { result.prepend(QChar(0x00B2)); break; } + case 3: { result.prepend(QChar(0x00B3)); break; } + default: { result.prepend(QChar(0x2070+digit)); break; } + } + number /= 10; + } + return result; +} + +/*! \internal + + Returns the unicode string representing \a number as subscript. This is used to build unicode + fractions in \ref unicodeFraction. +*/ +QString QCPAxisTickerPi::unicodeSubscript(int number) const +{ + if (number == 0) + return QString(QChar(0x2080)); + + QString result; + while (number > 0) + { + result.prepend(QChar(0x2080+number%10)); + number /= 10; + } + return result; +} +/* end of 'src/axis/axistickerpi.cpp' */ + + +/* including file 'src/axis/axistickerlog.cpp', size 7106 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisTickerLog +//////////////////////////////////////////////////////////////////////////////////////////////////// +/*! \class QCPAxisTickerLog + \brief Specialized axis ticker suited for logarithmic axes + + \image html axisticker-log.png + + This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic + axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). + + Especially in the case of a log base equal to 10 (the default), it might be desirable to have + tick labels in the form of powers of ten without mantissa display. To achieve this, set the + number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref + QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal + powers, so a format string of "eb". This will result in the following axis tick labels: + + \image html axisticker-log-powers.png + + The ticker can be created and assigned to an axis like this: + \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation +*/ + +/*! + Constructs the ticker and sets reasonable default values. Axis tickers are commonly created + managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. +*/ +QCPAxisTickerLog::QCPAxisTickerLog() : + mLogBase(10.0), + mSubTickCount(8), // generates 10 intervals + mLogBaseLnInv(1.0/qLn(mLogBase)) +{ +} + +/*! + Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer + powers of \a base. +*/ +void QCPAxisTickerLog::setLogBase(double base) +{ + if (base > 0) + { + mLogBase = base; + mLogBaseLnInv = 1.0/qLn(mLogBase); + } else + qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; +} + +/*! + Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced + linearly to provide a better visual guide, so the sub tick density increases toward the higher + tick. + + Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in + the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub + ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, + namely at 20, 30, 40, 50, 60, 70, 80 and 90. +*/ +void QCPAxisTickerLog::setSubTickCount(int subTicks) +{ + if (subTicks >= 0) + mSubTickCount = subTicks; + else + qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; +} + +/*! \internal + + Since logarithmic tick steps are necessarily different for each tick interval, this method does + nothing in the case of QCPAxisTickerLog + + \seebaseclassmethod +*/ +double QCPAxisTickerLog::getTickStep(const QCPRange &range) +{ + // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method + Q_UNUSED(range) + return 1.0; +} + +/*! \internal + + Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no + automatic sub tick count calculation necessary. + + \seebaseclassmethod +*/ +int QCPAxisTickerLog::getSubTickCount(double tickStep) +{ + Q_UNUSED(tickStep) + return mSubTickCount; +} + +/*! \internal + + Creates ticks with a spacing given by the logarithm base and an increasing integer power in the + provided \a range. The step in which the power increases tick by tick is chosen in order to keep + the total number of ticks as close as possible to the tick count (\ref setTickCount). The + parameter \a tickStep is ignored for QCPAxisTickerLog + + \seebaseclassmethod +*/ +QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) +{ + Q_UNUSED(tickStep) + QVector result; + if (range.lower > 0 && range.upper > 0) // positive range + { + double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick *= newLogBase; + result.append(currentTick); + } + } else if (range.lower < 0 && range.upper < 0) // negative range + { + double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); + double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); + double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); + result.append(currentTick); + while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + { + currentTick /= newLogBase; + result.append(currentTick); + } + } else // invalid range for logarithmic scale, because lower and upper have different sign + { + qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; + } + + return result; +} +/* end of 'src/axis/axistickerlog.cpp' */ + + +/* including file 'src/axis/axis.cpp', size 99397 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGrid +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGrid + \brief Responsible for drawing the grid of a QCPAxis. + + This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the + grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref + QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. + + The axis and grid drawing was split into two classes to allow them to be placed on different + layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid + in the background and the axes in the foreground, and any plottables/items in between. This + described situation is the default setup, see the QCPLayer documentation. +*/ + +/*! + Creates a QCPGrid instance and sets default values. + + You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. +*/ +QCPGrid::QCPGrid(QCPAxis *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mParentAxis(parentAxis) +{ + // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called + setParent(parentAxis); + setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); + setSubGridVisible(false); + setAntialiased(false); + setAntialiasedSubGrid(false); + setAntialiasedZeroLine(false); +} + +/*! + Sets whether grid lines at sub tick marks are drawn. + + \see setSubGridPen +*/ +void QCPGrid::setSubGridVisible(bool visible) +{ + mSubGridVisible = visible; +} + +/*! + Sets whether sub grid lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedSubGrid(bool enabled) +{ + mAntialiasedSubGrid = enabled; +} + +/*! + Sets whether zero lines are drawn antialiased. +*/ +void QCPGrid::setAntialiasedZeroLine(bool enabled) +{ + mAntialiasedZeroLine = enabled; +} + +/*! + Sets the pen with which (major) grid lines are drawn. +*/ +void QCPGrid::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen with which sub grid lines are drawn. +*/ +void QCPGrid::setSubGridPen(const QPen &pen) +{ + mSubGridPen = pen; +} + +/*! + Sets the pen with which zero lines are drawn. + + Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid + lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. +*/ +void QCPGrid::setZeroLinePen(const QPen &pen) +{ + mZeroLinePen = pen; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing the major grid lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); +} + +/*! \internal + + Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning + over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). +*/ +void QCPGrid::draw(QCPPainter *painter) +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + if (mParentAxis->subTicks() && mSubGridVisible) + drawSubGridLines(painter); + drawGridLines(painter); +} + +/*! \internal + + Draws the main grid lines and possibly a zero line with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + const int tickCount = mParentAxis->mTickVector.size(); + double t; // helper variable, result of coordinate-to-pixel transforms + if (mParentAxis->orientation() == Qt::Horizontal) + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + // draw zeroline: + int zeroLineIndex = -1; + if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + { + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.at(i)) < epsilon) + { + zeroLineIndex = i; + t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + break; + } + } + } + // draw grid lines: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + +/*! \internal + + Draws the sub grid lines with the specified painter. + + This is a helper function called by \ref draw. +*/ +void QCPGrid::drawSubGridLines(QCPPainter *painter) const +{ + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + + applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); + double t; // helper variable, result of coordinate-to-pixel transforms + painter->setPen(mSubGridPen); + if (mParentAxis->orientation() == Qt::Horizontal) + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + } + } else + { + for (int i=0; imSubTickVector.size(); ++i) + { + t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxis +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxis + \brief Manages a single axis inside a QCustomPlot. + + Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via + QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and + QCustomPlot::yAxis2 (right). + + Axes are always part of an axis rect, see QCPAxisRect. + \image html AxisNamesOverview.png +
Naming convention of axis parts
+ \n + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line + on the left represents the QCustomPlot widget border.
+ + Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and + tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of + the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the + documentation of QCPAxisTicker. +*/ + +/* start of documentation of inline functions */ + +/*! \fn Qt::Orientation QCPAxis::orientation() const + + Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced + from the axis type (left, top, right or bottom). + + \see orientation(AxisType type), pixelOrientation +*/ + +/*! \fn QCPGrid *QCPAxis::grid() const + + Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the + grid is displayed. +*/ + +/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) + + Returns the orientation of the specified axis type + + \see orientation(), pixelOrientation +*/ + +/*! \fn int QCPAxis::pixelOrientation() const + + Returns which direction points towards higher coordinate values/keys, in pixel space. + + This method returns either 1 or -1. If it returns 1, then going in the positive direction along + the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. + On the other hand, if this method returns -1, going to smaller pixel values corresponds to going + from lower to higher axis coordinates. + + For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, + without having to care about reversed or vertically aligned axes: + + \code + double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); + \endcode + + \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. +*/ + +/*! \fn QSharedPointer QCPAxis::ticker() const + + Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is + responsible for generating the tick positions and tick labels of this axis. You can access the + \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count + (\ref QCPAxisTicker::setTickCount). + + You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see + the documentation there. A new axis ticker can be set with \ref setTicker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see setTicker +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) + + This signal is emitted when the range of this axis has changed. You can connect it to the \ref + setRange slot of another axis to communicate the new range to the other axis, in order for it to + be synchronized. + + You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. + This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper + range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following + slot would limit the x axis to ranges between 0 and 10: + \code + customPlot->xAxis->setRange(newRange.bounded(0, 10)) + \endcode +*/ + +/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) + \overload + + Additionally to the new range, this signal also provides the previous range held by the axis as + \a oldRange. +*/ + +/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the scale type changes, by calls to \ref setScaleType +*/ + +/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) + + This signal is emitted when the selection state of this axis has changed, either by user interaction + or by a direct call to \ref setSelectedParts. +*/ + +/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); + + This signal is emitted when the selectability changes, by calls to \ref setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs an Axis instance of Type \a type for the axis rect \a parent. + + Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create + them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, + create them manually and then inject them also via \ref QCPAxisRect::addAxis. +*/ +QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : + QCPLayerable(parent->parentPlot(), QString(), parent), + // axis base: + mAxisType(type), + mAxisRect(parent), + mPadding(5), + mOrientation(orientation(type)), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + mTickLabels(true), + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedTickPen(QPen(Qt::blue, 2)), + mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedSubTickPen(QPen(Qt::blue, 2)), + // scale and range: + mRange(0, 5), + mRangeReversed(false), + mScaleType(stLinear), + // internal members: + mGrid(new QCPGrid(this)), + mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), + mTicker(new QCPAxisTicker), + mCachedMarginValid(false), + mCachedMargin(0) +{ + setParent(parent); + mGrid->setVisible(false); + setAntialiased(false); + setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again + + if (type == atTop) + { + setTickLabelPadding(3); + setLabelPadding(6); + } else if (type == atRight) + { + setTickLabelPadding(7); + setLabelPadding(12); + } else if (type == atBottom) + { + setTickLabelPadding(3); + setLabelPadding(3); + } else if (type == atLeft) + { + setTickLabelPadding(5); + setLabelPadding(10); + } +} + +QCPAxis::~QCPAxis() +{ + delete mAxisPainter; + delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLabelPadding() const +{ + return mAxisPainter->tickLabelPadding; +} + +/* No documentation as it is a property getter */ +double QCPAxis::tickLabelRotation() const +{ + return mAxisPainter->tickLabelRotation; +} + +/* No documentation as it is a property getter */ +QCPAxis::LabelSide QCPAxis::tickLabelSide() const +{ + return mAxisPainter->tickLabelSide; +} + +/* No documentation as it is a property getter */ +QString QCPAxis::numberFormat() const +{ + QString result; + result.append(mNumberFormatChar); + if (mNumberBeautifulPowers) + { + result.append(QLatin1Char('b')); + if (mAxisPainter->numberMultiplyCross) + result.append(QLatin1Char('c')); + } + return result; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthIn() const +{ + return mAxisPainter->tickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::tickLengthOut() const +{ + return mAxisPainter->tickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthIn() const +{ + return mAxisPainter->subTickLengthIn; +} + +/* No documentation as it is a property getter */ +int QCPAxis::subTickLengthOut() const +{ + return mAxisPainter->subTickLengthOut; +} + +/* No documentation as it is a property getter */ +int QCPAxis::labelPadding() const +{ + return mAxisPainter->labelPadding; +} + +/* No documentation as it is a property getter */ +int QCPAxis::offset() const +{ + return mAxisPainter->offset; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::lowerEnding() const +{ + return mAxisPainter->lowerEnding; +} + +/* No documentation as it is a property getter */ +QCPLineEnding QCPAxis::upperEnding() const +{ + return mAxisPainter->upperEnding; +} + +/*! + Sets whether the axis uses a linear scale or a logarithmic scale. + + Note that this method controls the coordinate transformation. You will likely also want to use a + logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref + QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the + details of logarithmic axis tick creation. + + \ref setNumberPrecision +*/ +void QCPAxis::setScaleType(QCPAxis::ScaleType type) +{ + if (mScaleType != type) + { + mScaleType = type; + if (mScaleType == stLogarithmic) + setRange(mRange.sanitizedForLogScale()); + mCachedMarginValid = false; + Q_EMIT scaleTypeChanged(mScaleType); + } +} + +/*! + Sets the range of the axis. + + This slot may be connected with the \ref rangeChanged signal of another axis so this axis + is always synchronized with the other axis range, when it changes. + + To invert the direction of an axis, use \ref setRangeReversed. +*/ +void QCPAxis::setRange(const QCPRange &range) +{ + if (range.lower == mRange.lower && range.upper == mRange.upper) + return; + + if (!QCPRange::validRange(range)) return; + QCPRange oldRange = mRange; + if (mScaleType == stLogarithmic) + { + mRange = range.sanitizedForLogScale(); + } else + { + mRange = range.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains iSelectAxes.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPAxis::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font. + + The entire selection mechanism for axes is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you + wish to change the selection state manually. + + This function can change the selection state of a part, independent of the \ref setSelectableParts setting. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, + setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor +*/ +void QCPAxis::setSelectedParts(const SelectableParts &selected) +{ + if (mSelectedParts != selected) + { + mSelectedParts = selected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + \overload + + Sets the lower and upper bound of the axis range. + + To invert the direction of an axis, use \ref setRangeReversed. + + There is also a slot to set a range, see \ref setRange(const QCPRange &range). +*/ +void QCPAxis::setRange(double lower, double upper) +{ + if (lower == mRange.lower && upper == mRange.upper) + return; + + if (!QCPRange::validRange(lower, upper)) return; + QCPRange oldRange = mRange; + mRange.lower = lower; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + \overload + + Sets the range of the axis. + + The \a position coordinate indicates together with the \a alignment parameter, where the new + range will be positioned. \a size defines the size of the new axis range. \a alignment may be + Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, + or center of the range to be aligned with \a position. Any other values of \a alignment will + default to Qt::AlignCenter. +*/ +void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) +{ + if (alignment == Qt::AlignLeft) + setRange(position, position+size); + else if (alignment == Qt::AlignRight) + setRange(position-size, position); + else // alignment == Qt::AlignCenter + setRange(position-size/2.0, position+size/2.0); +} + +/*! + Sets the lower bound of the axis range. The upper bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeLower(double lower) +{ + if (mRange.lower == lower) + return; + + QCPRange oldRange = mRange; + mRange.lower = lower; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets the upper bound of the axis range. The lower bound is not changed. + \see setRange +*/ +void QCPAxis::setRangeUpper(double upper) +{ + if (mRange.upper == upper) + return; + + QCPRange oldRange = mRange; + mRange.upper = upper; + if (mScaleType == stLogarithmic) + { + mRange = mRange.sanitizedForLogScale(); + } else + { + mRange = mRange.sanitizedForLinScale(); + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal + axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the + direction of increasing values is inverted. + + Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part + of the \ref setRange interface will still reference the mathematically smaller number than the \a + upper part. +*/ +void QCPAxis::setRangeReversed(bool reversed) +{ + mRangeReversed = reversed; +} + +/*! + The axis ticker is responsible for generating the tick positions and tick labels. See the + documentation of QCPAxisTicker for details on how to work with axis tickers. + + You can change the tick positioning/labeling behaviour of this axis by setting a different + QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis + ticker, access it via \ref ticker. + + Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis + ticker simply by passing the same shared pointer to multiple axes. + + \see ticker +*/ +void QCPAxis::setTicker(QSharedPointer ticker) +{ + if (ticker) + mTicker = ticker; + else + qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; + // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector +} + +/*! + Sets whether tick marks are displayed. + + Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve + that, see \ref setTickLabels. + + \see setSubTicks +*/ +void QCPAxis::setTicks(bool show) +{ + if (mTicks != show) + { + mTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. +*/ +void QCPAxis::setTickLabels(bool show) +{ + if (mTickLabels != show) + { + mTickLabels = show; + mCachedMarginValid = false; + if (!mTickLabels) + mTickVectorLabels.clear(); + } +} + +/*! + Sets the distance between the axis base line (including any outward ticks) and the tick labels. + \see setLabelPadding, setPadding +*/ +void QCPAxis::setTickLabelPadding(int padding) +{ + if (mAxisPainter->tickLabelPadding != padding) + { + mAxisPainter->tickLabelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the font of the tick labels. + + \see setTickLabels, setTickLabelColor +*/ +void QCPAxis::setTickLabelFont(const QFont &font) +{ + if (font != mTickLabelFont) + { + mTickLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the tick labels. + + \see setTickLabels, setTickLabelFont +*/ +void QCPAxis::setTickLabelColor(const QColor &color) +{ + mTickLabelColor = color; +} + +/*! + Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, + the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values + from -90 to 90 degrees. + + If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For + other angles, the label is drawn with an offset such that it seems to point toward or away from + the tick mark. +*/ +void QCPAxis::setTickLabelRotation(double degrees) +{ + if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) + { + mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); + mCachedMarginValid = false; + } +} + +/*! + Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. + + The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels + to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels + appear on the inside are additionally clipped to the axis rect. +*/ +void QCPAxis::setTickLabelSide(LabelSide side) +{ + mAxisPainter->tickLabelSide = side; + mCachedMarginValid = false; +} + +/*! + Sets the number format for the numbers in tick labels. This \a formatCode is an extended version + of the format code used e.g. by QString::number() and QLocale::toString(). For reference about + that, see the "Argument Formats" section in the detailed description of the QString class. + + \a formatCode is a string of one, two or three characters. The first character is identical to + the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed + format, 'g'/'G' scientific or fixed, whichever is shorter. + + The second and third characters are optional and specific to QCustomPlot:\n + If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. + "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for + "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 + [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. + If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can + be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the + cross and 183 (0xB7) for the dot. + + Examples for \a formatCode: + \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, + normal scientific format is used + \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with + beautifully typeset decimal powers and a dot as multiplication sign + \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as + multiplication sign + \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal + powers. Format code will be reduced to 'f'. + \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format + code will not be changed. +*/ +void QCPAxis::setNumberFormat(const QString &formatCode) +{ + if (formatCode.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; + return; + } + mCachedMarginValid = false; + + // interpret first char as number format char: + QString allowedFormatChars(QLatin1String("eEfgG")); + if (allowedFormatChars.contains(formatCode.at(0))) + { + mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; + return; + } + if (formatCode.length() < 2) + { + mNumberBeautifulPowers = false; + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret second char as indicator for beautiful decimal powers: + if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) + { + mNumberBeautifulPowers = true; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; + return; + } + if (formatCode.length() < 3) + { + mAxisPainter->numberMultiplyCross = false; + return; + } + + // interpret third char as indicator for dot or cross multiplication symbol: + if (formatCode.at(2) == QLatin1Char('c')) + { + mAxisPainter->numberMultiplyCross = true; + } else if (formatCode.at(2) == QLatin1Char('d')) + { + mAxisPainter->numberMultiplyCross = false; + } else + { + qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; + return; + } +} + +/*! + Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) + for details. The effect of precisions are most notably for number Formats starting with 'e', see + \ref setNumberFormat +*/ +void QCPAxis::setNumberPrecision(int precision) +{ + if (mNumberPrecision != precision) + { + mNumberPrecision = precision; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the + plot and \a outside is the length they will reach outside the plot. If \a outside is greater than + zero, the tick labels and axis label will increase their distance to the axis accordingly, so + they won't collide with the ticks. + + \see setSubTickLength, setTickLengthIn, setTickLengthOut +*/ +void QCPAxis::setTickLength(int inside, int outside) +{ + setTickLengthIn(inside); + setTickLengthOut(outside); +} + +/*! + Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach + inside the plot. + + \see setTickLengthOut, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthIn(int inside) +{ + if (mAxisPainter->tickLengthIn != inside) + { + mAxisPainter->tickLengthIn = inside; + } +} + +/*! + Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach + outside the plot. If \a outside is greater than zero, the tick labels and axis label will + increase their distance to the axis accordingly, so they won't collide with the ticks. + + \see setTickLengthIn, setTickLength, setSubTickLength +*/ +void QCPAxis::setTickLengthOut(int outside) +{ + if (mAxisPainter->tickLengthOut != outside) + { + mAxisPainter->tickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets whether sub tick marks are displayed. + + Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) + + \see setTicks +*/ +void QCPAxis::setSubTicks(bool show) +{ + if (mSubTicks != show) + { + mSubTicks = show; + mCachedMarginValid = false; + } +} + +/*! + Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside + the plot and \a outside is the length they will reach outside the plot. If \a outside is greater + than zero, the tick labels and axis label will increase their distance to the axis accordingly, + so they won't collide with the ticks. + + \see setTickLength, setSubTickLengthIn, setSubTickLengthOut +*/ +void QCPAxis::setSubTickLength(int inside, int outside) +{ + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); +} + +/*! + Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside + the plot. + + \see setSubTickLengthOut, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthIn(int inside) +{ + if (mAxisPainter->subTickLengthIn != inside) + { + mAxisPainter->subTickLengthIn = inside; + } +} + +/*! + Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach + outside the plot. If \a outside is greater than zero, the tick labels will increase their + distance to the axis accordingly, so they won't collide with the ticks. + + \see setSubTickLengthIn, setSubTickLength, setTickLength +*/ +void QCPAxis::setSubTickLengthOut(int outside) +{ + if (mAxisPainter->subTickLengthOut != outside) + { + mAxisPainter->subTickLengthOut = outside; + mCachedMarginValid = false; // only outside tick length can change margin + } +} + +/*! + Sets the pen, the axis base line is drawn with. + + \see setTickPen, setSubTickPen +*/ +void QCPAxis::setBasePen(const QPen &pen) +{ + mBasePen = pen; +} + +/*! + Sets the pen, tick marks will be drawn with. + + \see setTickLength, setBasePen +*/ +void QCPAxis::setTickPen(const QPen &pen) +{ + mTickPen = pen; +} + +/*! + Sets the pen, subtick marks will be drawn with. + + \see setSubTickCount, setSubTickLength, setBasePen +*/ +void QCPAxis::setSubTickPen(const QPen &pen) +{ + mSubTickPen = pen; +} + +/*! + Sets the font of the axis label. + + \see setLabelColor +*/ +void QCPAxis::setLabelFont(const QFont &font) +{ + if (mLabelFont != font) + { + mLabelFont = font; + mCachedMarginValid = false; + } +} + +/*! + Sets the color of the axis label. + + \see setLabelFont +*/ +void QCPAxis::setLabelColor(const QColor &color) +{ + mLabelColor = color; +} + +/*! + Sets the text of the axis label that will be shown below/above or next to the axis, depending on + its orientation. To disable axis labels, pass an empty string as \a str. +*/ +void QCPAxis::setLabel(const QString &str) +{ + if (mLabel != str) + { + mLabel = str; + mCachedMarginValid = false; + } +} + +/*! + Sets the distance between the tick labels and the axis label. + + \see setTickLabelPadding, setPadding +*/ +void QCPAxis::setLabelPadding(int padding) +{ + if (mAxisPainter->labelPadding != padding) + { + mAxisPainter->labelPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the padding of the axis. + + When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, + that is left blank. + + The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. + + \see setLabelPadding, setTickLabelPadding +*/ +void QCPAxis::setPadding(int padding) +{ + if (mPadding != padding) + { + mPadding = padding; + mCachedMarginValid = false; + } +} + +/*! + Sets the offset the axis has to its axis rect side. + + If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, + only the offset of the inner most axis has meaning (even if it is set to be invisible). The + offset of the other, outer axes is controlled automatically, to place them at appropriate + positions. +*/ +void QCPAxis::setOffset(int offset) +{ + mAxisPainter->offset = offset; +} + +/*! + Sets the font that is used for tick labels when they are selected. + + \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelFont(const QFont &font) +{ + if (font != mSelectedTickLabelFont) + { + mSelectedTickLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts + } +} + +/*! + Sets the font that is used for the axis label when it is selected. + + \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelFont(const QFont &font) +{ + mSelectedLabelFont = font; + // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts +} + +/*! + Sets the color that is used for tick labels when they are selected. + + \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickLabelColor(const QColor &color) +{ + if (color != mSelectedTickLabelColor) + { + mSelectedTickLabelColor = color; + } +} + +/*! + Sets the color that is used for the axis label when it is selected. + + \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedLabelColor(const QColor &color) +{ + mSelectedLabelColor = color; +} + +/*! + Sets the pen that is used to draw the axis base line when selected. + + \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedBasePen(const QPen &pen) +{ + mSelectedBasePen = pen; +} + +/*! + Sets the pen that is used to draw the (major) ticks when selected. + + \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedTickPen(const QPen &pen) +{ + mSelectedTickPen = pen; +} + +/*! + Sets the pen that is used to draw the subticks when selected. + + \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAxis::setSelectedSubTickPen(const QPen &pen) +{ + mSelectedSubTickPen = pen; +} + +/*! + Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setUpperEnding +*/ +void QCPAxis::setLowerEnding(const QCPLineEnding &ending) +{ + mAxisPainter->lowerEnding = ending; +} + +/*! + Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available + styles. + + For horizontal axes, this method refers to the right ending, for vertical axes the top ending. + Note that this meaning does not change when the axis range is reversed with \ref + setRangeReversed. + + \see setLowerEnding +*/ +void QCPAxis::setUpperEnding(const QCPLineEnding &ending) +{ + mAxisPainter->upperEnding = ending; +} + +/*! + If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper + bounds of the range. The range is simply moved by \a diff. + + If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This + corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). +*/ +void QCPAxis::moveRange(double diff) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + mRange.lower += diff; + mRange.upper += diff; + } else // mScaleType == stLogarithmic + { + mRange.lower *= diff; + mRange.upper *= diff; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis by \a factor around the center of the current axis range. For + example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis + range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around + the center will have moved symmetrically closer). + + If you wish to scale around a different coordinate than the current axis range center, use the + overload \ref scaleRange(double factor, double center). +*/ +void QCPAxis::scaleRange(double factor) +{ + scaleRange(factor, range().center()); +} + +/*! \overload + + Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a + factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at + coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates + around 1.0 will have moved symmetrically closer to 1.0). + + \see scaleRange(double factor) +*/ +void QCPAxis::scaleRange(double factor, double center) +{ + QCPRange oldRange = mRange; + if (mScaleType == stLinear) + { + QCPRange newRange; + newRange.lower = (mRange.lower-center)*factor + center; + newRange.upper = (mRange.upper-center)*factor + center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLinScale(); + } else // mScaleType == stLogarithmic + { + if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range + { + QCPRange newRange; + newRange.lower = qPow(mRange.lower/center, factor)*center; + newRange.upper = qPow(mRange.upper/center, factor)*center; + if (QCPRange::validRange(newRange)) + mRange = newRange.sanitizedForLogScale(); + } else + qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; + } + Q_EMIT rangeChanged(mRange); + Q_EMIT rangeChanged(mRange, oldRange); +} + +/*! + Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will + be done around the center of the current axis range. + + For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs + plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the + axis rect has. + + This is an operation that changes the range of this axis once, it doesn't fix the scale ratio + indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent + won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent + will follow. +*/ +void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) +{ + int otherPixelSize, ownPixelSize; + + if (otherAxis->orientation() == Qt::Horizontal) + otherPixelSize = otherAxis->axisRect()->width(); + else + otherPixelSize = otherAxis->axisRect()->height(); + + if (orientation() == Qt::Horizontal) + ownPixelSize = axisRect()->width(); + else + ownPixelSize = axisRect()->height(); + + double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; + setRange(range().center(), newRangeSize, Qt::AlignCenter); +} + +/*! + Changes the axis range such that all plottables associated with this axis are fully visible in + that dimension. + + \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes +*/ +void QCPAxis::rescale(bool onlyVisiblePlottables) +{ + QList p = plottables(); + QCPRange newRange; + bool haveRange = false; + for (int i=0; irealVisibility() && onlyVisiblePlottables) + continue; + QCPRange plottableRange; + bool currentFoundRange; + QCP::SignDomain signDomain = QCP::sdBoth; + if (mScaleType == stLogarithmic) + signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + if (p.at(i)->keyAxis() == this) + plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); + else + plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); + if (currentFoundRange) + { + if (!haveRange) + newRange = plottableRange; + else + newRange.expand(plottableRange); + haveRange = true; + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mScaleType == stLinear) + { + newRange.lower = center-mRange.size()/2.0; + newRange.upper = center+mRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mRange.upper/mRange.lower); + newRange.upper = center*qSqrt(mRange.upper/mRange.lower); + } + } + setRange(newRange); + } +} + +/*! + Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. +*/ +double QCPAxis::pixelToCoord(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; + else + return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; + else + return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic + { + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; + else + return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; + } + } +} + +/*! + Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. +*/ +double QCPAxis::coordToPixel(double value) const +{ + if (orientation() == Qt::Horizontal) + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + else + return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; + else + { + if (!mRangeReversed) + return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + else + return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + } + } + } else // orientation() == Qt::Vertical + { + if (mScaleType == stLinear) + { + if (!mRangeReversed) + return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); + else + return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); + } else // mScaleType == stLogarithmic + { + if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; + else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; + else + { + if (!mRangeReversed) + return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + else + return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + } + } + } +} + +/*! + Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function + is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this + function does not change the current selection state of the axis. + + If the axis is not visible (\ref setVisible), this function always returns \ref spNone. + + \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions +*/ +QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const +{ + if (!mVisible) + return spNone; + + if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) + return spAxis; + else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) + return spTickLabels; + else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) + return spAxisLabel; + else + return spNone; +} + +/* inherits documentation from base class */ +double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) + return -1; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; +} + +/*! + Returns a list of all the plottables that have this axis as key or value axis. + + If you are only interested in plottables of type QCPGraph, see \ref graphs. + + \see graphs, items +*/ +QList QCPAxis::plottables() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that have this axis as key or value axis. + + \see plottables, items +*/ +QList QCPAxis::graphs() const +{ + QList result; + if (!mParentPlot) return result; + + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis. An item is considered + associated with an axis if at least one of its positions uses the axis as key or value axis. + + \see plottables, graphs +*/ +QList QCPAxis::items() const +{ + QList result; + if (!mParentPlot) return result; + + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to + QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) +*/ +QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) +{ + switch (side) + { + case QCP::msLeft: return atLeft; + case QCP::msRight: return atRight; + case QCP::msTop: return atTop; + case QCP::msBottom: return atBottom; + default: break; + } + qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; + return atLeft; +} + +/*! + Returns the axis type that describes the opposite axis of an axis with the specified \a type. +*/ +QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) +{ + switch (type) + { + case atLeft: return atRight; break; + case atRight: return atLeft; break; + case atBottom: return atTop; break; + case atTop: return atBottom; break; + default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; + } +} + +/* inherits documentation from base class */ +void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + SelectablePart part = details.value(); + if (mSelectableParts.testFlag(part)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^part : part); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAxis::deselectEvent(bool *selectionStateChanged) +{ + SelectableParts selBefore = mSelectedParts; + setSelectedParts(mSelectedParts & ~mSelectableParts); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis + (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref + QCPAxisRect::setRangeDragAxes) + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. +*/ +void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || + !mAxisRect->rangeDrag().testFlag(orientation()) || + !mAxisRect->rangeDragAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + mDragStartRange = mRange; + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (mDragging) + { + const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); + const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); + if (mScaleType == QCPAxis::stLinear) + { + const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); + setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); + } else if (mScaleType == QCPAxis::stLogarithmic) + { + const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); + setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); + } + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user drag individual axes + exclusively, by startig the drag on top of the axis. + + \seebaseclassmethod + + \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis + rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. + + \see QCPAxis::mousePressEvent +*/ +void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + This mouse event reimplementation provides the functionality to let the user zoom individual axes + exclusively, by performing the wheel event on top of the axis. + + For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect + must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis + (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref + QCPAxisRect::setRangeZoomAxes) + + \seebaseclassmethod + + \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the + axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. +*/ +void QCPAxis::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || + !mAxisRect->rangeZoom().testFlag(orientation()) || + !mAxisRect->rangeZoomAxes(orientation()).contains(this)) + { + event->ignore(); + return; + } + + const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); + scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); + mParentPlot->replot(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing axis lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); +} + +/*! \internal + + Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. + + \seebaseclassmethod +*/ +void QCPAxis::draw(QCPPainter *painter) +{ + QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + subTickPositions.reserve(mSubTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->basePen = getBasePen(); + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->labelColor = getLabelColor(); + mAxisPainter->label = mLabel; + mAxisPainter->substituteExponent = mNumberBeautifulPowers; + mAxisPainter->tickPen = getTickPen(); + mAxisPainter->subTickPen = getSubTickPen(); + mAxisPainter->tickLabelFont = getTickLabelFont(); + mAxisPainter->tickLabelColor = getTickLabelColor(); + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; + mAxisPainter->reversedEndings = mRangeReversed; + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + mAxisPainter->subTickPositions = subTickPositions; + mAxisPainter->draw(painter); +} + +/*! \internal + + Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling + QCPAxisTicker::generate on the currently installed ticker. + + If a change in the label text/count is detected, the cached axis margin is invalidated to make + sure the next margin calculation recalculates the label sizes and returns an up-to-date value. +*/ +void QCPAxis::setupTickVectors() +{ + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; + + QVector oldLabels = mTickVectorLabels; + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too +} + +/*! \internal + + Returns the pen that is used to draw the axis base line. Depending on the selection state, this + is either mSelectedBasePen or mBasePen. +*/ +QPen QCPAxis::getBasePen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; +} + +/*! \internal + + Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this + is either mSelectedTickPen or mTickPen. +*/ +QPen QCPAxis::getTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; +} + +/*! \internal + + Returns the pen that is used to draw the subticks. Depending on the selection state, this + is either mSelectedSubTickPen or mSubTickPen. +*/ +QPen QCPAxis::getSubTickPen() const +{ + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; +} + +/*! \internal + + Returns the font that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelFont or mTickLabelFont. +*/ +QFont QCPAxis::getTickLabelFont() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; +} + +/*! \internal + + Returns the font that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelFont or mLabelFont. +*/ +QFont QCPAxis::getLabelFont() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; +} + +/*! \internal + + Returns the color that is used to draw the tick labels. Depending on the selection state, this + is either mSelectedTickLabelColor or mTickLabelColor. +*/ +QColor QCPAxis::getTickLabelColor() const +{ + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; +} + +/*! \internal + + Returns the color that is used to draw the axis label. Depending on the selection state, this + is either mSelectedLabelColor or mLabelColor. +*/ +QColor QCPAxis::getLabelColor() const +{ + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; +} + +/*! \internal + + Returns the appropriate outward margin for this axis. It is needed if \ref + QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref + atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom + margin and so forth. For the calculation, this function goes through similar steps as \ref draw, + so changing one function likely requires the modification of the other one as well. + + The margin consists of the outward tick length, tick label padding, tick label size, label + padding, label size, and padding. + + The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. + unchanged are very fast. +*/ +int QCPAxis::calculateMargin() +{ + if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis + return 0; + + if (mCachedMarginValid) + return mCachedMargin; + + // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels + int margin = 0; + + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve(mTickVector.size()); + tickLabels.reserve(mTickVector.size()); + + if (mTicks) + { + for (int i=0; itype = mAxisType; + mAxisPainter->labelFont = getLabelFont(); + mAxisPainter->label = mLabel; + mAxisPainter->tickLabelFont = mTickLabelFont; + mAxisPainter->axisRect = mAxisRect->rect(); + mAxisPainter->viewportRect = mParentPlot->viewport(); + mAxisPainter->tickPositions = tickPositions; + mAxisPainter->tickLabels = tickLabels; + margin += mAxisPainter->size(); + margin += mPadding; + + mCachedMargin = margin; + mCachedMarginValid = true; + return margin; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAxis::selectionCategory() const +{ + return QCP::iSelectAxes; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisPainterPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisPainterPrivate + + \internal + \brief (Private) + + This is a private class and not part of the public QCustomPlot interface. + + It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and + axis label. It also buffers the labels to reduce replot times. The parameters are configured by + directly accessing the public member variables. +*/ + +/*! + Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every + redraw, to utilize the caching mechanisms. +*/ +QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : + type(QCPAxis::atLeft), + basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + lowerEnding(QCPLineEnding::esNone), + upperEnding(QCPLineEnding::esNone), + labelPadding(0), + tickLabelPadding(0), + tickLabelRotation(0), + tickLabelSide(QCPAxis::lsOutside), + substituteExponent(true), + numberMultiplyCross(false), + tickLengthIn(5), + tickLengthOut(0), + subTickLengthIn(2), + subTickLengthOut(0), + tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + offset(0), + abbreviateDecimalPowers(false), + reversedEndings(false), + mParentPlot(parentPlot), + mLabelCache(16) // cache at most 16 (tick) labels +{ +} + +QCPAxisPainterPrivate::~QCPAxisPainterPrivate() +{ +} + +/*! \internal + + Draws the axis with the specified \a painter. + + The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set + here, too. +*/ +void QCPAxisPainterPrivate::draw(QCPPainter *painter) +{ + QByteArray newHash = generateLabelParameterHash(); + if (newHash != mLabelParameterHash) + { + mLabelCache.clear(); + mLabelParameterHash = newHash; + } + + QPoint origin; + switch (type) + { + case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; + case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; + case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; + case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; + } + + double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) + switch (type) + { + case QCPAxis::atTop: yCor = -1; break; + case QCPAxis::atRight: xCor = 1; break; + default: break; + } + int margin = 0; + // draw baseline: + QLineF baseLine; + painter->setPen(basePen); + if (QCPAxis::orientation(type) == Qt::Horizontal) + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); + else + baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); + if (reversedEndings) + baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later + painter->drawLine(baseLine); + + // draw ticks: + if (!tickPositions.isEmpty()) + { + painter->setPen(tickPen); + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); + } + } + + // draw subticks: + if (!subTickPositions.isEmpty()) + { + painter->setPen(subTickPen); + // direction of ticks ("inward" is right for left axis and left for right axis) + int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; + if (QCPAxis::orientation(type) == Qt::Horizontal) + { + for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); + } else + { + for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); + } + } + margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // draw axis base endings: + bool antialiasingBackup = painter->antialiasing(); + painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't + painter->setBrush(QBrush(basePen.color())); + QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); + if (lowerEnding.style() != QCPLineEnding::esNone) + lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); + if (upperEnding.style() != QCPLineEnding::esNone) + upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); + painter->setAntialiasing(antialiasingBackup); + + // tick labels: + QRect oldClipRect; + if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect + { + oldClipRect = painter->clipRegion().boundingRect(); + painter->setClipRect(axisRect); + } + QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label + if (!tickLabels.isEmpty()) + { + if (tickLabelSide == QCPAxis::lsOutside) + margin += tickLabelPadding; + painter->setFont(tickLabelFont); + painter->setPen(QPen(tickLabelColor)); + const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); + int distanceToAxis = margin; + if (tickLabelSide == QCPAxis::lsInside) + distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + for (int i=0; isetClipRect(oldClipRect); + + // axis label: + QRect labelBounds; + if (!label.isEmpty()) + { + margin += labelPadding; + painter->setFont(labelFont); + painter->setPen(QPen(labelColor)); + labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); + if (type == QCPAxis::atLeft) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); + painter->rotate(-90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atRight) + { + QTransform oldTransform = painter->transform(); + painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); + painter->rotate(90); + painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + painter->setTransform(oldTransform); + } + else if (type == QCPAxis::atTop) + painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + else if (type == QCPAxis::atBottom) + painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + } + + // set selection boxes: + int selectionTolerance = 0; + if (mParentPlot) + selectionTolerance = mParentPlot->selectionTolerance(); + else + qDebug() << Q_FUNC_INFO << "mParentPlot is null"; + int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); + int selAxisInSize = selectionTolerance; + int selTickLabelSize; + int selTickLabelOffset; + if (tickLabelSide == QCPAxis::lsOutside) + { + selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; + } else + { + selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); + selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + } + int selLabelSize = labelBounds.height(); + int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; + if (type == QCPAxis::atLeft) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atRight) + { + mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); + mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); + mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); + } else if (type == QCPAxis::atTop) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); + } else if (type == QCPAxis::atBottom) + { + mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); + mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); + mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); + } + mAxisSelectionBox = mAxisSelectionBox.normalized(); + mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); + mLabelSelectionBox = mLabelSelectionBox.normalized(); + // draw hitboxes for debug purposes: + //painter->setBrush(Qt::NoBrush); + //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); +} + +/*! \internal + + Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone + direction) needed to fit the axis. +*/ +int QCPAxisPainterPrivate::size() const +{ + int result = 0; + + // get length of tick marks pointing outwards: + if (!tickPositions.isEmpty()) + result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); + + // calculate size of tick labels: + if (tickLabelSide == QCPAxis::lsOutside) + { + QSize tickLabelsSize(0, 0); + if (!tickLabels.isEmpty()) + { + for (int i=0; ibufferDevicePixelRatio())); + result.append(QByteArray::number(tickLabelRotation)); + result.append(QByteArray::number((int)tickLabelSide)); + result.append(QByteArray::number((int)substituteExponent)); + result.append(QByteArray::number((int)numberMultiplyCross)); + result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); + result.append(tickLabelFont.toString().toLatin1()); + return result; +} + +/*! \internal + + Draws a single tick label with the provided \a painter, utilizing the internal label cache to + significantly speed up drawing of labels that were drawn in previous calls. The tick label is + always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in + pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence + for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), + at which the label should be drawn. + + In order to later draw the axis label in a place that doesn't overlap with the tick labels, the + largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref + drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a + tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently + holds. + + The label is drawn with the font and pen that are currently set on the \a painter. To draw + superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref + getTickLabelData). +*/ +void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) +{ + // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! + if (text.isEmpty()) return; + QSize finalSize; + QPointF labelAnchor; + switch (type) + { + case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; + case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; + case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; + case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; + } + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled + { + CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache + if (!cachedLabel) // no cached label existed, create it + { + cachedLabel = new CachedLabel; + TickLabelData labelData = getTickLabelData(painter->font(), text); + cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); + if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) + { + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif +#endif + } else + cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); + cachedLabel->pixmap.fill(Qt::transparent); + QCPPainter cachePainter(&cachedLabel->pixmap); + cachePainter.setPen(painter->pen()); + drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); + } + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); + else + labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } + mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created + } else // label caching disabled, draw text directly on surface: + { + TickLabelData labelData = getTickLabelData(painter->font(), text); + QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); + // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): + bool labelClippedByBorder = false; + if (tickLabelSide == QCPAxis::lsOutside) + { + if (QCPAxis::orientation(type) == Qt::Horizontal) + labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); + else + labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); + } + if (!labelClippedByBorder) + { + drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); + finalSize = labelData.rotatedTotalBounds.size(); + } + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a + y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to + directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when + QCP::phCacheLabels plotting hint is not set. +*/ +void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const +{ + // backup painter settings that we're about to change: + QTransform oldTransform = painter->transform(); + QFont oldFont = painter->font(); + + // transform painter to position/rotation: + painter->translate(x, y); + if (!qFuzzyIsNull(tickLabelRotation)) + painter->rotate(tickLabelRotation); + + // draw text: + if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); + if (!labelData.suffixPart.isEmpty()) + painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); + painter->setFont(labelData.expFont); + painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); + } else + { + painter->setFont(labelData.baseFont); + painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); + } + + // reset painter settings to what it was before: + painter->setTransform(oldTransform); + painter->setFont(oldFont); +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Transforms the passed \a text and \a font to a tickLabelData structure that can then be further + processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and + exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. +*/ +QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const +{ + TickLabelData result; + + // determine whether beautiful decimal powers should be used + bool useBeautifulPowers = false; + int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart + int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart + if (substituteExponent) + { + ePos = text.indexOf(QLatin1Char('e')); + if (ePos > 0 && text.at(ePos-1).isDigit()) + { + eLast = ePos; + while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) + ++eLast; + if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power + useBeautifulPowers = true; + } + } + + // calculate text bounding rects and do string preparation for beautiful decimal powers: + result.baseFont = font; + if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line + result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding + if (useBeautifulPowers) + { + // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: + result.basePart = text.left(ePos); + result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent + // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: + if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) + result.basePart = QLatin1String("10"); + else + result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); + result.expPart = text.mid(ePos+1, eLast-ePos); + // clip "+" and leading zeros off expPart: + while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' + result.expPart.remove(1, 1); + if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) + result.expPart.remove(0, 1); + // prepare smaller font for exponent: + result.expFont = font; + if (result.expFont.pointSize() > 0) + result.expFont.setPointSize(result.expFont.pointSize()*0.75); + else + result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); + // calculate bounding rects of base part(s), exponent part and total one: + result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); + result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); + if (!result.suffixPart.isEmpty()) + result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); + result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA + } else // useBeautifulPowers == false + { + result.basePart = text; + result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); + } + result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler + + // calculate possibly different bounding rect after rotation: + result.rotatedTotalBounds = result.totalBounds; + if (!qFuzzyIsNull(tickLabelRotation)) + { + QTransform transform; + transform.rotate(tickLabelRotation); + result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); + } + + return result; +} + +/*! \internal + + This is a \ref placeTickLabel helper function. + + Calculates the offset at which the top left corner of the specified tick label shall be drawn. + The offset is relative to a point right next to the tick the label belongs to. + + This function is thus responsible for e.g. centering tick labels under ticks and positioning them + appropriately when they are rotated. +*/ +QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const +{ + /* + calculate label offset from base point at tick (non-trivial, for best visual appearance): short + explanation for bottom axis: The anchor, i.e. the point in the label that is placed + horizontally under the corresponding tick is always on the label side that is closer to the + axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height + is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text + will be centered under the tick (i.e. displaced horizontally by half its height). At the same + time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick + labels. + */ + bool doRotation = !qFuzzyIsNull(tickLabelRotation); + bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. + double radians = tickLabelRotation/180.0*M_PI; + int x=0, y=0; + if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); + y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = -labelData.totalBounds.width(); + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height(); + y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; + } else + { + x = 0; + y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; + } + } else + { + x = 0; + y = -labelData.totalBounds.height()/2.0; + } + } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; + y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); + } else + { + x = -qSin(-radians)*labelData.totalBounds.height()/2.0; + y = -qCos(-radians)*labelData.totalBounds.height(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = -labelData.totalBounds.height(); + } + } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label + { + if (doRotation) + { + if (tickLabelRotation > 0) + { + x = +qSin(radians)*labelData.totalBounds.height()/2.0; + y = 0; + } else + { + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; + y = +qSin(-radians)*labelData.totalBounds.width(); + } + } else + { + x = -labelData.totalBounds.width()/2.0; + y = 0; + } + } + + return QPointF(x, y); +} + +/*! \internal + + Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label + to be drawn, depending on number format etc. Since only the largest tick label is wanted for the + margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a + smaller width/height. +*/ +void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const +{ + // note: this function must return the same tick label sizes as the placeTickLabel function. + QSize finalSize; + if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label + { + const CachedLabel *cachedLabel = mLabelCache.object(text); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + } else // label caching disabled or no label with this text cached: + { + TickLabelData labelData = getTickLabelData(font, text); + finalSize = labelData.rotatedTotalBounds.size(); + } + + // expand passed tickLabelsSize if current tick label is larger: + if (finalSize.width() > tickLabelsSize->width()) + tickLabelsSize->setWidth(finalSize.width()); + if (finalSize.height() > tickLabelsSize->height()) + tickLabelsSize->setHeight(finalSize.height()); +} +/* end of 'src/axis/axis.cpp' */ + + +/* including file 'src/scatterstyle.cpp', size 17450 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPScatterStyle +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPScatterStyle + \brief Represents the visual appearance of scatter points + + This class holds information about shape, color and size of scatter points. In plottables like + QCPGraph it is used to store how scatter points shall be drawn. For example, \ref + QCPGraph::setScatterStyle takes a QCPScatterStyle instance. + + A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a + fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can + be controlled with \ref setSize. + + \section QCPScatterStyle-defining Specifying a scatter style + + You can set all these configurations either by calling the respective functions on an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 + + Or you can use one of the various constructors that take different parameter combinations, making + it easy to specify a scatter style in a single call, like so: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 + + \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable + + There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref + QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref + isPenDefined will return false. It leads to scatter points that inherit the pen from the + plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line + color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes + it very convenient to set up typical scatter settings: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation + + Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works + because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly + into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) + constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref + ScatterShape, where actually a QCPScatterStyle is expected. + + \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps + + QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. + + For custom shapes, you can provide a QPainterPath with the desired shape to the \ref + setCustomPath function or call the constructor that takes a painter path. The scatter shape will + automatically be set to \ref ssCustom. + + For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the + constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. + Note that \ref setSize does not influence the appearance of the pixmap. +*/ + +/* start documentation of inline functions */ + +/*! \fn bool QCPScatterStyle::isNone() const + + Returns whether the scatter shape is \ref ssNone. + + \see setShape +*/ + +/*! \fn bool QCPScatterStyle::isPenDefined() const + + Returns whether a pen has been defined for this scatter style. + + The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those + are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen + is undefined, the pen of the respective plottable will be used for drawing scatters. + + If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call + \ref undefinePen. + + \see setPen +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle() : + mSize(6), + mShape(ssNone), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or + brush is defined. + + Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited + from the plottable that uses this scatter style. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : + mSize(size), + mShape(shape), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + and size to \a size. No brush is defined, i.e. the scatter point will not be filled. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(Qt::NoBrush), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, + the brush color to \a fill (with a solid pattern), and size to \a size. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : + mSize(size), + mShape(shape), + mPen(QPen(color)), + mBrush(QBrush(fill)), + mPenDefined(true) +{ +} + +/*! + Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the + brush to \a brush, and size to \a size. + + \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen + and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n + QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n + doesn't necessarily lead C++ to use this constructor in some cases, but might mistake + Qt::NoPen for a QColor and use the + \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) + constructor instead (which will lead to an unexpected look of the scatter points). To prevent + this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) + instead of just Qt::blue, to clearly point out to the compiler that this constructor is + wanted. +*/ +QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(shape), + mPen(pen), + mBrush(brush), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape + is set to \ref ssPixmap. +*/ +QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : + mSize(5), + mShape(ssPixmap), + mPen(Qt::NoPen), + mBrush(Qt::NoBrush), + mPixmap(pixmap), + mPenDefined(false) +{ +} + +/*! + Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The + scatter shape is set to \ref ssCustom. + + The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly + different meaning than for built-in scatter points: The custom path will be drawn scaled by a + factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its + original size by default. To for example double the size of the path, set \a size to 12. +*/ +QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : + mSize(size), + mShape(ssCustom), + mPen(pen), + mBrush(brush), + mCustomPath(customPath), + mPenDefined(pen.style() != Qt::NoPen) +{ +} + +/*! + Copies the specified \a properties from the \a other scatter style to this scatter style. +*/ +void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) +{ + if (properties.testFlag(spPen)) + { + setPen(other.pen()); + if (!other.isPenDefined()) + undefinePen(); + } + if (properties.testFlag(spBrush)) + setBrush(other.brush()); + if (properties.testFlag(spSize)) + setSize(other.size()); + if (properties.testFlag(spShape)) + { + setShape(other.shape()); + if (other.shape() == ssPixmap) + setPixmap(other.pixmap()); + else if (other.shape() == ssCustom) + setCustomPath(other.customPath()); + } +} + +/*! + Sets the size (pixel diameter) of the drawn scatter points to \a size. + + \see setShape +*/ +void QCPScatterStyle::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the shape to \a shape. + + Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref + ssPixmap and \ref ssCustom, respectively. + + \see setSize +*/ +void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) +{ + mShape = shape; +} + +/*! + Sets the pen that will be used to draw scatter points to \a pen. + + If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after + a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen + previously by calling this function and now wish to undefine the pen, call \ref undefinePen. + + \see setBrush +*/ +void QCPScatterStyle::setPen(const QPen &pen) +{ + mPenDefined = true; + mPen = pen; +} + +/*! + Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter + shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. + + \see setPen +*/ +void QCPScatterStyle::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the pixmap that will be drawn as scatter point to \a pixmap. + + Note that \ref setSize does not influence the appearance of the pixmap. + + The scatter shape is automatically set to \ref ssPixmap. +*/ +void QCPScatterStyle::setPixmap(const QPixmap &pixmap) +{ + setShape(ssPixmap); + mPixmap = pixmap; +} + +/*! + Sets the custom shape that will be drawn as scatter point to \a customPath. + + The scatter shape is automatically set to \ref ssCustom. +*/ +void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) +{ + setShape(ssCustom); + mCustomPath = customPath; +} + +/*! + Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen + implies). + + A call to \ref setPen will define a pen. +*/ +void QCPScatterStyle::undefinePen() +{ + mPenDefined = false; +} + +/*! + Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an + undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. + + This function is used by plottables (or any class that wants to draw scatters) just before a + number of scatters with this style shall be drawn with the \a painter. + + \see drawShape +*/ +void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const +{ + painter->setPen(mPenDefined ? mPen : defaultPen); + painter->setBrush(mBrush); +} + +/*! + Draws the scatter shape with \a painter at position \a pos. + + This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be + called before scatter points are drawn with \ref drawShape. + + \see applyTo +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const +{ + drawShape(painter, pos.x(), pos.y()); +} + +/*! \overload + Draws the scatter shape with \a painter at position \a x and \a y. +*/ +void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const +{ + double w = mSize/2.0; + switch (mShape) + { + case ssNone: break; + case ssDot: + { + painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); + break; + } + case ssCross: + { + painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); + painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); + break; + } + case ssPlus: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCircle: + { + painter->drawEllipse(QPointF(x , y), w, w); + break; + } + case ssDisc: + { + QBrush b = painter->brush(); + painter->setBrush(painter->pen().color()); + painter->drawEllipse(QPointF(x , y), w, w); + painter->setBrush(b); + break; + } + case ssSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + break; + } + case ssDiamond: + { + QPointF lineArray[4] = {QPointF(x-w, y), + QPointF( x, y-w), + QPointF(x+w, y), + QPointF( x, y+w)}; + painter->drawPolygon(lineArray, 4); + break; + } + case ssStar: + { + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); + break; + } + case ssTriangle: + { + QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), + QPointF(x+w, y+0.755*w), + QPointF( x, y-0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssTriangleInverted: + { + QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), + QPointF(x+w, y-0.755*w), + QPointF( x, y+0.977*w)}; + painter->drawPolygon(lineArray, 3); + break; + } + case ssCrossSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); + painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); + break; + } + case ssPlusSquare: + { + painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); + painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssCrossCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); + painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); + break; + } + case ssPlusCircle: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x-w, y, x+w, y)); + painter->drawLine(QLineF( x, y+w, x, y-w)); + break; + } + case ssPeace: + { + painter->drawEllipse(QPointF(x, y), w, w); + painter->drawLine(QLineF(x, y-w, x, y+w)); + painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); + painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); + break; + } + case ssPixmap: + { + const double widthHalf = mPixmap.width()*0.5; + const double heightHalf = mPixmap.height()*0.5; +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) + const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#else + const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); +#endif + if (clipRect.contains(x, y)) + painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); + break; + } + case ssCustom: + { + QTransform oldTransform = painter->transform(); + painter->translate(x, y); + painter->scale(mSize/6.0, mSize/6.0); + painter->drawPath(mCustomPath); + painter->setTransform(oldTransform); + break; + } + } +} +/* end of 'src/scatterstyle.cpp' */ + +//amalgamation: add datacontainer.cpp + +/* including file 'src/plottable.cpp', size 38845 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecorator +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecorator + \brief Controls how a plottable's data selection is drawn + + Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref + QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. + + The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the + scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref + QCPScatterStyle is itself composed of different properties such as color shape and size, the + decorator allows specifying exactly which of those properties shall be used for the selected data + point, via \ref setUsedScatterProperties. + + A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref + QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance + of selected segments. + + Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is + especially useful since plottables take ownership of the passed selection decorator, and thus the + same decorator instance can not be passed to multiple plottables. + + Selection decorators can also themselves perform drawing operations by reimplementing \ref + drawDecoration, which is called by the plottable's draw method. The base class \ref + QCPSelectionDecorator does not make use of this however. For example, \ref + QCPSelectionDecoratorBracket draws brackets around selected data segments. +*/ + +/*! + Creates a new QCPSelectionDecorator instance with default values +*/ +QCPSelectionDecorator::QCPSelectionDecorator() : + mPen(QColor(80, 80, 255), 2.5), + mBrush(Qt::NoBrush), + mScatterStyle(), + mUsedScatterProperties(QCPScatterStyle::spNone), + mPlottable(0) +{ +} + +QCPSelectionDecorator::~QCPSelectionDecorator() +{ +} + +/*! + Sets the pen that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the brush that will be used by the parent plottable to draw selected data segments. +*/ +void QCPSelectionDecorator::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the scatter style that will be used by the parent plottable to draw scatters in selected + data segments. + + \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the + plottable. The used properties can also be changed via \ref setUsedScatterProperties. +*/ +void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) +{ + mScatterStyle = scatterStyle; + setUsedScatterProperties(usedProperties); +} + +/*! + Use this method to define which properties of the scatter style (set via \ref setScatterStyle) + will be used for selected data segments. All properties of the scatter style that are not + specified in \a properties will remain as specified in the plottable's original scatter style. + + \see QCPScatterStyle::ScatterProperty +*/ +void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) +{ + mUsedScatterProperties = properties; +} + +/*! + Sets the pen of \a painter to the pen of this selection decorator. + + \see applyBrush, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyPen(QCPPainter *painter) const +{ + painter->setPen(mPen); +} + +/*! + Sets the brush of \a painter to the brush of this selection decorator. + + \see applyPen, getFinalScatterStyle +*/ +void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const +{ + painter->setBrush(mBrush); +} + +/*! + Returns the scatter style that the parent plottable shall use for selected scatter points. The + plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending + on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this + selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. + + \see applyPen, applyBrush, setScatterStyle +*/ +QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const +{ + QCPScatterStyle result(unselectedStyle); + result.setFromOther(mScatterStyle, mUsedScatterProperties); + + // if style shall inherit pen from plottable (has no own pen defined), give it the selected + // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the + // plottable: + if (!result.isPenDefined()) + result.setPen(mPen); + + return result; +} + +/*! + Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to + this selection decorator. +*/ +void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) +{ + setPen(other->pen()); + setBrush(other->brush()); + setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); +} + +/*! + This method is called by all plottables' draw methods to allow custom selection decorations to be + drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data + selection for which the decoration shall be drawn. + + The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so + this method does nothing. +*/ +void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + Q_UNUSED(painter) + Q_UNUSED(selection) +} + +/*! \internal + + This method is called as soon as a selection decorator is associated with a plottable, by a call + to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access + data points via the \ref QCPAbstractPlottable::interface1D interface). + + If the selection decorator was already added to a different plottable before, this method aborts + the registration and returns false. +*/ +bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottable) + { + mPlottable = plottable; + return true; + } else + { + qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); + return false; + } +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractPlottable +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractPlottable + \brief The abstract base class for all data representing objects in a plot. + + It defines a very basic interface like name, pen, brush, visibility etc. Since this class is + abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to + create new ways of displaying data (see "Creating own plottables" below). Plottables that display + one-dimensional data (i.e. data points have a single key dimension and one or multiple values at + each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details + there. + + All further specifics are in the subclasses, for example: + \li A normal graph with possibly a line and/or scatter points \ref QCPGraph + (typically created with \ref QCustomPlot::addGraph) + \li A parametric curve: \ref QCPCurve + \li A bar chart: \ref QCPBars + \li A statistical box plot: \ref QCPStatisticalBox + \li A color encoded two-dimensional map: \ref QCPColorMap + \li An OHLC/Candlestick chart: \ref QCPFinancial + + \section plottables-subclassing Creating own plottables + + Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display + two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) + data dimensions. If you want to display data with only one logical key dimension, you should + rather derive from \ref QCPAbstractPlottable1D. + + If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must + implement: + \li \ref selectTest + \li \ref draw + \li \ref drawLegendIcon + \li \ref getKeyRange + \li \ref getValueRange + + See the documentation of those functions for what they need to do. + + For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot + coordinates to pixel coordinates. This function is quite convenient, because it takes the + orientation of the key and value axes into account for you (x and y are swapped when the key axis + is vertical and the value axis horizontal). If you are worried about performance (i.e. you need + to translate many points in a loop like QCPGraph), you can directly use \ref + QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis + yourself. + + Here are some important members you inherit from QCPAbstractPlottable: + + + + + + + + + + + + + + + + + + + + + + + + + + +
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable + (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable + (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates + to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of + the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. + When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. + Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done + by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
+*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const + + Provides access to the selection decorator of this plottable. The selection decorator controls + how selected data ranges are drawn (e.g. their pen color and fill), see \ref + QCPSelectionDecorator for details. + + If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref + setSelectionDecorator. +*/ + +/*! \fn bool QCPAbstractPlottable::selected() const + + Returns true if there are any data points of the plottable currently selected. Use \ref selection + to retrieve the current \ref QCPDataSelection. +*/ + +/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const + + Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on + this plottable. + + \see selected, setSelection, setSelectable +*/ + +/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() + + If this plottable is a one-dimensional plottable, i.e. it implements the \ref + QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case + of a \ref QCPColorMap) returns zero. + + You can use this method to gain read access to data coordinates while holding a pointer to the + abstract base class only. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of pure virtual functions */ + +/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 + \internal + + called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation + of this plottable inside \a rect, next to the plottable name. + + The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't + appear outside the legend icon border. +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 + + Returns the coordinate range that all data in this plottable span in the key axis dimension. For + logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref + QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only + negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points + will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref + QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could + be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getValueRange +*/ + +/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 + + Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span + in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref + QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign + domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and + all positive points will be ignored for range calculation. For no restriction, just set \a + inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates + whether a range could be found or not. If this is false, you shouldn't use the returned range + (e.g. no points in data). + + If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), + all data points are considered, without any restriction on the keys. + + Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by + this function may have size zero (e.g. when there is only one data point). In this case \a + foundRange would return true, but the returned range is not a valid range in terms of \ref + QCPRange::validRange. + + \see rescaleAxes, getKeyRange +*/ + +/* end of documentation of pure virtual functions */ +/* start of documentation of signals */ + +/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether + there are any points selected or not. + + \see selectionChanged(const QCPDataSelection &selection) +*/ + +/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) + + This signal is emitted when the selection state of this plottable has changed, either by user + interaction or by a direct call to \ref setSelection. The parameter \a selection holds the + currently selected data ranges. + + \see selectionChanged(bool selected) +*/ + +/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); + + This signal is emitted when the selectability of this plottable has changed. + + \see setSelectable +*/ + +/* end of documentation of signals */ + +/*! + Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as + its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance + and have perpendicular orientations. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, + it can't be directly instantiated. + + You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. +*/ +QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), + mName(), + mAntialiasedFill(true), + mAntialiasedScatters(true), + mPen(Qt::black), + mBrush(Qt::NoBrush), + mKeyAxis(keyAxis), + mValueAxis(valueAxis), + mSelectable(QCP::stWhole), + mSelectionDecorator(0) +{ + if (keyAxis->parentPlot() != valueAxis->parentPlot()) + qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; + if (keyAxis->orientation() == valueAxis->orientation()) + qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; + + mParentPlot->registerPlottable(this); + setSelectionDecorator(new QCPSelectionDecorator); +} + +QCPAbstractPlottable::~QCPAbstractPlottable() +{ + if (mSelectionDecorator) + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + The name is the textual representation of this plottable as it is displayed in the legend + (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. +*/ +void QCPAbstractPlottable::setName(const QString &name) +{ + mName = name; +} + +/*! + Sets whether fills of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedFill(bool enabled) +{ + mAntialiasedFill = enabled; +} + +/*! + Sets whether the scatter symbols of this plottable are drawn antialiased or not. + + Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) +{ + mAntialiasedScatters = enabled; +} + +/*! + The pen is used to draw basic lines that make up the plottable representation in the + plot. + + For example, the \ref QCPGraph subclass draws its graph lines with this pen. + + \see setBrush +*/ +void QCPAbstractPlottable::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + The brush is used to draw basic fills of the plottable representation in the + plot. The Fill can be a color, gradient or texture, see the usage of QBrush. + + For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when + it's not set to Qt::NoBrush. + + \see setPen +*/ +void QCPAbstractPlottable::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal + to the plottable's value axis. This function performs no checks to make sure this is the case. + The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the + y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setValueAxis +*/ +void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) +{ + mKeyAxis = axis; +} + +/*! + The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is + orthogonal to the plottable's key axis. This function performs no checks to make sure this is the + case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and + the y-axis (QCustomPlot::yAxis) as value axis. + + Normally, the key and value axes are set in the constructor of the plottable (or \ref + QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). + + \see setKeyAxis +*/ +void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) +{ + mValueAxis = axis; +} + + +/*! + Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently + (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref + selectionDecorator). + + The entire selection mechanism for plottables is handled automatically when \ref + QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when + you wish to change the selection state programmatically. + + Using \ref setSelectable you can further specify for each plottable whether and to which + granularity it is selectable. If \a selection is not compatible with the current \ref + QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted + accordingly (see \ref QCPDataSelection::enforceType). + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractPlottable::setSelection(QCPDataSelection selection) +{ + selection.enforceType(mSelectable); + if (mSelection != selection) + { + mSelection = selection; + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } +} + +/*! + Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to + customize the visual representation of selected data ranges further than by using the default + QCPSelectionDecorator. + + The plottable takes ownership of the \a decorator. + + The currently set decorator can be accessed via \ref selectionDecorator. +*/ +void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) +{ + if (decorator) + { + if (decorator->registerWithPlottable(this)) + { + if (mSelectionDecorator) // delete old decorator if necessary + delete mSelectionDecorator; + mSelectionDecorator = decorator; + } + } else if (mSelectionDecorator) // just clear decorator + { + delete mSelectionDecorator; + mSelectionDecorator = 0; + } +} + +/*! + Sets whether and to which granularity this plottable can be selected. + + A selection can happen by clicking on the QCustomPlot surface (When \ref + QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect + (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by + calling \ref setSelection. + + \see setSelection, QCP::SelectionType +*/ +void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + QCPDataSelection oldSelection = mSelection; + mSelection.enforceType(mSelectable); + Q_EMIT selectableChanged(mSelectable); + if (mSelection != oldSelection) + { + Q_EMIT selectionChanged(selected()); + Q_EMIT selectionChanged(mSelection); + } + } +} + + +/*! + Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. + + \see pixelsToCoords, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + x = keyAxis->coordToPixel(key); + y = valueAxis->coordToPixel(value); + } else + { + y = keyAxis->coordToPixel(key); + x = valueAxis->coordToPixel(value); + } +} + +/*! \overload + + Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. +*/ +const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); + else + return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); +} + +/*! + Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, + taking the orientations of the axes associated with this plottable into account (e.g. whether key + represents x or y). + + \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. + + \see coordsToPixels, QCPAxis::coordToPixel +*/ +void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + key = keyAxis->pixelToCoord(x); + value = valueAxis->pixelToCoord(y); + } else + { + key = keyAxis->pixelToCoord(y); + value = valueAxis->pixelToCoord(x); + } +} + +/*! \overload + + Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. +*/ +void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const +{ + pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); +} + +/*! + Rescales the key and value axes associated with this plottable to contain all displayed data, so + the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make + sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. + Instead it will stay in the current sign domain and ignore all parts of the plottable that lie + outside of that domain. + + \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show + multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has + \a onlyEnlarge set to false (the default), and all subsequent set to true. + + \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale +*/ +void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const +{ + rescaleKeyAxis(onlyEnlarge); + rescaleValueAxis(onlyEnlarge); +} + +/*! + Rescales the key axis of the plottable so the whole plottable is visible. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (keyAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getKeyRange(foundRange, signDomain); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(keyAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (keyAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-keyAxis->range().size()/2.0; + newRange.upper = center+keyAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); + newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); + } + } + keyAxis->setRange(newRange); + } +} + +/*! + Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is + set to true, only the data points which are in the currently visible key axis range are + considered. + + Returns true if the axis was actually scaled. This might not be the case if this plottable has an + invalid range, e.g. because it has no data points. + + See \ref rescaleAxes for detailed behaviour. +*/ +void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCP::SignDomain signDomain = QCP::sdBoth; + if (valueAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + + bool foundRange; + QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); + if (foundRange) + { + if (onlyEnlarge) + newRange.expand(valueAxis->range()); + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + newRange.lower = center-valueAxis->range().size()/2.0; + newRange.upper = center+valueAxis->range().size()/2.0; + } else // scaleType() == stLogarithmic + { + newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); + newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); + } + } + valueAxis->setRange(newRange); + } +} + +/*! \overload + + Adds this plottable to the specified \a legend. + + Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. + when the legend exists and a legend item associated with this plottable isn't already in the + legend. + + If the plottable needs a more specialized representation in the legend, you can create a + corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead + of calling this method. + + \see removeFromLegend, QCPLegend::addItem +*/ +bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + if (legend->parentPlot() != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; + return false; + } + + if (!legend->hasItemWithPlottable(this)) + { + legend->addItem(new QCPPlottableLegendItem(legend, this)); + return true; + } else + return false; +} + +/*! \overload + + Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). + + \see removeFromLegend +*/ +bool QCPAbstractPlottable::addToLegend() +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return addToLegend(mParentPlot->legend); +} + +/*! \overload + + Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem + that is associated with this plottable is removed. + + Returns true on success, i.e. if the legend exists and a legend item associated with this + plottable was found and removed. + + \see addToLegend, QCPLegend::removeItem +*/ +bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const +{ + if (!legend) + { + qDebug() << Q_FUNC_INFO << "passed legend is null"; + return false; + } + + if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) + return legend->removeItem(lip); + else + return false; +} + +/*! \overload + + Removes the plottable from the legend of the parent QCustomPlot. + + \see addToLegend +*/ +bool QCPAbstractPlottable::removeFromLegend() const +{ + if (!mParentPlot || !mParentPlot->legend) + return false; + else + return removeFromLegend(mParentPlot->legend); +} + +/* inherits documentation from base class */ +QRect QCPAbstractPlottable::clipRect() const +{ + if (mKeyAxis && mValueAxis) + return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); + else + return QRect(); +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractPlottable::selectionCategory() const +{ + return QCP::iSelectPlottables; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable fills. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint +*/ +void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing plottable scatter points. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint +*/ +void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + + if (mSelectable != QCP::stNone) + { + QCPDataSelection newSelection = details.value(); + QCPDataSelection selectionBefore = mSelection; + if (additive) + { + if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit + { + if (selected()) + setSelection(QCPDataSelection()); + else + setSelection(newSelection); + } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments + { + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); + else + setSelection(mSelection+newSelection); + } + } else + setSelection(newSelection); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable != QCP::stNone) + { + QCPDataSelection selectionBefore = mSelection; + setSelection(QCPDataSelection()); + if (selectionStateChanged) + *selectionStateChanged = mSelection != selectionBefore; + } +} +/* end of 'src/plottable.cpp' */ + + +/* including file 'src/item.cpp', size 49269 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemAnchor +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemAnchor + \brief An anchor of an item to which positions can be attached to. + + An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't + control anything on its item, but provides a way to tie other items via their positions to the + anchor. + + For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. + Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can + attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by + calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the + QCPItemRect. This way the start of the line will now always follow the respective anchor location + on the rect item. + + Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an + anchor to other positions. + + To learn how to provide anchors in your own item subclasses, see the subclassing section of the + QCPAbstractItem documentation. +*/ + +/* start documentation of inline functions */ + +/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() + + Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if + it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). + + This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids + dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with + gcc compiler). +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : + mName(name), + mParentPlot(parentPlot), + mParentItem(parentItem), + mAnchorId(anchorId) +{ +} + +QCPItemAnchor::~QCPItemAnchor() +{ + // unregister as parent at children: + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } +} + +/*! + Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. + + The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the + parent item, QCPItemAnchor is just an intermediary. +*/ +QPointF QCPItemAnchor::pixelPosition() const +{ + if (mParentItem) + { + if (mAnchorId > -1) + { + return mParentItem->anchorPixelPosition(mAnchorId); + } else + { + qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; + return QPointF(); + } + } else + { + qDebug() << Q_FUNC_INFO << "no parent item set"; + return QPointF(); + } +} + +/*! \internal + + Adds \a pos to the childX list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.contains(pos)) + mChildrenX.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childX list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildX(QCPItemPosition *pos) +{ + if (!mChildrenX.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + +/*! \internal + + Adds \a pos to the childY list of this anchor, which keeps track of which children use this + anchor as parent anchor for the respective coordinate. This is necessary to notify the children + prior to destruction of the anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::addChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.contains(pos)) + mChildrenY.insert(pos); + else + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); +} + +/*! \internal + + Removes \a pos from the childY list of this anchor. + + Note that this function does not change the parent setting in \a pos. +*/ +void QCPItemAnchor::removeChildY(QCPItemPosition *pos) +{ + if (!mChildrenY.remove(pos)) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPosition +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPosition + \brief Manages the position of an item. + + Every item has at least one public QCPItemPosition member pointer which provides ways to position the + item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: + \a topLeft and \a bottomRight. + + QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type + defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel + coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also + possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref + setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y + direction, while following a plot coordinate in the X direction. + + A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie + multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) + are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) + means directly ontop of the parent anchor. For example, You could attach the \a start position of + a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line + always be centered under the text label, no matter where the text is moved to. For more advanced + plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see + \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X + direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B + in Y. + + Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent + anchor for other positions. + + To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This + works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref + setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified + pixel values. +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const + + Returns the current position type. + + If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the + type of the X coordinate. In that case rather use \a typeX() and \a typeY(). + + \see setType +*/ + +/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const + + Returns the current parent anchor. + + If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), + this method returns the parent anchor of the Y coordinate. In that case rather use \a + parentAnchorX() and \a parentAnchorY(). + + \see setParentAnchor +*/ + +/* end documentation of inline functions */ + +/*! + Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if + you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as + explained in the subclassing section of the QCPAbstractItem documentation. +*/ +QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : + QCPItemAnchor(parentPlot, parentItem, name), + mPositionTypeX(ptAbsolute), + mPositionTypeY(ptAbsolute), + mKey(0), + mValue(0), + mParentAnchorX(0), + mParentAnchorY(0) +{ +} + +QCPItemPosition::~QCPItemPosition() +{ + // unregister as parent at children: + // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then + // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition + Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) + { + if (child->parentAnchorX() == this) + child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + } + Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) + { + if (child->parentAnchorY() == this) + child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + } + // unregister as child in parent: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPItemPosition::axisRect() const +{ + return mAxisRect.data(); +} + +/*! + Sets the type of the position. The type defines how the coordinates passed to \ref setCoords + should be handled and how the QCPItemPosition should behave in the plot. + + The possible values for \a type can be separated in two main categories: + + \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords + and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. + By default, the QCustomPlot's x- and yAxis are used. + + \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This + corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref + ptAxisRectRatio. They differ only in the way the absolute position is described, see the + documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify + the axis rect with \ref setAxisRect. By default this is set to the main axis rect. + + Note that the position type \ref ptPlotCoords is only available (and sensible) when the position + has no parent anchor (\ref setParentAnchor). + + If the type is changed, the apparent pixel position on the plot is preserved. This means + the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. + + This method sets the type for both X and Y directions. It is also possible to set different types + for X and Y, see \ref setTypeX, \ref setTypeY. +*/ +void QCPItemPosition::setType(QCPItemPosition::PositionType type) +{ + setTypeX(type); + setTypeY(type); +} + +/*! + This method sets the position type of the X coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeY +*/ +void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) +{ + if (mPositionTypeX != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeX = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + This method sets the position type of the Y coordinate to \a type. + + For a detailed description of what a position type is, see the documentation of \ref setType. + + \see setType, setTypeX +*/ +void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) +{ + if (mPositionTypeY != type) + { + // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect + // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. + bool retainPixelPosition = true; + if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + retainPixelPosition = false; + if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + retainPixelPosition = false; + + QPointF pixel; + if (retainPixelPosition) + pixel = pixelPosition(); + + mPositionTypeY = type; + + if (retainPixelPosition) + setPixelPosition(pixel); + } +} + +/*! + Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now + follow any position changes of the anchor. The local coordinate system of positions with a parent + anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence + the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) + + if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved + during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position + will be exactly on top of the parent anchor. + + To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. + + If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is + set to \ref ptAbsolute, to keep the position in a valid state. + + This method sets the parent anchor for both X and Y directions. It is also possible to set + different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. +*/ +bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); + bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); + return successX && successY; +} + +/*! + This method sets the parent anchor of the X coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorY +*/ +bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorX(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) + setTypeX(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorX) + mParentAnchorX->removeChildX(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildX(this); + mParentAnchorX = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(0, coords().y()); + return true; +} + +/*! + This method sets the parent anchor of the Y coordinate to \a parentAnchor. + + For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. + + \see setParentAnchor, setParentAnchorX +*/ +bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +{ + // make sure self is not assigned as parent: + if (parentAnchor == this) + { + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + return false; + } + // make sure no recursive parent-child-relationships are created: + QCPItemAnchor *currentParent = parentAnchor; + while (currentParent) + { + if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + { + // is a QCPItemPosition, might have further parent, so keep iterating + if (currentParentPos == this) + { + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + return false; + } + currentParent = currentParentPos->parentAnchorY(); + } else + { + // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the + // same, to prevent a position being child of an anchor which itself depends on the position, + // because they're both on the same item: + if (currentParent->mParentItem == mParentItem) + { + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + return false; + } + break; + } + } + + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: + if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) + setTypeY(ptAbsolute); + + // save pixel position: + QPointF pixelP; + if (keepPixelPosition) + pixelP = pixelPosition(); + // unregister at current parent anchor: + if (mParentAnchorY) + mParentAnchorY->removeChildY(this); + // register at new parent anchor: + if (parentAnchor) + parentAnchor->addChildY(this); + mParentAnchorY = parentAnchor; + // restore pixel position under new parent: + if (keepPixelPosition) + setPixelPosition(pixelP); + else + setCoords(coords().x(), 0); + return true; +} + +/*! + Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type + (\ref setType, \ref setTypeX, \ref setTypeY). + + For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position + on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the + QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the + plot coordinate system defined by the axes set by \ref setAxes. By default those are the + QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available + coordinate types and their meaning. + + If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a + value must also be provided in the different coordinate systems. Here, the X type refers to \a + key, and the Y type refers to \a value. + + \see setPixelPosition +*/ +void QCPItemPosition::setCoords(double key, double value) +{ + mKey = key; + mValue = value; +} + +/*! \overload + + Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the + meaning of \a value of the \ref setCoords(double key, double value) method. +*/ +void QCPItemPosition::setCoords(const QPointF &pos) +{ + setCoords(pos.x(), pos.y()); +} + +/*! + Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It + includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). + + \see setPixelPosition +*/ +QPointF QCPItemPosition::pixelPosition() const +{ + QPointF result; + + // determine X: + switch (mPositionTypeX) + { + case ptAbsolute: + { + result.rx() = mKey; + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + result.rx() = mKey*mParentPlot->viewport().width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mParentPlot->viewport().left(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.rx() = mKey*mAxisRect.data()->width(); + if (mParentAnchorX) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mAxisRect.data()->left(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + result.rx() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + // determine Y: + switch (mPositionTypeY) + { + case ptAbsolute: + { + result.ry() = mValue; + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + result.ry() = mValue*mParentPlot->viewport().height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mParentPlot->viewport().top(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + result.ry() = mValue*mAxisRect.data()->height(); + if (mParentAnchorY) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mAxisRect.data()->top(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + result.ry() = mKeyAxis.data()->coordToPixel(mKey); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + result.ry() = mValueAxis.data()->coordToPixel(mValue); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + return result; +} + +/*! + When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the + coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and + yAxis of the QCustomPlot. +*/ +void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + mKeyAxis = keyAxis; + mValueAxis = valueAxis; +} + +/*! + When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the + coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of + the QCustomPlot. +*/ +void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) +{ + mAxisRect = axisRect; +} + +/*! + Sets the apparent pixel position. This works no matter what type (\ref setType) this + QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed + appropriately, to make the position finally appear at the specified pixel values. + + Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is + identical to that of \ref setCoords. + + \see pixelPosition, setCoords +*/ +void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) +{ + double x = pixelPosition.x(); + double y = pixelPosition.y(); + + switch (mPositionTypeX) + { + case ptAbsolute: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mParentPlot->viewport().left(); + x /= (double)mParentPlot->viewport().width(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mAxisRect.data()->left(); + x /= (double)mAxisRect.data()->width(); + } else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) + x = mKeyAxis.data()->pixelToCoord(x); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) + y = mValueAxis.data()->pixelToCoord(x); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + switch (mPositionTypeY) + { + case ptAbsolute: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mParentPlot->viewport().top(); + y /= (double)mParentPlot->viewport().height(); + break; + } + case ptAxisRectRatio: + { + if (mAxisRect) + { + if (mParentAnchorY) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mAxisRect.data()->top(); + y /= (double)mAxisRect.data()->height(); + } else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: + { + if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) + x = mKeyAxis.data()->pixelToCoord(y); + else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) + y = mValueAxis.data()->pixelToCoord(y); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + setCoords(x, y); +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractItem + \brief The abstract base class for all items in a plot. + + In QCustomPlot, items are supplemental graphical elements that are neither plottables + (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus + plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each + specific item has at least one QCPItemPosition member which controls the positioning. Some items + are defined by more than one coordinate and thus have two or more QCPItemPosition members (For + example, QCPItemRect has \a topLeft and \a bottomRight). + + This abstract base class defines a very basic interface like visibility and clipping. Since this + class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass + yourself to create new items. + + The built-in items are: + + + + + + + + + + +
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
+ + \section items-clipping Clipping + + Items are by default clipped to the main axis rect (they are only visible inside the axis rect). + To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect + "setClipToAxisRect(false)". + + On the other hand if you want the item to be clipped to a different axis rect, specify it via + \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and + in principle is independent of the coordinate axes the item might be tied to via its position + members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping + also contains the axes used for the item positions. + + \section items-using Using items + + First you instantiate the item you want to use and add it to the plot: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 + by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just + set the plot coordinates where the line should start/end: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 + If we don't want the line to be positioned in plot coordinates but a different coordinate system, + e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 + Then we can set the coordinates, this time in pixels: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 + and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 + + For more advanced plots, it is even possible to set different types and parent anchors per X/Y + coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref + QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. + + \section items-subclassing Creating own items + + To create an own item, you implement a subclass of QCPAbstractItem. These are the pure + virtual functions, you must implement: + \li \ref selectTest + \li \ref draw + + See the documentation of those functions for what they need to do. + + \subsection items-positioning Allowing the item to be positioned + + As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall + have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add + a public member of type QCPItemPosition like so: + + \code QCPItemPosition * const myPosition;\endcode + + the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition + instance it points to, can be modified, of course). + The initialization of this pointer is made easy with the \ref createPosition function. Just assign + the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition + takes a string which is the name of the position, typically this is identical to the variable name. + For example, the constructor of QCPItemExample could look like this: + + \code + QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + myPosition(createPosition("myPosition")) + { + // other constructor code + } + \endcode + + \subsection items-drawing The draw function + + To give your item a visual representation, reimplement the \ref draw function and use the passed + QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the + position member(s) via \ref QCPItemPosition::pixelPosition. + + To optimize performance you should calculate a bounding rect first (don't forget to take the pen + width into account), check whether it intersects the \ref clipRect, and only draw the item at all + if this is the case. + + \subsection items-selection The selectTest function + + Your implementation of the \ref selectTest function may use the helpers \ref + QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the + selection test becomes significantly simpler for most items. See the documentation of \ref + selectTest for what the function parameters mean and what the function should return. + + \subsection anchors Providing anchors + + Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public + member, e.g. + + \code QCPItemAnchor * const bottom;\endcode + + and create it in the constructor with the \ref createAnchor function, assigning it a name and an + anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). + Since anchors can be placed anywhere, relative to the item's position(s), your item needs to + provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int + anchorId) function. + + In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel + position when anything attached to the anchor needs to know the coordinates. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QList QCPAbstractItem::positions() const + + Returns all positions of the item in a list. + + \see anchors, position +*/ + +/*! \fn QList QCPAbstractItem::anchors() const + + Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always + also an anchor, the list will also contain the positions of this item. + + \see positions, anchor +*/ + +/* end of documentation of inline functions */ +/* start documentation of pure virtual functions */ + +/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 + \internal + + Draws this item with the provided \a painter. + + The cliprect of the provided painter is set to the rect returned by \ref clipRect before this + function is called. The clipRect depends on the clipping settings defined by \ref + setClipToAxisRect and \ref setClipAxisRect. +*/ + +/* end documentation of pure virtual functions */ +/* start documentation of signals */ + +/*! \fn void QCPAbstractItem::selectionChanged(bool selected) + This signal is emitted when the selection state of this item has changed, either by user interaction + or by a direct call to \ref setSelected. +*/ + +/* end documentation of signals */ + +/*! + Base class constructor which initializes base class members. +*/ +QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : + QCPLayerable(parentPlot), + mClipToAxisRect(false), + mSelectable(true), + mSelected(false) +{ + parentPlot->registerItem(this); + + QList rects = parentPlot->axisRects(); + if (rects.size() > 0) + { + setClipToAxisRect(true); + setClipAxisRect(rects.first()); + } +} + +QCPAbstractItem::~QCPAbstractItem() +{ + // don't delete mPositions because every position is also an anchor and thus in mAnchors + qDeleteAll(mAnchors); +} + +/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ +QCPAxisRect *QCPAbstractItem::clipAxisRect() const +{ + return mClipAxisRect.data(); +} + +/*! + Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the + entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. + + \see setClipAxisRect +*/ +void QCPAbstractItem::setClipToAxisRect(bool clip) +{ + mClipToAxisRect = clip; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref + setClipToAxisRect is set to true. + + \see setClipToAxisRect +*/ +void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) +{ + mClipAxisRect = rect; + if (mClipToAxisRect) + setParentLayerable(mClipAxisRect.data()); +} + +/*! + Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) + + However, even when \a selectable was set to false, it is possible to set the selection manually, + by calling \ref setSelected. + + \see QCustomPlot::setInteractions, setSelected +*/ +void QCPAbstractItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this item is selected or not. When selected, it might use a different visual + appearance (e.g. pen and brush), this depends on the specific item though. + + The entire selection mechanism for items is handled automatically when \ref + QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this + function when you wish to change the selection state manually. + + This function can change the selection state even when \ref setSelectable was set to false. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + \see setSelectable, selectTest +*/ +void QCPAbstractItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/*! + Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by + that name, returns 0. + + This function provides an alternative way to access item positions. Normally, you access + positions direcly by their member pointers (which typically have the same variable name as \a + name). + + \see positions, anchor +*/ +QCPItemPosition *QCPAbstractItem::position(const QString &name) const +{ + for (int i=0; iname() == name) + return mPositions.at(i); + } + qDebug() << Q_FUNC_INFO << "position with name not found:" << name; + return 0; +} + +/*! + Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by + that name, returns 0. + + This function provides an alternative way to access item anchors. Normally, you access + anchors direcly by their member pointers (which typically have the same variable name as \a + name). + + \see anchors, position +*/ +QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const +{ + for (int i=0; iname() == name) + return mAnchors.at(i); + } + qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; + return 0; +} + +/*! + Returns whether this item has an anchor with the specified \a name. + + Note that you can check for positions with this function, too. This is because every position is + also an anchor (QCPItemPosition inherits from QCPItemAnchor). + + \see anchor, position +*/ +bool QCPAbstractItem::hasAnchor(const QString &name) const +{ + for (int i=0; iname() == name) + return true; + } + return false; +} + +/*! \internal + + Returns the rect the visual representation of this item is clipped to. This depends on the + current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. + + If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. + + \see draw +*/ +QRect QCPAbstractItem::clipRect() const +{ + if (mClipToAxisRect && mClipAxisRect) + return mClipAxisRect.data()->rect(); + else + return mParentPlot->viewport(); +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing item lines. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \see setAntialiased +*/ +void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); +} + +/*! \internal + + A convenience function which returns the selectTest value for a specified \a rect and a specified + click position \a pos. \a filledRect defines whether a click inside the rect should also be + considered a hit or whether only the rect border is sensitive to hits. + + This function may be used to help with the implementation of the \ref selectTest function for + specific items. + + For example, if your item consists of four rects, call this function four times, once for each + rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four + returned values. +*/ +double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const +{ + double result = -1; + + // distance to border: + QList lines; + lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) + << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); + double minDistSqr = std::numeric_limits::max(); + for (int i=0; i mParentPlot->selectionTolerance()*0.99) + { + if (rect.contains(pos)) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/*! \internal + + Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in + item subclasses if they want to provide anchors (QCPItemAnchor). + + For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor + ids and returns the respective pixel points of the specified anchor. + + \see createAnchor +*/ +QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const +{ + qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the position + member (This is needed to provide the name-based \ref position access to positions). + + Don't delete positions created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each position member. Don't create QCPItemPositions with \b new yourself, because they + won't be registered with the item properly. + + \see createAnchor +*/ +QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); + mPositions.append(newPosition); + mAnchors.append(newPosition); // every position is also an anchor + newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); + newPosition->setType(QCPItemPosition::ptPlotCoords); + if (mParentPlot->axisRect()) + newPosition->setAxisRect(mParentPlot->axisRect()); + newPosition->setCoords(0, 0); + return newPosition; +} + +/*! \internal + + Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified + \a name must be a unique string that is usually identical to the variable name of the anchor + member (This is needed to provide the name based \ref anchor access to anchors). + + The \a anchorId must be a number identifying the created anchor. It is recommended to create an + enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor + to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns + the correct pixel coordinates for the passed anchor id. + + Don't delete anchors created by this function manually, as the item will take care of it. + + Use this function in the constructor (initialization list) of the specific item subclass to + create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they + won't be registered with the item properly. + + \see createPosition +*/ +QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) +{ + if (hasAnchor(name)) + qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; + QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); + mAnchors.append(newAnchor); + return newAnchor; +} + +/* inherits documentation from base class */ +void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractItem::selectionCategory() const +{ + return QCP::iSelectItems; +} +/* end of 'src/item.cpp' */ + + +/* including file 'src/core.cpp', size 125037 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCustomPlot +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCustomPlot + + \brief The central class of the library. This is the QWidget which displays the plot and + interacts with the user. + + For tutorials on how to use QCustomPlot, see the website\n + http://www.qcustomplot.com/ +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const + + Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used + to handle and draw selection rect interactions (see \ref setSelectionRectMode). + + \see setSelectionRect +*/ + +/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const + + Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just + one cell with the main QCPAxisRect inside. +*/ + +/* end of documentation of inline functions */ +/* start of documentation of signals */ + +/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse double click event. +*/ + +/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse press event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. +*/ + +/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse move event. + + It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref + QCPAxisRect::setRangeDragAxes. + + \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, + because the dragging starting point was saved the moment the mouse was pressed. Thus it only has + a meaning for the range drag axes that were set at that moment. If you want to change the drag + axes, consider doing this in the \ref mousePress signal instead. +*/ + +/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse release event. + + It is emitted before QCustomPlot handles any other mechanisms like object selection. So a + slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or + \ref QCPAbstractPlottable::setSelectable. +*/ + +/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) + + This signal is emitted when the QCustomPlot receives a mouse wheel event. + + It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot + connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref + QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. +*/ + +/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableDoubleClick +*/ + +/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) + + This signal is emitted when a plottable is double clicked. + + \a event is the mouse event that caused the click and \a plottable is the plottable that received + the click. The parameter \a dataIndex indicates the data point that was closest to the click + position. + + \see plottableClick +*/ + +/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemDoubleClick +*/ + +/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) + + This signal is emitted when an item is double clicked. + + \a event is the mouse event that caused the click and \a item is the item that received the + click. + + \see itemClick +*/ + +/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisDoubleClick +*/ + +/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) + + This signal is emitted when an axis is double clicked. + + \a event is the mouse event that caused the click, \a axis is the axis that received the click and + \a part indicates the part of the axis that was clicked. + + \see axisClick +*/ + +/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendDoubleClick +*/ + +/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) + + This signal is emitted when a legend (item) is double clicked. + + \a event is the mouse event that caused the click, \a legend is the legend that received the + click and \a item is the legend item that received the click. If only the legend and no item is + clicked, \a item is 0. This happens for a click inside the legend padding or the space between + two items. + + \see legendClick +*/ + +/*! \fn void QCustomPlot::selectionChangedByUser() + + This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by + clicking. It is not emitted when the selection state of an object has changed programmatically by + a direct call to setSelected()/setSelection() on an object or by calling \ref + deselectAll. + + In addition to this signal, selectable objects also provide individual signals, for example \ref + QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals + are emitted even if the selection state is changed programmatically. + + See the documentation of \ref setInteractions for details about the selection mechanism. + + \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends +*/ + +/*! \fn void QCustomPlot::beforeReplot() + + This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, afterReplot +*/ + +/*! \fn void QCustomPlot::afterReplot() + + This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref + replot). + + It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them + replot synchronously, it won't cause an infinite recursion. + + \see replot, beforeReplot +*/ + +/* end of documentation of signals */ +/* start of documentation of public members */ + +/*! \var QCPAxis *QCustomPlot::xAxis + + A pointer to the primary x Axis (bottom) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis + + A pointer to the primary y Axis (left) of the main axis rect of the plot. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::xAxis2 + + A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPAxis *QCustomPlot::yAxis2 + + A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are + invisible by default. Use QCPAxis::setVisible to change this (or use \ref + QCPAxisRect::setupFullAxesBox). + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref + QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the + default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointers become 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/*! \var QCPLegend *QCustomPlot::legend + + A pointer to the default legend of the main axis rect. The legend is invisible by default. Use + QCPLegend::setVisible to change this. + + QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref + yAxis2) and the \ref legend. They make it very easy working with plots that only have a single + axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the + layout system\endlink to add multiple legends to the plot, use the layout system interface to + access the new legend. For example, legends can be placed inside an axis rect's \ref + QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If + the default legend is removed due to manipulation of the layout system (e.g. by removing the main + axis rect), the corresponding pointer becomes 0. + + If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is + added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the + according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is + added after the main legend was removed before. +*/ + +/* end of documentation of public members */ + +/*! + Constructs a QCustomPlot and sets reasonable default values. +*/ +QCustomPlot::QCustomPlot(QWidget *parent) : + QWidget(parent), + xAxis(0), + yAxis(0), + xAxis2(0), + yAxis2(0), + legend(0), + mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below + mPlotLayout(0), + mAutoAddPlottableToLegend(true), + mAntialiasedElements(QCP::aeNone), + mNotAntialiasedElements(QCP::aeNone), + mInteractions(0), + mSelectionTolerance(8), + mNoAntialiasingOnDrag(false), + mBackgroundBrush(Qt::white, Qt::SolidPattern), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mCurrentLayer(0), + mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), + mMultiSelectModifier(Qt::ControlModifier), + mSelectionRectMode(QCP::srmNone), + mSelectionRect(0), + mOpenGl(false), + mMouseHasMoved(false), + mMouseEventLayerable(0), + mMouseSignalLayerable(0), + mReplotting(false), + mReplotQueued(false), + mOpenGlMultisamples(16), + mOpenGlAntialiasedElementsBackup(QCP::aeNone), + mOpenGlCacheLabelsBackup(true) +{ + setAttribute(Qt::WA_NoMousePropagation); + setAttribute(Qt::WA_OpaquePaintEvent); + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); + QLocale currentLocale = locale(); + currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); + setLocale(currentLocale); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); +# else + setBufferDevicePixelRatio(QWidget::devicePixelRatio()); +# endif +#endif + + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // create initial layers: + mLayers.append(new QCPLayer(this, QLatin1String("background"))); + mLayers.append(new QCPLayer(this, QLatin1String("grid"))); + mLayers.append(new QCPLayer(this, QLatin1String("main"))); + mLayers.append(new QCPLayer(this, QLatin1String("axes"))); + mLayers.append(new QCPLayer(this, QLatin1String("legend"))); + mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); + updateLayerIndices(); + setCurrentLayer(QLatin1String("main")); + layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); + + // create initial layout, axis rect and legend: + mPlotLayout = new QCPLayoutGrid; + mPlotLayout->initializeParentPlot(this); + mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry + mPlotLayout->setLayer(QLatin1String("main")); + QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); + mPlotLayout->addElement(0, 0, defaultAxisRect); + xAxis = defaultAxisRect->axis(QCPAxis::atBottom); + yAxis = defaultAxisRect->axis(QCPAxis::atLeft); + xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); + yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); + legend = new QCPLegend; + legend->setVisible(false); + defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); + defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); + + defaultAxisRect->setLayer(QLatin1String("background")); + xAxis->setLayer(QLatin1String("axes")); + yAxis->setLayer(QLatin1String("axes")); + xAxis2->setLayer(QLatin1String("axes")); + yAxis2->setLayer(QLatin1String("axes")); + xAxis->grid()->setLayer(QLatin1String("grid")); + yAxis->grid()->setLayer(QLatin1String("grid")); + xAxis2->grid()->setLayer(QLatin1String("grid")); + yAxis2->grid()->setLayer(QLatin1String("grid")); + legend->setLayer(QLatin1String("legend")); + + // create selection rect instance: + mSelectionRect = new QCPSelectionRect(this); + mSelectionRect->setLayer(QLatin1String("overlay")); + + setViewport(rect()); // needs to be called after mPlotLayout has been created + + replot(rpQueuedReplot); +} + +QCustomPlot::~QCustomPlot() +{ + clearPlottables(); + clearItems(); + + if (mPlotLayout) + { + delete mPlotLayout; + mPlotLayout = 0; + } + + mCurrentLayer = 0; + qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed + mLayers.clear(); +} + +/*! + Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is + removed from there. + + \see setNotAntialiasedElements +*/ +void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) +{ + mAntialiasedElements = antialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. + + See \ref setAntialiasedElements for details. + + \see setNotAntialiasedElement +*/ +void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) +{ + if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements &= ~antialiasedElement; + else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) + mAntialiasedElements |= antialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mNotAntialiasedElements |= ~mAntialiasedElements; +} + +/*! + Sets which elements are forcibly drawn not antialiased as an \a or combination of + QCP::AntialiasedElement. + + This overrides the antialiasing settings for whole element groups, normally controlled with the + \a setAntialiasing function on the individual elements. If an element is neither specified in + \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on + each individual element instance is used. + + For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be + drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set + to. + + if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is + removed from there. + + \see setAntialiasedElements +*/ +void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) +{ + mNotAntialiasedElements = notAntialiasedElements; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. + + See \ref setNotAntialiasedElements for details. + + \see setAntialiasedElement +*/ +void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) +{ + if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements &= ~notAntialiasedElement; + else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) + mNotAntialiasedElements |= notAntialiasedElement; + + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + mAntialiasedElements |= ~mNotAntialiasedElements; +} + +/*! + If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the + plottable to the legend (QCustomPlot::legend). + + \see addGraph, QCPLegend::addItem +*/ +void QCustomPlot::setAutoAddPlottableToLegend(bool on) +{ + mAutoAddPlottableToLegend = on; +} + +/*! + Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction + enums. There are the following types of interactions: + + Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the + respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. + For details how to control which axes the user may drag/zoom and in what orientations, see \ref + QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, + \ref QCPAxisRect::setRangeZoomAxes. + + Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref + QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and + their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the + user can actually select a plottable and its data can further be restricted with the \ref + QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the + special page about the \ref dataselection "data selection mechanism". To retrieve a list of all + currently selected plottables, call \ref selectedPlottables. If you're only interested in + QCPGraphs, you may use the convenience function \ref selectedGraphs. + + Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user + may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find + out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of + all currently selected items, call \ref selectedItems. + + Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user + may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick + labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for + each axis. To retrieve a list of all axes that currently contain selected parts, call \ref + selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). + + Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may + select the legend itself or individual items by clicking on them. What parts exactly are + selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the + legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To + find out which child items are selected, call \ref QCPLegend::selectedItems. + + All other selectable elements The selection of all other selectable objects (e.g. + QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the + user may select those objects by clicking on them. To find out which are currently selected, you + need to check their selected state explicitly. + + If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is + emitted. Each selectable object additionally emits an individual selectionChanged signal whenever + their selection state has changed, i.e. not only by user interaction. + + To allow multiple objects to be selected by holding the selection modifier (\ref + setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. + + \note In addition to the selection mechanism presented here, QCustomPlot always emits + corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and + \ref plottableDoubleClick for example. + + \see setInteraction, setSelectionTolerance +*/ +void QCustomPlot::setInteractions(const QCP::Interactions &interactions) +{ + mInteractions = interactions; +} + +/*! + Sets the single \a interaction of this QCustomPlot to \a enabled. + + For details about the interaction system, see \ref setInteractions. + + \see setInteractions +*/ +void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) +{ + if (!enabled && mInteractions.testFlag(interaction)) + mInteractions &= ~interaction; + else if (enabled && !mInteractions.testFlag(interaction)) + mInteractions |= interaction; +} + +/*! + Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or + not. + + If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a + potential selection when the minimum distance between the click position and the graph line is + smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks + directly inside the area and ignore this selection tolerance. In other words, it only has meaning + for parts of objects that are too thin to exactly hit with a click and thus need such a + tolerance. + + \see setInteractions, QCPLayerable::selectTest +*/ +void QCustomPlot::setSelectionTolerance(int pixels) +{ + mSelectionTolerance = pixels; +} + +/*! + Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes + ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves + performance during dragging. Thus it creates a more responsive user experience. As soon as the + user stops dragging, the last replot is done with normal antialiasing, to restore high image + quality. + + \see setAntialiasedElements, setNotAntialiasedElements +*/ +void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) +{ + mNoAntialiasingOnDrag = enabled; +} + +/*! + Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. + + \see setPlottingHint +*/ +void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) +{ + mPlottingHints = hints; +} + +/*! + Sets the specified plotting \a hint to \a enabled. + + \see setPlottingHints +*/ +void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) +{ + QCP::PlottingHints newHints = mPlottingHints; + if (!enabled) + newHints &= ~hint; + else + newHints |= hint; + + if (newHints != mPlottingHints) + setPlottingHints(newHints); +} + +/*! + Sets the keyboard modifier that will be recognized as multi-select-modifier. + + If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple + objects (or data points) by clicking on them one after the other while holding down \a modifier. + + By default the multi-select-modifier is set to Qt::ControlModifier. + + \see setInteractions +*/ +void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) +{ + mMultiSelectModifier = modifier; +} + +/*! + Sets how QCustomPlot processes mouse click-and-drag interactions by the user. + + If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For + example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref + QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref + selectionRect) becomes activated and allows e.g. rect zooming and data point selection. + + If you wish to provide your user both with axis range dragging and data selection/range zooming, + use this method to switch between the modes just before the interaction is processed, e.g. in + reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether + the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. + + If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the + interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes + will keep the selection rect active. Upon completion of the interaction, the behaviour is as + defined by the currently set \a mode, not the mode that was set when the interaction started. + + \see setInteractions, setSelectionRect, QCPSelectionRect +*/ +void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) +{ + if (mSelectionRect) + { + if (mode == QCP::srmNone) + mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect + + // disconnect old connections: + if (mSelectionRectMode == QCP::srmSelect) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + + // establish new ones: + if (mode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } + + mSelectionRectMode = mode; +} + +/*! + Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref + QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of + the passed \a selectionRect. It can be accessed later via \ref selectionRect. + + This method is useful if you wish to replace the default QCPSelectionRect instance with an + instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. + + \see setSelectionRectMode +*/ +void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) +{ + if (mSelectionRect) + delete mSelectionRect; + + mSelectionRect = selectionRect; + + if (mSelectionRect) + { + // establish connections with new selection rect: + if (mSelectionRectMode == QCP::srmSelect) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); + else if (mSelectionRectMode == QCP::srmZoom) + connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + } +} + +/*! + \warning This is still an experimental feature and its performance depends on the system that it + runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering + might cause context conflicts on some systems. + + This method allows to enable OpenGL plot rendering, for increased plotting performance of + graphically demanding plots (thick lines, translucent fills, etc.). + + If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, + continue plotting with hardware acceleration. The parameter \a multisampling controls how many + samples will be used per pixel, it essentially controls the antialiasing quality. If \a + multisampling is set too high for the current graphics hardware, the maximum allowed value will + be used. + + You can test whether switching to OpenGL rendering was successful by checking whether the + according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, + rendering continues with the regular software rasterizer, and an according qDebug output is + generated. + + If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint + "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override + for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a + higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the + OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is + controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching + settings are restored to what they were before OpenGL was enabled, if they weren't altered in the + meantime. + + \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL + defined. This define must be set before including the QCustomPlot header both during compilation + of the QCustomPlot library as well as when compiling your application. It is best to just include + the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. + \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c + QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a + newer OpenGL interface which is already in the "gui" module. +*/ +void QCustomPlot::setOpenGl(bool enabled, int multisampling) +{ + mOpenGlMultisamples = qMax(0, multisampling); +#ifdef QCUSTOMPLOT_USE_OPENGL + mOpenGl = enabled; + if (mOpenGl) + { + if (setupOpenGl()) + { + // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): + setAntialiasedElements(QCP::aeAll); + setPlottingHint(QCP::phCacheLabels, false); + } else + { + qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; + mOpenGl = false; + } + } else + { + // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: + if (mAntialiasedElements == QCP::aeAll) + setAntialiasedElements(mOpenGlAntialiasedElementsBackup); + if (!mPlottingHints.testFlag(QCP::phCacheLabels)) + setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); + freeOpenGl(); + } + // recreate all paint buffers: + mPaintBuffers.clear(); + setupPaintBuffers(); +#else + Q_UNUSED(enabled) + qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; +#endif +} + +/*! + Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the + viewport manually. + + The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take + the viewport to be the outer border of the plot. The viewport normally is the rect() of the + QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. + + Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically + an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger + and contains also the axes themselves, their tick numbers, their labels, or even additional axis + rects, color scales and other layout elements. + + This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref + savePdf, etc. by temporarily changing the viewport size. +*/ +void QCustomPlot::setViewport(const QRect &rect) +{ + mViewport = rect; + if (mPlotLayout) + mPlotLayout->setOuterRect(mViewport); +} + +/*! + Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. + + Normally, this doesn't need to be set manually, because it is initialized with the regular \a + QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal + displays, 2 for High-DPI displays). + + Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called + when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and + leaves the internal buffer device pixel ratio at 1.0. +*/ +void QCustomPlot::setBufferDevicePixelRatio(double ratio) +{ + if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mBufferDevicePixelRatio = ratio; + for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); + // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here +#else + qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; + mBufferDevicePixelRatio = 1.0; +#endif + } +} + +/*! + Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn + below all other objects in the plot. + + For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is + preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will + first be filled with that brush, before drawing the background pixmap. This can be useful for + background pixmaps with translucent areas. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! + Sets the background brush of the viewport (see \ref setViewport). + + Before drawing everything else, the background is filled with \a brush. If a background pixmap + was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport + before the background pixmap is drawn. This can be useful for background pixmaps with translucent + areas. + + Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be + useful for exporting to image formats which support transparency, e.g. \ref savePng. + + \see setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the viewport, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is + set to true, control whether and how the aspect ratio of the original pixmap is preserved with + \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the viewport dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCustomPlot::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this + function to define whether and how the aspect ratio of the original pixmap is preserved. + + \see setBackground, setBackgroundScaled +*/ +void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the plottable with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + plottable, see QCustomPlot::plottable() + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + { + return mPlottables.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last plottable that was added to the plot. If there are no plottables in the plot, + returns 0. + + \see plottableCount +*/ +QCPAbstractPlottable *QCustomPlot::plottable() +{ + if (!mPlottables.isEmpty()) + { + return mPlottables.last(); + } else + return 0; +} + +/*! + Removes the specified plottable from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). + + Returns true on success. + + \see clearPlottables +*/ +bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) +{ + if (!mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); + return false; + } + + // remove plottable from legend: + plottable->removeFromLegend(); + // special handling for QCPGraphs to maintain the simple graph interface: + if (QCPGraph *graph = qobject_cast(plottable)) + mGraphs.removeOne(graph); + // remove plottable: + delete plottable; + mPlottables.removeOne(plottable); + return true; +} + +/*! \overload + + Removes and deletes the plottable by its \a index. +*/ +bool QCustomPlot::removePlottable(int index) +{ + if (index >= 0 && index < mPlottables.size()) + return removePlottable(mPlottables[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all plottables from the plot and deletes them. Corresponding legend items are also + removed from the default legend (QCustomPlot::legend). + + Returns the number of plottables removed. + + \see removePlottable +*/ +int QCustomPlot::clearPlottables() +{ + int c = mPlottables.size(); + for (int i=c-1; i >= 0; --i) + removePlottable(mPlottables[i]); + return c; +} + +/*! + Returns the number of currently existing plottables in the plot + + \see plottable +*/ +int QCustomPlot::plottableCount() const +{ + return mPlottables.size(); +} + +/*! + Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. + + There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. + + \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedPlottables() const +{ + QList result; + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (plottable->selected()) + result.append(plottable); + } + return result; +} + +/*! + Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines + (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple + plottables come into consideration, the one closest to \a pos is returned. + + If \a onlySelectable is true, only plottables that are selectable + (QCPAbstractPlottable::setSelectable) are considered. + + If there is no plottable at \a pos, the return value is 0. + + \see itemAt, layoutElementAt +*/ +QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractPlottable *resultPlottable = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) + { + if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable + continue; + if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes + { + double currentDistance = plottable->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultPlottable = plottable; + resultDistance = currentDistance; + } + } + } + + return resultPlottable; +} + +/*! + Returns whether this QCustomPlot instance contains the \a plottable. +*/ +bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const +{ + return mPlottables.contains(plottable); +} + +/*! + Returns the graph with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last created + graph, see QCustomPlot::graph() + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph(int index) const +{ + if (index >= 0 && index < mGraphs.size()) + { + return mGraphs.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, + returns 0. + + \see graphCount, addGraph +*/ +QCPGraph *QCustomPlot::graph() const +{ + if (!mGraphs.isEmpty()) + { + return mGraphs.last(); + } else + return 0; +} + +/*! + Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the + bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a + keyAxis and \a valueAxis must reside in this QCustomPlot. + + \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically + "y") for the graph. + + Returns a pointer to the newly created graph, or 0 if adding the graph failed. + + \see graph, graphCount, removeGraph, clearGraphs +*/ +QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) +{ + if (!keyAxis) keyAxis = xAxis; + if (!valueAxis) valueAxis = yAxis; + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; + return 0; + } + if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; + return 0; + } + + QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); + newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); + return newGraph; +} + +/*! + Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding + legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in + the plot have a channel fill set towards the removed graph, the channel fill property of those + graphs is reset to zero (no channel fill). + + Returns true on success. + + \see clearGraphs +*/ +bool QCustomPlot::removeGraph(QCPGraph *graph) +{ + return removePlottable(graph); +} + +/*! \overload + + Removes and deletes the graph by its \a index. +*/ +bool QCustomPlot::removeGraph(int index) +{ + if (index >= 0 && index < mGraphs.size()) + return removeGraph(mGraphs[index]); + else + return false; +} + +/*! + Removes all graphs from the plot and deletes them. Corresponding legend items are also removed + from the default legend (QCustomPlot::legend). + + Returns the number of graphs removed. + + \see removeGraph +*/ +int QCustomPlot::clearGraphs() +{ + int c = mGraphs.size(); + for (int i=c-1; i >= 0; --i) + removeGraph(mGraphs[i]); + return c; +} + +/*! + Returns the number of currently existing graphs in the plot + + \see graph, addGraph +*/ +int QCustomPlot::graphCount() const +{ + return mGraphs.size(); +} + +/*! + Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. + + If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, + etc., use \ref selectedPlottables. + + \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection +*/ +QList QCustomPlot::selectedGraphs() const +{ + QList result; + Q_FOREACH (QCPGraph *graph, mGraphs) + { + if (graph->selected()) + result.append(graph); + } + return result; +} + +/*! + Returns the item with \a index. If the index is invalid, returns 0. + + There is an overloaded version of this function with no parameter which returns the last added + item, see QCustomPlot::item() + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item(int index) const +{ + if (index >= 0 && index < mItems.size()) + { + return mItems.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! \overload + + Returns the last item that was added to this plot. If there are no items in the plot, + returns 0. + + \see itemCount +*/ +QCPAbstractItem *QCustomPlot::item() const +{ + if (!mItems.isEmpty()) + { + return mItems.last(); + } else + return 0; +} + +/*! + Removes the specified item from the plot and deletes it. + + Returns true on success. + + \see clearItems +*/ +bool QCustomPlot::removeItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + delete item; + mItems.removeOne(item); + return true; + } else + { + qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); + return false; + } +} + +/*! \overload + + Removes and deletes the item by its \a index. +*/ +bool QCustomPlot::removeItem(int index) +{ + if (index >= 0 && index < mItems.size()) + return removeItem(mItems[index]); + else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return false; + } +} + +/*! + Removes all items from the plot and deletes them. + + Returns the number of items removed. + + \see removeItem +*/ +int QCustomPlot::clearItems() +{ + int c = mItems.size(); + for (int i=c-1; i >= 0; --i) + removeItem(mItems[i]); + return c; +} + +/*! + Returns the number of currently existing items in the plot + + \see item +*/ +int QCustomPlot::itemCount() const +{ + return mItems.size(); +} + +/*! + Returns a list of the selected items. If no items are currently selected, the list is empty. + + \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected +*/ +QList QCustomPlot::selectedItems() const +{ + QList result; + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (item->selected()) + result.append(item); + } + return result; +} + +/*! + Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref + QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref + setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is + returned. + + If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are + considered. + + If there is no item at \a pos, the return value is 0. + + \see plottableAt, layoutElementAt +*/ +QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const +{ + QCPAbstractItem *resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + Q_FOREACH (QCPAbstractItem *item, mItems) + { + if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + continue; + if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it + { + double currentDistance = item->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) + { + resultItem = item; + resultDistance = currentDistance; + } + } + } + + return resultItem; +} + +/*! + Returns whether this QCustomPlot contains the \a item. + + \see item +*/ +bool QCustomPlot::hasItem(QCPAbstractItem *item) const +{ + return mItems.contains(item); +} + +/*! + Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is + returned. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(const QString &name) const +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + if (layer->name() == name) + return layer; + } + return 0; +} + +/*! \overload + + Returns the layer by \a index. If the index is invalid, 0 is returned. + + \see addLayer, moveLayer, removeLayer +*/ +QCPLayer *QCustomPlot::layer(int index) const +{ + if (index >= 0 && index < mLayers.size()) + { + return mLayers.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Returns the layer that is set as current layer (see \ref setCurrentLayer). +*/ +QCPLayer *QCustomPlot::currentLayer() const +{ + return mCurrentLayer; +} + +/*! + Sets the layer with the specified \a name to be the current layer. All layerables (\ref + QCPLayerable), e.g. plottables and items, are created on the current layer. + + Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. + + Layer names are case-sensitive. + + \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer +*/ +bool QCustomPlot::setCurrentLayer(const QString &name) +{ + if (QCPLayer *newCurrentLayer = layer(name)) + { + return setCurrentLayer(newCurrentLayer); + } else + { + qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; + return false; + } +} + +/*! \overload + + Sets the provided \a layer to be the current layer. + + Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. + + \see addLayer, moveLayer, removeLayer +*/ +bool QCustomPlot::setCurrentLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + + mCurrentLayer = layer; + return true; +} + +/*! + Returns the number of currently existing layers in the plot + + \see layer, addLayer +*/ +int QCustomPlot::layerCount() const +{ + return mLayers.size(); +} + +/*! + Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which + must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. + + Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a + valid layer inside this QCustomPlot. + + If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. + + For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. + + \see layer, moveLayer, removeLayer +*/ +bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!otherLayer) + otherLayer = mLayers.last(); + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + if (layer(name)) + { + qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; + return false; + } + + QCPLayer *newLayer = new QCPLayer(this, name); + mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); + updateLayerIndices(); + setupPaintBuffers(); // associates new layer with the appropriate paint buffer + return true; +} + +/*! + Removes the specified \a layer and returns true on success. + + All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below + \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both + cases, the total rendering order of all layerables in the QCustomPlot is preserved. + + If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom + layer) becomes the new current layer. + + It is not possible to remove the last layer of the plot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::removeLayer(QCPLayer *layer) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (mLayers.size() < 2) + { + qDebug() << Q_FUNC_INFO << "can't remove last layer"; + return false; + } + + // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) + int removedIndex = layer->index(); + bool isFirstLayer = removedIndex==0; + QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); + QList children = layer->children(); + if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) + { + for (int i=children.size()-1; i>=0; --i) + children.at(i)->moveToLayer(targetLayer, true); + } else // append normally + { + for (int i=0; imoveToLayer(targetLayer, false); + } + // if removed layer is current layer, change current layer to layer below/above: + if (layer == mCurrentLayer) + setCurrentLayer(targetLayer); + // invalidate the paint buffer that was responsible for this layer: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + // remove layer: + delete layer; + mLayers.removeOne(layer); + updateLayerIndices(); + return true; +} + +/*! + Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or + below is controlled with \a insertMode. + + Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the + QCustomPlot. + + \see layer, addLayer, moveLayer +*/ +bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +{ + if (!mLayers.contains(layer)) + { + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + return false; + } + if (!mLayers.contains(otherLayer)) + { + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + return false; + } + + if (layer->index() > otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); + else if (layer->index() < otherLayer->index()) + mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); + + // invalidate the paint buffers that are responsible for the layers: + if (!layer->mPaintBuffer.isNull()) + layer->mPaintBuffer.data()->setInvalidated(); + if (!otherLayer->mPaintBuffer.isNull()) + otherLayer->mPaintBuffer.data()->setInvalidated(); + + updateLayerIndices(); + return true; +} + +/*! + Returns the number of axis rects in the plot. + + All axis rects can be accessed via QCustomPlot::axisRect(). + + Initially, only one axis rect exists in the plot. + + \see axisRect, axisRects +*/ +int QCustomPlot::axisRectCount() const +{ + return axisRects().size(); +} + +/*! + Returns the axis rect with \a index. + + Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were + added, all of them may be accessed with this function in a linear fashion (even when they are + nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). + + \see axisRectCount, axisRects +*/ +QCPAxisRect *QCustomPlot::axisRect(int index) const +{ + const QList rectList = axisRects(); + if (index >= 0 && index < rectList.size()) + { + return rectList.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; + return 0; + } +} + +/*! + Returns all axis rects in the plot. + + \see axisRectCount, axisRect +*/ +QList QCustomPlot::axisRects() const +{ + QList result; + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) + { + if (element) + { + elementStack.push(element); + if (QCPAxisRect *ar = qobject_cast(element)) + result.append(ar); + } + } + } + + return result; +} + +/*! + Returns the layout element at pixel position \a pos. If there is no element at that position, + returns 0. + + Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on + any of its parent elements is set to false, it will not be considered. + + \see itemAt, plottableAt +*/ +QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const +{ + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + break; + } + } + } + return currentElement; +} + +/*! + Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores + other layout elements even if they are visually in front of the axis rect (e.g. a \ref + QCPLegend). If there is no axis rect at that position, returns 0. + + Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or + on any of its parent elements is set to false, it will not be considered. + + \see layoutElementAt +*/ +QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const +{ + QCPAxisRect *result = 0; + QCPLayoutElement *currentElement = mPlotLayout; + bool searchSubElements = true; + while (searchSubElements && currentElement) + { + searchSubElements = false; + Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) + { + if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + { + currentElement = subElement; + searchSubElements = true; + if (QCPAxisRect *ar = qobject_cast(currentElement)) + result = ar; + break; + } + } + } + return result; +} + +/*! + Returns the axes that currently have selected parts, i.e. whose selection state is not \ref + QCPAxis::spNone. + + \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, + QCPAxis::setSelectableParts +*/ +QList QCustomPlot::selectedAxes() const +{ + QList result, allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + { + if (axis->selectedParts() != QCPAxis::spNone) + result.append(axis); + } + + return result; +} + +/*! + Returns the legends that currently have selected parts, i.e. whose selection state is not \ref + QCPLegend::spNone. + + \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, + QCPLegend::setSelectableParts, QCPLegend::selectedItems +*/ +QList QCustomPlot::selectedLegends() const +{ + QList result; + + QStack elementStack; + if (mPlotLayout) + elementStack.push(mPlotLayout); + + while (!elementStack.isEmpty()) + { + Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) + { + if (subElement) + { + elementStack.push(subElement); + if (QCPLegend *leg = qobject_cast(subElement)) + { + if (leg->selectedParts() != QCPLegend::spNone) + result.append(leg); + } + } + } + } + + return result; +} + +/*! + Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. + + Since calling this function is not a user interaction, this does not emit the \ref + selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the + objects were previously selected. + + \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends +*/ +void QCustomPlot::deselectAll() +{ + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + layerable->deselectEvent(0); + } +} + +/*! + Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is + refreshed with the new buffer contents. This is the method that must be called to make changes to + the plot, e.g. on the axis ranges or data points of graphs, visible. + + The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example + if your application calls \ref replot very quickly in succession (e.g. multiple independent + functions change some aspects of the plot and each wants to make sure the change gets replotted), + it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the + actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref + replot with this priority will only cause a single replot, avoiding redundant replots and + improving performance. + + Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the + QCustomPlot widget and user interactions (object selection and range dragging/zooming). + + Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref + afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two + signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite + recursion. + + If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to + replot only that specific layer via \ref QCPLayer::replot. See the documentation there for + details. +*/ +void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) +{ + if (refreshPriority == QCustomPlot::rpQueuedReplot) + { + if (!mReplotQueued) + { + mReplotQueued = true; + QTimer::singleShot(0, this, SLOT(replot())); + } + return; + } + + if (mReplotting) // incase signals loop back to replot slot + return; + mReplotting = true; + mReplotQueued = false; + Q_EMIT beforeReplot(); + + updateLayout(); + // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: + setupPaintBuffers(); + Q_FOREACH (QCPLayer *layer, mLayers) + layer->drawToPaintBuffer(); + for (int i=0; isetInvalidated(false); + + if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) + repaint(); + else + update(); + + Q_EMIT afterReplot(); + mReplotting = false; +} + +/*! + Rescales the axes such that all plottables (like graphs) in the plot are fully visible. + + if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true + (QCPLayerable::setVisible), will be used to rescale the axes. + + \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale +*/ +void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) +{ + QList allAxes; + Q_FOREACH (QCPAxisRect *rect, axisRects()) + allAxes << rect->axes(); + + Q_FOREACH (QCPAxis *axis, allAxes) + axis->rescale(onlyVisiblePlottables); +} + +/*! + Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale + of texts and lines will be derived from the specified \a width and \a height. This means, the + output will look like the normal on-screen output of a QCustomPlot widget with the corresponding + pixel width and height. If either \a width or \a height is zero, the exported image will have the + same dimensions as the QCustomPlot widget currently has. + + Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when + drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as + a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information + about cosmetic pens, see the QPainter and QPen documentation. + + The objects of the plot will appear in the current selection state. If you don't want any + selected objects to be painted in their selected look, deselect everything with \ref deselectAll + before calling this function. + + Returns true on success. + + \warning + \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it + is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines + (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). + \li If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting + PDF file. + + \note On Android systems, this method does nothing and issues an according qDebug warning + message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. + + \see savePng, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) +{ + bool success = false; +#ifdef QT_NO_PRINTER + Q_UNUSED(fileName) + Q_UNUSED(exportPen) + Q_UNUSED(width) + Q_UNUSED(height) + Q_UNUSED(pdfCreator) + Q_UNUSED(pdfTitle) + qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; +#else + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFileName(fileName); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); + printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) + printer.setFullPage(true); + printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); +#else + QPageLayout pageLayout; + pageLayout.setMode(QPageLayout::FullPageMode); + pageLayout.setOrientation(QPageLayout::Portrait); + pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); + pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); + printer.setPageLayout(pageLayout); +#endif + QCPPainter printpainter; + if (printpainter.begin(&printer)) + { + printpainter.setMode(QCPPainter::pmVectorized); + printpainter.setMode(QCPPainter::pmNoCaching); + printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); + printpainter.setWindow(mViewport); + if (mBackgroundBrush.style() != Qt::NoBrush && + mBackgroundBrush.color() != Qt::white && + mBackgroundBrush.color() != Qt::transparent && + mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent + printpainter.fillRect(viewport(), mBackgroundBrush); + draw(&printpainter); + printpainter.end(); + success = true; + } + setViewport(oldViewport); +#endif // QT_NO_PRINTER + return success; +} + +/*! + Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the PNG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) + with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, saveBmp, saveJpg, saveRastered +*/ +bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); +} + +/*! + Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + image compression can be controlled with the \a quality parameter which must be between 0 and 100 + or -1 to use the default setting. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the JPEG format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveBmp, saveRastered +*/ +bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); +} + +/*! + Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width + and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the + current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. + are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale + parameter. + + For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an + image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, + texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full + 200*200 pixel resolution. + + If you use a high scaling factor, it is recommended to enable antialiasing for all elements by + temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows + QCustomPlot to place objects with sub-pixel accuracy. + + The \a resolution will be written to the image file header and has no direct consequence for the + quality or the pixel size. However, if opening the image with a tool which respects the metadata, + it will be able to scale the image to match either a given size in real units of length (inch, + centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is + given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected + resolution unit internally. + + Returns true on success. If this function fails, most likely the BMP format isn't supported by + the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The objects of the plot will appear in the current selection state. If you don't want any selected + objects to be painted in their selected look, deselect everything with \ref deselectAll before calling + this function. + + \warning If calling this function inside the constructor of the parent of the QCustomPlot widget + (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide + explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this + function uses the current width and height of the QCustomPlot widget. However, in Qt, these + aren't defined yet inside the constructor, so you would get an image that has strange + widths/heights. + + \see savePdf, savePng, saveJpg, saveRastered +*/ +bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); +} + +/*! \internal + + Returns a minimum size hint that corresponds to the minimum size of the top level layout + (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum + size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. + This is especially important, when placed in a QLayout where other components try to take in as + much space as possible (e.g. QMdiArea). +*/ +QSize QCustomPlot::minimumSizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Returns a size hint that is the same as \ref minimumSizeHint. + +*/ +QSize QCustomPlot::sizeHint() const +{ + return mPlotLayout->minimumOuterSizeHint(); +} + +/*! \internal + + Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but + draws the internal buffer on the widget surface. +*/ +void QCustomPlot::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QCPPainter painter(this); + if (painter.isActive()) + { + painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem + if (mBackgroundBrush.style() != Qt::NoBrush) + painter.fillRect(mViewport, mBackgroundBrush); + drawBackground(&painter); + for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) + mPaintBuffers.at(bufferIndex)->draw(&painter); + } +} + +/*! \internal + + Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect + of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. +*/ +void QCustomPlot::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + // resize and repaint the buffer: + setViewport(rect()); + replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) +} + +/*! \internal + + Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then + determines the layerable under the cursor and forwards the event to it. Finally, emits the + specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref + axisDoubleClick, etc.). + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_EMIT mouseDoubleClick(event); + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + // determine layerable under the cursor (this event is called instead of the second press event in a double-click): + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + + // emit specialized object double click signals: + if (!candidates.isEmpty()) + { + if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) + { + int dataIndex = 0; + if (!details.first().value().isEmpty()) + dataIndex = details.first().value().dataRange().begin(); + Q_EMIT plottableDoubleClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(candidates.first())) + Q_EMIT axisDoubleClick(ax, details.first().value(), event); + else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) + Q_EMIT itemDoubleClick(ai, event); + else if (QCPLegend *lg = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) + Q_EMIT legendDoubleClick(li->parentLegend(), li, event); + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is pressed. Emits the mousePress signal. + + If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the + selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCustomPlot::mousePressEvent(QMouseEvent *event) +{ + Q_EMIT mousePress(event); + // save some state to tell in releaseEvent whether it was a click: + mMouseHasMoved = false; + mMousePressPos = event->pos(); + + if (mSelectionRect && mSelectionRectMode != QCP::srmNone) + { + if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect + mSelectionRect->startSelection(event); + } else + { + // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: + QList details; + QList candidates = layerableListAt(mMousePressPos, false, &details); + if (!candidates.isEmpty()) + { + mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) + mMouseSignalLayerableDetails = details.first(); + } + // forward event to topmost candidate which accepts the event: + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list + candidates.at(i)->mousePressEvent(event, details.at(i)); + if (event->isAccepted()) + { + mMouseEventLayerable = candidates.at(i); + mMouseEventLayerableDetails = details.at(i); + break; + } + } + } + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when the cursor is moved. Emits the \ref mouseMove signal. + + If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it + in order to update the rect geometry. + + Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the + layout element before), the mouseMoveEvent is forwarded to that element. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCustomPlot::mouseMoveEvent(QMouseEvent *event) +{ + Q_EMIT mouseMove(event); + + if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) + mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release + + if (mSelectionRect && mSelectionRect->isActive()) + mSelectionRect->moveSelection(event); + else if (mMouseEventLayerable) // call event of affected layerable: + mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. + + If the mouse was moved less than a certain threshold in any direction since the \ref + mousePressEvent, it is considered a click which causes the selection mechanism (if activated via + \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse + click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) + + If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable + before), the \ref mouseReleaseEvent is forwarded to that element. + + \see mousePressEvent, mouseMoveEvent +*/ +void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) +{ + Q_EMIT mouseRelease(event); + + if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click + { + if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here + mSelectionRect->cancel(); + if (event->button() == Qt::LeftButton) + processPointSelection(event); + + // emit specialized click signals of QCustomPlot instance: + if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) + { + int dataIndex = 0; + if (!mMouseSignalLayerableDetails.value().isEmpty()) + dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); + Q_EMIT plottableClick(ap, dataIndex, event); + } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) + Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); + else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) + Q_EMIT itemClick(ai, event); + else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(lg, 0, event); + else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) + Q_EMIT legendClick(li->parentLegend(), li, event); + mMouseSignalLayerable = 0; + } + + if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there + { + // finish selection rect, the appropriate action will be taken via signal-slot connection: + mSelectionRect->endSelection(event); + } else + { + // call event of affected layerable: + if (mMouseEventLayerable) + { + mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); + mMouseEventLayerable = 0; + } + } + + if (noAntialiasingOnDrag()) + replot(rpQueuedReplot); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then + determines the affected layerable and forwards the event to it. +*/ +void QCustomPlot::wheelEvent(QWheelEvent *event) +{ + Q_EMIT mouseWheel(event); + // forward event to layerable under cursor: + QList candidates = layerableListAt(event->pos(), false); + for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at(i)->wheelEvent(event); + if (event->isAccepted()) + break; + } + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. +} + +/*! \internal + + This function draws the entire plot, including background pixmap, with the specified \a painter. + It does not make use of the paint buffers like \ref replot, so this is the function typically + used by saving/exporting methods such as \ref savePdf or \ref toPainter. + + Note that it does not fill the background with the background brush (as the user may specify with + \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this + method. +*/ +void QCustomPlot::draw(QCPPainter *painter) +{ + updateLayout(); + + // draw viewport background pixmap: + drawBackground(painter); + + // draw all layered objects (grid, axes, plottables, items, legend,...): + Q_FOREACH (QCPLayer *layer, mLayers) + layer->draw(painter); + + /* Debug code to draw all layout element rects + foreach (QCPLayoutElement* el, findChildren()) + { + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->rect()); + painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); + painter->drawRect(el->outerRect()); + } + */ +} + +/*! \internal + + Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref + QCPLayoutElement::update on the main plot layout. + + Here, the layout elements calculate their positions and margins, and prepare for the following + draw call. +*/ +void QCustomPlot::updateLayout() +{ + // run through layout phases: + mPlotLayout->update(QCPLayoutElement::upPreparation); + mPlotLayout->update(QCPLayoutElement::upMargins); + mPlotLayout->update(QCPLayoutElement::upLayout); +} + +/*! \internal + + Draws the viewport background pixmap of the plot. + + If a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the viewport with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + Note that this function does not draw a fill with the background brush + (\ref setBackground(const QBrush &brush)) beneath the pixmap. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCustomPlot::drawBackground(QCPPainter *painter) +{ + // Note: background color is handled in individual replot/save functions + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mViewport.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); + } + } +} + +/*! \internal + + Goes through the layers and makes sure this QCustomPlot instance holds the correct number of + paint buffers and that they have the correct configuration (size, pixel ratio, etc.). + Allocations, reallocations and deletions of paint buffers are performed as necessary. It also + associates the paint buffers with the layers, so they draw themselves into the right buffer when + \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref + QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for + layers in \ref QCPLayer::lmBuffered mode. + + This method uses \ref createPaintBuffer to create new paint buffers. + + After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated + (so an attempt to replot only a single buffered layer causes a full replot). + + This method is called in every \ref replot call, prior to actually drawing the layers (into their + associated paint buffer). If the paint buffers don't need changing/reallocating, this method + basically leaves them alone and thus finishes very fast. +*/ +void QCustomPlot::setupPaintBuffers() +{ + int bufferIndex = 0; + if (mPaintBuffers.isEmpty()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + + for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) + { + QCPLayer *layer = mLayers.at(layerIndex); + if (layer->mode() == QCPLayer::lmLogical) + { + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + } else if (layer->mode() == QCPLayer::lmBuffered) + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); + if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables + { + ++bufferIndex; + if (bufferIndex >= mPaintBuffers.size()) + mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + } + } + } + // remove unneeded buffers: + while (mPaintBuffers.size()-1 > bufferIndex) + mPaintBuffers.removeLast(); + // resize buffers to viewport size and clear contents: + for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size + mPaintBuffers.at(i)->clear(Qt::transparent); + mPaintBuffers.at(i)->setInvalidated(); + } +} + +/*! \internal + + This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. + + Depending on the current setting of \ref setOpenGl, and the current Qt version, different + backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper + size and device pixel ratio, and returned. +*/ +QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() +{ + if (mOpenGl) + { +#if defined(QCP_OPENGL_FBO) + return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); +#elif defined(QCP_OPENGL_PBUFFER) + return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); +#else + qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +#endif + } else + return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); +} + +/*! + This method returns whether any of the paint buffers held by this QCustomPlot instance are + invalidated. + + If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always + causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example + the layer order has changed, new layers were added, layers were removed, or layer modes were + changed (\ref QCPLayer::setMode). + + \see QCPAbstractPaintBuffer::setInvalidated +*/ +bool QCustomPlot::hasInvalidatedPaintBuffers() +{ + for (int i=0; iinvalidated()) + return true; + } + return false; +} + +/*! \internal + + When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, + surface, paint device). + + Returns true on success. + + If this method is successful, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref + QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. + + \see freeOpenGl +*/ +bool QCustomPlot::setupOpenGl() +{ +#ifdef QCP_OPENGL_FBO + freeOpenGl(); + QSurfaceFormat proposedSurfaceFormat; + proposedSurfaceFormat.setSamples(mOpenGlMultisamples); +#ifdef QCP_OPENGL_OFFSCREENSURFACE + QOffscreenSurface *surface = new QOffscreenSurface; +#else + QWindow *surface = new QWindow; + surface->setSurfaceType(QSurface::OpenGLSurface); +#endif + surface->setFormat(proposedSurfaceFormat); + surface->create(); + mGlSurface = QSharedPointer(surface); + mGlContext = QSharedPointer(new QOpenGLContext); + mGlContext->setFormat(mGlSurface->format()); + if (!mGlContext->create()) + { + qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device + { + qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + { + qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; + mGlContext.clear(); + mGlSurface.clear(); + return false; + } + mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); + return true; +#elif defined(QCP_OPENGL_PBUFFER) + return QGLFormat::hasOpenGL(); +#else + return false; +#endif +} + +/*! \internal + + When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the + context and frees resources). + + After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling + \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref + QCPPaintBufferPixmap) is used for subsequent replots. + + \see setupOpenGl +*/ +void QCustomPlot::freeOpenGl() +{ +#ifdef QCP_OPENGL_FBO + mGlPaintDevice.clear(); + mGlContext.clear(); + mGlSurface.clear(); +#endif +} + +/*! \internal + + This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot + so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. +*/ +void QCustomPlot::axisRemoved(QCPAxis *axis) +{ + if (xAxis == axis) + xAxis = 0; + if (xAxis2 == axis) + xAxis2 = 0; + if (yAxis == axis) + yAxis = 0; + if (yAxis2 == axis) + yAxis2 = 0; + + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers +} + +/*! \internal + + This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so + it may clear its QCustomPlot::legend member accordingly. +*/ +void QCustomPlot::legendRemoved(QCPLegend *legend) +{ + if (this->legend == legend) + this->legend = 0; +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmSelect. + + First, it determines which axis rect was the origin of the selection rect judging by the starting + point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be + precise) associated with that axis rect and finds the data points that are in \a rect. It does + this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. + + Then, the actual selection is done by calling the plottables' \ref + QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details + parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a + rect receive a \ref QCPAbstractPlottable::deselectEvent. + + \see processRectZoom +*/ +void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) +{ + bool selectionStateChanged = false; + + if (mInteractions.testFlag(QCP::iSelectPlottables)) + { + QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size + QRectF rectF(rect.normalized()); + if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) + { + // determine plottables that were hit by the rect and thus are candidates for selection: + Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) + { + if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) + { + QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); + if (!dataSel.isEmpty()) + potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); + } + } + + if (!mInteractions.testFlag(QCP::iMultiSelect)) + { + // only leave plottable with most selected points in map, since we will only select a single plottable: + if (!potentialSelections.isEmpty()) + { + QMap >::iterator it = potentialSelections.begin(); + while (it != potentialSelections.end()-1) // erase all except last element + it = potentialSelections.erase(it); + } + } + + bool additive = event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + // emit deselection except to those plottables who will be selected afterwards: + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + // go through selections in reverse (largest selection first) and emit select events: + QMap >::const_iterator it = potentialSelections.constEnd(); + while (it != potentialSelections.constBegin()) + { + --it; + if (mInteractions.testFlag(it.value().first->selectionCategory())) + { + bool selChanged = false; + it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } else if (mSelectionRect) + mSelectionRect->layer()->replot(); +} + +/*! \internal + + This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref + setSelectionRectMode is set to \ref QCP::srmZoom. + + It determines which axis rect was the origin of the selection rect judging by the starting point + of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the + provided \a rect (see \ref QCPAxisRect::zoom). + + \see processRectSelection +*/ +void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) +{ + Q_UNUSED(event) + if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) + { + QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); + affectedAxes.removeAll(static_cast(0)); + axisRect->zoom(QRectF(rect), affectedAxes); + } + replot(rpQueuedReplot); // always replot to make selection rect disappear +} + +/*! \internal + + This method is called when a simple left mouse click was detected on the QCustomPlot surface. + + It first determines the layerable that was hit by the click, and then calls its \ref + QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the + multi-select modifier was pressed, see \ref setMultiSelectModifier). + + In this method the hit layerable is determined a second time using \ref layerableAt (after the + one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This + implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the + clicked layerable determined here. For example, if a non-selectable layerable is in front of a + selectable layerable at the click position, the front layerable will receive mouse events but the + selectable one in the back will receive the \ref QCPLayerable::selectEvent. + + \see processRectSelection, QCPLayerable::selectTest +*/ +void QCustomPlot::processPointSelection(QMouseEvent *event) +{ + QVariant details; + QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); + bool selectionStateChanged = false; + bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); + // deselect all other layerables if not additive selection: + if (!additive) + { + Q_FOREACH (QCPLayer *layer, mLayers) + { + Q_FOREACH (QCPLayerable *layerable, layer->children()) + { + if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) + { + bool selChanged = false; + layerable->deselectEvent(&selChanged); + selectionStateChanged |= selChanged; + } + } + } + } + if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) + { + // a layerable was actually clicked, call its selectEvent: + bool selChanged = false; + clickedLayerable->selectEvent(event, additive, details, &selChanged); + selectionStateChanged |= selChanged; + } + if (selectionStateChanged) + { + Q_EMIT selectionChangedByUser(); + replot(rpQueuedReplot); + } +} + +/*! \internal + + Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend + is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the + plottable. + + Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of + \a plottable is this QCustomPlot. + + This method is called automatically in the QCPAbstractPlottable base class constructor. +*/ +bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) +{ + if (mPlottables.contains(plottable)) + { + qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); + return false; + } + if (plottable->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); + return false; + } + + mPlottables.append(plottable); + // possibly add plottable to legend: + if (mAutoAddPlottableToLegend) + plottable->addToLegend(); + if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + plottable->setLayer(currentLayer()); + return true; +} + +/*! \internal + + In order to maintain the simplified graph interface of QCustomPlot, this method is called by the + QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true + on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. + + This graph specific registration happens in addition to the call to \ref registerPlottable by the + QCPAbstractPlottable base class. +*/ +bool QCustomPlot::registerGraph(QCPGraph *graph) +{ + if (!graph) + { + qDebug() << Q_FUNC_INFO << "passed graph is zero"; + return false; + } + if (mGraphs.contains(graph)) + { + qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; + return false; + } + + mGraphs.append(graph); + return true; +} + + +/*! \internal + + Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. + + Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a + item is this QCustomPlot. + + This method is called automatically in the QCPAbstractItem base class constructor. +*/ +bool QCustomPlot::registerItem(QCPAbstractItem *item) +{ + if (mItems.contains(item)) + { + qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); + return false; + } + if (item->parentPlot() != this) + { + qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); + return false; + } + + mItems.append(item); + if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) + item->setLayer(currentLayer()); + return true; +} + +/*! \internal + + Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called + after every operation that changes the layer indices, like layer removal, layer creation, layer + moving. +*/ +void QCustomPlot::updateLayerIndices() const +{ + for (int i=0; imIndex = i; +} + +/*! \internal + + Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, + only those layerables that are selectable will be considered. (Layerable subclasses communicate + their selectability via the QCPLayerable::selectTest method, by returning -1.) + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableListAt, layoutElementAt, axisRectAt +*/ +QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const +{ + QList details; + QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); + if (selectionDetails && !details.isEmpty()) + *selectionDetails = details.first(); + if (!candidates.isEmpty()) + return candidates.first(); + else + return 0; +} + +/*! \internal + + Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those + layerables that are selectable will be considered. (Layerable subclasses communicate their + selectability via the QCPLayerable::selectTest method, by returning -1.) + + The returned list is sorted by the layerable/drawing order. If you only need to know the top-most + layerable, rather use \ref layerableAt. + + \a selectionDetails is an output parameter that contains selection specifics of the affected + layerable. This is useful if the respective layerable shall be given a subsequent + QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains + information about which part of the layerable was hit, in multi-part layerables (e.g. + QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref + QCPDataSelection instance with the single data point which is closest to \a pos. + + \see layerableAt, layoutElementAt, axisRectAt +*/ +QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const +{ + QList result; + for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) + { + const QList layerables = mLayers.at(layerIndex)->children(); + for (int i=layerables.size()-1; i>=0; --i) + { + if (!layerables.at(i)->realVisibility()) + continue; + QVariant details; + double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); + if (dist >= 0 && dist < selectionTolerance()) + { + result.append(layerables.at(i)); + if (selectionDetails) + selectionDetails->append(details); + } + } + } + return result; +} + +/*! + Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is + sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead + to a full resolution file with width 200.) If the \a format supports compression, \a quality may + be between 0 and 100 to control it. + + Returns true on success. If this function fails, most likely the given \a format isn't supported + by the system, see Qt docs about QImageWriter::supportedImageFormats(). + + The \a resolution will be written to the image file header (if the file format supports this) and + has no direct consequence for the quality or the pixel size. However, if opening the image with a + tool which respects the metadata, it will be able to scale the image to match either a given size + in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in + which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted + to the format's expected resolution unit internally. + + \see saveBmp, saveJpg, savePng, savePdf +*/ +bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +{ + QImage buffer = toPixmap(width, height, scale).toImage(); + + int dotsPerMeter = 0; + switch (resolutionUnit) + { + case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; + case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; + case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; + } + buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + if (!buffer.isNull()) + return buffer.save(fileName, format, quality); + else + return false; +} + +/*! + Renders the plot to a pixmap and returns it. + + The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and + scale 2.0 lead to a full resolution pixmap with width 200.) + + \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf +*/ +QPixmap QCustomPlot::toPixmap(int width, int height, double scale) +{ + // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + int scaledWidth = qRound(scale*newWidth); + int scaledHeight = qRound(scale*newHeight); + + QPixmap result(scaledWidth, scaledHeight); + result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later + QCPPainter painter; + painter.begin(&result); + if (painter.isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter.setMode(QCPPainter::pmNoCaching); + if (!qFuzzyCompare(scale, 1.0)) + { + if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales + painter.setMode(QCPPainter::pmNonCosmetic); + painter.scale(scale, scale); + } + if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill + painter.fillRect(mViewport, mBackgroundBrush); + draw(&painter); + setViewport(oldViewport); + painter.end(); + } else // might happen if pixmap has width or height zero + { + qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; + return QPixmap(); + } + return result; +} + +/*! + Renders the plot using the passed \a painter. + + The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will + appear scaled accordingly. + + \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter + on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with + the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. + + \see toPixmap +*/ +void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) +{ + // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. + int newWidth, newHeight; + if (width == 0 || height == 0) + { + newWidth = this->width(); + newHeight = this->height(); + } else + { + newWidth = width; + newHeight = height; + } + + if (painter->isActive()) + { + QRect oldViewport = viewport(); + setViewport(QRect(0, 0, newWidth, newHeight)); + painter->setMode(QCPPainter::pmNoCaching); + if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here + painter->fillRect(mViewport, mBackgroundBrush); + draw(painter); + setViewport(oldViewport); + } else + qDebug() << Q_FUNC_INFO << "Passed painter is not active"; +} +/* end of 'src/core.cpp' */ + +//amalgamation: add plottable1d.cpp + +/* including file 'src/colorgradient.cpp', size 24646 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorGradient +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorGradient + \brief Defines a color gradient for use with e.g. \ref QCPColorMap + + This class describes a color gradient which can be used to encode data with color. For example, + QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which + take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) + with a \a position from 0 to 1. In between these defined color positions, the + color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. + + Alternatively, load one of the preset color gradients shown in the image below, with \ref + loadPreset, or by directly specifying the preset in the constructor. + + Apart from red, green and blue components, the gradient also interpolates the alpha values of the + configured color stops. This allows to display some portions of the data range as transparent in + the plot. + + \image html QCPColorGradient.png + + The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref + GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset + to all the \a setGradient methods, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient + + The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the + color gradient shall be applied periodically (wrapping around) to data values that lie outside + the data range specified on the plottable instance can be controlled with \ref setPeriodic. +*/ + +/*! + Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color + stops with \ref setColorStopAt. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient() : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); +} + +/*! + Constructs a new QCPColorGradient initialized with the colors and color interpolation according + to \a preset. + + The color level count is initialized to 350. +*/ +QCPColorGradient::QCPColorGradient(GradientPreset preset) : + mLevelCount(350), + mColorInterpolation(ciRGB), + mPeriodic(false), + mColorBufferInvalidated(true) +{ + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); + loadPreset(preset); +} + +/* undocumented operator */ +bool QCPColorGradient::operator==(const QCPColorGradient &other) const +{ + return ((other.mLevelCount == this->mLevelCount) && + (other.mColorInterpolation == this->mColorInterpolation) && + (other.mPeriodic == this->mPeriodic) && + (other.mColorStops == this->mColorStops)); +} + +/*! + Sets the number of discretization levels of the color gradient to \a n. The default is 350 which + is typically enough to create a smooth appearance. The minimum number of levels is 2. + + \image html QCPColorGradient-levelcount.png +*/ +void QCPColorGradient::setLevelCount(int n) +{ + if (n < 2) + { + qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; + n = 2; + } + if (n != mLevelCount) + { + mLevelCount = n; + mColorBufferInvalidated = true; + } +} + +/*! + Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the + colors are the values of the passed QMap \a colorStops. In between these color stops, the color + is interpolated according to \ref setColorInterpolation. + + A more convenient way to create a custom gradient may be to clear all color stops with \ref + clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with + \ref setColorStopAt. + + \see clearColorStops +*/ +void QCPColorGradient::setColorStops(const QMap &colorStops) +{ + mColorStops = colorStops; + mColorBufferInvalidated = true; +} + +/*! + Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between + these color stops, the color is interpolated according to \ref setColorInterpolation. + + \see setColorStops, clearColorStops +*/ +void QCPColorGradient::setColorStopAt(double position, const QColor &color) +{ + mColorStops.insert(position, color); + mColorBufferInvalidated = true; +} + +/*! + Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be + interpolated linearly in RGB or in HSV color space. + + For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, + whereas in HSV space the intermediate color is yellow. +*/ +void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) +{ + if (interpolation != mColorInterpolation) + { + mColorInterpolation = interpolation; + mColorBufferInvalidated = true; + } +} + +/*! + Sets whether data points that are outside the configured data range (e.g. \ref + QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether + they all have the same color, corresponding to the respective gradient boundary color. + + \image html QCPColorGradient-periodic.png + + As shown in the image above, gradients that have the same start and end color are especially + suitable for a periodic gradient mapping, since they produce smooth color transitions throughout + the color map. A preset that has this property is \ref gpHues. + + In practice, using periodic color gradients makes sense when the data corresponds to a periodic + dimension, such as an angle or a phase. If this is not the case, the color encoding might become + ambiguous, because multiple different data values are shown as the same color. +*/ +void QCPColorGradient::setPeriodic(bool enabled) +{ + mPeriodic = enabled; +} + +/*! \overload + + This method is used to quickly convert a \a data array to colors. The colors will be output in + the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this + function. The data range that shall be used for mapping the data value to the gradient is passed + in \a range. \a logarithmic indicates whether the data values shall be mapped to colors + logarithmically. + + if \a data actually contains 2D-data linearized via [row*columnCount + column], you can + set \a dataIndexFactor to columnCount to convert a column instead of a row of the data + array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data + is addressed data[i*dataIndexFactor]. + + Use the overloaded method to additionally provide alpha map data. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + scanLine[i] = mColorBuffer.at(index); + } + } + } +} + +/*! \overload + + Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which + has the same size and structure as \a data and encodes the alpha information per data point. + + The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied + with alpha (see QImage::Format_ARGB32_Premultiplied). +*/ +void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +{ + // If you change something here, make sure to also adapt color() and the other colorize() overload + if (!data) + { + qDebug() << Q_FUNC_INFO << "null pointer given as data"; + return; + } + if (!alpha) + { + qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; + return; + } + if (!scanLine) + { + qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; + return; + } + if (mColorBufferInvalidated) + updateColorBuffer(); + + if (!logarithmic) + { + const double posToIndexFactor = (mLevelCount-1)/range.size(); + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } else // logarithmic == true + { + if (mPeriodic) + { + for (int i=0; i= mLevelCount) + index = mLevelCount-1; + if (alpha[dataIndexFactor*i] == 255) + { + scanLine[i] = mColorBuffer.at(index); + } else + { + const QRgb rgb = mColorBuffer.at(index); + const float alphaF = alpha[dataIndexFactor*i]/255.0f; + scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + } + } + } + } +} + +/*! \internal + + This method is used to colorize a single data value given in \a position, to colors. The data + range that shall be used for mapping the data value to the gradient is passed in \a range. \a + logarithmic indicates whether the data value shall be mapped to a color logarithmically. + + If an entire array of data values shall be converted, rather use \ref colorize, for better + performance. + + The returned QRgb has its r, g and b components premultiplied with alpha (see + QImage::Format_ARGB32_Premultiplied). +*/ +QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) +{ + // If you change something here, make sure to also adapt ::colorize() + if (mColorBufferInvalidated) + updateColorBuffer(); + int index = 0; + if (!logarithmic) + index = (position-range.lower)*(mLevelCount-1)/range.size(); + else + index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); + if (mPeriodic) + { + index = index % mLevelCount; + if (index < 0) + index += mLevelCount; + } else + { + if (index < 0) + index = 0; + else if (index >= mLevelCount) + index = mLevelCount-1; + } + return mColorBuffer.at(index); +} + +/*! + Clears the current color stops and loads the specified \a preset. A preset consists of predefined + color stops and the corresponding color interpolation method. + + The available presets are: + \image html QCPColorGradient.png +*/ +void QCPColorGradient::loadPreset(GradientPreset preset) +{ + clearColorStops(); + switch (preset) + { + case gpGrayscale: + setColorInterpolation(ciRGB); + setColorStopAt(0, Qt::black); + setColorStopAt(1, Qt::white); + break; + case gpHot: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 0, 0)); + setColorStopAt(0.2, QColor(180, 10, 0)); + setColorStopAt(0.4, QColor(245, 50, 0)); + setColorStopAt(0.6, QColor(255, 150, 10)); + setColorStopAt(0.8, QColor(255, 255, 50)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpCold: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.2, QColor(0, 10, 180)); + setColorStopAt(0.4, QColor(0, 50, 245)); + setColorStopAt(0.6, QColor(10, 150, 255)); + setColorStopAt(0.8, QColor(50, 255, 255)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpNight: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(10, 20, 30)); + setColorStopAt(1, QColor(250, 255, 250)); + break; + case gpCandy: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(0, 0, 255)); + setColorStopAt(1, QColor(255, 250, 250)); + break; + case gpGeography: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(70, 170, 210)); + setColorStopAt(0.20, QColor(90, 160, 180)); + setColorStopAt(0.25, QColor(45, 130, 175)); + setColorStopAt(0.30, QColor(100, 140, 125)); + setColorStopAt(0.5, QColor(100, 140, 100)); + setColorStopAt(0.6, QColor(130, 145, 120)); + setColorStopAt(0.7, QColor(140, 130, 120)); + setColorStopAt(0.9, QColor(180, 190, 190)); + setColorStopAt(1, QColor(210, 210, 230)); + break; + case gpIon: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 10, 10)); + setColorStopAt(0.45, QColor(0, 0, 255)); + setColorStopAt(0.8, QColor(0, 255, 255)); + setColorStopAt(1, QColor(0, 255, 0)); + break; + case gpThermal: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 50)); + setColorStopAt(0.15, QColor(20, 0, 120)); + setColorStopAt(0.33, QColor(200, 30, 140)); + setColorStopAt(0.6, QColor(255, 100, 0)); + setColorStopAt(0.85, QColor(255, 255, 40)); + setColorStopAt(1, QColor(255, 255, 255)); + break; + case gpPolar: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(50, 255, 255)); + setColorStopAt(0.18, QColor(10, 70, 255)); + setColorStopAt(0.28, QColor(10, 10, 190)); + setColorStopAt(0.5, QColor(0, 0, 0)); + setColorStopAt(0.72, QColor(190, 10, 10)); + setColorStopAt(0.82, QColor(255, 70, 10)); + setColorStopAt(1, QColor(255, 255, 50)); + break; + case gpSpectrum: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(50, 0, 50)); + setColorStopAt(0.15, QColor(0, 0, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.6, QColor(255, 255, 0)); + setColorStopAt(0.75, QColor(255, 30, 0)); + setColorStopAt(1, QColor(50, 0, 0)); + break; + case gpJet: + setColorInterpolation(ciRGB); + setColorStopAt(0, QColor(0, 0, 100)); + setColorStopAt(0.15, QColor(0, 50, 255)); + setColorStopAt(0.35, QColor(0, 255, 255)); + setColorStopAt(0.65, QColor(255, 255, 0)); + setColorStopAt(0.85, QColor(255, 30, 0)); + setColorStopAt(1, QColor(100, 0, 0)); + break; + case gpHues: + setColorInterpolation(ciHSV); + setColorStopAt(0, QColor(255, 0, 0)); + setColorStopAt(1.0/3.0, QColor(0, 0, 255)); + setColorStopAt(2.0/3.0, QColor(0, 255, 0)); + setColorStopAt(1, QColor(255, 0, 0)); + break; + } +} + +/*! + Clears all color stops. + + \see setColorStops, setColorStopAt +*/ +void QCPColorGradient::clearColorStops() +{ + mColorStops.clear(); + mColorBufferInvalidated = true; +} + +/*! + Returns an inverted gradient. The inverted gradient has all properties as this \ref + QCPColorGradient, but the order of the color stops is inverted. + + \see setColorStops, setColorStopAt +*/ +QCPColorGradient QCPColorGradient::inverted() const +{ + QCPColorGradient result(*this); + result.clearColorStops(); + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + result.setColorStopAt(1.0-it.key(), it.value()); + return result; +} + +/*! \internal + + Returns true if the color gradient uses transparency, i.e. if any of the configured color stops + has an alpha value below 255. +*/ +bool QCPColorGradient::stopsUseAlpha() const +{ + for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + { + if (it.value().alpha() < 255) + return true; + } + return false; +} + +/*! \internal + + Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly + convert positions to colors. This is where the interpolation between color stops is calculated. +*/ +void QCPColorGradient::updateColorBuffer() +{ + if (mColorBuffer.size() != mLevelCount) + mColorBuffer.resize(mLevelCount); + if (mColorStops.size() > 1) + { + double indexToPosFactor = 1.0/(double)(mLevelCount-1); + const bool useAlpha = stopsUseAlpha(); + for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); + if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop + { + mColorBuffer[i] = (it-1).value().rgba(); + } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop + { + mColorBuffer[i] = it.value().rgba(); + } else // position is in between stops (or on an intermediate stop), interpolate color + { + QMap::const_iterator high = it; + QMap::const_iterator low = it-1; + double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 + switch (mColorInterpolation) + { + case ciRGB: + { + if (useAlpha) + { + const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); + const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, + ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, + ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, + alpha); + } else + { + mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), + ((1-t)*low.value().green() + t*high.value().green()), + ((1-t)*low.value().blue() + t*high.value().blue())); + } + break; + } + case ciHSV: + { + QColor lowHsv = low.value().toHsv(); + QColor highHsv = high.value().toHsv(); + double hue = 0; + double hueDiff = highHsv.hueF()-lowHsv.hueF(); + if (hueDiff > 0.5) + hue = lowHsv.hueF() - t*(1.0-hueDiff); + else if (hueDiff < -0.5) + hue = lowHsv.hueF() + t*(1.0+hueDiff); + else + hue = lowHsv.hueF() + t*hueDiff; + if (hue < 0) hue += 1.0; + else if (hue >= 1.0) hue -= 1.0; + if (useAlpha) + { + const QRgb rgb = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); + mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); + } + else + { + mColorBuffer[i] = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + } + break; + } + } + } + } + } else if (mColorStops.size() == 1) + { + const QRgb rgb = mColorStops.constBegin().value().rgb(); + const float alpha = mColorStops.constBegin().value().alphaF(); + mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); + } else // mColorStops is empty, fill color buffer with black + { + mColorBuffer.fill(qRgb(0, 0, 0)); + } + mColorBufferInvalidated = false; +} +/* end of 'src/colorgradient.cpp' */ + + +/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPSelectionDecoratorBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPSelectionDecoratorBracket + \brief A selection decorator which draws brackets around each selected data segment + + Additionally to the regular highlighting of selected segments via color, fill and scatter style, + this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data + segment of the plottable. + + The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and + \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref + setBracketBrush. + + To introduce custom bracket styles, it is only necessary to sublcass \ref + QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the + base class. +*/ + +/*! + Creates a new QCPSelectionDecoratorBracket instance with default values. +*/ +QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : + mBracketPen(QPen(Qt::black)), + mBracketBrush(Qt::NoBrush), + mBracketWidth(5), + mBracketHeight(50), + mBracketStyle(bsSquareBracket), + mTangentToData(false), + mTangentAverage(2) +{ + +} + +QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() +{ +} + +/*! + Sets the pen that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) +{ + mBracketPen = pen; +} + +/*! + Sets the brush that will be used to draw the brackets at the beginning and end of each selected + data segment. +*/ +void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) +{ + mBracketBrush = brush; +} + +/*! + Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of + the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketWidth(int width) +{ + mBracketWidth = width; +} + +/*! + Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis + of the data, or the tangent direction of the current data slope, if \ref setTangentToData is + enabled. +*/ +void QCPSelectionDecoratorBracket::setBracketHeight(int height) +{ + mBracketHeight = height; +} + +/*! + Sets the shape that the bracket/marker will have. + + \see setBracketWidth, setBracketHeight +*/ +void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) +{ + mBracketStyle = style; +} + +/*! + Sets whether the brackets will be rotated such that they align with the slope of the data at the + position that they appear in. + + For noisy data, it might be more visually appealing to average the slope over multiple data + points. This can be configured via \ref setTangentAverage. +*/ +void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) +{ + mTangentToData = enabled; +} + +/*! + Controls over how many data points the slope shall be averaged, when brackets shall be aligned + with the data (if \ref setTangentToData is true). + + From the position of the bracket, \a pointCount points towards the selected data range will be + taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to + disabling \ref setTangentToData. +*/ +void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) +{ + mTangentAverage = pointCount; + if (mTangentAverage < 1) + mTangentAverage = 1; +} + +/*! + Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and + indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening + bracket, respectively). + + The passed \a painter already contains all transformations that are necessary to position and + rotate the bracket appropriately. Painting operations can be performed as if drawing upright + brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. + + If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket + shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should + reimplement. +*/ +void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const +{ + switch (mBracketStyle) + { + case bsSquareBracket: + { + painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); + painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + break; + } + case bsHalfEllipse: + { + painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); + break; + } + case bsEllipse: + { + painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); + break; + } + case bsPlus: + { + painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); + painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); + break; + } + default: + { + qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); + break; + } + } +} + +/*! + Draws the bracket decoration on the data points at the begin and end of each selected data + segment given in \a seletion. + + It uses the method \ref drawBracket to actually draw the shapes. + + \seebaseclassmethod +*/ +void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +{ + if (!mPlottable || selection.isEmpty()) return; + + if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) + { + Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) + { + // determine position and (if tangent mode is enabled) angle of brackets: + int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; + int closeBracketDir = -openBracketDir; + QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); + QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); + double openBracketAngle = 0; + double closeBracketAngle = 0; + if (mTangentToData) + { + openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); + closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); + } + // draw opening bracket: + QTransform oldTransform = painter->transform(); + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(openBracketPos); + painter->rotate(openBracketAngle/M_PI*180.0); + drawBracket(painter, openBracketDir); + painter->setTransform(oldTransform); + // draw closing bracket: + painter->setPen(mBracketPen); + painter->setBrush(mBracketBrush); + painter->translate(closeBracketPos); + painter->rotate(closeBracketAngle/M_PI*180.0); + drawBracket(painter, closeBracketDir); + painter->setTransform(oldTransform); + } + } +} + +/*! \internal + + If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. + This method returns the angle in radians by which a bracket at the given \a dataIndex must be + rotated. + + The parameter \a direction must be set to either -1 or 1, representing whether it is an opening + or closing bracket. Since for slope calculation multiple data points are required, this defines + the direction in which the algorithm walks, starting at \a dataIndex, to average those data + points. (see \ref setTangentToData and \ref setTangentAverage) + + \a interface1d is the interface to the plottable's data which is used to query data coordinates. +*/ +double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const +{ + if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) + return 0; + direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 + + // how many steps we can actually go from index in the given direction without exceeding data bounds: + int averageCount; + if (direction < 0) + averageCount = qMin(mTangentAverage, dataIndex); + else + averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); + qDebug() << averageCount; + // calculate point average of averageCount points: + QVector points(averageCount); + QPointF pointsAverage; + int currentIndex = dataIndex; + for (int i=0; ikeyAxis(); + QCPAxis *valueAxis = mPlottable->valueAxis(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } + + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); + else + return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); +} +/* end of 'src/selectiondecorator-bracket.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAxisRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAxisRect + \brief Holds multiple axes and arranges them in a rectangular shape. + + This class represents an axis rect, a rectangular area that is bounded on all sides with an + arbitrary number of axes. + + Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the + layout system allows to have multiple axis rects, e.g. arranged in a grid layout + (QCustomPlot::plotLayout). + + By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be + accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. + If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be + invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref + addAxes. To remove an axis, use \ref removeAxis. + + The axis rect layerable itself only draws a background pixmap or color, if specified (\ref + setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an + explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be + placed on other layers, independently of the axis rect. + + Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref + insetLayout and can be used to have other layout elements (or even other layouts with multiple + elements) hovering inside the axis rect. + + If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The + behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel + is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable + via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are + only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref + QCP::iRangeZoom. + + \image html AxisRectSpacingOverview.png +
Overview of the spacings and paddings that define the geometry of an axis. The dashed + line on the far left indicates the viewport/widget border.
+*/ + +/* start documentation of inline functions */ + +/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const + + Returns the inset layout of this axis rect. It can be used to place other layout elements (or + even layouts with multiple other elements) inside/on top of an axis rect. + + \see QCPLayoutInset +*/ + +/*! \fn int QCPAxisRect::left() const + + Returns the pixel position of the left border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::right() const + + Returns the pixel position of the right border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::top() const + + Returns the pixel position of the top border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::bottom() const + + Returns the pixel position of the bottom border of this axis rect. Margins are not taken into + account here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::width() const + + Returns the pixel width of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn int QCPAxisRect::height() const + + Returns the pixel height of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QSize QCPAxisRect::size() const + + Returns the pixel size of this axis rect. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topLeft() const + + Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, + so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::topRight() const + + Returns the top right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomLeft() const + + Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::bottomRight() const + + Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account + here, so the returned value is with respect to the inner \ref rect. +*/ + +/*! \fn QPoint QCPAxisRect::center() const + + Returns the center of this axis rect in pixels. Margins are not taken into account here, so the + returned value is with respect to the inner \ref rect. +*/ + +/* end documentation of inline functions */ + +/*! + Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four + sides, the top and right axes are set invisible initially. +*/ +QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : + QCPLayoutElement(parentPlot), + mBackgroundBrush(Qt::NoBrush), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mInsetLayout(new QCPLayoutInset), + mRangeDrag(Qt::Horizontal|Qt::Vertical), + mRangeZoom(Qt::Horizontal|Qt::Vertical), + mRangeZoomFactorHorz(0.85), + mRangeZoomFactorVert(0.85), + mDragging(false) +{ + mInsetLayout->initializeParentPlot(mParentPlot); + mInsetLayout->setParentLayerable(this); + mInsetLayout->setParent(this); + + setMinimumSize(50, 50); + setMinimumMargins(QMargins(15, 15, 15, 15)); + mAxes.insert(QCPAxis::atLeft, QList()); + mAxes.insert(QCPAxis::atRight, QList()); + mAxes.insert(QCPAxis::atTop, QList()); + mAxes.insert(QCPAxis::atBottom, QList()); + + if (setupDefaultAxes) + { + QCPAxis *xAxis = addAxis(QCPAxis::atBottom); + QCPAxis *yAxis = addAxis(QCPAxis::atLeft); + QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); + QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); + setRangeDragAxes(xAxis, yAxis); + setRangeZoomAxes(xAxis, yAxis); + xAxis2->setVisible(false); + yAxis2->setVisible(false); + xAxis->grid()->setVisible(true); + yAxis->grid()->setVisible(true); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + xAxis2->grid()->setZeroLinePen(Qt::NoPen); + yAxis2->grid()->setZeroLinePen(Qt::NoPen); + xAxis2->grid()->setVisible(false); + yAxis2->grid()->setVisible(false); + } +} + +QCPAxisRect::~QCPAxisRect() +{ + delete mInsetLayout; + mInsetLayout = 0; + + QList axesList = axes(); + for (int i=0; i ax(mAxes.value(type)); + if (index >= 0 && index < ax.size()) + { + return ax.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; + return 0; + } +} + +/*! + Returns all axes on the axis rect sides specified with \a types. + + \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of + multiple sides. + + \see axis +*/ +QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << mAxes.value(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << mAxes.value(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << mAxes.value(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << mAxes.value(QCPAxis::atBottom); + return result; +} + +/*! \overload + + Returns all axes of this axis rect. +*/ +QList QCPAxisRect::axes() const +{ + QList result; + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + result << it.value(); + } + return result; +} + +/*! + Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a + new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to + remove an axis, use \ref removeAxis instead of deleting it manually. + + You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was + previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership + of the axis, so you may not delete it afterwards. Further, the \a axis must have been created + with this axis rect as parent and with the same axis type as specified in \a type. If this is not + the case, a debug output is generated, the axis is not added, and the method returns 0. + + This method can not be used to move \a axis between axis rects. The same \a axis instance must + not be added multiple times to the same or different axis rects. + + If an axis rect side already contains one or more axes, the lower and upper endings of the new + axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref + QCPLineEnding::esHalfBar. + + \see addAxes, setupFullAxesBox +*/ +QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) +{ + QCPAxis *newAxis = axis; + if (!newAxis) + { + newAxis = new QCPAxis(this, type); + } else // user provided existing axis instance, do some sanity checks + { + if (newAxis->axisType() != type) + { + qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; + return 0; + } + if (newAxis->axisRect() != this) + { + qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; + return 0; + } + if (axes().contains(newAxis)) + { + qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; + return 0; + } + } + if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset + { + bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); + newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); + newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); + } + mAxes[type].append(newAxis); + + // reset convenience axis pointers on parent QCustomPlot if they are unset: + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + switch (type) + { + case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } + case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } + case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } + case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } + } + } + + return newAxis; +} + +/*! + Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an + or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. + + Returns a list of the added axes. + + \see addAxis, setupFullAxesBox +*/ +QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) +{ + QList result; + if (types.testFlag(QCPAxis::atLeft)) + result << addAxis(QCPAxis::atLeft); + if (types.testFlag(QCPAxis::atRight)) + result << addAxis(QCPAxis::atRight); + if (types.testFlag(QCPAxis::atTop)) + result << addAxis(QCPAxis::atTop); + if (types.testFlag(QCPAxis::atBottom)) + result << addAxis(QCPAxis::atBottom); + return result; +} + +/*! + Removes the specified \a axis from the axis rect and deletes it. + + Returns true on success, i.e. if \a axis was a valid axis in this axis rect. + + \see addAxis +*/ +bool QCPAxisRect::removeAxis(QCPAxis *axis) +{ + // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: + QHashIterator > it(mAxes); + while (it.hasNext()) + { + it.next(); + if (it.value().contains(axis)) + { + if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) + it.value()[1]->setOffset(axis->offset()); + mAxes[it.key()].removeOne(axis); + if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) + parentPlot()->axisRemoved(axis); + delete axis; + return true; + } + } + qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); + return false; +} + +/*! + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom + specific axes, use the overloaded version of this method. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect) +{ + zoom(pixelRect, axes()); +} + +/*! \overload + + Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. + + Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. + + \see QCustomPlot::setSelectionRectMode +*/ +void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) +{ + Q_FOREACH (QCPAxis *axis, affectedAxes) + { + if (!axis) + { + qDebug() << Q_FUNC_INFO << "a passed axis was zero"; + continue; + } + QCPRange pixelRange; + if (axis->orientation() == Qt::Horizontal) + pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); + else + pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); + axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); + } +} + +/*! + Convenience function to create an axis on each side that doesn't have any axes yet and set their + visibility to true. Further, the top/right axes are assigned the following properties of the + bottom/left axes: + + \li range (\ref QCPAxis::setRange) + \li range reversed (\ref QCPAxis::setRangeReversed) + \li scale type (\ref QCPAxis::setScaleType) + \li tick visibility (\ref QCPAxis::setTicks) + \li number format (\ref QCPAxis::setNumberFormat) + \li number precision (\ref QCPAxis::setNumberPrecision) + \li tick count of ticker (\ref QCPAxisTicker::setTickCount) + \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) + + Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. + + If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom + and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. +*/ +void QCPAxisRect::setupFullAxesBox(bool connectRanges) +{ + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; + if (axisCount(QCPAxis::atBottom) == 0) + xAxis = addAxis(QCPAxis::atBottom); + else + xAxis = axis(QCPAxis::atBottom); + + if (axisCount(QCPAxis::atLeft) == 0) + yAxis = addAxis(QCPAxis::atLeft); + else + yAxis = axis(QCPAxis::atLeft); + + if (axisCount(QCPAxis::atTop) == 0) + xAxis2 = addAxis(QCPAxis::atTop); + else + xAxis2 = axis(QCPAxis::atTop); + + if (axisCount(QCPAxis::atRight) == 0) + yAxis2 = addAxis(QCPAxis::atRight); + else + yAxis2 = axis(QCPAxis::atRight); + + xAxis->setVisible(true); + yAxis->setVisible(true); + xAxis2->setVisible(true); + yAxis2->setVisible(true); + xAxis2->setTickLabels(false); + yAxis2->setTickLabels(false); + + xAxis2->setRange(xAxis->range()); + xAxis2->setRangeReversed(xAxis->rangeReversed()); + xAxis2->setScaleType(xAxis->scaleType()); + xAxis2->setTicks(xAxis->ticks()); + xAxis2->setNumberFormat(xAxis->numberFormat()); + xAxis2->setNumberPrecision(xAxis->numberPrecision()); + xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); + xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); + + yAxis2->setRange(yAxis->range()); + yAxis2->setRangeReversed(yAxis->rangeReversed()); + yAxis2->setScaleType(yAxis->scaleType()); + yAxis2->setTicks(yAxis->ticks()); + yAxis2->setNumberFormat(yAxis->numberFormat()); + yAxis2->setNumberPrecision(yAxis->numberPrecision()); + yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); + yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); + + if (connectRanges) + { + connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); + connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); + } +} + +/*! + Returns a list of all the plottables that are associated with this axis rect. + + A plottable is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see graphs, items +*/ +QList QCPAxisRect::plottables() const +{ + // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries + QList result; + for (int i=0; imPlottables.size(); ++i) + { + if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mPlottables.at(i)); + } + return result; +} + +/*! + Returns a list of all the graphs that are associated with this axis rect. + + A graph is considered associated with an axis rect if its key or value axis (or both) is in + this axis rect. + + \see plottables, items +*/ +QList QCPAxisRect::graphs() const +{ + // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries + QList result; + for (int i=0; imGraphs.size(); ++i) + { + if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) + result.append(mParentPlot->mGraphs.at(i)); + } + return result; +} + +/*! + Returns a list of all the items that are associated with this axis rect. + + An item is considered associated with an axis rect if any of its positions has key or value axis + set to an axis that is in this axis rect, or if any of its positions has \ref + QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref + QCPAbstractItem::setClipAxisRect) is set to this axis rect. + + \see plottables, graphs +*/ +QList QCPAxisRect::items() const +{ + // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries + // and miss those items that have this axis rect as clipAxisRect. + QList result; + for (int itemId=0; itemIdmItems.size(); ++itemId) + { + if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + continue; + } + QList positions = mParentPlot->mItems.at(itemId)->positions(); + for (int posId=0; posIdaxisRect() == this || + positions.at(posId)->keyAxis()->axisRect() == this || + positions.at(posId)->valueAxis()->axisRect() == this) + { + result.append(mParentPlot->mItems.at(itemId)); + break; + } + } + } + return result; +} + +/*! + This method is called automatically upon replot and doesn't need to be called by users of + QCPAxisRect. + + Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), + and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its + QCPInsetLayout::update function. + + \seebaseclassmethod +*/ +void QCPAxisRect::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + + switch (phase) + { + case upPreparation: + { + QList allAxes = axes(); + for (int i=0; isetupTickVectors(); + break; + } + case upLayout: + { + mInsetLayout->setOuterRect(rect()); + break; + } + default: break; + } + + // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): + mInsetLayout->update(phase); +} + +/* inherits documentation from base class */ +QList QCPAxisRect::elements(bool recursive) const +{ + QList result; + if (mInsetLayout) + { + result << mInsetLayout; + if (recursive) + result << mInsetLayout->elements(recursive); + } + return result; +} + +/* inherits documentation from base class */ +void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPAxisRect::draw(QCPPainter *painter) +{ + drawBackground(painter); +} + +/*! + Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the + axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect + backgrounds are usually drawn below everything else. + + For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be + enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio + is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, + consider using the overloaded version of this function. + + Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref + setBackground(const QBrush &brush). + + \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) +*/ +void QCPAxisRect::setBackground(const QPixmap &pm) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); +} + +/*! \overload + + Sets \a brush as the background brush. The axis rect background will be filled with this brush. + Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds + are usually drawn below everything else. + + The brush will be drawn before (under) any background pixmap, which may be specified with \ref + setBackground(const QPixmap &pm). + + To disable drawing of a background brush, set \a brush to Qt::NoBrush. + + \see setBackground(const QPixmap &pm) +*/ +void QCPAxisRect::setBackground(const QBrush &brush) +{ + mBackgroundBrush = brush; +} + +/*! \overload + + Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it + shall be scaled in one call. + + \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +{ + mBackgroundPixmap = pm; + mScaledBackgroundPixmap = QPixmap(); + mBackgroundScaled = scaled; + mBackgroundScaledMode = mode; +} + +/*! + Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled + is set to true, you may control whether and how the aspect ratio of the original pixmap is + preserved with \ref setBackgroundScaledMode. + + Note that the scaled version of the original pixmap is buffered, so there is no performance + penalty on replots. (Except when the axis rect dimensions are changed continuously.) + + \see setBackground, setBackgroundScaledMode +*/ +void QCPAxisRect::setBackgroundScaled(bool scaled) +{ + mBackgroundScaled = scaled; +} + +/*! + If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to + define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. + \see setBackground, setBackgroundScaled +*/ +void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) +{ + mBackgroundScaledMode = mode; +} + +/*! + Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeDragAxes to retrieve a list with all set axes). + + \see setRangeDragAxes +*/ +QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); + else + return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); +} + +/*! + Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns + the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). + + \see setRangeZoomAxes +*/ +QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) +{ + if (orientation == Qt::Horizontal) + return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); + else + return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); +} + +/*! + Returns all range drag axes of the \a orientation provided. + + \see rangeZoomAxis, setRangeZoomAxes +*/ +QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) +{ + QList result; + if (orientation == Qt::Horizontal) + { + for (int i=0; iQt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeDrag to enable the range dragging interaction. + + \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag +*/ +void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) +{ + mRangeDrag = orientations; +} + +/*! + Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation + corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, + QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical + axis is the left axis (yAxis). + + To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref + QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | + Qt::Vertical as \a orientations. + + In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions + contains \ref QCP::iRangeZoom to enable the range zooming interaction. + + \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag +*/ +void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) +{ + mRangeZoom = orientations; +} + +/*! \overload + + Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on + the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to dragging interactions. + + \see setRangeZoomAxes +*/ +void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag + orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag + motion, use the overload taking two separate lists for horizontal and vertical dragging. +*/ +void QCPAxisRect::setRangeDragAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeDragAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical dragging, and + define specifically which axis reacts to which drag orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) +{ + mRangeDragHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeDragVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeDragVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on + the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. + + The two axes can be zoomed with different strengths, when different factors are passed to \ref + setRangeZoomFactor(double horizontalFactor, double verticalFactor). + + Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall + react to zooming interactions. + + \see setRangeDragAxes +*/ +void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) +{ + QList horz, vert; + if (horizontal) + horz.append(horizontal); + if (vertical) + vert.append(vertical); + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set up multiple axes to react to horizontal and vertical range zooming. The + zoom orientation that the respective axis will react to is deduced from its orientation (\ref + QCPAxis::orientation). + + In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom + interaction, use the overload taking two separate lists for horizontal and vertical zooming. +*/ +void QCPAxisRect::setRangeZoomAxes(QList axes) +{ + QList horz, vert; + Q_FOREACH (QCPAxis *ax, axes) + { + if (ax->orientation() == Qt::Horizontal) + horz.append(ax); + else + vert.append(ax); + } + setRangeZoomAxes(horz, vert); +} + +/*! \overload + + This method allows to set multiple axes up to react to horizontal and vertical zooming, and + define specifically which axis reacts to which zoom orientation (irrespective of the axis + orientation). +*/ +void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) +{ + mRangeZoomHorzAxis.clear(); + Q_FOREACH (QCPAxis *ax, horizontal) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomHorzAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + } + mRangeZoomVertAxis.clear(); + Q_FOREACH (QCPAxis *ax, vertical) + { + QPointer axPointer(ax); + if (!axPointer.isNull()) + mRangeZoomVertAxis.append(axPointer); + else + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + } +} + +/*! + Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with + \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to + let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal + and which is vertical, can be set with \ref setRangeZoomAxes. + + When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) + will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the + same scrolling direction will zoom out. +*/ +void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) +{ + mRangeZoomFactorHorz = horizontalFactor; + mRangeZoomFactorVert = verticalFactor; +} + +/*! \overload + + Sets both the horizontal and vertical zoom \a factor. +*/ +void QCPAxisRect::setRangeZoomFactor(double factor) +{ + mRangeZoomFactorHorz = factor; + mRangeZoomFactorVert = factor; +} + +/*! \internal + + Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a + pixmap. + + If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an + according filling inside the axis rect with the provided \a painter. + + Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version + depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside + the axis rect with the provided \a painter. The scaled version is buffered in + mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when + the axis rect has changed in a way that requires a rescale of the background pixmap (this is + dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was + set. + + \see setBackground, setBackgroundScaled, setBackgroundScaledMode +*/ +void QCPAxisRect::drawBackground(QCPPainter *painter) +{ + // draw background fill: + if (mBackgroundBrush != Qt::NoBrush) + painter->fillRect(mRect, mBackgroundBrush); + + // draw background pixmap (on top of fill, if brush specified): + if (!mBackgroundPixmap.isNull()) + { + if (mBackgroundScaled) + { + // check whether mScaledBackground needs to be updated: + QSize scaledSize(mBackgroundPixmap.size()); + scaledSize.scale(mRect.size(), mBackgroundScaledMode); + if (mScaledBackgroundPixmap.size() != scaledSize) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); + } else + { + painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); + } + } +} + +/*! \internal + + This function makes sure multiple axes on the side specified with \a type don't collide, but are + distributed according to their respective space requirement (QCPAxis::calculateMargin). + + It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the + one with index zero. + + This function is called by \ref calculateAutoMargin. +*/ +void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) +{ + const QList axesList = mAxes.value(type); + if (axesList.isEmpty()) + return; + + bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false + for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); + if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) + { + if (!isFirstVisible) + offset += axesList.at(i)->tickLengthIn(); + isFirstVisible = false; + } + axesList.at(i)->setOffset(offset); + } +} + +/* inherits documentation from base class */ +int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) +{ + if (!mAutoMargins.testFlag(side)) + qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; + + updateAxesOffset(QCPAxis::marginSideToAxisType(side)); + + // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call + const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); + if (axesList.size() > 0) + return axesList.last()->offset() + axesList.last()->calculateMargin(); + else + return 0; +} + +/*! \internal + + Reacts to a change in layout to potentially set the convenience axis pointers \ref + QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective + axes of this axis rect. This is only done if the respective convenience pointer is currently zero + and if there is no QCPAxisRect at position (0, 0) of the plot layout. + + This automation makes it simpler to replace the main axis rect with a newly created one, without + the need to manually reset the convenience pointers. +*/ +void QCPAxisRect::layoutChanged() +{ + if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + { + if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) + mParentPlot->xAxis = axis(QCPAxis::atBottom); + if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) + mParentPlot->yAxis = axis(QCPAxis::atLeft); + if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) + mParentPlot->xAxis2 = axis(QCPAxis::atTop); + if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) + mParentPlot->yAxis2 = axis(QCPAxis::atRight); + } +} + +/*! \internal + + Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is + pressed, the range dragging interaction is initialized (the actual range manipulation happens in + the \ref mouseMoveEvent). + + The mDragging flag is set to true and some anchor points are set that are needed to determine the + distance the mouse was dragged in the mouse move/release events later. + + \see mouseMoveEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + if (event->buttons() & Qt::LeftButton) + { + mDragging = true; + // initialize antialiasing backup in case we start dragging: + if (mParentPlot->noAntialiasingOnDrag()) + { + mAADragBackup = mParentPlot->antialiasedElements(); + mNotAADragBackup = mParentPlot->notAntialiasedElements(); + } + // Mouse range dragging interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + mDragStartHorzRange.clear(); + for (int i=0; irange()); + mDragStartVertRange.clear(); + for (int i=0; irange()); + } + } +} + +/*! \internal + + Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a + preceding \ref mousePressEvent, the range is moved accordingly. + + \see mousePressEvent, mouseReleaseEvent +*/ +void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(startPos) + // Mouse range dragging interaction: + if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + { + + if (mRangeDrag.testFlag(Qt::Horizontal)) + { + for (int i=0; i= mDragStartHorzRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); + ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag.testFlag(Qt::Vertical)) + { + for (int i=0; i= mDragStartVertRange.size()) + break; + if (ax->mScaleType == QCPAxis::stLinear) + { + double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); + } else if (ax->mScaleType == QCPAxis::stLogarithmic) + { + double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); + ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); + } + } + } + + if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot + { + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); + } + + } +} + +/* inherits documentation from base class */ +void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + Q_UNUSED(event) + Q_UNUSED(startPos) + mDragging = false; + if (mParentPlot->noAntialiasingOnDrag()) + { + mParentPlot->setAntialiasedElements(mAADragBackup); + mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + } +} + +/*! \internal + + Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the + ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of + the scaling operation is the current cursor position inside the axis rect. The scaling factor is + dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural + zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. + + Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse + wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be + multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as + exponent of the range zoom factor. This takes care of the wheel direction automatically, by + inverting the factor, when the wheel step is negative (f^-1 = 1/f). +*/ +void QCPAxisRect::wheelEvent(QWheelEvent *event) +{ + // Mouse range zooming interaction: + if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) + { + if (mRangeZoom != 0) + { + double factor; + double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually + if (mRangeZoom.testFlag(Qt::Horizontal)) + { + factor = qPow(mRangeZoomFactorHorz, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); + } + } + if (mRangeZoom.testFlag(Qt::Vertical)) + { + factor = qPow(mRangeZoomFactorVert, wheelSteps); + for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); + } + } + mParentPlot->replot(); + } + } +} +/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPAbstractLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPAbstractLegendItem + \brief The abstract base class for all entries in a QCPLegend. + + It defines a very basic interface for entries in a QCPLegend. For representing plottables in the + legend, the subclass \ref QCPPlottableLegendItem is more suitable. + + Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry + that's not even associated with a plottable). + + You must implement the following pure virtual functions: + \li \ref draw (from QCPLayerable) + + You inherit the following members you may use: + + + + + + + + +
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
+*/ + +/* start of documentation of signals */ + +/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) + + This signal is emitted when the selection state of this legend item has changed, either by user + interaction or by a direct call to \ref setSelected. +*/ + +/* end of documentation of signals */ + +/*! + Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not + cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. +*/ +QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : + QCPLayoutElement(parent->parentPlot()), + mParentLegend(parent), + mFont(parent->font()), + mTextColor(parent->textColor()), + mSelectedFont(parent->selectedFont()), + mSelectedTextColor(parent->selectedTextColor()), + mSelectable(true), + mSelected(false) +{ + setLayer(QLatin1String("legend")); + setMargins(QMargins(0, 0, 0, 0)); +} + +/*! + Sets the default font of this specific legend item to \a font. + + \see setTextColor, QCPLegend::setFont +*/ +void QCPAbstractLegendItem::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the default text color of this specific legend item to \a color. + + \see setFont, QCPLegend::setTextColor +*/ +void QCPAbstractLegendItem::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + When this legend item is selected, \a font is used to draw generic text, instead of the normal + font set with \ref setFont. + + \see setFont, QCPLegend::setSelectedFont +*/ +void QCPAbstractLegendItem::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + When this legend item is selected, \a color is used to draw generic text, instead of the normal + color set with \ref setTextColor. + + \see setTextColor, QCPLegend::setSelectedTextColor +*/ +void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether this specific legend item is selectable. + + \see setSelectedParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets whether this specific legend item is selected. + + It is possible to set the selection state of this item by calling this function directly, even if + setSelectable is set to false. + + \see setSelectableParts, QCustomPlot::setInteractions +*/ +void QCPAbstractLegendItem::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (!mParentPlot) return -1; + if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) + return -1; + + if (mRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); +} + +/* inherits documentation from base class */ +QRect QCPAbstractLegendItem::clipRect() const +{ + return mOuterRect; +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPPlottableLegendItem +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPPlottableLegendItem + \brief A legend item representing a plottable with an icon and the plottable name. + + This is the standard legend item for plottables. It displays an icon of the plottable next to the + plottable name. The icon is drawn by the respective plottable itself (\ref + QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. + For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the + middle. + + Legend items of this type are always associated with one plottable (retrievable via the + plottable() function and settable with the constructor). You may change the font of the plottable + name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref + QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. + + The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend + creates/removes legend items of this type. + + Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of + QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout + interface, QCPLegend has specialized functions for handling legend items conveniently, see the + documentation of \ref QCPLegend. +*/ + +/*! + Creates a new legend item associated with \a plottable. + + Once it's created, it can be added to the legend via \ref QCPLegend::addItem. + + A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref + QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. +*/ +QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : + QCPAbstractLegendItem(parent), + mPlottable(plottable) +{ + setAntialiased(false); +} + +/*! \internal + + Returns the pen that shall be used to draw the icon border, taking into account the selection + state of this item. +*/ +QPen QCPPlottableLegendItem::getIconBorderPen() const +{ + return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); +} + +/*! \internal + + Returns the text color that shall be used to draw text, taking into account the selection state + of this item. +*/ +QColor QCPPlottableLegendItem::getTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} + +/*! \internal + + Returns the font that shall be used to draw text, taking into account the selection state of this + item. +*/ +QFont QCPPlottableLegendItem::getFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Draws the item with \a painter. The size and position of the drawn legend item is defined by the + parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref + maximumOuterSizeHint of this legend item. +*/ +void QCPPlottableLegendItem::draw(QCPPainter *painter) +{ + if (!mPlottable) return; + painter->setFont(getFont()); + painter->setPen(QPen(getTextColor())); + QSizeF iconSize = mParentLegend->iconSize(); + QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + QRectF iconRect(mRect.topLeft(), iconSize); + int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops + painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); + // draw icon: + painter->save(); + painter->setClipRect(iconRect, Qt::IntersectClip); + mPlottable->drawLegendIcon(painter, iconRect); + painter->restore(); + // draw icon border: + if (getIconBorderPen().style() != Qt::NoPen) + { + painter->setPen(getIconBorderPen()); + painter->setBrush(Qt::NoBrush); + int halfPen = qCeil(painter->pen().widthF()*0.5)+1; + painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped + painter->drawRect(iconRect); + } +} + +/*! \internal + + Calculates and returns the size of this item. This includes the icon, the text and the padding in + between. + + \seebaseclassmethod +*/ +QSize QCPPlottableLegendItem::minimumOuterSizeHint() const +{ + if (!mPlottable) return QSize(); + QSize result(0, 0); + QRect textRect; + QFontMetrics fontMetrics(getFont()); + QSize iconSize = mParentLegend->iconSize(); + textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); + result.setHeight(qMax(textRect.height(), iconSize.height())); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPLegend +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPLegend + \brief Manages a legend inside a QCustomPlot. + + A legend is a small box somewhere in the plot which lists plottables with their name and icon. + + A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the + plottable, for which a legend item shall be created. In the case of the main legend (\ref + QCustomPlot::legend), simply adding plottables to the plot while \ref + QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding + legend items. The legend item associated with a certain plottable can be removed with \ref + QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and + manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref + addItem, \ref removeItem, etc. + + Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref + QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement + "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds + an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as + mentioned above. In principle, any other layout elements may also be added to a legend via the + normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout + System\endlink for examples on how to add other elements to the legend and move it outside the axis + rect. + + Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control + in which order (column first or row first) the legend is filled up when calling \ref addItem, and + at which column or row wrapping occurs. + + By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the + inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another + position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend + outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement + interface. +*/ + +/* start of documentation of signals */ + +/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); + + This signal is emitted when the selection state of this legend has changed. + + \see setSelectedParts, setSelectableParts +*/ + +/* end of documentation of signals */ + +/*! + Constructs a new QCPLegend instance with default values. + + Note that by default, QCustomPlot already contains a legend ready to be used as \ref + QCustomPlot::legend +*/ +QCPLegend::QCPLegend() +{ + setFillOrder(QCPLayoutGrid::foRowsFirst); + setWrap(0); + + setRowSpacing(3); + setColumnSpacing(8); + setMargins(QMargins(7, 5, 7, 4)); + setAntialiased(false); + setIconSize(32, 18); + + setIconTextPadding(7); + + setSelectableParts(spLegendBox | spItems); + setSelectedParts(spNone); + + setBorderPen(QPen(Qt::black, 0)); + setSelectedBorderPen(QPen(Qt::blue, 2)); + setIconBorderPen(Qt::NoPen); + setSelectedIconBorderPen(QPen(Qt::blue, 2)); + setBrush(Qt::white); + setSelectedBrush(Qt::white); + setTextColor(Qt::black); + setSelectedTextColor(Qt::blue); +} + +QCPLegend::~QCPLegend() +{ + clearItems(); + if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) + mParentPlot->legendRemoved(this); +} + +/* no doc for getter, see setSelectedParts */ +QCPLegend::SelectableParts QCPLegend::selectedParts() const +{ + // check whether any legend elements selected, if yes, add spItems to return value + bool hasSelectedItems = false; + for (int i=0; iselected()) + { + hasSelectedItems = true; + break; + } + } + if (hasSelectedItems) + return mSelectedParts | spItems; + else + return mSelectedParts & ~spItems; +} + +/*! + Sets the pen, the border of the entire legend is drawn with. +*/ +void QCPLegend::setBorderPen(const QPen &pen) +{ + mBorderPen = pen; +} + +/*! + Sets the brush of the legend background. +*/ +void QCPLegend::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will + use this font by default. However, a different font can be specified on a per-item-basis by + accessing the specific legend item. + + This function will also set \a font on all already existing legend items. + + \see QCPAbstractLegendItem::setFont +*/ +void QCPLegend::setFont(const QFont &font) +{ + mFont = font; + for (int i=0; isetFont(mFont); + } +} + +/*! + Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) + will use this color by default. However, a different colors can be specified on a per-item-basis + by accessing the specific legend item. + + This function will also set \a color on all already existing legend items. + + \see QCPAbstractLegendItem::setTextColor +*/ +void QCPLegend::setTextColor(const QColor &color) +{ + mTextColor = color; + for (int i=0; isetTextColor(color); + } +} + +/*! + Sets the size of legend icons. Legend items that draw an icon (e.g. a visual + representation of the graph) will use this size by default. +*/ +void QCPLegend::setIconSize(const QSize &size) +{ + mIconSize = size; +} + +/*! \overload +*/ +void QCPLegend::setIconSize(int width, int height) +{ + mIconSize.setWidth(width); + mIconSize.setHeight(height); +} + +/*! + Sets the horizontal space in pixels between the legend icon and the text next to it. + Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the + name of the graph) will use this space by default. +*/ +void QCPLegend::setIconTextPadding(int padding) +{ + mIconTextPadding = padding; +} + +/*! + Sets the pen used to draw a border around each legend icon. Legend items that draw an + icon (e.g. a visual representation of the graph) will use this pen by default. + + If no border is wanted, set this to \a Qt::NoPen. +*/ +void QCPLegend::setIconBorderPen(const QPen &pen) +{ + mIconBorderPen = pen; +} + +/*! + Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. + (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) + + However, even when \a selectable is set to a value not allowing the selection of a specific part, + it is still possible to set the selection of this part manually, by calling \ref setSelectedParts + directly. + + \see SelectablePart, setSelectedParts +*/ +void QCPLegend::setSelectableParts(const SelectableParts &selectable) +{ + if (mSelectableParts != selectable) + { + mSelectableParts = selectable; + Q_EMIT selectableChanged(mSelectableParts); + } +} + +/*! + Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part + is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected + doesn't contain \ref spItems, those items become deselected. + + The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions + contains iSelectLegend. You only need to call this function when you wish to change the selection + state manually. + + This function can change the selection state of a part even when \ref setSelectableParts was set to a + value that actually excludes the part. + + emits the \ref selectionChanged signal when \a selected is different from the previous selection state. + + Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set + before, because there's no way to specify which exact items to newly select. Do this by calling + \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. + + \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, + setSelectedFont +*/ +void QCPLegend::setSelectedParts(const SelectableParts &selected) +{ + SelectableParts newSelected = selected; + mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed + + if (mSelectedParts != newSelected) + { + if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) + { + qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; + newSelected &= ~spItems; + } + if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection + { + for (int i=0; isetSelected(false); + } + } + mSelectedParts = newSelected; + Q_EMIT selectionChanged(mSelectedParts); + } +} + +/*! + When the legend box is selected, this pen is used to draw the border instead of the normal pen + set via \ref setBorderPen. + + \see setSelectedParts, setSelectableParts, setSelectedBrush +*/ +void QCPLegend::setSelectedBorderPen(const QPen &pen) +{ + mSelectedBorderPen = pen; +} + +/*! + Sets the pen legend items will use to draw their icon borders, when they are selected. + + \see setSelectedParts, setSelectableParts, setSelectedFont +*/ +void QCPLegend::setSelectedIconBorderPen(const QPen &pen) +{ + mSelectedIconBorderPen = pen; +} + +/*! + When the legend box is selected, this brush is used to draw the legend background instead of the normal brush + set via \ref setBrush. + + \see setSelectedParts, setSelectableParts, setSelectedBorderPen +*/ +void QCPLegend::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the default font that is used by legend items when they are selected. + + This function will also set \a font on all already existing legend items. + + \see setFont, QCPAbstractLegendItem::setSelectedFont +*/ +void QCPLegend::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; + for (int i=0; isetSelectedFont(font); + } +} + +/*! + Sets the default text color that is used by legend items when they are selected. + + This function will also set \a color on all already existing legend items. + + \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor +*/ +void QCPLegend::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; + for (int i=0; isetSelectedTextColor(color); + } +} + +/*! + Returns the item with index \a i. + + Note that the linear index depends on the current fill order (\ref setFillOrder). + + \see itemCount, addItem, itemWithPlottable +*/ +QCPAbstractLegendItem *QCPLegend::item(int index) const +{ + return qobject_cast(elementAt(index)); +} + +/*! + Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns 0. + + \see hasItemWithPlottable +*/ +QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + for (int i=0; i(item(i))) + { + if (pli->plottable() == plottable) + return pli; + } + } + return 0; +} + +/*! + Returns the number of items currently in the legend. + + Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid + base class which allows creating empty cells), they are included in the returned count. + + \see item +*/ +int QCPLegend::itemCount() const +{ + return elementCount(); +} + +/*! + Returns whether the legend contains \a item. + + \see hasItemWithPlottable +*/ +bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const +{ + for (int i=0; iitem(i)) + return true; + } + return false; +} + +/*! + Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). + If such an item isn't in the legend, returns false. + + \see itemWithPlottable +*/ +bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const +{ + return itemWithPlottable(plottable); +} + +/*! + Adds \a item to the legend, if it's not present already. The element is arranged according to the + current fill order (\ref setFillOrder) and wrapping (\ref setWrap). + + Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. + + The legend takes ownership of the item. + + \see removeItem, item, hasItem +*/ +bool QCPLegend::addItem(QCPAbstractLegendItem *item) +{ + return addElement(item); +} + +/*! \overload + + Removes the item with the specified \a index from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes + elements derived from \ref QCPAbstractLegendItem. + + \see itemCount, clearItems +*/ +bool QCPLegend::removeItem(int index) +{ + if (QCPAbstractLegendItem *ali = item(index)) + { + bool success = remove(ali); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; + } else + return false; +} + +/*! \overload + + Removes \a item from the legend and deletes it. + + After successful removal, the legend is reordered according to the current fill order (\ref + setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item + was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. + + Returns true, if successful. + + \see clearItems +*/ +bool QCPLegend::removeItem(QCPAbstractLegendItem *item) +{ + bool success = remove(item); + if (success) + setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + return success; +} + +/*! + Removes all items from the legend. +*/ +void QCPLegend::clearItems() +{ + for (int i=itemCount()-1; i>=0; --i) + removeItem(i); +} + +/*! + Returns the legend items that are currently selected. If no items are selected, + the list is empty. + + \see QCPAbstractLegendItem::setSelected, setSelectable +*/ +QList QCPLegend::selectedItems() const +{ + QList result; + for (int i=0; iselected()) + result.append(ali); + } + } + return result; +} + +/*! \internal + + A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter + before drawing main legend elements. + + This is the antialiasing state the painter passed to the \ref draw method is in by default. + + This function takes into account the local setting of the antialiasing flag as well as the + overrides set with \ref QCustomPlot::setAntialiasedElements and \ref + QCustomPlot::setNotAntialiasedElements. + + \seebaseclassmethod + + \see setAntialiased +*/ +void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); +} + +/*! \internal + + Returns the pen used to paint the border of the legend, taking into account the selection state + of the legend box. +*/ +QPen QCPLegend::getBorderPen() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; +} + +/*! \internal + + Returns the brush used to paint the background of the legend, taking into account the selection + state of the legend box. +*/ +QBrush QCPLegend::getBrush() const +{ + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; +} + +/*! \internal + + Draws the legend box with the provided \a painter. The individual legend items are layerables + themselves, thus are drawn independently. +*/ +void QCPLegend::draw(QCPPainter *painter) +{ + // draw background rect: + painter->setBrush(getBrush()); + painter->setPen(getBorderPen()); + painter->drawRect(mOuterRect); +} + +/* inherits documentation from base class */ +double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mParentPlot) return -1; + if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) + return -1; + + if (mOuterRect.contains(pos.toPoint())) + { + if (details) details->setValue(spLegendBox); + return mParentPlot->selectionTolerance()*0.99; + } + return -1; +} + +/* inherits documentation from base class */ +void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + mSelectedParts = selectedParts(); // in case item selection has changed + if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPLegend::deselectEvent(bool *selectionStateChanged) +{ + mSelectedParts = selectedParts(); // in case item selection has changed + if (mSelectableParts.testFlag(spLegendBox)) + { + SelectableParts selBefore = mSelectedParts; + setSelectedParts(selectedParts() & ~spLegendBox); + if (selectionStateChanged) + *selectionStateChanged = mSelectedParts != selBefore; + } +} + +/* inherits documentation from base class */ +QCP::Interaction QCPLegend::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +QCP::Interaction QCPAbstractLegendItem::selectionCategory() const +{ + return QCP::iSelectLegend; +} + +/* inherits documentation from base class */ +void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) +{ + if (parentPlot && !parentPlot->legend) + parentPlot->legend = this; +} +/* end of 'src/layoutelements/layoutelement-legend.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPTextElement +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPTextElement + \brief A layout element displaying a text + + The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, + \ref setTextColor, and \ref setTextFlags. + + A text element can be added as follows: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation +*/ + +/* start documentation of signals */ + +/*! \fn void QCPTextElement::selectionChanged(bool selected) + + This signal is emitted when the selection state has changed to \a selected, either by user + interaction or by a direct call to \ref setSelected. + + \see setSelected, setSelectable +*/ + +/*! \fn void QCPTextElement::clicked(QMouseEvent *event) + + This signal is emitted when the text element is clicked. + + \see doubleClicked, selectTest +*/ + +/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) + + This signal is emitted when the text element is double clicked. + + \see clicked, selectTest +*/ + +/* end documentation of signals */ + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref + setText). +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mText(), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mSelectedFont = parentPlot->font(); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + if (parentPlot) + { + mFont = parentPlot->font(); + mFont.setPointSizeF(pointSize); + mSelectedFont = parentPlot->font(); + mSelectedFont.setPointSizeF(pointSize); + } + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with \a pointSize and the specified \a fontFamily. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(QFont(fontFamily, pointSize)), + mTextColor(Qt::black), + mSelectedFont(QFont(fontFamily, pointSize)), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! \overload + + Creates a new QCPTextElement instance and sets default values. + + The initial text is set to \a text with the specified \a font. +*/ +QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : + QCPLayoutElement(parentPlot), + mText(text), + mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), + mFont(font), + mTextColor(Qt::black), + mSelectedFont(font), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) +{ + setMargins(QMargins(2, 2, 2, 2)); +} + +/*! + Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". + + \see setFont, setTextColor, setTextFlags +*/ +void QCPTextElement::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of + \c Qt::AlignmentFlag and \c Qt::TextFlag enums. + + Possible enums are: + - Qt::AlignLeft + - Qt::AlignRight + - Qt::AlignHCenter + - Qt::AlignJustify + - Qt::AlignTop + - Qt::AlignBottom + - Qt::AlignVCenter + - Qt::AlignCenter + - Qt::TextDontClip + - Qt::TextSingleLine + - Qt::TextExpandTabs + - Qt::TextShowMnemonic + - Qt::TextWordWrap + - Qt::TextIncludeTrailingSpaces +*/ +void QCPTextElement::setTextFlags(int flags) +{ + mTextFlags = flags; +} + +/*! + Sets the \a font of the text. + + \see setTextColor, setSelectedFont +*/ +void QCPTextElement::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the \a color of the text. + + \see setFont, setSelectedTextColor +*/ +void QCPTextElement::setTextColor(const QColor &color) +{ + mTextColor = color; +} + +/*! + Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). + + \see setFont +*/ +void QCPTextElement::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). + + \see setTextColor +*/ +void QCPTextElement::setSelectedTextColor(const QColor &color) +{ + mSelectedTextColor = color; +} + +/*! + Sets whether the user may select this text element. + + Note that even when \a selectable is set to false, the selection state may be changed + programmatically via \ref setSelected. +*/ +void QCPTextElement::setSelectable(bool selectable) +{ + if (mSelectable != selectable) + { + mSelectable = selectable; + Q_EMIT selectableChanged(mSelectable); + } +} + +/*! + Sets the selection state of this text element to \a selected. If the selection has changed, \ref + selectionChanged is emitted. + + Note that this function can change the selection state independently of the current \ref + setSelectable state. +*/ +void QCPTextElement::setSelected(bool selected) +{ + if (mSelected != selected) + { + mSelected = selected; + Q_EMIT selectionChanged(mSelected); + } +} + +/* inherits documentation from base class */ +void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); +} + +/* inherits documentation from base class */ +void QCPTextElement::draw(QCPPainter *painter) +{ + painter->setFont(mainFont()); + painter->setPen(QPen(mainTextColor())); + painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); +} + +/* inherits documentation from base class */ +QSize QCPTextElement::minimumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.rwidth() += mMargins.left()+mMargins.right(); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +QSize QCPTextElement::maximumOuterSizeHint() const +{ + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); + result.setWidth(QWIDGETSIZE_MAX); + result.rheight() += mMargins.top()+mMargins.bottom(); + return result; +} + +/* inherits documentation from base class */ +void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +{ + Q_UNUSED(event) + Q_UNUSED(details) + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(additive ? !mSelected : true); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/* inherits documentation from base class */ +void QCPTextElement::deselectEvent(bool *selectionStateChanged) +{ + if (mSelectable) + { + bool selBefore = mSelected; + setSelected(false); + if (selectionStateChanged) + *selectionStateChanged = mSelected != selBefore; + } +} + +/*! + Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is + within the bounding box of the text element's text. Note that this bounding box is updated in the + draw call. + + If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text + element is not selectable (\ref setSelectable), returns -1. + + \seebaseclassmethod +*/ +double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + if (mTextBoundingRect.contains(pos.toPoint())) + return mParentPlot->selectionTolerance()*0.99; + else + return -1; +} + +/*! + Accepts the mouse event in order to emit the according click signal in the \ref + mouseReleaseEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + event->accept(); +} + +/*! + Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref + mousePressEvent. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) + Q_EMIT clicked(event); +} + +/*! + Emits the \ref doubleClicked signal. + + \seebaseclassmethod +*/ +void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +{ + Q_UNUSED(details) + Q_EMIT doubleClicked(event); +} + +/*! \internal + + Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to + true, else mFont is returned. +*/ +QFont QCPTextElement::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to + true, else mTextColor is returned. +*/ +QColor QCPTextElement::mainTextColor() const +{ + return mSelected ? mSelectedTextColor : mTextColor; +} +/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ + + +/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScale +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScale + \brief A color scale for use with color coding data such as QCPColorMap + + This layout element can be placed on the plot to correlate a color gradient with data values. It + is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". + + \image html QCPColorScale.png + + The color scale can be either horizontal or vertical, as shown in the image above. The + orientation and the side where the numbers appear is controlled with \ref setType. + + Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are + connected, they share their gradient, data range and data scale type (\ref setGradient, \ref + setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color + scale, to make them all synchronize these properties. + + To have finer control over the number display and axis behaviour, you can directly access the + \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if + you want to change the number of automatically generated ticks, call + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount + + Placing a color scale next to the main axis rect works like with any other layout element: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation + In this case we have placed it to the right of the default axis rect, so it wasn't necessary to + call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color + scale can be set with \ref setLabel. + + For optimum appearance (like in the image above), it may be desirable to line up the axis rect and + the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup + + Color scales are initialized with a non-zero minimum top and bottom margin (\ref + setMinimumMargins), because vertical color scales are most common and the minimum top/bottom + margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a + horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you + might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). +*/ + +/* start documentation of inline functions */ + +/*! \fn QCPAxis *QCPColorScale::axis() const + + Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the + appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its + interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref + setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref + QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on + the QCPColorScale or on its QCPAxis. + + If the type of the color scale is changed with \ref setType, the axis returned by this method + will change, too, to either the left, right, bottom or top axis, depending on which type was set. +*/ + +/* end documentation of signals */ +/* start documentation of signals */ + +/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); + + This signal is emitted when the data range changes. + + \see setDataRange +*/ + +/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); + + This signal is emitted when the data scale type changes. + + \see setDataScaleType +*/ + +/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); + + This signal is emitted when the gradient changes. + + \see setGradient +*/ + +/* end documentation of signals */ + +/*! + Constructs a new QCPColorScale. +*/ +QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight + mDataScaleType(QCPAxis::stLinear), + mBarWidth(20), + mAxisRect(new QCPColorScaleAxisRectPrivate(this)) +{ + setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) + setType(QCPAxis::atRight); + setDataRange(QCPRange(0, 6)); +} + +QCPColorScale::~QCPColorScale() +{ + delete mAxisRect; +} + +/* undocumented getter */ +QString QCPColorScale::label() const +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return QString(); + } + + return mColorAxis.data()->label(); +} + +/* undocumented getter */ +bool QCPColorScale::rangeDrag() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/* undocumented getter */ +bool QCPColorScale::rangeZoom() const +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return false; + } + + return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && + mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); +} + +/*! + Sets at which side of the color scale the axis is placed, and thus also its orientation. + + Note that after setting \a type to a different value, the axis returned by \ref axis() will + be a different one. The new axis will adopt the following properties from the previous axis: The + range, scale type, label and ticker (the latter will be shared and not copied). +*/ +void QCPColorScale::setType(QCPAxis::AxisType type) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + if (mType != type) + { + mType = type; + QCPRange rangeTransfer(0, 6); + QString labelTransfer; + QSharedPointer tickerTransfer; + // transfer/revert some settings on old axis if it exists: + bool doTransfer = (bool)mColorAxis; + if (doTransfer) + { + rangeTransfer = mColorAxis.data()->range(); + labelTransfer = mColorAxis.data()->label(); + tickerTransfer = mColorAxis.data()->ticker(); + mColorAxis.data()->setLabel(QString()); + disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; + Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) + { + mAxisRect.data()->axis(atype)->setTicks(atype == mType); + mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); + } + // set new mColorAxis pointer: + mColorAxis = mAxisRect.data()->axis(mType); + // transfer settings to new axis: + if (doTransfer) + { + mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) + mColorAxis.data()->setLabel(labelTransfer); + mColorAxis.data()->setTicker(tickerTransfer); + } + connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); + } +} + +/*! + Sets the range spanned by the color gradient and that is shown by the axis in the color scale. + + It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its range with \ref + QCPAxis::setRange. + + \see setDataScaleType, setGradient, rescaleDataRange +*/ +void QCPColorScale::setDataRange(const QCPRange &dataRange) +{ + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + mDataRange = dataRange; + if (mColorAxis) + mColorAxis.data()->setRange(mDataRange); + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets the scale type of the color scale, i.e. whether values are linearly associated with colors + or logarithmically. + + It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is + also equivalent to directly accessing the \ref axis and setting its scale type with \ref + QCPAxis::setScaleType. + + \see setDataRange, setGradient +*/ +void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + if (mColorAxis) + mColorAxis.data()->setScaleType(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + Q_EMIT dataScaleTypeChanged(mDataScaleType); + } +} + +/*! + Sets the color gradient that will be used to represent data values. + + It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. + + \see setDataRange, setDataScaleType +*/ +void QCPColorScale::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + if (mAxisRect) + mAxisRect.data()->mGradientImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on + the internal \ref axis. +*/ +void QCPColorScale::setLabel(const QString &str) +{ + if (!mColorAxis) + { + qDebug() << Q_FUNC_INFO << "internal color axis undefined"; + return; + } + + mColorAxis.data()->setLabel(str); +} + +/*! + Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed + will have. +*/ +void QCPColorScale::setBarWidth(int width) +{ + mBarWidth = width; +} + +/*! + Sets whether the user can drag the data range (\ref setDataRange). + + Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeDrag(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeDrag(0); +} + +/*! + Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. + + Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref + QCustomPlot::setInteractions) to allow range dragging. +*/ +void QCPColorScale::setRangeZoom(bool enabled) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + if (enabled) + mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + else + mAxisRect.data()->setRangeZoom(0); +} + +/*! + Returns a list of all the color maps associated with this color scale. +*/ +QList QCPColorScale::colorMaps() const +{ + QList result; + for (int i=0; iplottableCount(); ++i) + { + if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) + if (cm->colorScale() == this) + result.append(cm); + } + return result; +} + +/*! + Changes the data range such that all color maps associated with this color scale are fully mapped + to the gradient in the data dimension. + + \see setDataRange +*/ +void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) +{ + QList maps = colorMaps(); + QCPRange newRange; + bool haveRange = false; + QCP::SignDomain sign = QCP::sdBoth; + if (mDataScaleType == QCPAxis::stLogarithmic) + sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + for (int i=0; irealVisibility() && onlyVisibleMaps) + continue; + QCPRange mapRange; + if (maps.at(i)->colorScale() == this) + { + bool currentFoundRange = true; + mapRange = maps.at(i)->data()->dataBounds(); + if (sign == QCP::sdPositive) + { + if (mapRange.lower <= 0 && mapRange.upper > 0) + mapRange.lower = mapRange.upper*1e-3; + else if (mapRange.lower <= 0 && mapRange.upper <= 0) + currentFoundRange = false; + } else if (sign == QCP::sdNegative) + { + if (mapRange.upper >= 0 && mapRange.lower < 0) + mapRange.upper = mapRange.lower*1e-3; + else if (mapRange.upper >= 0 && mapRange.lower >= 0) + currentFoundRange = false; + } + if (currentFoundRange) + { + if (!haveRange) + newRange = mapRange; + else + newRange.expand(mapRange); + haveRange = true; + } + } + } + if (haveRange) + { + if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data + { + double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if (mDataScaleType == QCPAxis::stLinear) + { + newRange.lower = center-mDataRange.size()/2.0; + newRange.upper = center+mDataRange.size()/2.0; + } else // mScaleType == stLogarithmic + { + newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); + newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); + } + } + setDataRange(newRange); + } +} + +/* inherits documentation from base class */ +void QCPColorScale::update(UpdatePhase phase) +{ + QCPLayoutElement::update(phase); + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + + mAxisRect.data()->update(phase); + + switch (phase) + { + case upMargins: + { + if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) + { + setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); + } else + { + setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); + setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); + } + break; + } + case upLayout: + { + mAxisRect.data()->setOuterRect(rect()); + break; + } + default: break; + } +} + +/* inherits documentation from base class */ +void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const +{ + painter->setAntialiasing(false); +} + +/* inherits documentation from base class */ +void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mousePressEvent(event, details); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseMoveEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->mouseReleaseEvent(event, startPos); +} + +/* inherits documentation from base class */ +void QCPColorScale::wheelEvent(QWheelEvent *event) +{ + if (!mAxisRect) + { + qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; + return; + } + mAxisRect.data()->wheelEvent(event); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorScaleAxisRectPrivate +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorScaleAxisRectPrivate + + \internal + \brief An axis rect subclass for use in a QCPColorScale + + This is a private class and not part of the public QCustomPlot interface. + + It provides the axis rect functionality for the QCPColorScale class. +*/ + + +/*! + Creates a new instance, as a child of \a parentColorScale. +*/ +QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : + QCPAxisRect(parentColorScale->parentPlot(), true), + mParentColorScale(parentColorScale), + mGradientImageInvalidated(true) +{ + setParentLayerable(parentColorScale); + setMinimumMargins(QMargins(0, 0, 0, 0)); + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + axis(type)->setVisible(true); + axis(type)->grid()->setVisible(false); + axis(type)->setPadding(0); + connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); + connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); + } + + connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); + connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); + connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); + + // make layer transfers of color scale transfer to axis rect and axes + // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); +} + +/*! \internal + + Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws + it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. + + \seebaseclassmethod +*/ +void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) +{ + if (mGradientImageInvalidated) + updateGradientImage(); + + bool mirrorHorz = false; + bool mirrorVert = false; + if (mParentColorScale->mColorAxis) + { + mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); + mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); + } + + painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); + QCPAxisRect::draw(painter); +} + +/*! \internal + + Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to + generate a gradient image. This gradient image will be used in the \ref draw method. +*/ +void QCPColorScaleAxisRectPrivate::updateGradientImage() +{ + if (rect().isEmpty()) + return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + int n = mParentColorScale->mGradient.levelCount(); + int w, h; + QVector data(n); + for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) + { + w = n; + h = rect().height(); + mGradientImage = QImage(w, h, format); + QVector pixels; + for (int y=0; y(mGradientImage.scanLine(y))); + mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); + for (int y=1; y(mGradientImage.scanLine(y)); + const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); + for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectedParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); + else + axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); + } + } +} + +/*! \internal + + This slot is connected to the selectableChanged signals of the four axes in the constructor. It + synchronizes the selectability of the axes. +*/ +void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) +{ + // synchronize axis base selectability: + QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; + Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) + { + if (QCPAxis *senderAxis = qobject_cast(sender())) + if (senderAxis->axisType() == type) + continue; + + if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + { + if (selectableParts.testFlag(QCPAxis::spAxis)) + axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); + else + axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); + } + } +} +/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ + + +/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraphData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraphData + \brief Holds the data of one single data point for QCPGraph. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPGraphDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPGraphData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPGraphData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPGraphData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and value set to zero. +*/ +QCPGraphData::QCPGraphData() : + key(0), + value(0) +{ +} + +/*! + Constructs a data point with the specified \a key and \a value. +*/ +QCPGraphData::QCPGraphData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPGraph +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPGraph + \brief A plottable representing a graph in a plot. + + \image html QCPGraph.png + + Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be + accessed via QCustomPlot::graph. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPGraphDataContainer. + + Graphs are used to display single-valued data. Single-valued means that there should only be one + data point per unique key coordinate. In other words, the graph can't have \a loops. If you do + want to plot non-single-valued curves, rather use the QCPCurve plottable. + + Gaps in the graph line can be created by adding data points with NaN as value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpgraph-appearance Changing the appearance + + The appearance of the graph is mainly determined by the line style, scatter style, brush and pen + of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). + + \subsection filling Filling under or between graphs + + QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to + the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, + just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. + + By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill + between this graph and another one, call \ref setChannelFillGraph with the other graph as + parameter. + + \see QCustomPlot::addGraph, QCustomPlot::graph +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPGraph::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually + but use QCustomPlot::removePlottable() instead. + + To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. +*/ +QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // special handling for QCPGraphs to maintain the simple graph interface: + mParentPlot->registerGraph(this); + + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setLineStyle(lsLine); + setScatterSkip(0); + setChannelFillGraph(0); + setAdaptiveSampling(true); +} + +QCPGraph::~QCPGraph() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. + Modifying the data in the container will then affect all graphs that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the graph's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 + + \see addData +*/ +void QCPGraph::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to + \ref lsNone and \ref setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPGraph::setLineStyle(LineStyle ls) +{ + mLineStyle = ls; +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points + are drawn (e.g. for line-only-plots with appropriate line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPGraph::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPGraph::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets the target graph for filling the area between this graph and \a targetGraph with the current + brush (\ref setBrush). + + When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To + disable any filling, set the brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) +{ + // prevent setting channel target to this graph itself: + if (targetGraph == this) + { + qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; + mChannelFillGraph = 0; + return; + } + // prevent setting channel target to a graph not in the plot: + if (targetGraph && targetGraph->mParentPlot != mParentPlot) + { + qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; + mChannelFillGraph = 0; + return; + } + + mChannelFillGraph = targetGraph; +} + +/*! + Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive + sampling technique can drastically improve the replot performance for graphs with a larger number + of points (e.g. above 10,000), without notably changing the appearance of the graph. + + By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive + sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no + disadvantage in almost all cases. + + \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" + + As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are + reproduced reliably, as well as the overall shape of the data set. The replot time reduces + dramatically though. This allows QCustomPlot to display large amounts of data in realtime. + + \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" + + Care must be taken when using high-density scatter plots in combination with adaptive sampling. + The adaptive sampling algorithm treats scatter plots more carefully than line plots which still + gives a significant reduction of replot times, but not quite as much as for line plots. This is + because scatter plots inherently need more data points to be preserved in order to still resemble + the original, non-adaptive-sampling plot. As shown above, the results still aren't quite + identical, as banding occurs for the outer data points. This is in fact intentional, such that + the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, + depends on the point density, i.e. the number of points in the plot. + + For some situations with scatter plots it might thus be desirable to manually turn adaptive + sampling off. For example, when saving the plot to disk. This can be achieved by setting \a + enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled + back to true afterwards. +*/ +void QCPGraph::setAdaptiveSampling(bool enabled) +{ + mAdaptiveSampling = enabled; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPGraph::addData(double key, double value) +{ + mDataContainer->add(QCPGraphData(key, value)); +} + +/* inherits documentation from base class */ +double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPGraph::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + if (mLineStyle == lsNone && mScatterStyle.isNone()) return; + + QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + // get line pixel points appropriate to line style: + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) + getLines(&lines, lineDataRange); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPGraphDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } +#endif + + // draw fill of graph: + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + drawFill(painter, &lines); + + // draw line: + if (mLineStyle != lsNone) + { + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + painter->setBrush(Qt::NoBrush); + if (mLineStyle == lsImpulse) + drawImpulsePlot(painter, lines); + else + drawLinePlot(painter, lines); // also step plots can be drawn as a line plot + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i)); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches + out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. + according to the line style of the graph. + + \a lines will be filled with points in pixel coordinates, that can be drawn with the according + draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines + aren't necessarily the original data points. For example, step line styles require additional + points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a + lines vector will be empty. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. + + \see getScatters +*/ +void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const +{ + if (!lines) return; + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + lines->clear(); + return; + } + + QVector lineData; + if (mLineStyle != lsNone) + getOptimizedLineData(&lineData, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) + std::reverse(lineData.begin(), lineData.end()); + + switch (mLineStyle) + { + case lsNone: lines->clear(); break; + case lsLine: *lines = dataToLines(lineData); break; + case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; + case lsStepRight: *lines = dataToStepRightLines(lineData); break; + case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; + case lsImpulse: *lines = dataToImpulseLines(lineData); break; + } +} + +/*! \internal + + This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then + converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be + passed to \ref drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. In this function, the specified range may exceed the total data bounds without harm: + a correspondingly trimmed data range will be used. This takes the burden off the user of this + function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref + getDataSegments. +*/ +void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const +{ + if (!scatters) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } + + QCPGraphDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, dataRange); + if (begin == end) + { + scatters->clear(); + return; + } + + QVector data; + getOptimizedScatterData(&data, begin, end); + + if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) + std::reverse(data.begin(), data.end()); + + scatters->resize(data.size()); + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } + } else + { + for (int i=0; icoordToPixel(data.at(i).key)); + (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + } +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsLine. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).value)); + result[i].setY(keyAxis->coordToPixel(data.at(i).key)); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key)); + result[i].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepLeft. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepLeftLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(lastValue); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + result[i*2+1].setX(key); + result[i*2+1].setY(lastValue); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepRight. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepRightLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(value); + result[i*2+0].setY(lastKey); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(value); + result[i*2+1].setY(lastKey); + } + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel(data.at(i).value); + result[i*2+0].setX(lastKey); + result[i*2+0].setY(value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+1].setX(lastKey); + result[i*2+1].setY(value); + } + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsStepCenter. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot +*/ +QVector QCPGraph::dataToStepCenterLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // calculate steps from data and transform to pixel coordinates: + if (keyAxis->orientation() == Qt::Vertical) + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastValue); + result[0].setY(lastKey); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(lastValue); + result[i*2-1].setY(key); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(lastValue); + result[i*2+0].setY(key); + } + result[data.size()*2-1].setX(lastValue); + result[data.size()*2-1].setY(lastKey); + } else // key axis is horizontal + { + double lastKey = keyAxis->coordToPixel(data.first().key); + double lastValue = valueAxis->coordToPixel(data.first().value); + result[0].setX(lastKey); + result[0].setY(lastValue); + for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; + result[i*2-1].setX(key); + result[i*2-1].setY(lastValue); + lastValue = valueAxis->coordToPixel(data.at(i).value); + lastKey = keyAxis->coordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(lastValue); + } + result[data.size()*2-1].setX(lastKey); + result[data.size()*2-1].setY(lastValue); + } + return result; +} + +/*! \internal + + Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel + coordinate points which are suitable for drawing the line style \ref lsImpulse. + + The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a + getLines if the line style is set accordingly. + + \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot +*/ +QVector QCPGraph::dataToImpulseLines(const QVector &data) const +{ + QVector result; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + + result.resize(data.size()*2); + + // transform data points to pixels: + if (keyAxis->orientation() == Qt::Vertical) + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(valueAxis->coordToPixel(0)); + result[i*2+0].setY(key); + result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); + result[i*2+1].setY(key); + } + } else // key axis is horizontal + { + for (int i=0; icoordToPixel(data.at(i).key); + result[i*2+0].setX(key); + result[i*2+0].setY(valueAxis->coordToPixel(0)); + result[i*2+1].setX(key); + result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); + } + } + return result; +} + +/*! \internal + + Draws the fill of the graph using the specified \a painter, with the currently set brush. + + Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref + getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. + + In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), + this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to + operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN + segments of the two involved graphs, before passing the overlapping pairs to \ref + getChannelFillPolygon. + + Pass the points of this graph's line as \a lines, in pixel coordinates. + + \see drawLinePlot, drawImpulsePlot, drawScatterPlot +*/ +void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const +{ + if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot + if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; + + applyFillAntialiasingHint(painter); + QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); + if (!mChannelFillGraph) + { + // draw base fill under graph, fill goes all the way to the zero-value-line: + for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); + } else + { + // draw fill between this graph and mChannelFillGraph: + QVector otherLines; + mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); + if (!otherLines.isEmpty()) + { + QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); + QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); + for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); + } + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawLinePlot, drawImpulsePlot +*/ +void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const +{ + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in + pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines + from the regular graph data points. + + \see drawLinePlot, drawScatterPlot +*/ +void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + QPen oldPen = painter->pen(); + QPen newPen = painter->pen(); + newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line + painter->setPen(newPen); + painter->drawLines(lines); + painter->setPen(oldPen); + } +} + +/*! \internal + + Returns via \a lineData the data points that need to be visualized for this graph when plotting + graph lines, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getLines to retrieve the basic working set of data. + + \see getOptimizedScatterData +*/ +void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const +{ + if (!lineData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (begin == end) return; + + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + QCPGraphDataContainer::const_iterator it = begin; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double lastIntervalEndKey = currentIntervalStartKey; + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary + { + if (it->value < minValue) + minValue = it->value; + else if (it->value > maxValue) + maxValue = it->value; + ++intervalDataCount; + } else // new pixel interval started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + lastIntervalEndKey = (it-1)->key; + minValue = it->value; + maxValue = it->value; + currentIntervalFirstPoint = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + ++it; + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + { + if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); + lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); + } else + lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + lineData->resize(dataCount); + std::copy(begin, end, lineData->begin()); + } +} + +/*! \internal + + Returns via \a scatterData the data points that need to be visualized for this graph when + plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref + setAdaptiveSampling is enabled, local point densities. The considered data can be restricted + further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref + getDataSegments). + + This method is used by \ref getScatters to retrieve the basic working set of data. + + \see getOptimizedLineData +*/ +void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const +{ + if (!scatterData) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int beginIndex = begin-mDataContainer->constBegin(); + int endIndex = end-mDataContainer->constBegin(); + while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++beginIndex; + ++begin; + } + if (begin == end) return; + int dataCount = end-begin; + int maxCount = std::numeric_limits::max(); + if (mAdaptiveSampling) + { + int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + maxCount = 2*keyPixelSpan+2; + } + + if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + { + double valueMaxRange = valueAxis->range().upper; + double valueMinRange = valueAxis->range().lower; + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + double minValue = it->value; + double maxValue = it->value; + QCPGraphDataContainer::const_iterator minValueIt = it; + QCPGraphDataContainer::const_iterator maxValueIt = it; + QCPGraphDataContainer::const_iterator currentIntervalStart = it; + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int intervalDataCount = 1; + // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + // main loop over data points: + while (it != end) + { + if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary + { + if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) + { + minValue = it->value; + minValueIt = it; + } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) + { + maxValue = it->value; + maxValueIt = it; + } + ++intervalDataCount; + } else // new pixel started + { + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else + intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + minValue = it->value; + maxValue = it->value; + currentIntervalStart = it; + currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); + if (keyEpsilonVariable) + keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + intervalDataCount = 1; + } + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + // handle last interval: + if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + { + // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): + double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); + int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; + int intervalItIndex = intervalIt-mDataContainer->constBegin(); + int c = 0; + while (intervalIt != it) + { + if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) + scatterData->append(*intervalIt); + ++c; + if (!doScatterSkip) + ++intervalIt; + else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: + { + intervalItIndex += scatterModulo; + if (intervalItIndex < itIndex) + intervalIt += scatterModulo; + else + { + intervalIt = it; + intervalItIndex = itIndex; + } + } + } + } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) + scatterData->append(*currentIntervalStart); + + } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + { + QCPGraphDataContainer::const_iterator it = begin; + int itIndex = beginIndex; + scatterData->reserve(dataCount); + while (it != end) + { + scatterData->append(*it); + // advance to next data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + This method takes into account that the drawing of data lines at the axis rect border always + requires the points just outside the visible axis range. So \a begin and \a end may actually + indicate a range that contains one additional data point to the left and right of the visible + axis range. +*/ +void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + if (rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + } else + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + // get visible data range: + begin = mDataContainer->findBegin(keyAxis->range().lower); + end = mDataContainer->findEnd(keyAxis->range().upper); + // limit lower/upperEnd to rangeRestriction: + mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything + } +} + +/*! \internal + + This method goes through the passed points in \a lineData and returns a list of the segments + which don't contain NaN data points. + + \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check + for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c + Qt::Vertical, the \a x member is checked. + + \see getOverlappingSegments, drawFill +*/ +QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const +{ + QVector result; + const int n = lineData->size(); + + QCPDataRange currentSegment(-1, -1); + int i = 0; + + if (keyOrientation == Qt::Horizontal) + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } else // keyOrientation == Qt::Vertical + { + while (i < n) + { + while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point + ++i; + if (i == n) + break; + currentSegment.setBegin(i++); + while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data + ++i; + currentSegment.setEnd(i++); + result.append(currentSegment); + } + } + return result; +} + +/*! \internal + + This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and + \a otherSegments, and their associated point data \a thisData and \a otherData. + + It returns all pairs of segments (the first from \a thisSegments, the second from \a + otherSegments), which overlap in plot coordinates. + + This method is useful in the case of a channel fill between two graphs, when only those non-NaN + segments which actually overlap in their key coordinate shall be considered for drawing a channel + fill polygon. + + It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and + that the segments don't overlap themselves. The same is assumed for the segments in \a + otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. + + \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon +*/ +QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const +{ + QVector > result; + if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) + return result; + + int thisIndex = 0; + int otherIndex = 0; + const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; + while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) + { + if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++thisIndex; + continue; + } + if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + { + ++otherIndex; + continue; + } + double thisLower, thisUpper, otherLower, otherUpper; + if (!verticalKey) + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); + } else + { + thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); + thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); + otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); + otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); + } + + int bPrecedence; + if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) + result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); + + if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment + ++otherIndex; + else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment + ++thisIndex; + } + + return result; +} + +/*! \internal + + Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) + have overlap. + + The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the + \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher + coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if + both segment's upper bounds are identical, 0 is returned as \a bPrecedence. + + It is assumed that the lower bounds always have smaller or equal values than the upper bounds. + + \see getOverlappingSegments +*/ +bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const +{ + bPrecedence = 0; + if (aLower > bUpper) + { + bPrecedence = -1; + return false; + } else if (bLower > aUpper) + { + bPrecedence = 1; + return false; + } else + { + if (aUpper > bUpper) + bPrecedence = -1; + else if (aUpper < bUpper) + bPrecedence = 1; + + return true; + } +} + +/*! \internal + + Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. + The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates + is in positive or negative infinity. So this case is handled separately by just closing the fill + polygon on the axis which lies in the direction towards the zero value. + + \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether + the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or + y value of the returned point, respectively. +*/ +QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + QPointF result; + if (valueAxis->scaleType() == QCPAxis::stLinear) + { + if (keyAxis->orientation() == Qt::Horizontal) + { + result.setX(matchingDataPoint.x()); + result.setY(valueAxis->coordToPixel(0)); + } else // keyAxis->orientation() == Qt::Vertical + { + result.setX(valueAxis->coordToPixel(0)); + result.setY(matchingDataPoint.y()); + } + } else // valueAxis->mScaleType == QCPAxis::stLogarithmic + { + // In logarithmic scaling we can't just draw to value 0 so we just fill all the way + // to the axis which is in the direction towards 0 + if (keyAxis->orientation() == Qt::Vertical) + { + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setX(keyAxis->axisRect()->right()); + else + result.setX(keyAxis->axisRect()->left()); + result.setY(matchingDataPoint.y()); + } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) + { + result.setX(matchingDataPoint.x()); + if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || + (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis + result.setY(keyAxis->axisRect()->top()); + else + result.setY(keyAxis->axisRect()->bottom()); + } + } + return result; +} + +/*! \internal + + Returns the polygon needed for drawing normal fills between this graph and the key axis. + + Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment + which shall be used for the fill. The collection of \a lineData points described by \a segment + must not contain NaN data points (see \ref getNonNanSegments). + + The returned fill polygon will be closed at the key axis (the zero-value line) for linear value + axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect + side (see \ref getFillBasePoint). + + For increased performance (due to implicit sharing), keep the returned QPolygonF const. + + \see drawFill, getNonNanSegments +*/ +const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const +{ + if (segment.size() < 2) + return QPolygonF(); + QPolygonF result(segment.size()+2); + + result[0] = getFillBasePoint(lineData->at(segment.begin())); + std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); + result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); + + return result; +} + +/*! \internal + + Returns the polygon needed for drawing (partial) channel fills between this graph and the graph + specified by \ref setChannelFillGraph. + + The data points of this graph are passed as pixel coordinates via \a thisData, the data of the + other graph as \a otherData. The returned polygon will be calculated for the specified data + segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a + otherData, respectively. + + The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by + \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap + need to be processed here. + + For increased performance due to implicit sharing, keep the returned QPolygonF const. + + \see drawFill, getOverlappingSegments, getNonNanSegments +*/ +const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const +{ + if (!mChannelFillGraph) + return QPolygonF(); + + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } + if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } + + if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) + return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) + + if (thisData->isEmpty()) return QPolygonF(); + QVector thisSegmentData(thisSegment.size()); + QVector otherSegmentData(otherSegment.size()); + std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); + std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); + // pointers to be able to swap them, depending which data range needs cropping: + QVector *staticData = &thisSegmentData; + QVector *croppedData = &otherSegmentData; + + // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): + if (keyAxis->orientation() == Qt::Horizontal) + { + // x is key + // crop lower bound: + if (staticData->first().x() < croppedData->first().x()) // other one must be cropped + qSwap(staticData, croppedData); + const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) + slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); + else + slope = 0; + (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); + (*croppedData)[0].setX(staticData->first().x()); + + // crop upper bound: + if (staticData->last().x() > croppedData->last().x()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveX(croppedData, staticData->last().x()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + const int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) + slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); + else + slope = 0; + (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); + (*croppedData)[li].setX(staticData->last().x()); + } else // mKeyAxis->orientation() == Qt::Vertical + { + // y is key + // crop lower bound: + if (staticData->first().y() < croppedData->first().y()) // other one must be cropped + qSwap(staticData, croppedData); + int lowBound = findIndexBelowY(croppedData, staticData->first().y()); + if (lowBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(0, lowBound); + // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + double slope; + if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots + slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); + else + slope = 0; + (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); + (*croppedData)[0].setY(staticData->first().y()); + + // crop upper bound: + if (staticData->last().y() > croppedData->last().y()) // other one must be cropped + qSwap(staticData, croppedData); + int highBound = findIndexAboveY(croppedData, staticData->last().y()); + if (highBound == -1) return QPolygonF(); // key ranges have no overlap + croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: + if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + int li = croppedData->size()-1; // last index + if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots + slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); + else + slope = 0; + (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); + (*croppedData)[li].setY(staticData->last().y()); + } + + // return joined: + for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted + thisSegmentData << otherSegmentData.at(i); + return QPolygonF(thisSegmentData); +} + +/*! \internal + + Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveX(const QVector *data, double x) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).x() < x) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is horizontal. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexBelowX(const QVector *data, double x) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).x() > x) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} + +/*! \internal + + Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in + \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key + axis is vertical. + + Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. +*/ +int QCPGraph::findIndexAboveY(const QVector *data, double y) const +{ + for (int i=data->size()-1; i>=0; --i) + { + if (data->at(i).y() < y) + { + if (isize()-1) + return i+1; + else + return data->size()-1; + } + } + return -1; +} + +/*! \internal + + Calculates the minimum distance in pixels the graph's representation has from the given \a + pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if + the graph has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the graph line is also taken into account. + + If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. +*/ +double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + // calculate minimum distances to graph data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // determine which key range comes into question, taking selection tolerance around pos into account: + double posKeyMin, posKeyMax, dummy; + pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); + pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); + if (posKeyMin > posKeyMax) + qSwap(posKeyMin, posKeyMax); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); + QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); + for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + // line displayed, calculate distance to line segments: + QVector lineData; + getLines(&lineData, QCPDataRange(0, dataCount())); + QCPVector2D p(pixelPoint); + const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected + for (int i=0; i *data, double y) const +{ + for (int i=0; isize(); ++i) + { + if (data->at(i).y() > y) + { + if (i>0) + return i-1; + else + return 0; + } + } + return -1; +} +/* end of 'src/plottables/plottable-graph.cpp' */ + + +/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurveData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurveData + \brief Holds the data of one single data point for QCPCurve. + + The stored data is: + \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) + \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) + \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPCurveDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPCurveData::sortKey() const + + Returns the \a t member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). + All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() + + Since the member \a key is the data point key coordinate and the member \a t is the data ordering + parameter, this method returns false. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPCurveData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPCurveData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a curve data point with t, key and value set to zero. +*/ +QCPCurveData::QCPCurveData() : + t(0), + key(0), + value(0) +{ +} + +/*! + Constructs a curve data point with the specified \a t, \a key and \a value. +*/ +QCPCurveData::QCPCurveData(double t, double key, double value) : + t(t), + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPCurve + \brief A plottable representing a parametric curve in a plot. + + \image html QCPCurve.png + + Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, + so their visual representation can have \a loops. This is realized by introducing a third + coordinate \a t, which defines the order of the points described by the other two coordinates \a + x and \a y. + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the curve's data via the \ref data method, which returns a pointer to the + internal \ref QCPCurveDataContainer. + + Gaps in the curve can be created by adding data points with NaN as key and value + (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be + separated. + + \section qcpcurve-appearance Changing the appearance + + The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). + + \section qcpcurve-usage Usage + + Like all data representing objects in QCustomPlot, the QCPCurve is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPCurve::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis) +{ + // modify inherited properties from abstract plottable: + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setScatterStyle(QCPScatterStyle()); + setLineStyle(lsLine); + setScatterSkip(0); +} + +QCPCurve::~QCPCurve() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. + Modifying the data in the container will then affect all curves that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the curve's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 + + \see addData +*/ +void QCPCurve::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a t, \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a t in ascending order, you can + set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(t, keys, values, alreadySorted); +} + + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + \see addData +*/ +void QCPCurve::setData(const QVector &keys, const QVector &values) +{ + mDataContainer->clear(); + addData(keys, values); +} + +/*! + Sets the visual appearance of single data points in the plot. If set to \ref + QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate + line style). + + \see QCPScatterStyle, setLineStyle +*/ +void QCPCurve::setScatterStyle(const QCPScatterStyle &style) +{ + mScatterStyle = style; +} + +/*! + If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of + scatter points are skipped/not drawn after every drawn scatter point. + + This can be used to make the data appear sparser while for example still having a smooth line, + and to improve performance for very high density plots. + + If \a skip is set to 0 (default), all scatter points are drawn. + + \see setScatterStyle +*/ +void QCPCurve::setScatterSkip(int skip) +{ + mScatterSkip = qMax(0, skip); +} + +/*! + Sets how the single data points are connected in the plot or how they are represented visually + apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref + setScatterStyle to the desired scatter style. + + \see setScatterStyle +*/ +void QCPCurve::setLineStyle(QCPCurve::LineStyle style) +{ + mLineStyle = style; +} + +/*! \overload + + Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (t.size() != keys.size() || t.size() != values.size()) + qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); + const int n = qMin(qMin(t.size(), keys.size()), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = t[i]; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + The t parameter of each data point will be set to the integer index of the respective key/value + pair. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(const QVector &keys, const QVector &values) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + double tStart; + if (!mDataContainer->isEmpty()) + tStart = (mDataContainer->constEnd()-1)->t + 1.0; + else + tStart = 0; + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->t = tStart + i; + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a t, \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double t, double key, double value) +{ + mDataContainer->add(QCPCurveData(t, key, value)); +} + +/*! \overload + + Adds the provided data point as \a key and \a value to the current data. + + The t parameter is generated automatically by increments of 1 for each point, starting at the + highest t of previously existing data or 0, if the curve data is empty. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPCurve::addData(double key, double value) +{ + if (!mDataContainer->isEmpty()) + mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); + else + mDataContainer->add(QCPCurveData(0.0, key, value)); +} + +/* inherits documentation from base class */ +double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + return mDataContainer->keyRange(foundRange, inSignDomain); +} + +/* inherits documentation from base class */ +QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPCurve::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + + // allocate line vector: + QVector lines, scatters; + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + + // fill with curve data: + QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width + if (isSelectedSegment && mSelectionDecorator) + finalCurvePen = mSelectionDecorator->pen(); + + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) + getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); + + // check data validity if flag set: + #ifdef QCUSTOMPLOT_CHECK_DATA + for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->t) || + QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + } + #endif + + // draw curve fill: + applyFillAntialiasingHint(painter); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyBrush(painter); + else + painter->setBrush(mBrush); + painter->setPen(Qt::NoPen); + if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) + painter->drawPolygon(QPolygonF(lines)); + + // draw curve line: + if (mLineStyle != lsNone) + { + painter->setPen(finalCurvePen); + painter->setBrush(Qt::NoBrush); + drawCurveLine(painter, lines); + } + + // draw scatters: + QCPScatterStyle finalScatterStyle = mScatterStyle; + if (isSelectedSegment && mSelectionDecorator) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); + if (!finalScatterStyle.isNone()) + { + getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); + drawScatterPlot(painter, scatters, finalScatterStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw fill: + if (mBrush.style() != Qt::NoBrush) + { + applyFillAntialiasingHint(painter); + painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + } + // draw line vertically centered: + if (mLineStyle != lsNone) + { + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + } + // draw scatter symbol: + if (!mScatterStyle.isNone()) + { + applyScattersAntialiasingHint(painter); + // scale scatter pixmap if it's too large to fit in legend icon rect: + if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + { + QCPScatterStyle scaledStyle(mScatterStyle); + scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + scaledStyle.applyTo(painter, mPen); + scaledStyle.drawShape(painter, QRectF(rect).center()); + } else + { + mScatterStyle.applyTo(painter, mPen); + mScatterStyle.drawShape(painter, QRectF(rect).center()); + } + } +} + +/*! \internal + + Draws lines between the points in \a lines, given in pixel coordinates. + + \see drawScatterPlot, getCurveLines +*/ +void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const +{ + if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + { + applyDefaultAntialiasingHint(painter); + drawPolyline(painter, lines); + } +} + +/*! \internal + + Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The + scatters will be drawn with \a painter and have the appearance as specified in \a style. + + \see drawCurveLine, getCurveLines +*/ +void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const +{ + // draw scatter point symbols: + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const +{ + if (!lines) return; + lines->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + // add margins to rect to compensate for stroke width + const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety + const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); + const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); + const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); + const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); + QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); + if (itBegin == itEnd) + return; + QCPCurveDataContainer::const_iterator it = itBegin; + QCPCurveDataContainer::const_iterator prevIt = itEnd-1; + int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); + QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) + while (it != itEnd) + { + const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); + if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R + { + if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal + { + QPointF crossA, crossB; + if (prevRegion == 5) // we're coming from R, so add this point optimized + { + lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); + // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } else if (mayTraverse(prevRegion, currentRegion) && + getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) + { + // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: + QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; + getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); + if (it != itBegin) + { + *lines << beforeTraverseCornerPoints; + lines->append(crossA); + lines->append(crossB); + *lines << afterTraverseCornerPoints; + } else + { + lines->append(crossB); + *lines << afterTraverseCornerPoints; + trailingPoints << beforeTraverseCornerPoints << crossA ; + } + } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) + { + *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + } + } else // segment does end in R, so we add previous point optimized and this point at original position + { + if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end + trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + else + lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); + lines->append(coordsToPixels(it->key, it->value)); + } + } else // region didn't change + { + if (currentRegion == 5) // still in R, keep adding original points + { + lines->append(coordsToPixels(it->key, it->value)); + } else // still outside R, no need to add anything + { + // see how this is not doing anything? That's the main optimization... + } + } + prevIt = it; + prevRegion = currentRegion; + ++it; + } + *lines << trailingPoints; +} + +/*! \internal + + Called by \ref draw to generate points in pixel coordinates which represent the scatters of the + curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly + sparser. + + Scatters that aren't visible in the current axis rect are optimized away. + + \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref + drawScatterPlot. + + \a dataRange specifies the beginning and ending data indices that will be taken into account for + conversion. + + \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel + coordinates generated by this function. This is needed here to calculate an accordingly wider + margin around the axis rect when performing the data point reduction. + + \see draw, drawScatterPlot +*/ +void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const +{ + if (!scatters) return; + scatters->clear(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); + if (begin == end) + return; + const int scatterModulo = mScatterSkip+1; + const bool doScatterSkip = mScatterSkip > 0; + int endIndex = end-mDataContainer->constBegin(); + + QCPRange keyRange = keyAxis->range(); + QCPRange valueRange = valueAxis->range(); + // extend range to include width of scatter symbols: + keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); + keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); + valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); + valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); + + QCPCurveDataContainer::const_iterator it = begin; + int itIndex = begin-mDataContainer->constBegin(); + while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + { + ++itIndex; + ++it; + } + if (keyAxis->orientation() == Qt::Vertical) + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } else + { + while (it != end) + { + if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) + scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); + + // advance iterator to next (non-skipped) data point: + if (!doScatterSkip) + ++it; + else + { + itIndex += scatterModulo; + if (itIndex < endIndex) // make sure we didn't jump over end + it += scatterModulo; + else + { + it = end; + itIndex = endIndex; + } + } + } + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + It returns the region of the given point (\a key, \a value) with respect to a rectangle defined + by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. + + The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a + keyMin to \a keyMax): + + + + + +
147
258
369
+ + With the rectangle being region 5, and the outer regions extending infinitely outwards. In the + curve optimization algorithm, region 5 is considered to be the visible portion of the plot. +*/ +int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + if (key < keyMin) // region 123 + { + if (value > valueMax) + return 1; + else if (value < valueMin) + return 3; + else + return 2; + } else if (key > keyMax) // region 789 + { + if (value > valueMax) + return 7; + else if (value < valueMin) + return 9; + else + return 8; + } else // region 456 + { + if (value > valueMax) + return 4; + else if (value < valueMin) + return 6; + else + return 5; + } +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method is used in case the current segment passes from inside the visible rect (region 5, + see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by + the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). + + It returns the intersection point of the segment with the border of region 5. + + For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or + whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or + leaving it. It is important though that \a otherRegion correctly identifies the other region not + equal to 5. +*/ +QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double otherValuePx = mValueAxis->coordToPixel(otherValue); + const double valuePx = mValueAxis->coordToPixel(value); + const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); + const double keyPx = mKeyAxis->coordToPixel(key); + double intersectKeyPx = keyMinPx; // initial key just a fail-safe + double intersectValuePx = valueMinPx; // initial value just a fail-safe + switch (otherRegion) + { + case 1: // top and left edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 2: // left edge + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 3: // bottom and left edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 4: // top edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 5: + { + break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table + } + case 6: // bottom edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + break; + } + case 7: // top and right edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + case 8: // right edge + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; + } + case 9: // bottom and right edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); + if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + } + break; + } + } + if (mKeyAxis->orientation() == Qt::Horizontal) + return QPointF(intersectKeyPx, intersectValuePx); + else + return QPointF(intersectValuePx, intersectKeyPx); +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + In situations where a single segment skips over multiple regions it might become necessary to add + extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment + doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. + This method provides these points that must be added, assuming the original segment doesn't + start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by + \ref getTraverseCornerPoints.) + + For example, consider a segment which directly goes from region 4 to 2 but originally is far out + to the top left such that it doesn't cross region 5. Naively optimizing these points by + projecting them on the top and left borders of region 5 will create a segment that surely crosses + 5, creating a visual artifact in the plot. This method prevents this by providing extra points at + the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without + traversing 5. +*/ +QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +{ + QVector result; + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMax); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } + case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + else + { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } + break; + } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 2: { result << coordsToPixels(keyMin, valueMin); break; } + case 6: { result << coordsToPixels(keyMin, valueMin); break; } + case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + else + { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } + break; + } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: + { + switch (currentRegion) + { + case 1: { result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 6: + { + switch (currentRegion) + { + case 3: { result << coordsToPixels(keyMin, valueMin); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 4: { result << coordsToPixels(keyMax, valueMax); break; } + case 8: { result << coordsToPixels(keyMax, valueMax); break; } + case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } + case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + else + { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } + break; + } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 7: { result << coordsToPixels(keyMax, valueMax); break; } + case 9: { result << coordsToPixels(keyMax, valueMin); break; } + case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } + case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } + case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 6: { result << coordsToPixels(keyMax, valueMin); break; } + case 8: { result << coordsToPixels(keyMax, valueMin); break; } + case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } + case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } + case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } + case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } + case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + else + { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } + break; + } + } + break; + } + } + return result; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref + getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion + nor \a currentRegion is 5 itself. + + If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the + segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref + getTraverse). +*/ +bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 4: + case 7: + case 2: + case 3: return false; + default: return true; + } + } + case 2: + { + switch (currentRegion) + { + case 1: + case 3: return false; + default: return true; + } + } + case 3: + { + switch (currentRegion) + { + case 1: + case 2: + case 6: + case 9: return false; + default: return true; + } + } + case 4: + { + switch (currentRegion) + { + case 1: + case 7: return false; + default: return true; + } + } + case 5: return false; // should never occur + case 6: + { + switch (currentRegion) + { + case 3: + case 9: return false; + default: return true; + } + } + case 7: + { + switch (currentRegion) + { + case 1: + case 4: + case 8: + case 9: return false; + default: return true; + } + } + case 8: + { + switch (currentRegion) + { + case 7: + case 9: return false; + default: return true; + } + } + case 9: + { + switch (currentRegion) + { + case 3: + case 6: + case 8: + case 7: return false; + default: return true; + } + } + default: return true; + } +} + + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref mayTraverse test has returned true, so there is a chance the + segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible + region 5. + + The return value of this method indicates whether the segment actually traverses region 5 or not. + + If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and + exit points of region 5. They will become the optimized points for that segment. +*/ +bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const +{ + // The intersection point interpolation here is done in pixel coordinates, so we don't need to + // differentiate between different axis scale types. Note that the nomenclature + // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be + // different in pixel coordinates (horz/vert key axes, reversed ranges) + + QList intersections; + const double valueMinPx = mValueAxis->coordToPixel(valueMin); + const double valueMaxPx = mValueAxis->coordToPixel(valueMax); + const double keyMinPx = mKeyAxis->coordToPixel(keyMin); + const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); + const double keyPx = mKeyAxis->coordToPixel(key); + const double valuePx = mValueAxis->coordToPixel(value); + const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); + const double prevValuePx = mValueAxis->coordToPixel(prevValue); + if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); + } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis + { + // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); + } else // line is skewed + { + double gamma; + double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); + // check top of rect: + gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); + // check bottom of rect: + gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; + if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); + const double valuePerKeyPx = 1.0/keyPerValuePx; + // check left of rect: + gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); + // check right of rect: + gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; + if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed + intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); + } + + // handle cases where found points isn't exactly 2: + if (intersections.size() > 2) + { + // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: + double distSqrMax = 0; + QPointF pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = intersections.at(i); + pv2 = intersections.at(k); + distSqrMax = distSqr; + } + } + } + intersections = QList() << pv1 << pv2; + } else if (intersections.size() != 2) + { + // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment + return false; + } + + // possibly re-sort points so optimized point segment has same direction as original segment: + double xDelta = keyPx-prevKeyPx; + double yDelta = valuePx-prevValuePx; + if (mKeyAxis->orientation() != Qt::Horizontal) + qSwap(xDelta, yDelta); + if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction + intersections.move(0, 1); + crossA = intersections.at(0); + crossB = intersections.at(1); + return true; +} + +/*! \internal + + This function is part of the curve optimization algorithm of \ref getCurveLines. + + This method assumes that the \ref getTraverse test has returned true, so the segment definitely + traverses the visible region 5 when going from \a prevRegion to \a currentRegion. + + In certain situations it is not sufficient to merely generate the entry and exit points of the + segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in + addition to traversing region 5, skips another region outside of region 5, which makes it + necessary to add an optimized corner point there (very similar to the job \ref + getOptimizedCornerPoints does for segments that are completely in outside regions and don't + traverse 5). + + As an example, consider a segment going from region 1 to region 6, traversing the lower left + corner of region 5. In this configuration, the segment additionally crosses the border between + region 1 and 2 before entering region 5. This makes it necessary to add an additional point in + the top left corner, before adding the optimized traverse points. So in this case, the output + parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be + empty. + + In some cases, such as when going from region 1 to 9, it may even be necessary to add additional + corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse + return the respective corner points. +*/ +void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const +{ + switch (prevRegion) + { + case 1: + { + switch (currentRegion) + { + case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } + } + break; + } + case 2: + { + switch (currentRegion) + { + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 3: + { + switch (currentRegion) + { + case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 4: + { + switch (currentRegion) + { + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + case 5: { break; } // shouldn't happen because this method only handles full traverses + case 6: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 7: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } + } + break; + } + case 8: + { + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + } + break; + } + case 9: + { + switch (currentRegion) + { + case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } + } + break; + } + } +} + +/*! \internal + + Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a + pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in + \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that + if the curve has a line representation, the returned distance may be smaller than the distance to + the \a closestData point, since the distance to the curve line is also taken into account. + + If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape + is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns + -1.0. +*/ +double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (mDataContainer->isEmpty()) + return -1.0; + if (mLineStyle == lsNone && mScatterStyle.isNone()) + return -1.0; + + if (mDataContainer->size() == 1) + { + QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); + closestData = mDataContainer->constBegin(); + return QCPVector2D(dataPoint-pixelPoint).length(); + } + + // calculate minimum distances to curve data points and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + // iterate over found data points and then choose the one with the shortest distance to pos: + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); + QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); + for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) + { + const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestData = it; + } + } + + // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): + if (mLineStyle != lsNone) + { + QVector lines; + getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width + for (int i=0; i QCPBarsGroup::bars() const + + Returns all bars currently in this group. + + \see bars(int index) +*/ + +/*! \fn int QCPBarsGroup::size() const + + Returns the number of QCPBars plottables that are part of this group. + +*/ + +/*! \fn bool QCPBarsGroup::isEmpty() const + + Returns whether this bars group is empty. + + \see size +*/ + +/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) + + Returns whether the specified \a bars plottable is part of this group. + +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new bars group for the specified QCustomPlot instance. +*/ +QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : + QObject(parentPlot), + mParentPlot(parentPlot), + mSpacingType(stAbsolute), + mSpacing(4) +{ +} + +QCPBarsGroup::~QCPBarsGroup() +{ + clear(); +} + +/*! + Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. + + The actual spacing can then be specified with \ref setSpacing. + + \see setSpacing +*/ +void QCPBarsGroup::setSpacingType(SpacingType spacingType) +{ + mSpacingType = spacingType; +} + +/*! + Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is + defined by the current \ref SpacingType, which can be set with \ref setSpacingType. + + \see setSpacingType +*/ +void QCPBarsGroup::setSpacing(double spacing) +{ + mSpacing = spacing; +} + +/*! + Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars + exists, returns 0. + + \see bars(), size +*/ +QCPBars *QCPBarsGroup::bars(int index) const +{ + if (index >= 0 && index < mBars.size()) + { + return mBars.at(index); + } else + { + qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; + return 0; + } +} + +/*! + Removes all QCPBars plottables from this group. + + \see isEmpty +*/ +void QCPBarsGroup::clear() +{ + Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay + bars->setBarsGroup(0); // removes itself via removeBars +} + +/*! + Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref + QCPBars::setBarsGroup on the \a bars instance. + + \see insert, remove +*/ +void QCPBarsGroup::append(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + else + qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); +} + +/*! + Inserts the specified \a bars plottable into this group at the specified index position \a i. + This gives you full control over the ordering of the bars. + + \a bars may already be part of this group. In that case, \a bars is just moved to the new index + position. + + \see append, remove +*/ +void QCPBarsGroup::insert(int i, QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + // first append to bars list normally: + if (!mBars.contains(bars)) + bars->setBarsGroup(this); + // then move to according position: + mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); +} + +/*! + Removes the specified \a bars plottable from this group. + + \see contains, clear +*/ +void QCPBarsGroup::remove(QCPBars *bars) +{ + if (!bars) + { + qDebug() << Q_FUNC_INFO << "bars is 0"; + return; + } + + if (mBars.contains(bars)) + bars->setBarsGroup(0); + else + qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); +} + +/*! \internal + + Adds the specified \a bars to the internal mBars list of bars. This method does not change the + barsGroup property on \a bars. + + \see unregisterBars +*/ +void QCPBarsGroup::registerBars(QCPBars *bars) +{ + if (!mBars.contains(bars)) + mBars.append(bars); +} + +/*! \internal + + Removes the specified \a bars from the internal mBars list of bars. This method does not change + the barsGroup property on \a bars. + + \see registerBars +*/ +void QCPBarsGroup::unregisterBars(QCPBars *bars) +{ + mBars.removeOne(bars); +} + +/*! \internal + + Returns the pixel offset in the key dimension the specified \a bars plottable should have at the + given key coordinate \a keyCoord. The offset is relative to the pixel position of the key + coordinate \a keyCoord. +*/ +double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) +{ + // find list of all base bars in case some mBars are stacked: + QList baseBars; + Q_FOREACH (const QCPBars *b, mBars) + { + while (b->barBelow()) + b = b->barBelow(); + if (!baseBars.contains(b)) + baseBars.append(b); + } + // find base bar this "bars" is stacked on: + const QCPBars *thisBase = bars; + while (thisBase->barBelow()) + thisBase = thisBase->barBelow(); + + // determine key pixel offset of this base bars considering all other base bars in this barsgroup: + double result = 0; + int index = baseBars.indexOf(thisBase); + if (index >= 0) + { + if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) + { + return result; + } else + { + double lowerPixelWidth, upperPixelWidth; + int startIndex; + int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative + if (baseBars.size() % 2 == 0) // even number of bars + { + startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); + result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing + } else // uneven number of bars + { + startIndex = (baseBars.size()-1)/2+dir; + baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar + result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing + } + for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars + { + baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth); + result += getPixelSpacing(baseBars.at(i), keyCoord); + } + // finally half of our bars width: + baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); + result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; + // correct sign of result depending on orientation and direction of key axis: + result *= dir*thisBase->keyAxis()->pixelOrientation(); + } + } + return result; +} + +/*! \internal + + Returns the spacing in pixels which is between this \a bars and the following one, both at the + key coordinate \a keyCoord. + + \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only + needed to get access to the key axis transformation and axis rect for the modes \ref + stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in + \ref stPlotCoords on a logarithmic axis. +*/ +double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) +{ + switch (mSpacingType) + { + case stAbsolute: + { + return mSpacing; + } + case stAxisRectRatio: + { + if (bars->keyAxis()->orientation() == Qt::Horizontal) + return bars->keyAxis()->axisRect()->width()*mSpacing; + else + return bars->keyAxis()->axisRect()->height()*mSpacing; + } + case stPlotCoords: + { + double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); + return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); + } + } + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBarsData + \brief Holds the data of one single data point (one bar) for QCPBars. + + The stored data is: + \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) + \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) + + The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for + \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPBarsDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPBarsData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPBarsData::mainValue() const + + Returns the \a value member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPBarsData::valueRange() const + + Returns a QCPRange with both lower and upper boundary set to \a value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a bar data point with key and value set to zero. +*/ +QCPBarsData::QCPBarsData() : + key(0), + value(0) +{ +} + +/*! + Constructs a bar data point with the specified \a key and \a value. +*/ +QCPBarsData::QCPBarsData(double key, double value) : + key(key), + value(value) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPBars + \brief A plottable representing a bar chart in a plot. + + \image html QCPBars.png + + To plot data, assign it with the \ref setData or \ref addData functions. + + \section qcpbars-appearance Changing the appearance + + The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). + The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. + + Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other + (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear + stacked. + + If you would like to group multiple QCPBars plottables together so they appear side by side as + shown below, use QCPBarsGroup. + + \image html QCPBarsGroup.png + + \section qcpbars-usage Usage + + Like all data representing objects in QCustomPlot, the QCPBars is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods. +*/ + +/*! \fn QCPBars *QCPBars::barBelow() const + Returns the bars plottable that is directly below this bars plottable. + If there is no such plottable, returns 0. + + \see barAbove, moveBelow, moveAbove +*/ + +/*! \fn QCPBars *QCPBars::barAbove() const + Returns the bars plottable that is directly above this bars plottable. + If there is no such plottable, returns 0. + + \see barBelow, moveBelow, moveAbove +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.75), + mWidthType(wtPlotCoords), + mBarsGroup(0), + mBaseValue(0), + mStackingGap(0) +{ + // modify inherited properties from abstract plottable: + mPen.setColor(Qt::blue); + mPen.setStyle(Qt::SolidLine); + mBrush.setColor(QColor(40, 50, 255, 30)); + mBrush.setStyle(Qt::SolidPattern); + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPBars::~QCPBars() +{ + setBarsGroup(0); + if (mBarBelow || mBarAbove) + connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. + Modifying the data in the container will then affect all bars that share the container. Sharing + can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the bar's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 + + \see addData +*/ +void QCPBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys and \a values. The provided + vectors should have equal length. Else, the number of added points will be the size of the + smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, values, alreadySorted); +} + +/*! + Sets the width of the bars. + + How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), + depends on the currently set width type, see \ref setWidthType and \ref WidthType. +*/ +void QCPBars::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the bars is defined. See the documentation of \ref WidthType for an + explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPBars::setWidthType(QCPBars::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref + QCPBarsGroup::append. + + To remove this QCPBars from any group, set \a barsGroup to 0. +*/ +void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) +{ + // deregister at old group: + if (mBarsGroup) + mBarsGroup->unregisterBars(this); + mBarsGroup = barsGroup; + // register at new group: + if (mBarsGroup) + mBarsGroup->registerBars(this); +} + +/*! + Sets the base value of this bars plottable. + + The base value defines where on the value coordinate the bars start. How far the bars extend from + the base value is given by their individual value data. For example, if the base value is set to + 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at + 3. + + For stacked bars, only the base value of the bottom-most QCPBars has meaning. + + The default base value is 0. +*/ +void QCPBars::setBaseValue(double baseValue) +{ + mBaseValue = baseValue; +} + +/*! + If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method + allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by + the bars below it. +*/ +void QCPBars::setStackingGap(double pixels) +{ + mStackingGap = pixels; +} + +/*! \overload + + Adds the provided points in \a keys and \a values to the current data. The provided vectors + should have equal length. Else, the number of added points will be the size of the smallest + vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) +{ + if (keys.size() != values.size()) + qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); + const int n = qMin(keys.size(), values.size()); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->value = values[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + Adds the provided data point as \a key and \a value to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPBars::addData(double key, double value) +{ + mDataContainer->add(QCPBarsData(key, value)); +} + +/*! + Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear + below the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object below itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barAbove, barBelow +*/ +void QCPBars::moveBelow(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar below it: + if (bars) + { + if (bars->mBarBelow) + connectBars(bars->mBarBelow.data(), this); + connectBars(this, bars); + } +} + +/*! + Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear + above the bars of \a bars. The move target \a bars must use the same key and value axis as this + plottable. + + Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already + has a bars object above itself, this bars object is inserted between the two. If this bars object + is already between two other bars, the two other bars will be stacked on top of each other after + the operation. + + To remove this bars plottable from any stacking, set \a bars to 0. + + \see moveBelow, barBelow, barAbove +*/ +void QCPBars::moveAbove(QCPBars *bars) +{ + if (bars == this) return; + if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + { + qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; + return; + } + // remove from stacking: + connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + // if new bar given, insert this bar above it: + if (bars) + { + if (bars->mBarAbove) + connectBars(this, bars->mBarAbove.data()); + connectBars(bars, this); + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getBarRect(it->key, it->value))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getBarRect(it->key, it->value).contains(pos)) + { + if (details) + { + int pointIndex = it-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return mParentPlot->selectionTolerance()*0.99; + } + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in + absolute pixels), using this method to adapt the key axis range to fit the bars into the + currently visible axis range will not work perfectly. Because in the moment the axis range is + changed to the new range, the fixed pixel widths/spacings will represent different coordinate + spans than before, which in turn would require a different key range to perfectly fit, and so on. + The only solution would be to iteratively approach the perfect fitting axis range, but the + mismatch isn't large enough in most applications, to warrant this here. If a user does need a + better fit, he should call the corresponding axis rescale multiple times in a row. + */ + QCPRange range; + range = mDataContainer->keyRange(foundRange, inSignDomain); + + // determine exact range of bars by including bar width and barsgroup offset: + if (foundRange && mKeyAxis) + { + double lowerPixelWidth, upperPixelWidth, keyPixel; + // lower range bound: + getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); + const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) + range.lower = lowerCorrected; + // upper range bound: + getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); + keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); + const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); + if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) + range.upper = upperCorrected; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + // Note: can't simply use mDataContainer->valueRange here because we need to + // take into account bar base value and possible stacking of multiple bars + QCPRange range; + range.lower = mBaseValue; + range.upper = mBaseValue; + bool haveLower = true; // set to true, because baseValue should always be visible in bar charts + bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts + QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (inKeyRange != QCPRange()) + { + itBegin = mDataContainer->findBegin(inKeyRange.lower); + itEnd = mDataContainer->findEnd(inKeyRange.upper); + } + for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + + foundRange = true; // return true because bar charts always have the 0-line visible + return range; +} + +/* inherits documentation from base class */ +QPointF QCPBars::dataPixelPosition(int index) const +{ + if (index >= 0 && index < mDataContainer->size()) + { + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } + + const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; + const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); + const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); + if (keyAxis->orientation() == Qt::Horizontal) + return QPointF(keyPixel, valuePixel); + else + return QPointF(valuePixel, keyPixel); + } else + { + qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; + return QPointF(); + } +} + +/* inherits documentation from base class */ +void QCPBars::draw(QCPPainter *painter) +{ + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mDataContainer->isEmpty()) return; + + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPBarsDataContainer::const_iterator begin = visibleBegin; + QCPBarsDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->value)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +#endif + // draw bar: + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyBrush(painter); + mSelectionDecorator->applyPen(painter); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + } + applyDefaultAntialiasingHint(painter); + painter->drawPolygon(getBarRect(it->key, it->value)); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setBrush(mBrush); + painter->setPen(mPen); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + if (mDataContainer->isEmpty()) + { + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + + // get visible data range as QMap iterators + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); + double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); + double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); + bool isVisible = false; + // walk left from begin to find lower bar that actually is completely outside visible pixel range: + QCPBarsDataContainer::const_iterator it = begin; + while (it != mDataContainer->constBegin()) + { + --it; + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); + if (isVisible) + begin = it; + else + break; + } + // walk right from ubound to find upper bar that actually is completely outside visible pixel range: + it = end; + while (it != mDataContainer->constEnd()) + { + const QRectF barRect = getBarRect(it->key, it->value); + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); + else // keyaxis is vertical + isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); + if (isVisible) + end = it+1; + else + break; + ++it; + } +} + +/*! \internal + + Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The + rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref + setBaseValue), and to have non-overlapping border lines with the bars stacked below. +*/ +QRectF QCPBars::getBarRect(double key, double value) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double lowerPixelWidth, upperPixelWidth; + getPixelWidth(key, lowerPixelWidth, upperPixelWidth); + double base = getStackedBaseValue(key, value >= 0); + double basePixel = valueAxis->coordToPixel(base); + double valuePixel = valueAxis->coordToPixel(base+value); + double keyPixel = keyAxis->coordToPixel(key); + if (mBarsGroup) + keyPixel += mBarsGroup->keyPixelOffset(this, key); + double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); + bottomOffset += mBarBelow ? mStackingGap : 0; + bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); + if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) + bottomOffset = valuePixel-basePixel; + if (keyAxis->orientation() == Qt::Horizontal) + { + return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); + } else + { + return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). + + The output parameters \a lower and \a upper return the number of pixels the bar extends to lower + and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a + lower is negative and \a upper positive). +*/ +void QCPBars::getPixelWidth(double key, double &lower, double &upper) const +{ + lower = 0; + upper = 0; + switch (mWidthType) + { + case wtAbsolute: + { + upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + lower = -upper; + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + { + double keyPixel = mKeyAxis.data()->coordToPixel(key); + upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; + // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by + // coordinate transform which includes range direction + } else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } +} + +/*! \internal + + This function is called to find at which value to start drawing the base of a bar at \a key, when + it is stacked on top of another QCPBars (e.g. with \ref moveAbove). + + positive and negative bars are separated per stack (positive are stacked above baseValue upwards, + negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the + bar for which we need the base value is negative, set \a positive to false. +*/ +double QCPBars::getStackedBaseValue(double key, bool positive) const +{ + if (mBarBelow) + { + double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack + // find bars of mBarBelow that are approximately at key and find largest one: + double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point + if (key == 0) + epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); + QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); + QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); + while (it != itEnd) + { + if (it->key > key-epsilon && it->key < key+epsilon) + { + if ((positive && it->value > max) || + (!positive && it->value < max)) + max = it->value; + } + ++it; + } + // recurse down the bar-stack to find the total height: + return max + mBarBelow.data()->getStackedBaseValue(key, positive); + } else + return mBaseValue; +} + +/*! \internal + + Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) + currently above lower and below upper will become disconnected to lower/upper. + + If lower is zero, upper will be disconnected at the bottom. + If upper is zero, lower will be disconnected at the top. +*/ +void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) +{ + if (!lower && !upper) return; + + if (!lower) // disconnect upper at bottom + { + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + upper->mBarBelow = 0; + } else if (!upper) // disconnect lower at top + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + lower->mBarAbove = 0; + } else // connect lower and upper + { + // disconnect old bar above lower: + if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + lower->mBarAbove.data()->mBarBelow = 0; + // disconnect old bar below upper: + if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + upper->mBarBelow.data()->mBarAbove = 0; + lower->mBarAbove = upper; + upper->mBarBelow = lower; + } +} +/* end of 'src/plottables/plottable-bars.cpp' */ + + +/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBoxData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBoxData + \brief Holds the data of one single data point for QCPStatisticalBox. + + The stored data is: + + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + + \li \a minimum: the position of the lower whisker, typically the minimum measurement of the + sample that's not considered an outlier. + + \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a median: the value of the median mark inside the quartile box. The median separates the + sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) + + \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two + statistical quartiles around the median of the sample, they should contain 50% of the sample + data. + + \li \a maximum: the position of the upper whisker, typically the maximum measurement of the + sample that's not considered an outlier. + + \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key + coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) + + The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a + typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template + parameter. See the documentation there for an explanation regarding the data type's generic + methods. + + \see QCPStatisticalBoxDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPStatisticalBoxData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPStatisticalBoxData::mainValue() const + + Returns the \a median member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const + + Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box + data point, possibly further expanded by outliers. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData() : + key(0), + minimum(0), + lowerQuartile(0), + median(0), + upperQuartile(0), + maximum(0) +{ +} + +/*! + Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a + upperQuartile, \a maximum and optionally a number of \a outliers. +*/ +QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : + key(key), + minimum(minimum), + lowerQuartile(lowerQuartile), + median(median), + upperQuartile(upperQuartile), + maximum(maximum), + outliers(outliers) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPStatisticalBox +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPStatisticalBox + \brief A plottable representing a single statistical box in a plot. + + \image html QCPStatisticalBox.png + + To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can + also access and modify the data via the \ref data method, which returns a pointer to the internal + \ref QCPStatisticalBoxDataContainer. + + Additionally each data point can itself have a list of outliers, drawn as scatter points at the + key coordinate of the respective statistical box data point. They can either be set by using the + respective \ref addData(double,double,double,double,double,double,const QVector&) + "addData" method or accessing the individual data points through \ref data, and setting the + QVector outliers of the data points directly. + + \section qcpstatisticalbox-appearance Changing the appearance + + The appearance of each data point box, ranging from the lower to the upper quartile, is + controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref + setWidth in plot coordinates. + + Each data point's visual representation also consists of two whiskers. Whiskers are the lines + which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. + The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, + \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at + the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set + the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a + few pixels due to the pen cap being not perfectly flat. + + The median indicator line inside the box has its own pen, \ref setMedianPen. + + The outlier data points are drawn as normal scatter points. Their look can be controlled with + \ref setOutlierStyle + + \section qcpstatisticalbox-usage Usage + + Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes + ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. + The newly created plottable can be modified, e.g.: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 +*/ + +/* start documentation of inline functions */ + +/*! \fn QSharedPointer QCPStatisticalBox::data() const + + Returns a shared pointer to the internal data storage of type \ref + QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more + convenient and faster than using the regular \ref setData or \ref addData methods. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its + value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and + not have the same orientation. If either of these restrictions is violated, a corresponding + message is printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not + delete it manually but use QCustomPlot::removePlottable() instead. +*/ +QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.5), + mWhiskerWidth(0.2), + mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), + mWhiskerBarPen(Qt::black), + mWhiskerAntialiased(false), + mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), + mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) +{ + setPen(QPen(Qt::black)); + setBrush(Qt::NoBrush); +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container + safely. Modifying the data in the container will then affect all statistical boxes that share the + container. Sharing can be achieved by simply exchanging the data containers wrapped in shared + pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the statistical box data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 + + \see addData +*/ +void QCPStatisticalBox::setData(QSharedPointer data) +{ + mDataContainer = data; +} +/*! \overload + + Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a + median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the + number of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData +*/ +void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); +} + +/*! + Sets the width of the boxes in key coordinates. + + \see setWhiskerWidth +*/ +void QCPStatisticalBox::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets the width of the whiskers in key coordinates. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWidth +*/ +void QCPStatisticalBox::setWhiskerWidth(double width) +{ + mWhiskerWidth = width; +} + +/*! + Sets the pen used for drawing the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone + line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. + + \see setWhiskerBarPen +*/ +void QCPStatisticalBox::setWhiskerPen(const QPen &pen) +{ + mWhiskerPen = pen; +} + +/*! + Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at + each end of the whisker backbone. + + Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower + quartile to the minimum. + + \see setWhiskerPen +*/ +void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) +{ + mWhiskerBarPen = pen; +} + +/*! + Sets whether the statistical boxes whiskers are drawn with antialiasing or not. + + Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and + QCustomPlot::setNotAntialiasedElements. +*/ +void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) +{ + mWhiskerAntialiased = enabled; +} + +/*! + Sets the pen used for drawing the median indicator line inside the statistical boxes. +*/ +void QCPStatisticalBox::setMedianPen(const QPen &pen) +{ + mMedianPen = pen; +} + +/*! + Sets the appearance of the outlier data points. + + Outliers can be specified with the method + \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +*/ +void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) +{ + mOutlierStyle = style; +} + +/*! \overload + + Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and + \a maximum to the current data. The provided vectors should have equal length. Else, the number + of added points will be the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +{ + if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || + median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" + << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); + const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->minimum = minimum[i]; + it->lowerQuartile = lowerQuartile[i]; + it->median = median[i]; + it->upperQuartile = upperQuartile[i]; + it->maximum = maximum[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile + and \a maximum to the current data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. +*/ +void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) +{ + mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(getQuartileBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + double minDistSqr = std::numeric_limits::max(); + for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (getQuartileBox(it).contains(pos)) // quartile box + { + double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } else // whiskers + { + const QVector whiskerBackbones(getWhiskerBackboneLines(it)); + for (int i=0; iconstBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return qSqrt(minDistSqr); + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::draw(QCPPainter *painter) +{ + if (mDataContainer->isEmpty()) return; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; + QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) + { + // check data validity if flag set: +# ifdef QCUSTOMPLOT_CHECK_DATA + if (QCP::isInvalidData(it->key, it->minimum) || + QCP::isInvalidData(it->lowerQuartile, it->median) || + QCP::isInvalidData(it->upperQuartile, it->maximum)) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); + for (int i=0; ioutliers.size(); ++i) + if (QCP::isInvalidData(it->outliers.at(i))) + qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); +# endif + + if (isSelectedSegment && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + QCPScatterStyle finalOutlierStyle = mOutlierStyle; + if (isSelectedSegment && mSelectionDecorator) + finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); + drawStatisticalBox(painter, it, finalOutlierStyle); + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + // draw filled rect: + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + painter->setBrush(mBrush); + QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); + r.moveCenter(rect.center()); + painter->drawRect(r); +} + +/*! + Draws the graphical representation of a single statistical box with the data given by the + iterator \a it with the provided \a painter. + + If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. + + \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const +{ + // draw quartile box: + applyDefaultAntialiasingHint(painter); + const QRectF quartileBox = getQuartileBox(it); + painter->drawRect(quartileBox); + // draw median line with cliprect set to quartile box: + painter->save(); + painter->setClipRect(quartileBox, Qt::IntersectClip); + painter->setPen(mMedianPen); + painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); + painter->restore(); + // draw whisker lines: + applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); + painter->setPen(mWhiskerPen); + painter->drawLines(getWhiskerBackboneLines(it)); + painter->setPen(mWhiskerBarPen); + painter->drawLines(getWhiskerBarLines(it)); + // draw outliers: + applyScattersAntialiasingHint(painter); + outlierStyle.applyTo(painter, mPen); + for (int i=0; ioutliers.size(); ++i) + outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); +} + +/*! \internal + + called by \ref draw to determine which data (key) range is visible at the current key axis range + setting, so only that needs to be processed. It also takes into account the bar width. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + lower may still be just outside the visible range. + + \a end returns an iterator one higher than the highest visible data point. Same as before, \a end + may also lie just outside of the visible range. + + if the plottable contains no data, both \a begin and \a end point to constEnd. +*/ +void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points +} + +/*! \internal + + Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the + value range from the lower to the upper quartile, of the data given by \a it. + + \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines +*/ +QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QRectF result; + result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); + result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); + return result; +} + +/*! \internal + + Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value + range from the minimum to the lower quartile, and from the upper quartile to the maximum of the + data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines +*/ +QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone + result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone + return result; +} + +/*! \internal + + Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the + end of the whisker backbones, at the minimum and maximum of the data given by \a it. + + \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines +*/ +QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const +{ + QVector result(2); + result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar + result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar + return result; +} +/* end of 'src/plottables/plottable-statisticalbox.cpp' */ + + +/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPColorMapData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPColorMapData + \brief Holds the two-dimensional data of a QCPColorMap plottable. + + This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref + QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a + color, depending on the value. + + The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). + Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref + setKeyRange, \ref setValueRange). + + The data cells can be accessed in two ways: They can be directly addressed by an integer index + with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot + coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are + provided by the functions \ref coordToCell and \ref cellToCoord. + + A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if + allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref + fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on + the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. + + This class also buffers the minimum and maximum values that are in the data set, to provide + QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value + that is greater than the current maximum increases this maximum to the new value. However, + setting the cell that currently holds the maximum value to a smaller value doesn't decrease the + maximum again, because finding the true new maximum would require going through the entire data + array, which might be time consuming. The same holds for the data minimum. This functionality is + given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the + true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience + parameter \a recalculateDataBounds which may be set to true to automatically call \ref + recalculateDataBounds internally. +*/ + +/* start of documentation of inline functions */ + +/*! \fn bool QCPColorMapData::isEmpty() const + + Returns whether this instance carries no data. This is equivalent to having a size where at least + one of the dimensions is 0 (see \ref setSize). +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction + and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap + at the coordinates \a keyRange and \a valueRange. + + \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange +*/ +QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : + mKeySize(0), + mValueSize(0), + mKeyRange(keyRange), + mValueRange(valueRange), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + setSize(keySize, valueSize); + fill(0); +} + +QCPColorMapData::~QCPColorMapData() +{ + if (mData) + delete[] mData; + if (mAlpha) + delete[] mAlpha; +} + +/*! + Constructs a new QCPColorMapData instance copying the data and range of \a other. +*/ +QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : + mKeySize(0), + mValueSize(0), + mIsEmpty(true), + mData(0), + mAlpha(0), + mDataModified(true) +{ + *this = other; +} + +/*! + Overwrites this color map data instance with the data stored in \a other. The alpha map state is + transferred, too. +*/ +QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) +{ + if (&other != this) + { + const int keySize = other.keySize(); + const int valueSize = other.valueSize(); + if (!other.mAlpha && mAlpha) + clearAlpha(); + setSize(keySize, valueSize); + if (other.mAlpha && !mAlpha) + createAlpha(false); + setRange(other.keyRange(), other.valueRange()); + if (!isEmpty()) + { + memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); + if (mAlpha) + memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); + } + mDataBounds = other.mDataBounds; + mDataModified = true; + } + return *this; +} + +/* undocumented getter */ +double QCPColorMapData::data(double key, double value) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + return mData[valueCell*mKeySize + keyCell]; + else + return 0; +} + +/* undocumented getter */ +double QCPColorMapData::cell(int keyIndex, int valueIndex) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mData[valueIndex*mKeySize + keyIndex]; + else + return 0; +} + +/*! + Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. + + If this color map data doesn't have an alpha map (because \ref setAlpha was never called after + creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. + + \see setAlpha +*/ +unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) +{ + if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + return mAlpha[valueIndex*mKeySize + keyIndex]; + else + return 255; +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in + the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref + isEmpty returns true. + + \see setRange, setKeySize, setValueSize +*/ +void QCPColorMapData::setSize(int keySize, int valueSize) +{ + if (keySize != mKeySize || valueSize != mValueSize) + { + mKeySize = keySize; + mValueSize = valueSize; + if (mData) + delete[] mData; + mIsEmpty = mKeySize == 0 || mValueSize == 0; + if (!mIsEmpty) + { +#ifdef __EXCEPTIONS + try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message +#endif + mData = new double[mKeySize*mValueSize]; +#ifdef __EXCEPTIONS + } catch (...) { mData = 0; } +#endif + if (mData) + fill(0); + else + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; + } else + mData = 0; + + if (mAlpha) // if we had an alpha map, recreate it with new size + createAlpha(); + + mDataModified = true; + } +} + +/*! + Resizes the data array to have \a keySize cells in the key dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. + + \see setKeyRange, setSize, setValueSize +*/ +void QCPColorMapData::setKeySize(int keySize) +{ + setSize(keySize, mValueSize); +} + +/*! + Resizes the data array to have \a valueSize cells in the value dimension. + + The current data is discarded and the map cells are set to 0, unless the map had already the + requested size. + + Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. + + \see setValueRange, setSize, setKeySize +*/ +void QCPColorMapData::setValueSize(int valueSize) +{ + setSize(mKeySize, valueSize); +} + +/*! + Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area + covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setSize +*/ +void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) +{ + setKeyRange(keyRange); + setValueRange(valueRange); +} + +/*! + Sets the coordinate range the data shall be distributed over in the key dimension. Together with + the value range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will + be cells centered on the key coordinates 2, 2.5 and 3. + + \see setRange, setValueRange, setSize +*/ +void QCPColorMapData::setKeyRange(const QCPRange &keyRange) +{ + mKeyRange = keyRange; +} + +/*! + Sets the coordinate range the data shall be distributed over in the value dimension. Together with + the key range, This defines the rectangular area covered by the color map in plot coordinates. + + The outer cells will be centered on the range boundaries given to this function. For example, if + the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there + will be cells centered on the value coordinates 2, 2.5 and 3. + + \see setRange, setKeyRange, setSize +*/ +void QCPColorMapData::setValueRange(const QCPRange &valueRange) +{ + mValueRange = valueRange; +} + +/*! + Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a + z. + + \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or + value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, + you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to + determine the cell index. Rather directly access the cell index with \ref + QCPColorMapData::setCell. + + \see setCell, setRange +*/ +void QCPColorMapData::setData(double key, double value, double z) +{ + int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; + int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; + if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + { + mData[valueCell*mKeySize + keyCell] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } +} + +/*! + Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices + enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see + \ref setSize). + + In the standard plot configuration (horizontal key axis and vertical value axis, both not + range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with + indices (keySize-1, valueSize-1) is in the top right corner of the color map. + + \see setData, setSize +*/ +void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + mData[valueIndex*mKeySize + keyIndex] = z; + if (z < mDataBounds.lower) + mDataBounds.lower = z; + if (z > mDataBounds.upper) + mDataBounds.upper = z; + mDataModified = true; + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value + of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully + opaque cell. + + If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish + to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. + + Note that the cell-wise alpha which can be configured here is independent of any alpha configured + in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise + and gradient alpha, the alpha values will be blended accordingly during rendering of the color + map. + + \see fillAlpha, clearAlpha +*/ +void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) +{ + if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + { + if (mAlpha || createAlpha()) + { + mAlpha[valueIndex*mKeySize + keyIndex] = alpha; + mDataModified = true; + } + } else + qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; +} + +/*! + Goes through the data and updates the buffered minimum and maximum data values. + + Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange + and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten + with a smaller or larger value respectively, since the buffered maximum/minimum values have been + updated the last time. Why this is the case is explained in the class description (\ref + QCPColorMapData). + + Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a + recalculateDataBounds for convenience. Setting this to true will call this method for you, before + doing the rescale. +*/ +void QCPColorMapData::recalculateDataBounds() +{ + if (mKeySize > 0 && mValueSize > 0) + { + double minHeight = mData[0]; + double maxHeight = mData[0]; + const int dataCount = mValueSize*mKeySize; + for (int i=0; i maxHeight) + maxHeight = mData[i]; + if (mData[i] < minHeight) + minHeight = mData[i]; + } + mDataBounds.lower = minHeight; + mDataBounds.upper = maxHeight; + } +} + +/*! + Frees the internal data memory. + + This is equivalent to calling \ref setSize "setSize(0, 0)". +*/ +void QCPColorMapData::clear() +{ + setSize(0, 0); +} + +/*! + Frees the internal alpha map. The color map will have full opacity again. +*/ +void QCPColorMapData::clearAlpha() +{ + if (mAlpha) + { + delete[] mAlpha; + mAlpha = 0; + mDataModified = true; + } +} + +/*! + Sets all cells to the value \a z. +*/ +void QCPColorMapData::fill(double z) +{ + const int dataCount = mValueSize*mKeySize; + for (int i=0; i(data); + return; + } + if (copy) + { + *mMapData = *data; + } else + { + delete mMapData; + mMapData = data; + } + mMapImageInvalidated = true; +} + +/*! + Sets the data range of this color map to \a dataRange. The data range defines which data values + are mapped to the color gradient. + + To make the data range span the full range of the data set, use \ref rescaleDataRange. + + \see QCPColorScale::setDataRange +*/ +void QCPColorMap::setDataRange(const QCPRange &dataRange) +{ + if (!QCPRange::validRange(dataRange)) return; + if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + { + if (mDataScaleType == QCPAxis::stLogarithmic) + mDataRange = dataRange.sanitizedForLogScale(); + else + mDataRange = dataRange.sanitizedForLinScale(); + mMapImageInvalidated = true; + Q_EMIT dataRangeChanged(mDataRange); + } +} + +/*! + Sets whether the data is correlated with the color gradient linearly or logarithmically. + + \see QCPColorScale::setDataScaleType +*/ +void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) +{ + if (mDataScaleType != scaleType) + { + mDataScaleType = scaleType; + mMapImageInvalidated = true; + Q_EMIT dataScaleTypeChanged(mDataScaleType); + if (mDataScaleType == QCPAxis::stLogarithmic) + setDataRange(mDataRange.sanitizedForLogScale()); + } +} + +/*! + Sets the color gradient that is used to represent the data. For more details on how to create an + own gradient or use one of the preset gradients, see \ref QCPColorGradient. + + The colors defined by the gradient will be used to represent data values in the currently set + data range, see \ref setDataRange. Data points that are outside this data range will either be + colored uniformly with the respective gradient boundary color, or the gradient will repeat, + depending on \ref QCPColorGradient::setPeriodic. + + \see QCPColorScale::setGradient +*/ +void QCPColorMap::setGradient(const QCPColorGradient &gradient) +{ + if (mGradient != gradient) + { + mGradient = gradient; + mMapImageInvalidated = true; + Q_EMIT gradientChanged(mGradient); + } +} + +/*! + Sets whether the color map image shall use bicubic interpolation when displaying the color map + shrinked or expanded, and not at a 1:1 pixel-to-data scale. + + \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" +*/ +void QCPColorMap::setInterpolate(bool enabled) +{ + mInterpolate = enabled; + mMapImageInvalidated = true; // because oversampling factors might need to change +} + +/*! + Sets whether the outer most data rows and columns are clipped to the specified key and value + range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). + + if \a enabled is set to false, the data points at the border of the color map are drawn with the + same width and height as all other data points. Since the data points are represented by + rectangles of one color centered on the data coordinate, this means that the shown color map + extends by half a data point over the specified key/value range in each direction. + + \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" +*/ +void QCPColorMap::setTightBoundary(bool enabled) +{ + mTightBoundary = enabled; +} + +/*! + Associates the color scale \a colorScale with this color map. + + This means that both the color scale and the color map synchronize their gradient, data range and + data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps + can be associated with one single color scale. This causes the color maps to also synchronize + those properties, via the mutual color scale. + + This function causes the color map to adopt the current color gradient, data range and data scale + type of \a colorScale. After this call, you may change these properties at either the color map + or the color scale, and the setting will be applied to both. + + Pass 0 as \a colorScale to disconnect the color scale from this color map again. +*/ +void QCPColorMap::setColorScale(QCPColorScale *colorScale) +{ + if (mColorScale) // unconnect signals from old color scale + { + disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } + mColorScale = colorScale; + if (mColorScale) // connect signals to new color scale + { + setGradient(mColorScale.data()->gradient()); + setDataRange(mColorScale.data()->dataRange()); + setDataScaleType(mColorScale.data()->dataScaleType()); + connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); + connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); + connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); + connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); + connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + } +} + +/*! + Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the + current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, + only for the third data dimension of the color map. + + The minimum and maximum values of the data set are buffered in the internal QCPColorMapData + instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref + QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For + performance reasons, however, they are only updated in an expanding fashion. So the buffered + maximum can only increase and the buffered minimum can only decrease. In consequence, changes to + the data that actually lower the maximum of the data set (by overwriting the cell holding the + current maximum with a smaller value), aren't recognized and the buffered maximum overestimates + the true maximum of the data set. The same happens for the buffered minimum. To recalculate the + true minimum and maximum by explicitly looking at each cell, the method + QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a + recalculateDataBounds calls this method before setting the data range to the buffered minimum and + maximum. + + \see setDataRange +*/ +void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) +{ + if (recalculateDataBounds) + mMapData->recalculateDataBounds(); + setDataRange(mMapData->dataBounds()); +} + +/*! + Takes the current appearance of the color map and updates the legend icon, which is used to + represent this color map in the legend (see \ref QCPLegend). + + The \a transformMode specifies whether the rescaling is done by a faster, low quality image + scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm + (Qt::SmoothTransformation). + + The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to + the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured + legend icon size, the thumb will be rescaled during drawing of the legend item. + + \see setDataRange +*/ +void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) +{ + if (mMapImage.isNull() && !data()->isEmpty()) + updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) + + if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again + { + bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); + } +} + +/* inherits documentation from base class */ +double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) + { + if (details) + details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. + return mParentPlot->selectionTolerance()*0.99; + } + } + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + foundRange = true; + QCPRange result = mMapData->keyRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/* inherits documentation from base class */ +QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (inKeyRange != QCPRange()) + { + if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) + { + foundRange = false; + return QCPRange(); + } + } + + foundRange = true; + QCPRange result = mMapData->valueRange(); + result.normalize(); + if (inSignDomain == QCP::sdPositive) + { + if (result.lower <= 0 && result.upper > 0) + result.lower = result.upper*1e-3; + else if (result.lower <= 0 && result.upper <= 0) + foundRange = false; + } else if (inSignDomain == QCP::sdNegative) + { + if (result.upper >= 0 && result.lower < 0) + result.upper = result.lower*1e-3; + else if (result.upper >= 0 && result.lower >= 0) + foundRange = false; + } + return result; +} + +/*! \internal + + Updates the internal map image buffer by going through the internal \ref QCPColorMapData and + turning the data values into color pixels with \ref QCPColorGradient::colorize. + + This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image + has been invalidated for a different reason (e.g. a change of the data range with \ref + setDataRange). + + If the map cell count is low, the image created will be oversampled in order to avoid a + QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images + without smooth transform enabled. Accordingly, oversampling isn't performed if \ref + setInterpolate is true. +*/ +void QCPColorMap::updateMapImage() +{ + QCPAxis *keyAxis = mKeyAxis.data(); + if (!keyAxis) return; + if (mMapData->isEmpty()) return; + + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; + const int keySize = mMapData->keySize(); + const int valueSize = mMapData->valueSize(); + int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + + // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: + if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) + mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); + else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) + mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); + + if (mMapImage.isNull()) + { + qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; + mMapImage = QImage(QSize(10, 10), format); + mMapImage.fill(Qt::black); + } else + { + QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + // resize undersampled map image to actual key/value cell sizes: + if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) + mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); + else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) + mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); + localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image + } else if (!mUndersampledMapImage.isNull()) + mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it + + const double *rawData = mMapData->mData; + const unsigned char *rawAlpha = mMapData->mAlpha; + if (keyAxis->orientation() == Qt::Horizontal) + { + const int lineCount = valueSize; + const int rowCount = keySize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + } + } else // keyAxis->orientation() == Qt::Vertical + { + const int lineCount = keySize; + const int rowCount = valueSize; + for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if (rawAlpha) + mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + else + mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + } + } + + if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + { + if (keyAxis->orientation() == Qt::Horizontal) + mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + else + mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + } + } + mMapData->mDataModified = false; + mMapImageInvalidated = false; +} + +/* inherits documentation from base class */ +void QCPColorMap::draw(QCPPainter *painter) +{ + if (mMapData->isEmpty()) return; + if (!mKeyAxis || !mValueAxis) return; + applyDefaultAntialiasingHint(painter); + + if (mMapData->mDataModified || mMapImageInvalidated) + updateMapImage(); + + // use buffer if painting vectorized (PDF): + const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); + QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized + QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in + QPixmap mapBuffer; + if (useBuffer) + { + const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps + mapBufferTarget = painter->clipRegion().boundingRect(); + mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); + mapBuffer.fill(Qt::transparent); + localPainter = new QCPPainter(&mapBuffer); + localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); + localPainter->translate(-mapBufferTarget.topLeft()); + } + + QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): + double halfCellWidth = 0; // in pixels + double halfCellHeight = 0; // in pixels + if (keyAxis()->orientation() == Qt::Horizontal) + { + if (mMapData->keySize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); + } else // keyAxis orientation is Qt::Vertical + { + if (mMapData->keySize() > 1) + halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); + if (mMapData->valueSize() > 1) + halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); + } + imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); + const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); + const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); + const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); + QRegion clipBackup; + if (mTightBoundary) + { + clipBackup = localPainter->clipRegion(); + QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), + coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + localPainter->setClipRect(tightClipRect, Qt::IntersectClip); + } + localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); + if (mTightBoundary) + localPainter->setClipRegion(clipBackup); + localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); + + if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter + { + delete localPainter; + painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); + } +} + +/* inherits documentation from base class */ +void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + // draw map thumbnail: + if (!mLegendIcon.isNull()) + { + QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); + QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); + iconRect.moveCenter(rect.center()); + painter->drawPixmap(iconRect.topLeft(), scaledIcon); + } + /* + // draw frame: + painter->setBrush(Qt::NoBrush); + painter->setPen(Qt::black); + painter->drawRect(rect.adjusted(1, 1, 0, 0)); + */ +} +/* end of 'src/plottables/plottable-colormap.cpp' */ + + +/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancialData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancialData + \brief Holds the data of one single data point for QCPFinancial. + + The stored data is: + \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) + \li \a open: The opening value at the data point (this is the \a mainValue) + \li \a high: The high/maximum value at the data point + \li \a low: The low/minimum value at the data point + \li \a close: The closing value at the data point + + The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef + for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the + documentation there for an explanation regarding the data type's generic methods. + + \see QCPFinancialDataContainer +*/ + +/* start documentation of inline functions */ + +/*! \fn double QCPFinancialData::sortKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) + + Returns a data point with the specified \a sortKey. All other members are set to zero. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() + + Since the member \a key is both the data point key coordinate and the data ordering parameter, + this method returns true. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainKey() const + + Returns the \a key member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn double QCPFinancialData::mainValue() const + + Returns the \a open member of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/*! \fn QCPRange QCPFinancialData::valueRange() const + + Returns a QCPRange spanning from the \a low to the \a high value of this data point. + + For a general explanation of what this method is good for in the context of the data container, + see the documentation of \ref QCPDataContainer. +*/ + +/* end documentation of inline functions */ + +/*! + Constructs a data point with key and all values set to zero. +*/ +QCPFinancialData::QCPFinancialData() : + key(0), + open(0), + high(0), + low(0), + close(0) +{ +} + +/*! + Constructs a data point with the specified \a key and OHLC values. +*/ +QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : + key(key), + open(open), + high(high), + low(low), + close(close) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPFinancial +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPFinancial + \brief A plottable representing a financial stock chart + + \image html QCPFinancial.png + + This plottable represents time series data binned to certain intervals, mainly used for stock + charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be + set via \ref setChartStyle. + + The data is passed via \ref setData as a set of open/high/low/close values at certain keys + (typically times). This means the data must be already binned appropriately. If data is only + available as a series of values (e.g. \a price against \a time), you can use the static + convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed + to \ref setData. + + The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref + setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and + the width to (or slightly less than) one time bin interval width. + + \section qcpfinancial-appearance Changing the appearance + + Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, + lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). + + If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are + represented with a different pen and brush than negative changes (\a close < \a open). These can + be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref + setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection + however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, + irrespective of whether the chart is single- or two-colored. + + \section qcpfinancial-usage Usage + + Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable + (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies + (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) + + Usually, you first create an instance: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 + which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot + instance takes ownership of the plottable, so do not delete it manually but use + QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: + + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 + Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data + series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const + + Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may + use it to directly manipulate the data, which may be more convenient and faster than using the + regular \ref setData or \ref addData methods, in certain situations. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a + keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually + but use QCustomPlot::removePlottable() instead. +*/ +QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mChartStyle(csCandlestick), + mWidth(0.5), + mWidthType(wtPlotCoords), + mTwoColored(true), + mBrushPositive(QBrush(QColor(50, 160, 0))), + mBrushNegative(QBrush(QColor(180, 0, 15))), + mPenPositive(QPen(QColor(40, 150, 0))), + mPenNegative(QPen(QColor(170, 5, 5))) +{ + mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); +} + +QCPFinancial::~QCPFinancial() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. + Modifying the data in the container will then affect all financials that share the container. + Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, rather use + the \ref QCPDataContainer::set method on the financial's data container directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a + close. The provided vectors should have equal length. Else, the number of added points will be + the size of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + \see addData, timeSeriesToOhlc +*/ +void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + mDataContainer->clear(); + addData(keys, open, high, low, close, alreadySorted); +} + +/*! + Sets which representation style shall be used to display the OHLC data. +*/ +void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) +{ + mChartStyle = style; +} + +/*! + Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. + + A typical choice is to set it to (or slightly less than) one bin interval width. +*/ +void QCPFinancial::setWidth(double width) +{ + mWidth = width; +} + +/*! + Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for + an explanation of the possible values for \a widthType. + + The default value is \ref wtPlotCoords. + + \see setWidth +*/ +void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) +{ + mWidthType = widthType; +} + +/*! + Sets whether this chart shall contrast positive from negative trends per data point by using two + separate colors to draw the respective bars/candlesticks. + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setTwoColored(bool twoColored) +{ + mTwoColored = twoColored; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushNegative, setPenPositive, setPenNegative +*/ +void QCPFinancial::setBrushPositive(const QBrush &brush) +{ + mBrushPositive = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills + of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setBrushPositive, setPenNegative, setPenPositive +*/ +void QCPFinancial::setBrushNegative(const QBrush &brush) +{ + mBrushNegative = brush; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenNegative, setBrushPositive, setBrushNegative +*/ +void QCPFinancial::setPenPositive(const QPen &pen) +{ + mPenPositive = pen; +} + +/*! + If \ref setTwoColored is set to true, this function controls the pen that is used to draw + outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). + + If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref + setBrush). + + \see setPenPositive, setBrushNegative, setBrushPositive +*/ +void QCPFinancial::setPenNegative(const QPen &pen) +{ + mPenNegative = pen; +} + +/*! \overload + + Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. + The provided vectors should have equal length. Else, the number of added points will be the size + of the smallest vector. + + If you can guarantee that the passed data points are sorted by \a keys in ascending order, you + can set \a alreadySorted to true, to improve performance by saving a sorting run. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +{ + if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) + qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); + const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); + QVector tempData(n); + QVector::iterator it = tempData.begin(); + const QVector::iterator itEnd = tempData.end(); + int i = 0; + while (it != itEnd) + { + it->key = keys[i]; + it->open = open[i]; + it->high = high[i]; + it->low = low[i]; + it->close = close[i]; + ++it; + ++i; + } + mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write +} + +/*! \overload + + Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current + data. + + Alternatively, you can also access and modify the data directly via the \ref data method, which + returns a pointer to the internal data container. + + \see timeSeriesToOhlc +*/ +void QCPFinancial::addData(double key, double open, double high, double low, double close) +{ + mDataContainer->add(QCPFinancialData(key, open, high, low, close)); +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + if (rect.intersects(selectionHitBox(it))) + result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + getVisibleDataBounds(visibleBegin, visibleEnd); + // perform select test according to configured style: + double result = -1; + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + case QCPFinancial::csCandlestick: + result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + } + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } + + return -1; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + // determine exact range by including width of bars/flags: + if (foundRange) + { + if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) + range.lower -= mWidth*0.5; + if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) + range.upper += mWidth*0.5; + } + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); +} + +/*! + A convenience function that converts time series data (\a value against \a time) to OHLC binned + data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const + QCPFinancialDataContainer&). + + The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. + For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour + each, set \a timeBinSize to 3600. + + \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The + value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. + It merely defines the mathematical offset/phase of the bins that will be used to process the + data. +*/ +QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) +{ + QCPFinancialDataContainer data; + int count = qMin(time.size(), value.size()); + if (count == 0) + return QCPFinancialDataContainer(); + + QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); + int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); + for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); + if (i == count-1) // last data point is in current bin, finalize bin: + { + currentBinData.close = value.at(i); + currentBinData.key = timeBinOffset+(index)*timeBinSize; + data.add(currentBinData); + } + } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: + { + // finalize current bin: + currentBinData.close = value.at(i-1); + currentBinData.key = timeBinOffset+(index-1)*timeBinSize; + data.add(currentBinData); + // start next bin: + currentBinIndex = index; + currentBinData.open = value.at(i); + currentBinData.high = value.at(i); + currentBinData.low = value.at(i); + } + } + + return data; +} + +/* inherits documentation from base class */ +void QCPFinancial::draw(QCPPainter *painter) +{ + // get visible data range: + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd); + + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + for (int i=0; i= unselectedSegments.size(); + QCPFinancialDataContainer::const_iterator begin = visibleBegin; + QCPFinancialDataContainer::const_iterator end = visibleEnd; + mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); + if (begin == end) + continue; + + // draw data segment according to configured style: + switch (mChartStyle) + { + case QCPFinancial::csOhlc: + drawOhlcPlot(painter, begin, end, isSelectedSegment); break; + case QCPFinancial::csCandlestick: + drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; + } + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing + if (mChartStyle == csOhlc) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + } + } else if (mChartStyle == csCandlestick) + { + if (mTwoColored) + { + // draw upper left half icon with positive color: + painter->setBrush(mBrushPositive); + painter->setPen(mPenPositive); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + // draw bottom right half icon with negative color: + painter->setBrush(mBrushNegative); + painter->setPen(mPenNegative); + painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } else + { + painter->setBrush(mBrush); + painter->setPen(mPen); + painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); + painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); + painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. +*/ +void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); + // draw close: + painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); + } + } else + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else if (mTwoColored) + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + else + painter->setPen(mPen); + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw backbone: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); + // draw open: + double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides + painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); + // draw close: + painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); + } + } +} + +/*! \internal + + Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. + + This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. +*/ +void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + // draw low: + painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + { + if (isSelected && mSelectionDecorator) + { + mSelectionDecorator->applyPen(painter); + mSelectionDecorator->applyBrush(painter); + } else if (mTwoColored) + { + painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else + { + painter->setPen(mPen); + painter->setBrush(mBrush); + } + double keyPixel = keyAxis->coordToPixel(it->key); + double openPixel = valueAxis->coordToPixel(it->open); + double closePixel = valueAxis->coordToPixel(it->close); + // draw high: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + // draw low: + painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + // draw open-close box: + double pixelWidth = getPixelWidth(it->key, keyPixel); + painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); + } + } +} + +/*! \internal + + This function is used to determine the width of the bar at coordinate \a key, according to the + specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of + \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel + when this function is called). + + It returns the number of pixels the bar extends to higher keys, relative to the \a key + coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed + horizontal axis, the return value is negative. This is important so the open/close flags on the + \ref csOhlc bar are drawn to the correct side. +*/ +double QCPFinancial::getPixelWidth(double key, double keyPixel) const +{ + double result = 0; + switch (mWidthType) + { + case wtAbsolute: + { + if (mKeyAxis) + result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + break; + } + case wtAxisRectRatio: + { + if (mKeyAxis && mKeyAxis.data()->axisRect()) + { + if (mKeyAxis.data()->orientation() == Qt::Horizontal) + result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + else + result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + } else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: + { + if (mKeyAxis) + result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } + } + return result; +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double keyPixel = keyAxis->coordToPixel(it->key); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + This method is a helper function for \ref selectTest. It is used to test for selection when the + chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a + end. + + Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical + representation of the plottable, and \a closestDataPoint will point to the respective data point. +*/ +double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +{ + closestDataPoint = mDataContainer->constEnd(); + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + + double minDistSqr = std::numeric_limits::max(); + if (keyAxis->orientation() == Qt::Horizontal) + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } else // keyAxis->orientation() == Qt::Vertical + { + for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); + QCPRange boxValueRange(it->close, it->open); + double posKey, posValue; + pixelsToCoords(pos, posKey, posValue); + if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; + } else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel(it->key); + double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + } + if (currentDistSqr < minDistSqr) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt(minDistSqr); +} + +/*! \internal + + called by the drawing methods to determine which data (key) range is visible at the current key + axis range setting, so only that needs to be processed. + + \a begin returns an iterator to the lowest data point that needs to be taken into account when + plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a + begin may still be just outside the visible range. + + \a end returns the iterator just above the highest data point that needs to be taken into + account. Same as before, \a end may also lie just outside of the visible range + + if the plottable contains no data, both \a begin and \a end point to \c constEnd. +*/ +void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const +{ + if (!mKeyAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key axis"; + begin = mDataContainer->constEnd(); + end = mDataContainer->constEnd(); + return; + } + begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points + end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points +} + +/*! \internal + + Returns the hit box in pixel coordinates that will be used for data selection with the selection + rect (\ref selectTestRect), of the data point given by \a it. +*/ +QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } + + double keyPixel = keyAxis->coordToPixel(it->key); + double highPixel = valueAxis->coordToPixel(it->high); + double lowPixel = valueAxis->coordToPixel(it->low); + double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); + if (keyAxis->orientation() == Qt::Horizontal) + return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); + else + return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); +} +/* end of 'src/plottables/plottable-financial.cpp' */ + + +/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBarsData +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBarsData + \brief Holds the data of one single error bar for QCPErrorBars. + + The stored data is: + \li \a errorMinus: how much the error bar extends towards negative coordinates from the data + point position + \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point + position + + The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a + typedef for QVector<\ref QCPErrorBarsData>. + + \see QCPErrorBarsDataContainer +*/ + +/*! + Constructs an error bar with errors set to zero. +*/ +QCPErrorBarsData::QCPErrorBarsData() : + errorMinus(0), + errorPlus(0) +{ +} + +/*! + Constructs an error bar with equal \a error in both negative and positive direction. +*/ +QCPErrorBarsData::QCPErrorBarsData(double error) : + errorMinus(error), + errorPlus(error) +{ +} + +/*! + Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, + respectively. +*/ +QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : + errorMinus(errorMinus), + errorPlus(errorPlus) +{ +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPErrorBars +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPErrorBars + \brief A plottable that adds a set of error bars to other plottables. + + \image html QCPErrorBars.png + + The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref + QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. + + Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the + error bars. The orientation of the error bars can be controlled with \ref setErrorType. + + By using \ref setData, you can supply the actual error data, either as symmetric error or + plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute + key/value position of each error bar will be adopted from the configured data plottable. The + error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points + of the data plottable. You can directly access and manipulate the error bar data via \ref data. + + Set either of the plus/minus errors to NaN (qQNaN() or + std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at + that index. + + \section qcperrorbars-appearance Changing the appearance + + The appearance of the error bars is defined by the pen (\ref setPen), and the width of the + whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data + point center to prevent that error bars are drawn too close to or even through scatter points. + This gap size can be controlled via \ref setSymbolGap. +*/ + +/* start of documentation of inline functions */ + +/*! \fn QSharedPointer QCPErrorBars::data() const + + Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You + may use it to directly manipulate the error values, which may be more convenient and faster than + using the regular \ref setData methods. +*/ + +/* end of documentation of inline functions */ + +/*! + Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value + axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have + the same orientation. If either of these restrictions is violated, a corresponding message is + printed to the debug output (qDebug), the construction is not aborted, though. + + It is also important that the \a keyAxis and \a valueAxis are the same for the error bars + plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). + + The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred + from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not + delete it manually but use \ref QCustomPlot::removePlottable() instead. +*/ +QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataContainer(new QVector), + mErrorType(etValueError), + mWhiskerWidth(9), + mSymbolGap(10) +{ + setPen(QPen(Qt::black, 0)); + setBrush(Qt::NoBrush); +} + +QCPErrorBars::~QCPErrorBars() +{ +} + +/*! \overload + + Replaces the current data container with the provided \a data container. + + Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data + container safely. Modifying the data in the container will then affect all \ref QCPErrorBars + instances that share the container. Sharing can be achieved by simply exchanging the data + containers wrapped in shared pointers: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 + + If you do not wish to share containers, but create a copy from an existing container, assign the + data containers directly: + \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 + (This uses different notation compared with other plottables, because the \ref QCPErrorBars + uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) + + \see addData +*/ +void QCPErrorBars::setData(QSharedPointer data) +{ + mDataContainer = data; +} + +/*! \overload + + Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &error) +{ + mDataContainer->clear(); + addData(error); +} + +/*! \overload + + Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see addData +*/ +void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) +{ + mDataContainer->clear(); + addData(errorMinus, errorPlus); +} + +/*! + Sets the data plottable to which the error bars will be applied. The error values specified e.g. + via \ref setData will be associated one-to-one by the data point index to the data points of \a + plottable. This means that the error bars will adopt the key/value coordinates of the data point + with the same index. + + The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref + QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either + of these restrictions is violated, a corresponding qDebug output is generated, and the data + plottable of this \ref QCPErrorBars instance is set to zero. + + For proper display, care must also be taken that the key and value axes of the \a plottable match + those configured for this \ref QCPErrorBars instance. +*/ +void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) +{ + if (plottable && qobject_cast(plottable)) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; + return; + } + if (plottable && !plottable->interface1D()) + { + mDataPlottable = 0; + qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; + return; + } + + mDataPlottable = plottable; +} + +/*! + Sets in which orientation the error bars shall appear on the data points. If your data needs both + error dimensions, create two \ref QCPErrorBars with different \a type. +*/ +void QCPErrorBars::setErrorType(ErrorType type) +{ + mErrorType = type; +} + +/*! + Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to + \a pixels. +*/ +void QCPErrorBars::setWhiskerWidth(double pixels) +{ + mWhiskerWidth = pixels; +} + +/*! + Sets the gap diameter around the data points that will be left out when drawing the error bar + backbones. This gap prevents that error bars are drawn too close to or even through scatter + points. +*/ +void QCPErrorBars::setSymbolGap(double pixels) +{ + mSymbolGap = pixels; +} + +/*! \overload + + Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one + by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &error) +{ + addData(error, error); +} + +/*! \overload + + Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be + associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) +{ + if (errorMinus.size() != errorPlus.size()) + qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); + const int n = qMin(errorMinus.size(), errorPlus.size()); + mDataContainer->reserve(n); + for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); +} + +/*! \overload + + Adds a single symmetrical error bar as specified in \a error. The errors will be associated + one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double error) +{ + mDataContainer->append(QCPErrorBarsData(error)); +} + +/*! \overload + + Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors + will be associated one-to-one by the data point index to the associated data plottable (\ref + setDataPlottable). + + You can directly access and manipulate the error bar data via \ref data. + + \see setData +*/ +void QCPErrorBars::addData(double errorMinus, double errorPlus) +{ + mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); +} + +/* inherits documentation from base class */ +int QCPErrorBars::dataCount() const +{ + return mDataContainer->size(); +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataSortKey(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataSortKey(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::dataMainValue(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataMainValue(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::dataValueRange(int index) const +{ + if (mDataPlottable) + { + const double value = mDataPlottable->interface1D()->dataMainValue(index); + if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) + return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); + else + return QCPRange(value, value); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QCPRange(); + } +} + +/* inherits documentation from base class */ +QPointF QCPErrorBars::dataPixelPosition(int index) const +{ + if (mDataPlottable) + return mDataPlottable->interface1D()->dataPixelPosition(index); + else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return QPointF(); +} + +/* inherits documentation from base class */ +bool QCPErrorBars::sortKeyIsMainKey() const +{ + if (mDataPlottable) + { + return mDataPlottable->interface1D()->sortKeyIsMainKey(); + } else + { + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return true; + } +} + +/*! + \copydoc QCPPlottableInterface1D::selectTestRect +*/ +QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +{ + QCPDataSelection result; + if (!mDataPlottable) + return result; + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return result; + if (!mKeyAxis || !mValueAxis) + return result; + + QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; + getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); + + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + { + backbones.clear(); + whiskers.clear(); + getErrorBarLines(it, backbones, whiskers); + for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); + break; + } + } + } + result.simplify(); + return result; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); + if (beginIndex >= mDataContainer->size()) + beginIndex = mDataContainer->size()-1; + return beginIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const +{ + if (mDataPlottable) + { + if (mDataContainer->isEmpty()) + return 0; + int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); + if (endIndex > mDataContainer->size()) + endIndex = mDataContainer->size(); + return endIndex; + } else + qDebug() << Q_FUNC_INFO << "no data plottable set"; + return 0; +} + +/* inherits documentation from base class */ +double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + if (!mDataPlottable) return -1; + + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + return -1; + if (!mKeyAxis || !mValueAxis) + return -1; + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + { + QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); + double result = pointDistance(pos, closestDataPoint); + if (details) + { + int pointIndex = closestDataPoint-mDataContainer->constBegin(); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + } + return result; + } else + return -1; +} + +/* inherits documentation from base class */ +void QCPErrorBars::draw(QCPPainter *painter) +{ + if (!mDataPlottable) return; + if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; + + // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually + // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): + bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); + + // check data validity if flag set: +#ifdef QCUSTOMPLOT_CHECK_DATA + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) + qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); + } +#endif + + applyDefaultAntialiasingHint(painter); + painter->setBrush(Qt::NoBrush); + // loop over and draw segments of unselected/selected data: + QList selectedSegments, unselectedSegments, allSegments; + getDataSegments(selectedSegments, unselectedSegments); + allSegments << unselectedSegments << selectedSegments; + QVector backbones, whiskers; + for (int i=0; i= unselectedSegments.size(); + if (isSelectedSegment && mSelectionDecorator) + mSelectionDecorator->applyPen(painter); + else + painter->setPen(mPen); + if (painter->pen().capStyle() == Qt::SquareCap) + { + QPen capFixPen(painter->pen()); + capFixPen.setCapStyle(Qt::FlatCap); + painter->setPen(capFixPen); + } + backbones.clear(); + whiskers.clear(); + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) + getErrorBarLines(it, backbones, whiskers); + } + painter->drawLines(backbones); + painter->drawLines(whiskers); + } + + // draw other selection decoration that isn't just line/scatter pens and brushes: + if (mSelectionDecorator) + mSelectionDecorator->drawDecoration(painter, selection()); +} + +/* inherits documentation from base class */ +void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +{ + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) + { + painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); + painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); + painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); + } else + { + painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); + painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); + painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); + } +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator it; + for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + { + if (mErrorType == etValueError) + { + // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } else // mErrorType == etKeyError + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (qIsNaN(dataKey)) continue; + // plus error: + double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/* inherits documentation from base class */ +QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +{ + if (!mDataPlottable) + { + foundRange = false; + return QCPRange(); + } + + QCPRange range; + const bool restrictKeyRange = inKeyRange != QCPRange(); + bool haveLower = false; + bool haveUpper = false; + QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); + QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); + if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) + { + itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); + itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); + } + for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + { + if (restrictKeyRange) + { + const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); + if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) + continue; + } + if (mErrorType == etValueError) + { + const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(dataValue)) continue; + // plus error: + double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + // minus error: + current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + } + } else // mErrorType == etKeyError + { + // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center + const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); + if (qIsNaN(current)) continue; + if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + { + if (current < range.lower || !haveLower) + { + range.lower = current; + haveLower = true; + } + if (current > range.upper || !haveUpper) + { + range.upper = current; + haveUpper = true; + } + } + } + } + + if (haveUpper && !haveLower) + { + range.lower = range.upper; + haveLower = true; + } else if (haveLower && !haveUpper) + { + range.upper = range.lower; + haveUpper = true; + } + + foundRange = haveLower && haveUpper; + return range; +} + +/*! \internal + + Calculates the lines that make up the error bar belonging to the data point \a it. + + The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so + calling this method with different \a it but the same \a backbones and \a whiskers allows to + accumulate lines for multiple data points. + + This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars + instance and within the bounds of the associated data plottable. +*/ +void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const +{ + if (!mDataPlottable) return; + + int index = it-mDataContainer->constBegin(); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) + return; + QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); + QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); + const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value + const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); + // plus error: + double errorStart, errorEnd; + if (!qIsNaN(it->errorPlus)) + { + errorStart = centerErrorAxisPixel+symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } + // minus error: + if (!qIsNaN(it->errorMinus)) + { + errorStart = centerErrorAxisPixel-symbolGap; + errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); + if (errorAxis->orientation() == Qt::Vertical) + { + if ((errorStart < errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); + whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); + } else + { + if ((errorStart > errorEnd) != errorAxis->rangeReversed()) + backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); + whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + } + } +} + +/*! \internal + + This method outputs the currently visible data range via \a begin and \a end. The returned range + will also never exceed \a rangeRestriction. + + Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key + coordinates relative to their data point key, this method checks all outer error bars whether + they truly don't reach into the visible portion of the axis rect, by calling \ref + errorBarVisible. On the other hand error bars with type \ref etValueError that are associated + with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype + "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of + error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref + QCPPlottableInterface1D::findEnd). + + If the plottable's sort key is not equal to the main key, this method returns the full data + range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a + point-by-point basis in the \ref draw method. +*/ +void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +{ + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable || rangeRestriction.isEmpty()) + { + end = mDataContainer->constEnd(); + begin = end; + return; + } + if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) + { + // if the sort key isn't the main key, it's not possible to find a contiguous range of visible + // data points, so this method then only applies the range restriction and otherwise returns + // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing + QCPDataRange dataRange(0, mDataContainer->size()); + dataRange = dataRange.bounded(rangeRestriction); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); + return; + } + + // get visible data range via interface from data plottable, and then restrict to available error data points: + const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); + int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); + int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); + int i = beginIndex; + while (i > 0 && i < n && i > rangeRestriction.begin()) + { + if (errorBarVisible(i)) + beginIndex = i; + --i; + } + i = endIndex; + while (i >= 0 && i < n && i < rangeRestriction.end()) + { + if (errorBarVisible(i)) + endIndex = i+1; + ++i; + } + QCPDataRange dataRange(beginIndex, endIndex); + dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); + begin = mDataContainer->constBegin()+dataRange.begin(); + end = mDataContainer->constBegin()+dataRange.end(); +} + +/*! \internal + + Calculates the minimum distance in pixels the error bars' representation has from the given \a + pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref + selectTest. The closest data point to \a pixelPoint is returned in \a closestData. +*/ +double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const +{ + closestData = mDataContainer->constEnd(); + if (!mDataPlottable || mDataContainer->isEmpty()) + return -1.0; + if (!mKeyAxis || !mValueAxis) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1.0; + } + + QCPErrorBarsDataContainer::const_iterator begin, end; + getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); + + // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: + double minDistSqr = std::numeric_limits::max(); + QVector backbones, whiskers; + for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + { + getErrorBarLines(it, backbones, whiskers); + for (int i=0; i &selectedSegments, QList &unselectedSegments) const +{ + selectedSegments.clear(); + unselectedSegments.clear(); + if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + { + if (selected()) + selectedSegments << QCPDataRange(0, dataCount()); + else + unselectedSegments << QCPDataRange(0, dataCount()); + } else + { + QCPDataSelection sel(selection()); + sel.simplify(); + selectedSegments = sel.dataRanges(); + unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + } +} + +/*! \internal + + Returns whether the error bar at the specified \a index is visible within the current key axis + range. + + This method assumes for performance reasons without checking that the key axis, the value axis, + and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid + bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. +*/ +bool QCPErrorBars::errorBarVisible(int index) const +{ + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); + if (qIsNaN(centerKeyPixel)) + return false; + + double keyMin, keyMax; + if (mErrorType == etKeyError) + { + const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); + const double errorPlus = mDataContainer->at(index).errorPlus; + const double errorMinus = mDataContainer->at(index).errorMinus; + keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); + keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); + } else // mErrorType == etValueError + { + keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + } + return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); +} + +/*! \internal + + Returns whether \a line intersects (or is contained in) \a pixelRect. + + \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for + error bar lines. +*/ +bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const +{ + if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) + return false; + else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) + return false; + else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) + return false; + else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) + return false; + else + return true; +} +/* end of 'src/plottables/plottable-errorbar.cpp' */ + + +/* including file 'src/items/item-straightline.cpp', size 7592 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemStraightLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemStraightLine + \brief A straight line that spans infinitely in both directions + + \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a point1 and \a point2, which define the straight line. +*/ + +/*! + Creates a straight line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + point1(createPosition(QLatin1String("point1"))), + point2(createPosition(QLatin1String("point2"))) +{ + point1->setCoords(0, 0); + point2->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemStraightLine::~QCPItemStraightLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemStraightLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemStraightLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); +} + +/* inherits documentation from base class */ +void QCPItemStraightLine::draw(QCPPainter *painter) +{ + QCPVector2D start(point1->pixelPosition()); + QCPVector2D end(point2->pixelPosition()); + // get visible segment of straight line inside clipRect: + double clipPad = mainPen().widthF(); + QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + } +} + +/*! \internal + + Returns the section of the straight line defined by \a base and direction vector \a + vec, that is visible in the specified \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const +{ + double bx, by; + double gamma; + QLineF result; + if (vec.x() == 0 && vec.y() == 0) + return result; + if (qFuzzyIsNull(vec.x())) // line is vertical + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical + } else if (qFuzzyIsNull(vec.y())) // line is horizontal + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal + } else // line is skewed + { + QList pointVectors; + // check top of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + // check left of rect: + bx = rect.left(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + // check right of rect: + bx = rect.right(); + by = rect.top(); + gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemStraightLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-straightline.cpp' */ + + +/* including file 'src/items/item-line.cpp', size 8498 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemLine +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemLine + \brief A line from one point to another + + \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a start and \a end, which define the end points of the line. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. +*/ + +/*! + Creates a line item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemLine::~QCPItemLine() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemLine::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemLine::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemLine::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemLine::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); +} + +/* inherits documentation from base class */ +void QCPItemLine::draw(QCPPainter *painter) +{ + QCPVector2D startVec(start->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if (qFuzzyIsNull((startVec-endVec).lengthSquared())) + return; + // get visible segment of straight line inside clipRect: + double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); + clipPad = qMax(clipPad, (double)mainPen().widthF()); + QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + // paint visible segment, if existent: + if (!line.isNull()) + { + painter->setPen(mainPen()); + painter->drawLine(line); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, startVec-endVec); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, endVec-startVec); + } +} + +/*! \internal + + Returns the section of the line defined by \a start and \a end, that is visible in the specified + \a rect. + + This is a helper function for \ref draw. +*/ +QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const +{ + bool containsStart = rect.contains(start.x(), start.y()); + bool containsEnd = rect.contains(end.x(), end.y()); + if (containsStart && containsEnd) + return QLineF(start.toPointF(), end.toPointF()); + + QCPVector2D base = start; + QCPVector2D vec = end-start; + double bx, by; + double gamma, mu; + QLineF result; + QList pointVectors; + + if (!qFuzzyIsNull(vec.y())) // line is not horizontal + { + // check top of rect: + bx = rect.left(); + by = rect.top(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + // check bottom of rect: + bx = rect.left(); + by = rect.bottom(); + mu = (by-base.y())/vec.y(); + if (mu >= 0 && mu <= 1) + { + gamma = base.x()-bx + mu*vec.x(); + if (gamma >= 0 && gamma <= rect.width()) + pointVectors.append(QCPVector2D(bx+gamma, by)); + } + } + if (!qFuzzyIsNull(vec.x())) // line is not vertical + { + // check left of rect: + bx = rect.left(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + // check right of rect: + bx = rect.right(); + by = rect.top(); + mu = (bx-base.x())/vec.x(); + if (mu >= 0 && mu <= 1) + { + gamma = base.y()-by + mu*vec.y(); + if (gamma >= 0 && gamma <= rect.height()) + pointVectors.append(QCPVector2D(bx, by+gamma)); + } + } + + if (containsStart) + pointVectors.append(start); + if (containsEnd) + pointVectors.append(end); + + // evaluate points: + if (pointVectors.size() == 2) + { + result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); + } else if (pointVectors.size() > 2) + { + // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: + double distSqrMax = 0; + QCPVector2D pv1, pv2; + for (int i=0; i distSqrMax) + { + pv1 = pointVectors.at(i); + pv2 = pointVectors.at(k); + distSqrMax = distSqr; + } + } + } + result.setPoints(pv1.toPointF(), pv2.toPointF()); + } + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemLine::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-line.cpp' */ + + +/* including file 'src/items/item-curve.cpp', size 7159 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemCurve +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemCurve + \brief A curved line from one point to another + + \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." + + It has four positions, \a start and \a end, which define the end points of the line, and two + control points which define the direction the line exits from the start and the direction from + which it approaches the end: \a startDir and \a endDir. + + With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an + arrow. + + Often it is desirable for the control points to stay at fixed relative positions to the start/end + point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, + and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. +*/ + +/*! + Creates a curve item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + start(createPosition(QLatin1String("start"))), + startDir(createPosition(QLatin1String("startDir"))), + endDir(createPosition(QLatin1String("endDir"))), + end(createPosition(QLatin1String("end"))) +{ + start->setCoords(0, 0); + startDir->setCoords(0.5, 0); + endDir->setCoords(0, 0.5); + end->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); +} + +QCPItemCurve::~QCPItemCurve() +{ +} + +/*! + Sets the pen that will be used to draw the line + + \see setSelectedPen +*/ +void QCPItemCurve::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line when selected + + \see setPen, setSelected +*/ +void QCPItemCurve::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the line ending style of the head. The head corresponds to the \a end position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode + + \see setTail +*/ +void QCPItemCurve::setHead(const QCPLineEnding &head) +{ + mHead = head; +} + +/*! + Sets the line ending style of the tail. The tail corresponds to the \a start position. + + Note that due to the overloaded QCPLineEnding constructor, you may directly specify + a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode + + \see setHead +*/ +void QCPItemCurve::setTail(const QCPLineEnding &tail) +{ + mTail = tail; +} + +/* inherits documentation from base class */ +double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF startVec(start->pixelPosition()); + QPointF startDirVec(startDir->pixelPosition()); + QPointF endDirVec(endDir->pixelPosition()); + QPointF endVec(end->pixelPosition()); + + QPainterPath cubicPath(startVec); + cubicPath.cubicTo(startDirVec, endDirVec, endVec); + + QPolygonF polygon = cubicPath.toSubpathPolygons().first(); + QCPVector2D p(pos); + double minDistSqr = std::numeric_limits::max(); + for (int i=1; ipixelPosition()); + QCPVector2D startDirVec(startDir->pixelPosition()); + QCPVector2D endDirVec(endDir->pixelPosition()); + QCPVector2D endVec(end->pixelPosition()); + if ((endVec-startVec).length() > 1e10) // too large curves cause crash + return; + + QPainterPath cubicPath(startVec.toPointF()); + cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); + + // paint visible segment, if existent: + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + QRect cubicRect = cubicPath.controlPointRect().toRect(); + if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position + cubicRect.adjust(0, 0, 1, 1); + if (clip.intersects(cubicRect)) + { + painter->setPen(mainPen()); + painter->drawPath(cubicPath); + painter->setBrush(Qt::SolidPattern); + if (mTail.style() != QCPLineEnding::esNone) + mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); + if (mHead.style() != QCPLineEnding::esNone) + mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemCurve::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-curve.cpp' */ + + +/* including file 'src/items/item-rect.cpp', size 6479 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemRect +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemRect + \brief A rectangle + + \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue,2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemRect::~QCPItemRect() +{ +} + +/*! + Sets the pen that will be used to draw the line of the rectangle + + \see setSelectedPen, setBrush +*/ +void QCPItemRect::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the rectangle when selected + + \see setPen, setSelected +*/ +void QCPItemRect::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemRect::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemRect::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); +} + +/* inherits documentation from base class */ +void QCPItemRect::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF rect = QRectF(p1, p2).normalized(); + double clipPad = mainPen().widthF(); + QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(rect); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemRect::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemRect::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemRect::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-rect.cpp' */ + + +/* including file 'src/items/item-text.cpp', size 13338 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemText +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemText + \brief A text label + + \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." + + Its position is defined by the member \a position and the setting of \ref setPositionAlignment. + The latter controls which part of the text rect shall be aligned with \a position. + + The text alignment itself (i.e. left, center, right) can be controlled with \ref + setTextAlignment. + + The text may be rotated around the \a position point with \ref setRotation. +*/ + +/*! + Creates a text item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemText::QCPItemText(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mText(QLatin1String("text")), + mPositionAlignment(Qt::AlignCenter), + mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), + mRotation(0) +{ + position->setCoords(0, 0); + + setPen(Qt::NoPen); + setSelectedPen(Qt::NoPen); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setColor(Qt::black); + setSelectedColor(Qt::blue); +} + +QCPItemText::~QCPItemText() +{ +} + +/*! + Sets the color of the text. +*/ +void QCPItemText::setColor(const QColor &color) +{ + mColor = color; +} + +/*! + Sets the color of the text that will be used when the item is selected. +*/ +void QCPItemText::setSelectedColor(const QColor &color) +{ + mSelectedColor = color; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text. To disable the + border, set \a pen to Qt::NoPen. + + \see setSelectedPen, setBrush, setPadding +*/ +void QCPItemText::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used do draw a rectangular border around the text, when the item is + selected. To disable the border, set \a pen to Qt::NoPen. + + \see setPen +*/ +void QCPItemText::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used do fill the background of the text. To disable the + background, set \a brush to Qt::NoBrush. + + \see setSelectedBrush, setPen, setPadding +*/ +void QCPItemText::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the + background, set \a brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemText::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the font of the text. + + \see setSelectedFont, setColor +*/ +void QCPItemText::setFont(const QFont &font) +{ + mFont = font; +} + +/*! + Sets the font of the text that will be used when the item is selected. + + \see setFont +*/ +void QCPItemText::setSelectedFont(const QFont &font) +{ + mSelectedFont = font; +} + +/*! + Sets the text that will be displayed. Multi-line texts are supported by inserting a line break + character, e.g. '\n'. + + \see setFont, setColor, setTextAlignment +*/ +void QCPItemText::setText(const QString &text) +{ + mText = text; +} + +/*! + Sets which point of the text rect shall be aligned with \a position. + + Examples: + \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such + that the top of the text rect will be horizontally centered on \a position. + \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the + bottom left corner of the text rect. + + If you want to control the alignment of (multi-lined) text within the text rect, use \ref + setTextAlignment. +*/ +void QCPItemText::setPositionAlignment(Qt::Alignment alignment) +{ + mPositionAlignment = alignment; +} + +/*! + Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). +*/ +void QCPItemText::setTextAlignment(Qt::Alignment alignment) +{ + mTextAlignment = alignment; +} + +/*! + Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated + around \a position. +*/ +void QCPItemText::setRotation(double degrees) +{ + mRotation = degrees; +} + +/*! + Sets the distance between the border of the text rectangle and the text. The appearance (and + visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. +*/ +void QCPItemText::setPadding(const QMargins &padding) +{ + mPadding = padding; +} + +/* inherits documentation from base class */ +double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + // The rect may be rotated, so we transform the actual clicked pos to the rotated + // coordinate system, so we can use the normal rectDistance function for non-rotated rects: + QPointF positionPixels(position->pixelPosition()); + QTransform inputTransform; + inputTransform.translate(positionPixels.x(), positionPixels.y()); + inputTransform.rotate(-mRotation); + inputTransform.translate(-positionPixels.x(), -positionPixels.y()); + QPointF rotatedPos = inputTransform.map(pos); + QFontMetrics fontMetrics(mFont); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); + textBoxRect.moveTopLeft(textPos.toPoint()); + + return rectDistance(textBoxRect, rotatedPos, true); +} + +/* inherits documentation from base class */ +void QCPItemText::draw(QCPPainter *painter) +{ + QPointF pos(position->pixelPosition()); + QTransform transform = painter->transform(); + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + painter->setFont(mainFont()); + QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); + textBoxRect.moveTopLeft(textPos.toPoint()); + double clipPad = mainPen().widthF(); + QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) + { + painter->setTransform(transform); + if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || + (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + painter->drawRect(textBoxRect); + } + painter->setBrush(Qt::NoBrush); + painter->setPen(QPen(mainColor())); + painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); + } +} + +/* inherits documentation from base class */ +QPointF QCPItemText::anchorPixelPosition(int anchorId) const +{ + // get actual rect points (pretty much copied from draw function): + QPointF pos(position->pixelPosition()); + QTransform transform; + transform.translate(pos.x(), pos.y()); + if (!qFuzzyIsNull(mRotation)) + transform.rotate(mRotation); + QFontMetrics fontMetrics(mainFont()); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); + QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); + QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation + textBoxRect.moveTopLeft(textPos.toPoint()); + QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); + + switch (anchorId) + { + case aiTopLeft: return rectPoly.at(0); + case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; + case aiTopRight: return rectPoly.at(1); + case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; + case aiBottomRight: return rectPoly.at(2); + case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; + case aiBottomLeft: return rectPoly.at(3); + case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the point that must be given to the QPainter::drawText function (which expects the top + left point of the text rect), according to the position \a pos, the text bounding box \a rect and + the requested \a positionAlignment. + + For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point + will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally + drawn at that point, the lower left corner of the resulting text rect is at \a pos. +*/ +QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const +{ + if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) + return pos; + + QPointF result = pos; // start at top left + if (positionAlignment.testFlag(Qt::AlignHCenter)) + result.rx() -= rect.width()/2.0; + else if (positionAlignment.testFlag(Qt::AlignRight)) + result.rx() -= rect.width(); + if (positionAlignment.testFlag(Qt::AlignVCenter)) + result.ry() -= rect.height()/2.0; + else if (positionAlignment.testFlag(Qt::AlignBottom)) + result.ry() -= rect.height(); + return result; +} + +/*! \internal + + Returns the font that should be used for drawing text. Returns mFont when the item is not selected + and mSelectedFont when it is. +*/ +QFont QCPItemText::mainFont() const +{ + return mSelected ? mSelectedFont : mFont; +} + +/*! \internal + + Returns the color that should be used for drawing text. Returns mColor when the item is not + selected and mSelectedColor when it is. +*/ +QColor QCPItemText::mainColor() const +{ + return mSelected ? mSelectedColor : mColor; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemText::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemText::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-text.cpp' */ + + +/* including file 'src/items/item-ellipse.cpp', size 7863 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemEllipse +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemEllipse + \brief An ellipse + + \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. +*/ + +/*! + Creates an ellipse item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), + top(createAnchor(QLatin1String("top"), aiTop)), + topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), + left(createAnchor(QLatin1String("left"), aiLeft)), + center(createAnchor(QLatin1String("center"), aiCenter)) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); +} + +QCPItemEllipse::~QCPItemEllipse() +{ +} + +/*! + Sets the pen that will be used to draw the line of the ellipse + + \see setSelectedPen, setBrush +*/ +void QCPItemEllipse::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the ellipse when selected + + \see setPen, setSelected +*/ +void QCPItemEllipse::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to + Qt::NoBrush. + + \see setSelectedBrush, setPen +*/ +void QCPItemEllipse::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a + brush to Qt::NoBrush. + + \see setBrush +*/ +void QCPItemEllipse::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/* inherits documentation from base class */ +double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + QPointF center((p1+p2)/2.0); + double a = qAbs(p1.x()-p2.x())/2.0; + double b = qAbs(p1.y()-p2.y())/2.0; + double x = pos.x()-center.x(); + double y = pos.y()-center.y(); + + // distance to border: + double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); + double result = qAbs(c-1)*qSqrt(x*x+y*y); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (x*x/(a*a) + y*y/(b*b) <= 1) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; +} + +/* inherits documentation from base class */ +void QCPItemEllipse::draw(QCPPainter *painter) +{ + QPointF p1 = topLeft->pixelPosition(); + QPointF p2 = bottomRight->pixelPosition(); + if (p1.toPoint() == p2.toPoint()) + return; + QRectF ellipseRect = QRectF(p1, p2).normalized(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect + { + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); +#ifdef __EXCEPTIONS + try // drawEllipse sometimes throws exceptions if ellipse is too big + { +#endif + painter->drawEllipse(ellipseRect); +#ifdef __EXCEPTIONS + } catch (...) + { + qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; + setVisible(false); + } +#endif + } +} + +/* inherits documentation from base class */ +QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const +{ + QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); + switch (anchorId) + { + case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemEllipse::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemEllipse::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-ellipse.cpp' */ + + +/* including file 'src/items/item-pixmap.cpp', size 10615 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemPixmap +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemPixmap + \brief An arbitrary pixmap + + \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will + be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to + fit the rectangle or be drawn aligned to the topLeft position. + + If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown + on the right side of the example image), the pixmap will be flipped in the respective + orientations. +*/ + +/*! + Creates a rectangle item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + topLeft(createPosition(QLatin1String("topLeft"))), + bottomRight(createPosition(QLatin1String("bottomRight"))), + top(createAnchor(QLatin1String("top"), aiTop)), + topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), + right(createAnchor(QLatin1String("right"), aiRight)), + bottom(createAnchor(QLatin1String("bottom"), aiBottom)), + bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), + left(createAnchor(QLatin1String("left"), aiLeft)), + mScaled(false), + mScaledPixmapInvalidated(true), + mAspectRatioMode(Qt::KeepAspectRatio), + mTransformationMode(Qt::SmoothTransformation) +{ + topLeft->setCoords(0, 1); + bottomRight->setCoords(1, 0); + + setPen(Qt::NoPen); + setSelectedPen(QPen(Qt::blue)); +} + +QCPItemPixmap::~QCPItemPixmap() +{ +} + +/*! + Sets the pixmap that will be displayed. +*/ +void QCPItemPixmap::setPixmap(const QPixmap &pixmap) +{ + mPixmap = pixmap; + mScaledPixmapInvalidated = true; + if (mPixmap.isNull()) + qDebug() << Q_FUNC_INFO << "pixmap is null"; +} + +/*! + Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a + bottomRight positions. +*/ +void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) +{ + mScaled = scaled; + mAspectRatioMode = aspectRatioMode; + mTransformationMode = transformationMode; + mScaledPixmapInvalidated = true; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap. + + \see setSelectedPen, setBrush +*/ +void QCPItemPixmap::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw a border around the pixmap when selected + + \see setPen, setSelected +*/ +void QCPItemPixmap::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/* inherits documentation from base class */ +double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + return rectDistance(getFinalRect(), pos, true); +} + +/* inherits documentation from base class */ +void QCPItemPixmap::draw(QCPPainter *painter) +{ + bool flipHorz = false; + bool flipVert = false; + QRect rect = getFinalRect(&flipHorz, &flipVert); + double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); + QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); + if (boundingRect.intersects(clipRect())) + { + updateScaledPixmap(rect, flipHorz, flipVert); + painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); + QPen pen = mainPen(); + if (pen.style() != Qt::NoPen) + { + painter->setPen(pen); + painter->setBrush(Qt::NoBrush); + painter->drawRect(rect); + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const +{ + bool flipHorz; + bool flipVert; + QRect rect = getFinalRect(&flipHorz, &flipVert); + // we actually want denormal rects (negative width/height) here, so restore + // the flipped state: + if (flipHorz) + rect.adjust(rect.width(), 0, -rect.width(), 0); + if (flipVert) + rect.adjust(0, rect.height(), 0, -rect.height()); + + switch (anchorId) + { + case aiTop: return (rect.topLeft()+rect.topRight())*0.5; + case aiTopRight: return rect.topRight(); + case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; + case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; + case aiBottomLeft: return rect.bottomLeft(); + case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; + } + + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The + parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped + horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a + bottomRight.) + + This function only creates the scaled pixmap when the buffered pixmap has a different size than + the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does + not cause expensive rescaling every time. + + If scaling is disabled, sets mScaledPixmap to a null QPixmap. +*/ +void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) +{ + if (mPixmap.isNull()) + return; + + if (mScaled) + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + double devicePixelRatio = mPixmap.devicePixelRatio(); +#else + double devicePixelRatio = 1.0; +#endif + if (finalRect.isNull()) + finalRect = getFinalRect(&flipHorz, &flipVert); + if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) + { + mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); + if (flipHorz || flipVert) + mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + mScaledPixmap.setDevicePixelRatio(devicePixelRatio); +#endif + } + } else if (!mScaledPixmap.isNull()) + mScaledPixmap = QPixmap(); + mScaledPixmapInvalidated = false; +} + +/*! \internal + + Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions + and scaling settings. + + The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn + flipped horizontally or vertically in the returned rect. (The returned rect itself is always + normalized, i.e. the top left corner of the rect is actually further to the top/left than the + bottom right corner). This is the case when the item position \a topLeft is further to the + bottom/right than \a bottomRight. + + If scaling is disabled, returns a rect with size of the original pixmap and the top left corner + aligned with the item position \a topLeft. The position \a bottomRight is ignored. +*/ +QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const +{ + QRect result; + bool flipHorz = false; + bool flipVert = false; + QPoint p1 = topLeft->pixelPosition().toPoint(); + QPoint p2 = bottomRight->pixelPosition().toPoint(); + if (p1 == p2) + return QRect(p1, QSize(0, 0)); + if (mScaled) + { + QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); + QPoint topLeft = p1; + if (newSize.width() < 0) + { + flipHorz = true; + newSize.rwidth() *= -1; + topLeft.setX(p2.x()); + } + if (newSize.height() < 0) + { + flipVert = true; + newSize.rheight() *= -1; + topLeft.setY(p2.y()); + } + QSize scaledSize = mPixmap.size(); +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + scaledSize /= mPixmap.devicePixelRatio(); + scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); +#else + scaledSize.scale(newSize, mAspectRatioMode); +#endif + result = QRect(topLeft, scaledSize); + } else + { +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED + result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); +#else + result = QRect(p1, mPixmap.size()); +#endif + } + if (flippedHorz) + *flippedHorz = flipHorz; + if (flippedVert) + *flippedVert = flipVert; + return result; +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemPixmap::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-pixmap.cpp' */ + + +/* including file 'src/items/item-tracer.cpp', size 14624 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemTracer +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemTracer + \brief Item that sticks to QCPGraph data points + + \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." + + The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt + the coordinate axes of the graph and update its \a position to be on the graph's data. This means + the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a + QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a + position will have no effect because they will be overriden in the next redraw (this is when the + coordinate update happens). + + If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will + stay at the corresponding end of the graph. + + With \ref setInterpolating you may specify whether the tracer may only stay exactly on data + points or whether it interpolates data points linearly, if given a key that lies between two data + points of the graph. + + The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer + have no own visual appearance (set the style to \ref tsNone), and just connect other item + positions to the tracer \a position (used as an anchor) via \ref + QCPItemPosition::setParentAnchor. + + \note The tracer position is only automatically updated upon redraws. So when the data of the + graph changes and immediately afterwards (without a redraw) the position coordinates of the + tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref + updatePosition must be called manually, prior to reading the tracer coordinates. +*/ + +/*! + Creates a tracer item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + mSize(6), + mStyle(tsCrosshair), + mGraph(0), + mGraphKey(0), + mInterpolating(false) +{ + position->setCoords(0, 0); + + setBrush(Qt::NoBrush); + setSelectedBrush(Qt::NoBrush); + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemTracer::~QCPItemTracer() +{ +} + +/*! + Sets the pen that will be used to draw the line of the tracer + + \see setSelectedPen, setBrush +*/ +void QCPItemTracer::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the line of the tracer when selected + + \see setPen, setSelected +*/ +void QCPItemTracer::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer + + \see setSelectedBrush, setPen +*/ +void QCPItemTracer::setBrush(const QBrush &brush) +{ + mBrush = brush; +} + +/*! + Sets the brush that will be used to draw any fills of the tracer, when selected. + + \see setBrush, setSelected +*/ +void QCPItemTracer::setSelectedBrush(const QBrush &brush) +{ + mSelectedBrush = brush; +} + +/*! + Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare + does, \ref tsCrosshair does not). +*/ +void QCPItemTracer::setSize(double size) +{ + mSize = size; +} + +/*! + Sets the style/visual appearance of the tracer. + + If you only want to use the tracer \a position as an anchor for other items, set \a style to + \ref tsNone. +*/ +void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) +{ + mStyle = style; +} + +/*! + Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type + QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. + + To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed + freely like any other item position. This is the state the tracer will assume when its graph gets + deleted while still attached to it. + + \see setGraphKey +*/ +void QCPItemTracer::setGraph(QCPGraph *graph) +{ + if (graph) + { + if (graph->parentPlot() == mParentPlot) + { + position->setType(QCPItemPosition::ptPlotCoords); + position->setAxes(graph->keyAxis(), graph->valueAxis()); + mGraph = graph; + updatePosition(); + } else + qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; + } else + { + mGraph = 0; + } +} + +/*! + Sets the key of the graph's data point the tracer will be positioned at. This is the only free + coordinate of a tracer when attached to a graph. + + Depending on \ref setInterpolating, the tracer will be either positioned on the data point + closest to \a key, or will stay exactly at \a key and interpolate the value linearly. + + \see setGraph, setInterpolating +*/ +void QCPItemTracer::setGraphKey(double key) +{ + mGraphKey = key; +} + +/*! + Sets whether the value of the graph's data points shall be interpolated, when positioning the + tracer. + + If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on + the data point of the graph which is closest to the key, but which is not necessarily exactly + there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and + the appropriate value will be interpolated from the graph's data points linearly. + + \see setGraph, setGraphKey +*/ +void QCPItemTracer::setInterpolating(bool enabled) +{ + mInterpolating = enabled; +} + +/* inherits documentation from base class */ +double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return -1; + case tsPlus: + { + if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), + QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); + break; + } + case tsCrosshair: + { + return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), + QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + // distance to border: + double centerDist = QCPVector2D(center-pos).length(); + double circleLine = w; + double result = qAbs(centerDist-circleLine); + // filled ellipse, allow click inside to count as hit: + if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + { + if (centerDist <= circleLine) + result = mParentPlot->selectionTolerance()*0.99; + } + return result; + } + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance(rect, pos, filledRect); + } + break; + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemTracer::draw(QCPPainter *painter) +{ + updatePosition(); + if (mStyle == tsNone) + return; + + painter->setPen(mainPen()); + painter->setBrush(mainBrush()); + QPointF center(position->pixelPosition()); + double w = mSize/2.0; + QRect clip = clipRect(); + switch (mStyle) + { + case tsNone: return; + case tsPlus: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + { + painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); + painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); + } + break; + } + case tsCrosshair: + { + if (center.y() > clip.top() && center.y() < clip.bottom()) + painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); + if (center.x() > clip.left() && center.x() < clip.right()) + painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); + break; + } + case tsCircle: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawEllipse(center, w, w); + break; + } + case tsSquare: + { + if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); + break; + } + } +} + +/*! + If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a + position to reside on the graph data, depending on the configured key (\ref setGraphKey). + + It is called automatically on every redraw and normally doesn't need to be called manually. One + exception is when you want to read the tracer coordinates via \a position and are not sure that + the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. + In that situation, call this function before accessing \a position, to make sure you don't get + out-of-date coordinates. + + If there is no graph set on this tracer, this function does nothing. +*/ +void QCPItemTracer::updatePosition() +{ + if (mGraph) + { + if (mParentPlot->hasPlottable(mGraph)) + { + if (mGraph->data()->size() > 1) + { + QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); + QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; + if (mGraphKey <= first->key) + position->setCoords(first->key, first->value); + else if (mGraphKey >= last->key) + position->setCoords(last->key, last->value); + else + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); + if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators + { + QCPGraphDataContainer::const_iterator prevIt = it; + ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before + if (mInterpolating) + { + // interpolate between iterators around mGraphKey: + double slope = 0; + if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) + slope = (it->value-prevIt->value)/(it->key-prevIt->key); + position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); + } else + { + // find iterator with key closest to mGraphKey: + if (mGraphKey < (prevIt->key+it->key)*0.5) + position->setCoords(prevIt->key, prevIt->value); + else + position->setCoords(it->key, it->value); + } + } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) + position->setCoords(it->key, it->value); + } + } else if (mGraph->data()->size() == 1) + { + QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); + position->setCoords(it->key, it->value); + } else + qDebug() << Q_FUNC_INFO << "graph has no data"; + } else + qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; + } +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected + and mSelectedPen when it is. +*/ +QPen QCPItemTracer::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} + +/*! \internal + + Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item + is not selected and mSelectedBrush when it is. +*/ +QBrush QCPItemTracer::mainBrush() const +{ + return mSelected ? mSelectedBrush : mBrush; +} +/* end of 'src/items/item-tracer.cpp' */ + + +/* including file 'src/items/item-bracket.cpp', size 10687 */ +/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////// QCPItemBracket +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*! \class QCPItemBracket + \brief A bracket for referencing/highlighting certain parts in the plot. + + \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." + + It has two positions, \a left and \a right, which define the span of the bracket. If \a left is + actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the + example image. + + The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket + stretches away from the embraced span, can be controlled with \ref setLength. + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+ + It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine + or QCPItemCurve) or a text label (QCPItemText), to the bracket. +*/ + +/*! + Creates a bracket item and sets default values. + + The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes + ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. +*/ +QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + left(createPosition(QLatin1String("left"))), + right(createPosition(QLatin1String("right"))), + center(createAnchor(QLatin1String("center"), aiCenter)), + mLength(8), + mStyle(bsCalligraphic) +{ + left->setCoords(0, 0); + right->setCoords(1, 1); + + setPen(QPen(Qt::black)); + setSelectedPen(QPen(Qt::blue, 2)); +} + +QCPItemBracket::~QCPItemBracket() +{ +} + +/*! + Sets the pen that will be used to draw the bracket. + + Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the + stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use + \ref setLength, which has a similar effect. + + \see setSelectedPen +*/ +void QCPItemBracket::setPen(const QPen &pen) +{ + mPen = pen; +} + +/*! + Sets the pen that will be used to draw the bracket when selected + + \see setPen, setSelected +*/ +void QCPItemBracket::setSelectedPen(const QPen &pen) +{ + mSelectedPen = pen; +} + +/*! + Sets the \a length in pixels how far the bracket extends in the direction towards the embraced + span of the bracket (i.e. perpendicular to the left-right-direction) + + \image html QCPItemBracket-length.png +
Demonstrating the effect of different values for \ref setLength, for styles \ref + bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
+*/ +void QCPItemBracket::setLength(double length) +{ + mLength = length; +} + +/*! + Sets the style of the bracket, i.e. the shape/visual appearance. + + \see setPen +*/ +void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) +{ + mStyle = style; +} + +/* inherits documentation from base class */ +double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +{ + Q_UNUSED(details) + if (onlySelectable && !mSelectable) + return -1; + + QCPVector2D p(pos); + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return -1; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (mStyle) + { + case QCPItemBracket::bsSquare: + case QCPItemBracket::bsRound: + { + double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); + double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); + return qSqrt(qMin(qMin(a, b), c)); + } + case QCPItemBracket::bsCurly: + case QCPItemBracket::bsCalligraphic: + { + double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); + double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); + double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); + return qSqrt(qMin(qMin(a, b), qMin(c, d))); + } + } + return -1; +} + +/* inherits documentation from base class */ +void QCPItemBracket::draw(QCPPainter *painter) +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return; + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + QPolygon boundingPoly; + boundingPoly << leftVec.toPoint() << rightVec.toPoint() + << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); + QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + if (clip.intersects(boundingPoly.boundingRect())) + { + painter->setPen(mainPen()); + switch (mStyle) + { + case bsSquare: + { + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); + painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + break; + } + case bsRound: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCurly: + { + painter->setBrush(Qt::NoBrush); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + painter->drawPath(path); + break; + } + case bsCalligraphic: + { + painter->setPen(Qt::NoPen); + painter->setBrush(QBrush(mainPen().color())); + QPainterPath path; + path.moveTo((centerVec+widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); + path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); + + path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); + path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); + + painter->drawPath(path); + break; + } + } + } +} + +/* inherits documentation from base class */ +QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const +{ + QCPVector2D leftVec(left->pixelPosition()); + QCPVector2D rightVec(right->pixelPosition()); + if (leftVec.toPoint() == rightVec.toPoint()) + return leftVec.toPointF(); + + QCPVector2D widthVec = (rightVec-leftVec)*0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; + QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + switch (anchorId) + { + case aiCenter: + return centerVec.toPointF(); + } + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; + return QPointF(); +} + +/*! \internal + + Returns the pen that should be used for drawing lines. Returns mPen when the + item is not selected and mSelectedPen when it is. +*/ +QPen QCPItemBracket::mainPen() const +{ + return mSelected ? mSelectedPen : mPen; +} +/* end of 'src/items/item-bracket.cpp' */ + + From ca89d22128723b423d8de52168818fbbe7e6d9c4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:33:49 -0400 Subject: [PATCH 0797/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 4a367c48..184b7d7a 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), - socialAction(0), + mainWindow(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -618,10 +618,10 @@ void BitcoinGUI::createActions() connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTH Chat - socialAction = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - socialAction->setStatusTip(tr("HTH World Social Media")); + mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + mainWindow->setStatusTip(tr("HTH World Social Media")); // HTHW Chat - connect(socialAction, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); // Jump directly to tabs in RPC-console @@ -725,7 +725,7 @@ void BitcoinGUI::createMenuBar() donate->addAction(externalDonate); QMenu *social = appMenuBar->addMenu(tr("&HTH World")); - social->addAction(socialAction); + social->addAction(mainWindow); } @@ -1055,7 +1055,7 @@ void BitcoinGUI::openClicked() void BitcoinGUI::gotoMainWindow() { - socialAction->setChecked(true); + mainWindow->setChecked(true); if (walletFrame) walletFrame->gotoMainWindow(); } From b3dab6ff8c7a7dbb3bacefd91baa94b50d4ee0b6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:36:04 -0400 Subject: [PATCH 0798/1324] Update qcustomplot.h --- src/qt/qcustomplot.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index 916c3522..ba91eea1 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -267,7 +267,7 @@ Q_DECLARE_FLAGS(Interactions, Interaction) enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) - ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. + ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's Q_SIGNALS (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. }; /*! @@ -722,7 +722,7 @@ class QCP_LIB_DECL QCPLayerable : public QObject // non-property methods: bool realVisibility() const; -QSIGNALS: +Q_SIGNALS: void layerChanged(QCPLayer *newLayer); protected: @@ -1112,7 +1112,7 @@ class QCP_LIB_DECL QCPSelectionRect : public QCPLayerable // non-property methods: Q_SLOT void cancel(); -QSIGNALS: +Q_SIGNALS: void started(QMouseEvent *event); void changed(const QRect &rect, QMouseEvent *event); void canceled(const QRect &rect, QInputEvent *event); @@ -2115,7 +2115,7 @@ class QCP_LIB_DECL QCPAxis : public QCPLayerable static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } static AxisType opposite(AxisType type); -QSIGNALS: +Q_SIGNALS: void rangeChanged(const QCPRange &newRange); void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); void scaleTypeChanged(QCPAxis::ScaleType scaleType); @@ -3347,7 +3347,7 @@ class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable bool removeFromLegend(QCPLegend *legend) const; bool removeFromLegend() const; -QSIGNALS: +Q_SIGNALS: void selectionChanged(bool selected); void selectionChanged(const QCPDataSelection &selection); void selectableChanged(QCP::SelectionType selectable); @@ -3537,7 +3537,7 @@ class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable QCPItemAnchor *anchor(const QString &name) const; bool hasAnchor(const QString &name) const; -QSIGNALS: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -3731,7 +3731,7 @@ class QCP_LIB_DECL QCustomPlot : public QWidget QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; QCPLegend *legend; -QSIGNALS: +Q_SIGNALS: void mouseDoubleClick(QMouseEvent *event); void mousePress(QMouseEvent *event); void mouseMove(QMouseEvent *event); @@ -4740,7 +4740,7 @@ class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement // reimplemented virtual methods: virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; -QSIGNALS: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); @@ -4877,7 +4877,7 @@ class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid void clearItems(); QList selectedItems() const; -QSIGNALS: +Q_SIGNALS: void selectionChanged(QCPLegend::SelectableParts parts); void selectableChanged(QCPLegend::SelectableParts parts); @@ -4968,7 +4968,7 @@ class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; -signals: +Q_SIGNALS: void selectionChanged(bool selected); void selectableChanged(bool selectable); void clicked(QMouseEvent *event); @@ -5080,7 +5080,7 @@ class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement // reimplemented virtual methods: virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; -QSIGNALS: +Q_SIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); @@ -5776,7 +5776,7 @@ class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; -QSIGNALS: +Q_SIGNALS: void dataRangeChanged(const QCPRange &newRange); void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); void gradientChanged(const QCPColorGradient &newGradient); @@ -6659,4 +6659,3 @@ Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) #endif // QCUSTOMPLOT_H - From d38912e0b0d336c0c8b3210c07bae2f13d2e3bd8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:37:52 -0400 Subject: [PATCH 0799/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 98989a0c..97cbcbdc 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,6 +11,7 @@ #include "amount.h" #include "governancelist.h" +#include "mainwindow.h" #include #include From 5d41a9e4b0b1d68b205f233068901a82a21f9651 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:39:19 -0400 Subject: [PATCH 0800/1324] Update walletview.h --- src/qt/walletview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 6acaf1dd..e70d87c1 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#inlcude "mainwindow.h" +#include "mainwindow.h" #include From a2d1913018036e97337943ec51ce6feb675e890e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:40:00 -0400 Subject: [PATCH 0801/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index dbd0c644..52f59a7a 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" +#include "newaccount.h" #include #include "homepage.h" #include "QMessageBox" From 6bc734e6a93897d34fe76aca35acdacc6013a8f3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:40:29 -0400 Subject: [PATCH 0802/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index b576bda0..81759eea 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -13,7 +13,7 @@ #include "QPushButton" #include #include "posts.h" -#include "Qstring" +#include "QString" #include #include "QFontMetrics" #include "QGroupBox" From f0cb1f6f101cb2f1f5463a6f7bb9aa490dc19f0e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:40:47 -0400 Subject: [PATCH 0803/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index b7b7deed..170d9290 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -12,7 +12,7 @@ #include "QPushButton" #include #include "posts.h" -#include "Qstring" +#include "QString" #include #include "QFontMetrics" #include "QGroupBox" From 0f24509b3c733bfabee0a310f6344fa4a28caf0c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:45:59 -0400 Subject: [PATCH 0804/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 52f59a7a..c85fc539 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -15,10 +15,10 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); - QPixmap pix(":/icons/chat.png"); + /* QPixmap pix(":/icons/chat.png"); int w = ui->label_pic->width(); int h = ui->label_pic->height(); - ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); + ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); */ } From 587928c1f389f994515fd8a86f045cda6f0f52d0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:48:40 -0400 Subject: [PATCH 0805/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 57058721..95277f51 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow private Q_SLOTS: void on_signUpButton_clicked(); - void on_logInButton_clicked(); + void on_pushButton_Login_clicked(); private: Ui::MainWindow *ui; From 693b7f6eeadd092e799105799043f803aaaa5245 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:51:15 -0400 Subject: [PATCH 0806/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 72 ++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index c85fc539..4263540b 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,44 +1,66 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "newaccount.h" -#include +#include #include "homepage.h" #include "QMessageBox" -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include -#include - MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), +QMainWindow(parent), +ui(new Ui::MainWindow) +{ +ui->setupUi(this); +ui->signUpLabel->setText("No account? Create one!"); +QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); +this->setWindowTitle("Social Network"); + +} + +MainWindow::MainWindow(int userID) : ui(new Ui::MainWindow) { ui->setupUi(this); - /* QPixmap pix(":/icons/chat.png"); - int w = ui->label_pic->width(); - int h = ui->label_pic->height(); - ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); */ - + ui->signUpLabel->setText("No account? Create one!"); + id=userID; + qDebug()<< "id is "<show(); + this->hide(); + + +} + +void MainWindow::on_logInButton_clicked() { - QString username = ui->lineEdit_username->text(); - QString password = ui->lineEdit_password->text(); - - if(username == "test" && password == "test") { - QMessageBox::information(this, "Login", "Username and password is correct"); - //hide(); - secDialog = new SecDialog(this); - secDialog->show(); + QString email=ui->txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; } - else { - QMessageBox::warning(this,"Login", "Username and password is not correct"); + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; } + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); + } From f0cb665ede8e46043c96ab9df274e0694939594a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:51:45 -0400 Subject: [PATCH 0807/1324] Update mainwindow.h --- src/qt/mainwindow.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 95277f51..1899ff01 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -12,13 +12,15 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; ~MainWindow(); private Q_SLOTS: void on_signUpButton_clicked(); - void on_pushButton_Login_clicked(); + void on_logInButton_clicked(); private: Ui::MainWindow *ui; From cee130c1d28a980b3b55de97ae50e8e01b969110 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:54:13 -0400 Subject: [PATCH 0808/1324] Update walletframe.h --- src/qt/walletframe.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 555bf8cf..428ba5ed 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,7 +63,9 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to social media page */ + /** Switch to social media page */ + void gotoGovernancePage(); + /** Switch to social media page */ void gotoMainWindow(); /** Switch to private send page */ void gotoPrivateSendPage(); From a2f5c2d740115a0221ffb6dc7a6fcd4dc589dbc0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Wed, 17 Jun 2020 23:59:12 -0400 Subject: [PATCH 0809/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 184b7d7a..8fd54376 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -604,6 +604,9 @@ void BitcoinGUI::createActions() // HTHW Donate externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); + // HTH Chat + mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + mainWindow->setStatusTip(tr("HTH World Chat")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -615,15 +618,10 @@ void BitcoinGUI::createActions() // HTHW Donate - connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); - - // HTH Chat - mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World Social Media")); - // HTHW Chat + connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); + // HTHW Chat connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); - // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -724,8 +722,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu *social = appMenuBar->addMenu(tr("&HTH World")); - social->addAction(mainWindow); + QMenu* media = appMenuBar->addMenu(tr("&HTH World")); + media->addAction(mainWindow); } From f72a8cb96e2d3e53146eb3caa1b44e90d5b1ec4d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:00:10 -0400 Subject: [PATCH 0810/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 97cbcbdc..217146e0 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* MainWindow; + QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ From 29cb8c9e9447e6174822e9456a3bbf6d24eeef6a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:04:36 -0400 Subject: [PATCH 0811/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index c00afa77..b9c54cef 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -68,7 +68,7 @@
- userName + User Name txtUserMail @@ -104,7 +104,7 @@ - password + Password lineEdit_2 @@ -122,7 +122,7 @@ - confirm password + Confirm Password lineEdit_3 From a06b5d417ed63ebcd15a1935bc44f1856047542a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:16:06 -0400 Subject: [PATCH 0812/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 71 +++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4263540b..56a729b7 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,66 +1,43 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newaccount.h" +#include "secdialg.h" #include #include "homepage.h" #include "QMessageBox" +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include MainWindow::MainWindow(QWidget *parent) : -QMainWindow(parent), -ui(new Ui::MainWindow) -{ -ui->setupUi(this); -ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); -this->setWindowTitle("Social Network"); - -} - -MainWindow::MainWindow(int userID) : + QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - id=userID; - qDebug()<< "id is "<label_pic->width(); + int h = ui->label_pic->height(); + ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); + } - + MainWindow::~MainWindow() { delete ui; } - -void MainWindow::on_signUpButton_clicked() + +void MainWindow::on_pushButton_Login_clicked() { - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); - - -} - -void MainWindow::on_logInButton_clicked() -{ - QString email=ui->txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) - { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; + QString username = ui->lineEdit_username->text(); + QString password = ui->lineEdit_password->text(); + + if(username == "test" && password == "test") { + QMessageBox::information(this, "Login", "Username and password is correct"); + //hide(); + secDialog = new SecDialog(this); + secDialog->show(); } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) - { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; + else { + QMessageBox::warning(this,"Login", "Username and password is not correct"); } - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); - } From 5b774f5d1eaf22ec29789cf8585ce4c08e935be4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:16:43 -0400 Subject: [PATCH 0813/1324] Update mainwindow.h --- src/qt/mainwindow.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 1899ff01..75d01db5 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,29 +1,27 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - + #include - +#include "secdialog.h" namespace Ui { class MainWindow; } - + class MainWindow : public QMainWindow { Q_OBJECT - + public: - explicit MainWindow(QWidget *parent = 0); - MainWindow(int userID ); - int id; + explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - + private Q_SLOTS: - void on_signUpButton_clicked(); - - void on_logInButton_clicked(); + void on_pushButton_Login_clicked(); + private: Ui::MainWindow *ui; + SecDialog *secDialog; }; - + #endif // MAINWINDOW_H From 83f1a97a0297befdcb5611d685bef8ac708c4c66 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:17:34 -0400 Subject: [PATCH 0814/1324] Update and rename newaccount.h to secdialog.h --- src/qt/newaccount.h | 36 ------------------------------------ src/qt/secdialog.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 36 deletions(-) delete mode 100644 src/qt/newaccount.h create mode 100644 src/qt/secdialog.h diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h deleted file mode 100644 index b69d4800..00000000 --- a/src/qt/newaccount.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef NEWACCOUNT_H -#define NEWACCOUNT_H - -#include -#include "mainwindow.h" -namespace Ui { -class newAccount; -} - -class newAccount : public QMainWindow -{ - Q_OBJECT - -public: - explicit newAccount(QWidget *parent = 0); - ~newAccount(); - int id; - - -public Q_SLOTS: - void setLoginPtr(MainWindow *ptr); - - -private Q_SLOTS: - void on_pushButton_clicked(); - - void on_pushButton_2_clicked(); - - -private: - Ui::newAccount *ui; - - MainWindow *mainWindowPtr; -}; - -#endif // NEWACCOUNT_H diff --git a/src/qt/secdialog.h b/src/qt/secdialog.h new file mode 100644 index 00000000..533f3eee --- /dev/null +++ b/src/qt/secdialog.h @@ -0,0 +1,22 @@ +#ifndef SECDIALOG_H +#define SECDIALOG_H + +#include + +namespace Ui { +class SecDialog; +} + +class SecDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SecDialog(QWidget *parent = 0); + ~SecDialog(); + +private: + Ui::SecDialog *ui; +}; + +#endif // SECDIALOG_H From 26b163af6a4e6bae5a9134067e1b4454c595cbd1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:17:57 -0400 Subject: [PATCH 0815/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 57 ++++++------------------------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 47e25a28..4d2045c9 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -1,55 +1,14 @@ -#include "newaccount.h" -#include "ui_newaccount.h" -#include "QMessageBox" -#include -newAccount::newAccount(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::newAccount) +#include "secdialog.h" +#include "ui_secdialog.h" + +SecDialog::SecDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SecDialog) { ui->setupUi(this); - user check; - id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/icons/about.png")); - this->setWindowTitle("Social Network"); - } - -newAccount::~newAccount() + +SecDialog::~SecDialog() { delete ui; } - -void newAccount::on_pushButton_clicked() -{ - QString password =ui->lineEdit_2->text(); - QString confirm =ui->lineEdit_3->text(); - QString mail=ui->txtUserMail->text(); - if(password!=confirm) - { - QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); - } - else - { - user temp (password,mail,ui->txtUserName->text(),id); - temp.setUsersList(temp); - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - this->hide(); -// temp.userFileManipulator.updateActivity(mail,0,0); - } - -} - -void newAccount::setLoginPtr(MainWindow *ptr) -{ - this->mainWindowPtr = ptr; -} - -void newAccount::on_pushButton_2_clicked() -{ - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - // mainWindowPtr->show(); - this->hide(); - -} From 9486b37f9ca91163cbe98ef61596ce0dd70e50a6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:18:27 -0400 Subject: [PATCH 0816/1324] Update and rename newaccount.ui to secdialog.ui --- src/qt/forms/{newaccount.ui => secdialog.ui} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/qt/forms/{newaccount.ui => secdialog.ui} (95%) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/secdialog.ui similarity index 95% rename from src/qt/forms/newaccount.ui rename to src/qt/forms/secdialog.ui index b9c54cef..7c2c4476 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/secdialog.ui @@ -1,7 +1,7 @@ - newAccount - + SecDialog + 0 From b7722d5743741b62649d21dc48b9531d9bfc976e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:26:06 -0400 Subject: [PATCH 0817/1324] Update secdialog.ui --- src/qt/forms/secdialog.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui index 7c2c4476..20931333 100644 --- a/src/qt/forms/secdialog.ui +++ b/src/qt/forms/secdialog.ui @@ -35,7 +35,7 @@ - + Times New Roman @@ -158,7 +158,7 @@ - + Times New Roman From 06020d134b0b7d4671ce1f08b4224ef299706c66 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:27:15 -0400 Subject: [PATCH 0818/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index f9070099..0bced8ba 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -442,7 +442,7 @@ - + PointingHandCursor @@ -506,7 +506,7 @@ - + PointingHandCursor From fd95e762921dc5d2bf6b05e1e9a7d0ead093c4a6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:30:06 -0400 Subject: [PATCH 0819/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index b61ddfec..33cb6edc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -59,7 +59,7 @@ QT_FORMS_UI = \ qt/forms/form.ui \ qt/forms/homepage.ui \ qt/forms/mainwindow.ui \ - qt/forms/newaccount.ui \ + qt/forms/secdialog.ui \ qt/forms/profilepage.ui QT_MOC_CPP = \ @@ -122,7 +122,7 @@ QT_MOC_CPP = \ qt/moc_form.cpp \ qt/moc_homepage.cpp \ qt/moc_mainwindow.cpp \ - qt/moc_newaccount.cpp \ + qt/moc_secdialog.cpp \ qt/moc_posts.cpp \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ @@ -219,7 +219,7 @@ BITCOIN_QT_H = \ qt/form.h \ qt/homepage.h \ qt/mainwindow.h \ - qt/newaccount.h \ + qt/secdialog.h \ qt/posts.h \ qt/profilepage.h \ qt/qcustomplot.h \ @@ -572,7 +572,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/homepage.cpp \ qt/main.cpp \ qt/mainwindow.cpp \ - qt/newaccount.cpp \ + qt/secdialog.cpp \ qt/posts.cpp \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ From 7fd75c5bd4b9f422a2a062c4a04f5f353ff85d5e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:30:57 -0400 Subject: [PATCH 0820/1324] Rename newaccount.cpp to secdialog.cpp --- src/qt/{newaccount.cpp => secdialog.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{newaccount.cpp => secdialog.cpp} (100%) diff --git a/src/qt/newaccount.cpp b/src/qt/secdialog.cpp similarity index 100% rename from src/qt/newaccount.cpp rename to src/qt/secdialog.cpp From e9feb232c31eab34d46b7f46332ffa3f7cc9b1a0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:32:25 -0400 Subject: [PATCH 0821/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 56a729b7..23290163 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "secdialg.h" +#include "secdialog.h" #include #include "homepage.h" #include "QMessageBox" From 7ecb22c1e3567b28820c008b270d52a95f300660 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:38:07 -0400 Subject: [PATCH 0822/1324] Update secdialog.ui --- src/qt/forms/secdialog.ui | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui index 20931333..0a327e6d 100644 --- a/src/qt/forms/secdialog.ui +++ b/src/qt/forms/secdialog.ui @@ -20,7 +20,7 @@ - + Times New Roman @@ -58,7 +58,7 @@ - + Times New Roman @@ -94,7 +94,7 @@ - + Times New Roman @@ -184,7 +184,7 @@ 0 0 532 - 26 + 21 From 83b3712dd590ca2094342e8629597844fa2ab924 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 00:42:46 -0400 Subject: [PATCH 0823/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index 0bced8ba..c18cd7e2 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -435,7 +435,7 @@ - + No account? Create one! @@ -460,7 +460,7 @@ - + 10 @@ -469,12 +469,12 @@ - Email + User Name - + 10 @@ -527,7 +527,7 @@ 0 0 464 - 26 + 21 From e374c0123ea379bebd1b1ca2c6f0b301ce865390 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:06:43 -0400 Subject: [PATCH 0824/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 23290163..9ab44f57 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -4,6 +4,7 @@ #include #include "homepage.h" #include "QMessageBox" +#include #include "mainwindow.h" #include "ui_mainwindow.h" From b03620a8f6a8b4a1463b649076859c298a5c4914 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:07:03 -0400 Subject: [PATCH 0825/1324] Update mainwindow.h --- src/qt/mainwindow.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 75d01db5..9bfe70fc 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include #include "secdialog.h" namespace Ui { class MainWindow; From b51c210fbe71caa08a718b5f8fb0c72e7f02df5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:10:07 -0400 Subject: [PATCH 0826/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 9bfe70fc..6ee2dbf0 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -8,7 +8,8 @@ namespace Ui { class MainWindow; } -class MainWindow : public QMainWindow +class MainWindow : public QDialog , private Ui::MainWindow + { Q_OBJECT From 2abc93fd44faf924e3dfae23956332d4f9acabbb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:11:27 -0400 Subject: [PATCH 0827/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 6ee2dbf0..5e4e86e3 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -8,7 +8,7 @@ namespace Ui { class MainWindow; } -class MainWindow : public QDialog , private Ui::MainWindow +class MainWindow : public QMainWindow { Q_OBJECT From e417d5f6fc39b1475c72e713d1edf2664db4743a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:13:23 -0400 Subject: [PATCH 0828/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 9ab44f57..4b224e5a 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -11,9 +11,11 @@ #include #include MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ + QDialog(parent), + walletModel(0), + ui(new Ui::MainWindow), + model(0) + { ui->setupUi(this); QPixmap pix(":/icons/chat.png"); int w = ui->label_pic->width(); From 45945c503ed28cccb05d7763be19c094625615e1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:13:59 -0400 Subject: [PATCH 0829/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 5e4e86e3..ff08c581 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -4,8 +4,9 @@ #include #include #include "secdialog.h" + namespace Ui { -class MainWindow; + class MainWindow; } class MainWindow : public QMainWindow From df357cd4289f2b3231159001c584c95524b1708d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:15:34 -0400 Subject: [PATCH 0830/1324] Update secdialog.ui --- src/qt/forms/secdialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui index 0a327e6d..c75b062c 100644 --- a/src/qt/forms/secdialog.ui +++ b/src/qt/forms/secdialog.ui @@ -1,7 +1,7 @@ SecDialog - + 0 From 89662b2a329f8cac3437c1a5a9cf473d3d906395 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:17:23 -0400 Subject: [PATCH 0831/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4b224e5a..187038f9 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -12,10 +12,8 @@ #include MainWindow::MainWindow(QWidget *parent) : QDialog(parent), - walletModel(0), ui(new Ui::MainWindow), - model(0) - { +{ ui->setupUi(this); QPixmap pix(":/icons/chat.png"); int w = ui->label_pic->width(); From 8c5923790e5916bb45d0d0d2a4d68d01a92c08e2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:18:14 -0400 Subject: [PATCH 0832/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 187038f9..be0702ef 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -11,7 +11,7 @@ #include #include MainWindow::MainWindow(QWidget *parent) : - QDialog(parent), + QMainWindow(parent), ui(new Ui::MainWindow), { ui->setupUi(this); From 584bcdb8c4c602dd88d6325962fa7a408d07cfe9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:20:13 -0400 Subject: [PATCH 0833/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index be0702ef..87e6a8c4 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -10,6 +10,7 @@ #include "ui_mainwindow.h" #include #include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), From d20952f1b2baaf6a6722f89cc876402a484b4285 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:21:10 -0400 Subject: [PATCH 0834/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 33cb6edc..db98d2a0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -117,7 +117,6 @@ QT_MOC_CPP = \ qt/moc_addcomment.cpp \ qt/moc_adminwindow.cpp \ qt/moc_comment.cpp \ - qt/moc_dialog.cpp \ qt/moc_fileman.cpp \ qt/moc_form.cpp \ qt/moc_homepage.cpp \ From a82cccf8fc9697a9bfe9c9c8146eb3e4d9365665 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:23:08 -0400 Subject: [PATCH 0835/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 87e6a8c4..cad1d02f 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -13,7 +13,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow), + ui(new Ui::MainWindow) { ui->setupUi(this); QPixmap pix(":/icons/chat.png"); From ef001fe42e78b97d2a284fe24f1d15f0b42c1b59 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:28:07 -0400 Subject: [PATCH 0836/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index c18cd7e2..ffc59ece 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -434,23 +434,13 @@ - + No account? Create one! - - - - PointingHandCursor - - - Sign Up - - - From add6062584c98ab20abbbbc9f380352ca6e30c74 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:45:39 -0400 Subject: [PATCH 0837/1324] Add files via upload --- src/qt/forms/chatdialog.ui | 1374 +++++++++++++++++++++++++++++++++++ src/qt/forms/chatentry.ui | 1389 ++++++++++++++++++++++++++++++++++++ 2 files changed, 2763 insertions(+) create mode 100644 src/qt/forms/chatdialog.ui create mode 100644 src/qt/forms/chatentry.ui diff --git a/src/qt/forms/chatdialog.ui b/src/qt/forms/chatdialog.ui new file mode 100644 index 00000000..762e717f --- /dev/null +++ b/src/qt/forms/chatdialog.ui @@ -0,0 +1,1374 @@ + + + ChatDialog + + + + 0 + 0 + 850 + 526 + + + + Chat + + + + 8 + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + 10 + + + 10 + + + + + 15 + + + + + + 0 + 0 + + + + + 75 + true + + + + font-weight:bold; + + + Coin Control Features + + + + + + + + + 8 + + + 10 + + + + + + + + Inputs... + + + false + + + + + + + automatically selected + + + 5 + + + + + + + + 75 + true + + + + color:red;font-weight:bold; + + + Insufficient funds! + + + 5 + + + + + + + Qt::Horizontal + + + + 40 + 1 + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 20 + + + 0 + + + 10 + + + + + 10 + + + 14 + + + 10 + + + 4 + + + 6 + + + + + + 75 + true + + + + Quantity: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0 + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Bytes: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + Amount: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Dust: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + no + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + Fee: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + 10 + + + 14 + + + 6 + + + 4 + + + 6 + + + + + + 75 + true + + + + After Fee: + + + 0 + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Change: + + + + + + + IBeamCursor + + + Qt::ActionsContextMenu + + + 0.00 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + + + 12 + + + QLayout::SetDefaultConstraint + + + 5 + + + 5 + + + + + If this is activated, but the change address is empty or invalid, change will be sent to a newly generated address. + + + Custom change address + + + + + + + false + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + 3 + + + + + + + + + Qt::Vertical + + + + 800 + 1 + + + + + + + + + + + + + true + + + + + 0 + 0 + 830 + 69 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 6 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 10 + + + 0 + + + + + 0 + + + + + 0 + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 1 + 4 + + + + + + + + 10 + + + + + + 0 + 0 + + + + + 75 + true + + + + font-weight:bold; + + + Transaction Fee: + + + + + + + + + + + + + + Choose... + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + collapse fee-settings + + + Hide + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 10 + + + 4 + + + 10 + + + 4 + + + + + 6 + + + + + + + If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. + + + per kilobyte + + + true + + + groupCustomFee + + + + + + + If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "total at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. + + + total at least + + + groupCustomFee + + + + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. + + + + + + + + + + true + + + Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. + + + (read the tooltip) + + + 5 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + + + Recommended: + + + true + + + groupFee + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + + Custom: + + + groupFee + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + 6 + + + 2 + + + + + + + + + + 2 + + + + + + + + + + + + + + (Smart fee not initialized yet. This usually takes a few blocks...) + + + 2 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + + + + + Confirmation time: + + + 2 + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + 30 + + + + + 0 + + + 24 + + + 1 + + + 0 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + + + + + + + normal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + fast + + + + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + + 8 + + + 4 + + + + + Send as zero-fee transaction if possible + + + + + + + (confirmation may take longer) + + + 5 + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + Qt::Vertical + + + + 800 + 1 + + + + + + + + + + + + + + + + 150 + 0 + + + + Confirm the send action + + + S&end + + + false + + + true + + + + + + + + 0 + 0 + + + + Clear all fields of the form. + + + Clear &All + + + false + + + + + + + Send to multiple recipients at once + + + Add &Recipient + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 3 + + + + + + 95 + 0 + + + + PrivateSend + + + false + + + + + + + true + + + + 85 + 0 + + + + InstantSend + + + + + + + Balance: + + + + + + + + 0 + 0 + + + + IBeamCursor + + + 123.456 IMG + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+ + BitcoinAmountField + QLineEdit +
bitcoinamountfield.h
+ 1 +
+
+ + + + + + + + +
\ No newline at end of file diff --git a/src/qt/forms/chatentry.ui b/src/qt/forms/chatentry.ui new file mode 100644 index 00000000..da92f8af --- /dev/null +++ b/src/qt/forms/chatentry.ui @@ -0,0 +1,1389 @@ + + + ChatEntry + + + + 0 + 0 + 729 + 552 + + + + Qt::TabFocus + + + false + + + 0 + + + + This is a normal payment. + + + QFrame::NoFrame + + + + 8 + + + 4 + + + 12 + + + 8 + + + + + 0 + + + + + The IMG address to send the message + + + + + + + Choose previously used address + + + + + + + 22 + 22 + + + + Alt+A + + + + + + + Paste address from clipboard + + + + + + + 22 + 22 + + + + Alt+P + + + + + + + + + Me: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 25 + + + + + + + + + + + 0 + + + + + IMG address to sender send you message + + + 33774 + + + + + + + + + + + 22 + 22 + + + + + + + + + + + + 22 + 22 + + + + + + + + Remove this entry + + + + + + + 22 + 22 + + + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + chatTo + + + + + + + + 600 + 240 + + + + + 16777215 + 240 + + + + + + + + Message: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Imgbase64Edit + + + + + + + + 16777215 + 25 + + + + A message that was attached to the dash: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Dash network. + + + Qt::PlainText + + + + + + + 0 + + + 0 + + + + + true + + + Enter a message to send. + + + margin-left:12px + + + 3000000 + + + + + + + + + 0 + + + 0 + + + + + Image/Video: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + margin-left:12px + + + + + + + Chooser + + + + + + + + + + + true + + + + + + + false + + + false + + + The fee will be deducted from the amount being sent. The recipient will receive a lower amount of Dash than you enter in the amount field. If multiple recipients are selected, the fee is split equally. + + + S&ubtract fee from amount + + + + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 191 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 191 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 191 + + + + + + + 127 + 127 + 63 + + + + + + + 170 + 170 + 84 + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 255 + + + + + + + 127 + 127 + 63 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 127 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + This is an unauthenticated payment request. + + + true + + + QFrame::NoFrame + + + + 12 + + + + + Pay To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + + + + Remove this entry + + + + + + + + + + + + Memo: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::PlainText + + + + + + + A&mount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + payAmount_is + + + + + + + false + + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 0 + 0 + 0 + + + + + + + 155 + 255 + 147 + + + + + + + 0 + 0 + 0 + + + + + + + 119 + 255 + 233 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 197 + 243 + 187 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 0 + 0 + 0 + + + + + + + 155 + 255 + 147 + + + + + + + 0 + 0 + 0 + + + + + + + 119 + 255 + 233 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 197 + 243 + 187 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 70 + 116 + 59 + + + + + + + 140 + 232 + 119 + + + + + + + 230 + 255 + 224 + + + + + + + 185 + 243 + 171 + + + + + + + 70 + 116 + 59 + + + + + + + 93 + 155 + 79 + + + + + + + 70 + 116 + 59 + + + + + + + 155 + 255 + 147 + + + + + + + 70 + 116 + 59 + + + + + + + 140 + 232 + 119 + + + + + + + 140 + 232 + 119 + + + + + + + 0 + 0 + 0 + + + + + + + 140 + 232 + 119 + + + + + + + 125 + 194 + 122 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + This is an authenticated payment request. + + + true + + + QFrame::NoFrame + + + + 12 + + + + + Pay To: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + Qt::PlainText + + + + + + + Remove this entry + + + + + + + + + + + + Memo: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::PlainText + + + + + + + A&mount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + payAmount_s + + + + + + + false + + + + + + + + + BitcoinAmountField + QWidget +
bitcoinamountfield.h
+ 1 +
+ + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+
+ + addressBookButton + pasteButton + payAmount_is + deleteButton_is + payAmount_s + deleteButton_s + + + + + +
From 37ea18e89f9cee299a4f103819bd57ceab187ea9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:46:00 -0400 Subject: [PATCH 0838/1324] Add files via upload --- src/qt/chatdialog.cpp | 952 ++++++++++++++++++++++++++++++++++++++++++ src/qt/chatdialog.h | 106 +++++ src/qt/chatentry.cpp | 558 +++++++++++++++++++++++++ src/qt/chatentry.h | 99 +++++ 4 files changed, 1715 insertions(+) create mode 100644 src/qt/chatdialog.cpp create mode 100644 src/qt/chatdialog.h create mode 100644 src/qt/chatentry.cpp create mode 100644 src/qt/chatentry.h diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp new file mode 100644 index 00000000..d1c770d8 --- /dev/null +++ b/src/qt/chatdialog.cpp @@ -0,0 +1,952 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chatdialog.h" +#include "ui_chatdialog.h" + +#include "addresstablemodel.h" +#include "bitcoinunits.h" +#include "clientmodel.h" +#include "coincontroldialog.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "platformstyle.h" +#include "chatentry.h" +#include "walletmodel.h" + +#include "base58.h" +#include "coincontrol.h" +#include "validation.h" // mempool and minRelayTxFee +#include "ui_interface.h" +#include "txmempool.h" +#include "wallet/wallet.h" + +#include "privatesend.h" + +#include +#include +#include +#include + +ChatDialog::ChatDialog(const PlatformStyle *platformStyle, QWidget *parent) : + QDialog(parent), + ui(new Ui::ChatDialog), + clientModel(0), + model(0), + fNewRecipientAllowed(true), + fFeeMinimized(true), + platformStyle(platformStyle) +{ + ui->setupUi(this); + QString theme = GUIUtil::getThemeName(); + + if (!platformStyle->getImagesOnButtons()) { + ui->addButton->setIcon(QIcon()); + ui->clearButton->setIcon(QIcon()); + ui->sendButton->setIcon(QIcon()); + } else { + ui->addButton->setIcon(QIcon(":/icons/" + theme + "/add")); + ui->clearButton->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->sendButton->setIcon(QIcon(":/icons/" + theme + "/send")); + + + } + + GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); + + addEntry(); + + connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); + connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); + + // Coin Control + connect(ui->pushButtonCoinControl, SIGNAL(clicked()), this, SLOT(coinControlButtonClicked())); + connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); + connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); + + // Dash specific + QSettings settings; + if (!settings.contains("bUseDarkSend")) + settings.setValue("bUseDarkSend", false); + if (!settings.contains("bUseInstantX")) + settings.setValue("bUseInstantX", false); +// + bool fUsePrivateSend = settings.value("bUseDarkSend").toBool(); + bool fUseInstantSend = settings.value("bUseInstantX").toBool(); + if(fLiteMode) { + ui->checkUsePrivateSend->setChecked(false); + ui->checkUsePrivateSend->setVisible(false); + ui->checkUseInstantSend->setVisible(false); + CoinControlDialog::coinControl->fUsePrivateSend = false; + CoinControlDialog::coinControl->fUseInstantSend = false; + } + else{ + ui->checkUsePrivateSend->setChecked(fUsePrivateSend); + ui->checkUseInstantSend->setChecked(fUseInstantSend); + CoinControlDialog::coinControl->fUsePrivateSend = fUsePrivateSend; + CoinControlDialog::coinControl->fUseInstantSend = fUseInstantSend; + } +// + connect(ui->checkUsePrivateSend, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); + connect(ui->checkUseInstantSend, SIGNAL(stateChanged ( int )), this, SLOT(updateInstantSend())); +// +// // Coin Control: clipboard actions + QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); + QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this); + QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this); + QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this); + QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this); + QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this); + QAction *clipboardChangeAction = new QAction(tr("Copy change"), this); + connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity())); + connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount())); + connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardFee())); + connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAfterFee())); + connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardBytes())); + connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardLowOutput())); + connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardChange())); + ui->labelCoinControlQuantity->addAction(clipboardQuantityAction); + ui->labelCoinControlAmount->addAction(clipboardAmountAction); + ui->labelCoinControlFee->addAction(clipboardFeeAction); + ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction); + ui->labelCoinControlBytes->addAction(clipboardBytesAction); + ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction); + ui->labelCoinControlChange->addAction(clipboardChangeAction); + + // init transaction fee section + if (!settings.contains("fFeeSectionMinimized")) + settings.setValue("fFeeSectionMinimized", true); + if (!settings.contains("nFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility + settings.setValue("nFeeRadio", 1); // custom + if (!settings.contains("nFeeRadio")) + settings.setValue("nFeeRadio", 0); // recommended + if (!settings.contains("nCustomFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility + settings.setValue("nCustomFeeRadio", 1); // total at least + if (!settings.contains("nCustomFeeRadio")) + settings.setValue("nCustomFeeRadio", 0); // per kilobyte + if (!settings.contains("nSmartFeeSliderPosition")) + settings.setValue("nSmartFeeSliderPosition", 0); + if (!settings.contains("nTransactionFee")) + settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); + if (!settings.contains("fPayOnlyMinFee")) + settings.setValue("fPayOnlyMinFee", false); + if (!settings.contains("fSendFreeTransactions")) + settings.setValue("fSendFreeTransactions", false); + + ui->groupFee->setId(ui->radioSmartFee, 0); + ui->groupFee->setId(ui->radioCustomFee, 1); + ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); + ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); + ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1); + ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); + ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt()); + ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); + ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); + ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); + minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); +} + +void ChatDialog::setClientModel(ClientModel *clientModel) +{ + this->clientModel = clientModel; + + if (clientModel) { + connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(updateSmartFeeLabel())); + } +} + +void ChatDialog::setModel(WalletModel *model) +{ + this->model = model; + + if(model && model->getOptionsModel()) + { + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + entry->setModel(model); + } + } + + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), + model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); + connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount))); + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + updateDisplayUnit(); + + // Coin Control + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool))); + ui->frameCoinControl->setVisible(model->getOptionsModel()->getCoinControlFeatures()); + coinControlUpdateLabels(); + + // fee section + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel())); + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(updateGlobalFeeVariables())); + connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); + connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); + connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); + ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000)); + updateFeeSectionControls(); + updateMinFeeLabel(); + updateSmartFeeLabel(); + updateGlobalFeeVariables(); + } +} + +ChatDialog::~ChatDialog() +{ + QSettings settings; + settings.setValue("fFeeSectionMinimized", fFeeMinimized); + settings.setValue("nFeeRadio", ui->groupFee->checkedId()); + settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId()); + settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); + settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); + settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); + settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); + + delete ui; +} + +void ChatDialog::on_sendButton_clicked() +{ + if(!model || !model->getOptionsModel()) + return; + + QList recipients; + bool valid = true; + + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + if(entry->validate()) + { + recipients.append(entry->getValue()); + } + else + { + // valid = false; + } + } + } + + if(!valid || recipients.isEmpty()) + { + return; + } + + QString strFunds = tr("using") + " " + tr("anonymous funds") + ""; + QString strFee = ""; + recipients[0].inputType = ONLY_DENOMINATED; + + if(ui->checkUsePrivateSend->isChecked()) { + recipients[0].inputType = ONLY_DENOMINATED; + strFunds = tr("using") + " " + tr("anonymous funds") + ""; + QString strNearestAmount( + BitcoinUnits::formatWithUnit( + model->getOptionsModel()->getDisplayUnit(), CPrivateSend::GetSmallestDenomination())); + strFee = QString(tr( + "(privatesend requires this amount to be rounded up to the nearest %1)." + ).arg(strNearestAmount)); + } else { + recipients[0].inputType = ALL_COINS; + strFunds = tr("using") + " " + tr("any available funds (not anonymous)") + ""; + } + + if(ui->checkUseInstantSend->isChecked()) { + recipients[0].fUseInstantSend = true; + strFunds += " "; + strFunds += tr("and InstantSend"); + } else { + recipients[0].fUseInstantSend = false; + } + + + fNewRecipientAllowed = false; + // request unlock only if was locked or unlocked for mixing: + // this way we let users unlock by walletpassphrase or by menu + // and make many transactions while unlocking through this dialog + // will call relock + WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); + if(encStatus == model->Locked || encStatus == model->UnlockedForMixingOnly) + { + WalletModel::UnlockContext ctx(model->requestUnlock()); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled + fNewRecipientAllowed = true; + return; + } + send(recipients, strFee, strFunds); + return; + } + // already unlocked or not encrypted at all + send(recipients, strFee, strFunds); +} + +void ChatDialog::send(QList recipients, QString strFee, QString strFunds) +{ + // prepare transaction for getting txFee earlier + WalletModelTransaction currentTransaction(recipients); + WalletModel::SendCoinsReturn prepareStatus; + if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled + prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); + else + prepareStatus = model->prepareTransaction(currentTransaction); + + // process prepareStatus and on error generate message shown to user + processSendCoinsReturn(prepareStatus, + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); + + if(prepareStatus.status != WalletModel::OK) { + fNewRecipientAllowed = true; + return; + } + + CAmount txFee = currentTransaction.getTransactionFee(); + + // Format confirmation message + QStringList formatted; + Q_FOREACH(const SendCoinsRecipient &rcp, currentTransaction.getRecipients()) + { + // generate bold amount string + QString amount = "" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); + amount.append(" ").append(strFunds); + + // generate monospace address string + QString address = "" + rcp.address; + address.append(""); + + QString recipientElement; + + if (!rcp.paymentRequest.IsInitialized()) // normal payment + { + if(rcp.label.length() > 0) // label with address + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); + recipientElement.append(QString(" (%1)").arg(address)); + } + else // just address + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + } + else if(!rcp.authenticatedMerchant.isEmpty()) // authenticated payment request + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); + } + else // unauthenticated payment request + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + + formatted.append(recipientElement); + } + + QString questionString = tr("Are you sure you want to send?"); + questionString.append("

%1"); + + if(txFee > 0.5) + { + // append fee string if a fee is required + questionString.append("
"); + questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); + questionString.append(" "); + questionString.append(tr("are added as transaction fee")); + questionString.append(" "); + questionString.append(strFee); + + // append transaction size + questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)"); + } + + // add total amount in all subdivision units + questionString.append("
"); + CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; + QStringList alternativeUnits; + Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) + { + if(u != model->getOptionsModel()->getDisplayUnit()) + alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); + } + + // Show total amount + all alternative units + questionString.append(tr("Total Amount = %1
= %2") + .arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) + .arg(alternativeUnits.join("
= "))); + + // Limit number of displayed entries + int messageEntries = formatted.size(); + int displayedEntries = 0; + for(int i = 0; i < formatted.size(); i++){ + if(i >= MAX_SEND_POPUP_ENTRIESCHAT){ + formatted.removeLast(); + i--; + } + else{ + displayedEntries = i+1; + } + } + questionString.append("
"); + questionString.append(tr("(%1 of %2 entries displayed)").arg(displayedEntries).arg(messageEntries)); + + // Display message box + if(txFee > 0.05) + { + + QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), + questionString.arg(formatted.join("
")), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + + if(retval != QMessageBox::Yes) + { + fNewRecipientAllowed = true; + return; + } + } + // now send the prepared transaction + WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); + // process sendStatus and on error generate message shown to user + processSendCoinsReturn(sendStatus); + + if (sendStatus.status == WalletModel::OK) + { + accept(); + //CoinControlDialog::coinControl->UnSelectAll(); + coinControlUpdateLabels(); + } + fNewRecipientAllowed = true; +} + +void ChatDialog::clear() +{ + // Remove entries until only one left + while(ui->entries->count()) + { + ui->entries->takeAt(0)->widget()->deleteLater(); + } + addEntry(); + + updateTabsAndLabels(); +} + +void ChatDialog::reject() +{ + // clear(); +} + +void ChatDialog::accept() +{ + // clear(); +} + +ChatEntry *ChatDialog::addEntry() +{ + ChatEntry *entry = new ChatEntry(platformStyle, this); + entry->setModel(model); + ui->entries->addWidget(entry); + connect(entry, SIGNAL(removeEntry(ChatEntry*)), this, SLOT(removeEntry(ChatEntry*))); + connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); + connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels())); + + // Focus the field, so that entry can start immediately + entry->clear(); + entry->setFocus(); + ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint()); + qApp->processEvents(); + QScrollBar* bar = ui->scrollArea->verticalScrollBar(); + if(bar) + bar->setSliderPosition(bar->maximum()); + + updateTabsAndLabels(); + return entry; +} + +void ChatDialog::updateTabsAndLabels() +{ + setupTabChain(0); + coinControlUpdateLabels(); +} + +void ChatDialog::removeEntry(ChatEntry* entry) +{ + entry->hide(); + + // If the last entry is about to be removed add an empty one + if (ui->entries->count() == 1) + addEntry(); + + entry->deleteLater(); + + updateTabsAndLabels(); +} + +QWidget *ChatDialog::setupTabChain(QWidget *prev) +{ + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry) + { + prev = entry->setupTabChain(prev); + } + } + QWidget::setTabOrder(prev, ui->sendButton); + QWidget::setTabOrder(ui->sendButton, ui->clearButton); + QWidget::setTabOrder(ui->clearButton, ui->addButton); + return ui->addButton; +} + +void ChatDialog::setAddress(const QString &address, QString imgbase64) +{ + ChatEntry *entry = 0; + // Replace the first entry if it is still unused + if(ui->entries->count() == 1) + { + ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); + if(first->isClear()) + { + entry = first; + } + } + if(!entry) + { + entry = addEntry(); + } + + entry->setAddress(address,imgbase64); +} + +void ChatDialog::pasteEntry(const SendCoinsRecipient &rv) +{ + if(!fNewRecipientAllowed) + return; + + ChatEntry *entry = 0; + // Replace the first entry if it is still unused + if(ui->entries->count() == 1) + { + ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); + if(first->isClear()) + { + entry = first; + } + } + if(!entry) + { + entry = addEntry(); + } + + entry->setValue(rv); + updateTabsAndLabels(); +} + +bool ChatDialog::handlePaymentRequest(const SendCoinsRecipient &rv) +{ + // Just paste the entry, all pre-checks + // are done in paymentserver.cpp. + pasteEntry(rv); + return true; +} + +void ChatDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, + const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance) +{ + Q_UNUSED(unconfirmedBalance); + Q_UNUSED(immatureBalance); + Q_UNUSED(anonymizedBalance); + Q_UNUSED(watchBalance); + Q_UNUSED(watchUnconfirmedBalance); + Q_UNUSED(watchImmatureBalance); + + if(model && model->getOptionsModel()) + { + uint64_t bal = 0; + QSettings settings; + settings.setValue("bUseDarkSend", ui->checkUsePrivateSend->isChecked()); + if(ui->checkUsePrivateSend->isChecked()) { + bal = anonymizedBalance; + } else { + bal = balance; + } + + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); + } +} + +void ChatDialog::updateDisplayUnit() +{ + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), + model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); + CoinControlDialog::coinControl->fUsePrivateSend = ui->checkUsePrivateSend->isChecked(); + coinControlUpdateLabels(); + ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + updateMinFeeLabel(); + updateSmartFeeLabel(); +} + +void ChatDialog::updateInstantSend() +{ + QSettings settings; + settings.setValue("bUseInstantX", ui->checkUseInstantSend->isChecked()); + CoinControlDialog::coinControl->fUseInstantSend = ui->checkUseInstantSend->isChecked(); + coinControlUpdateLabels(); +} + +void ChatDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) +{ + QPair msgParams; + // Default to a warning message, override if error message is needed + msgParams.second = CClientUIInterface::MSG_WARNING; + + // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. + // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() + // all others are used only in WalletModel::prepareTransaction() + switch(sendCoinsReturn.status) + { + case WalletModel::InvalidAddress: + msgParams.first = tr("The recipient address is not valid. Please recheck."); + break; + case WalletModel::InvalidAmount: + msgParams.first = tr("The amount to pay must be larger than 0."); + break; + case WalletModel::AmountExceedsBalance: + msgParams.first = tr("The amount exceeds your balance."); + break; + case WalletModel::AmountWithFeeExceedsBalance: + msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); + break; + case WalletModel::DuplicateAddress: + msgParams.first = tr("Duplicate address found: addresses should only be used once each."); + break; + case WalletModel::TransactionCreationFailed: + msgParams.first = tr("Transaction creation failed!"); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::TransactionCommitFailed: + msgParams.first = tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::AbsurdFee: + msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), maxTxFee)); + break; + case WalletModel::PaymentRequestExpired: + msgParams.first = tr("Payment request expired."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + // included to prevent a compiler warning. + case WalletModel::OK: + default: + return; + } + + Q_EMIT message(tr("Send Coins"), msgParams.first, msgParams.second); +} + +void ChatDialog::minimizeFeeSection(bool fMinimize) +{ + ui->labelFeeMinimized->setVisible(fMinimize); + ui->buttonChooseFee ->setVisible(fMinimize); + ui->buttonMinimizeFee->setVisible(!fMinimize); + ui->frameFeeSelection->setVisible(!fMinimize); + ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0, 0); + fFeeMinimized = fMinimize; +} + +void ChatDialog::on_buttonChooseFee_clicked() +{ + minimizeFeeSection(false); +} + +void ChatDialog::on_buttonMinimizeFee_clicked() +{ + updateFeeMinimizedLabel(); + minimizeFeeSection(true); +} + +void ChatDialog::setMinimumFee() +{ + ui->radioCustomPerKilobyte->setChecked(true); + ui->customFee->setValue(CWallet::GetRequiredFee(1000)); +} + +void ChatDialog::updateFeeSectionControls() +{ + ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked()); + ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked()); + ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked()); + ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked()); + ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); + ui->radioCustomAtLeast ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() && CoinControlDialog::coinControl->HasSelected()); + ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); +} + +void ChatDialog::updateGlobalFeeVariables() +{ + if (ui->radioSmartFee->isChecked()) + { + nTxConfirmTarget = defaultConfirmTargetChat - ui->sliderSmartFee->value(); + payTxFee = CFeeRate(0); + + // set nMinimumTotalFee to 0 to not accidentally pay a custom fee + CoinControlDialog::coinControl->nMinimumTotalFee = 0; + } + else + { + nTxConfirmTarget = defaultConfirmTargetChat; + payTxFee = CFeeRate(ui->customFee->value()); + + // if user has selected to set a minimum absolute fee, pass the value to coincontrol + // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB + CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; + } + + fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); +} + +void ChatDialog::updateFeeMinimizedLabel() +{ + if(!model || !model->getOptionsModel()) + return; + + if (ui->radioSmartFee->isChecked()) + ui->labelFeeMinimized->setText(ui->labelSmartFee->text()); + else { + ui->labelFeeMinimized->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ui->customFee->value()) + + ((ui->radioCustomPerKilobyte->isChecked()) ? "/kB" : "")); + } +} + +void ChatDialog::updateMinFeeLabel() +{ + if (model && model->getOptionsModel()) + ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg( + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB") + ); +} + +void ChatDialog::updateSmartFeeLabel() +{ + if(!model || !model->getOptionsModel()) + return; + + int nBlocksToConfirm = defaultConfirmTargetChat - ui->sliderSmartFee->value(); + int estimateFoundAtBlocks = nBlocksToConfirm; + CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks); + if (feeRate <= CFeeRate(0)) // not enough data => minfee + { + ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), + std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); + ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) + ui->labelFeeEstimation->setText(""); + } + else + { + ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), + std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); + ui->labelSmartFee2->hide(); + ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks)); + } + + updateFeeMinimizedLabel(); +} + +// Coin Control: copy label "Quantity" to clipboard +void ChatDialog::coinControlClipboardQuantity() +{ + GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); +} + +// Coin Control: copy label "Amount" to clipboard +void ChatDialog::coinControlClipboardAmount() +{ + GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); +} + +// Coin Control: copy label "Fee" to clipboard +void ChatDialog::coinControlClipboardFee() +{ + GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "After fee" to clipboard +void ChatDialog::coinControlClipboardAfterFee() +{ + GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "Bytes" to clipboard +void ChatDialog::coinControlClipboardBytes() +{ + GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, "")); +} + +// Coin Control: copy label "Dust" to clipboard +void ChatDialog::coinControlClipboardLowOutput() +{ + GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); +} + +// Coin Control: copy label "Change" to clipboard +void ChatDialog::coinControlClipboardChange() +{ + GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace(ASYMP_UTF8, "")); +} + +// Coin Control: settings menu - coin control enabled/disabled by user +void ChatDialog::coinControlFeatureChanged(bool checked) +{ + ui->frameCoinControl->setVisible(checked); + + if (!checked && model) // coin control features disabled + CoinControlDialog::coinControl->SetNull(); + + coinControlUpdateLabels(); +} + +// Coin Control: button inputs -> show actual coin control dialog +void ChatDialog::coinControlButtonClicked() +{ + CoinControlDialog dlg(platformStyle); + dlg.setModel(model); + dlg.exec(); + coinControlUpdateLabels(); +} + +// Coin Control: checkbox custom change address +void ChatDialog::coinControlChangeChecked(int state) +{ + if (state == Qt::Unchecked) + { + CoinControlDialog::coinControl->destChange = CNoDestination(); + ui->labelCoinControlChangeLabel->clear(); + } + else + // use this to re-validate an already entered address + coinControlChangeEdited(ui->lineEditCoinControlChange->text()); + + ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); +} + +// Coin Control: custom change address changed +void ChatDialog::coinControlChangeEdited(const QString& text) +{ + if (model && model->getAddressTableModel()) + { + // Default to no change address until verified + CoinControlDialog::coinControl->destChange = CNoDestination(); + ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); + + CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); + + if (text.isEmpty()) // Nothing entered + { + ui->labelCoinControlChangeLabel->setText(""); + } + else if (!addr.IsValid()) // Invalid address + { + ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Dash address")); + } + else // Valid address + { + CKeyID keyid; + addr.GetKeyID(keyid); + if (!model->havePrivKey(keyid)) // Unknown change address + { + ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); + } + else // Known change address + { + ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); + + // Query label + QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); + if (!associatedLabel.isEmpty()) + ui->labelCoinControlChangeLabel->setText(associatedLabel); + else + ui->labelCoinControlChangeLabel->setText(tr("(no label)")); + + CoinControlDialog::coinControl->destChange = addr.Get(); + } + } + } +} + +// Coin Control: update labels +void ChatDialog::coinControlUpdateLabels() +{ + if (!model || !model->getOptionsModel()) + return; + + if (model->getOptionsModel()->getCoinControlFeatures()) + { + // enable minimum absolute fee UI controls + ui->radioCustomAtLeast->setVisible(true); + + // only enable the feature if inputs are selected + ui->radioCustomAtLeast->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() &&CoinControlDialog::coinControl->HasSelected()); + } + else + { + // in case coin control is disabled (=default), hide minimum absolute fee UI controls + ui->radioCustomAtLeast->setVisible(false); + return; + } + + // set pay amounts + CoinControlDialog::payAmounts.clear(); + CoinControlDialog::fSubtractFeeFromAmount = false; + for(int i = 0; i < ui->entries->count(); ++i) + { + ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); + if(entry && !entry->isHidden()) + { + SendCoinsRecipient rcp = entry->getValue(); + CoinControlDialog::payAmounts.append(rcp.amount); + if (rcp.fSubtractFeeFromAmount) + CoinControlDialog::fSubtractFeeFromAmount = true; + } + } + + ui->checkUsePrivateSend->setChecked(CoinControlDialog::coinControl->fUsePrivateSend); + + if (CoinControlDialog::coinControl->HasSelected()) + { + // actual coin control calculation + CoinControlDialog::updateLabels(model, this); + + // show coin control stats + ui->labelCoinControlAutomaticallySelected->hide(); + ui->widgetCoinControl->show(); + } + else + { + // hide coin control stats + ui->labelCoinControlAutomaticallySelected->show(); + ui->widgetCoinControl->hide(); + ui->labelCoinControlInsuffFunds->hide(); + } +} diff --git a/src/qt/chatdialog.h b/src/qt/chatdialog.h new file mode 100644 index 00000000..9abf9d7e --- /dev/null +++ b/src/qt/chatdialog.h @@ -0,0 +1,106 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_CHATDIALOG_H +#define BITCOIN_QT_CHATDIALOG_H + +#include "walletmodel.h" + +#include +#include + +static const int MAX_SEND_POPUP_ENTRIESCHAT = 10; + +class ClientModel; +class OptionsModel; +class PlatformStyle; +class ChatEntry; +class SendCoinsRecipient; + +namespace Ui { + class ChatDialog; +} + +QT_BEGIN_NAMESPACE +class QUrl; +QT_END_NAMESPACE + +const int defaultConfirmTargetChat = 25; + +/** Dialog for sending bitcoins */ +class ChatDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ChatDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ChatDialog(); + + void setClientModel(ClientModel *clientModel); + void setModel(WalletModel *model); + + /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907). + */ + QWidget *setupTabChain(QWidget *prev); + + void setAddress(const QString &address, QString imgbase64); + void pasteEntry(const SendCoinsRecipient &rv); + bool handlePaymentRequest(const SendCoinsRecipient &recipient); + +public Q_SLOTS: + void clear(); + void reject(); + void accept(); + ChatEntry *addEntry(); + void updateTabsAndLabels(); + void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, + const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); + +private: + Ui::ChatDialog *ui; + ClientModel *clientModel; + WalletModel *model; + bool fNewRecipientAllowed; + void send(QList recipients, QString strFee, QString strFunds); + bool fFeeMinimized; + const PlatformStyle *platformStyle; + + // Process WalletModel::SendCoinsReturn and generate a pair consisting + // of a message and message flags for use in Q_EMIT message(). + // Additional parameter msgArg can be used via .arg(msgArg). + void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString()); + void minimizeFeeSection(bool fMinimize); + void updateFeeMinimizedLabel(); + +private Q_SLOTS: + void on_sendButton_clicked(); + void on_buttonChooseFee_clicked(); + void on_buttonMinimizeFee_clicked(); + void removeEntry(ChatEntry* entry); + void updateDisplayUnit(); + void updateInstantSend(); + void coinControlFeatureChanged(bool); + void coinControlButtonClicked(); + void coinControlChangeChecked(int); + void coinControlChangeEdited(const QString &); + void coinControlUpdateLabels(); + void coinControlClipboardQuantity(); + void coinControlClipboardAmount(); + void coinControlClipboardFee(); + void coinControlClipboardAfterFee(); + void coinControlClipboardBytes(); + void coinControlClipboardLowOutput(); + void coinControlClipboardChange(); + void setMinimumFee(); + void updateFeeSectionControls(); + void updateMinFeeLabel(); + void updateSmartFeeLabel(); + void updateGlobalFeeVariables(); + +Q_SIGNALS: + // Fired when a message should be reported to the user + void message(const QString &title, const QString &message, unsigned int style); +}; + +#endif // BITCOIN_QT_CHATDIALOG_H diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp new file mode 100644 index 00000000..3dee680d --- /dev/null +++ b/src/qt/chatentry.cpp @@ -0,0 +1,558 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2014-2017 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chatentry.h" +#include "ui_chatentry.h" + +#include "addressbookpage.h" +#include "addresstablemodel.h" +#include "transactionfilterproxy.h" +#include "transactiontablemodel.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "platformstyle.h" +#include "walletmodel.h" +#include "base64.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +base64 base64chat; +typedef unsigned char BYTE; + +bool fileselectedchat=false; + +ChatEntry::ChatEntry(const PlatformStyle *platformStyle, QWidget *parent) : + QStackedWidget(parent), + ui(new Ui::ChatEntry), + model(0), + platformStyle(platformStyle) +{ + ui->setupUi(this); + + setCurrentWidget(ui->Chat); + + if (platformStyle->getUseExtraSpacing()) + ui->chatToLayout->setSpacing(4); + + + QString theme = GUIUtil::getThemeName(); + + // These icons are needed on Mac also! + ui->addressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); + ui->pasteButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + ui->deleteButton->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->deleteButton_is->setIcon(QIcon(":/icons/" + theme + "/remove")); + ui->deleteButton_s->setIcon(QIcon(":/icons/" + theme + "/remove")); + //ui->pasteButtonBase64->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + ui->Imgbase64Edit->setMaxLength(10000000); + + //receive address icons + + ui->ReceiveAddressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); + ui->pasteReceiveButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); + + //ui->payAmount->setDisabled(true); + + ui->payAmount->setValue(0.0001); + + + // ui->payAmount->setVisible(false); + + // normal dash address field + GUIUtil::setupAddressWidget(ui->chatReceive, this); + GUIUtil::setupAddressWidget(ui->chatTo, this); + // just a label for displaying dash address(es) + ui->payTo_is->setFont(GUIUtil::fixedPitchFont()); + + // Connect signals + //connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged())); + //connect(ui->chatTo, SIGNAL(textChanged()), this, SIGNAL(on_chatTo_textChanged())); + //connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged())); + connect(ui->pasteButton, SIGNAL(clicked()), this, SLOT(on_pasteButton_clicked())); + connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); + connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked())); + connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked())); + + + connect(ui->ReceiveAddressBookButton, SIGNAL(clicked()), this, SLOT(on_addressReceiveBookButton_clicked())); + + connect(ui->pasteReceiveButton, SIGNAL(clicked()), this, SLOT(on_pasteReceiveAddressButton_clicked())); + + + + //connect(ui->chooserButton, SIGNAL(clicked()), this, SLOT(on_chooserButton_clicked())); + //connect(ui->pasteButtonBase64, SIGNAL(clicked()), this, SLOT(on_pasteButtonBase64_clicked())); + +} + +ChatEntry::~ChatEntry() +{ + delete ui; +} + +void ChatEntry::on_pasteButton_clicked() +{ + // Paste text from clipboard into recipient field + ui->chatTo->setText(QApplication::clipboard()->text()); +} + + +void ChatEntry::on_pasteReceiveAddressButton_clicked() +{ + // Paste text from clipboard into recipient field + ui->chatReceive->setText(QApplication::clipboard()->text()); +} + +void ChatEntry::on_pasteButtonBase64_clicked() +{ + // Paste text from clipboard into recipient field + ui->Imgbase64Edit->setText(QApplication::clipboard()->text()); +} + +void ChatEntry::on_addressBookButton_clicked() +{ + if(!model) + return; + AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this); + dlg.setModel(model->getAddressTableModel()); + if(dlg.exec()) + { + ui->chatTo->setText(dlg.getReturnValue()); + //ui->payAmount->setFocus(); + } +} + +void ChatEntry::on_addressReceiveBookButton_clicked() +{ + if(!model) + return; + AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); + dlg.setModel(model->getAddressTableModel()); + + if(dlg.exec()) + { + ui->chatReceive->setText(dlg.getReturnValue()); + //ui->payAmount->setFocus(); + } +} + +void ChatEntry::on_chatTo_textChanged(const QString &address) +{ + updateLabel(address); + checkaddresstransactions(address); +} + +void ChatEntry::on_chatReceive_textChanged(const QString &address) +{ + checkaddresstransactions(address); +} + +void ChatEntry::checkaddresstransactions(const QString &address) +{ + if (model->validateAddress(ui->chatTo->text()) && model->validateAddress(ui->chatReceive->text())) + { + + ui->chatTo->setDisabled(true); + ui->chatReceive->setDisabled(true); + ui->Imgbase64Edit->setText("Start messaging using to address : " + ui->chatReceive->text() + " and me : " + ui->chatTo->text()); + transactionProxyModel = new TransactionFilterProxy(this); + transactionProxyModel->setAddressPrefix(ui->chatTo->text(),ui->chatReceive->text()); + transactionProxyModel->setSourceModel(model->getTransactionTableModel()); + + + + ui->chattableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->chattableView->setTabKeyNavigation(false); + ui->chattableView->setContextMenuPolicy(Qt::CustomContextMenu); + ui->chattableView->installEventFilter(this); + + QAction *copyImgbase64Action = new QAction(tr("Copy "), this); + + contextMenu = new QMenu(this); + + contextMenu->addAction(copyImgbase64Action); + + connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); + + connect(ui->chattableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); + + transactionView = ui->chattableView; + transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + transactionView->setModel(transactionProxyModel); + transactionView->setAlternatingRowColors(true); + transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); + transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); + transactionView->setSortingEnabled(true); + transactionView->sortByColumn(TransactionTableModel::Date, Qt::AscendingOrder); + transactionView->verticalHeader()->hide(); + //transactionView->horizontalHeader()->hide(); + transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH); + //transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); + transactionView->setColumnWidth(TransactionTableModel::Imgbase64, IMGBASE64_COLUMN_WIDTH); + //transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); + // Actions + + + connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); + + columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, IMGBASE64_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this); + + + // show/hide column Watch-only + + transactionView->setColumnHidden(TransactionTableModel::Watchonly, true); //Watchonly + + transactionView->setColumnHidden(TransactionTableModel::ToAddress, true); //To address + + transactionView->setColumnHidden(TransactionTableModel::Amount, true); // Amount + + // Watch-only signal + // connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool))); + + + } +} + +void ChatEntry::setModel(WalletModel *model) +{ + this->model = model; + + if (model && model->getOptionsModel()) + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + + clear(); +} + +void ChatEntry::clear() +{ + // clear UI elements for normal payment + ui->chatReceive->clear(); + ui->chatTo->clear(); + //ui->addAsLabel->clear(); + //ui->payAmount->clear(); + ui->Imgbase64Edit->clear(); + ui->Imgbase64Edit->setEnabled(1); + fileselectedchat=false; + //ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); + ui->messageTextLabel->clear(); + ui->messageTextLabel->hide(); + ui->messageLabel->hide(); + // clear UI elements for unauthenticated payment request + ui->payTo_is->clear(); + ui->memoTextLabel_is->clear(); + //ui->payAmount_is->clear(); + // clear UI elements for authenticated payment request + ui->payTo_s->clear(); + ui->memoTextLabel_s->clear(); + ui->payAmount_s->clear(); + + // update the display unit, to not use the default ("BTC") + updateDisplayUnit(); +} + + +void ChatEntry::on_chooserButton_clicked() +{ + //clear + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); + ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); + + // Paste text from clipboard into recipient field + QFileDialog dialog(this); + dialog.setFileMode(QFileDialog::ExistingFiles); + + //dialog.setViewMode(QFileDialog::List); + dialog.setOption(QFileDialog::DontUseNativeDialog, false); + + if (dialog.exec()){ + QStringList fileNames = dialog.selectedFiles(); + + if(fileNames.size()>0){ + + + + QString file = fileNames[0]; + ui->FileNamesTxt->setText(file); + std::string filestr = file.toUtf8().constData(); + std::string encodedstring = base64chat.encode(filestr); + QString qsencoded = QString::fromStdString(encodedstring); + + if(!base64chat.base64Validator(encodedstring)){ + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Base64 string not valid."); + ui->Imgbase64Edit->setText(""); + return; + } + if(qsencoded.size()>10000000) + { + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); + ui->Imgbase64Edit->setText(""); + return; + } + fileselectedchat=true; + ui->Imgbase64Edit->setText(qsencoded); + ui->Imgbase64Edit->setDisabled(1); + } + } +} + +void ChatEntry::deleteClicked() +{ + Q_EMIT removeEntry(this); +} + +bool ChatEntry::validate() +{ + if (!model) + return false; + + + // Check input validity + bool retval = true; + + // Skip checks for payment request + if (recipient.paymentRequest.IsInitialized()) + return retval; + + if (!model->validateAddress(ui->chatTo->text())) + { + ui->chatTo->setValid(false); + retval = false; + } + + if (!model->validateAddress(ui->chatReceive->text())) + { + ui->chatReceive->setValid(false); + retval = false; + } + + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); + ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); + if (!ui->Imgbase64Edit->text().isEmpty()) + { + + std::string imgbase64=ui->Imgbase64Edit->text().toUtf8().constData(); + + + if(fileselectedchat) + { + if(!base64chat.base64Validator(imgbase64)){ + + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Base64 string not valid."); + ui->Imgbase64Edit->setText(""); + retval = false; + } + } + + + if(ui->Imgbase64Edit->text().length()>10000000) + { + ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); + ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); + ui->Imgbase64Edit->setText(""); + retval = false; + } + } + else { + retval = false; + } + + if (!ui->payAmount->validate()) + { + retval = false; + } + + // Sending a zero amount is invalid + if (ui->payAmount->value(0) <= 0) + { + ui->payAmount->setValid(false); + retval = false; + } + + // Reject dust outputs: + // if (retval && GUIUtil::isDust(ui->chatTo->text(), ui->payAmount->value())) { + // ui->payAmount->setValid(false); + // retval = false; + //} + + return retval; +} + +SendCoinsRecipient ChatEntry::getValue() +{ + // Payment request + if (recipient.paymentRequest.IsInitialized()) + return recipient; + + // Normal payment + recipient.address = ui->chatTo->text(); + //recipient.label = ui->addAsLabel->text(); + recipient.imgbase64 = ui->Imgbase64Edit->text(); + if(ui->Imgbase64Edit->text().size()>0 && !fileselectedchat){ //message + recipient.imgbase64 ="from:" + ui->chatReceive->text() + ":"+ ui->Imgbase64Edit->text(); + } + recipient.amount = ui->payAmount->value(); + recipient.message = ui->messageTextLabel->text(); + recipient.fSubtractFeeFromAmount = false;//(ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); + + return recipient; +} + +QWidget *ChatEntry::setupTabChain(QWidget *prev) +{ + QWidget::setTabOrder(prev, ui->chatTo); + QWidget::setTabOrder(ui->chatTo, ui->labelchatTo); + //QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel); + //QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount); + //QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton); + + QWidget::setTabOrder(ui->ReceiveAddressBookButton, ui->pasteReceiveButton); + QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton); + QWidget::setTabOrder(ui->pasteButton, ui->deleteButton); + return ui->deleteButton; +} + +void ChatEntry::setValue(const SendCoinsRecipient &value) +{ + recipient = value; + + if (recipient.paymentRequest.IsInitialized()) // payment request + { + if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated + { + ui->chatTo->setText(recipient.address); + //ui->memoTextLabel_is->setText(recipient.message); + ui->payAmount_is->setValue(recipient.amount); + ui->Imgbase64Edit->setText(recipient.imgbase64); + ui->payAmount->setValue(recipient.amount); + ui->payAmount_is->setReadOnly(true); + setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); + } + else // authenticated + { + ui->chatTo->setText(recipient.authenticatedMerchant); + //ui->memoTextLabel_s->setText(recipient.message); + + ui->payAmount_s->setValue(recipient.amount); + ui->payAmount_s->setReadOnly(true); + ui->Imgbase64Edit->setText(recipient.imgbase64); + setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); + } + } + else // normal payment + { + // message + ui->messageTextLabel->setText(recipient.message); + ui->messageTextLabel->setVisible(!recipient.message.isEmpty()); + ui->messageLabel->setVisible(!recipient.message.isEmpty()); + + //ui->addAsLabel->clear(); + ui->chatTo->setText(recipient.address); // this may set a label from addressbook + if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label + ui->labelchatTo->setText(recipient.label); + ui->payAmount->setValue(recipient.amount); + ui->Imgbase64Edit->setText(recipient.imgbase64); + } +} + +void ChatEntry::setAddress(const QString &address, QString imgbase64) +{ + ui->chatTo->setText(address); + if(!imgbase64.isNull()) ui->Imgbase64Edit->setText(imgbase64); + //ui->payAmount->setFocus(); +} + +bool ChatEntry::isClear() +{ + return ui->chatTo->text().isEmpty() && ui->chatReceive->text().isEmpty(); +} + +void ChatEntry::setFocus() +{ + ui->chatTo->setFocus(); +} + +void ChatEntry::updateDisplayUnit() +{ + if(model && model->getOptionsModel()) + { + // Update payAmount with the current unit + ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + } +} + +bool ChatEntry::updateLabel(const QString &address) +{ + if(!model) + return false; + + // Fill in label from address book, if address has an associated label + QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); + if(!associatedLabel.isEmpty()) + { + ui->labelchatTo->setText(associatedLabel); + return true; + } + + return false; +} + +void ChatEntry::contextualMenu(const QPoint &point) +{ + QModelIndex index = transactionView->indexAt(point); + QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); + if (selection.empty()) + return; + + // check if transaction can be abandoned, disable context menu action in case it doesn't + uint256 hash; + hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); + // abandonAction->setEnabled(model->transactionCanBeAbandoned(hash)); + + if(index.isValid()) + { + contextMenu->exec(QCursor::pos()); + } +} + +void ChatEntry::copyImgbase64() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); +} diff --git a/src/qt/chatentry.h b/src/qt/chatentry.h new file mode 100644 index 00000000..e7515a5f --- /dev/null +++ b/src/qt/chatentry.h @@ -0,0 +1,99 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2019- The IMAGEcOIN Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_CHATENTRY_H +#define BITCOIN_QT_CHATENTRY_H + +#include "walletmodel.h" +#include "guiutil.h" +#include +#include + +class WalletModel; +class PlatformStyle; +class TransactionFilterProxy; +class QTableView; +class QMenu; + +namespace Ui { + class ChatEntry; +} + +/** + * A single entry in the dialog for sending bitcoins. + * Stacked widget, with different UIs for payment requests + * with a strong payee identity. + */ +class ChatEntry : public QStackedWidget +{ + Q_OBJECT + +public: + explicit ChatEntry(const PlatformStyle *platformStyle, QWidget *parent = 0); + ~ChatEntry(); + + void setModel(WalletModel *model); + bool validate(); + SendCoinsRecipient getValue(); + + /** Return whether the entry is still empty and unedited */ + bool isClear(); + + void setValue(const SendCoinsRecipient &value); + void setAddress(const QString &address,QString imgbase64); + + /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases + * (issue https://bugreports.qt-project.org/browse/QTBUG-10907). + */ + QWidget *setupTabChain(QWidget *prev); + + void setFocus(); + + enum ColumnWidths { + STATUS_COLUMN_WIDTH = 30, + WATCHONLY_COLUMN_WIDTH = 23, + DATE_COLUMN_WIDTH = 120, + TYPE_COLUMN_WIDTH = 180, + IMGBASE64_COLUMN_WIDTH = 580, + AMOUNT_MINIMUM_COLUMN_WIDTH = 120, + MINIMUM_COLUMN_WIDTH = 23 + }; + +public Q_SLOTS: + void clear(); + +Q_SIGNALS: + void removeEntry(ChatEntry *entry); + void payAmountChanged(); + void subtractFeeFromAmountChanged(); + +private Q_SLOTS: + void deleteClicked(); + void on_chatTo_textChanged(const QString &address); + void on_addressBookButton_clicked(); + void on_addressReceiveBookButton_clicked(); + void on_pasteButton_clicked(); + void on_pasteReceiveAddressButton_clicked(); + void updateDisplayUnit(); + void on_chooserButton_clicked(); + void on_pasteButtonBase64_clicked(); + void copyImgbase64(); + void contextualMenu(const QPoint &); + void on_chatReceive_textChanged(const QString &address); + +private: + SendCoinsRecipient recipient; + Ui::ChatEntry *ui; + WalletModel *model; + const PlatformStyle *platformStyle; + TransactionFilterProxy *transactionProxyModel; + QTableView *transactionView; + QMenu *contextMenu; + GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; + bool updateLabel(const QString &address); + void checkaddresstransactions(const QString &address); +}; + +#endif // BITCOIN_QT_CHATIMGENTRY_H From 2002954abb9fefb8ac69b4155e4c3b14003ddbb6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:49:11 -0400 Subject: [PATCH 0839/1324] Update chatdialog.cpp --- src/qt/chatdialog.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp index d1c770d8..9f39ede3 100644 --- a/src/qt/chatdialog.cpp +++ b/src/qt/chatdialog.cpp @@ -16,7 +16,6 @@ #include "chatentry.h" #include "walletmodel.h" -#include "base58.h" #include "coincontrol.h" #include "validation.h" // mempool and minRelayTxFee #include "ui_interface.h" @@ -515,7 +514,7 @@ QWidget *ChatDialog::setupTabChain(QWidget *prev) return ui->addButton; } -void ChatDialog::setAddress(const QString &address, QString imgbase64) +void ChatDialog::setAddress(const QString &address) { ChatEntry *entry = 0; // Replace the first entry if it is still unused @@ -532,7 +531,7 @@ void ChatDialog::setAddress(const QString &address, QString imgbase64) entry = addEntry(); } - entry->setAddress(address,imgbase64); + entry->setAddress(address); } void ChatDialog::pasteEntry(const SendCoinsRecipient &rv) From 01a74a0856c1b37cef218c308fe0e9775e9607e0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:50:10 -0400 Subject: [PATCH 0840/1324] Update chatdialog.h --- src/qt/chatdialog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatdialog.h b/src/qt/chatdialog.h index 9abf9d7e..5cf86c8f 100644 --- a/src/qt/chatdialog.h +++ b/src/qt/chatdialog.h @@ -44,7 +44,7 @@ class ChatDialog : public QDialog */ QWidget *setupTabChain(QWidget *prev); - void setAddress(const QString &address, QString imgbase64); + void setAddress(const QString &address); void pasteEntry(const SendCoinsRecipient &rv); bool handlePaymentRequest(const SendCoinsRecipient &recipient); From 0bf9b439aabd0f07ea92de43e582f420a7e1fd0b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:54:34 -0400 Subject: [PATCH 0841/1324] Update chatentry.cpp --- src/qt/chatentry.cpp | 116 +------------------------------------------ 1 file changed, 1 insertion(+), 115 deletions(-) diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp index 3dee680d..fb965820 100644 --- a/src/qt/chatentry.cpp +++ b/src/qt/chatentry.cpp @@ -14,7 +14,6 @@ #include "optionsmodel.h" #include "platformstyle.h" #include "walletmodel.h" -#include "base64.h" #include #include @@ -131,12 +130,6 @@ void ChatEntry::on_pasteReceiveAddressButton_clicked() ui->chatReceive->setText(QApplication::clipboard()->text()); } -void ChatEntry::on_pasteButtonBase64_clicked() -{ - // Paste text from clipboard into recipient field - ui->Imgbase64Edit->setText(QApplication::clipboard()->text()); -} - void ChatEntry::on_addressBookButton_clicked() { if(!model) @@ -182,7 +175,6 @@ void ChatEntry::checkaddresstransactions(const QString &address) ui->chatTo->setDisabled(true); ui->chatReceive->setDisabled(true); - ui->Imgbase64Edit->setText("Start messaging using to address : " + ui->chatReceive->text() + " and me : " + ui->chatTo->text()); transactionProxyModel = new TransactionFilterProxy(this); transactionProxyModel->setAddressPrefix(ui->chatTo->text(),ui->chatReceive->text()); transactionProxyModel->setSourceModel(model->getTransactionTableModel()); @@ -194,14 +186,6 @@ void ChatEntry::checkaddresstransactions(const QString &address) ui->chattableView->setContextMenuPolicy(Qt::CustomContextMenu); ui->chattableView->installEventFilter(this); - QAction *copyImgbase64Action = new QAction(tr("Copy "), this); - - contextMenu = new QMenu(this); - - contextMenu->addAction(copyImgbase64Action); - - connect(copyImgbase64Action, SIGNAL(triggered()), this, SLOT(copyImgbase64())); - connect(ui->chattableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); transactionView = ui->chattableView; @@ -218,7 +202,6 @@ void ChatEntry::checkaddresstransactions(const QString &address) //transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Imgbase64, IMGBASE64_COLUMN_WIDTH); //transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); // Actions @@ -260,8 +243,6 @@ void ChatEntry::clear() ui->chatTo->clear(); //ui->addAsLabel->clear(); //ui->payAmount->clear(); - ui->Imgbase64Edit->clear(); - ui->Imgbase64Edit->setEnabled(1); fileselectedchat=false; //ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); ui->messageTextLabel->clear(); @@ -280,55 +261,6 @@ void ChatEntry::clear() updateDisplayUnit(); } - -void ChatEntry::on_chooserButton_clicked() -{ - //clear - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); - ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); - - // Paste text from clipboard into recipient field - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::ExistingFiles); - - //dialog.setViewMode(QFileDialog::List); - dialog.setOption(QFileDialog::DontUseNativeDialog, false); - - if (dialog.exec()){ - QStringList fileNames = dialog.selectedFiles(); - - if(fileNames.size()>0){ - - - - QString file = fileNames[0]; - ui->FileNamesTxt->setText(file); - std::string filestr = file.toUtf8().constData(); - std::string encodedstring = base64chat.encode(filestr); - QString qsencoded = QString::fromStdString(encodedstring); - - if(!base64chat.base64Validator(encodedstring)){ - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Base64 string not valid."); - ui->Imgbase64Edit->setText(""); - return; - } - if(qsencoded.size()>10000000) - { - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); - ui->Imgbase64Edit->setText(""); - return; - } - fileselectedchat=true; - ui->Imgbase64Edit->setText(qsencoded); - ui->Imgbase64Edit->setDisabled(1); - } - } -} - void ChatEntry::deleteClicked() { Q_EMIT removeEntry(this); @@ -359,39 +291,6 @@ bool ChatEntry::validate() retval = false; } - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(255, 128, 128); }"); - ui->Imgbase64Edit->setToolTip("Enter base64 string for this tx. "); - if (!ui->Imgbase64Edit->text().isEmpty()) - { - - std::string imgbase64=ui->Imgbase64Edit->text().toUtf8().constData(); - - - if(fileselectedchat) - { - if(!base64chat.base64Validator(imgbase64)){ - - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Base64 string not valid."); - ui->Imgbase64Edit->setText(""); - retval = false; - } - } - - - if(ui->Imgbase64Edit->text().length()>10000000) - { - ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); - ui->Imgbase64Edit->setToolTip("Large file maxSize 8MB "); - ui->Imgbase64Edit->setText(""); - retval = false; - } - } - else { - retval = false; - } - if (!ui->payAmount->validate()) { retval = false; @@ -422,10 +321,6 @@ SendCoinsRecipient ChatEntry::getValue() // Normal payment recipient.address = ui->chatTo->text(); //recipient.label = ui->addAsLabel->text(); - recipient.imgbase64 = ui->Imgbase64Edit->text(); - if(ui->Imgbase64Edit->text().size()>0 && !fileselectedchat){ //message - recipient.imgbase64 ="from:" + ui->chatReceive->text() + ":"+ ui->Imgbase64Edit->text(); - } recipient.amount = ui->payAmount->value(); recipient.message = ui->messageTextLabel->text(); recipient.fSubtractFeeFromAmount = false;//(ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); @@ -458,7 +353,6 @@ void ChatEntry::setValue(const SendCoinsRecipient &value) ui->chatTo->setText(recipient.address); //ui->memoTextLabel_is->setText(recipient.message); ui->payAmount_is->setValue(recipient.amount); - ui->Imgbase64Edit->setText(recipient.imgbase64); ui->payAmount->setValue(recipient.amount); ui->payAmount_is->setReadOnly(true); setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); @@ -470,7 +364,6 @@ void ChatEntry::setValue(const SendCoinsRecipient &value) ui->payAmount_s->setValue(recipient.amount); ui->payAmount_s->setReadOnly(true); - ui->Imgbase64Edit->setText(recipient.imgbase64); setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); } } @@ -486,14 +379,12 @@ void ChatEntry::setValue(const SendCoinsRecipient &value) if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label ui->labelchatTo->setText(recipient.label); ui->payAmount->setValue(recipient.amount); - ui->Imgbase64Edit->setText(recipient.imgbase64); } } -void ChatEntry::setAddress(const QString &address, QString imgbase64) +void ChatEntry::setAddress(const QString &address) { ui->chatTo->setText(address); - if(!imgbase64.isNull()) ui->Imgbase64Edit->setText(imgbase64); //ui->payAmount->setFocus(); } @@ -551,8 +442,3 @@ void ChatEntry::contextualMenu(const QPoint &point) contextMenu->exec(QCursor::pos()); } } - -void ChatEntry::copyImgbase64() -{ - GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::Imgbase64Role); -} From e933a73c93d80bc244d3b7f4d33ccd8579c44934 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:55:15 -0400 Subject: [PATCH 0842/1324] Update chatentry.h --- src/qt/chatentry.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/qt/chatentry.h b/src/qt/chatentry.h index e7515a5f..4f0ddca8 100644 --- a/src/qt/chatentry.h +++ b/src/qt/chatentry.h @@ -42,7 +42,7 @@ class ChatEntry : public QStackedWidget bool isClear(); void setValue(const SendCoinsRecipient &value); - void setAddress(const QString &address,QString imgbase64); + void setAddress(const QString &address); /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases * (issue https://bugreports.qt-project.org/browse/QTBUG-10907). @@ -56,7 +56,6 @@ class ChatEntry : public QStackedWidget WATCHONLY_COLUMN_WIDTH = 23, DATE_COLUMN_WIDTH = 120, TYPE_COLUMN_WIDTH = 180, - IMGBASE64_COLUMN_WIDTH = 580, AMOUNT_MINIMUM_COLUMN_WIDTH = 120, MINIMUM_COLUMN_WIDTH = 23 }; @@ -77,9 +76,6 @@ private Q_SLOTS: void on_pasteButton_clicked(); void on_pasteReceiveAddressButton_clicked(); void updateDisplayUnit(); - void on_chooserButton_clicked(); - void on_pasteButtonBase64_clicked(); - void copyImgbase64(); void contextualMenu(const QPoint &); void on_chatReceive_textChanged(const QString &address); From e284f167b1b781a076074fe146609361af3fc441 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:57:47 -0400 Subject: [PATCH 0843/1324] Update chatentry.ui --- src/qt/forms/chatentry.ui | 74 +++++---------------------------------- 1 file changed, 9 insertions(+), 65 deletions(-) diff --git a/src/qt/forms/chatentry.ui b/src/qt/forms/chatentry.ui index da92f8af..90a2a1b9 100644 --- a/src/qt/forms/chatentry.ui +++ b/src/qt/forms/chatentry.ui @@ -212,19 +212,6 @@
- - - - Message: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Imgbase64Edit - - - @@ -249,22 +236,6 @@ 0 - - - - true - - - Enter a message to send. - - - margin-left:12px - - - 3000000 - - -
@@ -275,39 +246,12 @@ 0 - - - - Image/Video: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - false - - - margin-left:12px - - - - - - - Chooser - - -
- + true @@ -823,7 +767,7 @@ - + false @@ -1352,7 +1296,7 @@ - + false @@ -1362,17 +1306,17 @@ - - BitcoinAmountField - QWidget -
bitcoinamountfield.h
- 1 -
QValidatedLineEdit QLineEdit
qvalidatedlineedit.h
+ + BitcoinAmountField + QLineEdit +
bitcoinamountfield.h
+ 1 +
addressBookButton From 1942233f5a90cb763d507ffbd8d9b489c84572dc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 01:59:38 -0400 Subject: [PATCH 0844/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index db98d2a0..153c4e3d 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -60,7 +60,9 @@ QT_FORMS_UI = \ qt/forms/homepage.ui \ qt/forms/mainwindow.ui \ qt/forms/secdialog.ui \ - qt/forms/profilepage.ui + qt/forms/profilepage.ui \ + qt/forms/chatdialog.ui \ + qt/forms/chatentry.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -126,7 +128,9 @@ QT_MOC_CPP = \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ - qt/moc_user.cpp + qt/moc_user.cpp \ + qt/moc_chatdialog.cpp \ + qt/moc_chatentry.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -223,7 +227,9 @@ BITCOIN_QT_H = \ qt/profilepage.h \ qt/qcustomplot.h \ qt/statistics.h \ - qt/user.h + qt/user.h \ + qt/chatdialog.h \ + qt/chatentry.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -576,7 +582,9 @@ BITCOIN_QT_WALLET_CPP = \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ qt/statistics.cpp \ - qt/user.cpp + qt/user.cpp \ + qt/chatdialog.cpp \ + qt/chatentry.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From e3e1f4cee46885cfc77946c4fabc6793136a6b5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:00:28 -0400 Subject: [PATCH 0845/1324] Add files via upload --- src/coincontrol.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/coincontrol.h diff --git a/src/coincontrol.h b/src/coincontrol.h new file mode 100644 index 00000000..ff8f33a8 --- /dev/null +++ b/src/coincontrol.h @@ -0,0 +1,74 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_COINCONTROL_H +#define BITCOIN_COINCONTROL_H + +#include "primitives/transaction.h" + +/** Coin Control Features. */ +class CCoinControl +{ +public: + CTxDestination destChange; + bool fUsePrivateSend; + bool fUseInstantSend; + //! If false, allows unselected inputs, but requires all selected inputs be used + bool fAllowOtherInputs; + //! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria + bool fAllowWatchOnly; + //! Minimum absolute fee (not per kilobyte) + CAmount nMinimumTotalFee; + + CCoinControl() + { + SetNull(); + } + + void SetNull() + { + destChange = CNoDestination(); + fAllowOtherInputs = false; + fAllowWatchOnly = false; + setSelected.clear(); + fUseInstantSend = false; + fUsePrivateSend = true; + nMinimumTotalFee = 0; + } + + bool HasSelected() const + { + return (setSelected.size() > 0); + } + + bool IsSelected(const COutPoint& output) const + { + return (setSelected.count(output) > 0); + } + + void Select(const COutPoint& output) + { + setSelected.insert(output); + } + + void UnSelect(const COutPoint& output) + { + setSelected.erase(output); + } + + void UnSelectAll() + { + setSelected.clear(); + } + + void ListSelected(std::vector& vOutpoints) const + { + vOutpoints.assign(setSelected.begin(), setSelected.end()); + } + +private: + std::set setSelected; +}; + +#endif // BITCOIN_COINCONTROL_H From 2b70062ac4471fb3abba9afe3e5ce25e55aa3dd0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:01:26 -0400 Subject: [PATCH 0846/1324] Update Makefile.am --- src/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4f3defa8..092d33e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -245,7 +245,8 @@ BITCOIN_CORE_H = \ zmq/zmqabstractnotifier.h \ zmq/zmqconfig.h\ zmq/zmqnotificationinterface.h \ - zmq/zmqpublishnotifier.h + zmq/zmqpublishnotifier.h \ + coincontrol.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj From c8c147995c05c333e4066c6743fb9ec0a04fc58e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:06:42 -0400 Subject: [PATCH 0847/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 8fd54376..2a40a6ca 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -144,6 +144,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * externalDonate(0), governanceAction(0), mainWindow(0), + chatAction(0), + chatMenuAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -499,6 +501,23 @@ void BitcoinGUI::createActions() connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); } + //chat + + chatAction = new QAction(QIcon(":/icons/" + theme + "/overview"), tr("&Messenger"), this); + chatAction->setStatusTip(tr("Messenger")); + chatAction->setToolTip(chatAction->statusTip()); + chatAction->setCheckable(true); + + #ifdef Q_OS_MAC + chatAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); + #else + chatAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); + #endif + tabGroup->addAction(chatAction); + + chatMenuAction = new QAction(QIcon(":/icons/" + theme + "/overview"), chatAction->text(), this); + chatMenuAction->setStatusTip(chatAction->statusTip()); + chatMenuAction->setToolTip(chatMenuAction->statusTip()); /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -527,6 +546,11 @@ void BitcoinGUI::createActions() connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); /* connect(privatesendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(privatesendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); */ + connect(chatAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(chatAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); + + connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); #endif // ENABLE_WALLET @@ -738,6 +762,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(sendCoinsAction); toolbar->addAction(receiveCoinsAction); toolbar->addAction(historyAction); + toolbar->addAction(chatAction); /* toolbar->addAction(privatesendAction); */ @@ -898,6 +923,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) receiveCoinsAction->setEnabled(enabled); receiveCoinsMenuAction->setEnabled(enabled); historyAction->setEnabled(enabled); + chatAction->setEnabled(enabled); + chatMenuAction->setEnabled(enabled); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); @@ -1051,6 +1078,12 @@ void BitcoinGUI::openClicked() } } +void BitcoinGUI::gotoChatPage() +{ + chatAction->setChecked(true); + if (walletFrame) walletFrame->gotoChatPage(); +} + void BitcoinGUI::gotoMainWindow() { mainWindow->setChecked(true); From 8bc5fe05cbc81cc8bcfc2d277504b615e32625cc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:07:26 -0400 Subject: [PATCH 0848/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 217146e0..f7f5795e 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -104,7 +104,8 @@ class BitcoinGUI : public QMainWindow QProgressDialog *progressDialog; QMenuBar *appMenuBar; - + QAction *chatAction; + QAction *chatMenuAction; QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; @@ -233,6 +234,8 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET + /** Switch to chat coins page */ + void gotoChatPage(); /** Switch to social media page */ void gotoMainWindow(); From aac184d55a41bed39d51c7fda9f150c8577740be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:07:53 -0400 Subject: [PATCH 0849/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index abf30d21..d302123c 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,6 +108,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } +void WalletFrame::gotoChatPage() +{ + QMap::const_iterator i; + for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) + i.value()->gotoChatPage(); +} + void WalletFrame::gotoMainWindow() { From 3e1f619f1b32b62e65f7fcc9d992b4f0ef55f8d1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:08:15 -0400 Subject: [PATCH 0850/1324] Update walletframe.h --- src/qt/walletframe.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 428ba5ed..a5220949 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,6 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: + /** Switch to WebWindow page */ + void gotoChatPage(); /** Switch to social media page */ void gotoGovernancePage(); /** Switch to social media page */ From e6dc90106e09d21e6a3ab2f45bc5d1c9b8b6471c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:10:13 -0400 Subject: [PATCH 0851/1324] Update walletview.cpp --- src/qt/walletview.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 581d2805..20197042 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,6 +21,7 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" +#include "chatdialog.h" #include "ui_interface.h" @@ -75,6 +76,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); governanceListPage = new GovernanceList(platformStyle); + ChatPage = new ChatDialog(platformStyle); addWidget(governanceListPage); @@ -85,7 +87,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); + addWidget(privateSendPage); + addWidget(ChatPage); mainWindow = new MainWindow(); addWidget(mainWindow); @@ -116,6 +119,9 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): // Pass through messages from sendCoinsPage connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + + // Pass through messages from ChatPage + connect(ChatPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); @@ -157,6 +163,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) privateSendPage->setClientModel(_clientModel); sendCoinsPage->setClientModel(_clientModel); governanceListPage->setClientModel(_clientModel); + ChatPage->setClientModel(clientModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); @@ -173,6 +180,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); governanceListPage->setWalletModel(_walletModel); + ChatPage->setModel(walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); @@ -236,6 +244,11 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } +void WalletView::gotoChatPage() +{ + setCurrentWidget(ChatPage); +} + void WalletView::gotoMainWindow() { setCurrentWidget(mainWindow); From 2df412503b7b63de2adcd7144907d0b36f534a91 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:11:02 -0400 Subject: [PATCH 0852/1324] Update walletview.h --- src/qt/walletview.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index e70d87c1..0556f46d 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -26,6 +26,7 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; class MainWindow; +class ChatDialog; @@ -77,6 +78,7 @@ class WalletView : public QStackedWidget PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; MainWindow *mainWindow; + ChatDialog *ChatPage; TransactionView *transactionView; @@ -86,6 +88,8 @@ class WalletView : public QStackedWidget public Q_SLOTS: + /** Switch to chat page */ + void gotoChatPage(); /** Switch to social media page */ void gotoMainWindow(); /** Switch to governance page */ From ad7dc05c95e951566dd5022dfd637ac91817a270 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:14:50 -0400 Subject: [PATCH 0853/1324] Update chatentry.cpp --- src/qt/chatentry.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp index fb965820..568759ac 100644 --- a/src/qt/chatentry.cpp +++ b/src/qt/chatentry.cpp @@ -43,7 +43,6 @@ #include -base64 base64chat; typedef unsigned char BYTE; bool fileselectedchat=false; @@ -70,8 +69,6 @@ ChatEntry::ChatEntry(const PlatformStyle *platformStyle, QWidget *parent) : ui->deleteButton->setIcon(QIcon(":/icons/" + theme + "/remove")); ui->deleteButton_is->setIcon(QIcon(":/icons/" + theme + "/remove")); ui->deleteButton_s->setIcon(QIcon(":/icons/" + theme + "/remove")); - //ui->pasteButtonBase64->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - ui->Imgbase64Edit->setMaxLength(10000000); //receive address icons @@ -208,7 +205,7 @@ void ChatEntry::checkaddresstransactions(const QString &address) connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); - columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, IMGBASE64_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this); + columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView,MINIMUM_COLUMN_WIDTH, this); // show/hide column Watch-only From 11838bb8464cf435cc63f9e8349a8e0de4bcdc9a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:17:45 -0400 Subject: [PATCH 0854/1324] Update sendcoinsdialog.cpp --- src/qt/sendcoinsdialog.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 3d7a0155..a8315108 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -134,6 +134,8 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); if (!settings.contains("fPayOnlyMinFee")) settings.setValue("fPayOnlyMinFee", false); + if (!settings.contains("fSendFreeTransactions")) + settings.setValue("fSendFreeTransactions", false); ui->groupFee->setId(ui->radioSmartFee, 0); ui->groupFee->setId(ui->radioCustomFee, 1); @@ -143,6 +145,7 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); + ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); } @@ -221,6 +224,7 @@ SendCoinsDialog::~SendCoinsDialog() settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); + settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); delete ui; } @@ -730,6 +734,7 @@ void SendCoinsDialog::updateGlobalFeeVariables() // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; } + fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); } void SendCoinsDialog::updateFeeMinimizedLabel() From 4e02eb2dc38468c99fb496e70471b243cd7bdd2e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:19:28 -0400 Subject: [PATCH 0855/1324] Update coincontroldialog.cpp --- src/qt/coincontroldialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 81516b33..4378eb01 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -562,6 +562,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // InstantSend Fee if (coinControl->fUseInstantSend) nPayFee = std::max(nPayFee, CTxLockRequest(txDummy).GetMinFee(true)); + + if (fSendFreeTransactions) + if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) + nPayFee = 0; if (nPayAmount > 0) { From 37571635fd2e71b2b752293d733b8452eea56fb4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:20:11 -0400 Subject: [PATCH 0856/1324] Update wallet.h --- src/wallet/wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 49026792..7af83ffb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -44,6 +44,7 @@ extern CFeeRate payTxFee; extern unsigned int nTxConfirmTarget; extern bool bSpendZeroConfChange; extern bool bBIP69Enabled; +extern bool fSendFreeTransactions; static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000; //! -paytxfee default From 8e180292fef2907e8d2bffe1b029a6fa8cc77bf1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:25:39 -0400 Subject: [PATCH 0857/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7c116009..22bc4409 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -50,6 +50,7 @@ CWallet* pwalletMain = NULL; CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE); unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE; +bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS; bool bBIP69Enabled = true; CAmount collateralAmount = 1000000; @@ -3731,6 +3732,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT strFailReason = _("Transaction has too long of a mempool chain"); return false; } + if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) } return true; } From 3fce4489eb1ada877c5c5eec56953a2046d7a4dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:32:44 -0400 Subject: [PATCH 0858/1324] Update init.cpp --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index ddcd24d8..589a2aed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1285,6 +1285,7 @@ bool AppInitParameterInteraction() fIsBareMultisigStd = GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes); + fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS); fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS); From 1e4659619f8d3c564f3ee36f49a9300bb9e67ba6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:35:42 -0400 Subject: [PATCH 0859/1324] Update chatdialog.cpp --- src/qt/chatdialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp index 9f39ede3..3e3839f6 100644 --- a/src/qt/chatdialog.cpp +++ b/src/qt/chatdialog.cpp @@ -16,6 +16,7 @@ #include "chatentry.h" #include "walletmodel.h" +#include "base58.h" #include "coincontrol.h" #include "validation.h" // mempool and minRelayTxFee #include "ui_interface.h" From 37dd1faf7142b974b6e2820ae163ba4dbaab805f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:36:12 -0400 Subject: [PATCH 0860/1324] Update chatentry.cpp --- src/qt/chatentry.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp index 568759ac..a23eb5d0 100644 --- a/src/qt/chatentry.cpp +++ b/src/qt/chatentry.cpp @@ -14,6 +14,7 @@ #include "optionsmodel.h" #include "platformstyle.h" #include "walletmodel.h" +#include "base58.h" #include #include From c472723b48169d3263500f6b691e93f5a056174b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:37:34 -0400 Subject: [PATCH 0861/1324] Update wallet.h --- src/wallet/wallet.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7af83ffb..1bcb8cc6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -61,6 +61,8 @@ static const CAmount MIN_CHANGE = CENT; static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2; //! Default for -spendzeroconfchange static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; +//! Default for -sendfreetransactions +static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false; //! Default for -walletrejectlongchains static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; //! -txconfirmtarget default From 291a2aeda78e44c5d313bbde6fc37cab903b786c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:39:08 -0400 Subject: [PATCH 0862/1324] Update init.cpp --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 589a2aed..739edbdf 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -450,6 +450,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands")); #endif } + strUsage += HelpMessageOpt("-sendfreetransactions", strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), DEFAULT_SEND_FREE_TRANSACTIONS)); strUsage += HelpMessageOpt("-datadir=
", _("Specify data directory")); strUsage += HelpMessageOpt("-dbcache=", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache)); strUsage += HelpMessageOpt("-loadblock=", _("Imports blocks from external blk000??.dat file on startup")); From 7af85fdab7575fb974eeef695b01e981b53a6932 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:43:00 -0400 Subject: [PATCH 0863/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 22bc4409..fa015b59 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3732,7 +3732,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT strFailReason = _("Transaction has too long of a mempool chain"); return false; } - if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) + if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE); } return true; } From 2658f05d280cefa9daed8722e5ca9657f47ad574 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:48:37 -0400 Subject: [PATCH 0864/1324] Update coincontroldialog.cpp --- src/qt/coincontroldialog.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 4378eb01..a58b1c4e 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -501,6 +501,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) unsigned int nBytesInputs = 0; unsigned int nQuantity = 0; int nQuantityUncompressed = 0; + bool fAllowFree = false; std::vector vCoinControl; std::vector vOutputs; @@ -562,7 +563,12 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // InstantSend Fee if (coinControl->fUseInstantSend) nPayFee = std::max(nPayFee, CTxLockRequest(txDummy).GetMinFee(true)); - + + // Allow free? (require at least hard-coded threshold and default to that if no estimate) + double mempoolEstimatePriority = mempool.estimateSmartPriority(nTxConfirmTarget); + dPriority = dPriorityInputs / (nBytes - nBytesInputs + (nQuantityUncompressed * 29)); // 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 bytes of the input are ignored for priority) + double dPriorityNeeded = std::max(mempoolEstimatePriority, AllowFreeThreshold()); + fAllowFree = (dPriority >= dPriorityNeeded); if (fSendFreeTransactions) if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) nPayFee = 0; From bbd287bcf4d260aa31b2b3105e5d87aa2bb5cbd9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 02:53:54 -0400 Subject: [PATCH 0865/1324] Update wallet.h --- src/wallet/wallet.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1bcb8cc6..f250de07 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -67,6 +67,8 @@ static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false; static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; //! -txconfirmtarget default static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6; +//! Largest (in bytes) free transaction we're willing to create +static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_DISABLE_WALLET = false; From 2dfcc9194d213fdb6d02bf33b80059250f68496c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 03:02:49 -0400 Subject: [PATCH 0866/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 78 ++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fa015b59..e5616075 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3614,40 +3614,47 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT nIn++; } - unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); + unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); - if (nExtraPayloadSize != 0) { - // account for extra payload in fee calculation - nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize; + // Remove scriptSigs if we used dummy signatures for fee calculation + if (!sign) { + BOOST_FOREACH (CTxIn& txin, txNew.vin) + txin.scriptSig = CScript(); } - if (nBytes > MAX_STANDARD_TX_SIZE) { - // Do not create oversized transactions (bad-txns-oversize). + // Embed the constructed transaction data in wtxNew. + *static_cast(&wtxNew) = CTransaction(txNew); + + // Limit size + if (nBytes >= MAX_STANDARD_TX_SIZE) + { strFailReason = _("Transaction too large"); return false; } - CTransaction txNewConst(txNew); - - // Remove scriptSigs to eliminate the fee calculation dummy signatures - for (auto& txin : txNew.vin) { - txin.scriptSig = CScript(); - } + dPriority = wtxNew.ComputePriority(dPriority, nBytes); - // Allow to override the default confirmation target over the CoinControl instance - int currentConfirmationTarget = nTxConfirmTarget; - if (coinControl && coinControl->nConfirmTarget > 0) - currentConfirmationTarget = coinControl->nConfirmTarget; + // Can we complete this as a free transaction? + // Note: InstantSend transaction can't be a free one + if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) + { + // Not enough fee: enough priority? + double dPriorityNeeded = mempool.estimateSmartPriority(nTxConfirmTarget); + // Require at least hard-coded AllowFree. + if (dPriority >= dPriorityNeeded && AllowFree(dPriority)) + break; - CAmount nFeeNeeded = std::max(nFeePay, GetMinimumFee(nBytes, currentConfirmationTarget, mempool)); + // Small enough, and priority high enough, to send for free +// if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded) +// break; + } + CAmount nFeeNeeded = max(nFeePay, GetMinimumFee(nBytes, nTxConfirmTarget, mempool)); if (coinControl && nFeeNeeded > 0 && coinControl->nMinimumTotalFee > nFeeNeeded) { nFeeNeeded = coinControl->nMinimumTotalFee; } if(fUseInstantSend) { - nFeeNeeded = std::max(nFeeNeeded, CTxLockRequest(txNew).GetMinFee(true)); + nFeeNeeded = std::max(nFeeNeeded, CTxLockRequest(txNew).GetMinFee()); } - if (coinControl && coinControl->fOverrideFeeRate) - nFeeNeeded = coinControl->nFeeRate.GetFee(nBytes); // If we made it here and we aren't even able to meet the relay fee on the next pass, give up // because we must be at the maximum allowed fee. @@ -3657,37 +3664,8 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT return false; } - if (nFeeRet >= nFeeNeeded) { - // Reduce fee to only the needed amount if we have change - // output to increase. This prevents potential overpayment - // in fees if the coins selected to meet nFeeNeeded result - // in a transaction that requires less fee than the prior - // iteration. - // TODO: The case where nSubtractFeeFromAmount > 0 remains - // to be addressed because it requires returning the fee to - // the payees and not the change output. - // TODO: The case where there is no change output remains - // to be addressed so we avoid creating too small an output. - if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) { - CAmount extraFeePaid = nFeeRet - nFeeNeeded; - std::vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; - change_position->nValue += extraFeePaid; - nFeeRet -= extraFeePaid; - } + if (nFeeRet >= nFeeNeeded) break; // Done, enough fee included. - } - - // Try to reduce change to include necessary fee - if (nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) { - CAmount additionalFeeNeeded = nFeeNeeded - nFeeRet; - std::vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; - // Only reduce change if remaining amount is still a large enough output. - if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { - change_position->nValue -= additionalFeeNeeded; - nFeeRet += additionalFeeNeeded; - break; // Done, able to increase fee from change - } - } // Include more fee and try again. nFeeRet = nFeeNeeded; From 1d78394ff1a26cc10ca2cedf2ea18ecad3cef0b8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:33:12 -0400 Subject: [PATCH 0867/1324] Update chatdialog.cpp --- src/qt/chatdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp index 3e3839f6..ceb94ade 100644 --- a/src/qt/chatdialog.cpp +++ b/src/qt/chatdialog.cpp @@ -17,7 +17,7 @@ #include "walletmodel.h" #include "base58.h" -#include "coincontrol.h" +#include "wallet/coincontrol.h" #include "validation.h" // mempool and minRelayTxFee #include "ui_interface.h" #include "txmempool.h" From 49d4c5a68569c7e7032ecd1dedc4e7bcec77f786 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:33:40 -0400 Subject: [PATCH 0868/1324] Delete coincontrol.h --- src/coincontrol.h | 74 ----------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/coincontrol.h diff --git a/src/coincontrol.h b/src/coincontrol.h deleted file mode 100644 index ff8f33a8..00000000 --- a/src/coincontrol.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_COINCONTROL_H -#define BITCOIN_COINCONTROL_H - -#include "primitives/transaction.h" - -/** Coin Control Features. */ -class CCoinControl -{ -public: - CTxDestination destChange; - bool fUsePrivateSend; - bool fUseInstantSend; - //! If false, allows unselected inputs, but requires all selected inputs be used - bool fAllowOtherInputs; - //! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria - bool fAllowWatchOnly; - //! Minimum absolute fee (not per kilobyte) - CAmount nMinimumTotalFee; - - CCoinControl() - { - SetNull(); - } - - void SetNull() - { - destChange = CNoDestination(); - fAllowOtherInputs = false; - fAllowWatchOnly = false; - setSelected.clear(); - fUseInstantSend = false; - fUsePrivateSend = true; - nMinimumTotalFee = 0; - } - - bool HasSelected() const - { - return (setSelected.size() > 0); - } - - bool IsSelected(const COutPoint& output) const - { - return (setSelected.count(output) > 0); - } - - void Select(const COutPoint& output) - { - setSelected.insert(output); - } - - void UnSelect(const COutPoint& output) - { - setSelected.erase(output); - } - - void UnSelectAll() - { - setSelected.clear(); - } - - void ListSelected(std::vector& vOutpoints) const - { - vOutpoints.assign(setSelected.begin(), setSelected.end()); - } - -private: - std::set setSelected; -}; - -#endif // BITCOIN_COINCONTROL_H From 2ea6de6a4c0d5ff24a5af724bfbfe6860a6d7ec9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:33:59 -0400 Subject: [PATCH 0869/1324] Update Makefile.am --- src/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 092d33e6..4f3defa8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -245,8 +245,7 @@ BITCOIN_CORE_H = \ zmq/zmqabstractnotifier.h \ zmq/zmqconfig.h\ zmq/zmqnotificationinterface.h \ - zmq/zmqpublishnotifier.h \ - coincontrol.h + zmq/zmqpublishnotifier.h obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj From d9f2d1eee14742207c9c171a0d28fba1c746212a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:39:53 -0400 Subject: [PATCH 0870/1324] Update init.cpp --- src/init.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 739edbdf..ddcd24d8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -450,7 +450,6 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands")); #endif } - strUsage += HelpMessageOpt("-sendfreetransactions", strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), DEFAULT_SEND_FREE_TRANSACTIONS)); strUsage += HelpMessageOpt("-datadir=", _("Specify data directory")); strUsage += HelpMessageOpt("-dbcache=", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache)); strUsage += HelpMessageOpt("-loadblock=", _("Imports blocks from external blk000??.dat file on startup")); @@ -1286,7 +1285,6 @@ bool AppInitParameterInteraction() fIsBareMultisigStd = GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes); - fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS); fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS); From dab96190fae310971bc0c405810ef8e12ca64cac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:40:43 -0400 Subject: [PATCH 0871/1324] Update util.cpp --- src/util.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index d7fa626e..9f33e155 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1054,4 +1054,3 @@ std::string SafeIntVersionToString(uint32_t nVersion) return "invalid_version"; } } - From 0ef18d7fc66591b12bafdbb993ec398036f0e261 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:41:52 -0400 Subject: [PATCH 0872/1324] Update validation.cpp From e2c5f60edc5004650454e9fe9526ff6a93f3d6d6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:42:24 -0400 Subject: [PATCH 0873/1324] Update validation.h --- src/validation.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/validation.h b/src/validation.h index 083dfaf4..47ec4e18 100644 --- a/src/validation.h +++ b/src/validation.h @@ -292,6 +292,7 @@ double ConvertBitsToDouble(unsigned int nBits); CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false); CAmount GetMasternodePayment(int nHeight, CAmount blockValue); CAmount GetDevelopersPayment(int nHeight, CAmount blockValue); +CAmount GetBlockSubsidy(int nHeight, CAmount blockValue); /** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex); From 9e063c1c852eedcffd7457e36949c5fa4046bcac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:43:24 -0400 Subject: [PATCH 0874/1324] Update wallet.cpp --- src/wallet/wallet.cpp | 80 +++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e5616075..7c116009 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -50,7 +50,6 @@ CWallet* pwalletMain = NULL; CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE); unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE; -bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS; bool bBIP69Enabled = true; CAmount collateralAmount = 1000000; @@ -3614,47 +3613,40 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT nIn++; } - unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); + unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); - // Remove scriptSigs if we used dummy signatures for fee calculation - if (!sign) { - BOOST_FOREACH (CTxIn& txin, txNew.vin) - txin.scriptSig = CScript(); + if (nExtraPayloadSize != 0) { + // account for extra payload in fee calculation + nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize; } - // Embed the constructed transaction data in wtxNew. - *static_cast(&wtxNew) = CTransaction(txNew); - - // Limit size - if (nBytes >= MAX_STANDARD_TX_SIZE) - { + if (nBytes > MAX_STANDARD_TX_SIZE) { + // Do not create oversized transactions (bad-txns-oversize). strFailReason = _("Transaction too large"); return false; } - dPriority = wtxNew.ComputePriority(dPriority, nBytes); - - // Can we complete this as a free transaction? - // Note: InstantSend transaction can't be a free one - if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) - { - // Not enough fee: enough priority? - double dPriorityNeeded = mempool.estimateSmartPriority(nTxConfirmTarget); - // Require at least hard-coded AllowFree. - if (dPriority >= dPriorityNeeded && AllowFree(dPriority)) - break; + CTransaction txNewConst(txNew); - // Small enough, and priority high enough, to send for free -// if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded) -// break; + // Remove scriptSigs to eliminate the fee calculation dummy signatures + for (auto& txin : txNew.vin) { + txin.scriptSig = CScript(); } - CAmount nFeeNeeded = max(nFeePay, GetMinimumFee(nBytes, nTxConfirmTarget, mempool)); + + // Allow to override the default confirmation target over the CoinControl instance + int currentConfirmationTarget = nTxConfirmTarget; + if (coinControl && coinControl->nConfirmTarget > 0) + currentConfirmationTarget = coinControl->nConfirmTarget; + + CAmount nFeeNeeded = std::max(nFeePay, GetMinimumFee(nBytes, currentConfirmationTarget, mempool)); if (coinControl && nFeeNeeded > 0 && coinControl->nMinimumTotalFee > nFeeNeeded) { nFeeNeeded = coinControl->nMinimumTotalFee; } if(fUseInstantSend) { - nFeeNeeded = std::max(nFeeNeeded, CTxLockRequest(txNew).GetMinFee()); + nFeeNeeded = std::max(nFeeNeeded, CTxLockRequest(txNew).GetMinFee(true)); } + if (coinControl && coinControl->fOverrideFeeRate) + nFeeNeeded = coinControl->nFeeRate.GetFee(nBytes); // If we made it here and we aren't even able to meet the relay fee on the next pass, give up // because we must be at the maximum allowed fee. @@ -3664,8 +3656,37 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT return false; } - if (nFeeRet >= nFeeNeeded) + if (nFeeRet >= nFeeNeeded) { + // Reduce fee to only the needed amount if we have change + // output to increase. This prevents potential overpayment + // in fees if the coins selected to meet nFeeNeeded result + // in a transaction that requires less fee than the prior + // iteration. + // TODO: The case where nSubtractFeeFromAmount > 0 remains + // to be addressed because it requires returning the fee to + // the payees and not the change output. + // TODO: The case where there is no change output remains + // to be addressed so we avoid creating too small an output. + if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) { + CAmount extraFeePaid = nFeeRet - nFeeNeeded; + std::vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; + change_position->nValue += extraFeePaid; + nFeeRet -= extraFeePaid; + } break; // Done, enough fee included. + } + + // Try to reduce change to include necessary fee + if (nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) { + CAmount additionalFeeNeeded = nFeeNeeded - nFeeRet; + std::vector::iterator change_position = txNew.vout.begin()+nChangePosInOut; + // Only reduce change if remaining amount is still a large enough output. + if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { + change_position->nValue -= additionalFeeNeeded; + nFeeRet += additionalFeeNeeded; + break; // Done, able to increase fee from change + } + } // Include more fee and try again. nFeeRet = nFeeNeeded; @@ -3710,7 +3731,6 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT strFailReason = _("Transaction has too long of a mempool chain"); return false; } - if (!fUseInstantSend && fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE); } return true; } From fb7ee36a2d1fc9606bdcefad24689f88c73cd2b0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:43:51 -0400 Subject: [PATCH 0875/1324] Update wallet.h --- src/wallet/wallet.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f250de07..49026792 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -44,7 +44,6 @@ extern CFeeRate payTxFee; extern unsigned int nTxConfirmTarget; extern bool bSpendZeroConfChange; extern bool bBIP69Enabled; -extern bool fSendFreeTransactions; static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000; //! -paytxfee default @@ -61,14 +60,10 @@ static const CAmount MIN_CHANGE = CENT; static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2; //! Default for -spendzeroconfchange static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; -//! Default for -sendfreetransactions -static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false; //! Default for -walletrejectlongchains static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; //! -txconfirmtarget default static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6; -//! Largest (in bytes) free transaction we're willing to create -static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_DISABLE_WALLET = false; From 499d0c2bc3a471352a8d365677469f2d7feae571 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:10 -0400 Subject: [PATCH 0876/1324] Delete chatdialog.ui --- src/qt/forms/chatdialog.ui | 1374 ------------------------------------ 1 file changed, 1374 deletions(-) delete mode 100644 src/qt/forms/chatdialog.ui diff --git a/src/qt/forms/chatdialog.ui b/src/qt/forms/chatdialog.ui deleted file mode 100644 index 762e717f..00000000 --- a/src/qt/forms/chatdialog.ui +++ /dev/null @@ -1,1374 +0,0 @@ - - - ChatDialog - - - - 0 - 0 - 850 - 526 - - - - Chat - - - - 8 - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - 0 - - - 10 - - - 10 - - - - - 15 - - - - - - 0 - 0 - - - - - 75 - true - - - - font-weight:bold; - - - Coin Control Features - - - - - - - - - 8 - - - 10 - - - - - - - - Inputs... - - - false - - - - - - - automatically selected - - - 5 - - - - - - - - 75 - true - - - - color:red;font-weight:bold; - - - Insufficient funds! - - - 5 - - - - - - - Qt::Horizontal - - - - 40 - 1 - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 20 - - - 0 - - - 10 - - - - - 10 - - - 14 - - - 10 - - - 4 - - - 6 - - - - - - 75 - true - - - - Quantity: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0 - - - 0 - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Bytes: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0 - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - Amount: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Dust: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - no - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - Fee: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - 10 - - - 14 - - - 6 - - - 4 - - - 6 - - - - - - 75 - true - - - - After Fee: - - - 0 - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 75 - true - - - - Change: - - - - - - - IBeamCursor - - - Qt::ActionsContextMenu - - - 0.00 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - - - - - - 12 - - - QLayout::SetDefaultConstraint - - - 5 - - - 5 - - - - - If this is activated, but the change address is empty or invalid, change will be sent to a newly generated address. - - - Custom change address - - - - - - - false - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - 3 - - - - - - - - - Qt::Vertical - - - - 800 - 1 - - - - - - - - - - - - - true - - - - - 0 - 0 - 830 - 69 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 6 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - 10 - - - 0 - - - - - 0 - - - - - 0 - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 1 - 4 - - - - - - - - 10 - - - - - - 0 - 0 - - - - - 75 - true - - - - font-weight:bold; - - - Transaction Fee: - - - - - - - - - - - - - - Choose... - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - collapse fee-settings - - - Hide - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 10 - - - 4 - - - 10 - - - 4 - - - - - 6 - - - - - - - If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. - - - per kilobyte - - - true - - - groupCustomFee - - - - - - - If the custom fee is set to 1000 duffs and the transaction is only 250 bytes, then "per kilobyte" only pays 250 duffs in fee,<br />while "total at least" pays 1000 duffs. For transactions bigger than a kilobyte both pay by kilobyte. - - - total at least - - - groupCustomFee - - - - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. - - - - - - - - - - true - - - Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.<br />But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process. - - - (read the tooltip) - - - 5 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - - - Recommended: - - - true - - - groupFee - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - - Custom: - - - groupFee - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - 6 - - - 2 - - - - - - - - - - 2 - - - - - - - - - - - - - - (Smart fee not initialized yet. This usually takes a few blocks...) - - - 2 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - - - - - Confirmation time: - - - 2 - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - 30 - - - - - 0 - - - 24 - - - 1 - - - 0 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - - - normal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - fast - - - - - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - - 8 - - - 4 - - - - - Send as zero-fee transaction if possible - - - - - - - (confirmation may take longer) - - - 5 - - - - - - - Qt::Horizontal - - - - 1 - 1 - - - - - - - - - - Qt::Vertical - - - - 1 - 1 - - - - - - - - - - - Qt::Vertical - - - - 800 - 1 - - - - - - - - - - - - - - - - 150 - 0 - - - - Confirm the send action - - - S&end - - - false - - - true - - - - - - - - 0 - 0 - - - - Clear all fields of the form. - - - Clear &All - - - false - - - - - - - Send to multiple recipients at once - - - Add &Recipient - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 3 - - - - - - 95 - 0 - - - - PrivateSend - - - false - - - - - - - true - - - - 85 - 0 - - - - InstantSend - - - - - - - Balance: - - - - - - - - 0 - 0 - - - - IBeamCursor - - - 123.456 IMG - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
- - BitcoinAmountField - QLineEdit -
bitcoinamountfield.h
- 1 -
-
- - - - - - - - -
\ No newline at end of file From c75376ceb16a0a3ff42f53162b09d27bcea07d9b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:16 -0400 Subject: [PATCH 0877/1324] Delete chatentry.ui --- src/qt/forms/chatentry.ui | 1333 ------------------------------------- 1 file changed, 1333 deletions(-) delete mode 100644 src/qt/forms/chatentry.ui diff --git a/src/qt/forms/chatentry.ui b/src/qt/forms/chatentry.ui deleted file mode 100644 index 90a2a1b9..00000000 --- a/src/qt/forms/chatentry.ui +++ /dev/null @@ -1,1333 +0,0 @@ - - - ChatEntry - - - - 0 - 0 - 729 - 552 - - - - Qt::TabFocus - - - false - - - 0 - - - - This is a normal payment. - - - QFrame::NoFrame - - - - 8 - - - 4 - - - 12 - - - 8 - - - - - 0 - - - - - The IMG address to send the message - - - - - - - Choose previously used address - - - - - - - 22 - 22 - - - - Alt+A - - - - - - - Paste address from clipboard - - - - - - - 22 - 22 - - - - Alt+P - - - - - - - - - Me: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 16777215 - 25 - - - - - - - - - - - 0 - - - - - IMG address to sender send you message - - - 33774 - - - - - - - - - - - 22 - 22 - - - - - - - - - - - - 22 - 22 - - - - - - - - Remove this entry - - - - - - - 22 - 22 - - - - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - chatTo - - - - - - - - 600 - 240 - - - - - 16777215 - 240 - - - - - - - - - 16777215 - 25 - - - - A message that was attached to the dash: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Dash network. - - - Qt::PlainText - - - - - - - 0 - - - 0 - - - - - - - 0 - - - 0 - - - - - - - - - true - - - - - - - false - - - false - - - The fee will be deducted from the amount being sent. The recipient will receive a lower amount of Dash than you enter in the amount field. If multiple recipients are selected, the fee is split equally. - - - S&ubtract fee from amount - - - - - - - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 191 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 191 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 191 - - - - - - - 127 - 127 - 63 - - - - - - - 170 - 170 - 84 - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 255 - - - - - - - 127 - 127 - 63 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 127 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 127 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - This is an unauthenticated payment request. - - - true - - - QFrame::NoFrame - - - - 12 - - - - - Pay To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0 - - - - - - - - Remove this entry - - - - - - - - - - - - Memo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::PlainText - - - - - - - A&mount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - payAmount_is - - - - - - - false - - - - - - - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 0 - 0 - 0 - - - - - - - 155 - 255 - 147 - - - - - - - 0 - 0 - 0 - - - - - - - 119 - 255 - 233 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 197 - 243 - 187 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 0 - 0 - 0 - - - - - - - 155 - 255 - 147 - - - - - - - 0 - 0 - 0 - - - - - - - 119 - 255 - 233 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 197 - 243 - 187 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 70 - 116 - 59 - - - - - - - 140 - 232 - 119 - - - - - - - 230 - 255 - 224 - - - - - - - 185 - 243 - 171 - - - - - - - 70 - 116 - 59 - - - - - - - 93 - 155 - 79 - - - - - - - 70 - 116 - 59 - - - - - - - 155 - 255 - 147 - - - - - - - 70 - 116 - 59 - - - - - - - 140 - 232 - 119 - - - - - - - 140 - 232 - 119 - - - - - - - 0 - 0 - 0 - - - - - - - 140 - 232 - 119 - - - - - - - 125 - 194 - 122 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - This is an authenticated payment request. - - - true - - - QFrame::NoFrame - - - - 12 - - - - - Pay To: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0 - - - - - Qt::PlainText - - - - - - - Remove this entry - - - - - - - - - - - - Memo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::PlainText - - - - - - - A&mount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - payAmount_s - - - - - - - false - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
- - BitcoinAmountField - QLineEdit -
bitcoinamountfield.h
- 1 -
-
- - addressBookButton - pasteButton - payAmount_is - deleteButton_is - payAmount_s - deleteButton_s - - - - - -
From 48401ed7900dcb8d94f458684e096b3d9057692b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:37 -0400 Subject: [PATCH 0878/1324] Delete chatdialog.cpp --- src/qt/chatdialog.cpp | 952 ------------------------------------------ 1 file changed, 952 deletions(-) delete mode 100644 src/qt/chatdialog.cpp diff --git a/src/qt/chatdialog.cpp b/src/qt/chatdialog.cpp deleted file mode 100644 index ceb94ade..00000000 --- a/src/qt/chatdialog.cpp +++ /dev/null @@ -1,952 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "chatdialog.h" -#include "ui_chatdialog.h" - -#include "addresstablemodel.h" -#include "bitcoinunits.h" -#include "clientmodel.h" -#include "coincontroldialog.h" -#include "guiutil.h" -#include "optionsmodel.h" -#include "platformstyle.h" -#include "chatentry.h" -#include "walletmodel.h" - -#include "base58.h" -#include "wallet/coincontrol.h" -#include "validation.h" // mempool and minRelayTxFee -#include "ui_interface.h" -#include "txmempool.h" -#include "wallet/wallet.h" - -#include "privatesend.h" - -#include -#include -#include -#include - -ChatDialog::ChatDialog(const PlatformStyle *platformStyle, QWidget *parent) : - QDialog(parent), - ui(new Ui::ChatDialog), - clientModel(0), - model(0), - fNewRecipientAllowed(true), - fFeeMinimized(true), - platformStyle(platformStyle) -{ - ui->setupUi(this); - QString theme = GUIUtil::getThemeName(); - - if (!platformStyle->getImagesOnButtons()) { - ui->addButton->setIcon(QIcon()); - ui->clearButton->setIcon(QIcon()); - ui->sendButton->setIcon(QIcon()); - } else { - ui->addButton->setIcon(QIcon(":/icons/" + theme + "/add")); - ui->clearButton->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->sendButton->setIcon(QIcon(":/icons/" + theme + "/send")); - - - } - - GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); - - addEntry(); - - connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); - connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); - - // Coin Control - connect(ui->pushButtonCoinControl, SIGNAL(clicked()), this, SLOT(coinControlButtonClicked())); - connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); - connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); - - // Dash specific - QSettings settings; - if (!settings.contains("bUseDarkSend")) - settings.setValue("bUseDarkSend", false); - if (!settings.contains("bUseInstantX")) - settings.setValue("bUseInstantX", false); -// - bool fUsePrivateSend = settings.value("bUseDarkSend").toBool(); - bool fUseInstantSend = settings.value("bUseInstantX").toBool(); - if(fLiteMode) { - ui->checkUsePrivateSend->setChecked(false); - ui->checkUsePrivateSend->setVisible(false); - ui->checkUseInstantSend->setVisible(false); - CoinControlDialog::coinControl->fUsePrivateSend = false; - CoinControlDialog::coinControl->fUseInstantSend = false; - } - else{ - ui->checkUsePrivateSend->setChecked(fUsePrivateSend); - ui->checkUseInstantSend->setChecked(fUseInstantSend); - CoinControlDialog::coinControl->fUsePrivateSend = fUsePrivateSend; - CoinControlDialog::coinControl->fUseInstantSend = fUseInstantSend; - } -// - connect(ui->checkUsePrivateSend, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); - connect(ui->checkUseInstantSend, SIGNAL(stateChanged ( int )), this, SLOT(updateInstantSend())); -// -// // Coin Control: clipboard actions - QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); - QAction *clipboardAmountAction = new QAction(tr("Copy amount"), this); - QAction *clipboardFeeAction = new QAction(tr("Copy fee"), this); - QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this); - QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this); - QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this); - QAction *clipboardChangeAction = new QAction(tr("Copy change"), this); - connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity())); - connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount())); - connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardFee())); - connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAfterFee())); - connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardBytes())); - connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardLowOutput())); - connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardChange())); - ui->labelCoinControlQuantity->addAction(clipboardQuantityAction); - ui->labelCoinControlAmount->addAction(clipboardAmountAction); - ui->labelCoinControlFee->addAction(clipboardFeeAction); - ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction); - ui->labelCoinControlBytes->addAction(clipboardBytesAction); - ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction); - ui->labelCoinControlChange->addAction(clipboardChangeAction); - - // init transaction fee section - if (!settings.contains("fFeeSectionMinimized")) - settings.setValue("fFeeSectionMinimized", true); - if (!settings.contains("nFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility - settings.setValue("nFeeRadio", 1); // custom - if (!settings.contains("nFeeRadio")) - settings.setValue("nFeeRadio", 0); // recommended - if (!settings.contains("nCustomFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility - settings.setValue("nCustomFeeRadio", 1); // total at least - if (!settings.contains("nCustomFeeRadio")) - settings.setValue("nCustomFeeRadio", 0); // per kilobyte - if (!settings.contains("nSmartFeeSliderPosition")) - settings.setValue("nSmartFeeSliderPosition", 0); - if (!settings.contains("nTransactionFee")) - settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); - if (!settings.contains("fPayOnlyMinFee")) - settings.setValue("fPayOnlyMinFee", false); - if (!settings.contains("fSendFreeTransactions")) - settings.setValue("fSendFreeTransactions", false); - - ui->groupFee->setId(ui->radioSmartFee, 0); - ui->groupFee->setId(ui->radioCustomFee, 1); - ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); - ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); - ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1); - ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); - ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt()); - ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); - ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); - ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); - minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); -} - -void ChatDialog::setClientModel(ClientModel *clientModel) -{ - this->clientModel = clientModel; - - if (clientModel) { - connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(updateSmartFeeLabel())); - } -} - -void ChatDialog::setModel(WalletModel *model) -{ - this->model = model; - - if(model && model->getOptionsModel()) - { - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - entry->setModel(model); - } - } - - setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), - model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); - connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount))); - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - updateDisplayUnit(); - - // Coin Control - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool))); - ui->frameCoinControl->setVisible(model->getOptionsModel()->getCoinControlFeatures()); - coinControlUpdateLabels(); - - // fee section - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel())); - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(updateGlobalFeeVariables())); - connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); - connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000)); - updateFeeSectionControls(); - updateMinFeeLabel(); - updateSmartFeeLabel(); - updateGlobalFeeVariables(); - } -} - -ChatDialog::~ChatDialog() -{ - QSettings settings; - settings.setValue("fFeeSectionMinimized", fFeeMinimized); - settings.setValue("nFeeRadio", ui->groupFee->checkedId()); - settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId()); - settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); - settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); - settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); - settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); - - delete ui; -} - -void ChatDialog::on_sendButton_clicked() -{ - if(!model || !model->getOptionsModel()) - return; - - QList recipients; - bool valid = true; - - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - if(entry->validate()) - { - recipients.append(entry->getValue()); - } - else - { - // valid = false; - } - } - } - - if(!valid || recipients.isEmpty()) - { - return; - } - - QString strFunds = tr("using") + " " + tr("anonymous funds") + ""; - QString strFee = ""; - recipients[0].inputType = ONLY_DENOMINATED; - - if(ui->checkUsePrivateSend->isChecked()) { - recipients[0].inputType = ONLY_DENOMINATED; - strFunds = tr("using") + " " + tr("anonymous funds") + ""; - QString strNearestAmount( - BitcoinUnits::formatWithUnit( - model->getOptionsModel()->getDisplayUnit(), CPrivateSend::GetSmallestDenomination())); - strFee = QString(tr( - "(privatesend requires this amount to be rounded up to the nearest %1)." - ).arg(strNearestAmount)); - } else { - recipients[0].inputType = ALL_COINS; - strFunds = tr("using") + " " + tr("any available funds (not anonymous)") + ""; - } - - if(ui->checkUseInstantSend->isChecked()) { - recipients[0].fUseInstantSend = true; - strFunds += " "; - strFunds += tr("and InstantSend"); - } else { - recipients[0].fUseInstantSend = false; - } - - - fNewRecipientAllowed = false; - // request unlock only if was locked or unlocked for mixing: - // this way we let users unlock by walletpassphrase or by menu - // and make many transactions while unlocking through this dialog - // will call relock - WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); - if(encStatus == model->Locked || encStatus == model->UnlockedForMixingOnly) - { - WalletModel::UnlockContext ctx(model->requestUnlock()); - if(!ctx.isValid()) - { - // Unlock wallet was cancelled - fNewRecipientAllowed = true; - return; - } - send(recipients, strFee, strFunds); - return; - } - // already unlocked or not encrypted at all - send(recipients, strFee, strFunds); -} - -void ChatDialog::send(QList recipients, QString strFee, QString strFunds) -{ - // prepare transaction for getting txFee earlier - WalletModelTransaction currentTransaction(recipients); - WalletModel::SendCoinsReturn prepareStatus; - if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled - prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); - else - prepareStatus = model->prepareTransaction(currentTransaction); - - // process prepareStatus and on error generate message shown to user - processSendCoinsReturn(prepareStatus, - BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); - - if(prepareStatus.status != WalletModel::OK) { - fNewRecipientAllowed = true; - return; - } - - CAmount txFee = currentTransaction.getTransactionFee(); - - // Format confirmation message - QStringList formatted; - Q_FOREACH(const SendCoinsRecipient &rcp, currentTransaction.getRecipients()) - { - // generate bold amount string - QString amount = "" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); - amount.append(" ").append(strFunds); - - // generate monospace address string - QString address = "" + rcp.address; - address.append(""); - - QString recipientElement; - - if (!rcp.paymentRequest.IsInitialized()) // normal payment - { - if(rcp.label.length() > 0) // label with address - { - recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); - recipientElement.append(QString(" (%1)").arg(address)); - } - else // just address - { - recipientElement = tr("%1 to %2").arg(amount, address); - } - } - else if(!rcp.authenticatedMerchant.isEmpty()) // authenticated payment request - { - recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); - } - else // unauthenticated payment request - { - recipientElement = tr("%1 to %2").arg(amount, address); - } - - formatted.append(recipientElement); - } - - QString questionString = tr("Are you sure you want to send?"); - questionString.append("

%1"); - - if(txFee > 0.5) - { - // append fee string if a fee is required - questionString.append("
"); - questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); - questionString.append(" "); - questionString.append(tr("are added as transaction fee")); - questionString.append(" "); - questionString.append(strFee); - - // append transaction size - questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)"); - } - - // add total amount in all subdivision units - questionString.append("
"); - CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; - QStringList alternativeUnits; - Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) - { - if(u != model->getOptionsModel()->getDisplayUnit()) - alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); - } - - // Show total amount + all alternative units - questionString.append(tr("Total Amount = %1
= %2") - .arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) - .arg(alternativeUnits.join("
= "))); - - // Limit number of displayed entries - int messageEntries = formatted.size(); - int displayedEntries = 0; - for(int i = 0; i < formatted.size(); i++){ - if(i >= MAX_SEND_POPUP_ENTRIESCHAT){ - formatted.removeLast(); - i--; - } - else{ - displayedEntries = i+1; - } - } - questionString.append("
"); - questionString.append(tr("(%1 of %2 entries displayed)").arg(displayedEntries).arg(messageEntries)); - - // Display message box - if(txFee > 0.05) - { - - QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), - questionString.arg(formatted.join("
")), - QMessageBox::Yes | QMessageBox::Cancel, - QMessageBox::Cancel); - - if(retval != QMessageBox::Yes) - { - fNewRecipientAllowed = true; - return; - } - } - // now send the prepared transaction - WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); - // process sendStatus and on error generate message shown to user - processSendCoinsReturn(sendStatus); - - if (sendStatus.status == WalletModel::OK) - { - accept(); - //CoinControlDialog::coinControl->UnSelectAll(); - coinControlUpdateLabels(); - } - fNewRecipientAllowed = true; -} - -void ChatDialog::clear() -{ - // Remove entries until only one left - while(ui->entries->count()) - { - ui->entries->takeAt(0)->widget()->deleteLater(); - } - addEntry(); - - updateTabsAndLabels(); -} - -void ChatDialog::reject() -{ - // clear(); -} - -void ChatDialog::accept() -{ - // clear(); -} - -ChatEntry *ChatDialog::addEntry() -{ - ChatEntry *entry = new ChatEntry(platformStyle, this); - entry->setModel(model); - ui->entries->addWidget(entry); - connect(entry, SIGNAL(removeEntry(ChatEntry*)), this, SLOT(removeEntry(ChatEntry*))); - connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); - connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels())); - - // Focus the field, so that entry can start immediately - entry->clear(); - entry->setFocus(); - ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint()); - qApp->processEvents(); - QScrollBar* bar = ui->scrollArea->verticalScrollBar(); - if(bar) - bar->setSliderPosition(bar->maximum()); - - updateTabsAndLabels(); - return entry; -} - -void ChatDialog::updateTabsAndLabels() -{ - setupTabChain(0); - coinControlUpdateLabels(); -} - -void ChatDialog::removeEntry(ChatEntry* entry) -{ - entry->hide(); - - // If the last entry is about to be removed add an empty one - if (ui->entries->count() == 1) - addEntry(); - - entry->deleteLater(); - - updateTabsAndLabels(); -} - -QWidget *ChatDialog::setupTabChain(QWidget *prev) -{ - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry) - { - prev = entry->setupTabChain(prev); - } - } - QWidget::setTabOrder(prev, ui->sendButton); - QWidget::setTabOrder(ui->sendButton, ui->clearButton); - QWidget::setTabOrder(ui->clearButton, ui->addButton); - return ui->addButton; -} - -void ChatDialog::setAddress(const QString &address) -{ - ChatEntry *entry = 0; - // Replace the first entry if it is still unused - if(ui->entries->count() == 1) - { - ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); - if(first->isClear()) - { - entry = first; - } - } - if(!entry) - { - entry = addEntry(); - } - - entry->setAddress(address); -} - -void ChatDialog::pasteEntry(const SendCoinsRecipient &rv) -{ - if(!fNewRecipientAllowed) - return; - - ChatEntry *entry = 0; - // Replace the first entry if it is still unused - if(ui->entries->count() == 1) - { - ChatEntry *first = qobject_cast(ui->entries->itemAt(0)->widget()); - if(first->isClear()) - { - entry = first; - } - } - if(!entry) - { - entry = addEntry(); - } - - entry->setValue(rv); - updateTabsAndLabels(); -} - -bool ChatDialog::handlePaymentRequest(const SendCoinsRecipient &rv) -{ - // Just paste the entry, all pre-checks - // are done in paymentserver.cpp. - pasteEntry(rv); - return true; -} - -void ChatDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, - const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance) -{ - Q_UNUSED(unconfirmedBalance); - Q_UNUSED(immatureBalance); - Q_UNUSED(anonymizedBalance); - Q_UNUSED(watchBalance); - Q_UNUSED(watchUnconfirmedBalance); - Q_UNUSED(watchImmatureBalance); - - if(model && model->getOptionsModel()) - { - uint64_t bal = 0; - QSettings settings; - settings.setValue("bUseDarkSend", ui->checkUsePrivateSend->isChecked()); - if(ui->checkUsePrivateSend->isChecked()) { - bal = anonymizedBalance; - } else { - bal = balance; - } - - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); - } -} - -void ChatDialog::updateDisplayUnit() -{ - setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(), - model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); - CoinControlDialog::coinControl->fUsePrivateSend = ui->checkUsePrivateSend->isChecked(); - coinControlUpdateLabels(); - ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - updateMinFeeLabel(); - updateSmartFeeLabel(); -} - -void ChatDialog::updateInstantSend() -{ - QSettings settings; - settings.setValue("bUseInstantX", ui->checkUseInstantSend->isChecked()); - CoinControlDialog::coinControl->fUseInstantSend = ui->checkUseInstantSend->isChecked(); - coinControlUpdateLabels(); -} - -void ChatDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) -{ - QPair msgParams; - // Default to a warning message, override if error message is needed - msgParams.second = CClientUIInterface::MSG_WARNING; - - // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. - // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() - // all others are used only in WalletModel::prepareTransaction() - switch(sendCoinsReturn.status) - { - case WalletModel::InvalidAddress: - msgParams.first = tr("The recipient address is not valid. Please recheck."); - break; - case WalletModel::InvalidAmount: - msgParams.first = tr("The amount to pay must be larger than 0."); - break; - case WalletModel::AmountExceedsBalance: - msgParams.first = tr("The amount exceeds your balance."); - break; - case WalletModel::AmountWithFeeExceedsBalance: - msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); - break; - case WalletModel::DuplicateAddress: - msgParams.first = tr("Duplicate address found: addresses should only be used once each."); - break; - case WalletModel::TransactionCreationFailed: - msgParams.first = tr("Transaction creation failed!"); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - case WalletModel::TransactionCommitFailed: - msgParams.first = tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - case WalletModel::AbsurdFee: - msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), maxTxFee)); - break; - case WalletModel::PaymentRequestExpired: - msgParams.first = tr("Payment request expired."); - msgParams.second = CClientUIInterface::MSG_ERROR; - break; - // included to prevent a compiler warning. - case WalletModel::OK: - default: - return; - } - - Q_EMIT message(tr("Send Coins"), msgParams.first, msgParams.second); -} - -void ChatDialog::minimizeFeeSection(bool fMinimize) -{ - ui->labelFeeMinimized->setVisible(fMinimize); - ui->buttonChooseFee ->setVisible(fMinimize); - ui->buttonMinimizeFee->setVisible(!fMinimize); - ui->frameFeeSelection->setVisible(!fMinimize); - ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0, 0); - fFeeMinimized = fMinimize; -} - -void ChatDialog::on_buttonChooseFee_clicked() -{ - minimizeFeeSection(false); -} - -void ChatDialog::on_buttonMinimizeFee_clicked() -{ - updateFeeMinimizedLabel(); - minimizeFeeSection(true); -} - -void ChatDialog::setMinimumFee() -{ - ui->radioCustomPerKilobyte->setChecked(true); - ui->customFee->setValue(CWallet::GetRequiredFee(1000)); -} - -void ChatDialog::updateFeeSectionControls() -{ - ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked()); - ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked()); - ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked()); - ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked()); - ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); - ui->radioCustomAtLeast ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() && CoinControlDialog::coinControl->HasSelected()); - ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); -} - -void ChatDialog::updateGlobalFeeVariables() -{ - if (ui->radioSmartFee->isChecked()) - { - nTxConfirmTarget = defaultConfirmTargetChat - ui->sliderSmartFee->value(); - payTxFee = CFeeRate(0); - - // set nMinimumTotalFee to 0 to not accidentally pay a custom fee - CoinControlDialog::coinControl->nMinimumTotalFee = 0; - } - else - { - nTxConfirmTarget = defaultConfirmTargetChat; - payTxFee = CFeeRate(ui->customFee->value()); - - // if user has selected to set a minimum absolute fee, pass the value to coincontrol - // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB - CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; - } - - fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); -} - -void ChatDialog::updateFeeMinimizedLabel() -{ - if(!model || !model->getOptionsModel()) - return; - - if (ui->radioSmartFee->isChecked()) - ui->labelFeeMinimized->setText(ui->labelSmartFee->text()); - else { - ui->labelFeeMinimized->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ui->customFee->value()) + - ((ui->radioCustomPerKilobyte->isChecked()) ? "/kB" : "")); - } -} - -void ChatDialog::updateMinFeeLabel() -{ - if (model && model->getOptionsModel()) - ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg( - BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB") - ); -} - -void ChatDialog::updateSmartFeeLabel() -{ - if(!model || !model->getOptionsModel()) - return; - - int nBlocksToConfirm = defaultConfirmTargetChat - ui->sliderSmartFee->value(); - int estimateFoundAtBlocks = nBlocksToConfirm; - CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks); - if (feeRate <= CFeeRate(0)) // not enough data => minfee - { - ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), - std::max(CWallet::fallbackFee.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); - ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) - ui->labelFeeEstimation->setText(""); - } - else - { - ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), - std::max(feeRate.GetFeePerK(), CWallet::GetRequiredFee(1000))) + "/kB"); - ui->labelSmartFee2->hide(); - ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", estimateFoundAtBlocks)); - } - - updateFeeMinimizedLabel(); -} - -// Coin Control: copy label "Quantity" to clipboard -void ChatDialog::coinControlClipboardQuantity() -{ - GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); -} - -// Coin Control: copy label "Amount" to clipboard -void ChatDialog::coinControlClipboardAmount() -{ - GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); -} - -// Coin Control: copy label "Fee" to clipboard -void ChatDialog::coinControlClipboardFee() -{ - GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "After fee" to clipboard -void ChatDialog::coinControlClipboardAfterFee() -{ - GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "Bytes" to clipboard -void ChatDialog::coinControlClipboardBytes() -{ - GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace(ASYMP_UTF8, "")); -} - -// Coin Control: copy label "Dust" to clipboard -void ChatDialog::coinControlClipboardLowOutput() -{ - GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); -} - -// Coin Control: copy label "Change" to clipboard -void ChatDialog::coinControlClipboardChange() -{ - GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace(ASYMP_UTF8, "")); -} - -// Coin Control: settings menu - coin control enabled/disabled by user -void ChatDialog::coinControlFeatureChanged(bool checked) -{ - ui->frameCoinControl->setVisible(checked); - - if (!checked && model) // coin control features disabled - CoinControlDialog::coinControl->SetNull(); - - coinControlUpdateLabels(); -} - -// Coin Control: button inputs -> show actual coin control dialog -void ChatDialog::coinControlButtonClicked() -{ - CoinControlDialog dlg(platformStyle); - dlg.setModel(model); - dlg.exec(); - coinControlUpdateLabels(); -} - -// Coin Control: checkbox custom change address -void ChatDialog::coinControlChangeChecked(int state) -{ - if (state == Qt::Unchecked) - { - CoinControlDialog::coinControl->destChange = CNoDestination(); - ui->labelCoinControlChangeLabel->clear(); - } - else - // use this to re-validate an already entered address - coinControlChangeEdited(ui->lineEditCoinControlChange->text()); - - ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); -} - -// Coin Control: custom change address changed -void ChatDialog::coinControlChangeEdited(const QString& text) -{ - if (model && model->getAddressTableModel()) - { - // Default to no change address until verified - CoinControlDialog::coinControl->destChange = CNoDestination(); - ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); - - CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); - - if (text.isEmpty()) // Nothing entered - { - ui->labelCoinControlChangeLabel->setText(""); - } - else if (!addr.IsValid()) // Invalid address - { - ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Dash address")); - } - else // Valid address - { - CKeyID keyid; - addr.GetKeyID(keyid); - if (!model->havePrivKey(keyid)) // Unknown change address - { - ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); - } - else // Known change address - { - ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); - - // Query label - QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); - if (!associatedLabel.isEmpty()) - ui->labelCoinControlChangeLabel->setText(associatedLabel); - else - ui->labelCoinControlChangeLabel->setText(tr("(no label)")); - - CoinControlDialog::coinControl->destChange = addr.Get(); - } - } - } -} - -// Coin Control: update labels -void ChatDialog::coinControlUpdateLabels() -{ - if (!model || !model->getOptionsModel()) - return; - - if (model->getOptionsModel()->getCoinControlFeatures()) - { - // enable minimum absolute fee UI controls - ui->radioCustomAtLeast->setVisible(true); - - // only enable the feature if inputs are selected - ui->radioCustomAtLeast->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked() &&CoinControlDialog::coinControl->HasSelected()); - } - else - { - // in case coin control is disabled (=default), hide minimum absolute fee UI controls - ui->radioCustomAtLeast->setVisible(false); - return; - } - - // set pay amounts - CoinControlDialog::payAmounts.clear(); - CoinControlDialog::fSubtractFeeFromAmount = false; - for(int i = 0; i < ui->entries->count(); ++i) - { - ChatEntry *entry = qobject_cast(ui->entries->itemAt(i)->widget()); - if(entry && !entry->isHidden()) - { - SendCoinsRecipient rcp = entry->getValue(); - CoinControlDialog::payAmounts.append(rcp.amount); - if (rcp.fSubtractFeeFromAmount) - CoinControlDialog::fSubtractFeeFromAmount = true; - } - } - - ui->checkUsePrivateSend->setChecked(CoinControlDialog::coinControl->fUsePrivateSend); - - if (CoinControlDialog::coinControl->HasSelected()) - { - // actual coin control calculation - CoinControlDialog::updateLabels(model, this); - - // show coin control stats - ui->labelCoinControlAutomaticallySelected->hide(); - ui->widgetCoinControl->show(); - } - else - { - // hide coin control stats - ui->labelCoinControlAutomaticallySelected->show(); - ui->widgetCoinControl->hide(); - ui->labelCoinControlInsuffFunds->hide(); - } -} From 6acd1b71afff419f7c2fa2954f8cdb0700ec37c1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:45 -0400 Subject: [PATCH 0879/1324] Delete chatdialog.h --- src/qt/chatdialog.h | 106 -------------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 src/qt/chatdialog.h diff --git a/src/qt/chatdialog.h b/src/qt/chatdialog.h deleted file mode 100644 index 5cf86c8f..00000000 --- a/src/qt/chatdialog.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_CHATDIALOG_H -#define BITCOIN_QT_CHATDIALOG_H - -#include "walletmodel.h" - -#include -#include - -static const int MAX_SEND_POPUP_ENTRIESCHAT = 10; - -class ClientModel; -class OptionsModel; -class PlatformStyle; -class ChatEntry; -class SendCoinsRecipient; - -namespace Ui { - class ChatDialog; -} - -QT_BEGIN_NAMESPACE -class QUrl; -QT_END_NAMESPACE - -const int defaultConfirmTargetChat = 25; - -/** Dialog for sending bitcoins */ -class ChatDialog : public QDialog -{ - Q_OBJECT - -public: - explicit ChatDialog(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ChatDialog(); - - void setClientModel(ClientModel *clientModel); - void setModel(WalletModel *model); - - /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907). - */ - QWidget *setupTabChain(QWidget *prev); - - void setAddress(const QString &address); - void pasteEntry(const SendCoinsRecipient &rv); - bool handlePaymentRequest(const SendCoinsRecipient &recipient); - -public Q_SLOTS: - void clear(); - void reject(); - void accept(); - ChatEntry *addEntry(); - void updateTabsAndLabels(); - void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, - const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); - -private: - Ui::ChatDialog *ui; - ClientModel *clientModel; - WalletModel *model; - bool fNewRecipientAllowed; - void send(QList recipients, QString strFee, QString strFunds); - bool fFeeMinimized; - const PlatformStyle *platformStyle; - - // Process WalletModel::SendCoinsReturn and generate a pair consisting - // of a message and message flags for use in Q_EMIT message(). - // Additional parameter msgArg can be used via .arg(msgArg). - void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString()); - void minimizeFeeSection(bool fMinimize); - void updateFeeMinimizedLabel(); - -private Q_SLOTS: - void on_sendButton_clicked(); - void on_buttonChooseFee_clicked(); - void on_buttonMinimizeFee_clicked(); - void removeEntry(ChatEntry* entry); - void updateDisplayUnit(); - void updateInstantSend(); - void coinControlFeatureChanged(bool); - void coinControlButtonClicked(); - void coinControlChangeChecked(int); - void coinControlChangeEdited(const QString &); - void coinControlUpdateLabels(); - void coinControlClipboardQuantity(); - void coinControlClipboardAmount(); - void coinControlClipboardFee(); - void coinControlClipboardAfterFee(); - void coinControlClipboardBytes(); - void coinControlClipboardLowOutput(); - void coinControlClipboardChange(); - void setMinimumFee(); - void updateFeeSectionControls(); - void updateMinFeeLabel(); - void updateSmartFeeLabel(); - void updateGlobalFeeVariables(); - -Q_SIGNALS: - // Fired when a message should be reported to the user - void message(const QString &title, const QString &message, unsigned int style); -}; - -#endif // BITCOIN_QT_CHATDIALOG_H From a86ac7575d1612eee415bf84810a22e86c051e6d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:53 -0400 Subject: [PATCH 0880/1324] Delete chatentry.cpp --- src/qt/chatentry.cpp | 442 ------------------------------------------- 1 file changed, 442 deletions(-) delete mode 100644 src/qt/chatentry.cpp diff --git a/src/qt/chatentry.cpp b/src/qt/chatentry.cpp deleted file mode 100644 index a23eb5d0..00000000 --- a/src/qt/chatentry.cpp +++ /dev/null @@ -1,442 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2014-2017 The Dash Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "chatentry.h" -#include "ui_chatentry.h" - -#include "addressbookpage.h" -#include "addresstablemodel.h" -#include "transactionfilterproxy.h" -#include "transactiontablemodel.h" -#include "guiutil.h" -#include "optionsmodel.h" -#include "platformstyle.h" -#include "walletmodel.h" -#include "base58.h" - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -typedef unsigned char BYTE; - -bool fileselectedchat=false; - -ChatEntry::ChatEntry(const PlatformStyle *platformStyle, QWidget *parent) : - QStackedWidget(parent), - ui(new Ui::ChatEntry), - model(0), - platformStyle(platformStyle) -{ - ui->setupUi(this); - - setCurrentWidget(ui->Chat); - - if (platformStyle->getUseExtraSpacing()) - ui->chatToLayout->setSpacing(4); - - - QString theme = GUIUtil::getThemeName(); - - // These icons are needed on Mac also! - ui->addressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); - ui->pasteButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - ui->deleteButton->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->deleteButton_is->setIcon(QIcon(":/icons/" + theme + "/remove")); - ui->deleteButton_s->setIcon(QIcon(":/icons/" + theme + "/remove")); - - //receive address icons - - ui->ReceiveAddressBookButton->setIcon(QIcon(":/icons/" + theme + "/address-book")); - ui->pasteReceiveButton->setIcon(QIcon(":/icons/" + theme + "/editpaste")); - - //ui->payAmount->setDisabled(true); - - ui->payAmount->setValue(0.0001); - - - // ui->payAmount->setVisible(false); - - // normal dash address field - GUIUtil::setupAddressWidget(ui->chatReceive, this); - GUIUtil::setupAddressWidget(ui->chatTo, this); - // just a label for displaying dash address(es) - ui->payTo_is->setFont(GUIUtil::fixedPitchFont()); - - // Connect signals - //connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged())); - //connect(ui->chatTo, SIGNAL(textChanged()), this, SIGNAL(on_chatTo_textChanged())); - //connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged())); - connect(ui->pasteButton, SIGNAL(clicked()), this, SLOT(on_pasteButton_clicked())); - connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); - connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked())); - connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked())); - - - connect(ui->ReceiveAddressBookButton, SIGNAL(clicked()), this, SLOT(on_addressReceiveBookButton_clicked())); - - connect(ui->pasteReceiveButton, SIGNAL(clicked()), this, SLOT(on_pasteReceiveAddressButton_clicked())); - - - - //connect(ui->chooserButton, SIGNAL(clicked()), this, SLOT(on_chooserButton_clicked())); - //connect(ui->pasteButtonBase64, SIGNAL(clicked()), this, SLOT(on_pasteButtonBase64_clicked())); - -} - -ChatEntry::~ChatEntry() -{ - delete ui; -} - -void ChatEntry::on_pasteButton_clicked() -{ - // Paste text from clipboard into recipient field - ui->chatTo->setText(QApplication::clipboard()->text()); -} - - -void ChatEntry::on_pasteReceiveAddressButton_clicked() -{ - // Paste text from clipboard into recipient field - ui->chatReceive->setText(QApplication::clipboard()->text()); -} - -void ChatEntry::on_addressBookButton_clicked() -{ - if(!model) - return; - AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this); - dlg.setModel(model->getAddressTableModel()); - if(dlg.exec()) - { - ui->chatTo->setText(dlg.getReturnValue()); - //ui->payAmount->setFocus(); - } -} - -void ChatEntry::on_addressReceiveBookButton_clicked() -{ - if(!model) - return; - AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); - dlg.setModel(model->getAddressTableModel()); - - if(dlg.exec()) - { - ui->chatReceive->setText(dlg.getReturnValue()); - //ui->payAmount->setFocus(); - } -} - -void ChatEntry::on_chatTo_textChanged(const QString &address) -{ - updateLabel(address); - checkaddresstransactions(address); -} - -void ChatEntry::on_chatReceive_textChanged(const QString &address) -{ - checkaddresstransactions(address); -} - -void ChatEntry::checkaddresstransactions(const QString &address) -{ - if (model->validateAddress(ui->chatTo->text()) && model->validateAddress(ui->chatReceive->text())) - { - - ui->chatTo->setDisabled(true); - ui->chatReceive->setDisabled(true); - transactionProxyModel = new TransactionFilterProxy(this); - transactionProxyModel->setAddressPrefix(ui->chatTo->text(),ui->chatReceive->text()); - transactionProxyModel->setSourceModel(model->getTransactionTableModel()); - - - - ui->chattableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - ui->chattableView->setTabKeyNavigation(false); - ui->chattableView->setContextMenuPolicy(Qt::CustomContextMenu); - ui->chattableView->installEventFilter(this); - - connect(ui->chattableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); - - transactionView = ui->chattableView; - transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - transactionView->setModel(transactionProxyModel); - transactionView->setAlternatingRowColors(true); - transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); - transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); - transactionView->setSortingEnabled(true); - transactionView->sortByColumn(TransactionTableModel::Date, Qt::AscendingOrder); - transactionView->verticalHeader()->hide(); - //transactionView->horizontalHeader()->hide(); - transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH); - //transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH); - transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH); - //transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH); - // Actions - - - connect(transactionView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(computeSum())); - - columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView,MINIMUM_COLUMN_WIDTH, this); - - - // show/hide column Watch-only - - transactionView->setColumnHidden(TransactionTableModel::Watchonly, true); //Watchonly - - transactionView->setColumnHidden(TransactionTableModel::ToAddress, true); //To address - - transactionView->setColumnHidden(TransactionTableModel::Amount, true); // Amount - - // Watch-only signal - // connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool))); - - - } -} - -void ChatEntry::setModel(WalletModel *model) -{ - this->model = model; - - if (model && model->getOptionsModel()) - connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - - clear(); -} - -void ChatEntry::clear() -{ - // clear UI elements for normal payment - ui->chatReceive->clear(); - ui->chatTo->clear(); - //ui->addAsLabel->clear(); - //ui->payAmount->clear(); - fileselectedchat=false; - //ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); - ui->messageTextLabel->clear(); - ui->messageTextLabel->hide(); - ui->messageLabel->hide(); - // clear UI elements for unauthenticated payment request - ui->payTo_is->clear(); - ui->memoTextLabel_is->clear(); - //ui->payAmount_is->clear(); - // clear UI elements for authenticated payment request - ui->payTo_s->clear(); - ui->memoTextLabel_s->clear(); - ui->payAmount_s->clear(); - - // update the display unit, to not use the default ("BTC") - updateDisplayUnit(); -} - -void ChatEntry::deleteClicked() -{ - Q_EMIT removeEntry(this); -} - -bool ChatEntry::validate() -{ - if (!model) - return false; - - - // Check input validity - bool retval = true; - - // Skip checks for payment request - if (recipient.paymentRequest.IsInitialized()) - return retval; - - if (!model->validateAddress(ui->chatTo->text())) - { - ui->chatTo->setValid(false); - retval = false; - } - - if (!model->validateAddress(ui->chatReceive->text())) - { - ui->chatReceive->setValid(false); - retval = false; - } - - if (!ui->payAmount->validate()) - { - retval = false; - } - - // Sending a zero amount is invalid - if (ui->payAmount->value(0) <= 0) - { - ui->payAmount->setValid(false); - retval = false; - } - - // Reject dust outputs: - // if (retval && GUIUtil::isDust(ui->chatTo->text(), ui->payAmount->value())) { - // ui->payAmount->setValid(false); - // retval = false; - //} - - return retval; -} - -SendCoinsRecipient ChatEntry::getValue() -{ - // Payment request - if (recipient.paymentRequest.IsInitialized()) - return recipient; - - // Normal payment - recipient.address = ui->chatTo->text(); - //recipient.label = ui->addAsLabel->text(); - recipient.amount = ui->payAmount->value(); - recipient.message = ui->messageTextLabel->text(); - recipient.fSubtractFeeFromAmount = false;//(ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); - - return recipient; -} - -QWidget *ChatEntry::setupTabChain(QWidget *prev) -{ - QWidget::setTabOrder(prev, ui->chatTo); - QWidget::setTabOrder(ui->chatTo, ui->labelchatTo); - //QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel); - //QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount); - //QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton); - - QWidget::setTabOrder(ui->ReceiveAddressBookButton, ui->pasteReceiveButton); - QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton); - QWidget::setTabOrder(ui->pasteButton, ui->deleteButton); - return ui->deleteButton; -} - -void ChatEntry::setValue(const SendCoinsRecipient &value) -{ - recipient = value; - - if (recipient.paymentRequest.IsInitialized()) // payment request - { - if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated - { - ui->chatTo->setText(recipient.address); - //ui->memoTextLabel_is->setText(recipient.message); - ui->payAmount_is->setValue(recipient.amount); - ui->payAmount->setValue(recipient.amount); - ui->payAmount_is->setReadOnly(true); - setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); - } - else // authenticated - { - ui->chatTo->setText(recipient.authenticatedMerchant); - //ui->memoTextLabel_s->setText(recipient.message); - - ui->payAmount_s->setValue(recipient.amount); - ui->payAmount_s->setReadOnly(true); - setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); - } - } - else // normal payment - { - // message - ui->messageTextLabel->setText(recipient.message); - ui->messageTextLabel->setVisible(!recipient.message.isEmpty()); - ui->messageLabel->setVisible(!recipient.message.isEmpty()); - - //ui->addAsLabel->clear(); - ui->chatTo->setText(recipient.address); // this may set a label from addressbook - if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label - ui->labelchatTo->setText(recipient.label); - ui->payAmount->setValue(recipient.amount); - } -} - -void ChatEntry::setAddress(const QString &address) -{ - ui->chatTo->setText(address); - //ui->payAmount->setFocus(); -} - -bool ChatEntry::isClear() -{ - return ui->chatTo->text().isEmpty() && ui->chatReceive->text().isEmpty(); -} - -void ChatEntry::setFocus() -{ - ui->chatTo->setFocus(); -} - -void ChatEntry::updateDisplayUnit() -{ - if(model && model->getOptionsModel()) - { - // Update payAmount with the current unit - ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); - } -} - -bool ChatEntry::updateLabel(const QString &address) -{ - if(!model) - return false; - - // Fill in label from address book, if address has an associated label - QString associatedLabel = model->getAddressTableModel()->labelForAddress(address); - if(!associatedLabel.isEmpty()) - { - ui->labelchatTo->setText(associatedLabel); - return true; - } - - return false; -} - -void ChatEntry::contextualMenu(const QPoint &point) -{ - QModelIndex index = transactionView->indexAt(point); - QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); - if (selection.empty()) - return; - - // check if transaction can be abandoned, disable context menu action in case it doesn't - uint256 hash; - hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); - // abandonAction->setEnabled(model->transactionCanBeAbandoned(hash)); - - if(index.isValid()) - { - contextMenu->exec(QCursor::pos()); - } -} From c9912273d5e92c0b2e0d230a77a04664d2fcda19 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:45:01 -0400 Subject: [PATCH 0881/1324] Delete chatentry.h --- src/qt/chatentry.h | 95 ---------------------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 src/qt/chatentry.h diff --git a/src/qt/chatentry.h b/src/qt/chatentry.h deleted file mode 100644 index 4f0ddca8..00000000 --- a/src/qt/chatentry.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers -// Copyright (c) 2019- The IMAGEcOIN Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_CHATENTRY_H -#define BITCOIN_QT_CHATENTRY_H - -#include "walletmodel.h" -#include "guiutil.h" -#include -#include - -class WalletModel; -class PlatformStyle; -class TransactionFilterProxy; -class QTableView; -class QMenu; - -namespace Ui { - class ChatEntry; -} - -/** - * A single entry in the dialog for sending bitcoins. - * Stacked widget, with different UIs for payment requests - * with a strong payee identity. - */ -class ChatEntry : public QStackedWidget -{ - Q_OBJECT - -public: - explicit ChatEntry(const PlatformStyle *platformStyle, QWidget *parent = 0); - ~ChatEntry(); - - void setModel(WalletModel *model); - bool validate(); - SendCoinsRecipient getValue(); - - /** Return whether the entry is still empty and unedited */ - bool isClear(); - - void setValue(const SendCoinsRecipient &value); - void setAddress(const QString &address); - - /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases - * (issue https://bugreports.qt-project.org/browse/QTBUG-10907). - */ - QWidget *setupTabChain(QWidget *prev); - - void setFocus(); - - enum ColumnWidths { - STATUS_COLUMN_WIDTH = 30, - WATCHONLY_COLUMN_WIDTH = 23, - DATE_COLUMN_WIDTH = 120, - TYPE_COLUMN_WIDTH = 180, - AMOUNT_MINIMUM_COLUMN_WIDTH = 120, - MINIMUM_COLUMN_WIDTH = 23 - }; - -public Q_SLOTS: - void clear(); - -Q_SIGNALS: - void removeEntry(ChatEntry *entry); - void payAmountChanged(); - void subtractFeeFromAmountChanged(); - -private Q_SLOTS: - void deleteClicked(); - void on_chatTo_textChanged(const QString &address); - void on_addressBookButton_clicked(); - void on_addressReceiveBookButton_clicked(); - void on_pasteButton_clicked(); - void on_pasteReceiveAddressButton_clicked(); - void updateDisplayUnit(); - void contextualMenu(const QPoint &); - void on_chatReceive_textChanged(const QString &address); - -private: - SendCoinsRecipient recipient; - Ui::ChatEntry *ui; - WalletModel *model; - const PlatformStyle *platformStyle; - TransactionFilterProxy *transactionProxyModel; - QTableView *transactionView; - QMenu *contextMenu; - GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; - bool updateLabel(const QString &address); - void checkaddresstransactions(const QString &address); -}; - -#endif // BITCOIN_QT_CHATIMGENTRY_H From 23dfae312b9a372b183c5d081d9b5f7a6f9179aa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:47:10 -0400 Subject: [PATCH 0882/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2a40a6ca..b8a33e51 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -144,8 +144,6 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * externalDonate(0), governanceAction(0), mainWindow(0), - chatAction(0), - chatMenuAction(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -501,23 +499,7 @@ void BitcoinGUI::createActions() connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); } - //chat - - chatAction = new QAction(QIcon(":/icons/" + theme + "/overview"), tr("&Messenger"), this); - chatAction->setStatusTip(tr("Messenger")); - chatAction->setToolTip(chatAction->statusTip()); - chatAction->setCheckable(true); - - #ifdef Q_OS_MAC - chatAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); - #else - chatAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); - #endif - tabGroup->addAction(chatAction); - - chatMenuAction = new QAction(QIcon(":/icons/" + theme + "/overview"), chatAction->text(), this); - chatMenuAction->setStatusTip(chatAction->statusTip()); - chatMenuAction->setToolTip(chatMenuAction->statusTip()); + /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -546,12 +528,7 @@ void BitcoinGUI::createActions() connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage())); /* connect(privatesendAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(privatesendAction, SIGNAL(triggered()), this, SLOT(gotoPrivateSendPage())); */ - connect(chatAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(chatAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); - - connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(chatMenuAction, SIGNAL(triggered()), this, SLOT(gotoChatPage())); - + #endif // ENABLE_WALLET quitAction = new QAction(QIcon(":/icons/" + theme + "/quit"), tr("E&xit"), this); @@ -630,7 +607,7 @@ void BitcoinGUI::createActions() externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World Chat")); + mainWindow->setStatusTip(tr("HTH World")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -761,8 +738,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(overviewAction); toolbar->addAction(sendCoinsAction); toolbar->addAction(receiveCoinsAction); - toolbar->addAction(historyAction); - toolbar->addAction(chatAction); + toolbar->addAction(historyAction); /* toolbar->addAction(privatesendAction); */ @@ -922,9 +898,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) sendCoinsMenuAction->setEnabled(enabled); receiveCoinsAction->setEnabled(enabled); receiveCoinsMenuAction->setEnabled(enabled); - historyAction->setEnabled(enabled); - chatAction->setEnabled(enabled); - chatMenuAction->setEnabled(enabled); + historyAction->setEnabled(enabled); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); @@ -1078,12 +1052,6 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoChatPage() -{ - chatAction->setChecked(true); - if (walletFrame) walletFrame->gotoChatPage(); -} - void BitcoinGUI::gotoMainWindow() { mainWindow->setChecked(true); From c44228865f84fdb178ed5da548d49b98b1ac490b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:47:40 -0400 Subject: [PATCH 0883/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index f7f5795e..050853f2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -104,8 +104,7 @@ class BitcoinGUI : public QMainWindow QProgressDialog *progressDialog; QMenuBar *appMenuBar; - QAction *chatAction; - QAction *chatMenuAction; + QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; @@ -234,8 +233,7 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to chat coins page */ - void gotoChatPage(); + /** Switch to social media page */ void gotoMainWindow(); From 574e0128aafe3bfa75cabb1631c29753b31dd098 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:48:01 -0400 Subject: [PATCH 0884/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index d302123c..abf30d21 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,13 +108,6 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoChatPage() -{ - QMap::const_iterator i; - for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoChatPage(); -} - void WalletFrame::gotoMainWindow() { From 4138673b5f940af8502e4688ffd01135a1f2dc2a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:48:23 -0400 Subject: [PATCH 0885/1324] Update walletframe.h --- src/qt/walletframe.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index a5220949..cd335d21 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,8 +63,7 @@ class WalletFrame : public QFrame public Q_SLOTS: - /** Switch to WebWindow page */ - void gotoChatPage(); + /** Switch to social media page */ void gotoGovernancePage(); /** Switch to social media page */ From 3aed7d0b617f9c01e384e4e0e141ecd7989d9ac3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:49:42 -0400 Subject: [PATCH 0886/1324] Update walletview.cpp --- src/qt/walletview.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 20197042..27f5558d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,6 @@ #include "transactionview.h" #include "walletmodel.h" #include "privatesendpage.h" -#include "chatdialog.h" #include "ui_interface.h" @@ -75,10 +74,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): receiveCoinsPage = new ReceiveCoinsDialog(platformStyle); sendCoinsPage = new SendCoinsDialog(platformStyle); - governanceListPage = new GovernanceList(platformStyle); - ChatPage = new ChatDialog(platformStyle); - addWidget(governanceListPage); - + governanceListPage = new GovernanceList(platformStyle); usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this); usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this); @@ -87,8 +83,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(transactionsPage); addWidget(receiveCoinsPage); addWidget(sendCoinsPage); - addWidget(privateSendPage); - addWidget(ChatPage); + addWidget(privateSendPage); mainWindow = new MainWindow(); addWidget(mainWindow); @@ -118,10 +113,7 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked())); // Pass through messages from sendCoinsPage - connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); - - // Pass through messages from ChatPage - connect(ChatPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); + connect(sendCoinsPage, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); // Pass through messages from transactionView connect(transactionView, SIGNAL(message(QString,QString,unsigned int)), this, SIGNAL(message(QString,QString,unsigned int))); @@ -163,7 +155,6 @@ void WalletView::setClientModel(ClientModel *_clientModel) privateSendPage->setClientModel(_clientModel); sendCoinsPage->setClientModel(_clientModel); governanceListPage->setClientModel(_clientModel); - ChatPage->setClientModel(clientModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setClientModel(_clientModel); @@ -180,7 +171,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel) overviewPage->setWalletModel(_walletModel); privateSendPage->setWalletModel(_walletModel); governanceListPage->setWalletModel(_walletModel); - ChatPage->setModel(walletModel); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); @@ -244,11 +234,6 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoChatPage() -{ - setCurrentWidget(ChatPage); -} - void WalletView::gotoMainWindow() { setCurrentWidget(mainWindow); From 2df5e01b0c09b289a27bf256fed5f98f6373d186 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:50:13 -0400 Subject: [PATCH 0887/1324] Update walletview.h --- src/qt/walletview.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 0556f46d..3be6fd21 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -26,9 +26,6 @@ class AddressBookPage; class PrivateSendPage; class GovernancePage; class MainWindow; -class ChatDialog; - - QT_BEGIN_NAMESPACE class QLabel; @@ -78,7 +75,6 @@ class WalletView : public QStackedWidget PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; MainWindow *mainWindow; - ChatDialog *ChatPage; TransactionView *transactionView; @@ -88,8 +84,7 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to chat page */ - void gotoChatPage(); + /** Switch to social media page */ void gotoMainWindow(); /** Switch to governance page */ From fca3440571097cb33931c879867e77b5eba249fc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:50:58 -0400 Subject: [PATCH 0888/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 153c4e3d..e19666ae 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -60,9 +60,7 @@ QT_FORMS_UI = \ qt/forms/homepage.ui \ qt/forms/mainwindow.ui \ qt/forms/secdialog.ui \ - qt/forms/profilepage.ui \ - qt/forms/chatdialog.ui \ - qt/forms/chatentry.ui + qt/forms/profilepage.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -128,9 +126,7 @@ QT_MOC_CPP = \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ - qt/moc_user.cpp \ - qt/moc_chatdialog.cpp \ - qt/moc_chatentry.cpp + qt/moc_user.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -227,9 +223,7 @@ BITCOIN_QT_H = \ qt/profilepage.h \ qt/qcustomplot.h \ qt/statistics.h \ - qt/user.h \ - qt/chatdialog.h \ - qt/chatentry.h + qt/user.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -582,9 +576,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ qt/statistics.cpp \ - qt/user.cpp \ - qt/chatdialog.cpp \ - qt/chatentry.cpp + qt/user.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From ed7889ddf5f3c04176e7e2dd8eea1994125f93f0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:54:05 -0400 Subject: [PATCH 0889/1324] Update coincontroldialog.cpp --- src/qt/coincontroldialog.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index a58b1c4e..81516b33 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -501,7 +501,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) unsigned int nBytesInputs = 0; unsigned int nQuantity = 0; int nQuantityUncompressed = 0; - bool fAllowFree = false; std::vector vCoinControl; std::vector vOutputs; @@ -563,15 +562,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // InstantSend Fee if (coinControl->fUseInstantSend) nPayFee = std::max(nPayFee, CTxLockRequest(txDummy).GetMinFee(true)); - - // Allow free? (require at least hard-coded threshold and default to that if no estimate) - double mempoolEstimatePriority = mempool.estimateSmartPriority(nTxConfirmTarget); - dPriority = dPriorityInputs / (nBytes - nBytesInputs + (nQuantityUncompressed * 29)); // 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 bytes of the input are ignored for priority) - double dPriorityNeeded = std::max(mempoolEstimatePriority, AllowFreeThreshold()); - fAllowFree = (dPriority >= dPriorityNeeded); - if (fSendFreeTransactions) - if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE) - nPayFee = 0; if (nPayAmount > 0) { From f09e7b18acb2fccc5a3257b56f846cf28b2d3746 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:54:28 -0400 Subject: [PATCH 0890/1324] Update coincontroldialog.h From 3a1774cc1564e1770fa774ea06bbbbacc2d878af Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:56:02 -0400 Subject: [PATCH 0891/1324] Update sendcoinsdialog.cpp --- src/qt/sendcoinsdialog.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index a8315108..3d7a0155 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -134,8 +134,6 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); if (!settings.contains("fPayOnlyMinFee")) settings.setValue("fPayOnlyMinFee", false); - if (!settings.contains("fSendFreeTransactions")) - settings.setValue("fSendFreeTransactions", false); ui->groupFee->setId(ui->radioSmartFee, 0); ui->groupFee->setId(ui->radioCustomFee, 1); @@ -145,7 +143,6 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); - ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); } @@ -224,7 +221,6 @@ SendCoinsDialog::~SendCoinsDialog() settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); - settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); delete ui; } @@ -734,7 +730,6 @@ void SendCoinsDialog::updateGlobalFeeVariables() // set nMinimumTotalFee to 0 in case of user has selected that the fee is per KB CoinControlDialog::coinControl->nMinimumTotalFee = ui->radioCustomAtLeast->isChecked() ? ui->customFee->value() : 0; } - fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); } void SendCoinsDialog::updateFeeMinimizedLabel() From afa4a70f870b37f7cb1df8573f6a1b2fc73a1872 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:07:58 -0400 Subject: [PATCH 0892/1324] Update main.cpp --- src/qt/main.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 4a4ca2b9..3825131f 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,12 +1,73 @@ -#include "mainwindow.h" -#include -#include "homepage.h" +// Main program -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); +int main() { + + + + User user1; + + ifstream usersFile("userData.txt"); + + long begin, end; + + + + if (usersFile.good()) + + { + + cout << "File userData.txt found!\n\n"; + + } + + + + else { + + user1.userRegister(); + + } + + + + if(usersFile.is_open()) + + { + + begin = usersFile.tellg(); + + usersFile.seekg (0, ios::end); + + + + end = usersFile.tellg(); + + usersFile.close(); + + + + if(begin == end) + + { + + user1.userRegister(); + + } + + + + else + + { + + user1.login(); + + } + + } + + + + getch(); - return a.exec(); } From 84f0d8c058c481a3afe5453e51e3240e3812eb69 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:09:11 -0400 Subject: [PATCH 0893/1324] Delete main.cpp --- src/qt/main.cpp | 73 ------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp deleted file mode 100644 index 3825131f..00000000 --- a/src/qt/main.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Main program - -int main() { - - - - User user1; - - ifstream usersFile("userData.txt"); - - long begin, end; - - - - if (usersFile.good()) - - { - - cout << "File userData.txt found!\n\n"; - - } - - - - else { - - user1.userRegister(); - - } - - - - if(usersFile.is_open()) - - { - - begin = usersFile.tellg(); - - usersFile.seekg (0, ios::end); - - - - end = usersFile.tellg(); - - usersFile.close(); - - - - if(begin == end) - - { - - user1.userRegister(); - - } - - - - else - - { - - user1.login(); - - } - - } - - - - getch(); - -} From 0554d5f3a4561d6e3818241e01c21730ee9ed944 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:10:41 -0400 Subject: [PATCH 0894/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 155 +++++++++++++++++++++++++++++++----------- 1 file changed, 114 insertions(+), 41 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index cad1d02f..c4cde86a 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,45 +1,118 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "secdialog.h" -#include -#include "homepage.h" -#include "QMessageBox" -#include - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include -#include - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - QPixmap pix(":/icons/chat.png"); - int w = ui->label_pic->width(); - int h = ui->label_pic->height(); - ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); - -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::on_pushButton_Login_clicked() -{ - QString username = ui->lineEdit_username->text(); - QString password = ui->lineEdit_password->text(); - - if(username == "test" && password == "test") { - QMessageBox::information(this, "Login", "Username and password is correct"); - //hide(); - secDialog = new SecDialog(this); - secDialog->show(); +#include +#include +#include +#include +using namespace std; + +class User { + +public: + string username; + string password; + string inputUsername; + string inputPassword; + + // User registration + void userRegisterDo() + { + + ofstream usersFile ("userData.txt"); + + if ( !usersFile.is_open()) + { + usersFile.open("userData.txt"); + } + + usersFile << username << " " << password << endl; + + usersFile.close(); + } + + // Initialize user registration + void userRegister() + { + cout << "Welcome!\n-------------------------\n\nPlease register.\nEnter a new username:\n"; + cin >> username; + + cout << "\nPlease enter a new password:\n"; + cin >> password; + + userRegisterDo(); + } + + // User login function + void login() + { + cout << "Please enter your username:\n"; + cin >> inputUsername; + + cout << "\nPlease enter your password:\n"; + cin >> inputPassword; + + string userAndPass = inputUsername + " " + inputPassword; // Search pattern + int offset; + string line; + ifstream usersFile; + usersFile.open ("userData.txt"); + + if(usersFile.is_open()) + { + while(!usersFile.eof()) + { + getline(usersFile,line); + if ((offset = line.find(userAndPass, 0)) != string::npos) { // if login data is found + cout << "found " << userAndPass << endl; + } + + else // if login data is not found + { + cout << "\nUsername and/or password incorrect!\n\n\n\n"; + login(); + } + } + + usersFile.close(); + } + else + cout << "Unable to open userData.txt file." << endl; + } + +}; + +// Main program +int main() { + + User user1; + ifstream usersFile("userData.txt"); + long begin, end; + + if (usersFile.good()) + { + cout << "File userData.txt found!\n\n"; } + else { - QMessageBox::warning(this,"Login", "Username and password is not correct"); + user1.userRegister(); } + + if(usersFile.is_open()) + { + begin = usersFile.tellg(); + usersFile.seekg (0, ios::end); + + end = usersFile.tellg(); + usersFile.close(); + + if(begin == end) + { + user1.userRegister(); + } + + else + { + user1.login(); + } + } + + getch(); } From b6739402e0add9fd7215653a21baa3b9a837ab47 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:10:56 -0400 Subject: [PATCH 0895/1324] Delete mainwindow.h --- src/qt/mainwindow.h | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/qt/mainwindow.h diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h deleted file mode 100644 index ff08c581..00000000 --- a/src/qt/mainwindow.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include "secdialog.h" - -namespace Ui { - class MainWindow; -} - -class MainWindow : public QMainWindow - -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private Q_SLOTS: - - void on_pushButton_Login_clicked(); - -private: - Ui::MainWindow *ui; - SecDialog *secDialog; -}; - -#endif // MAINWINDOW_H From 24bf281e53b723f9b8a6d60040cc06414749e516 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:11:07 -0400 Subject: [PATCH 0896/1324] Delete secdialog.cpp --- src/qt/secdialog.cpp | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/qt/secdialog.cpp diff --git a/src/qt/secdialog.cpp b/src/qt/secdialog.cpp deleted file mode 100644 index 4d2045c9..00000000 --- a/src/qt/secdialog.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "secdialog.h" -#include "ui_secdialog.h" - -SecDialog::SecDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::SecDialog) -{ - ui->setupUi(this); -} - -SecDialog::~SecDialog() -{ - delete ui; -} From 5f1673b341bce8aa073ca46a1fdf89877f748fd9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:11:20 -0400 Subject: [PATCH 0897/1324] Delete secdialog.h --- src/qt/secdialog.h | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/qt/secdialog.h diff --git a/src/qt/secdialog.h b/src/qt/secdialog.h deleted file mode 100644 index 533f3eee..00000000 --- a/src/qt/secdialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SECDIALOG_H -#define SECDIALOG_H - -#include - -namespace Ui { -class SecDialog; -} - -class SecDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SecDialog(QWidget *parent = 0); - ~SecDialog(); - -private: - Ui::SecDialog *ui; -}; - -#endif // SECDIALOG_H From 1a509d7c177fb60fe3769f88648da0279c716fa1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:11:32 -0400 Subject: [PATCH 0898/1324] Delete secdialog.ui --- src/qt/forms/secdialog.ui | 195 -------------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 src/qt/forms/secdialog.ui diff --git a/src/qt/forms/secdialog.ui b/src/qt/forms/secdialog.ui deleted file mode 100644 index c75b062c..00000000 --- a/src/qt/forms/secdialog.ui +++ /dev/null @@ -1,195 +0,0 @@ - - - SecDialog - - - - 0 - 0 - 532 - 312 - - - - MainWindow - - - - - - - - - - - - Times New Roman - 16 - 75 - true - - - - if you already have an account ---> - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign In - - - - - - - - - - - - - - - - Times New Roman - 14 - 75 - true - - - - User Name - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Email - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Password - - - lineEdit_2 - - - - - - - - Times New Roman - 14 - 75 - true - - - - Confirm Password - - - lineEdit_3 - - - - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - QLineEdit::Password - - - - - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign Up - - - - - - - - - - - - - 0 - 0 - 532 - 21 - - - - - - - - From 9ce4aea23862bb8524dc03d304f1766b8c84d0c7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:11:42 -0400 Subject: [PATCH 0899/1324] Delete mainwindow.ui --- src/qt/forms/mainwindow.ui | 537 ------------------------------------- 1 file changed, 537 deletions(-) delete mode 100644 src/qt/forms/mainwindow.ui diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui deleted file mode 100644 index ffc59ece..00000000 --- a/src/qt/forms/mainwindow.ui +++ /dev/null @@ -1,537 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 464 - 319 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 106 - 100 - 92 - - - - - - - 255 - 255 - 255 - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - MainWindow - - - - - - - - - - - No account? Create one! - - - - - - - - - - - - - - - - 10 - 75 - true - - - - User Name - - - - - - - - 10 - 75 - true - - - - Password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - PointingHandCursor - - - Log In - - - - - - - - - - - - - 0 - 0 - 464 - 21 - - - - - - TopToolBarArea - - - false - - - - - - - - From 068a302e25793356934a88d98621bafeb2630f6c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:12:32 -0400 Subject: [PATCH 0900/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e19666ae..1734d863 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -58,8 +58,6 @@ QT_FORMS_UI = \ qt/forms/dialog.ui \ qt/forms/form.ui \ qt/forms/homepage.ui \ - qt/forms/mainwindow.ui \ - qt/forms/secdialog.ui \ qt/forms/profilepage.ui QT_MOC_CPP = \ @@ -120,8 +118,6 @@ QT_MOC_CPP = \ qt/moc_fileman.cpp \ qt/moc_form.cpp \ qt/moc_homepage.cpp \ - qt/moc_mainwindow.cpp \ - qt/moc_secdialog.cpp \ qt/moc_posts.cpp \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ @@ -217,8 +213,6 @@ BITCOIN_QT_H = \ qt/fileman.h \ qt/form.h \ qt/homepage.h \ - qt/mainwindow.h \ - qt/secdialog.h \ qt/posts.h \ qt/profilepage.h \ qt/qcustomplot.h \ @@ -569,9 +563,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/fileman.cpp \ qt/form.cpp \ qt/homepage.cpp \ - qt/main.cpp \ - qt/mainwindow.cpp \ - qt/secdialog.cpp \ qt/posts.cpp \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ From a371846736063d95ab6e6714255344812de10295 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:13:34 -0400 Subject: [PATCH 0901/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 1734d863..a9479878 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -122,7 +122,8 @@ QT_MOC_CPP = \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ - qt/moc_user.cpp + qt/moc_user.cpp \ + qt/moc_mainwindow.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -567,7 +568,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ qt/statistics.cpp \ - qt/user.cpp + qt/user.cpp \ + qt/mainwindow.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From a24324d79f84a05d829d1555c3fa6f26850dd092 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:18:16 -0400 Subject: [PATCH 0902/1324] Update and rename mainwindow.cpp to mainwindow.h --- src/qt/{mainwindow.cpp => mainwindow.h} | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) rename src/qt/{mainwindow.cpp => mainwindow.h} (74%) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.h similarity index 74% rename from src/qt/mainwindow.cpp rename to src/qt/mainwindow.h index c4cde86a..cf7d3ffd 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.h @@ -55,22 +55,22 @@ class User { ifstream usersFile; usersFile.open ("userData.txt"); - if(usersFile.is_open()) - { - while(!usersFile.eof()) - { - getline(usersFile,line); - if ((offset = line.find(userAndPass, 0)) != string::npos) { // if login data is found - cout << "found " << userAndPass << endl; - } - - else // if login data is not found - { - cout << "\nUsername and/or password incorrect!\n\n\n\n"; - login(); - } - } - + bool found = false; + if(usersFile.is_open()) { + while(getline(usersFile,line) && !found) { + if (line.compare(userAndPass) == 0) { //match strings exactly! + found = true; // found is true => break loop + } + } + usersFile.close(); //close the file before recursivly opening it again later + if(found) { + cout << "Welcome "<< inputUsername << '\n'; + } + else { + cout << "\nUsername and/or password incorrect!\n\n\n\n"; + login(); //ok we didn't find them, lets redue this! + } + } usersFile.close(); } else From 505d53de1697d28e3926170fea8cecdff29ed541 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:19:10 -0400 Subject: [PATCH 0903/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a9479878..d0a55712 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -122,8 +122,7 @@ QT_MOC_CPP = \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ - qt/moc_user.cpp \ - qt/moc_mainwindow.cpp + qt/moc_user.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -218,7 +217,8 @@ BITCOIN_QT_H = \ qt/profilepage.h \ qt/qcustomplot.h \ qt/statistics.h \ - qt/user.h + qt/user.h \ + qt/mainwindow.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -568,8 +568,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ qt/statistics.cpp \ - qt/user.cpp \ - qt/mainwindow.cpp + qt/user.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 39a84f4dbfc594f50da9781c8a79a6e7ee184ba9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:24:24 -0400 Subject: [PATCH 0904/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index cf7d3ffd..10ebfdd9 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -77,8 +77,6 @@ class User { cout << "Unable to open userData.txt file." << endl; } -}; - // Main program int main() { From 12e87f71fb4e3d3a62f0546b79cb1f463b273a33 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:28:24 -0400 Subject: [PATCH 0905/1324] Update mainwindow.h --- src/qt/mainwindow.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 10ebfdd9..789f93b2 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -71,11 +71,8 @@ class User { login(); //ok we didn't find them, lets redue this! } } - usersFile.close(); - } - else - cout << "Unable to open userData.txt file." << endl; } + } // Main program int main() { From 22356d5f258f3642aba1fa2166c3f45ace5c16c9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:34:38 -0400 Subject: [PATCH 0906/1324] Update mainwindow.h --- src/qt/mainwindow.h | 152 +++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 102 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 789f93b2..a75966f1 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,113 +1,61 @@ #include #include -#include #include -using namespace std; - -class User { - -public: - string username; - string password; - string inputUsername; - string inputPassword; - - // User registration - void userRegisterDo() - { - - ofstream usersFile ("userData.txt"); - - if ( !usersFile.is_open()) - { - usersFile.open("userData.txt"); - } - - usersFile << username << " " << password << endl; - - usersFile.close(); - } - - // Initialize user registration - void userRegister() - { - cout << "Welcome!\n-------------------------\n\nPlease register.\nEnter a new username:\n"; - cin >> username; - - cout << "\nPlease enter a new password:\n"; - cin >> password; +#include // for exit(1); - userRegisterDo(); - } +using namespace std; - // User login function - void login() - { - cout << "Please enter your username:\n"; - cin >> inputUsername; - cout << "\nPlease enter your password:\n"; - cin >> inputPassword; +void Login(); - string userAndPass = inputUsername + " " + inputPassword; // Search pattern - int offset; - string line; - ifstream usersFile; - usersFile.open ("userData.txt"); +int main() +{ + Login(); + return 0; +} - bool found = false; - if(usersFile.is_open()) { - while(getline(usersFile,line) && !found) { - if (line.compare(userAndPass) == 0) { //match strings exactly! - found = true; // found is true => break loop - } - } - usersFile.close(); //close the file before recursivly opening it again later - if(found) { - cout << "Welcome "<< inputUsername << '\n'; +void Login() +{ + char login_un[50], login_pw[50], username[50], password[50]; + int c; + ifstream uin("user.txt"); + ifstream pin("pass.txt"); + + cout<<"Main\n\n" + <<"(1) Login\n" + <<"(2) Quit\n"; + cin>> c; + + + + if (c==1) + { + uin.getline(username, 50); + while (strcmp(login_un, username) !=0) + { + cout<<"Username: "; + cin.getline(login_un, 50); + if (strcmp(login_un, username) ==0) break; + else + cout<<"\nInvalid Username.\n"; + } + + pin.getline(password, 50); + while (strcmp(login_pw, password) !=0) + { + cout<<"\nPassword: "; + cin.getline(login_pw, 50); + if (strcmp(login_pw, password) ==0) break; + else + cout<<"\nInvalid Password\n"; + } + } - else { - cout << "\nUsername and/or password incorrect!\n\n\n\n"; - login(); //ok we didn't find them, lets redue this! + + else if (c==2) + { + cout<<"Quitting\n"; + exit(1); } - } - } - } - -// Main program -int main() { - - User user1; - ifstream usersFile("userData.txt"); - long begin, end; - - if (usersFile.good()) - { - cout << "File userData.txt found!\n\n"; - } - - else { - user1.userRegister(); - } - - if(usersFile.is_open()) - { - begin = usersFile.tellg(); - usersFile.seekg (0, ios::end); - - end = usersFile.tellg(); - usersFile.close(); - - if(begin == end) - { - user1.userRegister(); - } - - else - { - user1.login(); - } - } - - getch(); + return; } From 4080abc4cfe2909c9b84daf43cf15d61827237bc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:06:23 -0400 Subject: [PATCH 0907/1324] Update mainwindow.h --- src/qt/mainwindow.h | 238 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 186 insertions(+), 52 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index a75966f1..e252c980 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,61 +1,195 @@ -#include -#include -#include -#include // for exit(1); - +#include +#include +#include +#include +#include using namespace std; +void login(); +void registr(); +void forgot(); + +main() +{ + int choice; + cout<<"***********************************************************************\n\n\n"; + cout<<" Welcome to login page \n\n"; + cout<<"******************* MENU *******************************\n\n"; + cout<<"1.LOGIN"<>choice; + cout<>user; + cout<<"PASSWORD :"; + cin>>pass; + + ifstream input("database.txt"); + while(input>>u>>p) + { + if(u==user && p==pass) + + { + count=1; + system("cls"); + } + } + input.close(); + if(count==1) + { + cout<<"\nHello"<>reguser; + cout<<"\nEnter the password :"; + cin>>regpass; + + ofstream reg("database.txt",ios::app); + reg<> c; - - - - if (c==1) - { - uin.getline(username, 50); - while (strcmp(login_un, username) !=0) - { - cout<<"Username: "; - cin.getline(login_un, 50); - if (strcmp(login_un, username) ==0) break; - else - cout<<"\nInvalid Username.\n"; - } - - pin.getline(password, 50); - while (strcmp(login_pw, password) !=0) - { - cout<<"\nPassword: "; - cin.getline(login_pw, 50); - if (strcmp(login_pw, password) ==0) break; - else - cout<<"\nInvalid Password\n"; - } - - } - - else if (c==2) - { - cout<<"Quitting\n"; - exit(1); - } - return; + int ch; + system("cls"); + cout<<"Forgotten ? We're here for help\n"; + cout<<"1.Search your id by username"<>ch; + switch(ch) + { + case 1: + { + int count=0; + string searchuser,su,sp; + cout<<"\nEnter your remembered username :"; + cin>>searchuser; + + ifstream searchu("database.txt"); + while(searchu>>su>>sp) + { + if(su==searchuser) + { + count=1; + } + } + searchu.close(); + if(count==1) + { + cout<<"\n\nHurray, account found\n"; + cout<<"\nYour password is "<>searchpass; + + ifstream searchp("database.txt"); + while(searchp>>su2>>sp2) + { + if(sp2==searchpass) + { + count=1; + } + } + searchp.close(); + if(count==1) + { + cout<<"\nYour password is found in the database \n"; + cout<<"\nYour Id is : "< Date: Thu, 18 Jun 2020 19:15:09 -0400 Subject: [PATCH 0908/1324] Update mainwindow.h --- src/qt/mainwindow.h | 226 +++++++++----------------------------------- 1 file changed, 45 insertions(+), 181 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index e252c980..867b06f2 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,195 +1,59 @@ -#include -#include -#include -#include +#include//.h> #include -using namespace std; -void login(); -void registr(); -void forgot(); +//#include -main() -{ - int choice; - cout<<"***********************************************************************\n\n\n"; - cout<<" Welcome to login page \n\n"; - cout<<"******************* MENU *******************************\n\n"; - cout<<"1.LOGIN"<>choice; - cout<>user; - cout<<"PASSWORD :"; - cin>>pass; - - ifstream input("database.txt"); - while(input>>u>>p) - { - if(u==user && p==pass) - - { - count=1; - system("cls"); - } - } - input.close(); - if(count==1) + char Username[30]="sammasangcap",Password[30]="abc123",username[30], password[30],age[2],name[60],sex[6],address[100]; + + unsigned int attempts = 0; + do + { + cout<<"\nUsername:"; + cin>>username; + + if(strlen(username) <4) { - cout<<"\nHello"<>password; } -} + -void registr() -{ - - string reguser,regpass,ru,rp; - system("cls"); - cout<<"Enter the username :"; - cin>>reguser; - cout<<"\nEnter the password :"; - cin>>regpass; - - ofstream reg("database.txt",ios::app); - reg<>ch; - switch(ch) + } + else { - case 1: - { - int count=0; - string searchuser,su,sp; - cout<<"\nEnter your remembered username :"; - cin>>searchuser; - - ifstream searchu("database.txt"); - while(searchu>>su>>sp) - { - if(su==searchuser) - { - count=1; - } - } - searchu.close(); - if(count==1) - { - cout<<"\n\nHurray, account found\n"; - cout<<"\nYour password is "<>searchpass; - - ifstream searchp("database.txt"); - while(searchp>>su2>>sp2) - { - if(sp2==searchpass) - { - count=1; - } - } - searchp.close(); - if(count==1) - { - cout<<"\nYour password is found in the database \n"; - cout<<"\nYour Id is : "<>name; + cout<<"\nAge:"; + cin>>age; + cout<<"\nSex:"; + cin>>sex; + cout<<"\nAddress:"; + cin>>address; + break; } + }while(1); + + //getch(); + return 0; + + } From 56f90f887951a112080921278bbf179f6272bea9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:17:09 -0400 Subject: [PATCH 0909/1324] Update mainwindow.h --- src/qt/mainwindow.h | 107 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 57 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 867b06f2..726927d9 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,59 +1,52 @@ -#include//.h> +#include #include -//#include - -using namespace std; /// - -int main(){ - - char Username[30]="sammasangcap",Password[30]="abc123",username[30], password[30],age[2],name[60],sex[6],address[100]; - - unsigned int attempts = 0; - do - { - cout<<"\nUsername:"; - cin>>username; - - if(strlen(username) <4) - { - cout<<"\nUsername length must be atleast 4 characters"; - } - else - { - cout<<"\nPassword:"; - cin>>password; - } - - - if(!( (strcmp(username,Username) == 0) && (strcmp(password,Password) == 0))) - { - cout<<"\nWrong username or password"; - attempts++; - if(3 == attempts) - { - cout<<"You exceeded the number of times that you need to input the correct username and password. The system now is locked!"; - return 0; - } - - } - else - { - cout<<"\nLogin Successful!"; - cout<<"\nPlease input the following information:"; - cout<<"\nName"; - cin>>name; - cout<<"\nAge:"; - cin>>age; - cout<<"\nSex:"; - cin>>sex; - cout<<"\nAddress:"; - cin>>address; - break; - } - }while(1); - - //getch(); - return 0; - - +#include +#include + +using namespace std; + +int main() +{ + char uname[50]; + char pass[20]; + cout<<"\n Enter User Name : "; + gets(uname); + cout<<"\n Enter Password : "; + gets(pass); + try + { + //This section is used to verify the number of characters. + if(strlen(pass)<6) + { + cout<<"\n Password must be at least 6 Characters Long..."< Date: Thu, 18 Jun 2020 19:30:17 -0400 Subject: [PATCH 0910/1324] Update mainwindow.h --- src/qt/mainwindow.h | 65 ++++++++++----------------------------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 726927d9..1e7fec07 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,52 +1,15 @@ -#include -#include -#include -#include - -using namespace std; - -int main() +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class MainWindow : public QMainWindow { - char uname[50]; - char pass[20]; - cout<<"\n Enter User Name : "; - gets(uname); - cout<<"\n Enter Password : "; - gets(pass); - try - { - //This section is used to verify the number of characters. - if(strlen(pass)<6) - { - cout<<"\n Password must be at least 6 Characters Long..."< Date: Thu, 18 Jun 2020 19:30:35 -0400 Subject: [PATCH 0911/1324] Create mainwindow.cpp --- src/qt/mainwindow.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/qt/mainwindow.cpp diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 00000000..8861b7bc --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,9 @@ +#include "mainwindow.h" + +MainWindow::MainWindow() + : QMainWindow() +{ + setMinimumSize(800, 600); +} + +MainWindow::~MainWindow() {} From 5b93ab735d2deaa4bf3dee5c9e10cde391de4fe3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:30:49 -0400 Subject: [PATCH 0912/1324] Create main.cpp --- src/qt/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp new file mode 100644 index 00000000..d40bcce3 --- /dev/null +++ b/src/qt/main.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include "formlogin.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow* mainWindow = new MainWindow(); + FormLogin* formLogin = new FormLogin(mainWindow); + formLogin->show(); + mainWindow->show(); + + return a.exec(); +} From 9579b42b3be7ff40775e79054bed80dfe4711c28 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:31:22 -0400 Subject: [PATCH 0913/1324] Create formlogin.h --- src/qt/formlogin.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/qt/formlogin.h diff --git a/src/qt/formlogin.h b/src/qt/formlogin.h new file mode 100644 index 00000000..9481ad04 --- /dev/null +++ b/src/qt/formlogin.h @@ -0,0 +1,35 @@ +#ifndef FORMLOGIN_H +#define FORMLOGIN_H + +#include +#include +#include +#include +#include +#include +#include + +class FormLogin : public QDialog +{ + Q_OBJECT + +public: + FormLogin(QWidget* parent = 0); + ~FormLogin(); + +private Q_SLOTS: + void OnQuit(); + void OnLogin(); + +private: + void reject(); + + QLabel* userLabel; + QLabel* passLabel; + QLineEdit* userLineEdit; + QLineEdit* passLineEdit; + QPushButton* loginButton; + QPushButton* quitButton; +}; + +#endif // FORMLOGIN_H From a5f8eff7db123476e3318e91fc6c1323d45e6dfe Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:31:40 -0400 Subject: [PATCH 0914/1324] Create formlogin.cpp --- src/qt/formlogin.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/qt/formlogin.cpp diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp new file mode 100644 index 00000000..18cace09 --- /dev/null +++ b/src/qt/formlogin.cpp @@ -0,0 +1,63 @@ +#include "formlogin.h" + +FormLogin::FormLogin(QWidget* parent) + : QDialog(parent) +{ + setFixedSize(300, 120); + setWindowTitle("Form Login"); + setModal(true); + setAttribute(Qt::WA_DeleteOnClose); + + userLabel = new QLabel("Username:"); + passLabel = new QLabel("Password:"); + userLineEdit = new QLineEdit(); + passLineEdit = new QLineEdit(); + passLineEdit->setEchoMode(QLineEdit::Password); + loginButton = new QPushButton("Login"); + quitButton = new QPushButton("Quit"); + + QVBoxLayout* vbox = new QVBoxLayout(this); + QHBoxLayout* hbox1 = new QHBoxLayout(); + QHBoxLayout* hbox2 = new QHBoxLayout(); + QHBoxLayout* hbox3 = new QHBoxLayout(); + + hbox1->addWidget(userLabel, 1); + hbox1->addWidget(userLineEdit, 2); + hbox2->addWidget(passLabel, 1); + hbox2->addWidget(passLineEdit, 2); + hbox3->addWidget(loginButton, 1, Qt::AlignRight); + hbox3->addWidget(quitButton, 0, Qt::AlignRight); + + vbox->addSpacing(1); + vbox->addLayout(hbox1); + vbox->addLayout(hbox2); + vbox->addLayout(hbox3); + + connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); + connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); +} + +void FormLogin::reject() +{ + OnQuit(); +} + +void FormLogin::OnQuit() +{ + this->close(); + parentWidget()->close(); +} + +void FormLogin::OnLogin() +{ + QString username = userLineEdit->text(); + QString password = passLineEdit->text(); + + // Checking if username or password is empty + if (username.isEmpty() || password.isEmpty()) + QMessageBox::information(this, tr("Peringatan!"), "Username atau password tidak boleh kosong"); + else + this->destroy(); +} + +FormLogin::~FormLogin() {} From 0cd13a4f2c8459fa51d5ab9062a027ff1414e203 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:33:32 -0400 Subject: [PATCH 0915/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index d0a55712..5106a97a 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -122,7 +122,9 @@ QT_MOC_CPP = \ qt/moc_profilepage.cpp \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ - qt/moc_user.cpp + qt/moc_user.cpp \ + qt/moc_formlogin.cpp \ + qt/moc_mainwindow.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -218,7 +220,8 @@ BITCOIN_QT_H = \ qt/qcustomplot.h \ qt/statistics.h \ qt/user.h \ - qt/mainwindow.h + qt/mainwindow.h \ + qt/formlogin.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -568,7 +571,10 @@ BITCOIN_QT_WALLET_CPP = \ qt/profilepage.cpp \ qt/qcustomplot.cpp \ qt/statistics.cpp \ - qt/user.cpp + qt/user.cpp \ + qt/main.cpp \ + qt/mainwindow.cpp \ + qt/formlogin.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 712583c35681c589ff8d1dfa6d71ccba258301c9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:07:28 -0400 Subject: [PATCH 0916/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index b8a33e51..5f9a0377 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -621,7 +621,7 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoFormLogin())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -1052,10 +1052,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoMainWindow() +void BitcoinGUI::gotoFormLogin() { mainWindow->setChecked(true); - if (walletFrame) walletFrame->gotoMainWindow(); + if (walletFrame) walletFrame->gotoFormLogin(); } void BitcoinGUI::gotoGovernancePage() From c5fa696bf170d93a429d2d7714a05d1e93831d28 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:08:44 -0400 Subject: [PATCH 0917/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 050853f2..9f7a8ad7 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -39,7 +39,7 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -class MainWindow; +class FormLogin; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* mainWindow; + QAction* formLogin; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -235,7 +235,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoFormLogin(); /** Switch to masternode page */ void gotoGovernancePage(); From f418d449ff483d69187e243ebc5daf1c748c9078 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:10:11 -0400 Subject: [PATCH 0918/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5f9a0377..633af45b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "mainwindow.h" +#include "formlogin.h" /* #include "tradingdialogpage.h" */ @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), - mainWindow(0), + formLogin(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -606,8 +606,8 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World")); + formLogin = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + formLogin->setStatusTip(tr("HTH World")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -621,7 +621,7 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoFormLogin())); + connect(formLogin, SIGNAL(triggered()), this, SLOT(gotoFormLogin())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -723,8 +723,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(mainWindow); + QMenu* form = appMenuBar->addMenu(tr("&HTH World")); + form->addAction(formLogin); } @@ -1054,7 +1054,7 @@ void BitcoinGUI::openClicked() void BitcoinGUI::gotoFormLogin() { - mainWindow->setChecked(true); + formLogin->setChecked(true); if (walletFrame) walletFrame->gotoFormLogin(); } From 73eff85e8a78f68c085be7d3d7548d80b8a77cb7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:10:59 -0400 Subject: [PATCH 0919/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index abf30d21..f269c912 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoMainWindow() +void WalletFrame::gotoFormLogin() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoMainWindow(); + i.value()->gotoFormLogin(); } void WalletFrame::gotoGovernancePage() From a42c9a8a241090a6fd4f1ef5d7e21bb9a6b1b017 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:11:24 -0400 Subject: [PATCH 0920/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 9f7a8ad7..20d7f79d 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,7 @@ #include "amount.h" #include "governancelist.h" -#include "mainwindow.h" +#include "formlogin.h" #include #include From a155f5b992d01d0f72594d5a643e065337b5faf1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:11:41 -0400 Subject: [PATCH 0921/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index cd335d21..be877da6 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -67,7 +67,7 @@ public Q_SLOTS: /** Switch to social media page */ void gotoGovernancePage(); /** Switch to social media page */ - void gotoMainWindow(); + void gotoFormLogin(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 7a64adbd6b37266cbc2bff78dcb06e0cad312e83 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:12:38 -0400 Subject: [PATCH 0922/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 27f5558d..7eedc8bb 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,8 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - mainWindow = new MainWindow(); - addWidget(mainWindow); + formLogin = new FormLogin(); + addWidget(formLogin); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -234,9 +234,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoMainWindow() +void WalletView::gotoFormLogin() { - setCurrentWidget(mainWindow); + setCurrentWidget(formLogin); } void WalletView::gotoGovernancePage() From 53bb69da081a31695437ff84f81c1faf077d4ce9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:13:22 -0400 Subject: [PATCH 0923/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 3be6fd21..6036396e 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "mainwindow.h" +#include "formlogin.h" #include @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class MainWindow; +class FormLogin; QT_BEGIN_NAMESPACE class QLabel; @@ -74,7 +74,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - MainWindow *mainWindow; + FormLogin *formLogin; TransactionView *transactionView; @@ -86,7 +86,7 @@ public Q_SLOTS: /** Switch to social media page */ - void gotoMainWindow(); + void gotoFormLogin(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 8c6a1a011c3df26de5ff74414ead5687f3bc96f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:23:17 -0400 Subject: [PATCH 0924/1324] Update formlogin.cpp --- src/qt/formlogin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp index 18cace09..a53631cc 100644 --- a/src/qt/formlogin.cpp +++ b/src/qt/formlogin.cpp @@ -55,7 +55,7 @@ void FormLogin::OnLogin() // Checking if username or password is empty if (username.isEmpty() || password.isEmpty()) - QMessageBox::information(this, tr("Peringatan!"), "Username atau password tidak boleh kosong"); + QMessageBox::information(this, tr("Warning!"), "Username or password must not be blank"); else this->destroy(); } From 7d088420e31725229f4a9343fd073260a54a0b9b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:35:51 -0400 Subject: [PATCH 0925/1324] Update formlogin.cpp --- src/qt/formlogin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp index a53631cc..cfef5705 100644 --- a/src/qt/formlogin.cpp +++ b/src/qt/formlogin.cpp @@ -1,4 +1,5 @@ #include "formlogin.h" +#include "homepage.h" FormLogin::FormLogin(QWidget* parent) : QDialog(parent) @@ -35,6 +36,7 @@ FormLogin::FormLogin(QWidget* parent) connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); + connect(OnLogin, SIGNAL(clicked()), this, SLOT(gotoHomePage())); } void FormLogin::reject() From 3371d0a3ff61e64735ee58c947d4f1e6052a7ff6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:36:58 -0400 Subject: [PATCH 0926/1324] Update formlogin.cpp --- src/qt/formlogin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp index cfef5705..2515c757 100644 --- a/src/qt/formlogin.cpp +++ b/src/qt/formlogin.cpp @@ -36,7 +36,7 @@ FormLogin::FormLogin(QWidget* parent) connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); - connect(OnLogin, SIGNAL(clicked()), this, SLOT(gotoHomePage())); + connect(OnLogin, SIGNAL(clicked()), this, SLOT(HomePage())); } void FormLogin::reject() From d46ba7627b39be47806f26f25b6699bfd3c538f1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:37:39 -0400 Subject: [PATCH 0927/1324] Update formlogin.cpp --- src/qt/formlogin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp index 2515c757..86461c58 100644 --- a/src/qt/formlogin.cpp +++ b/src/qt/formlogin.cpp @@ -36,7 +36,6 @@ FormLogin::FormLogin(QWidget* parent) connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); - connect(OnLogin, SIGNAL(clicked()), this, SLOT(HomePage())); } void FormLogin::reject() From 4ee502b312c76120a71d7543caf1bbde009cc0f8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:55:22 -0400 Subject: [PATCH 0928/1324] Update formlogin.h --- src/qt/formlogin.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/formlogin.h b/src/qt/formlogin.h index 9481ad04..9714d564 100644 --- a/src/qt/formlogin.h +++ b/src/qt/formlogin.h @@ -8,6 +8,7 @@ #include #include #include +#include "homepage.h" class FormLogin : public QDialog { From 32699ab959334da89102cc56a65bb1ba8d2d6ebd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:06:52 -0400 Subject: [PATCH 0929/1324] Update formlogin.cpp --- src/qt/formlogin.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp index 86461c58..71efb89c 100644 --- a/src/qt/formlogin.cpp +++ b/src/qt/formlogin.cpp @@ -53,12 +53,15 @@ void FormLogin::OnLogin() { QString username = userLineEdit->text(); QString password = passLineEdit->text(); - + // Checking if username or password is empty if (username.isEmpty() || password.isEmpty()) QMessageBox::information(this, tr("Warning!"), "Username or password must not be blank"); else - this->destroy(); + this->hide(); + HomePage homepage; + homepage.setModal(true); + homepage.exec(); } FormLogin::~FormLogin() {} From 12dac20eb9d489a13c0ea261b70de1114a91498a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:19:52 -0400 Subject: [PATCH 0930/1324] Delete formlogin.cpp --- src/qt/formlogin.cpp | 67 -------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/qt/formlogin.cpp diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp deleted file mode 100644 index 71efb89c..00000000 --- a/src/qt/formlogin.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "formlogin.h" -#include "homepage.h" - -FormLogin::FormLogin(QWidget* parent) - : QDialog(parent) -{ - setFixedSize(300, 120); - setWindowTitle("Form Login"); - setModal(true); - setAttribute(Qt::WA_DeleteOnClose); - - userLabel = new QLabel("Username:"); - passLabel = new QLabel("Password:"); - userLineEdit = new QLineEdit(); - passLineEdit = new QLineEdit(); - passLineEdit->setEchoMode(QLineEdit::Password); - loginButton = new QPushButton("Login"); - quitButton = new QPushButton("Quit"); - - QVBoxLayout* vbox = new QVBoxLayout(this); - QHBoxLayout* hbox1 = new QHBoxLayout(); - QHBoxLayout* hbox2 = new QHBoxLayout(); - QHBoxLayout* hbox3 = new QHBoxLayout(); - - hbox1->addWidget(userLabel, 1); - hbox1->addWidget(userLineEdit, 2); - hbox2->addWidget(passLabel, 1); - hbox2->addWidget(passLineEdit, 2); - hbox3->addWidget(loginButton, 1, Qt::AlignRight); - hbox3->addWidget(quitButton, 0, Qt::AlignRight); - - vbox->addSpacing(1); - vbox->addLayout(hbox1); - vbox->addLayout(hbox2); - vbox->addLayout(hbox3); - - connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); - connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); -} - -void FormLogin::reject() -{ - OnQuit(); -} - -void FormLogin::OnQuit() -{ - this->close(); - parentWidget()->close(); -} - -void FormLogin::OnLogin() -{ - QString username = userLineEdit->text(); - QString password = passLineEdit->text(); - - // Checking if username or password is empty - if (username.isEmpty() || password.isEmpty()) - QMessageBox::information(this, tr("Warning!"), "Username or password must not be blank"); - else - this->hide(); - HomePage homepage; - homepage.setModal(true); - homepage.exec(); -} - -FormLogin::~FormLogin() {} From f5390bb7f7f564bd4e26e17c80b1ccb4b5ee0abc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:20:34 -0400 Subject: [PATCH 0931/1324] Delete formlogin.h --- src/qt/formlogin.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/qt/formlogin.h diff --git a/src/qt/formlogin.h b/src/qt/formlogin.h deleted file mode 100644 index 9714d564..00000000 --- a/src/qt/formlogin.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FORMLOGIN_H -#define FORMLOGIN_H - -#include -#include -#include -#include -#include -#include -#include -#include "homepage.h" - -class FormLogin : public QDialog -{ - Q_OBJECT - -public: - FormLogin(QWidget* parent = 0); - ~FormLogin(); - -private Q_SLOTS: - void OnQuit(); - void OnLogin(); - -private: - void reject(); - - QLabel* userLabel; - QLabel* passLabel; - QLineEdit* userLineEdit; - QLineEdit* passLineEdit; - QPushButton* loginButton; - QPushButton* quitButton; -}; - -#endif // FORMLOGIN_H From a2c19c33a364b88f072af4032a1bf9a005f33b1c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:21:13 -0400 Subject: [PATCH 0932/1324] Update main.cpp --- src/qt/main.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index d40bcce3..3620dde1 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,14 +1,11 @@ -#include "mainwindow.h" -#include "formlogin.h" +#include "loginsystem.h" #include - + int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow* mainWindow = new MainWindow(); - FormLogin* formLogin = new FormLogin(mainWindow); - formLogin->show(); - mainWindow->show(); - + LoginSystem w; + w.show(); + return a.exec(); } From b0ad0d5c477ad443fa37fc2e0498d9f1a9daaf1b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:23:02 -0400 Subject: [PATCH 0933/1324] Add files via upload --- src/qt/db.s3db | Bin 0 -> 7168 bytes src/qt/db.s3db.sql | 14 ++ src/qt/loginsystem.cpp | 546 +++++++++++++++++++++++++++++++++++++++++ src/qt/loginsystem.h | 74 ++++++ src/qt/qdb.cpp | 53 ++++ src/qt/qdb.h | Bin 0 -> 637 bytes 6 files changed, 687 insertions(+) create mode 100644 src/qt/db.s3db create mode 100644 src/qt/db.s3db.sql create mode 100644 src/qt/loginsystem.cpp create mode 100644 src/qt/loginsystem.h create mode 100644 src/qt/qdb.cpp create mode 100644 src/qt/qdb.h diff --git a/src/qt/db.s3db b/src/qt/db.s3db new file mode 100644 index 0000000000000000000000000000000000000000..dff92915b85d0c974aae76adbd759b642e228fc1 GIT binary patch literal 7168 zcmeHLL2uJA6t?5CuBAml6;%_OY7L<^TBy{)1@*9YBSVF*+e#|2Q)Iq+k}`JP zF8l!g!H)Y6`~tWjaoQbDOxlSH64*&=sHRSAJi@RsY@ zdVn8+7=RFzF$MrE5Q!5(LRbyaz$H1JxZx>9Lu z;1|jUt~AxvYMmIZD0NlF)S08(7FLy4Dz2{*Y1V4ES+A})6&dg9zQ1n{DrLNN(L%;H zYm{+^m6=N!d%DwRke({bm1a%F`JyCa%hp?+!9f^;2no*jfl5*_HIY?v5VRcAdh73X z$W&^2H*mwc#u(7%SurlW2djE%s7dI<54vW{)dI`j)k3bdV&wdS0s0kWb9W}&2;cFUnQ4c84Sw9@hePbX%-LRHx#?FH9+-Fqf_mJ8_n z=ugN!a0WO7W5z%nWgyvaXd<5scN1X}WfS2>K+k`O&H*|{U&ahIhr=1*3|xnSR1D=3 zEXOAvrXhR(NfRApx)hCn0Ugu){}{cy&S2bzGr$=bm4OGT1Q5kcIuqslG<9Eg-9_D# zgjs>8rUq2|W~8Ktc`yGbxqL7GPhTbfPZHn)Is@njIz!(^eF|>R8Q=_zAp?_0gk-bm y-Ml~fe-!_xfJFZ(`aFinIV8>iXW$A9+(i-%b+60{wC2-~eZn0iMX&wr``>TtBd!7f literal 0 HcmV?d00001 diff --git a/src/qt/db.s3db.sql b/src/qt/db.s3db.sql new file mode 100644 index 00000000..ed402741 --- /dev/null +++ b/src/qt/db.s3db.sql @@ -0,0 +1,14 @@ +-- +-- File generated with SQLiteStudio v3.0.7 on Sun Mar 20 17:59:39 2016 +-- +-- Text encoding used: windows-1252 +-- +PRAGMA foreign_keys = off; +BEGIN TRANSACTION; + +-- Table: sys_users +CREATE TABLE sys_users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, passwd TEXT NOT NULL, fname TEXT NOT NULL, mname TEXT, lname TEXT NOT NULL, rank INTEGER DEFAULT (1), email TEXT NOT NULL UNIQUE, UNIQUE (username)) +INSERT INTO sys_users (id, username, passwd, fname, mname, lname, rank, email) VALUES (1, 'admin', 'pass', 'Root', NULL, 'Administrator', -1, 'admin@root.org'); + +COMMIT TRANSACTION; +PRAGMA foreign_keys = on; diff --git a/src/qt/loginsystem.cpp b/src/qt/loginsystem.cpp new file mode 100644 index 00000000..2b81251f --- /dev/null +++ b/src/qt/loginsystem.cpp @@ -0,0 +1,546 @@ +#include "loginsystem.h" +#include "ui_loginsystem.h" +#include "qdb.h" +#include +#include +#include + +QDBLite::DB db; + +LoginSystem::LoginSystem(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::LoginSystem) +{ + ui->setupUi(this); + db.dbstate = db.Connect(QCoreApplication::applicationDirPath()+"/../../LogSys/db.s3db"); + ui->winStack->setCurrentIndex(0); + ui->stackedWidget->setCurrentIndex(1); + + ui->passwordBox->setEchoMode(QLineEdit::Password); + ui->passwordBox->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); + ui->pBox->setEchoMode(QLineEdit::Password); + ui->pBox->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); + ui->pBox_2->setEchoMode(QLineEdit::Password); + ui->pBox_2->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); +} + +LoginSystem::~LoginSystem() +{ + delete ui; +} + +void LoginSystem::on_loginButton_clicked() +{ + this->loggedIn = Login(ui->usernameBox->text(), ui->passwordBox->text()); + + if(this->loggedIn) + { + this->username = ui->usernameBox->text(); + this->password = ui->passwordBox->text(); + + ui->loginLabel->setText(""); + ui->winStack->setCurrentIndex(2); + } + else + { + ui->loginLabel->setText("Login failed: Invalid credentials!"); + } +} + +bool LoginSystem::Login(QString u, QString p) +{ + ui->adminButton->setVisible(false); + + bool exists = false; + + QSqlQuery checkQuery(db.db); + checkQuery.prepare("SELECT username FROM sys_users WHERE username = (:un) AND passwd = (:pw)"); + checkQuery.bindValue(":un", u); + checkQuery.bindValue(":pw", p); + + if (checkQuery.exec()) + { + if (checkQuery.next()) + { + exists = true; + } + } + + return exists; +} + + +void LoginSystem::on_regButton_clicked() +{ + ui->uBox->setText(ui->usernameBox->text()); + ui->pBox->setText(ui->passwordBox->text()); + ui->winStack->setCurrentIndex(1); +} + +void LoginSystem::on_logoutButton_clicked() +{ + if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, + "Login System", "Are you sure you want to logout?", + QMessageBox::Yes|QMessageBox::No).exec()) + { + this->loggedIn = false; + ui->passwordBox->setText(""); + ui->loginLabel->setText("You signed out!"); + ui->winStack->setCurrentIndex(0); + } +} + +void LoginSystem::on_completeRegButton_clicked() +{ + bool halt = false; + + if(ui->uBox->text() == "") + { + ui->uBox->setPlaceholderText("Username EMPTY!"); + halt = true; + } + + if(ui->pBox->text() == "") + { + ui->pBox->setPlaceholderText("Password EMPTY!"); + halt = true; + } + + if(ui->eBox->text() == "") + { + ui->eBox->setPlaceholderText("E-mail EMPTY!"); + halt = true; + } + + if(ui->fBox->text() == "") + { + ui->fBox->setPlaceholderText("First Name EMPTY!"); + halt = true; + } + + if(ui->mBox->text() == "") + { + ui->mBox->setPlaceholderText("Middle Name (optional)"); + halt = false; + } + + if(ui->lBox->text() == "") + { + ui->lBox->setPlaceholderText("Last Name EMPTY!"); + halt = true; + } + + QSqlQuery cQuery(db.db); + cQuery.prepare("SELECT username FROM sys_users WHERE username = (:un)"); + cQuery.bindValue(":un", ui->uBox->text()); + + if(cQuery.exec()) + { + if(cQuery.next()) + { + ui->uBox->setText(""); + ui->uBox->setPlaceholderText("Choose a different Username!"); + halt = true; + } + } + + QSqlQuery cQuery2(db.db); + cQuery2.prepare("SELECT email FROM sys_users WHERE email = (:em)"); + cQuery2.bindValue(":em", ui->eBox->text()); + + if(cQuery2.exec()) + { + if(cQuery2.next()) + { + ui->eBox->setText(""); + ui->eBox->setPlaceholderText("Use another E-mail!"); + halt = true; + } + } + + + if(halt) + { + ui->regLabel->setText("Please correct your mistakes."); + } + else + { + if (this->picName != "") + { + QString to = this->picDir+"/"+ui->uBox->text(); + + if (QFile::exists(to)) + { + QFile::remove(to); + } + + QFile::copy(this->picName, to); + this->picName = ""; + } + + ui->regLabel->setText(""); + QSqlQuery iQuery(db.db); + iQuery.prepare("INSERT INTO sys_users(username, passwd, fname, mname, lname, email)"\ + "VALUES(:un, :pw, :fn, :mn, :ln, :em)"); + iQuery.bindValue(":un", ui->uBox->text()); + iQuery.bindValue(":pw", ui->pBox->text()); + iQuery.bindValue(":fn", ui->fBox->text()); + iQuery.bindValue(":mn", ui->mBox->text()); + iQuery.bindValue(":ln", ui->lBox->text()); + iQuery.bindValue(":em", ui->eBox->text()); + + if(iQuery.exec()) + { + ui->uBox->setText(""); + ui->pBox->setText(""); + ui->eBox->setText(""); + ui->fBox->setText(""); + ui->mBox->setText(""); + ui->lBox->setText(""); + ui->rpLabel->setText(""); + ui->loginLabel->setText("Registration Successful! You can now login."); + ui->winStack->setCurrentIndex(0); + } + + } +} + +void LoginSystem::on_backButton_clicked() +{ + ui->loginLabel->setText(""); + ui->winStack->setCurrentIndex(0); +} + + +void LoginSystem::on_backButton_2_clicked() +{ + ui->winStack->setCurrentIndex(2); +} + +void LoginSystem::on_editButton_clicked() +{ + QSqlQuery fetcher; + fetcher.prepare("SELECT * FROM sys_users WHERE username = (:un) AND passwd = (:pw)"); + fetcher.bindValue(":un", this->username); + fetcher.bindValue(":pw", this->password); + fetcher.exec(); + + int idUsername = fetcher.record().indexOf("username"); + int idPasswd = fetcher.record().indexOf("passwd"); + int idEmail = fetcher.record().indexOf("email"); + int idFname = fetcher.record().indexOf("fname"); + int idMname = fetcher.record().indexOf("mname"); + int idLname = fetcher.record().indexOf("lname"); + + while (fetcher.next()) + { + ui->uBox_2->setText(fetcher.value(idUsername).toString()); + ui->pBox_2->setText(fetcher.value(idPasswd).toString()); + ui->eBox_2->setText(fetcher.value(idEmail).toString()); + ui->fBox_2->setText(fetcher.value(idFname).toString()); + ui->mBox_2->setText(fetcher.value(idMname).toString()); + ui->lBox_2->setText(fetcher.value(idLname).toString()); + } + + ui->winStack->setCurrentIndex(3); +} + +void LoginSystem::on_delButton_clicked() +{ + if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, + "Login System", "Are you sure you want to delete your account?", + QMessageBox::Yes|QMessageBox::No).exec()) + { + QString to = this->picDir+"/"+this->username; + + if (QFile::exists(to)) + { + QFile::remove(to); + } + + QSqlQuery dQuery(db.db); + dQuery.prepare("DELETE FROM sys_users WHERE username = (:un)"); + dQuery.bindValue(":un", this->username); + + if(dQuery.exec()) + { + ui->usernameBox->setText(""); + ui->passwordBox->setText(""); + ui->loginLabel->setText("Account deleted!"); + ui->winStack->setCurrentIndex(0); + } + } +} + +void LoginSystem::on_editedButton_clicked() +{ + + + bool halt = false; + + if(ui->uBox_2->text() == "") + { + ui->uBox_2->setPlaceholderText("Username EMPTY!"); + halt = true; + } + + if(ui->pBox_2->text() == "") + { + ui->pBox_2->setPlaceholderText("Password EMPTY!"); + halt = true; + } + + if(ui->eBox_2->text() == "") + { + ui->eBox_2->setPlaceholderText("E-mail EMPTY!"); + halt = true; + } + + if(ui->fBox_2->text() == "") + { + ui->fBox_2->setPlaceholderText("First Name EMPTY!"); + halt = true; + } + + if(ui->mBox_2->text() == "") + { + ui->mBox_2->setPlaceholderText("Middle Name (optional)"); + halt = false; + } + + if(ui->lBox_2->text() == "") + { + ui->lBox_2->setPlaceholderText("Last Name EMPTY!"); + halt = true; + } + + QSqlQuery cQuery(db.db); + cQuery.prepare("SELECT username FROM sys_users WHERE username = (:un)"); + cQuery.bindValue(":un", ui->uBox->text()); + + if(cQuery.exec()) + { + if(cQuery.next() && ui->uBox_2->text() != cQuery.value(0).toString()) + { + ui->uBox_2->setText(""); + ui->uBox_2->setPlaceholderText("Choose a different Username!"); + halt = true; + } + } + + QSqlQuery cQuery2(db.db); + cQuery2.prepare("SELECT email FROM sys_users WHERE email = (:em)"); + cQuery2.bindValue(":em", ui->eBox_2->text()); + + if(cQuery2.exec()) + { + if(cQuery2.next() && ui->eBox_2->text() != cQuery2.value(0).toString()) + { + ui->eBox_2->setText(""); + ui->eBox_2->setPlaceholderText("Use another E-mail!"); + halt = true; + } + } + + + if(halt) + { + ui->regLabel_2->setText("Please correct your mistakes."); + } + else + { + if (this->picName != "") + { + QString to = this->picDir+"/"+ui->uBox_2->text(); + + if (QFile::exists(to)) + { + QFile::remove(to); + } + + QFile::copy(this->picName, to); + this->picName = ""; + } + + ui->regLabel_2->setText(""); + QSqlQuery iQuery(db.db); + iQuery.prepare("UPDATE sys_users SET username=(:un), passwd=(:pw), fname=(:fn), mname=(:mn), lname=(:ln), email=(:em) WHERE username=(:uno)"); + iQuery.bindValue(":un", ui->uBox_2->text()); + iQuery.bindValue(":pw", ui->pBox_2->text()); + iQuery.bindValue(":fn", ui->fBox_2->text()); + iQuery.bindValue(":mn", ui->mBox_2->text()); + iQuery.bindValue(":ln", ui->lBox_2->text()); + iQuery.bindValue(":em", ui->eBox_2->text()); + iQuery.bindValue(":uno", ui->uBox_2->text()); + + if(iQuery.exec()) + { + ui->winStack->setCurrentIndex(2); + } + + } +} + +void LoginSystem::on_winStack_currentChanged(int arg1) +{ + + if(arg1 == 3 && this->loggedIn) + { + if(QFile::exists(this->picDir+"/"+this->username)) + { + ui->rpLabel_2->setText("picDir+"/"+this->username+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); + } + } + + if(arg1 == 2 && this->loggedIn) + { + if(QFile::exists(this->picDir+"/"+this->username)) + { + ui->loggedPic->setText("picDir+"/"+this->username+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); + } + + QSqlQuery fetcher; + fetcher.prepare("SELECT * FROM sys_users WHERE username = (:un)"); + fetcher.bindValue(":un", this->username); + fetcher.exec(); + + int idFname = fetcher.record().indexOf("fname"); + int idMname = fetcher.record().indexOf("mname"); + int idLname = fetcher.record().indexOf("lname"); + int idRank = fetcher.record().indexOf("rank"); + int idEmail = fetcher.record().indexOf("email"); + + QString fullname, email, rank; + + while (fetcher.next()) + { + fullname = fetcher.value(idFname).toString(); + fullname += " " + fetcher.value(idMname).toString(); + fullname += " " + fetcher.value(idLname).toString(); + rank = fetcher.value(idRank).toString(); + email = fetcher.value(idEmail).toString(); + } + if(rank == "-1") + { + ui->adminButton->setVisible(true); + } + ui->nameLabel->setText(fullname); + ui->rankLabel->setText(rank); + ui->emailLabel->setText(email); + } + + if(arg1 == 4 && this->loggedIn) + { + ui->stackedWidget->setCurrentIndex(0); + } +} + +void LoginSystem::on_uplButton_clicked() +{ + this->picName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)")); + ui->rpLabel->setText("picName+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); + +} + +void LoginSystem::on_uplButton_2_clicked() +{ + this->picName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)")); + ui->rpLabel_2->setText("picName+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); +} + +void LoginSystem::on_adminButton_clicked() +{ + ui->winStack->setCurrentIndex(4); +} + +void LoginSystem::on_pageButton_clicked() +{ + ui->winStack->setCurrentIndex(2); +} + +void LoginSystem::on_editedButton_2_clicked() +{ + if(this->tblMdl->submitAll()) + { + this->tblMdl->database().commit(); + ui->adminLabel->setText("Saved to database!"); + } + else + { + this->tblMdl->database().rollback(); + } +} + +void LoginSystem::on_backButton_5_clicked() +{ + this->tblMdl->revertAll(); + this->tblMdl->database().rollback(); +} + +void LoginSystem::on_userBrowse_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); +} + +void LoginSystem::on_delUButton_clicked() +{ + if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, + "Login System", "Are you sure you want to erase all accounts?", + QMessageBox::Yes|QMessageBox::No).exec()) + { + QSqlQuery dQuery(db.db); + dQuery.prepare("DELETE FROM sys_users WHERE rank != 0 AND rank != -1"); + + if(dQuery.exec()) + { + ui->adminLabel->setText("Query executed!"); + } + } +} + +void LoginSystem::on_stackedWidget_currentChanged(int arg1) +{ + if(arg1 == 0 && this->loggedIn) + { + ui->headLabel->setText("USERS"); + this->tblMdl = new QSqlTableModel; + this->tblMdl->setTable("sys_users"); + this->tblMdl->setFilter("rank != -1 AND rank != 0"); + this->tblMdl->select(); + ui->tableView->setModel(this->tblMdl); + this->tblMdl->database().transaction(); + } + + if(arg1 == 1 && this->loggedIn) + { + ui->headLabel->setText("ADMINS"); + this->tblMdl = new QSqlTableModel; + this->tblMdl->setTable("sys_users"); + this->tblMdl->setFilter("rank == -1 OR rank == 0"); + this->tblMdl->select(); + ui->tableView_2->setModel(this->tblMdl); + this->tblMdl->database().transaction(); + } +} + +void LoginSystem::on_adminBrowse_clicked() +{ + ui->stackedWidget->setCurrentIndex(1); +} + +void LoginSystem::on_delAButton_clicked() +{ + if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, + "Login System", "Are you sure you want to erase all administrators?"\ + "\n(This won't erase regular users and you)", + QMessageBox::Yes|QMessageBox::No).exec()) + { + QSqlQuery dQuery(db.db); + dQuery.prepare("DELETE FROM sys_users WHERE rank != 1 AND username != \"" + this->username + "\""); + + if(dQuery.exec()) + { + ui->adminLabel->setText("Query executed!"); + } + } +} diff --git a/src/qt/loginsystem.h b/src/qt/loginsystem.h new file mode 100644 index 00000000..c5227d78 --- /dev/null +++ b/src/qt/loginsystem.h @@ -0,0 +1,74 @@ +#ifndef LOGINSYSTEM_H +#define LOGINSYSTEM_H + +#include +#include +#include + +namespace Ui { +class LoginSystem; +} + +class LoginSystem : public QMainWindow +{ + Q_OBJECT + +public: + explicit LoginSystem(QWidget *parent = 0); + ~LoginSystem(); + bool Login(QString u, QString p); + bool loggedIn; + QString picName; + QString picDir = QCoreApplication::applicationDirPath()+"/../../LogSys/users/avatar"; + QSqlTableModel* tblMdl; + +private slots: + void on_loginButton_clicked(); + + void on_logoutButton_clicked(); + + void on_completeRegButton_clicked(); + + void on_backButton_clicked(); + + void on_regButton_clicked(); + + void on_backButton_2_clicked(); + + void on_editButton_clicked(); + + void on_delButton_clicked(); + + void on_editedButton_clicked(); + + void on_winStack_currentChanged(int arg1); + + void on_uplButton_clicked(); + + void on_uplButton_2_clicked(); + + void on_adminButton_clicked(); + + void on_pageButton_clicked(); + + void on_editedButton_2_clicked(); + + void on_backButton_5_clicked(); + + void on_userBrowse_clicked(); + + void on_delUButton_clicked(); + + void on_stackedWidget_currentChanged(int arg1); + + void on_adminBrowse_clicked(); + + void on_delAButton_clicked(); + +private: + Ui::LoginSystem *ui; + QString username; + QString password; +}; + +#endif // LOGINSYSTEM_H diff --git a/src/qt/qdb.cpp b/src/qt/qdb.cpp new file mode 100644 index 00000000..3c805326 --- /dev/null +++ b/src/qt/qdb.cpp @@ -0,0 +1,53 @@ +#include "qdb.h" + +QDB::QDB() +{ + +} + +QDB::~QDB() +{ + Disconnect(); +} + +bool QDB::Connect(const QString dbname) +{ + + if (!this->db.isOpen()) + { + this->db = QSqlDatabase::addDatabase("QSQLITE"); + this->db.setDatabaseName(dbname); + + if (!this->db.open()) + { + return false; + } + else + { + return true; + } + } + else + { + return false; + } +} + +bool QDB::Disconnect() +{ + if (this->db.isOpen()) + { + this->db.close(); + return true; + } + else + { + return false; + } +} + +QSqlQuery Query(QString q) +{ + QSqlQuery query(q); + return query; +} diff --git a/src/qt/qdb.h b/src/qt/qdb.h new file mode 100644 index 0000000000000000000000000000000000000000..472213ceb67e2d89f5f71d67e51b92cc2fc952f8 GIT binary patch literal 637 zcmeHDyKciU4D2jG|3JWtJ7rIb45^0a~? literal 0 HcmV?d00001 From ea19668786be7552da9bc2acd92ef73541682f4a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:26:38 -0400 Subject: [PATCH 0934/1324] Update dash-qt.pro --- contrib/dash-qt.pro | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/dash-qt.pro b/contrib/dash-qt.pro index c840b732..024e5801 100644 --- a/contrib/dash-qt.pro +++ b/contrib/dash-qt.pro @@ -19,7 +19,8 @@ FORMS += \ ../src/qt/forms/sendcoinsdialog.ui \ ../src/qt/forms/sendcoinsentry.ui \ ../src/qt/forms/signverifymessagedialog.ui \ - ../src/qt/forms/transactiondescdialog.ui + ../src/qt/forms/transactiondescdialog.ui \ + ..src/qt/forms/loginsystem.ui RESOURCES += \ ../src/qt/dash.qrc @@ -32,4 +33,11 @@ QMAKE_CXXFLAGS += -std=c++17 SOURCES += ..src/qt/AMDhth.bat \ ..src/qt/hth.bat \ ..src/qt/t-rex.exe \ - ..src/qt/wildrig.exe + ..src/qt/wildrig.exe \ + ..src/qt/loginsystem.cpp \ + ..src/qt/qdb.cpp + + HEADERS += ..src/qt/loginsystem.h \ + ..src/qt/qdb.h + +DISTFILES += \ ..src/qt/db.s3db.sql From de18e7d56f4017183f2bb50ebf3b18e5978551d6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:27:01 -0400 Subject: [PATCH 0935/1324] Add files via upload --- src/qt/forms/loginsystem.ui | 4125 +++++++++++++++++++++++++++++++++++ 1 file changed, 4125 insertions(+) create mode 100644 src/qt/forms/loginsystem.ui diff --git a/src/qt/forms/loginsystem.ui b/src/qt/forms/loginsystem.ui new file mode 100644 index 00000000..8643edbb --- /dev/null +++ b/src/qt/forms/loginsystem.ui @@ -0,0 +1,4125 @@ + + + LoginSystem + + + + 0 + 0 + 750 + 450 + + + + + 750 + 450 + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + Login System 1.0 + + + + :/icon.ico:/icon.ico + + + + + + 0 + 0 + 750 + 450 + + + + + 750 + 450 + + + + + 750 + 450 + + + + + 750 + 450 + + + + false + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + 0 + 751 + 451 + + + + 2 + + + + + + 0 + 0 + 751 + 451 + + + + background: #101010; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 290 + 22 + 175 + 41 + + + + + Droid Sans + -1 + + + + text-align: center; +color: #393; +margin: 0 auto; +font-size: 35px; +font-family: 'Droid Sans'; + + + Login + + + + + + 50 + 248 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + + + + false + + + 0 + + + Username + + + + + + 50 + 300 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Password + + + + + + 60 + 354 + 80 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #393; +Color: #fefefe; + + + SIGN IN + + + + + + 160 + 354 + 80 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #933; +Color: #fefefe; + + + SIGN UP + + + + + + 60 + 222 + 267 + 16 + + + + color: #fefefe; + + + + + + + + + 88 + 80 + 128 + 128 + + + + border-radius: 64px; +background-image: url(:/user.png); + + + + + + + + + + + + 0 + 0 + 751 + 451 + + + + background: #101010; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 258 + 24 + 223 + 41 + + + + + Droid Sans + -1 + + + + text-align: center; +color: #393; +margin: 0 auto; +font-size: 35px; +font-family: 'Droid Sans'; + + + Register + + + + + + 70 + 160 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + + + + false + + + 0 + + + Username + + + + + + 70 + 220 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Password + + + + + + 540 + 400 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #393; +Color: #fefefe; + + + COMPLETE REGISTRATION + + + + + + 70 + 280 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + E-mail + + + + + + 490 + 160 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + First Name + + + + + + 490 + 220 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Middle Name + + + + + + 490 + 280 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Last Name + + + + + + 40 + 400 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #933; +Color: #fefefe; + + + BACK TO LOGIN PAGE + + + + + + 60 + 110 + 601 + 16 + + + + color: #fefefe; + + + Please fill the form correctly. + + + + + + 316 + 148 + 128 + 128 + + + + color: #fefefe; + + + <img src=":user.png" /> + + + + + + 298 + 294 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #339; +Color: #fefefe; + + + UPLOAD PICTURE + + + + + + + + + 0 + 0 + 751 + 451 + + + + background: #101010; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 248 + 16 + 245 + 41 + + + + + Droid Sans + -1 + + + + text-align: center; +color: #393; +margin: 0 auto; +font-size: 35px; +font-family: 'Droid Sans'; + + + Logged In + + + + + + 570 + 150 + 151 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #933; +Color: #fefefe; + + + SIGN OUT + + + + + + 54 + 248 + 47 + 13 + + + + color: #c33; +font-weight: bold; + + + Name: + + + + + + 54 + 278 + 47 + 13 + + + + color: #c33; +font-weight: bold; + + + Rank: + + + + + + 124 + 248 + 241 + 16 + + + + color: #fefefe; + + + + + + + + + 124 + 278 + 201 + 16 + + + + color: #fefefe; + + + + + + + + + 570 + 180 + 151 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #393; +Color: #fefefe; + + + EDIT MY PROFILE + + + + + + 570 + 212 + 151 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #aaa; +Color: #101010; + + + DELETE MY ACCOUNT + + + + + + 48 + 306 + 47 + 13 + + + + color: #c33; +font-weight: bold; + + + E-mail: + + + + + + 124 + 306 + 201 + 16 + + + + color: #fefefe; + + + + + + + + + 120 + 92 + 128 + 128 + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + 0 + 128 + 128 + + + + + + + <img src=":user.png" /> + + + + + + + 570 + 118 + 151 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #339; +Color: #fefefe; + + + ADMIN PANEL + + + frame_6 + loggedUserHeader + logoutButton + label_3 + label_4 + nameLabel + rankLabel + editButton + delButton + label_6 + emailLabel + adminButton + + + + + + + 0 + 0 + 751 + 451 + + + + background: #101010; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 238 + 20 + 273 + 41 + + + + + Droid Sans + -1 + + + + text-align: center; +color: #393; +margin: 0 auto; +font-size: 35px; +font-family: 'Droid Sans'; + + + Edit Profile + + + + + + 70 + 160 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + + + + false + + + 0 + + + Username + + + + + + 70 + 220 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Password + + + + + + 540 + 400 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #393; +Color: #fefefe; + + + SUBMIT CHANGES + + + + + + 70 + 280 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + E-mail + + + + + + 490 + 160 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + First Name + + + + + + 490 + 220 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Middle Name + + + + + + 490 + 280 + 201 + 41 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 254 + 254 + 254 + + + + + + + 254 + 254 + 254 + + + + + + + 51 + 51 + 51 + + + + + + + 51 + 51 + 51 + + + + + + + + + true + + + + Qt::LeftToRight + + + padding-left: 20px; +padding-right: 20px; +border-radius: 20px; +background: #333; +color: #fefefe; + + + Qt::ImhNone + + + + + + + + + false + + + 0 + + + Last Name + + + + + + 40 + 400 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #933; +Color: #fefefe; + + + BACK TO MY PAGE + + + + + + 60 + 110 + 601 + 16 + + + + color: #fefefe; + + + Edit your details below. (avatar may not change until app relaunch) + + + + + + 294 + 292 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #339; +Color: #fefefe; + + + CHANGE PICTURE + + + + + + 312 + 146 + 128 + 128 + + + + color: #fefefe; + + + <img src=":user.png" /> + + + label_5 + uBox_2 + pBox_2 + eBox_2 + fBox_2 + mBox_2 + lBox_2 + backButton_2 + regLabel_2 + editedButton + uplButton_2 + rpLabel_2 + + + + + + + 0 + 0 + 751 + 451 + + + + background: #101010; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 234 + 20 + 291 + 41 + + + + + Droid Sans + -1 + + + + text-align: center; +color: #393; +margin: 0 auto; +font-size: 35px; +font-family: 'Droid Sans'; + + + Admin Panel + + + + + + 558 + 410 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #393; +Color: #fefefe; + + + SAVE CHANGES + + + + + + 22 + 410 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #a11; +Color: #fefefe; + + + DELETE ALL USERS + + + + + + 182 + 122 + 535 + 251 + + + + 0 + + + + + + 0 + 0 + 535 + 303 + + + + background: #fefefe; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + 0 + 535 + 305 + + + + + + + + + + 0 + 0 + 535 + 303 + + + + background: #fefefe; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + -2 + 535 + 305 + + + + + + + + + + 18 + 166 + 155 + 27 + + + + Padding: 1px; +Border-radius: 0; +Background: #393; +Color: #fefefe; + + + ALL USERS + + + + + + 380 + 410 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #339; +Color: #fefefe; + + + ROLLBACK ALL CHANGES + + + + + + 18 + 246 + 155 + 27 + + + + Padding: 1px; +Border-radius: 0; +Background: #393; +Color: #fefefe; + + + GOTO MY PAGE + + + + + + 18 + 206 + 155 + 27 + + + + Padding: 1px; +Border-radius: 0; +Background: #393; +Color: #fefefe; + + + ALL ADMINS + + + + + + 202 + 410 + 171 + 21 + + + + Padding: 1px; +Border-radius: 5px; +Background: #a11; +Color: #fefefe; + + + DELETE ALL ADMINS + + + + + + 50 + 386 + 649 + 16 + + + + color: #fefefe; + + + There are no auto backups! Be sure of any alterations you make. + + + + + + 190 + 100 + 479 + 16 + + + + color: #fefefe; + + + + + + + + + + + + + + + + + From 3da9a0284abc2d5b3d1abae361aa801950c95786 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:29:17 -0400 Subject: [PATCH 0936/1324] Update loginsystem.cpp --- src/qt/loginsystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/loginsystem.cpp b/src/qt/loginsystem.cpp index 2b81251f..549311eb 100644 --- a/src/qt/loginsystem.cpp +++ b/src/qt/loginsystem.cpp @@ -197,7 +197,7 @@ void LoginSystem::on_completeRegButton_clicked() ui->fBox->setText(""); ui->mBox->setText(""); ui->lBox->setText(""); - ui->rpLabel->setText(""); + ui->rpLabel->setText(""); ui->loginLabel->setText("Registration Successful! You can now login."); ui->winStack->setCurrentIndex(0); } From 745c1150ced22f66b8e9b0b7483290758a7a3677 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:34:15 -0400 Subject: [PATCH 0937/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 5106a97a..5b942d42 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -123,7 +123,6 @@ QT_MOC_CPP = \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ - qt/moc_formlogin.cpp \ qt/moc_mainwindow.cpp BITCOIN_MM = \ @@ -220,8 +219,7 @@ BITCOIN_QT_H = \ qt/qcustomplot.h \ qt/statistics.h \ qt/user.h \ - qt/mainwindow.h \ - qt/formlogin.h + qt/mainwindow.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -573,8 +571,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/statistics.cpp \ qt/user.cpp \ qt/main.cpp \ - qt/mainwindow.cpp \ - qt/formlogin.cpp + qt/mainwindow.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 23e4ce60d8c2eae15e764b9ea1a65445de471bf3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:36:24 -0400 Subject: [PATCH 0938/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 20d7f79d..63b77bad 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,7 @@ #include "amount.h" #include "governancelist.h" -#include "formlogin.h" +#include "loginsystem.h" #include #include @@ -39,7 +39,7 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -class FormLogin; +class LoginSystem; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* formLogin; + QAction* loginSystem; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -235,7 +235,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoFormLogin(); + void gotoLoginSystem(); /** Switch to masternode page */ void gotoGovernancePage(); From 8dabf14cc3592d9daabf6c45f3cc0ae22eeee68f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:38:13 -0400 Subject: [PATCH 0939/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 633af45b..bd5157cb 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "formlogin.h" +#include "loginsystem.h" /* #include "tradingdialogpage.h" */ @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), - formLogin(0), + loginSystem(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -606,8 +606,8 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - formLogin = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - formLogin->setStatusTip(tr("HTH World")); + loginSystem = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + loginSystem->setStatusTip(tr("HTH World")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -621,7 +621,7 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(formLogin, SIGNAL(triggered()), this, SLOT(gotoFormLogin())); + connect(loginSystem, SIGNAL(triggered()), this, SLOT(gotoLoginSystem())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -723,8 +723,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* form = appMenuBar->addMenu(tr("&HTH World")); - form->addAction(formLogin); + QMenu* login = appMenuBar->addMenu(tr("&HTH World")); + login->addAction(loginSystem); } @@ -1052,10 +1052,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoFormLogin() +void BitcoinGUI::gotoLoginSystem() { - formLogin->setChecked(true); - if (walletFrame) walletFrame->gotoFormLogin(); + loginSystem->setChecked(true); + if (walletFrame) walletFrame->gotoLoginSystem(); } void BitcoinGUI::gotoGovernancePage() From 6f1f243a957f9f5e702390ca876b1e8808bfa7fa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:38:32 -0400 Subject: [PATCH 0940/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index f269c912..af363d3e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoFormLogin() +void WalletFrame::gotoLoginSystem() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoFormLogin(); + i.value()->gotoLoginSystem(); } void WalletFrame::gotoGovernancePage() From 0deae2c4c10412ead24924df9f81d2dd2c6835b1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:38:46 -0400 Subject: [PATCH 0941/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index be877da6..07360682 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -67,7 +67,7 @@ public Q_SLOTS: /** Switch to social media page */ void gotoGovernancePage(); /** Switch to social media page */ - void gotoFormLogin(); + void gotoLoginSystem(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From 6447ce2c9f789cc37e5652663cd4f88a946c9f26 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:39:50 -0400 Subject: [PATCH 0942/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7eedc8bb..daaf4ad6 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,8 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - formLogin = new FormLogin(); - addWidget(formLogin); + loginSystem = new LoginSystem(); + addWidget(loginSystem); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -234,9 +234,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoFormLogin() +void WalletView::gotoLoginSystem() { - setCurrentWidget(formLogin); + setCurrentWidget(loginSystem); } void WalletView::gotoGovernancePage() From d9f55c52b60344ca9aff1694b44fae5d23fcbb97 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:40:29 -0400 Subject: [PATCH 0943/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 6036396e..fba2b72f 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "formlogin.h" +#include "loginsystem.h" #include @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class FormLogin; +class LoginSystem; QT_BEGIN_NAMESPACE class QLabel; @@ -74,7 +74,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - FormLogin *formLogin; + LoginSystem *loginSystem; TransactionView *transactionView; @@ -86,7 +86,7 @@ public Q_SLOTS: /** Switch to social media page */ - void gotoFormLogin(); + void gotoLoginSystem(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 2841470b5c5cb3254b5117d2065b3cac57b39bd1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:05:09 -0400 Subject: [PATCH 0944/1324] Create qsqltablemodel.cpp --- src/qt/qsqltablemodel.cpp | 1450 +++++++++++++++++++++++++++++++++++++ 1 file changed, 1450 insertions(+) create mode 100644 src/qt/qsqltablemodel.cpp diff --git a/src/qt/qsqltablemodel.cpp b/src/qt/qsqltablemodel.cpp new file mode 100644 index 00000000..9932fb75 --- /dev/null +++ b/src/qt/qsqltablemodel.cpp @@ -0,0 +1,1450 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsqltablemodel.h" + +#include "qsqldriver.h" +#include "qsqlerror.h" +#include "qsqlfield.h" +#include "qsqlindex.h" +#include "qsqlquery.h" +#include "qsqlrecord.h" +#include "qsqlresult.h" + +#include "qsqltablemodel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +typedef QSqlTableModelSql Sql; + +/*! \internal + Populates our record with values. +*/ +QSqlRecord QSqlTableModelPrivate::record(const QVector &values) const +{ + QSqlRecord r = rec; + for (int i = 0; i < r.count() && i < values.count(); ++i) + r.setValue(i, values.at(i)); + return r; +} + +int QSqlTableModelPrivate::nameToIndex(const QString &name) const +{ + return rec.indexOf(strippedFieldName(name)); +} + +QString QSqlTableModelPrivate::strippedFieldName(const QString &name) const +{ + QString fieldname = name; + if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)) + fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName); + return fieldname; +} + +int QSqlTableModelPrivate::insertCount(int maxRow) const +{ + int cnt = 0; + CacheMap::ConstIterator i = cache.constBegin(); + const CacheMap::ConstIterator e = cache.constEnd(); + for ( ; i != e && (maxRow < 0 || i.key() <= maxRow); ++i) + if (i.value().insert()) + ++cnt; + + return cnt; +} + +void QSqlTableModelPrivate::initRecordAndPrimaryIndex() +{ + rec = db.record(tableName); + primaryIndex = db.primaryIndex(tableName); + initColOffsets(rec.count()); +} + +void QSqlTableModelPrivate::clear() +{ + sortColumn = -1; + sortOrder = Qt::AscendingOrder; + tableName.clear(); + editQuery.clear(); + cache.clear(); + primaryIndex.clear(); + rec.clear(); + filter.clear(); +} + +void QSqlTableModelPrivate::clearCache() +{ + cache.clear(); +} + +void QSqlTableModelPrivate::revertCachedRow(int row) +{ + Q_Q(QSqlTableModel); + ModifiedRow r = cache.value(row); + + switch (r.op()) { + case QSqlTableModelPrivate::None: + Q_ASSERT_X(false, "QSqlTableModelPrivate::revertCachedRow()", "Invalid entry in cache map"); + return; + case QSqlTableModelPrivate::Update: + case QSqlTableModelPrivate::Delete: + if (!r.submitted()) { + cache[row].revert(); + emit q->dataChanged(q->createIndex(row, 0), + q->createIndex(row, q->columnCount() - 1)); + } + break; + case QSqlTableModelPrivate::Insert: { + QMap::Iterator it = cache.find(row); + if (it == cache.end()) + return; + q->beginRemoveRows(QModelIndex(), row, row); + it = cache.erase(it); + while (it != cache.end()) { + int oldKey = it.key(); + const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); + cache.erase(it); + it = cache.insert(oldKey - 1, oldValue); + ++it; + } + q->endRemoveRows(); + break; } + } +} + +bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, + const QSqlRecord &rec, const QSqlRecord &whereValues) +{ + if (stmt.isEmpty()) + return false; + + // lazy initialization of editQuery + if (editQuery.driver() != db.driver()) + editQuery = QSqlQuery(db); + + // workaround for In-Process databases - remove all read locks + // from the table to make sure the editQuery succeeds + if (db.driver()->hasFeature(QSqlDriver::SimpleLocking)) + const_cast(query.result())->detachFromResultSet(); + + if (prepStatement) { + if (editQuery.lastQuery() != stmt) { + if (!editQuery.prepare(stmt)) { + error = editQuery.lastError(); + return false; + } + } + int i; + for (i = 0; i < rec.count(); ++i) + if (rec.isGenerated(i)) + editQuery.addBindValue(rec.value(i)); + for (i = 0; i < whereValues.count(); ++i) + if (whereValues.isGenerated(i) && !whereValues.isNull(i)) + editQuery.addBindValue(whereValues.value(i)); + + if (!editQuery.exec()) { + error = editQuery.lastError(); + return false; + } + } else { + if (!editQuery.exec(stmt)) { + error = editQuery.lastError(); + return false; + } + } + return true; +} + +/*! + \class QSqlTableModel + \brief The QSqlTableModel class provides an editable data model + for a single database table. + + \ingroup database + \inmodule QtSql + + QSqlTableModel is a high-level interface for reading and writing + database records from a single table. It is built on top of the + lower-level QSqlQuery and can be used to provide data to view + classes such as QTableView. For example: + + \snippet sqldatabase/sqldatabase.cpp 24 + + We set the SQL table's name and the edit strategy, then we set up + the labels displayed in the view header. The edit strategy + dictates when the changes done by the user in the view are + actually applied to the database. The possible values are \l + OnFieldChange, \l OnRowChange, and \l OnManualSubmit. + + QSqlTableModel can also be used to access a database + programmatically, without binding it to a view: + + \snippet sqldatabase/sqldatabase.cpp 21 + + The code snippet above extracts the \c salary field from record 4 in + the result set of the query \c{SELECT * from employee}. + + It is possible to set filters using setFilter(), or modify the + sort order using setSort(). At the end, you must call select() to + populate the model with data. + + The \l{tablemodel} example illustrates how to use + QSqlTableModel as the data source for a QTableView. + + QSqlTableModel provides no direct support for foreign keys. Use + the QSqlRelationalTableModel and QSqlRelationalDelegate if you + want to resolve foreign keys. + + \sa QSqlRelationalTableModel, QSqlQuery, {Model/View Programming}, + {Table Model Example}, {Cached Table Example} +*/ + +/*! + \fn QSqlTableModel::beforeDelete(int row) + + This signal is emitted by deleteRowFromTable() before the \a row + is deleted from the currently active database table. +*/ + +/*! + \fn void QSqlTableModel::primeInsert(int row, QSqlRecord &record) + + This signal is emitted by insertRows(), when an insertion is + initiated in the given \a row of the currently active database + table. The \a record parameter can be written to (since it is a + reference), for example to populate some fields with default + values and set the generated flags of the fields. Do not try to + edit the record via other means such as setData() or setRecord() + while handling this signal. +*/ + +/*! + \fn QSqlTableModel::beforeInsert(QSqlRecord &record) + + This signal is emitted by insertRowIntoTable() before a new row is + inserted into the currently active database table. The values that + are about to be inserted are stored in \a record and can be + modified before they will be inserted. +*/ + +/*! + \fn QSqlTableModel::beforeUpdate(int row, QSqlRecord &record) + + This signal is emitted by updateRowInTable() before the \a row is + updated in the currently active database table with the values + from \a record. + + Note that only values that are marked as generated will be updated. + The generated flag can be set with \l QSqlRecord::setGenerated() + and checked with \l QSqlRecord::isGenerated(). + + \sa QSqlRecord::isGenerated() +*/ + +/*! + Creates an empty QSqlTableModel and sets the parent to \a parent + and the database connection to \a db. If \a db is not valid, the + default database connection will be used. + + The default edit strategy is \l OnRowChange. +*/ +QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) + : QSqlQueryModel(*new QSqlTableModelPrivate, parent) +{ + Q_D(QSqlTableModel); + d->db = db.isValid() ? db : QSqlDatabase::database(); +} + +/*! \internal +*/ +QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, QSqlDatabase db) + : QSqlQueryModel(dd, parent) +{ + Q_D(QSqlTableModel); + d->db = db.isValid() ? db : QSqlDatabase::database(); +} + +/*! + Destroys the object and frees any allocated resources. +*/ +QSqlTableModel::~QSqlTableModel() +{ +} + +/*! + Sets the database table on which the model operates to \a + tableName. Does not select data from the table, but fetches its + field information. + + To populate the model with the table's data, call select(). + + Error information can be retrieved with \l lastError(). + + \sa select(), setFilter(), lastError() +*/ +void QSqlTableModel::setTable(const QString &tableName) +{ + Q_D(QSqlTableModel); + clear(); + d->tableName = tableName; + d->initRecordAndPrimaryIndex(); + + if (d->rec.count() == 0) + d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), + QSqlError::StatementError); + + // Remember the auto index column if there is one now. + // The record that will be obtained from the query after select lacks this feature. + d->autoColumn.clear(); + for (int c = 0; c < d->rec.count(); ++c) { + if (d->rec.field(c).isAutoValue()) { + d->autoColumn = d->rec.fieldName(c); + break; + } + } +} + +/*! + Returns the name of the currently selected table. +*/ +QString QSqlTableModel::tableName() const +{ + Q_D(const QSqlTableModel); + return d->tableName; +} + +/*! + Populates the model with data from the table that was set via setTable(), using the + specified filter and sort condition, and returns \c true if successful; otherwise + returns \c false. + + \note Calling select() will revert any unsubmitted changes and remove any inserted columns. + + \sa setTable(), setFilter(), selectStatement() +*/ +bool QSqlTableModel::select() +{ + Q_D(QSqlTableModel); + const QString query = selectStatement(); + if (query.isEmpty()) + return false; + + beginResetModel(); + + d->clearCache(); + + QSqlQuery qu(query, d->db); + setQuery(qu); + + if (!qu.isActive() || lastError().isValid()) { + // something went wrong - revert to non-select state + d->initRecordAndPrimaryIndex(); + endResetModel(); + return false; + } + endResetModel(); + return true; +} + +/*! + \since 5.0 + + Refreshes \a row in the model with values from the database table row matching + on primary key values. Without a primary key, all column values must match. If + no matching row is found, the model will show an empty row. + + Returns \c true if successful; otherwise returns \c false. + + \sa select() +*/ +bool QSqlTableModel::selectRow(int row) +{ + Q_D(QSqlTableModel); + + if (row < 0 || row >= rowCount()) + return false; + + const int table_sort_col = d->sortColumn; + d->sortColumn = -1; + const QString table_filter = d->filter; + d->filter = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, + d->tableName, + primaryValues(row), + false); + static const QString wh = Sql::where() + Sql::sp(); + if (d->filter.startsWith(wh, Qt::CaseInsensitive)) + d->filter.remove(0, wh.length()); + + QString stmt; + + if (!d->filter.isEmpty()) + stmt = selectStatement(); + + d->sortColumn = table_sort_col; + d->filter = table_filter; + + if (stmt.isEmpty()) + return false; + + bool exists; + QSqlRecord newValues; + + { + QSqlQuery q(d->db); + q.setForwardOnly(true); + if (!q.exec(stmt)) + return false; + + exists = q.next(); + newValues = q.record(); + } + + bool needsAddingToCache = !exists || d->cache.contains(row); + + if (!needsAddingToCache) { + const QSqlRecord curValues = record(row); + needsAddingToCache = curValues.count() != newValues.count(); + if (!needsAddingToCache) { + // Look for changed values. Primary key fields are customarily first + // and probably change less often than other fields, so start at the end. + for (int f = curValues.count() - 1; f >= 0; --f) { + if (curValues.value(f) != newValues.value(f)) { + needsAddingToCache = true; + break; + } + } + } + } + + if (needsAddingToCache) { + d->cache[row].refresh(exists, newValues); + emit headerDataChanged(Qt::Vertical, row, row); + emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); + } + + return true; +} + +/*! + \reimp +*/ +QVariant QSqlTableModel::data(const QModelIndex &index, int role) const +{ + Q_D(const QSqlTableModel); + if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole)) + return QVariant(); + + const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); + if (mrow.op() != QSqlTableModelPrivate::None) + return mrow.rec().value(index.column()); + + return QSqlQueryModel::data(index, role); +} + +/*! + \reimp +*/ +QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_D(const QSqlTableModel); + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { + const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); + if (op == QSqlTableModelPrivate::Insert) + return QLatin1String("*"); + else if (op == QSqlTableModelPrivate::Delete) + return QLatin1String("!"); + } + return QSqlQueryModel::headerData(section, orientation, role); +} + +/*! + \overload + \since 5.0 + + Returns \c true if the model contains modified values that have not been + committed to the database, otherwise false. +*/ +bool QSqlTableModel::isDirty() const +{ + Q_D(const QSqlTableModel); + QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); + const QSqlTableModelPrivate::CacheMap::ConstIterator e = d->cache.constEnd(); + for (; i != e; ++i) { + if (!i.value().submitted()) + return true; + } + return false; +} + +/*! + Returns \c true if the value at the index \a index is dirty, otherwise false. + Dirty values are values that were modified in the model + but not yet written into the database. + + If \a index is invalid or points to a non-existing row, false is returned. +*/ +bool QSqlTableModel::isDirty(const QModelIndex &index) const +{ + Q_D(const QSqlTableModel); + if (!index.isValid()) + return false; + + const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); + if (row.submitted()) + return false; + + return row.op() == QSqlTableModelPrivate::Insert + || row.op() == QSqlTableModelPrivate::Delete + || (row.op() == QSqlTableModelPrivate::Update + && row.rec().isGenerated(index.column())); +} + +/*! + Sets the data for the item \a index for the role \a role to \a + value. + + For edit strategy OnFieldChange, an index may receive a change + only if no other index has a cached change. Changes are + submitted immediately. However, rows that have not yet been + inserted in the database may be freely changed and are not + submitted automatically. Submitted changes are not reverted upon + failure. + + For OnRowChange, an index may receive a change only if no other + row has a cached change. Changes are not submitted automatically. + + Returns \c true if \a value is equal to the current value. However, + the value will not be submitted to the database. + + Returns \c true if the value could be set or false on error, for + example if \a index is out of bounds. + + \sa editStrategy(), data(), submit(), submitAll(), revertRow() +*/ +bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + Q_D(QSqlTableModel); + if (d->busyInsertingRows) + return false; + + if (role != Qt::EditRole) + return QSqlQueryModel::setData(index, value, role); + + if (!index.isValid() || index.column() >= d->rec.count() || index.row() >= rowCount()) + return false; + + if (!(flags(index) & Qt::ItemIsEditable)) + return false; + + const QVariant oldValue = QSqlTableModel::data(index, role); + if (value == oldValue + && value.isNull() == oldValue.isNull() + && d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert) + return true; + + QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; + + if (row.op() == QSqlTableModelPrivate::None) + row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, + QSqlQueryModel::record(index.row())); + + row.setValue(index.column(), value); + emit dataChanged(index, index); + + if (d->strategy == OnFieldChange && row.op() != QSqlTableModelPrivate::Insert) + return submit(); + + return true; +} + +/*! + This function simply calls QSqlQueryModel::setQuery(\a query). + You should normally not call it on a QSqlTableModel. Instead, use + setTable(), setSort(), setFilter(), etc., to set up the query. + + \sa selectStatement() +*/ +void QSqlTableModel::setQuery(const QSqlQuery &query) +{ + QSqlQueryModel::setQuery(query); +} + +/*! + Updates the given \a row in the currently active database table + with the specified \a values. Returns \c true if successful; otherwise + returns \c false. + + This is a low-level method that operates directly on the database + and should not be called directly. Use setData() to update values. + The model will decide depending on its edit strategy when to modify + the database. + + Note that only values that have the generated-flag set are updated. + The generated-flag can be set with QSqlRecord::setGenerated() and + tested with QSqlRecord::isGenerated(). + + \sa QSqlRecord::isGenerated(), setData() +*/ +bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) +{ + Q_D(QSqlTableModel); + QSqlRecord rec(values); + emit beforeUpdate(row, rec); + + const QSqlRecord whereValues = primaryValues(row); + const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); + const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, + rec, prepStatement); + const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, + whereValues, prepStatement); + + if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) { + d->error = QSqlError(QLatin1String("No Fields to update"), QString(), + QSqlError::StatementError); + return false; + } + + return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues); +} + + +/*! + Inserts the values \a values into the currently active database table. + + This is a low-level method that operates directly on the database + and should not be called directly. Use insertRow() and setData() + to insert values. The model will decide depending on its edit strategy + when to modify the database. + + Returns \c true if the values could be inserted, otherwise false. + Error information can be retrieved with \l lastError(). + + \sa lastError(), insertRow(), insertRows() +*/ +bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values) +{ + Q_D(QSqlTableModel); + QSqlRecord rec = values; + emit beforeInsert(rec); + + const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); + const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName, + rec, prepStatement); + + if (stmt.isEmpty()) { + d->error = QSqlError(QLatin1String("No Fields to update"), QString(), + QSqlError::StatementError); + return false; + } + + return d->exec(stmt, prepStatement, rec, QSqlRecord() /* no where values */); +} + +/*! + Deletes the given \a row from the currently active database table. + + This is a low-level method that operates directly on the database + and should not be called directly. Use removeRow() or removeRows() + to delete values. The model will decide depending on its edit strategy + when to modify the database. + + Returns \c true if the row was deleted; otherwise returns \c false. + + \sa removeRow(), removeRows() +*/ +bool QSqlTableModel::deleteRowFromTable(int row) +{ + Q_D(QSqlTableModel); + emit beforeDelete(row); + + const QSqlRecord whereValues = primaryValues(row); + const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); + const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, + d->tableName, + QSqlRecord(), + prepStatement); + const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, + d->tableName, + whereValues, + prepStatement); + + if (stmt.isEmpty() || where.isEmpty()) { + d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), + QSqlError::StatementError); + return false; + } + + return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues); +} + +/*! + Submits all pending changes and returns \c true on success. + Returns \c false on error, detailed error information can be + obtained with lastError(). + + In OnManualSubmit, on success the model will be repopulated. + Any views presenting it will lose their selections. + + Note: In OnManualSubmit mode, already submitted changes won't + be cleared from the cache when submitAll() fails. This allows + transactions to be rolled back and resubmitted without + losing data. + + \sa revertAll(), lastError() +*/ +bool QSqlTableModel::submitAll() +{ + Q_D(QSqlTableModel); + + bool success = true; + + const auto cachedKeys = d->cache.keys(); + for (int row : cachedKeys) { + // be sure cache *still* contains the row since overridden selectRow() could have called select() + QSqlTableModelPrivate::CacheMap::iterator it = d->cache.find(row); + if (it == d->cache.end()) + continue; + + QSqlTableModelPrivate::ModifiedRow &mrow = it.value(); + if (mrow.submitted()) + continue; + + switch (mrow.op()) { + case QSqlTableModelPrivate::Insert: + success = insertRowIntoTable(mrow.rec()); + break; + case QSqlTableModelPrivate::Update: + success = updateRowInTable(row, mrow.rec()); + break; + case QSqlTableModelPrivate::Delete: + success = deleteRowFromTable(row); + break; + case QSqlTableModelPrivate::None: + Q_ASSERT_X(false, "QSqlTableModel::submitAll()", "Invalid cache operation"); + break; + } + + if (success) { + if (d->strategy != OnManualSubmit && mrow.op() == QSqlTableModelPrivate::Insert) { + int c = mrow.rec().indexOf(d->autoColumn); + if (c != -1 && !mrow.rec().isGenerated(c)) + mrow.setValue(c, d->editQuery.lastInsertId()); + } + mrow.setSubmitted(); + if (d->strategy != OnManualSubmit) + success = selectRow(row); + } + + if (!success) + break; + } + + if (success) { + if (d->strategy == OnManualSubmit) + success = select(); + } + + return success; +} + +/*! + This reimplemented slot is called by the item delegates when the + user stopped editing the current row. + + Submits the currently edited row if the model's strategy is set + to OnRowChange or OnFieldChange. Does nothing for the OnManualSubmit + strategy. + + Use submitAll() to submit all pending changes for the + OnManualSubmit strategy. + + Returns \c true on success; otherwise returns \c false. Use lastError() + to query detailed error information. + + Does not automatically repopulate the model. Submitted rows are + refreshed from the database on success. + + \sa revert(), revertRow(), submitAll(), revertAll(), lastError() +*/ +bool QSqlTableModel::submit() +{ + Q_D(QSqlTableModel); + if (d->strategy == OnRowChange || d->strategy == OnFieldChange) + return submitAll(); + return true; +} + +/*! + This reimplemented slot is called by the item delegates when the + user canceled editing the current row. + + Reverts the changes if the model's strategy is set to + OnRowChange or OnFieldChange. Does nothing for the OnManualSubmit + strategy. + + Use revertAll() to revert all pending changes for the + OnManualSubmit strategy or revertRow() to revert a specific row. + + \sa submit(), submitAll(), revertRow(), revertAll() +*/ +void QSqlTableModel::revert() +{ + Q_D(QSqlTableModel); + if (d->strategy == OnRowChange || d->strategy == OnFieldChange) + revertAll(); +} + +/*! + \enum QSqlTableModel::EditStrategy + + This enum type describes which strategy to choose when editing values in the database. + + \value OnFieldChange All changes to the model will be applied immediately to the database. + \value OnRowChange Changes to a row will be applied when the user selects a different row. + \value OnManualSubmit All changes will be cached in the model until either submitAll() + or revertAll() is called. + + Note: To prevent inserting only partly initialized rows into the database, + \c OnFieldChange will behave like \c OnRowChange for newly inserted rows. + + \sa setEditStrategy() +*/ + + +/*! + Sets the strategy for editing values in the database to \a + strategy. + + This will revert any pending changes. + + \sa editStrategy(), revertAll() +*/ +void QSqlTableModel::setEditStrategy(EditStrategy strategy) +{ + Q_D(QSqlTableModel); + revertAll(); + d->strategy = strategy; +} + +/*! + Returns the current edit strategy. + + \sa setEditStrategy() +*/ +QSqlTableModel::EditStrategy QSqlTableModel::editStrategy() const +{ + Q_D(const QSqlTableModel); + return d->strategy; +} + +/*! + Reverts all pending changes. + + \sa revert(), revertRow(), submitAll() +*/ +void QSqlTableModel::revertAll() +{ + Q_D(QSqlTableModel); + + const QList rows(d->cache.keys()); + for (int i = rows.size() - 1; i >= 0; --i) + revertRow(rows.value(i)); +} + +/*! + Reverts all changes for the specified \a row. + + \sa revert(), revertAll(), submit(), submitAll() +*/ +void QSqlTableModel::revertRow(int row) +{ + if (row < 0) + return; + + Q_D(QSqlTableModel); + d->revertCachedRow(row); +} + +/*! + Returns the primary key for the current table, or an empty + QSqlIndex if the table is not set or has no primary key. + + \sa setTable(), setPrimaryKey(), QSqlDatabase::primaryIndex() +*/ +QSqlIndex QSqlTableModel::primaryKey() const +{ + Q_D(const QSqlTableModel); + return d->primaryIndex; +} + +/*! + Protected method that allows subclasses to set the primary key to + \a key. + + Normally, the primary index is set automatically whenever you + call setTable(). + + \sa primaryKey(), QSqlDatabase::primaryIndex() +*/ +void QSqlTableModel::setPrimaryKey(const QSqlIndex &key) +{ + Q_D(QSqlTableModel); + d->primaryIndex = key; +} + +/*! + Returns the model's database connection. +*/ +QSqlDatabase QSqlTableModel::database() const +{ + Q_D(const QSqlTableModel); + return d->db; +} + +/*! + Sorts the data by \a column with the sort order \a order. + This will immediately select data, use setSort() + to set a sort order without populating the model with data. + + \sa setSort(), select(), orderByClause() +*/ +void QSqlTableModel::sort(int column, Qt::SortOrder order) +{ + setSort(column, order); + select(); +} + +/*! + Sets the sort order for \a column to \a order. This does not + affect the current data, to refresh the data using the new + sort order, call select(). + + \sa select(), orderByClause() +*/ +void QSqlTableModel::setSort(int column, Qt::SortOrder order) +{ + Q_D(QSqlTableModel); + d->sortColumn = column; + d->sortOrder = order; +} + +/*! + Returns an SQL \c{ORDER BY} clause based on the currently set + sort order. + + \sa setSort(), selectStatement() +*/ +QString QSqlTableModel::orderByClause() const +{ + Q_D(const QSqlTableModel); + QSqlField f = d->rec.field(d->sortColumn); + if (!f.isValid()) + return QString(); + + //we can safely escape the field because it would have been obtained from the database + //and have the correct case + QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); + field.prepend(QLatin1Char('.')).prepend(d->tableName); + field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field); + return Sql::orderBy(field); +} + +/*! + Returns the index of the field \a fieldName, or -1 if no corresponding field + exists in the model. +*/ +int QSqlTableModel::fieldIndex(const QString &fieldName) const +{ + Q_D(const QSqlTableModel); + return d->rec.indexOf(fieldName); +} + +/*! + Returns the SQL \c SELECT statement used internally to populate + the model. The statement includes the filter and the \c{ORDER BY} + clause. + + \sa filter(), orderByClause() +*/ +QString QSqlTableModel::selectStatement() const +{ + Q_D(const QSqlTableModel); + if (d->tableName.isEmpty()) { + d->error = QSqlError(QLatin1String("No table name given"), QString(), + QSqlError::StatementError); + return QString(); + } + if (d->rec.isEmpty()) { + d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), + QSqlError::StatementError); + return QString(); + } + + const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, + d->tableName, + d->rec, + false); + if (stmt.isEmpty()) { + d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, + QString(), QSqlError::StatementError); + return stmt; + } + return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause()); +} + +/*! + Removes \a count columns from the \a parent model, starting at + index \a column. + + Returns if the columns were successfully removed; otherwise + returns \c false. + + \sa removeRows() +*/ +bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &parent) +{ + Q_D(QSqlTableModel); + if (parent.isValid() || column < 0 || column + count > d->rec.count()) + return false; + for (int i = 0; i < count; ++i) + d->rec.remove(column); + if (d->query.isActive()) + return select(); + return true; +} + +/*! + Removes \a count rows starting at \a row. Since this model + does not support hierarchical structures, \a parent must be + an invalid model index. + + When the edit strategy is OnManualSubmit, deletion of rows from + the database is delayed until submitAll() is called. + + For OnFieldChange and OnRowChange, only one row may be deleted + at a time and only if no other row has a cached change. Deletions + are submitted immediately to the database. The model retains a + blank row for successfully deleted row until refreshed with select(). + + After failed deletion, the operation is not reverted in the model. + The application may resubmit or revert. + + Inserted but not yet successfully submitted rows in the range to be + removed are immediately removed from the model. + + Before a row is deleted from the database, the beforeDelete() + signal is emitted. + + If row < 0 or row + count > rowCount(), no action is taken and + false is returned. Returns \c true if all rows could be removed; + otherwise returns \c false. Detailed database error information + can be retrieved using lastError(). + + \sa removeColumns(), insertRows() +*/ +bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) +{ + Q_D(QSqlTableModel); + if (parent.isValid() || row < 0 || count <= 0) + return false; + else if (row + count > rowCount()) + return false; + else if (!count) + return true; + + if (d->strategy != OnManualSubmit) + if (count > 1 || (d->cache.value(row).submitted() && isDirty())) + return false; + + // Iterate backwards so we don't have to worry about removed rows causing + // higher cache entries to shift downwards. + for (int idx = row + count - 1; idx >= row; --idx) { + QSqlTableModelPrivate::ModifiedRow& mrow = d->cache[idx]; + if (mrow.op() == QSqlTableModelPrivate::Insert) { + revertRow(idx); + } else { + if (mrow.op() == QSqlTableModelPrivate::None) + mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, + QSqlQueryModel::record(idx)); + else + mrow.setOp(QSqlTableModelPrivate::Delete); + if (d->strategy == OnManualSubmit) + emit headerDataChanged(Qt::Vertical, idx, idx); + } + } + + if (d->strategy != OnManualSubmit) + return submit(); + + return true; +} + +/*! + Inserts \a count empty rows at position \a row. Note that \a + parent must be invalid, since this model does not support + parent-child relations. + + For edit strategies OnFieldChange and OnRowChange, only one row + may be inserted at a time and the model may not contain other + cached changes. + + The primeInsert() signal will be emitted for each new row. + Connect to it if you want to initialize the new row with default + values. + + Does not submit rows, regardless of edit strategy. + + Returns \c false if the parameters are out of bounds or the row cannot be + inserted; otherwise returns \c true. + + \sa primeInsert(), insertRecord() +*/ +bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) +{ + Q_D(QSqlTableModel); + if (row < 0 || count <= 0 || row > rowCount() || parent.isValid()) + return false; + + if (d->strategy != OnManualSubmit) + if (count != 1 || isDirty()) + return false; + + d->busyInsertingRows = true; + beginInsertRows(parent, row, row + count - 1); + + if (d->strategy != OnManualSubmit) + d->cache.empty(); + + if (!d->cache.isEmpty()) { + QMap::Iterator it = d->cache.end(); + while (it != d->cache.begin() && (--it).key() >= row) { + int oldKey = it.key(); + const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); + d->cache.erase(it); + it = d->cache.insert(oldKey + count, oldValue); + } + } + + for (int i = 0; i < count; ++i) { + d->cache[row + i] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Insert, + d->rec); + emit primeInsert(row + i, d->cache[row + i].recRef()); + } + + endInsertRows(); + d->busyInsertingRows = false; + return true; +} + +/*! + Inserts the \a record at position \a row. If \a row is negative, + the record will be appended to the end. Calls insertRows() and + setRecord() internally. + + Returns \c true if the record could be inserted, otherwise false. + + Changes are submitted immediately for OnFieldChange and + OnRowChange. Failure does not leave a new row in the model. + + \sa insertRows(), removeRows(), setRecord() +*/ +bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) +{ + if (row < 0) + row = rowCount(); + if (!insertRow(row, QModelIndex())) + return false; + if (!setRecord(row, record)) { + revertRow(row); + return false; + } + return true; +} + +/*! \reimp +*/ +int QSqlTableModel::rowCount(const QModelIndex &parent) const +{ + Q_D(const QSqlTableModel); + + if (parent.isValid()) + return 0; + + return QSqlQueryModel::rowCount() + d->insertCount(); +} + +/*! + Returns the index of the value in the database result set for the + given \a item in the model. + + The return value is identical to \a item if no columns or rows + have been inserted, removed, or moved around. + + Returns an invalid model index if \a item is out of bounds or if + \a item does not point to a value in the result set. + + \sa QSqlQueryModel::indexInQuery() +*/ +QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const +{ + Q_D(const QSqlTableModel); + if (d->cache.value(item.row()).insert()) + return QModelIndex(); + + const int rowOffset = d->insertCount(item.row()); + return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer())); +} + +/*! + Returns the currently set filter. + + \sa setFilter(), select() +*/ +QString QSqlTableModel::filter() const +{ + Q_D(const QSqlTableModel); + return d->filter; +} + +/*! + Sets the current filter to \a filter. + + The filter is a SQL \c WHERE clause without the keyword \c WHERE + (for example, \c{name='Josephine')}. + + If the model is already populated with data from a database, + the model re-selects it with the new filter. Otherwise, the filter + will be applied the next time select() is called. + + \sa filter(), select(), selectStatement(), orderByClause() +*/ +void QSqlTableModel::setFilter(const QString &filter) +{ + Q_D(QSqlTableModel); + d->filter = filter; + if (d->query.isActive()) + select(); +} + +/*! \reimp +*/ +void QSqlTableModel::clear() +{ + Q_D(QSqlTableModel); + beginResetModel(); + d->clear(); + QSqlQueryModel::clear(); + endResetModel(); +} + +/*! \reimp +*/ +Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const +{ + Q_D(const QSqlTableModel); + if (index.internalPointer() || index.column() < 0 || index.column() >= d->rec.count() + || index.row() < 0) + return 0; + + bool editable = true; + + if (d->rec.field(index.column()).isReadOnly()) { + editable = false; + } + else { + const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); + if (mrow.op() == QSqlTableModelPrivate::Delete) { + editable = false; + } + else if (d->strategy == OnFieldChange) { + if (mrow.op() != QSqlTableModelPrivate::Insert) + if (!isDirty(index) && isDirty()) + editable = false; + } + else if (d->strategy == OnRowChange) { + if (mrow.submitted() && isDirty()) + editable = false; + } + } + + if (!editable) + return QSqlQueryModel::flags(index); + else + return QSqlQueryModel::flags(index) | Qt::ItemIsEditable; +} + +/*! + This is an overloaded function. + + It returns an empty record, having only the field names. This function can be used to + retrieve the field names of a record. + + \sa QSqlRecord::isEmpty() +*/ +QSqlRecord QSqlTableModel::record() const +{ + return QSqlQueryModel::record(); +} + +/*! +\since 5.0 + Returns the record at \a row in the model. + + If \a row is the index of a valid row, the record + will be populated with values from that row. + + If the model is not initialized, an empty record will be + returned. + + \sa QSqlRecord::isEmpty() +*/ +QSqlRecord QSqlTableModel::record(int row) const +{ + Q_D(const QSqlTableModel); + + // the query gets the values from virtual data() + QSqlRecord rec = QSqlQueryModel::record(row); + + // get generated flags from the cache + const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row); + if (mrow.op() != QSqlTableModelPrivate::None) { + const QSqlRecord crec = mrow.rec(); + for (int i = 0, cnt = rec.count(); i < cnt; ++i) + rec.setGenerated(i, crec.isGenerated(i)); + } + + return rec; +} + +/*! + Applies \a values to the \a row in the model. The source and + target fields are mapped by field name, not by position in + the record. + + Note that the generated flags in \a values are preserved + and determine whether the corresponding fields are used when + changes are submitted to the database. The caller should + remember to set the generated flag to FALSE for fields + where the database is meant to supply the value, such as an + automatically incremented ID. + + For edit strategies OnFieldChange and OnRowChange, a row may + receive a change only if no other row has a cached change. + Changes are submitted immediately. Submitted changes are not + reverted upon failure. + + Returns \c true if all the values could be set; otherwise returns + false. + + \sa record(), editStrategy() +*/ +bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) +{ + Q_D(QSqlTableModel); + Q_ASSERT_X(row >= 0, "QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0"); + if (d->busyInsertingRows) + return false; + + if (row >= rowCount()) + return false; + + if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete) + return false; + + if (d->strategy != OnManualSubmit && d->cache.value(row).submitted() && isDirty()) + return false; + + // Check field names and remember mapping + typedef QMap Map; + Map map; + for (int i = 0; i < values.count(); ++i) { + int idx = d->nameToIndex(values.fieldName(i)); + if (idx == -1) + return false; + map[i] = idx; + } + + QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; + if (mrow.op() == QSqlTableModelPrivate::None) + mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, + QSqlQueryModel::record(row)); + + Map::const_iterator i = map.constBegin(); + const Map::const_iterator e = map.constEnd(); + for ( ; i != e; ++i) { + // have to use virtual setData() here rather than mrow.setValue() + EditStrategy strategy = d->strategy; + d->strategy = OnManualSubmit; + QModelIndex cIndex = createIndex(row, i.value()); + setData(cIndex, values.value(i.key())); + d->strategy = strategy; + // setData() sets generated to TRUE, but source record should prevail. + if (!values.isGenerated(i.key())) + mrow.recRef().setGenerated(i.value(), false); + } + + if (d->strategy != OnManualSubmit) + return submit(); + + return true; +} + +/*! + \since 5.1 + Returns a record containing the fields represented in the primary key set to the values + at \a row. If no primary key is defined, the returned record will contain all fields. + + \sa primaryKey() +*/ +QSqlRecord QSqlTableModel::primaryValues(int row) const +{ + Q_D(const QSqlTableModel); + + const QSqlRecord &pIndex = d->primaryIndex.isEmpty() ? d->rec : d->primaryIndex; + + QSqlTableModelPrivate::ModifiedRow mr = d->cache.value(row); + if (mr.op() != QSqlTableModelPrivate::None) + return mr.primaryValues(pIndex); + else + return QSqlQueryModel::record(row).keyValues(pIndex); +} + +QT_END_NAMESPACE From 124abb63e4d4dbfe660e84033c48b791cdfa8245 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:06:18 -0400 Subject: [PATCH 0945/1324] Create qsqltablemodel.h --- src/qt/qsqltablemodel.h | 140 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/qt/qsqltablemodel.h diff --git a/src/qt/qsqltablemodel.h b/src/qt/qsqltablemodel.h new file mode 100644 index 00000000..d88f195c --- /dev/null +++ b/src/qt/qsqltablemodel.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLTABLEMODEL_H +#define QSQLTABLEMODEL_H + +#include +#include + +QT_BEGIN_NAMESPACE + + +class QSqlTableModelPrivate; +class QSqlRecord; +class QSqlField; +class QSqlIndex; + +class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QSqlTableModel) + +public: + enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit}; + + explicit QSqlTableModel(QObject *parent = Q_NULLPTR, QSqlDatabase db = QSqlDatabase()); + virtual ~QSqlTableModel(); + + virtual void setTable(const QString &tableName); + QString tableName() const; + + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; + + QSqlRecord record() const; + QSqlRecord record(int row) const; + QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; + + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + + bool isDirty() const; + bool isDirty(const QModelIndex &index) const; + + void clear() Q_DECL_OVERRIDE; + + virtual void setEditStrategy(EditStrategy strategy); + EditStrategy editStrategy() const; + + QSqlIndex primaryKey() const; + QSqlDatabase database() const; + int fieldIndex(const QString &fieldName) const; + + void sort(int column, Qt::SortOrder order) Q_DECL_OVERRIDE; + virtual void setSort(int column, Qt::SortOrder order); + + QString filter() const; + virtual void setFilter(const QString &filter); + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + + bool insertRecord(int row, const QSqlRecord &record); + bool setRecord(int row, const QSqlRecord &record); + + virtual void revertRow(int row); + +public Q_SLOTS: + virtual bool select(); + virtual bool selectRow(int row); + + bool submit() Q_DECL_OVERRIDE; + void revert() Q_DECL_OVERRIDE; + + bool submitAll(); + void revertAll(); + +Q_SIGNALS: + void primeInsert(int row, QSqlRecord &record); + + void beforeInsert(QSqlRecord &record); + void beforeUpdate(int row, QSqlRecord &record); + void beforeDelete(int row); + +protected: + QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = Q_NULLPTR, QSqlDatabase db = QSqlDatabase()); + + virtual bool updateRowInTable(int row, const QSqlRecord &values); + virtual bool insertRowIntoTable(const QSqlRecord &values); + virtual bool deleteRowFromTable(int row); + virtual QString orderByClause() const; + virtual QString selectStatement() const; + + void setPrimaryKey(const QSqlIndex &key); + void setQuery(const QSqlQuery &query); + QModelIndex indexInQuery(const QModelIndex &item) const Q_DECL_OVERRIDE; + QSqlRecord primaryValues(int row) const; +}; + +QT_END_NAMESPACE + +#endif // QSQLTABLEMODEL_H From 4b46db8eaa1426dda9f0accb9bfc0a0b1dad8593 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:06:59 -0400 Subject: [PATCH 0946/1324] Update loginsystem.h --- src/qt/loginsystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/loginsystem.h b/src/qt/loginsystem.h index c5227d78..db609690 100644 --- a/src/qt/loginsystem.h +++ b/src/qt/loginsystem.h @@ -3,7 +3,7 @@ #include #include -#include +#include "qsqltablemodel.h" namespace Ui { class LoginSystem; From 3642452988925e7c510223aee0b0b898748b98f5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:07:47 -0400 Subject: [PATCH 0947/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 5b942d42..abcafae8 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -123,7 +123,8 @@ QT_MOC_CPP = \ qt/moc_qcustomplot.cpp \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ - qt/moc_mainwindow.cpp + qt/moc_mainwindow.cpp \ + qt/moc_qsqltablemodel.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -219,7 +220,8 @@ BITCOIN_QT_H = \ qt/qcustomplot.h \ qt/statistics.h \ qt/user.h \ - qt/mainwindow.h + qt/mainwindow.h \ + qt/qsqltablemodel.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -571,7 +573,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/statistics.cpp \ qt/user.cpp \ qt/main.cpp \ - qt/mainwindow.cpp + qt/mainwindow.cpp \ + qt/qsqltablemodel.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 7c6900a56a5bc29da7120d03d6c118c2226942c5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:13:24 -0400 Subject: [PATCH 0948/1324] Update qsqltablemodel.h --- src/qt/qsqltablemodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qsqltablemodel.h b/src/qt/qsqltablemodel.h index d88f195c..9e756037 100644 --- a/src/qt/qsqltablemodel.h +++ b/src/qt/qsqltablemodel.h @@ -40,7 +40,7 @@ #ifndef QSQLTABLEMODEL_H #define QSQLTABLEMODEL_H -#include +#include "qsqldatabase.h" #include QT_BEGIN_NAMESPACE From 7c9f26a782e47e7e49c679deed216cf858fe4946 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:13:46 -0400 Subject: [PATCH 0949/1324] Create qsqldatabase.cpp --- src/qt/qsqldatabase.cpp | 1528 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 1528 insertions(+) create mode 100644 src/qt/qsqldatabase.cpp diff --git a/src/qt/qsqldatabase.cpp b/src/qt/qsqldatabase.cpp new file mode 100644 index 00000000..62e1b6a7 --- /dev/null +++ b/src/qt/qsqldatabase.cpp @@ -0,0 +1,1528 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsqldatabase.h" +#include "qsqlquery.h" + +#ifdef Q_OS_WIN32 +// Conflicting declarations of LPCBYTE in sqlfront.h and winscard.h +#define _WINSCARD_H_ +#endif + +#ifdef QT_SQL_PSQL +#include "../drivers/psql/qsql_psql_p.h" +#endif +#ifdef QT_SQL_MYSQL +#include "../drivers/mysql/qsql_mysql_p.h" +#endif +#ifdef QT_SQL_ODBC +#include "../drivers/odbc/qsql_odbc_p.h" +#endif +#ifdef QT_SQL_OCI +#include "../drivers/oci/qsql_oci_p.h" +#endif +#ifdef QT_SQL_TDS +// conflicting RETCODE typedef between odbc and freetds +#define RETCODE DBRETCODE +#include "../drivers/tds/qsql_tds_p.h" +#undef RETCODE +#endif +#ifdef QT_SQL_DB2 +#include "../drivers/db2/qsql_db2_p.h" +#endif +#ifdef QT_SQL_SQLITE +#include "../drivers/sqlite/qsql_sqlite_p.h" +#endif +#ifdef QT_SQL_SQLITE2 +#include "../drivers/sqlite2/qsql_sqlite2_p.h" +#endif +#ifdef QT_SQL_IBASE +#undef SQL_FLOAT // avoid clash with ODBC +#undef SQL_DOUBLE +#undef SQL_TIMESTAMP +#undef SQL_TYPE_TIME +#undef SQL_TYPE_DATE +#undef SQL_DATE +#define SCHAR IBASE_SCHAR // avoid clash with ODBC (older versions of ibase.h with Firebird) +#include "../drivers/ibase/qsql_ibase_p.h" +#undef SCHAR +#endif + +#include "qdebug.h" +#include "qcoreapplication.h" +#include "qreadwritelock.h" +#include "qsqlresult.h" +#include "qsqldriver.h" +#include "qsqldriverplugin.h" +#include "qsqlindex.h" +#include "private/qfactoryloader_p.h" +#include "private/qsqlnulldriver_p.h" +#include "qmutex.h" +#include "qhash.h" +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QSqlDriverFactoryInterface_iid, + QLatin1String("/sqldrivers"))) + +#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900 +// ### Qt6: remove the #ifdef +const +#endif +char *QSqlDatabase::defaultConnection = const_cast("qt_sql_default_connection"); + +typedef QHash DriverDict; + +class QConnectionDict: public QHash +{ +public: + inline bool contains_ts(const QString &key) + { + QReadLocker locker(&lock); + return contains(key); + } + inline QStringList keys_ts() const + { + QReadLocker locker(&lock); + return keys(); + } + + mutable QReadWriteLock lock; +}; +Q_GLOBAL_STATIC(QConnectionDict, dbDict) + +class QSqlDatabasePrivate +{ +public: + QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = 0): + ref(1), + q(d), + driver(dr), + port(-1) + { + precisionPolicy = QSql::LowPrecisionDouble; + } + QSqlDatabasePrivate(const QSqlDatabasePrivate &other); + ~QSqlDatabasePrivate(); + void init(const QString& type); + void copy(const QSqlDatabasePrivate *other); + void disable(); + + QAtomicInt ref; + QSqlDatabase *q; + QSqlDriver* driver; + QString dbname; + QString uname; + QString pword; + QString hname; + QString drvName; + int port; + QString connOptions; + QString connName; + QSql::NumericalPrecisionPolicy precisionPolicy; + + static QSqlDatabasePrivate *shared_null(); + static QSqlDatabase database(const QString& name, bool open); + static void addDatabase(const QSqlDatabase &db, const QString & name); + static void removeDatabase(const QString& name); + static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn = true); + static DriverDict &driverDict(); + static void cleanConnections(); +}; + +QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref(1) +{ + q = other.q; + dbname = other.dbname; + uname = other.uname; + pword = other.pword; + hname = other.hname; + drvName = other.drvName; + port = other.port; + connOptions = other.connOptions; + driver = other.driver; + precisionPolicy = other.precisionPolicy; +} + +QSqlDatabasePrivate::~QSqlDatabasePrivate() +{ + if (driver != shared_null()->driver) + delete driver; +} + +void QSqlDatabasePrivate::cleanConnections() +{ + QConnectionDict *dict = dbDict(); + Q_ASSERT(dict); + QWriteLocker locker(&dict->lock); + + QConnectionDict::iterator it = dict->begin(); + while (it != dict->end()) { + invalidateDb(it.value(), it.key(), false); + ++it; + } + dict->clear(); +} + +static bool qDriverDictInit = false; +static void cleanDriverDict() +{ + qDeleteAll(QSqlDatabasePrivate::driverDict()); + QSqlDatabasePrivate::driverDict().clear(); + QSqlDatabasePrivate::cleanConnections(); + qDriverDictInit = false; +} + +DriverDict &QSqlDatabasePrivate::driverDict() +{ + static DriverDict dict; + if (!qDriverDictInit) { + qDriverDictInit = true; + qAddPostRoutine(cleanDriverDict); + } + return dict; +} + +QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null() +{ + static QSqlNullDriver dr; + static QSqlDatabasePrivate n(NULL, &dr); + return &n; +} + +void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn) +{ + if (db.d->ref.load() != 1 && doWarn) { + qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, " + "all queries will cease to work.", name.toLocal8Bit().constData()); + db.d->disable(); + db.d->connName.clear(); + } +} + +void QSqlDatabasePrivate::removeDatabase(const QString &name) +{ + QConnectionDict *dict = dbDict(); + Q_ASSERT(dict); + QWriteLocker locker(&dict->lock); + + if (!dict->contains(name)) + return; + + invalidateDb(dict->take(name), name); +} + +void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &name) +{ + QConnectionDict *dict = dbDict(); + Q_ASSERT(dict); + QWriteLocker locker(&dict->lock); + + if (dict->contains(name)) { + invalidateDb(dict->take(name), name); + qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old " + "connection removed.", name.toLocal8Bit().data()); + } + dict->insert(name, db); + db.d->connName = name; +} + +/*! \internal +*/ +QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open) +{ + const QConnectionDict *dict = dbDict(); + Q_ASSERT(dict); + + dict->lock.lockForRead(); + QSqlDatabase db = dict->value(name); + dict->lock.unlock(); + if (db.isValid() && !db.isOpen() && open) { + if (!db.open()) + qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text(); + + } + return db; +} + + +/*! \internal + Copies the connection data from \a other. +*/ +void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other) +{ + q = other->q; + dbname = other->dbname; + uname = other->uname; + pword = other->pword; + hname = other->hname; + drvName = other->drvName; + port = other->port; + connOptions = other->connOptions; + precisionPolicy = other->precisionPolicy; +} + +void QSqlDatabasePrivate::disable() +{ + if (driver != shared_null()->driver) { + delete driver; + driver = shared_null()->driver; + } +} + +/*! + \class QSqlDriverCreatorBase + \brief The QSqlDriverCreatorBase class is the base class for + SQL driver factories. + + \ingroup database + \inmodule QtSql + + Reimplement createObject() to return an instance of the specific + QSqlDriver subclass that you want to provide. + + See QSqlDatabase::registerSqlDriver() for details. + + \sa QSqlDriverCreator +*/ + +/*! + \fn QSqlDriverCreatorBase::~QSqlDriverCreatorBase() + + Destroys the SQL driver creator object. +*/ + +/*! + \fn QSqlDriver *QSqlDriverCreatorBase::createObject() const + + Reimplement this function to returns a new instance of a + QSqlDriver subclass. +*/ + +/*! + \class QSqlDriverCreator + \brief The QSqlDriverCreator class is a template class that + provides a SQL driver factory for a specific driver type. + + \ingroup database + \inmodule QtSql + + QSqlDriverCreator instantiates objects of type T, where T is a + QSqlDriver subclass. + + See QSqlDatabase::registerSqlDriver() for details. +*/ + +/*! + \fn QSqlDriver *QSqlDriverCreator::createObject() const + \reimp +*/ + +/*! + \class QSqlDatabase + \brief The QSqlDatabase class represents a connection to + a database. + + \ingroup database + + \inmodule QtSql + + The QSqlDatabase class provides an interface for accessing a + database through a connection. An instance of QSqlDatabase + represents the connection. The connection provides access to the + database via one of the \l{SQL Database Drivers#Supported + Databases} {supported database drivers}, which are derived from + QSqlDriver. Alternatively, you can subclass your own database + driver from QSqlDriver. See \l{How to Write Your Own Database + Driver} for more information. + + Create a connection (i.e., an instance of QSqlDatabase) by calling + one of the static addDatabase() functions, where you specify + \l{SQL Database Drivers#Supported Databases} {the driver or type + of driver} to use (i.e., what kind of database will you access?) + and a connection name. A connection is known by its own name, + \e{not} by the name of the database it connects to. You can have + multiple connections to one database. QSqlDatabase also supports + the concept of a \e{default} connection, which is the unnamed + connection. To create the default connection, don't pass the + connection name argument when you call addDatabase(). + Subsequently, when you call any static member function that takes + the connection name argument, if you don't pass the connection + name argument, the default connection is assumed. The following + snippet shows how to create and open a default connection to a + PostgreSQL database: + + \snippet sqldatabase/sqldatabase.cpp 0 + + Once the QSqlDatabase object has been created, set the connection + parameters with setDatabaseName(), setUserName(), setPassword(), + setHostName(), setPort(), and setConnectOptions(). Then call + open() to activate the physical connection to the database. The + connection is not usable until you open it. + + The connection defined above will be the \e{default} connection, + because we didn't give a connection name to \l{QSqlDatabase::} + {addDatabase()}. Subsequently, you can get the default connection + by calling database() without the connection name argument: + + \snippet sqldatabase/sqldatabase.cpp 1 + + QSqlDatabase is a value class. Changes made to a database + connection via one instance of QSqlDatabase will affect other + instances of QSqlDatabase that represent the same connection. Use + cloneDatabase() to create an independent database connection based + on an existing one. + + If you create multiple database connections, specify a unique + connection name for each one, when you call addDatabase(). Use + database() with a connection name to get that connection. Use + removeDatabase() with a connection name to remove a connection. + QSqlDatabase outputs a warning if you try to remove a connection + referenced by other QSqlDatabase objects. Use contains() to see if + a given connection name is in the list of connections. + + Once a connection is established, you can call tables() to get the + list of tables in the database, call primaryIndex() to get a + table's primary index, and call record() to get meta-information + about a table's fields (e.g., field names). + + \note QSqlDatabase::exec() is deprecated. Use QSqlQuery::exec() + instead. + + If the driver supports transactions, use transaction() to start a + transaction, and commit() or rollback() to complete it. Use + \l{QSqlDriver::} {hasFeature()} to ask if the driver supports + transactions. \note When using transactions, you must start the + transaction before you create your query. + + If an error occurs, lastError() will return information about it. + + Get the names of the available SQL drivers with drivers(). Check + for the presence of a particular driver with isDriverAvailable(). + If you have created your own custom driver, you must register it + with registerSqlDriver(). + + \sa QSqlDriver, QSqlQuery, {Qt SQL}, {Threads and the SQL Module} +*/ + +/*! \fn QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName) + \threadsafe + + Adds a database to the list of database connections using the + driver \a type and the connection name \a connectionName. If + there already exists a database connection called \a + connectionName, that connection is removed. + + The database connection is referred to by \a connectionName. The + newly added database connection is returned. + + If \a type is not available or could not be loaded, isValid() returns \c false. + + If \a connectionName is not specified, the new connection becomes + the default connection for the application, and subsequent calls + to database() without the connection name argument will return the + default connection. If a \a connectionName is provided here, use + database(\a connectionName) to retrieve the connection. + + \warning If you add a connection with the same name as an existing + connection, the new connection replaces the old one. If you call + this function more than once without specifying \a connectionName, + the default connection will be the one replaced. + + Before using the connection, it must be initialized. e.g., call + some or all of setDatabaseName(), setUserName(), setPassword(), + setHostName(), setPort(), and setConnectOptions(), and, finally, + open(). + + \sa database(), removeDatabase(), {Threads and the SQL Module} +*/ +QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName) +{ + QSqlDatabase db(type); + QSqlDatabasePrivate::addDatabase(db, connectionName); + return db; +} + +/*! + \threadsafe + + Returns the database connection called \a connectionName. The + database connection must have been previously added with + addDatabase(). If \a open is true (the default) and the database + connection is not already open it is opened now. If no \a + connectionName is specified the default connection is used. If \a + connectionName does not exist in the list of databases, an invalid + connection is returned. + + \sa isOpen(), {Threads and the SQL Module} +*/ + +QSqlDatabase QSqlDatabase::database(const QString& connectionName, bool open) +{ + return QSqlDatabasePrivate::database(connectionName, open); +} + +/*! + \threadsafe + + Removes the database connection \a connectionName from the list of + database connections. + + \warning There should be no open queries on the database + connection when this function is called, otherwise a resource leak + will occur. + + Example: + + \snippet code/src_sql_kernel_qsqldatabase.cpp 0 + + The correct way to do it: + + \snippet code/src_sql_kernel_qsqldatabase.cpp 1 + + To remove the default connection, which may have been created with a + call to addDatabase() not specifying a connection name, you can + retrieve the default connection name by calling connectionName() on + the database returned by database(). Note that if a default database + hasn't been created an invalid database will be returned. + + \sa database(), connectionName(), {Threads and the SQL Module} +*/ + +void QSqlDatabase::removeDatabase(const QString& connectionName) +{ + QSqlDatabasePrivate::removeDatabase(connectionName); +} + +/*! + Returns a list of all the available database drivers. + + \sa registerSqlDriver() +*/ + +QStringList QSqlDatabase::drivers() +{ + QStringList list; + +#ifdef QT_SQL_PSQL + list << QLatin1String("QPSQL7"); + list << QLatin1String("QPSQL"); +#endif +#ifdef QT_SQL_MYSQL + list << QLatin1String("QMYSQL3"); + list << QLatin1String("QMYSQL"); +#endif +#ifdef QT_SQL_ODBC + list << QLatin1String("QODBC3"); + list << QLatin1String("QODBC"); +#endif +#ifdef QT_SQL_OCI + list << QLatin1String("QOCI8"); + list << QLatin1String("QOCI"); +#endif +#ifdef QT_SQL_TDS + list << QLatin1String("QTDS7"); + list << QLatin1String("QTDS"); +#endif +#ifdef QT_SQL_DB2 + list << QLatin1String("QDB2"); +#endif +#ifdef QT_SQL_SQLITE + list << QLatin1String("QSQLITE"); +#endif +#ifdef QT_SQL_SQLITE2 + list << QLatin1String("QSQLITE2"); +#endif +#ifdef QT_SQL_IBASE + list << QLatin1String("QIBASE"); +#endif + + if (QFactoryLoader *fl = loader()) { + typedef QMultiMap PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + + const PluginKeyMap keyMap = fl->keyMap(); + const PluginKeyMapConstIterator cend = keyMap.constEnd(); + for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) + if (!list.contains(it.value())) + list << it.value(); + } + + DriverDict dict = QSqlDatabasePrivate::driverDict(); + for (DriverDict::const_iterator i = dict.constBegin(); i != dict.constEnd(); ++i) { + if (!list.contains(i.key())) + list << i.key(); + } + + return list; +} + +/*! + This function registers a new SQL driver called \a name, within + the SQL framework. This is useful if you have a custom SQL driver + and don't want to compile it as a plugin. + + Example: + \snippet code/src_sql_kernel_qsqldatabase.cpp 2 + + QSqlDatabase takes ownership of the \a creator pointer, so you + mustn't delete it yourself. + + \sa drivers() +*/ +void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase *creator) +{ + delete QSqlDatabasePrivate::driverDict().take(name); + if (creator) + QSqlDatabasePrivate::driverDict().insert(name, creator); +} + +/*! + \threadsafe + + Returns \c true if the list of database connections contains \a + connectionName; otherwise returns \c false. + + \sa connectionNames(), database(), {Threads and the SQL Module} +*/ + +bool QSqlDatabase::contains(const QString& connectionName) +{ + return dbDict()->contains_ts(connectionName); +} + +/*! + \threadsafe + + Returns a list containing the names of all connections. + + \sa contains(), database(), {Threads and the SQL Module} +*/ +QStringList QSqlDatabase::connectionNames() +{ + return dbDict()->keys_ts(); +} + +/*! + \overload + + Creates a QSqlDatabase connection that uses the driver referred + to by \a type. If the \a type is not recognized, the database + connection will have no functionality. + + The currently available driver types are: + + \table + \header \li Driver Type \li Description + \row \li QDB2 \li IBM DB2 + \row \li QIBASE \li Borland InterBase Driver + \row \li QMYSQL \li MySQL Driver + \row \li QOCI \li Oracle Call Interface Driver + \row \li QODBC \li ODBC Driver (includes Microsoft SQL Server) + \row \li QPSQL \li PostgreSQL Driver + \row \li QSQLITE \li SQLite version 3 or above + \row \li QSQLITE2 \li SQLite version 2 + \row \li QTDS \li Sybase Adaptive Server + \endtable + + Additional third party drivers, including your own custom + drivers, can be loaded dynamically. + + \sa {SQL Database Drivers}, registerSqlDriver(), drivers() +*/ + +QSqlDatabase::QSqlDatabase(const QString &type) +{ + d = new QSqlDatabasePrivate(this); + d->init(type); +} + +/*! + \overload + + Creates a database connection using the given \a driver. +*/ + +QSqlDatabase::QSqlDatabase(QSqlDriver *driver) +{ + d = new QSqlDatabasePrivate(this, driver); +} + +/*! + Creates an empty, invalid QSqlDatabase object. Use addDatabase(), + removeDatabase(), and database() to get valid QSqlDatabase + objects. +*/ +QSqlDatabase::QSqlDatabase() +{ + d = QSqlDatabasePrivate::shared_null(); + d->ref.ref(); +} + +/*! + Creates a copy of \a other. +*/ +QSqlDatabase::QSqlDatabase(const QSqlDatabase &other) +{ + d = other.d; + d->ref.ref(); +} + +/*! + Assigns \a other to this object. +*/ +QSqlDatabase &QSqlDatabase::operator=(const QSqlDatabase &other) +{ + qAtomicAssign(d, other.d); + return *this; +} + +/*! + \internal + + Create the actual driver instance \a type. +*/ + +void QSqlDatabasePrivate::init(const QString &type) +{ + drvName = type; + + if (!driver) { +#ifdef QT_SQL_PSQL + if (type == QLatin1String("QPSQL") || type == QLatin1String("QPSQL7")) + driver = new QPSQLDriver(); +#endif +#ifdef QT_SQL_MYSQL + if (type == QLatin1String("QMYSQL") || type == QLatin1String("QMYSQL3")) + driver = new QMYSQLDriver(); +#endif +#ifdef QT_SQL_ODBC + if (type == QLatin1String("QODBC") || type == QLatin1String("QODBC3")) + driver = new QODBCDriver(); +#endif +#ifdef QT_SQL_OCI + if (type == QLatin1String("QOCI") || type == QLatin1String("QOCI8")) + driver = new QOCIDriver(); +#endif +#ifdef QT_SQL_TDS + if (type == QLatin1String("QTDS") || type == QLatin1String("QTDS7")) + driver = new QTDSDriver(); +#endif +#ifdef QT_SQL_DB2 + if (type == QLatin1String("QDB2")) + driver = new QDB2Driver(); +#endif +#ifdef QT_SQL_SQLITE + if (type == QLatin1String("QSQLITE")) + driver = new QSQLiteDriver(); +#endif +#ifdef QT_SQL_SQLITE2 + if (type == QLatin1String("QSQLITE2")) + driver = new QSQLite2Driver(); +#endif +#ifdef QT_SQL_IBASE + if (type == QLatin1String("QIBASE")) + driver = new QIBaseDriver(); +#endif + } + + if (!driver) { + DriverDict dict = QSqlDatabasePrivate::driverDict(); + for (DriverDict::const_iterator it = dict.constBegin(); + it != dict.constEnd() && !driver; ++it) { + if (type == it.key()) { + driver = ((QSqlDriverCreatorBase*)(*it))->createObject(); + } + } + } + + if (!driver && loader()) + driver = qLoadPlugin(loader(), type); + + if (!driver) { + qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data()); + qWarning("QSqlDatabase: available drivers: %s", + QSqlDatabase::drivers().join(QLatin1Char(' ')).toLatin1().data()); + if (QCoreApplication::instance() == 0) + qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins"); + driver = shared_null()->driver; + } +} + +/*! + Destroys the object and frees any allocated resources. + + \sa close() +*/ + +QSqlDatabase::~QSqlDatabase() +{ + if (!d->ref.deref()) { + close(); + delete d; + } +} + +/*! + Executes a SQL statement on the database and returns a QSqlQuery + object. Use lastError() to retrieve error information. If \a + query is empty, an empty, invalid query is returned and + lastError() is not affected. + + \sa QSqlQuery, lastError() +*/ + +QSqlQuery QSqlDatabase::exec(const QString & query) const +{ + QSqlQuery r(d->driver->createResult()); + if (!query.isEmpty()) { + r.exec(query); + d->driver->setLastError(r.lastError()); + } + return r; +} + +/*! + Opens the database connection using the current connection + values. Returns \c true on success; otherwise returns \c false. Error + information can be retrieved using lastError(). + + \sa lastError(), setDatabaseName(), setUserName(), setPassword(), + setHostName(), setPort(), setConnectOptions() +*/ + +bool QSqlDatabase::open() +{ + return d->driver->open(d->dbname, d->uname, d->pword, d->hname, + d->port, d->connOptions); +} + +/*! + \overload + + Opens the database connection using the given \a user name and \a + password. Returns \c true on success; otherwise returns \c false. Error + information can be retrieved using the lastError() function. + + This function does not store the password it is given. Instead, + the password is passed directly to the driver for opening the + connection and it is then discarded. + + \sa lastError() +*/ + +bool QSqlDatabase::open(const QString& user, const QString& password) +{ + setUserName(user); + return d->driver->open(d->dbname, user, password, d->hname, + d->port, d->connOptions); +} + +/*! + Closes the database connection, freeing any resources acquired, and + invalidating any existing QSqlQuery objects that are used with the + database. + + This will also affect copies of this QSqlDatabase object. + + \sa removeDatabase() +*/ + +void QSqlDatabase::close() +{ + d->driver->close(); +} + +/*! + Returns \c true if the database connection is currently open; + otherwise returns \c false. +*/ + +bool QSqlDatabase::isOpen() const +{ + return d->driver->isOpen(); +} + +/*! + Returns \c true if there was an error opening the database + connection; otherwise returns \c false. Error information can be + retrieved using the lastError() function. +*/ + +bool QSqlDatabase::isOpenError() const +{ + return d->driver->isOpenError(); +} + +/*! + Begins a transaction on the database if the driver supports + transactions. Returns \c{true} if the operation succeeded. + Otherwise it returns \c{false}. + + \sa QSqlDriver::hasFeature(), commit(), rollback() +*/ +bool QSqlDatabase::transaction() +{ + if (!d->driver->hasFeature(QSqlDriver::Transactions)) + return false; + return d->driver->beginTransaction(); +} + +/*! + Commits a transaction to the database if the driver supports + transactions and a transaction() has been started. Returns \c{true} + if the operation succeeded. Otherwise it returns \c{false}. + + \note For some databases, the commit will fail and return \c{false} + if there is an \l{QSqlQuery::isActive()} {active query} using the + database for a \c{SELECT}. Make the query \l{QSqlQuery::isActive()} + {inactive} before doing the commit. + + Call lastError() to get information about errors. + + \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), rollback() +*/ +bool QSqlDatabase::commit() +{ + if (!d->driver->hasFeature(QSqlDriver::Transactions)) + return false; + return d->driver->commitTransaction(); +} + +/*! + Rolls back a transaction on the database, if the driver supports + transactions and a transaction() has been started. Returns \c{true} + if the operation succeeded. Otherwise it returns \c{false}. + + \note For some databases, the rollback will fail and return + \c{false} if there is an \l{QSqlQuery::isActive()} {active query} + using the database for a \c{SELECT}. Make the query + \l{QSqlQuery::isActive()} {inactive} before doing the rollback. + + Call lastError() to get information about errors. + + \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), commit() +*/ +bool QSqlDatabase::rollback() +{ + if (!d->driver->hasFeature(QSqlDriver::Transactions)) + return false; + return d->driver->rollbackTransaction(); +} + +/*! + Sets the connection's database name to \a name. To have effect, + the database name must be set \e{before} the connection is + \l{open()} {opened}. Alternatively, you can close() the + connection, set the database name, and call open() again. \note + The \e{database name} is not the \e{connection name}. The + connection name must be passed to addDatabase() at connection + object create time. + + For the QOCI (Oracle) driver, the database name is the TNS + Service Name. + + For the QODBC driver, the \a name can either be a DSN, a DSN + filename (in which case the file must have a \c .dsn extension), + or a connection string. + + For example, Microsoft Access users can use the following + connection string to open an \c .mdb file directly, instead of + having to create a DSN entry in the ODBC manager: + + \snippet code/src_sql_kernel_qsqldatabase.cpp 3 + + There is no default value. + + \sa databaseName(), setUserName(), setPassword(), setHostName(), + setPort(), setConnectOptions(), open() +*/ + +void QSqlDatabase::setDatabaseName(const QString& name) +{ + if (isValid()) + d->dbname = name; +} + +/*! + Sets the connection's user name to \a name. To have effect, the + user name must be set \e{before} the connection is \l{open()} + {opened}. Alternatively, you can close() the connection, set the + user name, and call open() again. + + There is no default value. + + \sa userName(), setDatabaseName(), setPassword(), setHostName(), + setPort(), setConnectOptions(), open() +*/ + +void QSqlDatabase::setUserName(const QString& name) +{ + if (isValid()) + d->uname = name; +} + +/*! + Sets the connection's password to \a password. To have effect, the + password must be set \e{before} the connection is \l{open()} + {opened}. Alternatively, you can close() the connection, set the + password, and call open() again. + + There is no default value. + + \warning This function stores the password in plain text within + Qt. Use the open() call that takes a password as parameter to + avoid this behavior. + + \sa password(), setUserName(), setDatabaseName(), setHostName(), + setPort(), setConnectOptions(), open() +*/ + +void QSqlDatabase::setPassword(const QString& password) +{ + if (isValid()) + d->pword = password; +} + +/*! + Sets the connection's host name to \a host. To have effect, the + host name must be set \e{before} the connection is \l{open()} + {opened}. Alternatively, you can close() the connection, set the + host name, and call open() again. + + There is no default value. + + \sa hostName(), setUserName(), setPassword(), setDatabaseName(), + setPort(), setConnectOptions(), open() +*/ + +void QSqlDatabase::setHostName(const QString& host) +{ + if (isValid()) + d->hname = host; +} + +/*! + Sets the connection's port number to \a port. To have effect, the + port number must be set \e{before} the connection is \l{open()} + {opened}. Alternatively, you can close() the connection, set the + port number, and call open() again.. + + There is no default value. + + \sa port(), setUserName(), setPassword(), setHostName(), + setDatabaseName(), setConnectOptions(), open() +*/ + +void QSqlDatabase::setPort(int port) +{ + if (isValid()) + d->port = port; +} + +/*! + Returns the connection's database name, which may be empty. + \note The database name is not the connection name. + + \sa setDatabaseName() +*/ +QString QSqlDatabase::databaseName() const +{ + return d->dbname; +} + +/*! + Returns the connection's user name; it may be empty. + + \sa setUserName() +*/ +QString QSqlDatabase::userName() const +{ + return d->uname; +} + +/*! + Returns the connection's password. If the password was not set + with setPassword(), and if the password was given in the open() + call, or if no password was used, an empty string is returned. +*/ +QString QSqlDatabase::password() const +{ + return d->pword; +} + +/*! + Returns the connection's host name; it may be empty. + + \sa setHostName() +*/ +QString QSqlDatabase::hostName() const +{ + return d->hname; +} + +/*! + Returns the connection's driver name. + + \sa addDatabase(), driver() +*/ +QString QSqlDatabase::driverName() const +{ + return d->drvName; +} + +/*! + Returns the connection's port number. The value is undefined if + the port number has not been set. + + \sa setPort() +*/ +int QSqlDatabase::port() const +{ + return d->port; +} + +/*! + Returns the database driver used to access the database + connection. + + \sa addDatabase(), drivers() +*/ + +QSqlDriver* QSqlDatabase::driver() const +{ + return d->driver; +} + +/*! + Returns information about the last error that occurred on the + database. + + Failures that occur in conjunction with an individual query are + reported by QSqlQuery::lastError(). + + \sa QSqlError, QSqlQuery::lastError() +*/ + +QSqlError QSqlDatabase::lastError() const +{ + return d->driver->lastError(); +} + + +/*! + Returns a list of the database's tables, system tables and views, + as specified by the parameter \a type. + + \sa primaryIndex(), record() +*/ + +QStringList QSqlDatabase::tables(QSql::TableType type) const +{ + return d->driver->tables(type); +} + +/*! + Returns the primary index for table \a tablename. If no primary + index exists an empty QSqlIndex is returned. + + \sa tables(), record() +*/ + +QSqlIndex QSqlDatabase::primaryIndex(const QString& tablename) const +{ + return d->driver->primaryIndex(tablename); +} + + +/*! + Returns a QSqlRecord populated with the names of all the fields in + the table (or view) called \a tablename. The order in which the + fields appear in the record is undefined. If no such table (or + view) exists, an empty record is returned. +*/ + +QSqlRecord QSqlDatabase::record(const QString& tablename) const +{ + return d->driver->record(tablename); +} + + +/*! + Sets database-specific \a options. This must be done before the + connection is opened or it has no effect (or you can close() the + connection, call this function and open() the connection again). + + The format of the \a options string is a semicolon separated list + of option names or option=value pairs. The options depend on the + database client used: + + \table + \header \li ODBC \li MySQL \li PostgreSQL + \row + + \li + \list + \li SQL_ATTR_ACCESS_MODE + \li SQL_ATTR_LOGIN_TIMEOUT + \li SQL_ATTR_CONNECTION_TIMEOUT + \li SQL_ATTR_CURRENT_CATALOG + \li SQL_ATTR_METADATA_ID + \li SQL_ATTR_PACKET_SIZE + \li SQL_ATTR_TRACEFILE + \li SQL_ATTR_TRACE + \li SQL_ATTR_CONNECTION_POOLING + \li SQL_ATTR_ODBC_VERSION + \endlist + + \li + \list + \li CLIENT_COMPRESS + \li CLIENT_FOUND_ROWS + \li CLIENT_IGNORE_SPACE + \li CLIENT_ODBC + \li CLIENT_NO_SCHEMA + \li CLIENT_INTERACTIVE + \li UNIX_SOCKET + \li MYSQL_OPT_RECONNECT + \li MYSQL_OPT_CONNECT_TIMEOUT + \li MYSQL_OPT_READ_TIMEOUT + \li MYSQL_OPT_WRITE_TIMEOUT + \li SSL_KEY + \li SSL_CERT + \li SSL_CA + \li SSL_CAPATH + \li SSL_CIPHER + \endlist + + \li + \list + \li connect_timeout + \li options + \li tty + \li requiressl + \li service + \endlist + + \header \li DB2 \li OCI \li TDS + \row + + \li + \list + \li SQL_ATTR_ACCESS_MODE + \li SQL_ATTR_LOGIN_TIMEOUT + \endlist + + \li + \list + \li OCI_ATTR_PREFETCH_ROWS + \li OCI_ATTR_PREFETCH_MEMORY + \endlist + + \li + \e none + + \header \li SQLite \li Interbase + \row + + \li + \list + \li QSQLITE_BUSY_TIMEOUT + \li QSQLITE_OPEN_READONLY + \li QSQLITE_OPEN_URI + \li QSQLITE_ENABLE_SHARED_CACHE + \endlist + + \li + \list + \li ISC_DPB_LC_CTYPE + \li ISC_DPB_SQL_ROLE_NAME + \endlist + + \endtable + + Examples: + \snippet code/src_sql_kernel_qsqldatabase.cpp 4 + + Refer to the client library documentation for more information + about the different options. + + \sa connectOptions() +*/ + +void QSqlDatabase::setConnectOptions(const QString &options) +{ + if (isValid()) + d->connOptions = options; +} + +/*! + Returns the connection options string used for this connection. + The string may be empty. + + \sa setConnectOptions() + */ +QString QSqlDatabase::connectOptions() const +{ + return d->connOptions; +} + +/*! + Returns \c true if a driver called \a name is available; otherwise + returns \c false. + + \sa drivers() +*/ + +bool QSqlDatabase::isDriverAvailable(const QString& name) +{ + return drivers().contains(name); +} + +/*! \fn QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName) + + This overload is useful when you want to create a database + connection with a \l{QSqlDriver} {driver} you instantiated + yourself. It might be your own database driver, or you might just + need to instantiate one of the Qt drivers yourself. If you do + this, it is recommended that you include the driver code in your + application. For example, you can create a PostgreSQL connection + with your own QPSQL driver like this: + + \snippet code/src_sql_kernel_qsqldatabase.cpp 5 + \codeline + \snippet code/src_sql_kernel_qsqldatabase.cpp 6 + + The above code sets up a PostgreSQL connection and instantiates a + QPSQLDriver object. Next, addDatabase() is called to add the + connection to the known connections so that it can be used by the + Qt SQL classes. When a driver is instantiated with a connection + handle (or set of handles), Qt assumes that you have already + opened the database connection. + + \note We assume that \c qtdir is the directory where Qt is + installed. This will pull in the code that is needed to use the + PostgreSQL client library and to instantiate a QPSQLDriver object, + assuming that you have the PostgreSQL headers somewhere in your + include search path. + + Remember that you must link your application against the database + client library. Make sure the client library is in your linker's + search path, and add lines like these to your \c{.pro} file: + + \snippet code/src_sql_kernel_qsqldatabase.cpp 7 + + The method described works for all the supplied drivers. The only + difference will be in the driver constructor arguments. Here is a + table of the drivers included with Qt, their source code files, + and their constructor arguments: + + \table + \header \li Driver \li Class name \li Constructor arguments \li File to include + \row + \li QPSQL + \li QPSQLDriver + \li PGconn *connection + \li \c qsql_psql.cpp + \row + \li QMYSQL + \li QMYSQLDriver + \li MYSQL *connection + \li \c qsql_mysql.cpp + \row + \li QOCI + \li QOCIDriver + \li OCIEnv *environment, OCISvcCtx *serviceContext + \li \c qsql_oci.cpp + \row + \li QODBC + \li QODBCDriver + \li SQLHANDLE environment, SQLHANDLE connection + \li \c qsql_odbc.cpp + \row + \li QDB2 + \li QDB2 + \li SQLHANDLE environment, SQLHANDLE connection + \li \c qsql_db2.cpp + \row + \li QTDS + \li QTDSDriver + \li LOGINREC *loginRecord, DBPROCESS *dbProcess, const QString &hostName + \li \c qsql_tds.cpp + \row + \li QSQLITE + \li QSQLiteDriver + \li sqlite *connection + \li \c qsql_sqlite.cpp + \row + \li QIBASE + \li QIBaseDriver + \li isc_db_handle connection + \li \c qsql_ibase.cpp + \endtable + + The host name (or service name) is needed when constructing the + QTDSDriver for creating new connections for internal queries. This + is to prevent blocking when several QSqlQuery objects are used + simultaneously. + + \warning Adding a database connection with the same connection + name as an existing connection, causes the existing connection to + be replaced by the new one. + + \warning The SQL framework takes ownership of the \a driver. It + must not be deleted. To remove the connection, use + removeDatabase(). + + \sa drivers() +*/ +QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName) +{ + QSqlDatabase db(driver); + QSqlDatabasePrivate::addDatabase(db, connectionName); + return db; +} + +/*! + Returns \c true if the QSqlDatabase has a valid driver. + + Example: + \snippet code/src_sql_kernel_qsqldatabase.cpp 8 +*/ +bool QSqlDatabase::isValid() const +{ + return d->driver && d->driver != d->shared_null()->driver; +} + +/*! + Clones the database connection \a other and stores it as \a + connectionName. All the settings from the original database, e.g. + databaseName(), hostName(), etc., are copied across. Does nothing + if \a other is an invalid database. Returns the newly created + database connection. + + \note The new connection has not been opened. Before using the new + connection, you must call open(). +*/ +QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QString &connectionName) +{ + if (!other.isValid()) + return QSqlDatabase(); + + QSqlDatabase db(other.driverName()); + db.d->copy(other.d); + QSqlDatabasePrivate::addDatabase(db, connectionName); + return db; +} + +/*! + \since 4.4 + + Returns the connection name, which may be empty. \note The + connection name is not the \l{databaseName()} {database name}. + + \sa addDatabase() +*/ +QString QSqlDatabase::connectionName() const +{ + return d->connName; +} + +/*! + \since 4.6 + + Sets the default numerical precision policy used by queries created + on this database connection to \a precisionPolicy. + + Note: Drivers that don't support fetching numerical values with low + precision will ignore the precision policy. You can use + QSqlDriver::hasFeature() to find out whether a driver supports this + feature. + + Note: Setting the default precision policy to \a precisionPolicy + doesn't affect any currently active queries. + + \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(), + QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy() +*/ +void QSqlDatabase::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) +{ + if(driver()) + driver()->setNumericalPrecisionPolicy(precisionPolicy); + d->precisionPolicy = precisionPolicy; +} + +/*! + \since 4.6 + + Returns the current default precision policy for the database connection. + + \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(), + QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy() +*/ +QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy() const +{ + if(driver()) + return driver()->numericalPrecisionPolicy(); + else + return d->precisionPolicy; +} + + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QSqlDatabase &d) +{ + QDebugStateSaver saver(dbg); + dbg.nospace(); + dbg.noquote(); + if (!d.isValid()) { + dbg << "QSqlDatabase(invalid)"; + return dbg; + } + + dbg << "QSqlDatabase(driver=\"" << d.driverName() << "\", database=\"" + << d.databaseName() << "\", host=\"" << d.hostName() << "\", port=" << d.port() + << ", user=\"" << d.userName() << "\", open=" << d.isOpen() << ')'; + return dbg; +} +#endif + +QT_END_NAMESPACE From 45565170746a970a2984e3f46e6388a4d6fb1588 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:14:39 -0400 Subject: [PATCH 0950/1324] Create qsldatabase.h --- src/qt/qsldatabase.h | 150 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/qt/qsldatabase.h diff --git a/src/qt/qsldatabase.h b/src/qt/qsldatabase.h new file mode 100644 index 00000000..ad071a69 --- /dev/null +++ b/src/qt/qsldatabase.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLDATABASE_H +#define QSQLDATABASE_H + +#include +#include + +QT_BEGIN_NAMESPACE + + +class QSqlError; +class QSqlDriver; +class QSqlIndex; +class QSqlRecord; +class QSqlQuery; +class QSqlDatabasePrivate; + +class Q_SQL_EXPORT QSqlDriverCreatorBase +{ +public: + virtual ~QSqlDriverCreatorBase() {} + virtual QSqlDriver *createObject() const = 0; +}; + +template +class QSqlDriverCreator : public QSqlDriverCreatorBase +{ +public: + QSqlDriver *createObject() const Q_DECL_OVERRIDE { return new T; } +}; + +class Q_SQL_EXPORT QSqlDatabase +{ +public: + QSqlDatabase(); + QSqlDatabase(const QSqlDatabase &other); + ~QSqlDatabase(); + + QSqlDatabase &operator=(const QSqlDatabase &other); + + bool open(); + bool open(const QString& user, const QString& password); + void close(); + bool isOpen() const; + bool isOpenError() const; + QStringList tables(QSql::TableType type = QSql::Tables) const; + QSqlIndex primaryIndex(const QString& tablename) const; + QSqlRecord record(const QString& tablename) const; + QSqlQuery exec(const QString& query = QString()) const; + QSqlError lastError() const; + bool isValid() const; + + bool transaction(); + bool commit(); + bool rollback(); + + void setDatabaseName(const QString& name); + void setUserName(const QString& name); + void setPassword(const QString& password); + void setHostName(const QString& host); + void setPort(int p); + void setConnectOptions(const QString& options = QString()); + QString databaseName() const; + QString userName() const; + QString password() const; + QString hostName() const; + QString driverName() const; + int port() const; + QString connectOptions() const; + QString connectionName() const; + void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); + QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; + + QSqlDriver* driver() const; + + static +#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900 + // ### Qt6: remove the #ifdef + const +#endif + char *defaultConnection; + + static QSqlDatabase addDatabase(const QString& type, + const QString& connectionName = QLatin1String(defaultConnection)); + static QSqlDatabase addDatabase(QSqlDriver* driver, + const QString& connectionName = QLatin1String(defaultConnection)); + static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName); + static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection), + bool open = true); + static void removeDatabase(const QString& connectionName); + static bool contains(const QString& connectionName = QLatin1String(defaultConnection)); + static QStringList drivers(); + static QStringList connectionNames(); + static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator); + static bool isDriverAvailable(const QString &name); + +protected: + explicit QSqlDatabase(const QString& type); + explicit QSqlDatabase(QSqlDriver* driver); + +private: + friend class QSqlDatabasePrivate; + QSqlDatabasePrivate *d; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &); +#endif + +QT_END_NAMESPACE + +#endif // QSQLDATABASE_H From d54722e48bbb71fd9f3b63fcea1086e802d0c35d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:15:35 -0400 Subject: [PATCH 0951/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index abcafae8..ba5ee9dc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -124,7 +124,8 @@ QT_MOC_CPP = \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ qt/moc_mainwindow.cpp \ - qt/moc_qsqltablemodel.cpp + qt/moc_qsqltablemodel.cpp \ + qt/moc_qsqldatabase.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -221,7 +222,8 @@ BITCOIN_QT_H = \ qt/statistics.h \ qt/user.h \ qt/mainwindow.h \ - qt/qsqltablemodel.h + qt/qsqltablemodel.h \ + qt/qsqldatabase.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -574,7 +576,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/user.cpp \ qt/main.cpp \ qt/mainwindow.cpp \ - qt/qsqltablemodel.cpp + qt/qsqltablemodel.cpp \ + qt/qsqldatabase.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 33b6dbb31e7ed01f840a748b1ccd65b3d0731ed2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:19:24 -0400 Subject: [PATCH 0952/1324] Rename qsldatabase.h to qsqldatabase.h --- src/qt/{qsldatabase.h => qsqldatabase.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{qsldatabase.h => qsqldatabase.h} (100%) diff --git a/src/qt/qsldatabase.h b/src/qt/qsqldatabase.h similarity index 100% rename from src/qt/qsldatabase.h rename to src/qt/qsqldatabase.h From 932f9b41221fb5dbf7cc22285cf4554e764f68df Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:20:36 -0400 Subject: [PATCH 0953/1324] Create qsql.h --- src/qt/qsql.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/qt/qsql.h diff --git a/src/qt/qsql.h b/src/qt/qsql.h new file mode 100644 index 00000000..02ebae7a --- /dev/null +++ b/src/qt/qsql.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQL_H +#define QSQL_H + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_SQL_LIB) +# define Q_SQL_EXPORT Q_DECL_EXPORT +# else +# define Q_SQL_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_SQL_EXPORT +#endif + +namespace QSql +{ + enum Location + { + BeforeFirstRow = -1, + AfterLastRow = -2 + }; + + enum ParamTypeFlag + { + In = 0x00000001, + Out = 0x00000002, + InOut = In | Out, + Binary = 0x00000004 + }; + Q_DECLARE_FLAGS(ParamType, ParamTypeFlag) + + enum TableType + { + Tables = 0x01, + SystemTables = 0x02, + Views = 0x04, + AllTables = 0xff + }; + + enum NumericalPrecisionPolicy + { + LowPrecisionInt32 = 0x01, + LowPrecisionInt64 = 0x02, + LowPrecisionDouble = 0x04, + + HighPrecision = 0 + }; +} + +Q_DECLARE_OPERATORS_FOR_FLAGS(QSql::ParamType) + +QT_END_NAMESPACE + +#endif // QSQL_H From 7c54b8a8dce0a077d51e22313b8b0e99171120a2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:21:09 -0400 Subject: [PATCH 0954/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index ba5ee9dc..ec268932 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -223,7 +223,8 @@ BITCOIN_QT_H = \ qt/user.h \ qt/mainwindow.h \ qt/qsqltablemodel.h \ - qt/qsqldatabase.h + qt/qsqldatabase.h \ + qt/qsql.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ From 6f7cadb8890e7cee8bf7f586687bff56ac51ccfe Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:21:44 -0400 Subject: [PATCH 0955/1324] Update qsqldatabase.h --- src/qt/qsqldatabase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qsqldatabase.h b/src/qt/qsqldatabase.h index ad071a69..9c0e5a57 100644 --- a/src/qt/qsqldatabase.h +++ b/src/qt/qsqldatabase.h @@ -41,7 +41,7 @@ #define QSQLDATABASE_H #include -#include +#include "qsql.h" QT_BEGIN_NAMESPACE From 817932d6559702d2147c0ba7f0a5356015024535 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:24:45 -0400 Subject: [PATCH 0956/1324] Create qsqlquerymodel.cpp --- src/qt/qsqlquerymodel.cpp | 680 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 680 insertions(+) create mode 100644 src/qt/qsqlquerymodel.cpp diff --git a/src/qt/qsqlquerymodel.cpp b/src/qt/qsqlquerymodel.cpp new file mode 100644 index 00000000..864c5b99 --- /dev/null +++ b/src/qt/qsqlquerymodel.cpp @@ -0,0 +1,680 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsqlquerymodel.h" +#include "qsqlquerymodel_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +#define QSQL_PREFETCH 255 + +void QSqlQueryModelPrivate::prefetch(int limit) +{ + Q_Q(QSqlQueryModel); + + if (atEnd || limit <= bottom.row() || bottom.column() == -1) + return; + + QModelIndex newBottom; + const int oldBottomRow = qMax(bottom.row(), 0); + + // try to seek directly + if (query.seek(limit)) { + newBottom = q->createIndex(limit, bottom.column()); + } else { + // have to seek back to our old position for MS Access + int i = oldBottomRow; + if (query.seek(i)) { + while (query.next()) + ++i; + newBottom = q->createIndex(i, bottom.column()); + } else { + // empty or invalid query + newBottom = q->createIndex(-1, bottom.column()); + } + atEnd = true; // this is the end. + } + if (newBottom.row() >= 0 && newBottom.row() > bottom.row()) { + q->beginInsertRows(QModelIndex(), bottom.row() + 1, newBottom.row()); + bottom = newBottom; + q->endInsertRows(); + } else { + bottom = newBottom; + } +} + +QSqlQueryModelPrivate::~QSqlQueryModelPrivate() +{ +} + +void QSqlQueryModelPrivate::initColOffsets(int size) +{ + colOffsets.resize(size); + memset(colOffsets.data(), 0, colOffsets.size() * sizeof(int)); +} + +int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const +{ + if (modelColumn < 0 || modelColumn >= rec.count() || !rec.isGenerated(modelColumn) || modelColumn >= colOffsets.size()) + return -1; + return modelColumn - colOffsets[modelColumn]; +} + +/*! + \class QSqlQueryModel + \brief The QSqlQueryModel class provides a read-only data model for SQL + result sets. + + \ingroup database + \inmodule QtSql + + QSqlQueryModel is a high-level interface for executing SQL + statements and traversing the result set. It is built on top of + the lower-level QSqlQuery and can be used to provide data to + view classes such as QTableView. For example: + + \snippet sqldatabase/sqldatabase.cpp 16 + + We set the model's query, then we set up the labels displayed in + the view header. + + QSqlQueryModel can also be used to access a database + programmatically, without binding it to a view: + + \snippet sqldatabase/sqldatabase.cpp 21 + + The code snippet above extracts the \c salary field from record 4 in + the result set of the query \c{SELECT * from employee}. Assuming + that \c salary is column 2, we can rewrite the last line as follows: + + \snippet sqldatabase/sqldatabase.cpp 22 + + The model is read-only by default. To make it read-write, you + must subclass it and reimplement setData() and flags(). Another + option is to use QSqlTableModel, which provides a read-write + model based on a single database table. + + The \l{querymodel} example illustrates how to use + QSqlQueryModel to display the result of a query. It also shows + how to subclass QSqlQueryModel to customize the contents of the + data before showing it to the user, and how to create a + read-write model based on QSqlQueryModel. + + If the database doesn't return the number of selected rows in + a query, the model will fetch rows incrementally. + See fetchMore() for more information. + + \sa QSqlTableModel, QSqlRelationalTableModel, QSqlQuery, + {Model/View Programming}, {Query Model Example} +*/ + +/*! + Creates an empty QSqlQueryModel with the given \a parent. + */ +QSqlQueryModel::QSqlQueryModel(QObject *parent) + : QAbstractTableModel(*new QSqlQueryModelPrivate, parent) +{ +} + +/*! \internal + */ +QSqlQueryModel::QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent) + : QAbstractTableModel(dd, parent) +{ +} + +/*! + Destroys the object and frees any allocated resources. + + \sa clear() +*/ +QSqlQueryModel::~QSqlQueryModel() +{ +} + +/*! + \since 4.1 + + Fetches more rows from a database. + This only affects databases that don't report back the size of a query + (see QSqlDriver::hasFeature()). + + To force fetching of the entire result set, you can use the following: + + \snippet code/src_sql_models_qsqlquerymodel.cpp 0 + + \a parent should always be an invalid QModelIndex. + + \sa canFetchMore() +*/ +void QSqlQueryModel::fetchMore(const QModelIndex &parent) +{ + Q_D(QSqlQueryModel); + if (parent.isValid()) + return; + d->prefetch(qMax(d->bottom.row(), 0) + QSQL_PREFETCH); +} + +/*! + \since 4.1 + + Returns \c true if it is possible to read more rows from the database. + This only affects databases that don't report back the size of a query + (see QSqlDriver::hasFeature()). + + \a parent should always be an invalid QModelIndex. + + \sa fetchMore() + */ +bool QSqlQueryModel::canFetchMore(const QModelIndex &parent) const +{ + Q_D(const QSqlQueryModel); + return (!parent.isValid() && !d->atEnd); +} + +/*! \internal + */ +void QSqlQueryModel::beginInsertRows(const QModelIndex &parent, int first, int last) +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::beginInsertRows(parent, first, last); +} + +/*! \internal + */ +void QSqlQueryModel::endInsertRows() +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::endInsertRows(); +} + +/*! \internal + */ +void QSqlQueryModel::beginRemoveRows(const QModelIndex &parent, int first, int last) +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::beginRemoveRows(parent, first, last); +} + +/*! \internal + */ +void QSqlQueryModel::endRemoveRows() +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::endRemoveRows(); +} + +/*! \internal + */ +void QSqlQueryModel::beginInsertColumns(const QModelIndex &parent, int first, int last) +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::beginInsertColumns(parent, first, last); +} + +/*! \internal + */ +void QSqlQueryModel::endInsertColumns() +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::endInsertColumns(); +} + +/*! \internal + */ +void QSqlQueryModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::beginRemoveColumns(parent, first, last); +} + +/*! \internal + */ +void QSqlQueryModel::endRemoveColumns() +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::endRemoveColumns(); +} + +/*! \internal + */ +void QSqlQueryModel::beginResetModel() +{ + Q_D(QSqlQueryModel); + if (!d->nestedResetLevel) + QAbstractTableModel::beginResetModel(); + ++d->nestedResetLevel; +} + +/*! \internal + */ +void QSqlQueryModel::endResetModel() +{ + Q_D(QSqlQueryModel); + --d->nestedResetLevel; + if (!d->nestedResetLevel) + QAbstractTableModel::endResetModel(); +} + +/*! \fn int QSqlQueryModel::rowCount(const QModelIndex &parent) const + \since 4.1 + + If the database supports returning the size of a query + (see QSqlDriver::hasFeature()), the number of rows of the current + query is returned. Otherwise, returns the number of rows + currently cached on the client. + + \a parent should always be an invalid QModelIndex. + + \sa canFetchMore(), QSqlDriver::hasFeature() + */ +int QSqlQueryModel::rowCount(const QModelIndex &index) const +{ + Q_D(const QSqlQueryModel); + return index.isValid() ? 0 : d->bottom.row() + 1; +} + +/*! \reimp + */ +int QSqlQueryModel::columnCount(const QModelIndex &index) const +{ + Q_D(const QSqlQueryModel); + return index.isValid() ? 0 : d->rec.count(); +} + +/*! + Returns the value for the specified \a item and \a role. + + If \a item is out of bounds or if an error occurred, an invalid + QVariant is returned. + + \sa lastError() +*/ +QVariant QSqlQueryModel::data(const QModelIndex &item, int role) const +{ + Q_D(const QSqlQueryModel); + if (!item.isValid()) + return QVariant(); + + QVariant v; + if (role & ~(Qt::DisplayRole | Qt::EditRole)) + return v; + + if (!d->rec.isGenerated(item.column())) + return v; + QModelIndex dItem = indexInQuery(item); + if (dItem.row() > d->bottom.row()) + const_cast(d)->prefetch(dItem.row()); + + if (!d->query.seek(dItem.row())) { + d->error = d->query.lastError(); + return v; + } + + return d->query.value(dItem.column()); +} + +/*! + Returns the header data for the given \a role in the \a section + of the header with the specified \a orientation. +*/ +QVariant QSqlQueryModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_D(const QSqlQueryModel); + if (orientation == Qt::Horizontal) { + QVariant val = d->headers.value(section).value(role); + if (role == Qt::DisplayRole && !val.isValid()) + val = d->headers.value(section).value(Qt::EditRole); + if (val.isValid()) + return val; + if (role == Qt::DisplayRole && d->rec.count() > section && d->columnInQuery(section) != -1) + return d->rec.fieldName(section); + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +/*! + This virtual function is called whenever the query changes. The + default implementation does nothing. + + query() returns the new query. + + \sa query(), setQuery() + */ +void QSqlQueryModel::queryChange() +{ + // do nothing +} + +/*! + Resets the model and sets the data provider to be the given \a + query. Note that the query must be active and must not be + isForwardOnly(). + + lastError() can be used to retrieve verbose information if there + was an error setting the query. + + \note Calling setQuery() will remove any inserted columns. + + \sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError() +*/ +void QSqlQueryModel::setQuery(const QSqlQuery &query) +{ + Q_D(QSqlQueryModel); + beginResetModel(); + + QSqlRecord newRec = query.record(); + bool columnsChanged = (newRec != d->rec); + + if (d->colOffsets.size() != newRec.count() || columnsChanged) + d->initColOffsets(newRec.count()); + + d->bottom = QModelIndex(); + d->error = QSqlError(); + d->query = query; + d->rec = newRec; + d->atEnd = true; + + if (query.isForwardOnly()) { + d->error = QSqlError(QLatin1String("Forward-only queries " + "cannot be used in a data model"), + QString(), QSqlError::ConnectionError); + endResetModel(); + return; + } + + if (!query.isActive()) { + d->error = query.lastError(); + endResetModel(); + return; + } + + if (query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) { + d->bottom = createIndex(d->query.size() - 1, d->rec.count() - 1); + } else { + d->bottom = createIndex(-1, d->rec.count() - 1); + d->atEnd = false; + } + + + // fetchMore does the rowsInserted stuff for incremental models + fetchMore(); + + endResetModel(); + queryChange(); +} + +/*! \overload + + Executes the query \a query for the given database connection \a + db. If no database (or an invalid database) is specified, the + default connection is used. + + lastError() can be used to retrieve verbose information if there + was an error setting the query. + + Example: + \snippet code/src_sql_models_qsqlquerymodel.cpp 1 + + \sa query(), queryChange(), lastError() +*/ +void QSqlQueryModel::setQuery(const QString &query, const QSqlDatabase &db) +{ + setQuery(QSqlQuery(query, db)); +} + +/*! + Clears the model and releases any acquired resource. +*/ +void QSqlQueryModel::clear() +{ + Q_D(QSqlQueryModel); + beginResetModel(); + d->error = QSqlError(); + d->atEnd = true; + d->query.clear(); + d->rec.clear(); + d->colOffsets.clear(); + d->bottom = QModelIndex(); + d->headers.clear(); + endResetModel(); +} + +/*! + Sets the caption for a horizontal header for the specified \a role to + \a value. This is useful if the model is used to + display data in a view (e.g., QTableView). + + Returns \c true if \a orientation is Qt::Horizontal and + the \a section refers to a valid section; otherwise returns + false. + + Note that this function cannot be used to modify values in the + database since the model is read-only. + + \sa data() + */ +bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation, + const QVariant &value, int role) +{ + Q_D(QSqlQueryModel); + if (orientation != Qt::Horizontal || section < 0 || columnCount() <= section) + return false; + + if (d->headers.size() <= section) + d->headers.resize(qMax(section + 1, 16)); + d->headers[section][role] = value; + emit headerDataChanged(orientation, section, section); + return true; +} + +/*! + Returns the QSqlQuery associated with this model. + + \sa setQuery() +*/ +QSqlQuery QSqlQueryModel::query() const +{ + Q_D(const QSqlQueryModel); + return d->query; +} + +/*! + Returns information about the last error that occurred on the + database. + + \sa query() +*/ +QSqlError QSqlQueryModel::lastError() const +{ + Q_D(const QSqlQueryModel); + return d->error; +} + +/*! + Protected function which allows derived classes to set the value of + the last error that occurred on the database to \a error. + + \sa lastError() +*/ +void QSqlQueryModel::setLastError(const QSqlError &error) +{ + Q_D(QSqlQueryModel); + d->error = error; +} + +/*! + Returns the record containing information about the fields of the + current query. If \a row is the index of a valid row, the record + will be populated with values from that row. + + If the model is not initialized, an empty record will be + returned. + + \sa QSqlRecord::isEmpty() +*/ +QSqlRecord QSqlQueryModel::record(int row) const +{ + Q_D(const QSqlQueryModel); + if (row < 0) + return d->rec; + + QSqlRecord rec = d->rec; + for (int i = 0; i < rec.count(); ++i) + rec.setValue(i, data(createIndex(row, i), Qt::EditRole)); + return rec; +} + +/*! \overload + + Returns an empty record containing information about the fields + of the current query. + + If the model is not initialized, an empty record will be + returned. + + \sa QSqlRecord::isEmpty() + */ +QSqlRecord QSqlQueryModel::record() const +{ + Q_D(const QSqlQueryModel); + return d->rec; +} + +/*! + Inserts \a count columns into the model at position \a column. The + \a parent parameter must always be an invalid QModelIndex, since + the model does not support parent-child relationships. + + Returns \c true if \a column is within bounds; otherwise returns \c false. + + By default, inserted columns are empty. To fill them with data, + reimplement data() and handle any inserted column separately: + + \snippet sqldatabase/sqldatabase.cpp 23 + + \sa removeColumns() +*/ +bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex &parent) +{ + Q_D(QSqlQueryModel); + if (count <= 0 || parent.isValid() || column < 0 || column > d->rec.count()) + return false; + + beginInsertColumns(parent, column, column + count - 1); + for (int c = 0; c < count; ++c) { + QSqlField field; + field.setReadOnly(true); + field.setGenerated(false); + d->rec.insert(column, field); + if (d->colOffsets.size() < d->rec.count()) { + int nVal = d->colOffsets.isEmpty() ? 0 : d->colOffsets[d->colOffsets.size() - 1]; + d->colOffsets.append(nVal); + Q_ASSERT(d->colOffsets.size() >= d->rec.count()); + } + for (int i = column + 1; i < d->colOffsets.count(); ++i) + ++d->colOffsets[i]; + } + endInsertColumns(); + return true; +} + +/*! + Removes \a count columns from the model starting from position \a + column. The \a parent parameter must always be an invalid + QModelIndex, since the model does not support parent-child + relationships. + + Removing columns effectively hides them. It does not affect the + underlying QSqlQuery. + + Returns \c true if the columns were removed; otherwise returns \c false. + */ +bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &parent) +{ + Q_D(QSqlQueryModel); + if (count <= 0 || parent.isValid() || column < 0 || column >= d->rec.count()) + return false; + + beginRemoveColumns(parent, column, column + count - 1); + + int i; + for (i = 0; i < count; ++i) + d->rec.remove(column); + for (i = column; i < d->colOffsets.count(); ++i) + d->colOffsets[i] -= count; + + endRemoveColumns(); + return true; +} + +/*! + Returns the index of the value in the database result set for the + given \a item in the model. + + The return value is identical to \a item if no columns or rows + have been inserted, removed, or moved around. + + Returns an invalid model index if \a item is out of bounds or if + \a item does not point to a value in the result set. + + \sa QSqlTableModel::indexInQuery(), insertColumns(), removeColumns() +*/ +QModelIndex QSqlQueryModel::indexInQuery(const QModelIndex &item) const +{ + Q_D(const QSqlQueryModel); + int modelColumn = d->columnInQuery(item.column()); + if (modelColumn < 0) + return QModelIndex(); + return createIndex(item.row(), modelColumn, item.internalPointer()); +} + +QT_END_NAMESPACE From 68cd07a302cc869a67691ebdc43afee13d80d069 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:25:11 -0400 Subject: [PATCH 0957/1324] Create qsqlquerymodel.h --- src/qt/qsqlquerymodel.h | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/qt/qsqlquerymodel.h diff --git a/src/qt/qsqlquerymodel.h b/src/qt/qsqlquerymodel.h new file mode 100644 index 00000000..d7c41196 --- /dev/null +++ b/src/qt/qsqlquerymodel.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLQUERYMODEL_H +#define QSQLQUERYMODEL_H + +#include +#include + +QT_BEGIN_NAMESPACE + + +class QSqlQueryModelPrivate; +class QSqlError; +class QSqlRecord; +class QSqlQuery; + +class Q_SQL_EXPORT QSqlQueryModel: public QAbstractTableModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QSqlQueryModel) + +public: + explicit QSqlQueryModel(QObject *parent = Q_NULLPTR); + virtual ~QSqlQueryModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QSqlRecord record(int row) const; + QSqlRecord record() const; + + QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, + int role = Qt::EditRole) Q_DECL_OVERRIDE; + + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + + void setQuery(const QSqlQuery &query); + void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase()); + QSqlQuery query() const; + + virtual void clear(); + + QSqlError lastError() const; + + void fetchMore(const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; + bool canFetchMore(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + +protected: + void beginInsertRows(const QModelIndex &parent, int first, int last); + void endInsertRows(); + + void beginRemoveRows(const QModelIndex &parent, int first, int last); + void endRemoveRows(); + + void beginInsertColumns(const QModelIndex &parent, int first, int last); + void endInsertColumns(); + + void beginRemoveColumns(const QModelIndex &parent, int first, int last); + void endRemoveColumns(); + + void beginResetModel(); + void endResetModel(); + virtual void queryChange(); + + virtual QModelIndex indexInQuery(const QModelIndex &item) const; + void setLastError(const QSqlError &error); + QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent = Q_NULLPTR); +}; + +QT_END_NAMESPACE + +#endif // QSQLQUERYMODEL_H From 0023ed30d5879278571e633ba24e6e37979c5b16 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:25:42 -0400 Subject: [PATCH 0958/1324] Update qsqltablemodel.h --- src/qt/qsqltablemodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qsqltablemodel.h b/src/qt/qsqltablemodel.h index 9e756037..767dfe0d 100644 --- a/src/qt/qsqltablemodel.h +++ b/src/qt/qsqltablemodel.h @@ -41,7 +41,7 @@ #define QSQLTABLEMODEL_H #include "qsqldatabase.h" -#include +#include "qsqlquerymodel.h" QT_BEGIN_NAMESPACE From df9167b7ceedc3810218d87bdd958ca13cd46ad5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:27:40 -0400 Subject: [PATCH 0959/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index ec268932..ad891a2a 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -125,7 +125,8 @@ QT_MOC_CPP = \ qt/moc_user.cpp \ qt/moc_mainwindow.cpp \ qt/moc_qsqltablemodel.cpp \ - qt/moc_qsqldatabase.cpp + qt/moc_qsqldatabase.cpp \ + qt/moc_qsqlquerymodel.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -224,7 +225,8 @@ BITCOIN_QT_H = \ qt/mainwindow.h \ qt/qsqltablemodel.h \ qt/qsqldatabase.h \ - qt/qsql.h + qt/qsql.h \ + qt/qsqlquerymodel.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -578,7 +580,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/main.cpp \ qt/mainwindow.cpp \ qt/qsqltablemodel.cpp \ - qt/qsqldatabase.cpp + qt/qsqldatabase.cpp \ + qt/qsqlquerymodel.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From f934ac5502d534b08721976966001b1edaab33bd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:28:57 -0400 Subject: [PATCH 0960/1324] Update qsqlquerymodel.h --- src/qt/qsqlquerymodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qsqlquerymodel.h b/src/qt/qsqlquerymodel.h index d7c41196..6c769f93 100644 --- a/src/qt/qsqlquerymodel.h +++ b/src/qt/qsqlquerymodel.h @@ -41,7 +41,7 @@ #define QSQLQUERYMODEL_H #include -#include +#include "qsqldatabase.h" QT_BEGIN_NAMESPACE From 3f999bc9b2c6a5bc6fc46ba66485809f24f2098d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:32:06 -0400 Subject: [PATCH 0961/1324] Update loginsystem.h --- src/qt/loginsystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/loginsystem.h b/src/qt/loginsystem.h index db609690..33407338 100644 --- a/src/qt/loginsystem.h +++ b/src/qt/loginsystem.h @@ -22,7 +22,7 @@ class LoginSystem : public QMainWindow QString picDir = QCoreApplication::applicationDirPath()+"/../../LogSys/users/avatar"; QSqlTableModel* tblMdl; -private slots: +private Q_SLOTS: void on_loginButton_clicked(); void on_logoutButton_clicked(); From c57d6bcba9db933dfda8fd4322d8ccf09d9f0f45 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:33:54 -0400 Subject: [PATCH 0962/1324] Add files via upload --- src/qt/qsqldriver.h | 1 + src/qt/qsqlerror.h | 1 + src/qt/qsqlfield.h | 1 + src/qt/qsqlindex.h | 1 + src/qt/qsqlquery.h | 1 + src/qt/qsqlrecord.h | 1 + src/qt/qsqlresult.h | 1 + 7 files changed, 7 insertions(+) create mode 100644 src/qt/qsqldriver.h create mode 100644 src/qt/qsqlerror.h create mode 100644 src/qt/qsqlfield.h create mode 100644 src/qt/qsqlindex.h create mode 100644 src/qt/qsqlquery.h create mode 100644 src/qt/qsqlrecord.h create mode 100644 src/qt/qsqlresult.h diff --git a/src/qt/qsqldriver.h b/src/qt/qsqldriver.h new file mode 100644 index 00000000..a882ea60 --- /dev/null +++ b/src/qt/qsqldriver.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqldriver.h" diff --git a/src/qt/qsqlerror.h b/src/qt/qsqlerror.h new file mode 100644 index 00000000..bc568863 --- /dev/null +++ b/src/qt/qsqlerror.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlerror.h" diff --git a/src/qt/qsqlfield.h b/src/qt/qsqlfield.h new file mode 100644 index 00000000..f278c466 --- /dev/null +++ b/src/qt/qsqlfield.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlfield.h" diff --git a/src/qt/qsqlindex.h b/src/qt/qsqlindex.h new file mode 100644 index 00000000..87b8cdd9 --- /dev/null +++ b/src/qt/qsqlindex.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlindex.h" diff --git a/src/qt/qsqlquery.h b/src/qt/qsqlquery.h new file mode 100644 index 00000000..43dd90f8 --- /dev/null +++ b/src/qt/qsqlquery.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlquery.h" diff --git a/src/qt/qsqlrecord.h b/src/qt/qsqlrecord.h new file mode 100644 index 00000000..87748dfa --- /dev/null +++ b/src/qt/qsqlrecord.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlrecord.h" diff --git a/src/qt/qsqlresult.h b/src/qt/qsqlresult.h new file mode 100644 index 00000000..723eb26c --- /dev/null +++ b/src/qt/qsqlresult.h @@ -0,0 +1 @@ +#include "../../src/sql/kernel/qsqlresult.h" From a22ebfc571ae09a0dbced0fa6862ab685ffad444 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:35:38 -0400 Subject: [PATCH 0963/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index ad891a2a..dd6d5d21 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -226,7 +226,14 @@ BITCOIN_QT_H = \ qt/qsqltablemodel.h \ qt/qsqldatabase.h \ qt/qsql.h \ - qt/qsqlquerymodel.h + qt/qsqlquerymodel.h \ + qt/qsqldriver.h \ + qt/qsqlerror.h \ + qt/qsqlfield.h \ + qt/qsqlindex.h \ + qt/qsqlquery.h \ + qt/qsqlrecord.h \ + qt/qsql/result.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ From 7c1dd83a7f2057ab15ecaa2c0a853361c4e7bd55 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:39:31 -0400 Subject: [PATCH 0964/1324] Update qsqlquery.h --- src/qt/qsqlquery.h | 123 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/src/qt/qsqlquery.h b/src/qt/qsqlquery.h index 43dd90f8..243e4a04 100644 --- a/src/qt/qsqlquery.h +++ b/src/qt/qsqlquery.h @@ -1 +1,122 @@ -#include "../../src/sql/kernel/qsqlquery.h" +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLQUERY_H +#define QSQLQUERY_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + + +class QVariant; +class QSqlDriver; +class QSqlError; +class QSqlResult; +class QSqlRecord; +template class QMap; +class QSqlQueryPrivate; + +class Q_SQL_EXPORT QSqlQuery +{ +public: + explicit QSqlQuery(QSqlResult *r); + explicit QSqlQuery(const QString& query = QString(), QSqlDatabase db = QSqlDatabase()); + explicit QSqlQuery(QSqlDatabase db); + QSqlQuery(const QSqlQuery& other); + QSqlQuery& operator=(const QSqlQuery& other); + ~QSqlQuery(); + + bool isValid() const; + bool isActive() const; + bool isNull(int field) const; + bool isNull(const QString &name) const; + int at() const; + QString lastQuery() const; + int numRowsAffected() const; + QSqlError lastError() const; + bool isSelect() const; + int size() const; + const QSqlDriver* driver() const; + const QSqlResult* result() const; + bool isForwardOnly() const; + QSqlRecord record() const; + + void setForwardOnly(bool forward); + bool exec(const QString& query); + QVariant value(int i) const; + QVariant value(const QString& name) const; + + void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); + QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; + + bool seek(int i, bool relative = false); + bool next(); + bool previous(); + bool first(); + bool last(); + + void clear(); + + // prepared query support + bool exec(); + enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns }; + bool execBatch(BatchExecutionMode mode = ValuesAsRows); + bool prepare(const QString& query); + void bindValue(const QString& placeholder, const QVariant& val, + QSql::ParamType type = QSql::In); + void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In); + void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In); + QVariant boundValue(const QString& placeholder) const; + QVariant boundValue(int pos) const; + QMap boundValues() const; + QString executedQuery() const; + QVariant lastInsertId() const; + void finish(); + bool nextResult(); + +private: + QSqlQueryPrivate* d; +}; + +QT_END_NAMESPACE + +#endif // QSQLQUERY_H From 49ae4d0e867ef867213139061ae4146dad4a8a91 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:39:52 -0400 Subject: [PATCH 0965/1324] Create qsqlquery.cpp --- src/qt/qsqlquery.cpp | 1298 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1298 insertions(+) create mode 100644 src/qt/qsqlquery.cpp diff --git a/src/qt/qsqlquery.cpp b/src/qt/qsqlquery.cpp new file mode 100644 index 00000000..f9cc07da --- /dev/null +++ b/src/qt/qsqlquery.cpp @@ -0,0 +1,1298 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsqlquery.h" + +//#define QT_DEBUG_SQL + +#include "qdebug.h" +#include "qelapsedtimer.h" +#include "qatomic.h" +#include "qsqlrecord.h" +#include "qsqlresult.h" +#include "qsqldriver.h" +#include "qsqldatabase.h" +#include "private/qsqlnulldriver_p.h" +#include "qvector.h" +#include "qmap.h" + +QT_BEGIN_NAMESPACE + +class QSqlQueryPrivate +{ +public: + QSqlQueryPrivate(QSqlResult* result); + ~QSqlQueryPrivate(); + QAtomicInt ref; + QSqlResult* sqlResult; + + static QSqlQueryPrivate* shared_null(); +}; + +Q_GLOBAL_STATIC_WITH_ARGS(QSqlQueryPrivate, nullQueryPrivate, (0)) +Q_GLOBAL_STATIC(QSqlNullDriver, nullDriver) +Q_GLOBAL_STATIC_WITH_ARGS(QSqlNullResult, nullResult, (nullDriver())) + +QSqlQueryPrivate* QSqlQueryPrivate::shared_null() +{ + QSqlQueryPrivate *null = nullQueryPrivate(); + null->ref.ref(); + return null; +} + +/*! +\internal +*/ +QSqlQueryPrivate::QSqlQueryPrivate(QSqlResult* result) + : ref(1), sqlResult(result) +{ + if (!sqlResult) + sqlResult = nullResult(); +} + +QSqlQueryPrivate::~QSqlQueryPrivate() +{ + QSqlResult *nr = nullResult(); + if (!nr || sqlResult == nr) + return; + delete sqlResult; +} + +/*! + \class QSqlQuery + \brief The QSqlQuery class provides a means of executing and + manipulating SQL statements. + + \ingroup database + \ingroup shared + + \inmodule QtSql + + QSqlQuery encapsulates the functionality involved in creating, + navigating and retrieving data from SQL queries which are + executed on a \l QSqlDatabase. It can be used to execute DML + (data manipulation language) statements, such as \c SELECT, \c + INSERT, \c UPDATE and \c DELETE, as well as DDL (data definition + language) statements, such as \c{CREATE} \c{TABLE}. It can also + be used to execute database-specific commands which are not + standard SQL (e.g. \c{SET DATESTYLE=ISO} for PostgreSQL). + + Successfully executed SQL statements set the query's state to + active so that isActive() returns \c true. Otherwise the query's + state is set to inactive. In either case, when executing a new SQL + statement, the query is positioned on an invalid record. An active + query must be navigated to a valid record (so that isValid() + returns \c true) before values can be retrieved. + + For some databases, if an active query that is a \c{SELECT} + statement exists when you call \l{QSqlDatabase::}{commit()} or + \l{QSqlDatabase::}{rollback()}, the commit or rollback will + fail. See isActive() for details. + + \target QSqlQuery examples + + Navigating records is performed with the following functions: + + \list + \li next() + \li previous() + \li first() + \li last() + \li seek() + \endlist + + These functions allow the programmer to move forward, backward + or arbitrarily through the records returned by the query. If you + only need to move forward through the results (e.g., by using + next()), you can use setForwardOnly(), which will save a + significant amount of memory overhead and improve performance on + some databases. Once an active query is positioned on a valid + record, data can be retrieved using value(). All data is + transferred from the SQL backend using QVariants. + + For example: + + \snippet sqldatabase/sqldatabase.cpp 7 + + To access the data returned by a query, use value(int). Each + field in the data returned by a \c SELECT statement is accessed + by passing the field's position in the statement, starting from + 0. This makes using \c{SELECT *} queries inadvisable because the + order of the fields returned is indeterminate. + + For the sake of efficiency, there are no functions to access a + field by name (unless you use prepared queries with names, as + explained below). To convert a field name into an index, use + record().\l{QSqlRecord::indexOf()}{indexOf()}, for example: + + \snippet sqldatabase/sqldatabase.cpp 8 + + QSqlQuery supports prepared query execution and the binding of + parameter values to placeholders. Some databases don't support + these features, so for those, Qt emulates the required + functionality. For example, the Oracle and ODBC drivers have + proper prepared query support, and Qt makes use of it; but for + databases that don't have this support, Qt implements the feature + itself, e.g. by replacing placeholders with actual values when a + query is executed. Use numRowsAffected() to find out how many rows + were affected by a non-\c SELECT query, and size() to find how + many were retrieved by a \c SELECT. + + Oracle databases identify placeholders by using a colon-name + syntax, e.g \c{:name}. ODBC simply uses \c ? characters. Qt + supports both syntaxes, with the restriction that you can't mix + them in the same query. + + You can retrieve the values of all the fields in a single variable + (a map) using boundValues(). + + \section1 Approaches to Binding Values + + Below we present the same example using each of the four + different binding approaches, as well as one example of binding + values to a stored procedure. + + \b{Named binding using named placeholders:} + + \snippet sqldatabase/sqldatabase.cpp 9 + + \b{Positional binding using named placeholders:} + + \snippet sqldatabase/sqldatabase.cpp 10 + + \b{Binding values using positional placeholders (version 1):} + + \snippet sqldatabase/sqldatabase.cpp 11 + + \b{Binding values using positional placeholders (version 2):} + + \snippet sqldatabase/sqldatabase.cpp 12 + + \b{Binding values to a stored procedure:} + + This code calls a stored procedure called \c AsciiToInt(), passing + it a character through its in parameter, and taking its result in + the out parameter. + + \snippet sqldatabase/sqldatabase.cpp 13 + + Note that unbound parameters will retain their values. + + Stored procedures that uses the return statement to return values, + or return multiple result sets, are not fully supported. For specific + details see \l{SQL Database Drivers}. + + \warning You must load the SQL driver and open the connection before a + QSqlQuery is created. Also, the connection must remain open while the + query exists; otherwise, the behavior of QSqlQuery is undefined. + + \sa QSqlDatabase, QSqlQueryModel, QSqlTableModel, QVariant +*/ + +/*! + Constructs a QSqlQuery object which uses the QSqlResult \a result + to communicate with a database. +*/ + +QSqlQuery::QSqlQuery(QSqlResult *result) +{ + d = new QSqlQueryPrivate(result); +} + +/*! + Destroys the object and frees any allocated resources. +*/ + +QSqlQuery::~QSqlQuery() +{ + if (!d->ref.deref()) + delete d; +} + +/*! + Constructs a copy of \a other. +*/ + +QSqlQuery::QSqlQuery(const QSqlQuery& other) +{ + d = other.d; + d->ref.ref(); +} + +/*! + \internal +*/ +static void qInit(QSqlQuery *q, const QString& query, QSqlDatabase db) +{ + QSqlDatabase database = db; + if (!database.isValid()) + database = QSqlDatabase::database(QLatin1String(QSqlDatabase::defaultConnection), false); + if (database.isValid()) { + *q = QSqlQuery(database.driver()->createResult()); + } + if (!query.isEmpty()) + q->exec(query); +} + +/*! + Constructs a QSqlQuery object using the SQL \a query and the + database \a db. If \a db is not specified, or is invalid, the application's + default database is used. If \a query is not an empty string, it + will be executed. + + \sa QSqlDatabase +*/ +QSqlQuery::QSqlQuery(const QString& query, QSqlDatabase db) +{ + d = QSqlQueryPrivate::shared_null(); + qInit(this, query, db); +} + +/*! + Constructs a QSqlQuery object using the database \a db. + If \a db is invalid, the application's default database will be used. + + \sa QSqlDatabase +*/ + +QSqlQuery::QSqlQuery(QSqlDatabase db) +{ + d = QSqlQueryPrivate::shared_null(); + qInit(this, QString(), db); +} + + +/*! + Assigns \a other to this object. +*/ + +QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other) +{ + qAtomicAssign(d, other.d); + return *this; +} + +/*! + Returns \c true if the query is not \l{isActive()}{active}, + the query is not positioned on a valid record, + there is no such \a field, or the \a field is null; otherwise \c false. + Note that for some drivers, isNull() will not return accurate + information until after an attempt is made to retrieve data. + + \sa isActive(), isValid(), value() +*/ + +bool QSqlQuery::isNull(int field) const +{ + return !d->sqlResult->isActive() + || !d->sqlResult->isValid() + || d->sqlResult->isNull(field); +} + +/*! + \overload + + Returns \c true if there is no field with this \a name; otherwise + returns isNull(int index) for the corresponding field index. + + This overload is less efficient than \l{QSqlQuery::}{isNull()} +*/ + +bool QSqlQuery::isNull(const QString &name) const +{ + int index = d->sqlResult->record().indexOf(name); + if (index > -1) + return isNull(index); + qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name)); + return true; +} + +/*! + + Executes the SQL in \a query. Returns \c true and sets the query state + to \l{isActive()}{active} if the query was successful; otherwise + returns \c false. The \a query string must use syntax appropriate for + the SQL database being queried (for example, standard SQL). + + After the query is executed, the query is positioned on an \e + invalid record and must be navigated to a valid record before data + values can be retrieved (for example, using next()). + + Note that the last error for this query is reset when exec() is + called. + + For SQLite, the query string can contain only one statement at a time. + If more than one statement is given, the function returns \c false. + + Example: + + \snippet sqldatabase/sqldatabase.cpp 34 + + \sa isActive(), isValid(), next(), previous(), first(), last(), + seek() +*/ + +bool QSqlQuery::exec(const QString& query) +{ +#ifdef QT_DEBUG_SQL + QElapsedTimer t; + t.start(); +#endif + if (d->ref.load() != 1) { + bool fo = isForwardOnly(); + *this = QSqlQuery(driver()->createResult()); + d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); + setForwardOnly(fo); + } else { + d->sqlResult->clear(); + d->sqlResult->setActive(false); + d->sqlResult->setLastError(QSqlError()); + d->sqlResult->setAt(QSql::BeforeFirstRow); + d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); + } + d->sqlResult->setQuery(query.trimmed()); + if (!driver()->isOpen() || driver()->isOpenError()) { + qWarning("QSqlQuery::exec: database not open"); + return false; + } + if (query.isEmpty()) { + qWarning("QSqlQuery::exec: empty query"); + return false; + } + + bool retval = d->sqlResult->reset(query); +#ifdef QT_DEBUG_SQL + qDebug().nospace() << "Executed query (" << t.elapsed() << "ms, " << d->sqlResult->size() + << " results, " << d->sqlResult->numRowsAffected() + << " affected): " << d->sqlResult->lastQuery(); +#endif + return retval; +} + +/*! + Returns the value of field \a index in the current record. + + The fields are numbered from left to right using the text of the + \c SELECT statement, e.g. in + + \snippet code/src_sql_kernel_qsqlquery.cpp 0 + + field 0 is \c forename and field 1 is \c + surname. Using \c{SELECT *} is not recommended because the order + of the fields in the query is undefined. + + An invalid QVariant is returned if field \a index does not + exist, if the query is inactive, or if the query is positioned on + an invalid record. + + \sa previous(), next(), first(), last(), seek(), isActive(), isValid() +*/ + +QVariant QSqlQuery::value(int index) const +{ + if (isActive() && isValid() && (index > -1)) + return d->sqlResult->data(index); + qWarning("QSqlQuery::value: not positioned on a valid record"); + return QVariant(); +} + +/*! + \overload + + Returns the value of the field called \a name in the current record. + If field \a name does not exist an invalid variant is returned. + + This overload is less efficient than \l{QSqlQuery::}{value()} +*/ + +QVariant QSqlQuery::value(const QString& name) const +{ + int index = d->sqlResult->record().indexOf(name); + if (index > -1) + return value(index); + qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name)); + return QVariant(); +} + +/*! + Returns the current internal position of the query. The first + record is at position zero. If the position is invalid, the + function returns QSql::BeforeFirstRow or + QSql::AfterLastRow, which are special negative values. + + \sa previous(), next(), first(), last(), seek(), isActive(), isValid() +*/ + +int QSqlQuery::at() const +{ + return d->sqlResult->at(); +} + +/*! + Returns the text of the current query being used, or an empty + string if there is no current query text. + + \sa executedQuery() +*/ + +QString QSqlQuery::lastQuery() const +{ + return d->sqlResult->lastQuery(); +} + +/*! + Returns the database driver associated with the query. +*/ + +const QSqlDriver *QSqlQuery::driver() const +{ + return d->sqlResult->driver(); +} + +/*! + Returns the result associated with the query. +*/ + +const QSqlResult* QSqlQuery::result() const +{ + return d->sqlResult; +} + +/*! + Retrieves the record at position \a index, if available, and + positions the query on the retrieved record. The first record is at + position 0. Note that the query must be in an \l{isActive()} + {active} state and isSelect() must return true before calling this + function. + + If \a relative is false (the default), the following rules apply: + + \list + + \li If \a index is negative, the result is positioned before the + first record and false is returned. + + \li Otherwise, an attempt is made to move to the record at position + \a index. If the record at position \a index could not be retrieved, + the result is positioned after the last record and false is + returned. If the record is successfully retrieved, true is returned. + + \endlist + + If \a relative is true, the following rules apply: + + \list + + \li If the result is currently positioned before the first record and: + \list + \li \a index is negative or zero, there is no change, and false is + returned. + \li \a index is positive, an attempt is made to position the result + at absolute position \a index - 1, following the sames rule for non + relative seek, above. + \endlist + + \li If the result is currently positioned after the last record and: + \list + \li \a index is positive or zero, there is no change, and false is + returned. + \li \a index is negative, an attempt is made to position the result + at \a index + 1 relative position from last record, following the + rule below. + \endlist + + \li If the result is currently located somewhere in the middle, and + the relative offset \a index moves the result below zero, the result + is positioned before the first record and false is returned. + + \li Otherwise, an attempt is made to move to the record \a index + records ahead of the current record (or \a index records behind the + current record if \a index is negative). If the record at offset \a + index could not be retrieved, the result is positioned after the + last record if \a index >= 0, (or before the first record if \a + index is negative), and false is returned. If the record is + successfully retrieved, true is returned. + + \endlist + + \sa next(), previous(), first(), last(), at(), isActive(), isValid() +*/ +bool QSqlQuery::seek(int index, bool relative) +{ + if (!isSelect() || !isActive()) + return false; + int actualIdx; + if (!relative) { // arbitrary seek + if (index < 0) { + d->sqlResult->setAt(QSql::BeforeFirstRow); + return false; + } + actualIdx = index; + } else { + switch (at()) { // relative seek + case QSql::BeforeFirstRow: + if (index > 0) + actualIdx = index - 1; + else { + return false; + } + break; + case QSql::AfterLastRow: + if (index < 0) { + d->sqlResult->fetchLast(); + actualIdx = at() + index + 1; + } else { + return false; + } + break; + default: + if ((at() + index) < 0) { + d->sqlResult->setAt(QSql::BeforeFirstRow); + return false; + } + actualIdx = at() + index; + break; + } + } + // let drivers optimize + if (isForwardOnly() && actualIdx < at()) { + qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); + return false; + } + if (actualIdx == (at() + 1) && at() != QSql::BeforeFirstRow) { + if (!d->sqlResult->fetchNext()) { + d->sqlResult->setAt(QSql::AfterLastRow); + return false; + } + return true; + } + if (actualIdx == (at() - 1)) { + if (!d->sqlResult->fetchPrevious()) { + d->sqlResult->setAt(QSql::BeforeFirstRow); + return false; + } + return true; + } + if (!d->sqlResult->fetch(actualIdx)) { + d->sqlResult->setAt(QSql::AfterLastRow); + return false; + } + return true; +} + +/*! + + Retrieves the next record in the result, if available, and positions + the query on the retrieved record. Note that the result must be in + the \l{isActive()}{active} state and isSelect() must return true + before calling this function or it will do nothing and return false. + + The following rules apply: + + \list + + \li If the result is currently located before the first record, + e.g. immediately after a query is executed, an attempt is made to + retrieve the first record. + + \li If the result is currently located after the last record, there + is no change and false is returned. + + \li If the result is located somewhere in the middle, an attempt is + made to retrieve the next record. + + \endlist + + If the record could not be retrieved, the result is positioned after + the last record and false is returned. If the record is successfully + retrieved, true is returned. + + \sa previous(), first(), last(), seek(), at(), isActive(), isValid() +*/ +bool QSqlQuery::next() +{ + if (!isSelect() || !isActive()) + return false; + bool b = false; + switch (at()) { + case QSql::BeforeFirstRow: + b = d->sqlResult->fetchFirst(); + return b; + case QSql::AfterLastRow: + return false; + default: + if (!d->sqlResult->fetchNext()) { + d->sqlResult->setAt(QSql::AfterLastRow); + return false; + } + return true; + } +} + +/*! + + Retrieves the previous record in the result, if available, and + positions the query on the retrieved record. Note that the result + must be in the \l{isActive()}{active} state and isSelect() must + return true before calling this function or it will do nothing and + return false. + + The following rules apply: + + \list + + \li If the result is currently located before the first record, there + is no change and false is returned. + + \li If the result is currently located after the last record, an + attempt is made to retrieve the last record. + + \li If the result is somewhere in the middle, an attempt is made to + retrieve the previous record. + + \endlist + + If the record could not be retrieved, the result is positioned + before the first record and false is returned. If the record is + successfully retrieved, true is returned. + + \sa next(), first(), last(), seek(), at(), isActive(), isValid() +*/ +bool QSqlQuery::previous() +{ + if (!isSelect() || !isActive()) + return false; + if (isForwardOnly()) { + qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); + return false; + } + + bool b = false; + switch (at()) { + case QSql::BeforeFirstRow: + return false; + case QSql::AfterLastRow: + b = d->sqlResult->fetchLast(); + return b; + default: + if (!d->sqlResult->fetchPrevious()) { + d->sqlResult->setAt(QSql::BeforeFirstRow); + return false; + } + return true; + } +} + +/*! + Retrieves the first record in the result, if available, and + positions the query on the retrieved record. Note that the result + must be in the \l{isActive()}{active} state and isSelect() must + return true before calling this function or it will do nothing and + return false. Returns \c true if successful. If unsuccessful the query + position is set to an invalid position and false is returned. + + \sa next(), previous(), last(), seek(), at(), isActive(), isValid() + */ +bool QSqlQuery::first() +{ + if (!isSelect() || !isActive()) + return false; + if (isForwardOnly() && at() > QSql::BeforeFirstRow) { + qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); + return false; + } + bool b = false; + b = d->sqlResult->fetchFirst(); + return b; +} + +/*! + + Retrieves the last record in the result, if available, and positions + the query on the retrieved record. Note that the result must be in + the \l{isActive()}{active} state and isSelect() must return true + before calling this function or it will do nothing and return false. + Returns \c true if successful. If unsuccessful the query position is + set to an invalid position and false is returned. + + \sa next(), previous(), first(), seek(), at(), isActive(), isValid() +*/ + +bool QSqlQuery::last() +{ + if (!isSelect() || !isActive()) + return false; + bool b = false; + b = d->sqlResult->fetchLast(); + return b; +} + +/*! + Returns the size of the result (number of rows returned), or -1 if + the size cannot be determined or if the database does not support + reporting information about query sizes. Note that for non-\c SELECT + statements (isSelect() returns \c false), size() will return -1. If the + query is not active (isActive() returns \c false), -1 is returned. + + To determine the number of rows affected by a non-\c SELECT + statement, use numRowsAffected(). + + \sa isActive(), numRowsAffected(), QSqlDriver::hasFeature() +*/ +int QSqlQuery::size() const +{ + if (isActive() && d->sqlResult->driver()->hasFeature(QSqlDriver::QuerySize)) + return d->sqlResult->size(); + return -1; +} + +/*! + Returns the number of rows affected by the result's SQL statement, + or -1 if it cannot be determined. Note that for \c SELECT + statements, the value is undefined; use size() instead. If the query + is not \l{isActive()}{active}, -1 is returned. + + \sa size(), QSqlDriver::hasFeature() +*/ + +int QSqlQuery::numRowsAffected() const +{ + if (isActive()) + return d->sqlResult->numRowsAffected(); + return -1; +} + +/*! + Returns error information about the last error (if any) that + occurred with this query. + + \sa QSqlError, QSqlDatabase::lastError() +*/ + +QSqlError QSqlQuery::lastError() const +{ + return d->sqlResult->lastError(); +} + +/*! + Returns \c true if the query is currently positioned on a valid + record; otherwise returns \c false. +*/ + +bool QSqlQuery::isValid() const +{ + return d->sqlResult->isValid(); +} + +/*! + + Returns \c true if the query is \e{active}. An active QSqlQuery is one + that has been \l{QSqlQuery::exec()} {exec()'d} successfully but not + yet finished with. When you are finished with an active query, you + can make the query inactive by calling finish() or clear(), or + you can delete the QSqlQuery instance. + + \note Of particular interest is an active query that is a \c{SELECT} + statement. For some databases that support transactions, an active + query that is a \c{SELECT} statement can cause a \l{QSqlDatabase::} + {commit()} or a \l{QSqlDatabase::} {rollback()} to fail, so before + committing or rolling back, you should make your active \c{SELECT} + statement query inactive using one of the ways listed above. + + \sa isSelect() + */ +bool QSqlQuery::isActive() const +{ + return d->sqlResult->isActive(); +} + +/*! + Returns \c true if the current query is a \c SELECT statement; + otherwise returns \c false. +*/ + +bool QSqlQuery::isSelect() const +{ + return d->sqlResult->isSelect(); +} + +/*! + Returns \c true if you can only scroll forward through a result set; + otherwise returns \c false. + + \sa setForwardOnly(), next() +*/ +bool QSqlQuery::isForwardOnly() const +{ + return d->sqlResult->isForwardOnly(); +} + +/*! + Sets forward only mode to \a forward. If \a forward is true, only + next() and seek() with positive values, are allowed for navigating + the results. + + Forward only mode can be (depending on the driver) more memory + efficient since results do not need to be cached. It will also + improve performance on some databases. For this to be true, you must + call \c setForwardOnly() before the query is prepared or executed. + Note that the constructor that takes a query and a database may + execute the query. + + Forward only mode is off by default. + + Setting forward only to false is a suggestion to the database engine, + which has the final say on whether a result set is forward only or + scrollable. isForwardOnly() will always return the correct status of + the result set. + + \note Calling setForwardOnly after execution of the query will result + in unexpected results at best, and crashes at worst. + + \sa isForwardOnly(), next(), seek(), QSqlResult::setForwardOnly() +*/ +void QSqlQuery::setForwardOnly(bool forward) +{ + d->sqlResult->setForwardOnly(forward); +} + +/*! + Returns a QSqlRecord containing the field information for the + current query. If the query points to a valid row (isValid() returns + true), the record is populated with the row's values. An empty + record is returned when there is no active query (isActive() returns + false). + + To retrieve values from a query, value() should be used since + its index-based lookup is faster. + + In the following example, a \c{SELECT * FROM} query is executed. + Since the order of the columns is not defined, QSqlRecord::indexOf() + is used to obtain the index of a column. + + \snippet code/src_sql_kernel_qsqlquery.cpp 1 + + \sa value() +*/ +QSqlRecord QSqlQuery::record() const +{ + QSqlRecord rec = d->sqlResult->record(); + + if (isValid()) { + for (int i = 0; i < rec.count(); ++i) + rec.setValue(i, value(i)); + } + return rec; +} + +/*! + Clears the result set and releases any resources held by the + query. Sets the query state to inactive. You should rarely if ever + need to call this function. +*/ +void QSqlQuery::clear() +{ + *this = QSqlQuery(driver()->createResult()); +} + +/*! + Prepares the SQL query \a query for execution. Returns \c true if the + query is prepared successfully; otherwise returns \c false. + + The query may contain placeholders for binding values. Both Oracle + style colon-name (e.g., \c{:surname}), and ODBC style (\c{?}) + placeholders are supported; but they cannot be mixed in the same + query. See the \l{QSqlQuery examples}{Detailed Description} for + examples. + + Portability note: Some databases choose to delay preparing a query + until it is executed the first time. In this case, preparing a + syntactically wrong query succeeds, but every consecutive exec() + will fail. + + For SQLite, the query string can contain only one statement at a time. + If more than one statement is given, the function returns \c false. + + Example: + + \snippet sqldatabase/sqldatabase.cpp 9 + + \sa exec(), bindValue(), addBindValue() +*/ +bool QSqlQuery::prepare(const QString& query) +{ + if (d->ref.load() != 1) { + bool fo = isForwardOnly(); + *this = QSqlQuery(driver()->createResult()); + setForwardOnly(fo); + d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); + } else { + d->sqlResult->setActive(false); + d->sqlResult->setLastError(QSqlError()); + d->sqlResult->setAt(QSql::BeforeFirstRow); + d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); + } + if (!driver()) { + qWarning("QSqlQuery::prepare: no driver"); + return false; + } + if (!driver()->isOpen() || driver()->isOpenError()) { + qWarning("QSqlQuery::prepare: database not open"); + return false; + } + if (query.isEmpty()) { + qWarning("QSqlQuery::prepare: empty query"); + return false; + } +#ifdef QT_DEBUG_SQL + qDebug("\n QSqlQuery::prepare: %s", query.toLocal8Bit().constData()); +#endif + return d->sqlResult->savePrepare(query); +} + +/*! + Executes a previously prepared SQL query. Returns \c true if the query + executed successfully; otherwise returns \c false. + + Note that the last error for this query is reset when exec() is + called. + + \sa prepare(), bindValue(), addBindValue(), boundValue(), boundValues() +*/ +bool QSqlQuery::exec() +{ +#ifdef QT_DEBUG_SQL + QElapsedTimer t; + t.start(); +#endif + d->sqlResult->resetBindCount(); + + if (d->sqlResult->lastError().isValid()) + d->sqlResult->setLastError(QSqlError()); + + bool retval = d->sqlResult->exec(); +#ifdef QT_DEBUG_SQL + qDebug().nospace() << "Executed prepared query (" << t.elapsed() << "ms, " + << d->sqlResult->size() << " results, " << d->sqlResult->numRowsAffected() + << " affected): " << d->sqlResult->lastQuery(); +#endif + return retval; +} + +/*! \enum QSqlQuery::BatchExecutionMode + + \value ValuesAsRows - Updates multiple rows. Treats every entry in a QVariantList as a value for updating the next row. + \value ValuesAsColumns - Updates a single row. Treats every entry in a QVariantList as a single value of an array type. +*/ + +/*! + \since 4.2 + + Executes a previously prepared SQL query in a batch. All the bound + parameters have to be lists of variants. If the database doesn't + support batch executions, the driver will simulate it using + conventional exec() calls. + + Returns \c true if the query is executed successfully; otherwise + returns \c false. + + Example: + + \snippet code/src_sql_kernel_qsqlquery.cpp 2 + + The example above inserts four new rows into \c myTable: + + \snippet code/src_sql_kernel_qsqlquery.cpp 3 + + To bind NULL values, a null QVariant of the relevant type has to be + added to the bound QVariantList; for example, \c + {QVariant(QVariant::String)} should be used if you are using + strings. + + \note Every bound QVariantList must contain the same amount of + variants. + + \note The type of the QVariants in a list must not change. For + example, you cannot mix integer and string variants within a + QVariantList. + + The \a mode parameter indicates how the bound QVariantList will be + interpreted. If \a mode is \c ValuesAsRows, every variant within + the QVariantList will be interpreted as a value for a new row. \c + ValuesAsColumns is a special case for the Oracle driver. In this + mode, every entry within a QVariantList will be interpreted as + array-value for an IN or OUT value within a stored procedure. Note + that this will only work if the IN or OUT value is a table-type + consisting of only one column of a basic type, for example \c{TYPE + myType IS TABLE OF VARCHAR(64) INDEX BY BINARY_INTEGER;} + + \sa prepare(), bindValue(), addBindValue() +*/ +bool QSqlQuery::execBatch(BatchExecutionMode mode) +{ + d->sqlResult->resetBindCount(); + return d->sqlResult->execBatch(mode == ValuesAsColumns); +} + +/*! + Set the placeholder \a placeholder to be bound to value \a val in + the prepared statement. Note that the placeholder mark (e.g \c{:}) + must be included when specifying the placeholder name. If \a + paramType is QSql::Out or QSql::InOut, the placeholder will be + overwritten with data from the database after the exec() call. + In this case, sufficient space must be pre-allocated to store + the result into. + + To bind a NULL value, use a null QVariant; for example, use + \c {QVariant(QVariant::String)} if you are binding a string. + + \sa addBindValue(), prepare(), exec(), boundValue(), boundValues() +*/ +void QSqlQuery::bindValue(const QString& placeholder, const QVariant& val, + QSql::ParamType paramType +) +{ + d->sqlResult->bindValue(placeholder, val, paramType); +} + +/*! + Set the placeholder in position \a pos to be bound to value \a val + in the prepared statement. Field numbering starts at 0. If \a + paramType is QSql::Out or QSql::InOut, the placeholder will be + overwritten with data from the database after the exec() call. +*/ +void QSqlQuery::bindValue(int pos, const QVariant& val, QSql::ParamType paramType) +{ + d->sqlResult->bindValue(pos, val, paramType); +} + +/*! + Adds the value \a val to the list of values when using positional + value binding. The order of the addBindValue() calls determines + which placeholder a value will be bound to in the prepared query. + If \a paramType is QSql::Out or QSql::InOut, the placeholder will be + overwritten with data from the database after the exec() call. + + To bind a NULL value, use a null QVariant; for example, use \c + {QVariant(QVariant::String)} if you are binding a string. + + \sa bindValue(), prepare(), exec(), boundValue(), boundValues() +*/ +void QSqlQuery::addBindValue(const QVariant& val, QSql::ParamType paramType) +{ + d->sqlResult->addBindValue(val, paramType); +} + +/*! + Returns the value for the \a placeholder. + + \sa boundValues(), bindValue(), addBindValue() +*/ +QVariant QSqlQuery::boundValue(const QString& placeholder) const +{ + return d->sqlResult->boundValue(placeholder); +} + +/*! + Returns the value for the placeholder at position \a pos. +*/ +QVariant QSqlQuery::boundValue(int pos) const +{ + return d->sqlResult->boundValue(pos); +} + +/*! + Returns a map of the bound values. + + With named binding, the bound values can be examined in the + following ways: + + \snippet sqldatabase/sqldatabase.cpp 14 + + With positional binding, the code becomes: + + \snippet sqldatabase/sqldatabase.cpp 15 + + \sa boundValue(), bindValue(), addBindValue() +*/ +QMap QSqlQuery::boundValues() const +{ + QMap map; + + const QVector values(d->sqlResult->boundValues()); + for (int i = 0; i < values.count(); ++i) + map[d->sqlResult->boundValueName(i)] = values.at(i); + return map; +} + +/*! + Returns the last query that was successfully executed. + + In most cases this function returns the same string as lastQuery(). + If a prepared query with placeholders is executed on a DBMS that + does not support it, the preparation of this query is emulated. The + placeholders in the original query are replaced with their bound + values to form a new query. This function returns the modified + query. It is mostly useful for debugging purposes. + + \sa lastQuery() +*/ +QString QSqlQuery::executedQuery() const +{ + return d->sqlResult->executedQuery(); +} + +/*! + Returns the object ID of the most recent inserted row if the + database supports it. An invalid QVariant will be returned if the + query did not insert any value or if the database does not report + the id back. If more than one row was touched by the insert, the + behavior is undefined. + + For MySQL databases the row's auto-increment field will be returned. + + \note For this function to work in PSQL, the table table must + contain OIDs, which may not have been created by default. Check the + \c default_with_oids configuration variable to be sure. + + \sa QSqlDriver::hasFeature() +*/ +QVariant QSqlQuery::lastInsertId() const +{ + return d->sqlResult->lastInsertId(); +} + +/*! + + Instruct the database driver to return numerical values with a + precision specified by \a precisionPolicy. + + The Oracle driver, for example, can retrieve numerical values as + strings to prevent the loss of precision. If high precision doesn't + matter, use this method to increase execution speed by bypassing + string conversions. + + Note: Drivers that don't support fetching numerical values with low + precision will ignore the precision policy. You can use + QSqlDriver::hasFeature() to find out whether a driver supports this + feature. + + Note: Setting the precision policy doesn't affect the currently + active query. Call \l{exec()}{exec(QString)} or prepare() in order + to activate the policy. + + \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy() +*/ +void QSqlQuery::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) +{ + d->sqlResult->setNumericalPrecisionPolicy(precisionPolicy); +} + +/*! + Returns the current precision policy. + + \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy() +*/ +QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const +{ + return d->sqlResult->numericalPrecisionPolicy(); +} + +/*! + \since 4.3.2 + + Instruct the database driver that no more data will be fetched from + this query until it is re-executed. There is normally no need to + call this function, but it may be helpful in order to free resources + such as locks or cursors if you intend to re-use the query at a + later time. + + Sets the query to inactive. Bound values retain their values. + + \sa prepare(), exec(), isActive() +*/ +void QSqlQuery::finish() +{ + if (isActive()) { + d->sqlResult->setLastError(QSqlError()); + d->sqlResult->setAt(QSql::BeforeFirstRow); + d->sqlResult->detachFromResultSet(); + d->sqlResult->setActive(false); + } +} + +/*! + \since 4.4 + + Discards the current result set and navigates to the next if available. + + Some databases are capable of returning multiple result sets for + stored procedures or SQL batches (a query strings that contains + multiple statements). If multiple result sets are available after + executing a query this function can be used to navigate to the next + result set(s). + + If a new result set is available this function will return true. + The query will be repositioned on an \e invalid record in the new + result set and must be navigated to a valid record before data + values can be retrieved. If a new result set isn't available the + function returns \c false and the query is set to inactive. In any + case the old result set will be discarded. + + When one of the statements is a non-select statement a count of + affected rows may be available instead of a result set. + + Note that some databases, i.e. Microsoft SQL Server, requires + non-scrollable cursors when working with multiple result sets. Some + databases may execute all statements at once while others may delay + the execution until the result set is actually accessed, and some + databases may have restrictions on which statements are allowed to + be used in a SQL batch. + + \sa QSqlDriver::hasFeature(), setForwardOnly(), next(), isSelect(), + numRowsAffected(), isActive(), lastError() +*/ +bool QSqlQuery::nextResult() +{ + if (isActive()) + return d->sqlResult->nextResult(); + return false; +} + +QT_END_NAMESPACE From 95b33b01c48900e581565de12d1d2903cd9d08da Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:40:34 -0400 Subject: [PATCH 0966/1324] Update qsqldriver.h --- src/qt/qsqldriver.h | 155 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-) diff --git a/src/qt/qsqldriver.h b/src/qt/qsqldriver.h index a882ea60..9fd7523f 100644 --- a/src/qt/qsqldriver.h +++ b/src/qt/qsqldriver.h @@ -1 +1,154 @@ -#include "../../src/sql/kernel/qsqldriver.h" +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLDRIVER_H +#define QSQLDRIVER_H + +#include +#include +#include +#include "qsql.h" + +QT_BEGIN_NAMESPACE + + +class QSqlDatabase; +class QSqlDriverPrivate; +class QSqlError; +class QSqlField; +class QSqlIndex; +class QSqlRecord; +class QSqlResult; +class QVariant; + +class Q_SQL_EXPORT QSqlDriver : public QObject +{ + friend class QSqlDatabase; + friend class QSqlResultPrivate; + Q_OBJECT + Q_DECLARE_PRIVATE(QSqlDriver) + +public: + enum DriverFeature { Transactions, QuerySize, BLOB, Unicode, PreparedQueries, + NamedPlaceholders, PositionalPlaceholders, LastInsertId, + BatchOperations, SimpleLocking, LowPrecisionNumbers, + EventNotifications, FinishQuery, MultipleResultSets, CancelQuery }; + + enum StatementType { WhereStatement, SelectStatement, UpdateStatement, + InsertStatement, DeleteStatement }; + + enum IdentifierType { FieldName, TableName }; + + enum NotificationSource { UnknownSource, SelfSource, OtherSource }; + + enum DbmsType { + UnknownDbms, + MSSqlServer, + MySqlServer, + PostgreSQL, + Oracle, + Sybase, + SQLite, + Interbase, + DB2 + }; + + explicit QSqlDriver(QObject *parent = Q_NULLPTR); + ~QSqlDriver(); + virtual bool isOpen() const; + bool isOpenError() const; + + virtual bool beginTransaction(); + virtual bool commitTransaction(); + virtual bool rollbackTransaction(); + virtual QStringList tables(QSql::TableType tableType) const; + virtual QSqlIndex primaryIndex(const QString &tableName) const; + virtual QSqlRecord record(const QString &tableName) const; + virtual QString formatValue(const QSqlField& field, bool trimStrings = false) const; + + virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const; + virtual QString sqlStatement(StatementType type, const QString &tableName, + const QSqlRecord &rec, bool preparedStatement) const; + + QSqlError lastError() const; + + virtual QVariant handle() const; + virtual bool hasFeature(DriverFeature f) const = 0; + virtual void close() = 0; + virtual QSqlResult *createResult() const = 0; + + virtual bool open(const QString& db, + const QString& user = QString(), + const QString& password = QString(), + const QString& host = QString(), + int port = -1, + const QString& connOpts = QString()) = 0; + virtual bool subscribeToNotification(const QString &name); + virtual bool unsubscribeFromNotification(const QString &name); + virtual QStringList subscribedToNotifications() const; + + virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; + virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const; + + void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); + QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; + + DbmsType dbmsType() const; + +public Q_SLOTS: + virtual bool cancelQuery(); + +Q_SIGNALS: + void notification(const QString &name); + void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); + +protected: + QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = Q_NULLPTR); + virtual void setOpen(bool o); + virtual void setOpenError(bool e); + virtual void setLastError(const QSqlError& e); + + +private: + Q_DISABLE_COPY(QSqlDriver) +}; + +QT_END_NAMESPACE + +#endif // QSQLDRIVER_H From 1a5bdee005abbc3109479bd69810dec9aca7d3be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:41:07 -0400 Subject: [PATCH 0967/1324] Create qsqldriver.cpp --- src/qt/qsqldriver.cpp | 841 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 841 insertions(+) create mode 100644 src/qt/qsqldriver.cpp diff --git a/src/qt/qsqldriver.cpp b/src/qt/qsqldriver.cpp new file mode 100644 index 00000000..ad5207cf --- /dev/null +++ b/src/qt/qsqldriver.cpp @@ -0,0 +1,841 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsqldriver.h" + +#include "qdatetime.h" +#include "qsqlerror.h" +#include "qsqlfield.h" +#include "qsqlindex.h" +#include "private/qobject_p.h" +#include "private/qsqldriver_p.h" + +QT_BEGIN_NAMESPACE + +static QString prepareIdentifier(const QString &identifier, + QSqlDriver::IdentifierType type, const QSqlDriver *driver) +{ + Q_ASSERT( driver != NULL ); + QString ret = identifier; + if (!driver->isIdentifierEscaped(identifier, type)) { + ret = driver->escapeIdentifier(identifier, type); + } + return ret; +} + +/*! + \class QSqlDriver + \brief The QSqlDriver class is an abstract base class for accessing + specific SQL databases. + + \ingroup database + \inmodule QtSql + + This class should not be used directly. Use QSqlDatabase instead. + + If you want to create your own SQL drivers, you can subclass this + class and reimplement its pure virtual functions and those + virtual functions that you need. See \l{How to Write Your Own + Database Driver} for more information. + + \sa QSqlDatabase, QSqlResult +*/ + +/*! + Constructs a new driver with the given \a parent. +*/ + +QSqlDriver::QSqlDriver(QObject *parent) + : QObject(*new QSqlDriverPrivate, parent) +{ +} + +/*! \internal +*/ +QSqlDriver::QSqlDriver(QSqlDriverPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + +/*! + Destroys the object and frees any allocated resources. +*/ + +QSqlDriver::~QSqlDriver() +{ +} + +/*! + \since 4.4 + + \fn QSqlDriver::notification(const QString &name) + + This signal is emitted when the database posts an event notification + that the driver subscribes to. \a name identifies the event notification. + + \sa subscribeToNotification() +*/ + +/*! + \since 5.0 + + \fn QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant & payload) + + This signal is emitted when the database posts an event notification + that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source, + \a payload holds the extra data optionally delivered with the notification. + + \sa subscribeToNotification() +*/ + +/*! + \fn bool QSqlDriver::open(const QString &db, const QString &user, const QString& password, + const QString &host, int port, const QString &options) + + Derived classes must reimplement this pure virtual function to + open a database connection on database \a db, using user name \a + user, password \a password, host \a host, port \a port and + connection options \a options. + + The function must return true on success and false on failure. + + \sa setOpen() +*/ + +/*! + \fn bool QSqlDriver::close() + + Derived classes must reimplement this pure virtual function in + order to close the database connection. Return true on success, + false on failure. + + \sa open(), setOpen() +*/ + +/*! + \fn QSqlResult *QSqlDriver::createResult() const + + Creates an empty SQL result on the database. Derived classes must + reimplement this function and return a QSqlResult object + appropriate for their database to the caller. +*/ + +/*! + Returns \c true if the database connection is open; otherwise returns + false. +*/ + +bool QSqlDriver::isOpen() const +{ + Q_D(const QSqlDriver); + return d->isOpen; +} + +/*! + Returns \c true if the there was an error opening the database + connection; otherwise returns \c false. +*/ + +bool QSqlDriver::isOpenError() const +{ + Q_D(const QSqlDriver); + return d->isOpenError; +} + +/*! + \enum QSqlDriver::DriverFeature + + This enum contains a list of features a driver might support. Use + hasFeature() to query whether a feature is supported or not. + + \value Transactions Whether the driver supports SQL transactions. + \value QuerySize Whether the database is capable of reporting the size + of a query. Note that some databases do not support returning the size + (i.e. number of rows returned) of a query, in which case + QSqlQuery::size() will return -1. + \value BLOB Whether the driver supports Binary Large Object fields. + \value Unicode Whether the driver supports Unicode strings if the + database server does. + \value PreparedQueries Whether the driver supports prepared query execution. + \value NamedPlaceholders Whether the driver supports the use of named placeholders. + \value PositionalPlaceholders Whether the driver supports the use of positional placeholders. + \value LastInsertId Whether the driver supports returning the Id of the last touched row. + \value BatchOperations Whether the driver supports batched operations, see QSqlQuery::execBatch() + \value SimpleLocking Whether the driver disallows a write lock on a table while other queries have a read lock on it. + \value LowPrecisionNumbers Whether the driver allows fetching numerical values with low precision. + \value EventNotifications Whether the driver supports database event notifications. + \value FinishQuery Whether the driver can do any low-level resource cleanup when QSqlQuery::finish() is called. + \value MultipleResultSets Whether the driver can access multiple result sets returned from batched statements or stored procedures. + \value CancelQuery Whether the driver allows cancelling a running query. + + More information about supported features can be found in the + \l{sql-driver.html}{Qt SQL driver} documentation. + + \sa hasFeature() +*/ + +/*! + \enum QSqlDriver::StatementType + + This enum contains a list of SQL statement (or clause) types the + driver can create. + + \value WhereStatement An SQL \c WHERE statement (e.g., \c{WHERE f = 5}). + \value SelectStatement An SQL \c SELECT statement (e.g., \c{SELECT f FROM t}). + \value UpdateStatement An SQL \c UPDATE statement (e.g., \c{UPDATE TABLE t set f = 1}). + \value InsertStatement An SQL \c INSERT statement (e.g., \c{INSERT INTO t (f) values (1)}). + \value DeleteStatement An SQL \c DELETE statement (e.g., \c{DELETE FROM t}). + + \sa sqlStatement() +*/ + +/*! + \enum QSqlDriver::IdentifierType + + This enum contains a list of SQL identifier types. + + \value FieldName A SQL field name + \value TableName A SQL table name +*/ + +/*! + \enum QSqlDriver::NotificationSource + + This enum contains a list of SQL notification sources. + + \value UnknownSource The notification source is unknown + \value SelfSource The notification source is this connection + \value OtherSource The notification source is another connection +*/ + +/*! + \enum QSqlDriver::DbmsType + + This enum contains DBMS types. + + \value UnknownDbms + \value MSSqlServer + \value MySqlServer + \value PostgreSQL + \value Oracle + \value Sybase + \value SQLite + \value Interbase + \value DB2 +*/ + +/*! + \fn bool QSqlDriver::hasFeature(DriverFeature feature) const + + Returns \c true if the driver supports feature \a feature; otherwise + returns \c false. + + Note that some databases need to be open() before this can be + determined. + + \sa DriverFeature +*/ + +/*! + This function sets the open state of the database to \a open. + Derived classes can use this function to report the status of + open(). + + \sa open(), setOpenError() +*/ + +void QSqlDriver::setOpen(bool open) +{ + Q_D(QSqlDriver); + d->isOpen = open; +} + +/*! + This function sets the open error state of the database to \a + error. Derived classes can use this function to report the status + of open(). Note that if \a error is true the open state of the + database is set to closed (i.e., isOpen() returns \c false). + + \sa open(), setOpen() +*/ + +void QSqlDriver::setOpenError(bool error) +{ + Q_D(QSqlDriver); + d->isOpenError = error; + if (error) + d->isOpen = false; +} + +/*! + This function is called to begin a transaction. If successful, + return true, otherwise return false. The default implementation + does nothing and returns \c false. + + \sa commitTransaction(), rollbackTransaction() +*/ + +bool QSqlDriver::beginTransaction() +{ + return false; +} + +/*! + This function is called to commit a transaction. If successful, + return true, otherwise return false. The default implementation + does nothing and returns \c false. + + \sa beginTransaction(), rollbackTransaction() +*/ + +bool QSqlDriver::commitTransaction() +{ + return false; +} + +/*! + This function is called to rollback a transaction. If successful, + return true, otherwise return false. The default implementation + does nothing and returns \c false. + + \sa beginTransaction(), commitTransaction() +*/ + +bool QSqlDriver::rollbackTransaction() +{ + return false; +} + +/*! + This function is used to set the value of the last error, \a error, + that occurred on the database. + + \sa lastError() +*/ + +void QSqlDriver::setLastError(const QSqlError &error) +{ + Q_D(QSqlDriver); + d->error = error; +} + +/*! + Returns a QSqlError object which contains information about the + last error that occurred on the database. +*/ + +QSqlError QSqlDriver::lastError() const +{ + Q_D(const QSqlDriver); + return d->error; +} + +/*! + Returns a list of the names of the tables in the database. The + default implementation returns an empty list. + + The \a tableType argument describes what types of tables + should be returned. Due to binary compatibility, the string + contains the value of the enum QSql::TableTypes as text. + An empty string should be treated as QSql::Tables for + backward compatibility. +*/ + +QStringList QSqlDriver::tables(QSql::TableType) const +{ + return QStringList(); +} + +/*! + Returns the primary index for table \a tableName. Returns an empty + QSqlIndex if the table doesn't have a primary index. The default + implementation returns an empty index. +*/ + +QSqlIndex QSqlDriver::primaryIndex(const QString&) const +{ + return QSqlIndex(); +} + + +/*! + Returns a QSqlRecord populated with the names of the fields in + table \a tableName. If no such table exists, an empty record is + returned. The default implementation returns an empty record. +*/ + +QSqlRecord QSqlDriver::record(const QString & /* tableName */) const +{ + return QSqlRecord(); +} + +/*! + Returns the \a identifier escaped according to the database rules. + \a identifier can either be a table name or field name, dependent + on \a type. + + The default implementation does nothing. + \sa isIdentifierEscaped() + */ +QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const +{ + return identifier; +} + +/*! + Returns whether \a identifier is escaped according to the database rules. + \a identifier can either be a table name or field name, dependent + on \a type. + + Reimplement this function if you want to provide your own implementation in your + QSqlDriver subclass, + + \sa stripDelimiters(), escapeIdentifier() + */ +bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const +{ + Q_UNUSED(type); + return identifier.size() > 2 + && identifier.startsWith(QLatin1Char('"')) //left delimited + && identifier.endsWith(QLatin1Char('"')); //right delimited +} + +/*! + Returns the \a identifier with the leading and trailing delimiters removed, + \a identifier can either be a table name or field name, + dependent on \a type. If \a identifier does not have leading + and trailing delimiter characters, \a identifier is returned without + modification. + + Reimplement this function if you want to provide your own implementation in your + QSqlDriver subclass, + + \since 4.5 + \sa isIdentifierEscaped() + */ +QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const +{ + QString ret; + if (isIdentifierEscaped(identifier, type)) { + ret = identifier.mid(1); + ret.chop(1); + } else { + ret = identifier; + } + return ret; +} + +/*! + Returns a SQL statement of type \a type for the table \a tableName + with the values from \a rec. If \a preparedStatement is true, the + string will contain placeholders instead of values. + + The generated flag in each field of \a rec determines whether the + field is included in the generated statement. + + This method can be used to manipulate tables without having to worry + about database-dependent SQL dialects. For non-prepared statements, + the values will be properly escaped. + + In the WHERE statement, each non-null field of \a rec specifies a + filter condition of equality to the field value, or if prepared, a + placeholder. However, prepared or not, a null field specifies the + condition IS NULL and never introduces a placeholder. The + application must not attempt to bind data for the null field during + execution. The field must be set to some non-null value if a + placeholder is desired. Furthermore, since non-null fields specify + equality conditions and SQL NULL is not equal to anything, even + itself, it is generally not useful to bind a null to a placeholder. + +*/ +QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, + const QSqlRecord &rec, bool preparedStatement) const +{ + int i; + QString s; + s.reserve(128); + switch (type) { + case SelectStatement: + for (i = 0; i < rec.count(); ++i) { + if (rec.isGenerated(i)) + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + } + if (s.isEmpty()) + return s; + s.chop(2); + s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); + break; + case WhereStatement: + { + const QString tableNamePrefix = tableName.isEmpty() + ? QString() + : prepareIdentifier(tableName, QSqlDriver::TableName, this) + QLatin1Char('.'); + for (int i = 0; i < rec.count(); ++i) { + if (!rec.isGenerated(i)) + continue; + s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND ")); + s.append(tableNamePrefix); + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); + if (rec.isNull(i)) + s.append(QLatin1String(" IS NULL")); + else if (preparedStatement) + s.append(QLatin1String(" = ?")); + else + s.append(QLatin1String(" = ")).append(formatValue(rec.field(i))); + } + break; + } + case UpdateStatement: + s.append(QLatin1String("UPDATE ")).append(tableName).append( + QLatin1String(" SET ")); + for (i = 0; i < rec.count(); ++i) { + if (!rec.isGenerated(i)) + continue; + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); + if (preparedStatement) + s.append(QLatin1Char('?')); + else + s.append(formatValue(rec.field(i))); + s.append(QLatin1String(", ")); + } + if (s.endsWith(QLatin1String(", "))) + s.chop(2); + else + s.clear(); + break; + case DeleteStatement: + s.append(QLatin1String("DELETE FROM ")).append(tableName); + break; + case InsertStatement: { + s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); + QString vals; + for (i = 0; i < rec.count(); ++i) { + if (!rec.isGenerated(i)) + continue; + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + if (preparedStatement) + vals.append(QLatin1Char('?')); + else + vals.append(formatValue(rec.field(i))); + vals.append(QLatin1String(", ")); + } + if (vals.isEmpty()) { + s.clear(); + } else { + vals.chop(2); // remove trailing comma + s[s.length() - 2] = QLatin1Char(')'); + s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')')); + } + break; } + } + return s; +} + +/*! + Returns a string representation of the \a field value for the + database. This is used, for example, when constructing INSERT and + UPDATE statements. + + The default implementation returns the value formatted as a string + according to the following rules: + + \list + + \li If \a field is character data, the value is returned enclosed + in single quotation marks, which is appropriate for many SQL + databases. Any embedded single-quote characters are escaped + (replaced with two single-quote characters). If \a trimStrings is + true (the default is false), all trailing whitespace is trimmed + from the field. + + \li If \a field is date/time data, the value is formatted in ISO + format and enclosed in single quotation marks. If the date/time + data is invalid, "NULL" is returned. + + \li If \a field is \l{QByteArray}{bytearray} data, and the + driver can edit binary fields, the value is formatted as a + hexadecimal string. + + \li For any other field type, toString() is called on its value + and the result of this is returned. + + \endlist + + \sa QVariant::toString() + +*/ +QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const +{ + const QLatin1String nullTxt("NULL"); + + QString r; + if (field.isNull()) + r = nullTxt; + else { + switch (field.type()) { + case QVariant::Int: + case QVariant::UInt: + if (field.value().type() == QVariant::Bool) + r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); + else + r = field.value().toString(); + break; +#ifndef QT_NO_DATESTRING + case QVariant::Date: + if (field.value().toDate().isValid()) + r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) + + QLatin1Char('\''); + else + r = nullTxt; + break; + case QVariant::Time: + if (field.value().toTime().isValid()) + r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + + QLatin1Char('\''); + else + r = nullTxt; + break; + case QVariant::DateTime: + if (field.value().toDateTime().isValid()) + r = QLatin1Char('\'') + + field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); + else + r = nullTxt; + break; +#endif + case QVariant::String: + case QVariant::Char: + { + QString result = field.value().toString(); + if (trimStrings) { + int end = result.length(); + while (end && result.at(end-1).isSpace()) /* skip white space from end */ + end--; + result.truncate(end); + } + /* escape the "'" character */ + result.replace(QLatin1Char('\''), QLatin1String("''")); + r = QLatin1Char('\'') + result + QLatin1Char('\''); + break; + } + case QVariant::Bool: + r = QString::number(field.value().toBool()); + break; + case QVariant::ByteArray : { + if (hasFeature(BLOB)) { + QByteArray ba = field.value().toByteArray(); + QString res; + static const char hexchars[] = "0123456789abcdef"; + for (int i = 0; i < ba.size(); ++i) { + uchar s = (uchar) ba[i]; + res += QLatin1Char(hexchars[s >> 4]); + res += QLatin1Char(hexchars[s & 0x0f]); + } + r = QLatin1Char('\'') + res + QLatin1Char('\''); + break; + } + } + default: + r = field.value().toString(); + break; + } + } + return r; +} + +/*! + Returns the low-level database handle wrapped in a QVariant or an + invalid variant if there is no handle. + + \warning Use this with uttermost care and only if you know what you're doing. + + \warning The handle returned here can become a stale pointer if the connection + is modified (for example, if you close the connection). + + \warning The handle can be NULL if the connection is not open yet. + + The handle returned here is database-dependent, you should query the type + name of the variant before accessing it. + + This example retrieves the handle for a connection to sqlite: + + \snippet code/src_sql_kernel_qsqldriver.cpp 0 + + This snippet returns the handle for PostgreSQL or MySQL: + + \snippet code/src_sql_kernel_qsqldriver.cpp 1 + + \sa QSqlResult::handle() +*/ +QVariant QSqlDriver::handle() const +{ + return QVariant(); +} + +/*! + This function is called to subscribe to event notifications from the database. + \a name identifies the event notification. + + If successful, return true, otherwise return false. + + The database must be open when this function is called. When the database is closed + by calling close() all subscribed event notifications are automatically unsubscribed. + Note that calling open() on an already open database may implicitly cause close() to + be called, which will cause the driver to unsubscribe from all event notifications. + + When an event notification identified by \a name is posted by the database the + notification() signal is emitted. + + Reimplement this function if you want to provide event notification support in your + own QSqlDriver subclass, + + \since 4.4 + \sa unsubscribeFromNotification(), subscribedToNotifications(), QSqlDriver::hasFeature() +*/ +bool QSqlDriver::subscribeToNotification(const QString &name) +{ + Q_UNUSED(name); + return false; +} + +/*! + This function is called to unsubscribe from event notifications from the database. + \a name identifies the event notification. + + If successful, return true, otherwise return false. + + The database must be open when this function is called. All subscribed event + notifications are automatically unsubscribed from when the close() function is called. + + After calling \e this function the notification() signal will no longer be emitted + when an event notification identified by \a name is posted by the database. + + Reimplement this function if you want to provide event notification support in your + own QSqlDriver subclass, + + \since 4.4 + \sa subscribeToNotification(), subscribedToNotifications() +*/ +bool QSqlDriver::unsubscribeFromNotification(const QString &name) +{ + Q_UNUSED(name); + return false; +} + +/*! + Returns a list of the names of the event notifications that are currently subscribed to. + + Reimplement this function if you want to provide event notification support in your + own QSqlDriver subclass, + + \since 4.4 + \sa subscribeToNotification(), unsubscribeFromNotification() +*/ +QStringList QSqlDriver::subscribedToNotifications() const +{ + return QStringList(); +} + +/*! + \since 4.6 + + Sets the default numerical precision policy used by queries created + by this driver to \a precisionPolicy. + + Note: Setting the default precision policy to \a precisionPolicy + doesn't affect any currently active queries. + + \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(), + QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy() +*/ +void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) +{ + Q_D(QSqlDriver); + d->precisionPolicy = precisionPolicy; +} + +/*! + \since 4.6 + + Returns the current default precision policy for the database connection. + + \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(), + QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy() +*/ +QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const +{ + Q_D(const QSqlDriver); + return d->precisionPolicy; +} + +/*! + \since 5.4 + + Returns the current DBMS type for the database connection. +*/ +QSqlDriver::DbmsType QSqlDriver::dbmsType() const +{ + Q_D(const QSqlDriver); + return d->dbmsType; +} + +/*! + \since 5.0 + \internal + + Tries to cancel the running query, if the underlying driver has the + capability to cancel queries. Returns \c true on success, otherwise false. + + This function can be called from a different thread. + + If you use this function as a slot, you need to use a Qt::DirectConnection + from a different thread. + + Reimplement this function to support canceling running queries in + your own QSqlDriver subclass. It must be implemented in a thread-safe + manner. + + \sa QSqlDriver::hasFeature() +*/ +bool QSqlDriver::cancelQuery() +{ + return false; +} + +QT_END_NAMESPACE From 02db75c492c6e89f5d17f4eab05c648fd5375500 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:41:26 -0400 Subject: [PATCH 0968/1324] Delete qsql.h --- src/qt/qsql.h | 96 --------------------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 src/qt/qsql.h diff --git a/src/qt/qsql.h b/src/qt/qsql.h deleted file mode 100644 index 02ebae7a..00000000 --- a/src/qt/qsql.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQL_H -#define QSQL_H - -#include - -QT_BEGIN_NAMESPACE - -#ifndef QT_STATIC -# if defined(QT_BUILD_SQL_LIB) -# define Q_SQL_EXPORT Q_DECL_EXPORT -# else -# define Q_SQL_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_SQL_EXPORT -#endif - -namespace QSql -{ - enum Location - { - BeforeFirstRow = -1, - AfterLastRow = -2 - }; - - enum ParamTypeFlag - { - In = 0x00000001, - Out = 0x00000002, - InOut = In | Out, - Binary = 0x00000004 - }; - Q_DECLARE_FLAGS(ParamType, ParamTypeFlag) - - enum TableType - { - Tables = 0x01, - SystemTables = 0x02, - Views = 0x04, - AllTables = 0xff - }; - - enum NumericalPrecisionPolicy - { - LowPrecisionInt32 = 0x01, - LowPrecisionInt64 = 0x02, - LowPrecisionDouble = 0x04, - - HighPrecision = 0 - }; -} - -Q_DECLARE_OPERATORS_FOR_FLAGS(QSql::ParamType) - -QT_END_NAMESPACE - -#endif // QSQL_H From fb591d057200957b57b7718bd320c99e045cf6ac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:41:43 -0400 Subject: [PATCH 0969/1324] Delete qsqldatabase.cpp --- src/qt/qsqldatabase.cpp | 1528 --------------------------------------- 1 file changed, 1528 deletions(-) delete mode 100644 src/qt/qsqldatabase.cpp diff --git a/src/qt/qsqldatabase.cpp b/src/qt/qsqldatabase.cpp deleted file mode 100644 index 62e1b6a7..00000000 --- a/src/qt/qsqldatabase.cpp +++ /dev/null @@ -1,1528 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsqldatabase.h" -#include "qsqlquery.h" - -#ifdef Q_OS_WIN32 -// Conflicting declarations of LPCBYTE in sqlfront.h and winscard.h -#define _WINSCARD_H_ -#endif - -#ifdef QT_SQL_PSQL -#include "../drivers/psql/qsql_psql_p.h" -#endif -#ifdef QT_SQL_MYSQL -#include "../drivers/mysql/qsql_mysql_p.h" -#endif -#ifdef QT_SQL_ODBC -#include "../drivers/odbc/qsql_odbc_p.h" -#endif -#ifdef QT_SQL_OCI -#include "../drivers/oci/qsql_oci_p.h" -#endif -#ifdef QT_SQL_TDS -// conflicting RETCODE typedef between odbc and freetds -#define RETCODE DBRETCODE -#include "../drivers/tds/qsql_tds_p.h" -#undef RETCODE -#endif -#ifdef QT_SQL_DB2 -#include "../drivers/db2/qsql_db2_p.h" -#endif -#ifdef QT_SQL_SQLITE -#include "../drivers/sqlite/qsql_sqlite_p.h" -#endif -#ifdef QT_SQL_SQLITE2 -#include "../drivers/sqlite2/qsql_sqlite2_p.h" -#endif -#ifdef QT_SQL_IBASE -#undef SQL_FLOAT // avoid clash with ODBC -#undef SQL_DOUBLE -#undef SQL_TIMESTAMP -#undef SQL_TYPE_TIME -#undef SQL_TYPE_DATE -#undef SQL_DATE -#define SCHAR IBASE_SCHAR // avoid clash with ODBC (older versions of ibase.h with Firebird) -#include "../drivers/ibase/qsql_ibase_p.h" -#undef SCHAR -#endif - -#include "qdebug.h" -#include "qcoreapplication.h" -#include "qreadwritelock.h" -#include "qsqlresult.h" -#include "qsqldriver.h" -#include "qsqldriverplugin.h" -#include "qsqlindex.h" -#include "private/qfactoryloader_p.h" -#include "private/qsqlnulldriver_p.h" -#include "qmutex.h" -#include "qhash.h" -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QSqlDriverFactoryInterface_iid, - QLatin1String("/sqldrivers"))) - -#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900 -// ### Qt6: remove the #ifdef -const -#endif -char *QSqlDatabase::defaultConnection = const_cast("qt_sql_default_connection"); - -typedef QHash DriverDict; - -class QConnectionDict: public QHash -{ -public: - inline bool contains_ts(const QString &key) - { - QReadLocker locker(&lock); - return contains(key); - } - inline QStringList keys_ts() const - { - QReadLocker locker(&lock); - return keys(); - } - - mutable QReadWriteLock lock; -}; -Q_GLOBAL_STATIC(QConnectionDict, dbDict) - -class QSqlDatabasePrivate -{ -public: - QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = 0): - ref(1), - q(d), - driver(dr), - port(-1) - { - precisionPolicy = QSql::LowPrecisionDouble; - } - QSqlDatabasePrivate(const QSqlDatabasePrivate &other); - ~QSqlDatabasePrivate(); - void init(const QString& type); - void copy(const QSqlDatabasePrivate *other); - void disable(); - - QAtomicInt ref; - QSqlDatabase *q; - QSqlDriver* driver; - QString dbname; - QString uname; - QString pword; - QString hname; - QString drvName; - int port; - QString connOptions; - QString connName; - QSql::NumericalPrecisionPolicy precisionPolicy; - - static QSqlDatabasePrivate *shared_null(); - static QSqlDatabase database(const QString& name, bool open); - static void addDatabase(const QSqlDatabase &db, const QString & name); - static void removeDatabase(const QString& name); - static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn = true); - static DriverDict &driverDict(); - static void cleanConnections(); -}; - -QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref(1) -{ - q = other.q; - dbname = other.dbname; - uname = other.uname; - pword = other.pword; - hname = other.hname; - drvName = other.drvName; - port = other.port; - connOptions = other.connOptions; - driver = other.driver; - precisionPolicy = other.precisionPolicy; -} - -QSqlDatabasePrivate::~QSqlDatabasePrivate() -{ - if (driver != shared_null()->driver) - delete driver; -} - -void QSqlDatabasePrivate::cleanConnections() -{ - QConnectionDict *dict = dbDict(); - Q_ASSERT(dict); - QWriteLocker locker(&dict->lock); - - QConnectionDict::iterator it = dict->begin(); - while (it != dict->end()) { - invalidateDb(it.value(), it.key(), false); - ++it; - } - dict->clear(); -} - -static bool qDriverDictInit = false; -static void cleanDriverDict() -{ - qDeleteAll(QSqlDatabasePrivate::driverDict()); - QSqlDatabasePrivate::driverDict().clear(); - QSqlDatabasePrivate::cleanConnections(); - qDriverDictInit = false; -} - -DriverDict &QSqlDatabasePrivate::driverDict() -{ - static DriverDict dict; - if (!qDriverDictInit) { - qDriverDictInit = true; - qAddPostRoutine(cleanDriverDict); - } - return dict; -} - -QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null() -{ - static QSqlNullDriver dr; - static QSqlDatabasePrivate n(NULL, &dr); - return &n; -} - -void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn) -{ - if (db.d->ref.load() != 1 && doWarn) { - qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, " - "all queries will cease to work.", name.toLocal8Bit().constData()); - db.d->disable(); - db.d->connName.clear(); - } -} - -void QSqlDatabasePrivate::removeDatabase(const QString &name) -{ - QConnectionDict *dict = dbDict(); - Q_ASSERT(dict); - QWriteLocker locker(&dict->lock); - - if (!dict->contains(name)) - return; - - invalidateDb(dict->take(name), name); -} - -void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &name) -{ - QConnectionDict *dict = dbDict(); - Q_ASSERT(dict); - QWriteLocker locker(&dict->lock); - - if (dict->contains(name)) { - invalidateDb(dict->take(name), name); - qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old " - "connection removed.", name.toLocal8Bit().data()); - } - dict->insert(name, db); - db.d->connName = name; -} - -/*! \internal -*/ -QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open) -{ - const QConnectionDict *dict = dbDict(); - Q_ASSERT(dict); - - dict->lock.lockForRead(); - QSqlDatabase db = dict->value(name); - dict->lock.unlock(); - if (db.isValid() && !db.isOpen() && open) { - if (!db.open()) - qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text(); - - } - return db; -} - - -/*! \internal - Copies the connection data from \a other. -*/ -void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other) -{ - q = other->q; - dbname = other->dbname; - uname = other->uname; - pword = other->pword; - hname = other->hname; - drvName = other->drvName; - port = other->port; - connOptions = other->connOptions; - precisionPolicy = other->precisionPolicy; -} - -void QSqlDatabasePrivate::disable() -{ - if (driver != shared_null()->driver) { - delete driver; - driver = shared_null()->driver; - } -} - -/*! - \class QSqlDriverCreatorBase - \brief The QSqlDriverCreatorBase class is the base class for - SQL driver factories. - - \ingroup database - \inmodule QtSql - - Reimplement createObject() to return an instance of the specific - QSqlDriver subclass that you want to provide. - - See QSqlDatabase::registerSqlDriver() for details. - - \sa QSqlDriverCreator -*/ - -/*! - \fn QSqlDriverCreatorBase::~QSqlDriverCreatorBase() - - Destroys the SQL driver creator object. -*/ - -/*! - \fn QSqlDriver *QSqlDriverCreatorBase::createObject() const - - Reimplement this function to returns a new instance of a - QSqlDriver subclass. -*/ - -/*! - \class QSqlDriverCreator - \brief The QSqlDriverCreator class is a template class that - provides a SQL driver factory for a specific driver type. - - \ingroup database - \inmodule QtSql - - QSqlDriverCreator instantiates objects of type T, where T is a - QSqlDriver subclass. - - See QSqlDatabase::registerSqlDriver() for details. -*/ - -/*! - \fn QSqlDriver *QSqlDriverCreator::createObject() const - \reimp -*/ - -/*! - \class QSqlDatabase - \brief The QSqlDatabase class represents a connection to - a database. - - \ingroup database - - \inmodule QtSql - - The QSqlDatabase class provides an interface for accessing a - database through a connection. An instance of QSqlDatabase - represents the connection. The connection provides access to the - database via one of the \l{SQL Database Drivers#Supported - Databases} {supported database drivers}, which are derived from - QSqlDriver. Alternatively, you can subclass your own database - driver from QSqlDriver. See \l{How to Write Your Own Database - Driver} for more information. - - Create a connection (i.e., an instance of QSqlDatabase) by calling - one of the static addDatabase() functions, where you specify - \l{SQL Database Drivers#Supported Databases} {the driver or type - of driver} to use (i.e., what kind of database will you access?) - and a connection name. A connection is known by its own name, - \e{not} by the name of the database it connects to. You can have - multiple connections to one database. QSqlDatabase also supports - the concept of a \e{default} connection, which is the unnamed - connection. To create the default connection, don't pass the - connection name argument when you call addDatabase(). - Subsequently, when you call any static member function that takes - the connection name argument, if you don't pass the connection - name argument, the default connection is assumed. The following - snippet shows how to create and open a default connection to a - PostgreSQL database: - - \snippet sqldatabase/sqldatabase.cpp 0 - - Once the QSqlDatabase object has been created, set the connection - parameters with setDatabaseName(), setUserName(), setPassword(), - setHostName(), setPort(), and setConnectOptions(). Then call - open() to activate the physical connection to the database. The - connection is not usable until you open it. - - The connection defined above will be the \e{default} connection, - because we didn't give a connection name to \l{QSqlDatabase::} - {addDatabase()}. Subsequently, you can get the default connection - by calling database() without the connection name argument: - - \snippet sqldatabase/sqldatabase.cpp 1 - - QSqlDatabase is a value class. Changes made to a database - connection via one instance of QSqlDatabase will affect other - instances of QSqlDatabase that represent the same connection. Use - cloneDatabase() to create an independent database connection based - on an existing one. - - If you create multiple database connections, specify a unique - connection name for each one, when you call addDatabase(). Use - database() with a connection name to get that connection. Use - removeDatabase() with a connection name to remove a connection. - QSqlDatabase outputs a warning if you try to remove a connection - referenced by other QSqlDatabase objects. Use contains() to see if - a given connection name is in the list of connections. - - Once a connection is established, you can call tables() to get the - list of tables in the database, call primaryIndex() to get a - table's primary index, and call record() to get meta-information - about a table's fields (e.g., field names). - - \note QSqlDatabase::exec() is deprecated. Use QSqlQuery::exec() - instead. - - If the driver supports transactions, use transaction() to start a - transaction, and commit() or rollback() to complete it. Use - \l{QSqlDriver::} {hasFeature()} to ask if the driver supports - transactions. \note When using transactions, you must start the - transaction before you create your query. - - If an error occurs, lastError() will return information about it. - - Get the names of the available SQL drivers with drivers(). Check - for the presence of a particular driver with isDriverAvailable(). - If you have created your own custom driver, you must register it - with registerSqlDriver(). - - \sa QSqlDriver, QSqlQuery, {Qt SQL}, {Threads and the SQL Module} -*/ - -/*! \fn QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName) - \threadsafe - - Adds a database to the list of database connections using the - driver \a type and the connection name \a connectionName. If - there already exists a database connection called \a - connectionName, that connection is removed. - - The database connection is referred to by \a connectionName. The - newly added database connection is returned. - - If \a type is not available or could not be loaded, isValid() returns \c false. - - If \a connectionName is not specified, the new connection becomes - the default connection for the application, and subsequent calls - to database() without the connection name argument will return the - default connection. If a \a connectionName is provided here, use - database(\a connectionName) to retrieve the connection. - - \warning If you add a connection with the same name as an existing - connection, the new connection replaces the old one. If you call - this function more than once without specifying \a connectionName, - the default connection will be the one replaced. - - Before using the connection, it must be initialized. e.g., call - some or all of setDatabaseName(), setUserName(), setPassword(), - setHostName(), setPort(), and setConnectOptions(), and, finally, - open(). - - \sa database(), removeDatabase(), {Threads and the SQL Module} -*/ -QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName) -{ - QSqlDatabase db(type); - QSqlDatabasePrivate::addDatabase(db, connectionName); - return db; -} - -/*! - \threadsafe - - Returns the database connection called \a connectionName. The - database connection must have been previously added with - addDatabase(). If \a open is true (the default) and the database - connection is not already open it is opened now. If no \a - connectionName is specified the default connection is used. If \a - connectionName does not exist in the list of databases, an invalid - connection is returned. - - \sa isOpen(), {Threads and the SQL Module} -*/ - -QSqlDatabase QSqlDatabase::database(const QString& connectionName, bool open) -{ - return QSqlDatabasePrivate::database(connectionName, open); -} - -/*! - \threadsafe - - Removes the database connection \a connectionName from the list of - database connections. - - \warning There should be no open queries on the database - connection when this function is called, otherwise a resource leak - will occur. - - Example: - - \snippet code/src_sql_kernel_qsqldatabase.cpp 0 - - The correct way to do it: - - \snippet code/src_sql_kernel_qsqldatabase.cpp 1 - - To remove the default connection, which may have been created with a - call to addDatabase() not specifying a connection name, you can - retrieve the default connection name by calling connectionName() on - the database returned by database(). Note that if a default database - hasn't been created an invalid database will be returned. - - \sa database(), connectionName(), {Threads and the SQL Module} -*/ - -void QSqlDatabase::removeDatabase(const QString& connectionName) -{ - QSqlDatabasePrivate::removeDatabase(connectionName); -} - -/*! - Returns a list of all the available database drivers. - - \sa registerSqlDriver() -*/ - -QStringList QSqlDatabase::drivers() -{ - QStringList list; - -#ifdef QT_SQL_PSQL - list << QLatin1String("QPSQL7"); - list << QLatin1String("QPSQL"); -#endif -#ifdef QT_SQL_MYSQL - list << QLatin1String("QMYSQL3"); - list << QLatin1String("QMYSQL"); -#endif -#ifdef QT_SQL_ODBC - list << QLatin1String("QODBC3"); - list << QLatin1String("QODBC"); -#endif -#ifdef QT_SQL_OCI - list << QLatin1String("QOCI8"); - list << QLatin1String("QOCI"); -#endif -#ifdef QT_SQL_TDS - list << QLatin1String("QTDS7"); - list << QLatin1String("QTDS"); -#endif -#ifdef QT_SQL_DB2 - list << QLatin1String("QDB2"); -#endif -#ifdef QT_SQL_SQLITE - list << QLatin1String("QSQLITE"); -#endif -#ifdef QT_SQL_SQLITE2 - list << QLatin1String("QSQLITE2"); -#endif -#ifdef QT_SQL_IBASE - list << QLatin1String("QIBASE"); -#endif - - if (QFactoryLoader *fl = loader()) { - typedef QMultiMap PluginKeyMap; - typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; - - const PluginKeyMap keyMap = fl->keyMap(); - const PluginKeyMapConstIterator cend = keyMap.constEnd(); - for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) - if (!list.contains(it.value())) - list << it.value(); - } - - DriverDict dict = QSqlDatabasePrivate::driverDict(); - for (DriverDict::const_iterator i = dict.constBegin(); i != dict.constEnd(); ++i) { - if (!list.contains(i.key())) - list << i.key(); - } - - return list; -} - -/*! - This function registers a new SQL driver called \a name, within - the SQL framework. This is useful if you have a custom SQL driver - and don't want to compile it as a plugin. - - Example: - \snippet code/src_sql_kernel_qsqldatabase.cpp 2 - - QSqlDatabase takes ownership of the \a creator pointer, so you - mustn't delete it yourself. - - \sa drivers() -*/ -void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase *creator) -{ - delete QSqlDatabasePrivate::driverDict().take(name); - if (creator) - QSqlDatabasePrivate::driverDict().insert(name, creator); -} - -/*! - \threadsafe - - Returns \c true if the list of database connections contains \a - connectionName; otherwise returns \c false. - - \sa connectionNames(), database(), {Threads and the SQL Module} -*/ - -bool QSqlDatabase::contains(const QString& connectionName) -{ - return dbDict()->contains_ts(connectionName); -} - -/*! - \threadsafe - - Returns a list containing the names of all connections. - - \sa contains(), database(), {Threads and the SQL Module} -*/ -QStringList QSqlDatabase::connectionNames() -{ - return dbDict()->keys_ts(); -} - -/*! - \overload - - Creates a QSqlDatabase connection that uses the driver referred - to by \a type. If the \a type is not recognized, the database - connection will have no functionality. - - The currently available driver types are: - - \table - \header \li Driver Type \li Description - \row \li QDB2 \li IBM DB2 - \row \li QIBASE \li Borland InterBase Driver - \row \li QMYSQL \li MySQL Driver - \row \li QOCI \li Oracle Call Interface Driver - \row \li QODBC \li ODBC Driver (includes Microsoft SQL Server) - \row \li QPSQL \li PostgreSQL Driver - \row \li QSQLITE \li SQLite version 3 or above - \row \li QSQLITE2 \li SQLite version 2 - \row \li QTDS \li Sybase Adaptive Server - \endtable - - Additional third party drivers, including your own custom - drivers, can be loaded dynamically. - - \sa {SQL Database Drivers}, registerSqlDriver(), drivers() -*/ - -QSqlDatabase::QSqlDatabase(const QString &type) -{ - d = new QSqlDatabasePrivate(this); - d->init(type); -} - -/*! - \overload - - Creates a database connection using the given \a driver. -*/ - -QSqlDatabase::QSqlDatabase(QSqlDriver *driver) -{ - d = new QSqlDatabasePrivate(this, driver); -} - -/*! - Creates an empty, invalid QSqlDatabase object. Use addDatabase(), - removeDatabase(), and database() to get valid QSqlDatabase - objects. -*/ -QSqlDatabase::QSqlDatabase() -{ - d = QSqlDatabasePrivate::shared_null(); - d->ref.ref(); -} - -/*! - Creates a copy of \a other. -*/ -QSqlDatabase::QSqlDatabase(const QSqlDatabase &other) -{ - d = other.d; - d->ref.ref(); -} - -/*! - Assigns \a other to this object. -*/ -QSqlDatabase &QSqlDatabase::operator=(const QSqlDatabase &other) -{ - qAtomicAssign(d, other.d); - return *this; -} - -/*! - \internal - - Create the actual driver instance \a type. -*/ - -void QSqlDatabasePrivate::init(const QString &type) -{ - drvName = type; - - if (!driver) { -#ifdef QT_SQL_PSQL - if (type == QLatin1String("QPSQL") || type == QLatin1String("QPSQL7")) - driver = new QPSQLDriver(); -#endif -#ifdef QT_SQL_MYSQL - if (type == QLatin1String("QMYSQL") || type == QLatin1String("QMYSQL3")) - driver = new QMYSQLDriver(); -#endif -#ifdef QT_SQL_ODBC - if (type == QLatin1String("QODBC") || type == QLatin1String("QODBC3")) - driver = new QODBCDriver(); -#endif -#ifdef QT_SQL_OCI - if (type == QLatin1String("QOCI") || type == QLatin1String("QOCI8")) - driver = new QOCIDriver(); -#endif -#ifdef QT_SQL_TDS - if (type == QLatin1String("QTDS") || type == QLatin1String("QTDS7")) - driver = new QTDSDriver(); -#endif -#ifdef QT_SQL_DB2 - if (type == QLatin1String("QDB2")) - driver = new QDB2Driver(); -#endif -#ifdef QT_SQL_SQLITE - if (type == QLatin1String("QSQLITE")) - driver = new QSQLiteDriver(); -#endif -#ifdef QT_SQL_SQLITE2 - if (type == QLatin1String("QSQLITE2")) - driver = new QSQLite2Driver(); -#endif -#ifdef QT_SQL_IBASE - if (type == QLatin1String("QIBASE")) - driver = new QIBaseDriver(); -#endif - } - - if (!driver) { - DriverDict dict = QSqlDatabasePrivate::driverDict(); - for (DriverDict::const_iterator it = dict.constBegin(); - it != dict.constEnd() && !driver; ++it) { - if (type == it.key()) { - driver = ((QSqlDriverCreatorBase*)(*it))->createObject(); - } - } - } - - if (!driver && loader()) - driver = qLoadPlugin(loader(), type); - - if (!driver) { - qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data()); - qWarning("QSqlDatabase: available drivers: %s", - QSqlDatabase::drivers().join(QLatin1Char(' ')).toLatin1().data()); - if (QCoreApplication::instance() == 0) - qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins"); - driver = shared_null()->driver; - } -} - -/*! - Destroys the object and frees any allocated resources. - - \sa close() -*/ - -QSqlDatabase::~QSqlDatabase() -{ - if (!d->ref.deref()) { - close(); - delete d; - } -} - -/*! - Executes a SQL statement on the database and returns a QSqlQuery - object. Use lastError() to retrieve error information. If \a - query is empty, an empty, invalid query is returned and - lastError() is not affected. - - \sa QSqlQuery, lastError() -*/ - -QSqlQuery QSqlDatabase::exec(const QString & query) const -{ - QSqlQuery r(d->driver->createResult()); - if (!query.isEmpty()) { - r.exec(query); - d->driver->setLastError(r.lastError()); - } - return r; -} - -/*! - Opens the database connection using the current connection - values. Returns \c true on success; otherwise returns \c false. Error - information can be retrieved using lastError(). - - \sa lastError(), setDatabaseName(), setUserName(), setPassword(), - setHostName(), setPort(), setConnectOptions() -*/ - -bool QSqlDatabase::open() -{ - return d->driver->open(d->dbname, d->uname, d->pword, d->hname, - d->port, d->connOptions); -} - -/*! - \overload - - Opens the database connection using the given \a user name and \a - password. Returns \c true on success; otherwise returns \c false. Error - information can be retrieved using the lastError() function. - - This function does not store the password it is given. Instead, - the password is passed directly to the driver for opening the - connection and it is then discarded. - - \sa lastError() -*/ - -bool QSqlDatabase::open(const QString& user, const QString& password) -{ - setUserName(user); - return d->driver->open(d->dbname, user, password, d->hname, - d->port, d->connOptions); -} - -/*! - Closes the database connection, freeing any resources acquired, and - invalidating any existing QSqlQuery objects that are used with the - database. - - This will also affect copies of this QSqlDatabase object. - - \sa removeDatabase() -*/ - -void QSqlDatabase::close() -{ - d->driver->close(); -} - -/*! - Returns \c true if the database connection is currently open; - otherwise returns \c false. -*/ - -bool QSqlDatabase::isOpen() const -{ - return d->driver->isOpen(); -} - -/*! - Returns \c true if there was an error opening the database - connection; otherwise returns \c false. Error information can be - retrieved using the lastError() function. -*/ - -bool QSqlDatabase::isOpenError() const -{ - return d->driver->isOpenError(); -} - -/*! - Begins a transaction on the database if the driver supports - transactions. Returns \c{true} if the operation succeeded. - Otherwise it returns \c{false}. - - \sa QSqlDriver::hasFeature(), commit(), rollback() -*/ -bool QSqlDatabase::transaction() -{ - if (!d->driver->hasFeature(QSqlDriver::Transactions)) - return false; - return d->driver->beginTransaction(); -} - -/*! - Commits a transaction to the database if the driver supports - transactions and a transaction() has been started. Returns \c{true} - if the operation succeeded. Otherwise it returns \c{false}. - - \note For some databases, the commit will fail and return \c{false} - if there is an \l{QSqlQuery::isActive()} {active query} using the - database for a \c{SELECT}. Make the query \l{QSqlQuery::isActive()} - {inactive} before doing the commit. - - Call lastError() to get information about errors. - - \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), rollback() -*/ -bool QSqlDatabase::commit() -{ - if (!d->driver->hasFeature(QSqlDriver::Transactions)) - return false; - return d->driver->commitTransaction(); -} - -/*! - Rolls back a transaction on the database, if the driver supports - transactions and a transaction() has been started. Returns \c{true} - if the operation succeeded. Otherwise it returns \c{false}. - - \note For some databases, the rollback will fail and return - \c{false} if there is an \l{QSqlQuery::isActive()} {active query} - using the database for a \c{SELECT}. Make the query - \l{QSqlQuery::isActive()} {inactive} before doing the rollback. - - Call lastError() to get information about errors. - - \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), commit() -*/ -bool QSqlDatabase::rollback() -{ - if (!d->driver->hasFeature(QSqlDriver::Transactions)) - return false; - return d->driver->rollbackTransaction(); -} - -/*! - Sets the connection's database name to \a name. To have effect, - the database name must be set \e{before} the connection is - \l{open()} {opened}. Alternatively, you can close() the - connection, set the database name, and call open() again. \note - The \e{database name} is not the \e{connection name}. The - connection name must be passed to addDatabase() at connection - object create time. - - For the QOCI (Oracle) driver, the database name is the TNS - Service Name. - - For the QODBC driver, the \a name can either be a DSN, a DSN - filename (in which case the file must have a \c .dsn extension), - or a connection string. - - For example, Microsoft Access users can use the following - connection string to open an \c .mdb file directly, instead of - having to create a DSN entry in the ODBC manager: - - \snippet code/src_sql_kernel_qsqldatabase.cpp 3 - - There is no default value. - - \sa databaseName(), setUserName(), setPassword(), setHostName(), - setPort(), setConnectOptions(), open() -*/ - -void QSqlDatabase::setDatabaseName(const QString& name) -{ - if (isValid()) - d->dbname = name; -} - -/*! - Sets the connection's user name to \a name. To have effect, the - user name must be set \e{before} the connection is \l{open()} - {opened}. Alternatively, you can close() the connection, set the - user name, and call open() again. - - There is no default value. - - \sa userName(), setDatabaseName(), setPassword(), setHostName(), - setPort(), setConnectOptions(), open() -*/ - -void QSqlDatabase::setUserName(const QString& name) -{ - if (isValid()) - d->uname = name; -} - -/*! - Sets the connection's password to \a password. To have effect, the - password must be set \e{before} the connection is \l{open()} - {opened}. Alternatively, you can close() the connection, set the - password, and call open() again. - - There is no default value. - - \warning This function stores the password in plain text within - Qt. Use the open() call that takes a password as parameter to - avoid this behavior. - - \sa password(), setUserName(), setDatabaseName(), setHostName(), - setPort(), setConnectOptions(), open() -*/ - -void QSqlDatabase::setPassword(const QString& password) -{ - if (isValid()) - d->pword = password; -} - -/*! - Sets the connection's host name to \a host. To have effect, the - host name must be set \e{before} the connection is \l{open()} - {opened}. Alternatively, you can close() the connection, set the - host name, and call open() again. - - There is no default value. - - \sa hostName(), setUserName(), setPassword(), setDatabaseName(), - setPort(), setConnectOptions(), open() -*/ - -void QSqlDatabase::setHostName(const QString& host) -{ - if (isValid()) - d->hname = host; -} - -/*! - Sets the connection's port number to \a port. To have effect, the - port number must be set \e{before} the connection is \l{open()} - {opened}. Alternatively, you can close() the connection, set the - port number, and call open() again.. - - There is no default value. - - \sa port(), setUserName(), setPassword(), setHostName(), - setDatabaseName(), setConnectOptions(), open() -*/ - -void QSqlDatabase::setPort(int port) -{ - if (isValid()) - d->port = port; -} - -/*! - Returns the connection's database name, which may be empty. - \note The database name is not the connection name. - - \sa setDatabaseName() -*/ -QString QSqlDatabase::databaseName() const -{ - return d->dbname; -} - -/*! - Returns the connection's user name; it may be empty. - - \sa setUserName() -*/ -QString QSqlDatabase::userName() const -{ - return d->uname; -} - -/*! - Returns the connection's password. If the password was not set - with setPassword(), and if the password was given in the open() - call, or if no password was used, an empty string is returned. -*/ -QString QSqlDatabase::password() const -{ - return d->pword; -} - -/*! - Returns the connection's host name; it may be empty. - - \sa setHostName() -*/ -QString QSqlDatabase::hostName() const -{ - return d->hname; -} - -/*! - Returns the connection's driver name. - - \sa addDatabase(), driver() -*/ -QString QSqlDatabase::driverName() const -{ - return d->drvName; -} - -/*! - Returns the connection's port number. The value is undefined if - the port number has not been set. - - \sa setPort() -*/ -int QSqlDatabase::port() const -{ - return d->port; -} - -/*! - Returns the database driver used to access the database - connection. - - \sa addDatabase(), drivers() -*/ - -QSqlDriver* QSqlDatabase::driver() const -{ - return d->driver; -} - -/*! - Returns information about the last error that occurred on the - database. - - Failures that occur in conjunction with an individual query are - reported by QSqlQuery::lastError(). - - \sa QSqlError, QSqlQuery::lastError() -*/ - -QSqlError QSqlDatabase::lastError() const -{ - return d->driver->lastError(); -} - - -/*! - Returns a list of the database's tables, system tables and views, - as specified by the parameter \a type. - - \sa primaryIndex(), record() -*/ - -QStringList QSqlDatabase::tables(QSql::TableType type) const -{ - return d->driver->tables(type); -} - -/*! - Returns the primary index for table \a tablename. If no primary - index exists an empty QSqlIndex is returned. - - \sa tables(), record() -*/ - -QSqlIndex QSqlDatabase::primaryIndex(const QString& tablename) const -{ - return d->driver->primaryIndex(tablename); -} - - -/*! - Returns a QSqlRecord populated with the names of all the fields in - the table (or view) called \a tablename. The order in which the - fields appear in the record is undefined. If no such table (or - view) exists, an empty record is returned. -*/ - -QSqlRecord QSqlDatabase::record(const QString& tablename) const -{ - return d->driver->record(tablename); -} - - -/*! - Sets database-specific \a options. This must be done before the - connection is opened or it has no effect (or you can close() the - connection, call this function and open() the connection again). - - The format of the \a options string is a semicolon separated list - of option names or option=value pairs. The options depend on the - database client used: - - \table - \header \li ODBC \li MySQL \li PostgreSQL - \row - - \li - \list - \li SQL_ATTR_ACCESS_MODE - \li SQL_ATTR_LOGIN_TIMEOUT - \li SQL_ATTR_CONNECTION_TIMEOUT - \li SQL_ATTR_CURRENT_CATALOG - \li SQL_ATTR_METADATA_ID - \li SQL_ATTR_PACKET_SIZE - \li SQL_ATTR_TRACEFILE - \li SQL_ATTR_TRACE - \li SQL_ATTR_CONNECTION_POOLING - \li SQL_ATTR_ODBC_VERSION - \endlist - - \li - \list - \li CLIENT_COMPRESS - \li CLIENT_FOUND_ROWS - \li CLIENT_IGNORE_SPACE - \li CLIENT_ODBC - \li CLIENT_NO_SCHEMA - \li CLIENT_INTERACTIVE - \li UNIX_SOCKET - \li MYSQL_OPT_RECONNECT - \li MYSQL_OPT_CONNECT_TIMEOUT - \li MYSQL_OPT_READ_TIMEOUT - \li MYSQL_OPT_WRITE_TIMEOUT - \li SSL_KEY - \li SSL_CERT - \li SSL_CA - \li SSL_CAPATH - \li SSL_CIPHER - \endlist - - \li - \list - \li connect_timeout - \li options - \li tty - \li requiressl - \li service - \endlist - - \header \li DB2 \li OCI \li TDS - \row - - \li - \list - \li SQL_ATTR_ACCESS_MODE - \li SQL_ATTR_LOGIN_TIMEOUT - \endlist - - \li - \list - \li OCI_ATTR_PREFETCH_ROWS - \li OCI_ATTR_PREFETCH_MEMORY - \endlist - - \li - \e none - - \header \li SQLite \li Interbase - \row - - \li - \list - \li QSQLITE_BUSY_TIMEOUT - \li QSQLITE_OPEN_READONLY - \li QSQLITE_OPEN_URI - \li QSQLITE_ENABLE_SHARED_CACHE - \endlist - - \li - \list - \li ISC_DPB_LC_CTYPE - \li ISC_DPB_SQL_ROLE_NAME - \endlist - - \endtable - - Examples: - \snippet code/src_sql_kernel_qsqldatabase.cpp 4 - - Refer to the client library documentation for more information - about the different options. - - \sa connectOptions() -*/ - -void QSqlDatabase::setConnectOptions(const QString &options) -{ - if (isValid()) - d->connOptions = options; -} - -/*! - Returns the connection options string used for this connection. - The string may be empty. - - \sa setConnectOptions() - */ -QString QSqlDatabase::connectOptions() const -{ - return d->connOptions; -} - -/*! - Returns \c true if a driver called \a name is available; otherwise - returns \c false. - - \sa drivers() -*/ - -bool QSqlDatabase::isDriverAvailable(const QString& name) -{ - return drivers().contains(name); -} - -/*! \fn QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName) - - This overload is useful when you want to create a database - connection with a \l{QSqlDriver} {driver} you instantiated - yourself. It might be your own database driver, or you might just - need to instantiate one of the Qt drivers yourself. If you do - this, it is recommended that you include the driver code in your - application. For example, you can create a PostgreSQL connection - with your own QPSQL driver like this: - - \snippet code/src_sql_kernel_qsqldatabase.cpp 5 - \codeline - \snippet code/src_sql_kernel_qsqldatabase.cpp 6 - - The above code sets up a PostgreSQL connection and instantiates a - QPSQLDriver object. Next, addDatabase() is called to add the - connection to the known connections so that it can be used by the - Qt SQL classes. When a driver is instantiated with a connection - handle (or set of handles), Qt assumes that you have already - opened the database connection. - - \note We assume that \c qtdir is the directory where Qt is - installed. This will pull in the code that is needed to use the - PostgreSQL client library and to instantiate a QPSQLDriver object, - assuming that you have the PostgreSQL headers somewhere in your - include search path. - - Remember that you must link your application against the database - client library. Make sure the client library is in your linker's - search path, and add lines like these to your \c{.pro} file: - - \snippet code/src_sql_kernel_qsqldatabase.cpp 7 - - The method described works for all the supplied drivers. The only - difference will be in the driver constructor arguments. Here is a - table of the drivers included with Qt, their source code files, - and their constructor arguments: - - \table - \header \li Driver \li Class name \li Constructor arguments \li File to include - \row - \li QPSQL - \li QPSQLDriver - \li PGconn *connection - \li \c qsql_psql.cpp - \row - \li QMYSQL - \li QMYSQLDriver - \li MYSQL *connection - \li \c qsql_mysql.cpp - \row - \li QOCI - \li QOCIDriver - \li OCIEnv *environment, OCISvcCtx *serviceContext - \li \c qsql_oci.cpp - \row - \li QODBC - \li QODBCDriver - \li SQLHANDLE environment, SQLHANDLE connection - \li \c qsql_odbc.cpp - \row - \li QDB2 - \li QDB2 - \li SQLHANDLE environment, SQLHANDLE connection - \li \c qsql_db2.cpp - \row - \li QTDS - \li QTDSDriver - \li LOGINREC *loginRecord, DBPROCESS *dbProcess, const QString &hostName - \li \c qsql_tds.cpp - \row - \li QSQLITE - \li QSQLiteDriver - \li sqlite *connection - \li \c qsql_sqlite.cpp - \row - \li QIBASE - \li QIBaseDriver - \li isc_db_handle connection - \li \c qsql_ibase.cpp - \endtable - - The host name (or service name) is needed when constructing the - QTDSDriver for creating new connections for internal queries. This - is to prevent blocking when several QSqlQuery objects are used - simultaneously. - - \warning Adding a database connection with the same connection - name as an existing connection, causes the existing connection to - be replaced by the new one. - - \warning The SQL framework takes ownership of the \a driver. It - must not be deleted. To remove the connection, use - removeDatabase(). - - \sa drivers() -*/ -QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName) -{ - QSqlDatabase db(driver); - QSqlDatabasePrivate::addDatabase(db, connectionName); - return db; -} - -/*! - Returns \c true if the QSqlDatabase has a valid driver. - - Example: - \snippet code/src_sql_kernel_qsqldatabase.cpp 8 -*/ -bool QSqlDatabase::isValid() const -{ - return d->driver && d->driver != d->shared_null()->driver; -} - -/*! - Clones the database connection \a other and stores it as \a - connectionName. All the settings from the original database, e.g. - databaseName(), hostName(), etc., are copied across. Does nothing - if \a other is an invalid database. Returns the newly created - database connection. - - \note The new connection has not been opened. Before using the new - connection, you must call open(). -*/ -QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QString &connectionName) -{ - if (!other.isValid()) - return QSqlDatabase(); - - QSqlDatabase db(other.driverName()); - db.d->copy(other.d); - QSqlDatabasePrivate::addDatabase(db, connectionName); - return db; -} - -/*! - \since 4.4 - - Returns the connection name, which may be empty. \note The - connection name is not the \l{databaseName()} {database name}. - - \sa addDatabase() -*/ -QString QSqlDatabase::connectionName() const -{ - return d->connName; -} - -/*! - \since 4.6 - - Sets the default numerical precision policy used by queries created - on this database connection to \a precisionPolicy. - - Note: Drivers that don't support fetching numerical values with low - precision will ignore the precision policy. You can use - QSqlDriver::hasFeature() to find out whether a driver supports this - feature. - - Note: Setting the default precision policy to \a precisionPolicy - doesn't affect any currently active queries. - - \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(), - QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy() -*/ -void QSqlDatabase::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) -{ - if(driver()) - driver()->setNumericalPrecisionPolicy(precisionPolicy); - d->precisionPolicy = precisionPolicy; -} - -/*! - \since 4.6 - - Returns the current default precision policy for the database connection. - - \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(), - QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy() -*/ -QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy() const -{ - if(driver()) - return driver()->numericalPrecisionPolicy(); - else - return d->precisionPolicy; -} - - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QSqlDatabase &d) -{ - QDebugStateSaver saver(dbg); - dbg.nospace(); - dbg.noquote(); - if (!d.isValid()) { - dbg << "QSqlDatabase(invalid)"; - return dbg; - } - - dbg << "QSqlDatabase(driver=\"" << d.driverName() << "\", database=\"" - << d.databaseName() << "\", host=\"" << d.hostName() << "\", port=" << d.port() - << ", user=\"" << d.userName() << "\", open=" << d.isOpen() << ')'; - return dbg; -} -#endif - -QT_END_NAMESPACE From e3079c6f7d3fe352d62c90a75465f8bcf15cbb83 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:41:52 -0400 Subject: [PATCH 0970/1324] Delete qsqldatabase.h --- src/qt/qsqldatabase.h | 150 ------------------------------------------ 1 file changed, 150 deletions(-) delete mode 100644 src/qt/qsqldatabase.h diff --git a/src/qt/qsqldatabase.h b/src/qt/qsqldatabase.h deleted file mode 100644 index 9c0e5a57..00000000 --- a/src/qt/qsqldatabase.h +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQLDATABASE_H -#define QSQLDATABASE_H - -#include -#include "qsql.h" - -QT_BEGIN_NAMESPACE - - -class QSqlError; -class QSqlDriver; -class QSqlIndex; -class QSqlRecord; -class QSqlQuery; -class QSqlDatabasePrivate; - -class Q_SQL_EXPORT QSqlDriverCreatorBase -{ -public: - virtual ~QSqlDriverCreatorBase() {} - virtual QSqlDriver *createObject() const = 0; -}; - -template -class QSqlDriverCreator : public QSqlDriverCreatorBase -{ -public: - QSqlDriver *createObject() const Q_DECL_OVERRIDE { return new T; } -}; - -class Q_SQL_EXPORT QSqlDatabase -{ -public: - QSqlDatabase(); - QSqlDatabase(const QSqlDatabase &other); - ~QSqlDatabase(); - - QSqlDatabase &operator=(const QSqlDatabase &other); - - bool open(); - bool open(const QString& user, const QString& password); - void close(); - bool isOpen() const; - bool isOpenError() const; - QStringList tables(QSql::TableType type = QSql::Tables) const; - QSqlIndex primaryIndex(const QString& tablename) const; - QSqlRecord record(const QString& tablename) const; - QSqlQuery exec(const QString& query = QString()) const; - QSqlError lastError() const; - bool isValid() const; - - bool transaction(); - bool commit(); - bool rollback(); - - void setDatabaseName(const QString& name); - void setUserName(const QString& name); - void setPassword(const QString& password); - void setHostName(const QString& host); - void setPort(int p); - void setConnectOptions(const QString& options = QString()); - QString databaseName() const; - QString userName() const; - QString password() const; - QString hostName() const; - QString driverName() const; - int port() const; - QString connectOptions() const; - QString connectionName() const; - void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); - QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; - - QSqlDriver* driver() const; - - static -#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900 - // ### Qt6: remove the #ifdef - const -#endif - char *defaultConnection; - - static QSqlDatabase addDatabase(const QString& type, - const QString& connectionName = QLatin1String(defaultConnection)); - static QSqlDatabase addDatabase(QSqlDriver* driver, - const QString& connectionName = QLatin1String(defaultConnection)); - static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName); - static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection), - bool open = true); - static void removeDatabase(const QString& connectionName); - static bool contains(const QString& connectionName = QLatin1String(defaultConnection)); - static QStringList drivers(); - static QStringList connectionNames(); - static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator); - static bool isDriverAvailable(const QString &name); - -protected: - explicit QSqlDatabase(const QString& type); - explicit QSqlDatabase(QSqlDriver* driver); - -private: - friend class QSqlDatabasePrivate; - QSqlDatabasePrivate *d; -}; - -#ifndef QT_NO_DEBUG_STREAM -Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &); -#endif - -QT_END_NAMESPACE - -#endif // QSQLDATABASE_H From 672a7fc0b53a584aa0f72d81040a6d887caafbac Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:01 -0400 Subject: [PATCH 0971/1324] Delete qsqldriver.cpp --- src/qt/qsqldriver.cpp | 841 ------------------------------------------ 1 file changed, 841 deletions(-) delete mode 100644 src/qt/qsqldriver.cpp diff --git a/src/qt/qsqldriver.cpp b/src/qt/qsqldriver.cpp deleted file mode 100644 index ad5207cf..00000000 --- a/src/qt/qsqldriver.cpp +++ /dev/null @@ -1,841 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsqldriver.h" - -#include "qdatetime.h" -#include "qsqlerror.h" -#include "qsqlfield.h" -#include "qsqlindex.h" -#include "private/qobject_p.h" -#include "private/qsqldriver_p.h" - -QT_BEGIN_NAMESPACE - -static QString prepareIdentifier(const QString &identifier, - QSqlDriver::IdentifierType type, const QSqlDriver *driver) -{ - Q_ASSERT( driver != NULL ); - QString ret = identifier; - if (!driver->isIdentifierEscaped(identifier, type)) { - ret = driver->escapeIdentifier(identifier, type); - } - return ret; -} - -/*! - \class QSqlDriver - \brief The QSqlDriver class is an abstract base class for accessing - specific SQL databases. - - \ingroup database - \inmodule QtSql - - This class should not be used directly. Use QSqlDatabase instead. - - If you want to create your own SQL drivers, you can subclass this - class and reimplement its pure virtual functions and those - virtual functions that you need. See \l{How to Write Your Own - Database Driver} for more information. - - \sa QSqlDatabase, QSqlResult -*/ - -/*! - Constructs a new driver with the given \a parent. -*/ - -QSqlDriver::QSqlDriver(QObject *parent) - : QObject(*new QSqlDriverPrivate, parent) -{ -} - -/*! \internal -*/ -QSqlDriver::QSqlDriver(QSqlDriverPrivate &dd, QObject *parent) - : QObject(dd, parent) -{ -} - -/*! - Destroys the object and frees any allocated resources. -*/ - -QSqlDriver::~QSqlDriver() -{ -} - -/*! - \since 4.4 - - \fn QSqlDriver::notification(const QString &name) - - This signal is emitted when the database posts an event notification - that the driver subscribes to. \a name identifies the event notification. - - \sa subscribeToNotification() -*/ - -/*! - \since 5.0 - - \fn QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant & payload) - - This signal is emitted when the database posts an event notification - that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source, - \a payload holds the extra data optionally delivered with the notification. - - \sa subscribeToNotification() -*/ - -/*! - \fn bool QSqlDriver::open(const QString &db, const QString &user, const QString& password, - const QString &host, int port, const QString &options) - - Derived classes must reimplement this pure virtual function to - open a database connection on database \a db, using user name \a - user, password \a password, host \a host, port \a port and - connection options \a options. - - The function must return true on success and false on failure. - - \sa setOpen() -*/ - -/*! - \fn bool QSqlDriver::close() - - Derived classes must reimplement this pure virtual function in - order to close the database connection. Return true on success, - false on failure. - - \sa open(), setOpen() -*/ - -/*! - \fn QSqlResult *QSqlDriver::createResult() const - - Creates an empty SQL result on the database. Derived classes must - reimplement this function and return a QSqlResult object - appropriate for their database to the caller. -*/ - -/*! - Returns \c true if the database connection is open; otherwise returns - false. -*/ - -bool QSqlDriver::isOpen() const -{ - Q_D(const QSqlDriver); - return d->isOpen; -} - -/*! - Returns \c true if the there was an error opening the database - connection; otherwise returns \c false. -*/ - -bool QSqlDriver::isOpenError() const -{ - Q_D(const QSqlDriver); - return d->isOpenError; -} - -/*! - \enum QSqlDriver::DriverFeature - - This enum contains a list of features a driver might support. Use - hasFeature() to query whether a feature is supported or not. - - \value Transactions Whether the driver supports SQL transactions. - \value QuerySize Whether the database is capable of reporting the size - of a query. Note that some databases do not support returning the size - (i.e. number of rows returned) of a query, in which case - QSqlQuery::size() will return -1. - \value BLOB Whether the driver supports Binary Large Object fields. - \value Unicode Whether the driver supports Unicode strings if the - database server does. - \value PreparedQueries Whether the driver supports prepared query execution. - \value NamedPlaceholders Whether the driver supports the use of named placeholders. - \value PositionalPlaceholders Whether the driver supports the use of positional placeholders. - \value LastInsertId Whether the driver supports returning the Id of the last touched row. - \value BatchOperations Whether the driver supports batched operations, see QSqlQuery::execBatch() - \value SimpleLocking Whether the driver disallows a write lock on a table while other queries have a read lock on it. - \value LowPrecisionNumbers Whether the driver allows fetching numerical values with low precision. - \value EventNotifications Whether the driver supports database event notifications. - \value FinishQuery Whether the driver can do any low-level resource cleanup when QSqlQuery::finish() is called. - \value MultipleResultSets Whether the driver can access multiple result sets returned from batched statements or stored procedures. - \value CancelQuery Whether the driver allows cancelling a running query. - - More information about supported features can be found in the - \l{sql-driver.html}{Qt SQL driver} documentation. - - \sa hasFeature() -*/ - -/*! - \enum QSqlDriver::StatementType - - This enum contains a list of SQL statement (or clause) types the - driver can create. - - \value WhereStatement An SQL \c WHERE statement (e.g., \c{WHERE f = 5}). - \value SelectStatement An SQL \c SELECT statement (e.g., \c{SELECT f FROM t}). - \value UpdateStatement An SQL \c UPDATE statement (e.g., \c{UPDATE TABLE t set f = 1}). - \value InsertStatement An SQL \c INSERT statement (e.g., \c{INSERT INTO t (f) values (1)}). - \value DeleteStatement An SQL \c DELETE statement (e.g., \c{DELETE FROM t}). - - \sa sqlStatement() -*/ - -/*! - \enum QSqlDriver::IdentifierType - - This enum contains a list of SQL identifier types. - - \value FieldName A SQL field name - \value TableName A SQL table name -*/ - -/*! - \enum QSqlDriver::NotificationSource - - This enum contains a list of SQL notification sources. - - \value UnknownSource The notification source is unknown - \value SelfSource The notification source is this connection - \value OtherSource The notification source is another connection -*/ - -/*! - \enum QSqlDriver::DbmsType - - This enum contains DBMS types. - - \value UnknownDbms - \value MSSqlServer - \value MySqlServer - \value PostgreSQL - \value Oracle - \value Sybase - \value SQLite - \value Interbase - \value DB2 -*/ - -/*! - \fn bool QSqlDriver::hasFeature(DriverFeature feature) const - - Returns \c true if the driver supports feature \a feature; otherwise - returns \c false. - - Note that some databases need to be open() before this can be - determined. - - \sa DriverFeature -*/ - -/*! - This function sets the open state of the database to \a open. - Derived classes can use this function to report the status of - open(). - - \sa open(), setOpenError() -*/ - -void QSqlDriver::setOpen(bool open) -{ - Q_D(QSqlDriver); - d->isOpen = open; -} - -/*! - This function sets the open error state of the database to \a - error. Derived classes can use this function to report the status - of open(). Note that if \a error is true the open state of the - database is set to closed (i.e., isOpen() returns \c false). - - \sa open(), setOpen() -*/ - -void QSqlDriver::setOpenError(bool error) -{ - Q_D(QSqlDriver); - d->isOpenError = error; - if (error) - d->isOpen = false; -} - -/*! - This function is called to begin a transaction. If successful, - return true, otherwise return false. The default implementation - does nothing and returns \c false. - - \sa commitTransaction(), rollbackTransaction() -*/ - -bool QSqlDriver::beginTransaction() -{ - return false; -} - -/*! - This function is called to commit a transaction. If successful, - return true, otherwise return false. The default implementation - does nothing and returns \c false. - - \sa beginTransaction(), rollbackTransaction() -*/ - -bool QSqlDriver::commitTransaction() -{ - return false; -} - -/*! - This function is called to rollback a transaction. If successful, - return true, otherwise return false. The default implementation - does nothing and returns \c false. - - \sa beginTransaction(), commitTransaction() -*/ - -bool QSqlDriver::rollbackTransaction() -{ - return false; -} - -/*! - This function is used to set the value of the last error, \a error, - that occurred on the database. - - \sa lastError() -*/ - -void QSqlDriver::setLastError(const QSqlError &error) -{ - Q_D(QSqlDriver); - d->error = error; -} - -/*! - Returns a QSqlError object which contains information about the - last error that occurred on the database. -*/ - -QSqlError QSqlDriver::lastError() const -{ - Q_D(const QSqlDriver); - return d->error; -} - -/*! - Returns a list of the names of the tables in the database. The - default implementation returns an empty list. - - The \a tableType argument describes what types of tables - should be returned. Due to binary compatibility, the string - contains the value of the enum QSql::TableTypes as text. - An empty string should be treated as QSql::Tables for - backward compatibility. -*/ - -QStringList QSqlDriver::tables(QSql::TableType) const -{ - return QStringList(); -} - -/*! - Returns the primary index for table \a tableName. Returns an empty - QSqlIndex if the table doesn't have a primary index. The default - implementation returns an empty index. -*/ - -QSqlIndex QSqlDriver::primaryIndex(const QString&) const -{ - return QSqlIndex(); -} - - -/*! - Returns a QSqlRecord populated with the names of the fields in - table \a tableName. If no such table exists, an empty record is - returned. The default implementation returns an empty record. -*/ - -QSqlRecord QSqlDriver::record(const QString & /* tableName */) const -{ - return QSqlRecord(); -} - -/*! - Returns the \a identifier escaped according to the database rules. - \a identifier can either be a table name or field name, dependent - on \a type. - - The default implementation does nothing. - \sa isIdentifierEscaped() - */ -QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const -{ - return identifier; -} - -/*! - Returns whether \a identifier is escaped according to the database rules. - \a identifier can either be a table name or field name, dependent - on \a type. - - Reimplement this function if you want to provide your own implementation in your - QSqlDriver subclass, - - \sa stripDelimiters(), escapeIdentifier() - */ -bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const -{ - Q_UNUSED(type); - return identifier.size() > 2 - && identifier.startsWith(QLatin1Char('"')) //left delimited - && identifier.endsWith(QLatin1Char('"')); //right delimited -} - -/*! - Returns the \a identifier with the leading and trailing delimiters removed, - \a identifier can either be a table name or field name, - dependent on \a type. If \a identifier does not have leading - and trailing delimiter characters, \a identifier is returned without - modification. - - Reimplement this function if you want to provide your own implementation in your - QSqlDriver subclass, - - \since 4.5 - \sa isIdentifierEscaped() - */ -QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const -{ - QString ret; - if (isIdentifierEscaped(identifier, type)) { - ret = identifier.mid(1); - ret.chop(1); - } else { - ret = identifier; - } - return ret; -} - -/*! - Returns a SQL statement of type \a type for the table \a tableName - with the values from \a rec. If \a preparedStatement is true, the - string will contain placeholders instead of values. - - The generated flag in each field of \a rec determines whether the - field is included in the generated statement. - - This method can be used to manipulate tables without having to worry - about database-dependent SQL dialects. For non-prepared statements, - the values will be properly escaped. - - In the WHERE statement, each non-null field of \a rec specifies a - filter condition of equality to the field value, or if prepared, a - placeholder. However, prepared or not, a null field specifies the - condition IS NULL and never introduces a placeholder. The - application must not attempt to bind data for the null field during - execution. The field must be set to some non-null value if a - placeholder is desired. Furthermore, since non-null fields specify - equality conditions and SQL NULL is not equal to anything, even - itself, it is generally not useful to bind a null to a placeholder. - -*/ -QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, - const QSqlRecord &rec, bool preparedStatement) const -{ - int i; - QString s; - s.reserve(128); - switch (type) { - case SelectStatement: - for (i = 0; i < rec.count(); ++i) { - if (rec.isGenerated(i)) - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); - } - if (s.isEmpty()) - return s; - s.chop(2); - s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); - break; - case WhereStatement: - { - const QString tableNamePrefix = tableName.isEmpty() - ? QString() - : prepareIdentifier(tableName, QSqlDriver::TableName, this) + QLatin1Char('.'); - for (int i = 0; i < rec.count(); ++i) { - if (!rec.isGenerated(i)) - continue; - s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND ")); - s.append(tableNamePrefix); - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); - if (rec.isNull(i)) - s.append(QLatin1String(" IS NULL")); - else if (preparedStatement) - s.append(QLatin1String(" = ?")); - else - s.append(QLatin1String(" = ")).append(formatValue(rec.field(i))); - } - break; - } - case UpdateStatement: - s.append(QLatin1String("UPDATE ")).append(tableName).append( - QLatin1String(" SET ")); - for (i = 0; i < rec.count(); ++i) { - if (!rec.isGenerated(i)) - continue; - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); - if (preparedStatement) - s.append(QLatin1Char('?')); - else - s.append(formatValue(rec.field(i))); - s.append(QLatin1String(", ")); - } - if (s.endsWith(QLatin1String(", "))) - s.chop(2); - else - s.clear(); - break; - case DeleteStatement: - s.append(QLatin1String("DELETE FROM ")).append(tableName); - break; - case InsertStatement: { - s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); - QString vals; - for (i = 0; i < rec.count(); ++i) { - if (!rec.isGenerated(i)) - continue; - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); - if (preparedStatement) - vals.append(QLatin1Char('?')); - else - vals.append(formatValue(rec.field(i))); - vals.append(QLatin1String(", ")); - } - if (vals.isEmpty()) { - s.clear(); - } else { - vals.chop(2); // remove trailing comma - s[s.length() - 2] = QLatin1Char(')'); - s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')')); - } - break; } - } - return s; -} - -/*! - Returns a string representation of the \a field value for the - database. This is used, for example, when constructing INSERT and - UPDATE statements. - - The default implementation returns the value formatted as a string - according to the following rules: - - \list - - \li If \a field is character data, the value is returned enclosed - in single quotation marks, which is appropriate for many SQL - databases. Any embedded single-quote characters are escaped - (replaced with two single-quote characters). If \a trimStrings is - true (the default is false), all trailing whitespace is trimmed - from the field. - - \li If \a field is date/time data, the value is formatted in ISO - format and enclosed in single quotation marks. If the date/time - data is invalid, "NULL" is returned. - - \li If \a field is \l{QByteArray}{bytearray} data, and the - driver can edit binary fields, the value is formatted as a - hexadecimal string. - - \li For any other field type, toString() is called on its value - and the result of this is returned. - - \endlist - - \sa QVariant::toString() - -*/ -QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const -{ - const QLatin1String nullTxt("NULL"); - - QString r; - if (field.isNull()) - r = nullTxt; - else { - switch (field.type()) { - case QVariant::Int: - case QVariant::UInt: - if (field.value().type() == QVariant::Bool) - r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); - else - r = field.value().toString(); - break; -#ifndef QT_NO_DATESTRING - case QVariant::Date: - if (field.value().toDate().isValid()) - r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) - + QLatin1Char('\''); - else - r = nullTxt; - break; - case QVariant::Time: - if (field.value().toTime().isValid()) - r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) - + QLatin1Char('\''); - else - r = nullTxt; - break; - case QVariant::DateTime: - if (field.value().toDateTime().isValid()) - r = QLatin1Char('\'') + - field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); - else - r = nullTxt; - break; -#endif - case QVariant::String: - case QVariant::Char: - { - QString result = field.value().toString(); - if (trimStrings) { - int end = result.length(); - while (end && result.at(end-1).isSpace()) /* skip white space from end */ - end--; - result.truncate(end); - } - /* escape the "'" character */ - result.replace(QLatin1Char('\''), QLatin1String("''")); - r = QLatin1Char('\'') + result + QLatin1Char('\''); - break; - } - case QVariant::Bool: - r = QString::number(field.value().toBool()); - break; - case QVariant::ByteArray : { - if (hasFeature(BLOB)) { - QByteArray ba = field.value().toByteArray(); - QString res; - static const char hexchars[] = "0123456789abcdef"; - for (int i = 0; i < ba.size(); ++i) { - uchar s = (uchar) ba[i]; - res += QLatin1Char(hexchars[s >> 4]); - res += QLatin1Char(hexchars[s & 0x0f]); - } - r = QLatin1Char('\'') + res + QLatin1Char('\''); - break; - } - } - default: - r = field.value().toString(); - break; - } - } - return r; -} - -/*! - Returns the low-level database handle wrapped in a QVariant or an - invalid variant if there is no handle. - - \warning Use this with uttermost care and only if you know what you're doing. - - \warning The handle returned here can become a stale pointer if the connection - is modified (for example, if you close the connection). - - \warning The handle can be NULL if the connection is not open yet. - - The handle returned here is database-dependent, you should query the type - name of the variant before accessing it. - - This example retrieves the handle for a connection to sqlite: - - \snippet code/src_sql_kernel_qsqldriver.cpp 0 - - This snippet returns the handle for PostgreSQL or MySQL: - - \snippet code/src_sql_kernel_qsqldriver.cpp 1 - - \sa QSqlResult::handle() -*/ -QVariant QSqlDriver::handle() const -{ - return QVariant(); -} - -/*! - This function is called to subscribe to event notifications from the database. - \a name identifies the event notification. - - If successful, return true, otherwise return false. - - The database must be open when this function is called. When the database is closed - by calling close() all subscribed event notifications are automatically unsubscribed. - Note that calling open() on an already open database may implicitly cause close() to - be called, which will cause the driver to unsubscribe from all event notifications. - - When an event notification identified by \a name is posted by the database the - notification() signal is emitted. - - Reimplement this function if you want to provide event notification support in your - own QSqlDriver subclass, - - \since 4.4 - \sa unsubscribeFromNotification(), subscribedToNotifications(), QSqlDriver::hasFeature() -*/ -bool QSqlDriver::subscribeToNotification(const QString &name) -{ - Q_UNUSED(name); - return false; -} - -/*! - This function is called to unsubscribe from event notifications from the database. - \a name identifies the event notification. - - If successful, return true, otherwise return false. - - The database must be open when this function is called. All subscribed event - notifications are automatically unsubscribed from when the close() function is called. - - After calling \e this function the notification() signal will no longer be emitted - when an event notification identified by \a name is posted by the database. - - Reimplement this function if you want to provide event notification support in your - own QSqlDriver subclass, - - \since 4.4 - \sa subscribeToNotification(), subscribedToNotifications() -*/ -bool QSqlDriver::unsubscribeFromNotification(const QString &name) -{ - Q_UNUSED(name); - return false; -} - -/*! - Returns a list of the names of the event notifications that are currently subscribed to. - - Reimplement this function if you want to provide event notification support in your - own QSqlDriver subclass, - - \since 4.4 - \sa subscribeToNotification(), unsubscribeFromNotification() -*/ -QStringList QSqlDriver::subscribedToNotifications() const -{ - return QStringList(); -} - -/*! - \since 4.6 - - Sets the default numerical precision policy used by queries created - by this driver to \a precisionPolicy. - - Note: Setting the default precision policy to \a precisionPolicy - doesn't affect any currently active queries. - - \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(), - QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy() -*/ -void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) -{ - Q_D(QSqlDriver); - d->precisionPolicy = precisionPolicy; -} - -/*! - \since 4.6 - - Returns the current default precision policy for the database connection. - - \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(), - QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy() -*/ -QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const -{ - Q_D(const QSqlDriver); - return d->precisionPolicy; -} - -/*! - \since 5.4 - - Returns the current DBMS type for the database connection. -*/ -QSqlDriver::DbmsType QSqlDriver::dbmsType() const -{ - Q_D(const QSqlDriver); - return d->dbmsType; -} - -/*! - \since 5.0 - \internal - - Tries to cancel the running query, if the underlying driver has the - capability to cancel queries. Returns \c true on success, otherwise false. - - This function can be called from a different thread. - - If you use this function as a slot, you need to use a Qt::DirectConnection - from a different thread. - - Reimplement this function to support canceling running queries in - your own QSqlDriver subclass. It must be implemented in a thread-safe - manner. - - \sa QSqlDriver::hasFeature() -*/ -bool QSqlDriver::cancelQuery() -{ - return false; -} - -QT_END_NAMESPACE From 81cae4ab4e9e93cb0a32ace993ceba68a34e0244 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:11 -0400 Subject: [PATCH 0972/1324] Delete qsqldriver.h --- src/qt/qsqldriver.h | 154 -------------------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 src/qt/qsqldriver.h diff --git a/src/qt/qsqldriver.h b/src/qt/qsqldriver.h deleted file mode 100644 index 9fd7523f..00000000 --- a/src/qt/qsqldriver.h +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQLDRIVER_H -#define QSQLDRIVER_H - -#include -#include -#include -#include "qsql.h" - -QT_BEGIN_NAMESPACE - - -class QSqlDatabase; -class QSqlDriverPrivate; -class QSqlError; -class QSqlField; -class QSqlIndex; -class QSqlRecord; -class QSqlResult; -class QVariant; - -class Q_SQL_EXPORT QSqlDriver : public QObject -{ - friend class QSqlDatabase; - friend class QSqlResultPrivate; - Q_OBJECT - Q_DECLARE_PRIVATE(QSqlDriver) - -public: - enum DriverFeature { Transactions, QuerySize, BLOB, Unicode, PreparedQueries, - NamedPlaceholders, PositionalPlaceholders, LastInsertId, - BatchOperations, SimpleLocking, LowPrecisionNumbers, - EventNotifications, FinishQuery, MultipleResultSets, CancelQuery }; - - enum StatementType { WhereStatement, SelectStatement, UpdateStatement, - InsertStatement, DeleteStatement }; - - enum IdentifierType { FieldName, TableName }; - - enum NotificationSource { UnknownSource, SelfSource, OtherSource }; - - enum DbmsType { - UnknownDbms, - MSSqlServer, - MySqlServer, - PostgreSQL, - Oracle, - Sybase, - SQLite, - Interbase, - DB2 - }; - - explicit QSqlDriver(QObject *parent = Q_NULLPTR); - ~QSqlDriver(); - virtual bool isOpen() const; - bool isOpenError() const; - - virtual bool beginTransaction(); - virtual bool commitTransaction(); - virtual bool rollbackTransaction(); - virtual QStringList tables(QSql::TableType tableType) const; - virtual QSqlIndex primaryIndex(const QString &tableName) const; - virtual QSqlRecord record(const QString &tableName) const; - virtual QString formatValue(const QSqlField& field, bool trimStrings = false) const; - - virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const; - virtual QString sqlStatement(StatementType type, const QString &tableName, - const QSqlRecord &rec, bool preparedStatement) const; - - QSqlError lastError() const; - - virtual QVariant handle() const; - virtual bool hasFeature(DriverFeature f) const = 0; - virtual void close() = 0; - virtual QSqlResult *createResult() const = 0; - - virtual bool open(const QString& db, - const QString& user = QString(), - const QString& password = QString(), - const QString& host = QString(), - int port = -1, - const QString& connOpts = QString()) = 0; - virtual bool subscribeToNotification(const QString &name); - virtual bool unsubscribeFromNotification(const QString &name); - virtual QStringList subscribedToNotifications() const; - - virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; - virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const; - - void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); - QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; - - DbmsType dbmsType() const; - -public Q_SLOTS: - virtual bool cancelQuery(); - -Q_SIGNALS: - void notification(const QString &name); - void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); - -protected: - QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = Q_NULLPTR); - virtual void setOpen(bool o); - virtual void setOpenError(bool e); - virtual void setLastError(const QSqlError& e); - - -private: - Q_DISABLE_COPY(QSqlDriver) -}; - -QT_END_NAMESPACE - -#endif // QSQLDRIVER_H From 420785862ed2d12135155c52dfd65194be1267f8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:21 -0400 Subject: [PATCH 0973/1324] Delete qsqlerror.h --- src/qt/qsqlerror.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/qsqlerror.h diff --git a/src/qt/qsqlerror.h b/src/qt/qsqlerror.h deleted file mode 100644 index bc568863..00000000 --- a/src/qt/qsqlerror.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../src/sql/kernel/qsqlerror.h" From ed5289f5ffcecceb5604917a09f39078b801b49d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:29 -0400 Subject: [PATCH 0974/1324] Delete qsqlfield.h --- src/qt/qsqlfield.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/qsqlfield.h diff --git a/src/qt/qsqlfield.h b/src/qt/qsqlfield.h deleted file mode 100644 index f278c466..00000000 --- a/src/qt/qsqlfield.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../src/sql/kernel/qsqlfield.h" From 17d6c8b83fa6daecaccb90c8c92fa7705863b21f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:40 -0400 Subject: [PATCH 0975/1324] Delete qsqlindex.h --- src/qt/qsqlindex.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/qsqlindex.h diff --git a/src/qt/qsqlindex.h b/src/qt/qsqlindex.h deleted file mode 100644 index 87b8cdd9..00000000 --- a/src/qt/qsqlindex.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../src/sql/kernel/qsqlindex.h" From b87e0e63d10f1b8f245cc28c44777ee91655c59e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:48 -0400 Subject: [PATCH 0976/1324] Delete qsqlquery.cpp --- src/qt/qsqlquery.cpp | 1298 ------------------------------------------ 1 file changed, 1298 deletions(-) delete mode 100644 src/qt/qsqlquery.cpp diff --git a/src/qt/qsqlquery.cpp b/src/qt/qsqlquery.cpp deleted file mode 100644 index f9cc07da..00000000 --- a/src/qt/qsqlquery.cpp +++ /dev/null @@ -1,1298 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsqlquery.h" - -//#define QT_DEBUG_SQL - -#include "qdebug.h" -#include "qelapsedtimer.h" -#include "qatomic.h" -#include "qsqlrecord.h" -#include "qsqlresult.h" -#include "qsqldriver.h" -#include "qsqldatabase.h" -#include "private/qsqlnulldriver_p.h" -#include "qvector.h" -#include "qmap.h" - -QT_BEGIN_NAMESPACE - -class QSqlQueryPrivate -{ -public: - QSqlQueryPrivate(QSqlResult* result); - ~QSqlQueryPrivate(); - QAtomicInt ref; - QSqlResult* sqlResult; - - static QSqlQueryPrivate* shared_null(); -}; - -Q_GLOBAL_STATIC_WITH_ARGS(QSqlQueryPrivate, nullQueryPrivate, (0)) -Q_GLOBAL_STATIC(QSqlNullDriver, nullDriver) -Q_GLOBAL_STATIC_WITH_ARGS(QSqlNullResult, nullResult, (nullDriver())) - -QSqlQueryPrivate* QSqlQueryPrivate::shared_null() -{ - QSqlQueryPrivate *null = nullQueryPrivate(); - null->ref.ref(); - return null; -} - -/*! -\internal -*/ -QSqlQueryPrivate::QSqlQueryPrivate(QSqlResult* result) - : ref(1), sqlResult(result) -{ - if (!sqlResult) - sqlResult = nullResult(); -} - -QSqlQueryPrivate::~QSqlQueryPrivate() -{ - QSqlResult *nr = nullResult(); - if (!nr || sqlResult == nr) - return; - delete sqlResult; -} - -/*! - \class QSqlQuery - \brief The QSqlQuery class provides a means of executing and - manipulating SQL statements. - - \ingroup database - \ingroup shared - - \inmodule QtSql - - QSqlQuery encapsulates the functionality involved in creating, - navigating and retrieving data from SQL queries which are - executed on a \l QSqlDatabase. It can be used to execute DML - (data manipulation language) statements, such as \c SELECT, \c - INSERT, \c UPDATE and \c DELETE, as well as DDL (data definition - language) statements, such as \c{CREATE} \c{TABLE}. It can also - be used to execute database-specific commands which are not - standard SQL (e.g. \c{SET DATESTYLE=ISO} for PostgreSQL). - - Successfully executed SQL statements set the query's state to - active so that isActive() returns \c true. Otherwise the query's - state is set to inactive. In either case, when executing a new SQL - statement, the query is positioned on an invalid record. An active - query must be navigated to a valid record (so that isValid() - returns \c true) before values can be retrieved. - - For some databases, if an active query that is a \c{SELECT} - statement exists when you call \l{QSqlDatabase::}{commit()} or - \l{QSqlDatabase::}{rollback()}, the commit or rollback will - fail. See isActive() for details. - - \target QSqlQuery examples - - Navigating records is performed with the following functions: - - \list - \li next() - \li previous() - \li first() - \li last() - \li seek() - \endlist - - These functions allow the programmer to move forward, backward - or arbitrarily through the records returned by the query. If you - only need to move forward through the results (e.g., by using - next()), you can use setForwardOnly(), which will save a - significant amount of memory overhead and improve performance on - some databases. Once an active query is positioned on a valid - record, data can be retrieved using value(). All data is - transferred from the SQL backend using QVariants. - - For example: - - \snippet sqldatabase/sqldatabase.cpp 7 - - To access the data returned by a query, use value(int). Each - field in the data returned by a \c SELECT statement is accessed - by passing the field's position in the statement, starting from - 0. This makes using \c{SELECT *} queries inadvisable because the - order of the fields returned is indeterminate. - - For the sake of efficiency, there are no functions to access a - field by name (unless you use prepared queries with names, as - explained below). To convert a field name into an index, use - record().\l{QSqlRecord::indexOf()}{indexOf()}, for example: - - \snippet sqldatabase/sqldatabase.cpp 8 - - QSqlQuery supports prepared query execution and the binding of - parameter values to placeholders. Some databases don't support - these features, so for those, Qt emulates the required - functionality. For example, the Oracle and ODBC drivers have - proper prepared query support, and Qt makes use of it; but for - databases that don't have this support, Qt implements the feature - itself, e.g. by replacing placeholders with actual values when a - query is executed. Use numRowsAffected() to find out how many rows - were affected by a non-\c SELECT query, and size() to find how - many were retrieved by a \c SELECT. - - Oracle databases identify placeholders by using a colon-name - syntax, e.g \c{:name}. ODBC simply uses \c ? characters. Qt - supports both syntaxes, with the restriction that you can't mix - them in the same query. - - You can retrieve the values of all the fields in a single variable - (a map) using boundValues(). - - \section1 Approaches to Binding Values - - Below we present the same example using each of the four - different binding approaches, as well as one example of binding - values to a stored procedure. - - \b{Named binding using named placeholders:} - - \snippet sqldatabase/sqldatabase.cpp 9 - - \b{Positional binding using named placeholders:} - - \snippet sqldatabase/sqldatabase.cpp 10 - - \b{Binding values using positional placeholders (version 1):} - - \snippet sqldatabase/sqldatabase.cpp 11 - - \b{Binding values using positional placeholders (version 2):} - - \snippet sqldatabase/sqldatabase.cpp 12 - - \b{Binding values to a stored procedure:} - - This code calls a stored procedure called \c AsciiToInt(), passing - it a character through its in parameter, and taking its result in - the out parameter. - - \snippet sqldatabase/sqldatabase.cpp 13 - - Note that unbound parameters will retain their values. - - Stored procedures that uses the return statement to return values, - or return multiple result sets, are not fully supported. For specific - details see \l{SQL Database Drivers}. - - \warning You must load the SQL driver and open the connection before a - QSqlQuery is created. Also, the connection must remain open while the - query exists; otherwise, the behavior of QSqlQuery is undefined. - - \sa QSqlDatabase, QSqlQueryModel, QSqlTableModel, QVariant -*/ - -/*! - Constructs a QSqlQuery object which uses the QSqlResult \a result - to communicate with a database. -*/ - -QSqlQuery::QSqlQuery(QSqlResult *result) -{ - d = new QSqlQueryPrivate(result); -} - -/*! - Destroys the object and frees any allocated resources. -*/ - -QSqlQuery::~QSqlQuery() -{ - if (!d->ref.deref()) - delete d; -} - -/*! - Constructs a copy of \a other. -*/ - -QSqlQuery::QSqlQuery(const QSqlQuery& other) -{ - d = other.d; - d->ref.ref(); -} - -/*! - \internal -*/ -static void qInit(QSqlQuery *q, const QString& query, QSqlDatabase db) -{ - QSqlDatabase database = db; - if (!database.isValid()) - database = QSqlDatabase::database(QLatin1String(QSqlDatabase::defaultConnection), false); - if (database.isValid()) { - *q = QSqlQuery(database.driver()->createResult()); - } - if (!query.isEmpty()) - q->exec(query); -} - -/*! - Constructs a QSqlQuery object using the SQL \a query and the - database \a db. If \a db is not specified, or is invalid, the application's - default database is used. If \a query is not an empty string, it - will be executed. - - \sa QSqlDatabase -*/ -QSqlQuery::QSqlQuery(const QString& query, QSqlDatabase db) -{ - d = QSqlQueryPrivate::shared_null(); - qInit(this, query, db); -} - -/*! - Constructs a QSqlQuery object using the database \a db. - If \a db is invalid, the application's default database will be used. - - \sa QSqlDatabase -*/ - -QSqlQuery::QSqlQuery(QSqlDatabase db) -{ - d = QSqlQueryPrivate::shared_null(); - qInit(this, QString(), db); -} - - -/*! - Assigns \a other to this object. -*/ - -QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other) -{ - qAtomicAssign(d, other.d); - return *this; -} - -/*! - Returns \c true if the query is not \l{isActive()}{active}, - the query is not positioned on a valid record, - there is no such \a field, or the \a field is null; otherwise \c false. - Note that for some drivers, isNull() will not return accurate - information until after an attempt is made to retrieve data. - - \sa isActive(), isValid(), value() -*/ - -bool QSqlQuery::isNull(int field) const -{ - return !d->sqlResult->isActive() - || !d->sqlResult->isValid() - || d->sqlResult->isNull(field); -} - -/*! - \overload - - Returns \c true if there is no field with this \a name; otherwise - returns isNull(int index) for the corresponding field index. - - This overload is less efficient than \l{QSqlQuery::}{isNull()} -*/ - -bool QSqlQuery::isNull(const QString &name) const -{ - int index = d->sqlResult->record().indexOf(name); - if (index > -1) - return isNull(index); - qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name)); - return true; -} - -/*! - - Executes the SQL in \a query. Returns \c true and sets the query state - to \l{isActive()}{active} if the query was successful; otherwise - returns \c false. The \a query string must use syntax appropriate for - the SQL database being queried (for example, standard SQL). - - After the query is executed, the query is positioned on an \e - invalid record and must be navigated to a valid record before data - values can be retrieved (for example, using next()). - - Note that the last error for this query is reset when exec() is - called. - - For SQLite, the query string can contain only one statement at a time. - If more than one statement is given, the function returns \c false. - - Example: - - \snippet sqldatabase/sqldatabase.cpp 34 - - \sa isActive(), isValid(), next(), previous(), first(), last(), - seek() -*/ - -bool QSqlQuery::exec(const QString& query) -{ -#ifdef QT_DEBUG_SQL - QElapsedTimer t; - t.start(); -#endif - if (d->ref.load() != 1) { - bool fo = isForwardOnly(); - *this = QSqlQuery(driver()->createResult()); - d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); - setForwardOnly(fo); - } else { - d->sqlResult->clear(); - d->sqlResult->setActive(false); - d->sqlResult->setLastError(QSqlError()); - d->sqlResult->setAt(QSql::BeforeFirstRow); - d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); - } - d->sqlResult->setQuery(query.trimmed()); - if (!driver()->isOpen() || driver()->isOpenError()) { - qWarning("QSqlQuery::exec: database not open"); - return false; - } - if (query.isEmpty()) { - qWarning("QSqlQuery::exec: empty query"); - return false; - } - - bool retval = d->sqlResult->reset(query); -#ifdef QT_DEBUG_SQL - qDebug().nospace() << "Executed query (" << t.elapsed() << "ms, " << d->sqlResult->size() - << " results, " << d->sqlResult->numRowsAffected() - << " affected): " << d->sqlResult->lastQuery(); -#endif - return retval; -} - -/*! - Returns the value of field \a index in the current record. - - The fields are numbered from left to right using the text of the - \c SELECT statement, e.g. in - - \snippet code/src_sql_kernel_qsqlquery.cpp 0 - - field 0 is \c forename and field 1 is \c - surname. Using \c{SELECT *} is not recommended because the order - of the fields in the query is undefined. - - An invalid QVariant is returned if field \a index does not - exist, if the query is inactive, or if the query is positioned on - an invalid record. - - \sa previous(), next(), first(), last(), seek(), isActive(), isValid() -*/ - -QVariant QSqlQuery::value(int index) const -{ - if (isActive() && isValid() && (index > -1)) - return d->sqlResult->data(index); - qWarning("QSqlQuery::value: not positioned on a valid record"); - return QVariant(); -} - -/*! - \overload - - Returns the value of the field called \a name in the current record. - If field \a name does not exist an invalid variant is returned. - - This overload is less efficient than \l{QSqlQuery::}{value()} -*/ - -QVariant QSqlQuery::value(const QString& name) const -{ - int index = d->sqlResult->record().indexOf(name); - if (index > -1) - return value(index); - qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name)); - return QVariant(); -} - -/*! - Returns the current internal position of the query. The first - record is at position zero. If the position is invalid, the - function returns QSql::BeforeFirstRow or - QSql::AfterLastRow, which are special negative values. - - \sa previous(), next(), first(), last(), seek(), isActive(), isValid() -*/ - -int QSqlQuery::at() const -{ - return d->sqlResult->at(); -} - -/*! - Returns the text of the current query being used, or an empty - string if there is no current query text. - - \sa executedQuery() -*/ - -QString QSqlQuery::lastQuery() const -{ - return d->sqlResult->lastQuery(); -} - -/*! - Returns the database driver associated with the query. -*/ - -const QSqlDriver *QSqlQuery::driver() const -{ - return d->sqlResult->driver(); -} - -/*! - Returns the result associated with the query. -*/ - -const QSqlResult* QSqlQuery::result() const -{ - return d->sqlResult; -} - -/*! - Retrieves the record at position \a index, if available, and - positions the query on the retrieved record. The first record is at - position 0. Note that the query must be in an \l{isActive()} - {active} state and isSelect() must return true before calling this - function. - - If \a relative is false (the default), the following rules apply: - - \list - - \li If \a index is negative, the result is positioned before the - first record and false is returned. - - \li Otherwise, an attempt is made to move to the record at position - \a index. If the record at position \a index could not be retrieved, - the result is positioned after the last record and false is - returned. If the record is successfully retrieved, true is returned. - - \endlist - - If \a relative is true, the following rules apply: - - \list - - \li If the result is currently positioned before the first record and: - \list - \li \a index is negative or zero, there is no change, and false is - returned. - \li \a index is positive, an attempt is made to position the result - at absolute position \a index - 1, following the sames rule for non - relative seek, above. - \endlist - - \li If the result is currently positioned after the last record and: - \list - \li \a index is positive or zero, there is no change, and false is - returned. - \li \a index is negative, an attempt is made to position the result - at \a index + 1 relative position from last record, following the - rule below. - \endlist - - \li If the result is currently located somewhere in the middle, and - the relative offset \a index moves the result below zero, the result - is positioned before the first record and false is returned. - - \li Otherwise, an attempt is made to move to the record \a index - records ahead of the current record (or \a index records behind the - current record if \a index is negative). If the record at offset \a - index could not be retrieved, the result is positioned after the - last record if \a index >= 0, (or before the first record if \a - index is negative), and false is returned. If the record is - successfully retrieved, true is returned. - - \endlist - - \sa next(), previous(), first(), last(), at(), isActive(), isValid() -*/ -bool QSqlQuery::seek(int index, bool relative) -{ - if (!isSelect() || !isActive()) - return false; - int actualIdx; - if (!relative) { // arbitrary seek - if (index < 0) { - d->sqlResult->setAt(QSql::BeforeFirstRow); - return false; - } - actualIdx = index; - } else { - switch (at()) { // relative seek - case QSql::BeforeFirstRow: - if (index > 0) - actualIdx = index - 1; - else { - return false; - } - break; - case QSql::AfterLastRow: - if (index < 0) { - d->sqlResult->fetchLast(); - actualIdx = at() + index + 1; - } else { - return false; - } - break; - default: - if ((at() + index) < 0) { - d->sqlResult->setAt(QSql::BeforeFirstRow); - return false; - } - actualIdx = at() + index; - break; - } - } - // let drivers optimize - if (isForwardOnly() && actualIdx < at()) { - qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); - return false; - } - if (actualIdx == (at() + 1) && at() != QSql::BeforeFirstRow) { - if (!d->sqlResult->fetchNext()) { - d->sqlResult->setAt(QSql::AfterLastRow); - return false; - } - return true; - } - if (actualIdx == (at() - 1)) { - if (!d->sqlResult->fetchPrevious()) { - d->sqlResult->setAt(QSql::BeforeFirstRow); - return false; - } - return true; - } - if (!d->sqlResult->fetch(actualIdx)) { - d->sqlResult->setAt(QSql::AfterLastRow); - return false; - } - return true; -} - -/*! - - Retrieves the next record in the result, if available, and positions - the query on the retrieved record. Note that the result must be in - the \l{isActive()}{active} state and isSelect() must return true - before calling this function or it will do nothing and return false. - - The following rules apply: - - \list - - \li If the result is currently located before the first record, - e.g. immediately after a query is executed, an attempt is made to - retrieve the first record. - - \li If the result is currently located after the last record, there - is no change and false is returned. - - \li If the result is located somewhere in the middle, an attempt is - made to retrieve the next record. - - \endlist - - If the record could not be retrieved, the result is positioned after - the last record and false is returned. If the record is successfully - retrieved, true is returned. - - \sa previous(), first(), last(), seek(), at(), isActive(), isValid() -*/ -bool QSqlQuery::next() -{ - if (!isSelect() || !isActive()) - return false; - bool b = false; - switch (at()) { - case QSql::BeforeFirstRow: - b = d->sqlResult->fetchFirst(); - return b; - case QSql::AfterLastRow: - return false; - default: - if (!d->sqlResult->fetchNext()) { - d->sqlResult->setAt(QSql::AfterLastRow); - return false; - } - return true; - } -} - -/*! - - Retrieves the previous record in the result, if available, and - positions the query on the retrieved record. Note that the result - must be in the \l{isActive()}{active} state and isSelect() must - return true before calling this function or it will do nothing and - return false. - - The following rules apply: - - \list - - \li If the result is currently located before the first record, there - is no change and false is returned. - - \li If the result is currently located after the last record, an - attempt is made to retrieve the last record. - - \li If the result is somewhere in the middle, an attempt is made to - retrieve the previous record. - - \endlist - - If the record could not be retrieved, the result is positioned - before the first record and false is returned. If the record is - successfully retrieved, true is returned. - - \sa next(), first(), last(), seek(), at(), isActive(), isValid() -*/ -bool QSqlQuery::previous() -{ - if (!isSelect() || !isActive()) - return false; - if (isForwardOnly()) { - qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); - return false; - } - - bool b = false; - switch (at()) { - case QSql::BeforeFirstRow: - return false; - case QSql::AfterLastRow: - b = d->sqlResult->fetchLast(); - return b; - default: - if (!d->sqlResult->fetchPrevious()) { - d->sqlResult->setAt(QSql::BeforeFirstRow); - return false; - } - return true; - } -} - -/*! - Retrieves the first record in the result, if available, and - positions the query on the retrieved record. Note that the result - must be in the \l{isActive()}{active} state and isSelect() must - return true before calling this function or it will do nothing and - return false. Returns \c true if successful. If unsuccessful the query - position is set to an invalid position and false is returned. - - \sa next(), previous(), last(), seek(), at(), isActive(), isValid() - */ -bool QSqlQuery::first() -{ - if (!isSelect() || !isActive()) - return false; - if (isForwardOnly() && at() > QSql::BeforeFirstRow) { - qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query"); - return false; - } - bool b = false; - b = d->sqlResult->fetchFirst(); - return b; -} - -/*! - - Retrieves the last record in the result, if available, and positions - the query on the retrieved record. Note that the result must be in - the \l{isActive()}{active} state and isSelect() must return true - before calling this function or it will do nothing and return false. - Returns \c true if successful. If unsuccessful the query position is - set to an invalid position and false is returned. - - \sa next(), previous(), first(), seek(), at(), isActive(), isValid() -*/ - -bool QSqlQuery::last() -{ - if (!isSelect() || !isActive()) - return false; - bool b = false; - b = d->sqlResult->fetchLast(); - return b; -} - -/*! - Returns the size of the result (number of rows returned), or -1 if - the size cannot be determined or if the database does not support - reporting information about query sizes. Note that for non-\c SELECT - statements (isSelect() returns \c false), size() will return -1. If the - query is not active (isActive() returns \c false), -1 is returned. - - To determine the number of rows affected by a non-\c SELECT - statement, use numRowsAffected(). - - \sa isActive(), numRowsAffected(), QSqlDriver::hasFeature() -*/ -int QSqlQuery::size() const -{ - if (isActive() && d->sqlResult->driver()->hasFeature(QSqlDriver::QuerySize)) - return d->sqlResult->size(); - return -1; -} - -/*! - Returns the number of rows affected by the result's SQL statement, - or -1 if it cannot be determined. Note that for \c SELECT - statements, the value is undefined; use size() instead. If the query - is not \l{isActive()}{active}, -1 is returned. - - \sa size(), QSqlDriver::hasFeature() -*/ - -int QSqlQuery::numRowsAffected() const -{ - if (isActive()) - return d->sqlResult->numRowsAffected(); - return -1; -} - -/*! - Returns error information about the last error (if any) that - occurred with this query. - - \sa QSqlError, QSqlDatabase::lastError() -*/ - -QSqlError QSqlQuery::lastError() const -{ - return d->sqlResult->lastError(); -} - -/*! - Returns \c true if the query is currently positioned on a valid - record; otherwise returns \c false. -*/ - -bool QSqlQuery::isValid() const -{ - return d->sqlResult->isValid(); -} - -/*! - - Returns \c true if the query is \e{active}. An active QSqlQuery is one - that has been \l{QSqlQuery::exec()} {exec()'d} successfully but not - yet finished with. When you are finished with an active query, you - can make the query inactive by calling finish() or clear(), or - you can delete the QSqlQuery instance. - - \note Of particular interest is an active query that is a \c{SELECT} - statement. For some databases that support transactions, an active - query that is a \c{SELECT} statement can cause a \l{QSqlDatabase::} - {commit()} or a \l{QSqlDatabase::} {rollback()} to fail, so before - committing or rolling back, you should make your active \c{SELECT} - statement query inactive using one of the ways listed above. - - \sa isSelect() - */ -bool QSqlQuery::isActive() const -{ - return d->sqlResult->isActive(); -} - -/*! - Returns \c true if the current query is a \c SELECT statement; - otherwise returns \c false. -*/ - -bool QSqlQuery::isSelect() const -{ - return d->sqlResult->isSelect(); -} - -/*! - Returns \c true if you can only scroll forward through a result set; - otherwise returns \c false. - - \sa setForwardOnly(), next() -*/ -bool QSqlQuery::isForwardOnly() const -{ - return d->sqlResult->isForwardOnly(); -} - -/*! - Sets forward only mode to \a forward. If \a forward is true, only - next() and seek() with positive values, are allowed for navigating - the results. - - Forward only mode can be (depending on the driver) more memory - efficient since results do not need to be cached. It will also - improve performance on some databases. For this to be true, you must - call \c setForwardOnly() before the query is prepared or executed. - Note that the constructor that takes a query and a database may - execute the query. - - Forward only mode is off by default. - - Setting forward only to false is a suggestion to the database engine, - which has the final say on whether a result set is forward only or - scrollable. isForwardOnly() will always return the correct status of - the result set. - - \note Calling setForwardOnly after execution of the query will result - in unexpected results at best, and crashes at worst. - - \sa isForwardOnly(), next(), seek(), QSqlResult::setForwardOnly() -*/ -void QSqlQuery::setForwardOnly(bool forward) -{ - d->sqlResult->setForwardOnly(forward); -} - -/*! - Returns a QSqlRecord containing the field information for the - current query. If the query points to a valid row (isValid() returns - true), the record is populated with the row's values. An empty - record is returned when there is no active query (isActive() returns - false). - - To retrieve values from a query, value() should be used since - its index-based lookup is faster. - - In the following example, a \c{SELECT * FROM} query is executed. - Since the order of the columns is not defined, QSqlRecord::indexOf() - is used to obtain the index of a column. - - \snippet code/src_sql_kernel_qsqlquery.cpp 1 - - \sa value() -*/ -QSqlRecord QSqlQuery::record() const -{ - QSqlRecord rec = d->sqlResult->record(); - - if (isValid()) { - for (int i = 0; i < rec.count(); ++i) - rec.setValue(i, value(i)); - } - return rec; -} - -/*! - Clears the result set and releases any resources held by the - query. Sets the query state to inactive. You should rarely if ever - need to call this function. -*/ -void QSqlQuery::clear() -{ - *this = QSqlQuery(driver()->createResult()); -} - -/*! - Prepares the SQL query \a query for execution. Returns \c true if the - query is prepared successfully; otherwise returns \c false. - - The query may contain placeholders for binding values. Both Oracle - style colon-name (e.g., \c{:surname}), and ODBC style (\c{?}) - placeholders are supported; but they cannot be mixed in the same - query. See the \l{QSqlQuery examples}{Detailed Description} for - examples. - - Portability note: Some databases choose to delay preparing a query - until it is executed the first time. In this case, preparing a - syntactically wrong query succeeds, but every consecutive exec() - will fail. - - For SQLite, the query string can contain only one statement at a time. - If more than one statement is given, the function returns \c false. - - Example: - - \snippet sqldatabase/sqldatabase.cpp 9 - - \sa exec(), bindValue(), addBindValue() -*/ -bool QSqlQuery::prepare(const QString& query) -{ - if (d->ref.load() != 1) { - bool fo = isForwardOnly(); - *this = QSqlQuery(driver()->createResult()); - setForwardOnly(fo); - d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); - } else { - d->sqlResult->setActive(false); - d->sqlResult->setLastError(QSqlError()); - d->sqlResult->setAt(QSql::BeforeFirstRow); - d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); - } - if (!driver()) { - qWarning("QSqlQuery::prepare: no driver"); - return false; - } - if (!driver()->isOpen() || driver()->isOpenError()) { - qWarning("QSqlQuery::prepare: database not open"); - return false; - } - if (query.isEmpty()) { - qWarning("QSqlQuery::prepare: empty query"); - return false; - } -#ifdef QT_DEBUG_SQL - qDebug("\n QSqlQuery::prepare: %s", query.toLocal8Bit().constData()); -#endif - return d->sqlResult->savePrepare(query); -} - -/*! - Executes a previously prepared SQL query. Returns \c true if the query - executed successfully; otherwise returns \c false. - - Note that the last error for this query is reset when exec() is - called. - - \sa prepare(), bindValue(), addBindValue(), boundValue(), boundValues() -*/ -bool QSqlQuery::exec() -{ -#ifdef QT_DEBUG_SQL - QElapsedTimer t; - t.start(); -#endif - d->sqlResult->resetBindCount(); - - if (d->sqlResult->lastError().isValid()) - d->sqlResult->setLastError(QSqlError()); - - bool retval = d->sqlResult->exec(); -#ifdef QT_DEBUG_SQL - qDebug().nospace() << "Executed prepared query (" << t.elapsed() << "ms, " - << d->sqlResult->size() << " results, " << d->sqlResult->numRowsAffected() - << " affected): " << d->sqlResult->lastQuery(); -#endif - return retval; -} - -/*! \enum QSqlQuery::BatchExecutionMode - - \value ValuesAsRows - Updates multiple rows. Treats every entry in a QVariantList as a value for updating the next row. - \value ValuesAsColumns - Updates a single row. Treats every entry in a QVariantList as a single value of an array type. -*/ - -/*! - \since 4.2 - - Executes a previously prepared SQL query in a batch. All the bound - parameters have to be lists of variants. If the database doesn't - support batch executions, the driver will simulate it using - conventional exec() calls. - - Returns \c true if the query is executed successfully; otherwise - returns \c false. - - Example: - - \snippet code/src_sql_kernel_qsqlquery.cpp 2 - - The example above inserts four new rows into \c myTable: - - \snippet code/src_sql_kernel_qsqlquery.cpp 3 - - To bind NULL values, a null QVariant of the relevant type has to be - added to the bound QVariantList; for example, \c - {QVariant(QVariant::String)} should be used if you are using - strings. - - \note Every bound QVariantList must contain the same amount of - variants. - - \note The type of the QVariants in a list must not change. For - example, you cannot mix integer and string variants within a - QVariantList. - - The \a mode parameter indicates how the bound QVariantList will be - interpreted. If \a mode is \c ValuesAsRows, every variant within - the QVariantList will be interpreted as a value for a new row. \c - ValuesAsColumns is a special case for the Oracle driver. In this - mode, every entry within a QVariantList will be interpreted as - array-value for an IN or OUT value within a stored procedure. Note - that this will only work if the IN or OUT value is a table-type - consisting of only one column of a basic type, for example \c{TYPE - myType IS TABLE OF VARCHAR(64) INDEX BY BINARY_INTEGER;} - - \sa prepare(), bindValue(), addBindValue() -*/ -bool QSqlQuery::execBatch(BatchExecutionMode mode) -{ - d->sqlResult->resetBindCount(); - return d->sqlResult->execBatch(mode == ValuesAsColumns); -} - -/*! - Set the placeholder \a placeholder to be bound to value \a val in - the prepared statement. Note that the placeholder mark (e.g \c{:}) - must be included when specifying the placeholder name. If \a - paramType is QSql::Out or QSql::InOut, the placeholder will be - overwritten with data from the database after the exec() call. - In this case, sufficient space must be pre-allocated to store - the result into. - - To bind a NULL value, use a null QVariant; for example, use - \c {QVariant(QVariant::String)} if you are binding a string. - - \sa addBindValue(), prepare(), exec(), boundValue(), boundValues() -*/ -void QSqlQuery::bindValue(const QString& placeholder, const QVariant& val, - QSql::ParamType paramType -) -{ - d->sqlResult->bindValue(placeholder, val, paramType); -} - -/*! - Set the placeholder in position \a pos to be bound to value \a val - in the prepared statement. Field numbering starts at 0. If \a - paramType is QSql::Out or QSql::InOut, the placeholder will be - overwritten with data from the database after the exec() call. -*/ -void QSqlQuery::bindValue(int pos, const QVariant& val, QSql::ParamType paramType) -{ - d->sqlResult->bindValue(pos, val, paramType); -} - -/*! - Adds the value \a val to the list of values when using positional - value binding. The order of the addBindValue() calls determines - which placeholder a value will be bound to in the prepared query. - If \a paramType is QSql::Out or QSql::InOut, the placeholder will be - overwritten with data from the database after the exec() call. - - To bind a NULL value, use a null QVariant; for example, use \c - {QVariant(QVariant::String)} if you are binding a string. - - \sa bindValue(), prepare(), exec(), boundValue(), boundValues() -*/ -void QSqlQuery::addBindValue(const QVariant& val, QSql::ParamType paramType) -{ - d->sqlResult->addBindValue(val, paramType); -} - -/*! - Returns the value for the \a placeholder. - - \sa boundValues(), bindValue(), addBindValue() -*/ -QVariant QSqlQuery::boundValue(const QString& placeholder) const -{ - return d->sqlResult->boundValue(placeholder); -} - -/*! - Returns the value for the placeholder at position \a pos. -*/ -QVariant QSqlQuery::boundValue(int pos) const -{ - return d->sqlResult->boundValue(pos); -} - -/*! - Returns a map of the bound values. - - With named binding, the bound values can be examined in the - following ways: - - \snippet sqldatabase/sqldatabase.cpp 14 - - With positional binding, the code becomes: - - \snippet sqldatabase/sqldatabase.cpp 15 - - \sa boundValue(), bindValue(), addBindValue() -*/ -QMap QSqlQuery::boundValues() const -{ - QMap map; - - const QVector values(d->sqlResult->boundValues()); - for (int i = 0; i < values.count(); ++i) - map[d->sqlResult->boundValueName(i)] = values.at(i); - return map; -} - -/*! - Returns the last query that was successfully executed. - - In most cases this function returns the same string as lastQuery(). - If a prepared query with placeholders is executed on a DBMS that - does not support it, the preparation of this query is emulated. The - placeholders in the original query are replaced with their bound - values to form a new query. This function returns the modified - query. It is mostly useful for debugging purposes. - - \sa lastQuery() -*/ -QString QSqlQuery::executedQuery() const -{ - return d->sqlResult->executedQuery(); -} - -/*! - Returns the object ID of the most recent inserted row if the - database supports it. An invalid QVariant will be returned if the - query did not insert any value or if the database does not report - the id back. If more than one row was touched by the insert, the - behavior is undefined. - - For MySQL databases the row's auto-increment field will be returned. - - \note For this function to work in PSQL, the table table must - contain OIDs, which may not have been created by default. Check the - \c default_with_oids configuration variable to be sure. - - \sa QSqlDriver::hasFeature() -*/ -QVariant QSqlQuery::lastInsertId() const -{ - return d->sqlResult->lastInsertId(); -} - -/*! - - Instruct the database driver to return numerical values with a - precision specified by \a precisionPolicy. - - The Oracle driver, for example, can retrieve numerical values as - strings to prevent the loss of precision. If high precision doesn't - matter, use this method to increase execution speed by bypassing - string conversions. - - Note: Drivers that don't support fetching numerical values with low - precision will ignore the precision policy. You can use - QSqlDriver::hasFeature() to find out whether a driver supports this - feature. - - Note: Setting the precision policy doesn't affect the currently - active query. Call \l{exec()}{exec(QString)} or prepare() in order - to activate the policy. - - \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy() -*/ -void QSqlQuery::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) -{ - d->sqlResult->setNumericalPrecisionPolicy(precisionPolicy); -} - -/*! - Returns the current precision policy. - - \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy() -*/ -QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const -{ - return d->sqlResult->numericalPrecisionPolicy(); -} - -/*! - \since 4.3.2 - - Instruct the database driver that no more data will be fetched from - this query until it is re-executed. There is normally no need to - call this function, but it may be helpful in order to free resources - such as locks or cursors if you intend to re-use the query at a - later time. - - Sets the query to inactive. Bound values retain their values. - - \sa prepare(), exec(), isActive() -*/ -void QSqlQuery::finish() -{ - if (isActive()) { - d->sqlResult->setLastError(QSqlError()); - d->sqlResult->setAt(QSql::BeforeFirstRow); - d->sqlResult->detachFromResultSet(); - d->sqlResult->setActive(false); - } -} - -/*! - \since 4.4 - - Discards the current result set and navigates to the next if available. - - Some databases are capable of returning multiple result sets for - stored procedures or SQL batches (a query strings that contains - multiple statements). If multiple result sets are available after - executing a query this function can be used to navigate to the next - result set(s). - - If a new result set is available this function will return true. - The query will be repositioned on an \e invalid record in the new - result set and must be navigated to a valid record before data - values can be retrieved. If a new result set isn't available the - function returns \c false and the query is set to inactive. In any - case the old result set will be discarded. - - When one of the statements is a non-select statement a count of - affected rows may be available instead of a result set. - - Note that some databases, i.e. Microsoft SQL Server, requires - non-scrollable cursors when working with multiple result sets. Some - databases may execute all statements at once while others may delay - the execution until the result set is actually accessed, and some - databases may have restrictions on which statements are allowed to - be used in a SQL batch. - - \sa QSqlDriver::hasFeature(), setForwardOnly(), next(), isSelect(), - numRowsAffected(), isActive(), lastError() -*/ -bool QSqlQuery::nextResult() -{ - if (isActive()) - return d->sqlResult->nextResult(); - return false; -} - -QT_END_NAMESPACE From e6183b735fa2e01f334db1e33d5c9f59777835b9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:42:56 -0400 Subject: [PATCH 0977/1324] Delete qsqlquery.h --- src/qt/qsqlquery.h | 122 --------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 src/qt/qsqlquery.h diff --git a/src/qt/qsqlquery.h b/src/qt/qsqlquery.h deleted file mode 100644 index 243e4a04..00000000 --- a/src/qt/qsqlquery.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQLQUERY_H -#define QSQLQUERY_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - - -class QVariant; -class QSqlDriver; -class QSqlError; -class QSqlResult; -class QSqlRecord; -template class QMap; -class QSqlQueryPrivate; - -class Q_SQL_EXPORT QSqlQuery -{ -public: - explicit QSqlQuery(QSqlResult *r); - explicit QSqlQuery(const QString& query = QString(), QSqlDatabase db = QSqlDatabase()); - explicit QSqlQuery(QSqlDatabase db); - QSqlQuery(const QSqlQuery& other); - QSqlQuery& operator=(const QSqlQuery& other); - ~QSqlQuery(); - - bool isValid() const; - bool isActive() const; - bool isNull(int field) const; - bool isNull(const QString &name) const; - int at() const; - QString lastQuery() const; - int numRowsAffected() const; - QSqlError lastError() const; - bool isSelect() const; - int size() const; - const QSqlDriver* driver() const; - const QSqlResult* result() const; - bool isForwardOnly() const; - QSqlRecord record() const; - - void setForwardOnly(bool forward); - bool exec(const QString& query); - QVariant value(int i) const; - QVariant value(const QString& name) const; - - void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); - QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; - - bool seek(int i, bool relative = false); - bool next(); - bool previous(); - bool first(); - bool last(); - - void clear(); - - // prepared query support - bool exec(); - enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns }; - bool execBatch(BatchExecutionMode mode = ValuesAsRows); - bool prepare(const QString& query); - void bindValue(const QString& placeholder, const QVariant& val, - QSql::ParamType type = QSql::In); - void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In); - void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In); - QVariant boundValue(const QString& placeholder) const; - QVariant boundValue(int pos) const; - QMap boundValues() const; - QString executedQuery() const; - QVariant lastInsertId() const; - void finish(); - bool nextResult(); - -private: - QSqlQueryPrivate* d; -}; - -QT_END_NAMESPACE - -#endif // QSQLQUERY_H From 7ebc152be6109b7e9d1fed436e2d4329dc3f01f6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:06 -0400 Subject: [PATCH 0978/1324] Delete qsqlquerymodel.cpp --- src/qt/qsqlquerymodel.cpp | 680 -------------------------------------- 1 file changed, 680 deletions(-) delete mode 100644 src/qt/qsqlquerymodel.cpp diff --git a/src/qt/qsqlquerymodel.cpp b/src/qt/qsqlquerymodel.cpp deleted file mode 100644 index 864c5b99..00000000 --- a/src/qt/qsqlquerymodel.cpp +++ /dev/null @@ -1,680 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsqlquerymodel.h" -#include "qsqlquerymodel_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -#define QSQL_PREFETCH 255 - -void QSqlQueryModelPrivate::prefetch(int limit) -{ - Q_Q(QSqlQueryModel); - - if (atEnd || limit <= bottom.row() || bottom.column() == -1) - return; - - QModelIndex newBottom; - const int oldBottomRow = qMax(bottom.row(), 0); - - // try to seek directly - if (query.seek(limit)) { - newBottom = q->createIndex(limit, bottom.column()); - } else { - // have to seek back to our old position for MS Access - int i = oldBottomRow; - if (query.seek(i)) { - while (query.next()) - ++i; - newBottom = q->createIndex(i, bottom.column()); - } else { - // empty or invalid query - newBottom = q->createIndex(-1, bottom.column()); - } - atEnd = true; // this is the end. - } - if (newBottom.row() >= 0 && newBottom.row() > bottom.row()) { - q->beginInsertRows(QModelIndex(), bottom.row() + 1, newBottom.row()); - bottom = newBottom; - q->endInsertRows(); - } else { - bottom = newBottom; - } -} - -QSqlQueryModelPrivate::~QSqlQueryModelPrivate() -{ -} - -void QSqlQueryModelPrivate::initColOffsets(int size) -{ - colOffsets.resize(size); - memset(colOffsets.data(), 0, colOffsets.size() * sizeof(int)); -} - -int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const -{ - if (modelColumn < 0 || modelColumn >= rec.count() || !rec.isGenerated(modelColumn) || modelColumn >= colOffsets.size()) - return -1; - return modelColumn - colOffsets[modelColumn]; -} - -/*! - \class QSqlQueryModel - \brief The QSqlQueryModel class provides a read-only data model for SQL - result sets. - - \ingroup database - \inmodule QtSql - - QSqlQueryModel is a high-level interface for executing SQL - statements and traversing the result set. It is built on top of - the lower-level QSqlQuery and can be used to provide data to - view classes such as QTableView. For example: - - \snippet sqldatabase/sqldatabase.cpp 16 - - We set the model's query, then we set up the labels displayed in - the view header. - - QSqlQueryModel can also be used to access a database - programmatically, without binding it to a view: - - \snippet sqldatabase/sqldatabase.cpp 21 - - The code snippet above extracts the \c salary field from record 4 in - the result set of the query \c{SELECT * from employee}. Assuming - that \c salary is column 2, we can rewrite the last line as follows: - - \snippet sqldatabase/sqldatabase.cpp 22 - - The model is read-only by default. To make it read-write, you - must subclass it and reimplement setData() and flags(). Another - option is to use QSqlTableModel, which provides a read-write - model based on a single database table. - - The \l{querymodel} example illustrates how to use - QSqlQueryModel to display the result of a query. It also shows - how to subclass QSqlQueryModel to customize the contents of the - data before showing it to the user, and how to create a - read-write model based on QSqlQueryModel. - - If the database doesn't return the number of selected rows in - a query, the model will fetch rows incrementally. - See fetchMore() for more information. - - \sa QSqlTableModel, QSqlRelationalTableModel, QSqlQuery, - {Model/View Programming}, {Query Model Example} -*/ - -/*! - Creates an empty QSqlQueryModel with the given \a parent. - */ -QSqlQueryModel::QSqlQueryModel(QObject *parent) - : QAbstractTableModel(*new QSqlQueryModelPrivate, parent) -{ -} - -/*! \internal - */ -QSqlQueryModel::QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent) - : QAbstractTableModel(dd, parent) -{ -} - -/*! - Destroys the object and frees any allocated resources. - - \sa clear() -*/ -QSqlQueryModel::~QSqlQueryModel() -{ -} - -/*! - \since 4.1 - - Fetches more rows from a database. - This only affects databases that don't report back the size of a query - (see QSqlDriver::hasFeature()). - - To force fetching of the entire result set, you can use the following: - - \snippet code/src_sql_models_qsqlquerymodel.cpp 0 - - \a parent should always be an invalid QModelIndex. - - \sa canFetchMore() -*/ -void QSqlQueryModel::fetchMore(const QModelIndex &parent) -{ - Q_D(QSqlQueryModel); - if (parent.isValid()) - return; - d->prefetch(qMax(d->bottom.row(), 0) + QSQL_PREFETCH); -} - -/*! - \since 4.1 - - Returns \c true if it is possible to read more rows from the database. - This only affects databases that don't report back the size of a query - (see QSqlDriver::hasFeature()). - - \a parent should always be an invalid QModelIndex. - - \sa fetchMore() - */ -bool QSqlQueryModel::canFetchMore(const QModelIndex &parent) const -{ - Q_D(const QSqlQueryModel); - return (!parent.isValid() && !d->atEnd); -} - -/*! \internal - */ -void QSqlQueryModel::beginInsertRows(const QModelIndex &parent, int first, int last) -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::beginInsertRows(parent, first, last); -} - -/*! \internal - */ -void QSqlQueryModel::endInsertRows() -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::endInsertRows(); -} - -/*! \internal - */ -void QSqlQueryModel::beginRemoveRows(const QModelIndex &parent, int first, int last) -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::beginRemoveRows(parent, first, last); -} - -/*! \internal - */ -void QSqlQueryModel::endRemoveRows() -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::endRemoveRows(); -} - -/*! \internal - */ -void QSqlQueryModel::beginInsertColumns(const QModelIndex &parent, int first, int last) -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::beginInsertColumns(parent, first, last); -} - -/*! \internal - */ -void QSqlQueryModel::endInsertColumns() -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::endInsertColumns(); -} - -/*! \internal - */ -void QSqlQueryModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::beginRemoveColumns(parent, first, last); -} - -/*! \internal - */ -void QSqlQueryModel::endRemoveColumns() -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::endRemoveColumns(); -} - -/*! \internal - */ -void QSqlQueryModel::beginResetModel() -{ - Q_D(QSqlQueryModel); - if (!d->nestedResetLevel) - QAbstractTableModel::beginResetModel(); - ++d->nestedResetLevel; -} - -/*! \internal - */ -void QSqlQueryModel::endResetModel() -{ - Q_D(QSqlQueryModel); - --d->nestedResetLevel; - if (!d->nestedResetLevel) - QAbstractTableModel::endResetModel(); -} - -/*! \fn int QSqlQueryModel::rowCount(const QModelIndex &parent) const - \since 4.1 - - If the database supports returning the size of a query - (see QSqlDriver::hasFeature()), the number of rows of the current - query is returned. Otherwise, returns the number of rows - currently cached on the client. - - \a parent should always be an invalid QModelIndex. - - \sa canFetchMore(), QSqlDriver::hasFeature() - */ -int QSqlQueryModel::rowCount(const QModelIndex &index) const -{ - Q_D(const QSqlQueryModel); - return index.isValid() ? 0 : d->bottom.row() + 1; -} - -/*! \reimp - */ -int QSqlQueryModel::columnCount(const QModelIndex &index) const -{ - Q_D(const QSqlQueryModel); - return index.isValid() ? 0 : d->rec.count(); -} - -/*! - Returns the value for the specified \a item and \a role. - - If \a item is out of bounds or if an error occurred, an invalid - QVariant is returned. - - \sa lastError() -*/ -QVariant QSqlQueryModel::data(const QModelIndex &item, int role) const -{ - Q_D(const QSqlQueryModel); - if (!item.isValid()) - return QVariant(); - - QVariant v; - if (role & ~(Qt::DisplayRole | Qt::EditRole)) - return v; - - if (!d->rec.isGenerated(item.column())) - return v; - QModelIndex dItem = indexInQuery(item); - if (dItem.row() > d->bottom.row()) - const_cast(d)->prefetch(dItem.row()); - - if (!d->query.seek(dItem.row())) { - d->error = d->query.lastError(); - return v; - } - - return d->query.value(dItem.column()); -} - -/*! - Returns the header data for the given \a role in the \a section - of the header with the specified \a orientation. -*/ -QVariant QSqlQueryModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_D(const QSqlQueryModel); - if (orientation == Qt::Horizontal) { - QVariant val = d->headers.value(section).value(role); - if (role == Qt::DisplayRole && !val.isValid()) - val = d->headers.value(section).value(Qt::EditRole); - if (val.isValid()) - return val; - if (role == Qt::DisplayRole && d->rec.count() > section && d->columnInQuery(section) != -1) - return d->rec.fieldName(section); - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -/*! - This virtual function is called whenever the query changes. The - default implementation does nothing. - - query() returns the new query. - - \sa query(), setQuery() - */ -void QSqlQueryModel::queryChange() -{ - // do nothing -} - -/*! - Resets the model and sets the data provider to be the given \a - query. Note that the query must be active and must not be - isForwardOnly(). - - lastError() can be used to retrieve verbose information if there - was an error setting the query. - - \note Calling setQuery() will remove any inserted columns. - - \sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError() -*/ -void QSqlQueryModel::setQuery(const QSqlQuery &query) -{ - Q_D(QSqlQueryModel); - beginResetModel(); - - QSqlRecord newRec = query.record(); - bool columnsChanged = (newRec != d->rec); - - if (d->colOffsets.size() != newRec.count() || columnsChanged) - d->initColOffsets(newRec.count()); - - d->bottom = QModelIndex(); - d->error = QSqlError(); - d->query = query; - d->rec = newRec; - d->atEnd = true; - - if (query.isForwardOnly()) { - d->error = QSqlError(QLatin1String("Forward-only queries " - "cannot be used in a data model"), - QString(), QSqlError::ConnectionError); - endResetModel(); - return; - } - - if (!query.isActive()) { - d->error = query.lastError(); - endResetModel(); - return; - } - - if (query.driver()->hasFeature(QSqlDriver::QuerySize) && d->query.size() > 0) { - d->bottom = createIndex(d->query.size() - 1, d->rec.count() - 1); - } else { - d->bottom = createIndex(-1, d->rec.count() - 1); - d->atEnd = false; - } - - - // fetchMore does the rowsInserted stuff for incremental models - fetchMore(); - - endResetModel(); - queryChange(); -} - -/*! \overload - - Executes the query \a query for the given database connection \a - db. If no database (or an invalid database) is specified, the - default connection is used. - - lastError() can be used to retrieve verbose information if there - was an error setting the query. - - Example: - \snippet code/src_sql_models_qsqlquerymodel.cpp 1 - - \sa query(), queryChange(), lastError() -*/ -void QSqlQueryModel::setQuery(const QString &query, const QSqlDatabase &db) -{ - setQuery(QSqlQuery(query, db)); -} - -/*! - Clears the model and releases any acquired resource. -*/ -void QSqlQueryModel::clear() -{ - Q_D(QSqlQueryModel); - beginResetModel(); - d->error = QSqlError(); - d->atEnd = true; - d->query.clear(); - d->rec.clear(); - d->colOffsets.clear(); - d->bottom = QModelIndex(); - d->headers.clear(); - endResetModel(); -} - -/*! - Sets the caption for a horizontal header for the specified \a role to - \a value. This is useful if the model is used to - display data in a view (e.g., QTableView). - - Returns \c true if \a orientation is Qt::Horizontal and - the \a section refers to a valid section; otherwise returns - false. - - Note that this function cannot be used to modify values in the - database since the model is read-only. - - \sa data() - */ -bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation, - const QVariant &value, int role) -{ - Q_D(QSqlQueryModel); - if (orientation != Qt::Horizontal || section < 0 || columnCount() <= section) - return false; - - if (d->headers.size() <= section) - d->headers.resize(qMax(section + 1, 16)); - d->headers[section][role] = value; - emit headerDataChanged(orientation, section, section); - return true; -} - -/*! - Returns the QSqlQuery associated with this model. - - \sa setQuery() -*/ -QSqlQuery QSqlQueryModel::query() const -{ - Q_D(const QSqlQueryModel); - return d->query; -} - -/*! - Returns information about the last error that occurred on the - database. - - \sa query() -*/ -QSqlError QSqlQueryModel::lastError() const -{ - Q_D(const QSqlQueryModel); - return d->error; -} - -/*! - Protected function which allows derived classes to set the value of - the last error that occurred on the database to \a error. - - \sa lastError() -*/ -void QSqlQueryModel::setLastError(const QSqlError &error) -{ - Q_D(QSqlQueryModel); - d->error = error; -} - -/*! - Returns the record containing information about the fields of the - current query. If \a row is the index of a valid row, the record - will be populated with values from that row. - - If the model is not initialized, an empty record will be - returned. - - \sa QSqlRecord::isEmpty() -*/ -QSqlRecord QSqlQueryModel::record(int row) const -{ - Q_D(const QSqlQueryModel); - if (row < 0) - return d->rec; - - QSqlRecord rec = d->rec; - for (int i = 0; i < rec.count(); ++i) - rec.setValue(i, data(createIndex(row, i), Qt::EditRole)); - return rec; -} - -/*! \overload - - Returns an empty record containing information about the fields - of the current query. - - If the model is not initialized, an empty record will be - returned. - - \sa QSqlRecord::isEmpty() - */ -QSqlRecord QSqlQueryModel::record() const -{ - Q_D(const QSqlQueryModel); - return d->rec; -} - -/*! - Inserts \a count columns into the model at position \a column. The - \a parent parameter must always be an invalid QModelIndex, since - the model does not support parent-child relationships. - - Returns \c true if \a column is within bounds; otherwise returns \c false. - - By default, inserted columns are empty. To fill them with data, - reimplement data() and handle any inserted column separately: - - \snippet sqldatabase/sqldatabase.cpp 23 - - \sa removeColumns() -*/ -bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex &parent) -{ - Q_D(QSqlQueryModel); - if (count <= 0 || parent.isValid() || column < 0 || column > d->rec.count()) - return false; - - beginInsertColumns(parent, column, column + count - 1); - for (int c = 0; c < count; ++c) { - QSqlField field; - field.setReadOnly(true); - field.setGenerated(false); - d->rec.insert(column, field); - if (d->colOffsets.size() < d->rec.count()) { - int nVal = d->colOffsets.isEmpty() ? 0 : d->colOffsets[d->colOffsets.size() - 1]; - d->colOffsets.append(nVal); - Q_ASSERT(d->colOffsets.size() >= d->rec.count()); - } - for (int i = column + 1; i < d->colOffsets.count(); ++i) - ++d->colOffsets[i]; - } - endInsertColumns(); - return true; -} - -/*! - Removes \a count columns from the model starting from position \a - column. The \a parent parameter must always be an invalid - QModelIndex, since the model does not support parent-child - relationships. - - Removing columns effectively hides them. It does not affect the - underlying QSqlQuery. - - Returns \c true if the columns were removed; otherwise returns \c false. - */ -bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &parent) -{ - Q_D(QSqlQueryModel); - if (count <= 0 || parent.isValid() || column < 0 || column >= d->rec.count()) - return false; - - beginRemoveColumns(parent, column, column + count - 1); - - int i; - for (i = 0; i < count; ++i) - d->rec.remove(column); - for (i = column; i < d->colOffsets.count(); ++i) - d->colOffsets[i] -= count; - - endRemoveColumns(); - return true; -} - -/*! - Returns the index of the value in the database result set for the - given \a item in the model. - - The return value is identical to \a item if no columns or rows - have been inserted, removed, or moved around. - - Returns an invalid model index if \a item is out of bounds or if - \a item does not point to a value in the result set. - - \sa QSqlTableModel::indexInQuery(), insertColumns(), removeColumns() -*/ -QModelIndex QSqlQueryModel::indexInQuery(const QModelIndex &item) const -{ - Q_D(const QSqlQueryModel); - int modelColumn = d->columnInQuery(item.column()); - if (modelColumn < 0) - return QModelIndex(); - return createIndex(item.row(), modelColumn, item.internalPointer()); -} - -QT_END_NAMESPACE From a99b97b605f9b1170668002e98640e918acfe8bd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:14 -0400 Subject: [PATCH 0979/1324] Delete qsqlquerymodel.h --- src/qt/qsqlquerymodel.h | 112 ---------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 src/qt/qsqlquerymodel.h diff --git a/src/qt/qsqlquerymodel.h b/src/qt/qsqlquerymodel.h deleted file mode 100644 index 6c769f93..00000000 --- a/src/qt/qsqlquerymodel.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQLQUERYMODEL_H -#define QSQLQUERYMODEL_H - -#include -#include "qsqldatabase.h" - -QT_BEGIN_NAMESPACE - - -class QSqlQueryModelPrivate; -class QSqlError; -class QSqlRecord; -class QSqlQuery; - -class Q_SQL_EXPORT QSqlQueryModel: public QAbstractTableModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QSqlQueryModel) - -public: - explicit QSqlQueryModel(QObject *parent = Q_NULLPTR); - virtual ~QSqlQueryModel(); - - int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - QSqlRecord record(int row) const; - QSqlRecord record() const; - - QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, - int role = Qt::EditRole) Q_DECL_OVERRIDE; - - bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - - void setQuery(const QSqlQuery &query); - void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase()); - QSqlQuery query() const; - - virtual void clear(); - - QSqlError lastError() const; - - void fetchMore(const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - bool canFetchMore(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - -protected: - void beginInsertRows(const QModelIndex &parent, int first, int last); - void endInsertRows(); - - void beginRemoveRows(const QModelIndex &parent, int first, int last); - void endRemoveRows(); - - void beginInsertColumns(const QModelIndex &parent, int first, int last); - void endInsertColumns(); - - void beginRemoveColumns(const QModelIndex &parent, int first, int last); - void endRemoveColumns(); - - void beginResetModel(); - void endResetModel(); - virtual void queryChange(); - - virtual QModelIndex indexInQuery(const QModelIndex &item) const; - void setLastError(const QSqlError &error); - QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent = Q_NULLPTR); -}; - -QT_END_NAMESPACE - -#endif // QSQLQUERYMODEL_H From 18d68c90ef6506d45393aac1427db7c1b67dac2a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:23 -0400 Subject: [PATCH 0980/1324] Delete qsqlrecord.h --- src/qt/qsqlrecord.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/qsqlrecord.h diff --git a/src/qt/qsqlrecord.h b/src/qt/qsqlrecord.h deleted file mode 100644 index 87748dfa..00000000 --- a/src/qt/qsqlrecord.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../src/sql/kernel/qsqlrecord.h" From 9414566c3ac69ccfd14396370956b0f943bfb076 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:31 -0400 Subject: [PATCH 0981/1324] Delete qsqlresult.h --- src/qt/qsqlresult.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/qt/qsqlresult.h diff --git a/src/qt/qsqlresult.h b/src/qt/qsqlresult.h deleted file mode 100644 index 723eb26c..00000000 --- a/src/qt/qsqlresult.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../src/sql/kernel/qsqlresult.h" From 24157bc109551d55dcad3fdbd9b5981500637ba7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:39 -0400 Subject: [PATCH 0982/1324] Delete qsqltablemodel.cpp --- src/qt/qsqltablemodel.cpp | 1450 ------------------------------------- 1 file changed, 1450 deletions(-) delete mode 100644 src/qt/qsqltablemodel.cpp diff --git a/src/qt/qsqltablemodel.cpp b/src/qt/qsqltablemodel.cpp deleted file mode 100644 index 9932fb75..00000000 --- a/src/qt/qsqltablemodel.cpp +++ /dev/null @@ -1,1450 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsqltablemodel.h" - -#include "qsqldriver.h" -#include "qsqlerror.h" -#include "qsqlfield.h" -#include "qsqlindex.h" -#include "qsqlquery.h" -#include "qsqlrecord.h" -#include "qsqlresult.h" - -#include "qsqltablemodel_p.h" - -#include - -QT_BEGIN_NAMESPACE - -typedef QSqlTableModelSql Sql; - -/*! \internal - Populates our record with values. -*/ -QSqlRecord QSqlTableModelPrivate::record(const QVector &values) const -{ - QSqlRecord r = rec; - for (int i = 0; i < r.count() && i < values.count(); ++i) - r.setValue(i, values.at(i)); - return r; -} - -int QSqlTableModelPrivate::nameToIndex(const QString &name) const -{ - return rec.indexOf(strippedFieldName(name)); -} - -QString QSqlTableModelPrivate::strippedFieldName(const QString &name) const -{ - QString fieldname = name; - if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)) - fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName); - return fieldname; -} - -int QSqlTableModelPrivate::insertCount(int maxRow) const -{ - int cnt = 0; - CacheMap::ConstIterator i = cache.constBegin(); - const CacheMap::ConstIterator e = cache.constEnd(); - for ( ; i != e && (maxRow < 0 || i.key() <= maxRow); ++i) - if (i.value().insert()) - ++cnt; - - return cnt; -} - -void QSqlTableModelPrivate::initRecordAndPrimaryIndex() -{ - rec = db.record(tableName); - primaryIndex = db.primaryIndex(tableName); - initColOffsets(rec.count()); -} - -void QSqlTableModelPrivate::clear() -{ - sortColumn = -1; - sortOrder = Qt::AscendingOrder; - tableName.clear(); - editQuery.clear(); - cache.clear(); - primaryIndex.clear(); - rec.clear(); - filter.clear(); -} - -void QSqlTableModelPrivate::clearCache() -{ - cache.clear(); -} - -void QSqlTableModelPrivate::revertCachedRow(int row) -{ - Q_Q(QSqlTableModel); - ModifiedRow r = cache.value(row); - - switch (r.op()) { - case QSqlTableModelPrivate::None: - Q_ASSERT_X(false, "QSqlTableModelPrivate::revertCachedRow()", "Invalid entry in cache map"); - return; - case QSqlTableModelPrivate::Update: - case QSqlTableModelPrivate::Delete: - if (!r.submitted()) { - cache[row].revert(); - emit q->dataChanged(q->createIndex(row, 0), - q->createIndex(row, q->columnCount() - 1)); - } - break; - case QSqlTableModelPrivate::Insert: { - QMap::Iterator it = cache.find(row); - if (it == cache.end()) - return; - q->beginRemoveRows(QModelIndex(), row, row); - it = cache.erase(it); - while (it != cache.end()) { - int oldKey = it.key(); - const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); - cache.erase(it); - it = cache.insert(oldKey - 1, oldValue); - ++it; - } - q->endRemoveRows(); - break; } - } -} - -bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, - const QSqlRecord &rec, const QSqlRecord &whereValues) -{ - if (stmt.isEmpty()) - return false; - - // lazy initialization of editQuery - if (editQuery.driver() != db.driver()) - editQuery = QSqlQuery(db); - - // workaround for In-Process databases - remove all read locks - // from the table to make sure the editQuery succeeds - if (db.driver()->hasFeature(QSqlDriver::SimpleLocking)) - const_cast(query.result())->detachFromResultSet(); - - if (prepStatement) { - if (editQuery.lastQuery() != stmt) { - if (!editQuery.prepare(stmt)) { - error = editQuery.lastError(); - return false; - } - } - int i; - for (i = 0; i < rec.count(); ++i) - if (rec.isGenerated(i)) - editQuery.addBindValue(rec.value(i)); - for (i = 0; i < whereValues.count(); ++i) - if (whereValues.isGenerated(i) && !whereValues.isNull(i)) - editQuery.addBindValue(whereValues.value(i)); - - if (!editQuery.exec()) { - error = editQuery.lastError(); - return false; - } - } else { - if (!editQuery.exec(stmt)) { - error = editQuery.lastError(); - return false; - } - } - return true; -} - -/*! - \class QSqlTableModel - \brief The QSqlTableModel class provides an editable data model - for a single database table. - - \ingroup database - \inmodule QtSql - - QSqlTableModel is a high-level interface for reading and writing - database records from a single table. It is built on top of the - lower-level QSqlQuery and can be used to provide data to view - classes such as QTableView. For example: - - \snippet sqldatabase/sqldatabase.cpp 24 - - We set the SQL table's name and the edit strategy, then we set up - the labels displayed in the view header. The edit strategy - dictates when the changes done by the user in the view are - actually applied to the database. The possible values are \l - OnFieldChange, \l OnRowChange, and \l OnManualSubmit. - - QSqlTableModel can also be used to access a database - programmatically, without binding it to a view: - - \snippet sqldatabase/sqldatabase.cpp 21 - - The code snippet above extracts the \c salary field from record 4 in - the result set of the query \c{SELECT * from employee}. - - It is possible to set filters using setFilter(), or modify the - sort order using setSort(). At the end, you must call select() to - populate the model with data. - - The \l{tablemodel} example illustrates how to use - QSqlTableModel as the data source for a QTableView. - - QSqlTableModel provides no direct support for foreign keys. Use - the QSqlRelationalTableModel and QSqlRelationalDelegate if you - want to resolve foreign keys. - - \sa QSqlRelationalTableModel, QSqlQuery, {Model/View Programming}, - {Table Model Example}, {Cached Table Example} -*/ - -/*! - \fn QSqlTableModel::beforeDelete(int row) - - This signal is emitted by deleteRowFromTable() before the \a row - is deleted from the currently active database table. -*/ - -/*! - \fn void QSqlTableModel::primeInsert(int row, QSqlRecord &record) - - This signal is emitted by insertRows(), when an insertion is - initiated in the given \a row of the currently active database - table. The \a record parameter can be written to (since it is a - reference), for example to populate some fields with default - values and set the generated flags of the fields. Do not try to - edit the record via other means such as setData() or setRecord() - while handling this signal. -*/ - -/*! - \fn QSqlTableModel::beforeInsert(QSqlRecord &record) - - This signal is emitted by insertRowIntoTable() before a new row is - inserted into the currently active database table. The values that - are about to be inserted are stored in \a record and can be - modified before they will be inserted. -*/ - -/*! - \fn QSqlTableModel::beforeUpdate(int row, QSqlRecord &record) - - This signal is emitted by updateRowInTable() before the \a row is - updated in the currently active database table with the values - from \a record. - - Note that only values that are marked as generated will be updated. - The generated flag can be set with \l QSqlRecord::setGenerated() - and checked with \l QSqlRecord::isGenerated(). - - \sa QSqlRecord::isGenerated() -*/ - -/*! - Creates an empty QSqlTableModel and sets the parent to \a parent - and the database connection to \a db. If \a db is not valid, the - default database connection will be used. - - The default edit strategy is \l OnRowChange. -*/ -QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) - : QSqlQueryModel(*new QSqlTableModelPrivate, parent) -{ - Q_D(QSqlTableModel); - d->db = db.isValid() ? db : QSqlDatabase::database(); -} - -/*! \internal -*/ -QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, QSqlDatabase db) - : QSqlQueryModel(dd, parent) -{ - Q_D(QSqlTableModel); - d->db = db.isValid() ? db : QSqlDatabase::database(); -} - -/*! - Destroys the object and frees any allocated resources. -*/ -QSqlTableModel::~QSqlTableModel() -{ -} - -/*! - Sets the database table on which the model operates to \a - tableName. Does not select data from the table, but fetches its - field information. - - To populate the model with the table's data, call select(). - - Error information can be retrieved with \l lastError(). - - \sa select(), setFilter(), lastError() -*/ -void QSqlTableModel::setTable(const QString &tableName) -{ - Q_D(QSqlTableModel); - clear(); - d->tableName = tableName; - d->initRecordAndPrimaryIndex(); - - if (d->rec.count() == 0) - d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), - QSqlError::StatementError); - - // Remember the auto index column if there is one now. - // The record that will be obtained from the query after select lacks this feature. - d->autoColumn.clear(); - for (int c = 0; c < d->rec.count(); ++c) { - if (d->rec.field(c).isAutoValue()) { - d->autoColumn = d->rec.fieldName(c); - break; - } - } -} - -/*! - Returns the name of the currently selected table. -*/ -QString QSqlTableModel::tableName() const -{ - Q_D(const QSqlTableModel); - return d->tableName; -} - -/*! - Populates the model with data from the table that was set via setTable(), using the - specified filter and sort condition, and returns \c true if successful; otherwise - returns \c false. - - \note Calling select() will revert any unsubmitted changes and remove any inserted columns. - - \sa setTable(), setFilter(), selectStatement() -*/ -bool QSqlTableModel::select() -{ - Q_D(QSqlTableModel); - const QString query = selectStatement(); - if (query.isEmpty()) - return false; - - beginResetModel(); - - d->clearCache(); - - QSqlQuery qu(query, d->db); - setQuery(qu); - - if (!qu.isActive() || lastError().isValid()) { - // something went wrong - revert to non-select state - d->initRecordAndPrimaryIndex(); - endResetModel(); - return false; - } - endResetModel(); - return true; -} - -/*! - \since 5.0 - - Refreshes \a row in the model with values from the database table row matching - on primary key values. Without a primary key, all column values must match. If - no matching row is found, the model will show an empty row. - - Returns \c true if successful; otherwise returns \c false. - - \sa select() -*/ -bool QSqlTableModel::selectRow(int row) -{ - Q_D(QSqlTableModel); - - if (row < 0 || row >= rowCount()) - return false; - - const int table_sort_col = d->sortColumn; - d->sortColumn = -1; - const QString table_filter = d->filter; - d->filter = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, - d->tableName, - primaryValues(row), - false); - static const QString wh = Sql::where() + Sql::sp(); - if (d->filter.startsWith(wh, Qt::CaseInsensitive)) - d->filter.remove(0, wh.length()); - - QString stmt; - - if (!d->filter.isEmpty()) - stmt = selectStatement(); - - d->sortColumn = table_sort_col; - d->filter = table_filter; - - if (stmt.isEmpty()) - return false; - - bool exists; - QSqlRecord newValues; - - { - QSqlQuery q(d->db); - q.setForwardOnly(true); - if (!q.exec(stmt)) - return false; - - exists = q.next(); - newValues = q.record(); - } - - bool needsAddingToCache = !exists || d->cache.contains(row); - - if (!needsAddingToCache) { - const QSqlRecord curValues = record(row); - needsAddingToCache = curValues.count() != newValues.count(); - if (!needsAddingToCache) { - // Look for changed values. Primary key fields are customarily first - // and probably change less often than other fields, so start at the end. - for (int f = curValues.count() - 1; f >= 0; --f) { - if (curValues.value(f) != newValues.value(f)) { - needsAddingToCache = true; - break; - } - } - } - } - - if (needsAddingToCache) { - d->cache[row].refresh(exists, newValues); - emit headerDataChanged(Qt::Vertical, row, row); - emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); - } - - return true; -} - -/*! - \reimp -*/ -QVariant QSqlTableModel::data(const QModelIndex &index, int role) const -{ - Q_D(const QSqlTableModel); - if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole)) - return QVariant(); - - const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); - if (mrow.op() != QSqlTableModelPrivate::None) - return mrow.rec().value(index.column()); - - return QSqlQueryModel::data(index, role); -} - -/*! - \reimp -*/ -QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_D(const QSqlTableModel); - if (orientation == Qt::Vertical && role == Qt::DisplayRole) { - const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); - if (op == QSqlTableModelPrivate::Insert) - return QLatin1String("*"); - else if (op == QSqlTableModelPrivate::Delete) - return QLatin1String("!"); - } - return QSqlQueryModel::headerData(section, orientation, role); -} - -/*! - \overload - \since 5.0 - - Returns \c true if the model contains modified values that have not been - committed to the database, otherwise false. -*/ -bool QSqlTableModel::isDirty() const -{ - Q_D(const QSqlTableModel); - QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); - const QSqlTableModelPrivate::CacheMap::ConstIterator e = d->cache.constEnd(); - for (; i != e; ++i) { - if (!i.value().submitted()) - return true; - } - return false; -} - -/*! - Returns \c true if the value at the index \a index is dirty, otherwise false. - Dirty values are values that were modified in the model - but not yet written into the database. - - If \a index is invalid or points to a non-existing row, false is returned. -*/ -bool QSqlTableModel::isDirty(const QModelIndex &index) const -{ - Q_D(const QSqlTableModel); - if (!index.isValid()) - return false; - - const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); - if (row.submitted()) - return false; - - return row.op() == QSqlTableModelPrivate::Insert - || row.op() == QSqlTableModelPrivate::Delete - || (row.op() == QSqlTableModelPrivate::Update - && row.rec().isGenerated(index.column())); -} - -/*! - Sets the data for the item \a index for the role \a role to \a - value. - - For edit strategy OnFieldChange, an index may receive a change - only if no other index has a cached change. Changes are - submitted immediately. However, rows that have not yet been - inserted in the database may be freely changed and are not - submitted automatically. Submitted changes are not reverted upon - failure. - - For OnRowChange, an index may receive a change only if no other - row has a cached change. Changes are not submitted automatically. - - Returns \c true if \a value is equal to the current value. However, - the value will not be submitted to the database. - - Returns \c true if the value could be set or false on error, for - example if \a index is out of bounds. - - \sa editStrategy(), data(), submit(), submitAll(), revertRow() -*/ -bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - Q_D(QSqlTableModel); - if (d->busyInsertingRows) - return false; - - if (role != Qt::EditRole) - return QSqlQueryModel::setData(index, value, role); - - if (!index.isValid() || index.column() >= d->rec.count() || index.row() >= rowCount()) - return false; - - if (!(flags(index) & Qt::ItemIsEditable)) - return false; - - const QVariant oldValue = QSqlTableModel::data(index, role); - if (value == oldValue - && value.isNull() == oldValue.isNull() - && d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert) - return true; - - QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; - - if (row.op() == QSqlTableModelPrivate::None) - row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - QSqlQueryModel::record(index.row())); - - row.setValue(index.column(), value); - emit dataChanged(index, index); - - if (d->strategy == OnFieldChange && row.op() != QSqlTableModelPrivate::Insert) - return submit(); - - return true; -} - -/*! - This function simply calls QSqlQueryModel::setQuery(\a query). - You should normally not call it on a QSqlTableModel. Instead, use - setTable(), setSort(), setFilter(), etc., to set up the query. - - \sa selectStatement() -*/ -void QSqlTableModel::setQuery(const QSqlQuery &query) -{ - QSqlQueryModel::setQuery(query); -} - -/*! - Updates the given \a row in the currently active database table - with the specified \a values. Returns \c true if successful; otherwise - returns \c false. - - This is a low-level method that operates directly on the database - and should not be called directly. Use setData() to update values. - The model will decide depending on its edit strategy when to modify - the database. - - Note that only values that have the generated-flag set are updated. - The generated-flag can be set with QSqlRecord::setGenerated() and - tested with QSqlRecord::isGenerated(). - - \sa QSqlRecord::isGenerated(), setData() -*/ -bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) -{ - Q_D(QSqlTableModel); - QSqlRecord rec(values); - emit beforeUpdate(row, rec); - - const QSqlRecord whereValues = primaryValues(row); - const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); - const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, - rec, prepStatement); - const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, - whereValues, prepStatement); - - if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) { - d->error = QSqlError(QLatin1String("No Fields to update"), QString(), - QSqlError::StatementError); - return false; - } - - return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues); -} - - -/*! - Inserts the values \a values into the currently active database table. - - This is a low-level method that operates directly on the database - and should not be called directly. Use insertRow() and setData() - to insert values. The model will decide depending on its edit strategy - when to modify the database. - - Returns \c true if the values could be inserted, otherwise false. - Error information can be retrieved with \l lastError(). - - \sa lastError(), insertRow(), insertRows() -*/ -bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values) -{ - Q_D(QSqlTableModel); - QSqlRecord rec = values; - emit beforeInsert(rec); - - const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); - const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName, - rec, prepStatement); - - if (stmt.isEmpty()) { - d->error = QSqlError(QLatin1String("No Fields to update"), QString(), - QSqlError::StatementError); - return false; - } - - return d->exec(stmt, prepStatement, rec, QSqlRecord() /* no where values */); -} - -/*! - Deletes the given \a row from the currently active database table. - - This is a low-level method that operates directly on the database - and should not be called directly. Use removeRow() or removeRows() - to delete values. The model will decide depending on its edit strategy - when to modify the database. - - Returns \c true if the row was deleted; otherwise returns \c false. - - \sa removeRow(), removeRows() -*/ -bool QSqlTableModel::deleteRowFromTable(int row) -{ - Q_D(QSqlTableModel); - emit beforeDelete(row); - - const QSqlRecord whereValues = primaryValues(row); - const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); - const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, - d->tableName, - QSqlRecord(), - prepStatement); - const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, - d->tableName, - whereValues, - prepStatement); - - if (stmt.isEmpty() || where.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), - QSqlError::StatementError); - return false; - } - - return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() /* no new values */, whereValues); -} - -/*! - Submits all pending changes and returns \c true on success. - Returns \c false on error, detailed error information can be - obtained with lastError(). - - In OnManualSubmit, on success the model will be repopulated. - Any views presenting it will lose their selections. - - Note: In OnManualSubmit mode, already submitted changes won't - be cleared from the cache when submitAll() fails. This allows - transactions to be rolled back and resubmitted without - losing data. - - \sa revertAll(), lastError() -*/ -bool QSqlTableModel::submitAll() -{ - Q_D(QSqlTableModel); - - bool success = true; - - const auto cachedKeys = d->cache.keys(); - for (int row : cachedKeys) { - // be sure cache *still* contains the row since overridden selectRow() could have called select() - QSqlTableModelPrivate::CacheMap::iterator it = d->cache.find(row); - if (it == d->cache.end()) - continue; - - QSqlTableModelPrivate::ModifiedRow &mrow = it.value(); - if (mrow.submitted()) - continue; - - switch (mrow.op()) { - case QSqlTableModelPrivate::Insert: - success = insertRowIntoTable(mrow.rec()); - break; - case QSqlTableModelPrivate::Update: - success = updateRowInTable(row, mrow.rec()); - break; - case QSqlTableModelPrivate::Delete: - success = deleteRowFromTable(row); - break; - case QSqlTableModelPrivate::None: - Q_ASSERT_X(false, "QSqlTableModel::submitAll()", "Invalid cache operation"); - break; - } - - if (success) { - if (d->strategy != OnManualSubmit && mrow.op() == QSqlTableModelPrivate::Insert) { - int c = mrow.rec().indexOf(d->autoColumn); - if (c != -1 && !mrow.rec().isGenerated(c)) - mrow.setValue(c, d->editQuery.lastInsertId()); - } - mrow.setSubmitted(); - if (d->strategy != OnManualSubmit) - success = selectRow(row); - } - - if (!success) - break; - } - - if (success) { - if (d->strategy == OnManualSubmit) - success = select(); - } - - return success; -} - -/*! - This reimplemented slot is called by the item delegates when the - user stopped editing the current row. - - Submits the currently edited row if the model's strategy is set - to OnRowChange or OnFieldChange. Does nothing for the OnManualSubmit - strategy. - - Use submitAll() to submit all pending changes for the - OnManualSubmit strategy. - - Returns \c true on success; otherwise returns \c false. Use lastError() - to query detailed error information. - - Does not automatically repopulate the model. Submitted rows are - refreshed from the database on success. - - \sa revert(), revertRow(), submitAll(), revertAll(), lastError() -*/ -bool QSqlTableModel::submit() -{ - Q_D(QSqlTableModel); - if (d->strategy == OnRowChange || d->strategy == OnFieldChange) - return submitAll(); - return true; -} - -/*! - This reimplemented slot is called by the item delegates when the - user canceled editing the current row. - - Reverts the changes if the model's strategy is set to - OnRowChange or OnFieldChange. Does nothing for the OnManualSubmit - strategy. - - Use revertAll() to revert all pending changes for the - OnManualSubmit strategy or revertRow() to revert a specific row. - - \sa submit(), submitAll(), revertRow(), revertAll() -*/ -void QSqlTableModel::revert() -{ - Q_D(QSqlTableModel); - if (d->strategy == OnRowChange || d->strategy == OnFieldChange) - revertAll(); -} - -/*! - \enum QSqlTableModel::EditStrategy - - This enum type describes which strategy to choose when editing values in the database. - - \value OnFieldChange All changes to the model will be applied immediately to the database. - \value OnRowChange Changes to a row will be applied when the user selects a different row. - \value OnManualSubmit All changes will be cached in the model until either submitAll() - or revertAll() is called. - - Note: To prevent inserting only partly initialized rows into the database, - \c OnFieldChange will behave like \c OnRowChange for newly inserted rows. - - \sa setEditStrategy() -*/ - - -/*! - Sets the strategy for editing values in the database to \a - strategy. - - This will revert any pending changes. - - \sa editStrategy(), revertAll() -*/ -void QSqlTableModel::setEditStrategy(EditStrategy strategy) -{ - Q_D(QSqlTableModel); - revertAll(); - d->strategy = strategy; -} - -/*! - Returns the current edit strategy. - - \sa setEditStrategy() -*/ -QSqlTableModel::EditStrategy QSqlTableModel::editStrategy() const -{ - Q_D(const QSqlTableModel); - return d->strategy; -} - -/*! - Reverts all pending changes. - - \sa revert(), revertRow(), submitAll() -*/ -void QSqlTableModel::revertAll() -{ - Q_D(QSqlTableModel); - - const QList rows(d->cache.keys()); - for (int i = rows.size() - 1; i >= 0; --i) - revertRow(rows.value(i)); -} - -/*! - Reverts all changes for the specified \a row. - - \sa revert(), revertAll(), submit(), submitAll() -*/ -void QSqlTableModel::revertRow(int row) -{ - if (row < 0) - return; - - Q_D(QSqlTableModel); - d->revertCachedRow(row); -} - -/*! - Returns the primary key for the current table, or an empty - QSqlIndex if the table is not set or has no primary key. - - \sa setTable(), setPrimaryKey(), QSqlDatabase::primaryIndex() -*/ -QSqlIndex QSqlTableModel::primaryKey() const -{ - Q_D(const QSqlTableModel); - return d->primaryIndex; -} - -/*! - Protected method that allows subclasses to set the primary key to - \a key. - - Normally, the primary index is set automatically whenever you - call setTable(). - - \sa primaryKey(), QSqlDatabase::primaryIndex() -*/ -void QSqlTableModel::setPrimaryKey(const QSqlIndex &key) -{ - Q_D(QSqlTableModel); - d->primaryIndex = key; -} - -/*! - Returns the model's database connection. -*/ -QSqlDatabase QSqlTableModel::database() const -{ - Q_D(const QSqlTableModel); - return d->db; -} - -/*! - Sorts the data by \a column with the sort order \a order. - This will immediately select data, use setSort() - to set a sort order without populating the model with data. - - \sa setSort(), select(), orderByClause() -*/ -void QSqlTableModel::sort(int column, Qt::SortOrder order) -{ - setSort(column, order); - select(); -} - -/*! - Sets the sort order for \a column to \a order. This does not - affect the current data, to refresh the data using the new - sort order, call select(). - - \sa select(), orderByClause() -*/ -void QSqlTableModel::setSort(int column, Qt::SortOrder order) -{ - Q_D(QSqlTableModel); - d->sortColumn = column; - d->sortOrder = order; -} - -/*! - Returns an SQL \c{ORDER BY} clause based on the currently set - sort order. - - \sa setSort(), selectStatement() -*/ -QString QSqlTableModel::orderByClause() const -{ - Q_D(const QSqlTableModel); - QSqlField f = d->rec.field(d->sortColumn); - if (!f.isValid()) - return QString(); - - //we can safely escape the field because it would have been obtained from the database - //and have the correct case - QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); - field.prepend(QLatin1Char('.')).prepend(d->tableName); - field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field); - return Sql::orderBy(field); -} - -/*! - Returns the index of the field \a fieldName, or -1 if no corresponding field - exists in the model. -*/ -int QSqlTableModel::fieldIndex(const QString &fieldName) const -{ - Q_D(const QSqlTableModel); - return d->rec.indexOf(fieldName); -} - -/*! - Returns the SQL \c SELECT statement used internally to populate - the model. The statement includes the filter and the \c{ORDER BY} - clause. - - \sa filter(), orderByClause() -*/ -QString QSqlTableModel::selectStatement() const -{ - Q_D(const QSqlTableModel); - if (d->tableName.isEmpty()) { - d->error = QSqlError(QLatin1String("No table name given"), QString(), - QSqlError::StatementError); - return QString(); - } - if (d->rec.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), - QSqlError::StatementError); - return QString(); - } - - const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, - d->tableName, - d->rec, - false); - if (stmt.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, - QString(), QSqlError::StatementError); - return stmt; - } - return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause()); -} - -/*! - Removes \a count columns from the \a parent model, starting at - index \a column. - - Returns if the columns were successfully removed; otherwise - returns \c false. - - \sa removeRows() -*/ -bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &parent) -{ - Q_D(QSqlTableModel); - if (parent.isValid() || column < 0 || column + count > d->rec.count()) - return false; - for (int i = 0; i < count; ++i) - d->rec.remove(column); - if (d->query.isActive()) - return select(); - return true; -} - -/*! - Removes \a count rows starting at \a row. Since this model - does not support hierarchical structures, \a parent must be - an invalid model index. - - When the edit strategy is OnManualSubmit, deletion of rows from - the database is delayed until submitAll() is called. - - For OnFieldChange and OnRowChange, only one row may be deleted - at a time and only if no other row has a cached change. Deletions - are submitted immediately to the database. The model retains a - blank row for successfully deleted row until refreshed with select(). - - After failed deletion, the operation is not reverted in the model. - The application may resubmit or revert. - - Inserted but not yet successfully submitted rows in the range to be - removed are immediately removed from the model. - - Before a row is deleted from the database, the beforeDelete() - signal is emitted. - - If row < 0 or row + count > rowCount(), no action is taken and - false is returned. Returns \c true if all rows could be removed; - otherwise returns \c false. Detailed database error information - can be retrieved using lastError(). - - \sa removeColumns(), insertRows() -*/ -bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) -{ - Q_D(QSqlTableModel); - if (parent.isValid() || row < 0 || count <= 0) - return false; - else if (row + count > rowCount()) - return false; - else if (!count) - return true; - - if (d->strategy != OnManualSubmit) - if (count > 1 || (d->cache.value(row).submitted() && isDirty())) - return false; - - // Iterate backwards so we don't have to worry about removed rows causing - // higher cache entries to shift downwards. - for (int idx = row + count - 1; idx >= row; --idx) { - QSqlTableModelPrivate::ModifiedRow& mrow = d->cache[idx]; - if (mrow.op() == QSqlTableModelPrivate::Insert) { - revertRow(idx); - } else { - if (mrow.op() == QSqlTableModelPrivate::None) - mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, - QSqlQueryModel::record(idx)); - else - mrow.setOp(QSqlTableModelPrivate::Delete); - if (d->strategy == OnManualSubmit) - emit headerDataChanged(Qt::Vertical, idx, idx); - } - } - - if (d->strategy != OnManualSubmit) - return submit(); - - return true; -} - -/*! - Inserts \a count empty rows at position \a row. Note that \a - parent must be invalid, since this model does not support - parent-child relations. - - For edit strategies OnFieldChange and OnRowChange, only one row - may be inserted at a time and the model may not contain other - cached changes. - - The primeInsert() signal will be emitted for each new row. - Connect to it if you want to initialize the new row with default - values. - - Does not submit rows, regardless of edit strategy. - - Returns \c false if the parameters are out of bounds or the row cannot be - inserted; otherwise returns \c true. - - \sa primeInsert(), insertRecord() -*/ -bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) -{ - Q_D(QSqlTableModel); - if (row < 0 || count <= 0 || row > rowCount() || parent.isValid()) - return false; - - if (d->strategy != OnManualSubmit) - if (count != 1 || isDirty()) - return false; - - d->busyInsertingRows = true; - beginInsertRows(parent, row, row + count - 1); - - if (d->strategy != OnManualSubmit) - d->cache.empty(); - - if (!d->cache.isEmpty()) { - QMap::Iterator it = d->cache.end(); - while (it != d->cache.begin() && (--it).key() >= row) { - int oldKey = it.key(); - const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); - d->cache.erase(it); - it = d->cache.insert(oldKey + count, oldValue); - } - } - - for (int i = 0; i < count; ++i) { - d->cache[row + i] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Insert, - d->rec); - emit primeInsert(row + i, d->cache[row + i].recRef()); - } - - endInsertRows(); - d->busyInsertingRows = false; - return true; -} - -/*! - Inserts the \a record at position \a row. If \a row is negative, - the record will be appended to the end. Calls insertRows() and - setRecord() internally. - - Returns \c true if the record could be inserted, otherwise false. - - Changes are submitted immediately for OnFieldChange and - OnRowChange. Failure does not leave a new row in the model. - - \sa insertRows(), removeRows(), setRecord() -*/ -bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) -{ - if (row < 0) - row = rowCount(); - if (!insertRow(row, QModelIndex())) - return false; - if (!setRecord(row, record)) { - revertRow(row); - return false; - } - return true; -} - -/*! \reimp -*/ -int QSqlTableModel::rowCount(const QModelIndex &parent) const -{ - Q_D(const QSqlTableModel); - - if (parent.isValid()) - return 0; - - return QSqlQueryModel::rowCount() + d->insertCount(); -} - -/*! - Returns the index of the value in the database result set for the - given \a item in the model. - - The return value is identical to \a item if no columns or rows - have been inserted, removed, or moved around. - - Returns an invalid model index if \a item is out of bounds or if - \a item does not point to a value in the result set. - - \sa QSqlQueryModel::indexInQuery() -*/ -QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const -{ - Q_D(const QSqlTableModel); - if (d->cache.value(item.row()).insert()) - return QModelIndex(); - - const int rowOffset = d->insertCount(item.row()); - return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer())); -} - -/*! - Returns the currently set filter. - - \sa setFilter(), select() -*/ -QString QSqlTableModel::filter() const -{ - Q_D(const QSqlTableModel); - return d->filter; -} - -/*! - Sets the current filter to \a filter. - - The filter is a SQL \c WHERE clause without the keyword \c WHERE - (for example, \c{name='Josephine')}. - - If the model is already populated with data from a database, - the model re-selects it with the new filter. Otherwise, the filter - will be applied the next time select() is called. - - \sa filter(), select(), selectStatement(), orderByClause() -*/ -void QSqlTableModel::setFilter(const QString &filter) -{ - Q_D(QSqlTableModel); - d->filter = filter; - if (d->query.isActive()) - select(); -} - -/*! \reimp -*/ -void QSqlTableModel::clear() -{ - Q_D(QSqlTableModel); - beginResetModel(); - d->clear(); - QSqlQueryModel::clear(); - endResetModel(); -} - -/*! \reimp -*/ -Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const -{ - Q_D(const QSqlTableModel); - if (index.internalPointer() || index.column() < 0 || index.column() >= d->rec.count() - || index.row() < 0) - return 0; - - bool editable = true; - - if (d->rec.field(index.column()).isReadOnly()) { - editable = false; - } - else { - const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); - if (mrow.op() == QSqlTableModelPrivate::Delete) { - editable = false; - } - else if (d->strategy == OnFieldChange) { - if (mrow.op() != QSqlTableModelPrivate::Insert) - if (!isDirty(index) && isDirty()) - editable = false; - } - else if (d->strategy == OnRowChange) { - if (mrow.submitted() && isDirty()) - editable = false; - } - } - - if (!editable) - return QSqlQueryModel::flags(index); - else - return QSqlQueryModel::flags(index) | Qt::ItemIsEditable; -} - -/*! - This is an overloaded function. - - It returns an empty record, having only the field names. This function can be used to - retrieve the field names of a record. - - \sa QSqlRecord::isEmpty() -*/ -QSqlRecord QSqlTableModel::record() const -{ - return QSqlQueryModel::record(); -} - -/*! -\since 5.0 - Returns the record at \a row in the model. - - If \a row is the index of a valid row, the record - will be populated with values from that row. - - If the model is not initialized, an empty record will be - returned. - - \sa QSqlRecord::isEmpty() -*/ -QSqlRecord QSqlTableModel::record(int row) const -{ - Q_D(const QSqlTableModel); - - // the query gets the values from virtual data() - QSqlRecord rec = QSqlQueryModel::record(row); - - // get generated flags from the cache - const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row); - if (mrow.op() != QSqlTableModelPrivate::None) { - const QSqlRecord crec = mrow.rec(); - for (int i = 0, cnt = rec.count(); i < cnt; ++i) - rec.setGenerated(i, crec.isGenerated(i)); - } - - return rec; -} - -/*! - Applies \a values to the \a row in the model. The source and - target fields are mapped by field name, not by position in - the record. - - Note that the generated flags in \a values are preserved - and determine whether the corresponding fields are used when - changes are submitted to the database. The caller should - remember to set the generated flag to FALSE for fields - where the database is meant to supply the value, such as an - automatically incremented ID. - - For edit strategies OnFieldChange and OnRowChange, a row may - receive a change only if no other row has a cached change. - Changes are submitted immediately. Submitted changes are not - reverted upon failure. - - Returns \c true if all the values could be set; otherwise returns - false. - - \sa record(), editStrategy() -*/ -bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) -{ - Q_D(QSqlTableModel); - Q_ASSERT_X(row >= 0, "QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0"); - if (d->busyInsertingRows) - return false; - - if (row >= rowCount()) - return false; - - if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete) - return false; - - if (d->strategy != OnManualSubmit && d->cache.value(row).submitted() && isDirty()) - return false; - - // Check field names and remember mapping - typedef QMap Map; - Map map; - for (int i = 0; i < values.count(); ++i) { - int idx = d->nameToIndex(values.fieldName(i)); - if (idx == -1) - return false; - map[i] = idx; - } - - QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; - if (mrow.op() == QSqlTableModelPrivate::None) - mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - QSqlQueryModel::record(row)); - - Map::const_iterator i = map.constBegin(); - const Map::const_iterator e = map.constEnd(); - for ( ; i != e; ++i) { - // have to use virtual setData() here rather than mrow.setValue() - EditStrategy strategy = d->strategy; - d->strategy = OnManualSubmit; - QModelIndex cIndex = createIndex(row, i.value()); - setData(cIndex, values.value(i.key())); - d->strategy = strategy; - // setData() sets generated to TRUE, but source record should prevail. - if (!values.isGenerated(i.key())) - mrow.recRef().setGenerated(i.value(), false); - } - - if (d->strategy != OnManualSubmit) - return submit(); - - return true; -} - -/*! - \since 5.1 - Returns a record containing the fields represented in the primary key set to the values - at \a row. If no primary key is defined, the returned record will contain all fields. - - \sa primaryKey() -*/ -QSqlRecord QSqlTableModel::primaryValues(int row) const -{ - Q_D(const QSqlTableModel); - - const QSqlRecord &pIndex = d->primaryIndex.isEmpty() ? d->rec : d->primaryIndex; - - QSqlTableModelPrivate::ModifiedRow mr = d->cache.value(row); - if (mr.op() != QSqlTableModelPrivate::None) - return mr.primaryValues(pIndex); - else - return QSqlQueryModel::record(row).keyValues(pIndex); -} - -QT_END_NAMESPACE From f6ceb0f75fbcf2df89b6bcee1d17b920ee96b3fc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:43:48 -0400 Subject: [PATCH 0983/1324] Delete qsqltablemodel.h --- src/qt/qsqltablemodel.h | 140 ---------------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 src/qt/qsqltablemodel.h diff --git a/src/qt/qsqltablemodel.h b/src/qt/qsqltablemodel.h deleted file mode 100644 index 767dfe0d..00000000 --- a/src/qt/qsqltablemodel.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSQLTABLEMODEL_H -#define QSQLTABLEMODEL_H - -#include "qsqldatabase.h" -#include "qsqlquerymodel.h" - -QT_BEGIN_NAMESPACE - - -class QSqlTableModelPrivate; -class QSqlRecord; -class QSqlField; -class QSqlIndex; - -class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QSqlTableModel) - -public: - enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit}; - - explicit QSqlTableModel(QObject *parent = Q_NULLPTR, QSqlDatabase db = QSqlDatabase()); - virtual ~QSqlTableModel(); - - virtual void setTable(const QString &tableName); - QString tableName() const; - - Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; - - QSqlRecord record() const; - QSqlRecord record(int row) const; - QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; - - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - - bool isDirty() const; - bool isDirty(const QModelIndex &index) const; - - void clear() Q_DECL_OVERRIDE; - - virtual void setEditStrategy(EditStrategy strategy); - EditStrategy editStrategy() const; - - QSqlIndex primaryKey() const; - QSqlDatabase database() const; - int fieldIndex(const QString &fieldName) const; - - void sort(int column, Qt::SortOrder order) Q_DECL_OVERRIDE; - virtual void setSort(int column, Qt::SortOrder order); - - QString filter() const; - virtual void setFilter(const QString &filter); - - int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - - bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; - - bool insertRecord(int row, const QSqlRecord &record); - bool setRecord(int row, const QSqlRecord &record); - - virtual void revertRow(int row); - -public Q_SLOTS: - virtual bool select(); - virtual bool selectRow(int row); - - bool submit() Q_DECL_OVERRIDE; - void revert() Q_DECL_OVERRIDE; - - bool submitAll(); - void revertAll(); - -Q_SIGNALS: - void primeInsert(int row, QSqlRecord &record); - - void beforeInsert(QSqlRecord &record); - void beforeUpdate(int row, QSqlRecord &record); - void beforeDelete(int row); - -protected: - QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = Q_NULLPTR, QSqlDatabase db = QSqlDatabase()); - - virtual bool updateRowInTable(int row, const QSqlRecord &values); - virtual bool insertRowIntoTable(const QSqlRecord &values); - virtual bool deleteRowFromTable(int row); - virtual QString orderByClause() const; - virtual QString selectStatement() const; - - void setPrimaryKey(const QSqlIndex &key); - void setQuery(const QSqlQuery &query); - QModelIndex indexInQuery(const QModelIndex &item) const Q_DECL_OVERRIDE; - QSqlRecord primaryValues(int row) const; -}; - -QT_END_NAMESPACE - -#endif // QSQLTABLEMODEL_H From 90689355247804f757ad33c8c93084b3f9f43ec5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:53:55 -0400 Subject: [PATCH 0984/1324] Delete loginsystem.cpp --- src/qt/loginsystem.cpp | 546 ----------------------------------------- 1 file changed, 546 deletions(-) delete mode 100644 src/qt/loginsystem.cpp diff --git a/src/qt/loginsystem.cpp b/src/qt/loginsystem.cpp deleted file mode 100644 index 549311eb..00000000 --- a/src/qt/loginsystem.cpp +++ /dev/null @@ -1,546 +0,0 @@ -#include "loginsystem.h" -#include "ui_loginsystem.h" -#include "qdb.h" -#include -#include -#include - -QDBLite::DB db; - -LoginSystem::LoginSystem(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::LoginSystem) -{ - ui->setupUi(this); - db.dbstate = db.Connect(QCoreApplication::applicationDirPath()+"/../../LogSys/db.s3db"); - ui->winStack->setCurrentIndex(0); - ui->stackedWidget->setCurrentIndex(1); - - ui->passwordBox->setEchoMode(QLineEdit::Password); - ui->passwordBox->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); - ui->pBox->setEchoMode(QLineEdit::Password); - ui->pBox->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); - ui->pBox_2->setEchoMode(QLineEdit::Password); - ui->pBox_2->setInputMethodHints(Qt::ImhHiddenText| Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase); -} - -LoginSystem::~LoginSystem() -{ - delete ui; -} - -void LoginSystem::on_loginButton_clicked() -{ - this->loggedIn = Login(ui->usernameBox->text(), ui->passwordBox->text()); - - if(this->loggedIn) - { - this->username = ui->usernameBox->text(); - this->password = ui->passwordBox->text(); - - ui->loginLabel->setText(""); - ui->winStack->setCurrentIndex(2); - } - else - { - ui->loginLabel->setText("Login failed: Invalid credentials!"); - } -} - -bool LoginSystem::Login(QString u, QString p) -{ - ui->adminButton->setVisible(false); - - bool exists = false; - - QSqlQuery checkQuery(db.db); - checkQuery.prepare("SELECT username FROM sys_users WHERE username = (:un) AND passwd = (:pw)"); - checkQuery.bindValue(":un", u); - checkQuery.bindValue(":pw", p); - - if (checkQuery.exec()) - { - if (checkQuery.next()) - { - exists = true; - } - } - - return exists; -} - - -void LoginSystem::on_regButton_clicked() -{ - ui->uBox->setText(ui->usernameBox->text()); - ui->pBox->setText(ui->passwordBox->text()); - ui->winStack->setCurrentIndex(1); -} - -void LoginSystem::on_logoutButton_clicked() -{ - if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, - "Login System", "Are you sure you want to logout?", - QMessageBox::Yes|QMessageBox::No).exec()) - { - this->loggedIn = false; - ui->passwordBox->setText(""); - ui->loginLabel->setText("You signed out!"); - ui->winStack->setCurrentIndex(0); - } -} - -void LoginSystem::on_completeRegButton_clicked() -{ - bool halt = false; - - if(ui->uBox->text() == "") - { - ui->uBox->setPlaceholderText("Username EMPTY!"); - halt = true; - } - - if(ui->pBox->text() == "") - { - ui->pBox->setPlaceholderText("Password EMPTY!"); - halt = true; - } - - if(ui->eBox->text() == "") - { - ui->eBox->setPlaceholderText("E-mail EMPTY!"); - halt = true; - } - - if(ui->fBox->text() == "") - { - ui->fBox->setPlaceholderText("First Name EMPTY!"); - halt = true; - } - - if(ui->mBox->text() == "") - { - ui->mBox->setPlaceholderText("Middle Name (optional)"); - halt = false; - } - - if(ui->lBox->text() == "") - { - ui->lBox->setPlaceholderText("Last Name EMPTY!"); - halt = true; - } - - QSqlQuery cQuery(db.db); - cQuery.prepare("SELECT username FROM sys_users WHERE username = (:un)"); - cQuery.bindValue(":un", ui->uBox->text()); - - if(cQuery.exec()) - { - if(cQuery.next()) - { - ui->uBox->setText(""); - ui->uBox->setPlaceholderText("Choose a different Username!"); - halt = true; - } - } - - QSqlQuery cQuery2(db.db); - cQuery2.prepare("SELECT email FROM sys_users WHERE email = (:em)"); - cQuery2.bindValue(":em", ui->eBox->text()); - - if(cQuery2.exec()) - { - if(cQuery2.next()) - { - ui->eBox->setText(""); - ui->eBox->setPlaceholderText("Use another E-mail!"); - halt = true; - } - } - - - if(halt) - { - ui->regLabel->setText("Please correct your mistakes."); - } - else - { - if (this->picName != "") - { - QString to = this->picDir+"/"+ui->uBox->text(); - - if (QFile::exists(to)) - { - QFile::remove(to); - } - - QFile::copy(this->picName, to); - this->picName = ""; - } - - ui->regLabel->setText(""); - QSqlQuery iQuery(db.db); - iQuery.prepare("INSERT INTO sys_users(username, passwd, fname, mname, lname, email)"\ - "VALUES(:un, :pw, :fn, :mn, :ln, :em)"); - iQuery.bindValue(":un", ui->uBox->text()); - iQuery.bindValue(":pw", ui->pBox->text()); - iQuery.bindValue(":fn", ui->fBox->text()); - iQuery.bindValue(":mn", ui->mBox->text()); - iQuery.bindValue(":ln", ui->lBox->text()); - iQuery.bindValue(":em", ui->eBox->text()); - - if(iQuery.exec()) - { - ui->uBox->setText(""); - ui->pBox->setText(""); - ui->eBox->setText(""); - ui->fBox->setText(""); - ui->mBox->setText(""); - ui->lBox->setText(""); - ui->rpLabel->setText(""); - ui->loginLabel->setText("Registration Successful! You can now login."); - ui->winStack->setCurrentIndex(0); - } - - } -} - -void LoginSystem::on_backButton_clicked() -{ - ui->loginLabel->setText(""); - ui->winStack->setCurrentIndex(0); -} - - -void LoginSystem::on_backButton_2_clicked() -{ - ui->winStack->setCurrentIndex(2); -} - -void LoginSystem::on_editButton_clicked() -{ - QSqlQuery fetcher; - fetcher.prepare("SELECT * FROM sys_users WHERE username = (:un) AND passwd = (:pw)"); - fetcher.bindValue(":un", this->username); - fetcher.bindValue(":pw", this->password); - fetcher.exec(); - - int idUsername = fetcher.record().indexOf("username"); - int idPasswd = fetcher.record().indexOf("passwd"); - int idEmail = fetcher.record().indexOf("email"); - int idFname = fetcher.record().indexOf("fname"); - int idMname = fetcher.record().indexOf("mname"); - int idLname = fetcher.record().indexOf("lname"); - - while (fetcher.next()) - { - ui->uBox_2->setText(fetcher.value(idUsername).toString()); - ui->pBox_2->setText(fetcher.value(idPasswd).toString()); - ui->eBox_2->setText(fetcher.value(idEmail).toString()); - ui->fBox_2->setText(fetcher.value(idFname).toString()); - ui->mBox_2->setText(fetcher.value(idMname).toString()); - ui->lBox_2->setText(fetcher.value(idLname).toString()); - } - - ui->winStack->setCurrentIndex(3); -} - -void LoginSystem::on_delButton_clicked() -{ - if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, - "Login System", "Are you sure you want to delete your account?", - QMessageBox::Yes|QMessageBox::No).exec()) - { - QString to = this->picDir+"/"+this->username; - - if (QFile::exists(to)) - { - QFile::remove(to); - } - - QSqlQuery dQuery(db.db); - dQuery.prepare("DELETE FROM sys_users WHERE username = (:un)"); - dQuery.bindValue(":un", this->username); - - if(dQuery.exec()) - { - ui->usernameBox->setText(""); - ui->passwordBox->setText(""); - ui->loginLabel->setText("Account deleted!"); - ui->winStack->setCurrentIndex(0); - } - } -} - -void LoginSystem::on_editedButton_clicked() -{ - - - bool halt = false; - - if(ui->uBox_2->text() == "") - { - ui->uBox_2->setPlaceholderText("Username EMPTY!"); - halt = true; - } - - if(ui->pBox_2->text() == "") - { - ui->pBox_2->setPlaceholderText("Password EMPTY!"); - halt = true; - } - - if(ui->eBox_2->text() == "") - { - ui->eBox_2->setPlaceholderText("E-mail EMPTY!"); - halt = true; - } - - if(ui->fBox_2->text() == "") - { - ui->fBox_2->setPlaceholderText("First Name EMPTY!"); - halt = true; - } - - if(ui->mBox_2->text() == "") - { - ui->mBox_2->setPlaceholderText("Middle Name (optional)"); - halt = false; - } - - if(ui->lBox_2->text() == "") - { - ui->lBox_2->setPlaceholderText("Last Name EMPTY!"); - halt = true; - } - - QSqlQuery cQuery(db.db); - cQuery.prepare("SELECT username FROM sys_users WHERE username = (:un)"); - cQuery.bindValue(":un", ui->uBox->text()); - - if(cQuery.exec()) - { - if(cQuery.next() && ui->uBox_2->text() != cQuery.value(0).toString()) - { - ui->uBox_2->setText(""); - ui->uBox_2->setPlaceholderText("Choose a different Username!"); - halt = true; - } - } - - QSqlQuery cQuery2(db.db); - cQuery2.prepare("SELECT email FROM sys_users WHERE email = (:em)"); - cQuery2.bindValue(":em", ui->eBox_2->text()); - - if(cQuery2.exec()) - { - if(cQuery2.next() && ui->eBox_2->text() != cQuery2.value(0).toString()) - { - ui->eBox_2->setText(""); - ui->eBox_2->setPlaceholderText("Use another E-mail!"); - halt = true; - } - } - - - if(halt) - { - ui->regLabel_2->setText("Please correct your mistakes."); - } - else - { - if (this->picName != "") - { - QString to = this->picDir+"/"+ui->uBox_2->text(); - - if (QFile::exists(to)) - { - QFile::remove(to); - } - - QFile::copy(this->picName, to); - this->picName = ""; - } - - ui->regLabel_2->setText(""); - QSqlQuery iQuery(db.db); - iQuery.prepare("UPDATE sys_users SET username=(:un), passwd=(:pw), fname=(:fn), mname=(:mn), lname=(:ln), email=(:em) WHERE username=(:uno)"); - iQuery.bindValue(":un", ui->uBox_2->text()); - iQuery.bindValue(":pw", ui->pBox_2->text()); - iQuery.bindValue(":fn", ui->fBox_2->text()); - iQuery.bindValue(":mn", ui->mBox_2->text()); - iQuery.bindValue(":ln", ui->lBox_2->text()); - iQuery.bindValue(":em", ui->eBox_2->text()); - iQuery.bindValue(":uno", ui->uBox_2->text()); - - if(iQuery.exec()) - { - ui->winStack->setCurrentIndex(2); - } - - } -} - -void LoginSystem::on_winStack_currentChanged(int arg1) -{ - - if(arg1 == 3 && this->loggedIn) - { - if(QFile::exists(this->picDir+"/"+this->username)) - { - ui->rpLabel_2->setText("picDir+"/"+this->username+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); - } - } - - if(arg1 == 2 && this->loggedIn) - { - if(QFile::exists(this->picDir+"/"+this->username)) - { - ui->loggedPic->setText("picDir+"/"+this->username+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); - } - - QSqlQuery fetcher; - fetcher.prepare("SELECT * FROM sys_users WHERE username = (:un)"); - fetcher.bindValue(":un", this->username); - fetcher.exec(); - - int idFname = fetcher.record().indexOf("fname"); - int idMname = fetcher.record().indexOf("mname"); - int idLname = fetcher.record().indexOf("lname"); - int idRank = fetcher.record().indexOf("rank"); - int idEmail = fetcher.record().indexOf("email"); - - QString fullname, email, rank; - - while (fetcher.next()) - { - fullname = fetcher.value(idFname).toString(); - fullname += " " + fetcher.value(idMname).toString(); - fullname += " " + fetcher.value(idLname).toString(); - rank = fetcher.value(idRank).toString(); - email = fetcher.value(idEmail).toString(); - } - if(rank == "-1") - { - ui->adminButton->setVisible(true); - } - ui->nameLabel->setText(fullname); - ui->rankLabel->setText(rank); - ui->emailLabel->setText(email); - } - - if(arg1 == 4 && this->loggedIn) - { - ui->stackedWidget->setCurrentIndex(0); - } -} - -void LoginSystem::on_uplButton_clicked() -{ - this->picName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)")); - ui->rpLabel->setText("picName+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); - -} - -void LoginSystem::on_uplButton_2_clicked() -{ - this->picName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)")); - ui->rpLabel_2->setText("picName+"\" alt=\"Image read error!\" height=\"128\" width=\"128\" />"); -} - -void LoginSystem::on_adminButton_clicked() -{ - ui->winStack->setCurrentIndex(4); -} - -void LoginSystem::on_pageButton_clicked() -{ - ui->winStack->setCurrentIndex(2); -} - -void LoginSystem::on_editedButton_2_clicked() -{ - if(this->tblMdl->submitAll()) - { - this->tblMdl->database().commit(); - ui->adminLabel->setText("Saved to database!"); - } - else - { - this->tblMdl->database().rollback(); - } -} - -void LoginSystem::on_backButton_5_clicked() -{ - this->tblMdl->revertAll(); - this->tblMdl->database().rollback(); -} - -void LoginSystem::on_userBrowse_clicked() -{ - ui->stackedWidget->setCurrentIndex(0); -} - -void LoginSystem::on_delUButton_clicked() -{ - if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, - "Login System", "Are you sure you want to erase all accounts?", - QMessageBox::Yes|QMessageBox::No).exec()) - { - QSqlQuery dQuery(db.db); - dQuery.prepare("DELETE FROM sys_users WHERE rank != 0 AND rank != -1"); - - if(dQuery.exec()) - { - ui->adminLabel->setText("Query executed!"); - } - } -} - -void LoginSystem::on_stackedWidget_currentChanged(int arg1) -{ - if(arg1 == 0 && this->loggedIn) - { - ui->headLabel->setText("USERS"); - this->tblMdl = new QSqlTableModel; - this->tblMdl->setTable("sys_users"); - this->tblMdl->setFilter("rank != -1 AND rank != 0"); - this->tblMdl->select(); - ui->tableView->setModel(this->tblMdl); - this->tblMdl->database().transaction(); - } - - if(arg1 == 1 && this->loggedIn) - { - ui->headLabel->setText("ADMINS"); - this->tblMdl = new QSqlTableModel; - this->tblMdl->setTable("sys_users"); - this->tblMdl->setFilter("rank == -1 OR rank == 0"); - this->tblMdl->select(); - ui->tableView_2->setModel(this->tblMdl); - this->tblMdl->database().transaction(); - } -} - -void LoginSystem::on_adminBrowse_clicked() -{ - ui->stackedWidget->setCurrentIndex(1); -} - -void LoginSystem::on_delAButton_clicked() -{ - if(QMessageBox::Yes == QMessageBox(QMessageBox::Question, - "Login System", "Are you sure you want to erase all administrators?"\ - "\n(This won't erase regular users and you)", - QMessageBox::Yes|QMessageBox::No).exec()) - { - QSqlQuery dQuery(db.db); - dQuery.prepare("DELETE FROM sys_users WHERE rank != 1 AND username != \"" + this->username + "\""); - - if(dQuery.exec()) - { - ui->adminLabel->setText("Query executed!"); - } - } -} From 3b1e97e711097bb0eb0b922d4227e573c4a252bb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:54:04 -0400 Subject: [PATCH 0985/1324] Delete loginsystem.h --- src/qt/loginsystem.h | 74 -------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/qt/loginsystem.h diff --git a/src/qt/loginsystem.h b/src/qt/loginsystem.h deleted file mode 100644 index 33407338..00000000 --- a/src/qt/loginsystem.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef LOGINSYSTEM_H -#define LOGINSYSTEM_H - -#include -#include -#include "qsqltablemodel.h" - -namespace Ui { -class LoginSystem; -} - -class LoginSystem : public QMainWindow -{ - Q_OBJECT - -public: - explicit LoginSystem(QWidget *parent = 0); - ~LoginSystem(); - bool Login(QString u, QString p); - bool loggedIn; - QString picName; - QString picDir = QCoreApplication::applicationDirPath()+"/../../LogSys/users/avatar"; - QSqlTableModel* tblMdl; - -private Q_SLOTS: - void on_loginButton_clicked(); - - void on_logoutButton_clicked(); - - void on_completeRegButton_clicked(); - - void on_backButton_clicked(); - - void on_regButton_clicked(); - - void on_backButton_2_clicked(); - - void on_editButton_clicked(); - - void on_delButton_clicked(); - - void on_editedButton_clicked(); - - void on_winStack_currentChanged(int arg1); - - void on_uplButton_clicked(); - - void on_uplButton_2_clicked(); - - void on_adminButton_clicked(); - - void on_pageButton_clicked(); - - void on_editedButton_2_clicked(); - - void on_backButton_5_clicked(); - - void on_userBrowse_clicked(); - - void on_delUButton_clicked(); - - void on_stackedWidget_currentChanged(int arg1); - - void on_adminBrowse_clicked(); - - void on_delAButton_clicked(); - -private: - Ui::LoginSystem *ui; - QString username; - QString password; -}; - -#endif // LOGINSYSTEM_H From c1d0f380a53880fd11fe3208494157fb6d5c6471 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:54:13 -0400 Subject: [PATCH 0986/1324] Delete loginsystem.ui --- src/qt/forms/loginsystem.ui | 4125 ----------------------------------- 1 file changed, 4125 deletions(-) delete mode 100644 src/qt/forms/loginsystem.ui diff --git a/src/qt/forms/loginsystem.ui b/src/qt/forms/loginsystem.ui deleted file mode 100644 index 8643edbb..00000000 --- a/src/qt/forms/loginsystem.ui +++ /dev/null @@ -1,4125 +0,0 @@ - - - LoginSystem - - - - 0 - 0 - 750 - 450 - - - - - 750 - 450 - - - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - - - 120 - 120 - 120 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - Login System 1.0 - - - - :/icon.ico:/icon.ico - - - - - - 0 - 0 - 750 - 450 - - - - - 750 - 450 - - - - - 750 - 450 - - - - - 750 - 450 - - - - false - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 0 - 0 - 751 - 451 - - - - 2 - - - - - - 0 - 0 - 751 - 451 - - - - background: #101010; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 290 - 22 - 175 - 41 - - - - - Droid Sans - -1 - - - - text-align: center; -color: #393; -margin: 0 auto; -font-size: 35px; -font-family: 'Droid Sans'; - - - Login - - - - - - 50 - 248 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - - - - false - - - 0 - - - Username - - - - - - 50 - 300 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Password - - - - - - 60 - 354 - 80 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #393; -Color: #fefefe; - - - SIGN IN - - - - - - 160 - 354 - 80 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #933; -Color: #fefefe; - - - SIGN UP - - - - - - 60 - 222 - 267 - 16 - - - - color: #fefefe; - - - - - - - - - 88 - 80 - 128 - 128 - - - - border-radius: 64px; -background-image: url(:/user.png); - - - - - - - - - - - - 0 - 0 - 751 - 451 - - - - background: #101010; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 258 - 24 - 223 - 41 - - - - - Droid Sans - -1 - - - - text-align: center; -color: #393; -margin: 0 auto; -font-size: 35px; -font-family: 'Droid Sans'; - - - Register - - - - - - 70 - 160 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - - - - false - - - 0 - - - Username - - - - - - 70 - 220 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Password - - - - - - 540 - 400 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #393; -Color: #fefefe; - - - COMPLETE REGISTRATION - - - - - - 70 - 280 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - E-mail - - - - - - 490 - 160 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - First Name - - - - - - 490 - 220 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Middle Name - - - - - - 490 - 280 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Last Name - - - - - - 40 - 400 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #933; -Color: #fefefe; - - - BACK TO LOGIN PAGE - - - - - - 60 - 110 - 601 - 16 - - - - color: #fefefe; - - - Please fill the form correctly. - - - - - - 316 - 148 - 128 - 128 - - - - color: #fefefe; - - - <img src=":user.png" /> - - - - - - 298 - 294 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #339; -Color: #fefefe; - - - UPLOAD PICTURE - - - - - - - - - 0 - 0 - 751 - 451 - - - - background: #101010; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 248 - 16 - 245 - 41 - - - - - Droid Sans - -1 - - - - text-align: center; -color: #393; -margin: 0 auto; -font-size: 35px; -font-family: 'Droid Sans'; - - - Logged In - - - - - - 570 - 150 - 151 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #933; -Color: #fefefe; - - - SIGN OUT - - - - - - 54 - 248 - 47 - 13 - - - - color: #c33; -font-weight: bold; - - - Name: - - - - - - 54 - 278 - 47 - 13 - - - - color: #c33; -font-weight: bold; - - - Rank: - - - - - - 124 - 248 - 241 - 16 - - - - color: #fefefe; - - - - - - - - - 124 - 278 - 201 - 16 - - - - color: #fefefe; - - - - - - - - - 570 - 180 - 151 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #393; -Color: #fefefe; - - - EDIT MY PROFILE - - - - - - 570 - 212 - 151 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #aaa; -Color: #101010; - - - DELETE MY ACCOUNT - - - - - - 48 - 306 - 47 - 13 - - - - color: #c33; -font-weight: bold; - - - E-mail: - - - - - - 124 - 306 - 201 - 16 - - - - color: #fefefe; - - - - - - - - - 120 - 92 - 128 - 128 - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 0 - 0 - 128 - 128 - - - - - - - <img src=":user.png" /> - - - - - - - 570 - 118 - 151 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #339; -Color: #fefefe; - - - ADMIN PANEL - - - frame_6 - loggedUserHeader - logoutButton - label_3 - label_4 - nameLabel - rankLabel - editButton - delButton - label_6 - emailLabel - adminButton - - - - - - - 0 - 0 - 751 - 451 - - - - background: #101010; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 238 - 20 - 273 - 41 - - - - - Droid Sans - -1 - - - - text-align: center; -color: #393; -margin: 0 auto; -font-size: 35px; -font-family: 'Droid Sans'; - - - Edit Profile - - - - - - 70 - 160 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - - - - false - - - 0 - - - Username - - - - - - 70 - 220 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Password - - - - - - 540 - 400 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #393; -Color: #fefefe; - - - SUBMIT CHANGES - - - - - - 70 - 280 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - E-mail - - - - - - 490 - 160 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - First Name - - - - - - 490 - 220 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Middle Name - - - - - - 490 - 280 - 201 - 41 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 254 - 254 - 254 - - - - - - - 254 - 254 - 254 - - - - - - - 51 - 51 - 51 - - - - - - - 51 - 51 - 51 - - - - - - - - - true - - - - Qt::LeftToRight - - - padding-left: 20px; -padding-right: 20px; -border-radius: 20px; -background: #333; -color: #fefefe; - - - Qt::ImhNone - - - - - - - - - false - - - 0 - - - Last Name - - - - - - 40 - 400 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #933; -Color: #fefefe; - - - BACK TO MY PAGE - - - - - - 60 - 110 - 601 - 16 - - - - color: #fefefe; - - - Edit your details below. (avatar may not change until app relaunch) - - - - - - 294 - 292 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #339; -Color: #fefefe; - - - CHANGE PICTURE - - - - - - 312 - 146 - 128 - 128 - - - - color: #fefefe; - - - <img src=":user.png" /> - - - label_5 - uBox_2 - pBox_2 - eBox_2 - fBox_2 - mBox_2 - lBox_2 - backButton_2 - regLabel_2 - editedButton - uplButton_2 - rpLabel_2 - - - - - - - 0 - 0 - 751 - 451 - - - - background: #101010; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 234 - 20 - 291 - 41 - - - - - Droid Sans - -1 - - - - text-align: center; -color: #393; -margin: 0 auto; -font-size: 35px; -font-family: 'Droid Sans'; - - - Admin Panel - - - - - - 558 - 410 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #393; -Color: #fefefe; - - - SAVE CHANGES - - - - - - 22 - 410 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #a11; -Color: #fefefe; - - - DELETE ALL USERS - - - - - - 182 - 122 - 535 - 251 - - - - 0 - - - - - - 0 - 0 - 535 - 303 - - - - background: #fefefe; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 0 - 0 - 535 - 305 - - - - - - - - - - 0 - 0 - 535 - 303 - - - - background: #fefefe; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 0 - -2 - 535 - 305 - - - - - - - - - - 18 - 166 - 155 - 27 - - - - Padding: 1px; -Border-radius: 0; -Background: #393; -Color: #fefefe; - - - ALL USERS - - - - - - 380 - 410 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #339; -Color: #fefefe; - - - ROLLBACK ALL CHANGES - - - - - - 18 - 246 - 155 - 27 - - - - Padding: 1px; -Border-radius: 0; -Background: #393; -Color: #fefefe; - - - GOTO MY PAGE - - - - - - 18 - 206 - 155 - 27 - - - - Padding: 1px; -Border-radius: 0; -Background: #393; -Color: #fefefe; - - - ALL ADMINS - - - - - - 202 - 410 - 171 - 21 - - - - Padding: 1px; -Border-radius: 5px; -Background: #a11; -Color: #fefefe; - - - DELETE ALL ADMINS - - - - - - 50 - 386 - 649 - 16 - - - - color: #fefefe; - - - There are no auto backups! Be sure of any alterations you make. - - - - - - 190 - 100 - 479 - 16 - - - - color: #fefefe; - - - - - - - - - - - - - - - - - From f05b9d104a71d6fce1e6f6636974d6d25245b84c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:54:37 -0400 Subject: [PATCH 0987/1324] Add files via upload --- src/qt/forms/mainwindow.ui | 547 +++++++++++++++++++++++++++++++++++++ 1 file changed, 547 insertions(+) create mode 100644 src/qt/forms/mainwindow.ui diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui new file mode 100644 index 00000000..f9070099 --- /dev/null +++ b/src/qt/forms/mainwindow.ui @@ -0,0 +1,547 @@ + + + MainWindow + + + + 0 + 0 + 464 + 319 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 233 + 228 + 219 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 255 + + + + + + + 233 + 228 + 219 + + + + + + + 106 + 100 + 92 + + + + + + + 141 + 134 + 123 + + + + + + + 106 + 100 + 92 + + + + + + + 255 + 255 + 255 + + + + + + + 106 + 100 + 92 + + + + + + + 212 + 201 + 184 + + + + + + + 212 + 201 + 184 + + + + + + + 0 + 0 + 0 + + + + + + + 212 + 201 + 184 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + MainWindow + + + + + + + + + + + No account? Create one! + + + + + + + PointingHandCursor + + + Sign Up + + + + + + + + + + + + + + + + 10 + 75 + true + + + + Email + + + + + + + + 10 + 75 + true + + + + Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + PointingHandCursor + + + Log In + + + + + + + + + + + + + 0 + 0 + 464 + 26 + + + + + + TopToolBarArea + + + false + + + + + + + + From e88f89d55fa229d8bde32fd08019cdaabe4bff1a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:55:03 -0400 Subject: [PATCH 0988/1324] Update main.cpp --- src/qt/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 3620dde1..c72209ce 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,10 +1,11 @@ -#include "loginsystem.h" +#include "mainwindow.h" #include +#include "homepage.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - LoginSystem w; + MainWindow w; w.show(); return a.exec(); From 607efa10c897711a75fb69a0d8225a872a3e50d8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:55:37 -0400 Subject: [PATCH 0989/1324] Add files via upload --- src/qt/mainwindow.cpp | 53 ++++++++++++++++++++++++++++++++++------- src/qt/newaccount.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ src/qt/newaccount.h | 36 ++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/qt/newaccount.cpp create mode 100644 src/qt/newaccount.h diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 8861b7bc..3699f475 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,9 +1,44 @@ -#include "mainwindow.h" - -MainWindow::MainWindow() - : QMainWindow() -{ - setMinimumSize(800, 600); -} - -MainWindow::~MainWindow() {} +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "newAccount.h" +#include +#include "homepage.h" +#include "QMessageBox" +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include + + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + QPixmap pix(":/resources/img/login-icon.png"); + int w = ui->label_pic->width(); + int h = ui->label_pic->height(); + ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); + +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_Login_clicked() +{ + QString username = ui->lineEdit_username->text(); + QString password = ui->lineEdit_password->text(); + + if(username == "test" && password == "test") { + QMessageBox::information(this, "Login", "Username and password is correct"); + //hide(); + secDialog = new SecDialog(this); + secDialog->show(); + } + else { + QMessageBox::warning(this,"Login", "Username and password is not correct"); + } +} \ No newline at end of file diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp new file mode 100644 index 00000000..89c986e8 --- /dev/null +++ b/src/qt/newaccount.cpp @@ -0,0 +1,55 @@ +#include "newaccount.h" +#include "ui_newaccount.h" +#include "QMessageBox" +#include +newAccount::newAccount(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::newAccount) +{ + ui->setupUi(this); + user check; + id=check.getUsersSize(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->setWindowTitle("Social Network"); + +} + +newAccount::~newAccount() +{ + delete ui; +} + +void newAccount::on_pushButton_clicked() +{ + QString password =ui->lineEdit_2->text(); + QString confirm =ui->lineEdit_3->text(); + QString mail=ui->txtUserMail->text(); + if(password!=confirm) + { + QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); + } + else + { + user temp (password,mail,ui->txtUserName->text(),id); + temp.setUsersList(temp); + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + this->hide(); +// temp.userFileManipulator.updateActivity(mail,0,0); + } + +} + +void newAccount::setLoginPtr(MainWindow *ptr) +{ + this->mainWindowPtr = ptr; +} + +void newAccount::on_pushButton_2_clicked() +{ + MainWindow* newWindow= new MainWindow(id); + newWindow->show(); + // mainWindowPtr->show(); + this->hide(); + +} diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h new file mode 100644 index 00000000..9114dcdd --- /dev/null +++ b/src/qt/newaccount.h @@ -0,0 +1,36 @@ +#ifndef NEWACCOUNT_H +#define NEWACCOUNT_H + +#include +#include "mainwindow.h" +namespace Ui { +class newAccount; +} + +class newAccount : public QMainWindow +{ + Q_OBJECT + +public: + explicit newAccount(QWidget *parent = 0); + ~newAccount(); + int id; + + +public slots: + void setLoginPtr(MainWindow *ptr); + + +private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + +private: + Ui::newAccount *ui; + + MainWindow *mainWindowPtr; +}; + +#endif // NEWACCOUNT_H From 050b4dbc33ba6cbe62f74c9ae727d0d4b4407416 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:55:53 -0400 Subject: [PATCH 0990/1324] Add files via upload --- src/qt/forms/newaccount.ui | 195 +++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/qt/forms/newaccount.ui diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui new file mode 100644 index 00000000..c00afa77 --- /dev/null +++ b/src/qt/forms/newaccount.ui @@ -0,0 +1,195 @@ + + + newAccount + + + + 0 + 0 + 532 + 312 + + + + MainWindow + + + + + + + + + + + + Times New Roman + 16 + 75 + true + + + + if you already have an account ---> + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign In + + + + + + + + + + + + + + + + Times New Roman + 14 + 75 + true + + + + userName + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + Email + + + txtUserMail + + + + + + + + Times New Roman + 14 + 75 + true + + + + password + + + lineEdit_2 + + + + + + + + Times New Roman + 14 + 75 + true + + + + confirm password + + + lineEdit_3 + + + + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + QLineEdit::Password + + + + + + + + + + + + Times New Roman + 11 + 75 + true + + + + Sign Up + + + + + + + + + + + + + 0 + 0 + 532 + 26 + + + + + + + + From 75b0690c9dfa0d59ec7607373bc230833a2cd93b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:56:39 -0400 Subject: [PATCH 0991/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 3699f475..5eb65c31 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,7 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" -#include +#include "newaccount.h" +#include #include "homepage.h" #include "QMessageBox" #include "mainwindow.h" @@ -15,7 +15,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); - QPixmap pix(":/resources/img/login-icon.png"); + QPixmap pix(":/icons/chat.png"); int w = ui->label_pic->width(); int h = ui->label_pic->height(); ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); @@ -41,4 +41,4 @@ void MainWindow::on_pushButton_Login_clicked() else { QMessageBox::warning(this,"Login", "Username and password is not correct"); } -} \ No newline at end of file +} From 56b5c1e78f2b264762e3e1eb47a5e33d5dff2eaf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:57:12 -0400 Subject: [PATCH 0992/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 89c986e8..9ca3731f 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -9,7 +9,7 @@ newAccount::newAccount(QWidget *parent) : ui->setupUi(this); user check; id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + QWidget::setWindowIcon(QIcon(":/icons/chat.png")); this->setWindowTitle("Social Network"); } From efdf59ea9b16ee3fd4d8fb1c36702dfb62988c0f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:58:14 -0400 Subject: [PATCH 0993/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index c00afa77..dd87603b 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -30,7 +30,7 @@
- if you already have an account ---> + If You Already Have An Account ---> @@ -68,7 +68,7 @@
- userName + User Name txtUserMail @@ -104,7 +104,7 @@ - password + Password lineEdit_2 @@ -122,7 +122,7 @@ - confirm password + Confirm Password lineEdit_3 From e719ca4898cab073f16beea4d659b4309a4b8751 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:59:45 -0400 Subject: [PATCH 0994/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index dd6d5d21..a22f9aa5 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -58,7 +58,9 @@ QT_FORMS_UI = \ qt/forms/dialog.ui \ qt/forms/form.ui \ qt/forms/homepage.ui \ - qt/forms/profilepage.ui + qt/forms/profilepage.ui \ + qt/forms/mainwindow.ui \ + qt/forms/newaccount.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -124,9 +126,7 @@ QT_MOC_CPP = \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ qt/moc_mainwindow.cpp \ - qt/moc_qsqltablemodel.cpp \ - qt/moc_qsqldatabase.cpp \ - qt/moc_qsqlquerymodel.cpp + qt/moc_newaccount.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -223,17 +223,7 @@ BITCOIN_QT_H = \ qt/statistics.h \ qt/user.h \ qt/mainwindow.h \ - qt/qsqltablemodel.h \ - qt/qsqldatabase.h \ - qt/qsql.h \ - qt/qsqlquerymodel.h \ - qt/qsqldriver.h \ - qt/qsqlerror.h \ - qt/qsqlfield.h \ - qt/qsqlindex.h \ - qt/qsqlquery.h \ - qt/qsqlrecord.h \ - qt/qsql/result.h + qt/newaccount.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -586,9 +576,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/user.cpp \ qt/main.cpp \ qt/mainwindow.cpp \ - qt/qsqltablemodel.cpp \ - qt/qsqldatabase.cpp \ - qt/qsqlquerymodel.cpp + qt/newaccount.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 9a084904e569a88d4af658158c306ab881503024 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:01:48 -0400 Subject: [PATCH 0995/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index bd5157cb..b8a33e51 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,7 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "loginsystem.h" +#include "mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -143,7 +143,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), - loginSystem(0), + mainWindow(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -606,8 +606,8 @@ void BitcoinGUI::createActions() externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); // HTH Chat - loginSystem = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - loginSystem->setStatusTip(tr("HTH World")); + mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); + mainWindow->setStatusTip(tr("HTH World")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); @@ -621,7 +621,7 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // HTHW Chat - connect(loginSystem, SIGNAL(triggered()), this, SLOT(gotoLoginSystem())); + connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -723,8 +723,8 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - QMenu* login = appMenuBar->addMenu(tr("&HTH World")); - login->addAction(loginSystem); + QMenu* media = appMenuBar->addMenu(tr("&HTH World")); + media->addAction(mainWindow); } @@ -1052,10 +1052,10 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoLoginSystem() +void BitcoinGUI::gotoMainWindow() { - loginSystem->setChecked(true); - if (walletFrame) walletFrame->gotoLoginSystem(); + mainWindow->setChecked(true); + if (walletFrame) walletFrame->gotoMainWindow(); } void BitcoinGUI::gotoGovernancePage() From 7c6e8e281d4d5f3f0348d5566b71343c4f76562a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:02:21 -0400 Subject: [PATCH 0996/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 63b77bad..85b153e4 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,7 @@ #include "amount.h" #include "governancelist.h" -#include "loginsystem.h" +#include "mainWindow.h" #include #include @@ -39,7 +39,7 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -class LoginSystem; +class MainWindow; class CWallet; @@ -105,7 +105,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* loginSystem; + QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -235,7 +235,7 @@ private Q_SLOTS: /** Switch to social media page */ - void gotoLoginSystem(); + void gotoMainWindow(); /** Switch to masternode page */ void gotoGovernancePage(); From 7a78a53d6e8b671c3ed8d66fb8a771b8e0f32ce8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:02:50 -0400 Subject: [PATCH 0997/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index af363d3e..abf30d21 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,12 +108,12 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoLoginSystem() +void WalletFrame::gotoMainWindow() { QMap::const_iterator i; for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoLoginSystem(); + i.value()->gotoMainWindow(); } void WalletFrame::gotoGovernancePage() From 8275cd89126975666fb6509c2f043bf335eb7816 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:03:04 -0400 Subject: [PATCH 0998/1324] Update walletframe.h --- src/qt/walletframe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 07360682..cd335d21 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -67,7 +67,7 @@ public Q_SLOTS: /** Switch to social media page */ void gotoGovernancePage(); /** Switch to social media page */ - void gotoLoginSystem(); + void gotoMainWindow(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From afafaf03f58e844a5d3acd3c0dc291e7228783a3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:03:46 -0400 Subject: [PATCH 0999/1324] Update walletview.cpp --- src/qt/walletview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index daaf4ad6..27f5558d 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -85,8 +85,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(sendCoinsPage); addWidget(privateSendPage); - loginSystem = new LoginSystem(); - addWidget(loginSystem); + mainWindow = new MainWindow(); + addWidget(mainWindow); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { @@ -234,9 +234,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoLoginSystem() +void WalletView::gotoMainWindow() { - setCurrentWidget(loginSystem); + setCurrentWidget(mainWindow); } void WalletView::gotoGovernancePage() From bfae81249d55a5cd1a6396d54e7be78b31040825 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:04:21 -0400 Subject: [PATCH 1000/1324] Update walletview.h --- src/qt/walletview.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index fba2b72f..3be6fd21 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,7 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "loginsystem.h" +#include "mainwindow.h" #include @@ -25,7 +25,7 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class LoginSystem; +class MainWindow; QT_BEGIN_NAMESPACE class QLabel; @@ -74,7 +74,7 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - LoginSystem *loginSystem; + MainWindow *mainWindow; TransactionView *transactionView; @@ -86,7 +86,7 @@ public Q_SLOTS: /** Switch to social media page */ - void gotoLoginSystem(); + void gotoMainWindow(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 75e86fb9aabda0afec88b3e9fbceb2d23e90baeb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:04:54 -0400 Subject: [PATCH 1001/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 85b153e4..050853f2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,7 @@ #include "amount.h" #include "governancelist.h" -#include "mainWindow.h" +#include "mainwindow.h" #include #include From 548822ed898cf3f88e127414f6bd40c5ddc6c49d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:05:33 -0400 Subject: [PATCH 1002/1324] Update newaccount.h --- src/qt/newaccount.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index 9114dcdd..b69d4800 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -17,11 +17,11 @@ class newAccount : public QMainWindow int id; -public slots: +public Q_SLOTS: void setLoginPtr(MainWindow *ptr); -private slots: +private Q_SLOTS: void on_pushButton_clicked(); void on_pushButton_2_clicked(); From 8e29bf0a25ba8cf8f3b7a9126d330bf32803ad6d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:10:14 -0400 Subject: [PATCH 1003/1324] Update mainwindow.h --- src/qt/mainwindow.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 1e7fec07..57058721 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,15 +1,27 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - + #include - + +namespace Ui { +class MainWindow; +} + class MainWindow : public QMainWindow { Q_OBJECT - + public: - MainWindow(); + explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + +private Q_SLOTS: + void on_signUpButton_clicked(); + + void on_logInButton_clicked(); + +private: + Ui::MainWindow *ui; }; - + #endif // MAINWINDOW_H From 94ab1c9ecadf53e58043ca4437aebcdaef5342bc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:14:04 -0400 Subject: [PATCH 1004/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 70 ++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 5eb65c31..1e5bb370 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -4,41 +4,63 @@ #include #include "homepage.h" #include "QMessageBox" -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include -#include - MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), +QMainWindow(parent), +ui(new Ui::MainWindow) +{ +ui->setupUi(this); +ui->signUpLabel->setText("No account? Create one!"); +QWidget::setWindowIcon(QIcon(":/icons/chat.png")); +this->setWindowTitle("Social Network"); + +} + +MainWindow::MainWindow(int userID) : ui(new Ui::MainWindow) { ui->setupUi(this); - QPixmap pix(":/icons/chat.png"); - int w = ui->label_pic->width(); - int h = ui->label_pic->height(); - ui->label_pic->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio)); - + ui->signUpLabel->setText("No account? Create one!"); + id=userID; + qDebug()<< "id is "<show(); + this->hide(); + + +} + +void MainWindow::on_logInButton_clicked() { - QString username = ui->lineEdit_username->text(); - QString password = ui->lineEdit_password->text(); - - if(username == "test" && password == "test") { - QMessageBox::information(this, "Login", "Username and password is correct"); - //hide(); - secDialog = new SecDialog(this); - secDialog->show(); + QString email=ui->txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; } - else { - QMessageBox::warning(this,"Login", "Username and password is not correct"); + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; } + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); + } From 0f3f2dcdfedeccf32216aedd75fe8911add64efb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:14:31 -0400 Subject: [PATCH 1005/1324] Update mainwindow.h --- src/qt/mainwindow.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 57058721..1899ff01 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -12,7 +12,9 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; ~MainWindow(); private Q_SLOTS: From 35e47b6407799bcd78304c5bbafaa105ef81ae7b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:32:22 -0400 Subject: [PATCH 1006/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 108 +++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 1e5bb370..4b9a1345 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,66 +1,74 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newaccount.h" #include #include "homepage.h" #include "QMessageBox" -MainWindow::MainWindow(QWidget *parent) : -QMainWindow(parent), -ui(new Ui::MainWindow) +MainWindow::MainWindow(QWidget* parent) + : QDialog(parent) { -ui->setupUi(this); -ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/chat.png")); -this->setWindowTitle("Social Network"); - + setFixedSize(300, 120); + setWindowTitle("Form Login"); + setModal(true); + setAttribute(Qt::WA_DeleteOnClose); + + userLabel = new QLabel("Username:"); + passLabel = new QLabel("Password:"); + userLineEdit = new QLineEdit(); + passLineEdit = new QLineEdit(); + passLineEdit->setEchoMode(QLineEdit::Password); + loginButton = new QPushButton("Login"); + quitButton = new QPushButton("Quit"); + + QVBoxLayout* vbox = new QVBoxLayout(this); + QHBoxLayout* hbox1 = new QHBoxLayout(); + QHBoxLayout* hbox2 = new QHBoxLayout(); + QHBoxLayout* hbox3 = new QHBoxLayout(); + + hbox1->addWidget(userLabel, 1); + hbox1->addWidget(userLineEdit, 2); + hbox2->addWidget(passLabel, 1); + hbox2->addWidget(passLineEdit, 2); + hbox3->addWidget(loginButton, 1, Qt::AlignRight); + hbox3->addWidget(quitButton, 0, Qt::AlignRight); + + vbox->addSpacing(1); + vbox->addLayout(hbox1); + vbox->addLayout(hbox2); + vbox->addLayout(hbox3); + + connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); + connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); } - -MainWindow::MainWindow(int userID) : - ui(new Ui::MainWindow) + +void MainWindow() { - ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - id=userID; - qDebug()<< "id is "<close(); + parentWidget()->close(); } - -void MainWindow::on_signUpButton_clicked() + +void MainWindow() { - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); + QString username = userLineEdit->text(); + QString password = passLineEdit->text(); + + // Checking if username or password is empty + if (username.isEmpty() || password.isEmpty()) + QMessageBox::information(this, tr("Peringatan!"), "Username atau password tidak boleh kosong"); + else + this->hide(); + + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); } - -void MainWindow::on_logInButton_clicked() -{ - QString email=ui->txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) - { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; - } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) - { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; - } - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); - -} + +MainWindow::~MainWindow() {} From 15d60456de3d2b688944371b3c5ac2fe6e327527 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:33:58 -0400 Subject: [PATCH 1007/1324] Update mainwindow.h --- src/qt/mainwindow.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 1899ff01..b719553e 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,6 +2,14 @@ #define MAINWINDOW_H #include +#include +#include +#include +#include +#include +#include +#include +#include "homepage.h" namespace Ui { class MainWindow; @@ -10,20 +18,24 @@ class MainWindow; class MainWindow : public QMainWindow { Q_OBJECT - + public: - explicit MainWindow(QWidget *parent = 0); - MainWindow(int userID ); - int id; + MainWindow(QWidget* parent = 0); ~MainWindow(); - + private Q_SLOTS: - void on_signUpButton_clicked(); - - void on_logInButton_clicked(); - + void OnQuit(); + void OnLogin(); + private: - Ui::MainWindow *ui; + void reject(); + + QLabel* userLabel; + QLabel* passLabel; + QLineEdit* userLineEdit; + QLineEdit* passLineEdit; + QPushButton* loginButton; + QPushButton* quitButton; }; - + #endif // MAINWINDOW_H From b25096755c21f54f08cba96b92fa1f3750247833 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:37:45 -0400 Subject: [PATCH 1008/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 4b9a1345..82eaabe5 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,5 +1,4 @@ #include "mainwindow.h" -#include "ui_mainwindow.h" #include #include "homepage.h" #include "QMessageBox" @@ -59,7 +58,7 @@ void MainWindow() // Checking if username or password is empty if (username.isEmpty() || password.isEmpty()) - QMessageBox::information(this, tr("Peringatan!"), "Username atau password tidak boleh kosong"); + QMessageBox::information(this, tr("Warning!"), "Do Not Leave User Name & Password Blank"); else this->hide(); From 1759321d348917f8a419c6877c6aaa0fff3a20f4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:38:14 -0400 Subject: [PATCH 1009/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 82eaabe5..2f6b1d8a 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -4,7 +4,7 @@ #include "QMessageBox" MainWindow::MainWindow(QWidget* parent) - : QDialog(parent) + : QMainWndow(parent) { setFixedSize(300, 120); setWindowTitle("Form Login"); From f7025893b2763376195745fe41fa9d56f15f9564 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:42:34 -0400 Subject: [PATCH 1010/1324] Update and rename mainwindow.cpp to FormLogin.cpp --- src/qt/{mainwindow.cpp => FormLogin.cpp} | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) rename src/qt/{mainwindow.cpp => FormLogin.cpp} (85%) diff --git a/src/qt/mainwindow.cpp b/src/qt/FormLogin.cpp similarity index 85% rename from src/qt/mainwindow.cpp rename to src/qt/FormLogin.cpp index 2f6b1d8a..321930f9 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/FormLogin.cpp @@ -1,10 +1,8 @@ -#include "mainwindow.h" -#include +#include "formlogin.h" #include "homepage.h" -#include "QMessageBox" - -MainWindow::MainWindow(QWidget* parent) - : QMainWndow(parent) + +FormLogin::FormLogin(QWidget* parent) + : QDialog(parent) { setFixedSize(300, 120); setWindowTitle("Form Login"); @@ -40,18 +38,18 @@ MainWindow::MainWindow(QWidget* parent) connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); } -void MainWindow() +void FormLogin::reject() { OnQuit(); } -void MainWindow() +void FormLogin::OnQuit() { this->close(); parentWidget()->close(); } -void MainWindow() +void FormLogin::OnLogin() { QString username = userLineEdit->text(); QString password = passLineEdit->text(); @@ -70,4 +68,4 @@ void MainWindow() } -MainWindow::~MainWindow() {} +FormLogin::~FormLogin() {} From e29acd6f784463f2e2eaa41b6cc7b469447dea85 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:42:49 -0400 Subject: [PATCH 1011/1324] Rename FormLogin.cpp to formlogin.cpp --- src/qt/{FormLogin.cpp => formlogin.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{FormLogin.cpp => formlogin.cpp} (100%) diff --git a/src/qt/FormLogin.cpp b/src/qt/formlogin.cpp similarity index 100% rename from src/qt/FormLogin.cpp rename to src/qt/formlogin.cpp From a4e02ae9613159f0c83790dc7d3fc523aa90dbfc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:43:29 -0400 Subject: [PATCH 1012/1324] Update mainwindow.h --- src/qt/mainwindow.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index b719553e..9bac3050 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,7 +1,6 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include +#ifndef FORMLOGIN_H +#define FORMLOGIN_H + #include #include #include @@ -10,18 +9,14 @@ #include #include #include "homepage.h" - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow + +class FormLogin : public QDialog { Q_OBJECT public: - MainWindow(QWidget* parent = 0); - ~MainWindow(); + FormLogin(QWidget* parent = 0); + ~FormLogin(); private Q_SLOTS: void OnQuit(); @@ -38,4 +33,4 @@ private Q_SLOTS: QPushButton* quitButton; }; -#endif // MAINWINDOW_H +#endif // FORMLOGIN_H From dc264b1adeba99ed41bc994b5ea903db8f6178b5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:43:56 -0400 Subject: [PATCH 1013/1324] Rename mainwindow.h to formlogin.h --- src/qt/{mainwindow.h => formlogin.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/qt/{mainwindow.h => formlogin.h} (100%) diff --git a/src/qt/mainwindow.h b/src/qt/formlogin.h similarity index 100% rename from src/qt/mainwindow.h rename to src/qt/formlogin.h From 389fb1ad7f9a08fc9f1d5d8b8e378c21681aa628 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:44:10 -0400 Subject: [PATCH 1014/1324] Create mainwindow.cpp --- src/qt/mainwindow.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/qt/mainwindow.cpp diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 00000000..8861b7bc --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,9 @@ +#include "mainwindow.h" + +MainWindow::MainWindow() + : QMainWindow() +{ + setMinimumSize(800, 600); +} + +MainWindow::~MainWindow() {} From af5bfeab83caeeb16af96cbca5e609edc2e5022c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:44:37 -0400 Subject: [PATCH 1015/1324] Create mainwindow.h --- src/qt/mainwindow.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/qt/mainwindow.h diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h new file mode 100644 index 00000000..960944ad --- /dev/null +++ b/src/qt/mainwindow.h @@ -0,0 +1,15 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + ~MainWindow(); +}; + +#endif // MAINWINDOW_H From 206c36ec09c5801702a7822fbb1227445212d5c7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:45:03 -0400 Subject: [PATCH 1016/1324] Update main.cpp --- src/qt/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index c72209ce..2b7e3d34 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,12 +1,15 @@ + #include "mainwindow.h" +#include "formlogin.h" #include -#include "homepage.h" - + int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; - w.show(); - + MainWindow* mainWindow = new MainWindow(); + FormLogin* formLogin = new FormLogin(mainWindow); + formLogin->show(); + mainWindow->show(); + return a.exec(); } From b360d8ab26679cb152e8ee5e4d9684cbd9541e0c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 18 Jun 2020 23:46:06 -0400 Subject: [PATCH 1017/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a22f9aa5..676fdc18 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -126,7 +126,8 @@ QT_MOC_CPP = \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ qt/moc_mainwindow.cpp \ - qt/moc_newaccount.cpp + qt/moc_newaccount.cpp \ + qt/moc_formlogin.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -223,7 +224,8 @@ BITCOIN_QT_H = \ qt/statistics.h \ qt/user.h \ qt/mainwindow.h \ - qt/newaccount.h + qt/newaccount.h \ + qt/formlogin.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -576,7 +578,8 @@ BITCOIN_QT_WALLET_CPP = \ qt/user.cpp \ qt/main.cpp \ qt/mainwindow.cpp \ - qt/newaccount.cpp + qt/newaccount.cpp \ + qt/formlogin.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From acd90581b11bda7d6ffff49c3b086f2ed1e4e207 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:07:54 -0400 Subject: [PATCH 1018/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 676fdc18..a22f9aa5 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -126,8 +126,7 @@ QT_MOC_CPP = \ qt/moc_statistics.cpp \ qt/moc_user.cpp \ qt/moc_mainwindow.cpp \ - qt/moc_newaccount.cpp \ - qt/moc_formlogin.cpp + qt/moc_newaccount.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -224,8 +223,7 @@ BITCOIN_QT_H = \ qt/statistics.h \ qt/user.h \ qt/mainwindow.h \ - qt/newaccount.h \ - qt/formlogin.h + qt/newaccount.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -578,8 +576,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/user.cpp \ qt/main.cpp \ qt/mainwindow.cpp \ - qt/newaccount.cpp \ - qt/formlogin.cpp + qt/newaccount.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From b88a8ef444a047af88ccb2648a134853b8669414 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:08:07 -0400 Subject: [PATCH 1019/1324] Delete formlogin.cpp --- src/qt/formlogin.cpp | 71 -------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/qt/formlogin.cpp diff --git a/src/qt/formlogin.cpp b/src/qt/formlogin.cpp deleted file mode 100644 index 321930f9..00000000 --- a/src/qt/formlogin.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "formlogin.h" -#include "homepage.h" - -FormLogin::FormLogin(QWidget* parent) - : QDialog(parent) -{ - setFixedSize(300, 120); - setWindowTitle("Form Login"); - setModal(true); - setAttribute(Qt::WA_DeleteOnClose); - - userLabel = new QLabel("Username:"); - passLabel = new QLabel("Password:"); - userLineEdit = new QLineEdit(); - passLineEdit = new QLineEdit(); - passLineEdit->setEchoMode(QLineEdit::Password); - loginButton = new QPushButton("Login"); - quitButton = new QPushButton("Quit"); - - QVBoxLayout* vbox = new QVBoxLayout(this); - QHBoxLayout* hbox1 = new QHBoxLayout(); - QHBoxLayout* hbox2 = new QHBoxLayout(); - QHBoxLayout* hbox3 = new QHBoxLayout(); - - hbox1->addWidget(userLabel, 1); - hbox1->addWidget(userLineEdit, 2); - hbox2->addWidget(passLabel, 1); - hbox2->addWidget(passLineEdit, 2); - hbox3->addWidget(loginButton, 1, Qt::AlignRight); - hbox3->addWidget(quitButton, 0, Qt::AlignRight); - - vbox->addSpacing(1); - vbox->addLayout(hbox1); - vbox->addLayout(hbox2); - vbox->addLayout(hbox3); - - connect(quitButton, SIGNAL(clicked()), this, SLOT(OnQuit())); - connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin())); -} - -void FormLogin::reject() -{ - OnQuit(); -} - -void FormLogin::OnQuit() -{ - this->close(); - parentWidget()->close(); -} - -void FormLogin::OnLogin() -{ - QString username = userLineEdit->text(); - QString password = passLineEdit->text(); - - // Checking if username or password is empty - if (username.isEmpty() || password.isEmpty()) - QMessageBox::information(this, tr("Warning!"), "Do Not Leave User Name & Password Blank"); - else - this->hide(); - - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); - - -} - -FormLogin::~FormLogin() {} From e7d43f33114720d40fb79b206f96fbe961bff6f1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:08:17 -0400 Subject: [PATCH 1020/1324] Delete formlogin.h --- src/qt/formlogin.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/qt/formlogin.h diff --git a/src/qt/formlogin.h b/src/qt/formlogin.h deleted file mode 100644 index 9bac3050..00000000 --- a/src/qt/formlogin.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FORMLOGIN_H -#define FORMLOGIN_H - -#include -#include -#include -#include -#include -#include -#include -#include "homepage.h" - -class FormLogin : public QDialog -{ - Q_OBJECT - -public: - FormLogin(QWidget* parent = 0); - ~FormLogin(); - -private Q_SLOTS: - void OnQuit(); - void OnLogin(); - -private: - void reject(); - - QLabel* userLabel; - QLabel* passLabel; - QLineEdit* userLineEdit; - QLineEdit* passLineEdit; - QPushButton* loginButton; - QPushButton* quitButton; -}; - -#endif // FORMLOGIN_H From 5e56180aeae0805563fe68b355978e4994131c5f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:08:40 -0400 Subject: [PATCH 1021/1324] Delete db.s3db --- src/qt/db.s3db | Bin 7168 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/db.s3db diff --git a/src/qt/db.s3db b/src/qt/db.s3db deleted file mode 100644 index dff92915b85d0c974aae76adbd759b642e228fc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7168 zcmeHLL2uJA6t?5CuBAml6;%_OY7L<^TBy{)1@*9YBSVF*+e#|2Q)Iq+k}`JP zF8l!g!H)Y6`~tWjaoQbDOxlSH64*&=sHRSAJi@RsY@ zdVn8+7=RFzF$MrE5Q!5(LRbyaz$H1JxZx>9Lu z;1|jUt~AxvYMmIZD0NlF)S08(7FLy4Dz2{*Y1V4ES+A})6&dg9zQ1n{DrLNN(L%;H zYm{+^m6=N!d%DwRke({bm1a%F`JyCa%hp?+!9f^;2no*jfl5*_HIY?v5VRcAdh73X z$W&^2H*mwc#u(7%SurlW2djE%s7dI<54vW{)dI`j)k3bdV&wdS0s0kWb9W}&2;cFUnQ4c84Sw9@hePbX%-LRHx#?FH9+-Fqf_mJ8_n z=ugN!a0WO7W5z%nWgyvaXd<5scN1X}WfS2>K+k`O&H*|{U&ahIhr=1*3|xnSR1D=3 zEXOAvrXhR(NfRApx)hCn0Ugu){}{cy&S2bzGr$=bm4OGT1Q5kcIuqslG<9Eg-9_D# zgjs>8rUq2|W~8Ktc`yGbxqL7GPhTbfPZHn)Is@njIz!(^eF|>R8Q=_zAp?_0gk-bm y-Ml~fe-!_xfJFZ(`aFinIV8>iXW$A9+(i-%b+60{wC2-~eZn0iMX&wr``>TtBd!7f From b93157426b7071056ee7f6c3c1bd65d64c4e517a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:08:56 -0400 Subject: [PATCH 1022/1324] Delete db.s3db.sql --- src/qt/db.s3db.sql | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/qt/db.s3db.sql diff --git a/src/qt/db.s3db.sql b/src/qt/db.s3db.sql deleted file mode 100644 index ed402741..00000000 --- a/src/qt/db.s3db.sql +++ /dev/null @@ -1,14 +0,0 @@ --- --- File generated with SQLiteStudio v3.0.7 on Sun Mar 20 17:59:39 2016 --- --- Text encoding used: windows-1252 --- -PRAGMA foreign_keys = off; -BEGIN TRANSACTION; - --- Table: sys_users -CREATE TABLE sys_users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, passwd TEXT NOT NULL, fname TEXT NOT NULL, mname TEXT, lname TEXT NOT NULL, rank INTEGER DEFAULT (1), email TEXT NOT NULL UNIQUE, UNIQUE (username)) -INSERT INTO sys_users (id, username, passwd, fname, mname, lname, rank, email) VALUES (1, 'admin', 'pass', 'Root', NULL, 'Administrator', -1, 'admin@root.org'); - -COMMIT TRANSACTION; -PRAGMA foreign_keys = on; From f0cc7deb2fdb95448659a1630b23f2ee38f04b98 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:09:30 -0400 Subject: [PATCH 1023/1324] Update main.cpp --- src/qt/main.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 2b7e3d34..c72209ce 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,15 +1,12 @@ - #include "mainwindow.h" -#include "formlogin.h" #include - +#include "homepage.h" + int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow* mainWindow = new MainWindow(); - FormLogin* formLogin = new FormLogin(mainWindow); - formLogin->show(); - mainWindow->show(); - + MainWindow w; + w.show(); + return a.exec(); } From 6b38ed7e5afebcaab2b7fe003045023a343f669c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:10:59 -0400 Subject: [PATCH 1024/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 69 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 8861b7bc..bd7d9771 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,9 +1,66 @@ #include "mainwindow.h" - -MainWindow::MainWindow() - : QMainWindow() +#include "ui_mainwindow.h" +#include "newaccount.h" +#include +#include "homepage.h" +#include + +MainWindow::MainWindow(QWidget *parent) : +QMainWindow(parent), +ui(new Ui::MainWindow) { - setMinimumSize(800, 600); +ui->setupUi(this); +ui->signUpLabel->setText("No account? Create one!"); +QWidget::setWindowIcon(QIcon(":/icons/about.png")); +this->setWindowTitle("Social Network"); + +} + +MainWindow::MainWindow(int userID) : + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + ui->signUpLabel->setText("No account? Create one!"); + id=userID; + qDebug()<< "id is "<show(); + this->hide(); + + +} + +void MainWindow::on_logInButton_clicked() +{ + QString email=ui->txtUserMail->text(); + QFile userFile("Users/"+email+".xml"); + if(!userFile.open(QFile::ReadOnly)) + { + QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); + return; + } + user *currentSessionUser = new user(); + currentSessionUser->userName = email; + currentSessionUser->userFileManipulator.name = email; + QString password = currentSessionUser->userFileManipulator.getPassword(email); + if(password != ui->txtPassword->text()) + { + QMessageBox::information(this,"Error","Wrong Password. Please try again!"); + return; + } + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); + this->hide(); + } - -MainWindow::~MainWindow() {} From ad8a8f8babe7988ae24a1f22a85afcc632a9c725 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:11:44 -0400 Subject: [PATCH 1025/1324] Update mainwindow.h --- src/qt/mainwindow.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 960944ad..5b17c669 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,15 +1,29 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - + #include - + +namespace Ui { +class MainWindow; +} + class MainWindow : public QMainWindow { Q_OBJECT - + public: - MainWindow(); + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; ~MainWindow(); + +private Q_SLOTS: + void on_signUpButton_clicked(); + + void on_logInButton_clicked(); + +private: + Ui::MainWindow *ui; }; - + #endif // MAINWINDOW_H From 2b2a7a5117313118c2f73470c27d1fba47cf25dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:17:44 -0400 Subject: [PATCH 1026/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index bd7d9771..5acef1b0 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -2,6 +2,8 @@ #include "ui_mainwindow.h" #include "newaccount.h" #include +#include +#include #include "homepage.h" #include From 580a15d25e211dcb1ad19243a2d1c63def56b419 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:22:15 -0400 Subject: [PATCH 1027/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 9ca3731f..292c76b9 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -1,6 +1,8 @@ #include "newaccount.h" #include "ui_newaccount.h" -#include "QMessageBox" +#include +#include +#include #include newAccount::newAccount(QWidget *parent) : QMainWindow(parent), From 55211a396310853f3c3d343914e2be8ed21cd39c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:22:39 -0400 Subject: [PATCH 1028/1324] Update activity.h --- src/qt/activity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/activity.h b/src/qt/activity.h index 24896d27..2971b0c9 100644 --- a/src/qt/activity.h +++ b/src/qt/activity.h @@ -4,7 +4,7 @@ #include #include "vector" #include "posts.h" -#include "QList" +#include class Activity { unsigned int likesNumbers; From 0312ea013960ad739bd23b37787091715a92bc00 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:23:45 -0400 Subject: [PATCH 1029/1324] Update comment.h --- src/qt/comment.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qt/comment.h b/src/qt/comment.h index 9a54b7c9..0161d3ca 100644 --- a/src/qt/comment.h +++ b/src/qt/comment.h @@ -1,9 +1,9 @@ #ifndef COMMENT_H #define COMMENT_H -#include "QString" -#include "QDate" -#include "QTime" +#include +#include +#include class Date : public QDate { QTime timeIsNow; From 55f7941e020b275557b5213901f9a759c2dd000f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:24:19 -0400 Subject: [PATCH 1030/1324] Update fileman.cpp --- src/qt/fileman.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qt/fileman.cpp b/src/qt/fileman.cpp index cab9aee7..90d3993b 100644 --- a/src/qt/fileman.cpp +++ b/src/qt/fileman.cpp @@ -1,5 +1,8 @@ #include "fileman.h" #include +#include +#include +#include int numberOfUsers=0; QList emailss; From 955a35a751fa03e745db3f512bbcc1ba24fb985c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:25:43 -0400 Subject: [PATCH 1031/1324] Update homepage.cpp --- src/qt/homepage.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 81759eea..25589410 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -6,18 +6,18 @@ //selim includes #include "mainwindow.h" #include "ui_mainwindow.h" -#include "QHBoxLayout" -#include "QVBoxLayout" -#include "QLabel" -#include "QSpacerItem" -#include "QPushButton" +#include +#include +#include +#include +#include #include #include "posts.h" -#include "QString" +#include #include -#include "QFontMetrics" -#include "QGroupBox" -#include "QScrollBar" +#include +#include +#include #include "mainwindow.h" #include "addcomment.h" #include "adminwindow.h" From d680d6633a8db60b54f2bdb38165218a9c63676d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:26:27 -0400 Subject: [PATCH 1032/1324] Update homepage.h --- src/qt/homepage.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index 15a070a1..bb524d61 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -5,8 +5,9 @@ #include "profilepage.h" #include "posts.h" #include "user.h" -#include "QList" -#include "QVBoxLayout" +#include +#include +#include namespace Ui { class HomePage; } From 8e2cd952c54427fc605c8d6f704fe80c3ba4a718 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:28:12 -0400 Subject: [PATCH 1033/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 170d9290..e459fb90 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -5,18 +5,18 @@ //selim includes #include "mainwindow.h" #include "ui_mainwindow.h" -#include "QHBoxLayout" -#include "QVBoxLayout" -#include "QLabel" -#include "QSpacerItem" -#include "QPushButton" +#include +#include +#include +#include +#include #include #include "posts.h" -#include "QString" +#include #include -#include "QFontMetrics" -#include "QGroupBox" -#include "QScrollBar" +#include +#include +#include #include "mainwindow.h" #include "addcomment.h" #define POSTSNUMBER 100 From a7af94f6894ff0fb61d0e045b6a074198514d20b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 21:29:12 -0400 Subject: [PATCH 1034/1324] Update statistics.h --- src/qt/statistics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/statistics.h b/src/qt/statistics.h index bbb5f472..0cec4093 100644 --- a/src/qt/statistics.h +++ b/src/qt/statistics.h @@ -1,6 +1,6 @@ #ifndef STATISTICS_H #define STATISTICS_H -#include "QString" +#include class Statistics { From 6920143d1d100970aaff3a275f44fe55c4589b4d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:05:53 -0400 Subject: [PATCH 1035/1324] Update main.cpp --- src/qt/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index c72209ce..bfa4d5f0 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,12 +1,12 @@ -#include "mainwindow.h" -#include +#include "LoginForm.h" #include "homepage.h" int main(int argc, char *argv[]) { - QApplication a(argc, argv); - MainWindow w; - w.show(); + QApplication app(argc, argv); - return a.exec(); + LoginForm form; + form.show(); + + return app.exec(); } From 6e6fdeb563bcba40013ad402844353b0cfc22239 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:07:47 -0400 Subject: [PATCH 1036/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 110 ++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 5acef1b0..170a3768 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,68 +1,82 @@ +#ifndef _MainWindow_CPP +#define _MainWindow_CPP + #include "mainwindow.h" -#include "ui_mainwindow.h" -#include "newaccount.h" -#include -#include -#include -#include "homepage.h" -#include -MainWindow::MainWindow(QWidget *parent) : -QMainWindow(parent), -ui(new Ui::MainWindow) +MainWindow::MainWindow() { -ui->setupUi(this); -ui->signUpLabel->setText("No account? Create one!"); -QWidget::setWindowIcon(QIcon(":/icons/about.png")); -this->setWindowTitle("Social Network"); - + setupUi(this); + connect(loginbtn, SIGNAL(clicked()), this, SLOT(loginclick())); + connect(quitbtn, SIGNAL(clicked()), this, SLOT(close())); } -MainWindow::MainWindow(int userID) : - ui(new Ui::MainWindow) +void MainWindow::setupUi(QDialog *MainWindow) { - ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - id=userID; - qDebug()<< "id is "<objectName().isEmpty()) + MainWindow->setObjectName(QString::fromUtf8("LoginForm")); + MainWindow->setWindowModality(Qt::NonModal); + MainWindow->resize(627, 414); + loginbtn = new QPushButton(LoginForm); + loginbtn->setObjectName(QString::fromUtf8("loginbtn")); + loginbtn->setGeometry(QRect(140, 250, 114, 32)); + quitbtn = new QPushButton(LoginForm); + quitbtn->setObjectName(QString::fromUtf8("quitbtn")); + quitbtn->setGeometry(QRect(300, 250, 114, 32)); + usernametext = new QLineEdit(LoginForm); + usernametext->setObjectName(QString::fromUtf8("usernametext")); + usernametext->setGeometry(QRect(240, 140, 113, 22)); + passtext = new QLineEdit(LoginForm); + passtext->setObjectName(QString::fromUtf8("passtext")); + passtext->setGeometry(QRect(240, 190, 113, 22)); + passtext->setInputMask(QString::fromUtf8("")); + passtext->setMaxLength(32767); + passtext->setEchoMode(QLineEdit::Password); + password = new QLabel(LoginForm); + password->setObjectName(QString::fromUtf8("password")); + password->setGeometry(QRect(130, 190, 62, 16)); + username = new QLabel(LoginForm); + username->setObjectName(QString::fromUtf8("username")); + username->setGeometry(QRect(130, 140, 62, 16)); -} + retranslateUi(LoginForm); -MainWindow::~MainWindow() -{ - delete ui; -} + QMetaObject::connectSlotsByName(LoginForm); +} // setupUi -void MainWindow::on_signUpButton_clicked() +void MainWindow::retranslateUi(QDialog *MainWindow) { - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); + MainWindow->setWindowTitle(QApplication::translate("LoginForm", "User System Login", 0, QApplication::UnicodeUTF8)); + loginbtn->setText(QApplication::translate("LoginForm", "Login", 0, QApplication::UnicodeUTF8)); + quitbtn->setText(QApplication::translate("LoginForm", "Quit", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + usernametext->setToolTip(QApplication::translate("LoginForm", "Enter Username", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP + passtext->setToolTip(QApplication::translate("LoginForm", "Enter Password", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP + + passtext->setText(QString()); + passtext->setPlaceholderText(QString()); + password->setText(QApplication::translate("LoginForm", "Password", 0, QApplication::UnicodeUTF8)); + username->setText(QApplication::translate("LoginForm", "Username", 0, QApplication::UnicodeUTF8)); +} // retranslateUi + +MainWindow::~MainWindow() +{ } -void MainWindow::on_logInButton_clicked() +void MainWindow::loginclick() { - QString email=ui->txtUserMail->text(); - QFile userFile("Users/"+email+".xml"); - if(!userFile.open(QFile::ReadOnly)) + if (usernametext->text() == "Devilking6105" && passtext->text() == "123456") { - QMessageBox::information(this,"Error","Email doesn't exist. Please sign up!"); - return; + QMessageBox::information(this, "Success", "Password Correct"); } - user *currentSessionUser = new user(); - currentSessionUser->userName = email; - currentSessionUser->userFileManipulator.name = email; - QString password = currentSessionUser->userFileManipulator.getPassword(email); - if(password != ui->txtPassword->text()) + else { - QMessageBox::information(this,"Error","Wrong Password. Please try again!"); - return; + QMessageBox::information(this, "Failure", "Password Incorrect"); } - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); - } + +#endif From d88913837306d25971272f3eb87549c11b94f716 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:08:49 -0400 Subject: [PATCH 1037/1324] Update mainwindow.h --- src/qt/mainwindow.h | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 5b17c669..1067e618 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,29 +1,27 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#ifndef _MainWindow_H +#define _MainWindow_H -#include +#include -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow +class MainWindow : public QDialog { Q_OBJECT - public: - explicit MainWindow(QWidget *parent = 0); - MainWindow(int userID ); - int id; - ~MainWindow(); - -private Q_SLOTS: - void on_signUpButton_clicked(); - - void on_logInButton_clicked(); - + MainWindow(); + QPushButton *loginbtn; + QPushButton *quitbtn; + QLineEdit *usernametext; + QLineEdit *passtext; + QLabel *password; + QLabel *username; + void setupUi(QDialog *MainWindow); + void retranslateUi(QDialog *MainWindow); + virtual ~MainWindow(); +public Q_SLOTS: + void loginclick(); private: - Ui::MainWindow *ui; + QString user; + QString pass; }; -#endif // MAINWINDOW_H +#endif /* _MainWindow_H */ From 414f87ac7322c2d15186c49450859a42f1512107 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:10:48 -0400 Subject: [PATCH 1038/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 1067e618..dbcc53d5 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -2,6 +2,9 @@ #define _MainWindow_H #include +#include +#include +#Include class MainWindow : public QDialog { From c47a0b1f63ba5699349d1ecee5ba39b78fd62629 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:11:44 -0400 Subject: [PATCH 1039/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index dbcc53d5..946fb407 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -4,7 +4,7 @@ #include #include #include -#Include +#include class MainWindow : public QDialog { From e641173615e384cc6fdb29ea0203c3a8ac8e07fc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:12:36 -0400 Subject: [PATCH 1040/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 946fb407..b7c5ba69 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -6,7 +6,7 @@ #include #include -class MainWindow : public QDialog +class MainWindow : public QMainWindow { Q_OBJECT public: From ad9df5ab1651d17cd89fd6d4db3ebf7a255b9f7d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:13:40 -0400 Subject: [PATCH 1041/1324] Update main.cpp --- src/qt/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index bfa4d5f0..9bb13201 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,11 +1,11 @@ -#include "LoginForm.h" +#include "mainwindow.h" #include "homepage.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); - LoginForm form; + MainWindow form; form.show(); return app.exec(); From 48905256b7b1e7b464ce71ad53da579fa1e6fcd7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:14:18 -0400 Subject: [PATCH 1042/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 170a3768..8f3fbb7d 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,7 @@ #ifndef _MainWindow_CPP #define _MainWindow_CPP +#include #include "mainwindow.h" MainWindow::MainWindow() From ab0144183590e02e5fd418e5dca3f57475408388 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:14:48 -0400 Subject: [PATCH 1043/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 8f3fbb7d..b8d0ae08 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -2,6 +2,7 @@ #define _MainWindow_CPP #include +#include #include "mainwindow.h" MainWindow::MainWindow() From 00e00923fe4d594b343b75ca7ec1c8b475ff6a5b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:18:28 -0400 Subject: [PATCH 1044/1324] Update mainwindow.h --- src/qt/mainwindow.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index b7c5ba69..74f0b70b 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -5,8 +5,9 @@ #include #include #include +#include -class MainWindow : public QMainWindow +class MainWindow : public QDialog { Q_OBJECT public: From 18ae0e42fe06bfe9dbd1efb99984ac06af0ac466 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:18:45 -0400 Subject: [PATCH 1045/1324] Update mainwindow.h --- src/qt/mainwindow.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 74f0b70b..6ac69ad0 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -6,6 +6,7 @@ #include #include #include +#include class MainWindow : public QDialog { From 3bde864d21743af8808b25c85d62f43ae72292c3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:23:06 -0400 Subject: [PATCH 1046/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index b8d0ae08..be139a51 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -18,31 +18,31 @@ void MainWindow::setupUi(QDialog *MainWindow) MainWindow->setObjectName(QString::fromUtf8("LoginForm")); MainWindow->setWindowModality(Qt::NonModal); MainWindow->resize(627, 414); - loginbtn = new QPushButton(LoginForm); + loginbtn = new QPushButton(MainWindow); loginbtn->setObjectName(QString::fromUtf8("loginbtn")); loginbtn->setGeometry(QRect(140, 250, 114, 32)); - quitbtn = new QPushButton(LoginForm); + quitbtn = new QPushButton(MainWindow); quitbtn->setObjectName(QString::fromUtf8("quitbtn")); quitbtn->setGeometry(QRect(300, 250, 114, 32)); - usernametext = new QLineEdit(LoginForm); + usernametext = new QLineEdit(MainWindow); usernametext->setObjectName(QString::fromUtf8("usernametext")); usernametext->setGeometry(QRect(240, 140, 113, 22)); - passtext = new QLineEdit(LoginForm); + passtext = new QLineEdit(MainWindow); passtext->setObjectName(QString::fromUtf8("passtext")); passtext->setGeometry(QRect(240, 190, 113, 22)); passtext->setInputMask(QString::fromUtf8("")); passtext->setMaxLength(32767); passtext->setEchoMode(QLineEdit::Password); - password = new QLabel(LoginForm); + password = new QLabel(MainWindow); password->setObjectName(QString::fromUtf8("password")); password->setGeometry(QRect(130, 190, 62, 16)); - username = new QLabel(LoginForm); + username = new QLabel(MainWindow); username->setObjectName(QString::fromUtf8("username")); username->setGeometry(QRect(130, 140, 62, 16)); - retranslateUi(LoginForm); + retranslateUi(MainWindow); - QMetaObject::connectSlotsByName(LoginForm); + QMetaObject::connectSlotsByName(MainWindow); } // setupUi void MainWindow::retranslateUi(QDialog *MainWindow) From bfe8edf6397ab3c2a831e08fe3cc1eb5ccbd366a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:23:36 -0400 Subject: [PATCH 1047/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 6ac69ad0..3ee32bf8 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -8,7 +8,7 @@ #include #include -class MainWindow : public QDialog +class MainWindow : public QMainWindow { Q_OBJECT public: From bad939f9f66b8419e1a3ad2294868adb24cff15e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:26:03 -0400 Subject: [PATCH 1048/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 3ee32bf8..0fb6dcde 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -8,7 +8,7 @@ #include #include -class MainWindow : public QMainWindow +class MainWindow : public MainWindow { Q_OBJECT public: From 13c5941471787f7f75a50986a0140434248223ca Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:30:05 -0400 Subject: [PATCH 1049/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 0fb6dcde..3ee32bf8 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -8,7 +8,7 @@ #include #include -class MainWindow : public MainWindow +class MainWindow : public QMainWindow { Q_OBJECT public: From 8151eb35defbccd3b1229794b5b29e673ddbcb77 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:39:06 -0400 Subject: [PATCH 1050/1324] Update mainwindow.h --- src/qt/mainwindow.h | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 3ee32bf8..eae1a7ce 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -1,32 +1,27 @@ -#ifndef _MainWindow_H -#define _MainWindow_H +#ifndef MAINWINDOW_H +#define MAINWINDOW_H -#include -#include -#include -#include -#include -#include +#include + +namespace Ui { +class MainWindow; +} class MainWindow : public QMainWindow { Q_OBJECT + public: - MainWindow(); - QPushButton *loginbtn; - QPushButton *quitbtn; - QLineEdit *usernametext; - QLineEdit *passtext; - QLabel *password; - QLabel *username; - void setupUi(QDialog *MainWindow); - void retranslateUi(QDialog *MainWindow); - virtual ~MainWindow(); -public Q_SLOTS: - void loginclick(); + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private Q_SLOTS: + void on_signUpButton_clicked(); + + void on_logInButton_clicked(); + private: - QString user; - QString pass; + Ui::MainWindow *ui; }; -#endif /* _MainWindow_H */ +#endif // MAINWINDOW_H From 5a41b1c4f376f24d9992229af3828f99523b01d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:40:04 -0400 Subject: [PATCH 1051/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 95 ++++++++++--------------------------------- 1 file changed, 22 insertions(+), 73 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index be139a51..0e037e21 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,84 +1,33 @@ -#ifndef _MainWindow_CPP -#define _MainWindow_CPP - -#include -#include #include "mainwindow.h" - -MainWindow::MainWindow() +#include "ui_mainwindow.h" +#include "newaccount.h" +#include "homepage.h" +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) { - setupUi(this); - connect(loginbtn, SIGNAL(clicked()), this, SLOT(loginclick())); - connect(quitbtn, SIGNAL(clicked()), this, SLOT(close())); + ui->setupUi(this); + ui->signUpLabel->setText("No account? Create one!"); + } -void MainWindow::setupUi(QDialog *MainWindow) +MainWindow::~MainWindow() { - if (MainWindow->objectName().isEmpty()) - MainWindow->setObjectName(QString::fromUtf8("LoginForm")); - MainWindow->setWindowModality(Qt::NonModal); - MainWindow->resize(627, 414); - loginbtn = new QPushButton(MainWindow); - loginbtn->setObjectName(QString::fromUtf8("loginbtn")); - loginbtn->setGeometry(QRect(140, 250, 114, 32)); - quitbtn = new QPushButton(MainWindow); - quitbtn->setObjectName(QString::fromUtf8("quitbtn")); - quitbtn->setGeometry(QRect(300, 250, 114, 32)); - usernametext = new QLineEdit(MainWindow); - usernametext->setObjectName(QString::fromUtf8("usernametext")); - usernametext->setGeometry(QRect(240, 140, 113, 22)); - passtext = new QLineEdit(MainWindow); - passtext->setObjectName(QString::fromUtf8("passtext")); - passtext->setGeometry(QRect(240, 190, 113, 22)); - passtext->setInputMask(QString::fromUtf8("")); - passtext->setMaxLength(32767); - passtext->setEchoMode(QLineEdit::Password); - password = new QLabel(MainWindow); - password->setObjectName(QString::fromUtf8("password")); - password->setGeometry(QRect(130, 190, 62, 16)); - username = new QLabel(MainWindow); - username->setObjectName(QString::fromUtf8("username")); - username->setGeometry(QRect(130, 140, 62, 16)); - - retranslateUi(MainWindow); - - QMetaObject::connectSlotsByName(MainWindow); -} // setupUi + delete ui; +} -void MainWindow::retranslateUi(QDialog *MainWindow) +/*void MainWindow::on_signUpButton_clicked() { - MainWindow->setWindowTitle(QApplication::translate("LoginForm", "User System Login", 0, QApplication::UnicodeUTF8)); - loginbtn->setText(QApplication::translate("LoginForm", "Login", 0, QApplication::UnicodeUTF8)); - quitbtn->setText(QApplication::translate("LoginForm", "Quit", 0, QApplication::UnicodeUTF8)); + newAccount *newAccountWindow = new newAccount; + newAccountWindow->show(); + this->hide(); + newAccountWindow->setLoginPtr(this); -#ifndef QT_NO_TOOLTIP - usernametext->setToolTip(QApplication::translate("LoginForm", "Enter Username", 0, QApplication::UnicodeUTF8)); -#endif // QT_NO_TOOLTIP +} */ -#ifndef QT_NO_TOOLTIP - passtext->setToolTip(QApplication::translate("LoginForm", "Enter Password", 0, QApplication::UnicodeUTF8)); -#endif // QT_NO_TOOLTIP - - passtext->setText(QString()); - passtext->setPlaceholderText(QString()); - password->setText(QApplication::translate("LoginForm", "Password", 0, QApplication::UnicodeUTF8)); - username->setText(QApplication::translate("LoginForm", "Username", 0, QApplication::UnicodeUTF8)); -} // retranslateUi - -MainWindow::~MainWindow() +void MainWindow::on_logInButton_clicked() { + this->hide(); + HomePage *homePageWindow = new HomePage; + homePageWindow->show(); } - -void MainWindow::loginclick() -{ - if (usernametext->text() == "Devilking6105" && passtext->text() == "123456") - { - QMessageBox::information(this, "Success", "Password Correct"); - } - else - { - QMessageBox::information(this, "Failure", "Password Incorrect"); - } -} - -#endif From 922b5c960239c8e13307589556b21bc20c9b2d26 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:40:24 -0400 Subject: [PATCH 1052/1324] Update main.cpp --- src/qt/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 9bb13201..c72209ce 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -1,12 +1,12 @@ #include "mainwindow.h" +#include #include "homepage.h" int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QApplication a(argc, argv); + MainWindow w; + w.show(); - MainWindow form; - form.show(); - - return app.exec(); + return a.exec(); } From d77753e79054346228609d295a24eeae4fb48e1c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:46:01 -0400 Subject: [PATCH 1053/1324] Update mainwindow.h --- src/qt/mainwindow.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index eae1a7ce..5b17c669 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -12,7 +12,9 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); + MainWindow(int userID ); + int id; ~MainWindow(); private Q_SLOTS: From e514ff91c313da3814d4d86057c7db7fa3b86ad1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 22:47:50 -0400 Subject: [PATCH 1054/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 5b17c669..b8b19f9d 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow ~MainWindow(); private Q_SLOTS: - void on_signUpButton_clicked(); +/* void on_signUpButton_clicked(); */ void on_logInButton_clicked(); From 000b5f830eed2cafd92c10d066a6db16be5d3753 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:10:52 -0400 Subject: [PATCH 1055/1324] Update adminwindow.ui --- src/qt/forms/adminwindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui index 4eb710bd..51fa3ceb 100644 --- a/src/qt/forms/adminwindow.ui +++ b/src/qt/forms/adminwindow.ui @@ -1,7 +1,7 @@ AdminWindow - + 0 From cbd6ba4dcf14dd6e48d0fb62a82d89268083506e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:11:13 -0400 Subject: [PATCH 1056/1324] Update homepage.ui --- src/qt/forms/homepage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui index 0d3cdb97..81781281 100644 --- a/src/qt/forms/homepage.ui +++ b/src/qt/forms/homepage.ui @@ -1,7 +1,7 @@ HomePage - + 0 From b777b371952d70a2d6449aa19a6a8da2994af5a1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:11:25 -0400 Subject: [PATCH 1057/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index f9070099..a90c738f 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -1,7 +1,7 @@ MainWindow - + 0 From 9d885c6678f8649ee7620ca7629f6634322fc2c5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:11:36 -0400 Subject: [PATCH 1058/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index dd87603b..b7d052f1 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -1,7 +1,7 @@ newAccount - + 0 From 513b0f4f9a36cb8aea0dde0f6446d14212d5a471 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:11:49 -0400 Subject: [PATCH 1059/1324] Update profilepage.ui --- src/qt/forms/profilepage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui index 8114320a..87fc0cd5 100644 --- a/src/qt/forms/profilepage.ui +++ b/src/qt/forms/profilepage.ui @@ -1,7 +1,7 @@ ProfilePage - + 0 From 6d73ee94c2e1f93657704466d453024a21ec7947 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:13:10 -0400 Subject: [PATCH 1060/1324] Update adminwindow.cpp --- src/qt/adminwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp index 0a8e4f58..1e5ef6b3 100644 --- a/src/qt/adminwindow.cpp +++ b/src/qt/adminwindow.cpp @@ -3,7 +3,7 @@ #include "statistics.h" #include "fileman.h" AdminWindow::AdminWindow(QWidget *parent) : - QMainWindow(parent), + QWidget(parent), ui(new Ui::AdminWindow) { ui->setupUi(this); From 0ad6e4e1694e53422788b8e6293168d9f9d7d474 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:13:39 -0400 Subject: [PATCH 1061/1324] Update adminwindow.h --- src/qt/adminwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h index 3fb32a8a..0c5cc3dd 100644 --- a/src/qt/adminwindow.h +++ b/src/qt/adminwindow.h @@ -7,7 +7,7 @@ namespace Ui { class AdminWindow; } -class AdminWindow : public QMainWindow +class AdminWindow : public QWidget { Q_OBJECT From 1440578b87bbc14b7ca29ea5df2423d5101ad89d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:14:34 -0400 Subject: [PATCH 1062/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 25589410..4535702c 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -26,7 +26,7 @@ #define POSTSATATIME 15 //_____ HomePage::HomePage(QWidget *parent) : - QMainWindow(parent), + QWidget(parent), ui(new Ui::HomePage) { ui->setupUi(this); From 1080a5aa64dd1627904ddbefe686c03135c42026 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:14:48 -0400 Subject: [PATCH 1063/1324] Update homepage.h --- src/qt/homepage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index bb524d61..9acefc23 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -12,7 +12,7 @@ namespace Ui { class HomePage; } -class HomePage : public QMainWindow +class HomePage : public QWidget { Q_OBJECT From 74b0ec75b08ddf647cf8ac0aaa7315f96b35c02e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:15:07 -0400 Subject: [PATCH 1064/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 0e037e21..a996b094 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -3,7 +3,7 @@ #include "newaccount.h" #include "homepage.h" MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), + QWidget(parent), ui(new Ui::MainWindow) { ui->setupUi(this); From d115e9aec5c439c204ec164a06965ff02f652282 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:15:22 -0400 Subject: [PATCH 1065/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index b8b19f9d..303e0cc5 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -7,7 +7,7 @@ namespace Ui { class MainWindow; } -class MainWindow : public QMainWindow +class MainWindow : public QWidget { Q_OBJECT From 0e86c10e23b51f5b69d49ecfc8ba0c5611486631 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:15:40 -0400 Subject: [PATCH 1066/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 292c76b9..999d21b8 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -5,7 +5,7 @@ #include #include newAccount::newAccount(QWidget *parent) : - QMainWindow(parent), + QWidget(parent), ui(new Ui::newAccount) { ui->setupUi(this); From 90c6fc5acd90c569385e0642b27e05951044e37d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:15:53 -0400 Subject: [PATCH 1067/1324] Update newaccount.h --- src/qt/newaccount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index b69d4800..52364985 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -7,7 +7,7 @@ namespace Ui { class newAccount; } -class newAccount : public QMainWindow +class newAccount : public QWidget { Q_OBJECT From 181054e0eafc68ba414f18dacd076f2cee3d93b1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:16:19 -0400 Subject: [PATCH 1068/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index e459fb90..5d00b9ff 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -27,7 +27,7 @@ #include "qprocess.h" ProfilePage::ProfilePage(QWidget *parent) : - QMainWindow(parent), + QWidget(parent), ui(new Ui::ProfilePage) { ui->setupUi(this); From b59e620f3551ca69c3e13140d17f46c68710466d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:16:32 -0400 Subject: [PATCH 1069/1324] Update profilepage.h --- src/qt/profilepage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index a480b3dd..c1fcc08d 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -9,7 +9,7 @@ namespace Ui { class ProfilePage; } -class ProfilePage : public QMainWindow +class ProfilePage : public QWidget { Q_OBJECT From b4f276a01735ff270fb8071b6dba1fd88dbc605d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:19:20 -0400 Subject: [PATCH 1070/1324] Update adminwindow.cpp --- src/qt/adminwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp index 1e5ef6b3..0a8e4f58 100644 --- a/src/qt/adminwindow.cpp +++ b/src/qt/adminwindow.cpp @@ -3,7 +3,7 @@ #include "statistics.h" #include "fileman.h" AdminWindow::AdminWindow(QWidget *parent) : - QWidget(parent), + QMainWindow(parent), ui(new Ui::AdminWindow) { ui->setupUi(this); From 6f40c9e0e51e57c55ab721d300252a8831ff956f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:19:35 -0400 Subject: [PATCH 1071/1324] Update adminwindow.h --- src/qt/adminwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h index 0c5cc3dd..3fb32a8a 100644 --- a/src/qt/adminwindow.h +++ b/src/qt/adminwindow.h @@ -7,7 +7,7 @@ namespace Ui { class AdminWindow; } -class AdminWindow : public QWidget +class AdminWindow : public QMainWindow { Q_OBJECT From 8b2b1b604129b89cd09011100cbbb9ad635ef19a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:19:54 -0400 Subject: [PATCH 1072/1324] Update homepage.cpp --- src/qt/homepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp index 4535702c..25589410 100644 --- a/src/qt/homepage.cpp +++ b/src/qt/homepage.cpp @@ -26,7 +26,7 @@ #define POSTSATATIME 15 //_____ HomePage::HomePage(QWidget *parent) : - QWidget(parent), + QMainWindow(parent), ui(new Ui::HomePage) { ui->setupUi(this); From 8eeb0577c2fb44df5802a75af2a043586e196b1a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:20:09 -0400 Subject: [PATCH 1073/1324] Update homepage.h --- src/qt/homepage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/homepage.h b/src/qt/homepage.h index 9acefc23..bb524d61 100644 --- a/src/qt/homepage.h +++ b/src/qt/homepage.h @@ -12,7 +12,7 @@ namespace Ui { class HomePage; } -class HomePage : public QWidget +class HomePage : public QMainWindow { Q_OBJECT From 42965d707a185883c241189a8bd749f45d6fec41 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:20:32 -0400 Subject: [PATCH 1074/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index a996b094..0e037e21 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -3,7 +3,7 @@ #include "newaccount.h" #include "homepage.h" MainWindow::MainWindow(QWidget *parent) : - QWidget(parent), + QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); From 4c63075e20ef93962bd4b61707cad447da0d118c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:21:20 -0400 Subject: [PATCH 1075/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index 303e0cc5..b8b19f9d 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -7,7 +7,7 @@ namespace Ui { class MainWindow; } -class MainWindow : public QWidget +class MainWindow : public QMainWindow { Q_OBJECT From 45bd3a23769c66f16bc101118edf3dbdc8fa1a5e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:21:32 -0400 Subject: [PATCH 1076/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 999d21b8..292c76b9 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -5,7 +5,7 @@ #include #include newAccount::newAccount(QWidget *parent) : - QWidget(parent), + QMainWindow(parent), ui(new Ui::newAccount) { ui->setupUi(this); From b49f9ff79eed4f78651d180d5f861ef9318f1e55 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:21:45 -0400 Subject: [PATCH 1077/1324] Update newaccount.h --- src/qt/newaccount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index 52364985..b69d4800 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -7,7 +7,7 @@ namespace Ui { class newAccount; } -class newAccount : public QWidget +class newAccount : public QMainWindow { Q_OBJECT From 3b081398c561891093d706fac95b01a6a836faf5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:22:03 -0400 Subject: [PATCH 1078/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 5d00b9ff..e459fb90 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -27,7 +27,7 @@ #include "qprocess.h" ProfilePage::ProfilePage(QWidget *parent) : - QWidget(parent), + QMainWindow(parent), ui(new Ui::ProfilePage) { ui->setupUi(this); From 74bb95ada40aecdd02f97a573a4da4f544fc1ea0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:22:18 -0400 Subject: [PATCH 1079/1324] Update profilepage.h --- src/qt/profilepage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index c1fcc08d..a480b3dd 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -9,7 +9,7 @@ namespace Ui { class ProfilePage; } -class ProfilePage : public QWidget +class ProfilePage : public QMainWindow { Q_OBJECT From 2ed0ffe2441e7f96fb082bfec7683c5d84793123 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:22:47 -0400 Subject: [PATCH 1080/1324] Update adminwindow.ui --- src/qt/forms/adminwindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui index 51fa3ceb..4eb710bd 100644 --- a/src/qt/forms/adminwindow.ui +++ b/src/qt/forms/adminwindow.ui @@ -1,7 +1,7 @@ AdminWindow - + 0 From b852e965230a7bb648f6a2967517022607889704 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:23:00 -0400 Subject: [PATCH 1081/1324] Update homepage.ui --- src/qt/forms/homepage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui index 81781281..0d3cdb97 100644 --- a/src/qt/forms/homepage.ui +++ b/src/qt/forms/homepage.ui @@ -1,7 +1,7 @@ HomePage - + 0 From 651b370e8bd8061140d6419aa38bdd57648482b7 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:23:13 -0400 Subject: [PATCH 1082/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index a90c738f..f9070099 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -1,7 +1,7 @@ MainWindow - + 0 From 9dc40f490a4880355c321fdb9eb4c38080a78bd5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:23:27 -0400 Subject: [PATCH 1083/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index b7d052f1..dd87603b 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -1,7 +1,7 @@ newAccount - + 0 From 79162fb2ddb10c5d6a5404636bc63298d65a88f9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:23:38 -0400 Subject: [PATCH 1084/1324] Update profilepage.ui --- src/qt/forms/profilepage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui index 87fc0cd5..8114320a 100644 --- a/src/qt/forms/profilepage.ui +++ b/src/qt/forms/profilepage.ui @@ -1,7 +1,7 @@ ProfilePage - + 0 From 1ee67bc83808e945020ffee398ff7bd04f59882e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:27:21 -0400 Subject: [PATCH 1085/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 292c76b9..4c83e4a6 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -37,7 +37,7 @@ void newAccount::on_pushButton_clicked() MainWindow* newWindow= new MainWindow(id); newWindow->show(); this->hide(); -// temp.userFileManipulator.updateActivity(mail,0,0); + temp.userFileManipulator.updateActivity(mail,0,0); } } From 317883a76e40621f07c519ab5922419ec7c7dcaa Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:27:40 -0400 Subject: [PATCH 1086/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 0e037e21..fb87f933 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -16,14 +16,14 @@ MainWindow::~MainWindow() delete ui; } -/*void MainWindow::on_signUpButton_clicked() +void MainWindow::on_signUpButton_clicked() { newAccount *newAccountWindow = new newAccount; newAccountWindow->show(); this->hide(); newAccountWindow->setLoginPtr(this); -} */ +} void MainWindow::on_logInButton_clicked() { From efc9755e5ef148ef80de3a5a9dbd5f49b8210d37 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:28:07 -0400 Subject: [PATCH 1087/1324] Update mainwindow.h --- src/qt/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index b8b19f9d..fb256a1d 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow ~MainWindow(); private Q_SLOTS: -/* void on_signUpButton_clicked(); */ + void on_signUpButton_clicked(); void on_logInButton_clicked(); From e791719618e11aa831c39f0a340cb51e06e95e03 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:33:57 -0400 Subject: [PATCH 1088/1324] Update newaccount.h --- src/qt/newaccount.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index b69d4800..6ea168e4 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -14,22 +14,16 @@ class newAccount : public QMainWindow public: explicit newAccount(QWidget *parent = 0); ~newAccount(); - int id; - -public Q_SLOTS: +public slots: void setLoginPtr(MainWindow *ptr); - - -private Q_SLOTS: +private slots: void on_pushButton_clicked(); void on_pushButton_2_clicked(); - private: Ui::newAccount *ui; - MainWindow *mainWindowPtr; }; From b1232f28b976e9b2a9bb72e7f7ab6113865e0930 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:34:26 -0400 Subject: [PATCH 1089/1324] Update newaccount.cpp --- src/qt/newaccount.cpp | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp index 4c83e4a6..b5876f88 100644 --- a/src/qt/newaccount.cpp +++ b/src/qt/newaccount.cpp @@ -1,19 +1,11 @@ #include "newaccount.h" #include "ui_newaccount.h" -#include -#include -#include -#include +#include "QMessageBox" newAccount::newAccount(QWidget *parent) : QMainWindow(parent), ui(new Ui::newAccount) { ui->setupUi(this); - user check; - id=check.getUsersSize(); - QWidget::setWindowIcon(QIcon(":/icons/chat.png")); - this->setWindowTitle("Social Network"); - } newAccount::~newAccount() @@ -25,21 +17,10 @@ void newAccount::on_pushButton_clicked() { QString password =ui->lineEdit_2->text(); QString confirm =ui->lineEdit_3->text(); - QString mail=ui->txtUserMail->text(); if(password!=confirm) { QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); } - else - { - user temp (password,mail,ui->txtUserName->text(),id); - temp.setUsersList(temp); - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - this->hide(); - temp.userFileManipulator.updateActivity(mail,0,0); - } - } void newAccount::setLoginPtr(MainWindow *ptr) @@ -49,9 +30,6 @@ void newAccount::setLoginPtr(MainWindow *ptr) void newAccount::on_pushButton_2_clicked() { - MainWindow* newWindow= new MainWindow(id); - newWindow->show(); - // mainWindowPtr->show(); + mainWindowPtr->show(); this->hide(); - } From ad0910c17de33f1b40e2d2f00059d3fd9d1ff159 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:34:47 -0400 Subject: [PATCH 1090/1324] Update newaccount.ui --- src/qt/forms/newaccount.ui | 340 +++++++++++++++++++------------------ 1 file changed, 174 insertions(+), 166 deletions(-) diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui index dd87603b..1103a2c9 100644 --- a/src/qt/forms/newaccount.ui +++ b/src/qt/forms/newaccount.ui @@ -6,184 +6,192 @@ 0 0 - 532 - 312 + 800 + 600 MainWindow - - - - - - - - - - Times New Roman - 16 - 75 - true - - - - If You Already Have An Account ---> - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign In - - - - - - - - - - - - - - - - Times New Roman - 14 - 75 - true - - - - User Name - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Email - - - txtUserMail - - - - - - - - Times New Roman - 14 - 75 - true - - - - Password - - - lineEdit_2 - - - - - - - - Times New Roman - 14 - 75 - true - - - - Confirm Password - - - lineEdit_3 - - - - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - QLineEdit::Password - - - - - - - - - - - - Times New Roman - 11 - 75 - true - - - - Sign Up - - - - - - - - + + + + 250 + 290 + 161 + 20 + + + + QLineEdit::Password + + + + + + 70 + 320 + 151 + 20 + + + + + Times New Roman + 14 + 75 + true + + + + confirm password + + + lineEdit_3 + + + + + + 610 + 280 + 81 + 31 + + + + + Times New Roman + 11 + 75 + true + + + + Sign Up + + + + + + 250 + 320 + 161 + 20 + + + + QLineEdit::Password + + + + + + 90 + 290 + 101 + 16 + + + + + Times New Roman + 14 + 75 + true + + + + password + + + lineEdit_2 + + + + + + 500 + 80 + 121 + 31 + + + + + Times New Roman + 11 + 75 + true + + + + Sign In + + + + + + 100 + 260 + 61 + 16 + + + + + Times New Roman + 14 + 75 + true + + + + Email + + + lineEdit + + + + + + 250 + 260 + 161 + 20 + + + + + + + 110 + 130 + 321 + 20 + + + + + Times New Roman + 16 + 75 + true + + + + if you already have an account ---> + + 0 0 - 532 + 800 26 From 73ba46498788f1e557bff04677569ce802221f86 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:36:17 -0400 Subject: [PATCH 1091/1324] Update newaccount.h --- src/qt/newaccount.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h index 6ea168e4..f9b779a7 100644 --- a/src/qt/newaccount.h +++ b/src/qt/newaccount.h @@ -15,9 +15,9 @@ class newAccount : public QMainWindow explicit newAccount(QWidget *parent = 0); ~newAccount(); -public slots: +public Q_SLOTS: void setLoginPtr(MainWindow *ptr); -private slots: +private Q_SLOTS: void on_pushButton_clicked(); void on_pushButton_2_clicked(); From 3a3ef649f1d5e15393212a75460e89cbf12eb209 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:41:47 -0400 Subject: [PATCH 1092/1324] Update addcomment.cpp --- src/qt/addcomment.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp index 0fef6054..0c0cae86 100644 --- a/src/qt/addcomment.cpp +++ b/src/qt/addcomment.cpp @@ -7,7 +7,6 @@ AddComment::AddComment(QWidget *parent) : { ui->setupUi(this); commentBody = ""; - QWidget::setWindowIcon(QIcon(":/icons/chat.png")); } AddComment::~AddComment() From 98993b8ebcd85849a9a8d6af28c2ea8ec39d1f67 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:42:12 -0400 Subject: [PATCH 1093/1324] Update addcomment.h --- src/qt/addcomment.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h index 78fc9e25..a6adb04b 100644 --- a/src/qt/addcomment.h +++ b/src/qt/addcomment.h @@ -13,20 +13,15 @@ class AddComment : public QDialog public: explicit AddComment(QWidget *parent = 0); - ~AddComment(); -public Q_SLOTS: +public slots: QString getCommentBody(); - - -private Q_SLOTS: +private slots: void on_AddComment_accepted(); - private: Ui::AddComment *ui; - QString commentBody; }; From 802ea62ec1ad8bb8f51a3af69761bb8fb7c6d5d8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:44:22 -0400 Subject: [PATCH 1094/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index fb87f933..a10b6857 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newaccount.h" +#include "newAccount.h" #include "homepage.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), From 195249748d7cd1cb09a7f0d0cebe2aa5b7a37873 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:44:59 -0400 Subject: [PATCH 1095/1324] Update mainwindow.h --- src/qt/mainwindow.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h index fb256a1d..eae1a7ce 100644 --- a/src/qt/mainwindow.h +++ b/src/qt/mainwindow.h @@ -12,13 +12,11 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - MainWindow(int userID ); - int id; + explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private Q_SLOTS: - void on_signUpButton_clicked(); + void on_signUpButton_clicked(); void on_logInButton_clicked(); From 63286508798b90ff098f2270aef342dee995aea2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:45:12 -0400 Subject: [PATCH 1096/1324] Update mainwindow.cpp --- src/qt/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index a10b6857..fb87f933 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "newAccount.h" +#include "newaccount.h" #include "homepage.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), From 39bdb2c1c7a981db6ca269b7413c0eb52afbbfb8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:45:35 -0400 Subject: [PATCH 1097/1324] Update mainwindow.ui --- src/qt/forms/mainwindow.ui | 202 ++++++++++++++++++++----------------- 1 file changed, 108 insertions(+), 94 deletions(-) diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui index f9070099..bf97769c 100644 --- a/src/qt/forms/mainwindow.ui +++ b/src/qt/forms/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 464 - 319 + 767 + 534 @@ -429,104 +429,118 @@ MainWindow - - - - - - - - - No account? Create one! - - - - - - - PointingHandCursor - - - Sign Up - - - - - - - - - - - - - - - - 10 - 75 - true - - - - Email - - - - - - - - 10 - 75 - true - - - - Password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - PointingHandCursor - - - Log In - - - - - - - - + + + + 330 + 60 + 101 + 31 + + + + PointingHandCursor + + + Sign Up + + + + + + 150 + 220 + 91 + 31 + + + + PointingHandCursor + + + Log In + + + + + + 170 + 130 + 171 + 21 + + + + + + + 170 + 170 + 171 + 21 + + + + + + + 20 + 130 + 121 + 21 + + + + + 10 + 75 + true + + + + Username + + + + + + 20 + 170 + 131 + 16 + + + + + 10 + 75 + true + + + + Password + + + + + + 320 + 30 + 141 + 21 + + + + No account? Create one! + + 0 0 - 464 + 767 26 From fad43ecb70b592b900c470122497ef0be0d2c672 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:47:08 -0400 Subject: [PATCH 1098/1324] Update addcomment.h --- src/qt/addcomment.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h index a6adb04b..78fc9e25 100644 --- a/src/qt/addcomment.h +++ b/src/qt/addcomment.h @@ -13,15 +13,20 @@ class AddComment : public QDialog public: explicit AddComment(QWidget *parent = 0); + ~AddComment(); -public slots: +public Q_SLOTS: QString getCommentBody(); -private slots: + + +private Q_SLOTS: void on_AddComment_accepted(); + private: Ui::AddComment *ui; + QString commentBody; }; From f84233eb2a733d29a5ee074656adb02155d7d97d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Fri, 19 Jun 2020 23:47:29 -0400 Subject: [PATCH 1099/1324] Update addcomment.cpp --- src/qt/addcomment.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp index 0c0cae86..fde45cd1 100644 --- a/src/qt/addcomment.cpp +++ b/src/qt/addcomment.cpp @@ -7,6 +7,7 @@ AddComment::AddComment(QWidget *parent) : { ui->setupUi(this); commentBody = ""; + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); } AddComment::~AddComment() From decdb6f618fce79e43cc3dc308e04741344686e2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:11:38 -0400 Subject: [PATCH 1100/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 236 ++++++++++------------------------------- 1 file changed, 54 insertions(+), 182 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index e459fb90..97e72ba8 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -5,18 +5,18 @@ //selim includes #include "mainwindow.h" #include "ui_mainwindow.h" -#include -#include -#include -#include -#include +#include "QHBoxLayout" +#include "QVBoxLayout" +#include "QLabel" +#include "QSpacerItem" +#include "QPushButton" #include #include "posts.h" -#include +#include "Qstring" #include -#include -#include -#include +#include "QFontMetrics" +#include "QGroupBox" +#include "QScrollBar" #include "mainwindow.h" #include "addcomment.h" #define POSTSNUMBER 100 @@ -24,7 +24,7 @@ #define POSTSATATIME 15 //_____ -#include "qprocess.h" + ProfilePage::ProfilePage(QWidget *parent) : QMainWindow(parent), @@ -32,26 +32,10 @@ ProfilePage::ProfilePage(QWidget *parent) : { ui->setupUi(this); shownPostsNumber = 0; - //pagePosts = makePosts(); - // viewPosts(); - QWidget::setWindowIcon(QIcon(":/icons/about.png")); - this->showMaximized(); - this->setWindowTitle("Social Network"); + pagePosts = makePosts(); + viewPosts(); } - ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) - { - - ui->setupUi(this); - user A; - // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( - ui->lblMail->setText(email);//user file's name is the email of the user - shownPostsNumber = 0; - qDebug()<<"id is "<userName = homePageOwnerMail; - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); + HomePage* HomePageWindow= new HomePage; this->hide(); -} - + HomePageWindow->show(); -void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) -{ - this->currentSessionUser = currentSessionUser_ptr; - pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); - viewPosts(); - if(homePageOwnerMail != "") - { - fileman x; - QList friendsList = x.getFriends(homePageOwnerMail); - for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) - { - if(*it == currentSessionUser_ptr->userName) - { - ui->addFriendBtn->setEnabled(false); - break; - } - } - } } -//Selim functions + +//selim functions void ProfilePage::viewPosts() { - ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); - ui->lblMail->setText(currentSessionUser->userName); - ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); - QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); - if(homePageOwnerMail == "") - ui->addFriendBtn->setEnabled(false); - int j,k; - for(j = 1; j < friendsList.size() - 1; j = j + 3) - { - ui->friendsComboBox->addItem(friendsList[j]); - } + unsigned int j,k; static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; qDebug("now"); - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) + for(k = shownPostsNumber; shownPostsNumber < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; shownPostsNumber++) { QGroupBox *postframe = new QGroupBox; - //postframe->setObjectName("frame"+QString::number(k)); QVBoxLayout *postLayout = new QVBoxLayout; postframe->setLayout(postLayout); postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); - QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); - postLayout->addWidget(postDate); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].owner+":"); + postLayout->addWidget(postOwner); QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber + postBody->setText((*pagePosts)[shownPostsNumber].postBody); QFontMetrics font_metrics(postBody->font()); int font_height = font_metrics.height(); // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added @@ -142,29 +86,13 @@ void ProfilePage::viewPosts() likeAndComment->addWidget(like); likeAndComment->addWidget(comment); postLayout->addLayout(likeAndComment); - std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); - for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) - { - if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) - { - like->setEnabled(false); - break; - } - } - QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) - +" people are liking this!"); - likesOwners->setObjectName("likesOwnersButton"); - connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); - QHBoxLayout *likesOwnersLayout = new QHBoxLayout; - likesOwnersLayout->addWidget(likesOwners); - postLayout->addLayout(likesOwnersLayout); - for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) + for(j = 0; j < (*pagePosts)[shownPostsNumber].postComments.size(); j++) { QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); + QLabel *commentOwner = new QLabel ((*pagePosts)[shownPostsNumber].postComments[j].owner); commentLayout->addWidget(commentOwner); QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); + commentBody->setText((*pagePosts)[shownPostsNumber].postComments[j].commentBody); commentBody->setMinimumHeight(height); commentBody->setMaximumHeight(height); commentLayout->addWidget(commentBody); @@ -183,26 +111,9 @@ void ProfilePage::viewPosts() } void ProfilePage::on_LikeButton_clicked() { - QVBoxLayout *postLayout; QPushButton *button = qobject_cast( QObject::sender() ); - button->setEnabled(false); QString name = button->objectName(); qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - if(homePageOwnerMail == "") - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); - else - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); - int postsNumber,likesNumber; - currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); - currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); - } void ProfilePage::on_CommentButton_clicked() { @@ -216,8 +127,7 @@ void ProfilePage::on_CommentButton_clicked() QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); postLayout = qobject_cast (postframe->layout()); QHBoxLayout *commentLayout = new QHBoxLayout; - QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); - QLabel *commentOwner = new QLabel (commentOwnerName); + QLabel *commentOwner = new QLabel ("manuallyAddedComment"); commentLayout->addWidget(commentOwner); QTextBrowser *commentBodyTextBrowser = new QTextBrowser; commentBodyTextBrowser->setText(commentBody); @@ -229,44 +139,7 @@ void ProfilePage::on_CommentButton_clicked() commentBodyTextBrowser->setMaximumHeight(height); commentLayout->addWidget(commentBodyTextBrowser); postLayout->addLayout(commentLayout); - /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - qDebug(labelString.toLatin1()); - currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) - ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); -} - -void ProfilePage::on_likesOwners_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); - QScrollArea* likesOwners = new QScrollArea; - QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; - likesOwners->setLayout(scrollingAreaLayout); - for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) - { - if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) - { - std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); - for(int i = 0; i < likesVector->size(); i++) - { - QLabel* userLabel = new QLabel((*likesVector)[i]); - scrollingAreaLayout->addWidget(userLabel); - } - } - } - likesOwners->show(); } - void ProfilePage::viewMorePosts(int i) { QScrollBar *bar = qobject_cast (QObject::sender()); @@ -276,39 +149,38 @@ void ProfilePage::viewMorePosts(int i) viewPosts(); } } - - - -void ProfilePage::on_Post_btn_clicked() +std::vector* ProfilePage::makePosts() { - QString postText = ui->newPost_txtEdit->toPlainText(); -// currentSessionUser.userFileManipulator.addPost(postText); - Date Now; - Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); - pagePosts->push_front(recentlyAddedPost); - shownPostsNumber = 0; - // clear the post area - //ui->PostsArea-> - viewPosts(); - currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); + unsigned int i,j; + std::vector *testPosts= new std::vector; + for(i = 0; i < POSTSNUMBER; i++) + { + QString postOwner = "Owner" + QString::number(i); + QString postBody = "this is Post number" + QString::number(i)+"\n"+ + "Again, This is Post number" + QString::number(i)+"\n"+ + "Again, This is Post number" + QString::number(i)+"\n"+ + "Again, This is Post number" + QString::number(i)+"\n"+ + "Again, This is Post number" + QString::number(i); + std::vector postComments; + for(j = 0; j < COMMENTSNUMBER; j++) + { + Comment postComment; + postComment.owner = "Owner" + QString::number(i); + postComment.commentBody = "this is Comment number" + QString::number(i)+"\n"+ + "Again, This is Comment number" + QString::number(i)+"\n"+ + "Again, This is Comment number" + QString::number(i)+"\n"+ + "Again, This is Comment number" + QString::number(i)+"\n"+ + "Again, This is Comment number" + QString::number(i); + postComments.push_back(postComment); + } + Post tempPost = {postOwner,postBody,postComments}; + testPosts->push_back(tempPost); + } + return testPosts; } -void ProfilePage::setHomePageOwnerMail(QString owner) -{ - homePageOwnerMail = owner; - ui->newPost_txtEdit->setVisible(false); - ui->Post_btn->setVisible(false); -} +//___ -void ProfilePage::on_addFriendBtn_clicked() -{ - currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); - ui->addFriendBtn->setEnabled(false); -} -void ProfilePage::on_actionLog_out_triggered() -{ - qApp->quit(); - QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); -} +///////------- end of selim's functions From 21f80ca396f73866ceb1ba92b6c6c3441f22f324 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:12:18 -0400 Subject: [PATCH 1101/1324] Update profilepage.h --- src/qt/profilepage.h | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index a480b3dd..df139e89 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -3,8 +3,6 @@ #include #include "posts.h" -#include "user.h" -#include "homepage.h" namespace Ui { class ProfilePage; } @@ -15,47 +13,20 @@ class ProfilePage : public QMainWindow public: explicit ProfilePage(QWidget *parent = 0); - ~ProfilePage(); - ProfilePage(int userID,QString userFile); - private Q_SLOTS: void on_pushButton_2_clicked(); - void viewPosts(); - + std::vector* makePosts(); void on_LikeButton_clicked(); - void viewMorePosts(int i); - void on_CommentButton_clicked(); - void on_addFriendBtn_clicked(); - - void on_actionLog_out_triggered(); - - -public Q_SLOTS: - void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); - - void on_Post_btn_clicked(); - - void setHomePageOwnerMail(QString owner); - - void on_likesOwners_clicked(); - - private: Ui::ProfilePage *ui; - unsigned int shownPostsNumber; - - QList *pagePosts; - - user *currentSessionUser; - - QString homePageOwnerMail; + std::vector *pagePosts; }; #endif // PROFILEPAGE_H From 36ec749319f7e081fa389801c827e9132a09db31 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:13:34 -0400 Subject: [PATCH 1102/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 97e72ba8..82e70fd8 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -12,7 +12,7 @@ #include "QPushButton" #include #include "posts.h" -#include "Qstring" +#include #include #include "QFontMetrics" #include "QGroupBox" From 37f41d04994ca4f222f67a8977421c36dc2823d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:14:18 -0400 Subject: [PATCH 1103/1324] Update profilepage.ui --- src/qt/forms/profilepage.ui | 485 +++++++++++++++++++----------------- 1 file changed, 263 insertions(+), 222 deletions(-) diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui index 8114320a..6307744d 100644 --- a/src/qt/forms/profilepage.ui +++ b/src/qt/forms/profilepage.ui @@ -14,232 +14,286 @@ MainWindow - - - - - - - - - - Arial - 15 - 75 - true - - - - User name label Area - - - - - - - Add as a friend - - - - - - - - - - - - Arial - 9 - 75 - true - - + + + + 0 + 0 + 1001 + 541 + + + + + + + + Arial + 15 + 75 + true + + + + User name label Area + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Arial + 9 + 75 + true + + + + Home + + + + + + + + Arial + 9 + 75 + true + + + + Friends + + + 8 + + - Home - - - - - - - - Arial - 9 - 75 - true - - - Friends - - 8 - - + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Arial + 12 + 75 + true + + + + INFO + + + + + + + + + + Arial + 9 + + - Friends + From - - - - - - - - - - - - Arial - 12 - 75 - true - - - - INFO - - - - - - - - - - - - - Arial - 9 - - - - Email - - - - - - - lblMail - - - - - - - - - - - - Arial - 9 - - - - Number of friends - - - - - - - labelNumber - - - - - - - - - - - border-color:blue; + + + + + + labelAddress + + + + + + + + + + + + Arial + 9 + + + + Number of friends + + + + + + + labelNumber + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + border-color:blue; + + + true + + + + + 0 + 0 + 997 + 261 + - - true - - + 0 0 - 982 - 349 + 1001 + 61 - - - - - - 16777215 - 100 - - - - - - - What's on your mind? - - - - - - - - Arial - 9 - 75 - true - - - - false - - - background-color: rgb(85, 0, 255); + + + + + What's on your mind? + + + + + + 800 + 60 + 201 + 23 + + + + + Arial + 9 + 75 + true + + + + false + + + background-color: rgb(85, 0, 255); color:white; selection-color: rgb(255, 255, 255); - - - Post - - - - - - - true - - - - - 0 - 0 - 958 - 183 - - - - - - + + + Post + + + + + + 9 + 96 + 991 + 161 + + + + true + + + + + 0 + 0 + 989 + 159 + + + - - - - - - - + + + + + + + @@ -250,21 +304,8 @@ selection-color: rgb(255, 255, 255); 26 - - - File - - - - - - - - Log out - - From ff2058ac90f7e6ae6b33ae8293ec98b8ee8cad1b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:15:52 -0400 Subject: [PATCH 1104/1324] Update profilepage.ui --- src/qt/forms/profilepage.ui | 485 +++++++++++++++++------------------- 1 file changed, 222 insertions(+), 263 deletions(-) diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui index 6307744d..8114320a 100644 --- a/src/qt/forms/profilepage.ui +++ b/src/qt/forms/profilepage.ui @@ -14,286 +14,232 @@ MainWindow - - - - 0 - 0 - 1001 - 541 - - - - - - - - Arial - 15 - 75 - true - - - - User name label Area - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Arial - 9 - 75 - true - - - - Home - - - - - - - - Arial - 9 - 75 - true - - - - Friends - - - 8 - - + + + + + + + + + + Arial + 15 + 75 + true + + + User name label Area + + + + + + + Add as a friend + + + + + + + + + + + + Arial + 9 + 75 + true + + + + Home + + + + + + + + Arial + 9 + 75 + true + + + Friends - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Arial - 12 - 75 - true - - - - INFO - - - - - - - - - - Arial - 9 - - - - From - - - - - - - labelAddress - - - - - - - - - - - - Arial - 9 - - - - Number of friends - - - - - + + 8 + + - labelNumber + Friends - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - border-color:blue; + + + + + + + + + + + + Arial + 12 + 75 + true + + + + INFO + + + + + + + + + + + + + Arial + 9 + + + + Email + + + + + + + lblMail + + + + + + + + + + + + Arial + 9 + + + + Number of friends + + + + + + + labelNumber + + + + + + + + + + + border-color:blue; - - - true - - - - - 0 - 0 - 997 - 261 - - + + true + + 0 0 - 1001 - 61 + 982 + 349 - - - - - What's on your mind? - - - - - - 800 - 60 - 201 - 23 - - - - - Arial - 9 - 75 - true - - - - false - - - background-color: rgb(85, 0, 255); + + + + + + 16777215 + 100 + + + + + + + What's on your mind? + + + + + + + + Arial + 9 + 75 + true + + + + false + + + background-color: rgb(85, 0, 255); color:white; selection-color: rgb(255, 255, 255); - - - Post - - - - - - 9 - 96 - 991 - 161 - - - - true - - - - - 0 - 0 - 989 - 159 - - - + + + Post + + + + + + + true + + + + + 0 + 0 + 958 + 183 + + + + + + - - - - - - - + + + + + + + @@ -304,8 +250,21 @@ selection-color: rgb(255, 255, 255); 26 + + + File + + + + + + + + Log out + + From 9cc61c32a84c15431023629dd2883cf88da51d64 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:16:56 -0400 Subject: [PATCH 1105/1324] Update profilepage.cpp --- src/qt/profilepage.cpp | 220 ++++++++++++++++++++++++++++++++--------- 1 file changed, 174 insertions(+), 46 deletions(-) diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp index 82e70fd8..cc8ac1a0 100644 --- a/src/qt/profilepage.cpp +++ b/src/qt/profilepage.cpp @@ -12,7 +12,7 @@ #include "QPushButton" #include #include "posts.h" -#include +#include "QString" #include #include "QFontMetrics" #include "QGroupBox" @@ -24,7 +24,7 @@ #define POSTSATATIME 15 //_____ - +#include "qprocess.h" ProfilePage::ProfilePage(QWidget *parent) : QMainWindow(parent), @@ -32,10 +32,26 @@ ProfilePage::ProfilePage(QWidget *parent) : { ui->setupUi(this); shownPostsNumber = 0; - pagePosts = makePosts(); - viewPosts(); + //pagePosts = makePosts(); + // viewPosts(); + QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); + this->showMaximized(); + this->setWindowTitle("Social Network"); } + ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) + { + + ui->setupUi(this); + user A; + // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( + ui->lblMail->setText(email);//user file's name is the email of the user + shownPostsNumber = 0; + qDebug()<<"id is "<userName = homePageOwnerMail; + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + HomePage *homePageWindow = new HomePage(); + homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); + homePageWindow->show(); this->hide(); - HomePageWindow->show(); - } -//selim functions +void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) +{ + this->currentSessionUser = currentSessionUser_ptr; + pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); + viewPosts(); + if(homePageOwnerMail != "") + { + fileman x; + QList friendsList = x.getFriends(homePageOwnerMail); + for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) + { + if(*it == currentSessionUser_ptr->userName) + { + ui->addFriendBtn->setEnabled(false); + break; + } + } + } +} + +//Selim functions void ProfilePage::viewPosts() { - unsigned int j,k; + ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); + ui->lblMail->setText(currentSessionUser->userName); + ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); + QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); + if(homePageOwnerMail == "") + ui->addFriendBtn->setEnabled(false); + int j,k; + for(j = 1; j < friendsList.size() - 1; j = j + 3) + { + ui->friendsComboBox->addItem(friendsList[j]); + } static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; qDebug("now"); - for(k = shownPostsNumber; shownPostsNumber < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; shownPostsNumber++) + QList oldPosts = ui->scrollAreaWidgetContents->children(); + for(int i = 1; i < oldPosts.size(); i++) + delete oldPosts[i]; + for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) { QGroupBox *postframe = new QGroupBox; + //postframe->setObjectName("frame"+QString::number(k)); QVBoxLayout *postLayout = new QVBoxLayout; postframe->setLayout(postLayout); postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].owner+":"); - postLayout->addWidget(postOwner); + QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); + QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); + postLayout->addWidget(postDate); QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[shownPostsNumber].postBody); + postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber QFontMetrics font_metrics(postBody->font()); int font_height = font_metrics.height(); // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added @@ -86,13 +142,29 @@ void ProfilePage::viewPosts() likeAndComment->addWidget(like); likeAndComment->addWidget(comment); postLayout->addLayout(likeAndComment); - for(j = 0; j < (*pagePosts)[shownPostsNumber].postComments.size(); j++) + std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); + for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) + { + if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) + { + like->setEnabled(false); + break; + } + } + QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) + +" people are liking this!"); + likesOwners->setObjectName("likesOwnersButton"); + connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); + QHBoxLayout *likesOwnersLayout = new QHBoxLayout; + likesOwnersLayout->addWidget(likesOwners); + postLayout->addLayout(likesOwnersLayout); + for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) { QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*pagePosts)[shownPostsNumber].postComments[j].owner); + QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); commentLayout->addWidget(commentOwner); QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*pagePosts)[shownPostsNumber].postComments[j].commentBody); + commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); commentBody->setMinimumHeight(height); commentBody->setMaximumHeight(height); commentLayout->addWidget(commentBody); @@ -111,9 +183,26 @@ void ProfilePage::viewPosts() } void ProfilePage::on_LikeButton_clicked() { + QVBoxLayout *postLayout; QPushButton *button = qobject_cast( QObject::sender() ); + button->setEnabled(false); QString name = button->objectName(); qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + if(homePageOwnerMail == "") + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); + else + currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), + labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); + int postsNumber,likesNumber; + currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); + currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); + } void ProfilePage::on_CommentButton_clicked() { @@ -127,7 +216,8 @@ void ProfilePage::on_CommentButton_clicked() QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); postLayout = qobject_cast (postframe->layout()); QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ("manuallyAddedComment"); + QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); + QLabel *commentOwner = new QLabel (commentOwnerName); commentLayout->addWidget(commentOwner); QTextBrowser *commentBodyTextBrowser = new QTextBrowser; commentBodyTextBrowser->setText(commentBody); @@ -139,7 +229,44 @@ void ProfilePage::on_CommentButton_clicked() commentBodyTextBrowser->setMaximumHeight(height); commentLayout->addWidget(commentBodyTextBrowser); postLayout->addLayout(commentLayout); + /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + qDebug(labelString.toLatin1()); + currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) + ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); +} + +void ProfilePage::on_likesOwners_clicked() +{ + QVBoxLayout *postLayout; + QPushButton *button = qobject_cast( QObject::sender() ); + QString name = button->objectName(); + qDebug(name.toLatin1()); + QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); + postLayout = qobject_cast (postframe->layout()); + QObject* labelObject = (postframe->children()[1]); + QLabel* commentLabel = qobject_cast (labelObject); + QString labelString = commentLabel->text(); + QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); + QScrollArea* likesOwners = new QScrollArea; + QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; + likesOwners->setLayout(scrollingAreaLayout); + for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) + { + if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) + { + std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); + for(int i = 0; i < likesVector->size(); i++) + { + QLabel* userLabel = new QLabel((*likesVector)[i]); + scrollingAreaLayout->addWidget(userLabel); + } + } + } + likesOwners->show(); } + void ProfilePage::viewMorePosts(int i) { QScrollBar *bar = qobject_cast (QObject::sender()); @@ -149,38 +276,39 @@ void ProfilePage::viewMorePosts(int i) viewPosts(); } } -std::vector* ProfilePage::makePosts() + + + +void ProfilePage::on_Post_btn_clicked() { - unsigned int i,j; - std::vector *testPosts= new std::vector; - for(i = 0; i < POSTSNUMBER; i++) - { - QString postOwner = "Owner" + QString::number(i); - QString postBody = "this is Post number" + QString::number(i)+"\n"+ - "Again, This is Post number" + QString::number(i)+"\n"+ - "Again, This is Post number" + QString::number(i)+"\n"+ - "Again, This is Post number" + QString::number(i)+"\n"+ - "Again, This is Post number" + QString::number(i); - std::vector postComments; - for(j = 0; j < COMMENTSNUMBER; j++) - { - Comment postComment; - postComment.owner = "Owner" + QString::number(i); - postComment.commentBody = "this is Comment number" + QString::number(i)+"\n"+ - "Again, This is Comment number" + QString::number(i)+"\n"+ - "Again, This is Comment number" + QString::number(i)+"\n"+ - "Again, This is Comment number" + QString::number(i)+"\n"+ - "Again, This is Comment number" + QString::number(i); - postComments.push_back(postComment); - } - Post tempPost = {postOwner,postBody,postComments}; - testPosts->push_back(tempPost); - } - return testPosts; + QString postText = ui->newPost_txtEdit->toPlainText(); +// currentSessionUser.userFileManipulator.addPost(postText); + Date Now; + Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); + pagePosts->push_front(recentlyAddedPost); + shownPostsNumber = 0; + // clear the post area + //ui->PostsArea-> + viewPosts(); + currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); } -//___ +void ProfilePage::setHomePageOwnerMail(QString owner) +{ + homePageOwnerMail = owner; + ui->newPost_txtEdit->setVisible(false); + ui->Post_btn->setVisible(false); +} +void ProfilePage::on_addFriendBtn_clicked() +{ + currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); + ui->addFriendBtn->setEnabled(false); +} -///////------- end of selim's functions +void ProfilePage::on_actionLog_out_triggered() +{ + qApp->quit(); + QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); +} From 2ccbde0f76a0e579a0ada2379c0b591149ba2278 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:17:34 -0400 Subject: [PATCH 1106/1324] Update profilepage.h --- src/qt/profilepage.h | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h index df139e89..a480b3dd 100644 --- a/src/qt/profilepage.h +++ b/src/qt/profilepage.h @@ -3,6 +3,8 @@ #include #include "posts.h" +#include "user.h" +#include "homepage.h" namespace Ui { class ProfilePage; } @@ -13,20 +15,47 @@ class ProfilePage : public QMainWindow public: explicit ProfilePage(QWidget *parent = 0); + ~ProfilePage(); + ProfilePage(int userID,QString userFile); + private Q_SLOTS: void on_pushButton_2_clicked(); + void viewPosts(); - std::vector* makePosts(); + void on_LikeButton_clicked(); + void viewMorePosts(int i); + void on_CommentButton_clicked(); + void on_addFriendBtn_clicked(); + + void on_actionLog_out_triggered(); + + +public Q_SLOTS: + void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); + + void on_Post_btn_clicked(); + + void setHomePageOwnerMail(QString owner); + + void on_likesOwners_clicked(); + + private: Ui::ProfilePage *ui; + unsigned int shownPostsNumber; - std::vector *pagePosts; + + QList *pagePosts; + + user *currentSessionUser; + + QString homePageOwnerMail; }; #endif // PROFILEPAGE_H From 73d8bbbed931298b3bb9961fb32e6f9594253665 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:26:38 -0400 Subject: [PATCH 1107/1324] Delete profilepage.h --- src/qt/profilepage.h | 61 -------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 src/qt/profilepage.h diff --git a/src/qt/profilepage.h b/src/qt/profilepage.h deleted file mode 100644 index a480b3dd..00000000 --- a/src/qt/profilepage.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef PROFILEPAGE_H -#define PROFILEPAGE_H - -#include -#include "posts.h" -#include "user.h" -#include "homepage.h" -namespace Ui { -class ProfilePage; -} - -class ProfilePage : public QMainWindow -{ - Q_OBJECT - -public: - explicit ProfilePage(QWidget *parent = 0); - - ~ProfilePage(); - - ProfilePage(int userID,QString userFile); - -private Q_SLOTS: - void on_pushButton_2_clicked(); - - void viewPosts(); - - void on_LikeButton_clicked(); - - void viewMorePosts(int i); - - void on_CommentButton_clicked(); - - void on_addFriendBtn_clicked(); - - void on_actionLog_out_triggered(); - - -public Q_SLOTS: - void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); - - void on_Post_btn_clicked(); - - void setHomePageOwnerMail(QString owner); - - void on_likesOwners_clicked(); - - -private: - Ui::ProfilePage *ui; - - unsigned int shownPostsNumber; - - QList *pagePosts; - - user *currentSessionUser; - - QString homePageOwnerMail; -}; - -#endif // PROFILEPAGE_H From d9bd9014ee01c05152c40a041d974c589c0e2fe6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:26:51 -0400 Subject: [PATCH 1108/1324] Delete activity.cpp --- src/qt/activity.cpp | 48 --------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/qt/activity.cpp diff --git a/src/qt/activity.cpp b/src/qt/activity.cpp deleted file mode 100644 index 3d7ef1f8..00000000 --- a/src/qt/activity.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "activity.h" -#include -#include "posts.h" -#include"vector" - - -Activity::Activity() -{ - likesNumbers = 0; - postsNumber = 0; -} - -Activity::~Activity() -{ - -} -unsigned int Activity::getFriendsNumbers() - - {return friends.size();} - -unsigned int Activity::getPostsNumbers() - -{ return postsNumber;} - -void Activity::addFriend(QString friendName) -{ - friends.push_back(friendName); -} - -void Activity::addPost() -{ - postsNumber++; -} - -unsigned int Activity::getLikesNumbers() -{ - return likesNumbers; -} - -void Activity:: addLike() -{ - likesNumbers++; -} - -QList *Activity::getFriendsList_Ptr() -{ - return &friends; -} From e1c599408d716a5e392735242e9013bc900eb2b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:26:57 -0400 Subject: [PATCH 1109/1324] Delete activity.h --- src/qt/activity.h | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/qt/activity.h diff --git a/src/qt/activity.h b/src/qt/activity.h deleted file mode 100644 index 2971b0c9..00000000 --- a/src/qt/activity.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef ACTIVITY_H -#define ACTIVITY_H -#include -#include -#include "vector" -#include "posts.h" -#include -class Activity -{ - unsigned int likesNumbers; - - unsigned int postsNumber; - - QList friends; - - -public: - - Activity(); - - ~Activity(); - - unsigned int getLikesNumbers(); - - unsigned int getFriendsNumbers(); - - unsigned int getPostsNumbers(); - - void addLike(); - - void addFriend(QString); - - void addPost(); - - QList *getFriendsList_Ptr(); -}; - -#endif // ACTIVITY_H From 4a655840b9bc3495425155ae178519cbbfeeb362 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:03 -0400 Subject: [PATCH 1110/1324] Delete addcomment.cpp --- src/qt/addcomment.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/addcomment.cpp diff --git a/src/qt/addcomment.cpp b/src/qt/addcomment.cpp deleted file mode 100644 index fde45cd1..00000000 --- a/src/qt/addcomment.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "addcomment.h" -#include "ui_addcomment.h" - -AddComment::AddComment(QWidget *parent) : - QDialog(parent), - ui(new Ui::AddComment) -{ - ui->setupUi(this); - commentBody = ""; - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); -} - -AddComment::~AddComment() -{ - delete ui; -} - -void AddComment::on_AddComment_accepted() -{ - commentBody = ui->plainTextEdit->toPlainText(); -} - -QString AddComment::getCommentBody() -{ - return commentBody; -} From ab2f22134226b1e59cd22a7507de3e30235d2bb3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:09 -0400 Subject: [PATCH 1111/1324] Delete addcomment.h --- src/qt/addcomment.h | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/qt/addcomment.h diff --git a/src/qt/addcomment.h b/src/qt/addcomment.h deleted file mode 100644 index 78fc9e25..00000000 --- a/src/qt/addcomment.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ADDCOMMENT_H -#define ADDCOMMENT_H - -#include - -namespace Ui { -class AddComment; -} - -class AddComment : public QDialog -{ - Q_OBJECT - -public: - explicit AddComment(QWidget *parent = 0); - - ~AddComment(); - -public Q_SLOTS: - QString getCommentBody(); - - -private Q_SLOTS: - void on_AddComment_accepted(); - - -private: - Ui::AddComment *ui; - - QString commentBody; -}; - -#endif // ADDCOMMENT_H From 66b6936f581f477016ebdf9c6d1ed84144d7fc6b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:17 -0400 Subject: [PATCH 1112/1324] Delete adminwindow.cpp --- src/qt/adminwindow.cpp | 94 ------------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 src/qt/adminwindow.cpp diff --git a/src/qt/adminwindow.cpp b/src/qt/adminwindow.cpp deleted file mode 100644 index 0a8e4f58..00000000 --- a/src/qt/adminwindow.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "adminwindow.h" -#include "ui_adminwindow.h" -#include "statistics.h" -#include "fileman.h" -AdminWindow::AdminWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::AdminWindow) -{ - ui->setupUi(this); - QWidget::setWindowIcon(QIcon(":/icons/about.png")); - this->showMaximized(); - this->setWindowTitle("Social Network"); - -} - -AdminWindow::~AdminWindow() -{ - delete ui; -} - - -void AdminWindow:: makePlot(QVector *plotData) -{ - ui->customPlot->clearGraphs(); - ui->customPlot->legend->setVisible(true); - ui->customPlot->legend->setFont(QFont("Helvetica", 9)); - QPen pen; - QStringList lineNames; - lineNames << "Friends Number" << "Likes Number" << "Posts Number"; - // add graphs with different line styles: - for (int i = 0; i < 3; ++i) - { - ui->customPlot->addGraph(); - if(i == 0) - pen.setColor(QColor(0x02, 0xa0, 0xc3)); - else if(i == 1) - pen.setColor(QColor(0xef, 0xef, 0x00)); - else - pen.setColor(QColor(0xef, 0x2b, 0x90)); - ui->customPlot->graph()->setPen(pen); - ui->customPlot->graph()->setName(lineNames.at(i)); - ui->customPlot->graph()->setLineStyle((QCPGraph::lsLine)); - ui->customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); - // generate data: - QVector x((*plotData).size()), y(1000); - for (int j = 0; j < (*plotData).size(); ++j) - { - x[j] = (*plotData)[j].getUserID(); - if(i == 0) - y[j] = (*plotData)[j].getFriendsNumber(); - else if(i == 1) - y[j] = (*plotData)[j].getLikesNumber(); - else - y[j] = (*plotData)[j].getPostsNumber(); - } - ui->customPlot->graph()->setData(x, y); - ui->customPlot->graph()->rescaleAxes(true); - } - // zoom out a bit: - ui->customPlot->yAxis->scaleRange(0, plotData->size()+1); - ui->customPlot->xAxis->scaleRange(0, 1000); - // set blank axis lines: - ui->customPlot->xAxis->setTicks(true); - ui->customPlot->yAxis->setTicks(true); - ui->customPlot->xAxis->setTickLabels(true); - ui->customPlot->yAxis->setTickLabels(true); - ui->customPlot->xAxis2->setVisible(true); - ui->customPlot->yAxis2->setVisible(true); - ui->customPlot->xAxis2->setTicks(false); - ui->customPlot->yAxis2->setTicks(false); - // make top right axes clones of bottom left axes: -// ui->customPlot->axisRect()->setupFullAxesBox(); - ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); - ui->customPlot->replot(); - - -} -void AdminWindow::on_showStatistics_clicked() -{ - QVector *testingData = new QVector; - fileman network; - QList emails = network.readEmails(); - testingData->resize(emails.size()); - for(int i = 0; i < emails.size(); i++) - { - (*testingData)[i].setUserID(i); - (*testingData)[i].setFriendsNumber(network.getFriends(emails[i]).size() / 3); - int likesNumber,postsNumber; - network.getActivity(emails[i],postsNumber,likesNumber); - (*testingData)[i].setPostsNumber(network.getPosts(emails[i])->size()); - (*testingData)[i].setLikesNumber(likesNumber); - } - makePlot(testingData); -} From d9166fa87c3746e90ee130ba48781255b6b8c09b Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:24 -0400 Subject: [PATCH 1113/1324] Delete adminwindow.h --- src/qt/adminwindow.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/adminwindow.h diff --git a/src/qt/adminwindow.h b/src/qt/adminwindow.h deleted file mode 100644 index 3fb32a8a..00000000 --- a/src/qt/adminwindow.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ADMINWINDOW_H -#define ADMINWINDOW_H - -#include -#include "statistics.h" -namespace Ui { -class AdminWindow; -} - -class AdminWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit AdminWindow(QWidget *parent = 0); - ~AdminWindow(); - -private Q_SLOTS: - void on_showStatistics_clicked(); - - void makePlot(QVector *plotData); -private: - Ui::AdminWindow *ui; -}; - -#endif // ADMINWINDOW_H From 0a0c79fcb38a8519b1f47b668d3aff6d3d7b56dc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:34 -0400 Subject: [PATCH 1114/1324] Delete comment.cpp --- src/qt/comment.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/qt/comment.cpp diff --git a/src/qt/comment.cpp b/src/qt/comment.cpp deleted file mode 100644 index 09328393..00000000 --- a/src/qt/comment.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "comment.h" - -Comment::Comment() -{ - commentOwner = ""; - commentText = ""; -} - -Comment::Comment(QString owner, QString text, QString creationDate) -{ - - commentOwner = owner; - commentText = text; - commentDate = creationDate; -} - -void Comment::setCommentOwner(QString owner) -{ - commentOwner = owner; -} - -QString Comment::getCommentOwner() -{ - return commentOwner; -} - -void Comment::setCommentText(QString text) -{ - commentText = text; -} - -QString Comment::getCommentText() -{ - return commentText; -} - -void Comment::setCommentDate(QString creationDate) -{ - commentDate = creationDate; -} - -QString Comment::getCommentDate() -{ - return commentDate; -} - From 2fc4e52e9a3f9909b269e1d9d187e8bcd27d8146 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:41 -0400 Subject: [PATCH 1115/1324] Delete comment.h --- src/qt/comment.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/qt/comment.h diff --git a/src/qt/comment.h b/src/qt/comment.h deleted file mode 100644 index 0161d3ca..00000000 --- a/src/qt/comment.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef COMMENT_H -#define COMMENT_H - -#include -#include -#include -class Date : public QDate -{ - QTime timeIsNow; -public: - QString getDateNow(){return this->currentDate().toString("yyyy.MM.dd") +" @ " +timeIsNow.currentTime().toString("HH:mm:ss");} -}; -class Comment -{ - QString commentOwner; - QString commentText; - QString commentDate; -public: - Comment(); - - Comment(QString, QString, QString); - - void setCommentOwner(QString); - - QString getCommentOwner(); - - void setCommentText(QString); - - QString getCommentText(); - - void setCommentDate(QString); - - QString getCommentDate(); -}; - -#endif // COMMENT_H From 582d98239ce5677e716ca914094aaa218e8f5c72 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:27:53 -0400 Subject: [PATCH 1116/1324] Delete fileman.cpp --- src/qt/fileman.cpp | 759 --------------------------------------------- 1 file changed, 759 deletions(-) delete mode 100644 src/qt/fileman.cpp diff --git a/src/qt/fileman.cpp b/src/qt/fileman.cpp deleted file mode 100644 index 90d3993b..00000000 --- a/src/qt/fileman.cpp +++ /dev/null @@ -1,759 +0,0 @@ -#include "fileman.h" -#include -#include -#include -#include - -int numberOfUsers=0; -QList emailss; -fileman::fileman() -{ - //name=username; - path=""; - -} -void fileman:: TESTTEST() -{ - QString line; - QFile in(path+name); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YOMNA SAN"; - QTextStream innn(&in); - line=innn.readLine(); - qDebug()<") - { - - line=innn.readLine(); - if(line==Date){ - line=innn.readLine(); - while(line!=NULL){ - - if(line==""){ - line=innn.readLine(); - while(line!="") - { - // cout<* fileman:: getPosts(QString email){ - QString line; - QFile in(path+"Users/"+email+".xml"); - QTextStream innn(&in); - QList *posts = new QList ; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - //bool begin_tag = false; - line=innn.readLine(); - while (line!=NULL) - { - - if(line==""){ - temp=""; - line=innn.readLine(); - while(!(line=="") ) - { - //cout<append(tempPost); - - } - line=innn.readLine(); -} - return posts; -} - - QString fileman:: getUserNameByEmail(QString email) - { - QFile in(path+"Users/"+email+".xml"); - QTextStream f (&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN the file "; - QString line=f.readLine(); - while(1) - { - if(line=="") - { - line=f.readLine(); - // qDebug()<") break; - - - } - - - - } - -void fileman:: createFile( QString passWord,QString email,QString userName,QString date ) -{ - emailss.push_back(email); - numberOfUsers++; - QString newFileStamp="\n"+userName+"\n\n"+"\n"+email+"\n\n\n"+date+"\n\n\n"+passWord+"\n\n\n\n\n0\n\n\n0\n"; - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &file ); - stream << newFileStamp; - } - - addEmail(email); - -} - -void fileman:: addPost(QString userPost, QString Date, QString name) -{ - // QString newPost=readFile("addPost.txt"); - - QFile i(path+name+".txt"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - - - - QFile in(path+"addPost.txt"); - QTextStream innn(&in); - - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString newPost=innn.readAll(); //This file is with norhaaaan doko kana wakaranai - in.close(); - - int indexText= newPost.indexOf(""); //+10 - newPost.insert(indexText+11,userPost); - - int indexDate=newPost.indexOf(""); - newPost.insert(indexDate+11,Date); - indexText= userFile.lastIndexOf(""); - userFile.insert(indexText+8,newPost); - QFile file(path+name+".txt"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} - - -void fileman:: addComment(QString userComment){ - - QString commentStamp="\n\n\n"+userComment+"\n\n\n\n\n"; - //now lets open the user file to insert el bta3 da - - QFile i(path+"addUser.txt"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - //Now we have all the user file content in userFile - int index=userFile.indexOf(""); - userFile.insert(index,commentStamp); - // qDebug()<\n\n"+nameComment+"\n\n\n"; - //now lets open the user file to insert el bta3 da - - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); -//now insert fe el userFile how is that :) - QString copy=userFile; -int from=0; -while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; -QString line="";int j=11; -line=userFile.mid(indexOfPostDate+11,Date.count()); -//userFile.insert(indexOfPostDate+j,commentStamp); - -//qDebug()<\n\n"+userPost+"\n\n"+"\n\n"+""; - - int indexText= userFile.indexOf(""); - userFile.insert(indexText+11,postStamp); - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - // qDebug()<< "couldn't open file"; - - file.close(); - -} -//QList * fileman:: getCommentsByPostDate(QString email,QString date) - -void fileman:: getCommentsByPostDate(QString email,QString date){ - - QString line; - QFile in(path+"Users/"+email+".xml"); - QTextStream inn(&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); -qDebug()< *comments = new QList ; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - - qDebug()<<"COULD NOT OPEN YA BENTY"; - int from=0; - //while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; - //QString line; - int j=11+1+1; - int indexOfCommentTag; - line=userFile.mid(indexOfPostDate+j,date.count()); - //userFile.insert(indexOfPostDate+date.count()+j+11,"hiiiiii i am here"); - // qDebug()<"; - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - int indexOfFriend=userFile.indexOf(""); - userFile.insert(indexOfFriend+9,friendStamp); -QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} -void fileman:: updateActivity(QString email, int numberOfLikes , int numberOfComments){ - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - int indexOfLikes=userFile.indexOf(""); - /* int ii=16; - QChar x=userFile[indexOfLikes+ii]; - - while(x!='\n'){ - userFile[indexOfLikes+ii]='NULL'; - ii++; - x=userFile[indexOfLikes+ii]; - - } -*/ - userFile.insert(indexOfLikes+15,"\n"+QString::number(numberOfLikes)); - int indexOfComments=userFile.indexOf(""); - userFile.insert(indexOfComments+18,"\n"+QString::number(numberOfComments)); - QFile file(path+"Users/"+email+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); -} - - -void fileman:: networkFile(){ - QString newFileStamp="\n"+QString::number(numberOfUsers)+"\n\n"; - QFile file(path+"Users/"+"network"+".xml"); - if ( file.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &file ); - stream << newFileStamp; - } - - -} - -void fileman::addUsers(){ - QFile i(path+"Users/network.xml"); - QTextStream inn(&i); - int id=0; - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - QFile file(path+"Users/network.xml"); - fileman x; - QList emails=x.readEmails(); -for (int k = 0; k \n\n"+QString::number(id)+"\n"; - id++; - int indexText= userFile.indexOf(""); - userFile.insert(indexText+16,emailStamp); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - - } - -} - -void fileman::createEmailFile() -{ - QString stamp="\n"; - QFile f(path+"Users/"+"email"+".xml"); - if ( f.open(QIODevice::WriteOnly | QIODevice::Text) ) - { - QTextStream stream( &f ); - stream << stamp; - } -} -void fileman::addEmail(QString email){ - QFile i(path+"Users/"+"email"+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); - i.close(); - int indexText= userFile.indexOf(""); - userFile.insert(indexText+8,"\n"+email); - QFile file(path+"Users/"+"email"+".xml"); - if ( file.open(QIODevice::ReadWrite) ) - { - QTextStream stream( &file ); - stream << userFile << endl; - } - else - qDebug()<< "couldn't open file"; - - file.close(); - -} -QList fileman:: readEmails(){ - QString line; - QFile in(path+"Users/"+"email"+".xml"); - QTextStream innn(&in); -// QList emails = new QList ; - QList emails; - QString temp=""; - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - line=innn.readLine(); - - if(line==""){ - line=innn.readLine(); - while(1) - { - emails.append(line); - // qDebug()<") break; - - // if(line==NULL) break; - - } - } - - return emails; - -} - -QList fileman:: getFriends(QString email) -{ - QList result; - QFile in(path+"Users/"+email+".xml"); - QTextStream innn(&in); - if(!in.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString line=innn.readLine(); - while(1){ - if(line=="") - { - while(1) - { - line=innn.readLine(); - - if(line=="") break; - result.append(line); - if(line==""||line=="") continue; - //qDebug()<") - { - line=inn.readLine(); - numberOfLikes=line.toInt(); - break; - } - if(line=="") - { - line=inn.readLine(); - numberOfPosts=line.toInt(); - break; - } - line=inn.readLine(); - if(line=="") - break; - - } -} - -QList *fileman::getPosts_new(QString email) -{ - QList *result = new QList; - - - - QFile i(path+"Users\\"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString line=inn.readLine(); - while(1) - { - Post temp; temp.setPostText(""); - if(line=="") - { - line=inn.readLine(); - while(1) - { - - if(line=="") - { - line=inn.readLine(); - temp.setPostDate(line); - // qDebug()<") - { - temp.setPostText(""); - line=inn.readLine(); - while(1) - { - if(line=="") - { - break; - } - temp.setPostText(temp.getPostText()+line); - // qDebug()<") - { - - Comment tempCom; - line=inn.readLine(); - while(1) - { - if(line=="") - { - tempCom.setCommentText(""); - line=inn.readLine(); - while(1) - { - tempCom.setCommentText(tempCom.getCommentText()+line); - line=inn.readLine(); - if(line=="")break; - } - } - if(line=="") - { - tempCom.setCommentOwner(inn.readLine()); - } - line=inn.readLine(); - if(line=="")break; - - } - //qDebug()<") - { - line=inn.readLine(); - while(line!="") - { - if(line=="") break; - if(line==""|| line=="") - { - line=inn.readLine(); - continue; - } - - temp.getPostLikesOwnersVectorPtr()->push_back(line); - - // qDebug()<") - { - fileman x; - temp.setPostOwner(email); - result->append(temp); - break; - } - - } - } - line=inn.readLine(); - if(line=="")break; - } -return result; -} - - - -void fileman ::addLikeByPostDate(QString email, QString Date, QString likePerson) -{ - QString likeStamp="\n\n"+likePerson+"\n"; - QFile i(path+"Users/"+email+".xml"); - QTextStream inn(&i); - if(!i.open(QFile::ReadOnly| QFile::Text)) - qDebug()<<"COULD NOT OPEN YA BENTY"; - QString userFile=inn.readAll(); //This file is with norhaaaan doko kana wakaranai - i.close(); - - int from=0; int k=0; - while(from<=userFile.count()){ - int indexOfPostDate=userFile.indexOf("",from);//qDebug()<<"hiiiiiiiiii"; - QString line="";int j=11; - - line=userFile.mid(indexOfPostDate+11,Date.count()); -// userFile.insert(indexOfPostDate+j,likeStamp); - - //qDebug()<",from); - int likeTagIndex= userFile.indexOf("",from); - - userFile.insert(likeTagIndex+6,likeStamp); - k++; - - qDebug()<") - { - line=f.readLine(); - // qDebug()<") break; - - - } -} From f9de410338007981c1029850c0efd492f500e12c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:00 -0400 Subject: [PATCH 1117/1324] Delete fileman.h --- src/qt/fileman.h | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 src/qt/fileman.h diff --git a/src/qt/fileman.h b/src/qt/fileman.h deleted file mode 100644 index 901e5f57..00000000 --- a/src/qt/fileman.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef FILEMAN_H -#define FILEMAN_H -#include -#include -#include -#include -#include -#include -#include "posts.h" -#include "comment.h" - - -class fileman{ -public: - QString path; - QString name; - QList posts; - - fileman(); - QString getPostByDate(QString Date); - QList * getPosts(QString email); - QString getUserNameByEmail(QString email); - void addPost(QString userPost, QString Date, QString name); - void addComment(QString userComment); - void addCommentByPostDate(QString userComment, QString Date, QString nameComment,QString nameFile); - void createFile( QString passWord,QString email,QString userName,QString date ); - void addFriend (QString friendName, QString name); - void addPost_new(QString userPost, QString Date, QString name); - void getCommentsByPostDate(QString email,QString date); - void addFriends(QString email,QString friendName); - void updateActivity(QString email, int numberOfLikes , int numberOfComments); - friend class user; - void networkFile(); - void addUsers(); - void TESTTEST(); - void createEmailFile(); - void addEmail(QString email); - QList readEmails(); - QList getFriends(QString email); - void getActivity(QString email, int &numberOfPosts, int &numberOfLikes); - QList * getPosts_new(QString email); - -public Q_SLOTS: - void addLikeByPostDate(QString email, QString Date, QString likePerson); - QString getPassword(QString email); -}; - -#endif From 4afb7c66ab0a92939275300289e2031613a6a43e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:07 -0400 Subject: [PATCH 1118/1324] Delete form.cpp --- src/qt/form.cpp | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/qt/form.cpp diff --git a/src/qt/form.cpp b/src/qt/form.cpp deleted file mode 100644 index 20e6af24..00000000 --- a/src/qt/form.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "form.h" -#include "ui_form.h" - -Form::Form(QWidget *parent) : - QWidget(parent), - ui(new Ui::Form) -{ - ui->setupUi(this); -} - -Form::~Form() -{ - delete ui; -} From 4a19000613dec8d1c8e048044825fc5437ab5856 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:18 -0400 Subject: [PATCH 1119/1324] Delete form.h --- src/qt/form.h | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/qt/form.h diff --git a/src/qt/form.h b/src/qt/form.h deleted file mode 100644 index 59d50c60..00000000 --- a/src/qt/form.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FORM_H -#define FORM_H - -#include - -namespace Ui { -class Form; -} - -class Form : public QWidget -{ - Q_OBJECT - -public: - explicit Form(QWidget *parent = 0); - ~Form(); - -private: - Ui::Form *ui; -}; - -#endif // FORM_H From 1f44e62510104b73e512becae951a4390b92fbdc Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:27 -0400 Subject: [PATCH 1120/1324] Delete homepage.cpp --- src/qt/homepage.cpp | 441 -------------------------------------------- 1 file changed, 441 deletions(-) delete mode 100644 src/qt/homepage.cpp diff --git a/src/qt/homepage.cpp b/src/qt/homepage.cpp deleted file mode 100644 index 25589410..00000000 --- a/src/qt/homepage.cpp +++ /dev/null @@ -1,441 +0,0 @@ -#include "homepage.h" -#include "ui_homepage.h" -#include "profilepage.h" -#include "qprocess.h" - -//selim includes -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include -#include -#include -#include -#include -#include -#include "posts.h" -#include -#include -#include -#include -#include -#include "mainwindow.h" -#include "addcomment.h" -#include "adminwindow.h" -#define POSTSNUMBER 100 -#define COMMENTSNUMBER 3 -#define POSTSATATIME 15 -//_____ -HomePage::HomePage(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::HomePage) -{ - ui->setupUi(this); - shownPostsNumber = 0; - ui->comboBox->setVisible(false); - pagePosts = new QList; - QWidget::setWindowIcon(QIcon(":/icons/about.png")); - this->showMaximized(); - this->setWindowTitle("Social Network"); - -} - -void HomePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) -{ - this->currentSessionUser = currentSessionUser_ptr; - randomPosts(currentSessionUser_ptr->userName,POSTSATATIME); - QString domain = currentSessionUser_ptr->userName.mid(currentSessionUser_ptr->userName.length()-9,9); - if( domain!= "admin.com") - ui->StatisticsWindow_btn->setVisible(false); - viewPosts(); -} - - -void HomePage::viewPosts() -{ - unsigned int j,k; - static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; - qDebug("now"); - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) - { - QGroupBox *postframe = new QGroupBox; - QVBoxLayout *postLayout = new QVBoxLayout; - postframe->setLayout(postLayout); - postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); - QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); - postLayout->addWidget(postDate); - QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber - QFontMetrics font_metrics(postBody->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added - int height = font_height * 6; - postBody->setMinimumHeight(height); - postBody->setMaximumHeight(height); - postLayout->addWidget(postBody); - ParentVerticalLayout->addWidget(postframe); - QHBoxLayout *likeAndComment = new QHBoxLayout; - QPushButton *like = new QPushButton("Like"); - like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); - connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); - like->setStyleSheet("background-color: rgb(c0,c6,c8);"); - QPushButton *comment = new QPushButton("Comment",postframe); - comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); - connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); - comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); - likeAndComment->addWidget(like); - likeAndComment->addWidget(comment); - postLayout->addLayout(likeAndComment); - std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); - for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) - { - if(currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt]) - { - like->setEnabled(false); - break; - } - } - QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) - +" people are liking this!"); - likesOwners->setObjectName("likesOwnersButton"); - connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); - QHBoxLayout *likesOwnersLayout = new QHBoxLayout; - likesOwnersLayout->addWidget(likesOwners); - postLayout->addLayout(likesOwnersLayout); - for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) - { - QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); - commentBody->setMinimumHeight(height); - commentBody->setMaximumHeight(height); - commentLayout->addWidget(commentBody); - postLayout->addLayout(commentLayout); - } - QFrame* line = new QFrame(); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - ParentVerticalLayout->addWidget(line); - } - ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); - ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); - QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); - connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); -} -void HomePage::on_LikeButton_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - button->setEnabled(false); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); - int postsNumber,likesNumber; - currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); - currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); -} -void HomePage::on_CommentButton_clicked() -{ - QString commentBody; - QVBoxLayout *postLayout; - AddComment commentWindow; - commentWindow.setModal(true); - commentWindow.exec(); - commentBody = commentWindow.getCommentBody(); - qDebug(commentBody.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QHBoxLayout *commentLayout = new QHBoxLayout; - QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); - QLabel *commentOwner = new QLabel (commentOwnerName); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBodyTextBrowser = new QTextBrowser; - commentBodyTextBrowser->setText(commentBody); - QFontMetrics font_metrics(commentBodyTextBrowser->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? - int height = font_height * 2; - commentBodyTextBrowser->setMinimumHeight(height); - commentBodyTextBrowser->setMaximumHeight(height); - commentLayout->addWidget(commentBodyTextBrowser); - postLayout->addLayout(commentLayout); - /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - qDebug(labelString.toLatin1()); - currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) - ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); -} - - -void HomePage::on_likesOwners_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); - QScrollArea* likesOwners = new QScrollArea; - QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; - likesOwners->setLayout(scrollingAreaLayout); - for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) - { - if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) - { - std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); - for(int i = 0; i < likesVector->size(); i++) - { - QLabel* userLabel = new QLabel((*likesVector)[i]); - scrollingAreaLayout->addWidget(userLabel); - } - } - } - likesOwners->show(); -} - -void HomePage::viewMorePosts(int i) -{ - QScrollBar *bar = qobject_cast (QObject::sender()); - int max = bar ->maximum(); - if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) - { - viewPosts(); - } -} - - -HomePage::~HomePage() -{ - delete ui; -} - -void HomePage::on_pushButton_clicked() -{ - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - ProfilePage * profilePageWindow=new ProfilePage; - profilePageWindow->show(); - this->hide(); - profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); -} - -void HomePage::on_Post_btn_clicked() -{ - QString postText = ui->newPost_txtEdit->toPlainText(); - Date Now; - Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); - pagePosts->push_front(recentlyAddedPost); - shownPostsNumber = 0; - viewPosts(); - currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); - -} - -void HomePage::on_StatisticsWindow_btn_clicked() -{ - AdminWindow *adminWindow = new AdminWindow; - adminWindow->show();; - this->hide(); -} - - -void HomePage::swap(QString *a,QString *b) -{ - - QString temp=*a; - *a=*b; - *b=temp; -} - -void HomePage::siftUp(QList&myList,int index) //O(log(n) -{ - - int parentIndex= (index%2==0)?(index-2)/2 : (index-1)/2; - while( index!=0 && myList[parentIndex][0]&myList,int size) //O(log(n) -{ int index=0; - int leftChild= (2*index)+1; int rightChild=(2*index)+2; - while ((leftChild& myList) //O(n log(n)) -{ - - int size= myList.count(); - while(size>1) - { - swap(&myList[0],&myList[size-1]); - size--; - siftDown(myList,size); - - } - -} - - - -void HomePage::internalSearch (QString x,QList &myList,int begin,int end,QList &temp) -{ - - if(begin>end) {temp.append("\0");return ;} //not found - int middle= (begin+end)/2; bool indicator=false; - //qDebug()< x[0]) - { - - internalSearch ( x, myList,begin,middle-1,temp); - } - else - internalSearch ( x, myList,middle+1,end,temp); - - - -} - - -QList HomePage::search (QString x,QList & myList) -{ - for(int i=1;i temp; - internalSearch(x,myList,0,myList.count()-1,temp); - return temp; -} - - -void HomePage::on_friendSearch_textChanged(const QString &arg1) -{ - QString name= ui->friendSearch->text(); - if(name=="")return; - ui->comboBox->setVisible(true); - QList list= currentSessionUser->userFileManipulator.readEmails(); //yomna's list of mails - QListoptionsList=search(name,list); - ui->comboBox->addItem("Search Results"); - for(int i=0;icomboBox->addItem(optionsList[i]); - } - -} - -void HomePage::on_comboBox_currentIndexChanged(int index) -{ - QList items = ui->comboBox->children(); - if(index == -1) - return ; - QString mail = ui->comboBox->itemText(index); - if(mail == "Search Results") - return; - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - ProfilePage * profilePageWindow=new ProfilePage; - profilePageWindow->show(); - this->hide(); - profilePageWindow->setHomePageOwnerMail(currentSessionUser->userName); - currentSessionUser->userName = mail; - profilePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - -} - - -QList *HomePage::randomPosts(QString mail,int number) -{ - fileman A; - QList friendsMail=A.getFriends( mail); - friendsMail.push_front(currentSessionUser->userName); - friendsMail.push_front(currentSessionUser->userName); - friendsMail.push_front(currentSessionUser->userName); - for(int i=1;i *friendsPosts=currentSessionUser->userFileManipulator.getPosts_new(friendsMail[i]); - for(int j=0; jcount()) - pagePosts->push_back((*friendsPosts)[j]); - } - } -} - -void HomePage::on_actionLog_Out_triggered() -{ - qApp->quit(); - QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); -} From aba91197164750f3c72a3f92c8f48a37ef64a596 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:34 -0400 Subject: [PATCH 1121/1324] Delete homepage.h --- src/qt/homepage.h | 85 ----------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 src/qt/homepage.h diff --git a/src/qt/homepage.h b/src/qt/homepage.h deleted file mode 100644 index bb524d61..00000000 --- a/src/qt/homepage.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef HOMEPAGE_H -#define HOMEPAGE_H - -#include -#include "profilepage.h" -#include "posts.h" -#include "user.h" -#include -#include -#include -namespace Ui { -class HomePage; -} - -class HomePage : public QMainWindow -{ - Q_OBJECT - -public: - explicit HomePage(QWidget *parent = 0); - - void setCurrentSessionUser_Ptr(user *currentSessionUser_ptr); - - friend class ProfilePage; - - QList search(char x, QList &myList); - - ~HomePage(); - - -public Q_SLOTS: - QList search(QString x, QList& myList); - - void internalSearch(QString x, QList &myList, int begin, int end, QList &temp); - - void sort(QList &myList); - - void siftDown(QList &myList, int size); - - void siftUp(QList &myList, int index); - - void swap(QString *a, QString *b); - - QList *randomPosts(QString mail, int number); - - void on_likesOwners_clicked(); - - -private: - - Ui::HomePage *ui; - - user *currentSessionUser; - -private Q_SLOTS: - - void viewPosts(); - - void on_LikeButton_clicked(); - - void viewMorePosts(int i); - - void on_CommentButton_clicked(); - - void on_Post_btn_clicked(); - - void on_pushButton_clicked(); - - void on_StatisticsWindow_btn_clicked(); - - void on_friendSearch_textChanged(const QString &arg1); - - void on_comboBox_currentIndexChanged(int index); - - void on_actionLog_Out_triggered(); - - -private: - unsigned int shownPostsNumber; - - QList *pagePosts; - -}; - -#endif // HOMEPAGE_H From 2afe18788ea849afb874c5cb5eba9e2df6b9acb9 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:46 -0400 Subject: [PATCH 1122/1324] Delete main.cpp --- src/qt/main.cpp | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/qt/main.cpp diff --git a/src/qt/main.cpp b/src/qt/main.cpp deleted file mode 100644 index c72209ce..00000000 --- a/src/qt/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mainwindow.h" -#include -#include "homepage.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} From 888634c80fcadaad39160328a4af99f08845a5e6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:28:53 -0400 Subject: [PATCH 1123/1324] Delete mainwindow.cpp --- src/qt/mainwindow.cpp | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/qt/mainwindow.cpp diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp deleted file mode 100644 index fb87f933..00000000 --- a/src/qt/mainwindow.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "newaccount.h" -#include "homepage.h" -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - ui->signUpLabel->setText("No account? Create one!"); - -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::on_signUpButton_clicked() -{ - newAccount *newAccountWindow = new newAccount; - newAccountWindow->show(); - this->hide(); - newAccountWindow->setLoginPtr(this); - -} - -void MainWindow::on_logInButton_clicked() -{ - this->hide(); - HomePage *homePageWindow = new HomePage; - homePageWindow->show(); -} From cfb0b017001a32bd803a1160b2da4d0656ee8542 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:01 -0400 Subject: [PATCH 1124/1324] Delete mainwindow.h --- src/qt/mainwindow.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/qt/mainwindow.h diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h deleted file mode 100644 index eae1a7ce..00000000 --- a/src/qt/mainwindow.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private Q_SLOTS: - void on_signUpButton_clicked(); - - void on_logInButton_clicked(); - -private: - Ui::MainWindow *ui; -}; - -#endif // MAINWINDOW_H From 289ac1135a880b3d42863f32f39279bc68785eb4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:10 -0400 Subject: [PATCH 1125/1324] Delete newaccount.cpp --- src/qt/newaccount.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/qt/newaccount.cpp diff --git a/src/qt/newaccount.cpp b/src/qt/newaccount.cpp deleted file mode 100644 index b5876f88..00000000 --- a/src/qt/newaccount.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "newaccount.h" -#include "ui_newaccount.h" -#include "QMessageBox" -newAccount::newAccount(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::newAccount) -{ - ui->setupUi(this); -} - -newAccount::~newAccount() -{ - delete ui; -} - -void newAccount::on_pushButton_clicked() -{ - QString password =ui->lineEdit_2->text(); - QString confirm =ui->lineEdit_3->text(); - if(password!=confirm) - { - QMessageBox :: information(this,"confirmation","your password isn't confirmed try again"); - } -} - -void newAccount::setLoginPtr(MainWindow *ptr) -{ - this->mainWindowPtr = ptr; -} - -void newAccount::on_pushButton_2_clicked() -{ - mainWindowPtr->show(); - this->hide(); -} From 116bbf5d31062ddf620f15eafc265c94cfacb3bf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:18 -0400 Subject: [PATCH 1126/1324] Delete newaccount.h --- src/qt/newaccount.h | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/qt/newaccount.h diff --git a/src/qt/newaccount.h b/src/qt/newaccount.h deleted file mode 100644 index f9b779a7..00000000 --- a/src/qt/newaccount.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NEWACCOUNT_H -#define NEWACCOUNT_H - -#include -#include "mainwindow.h" -namespace Ui { -class newAccount; -} - -class newAccount : public QMainWindow -{ - Q_OBJECT - -public: - explicit newAccount(QWidget *parent = 0); - ~newAccount(); - -public Q_SLOTS: - void setLoginPtr(MainWindow *ptr); -private Q_SLOTS: - void on_pushButton_clicked(); - - void on_pushButton_2_clicked(); - -private: - Ui::newAccount *ui; - MainWindow *mainWindowPtr; -}; - -#endif // NEWACCOUNT_H From be5e869af0f98924293de58537099e08d07fd8dd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:30 -0400 Subject: [PATCH 1127/1324] Delete posts.cpp --- src/qt/posts.cpp | 112 ----------------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 src/qt/posts.cpp diff --git a/src/qt/posts.cpp b/src/qt/posts.cpp deleted file mode 100644 index ef082536..00000000 --- a/src/qt/posts.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "posts.h" - -Post::Post() -{ - postOwner = ""; - postText = ""; -} - -Post::Post(QString owner, QString text, QString creationDate) -{ - postOwner = owner; - postText = text; - postDate = creationDate; - postLikesNumber = 0; -} - -void Post::setPostOwner(QString owner) -{ - postOwner = owner; -} - -QString Post::getPostOwner() -{ - return postOwner; -} - -void Post::setPostText(QString text) -{ - postText = text; -} - -QString Post::getPostText() -{ - return postText; -} - -void Post::addPostLike(QString likeOwner) -{ - postLikesNumber++; - postLikesOwners.push_back(likeOwner); -} - -void Post::removePostLike(QString owner) -{ - std::vector::iterator iterator; - for(iterator = postLikesOwners.begin(); iterator != postLikesOwners.end(); iterator++) - { - if(*iterator == owner) - { - postLikesOwners.erase(iterator); - break; - } - } -} - -unsigned int Post::getPostLikesNumber() -{ - return postLikesNumber; -} - -std::vector *Post::getPostLikesOwnersVectorPtr() -{ - return &postLikesOwners; -} - -void Post::addComment(Comment newComment) -{ - postComments.push_back(newComment); -} - -void Post::deleteComment(Comment toBeDeleted) -{ - std::vector::iterator iterator; - for(iterator = postComments.begin(); iterator != postComments.end(); iterator++) - { - if((*iterator).getCommentText() == toBeDeleted.getCommentText()) - { - postComments.erase(iterator); - break; - } - } -} - -std::vector *Post::getPostCommentsVectorPtr() -{ - return &postComments; -} - -void Post::setPostDate(QString creationDate) -{ - postDate = creationDate; -} - -QString Post::getPostDate() -{ - return postDate; -} - - - - - - - - - - - - - - - From 1f3d27883ddf391211d51a1c1d6d0640a84bc3e1 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:38 -0400 Subject: [PATCH 1128/1324] Delete posts.h --- src/qt/posts.h | 179 ------------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 src/qt/posts.h diff --git a/src/qt/posts.h b/src/qt/posts.h deleted file mode 100644 index 094b3c17..00000000 --- a/src/qt/posts.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef POSTS_H -#define POSTS_H -#include "comment.h" -#include -#include -class Post -{ - QString postOwner; - QString postText; - unsigned int postLikesNumber; - std::vector postLikesOwners; - std::vector postComments; - QString postDate; -public: - - /** - * @brief - * - * @param - * - * @return - */ - Post(); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - Post(QString,QString,QString); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - void setPostOwner(QString); - - /** - * @brief - * - * @param - * - * @example - * - * @return - */ - QString getPostOwner(); - - /** - * @brief - * - * @ - * - * @param - * - * @return - */ - void setPostText(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - QString getPostText(); - - /** - * @brief - * - * @example
- * - * @param - * - * @return - */ - void addPostLike(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void removePostLike(QString); - - /** - * @brief - * - * @example <35 likes or so. Maybe used to view the post likes number in a label or something.> - * - * @param - * - * @return - */ - unsigned int getPostLikesNumber(); - - /** - * @brief - * - * @example - * - * @param - * - * @return * postLikesOwners> - */ - std::vector* getPostLikesOwnersVectorPtr(); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void addComment(Comment); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - void deleteComment(Comment); - - /** - * @brief - * - * @example - * - * @param - * - * @return * commentsVector> - */ - std::vector* getPostCommentsVectorPtr(); - - /** - * @brief - * - * @example: - * - * @param - * - * @return - */ - void setPostDate(QString); - - /** - * @brief - * - * @example - * - * @param - * - * @return - */ - QString getPostDate(); -}; -#endif // POSTS_H From f47f063ebce981965a53da06614a9851a5a2c2a5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:29:53 -0400 Subject: [PATCH 1129/1324] Delete qdb.cpp --- src/qt/qdb.cpp | 53 -------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 src/qt/qdb.cpp diff --git a/src/qt/qdb.cpp b/src/qt/qdb.cpp deleted file mode 100644 index 3c805326..00000000 --- a/src/qt/qdb.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "qdb.h" - -QDB::QDB() -{ - -} - -QDB::~QDB() -{ - Disconnect(); -} - -bool QDB::Connect(const QString dbname) -{ - - if (!this->db.isOpen()) - { - this->db = QSqlDatabase::addDatabase("QSQLITE"); - this->db.setDatabaseName(dbname); - - if (!this->db.open()) - { - return false; - } - else - { - return true; - } - } - else - { - return false; - } -} - -bool QDB::Disconnect() -{ - if (this->db.isOpen()) - { - this->db.close(); - return true; - } - else - { - return false; - } -} - -QSqlQuery Query(QString q) -{ - QSqlQuery query(q); - return query; -} From 04bef037abf5a4a9e293dd03d71386f9aab07402 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:30:02 -0400 Subject: [PATCH 1130/1324] Delete qdb.h --- src/qt/qdb.h | Bin 637 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/qt/qdb.h diff --git a/src/qt/qdb.h b/src/qt/qdb.h deleted file mode 100644 index 472213ceb67e2d89f5f71d67e51b92cc2fc952f8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 637 zcmeHDyKciU4D2jG|3JWtJ7rIb45^0a~? From 00b221f99fec4af0a90080585f2798f7200c725d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:30:12 -0400 Subject: [PATCH 1131/1324] Delete qcustomplot.cpp --- src/qt/qcustomplot.cpp | 30121 --------------------------------------- 1 file changed, 30121 deletions(-) delete mode 100644 src/qt/qcustomplot.cpp diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp deleted file mode 100644 index e59374ab..00000000 --- a/src/qt/qcustomplot.cpp +++ /dev/null @@ -1,30121 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#include "qcustomplot.h" - - -/* including file 'src/vector2d.cpp', size 7340 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPVector2D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPVector2D - \brief Represents two doubles as a mathematical 2D vector - - This class acts as a replacement for QVector2D with the advantage of double precision instead of - single, and some convenience methods tailored for the QCustomPlot library. -*/ - -/* start documentation of inline functions */ - -/*! \fn void QCPVector2D::setX(double x) - - Sets the x coordinate of this vector to \a x. - - \see setY -*/ - -/*! \fn void QCPVector2D::setY(double y) - - Sets the y coordinate of this vector to \a y. - - \see setX -*/ - -/*! \fn double QCPVector2D::length() const - - Returns the length of this vector. - - \see lengthSquared -*/ - -/*! \fn double QCPVector2D::lengthSquared() const - - Returns the squared length of this vector. In some situations, e.g. when just trying to find the - shortest vector of a group, this is faster than calculating \ref length, because it avoids - calculation of a square root. - - \see length -*/ - -/*! \fn QPoint QCPVector2D::toPoint() const - - Returns a QPoint which has the x and y coordinates of this vector, truncating any floating point - information. - - \see toPointF -*/ - -/*! \fn QPointF QCPVector2D::toPointF() const - - Returns a QPointF which has the x and y coordinates of this vector. - - \see toPoint -*/ - -/*! \fn bool QCPVector2D::isNull() const - - Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y - coordinates, i.e. if both are binary equal to 0. -*/ - -/*! \fn QCPVector2D QCPVector2D::perpendicular() const - - Returns a vector perpendicular to this vector, with the same length. -*/ - -/*! \fn double QCPVector2D::dot() const - - Returns the dot/scalar product of this vector with the specified vector \a vec. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates to 0. -*/ -QCPVector2D::QCPVector2D() : - mX(0), - mY(0) -{ -} - -/*! - Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified - values. -*/ -QCPVector2D::QCPVector2D(double x, double y) : - mX(x), - mY(y) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPoint &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of - the specified \a point. -*/ -QCPVector2D::QCPVector2D(const QPointF &point) : - mX(point.x()), - mY(point.y()) -{ -} - -/*! - Normalizes this vector. After this operation, the length of the vector is equal to 1. - - \see normalized, length, lengthSquared -*/ -void QCPVector2D::normalize() -{ - double len = length(); - mX /= len; - mY /= len; -} - -/*! - Returns a normalized version of this vector. The length of the returned vector is equal to 1. - - \see normalize, length, lengthSquared -*/ -QCPVector2D QCPVector2D::normalized() const -{ - QCPVector2D result(mX, mY); - result.normalize(); - return result; -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a start and \a end. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const -{ - QCPVector2D v(end-start); - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = v.dot(*this-start)/vLengthSqr; - if (mu < 0) - return (*this-start).lengthSquared(); - else if (mu > 1) - return (*this-end).lengthSquared(); - else - return ((start + mu*v)-*this).lengthSquared(); - } else - return (*this-start).lengthSquared(); -} - -/*! \overload - - Returns the squared shortest distance of this vector (interpreted as a point) to the finite line - segment given by \a line. - - \see distanceToStraightLine -*/ -double QCPVector2D::distanceSquaredToLine(const QLineF &line) const -{ - return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); -} - -/*! - Returns the shortest distance of this vector (interpreted as a point) to the infinite straight - line given by a \a base point and a \a direction vector. - - \see distanceSquaredToLine -*/ -double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const -{ - return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); -} - -/*! - Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a - factor. -*/ -QCPVector2D &QCPVector2D::operator*=(double factor) -{ - mX *= factor; - mY *= factor; - return *this; -} - -/*! - Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a - divisor. -*/ -QCPVector2D &QCPVector2D::operator/=(double divisor) -{ - mX /= divisor; - mY /= divisor; - return *this; -} - -/*! - Adds the given \a vector to this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) -{ - mX += vector.mX; - mY += vector.mY; - return *this; -} - -/*! - subtracts the given \a vector from this vector component-wise. -*/ -QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) -{ - mX -= vector.mX; - mY -= vector.mY; - return *this; -} -/* end of 'src/vector2d.cpp' */ - - -/* including file 'src/painter.cpp', size 8670 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPainter -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPainter - \brief QPainter subclass used internally - - This QPainter subclass is used to provide some extended functionality e.g. for tweaking position - consistency between antialiased and non-antialiased painting. Further it provides workarounds - for QPainter quirks. - - \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and - restore. So while it is possible to pass a QCPPainter instance to a function that expects a - QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because - it will call the base class implementations of the functions actually hidden by QCPPainter). -*/ - -/*! - Creates a new QCPPainter instance and sets default values -*/ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) -{ - // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and - // a call to begin() will follow -} - -/*! - Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just - like the analogous QPainter constructor, begins painting on \a device immediately. - - Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. -*/ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif -} - -/*! - Sets the pen of the painter and applies certain fixes to it, depending on the mode of this - QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QPen &pen) -{ - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QColor &color) -{ - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(Qt::PenStyle penStyle) -{ - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when - antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to - integer coordinates and then passes it to the original drawLine. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::drawLine(const QLineF &line) -{ - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); - else - QPainter::drawLine(line.toLine()); -} - -/*! - Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint - with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between - antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for - AA/Non-AA painting). -*/ -void QCPPainter::setAntialiasing(bool enabled) -{ - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) - { - mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs - { - if (mIsAntialiasing) - translate(0.5, 0.5); - else - translate(-0.5, -0.5); - } - } -} - -/*! - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setModes(QCPPainter::PainterModes modes) -{ - mModes = modes; -} - -/*! - Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a - device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, - all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that - behaviour. - - The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets - the render hint as appropriate. - - \note this function hides the non-virtual base class implementation. -*/ -bool QCPPainter::begin(QPaintDevice *device) -{ - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif - return result; -} - -/*! \overload - - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) -{ - if (!enabled && mModes.testFlag(mode)) - mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) - mModes |= mode; -} - -/*! - Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see restore -*/ -void QCPPainter::save() -{ - mAntialiasingStack.push(mIsAntialiasing); - QPainter::save(); -} - -/*! - Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see save -*/ -void QCPPainter::restore() -{ - if (!mAntialiasingStack.isEmpty()) - mIsAntialiasing = mAntialiasingStack.pop(); - else - qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; - QPainter::restore(); -} - -/*! - Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen - overrides when the \ref pmNonCosmetic mode is set. -*/ -void QCPPainter::makeNonCosmetic() -{ - if (qFuzzyIsNull(pen().widthF())) - { - QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); - } -} -/* end of 'src/painter.cpp' */ - - -/* including file 'src/paintbuffer.cpp', size 18502 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPaintBuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPaintBuffer - \brief The abstract base class for paint buffers, which define the rendering backend - - This abstract base class defines the basic interface that a paint buffer needs to provide in - order to be usable by QCustomPlot. - - A paint buffer manages both a surface to draw onto, and the matching paint device. The size of - the surface can be changed via \ref setSize. External classes (\ref QCustomPlot and \ref - QCPLayer) request a painter via \ref startPainting and then perform the draw calls. Once the - painting is complete, \ref donePainting is called, so the paint buffer implementation can do - clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color - using \ref clear (usually the color is \c Qt::transparent), to remove the contents of the - previous frame. - - The simplest paint buffer implementation is \ref QCPPaintBufferPixmap which allows regular - software rendering via the raster engine. Hardware accelerated rendering via pixel buffers and - frame buffer objects is provided by \ref QCPPaintBufferGlPbuffer and \ref QCPPaintBufferGlFbo. - They are used automatically if \ref QCustomPlot::setOpenGl is enabled. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual QCPPainter *QCPAbstractPaintBuffer::startPainting() = 0 - - Returns a \ref QCPPainter which is ready to draw to this buffer. The ownership and thus the - responsibility to delete the painter after the painting operations are complete is given to the - caller of this method. - - Once you are done using the painter, delete the painter and call \ref donePainting. - - While a painter generated with this method is active, you must not call \ref setSize, \ref - setDevicePixelRatio or \ref clear. - - This method may return 0, if a painter couldn't be activated on the buffer. This usually - indicates a problem with the respective painting backend. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::draw(QCPPainter *painter) const = 0 - - Draws the contents of this buffer with the provided \a painter. This is the method that is used - to finally join all paint buffers and draw them onto the screen. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::clear(const QColor &color) = 0 - - Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the - named color \c Qt::transparent. - - This method must not be called if there is currently a painter (acquired with \ref startPainting) - active. -*/ - -/*! \fn virtual void QCPAbstractPaintBuffer::reallocateBuffer() = 0 - - Reallocates the internal buffer with the currently configured size (\ref setSize) and device - pixel ratio, if applicable (\ref setDevicePixelRatio). It is called as soon as any of those - properties are changed on this paint buffer. - - \note Subclasses of \ref QCPAbstractPaintBuffer must call their reimplementation of this method - in their constructor, to perform the first allocation (this can not be done by the base class - because calling pure virtual methods in base class constructors is not possible). -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of inline functions */ - -/*! \fn virtual void QCPAbstractPaintBuffer::donePainting() - - If you have acquired a \ref QCPPainter to paint onto this paint buffer via \ref startPainting, - call this method as soon as you are done with the painting operations and have deleted the - painter. - - paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The - default implementation does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a paint buffer and initializes it with the provided \a size and \a devicePixelRatio. - - Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. -*/ -QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : - mSize(size), - mDevicePixelRatio(devicePixelRatio), - mInvalidated(true) -{ -} - -QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() -{ -} - -/*! - Sets the paint buffer size. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - If \a size is already the current buffer size, this method does nothing. -*/ -void QCPAbstractPaintBuffer::setSize(const QSize &size) -{ - if (mSize != size) - { - mSize = size; - reallocateBuffer(); - } -} - -/*! - Sets the invalidated flag to \a invalidated. - - This mechanism is used internally in conjunction with isolated replotting of \ref QCPLayer - instances (in \ref QCPLayer::lmBuffered mode). If \ref QCPLayer::replot is called on a buffered - layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested, - QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also - replots them, instead of only the layer on which the replot was called. - - The invalidated flag is set to true when \ref QCPLayer association has changed, i.e. if layers - were added or removed from this buffer, or if they were reordered. It is set to false as soon as - all associated \ref QCPLayer instances are drawn onto the buffer. - - Under normal circumstances, it is not necessary to manually call this method. -*/ -void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) -{ - mInvalidated = invalidated; -} - -/*! - Sets the the device pixel ratio to \a ratio. This is useful to render on high-DPI output devices. - The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance. - - The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained - by \ref startPainting are invalidated and must not be used after calling this method. - - \note This method is only available for Qt versions 5.4 and higher. -*/ -void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mDevicePixelRatio = ratio; - reallocateBuffer(); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; -#endif - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferPixmap - \brief A paint buffer based on QPixmap, using software raster rendering - - This paint buffer is the default and fall-back paint buffer which uses software rendering and - QPixmap as internal buffer. It is used if \ref QCustomPlot::setOpenGl is false. -*/ - -/*! - Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if - applicable. -*/ -QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : - QCPAbstractPaintBuffer(size, devicePixelRatio) -{ - QCPPaintBufferPixmap::reallocateBuffer(); -} - -QCPPaintBufferPixmap::~QCPPaintBufferPixmap() -{ -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferPixmap::startPainting() -{ - QCPPainter *result = new QCPPainter(&mBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::draw(QCPPainter *painter) const -{ - if (painter && painter->isActive()) - painter->drawPixmap(0, 0, mBuffer); - else - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::clear(const QColor &color) -{ - mBuffer.fill(color); -} - -/* inherits documentation from base class */ -void QCPPaintBufferPixmap::reallocateBuffer() -{ - setInvalidated(); - if (!qFuzzyCompare(1.0, mDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBuffer = QPixmap(mSize*mDevicePixelRatio); - mBuffer.setDevicePixelRatio(mDevicePixelRatio); -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mDevicePixelRatio = 1.0; - mBuffer = QPixmap(mSize); -#endif - } else - { - mBuffer = QPixmap(mSize); - } -} - - -#ifdef QCP_OPENGL_PBUFFER -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlPbuffer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlPbuffer - \brief A paint buffer based on OpenGL pixel buffers, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL pixel buffers (pbuffer) and is used in Qt versions before 5.0. - (See \ref QCPPaintBufferGlFbo used in newer Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlPbuffer instance with the specified \a size and \a - devicePixelRatio, if applicable. - - The parameter \a multisamples defines how many samples are used per pixel. Higher values thus - result in higher quality antialiasing. If the specified \a multisamples value exceeds the - capability of the graphics hardware, the highest supported multisampling is used. -*/ -QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlPBuffer(0), - mMultisamples(qMax(0, multisamples)) -{ - QCPPaintBufferGlPbuffer::reallocateBuffer(); -} - -QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlPbuffer::startPainting() -{ - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - QCPPainter *result = new QCPPainter(mGlPBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlPBuffer->isValid()) - { - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlPBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::clear(const QColor &color) -{ - if (mGlPBuffer->isValid()) - { - mGlPBuffer->makeCurrent(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlPBuffer->doneCurrent(); - } else - qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::reallocateBuffer() -{ - if (mGlPBuffer) - delete mGlPBuffer; - - QGLFormat format; - format.setAlpha(true); - format.setSamples(mMultisamples); - mGlPBuffer = new QGLPixelBuffer(mSize, format); -} -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPaintBufferGlFbo -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPaintBufferGlFbo - \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering - - This paint buffer is one of the OpenGL paint buffers which facilitate hardware accelerated plot - rendering. It is based on OpenGL frame buffer objects (fbo) and is used in Qt versions 5.0 and - higher. (See \ref QCPPaintBufferGlPbuffer used in older Qt versions.) - - The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are - supported by the system. -*/ - -/*! - Creates a \ref QCPPaintBufferGlFbo instance with the specified \a size and \a devicePixelRatio, - if applicable. - - All frame buffer objects shall share one OpenGL context and paint device, which need to be set up - externally and passed via \a glContext and \a glPaintDevice. The set-up is done in \ref - QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot - instance. -*/ -QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlContext(glContext), - mGlPaintDevice(glPaintDevice), - mGlFrameBuffer(0) -{ - QCPPaintBufferGlFbo::reallocateBuffer(); -} - -QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() -{ - if (mGlFrameBuffer) - delete mGlFrameBuffer; -} - -/* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlFbo::startPainting() -{ - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return 0; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return 0; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); - result->setRenderHint(QPainter::HighQualityAntialiasing); - return result; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::donePainting() -{ - if (mGlFrameBuffer && mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - else - qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const -{ - if (!painter || !painter->isActive()) - { - qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - painter->drawImage(0, 0, mGlFrameBuffer->toImage()); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::clear(const QColor &color) -{ - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (!mGlFrameBuffer) - { - qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; - return; - } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - mGlFrameBuffer->bind(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - mGlFrameBuffer->release(); -} - -/* inherits documentation from base class */ -void QCPPaintBufferGlFbo::reallocateBuffer() -{ - // release and delete possibly existing framebuffer: - if (mGlFrameBuffer) - { - if (mGlFrameBuffer->isBound()) - mGlFrameBuffer->release(); - delete mGlFrameBuffer; - mGlFrameBuffer = 0; - } - - if (mGlContext.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; - return; - } - if (mGlPaintDevice.isNull()) - { - qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; - return; - } - - // create new fbo with appropriate size: - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); - QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples(mGlContext.data()->format().samples()); - frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); - if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) - mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); -#endif -} -#endif // QCP_OPENGL_FBO -/* end of 'src/paintbuffer.cpp' */ - - -/* including file 'src/layer.cpp', size 37064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayer - \brief A layer that may contain objects, to control the rendering order - - The Layering system of QCustomPlot is the mechanism to control the rendering order of the - elements inside the plot. - - It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of - one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, - QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers - bottom to top and successively draws the layerables of the layers into the paint buffer(s). - - A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base - class from which almost all visible objects derive, like axes, grids, graphs, items, etc. - - \section qcplayer-defaultlayers Default layers - - Initially, QCustomPlot has six layers: "background", "grid", "main", "axes", "legend" and - "overlay" (in that order). On top is the "overlay" layer, which only contains the QCustomPlot's - selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain - the default axes and legend, so they will be drawn above plottables. In the middle, there is the - "main" layer. It is initially empty and set as the current layer (see - QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this - layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong - tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind - everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of - course, the layer affiliation of the individual objects can be changed as required (\ref - QCPLayerable::setLayer). - - \section qcplayer-ordering Controlling the rendering order via layers - - Controlling the ordering of layerables in the plot is easy: Create a new layer in the position - you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the - current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the - objects normally. They will be placed on the new layer automatically, due to the current layer - setting. Alternatively you could have also ignored the current layer setting and just moved the - objects with \ref QCPLayerable::setLayer to the desired layer after creating them. - - It is also possible to move whole layers. For example, If you want the grid to be shown in front - of all plottables/items on the "main" layer, just move it above "main" with - QCustomPlot::moveLayer. - - The rendering order within one layer is simply by order of creation or insertion. The item - created last (or added last to the layer), is drawn on top of all other objects on that layer. - - When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below - the deleted layer, see QCustomPlot::removeLayer. - - \section qcplayer-buffering Replotting only a specific layer - - If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific - layer by calling \ref replot. In certain situations this can provide better replot performance, - compared with a full replot of all layers. Upon creation of a new layer, the layer mode is - initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref - QCustomPlot instance is the "overlay" layer, containing the selection rect. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPLayer::children() const - - Returns a list of all layerables on this layer. The order corresponds to the rendering order: - layerables with higher indices are drawn above layerables with lower indices. -*/ - -/*! \fn int QCPLayer::index() const - - Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be - accessed via \ref QCustomPlot::layer. - - Layers with higher indices will be drawn above layers with lower indices. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPLayer instance. - - Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. - - \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. - This check is only performed by \ref QCustomPlot::addLayer. -*/ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true), - mMode(lmLogical) -{ - // Note: no need to make sure layerName is unique, because layer - // management is done with QCustomPlot functions. -} - -QCPLayer::~QCPLayer() -{ - // If child layerables are still on this layer, detach them, so they don't try to reach back to this - // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted - // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to - // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) - qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; -} - -/*! - Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this - layer will be invisible. - - This function doesn't change the visibility property of the layerables (\ref - QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the - visibility of the parent layer into account. -*/ -void QCPLayer::setVisible(bool visible) -{ - mVisible = visible; -} - -/*! - Sets the rendering mode of this layer. - - If \a mode is set to \ref lmBuffered for a layer, it will be given a dedicated paint buffer by - the parent QCustomPlot instance. This means it may be replotted individually by calling \ref - QCPLayer::replot, without needing to replot all other layers. - - Layers which are set to \ref lmLogical (the default) are used only to define the rendering order - and can't be replotted individually. - - Note that each layer which is set to \ref lmBuffered requires additional paint buffers for the - layers below, above and for the layer itself. This increases the memory consumption and - (slightly) decreases the repainting speed because multiple paint buffers need to be joined. So - you should carefully choose which layers benefit from having their own paint buffer. A typical - example would be a layer which contains certain layerables (e.g. items) that need to be changed - and thus replotted regularly, while all other layerables on other layers stay static. By default, - only the topmost layer called "overlay" is in mode \ref lmBuffered, and contains the selection - rect. - - \see replot -*/ -void QCPLayer::setMode(QCPLayer::LayerMode mode) -{ - if (mMode != mode) - { - mMode = mode; - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } -} - -/*! \internal - - Draws the contents of this layer with the provided \a painter. - - \see replot, drawToPaintBuffer -*/ -void QCPLayer::draw(QCPPainter *painter) -{ - Q_FOREACH (QCPLayerable *child, mChildren) - { - if (child->realVisibility()) - { - painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); - painter->restore(); - } - } -} - -/*! \internal - - Draws the contents of this layer into the paint buffer which is associated with this layer. The - association is established by the parent QCustomPlot, which manages all paint buffers (see \ref - QCustomPlot::setupPaintBuffers). - - \see draw -*/ -void QCPLayer::drawToPaintBuffer() -{ - if (!mPaintBuffer.isNull()) - { - if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) - { - if (painter->isActive()) - draw(painter); - else - qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; - delete painter; - mPaintBuffer.data()->donePainting(); - } else - qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; -} - -/*! - If the layer mode (\ref setMode) is set to \ref lmBuffered, this method allows replotting only - the layerables on this specific layer, without the need to replot all other layers (as a call to - \ref QCustomPlot::replot would do). - - If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on - the parent QCustomPlot instance. - - QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering - has changed since the last full replot and the other paint buffers were thus invalidated. - - \see draw -*/ -void QCPLayer::replot() -{ - if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) - { - if (!mPaintBuffer.isNull()) - { - mPaintBuffer.data()->clear(Qt::transparent); - drawToPaintBuffer(); - mPaintBuffer.data()->setInvalidated(false); - mParentPlot->update(); - } else - qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } else if (mMode == lmLogical) - mParentPlot->replot(); -} - -/*! \internal - - Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will - be prepended to the list, i.e. be drawn beneath the other layerables already in the list. - - This function does not change the \a mLayer member of \a layerable to this layer. (Use - QCPLayerable::setLayer to change the layer of an object, not this function.) - - \see removeChild -*/ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) -{ - if (!mChildren.contains(layerable)) - { - if (prepend) - mChildren.prepend(layerable); - else - mChildren.append(layerable); - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); -} - -/*! \internal - - Removes the \a layerable from the list of this layer. - - This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer - to change the layer of an object, not this function.) - - \see addChild -*/ -void QCPLayer::removeChild(QCPLayerable *layerable) -{ - if (mChildren.removeOne(layerable)) - { - if (!mPaintBuffer.isNull()) - mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayerable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayerable - \brief Base class for all drawable objects - - This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid - etc. - - Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking - the layers accordingly. - - For details about the layering mechanism, see the QCPLayer documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const - - Returns the parent layerable of this layerable. The parent layerable is used to provide - visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables - only get drawn if their parent layerables are visible, too. - - Note that a parent layerable is not necessarily also the QObject parent for memory management. - Further, a layerable doesn't always have a parent layerable, so this function may return 0. - - A parent layerable is set implicitly when placed inside layout elements and doesn't need to be - set manually by the user. -*/ - -/* end documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 - \internal - - This function applies the default antialiasing setting to the specified \a painter, using the - function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when - \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing - setting may be specified individually, this function should set the antialiasing state of the - most prominent entity. In this case however, the \ref draw function usually calls the specialized - versions of this function before drawing each entity, effectively overriding the setting of the - default antialiasing hint. - - First example: QCPGraph has multiple entities that have an antialiasing setting: The graph - line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, - QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only - the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's - antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and - QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw - calls the respective specialized applyAntialiasingHint function. - - Second example: QCPItemLine consists only of a line so there is only one antialiasing - setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by - all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the - respective layerable subclass.) Consequently it only has the normal - QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to - care about setting any antialiasing states, because the default antialiasing hint is already set - on the painter when the \ref draw function is called, and that's the state it wants to draw the - line with. -*/ - -/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 - \internal - - This function draws the layerable with the specified \a painter. It is only called by - QCustomPlot, if the layerable is visible (\ref setVisible). - - Before this function is called, the painter's antialiasing state is set via \ref - applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was - set to \ref clipRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); - - This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to - a different layer. - - \see setLayer -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPLayerable instance. - - Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the - derived classes. - - If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a - targetLayer is an empty string, it places itself on the current layer of the plot (see \ref - QCustomPlot::setCurrentLayer). - - It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later - time with \ref initializeParentPlot. - - The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable - parents are mainly used to control visibility in a hierarchy of layerables. This means a - layerable is only drawn, if all its ancestor layerables are also visible. Note that \a - parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a - plot does. It is not uncommon to set the QObject-parent to something else in the constructors of - QCPLayerable subclasses, to guarantee a working destruction hierarchy. -*/ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) -{ - if (mParentPlot) - { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) - qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; - } -} - -QCPLayerable::~QCPLayerable() -{ - if (mLayer) - { - mLayer->removeChild(this); - mLayer = 0; - } -} - -/*! - Sets the visibility of this layerable object. If an object is not visible, it will not be drawn - on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not - possible. -*/ -void QCPLayerable::setVisible(bool on) -{ - mVisible = on; -} - -/*! - Sets the \a layer of this layerable object. The object will be placed on top of the other objects - already on \a layer. - - If \a layer is 0, this layerable will not be on any layer and thus not appear in the plot (or - interact/receive events). - - Returns true if the layer of this layerable was successfully changed to \a layer. -*/ -bool QCPLayerable::setLayer(QCPLayer *layer) -{ - return moveToLayer(layer, false); -} - -/*! \overload - Sets the layer of this layerable object by name - - Returns true on success, i.e. if \a layerName is a valid layer name. -*/ -bool QCPLayerable::setLayer(const QString &layerName) -{ - if (!mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (QCPLayer *layer = mParentPlot->layer(layerName)) - { - return setLayer(layer); - } else - { - qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; - return false; - } -} - -/*! - Sets whether this object will be drawn antialiased or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPLayerable::setAntialiased(bool enabled) -{ - mAntialiased = enabled; -} - -/*! - Returns whether this layerable is visible, taking the visibility of the layerable parent and the - visibility of this layerable's layer into account. This is the method that is consulted to decide - whether a layerable shall be drawn or not. - - If this layerable has a direct layerable parent (usually set via hierarchies implemented in - subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this - layerable has its visibility set to true and the parent layerable's \ref realVisibility returns - true. -*/ -bool QCPLayerable::realVisibility() const -{ - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); -} - -/*! - This function is used to decide whether a click hits a layerable object or not. - - \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the - shortest pixel distance of this point to the object. If the object is either invisible or the - distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the - object is not selectable, -1.0 is returned, too. - - If the object is represented not by single lines but by an area like a \ref QCPItemText or the - bars of a \ref QCPBars plottable, a click inside the area should also be considered a hit. In - these cases this function thus returns a constant value greater zero but still below the parent - plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99). - - Providing a constant value for area objects allows selecting line objects even when they are - obscured by such area objects, by clicking close to the lines (i.e. closer than - 0.99*selectionTolerance). - - The actual setting of the selection state is not done by this function. This is handled by the - parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified - via the \ref selectEvent/\ref deselectEvent methods. - - \a details is an optional output parameter. Every layerable subclass may place any information - in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot - decides on the basis of this selectTest call, that the object was successfully selected. The - subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part - objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked - is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be - placed in \a details. So in the subsequent \ref selectEvent, the decision which part was - selected doesn't have to be done a second time for a single selection operation. - - You may pass 0 as \a details to indicate that you are not interested in those selection details. - - \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions -*/ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) - return -1.0; -} - -/*! \internal - - Sets the parent plot of this layerable. Use this function once to set the parent plot if you have - passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to - another one. - - Note that, unlike when passing a non-null parent plot in the constructor, this function does not - make \a parentPlot the QObject-parent of this layerable. If you want this, call - QObject::setParent(\a parentPlot) in addition to this function. - - Further, you will probably want to set a layer (\ref setLayer) after calling this function, to - make the layerable appear on the QCustomPlot. - - The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized - so they can react accordingly (e.g. also initialize the parent plot of child layerables, like - QCPLayout does). -*/ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) -{ - if (mParentPlot) - { - qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; - return; - } - - if (!parentPlot) - qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - - mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); -} - -/*! \internal - - Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not - become the QObject-parent (for memory management) of this layerable. - - The parent layerable has influence on the return value of the \ref realVisibility method. Only - layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be - drawn. - - \see realVisibility -*/ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) -{ - mParentLayerable = parentLayerable; -} - -/*! \internal - - Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to - the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is - false, the object will be appended. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) -{ - if (layer && !mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (layer && layer->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; - return false; - } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); - mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - Q_EMIT layerChanged(mLayer); - return true; -} - -/*! \internal - - Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a - localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is - controlled via \a overrideElement. -*/ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const -{ - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); - else - painter->setAntialiasing(localAntialiased); -} - -/*! \internal - - This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting - of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the - parent plot is set at a later time. - - For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any - QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level - element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To - propagate the parent plot to all the children of the hierarchy, the top level element then uses - this function to pass the parent plot on to its child elements. - - The default implementation does nothing. - - \see initializeParentPlot -*/ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - -/*! \internal - - Returns the selection category this layerable shall belong to. The selection category is used in - conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and - which aren't. - - Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref - QCP::iSelectOther. This is what the default implementation returns. - - \see QCustomPlot::setInteractions -*/ -QCP::Interaction QCPLayerable::selectionCategory() const -{ - return QCP::iSelectOther; -} - -/*! \internal - - Returns the clipping rectangle of this layerable object. By default, this is the viewport of the - parent QCustomPlot. Specific subclasses may reimplement this function to provide different - clipping rects. - - The returned clipping rect is set on the painter before the draw function of the respective - object is called. -*/ -QRect QCPLayerable::clipRect() const -{ - if (mParentPlot) - return mParentPlot->viewport(); - else - return QRect(); -} - -/*! \internal - - This event is called when the layerable shall be selected, as a consequence of a click by the - user. Subclasses should react to it by setting their selection state appropriately. The default - implementation does nothing. - - \a event is the mouse event that caused the selection. \a additive indicates, whether the user - was holding the multi-select-modifier while performing the selection (see \ref - QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled - (i.e. become selected when unselected and unselected when selected). - - Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. - returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). - The \a details data you output from \ref selectTest is fed back via \a details here. You may - use it to transport any kind of information from the selectTest to the possibly subsequent - selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable - that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need - to do the calculation again to find out which part was actually clicked. - - \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must - set the value either to true or false, depending on whether the selection state of this layerable - was actually changed. For layerables that only are selectable as a whole and not in parts, this - is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the - selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the - layerable was previously unselected and now is switched to the selected state. - - \see selectTest, deselectEvent -*/ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) -} - -/*! \internal - - This event is called when the layerable shall be deselected, either as consequence of a user - interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by - unsetting their selection appropriately. - - just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must - return true or false when the selection state of this layerable has changed or not changed, - respectively. - - \see selectTest, selectEvent -*/ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) -{ - Q_UNUSED(selectionStateChanged) -} - -/*! - This event gets called when the user presses a mouse button while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - QCustomPlot uses an event propagation system that works the same as Qt's system. If your - layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in - its reimplementation, the event will be propagated to the next layerable in the stacking order. - - Once a layerable has accepted the \ref mousePressEvent, it is considered the mouse grabber and - will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse - interaction (a "mouse interaction" in this context ends with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user moves the mouse while holding a mouse button, after this - layerable has become the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user releases the mouse button, after this layerable has become - the mouse grabber by accepting the preceding \ref mousePressEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a startPos indicates the position where the initial \ref - mousePressEvent occured, that started the mouse interaction. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent -*/ -void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - event->ignore(); -} - -/*! - This event gets called when the user presses the mouse button a second time in a double-click, - while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a - preceding call to \ref selectTest. - - The \ref mouseDoubleClickEvent is called instead of the second \ref mousePressEvent. So in the - case of a double-click, the event succession is - pressEvent – releaseEvent – doubleClickEvent – releaseEvent. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). The parameter \a details contains layerable-specific details about the hit, which - were generated in the previous call to \ref selectTest. For example, One-dimensional plottables - like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as - \ref QCPDataSelection packed as QVariant. Multi-part objects convey the specific \c - SelectablePart that was hit (e.g. \ref QCPAxis::SelectablePart in the case of axes). - - Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent, - it is considered the mouse grabber and will receive all following calls to \ref mouseMoveEvent - and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends - with the release). - - The default implementation does nothing except explicitly ignoring the event with \c - event->ignore(). - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent -*/ -void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->ignore(); -} - -/*! - This event gets called when the user turns the mouse scroll wheel while the cursor is over the - layerable. Whether a cursor is over the layerable is decided by a preceding call to \ref - selectTest. - - The current pixel position of the cursor on the QCustomPlot widget is accessible via \c - event->pos(). - - The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for - single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may - accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has - very smooth steps or none at all, the delta may be smaller. - - The default implementation does nothing. - - \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent -*/ -void QCPLayerable::wheelEvent(QWheelEvent *event) -{ - event->ignore(); -} -/* end of 'src/layer.cpp' */ - - -/* including file 'src/axis/range.cpp', size 12221 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPRange -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPRange - \brief Represents the range an axis is encompassing. - - contains a \a lower and \a upper double value and provides convenience input, output and - modification functions. - - \see QCPAxis::setRange -*/ - -/* start of documentation of inline functions */ - -/*! \fn double QCPRange::size() const - - Returns the size of the range, i.e. \a upper-\a lower -*/ - -/*! \fn double QCPRange::center() const - - Returns the center of the range, i.e. (\a upper+\a lower)*0.5 -*/ - -/*! \fn void QCPRange::normalize() - - Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are - swapped. -*/ - -/*! \fn bool QCPRange::contains(double value) const - - Returns true when \a value lies within or exactly on the borders of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator+=(const double& value) - - Adds \a value to both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator-=(const double& value) - - Subtracts \a value from both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator*=(const double& value) - - Multiplies both boundaries of the range by \a value. -*/ - -/*! \fn QCPRange &QCPRange::operator/=(const double& value) - - Divides both boundaries of the range by \a value. -*/ - -/* end of documentation of inline functions */ - -/*! - Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller - intervals would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a minimum magnitude of roughly 1e-308. - - \warning Do not use this constant to indicate "arbitrarily small" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining underflowing ranges. - - \see validRange, maxRange -*/ -const double QCPRange::minRange = 1e-280; - -/*! - Maximum values (negative and positive) the range will accept in range-changing functions. - Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a maximum magnitude of roughly 1e308. - - \warning Do not use this constant to indicate "arbitrarily large" values in plotting logic (as - values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to - prevent axis ranges from obtaining overflowing ranges. - - \see validRange, minRange -*/ -const double QCPRange::maxRange = 1e250; - -/*! - Constructs a range with \a lower and \a upper set to zero. -*/ -QCPRange::QCPRange() : - lower(0), - upper(0) -{ -} - -/*! \overload - - Constructs a range with the specified \a lower and \a upper values. - - The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically - smaller than \a upper, they will be swapped. -*/ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) -{ - normalize(); -} - -/*! \overload - - Expands this range such that \a otherRange is contained in the new range. It is assumed that both - this range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, it will be replaced by the respective bound - of \a otherRange. - - If \a otherRange is already inside the current range, this function does nothing. - - \see expanded -*/ -void QCPRange::expand(const QCPRange &otherRange) -{ - if (lower > otherRange.lower || qIsNaN(lower)) - lower = otherRange.lower; - if (upper < otherRange.upper || qIsNaN(upper)) - upper = otherRange.upper; -} - -/*! \overload - - Expands this range such that \a includeCoord is contained in the new range. It is assumed that - this range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the respective bound will be set to \a - includeCoord. - - If \a includeCoord is already inside the current range, this function does nothing. - - \see expand -*/ -void QCPRange::expand(double includeCoord) -{ - if (lower > includeCoord || qIsNaN(lower)) - lower = includeCoord; - if (upper < includeCoord || qIsNaN(upper)) - upper = includeCoord; -} - - -/*! \overload - - Returns an expanded range that contains this and \a otherRange. It is assumed that both this - range and \a otherRange are normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be taken from - \a otherRange. - - \see expand -*/ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const -{ - QCPRange result = *this; - result.expand(otherRange); - return result; -} - -/*! \overload - - Returns an expanded range that includes the specified \a includeCoord. It is assumed that this - range is normalized (see \ref normalize). - - If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a - includeCoord. - - \see expand -*/ -QCPRange QCPRange::expanded(double includeCoord) const -{ - QCPRange result = *this; - result.expand(includeCoord); - return result; -} - -/*! - Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a - upperBound. If possible, the size of the current range is preserved in the process. - - If the range shall only be bounded at the lower side, you can set \a upperBound to \ref - QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref - QCPRange::maxRange. -*/ -QCPRange QCPRange::bounded(double lowerBound, double upperBound) const -{ - if (lowerBound > upperBound) - qSwap(lowerBound, upperBound); - - QCPRange result(lower, upper); - if (result.lower < lowerBound) - { - result.lower = lowerBound; - result.upper = lowerBound + size(); - if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.upper = upperBound; - } else if (result.upper > upperBound) - { - result.upper = upperBound; - result.lower = upperBound - size(); - if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) - result.lower = lowerBound; - } - - return result; -} - -/*! - Returns a sanitized version of the range. Sanitized means for logarithmic scales, that - the range won't span the positive and negative sign domain, i.e. contain zero. Further - \a lower will always be numerically smaller (or equal) to \a upper. - - If the original range does span positive and negative sign domains or contains zero, - the returned range will try to approximate the original range as good as possible. - If the positive interval of the original range is wider than the negative interval, the - returned range will only contain the positive interval, with lower bound set to \a rangeFac or - \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval - is wider than the positive interval, this time by changing the \a upper bound. -*/ -QCPRange QCPRange::sanitizedForLogScale() const -{ - double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - // can't have range spanning negative and positive values in log plot, so change range to fix it - //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) - { - // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) - { - // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) - { - // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) - { - // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else - { - // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } - } - // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange && - !(lower > 0 && qIsInf(upper/lower)) && - !(upper < 0 && qIsInf(lower/upper))); -} - -/*! - \overload - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(const QCPRange &range) -{ - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - !(range.lower > 0 && qIsInf(range.upper/range.lower)) && - !(range.upper < 0 && qIsInf(range.lower/range.upper))); -} -/* end of 'src/axis/range.cpp' */ - - -/* including file 'src/selection.cpp', size 21906 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataRange -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataRange - \brief Describes a data range given by begin and end index - - QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index - of a contiguous set of data points. The end index points to the data point above the last data point that's part of - the data range, similarly to the nomenclature used in standard iterators. - - Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and - modified. If a non-contiguous data set shall be described, the class \ref QCPDataSelection is - used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref - QCPDataSelection is thus used. - - Both \ref QCPDataRange and \ref QCPDataSelection offer convenience methods to work with them, - e.g. \ref bounded, \ref expanded, \ref intersects, \ref intersection, \ref adjusted, \ref - contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be - used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding - \ref QCPDataSelection. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and - QCPDataRange. - - \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval - in floating point plot coordinates, e.g. the current axis range. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataRange::size() const - - Returns the number of data points described by this data range. This is equal to the end index - minus the begin index. - - \see length -*/ - -/*! \fn int QCPDataRange::length() const - - Returns the number of data points described by this data range. Equivalent to \ref size. -*/ - -/*! \fn void QCPDataRange::setBegin(int begin) - - Sets the begin of this data range. The \a begin index points to the first data point that is part - of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setEnd -*/ - -/*! \fn void QCPDataRange::setEnd(int end) - - Sets the end of this data range. The \a end index points to the data point just above the last - data point that is part of the data range. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). - - \see setBegin -*/ - -/*! \fn bool QCPDataRange::isValid() const - - Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and - an end index greater or equal to the begin index. - - \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods - (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's - methods. The invalid range is not inherently prevented in QCPDataRange, to allow temporary - invalid begin/end values while manipulating the range. An invalid range is not necessarily empty - (\ref isEmpty), since its \ref length can be negative and thus non-zero. -*/ - -/*! \fn bool QCPDataRange::isEmpty() const - - Returns whether this range is empty, i.e. whether its begin index equals its end index. - - \see size, length -*/ - -/*! \fn QCPDataRange QCPDataRange::adjusted(int changeBegin, int changeEnd) const - - Returns a data range where \a changeBegin and \a changeEnd were added to the begin and end - indices, respectively. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataRange, with begin and end set to 0. -*/ -QCPDataRange::QCPDataRange() : - mBegin(0), - mEnd(0) -{ -} - -/*! - Creates a QCPDataRange, initialized with the specified \a begin and \a end. - - No checks or corrections are made to ensure the resulting range is valid (\ref isValid). -*/ -QCPDataRange::QCPDataRange(int begin, int end) : - mBegin(begin), - mEnd(end) -{ -} - -/*! - Returns a data range that matches this data range, except that parts exceeding \a other are - excluded. - - This method is very similar to \ref intersection, with one distinction: If this range and the \a - other range share no intersection, the returned data range will be empty with begin and end set - to the respective boundary side of \a other, at which this range is residing. (\ref intersection - would just return a range with begin and end set to 0.) -*/ -QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const -{ - QCPDataRange result(intersection(other)); - if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value - { - if (mEnd <= other.mBegin) - result = QCPDataRange(other.mBegin, other.mBegin); - else - result = QCPDataRange(other.mEnd, other.mEnd); - } - return result; -} - -/*! - Returns a data range that contains both this data range as well as \a other. -*/ -QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const -{ - return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); -} - -/*! - Returns the data range which is contained in both this data range and \a other. - - This method is very similar to \ref bounded, with one distinction: If this range and the \a other - range share no intersection, the returned data range will be empty with begin and end set to 0. - (\ref bounded would return a range with begin and end set to one of the boundaries of \a other, - depending on which side this range is on.) - - \see QCPDataSelection::intersection -*/ -QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const -{ - QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); - if (result.isValid()) - return result; - else - return QCPDataRange(); -} - -/*! - Returns whether this data range and \a other share common data points. - - \see intersection, contains -*/ -bool QCPDataRange::intersects(const QCPDataRange &other) const -{ - return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || - (mEnd <= other.mBegin && mEnd < other.mEnd) ); -} - -/*! - Returns whether all data points described by this data range are also in \a other. - - \see intersects -*/ -bool QCPDataRange::contains(const QCPDataRange &other) const -{ - return mBegin <= other.mBegin && mEnd >= other.mEnd; -} - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataSelection -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataSelection - \brief Describes a data set by holding multiple QCPDataRange instances - - QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly - disjoint) set of data selection. - - The data selection can be modified with addition and subtraction operators which take - QCPDataSelection and QCPDataRange instances, as well as methods such as \ref addDataRange and - \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc. - - The method \ref simplify is used to join directly adjacent or even overlapping QCPDataRange - instances. QCPDataSelection automatically simplifies when using the addition/subtraction - operators. The only case when \ref simplify is left to the user, is when calling \ref - addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data - ranges will be added to the selection successively and the overhead for simplifying after each - iteration shall be avoided. In this case, you should make sure to call \ref simplify after - completing the operation. - - Use \ref enforceType to bring the data selection into a state complying with the constraints for - selections defined in \ref QCP::SelectionType. - - %QCustomPlot's \ref dataselection "data selection mechanism" is based on QCPDataSelection and - QCPDataRange. - - \section qcpdataselection-iterating Iterating over a data selection - - As an example, the following code snippet calculates the average value of a graph's data - \ref QCPAbstractPlottable::selection "selection": - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpdataselection-iterating-1 - -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataSelection::dataRangeCount() const - - Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref - dataRange via their index. - - \see dataRange, dataPointCount -*/ - -/*! \fn QList QCPDataSelection::dataRanges() const - - Returns all data ranges that make up the data selection. If the data selection is simplified (the - usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point - index. - - \see dataRange -*/ - -/*! \fn bool QCPDataSelection::isEmpty() const - - Returns true if there are no data ranges, and thus no data points, in this QCPDataSelection - instance. - - \see dataRangeCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an empty QCPDataSelection. -*/ -QCPDataSelection::QCPDataSelection() -{ -} - -/*! - Creates a QCPDataSelection containing the provided \a range. -*/ -QCPDataSelection::QCPDataSelection(const QCPDataRange &range) -{ - mDataRanges.append(range); -} - -/*! - Returns true if this selection is identical (contains the same data ranges with the same begin - and end indices) to \a other. - - Note that both data selections must be in simplified state (the usual state of the selection, see - \ref simplify) for this operator to return correct results. -*/ -bool QCPDataSelection::operator==(const QCPDataSelection &other) const -{ - if (mDataRanges.size() != other.mDataRanges.size()) - return false; - for (int i=0; i= other.end()) - break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this - - if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored - { - if (thisBegin >= other.begin()) // range leading segment is encompassed - { - if (thisEnd <= other.end()) // range fully encompassed, remove completely - { - mDataRanges.removeAt(i); - continue; - } else // only leading segment is encompassed, trim accordingly - mDataRanges[i].setBegin(other.end()); - } else // leading segment is not encompassed - { - if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly - { - mDataRanges[i].setEnd(other.begin()); - } else // other lies inside this range, so split range - { - mDataRanges[i].setEnd(other.begin()); - mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); - break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here - } - } - } - ++i; - } - - return *this; -} - -/*! - Returns the total number of data points contained in all data ranges that make up this data - selection. -*/ -int QCPDataSelection::dataPointCount() const -{ - int result = 0; - for (int i=0; i= 0 && index < mDataRanges.size()) - { - return mDataRanges.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of range:" << index; - return QCPDataRange(); - } -} - -/*! - Returns a \ref QCPDataRange which spans the entire data selection, including possible - intermediate segments which are not part of the original data selection. -*/ -QCPDataRange QCPDataSelection::span() const -{ - if (isEmpty()) - return QCPDataRange(); - else - return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); -} - -/*! - Adds the given \a dataRange to this data selection. This is equivalent to the += operator but - allows disabling immediate simplification by setting \a simplify to false. This can improve - performance if adding a very large amount of data ranges successively. In this case, make sure to - call \ref simplify manually, after the operation. -*/ -void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) -{ - mDataRanges.append(dataRange); - if (simplify) - this->simplify(); -} - -/*! - Removes all data ranges. The data selection then contains no data points. - - \ref isEmpty -*/ -void QCPDataSelection::clear() -{ - mDataRanges.clear(); -} - -/*! - Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent - or overlapping ranges. This can reduce the number of individual data ranges in the selection, and - prevents possible double-counting when iterating over the data points held by the data ranges. - - This method is automatically called when using the addition/subtraction operators. The only case - when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a - simplify explicitly set to false. -*/ -void QCPDataSelection::simplify() -{ - // remove any empty ranges: - for (int i=mDataRanges.size()-1; i>=0; --i) - { - if (mDataRanges.at(i).isEmpty()) - mDataRanges.removeAt(i); - } - if (mDataRanges.isEmpty()) - return; - - // sort ranges by starting value, ascending: - std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); - - // join overlapping/contiguous ranges: - int i = 1; - while (i < mDataRanges.size()) - { - if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list - { - mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); - mDataRanges.removeAt(i); - } else - ++i; - } -} - -/*! - Makes sure this data selection conforms to the specified \a type selection type. Before the type - is enforced, \ref simplify is called. - - Depending on \a type, enforcing means adding new data points that were previously not part of the - selection, or removing data points from the selection. If the current selection already conforms - to \a type, the data selection is not changed. - - \see QCP::SelectionType -*/ -void QCPDataSelection::enforceType(QCP::SelectionType type) -{ - simplify(); - switch (type) - { - case QCP::stNone: - { - mDataRanges.clear(); - break; - } - case QCP::stWhole: - { - // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) - break; - } - case QCP::stSingleData: - { - // reduce all data ranges to the single first data point: - if (!mDataRanges.isEmpty()) - { - if (mDataRanges.size() > 1) - mDataRanges = QList() << mDataRanges.first(); - if (mDataRanges.first().length() > 1) - mDataRanges.first().setEnd(mDataRanges.first().begin()+1); - } - break; - } - case QCP::stDataRange: - { - mDataRanges = QList() << span(); - break; - } - case QCP::stMultipleDataRanges: - { - // this is the selection type that allows all concievable combinations of ranges, so do nothing - break; - } - } -} - -/*! - Returns true if the data selection \a other is contained entirely in this data selection, i.e. - all data point indices that are in \a other are also in this data selection. - - \see QCPDataRange::contains -*/ -bool QCPDataSelection::contains(const QCPDataSelection &other) const -{ - if (other.isEmpty()) return false; - - int otherIndex = 0; - int thisIndex = 0; - while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) - { - if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) - ++otherIndex; - else - ++thisIndex; - } - return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this -} - -/*! - Returns a data selection containing the points which are both in this data selection and in the - data range \a other. - - A common use case is to limit an unknown data selection to the valid range of a data container, - using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned - data selection without exceeding the data container's bounds. -*/ -QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const -{ - QCPDataSelection result; - for (int i=0; iorientation() == Qt::Horizontal) - return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); - else - return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); - } else - { - qDebug() << Q_FUNC_INFO << "called with axis zero"; - return QCPRange(); - } -} - -/*! - Sets the pen that will be used to draw the selection rect outline. - - \see setBrush -*/ -void QCPSelectionRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used to fill the selection rect. By default the selection rect is not - filled, i.e. \a brush is Qt::NoBrush. - - \see setPen -*/ -void QCPSelectionRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - If there is currently a selection interaction going on (\ref isActive), the interaction is - canceled. The selection rect will emit the \ref canceled signal. -*/ -void QCPSelectionRect::cancel() -{ - if (mActive) - { - mActive = false; - Q_EMIT canceled(mRect, 0); - } -} - -/*! \internal - - This method is called by QCustomPlot to indicate that a selection rect interaction was initiated. - The default implementation sets the selection rect to active, initializes the selection rect - geometry and emits the \ref started signal. -*/ -void QCPSelectionRect::startSelection(QMouseEvent *event) -{ - mActive = true; - mRect = QRect(event->pos(), event->pos()); - Q_EMIT started(event); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs - to update its geometry. The default implementation updates the rect and emits the \ref changed - signal. -*/ -void QCPSelectionRect::moveSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - Q_EMIT changed(mRect, event); - layer()->replot(); -} - -/*! \internal - - This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has - finished by the user releasing the mouse button. The default implementation deactivates the - selection rect and emits the \ref accepted signal. -*/ -void QCPSelectionRect::endSelection(QMouseEvent *event) -{ - mRect.setBottomRight(event->pos()); - mActive = false; - Q_EMIT accepted(mRect, event); -} - -/*! \internal - - This method is called by QCustomPlot when a key has been pressed by the user while the selection - rect interaction is active. The default implementation allows to \ref cancel the interaction by - hitting the escape key. -*/ -void QCPSelectionRect::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape && mActive) - { - mActive = false; - Q_EMIT canceled(mRect, event); - } -} - -/* inherits documentation from base class */ -void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/*! \internal - - If the selection rect is active (\ref isActive), draws the selection rect defined by \a mRect. - - \seebaseclassmethod -*/ -void QCPSelectionRect::draw(QCPPainter *painter) -{ - if (mActive) - { - painter->setPen(mPen); - painter->setBrush(mBrush); - painter->drawRect(mRect); - } -} -/* end of 'src/selectionrect.cpp' */ - - -/* including file 'src/layout.cpp', size 79064 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPMarginGroup -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPMarginGroup - \brief A margin group allows synchronization of margin sides if working with multiple layout elements. - - QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that - they will all have the same size, based on the largest required margin in the group. - - \n - \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" - \n - - In certain situations it is desirable that margins at specific sides are synchronized across - layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will - provide a cleaner look to the user if the left and right margins of the two axis rects are of the - same size. The left axis of the top axis rect will then be at the same horizontal position as the - left axis of the lower axis rect, making them appear aligned. The same applies for the right - axes. This is what QCPMarginGroup makes possible. - - To add/remove a specific side of a layout element to/from a margin group, use the \ref - QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call - \ref clear, or just delete the margin group. - - \section QCPMarginGroup-example Example - - First create a margin group: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-1 - Then set this group on the layout element sides: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpmargingroup-creation-2 - Here, we've used the first two axis rects of the plot and synchronized their left margins with - each other and their right margins with each other. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList QCPMarginGroup::elements(QCP::MarginSide side) const - - Returns a list of all layout elements that have their margin \a side associated with this margin - group. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPMarginGroup instance in \a parentPlot. -*/ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) -{ - mChildren.insert(QCP::msLeft, QList()); - mChildren.insert(QCP::msRight, QList()); - mChildren.insert(QCP::msTop, QList()); - mChildren.insert(QCP::msBottom, QList()); -} - -QCPMarginGroup::~QCPMarginGroup() -{ - clear(); -} - -/*! - Returns whether this margin group is empty. If this function returns true, no layout elements use - this margin group to synchronize margin sides. -*/ -bool QCPMarginGroup::isEmpty() const -{ - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - if (!it.value().isEmpty()) - return false; - } - return true; -} - -/*! - Clears this margin group. The synchronization of the margin sides that use this margin group is - lifted and they will use their individual margin sizes again. -*/ -void QCPMarginGroup::clear() -{ - // make all children remove themselves from this margin group: - QHashIterator > it(mChildren); - while (it.hasNext()) - { - it.next(); - const QList elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild - } -} - -/*! \internal - - Returns the synchronized common margin for \a side. This is the margin value that will be used by - the layout element on the respective side, if it is part of this margin group. - - The common margin is calculated by requesting the automatic margin (\ref - QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin - group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into - account, too.) -*/ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const -{ - // query all automatic margins of the layout elements in this margin group side and find maximum: - int result = 0; - const QList elements = mChildren.value(side); - for (int i=0; iautoMargins().testFlag(side)) - continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) - result = m; - } - return result; -} - -/*! \internal - - Adds \a element to the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].contains(element)) - mChildren[side].append(element); - else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); -} - -/*! \internal - - Removes \a element from the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutElement - \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". - - This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. - - A Layout element is a rectangular object which can be placed in layouts. It has an outer rect - (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference - between outer and inner rect is called its margin. The margin can either be set to automatic or - manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be - set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, - the layout element subclass will control the value itself (via \ref calculateAutoMargin). - - Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level - layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref - QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. - - Thus in QCustomPlot one can divide layout elements into two categories: The ones that are - invisible by themselves, because they don't draw anything. Their only purpose is to manage the - position and size of other layout elements. This category of layout elements usually use - QCPLayout as base class. Then there is the category of layout elements which actually draw - something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does - not necessarily mean that the latter category can't have child layout elements. QCPLegend for - instance, actually derives from QCPLayoutGrid and the individual legend items are child layout - elements in the grid layout. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayout *QCPLayoutElement::layout() const - - Returns the parent layout of this layout element. -*/ - -/*! \fn QRect QCPLayoutElement::rect() const - - Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref - setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). - - In some cases, the area between outer and inner rect is left blank. In other cases the margin - area is used to display peripheral graphics while the main content is in the inner rect. This is - where automatic margin calculation becomes interesting because it allows the layout element to - adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect - draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if - \ref setAutoMargins is enabled) according to the space required by the labels of the axes. - - \see outerRect -*/ - -/*! \fn QRect QCPLayoutElement::outerRect() const - - Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the - margins (\ref setMargins, \ref setAutoMargins). The outer rect is used (and set via \ref - setOuterRect) by the parent \ref QCPLayout to control the size of this layout element. - - \see rect -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutElement and sets default values. -*/ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mSizeConstraintRect(scrInnerRect), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) -{ -} - -QCPLayoutElement::~QCPLayoutElement() -{ - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any - // unregister at layout: - if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); -} - -/*! - Sets the outer rect of this layout element. If the layout element is inside a layout, the layout - sets the position and size of this layout element using this function. - - Calling this function externally has no effect, since the layout will overwrite any changes to - the outer rect upon the next replot. - - The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. - - \see rect -*/ -void QCPLayoutElement::setOuterRect(const QRect &rect) -{ - if (mOuterRect != rect) - { - mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all - sides, this function is used to manually set the margin on those sides. Sides that are still set - to be handled automatically are ignored and may have any value in \a margins. - - The margin is the distance between the outer rect (controlled by the parent layout via \ref - setOuterRect) and the inner \ref rect (which usually contains the main content of this layout - element). - - \see setAutoMargins -*/ -void QCPLayoutElement::setMargins(const QMargins &margins) -{ - if (mMargins != margins) - { - mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - If \ref setAutoMargins is enabled on some or all margins, this function is used to provide - minimum values for those margins. - - The minimum values are not enforced on margin sides that were set to be under manual control via - \ref setAutoMargins. - - \see setAutoMargins -*/ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) -{ - if (mMinimumMargins != margins) - { - mMinimumMargins = margins; - } -} - -/*! - Sets on which sides the margin shall be calculated automatically. If a side is calculated - automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is - set to be controlled manually, the value may be specified with \ref setMargins. - - Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref - setMarginGroup), to synchronize (align) it with other layout elements in the plot. - - \see setMinimumMargins, setMargins, QCP::MarginSide -*/ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) -{ - mAutoMargins = sides; -} - -/*! - Sets the minimum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - If the parent layout size is not sufficient to satisfy all minimum size constraints of its child - layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot - propagates the layout's size constraints to the outside by setting its own minimum QWidget size - accordingly, so violations of \a size should be exceptions. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(const QSize &size) -{ - if (mMinimumSize != size) - { - mMinimumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the minimum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMinimumSize(int width, int height) -{ - setMinimumSize(QSize(width, height)); -} - -/*! - Sets the maximum size of this layout element. A parent layout tries to respect the \a size here - by changing row/column sizes in the layout accordingly. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(const QSize &size) -{ - if (mMaximumSize != size) - { - mMaximumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the maximum size of this layout element. - - Whether this constraint applies to the inner or the outer rect can be specified with \ref - setSizeConstraintRect (see \ref rect and \ref outerRect). -*/ -void QCPLayoutElement::setMaximumSize(int width, int height) -{ - setMaximumSize(QSize(width, height)); -} - -/*! - Sets to which rect of a layout element the size constraints apply. Size constraints can be set - via \ref setMinimumSize and \ref setMaximumSize. - - The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis - labels), whereas the inner rect (\ref rect) does not. - - \see setMinimumSize, setMaximumSize -*/ -void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) -{ - if (mSizeConstraintRect != constraintRect) - { - mSizeConstraintRect = constraintRect; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! - Sets the margin \a group of the specified margin \a sides. - - Margin groups allow synchronizing specified margins across layout elements, see the documentation - of \ref QCPMarginGroup. - - To unset the margin group of \a sides, set \a group to 0. - - Note that margin groups only work for margin sides that are set to automatic (\ref - setAutoMargins). - - \see QCP::MarginSide -*/ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) -{ - QVector sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; iremoveChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there - { - mMarginGroups.remove(side); - } else // setting to a new group - { - mMarginGroups[side] = group; - group->addChild(side, this); - } - } - } -} - -/*! - Updates the layout element and sub-elements. This function is automatically called before every - replot by the parent layout element. It is called multiple times, once for every \ref - UpdatePhase. The phases are run through in the order of the enum values. For details about what - happens at the different phases, see the documentation of \ref UpdatePhase. - - Layout elements that have child elements should call the \ref update method of their child - elements, and pass the current \a phase unchanged. - - The default implementation executes the automatic margin mechanism in the \ref upMargins phase. - Subclasses should make sure to call the base class implementation. -*/ -void QCPLayoutElement::update(UpdatePhase phase) -{ - if (phase == upMargins) - { - if (mAutoMargins != QCP::msNone) - { - // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: - QMargins newMargins = mMargins; - QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; - Q_FOREACH (QCP::MarginSide side, allMarginSides) - { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically - { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group - else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly - // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); - } - } - setMargins(newMargins); - } - } -} - -/*! - Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to, - if no manual minimum size is set. - - if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size - (usually indirectly through \ref QCPLayout::getFinalMinimumOuterSize) to determine the minimum - allowed size of this layout element. - - A manual minimum size is considered set if it is non-zero. - - The default implementation simply returns the sum of the horizontal margins for the width and the - sum of the vertical margins for the height. Reimplementations may use their detailed knowledge - about the layout element's content to provide size hints. -*/ -QSize QCPLayoutElement::minimumOuterSizeHint() const -{ - return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); -} - -/*! - Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to, - if no manual maximum size is set. - - if a maximum size (\ref setMaximumSize) was not set manually, parent layouts use the returned - size (usually indirectly through \ref QCPLayout::getFinalMaximumOuterSize) to determine the - maximum allowed size of this layout element. - - A manual maximum size is considered set if it is smaller than Qt's \c QWIDGETSIZE_MAX. - - The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying - no suggested maximum size. Reimplementations may use their detailed knowledge about the layout - element's content to provide size hints. -*/ -QSize QCPLayoutElement::maximumOuterSizeHint() const -{ - return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); -} - -/*! - Returns a list of all child elements in this layout element. If \a recursive is true, all - sub-child elements are included in the list, too. - - \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have - empty cells which yield 0 at the respective index.) -*/ -QList QCPLayoutElement::elements(bool recursive) const -{ - Q_UNUSED(recursive) - return QList(); -} - -/*! - Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer - rect, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is - true, -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. - - QCPLayoutElement subclasses may reimplement this method to provide more specific selection test - behaviour. -*/ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - - if (onlySelectable) - return -1; - - if (QRectF(mOuterRect).contains(pos)) - { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; - else - { - qDebug() << Q_FUNC_INFO << "parent plot not defined"; - return -1; - } - } else - return -1; -} - -/*! \internal - - propagates the parent plot initialization to all child elements, by calling \ref - QCPLayerable::initializeParentPlot on them. -*/ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_FOREACH (QCPLayoutElement* el, elements(false)) - { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); - } -} - -/*! \internal - - Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a - side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the - returned value will not be smaller than the specified minimum margin. - - The default implementation just returns the respective manual margin (\ref setMargins) or the - minimum margin, whichever is larger. -*/ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) -{ - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); -} - -/*! \internal - - This virtual method is called when this layout element was moved to a different QCPLayout, or - when this layout element has changed its logical position (e.g. row and/or column) within the - same QCPLayout. Subclasses may use this to react accordingly. - - Since this method is called after the completion of the move, you can access the new parent - layout via \ref layout(). - - The default implementation does nothing. -*/ -void QCPLayoutElement::layoutChanged() -{ -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayout -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayout - \brief The abstract base class for layouts - - This is an abstract base class for layout elements whose main purpose is to define the position - and size of other child layout elements. In most cases, layouts don't draw anything themselves - (but there are exceptions to this, e.g. QCPLegend). - - QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. - - QCPLayout introduces a common interface for accessing and manipulating the child elements. Those - functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref - simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions - to this interface which are more specialized to the form of the layout. For example, \ref - QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid - more conveniently. - - Since this is an abstract base class, you can't instantiate it directly. Rather use one of its - subclasses like QCPLayoutGrid or QCPLayoutInset. - - For a general introduction to the layout system, see the dedicated documentation page \ref - thelayoutsystem "The Layout System". -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPLayout::elementCount() const = 0 - - Returns the number of elements/cells in the layout. - - \see elements, elementAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 - - Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. - - Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. - QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check - whether a cell is empty or not. - - \see elements, elementCount, takeAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 - - Removes the element with the given \a index from the layout and returns it. - - If the \a index is invalid or the cell with that index is empty, returns 0. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see elementAt, take -*/ - -/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 - - Removes the specified \a element from the layout and returns true on success. - - If the \a element isn't in this layout, returns false. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see takeAt -*/ - -/* end documentation of pure virtual functions */ - -/*! - Creates an instance of QCPLayout and sets default values. Note that since QCPLayout - is an abstract base class, it can't be instantiated directly. -*/ -QCPLayout::QCPLayout() -{ -} - -/*! - If \a phase is \ref upLayout, calls \ref updateLayout, which subclasses may reimplement to - reposition and resize their cells. - - Finally, the call is propagated down to all child \ref QCPLayoutElement "QCPLayoutElements". - - For details about this method and the update phases, see the documentation of \ref - QCPLayoutElement::update. -*/ -void QCPLayout::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - // set child element rects according to layout: - if (phase == upLayout) - updateLayout(); - - // propagate update call to child elements: - const int elCount = elementCount(); - for (int i=0; iupdate(phase); - } -} - -/* inherits documentation from base class */ -QList QCPLayout::elements(bool recursive) const -{ - const int c = elementCount(); - QList result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the - default implementation does nothing. - - Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit - simplification while QCPLayoutGrid does. -*/ -void QCPLayout::simplify() -{ -} - -/*! - Removes and deletes the element at the provided \a index. Returns true on success. If \a index is - invalid or points to an empty cell, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the returned element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see remove, takeAt -*/ -bool QCPLayout::removeAt(int index) -{ - if (QCPLayoutElement *el = takeAt(index)) - { - delete el; - return true; - } else - return false; -} - -/*! - Removes and deletes the provided \a element. Returns true on success. If \a element is not in the - layout, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the element. Note that some layouts don't remove the respective cell right away but leave an - empty cell after successful removal of the layout element. To collapse empty cells, use \ref - simplify. - - \see removeAt, take -*/ -bool QCPLayout::remove(QCPLayoutElement *element) -{ - if (take(element)) - { - delete element; - return true; - } else - return false; -} - -/*! - Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure - all empty cells are collapsed. - - \see remove, removeAt -*/ -void QCPLayout::clear() -{ - for (int i=elementCount()-1; i>=0; --i) - { - if (elementAt(i)) - removeAt(i); - } - simplify(); -} - -/*! - Subclasses call this method to report changed (minimum/maximum) size constraints. - - If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref - sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of - QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, - it may update itself and resize cells accordingly. -*/ -void QCPLayout::sizeConstraintsChanged() const -{ - if (QWidget *w = qobject_cast(parent())) - w->updateGeometry(); - else if (QCPLayout *l = qobject_cast(parent())) - l->sizeConstraintsChanged(); -} - -/*! \internal - - Subclasses reimplement this method to update the position and sizes of the child elements/cells - via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. - - The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay - within that rect. - - \ref getSectionSizes may help with the reimplementation of this function. - - \see update -*/ -void QCPLayout::updateLayout() -{ -} - - -/*! \internal - - Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the - \ref QCPLayerable::parentLayerable and the QObject parent to this layout. - - Further, if \a el didn't previously have a parent plot, calls \ref - QCPLayerable::initializeParentPlot on \a el to set the paret plot. - - This method is used by subclass specific methods that add elements to the layout. Note that this - method only changes properties in \a el. The removal from the old layout and the insertion into - the new layout must be done additionally. -*/ -void QCPLayout::adoptElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); - el->layoutChanged(); - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout - and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent - QCustomPlot. - - This method is used by subclass specific methods that remove elements from the layout (e.g. \ref - take or \ref takeAt). Note that this method only changes properties in \a el. The removal from - the old layout must be done additionally. -*/ -void QCPLayout::releaseElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); - // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - This is a helper function for the implementation of \ref updateLayout in subclasses. - - It calculates the sizes of one-dimensional sections with provided constraints on maximum section - sizes, minimum section sizes, relative stretch factors and the final total size of all sections. - - The QVector entries refer to the sections. Thus all QVectors must have the same size. - - \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size - imposed, set all vector values to Qt's QWIDGETSIZE_MAX. - - \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size - imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than - \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, - not exceeding the allowed total size is taken to be more important than not going below minimum - section sizes.) - - \a stretchFactors give the relative proportions of the sections to each other. If all sections - shall be scaled equally, set all values equal. If the first section shall be double the size of - each individual other section, set the first number of \a stretchFactors to double the value of - the other individual values (e.g. {2, 1, 1, 1}). - - \a totalSize is the value that the final section sizes will add up to. Due to rounding, the - actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, - you could distribute the remaining difference on the sections. - - The return value is a QVector containing the section sizes. -*/ -QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const -{ - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) - { - qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; - return QVector(); - } - if (stretchFactors.isEmpty()) - return QVector(); - int sectionCount = stretchFactors.size(); - QVector sectionSizes(sectionCount); - // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): - int minSizeSum = 0; - for (int i=0; i minimumLockedSections; - QList unfinishedSections; - for (int i=0; i result(sectionCount); - for (int i=0; iminimumOuterSizeHint(); - QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) - if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rwidth() += el->margins().left() + el->margins().right(); - if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - minOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; -} - -/*! \internal - - This is a helper function for the implementation of subclasses. - - It returns the maximum size that should finally be used for the outer rect of the passed layout - element \a el. - - It takes into account whether a manual maximum size is set (\ref - QCPLayoutElement::setMaximumSize), which size constraint is set (\ref - QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum - size was set (\ref QCPLayoutElement::maximumOuterSizeHint). -*/ -QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) -{ - QSize maxOuterHint = el->maximumOuterSizeHint(); - QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) - if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rwidth() += el->margins().left() + el->margins().right(); - if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) - maxOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutGrid - \brief A layout that arranges child elements in a grid - - Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, - \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). - - Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or - column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref - hasElement, that element can be retrieved with \ref element. If rows and columns that only have - empty cells shall be removed, call \ref simplify. Removal of elements is either done by just - adding the element to a different layout or by using the QCPLayout interface \ref take or \ref - remove. - - If you use \ref addElement(QCPLayoutElement*) without explicit parameters for \a row and \a - column, the grid layout will choose the position according to the current \ref setFillOrder and - the wrapping (\ref setWrap). - - Row and column insertion can be performed with \ref insertRow and \ref insertColumn. -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPLayoutGrid::rowCount() const - - Returns the number of rows in the layout. - - \see columnCount -*/ - -/*! \fn int QCPLayoutGrid::columnCount() const - - Returns the number of columns in the layout. - - \see rowCount -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutGrid and sets default values. -*/ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5), - mWrap(0), - mFillOrder(foRowsFirst) -{ -} - -QCPLayoutGrid::~QCPLayoutGrid() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the element in the cell in \a row and \a column. - - Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug - message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. - - \see addElement, hasElement -*/ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const -{ - if (row >= 0 && row < mElements.size()) - { - if (column >= 0 && column < mElements.first().size()) - { - if (QCPLayoutElement *result = mElements.at(row).at(column)) - return result; - else - qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; - return 0; -} - - -/*! \overload - - Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it - is first removed from there. If \a row or \a column don't exist yet, the layout is expanded - accordingly. - - Returns true if the element was added successfully, i.e. if the cell at \a row and \a column - didn't already have an element. - - Use the overload of this method without explicit row/column index to place the element according - to the configured fill order and wrapping settings. - - \see element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) -{ - if (!hasElement(row, column)) - { - if (element && element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); - mElements[row][column] = element; - if (element) - adoptElement(element); - return true; - } else - qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; - return false; -} - -/*! \overload - - Adds the \a element to the next empty cell according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap). If \a element is already in a layout, it is first - removed from there. If necessary, the layout is expanded to hold the new element. - - Returns true if the element was added successfully. - - \see setFillOrder, setWrap, element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(QCPLayoutElement *element) -{ - int rowIndex = 0; - int colIndex = 0; - if (mFillOrder == foColumnsFirst) - { - while (hasElement(rowIndex, colIndex)) - { - ++colIndex; - if (colIndex >= mWrap && mWrap > 0) - { - colIndex = 0; - ++rowIndex; - } - } - } else - { - while (hasElement(rowIndex, colIndex)) - { - ++rowIndex; - if (rowIndex >= mWrap && mWrap > 0) - { - rowIndex = 0; - ++colIndex; - } - } - } - return addElement(rowIndex, colIndex, element); -} - -/*! - Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't - empty. - - \see element -*/ -bool QCPLayoutGrid::hasElement(int row, int column) -{ - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); - else - return false; -} - -/*! - Sets the stretch \a factor of \a column. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) -{ - if (column >= 0 && column < columnCount()) - { - if (factor > 0) - mColumnStretchFactors[column] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid column:" << column; -} - -/*! - Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactor, setRowStretchFactors -*/ -void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) -{ - if (factors.size() == mColumnStretchFactors.size()) - { - mColumnStretchFactors = factors; - for (int i=0; i= 0 && row < rowCount()) - { - if (factor > 0) - mRowStretchFactors[row] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid row:" << row; -} - -/*! - Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights, regardless of the stretch factor. (see \ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize, \ref - QCPLayoutElement::setSizeConstraintRect.) - - The default stretch factor of newly created rows/columns is 1. - - \see setRowStretchFactor, setColumnStretchFactors -*/ -void QCPLayoutGrid::setRowStretchFactors(const QList &factors) -{ - if (factors.size() == mRowStretchFactors.size()) - { - mRowStretchFactors = factors; - for (int i=0; i tempElements; - if (rearrange) - { - tempElements.reserve(elCount); - for (int i=0; i()); - mRowStretchFactors.append(1); - } - // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i rowCount()) - newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); - QList newRow; - for (int col=0; col columnCount()) - newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row= 0 && row < rowCount()) - { - if (column >= 0 && column < columnCount()) - { - switch (mFillOrder) - { - case foRowsFirst: return column*rowCount() + row; - case foColumnsFirst: return row*columnCount() + column; - } - } else - qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; - } else - qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; - return 0; -} - -/*! - Converts the linear index to row and column indices and writes the result to \a row and \a - column. - - The way the cells are indexed depends on \ref setFillOrder. If it is \ref foRowsFirst, the - indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices - increase top to bottom and then left to right. - - If there are no cells (i.e. column or row count is zero), sets \a row and \a column to -1. - - For the retrieved \a row and \a column to be valid, the passed \a index must be valid itself, - i.e. greater or equal to zero and smaller than the current \ref elementCount. - - \see rowColToIndex -*/ -void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const -{ - row = -1; - column = -1; - const int nCols = columnCount(); - const int nRows = rowCount(); - if (nCols == 0 || nRows == 0) - return; - if (index < 0 || index >= elementCount()) - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return; - } - - switch (mFillOrder) - { - case foRowsFirst: - { - column = index / nRows; - row = index % nRows; - break; - } - case foColumnsFirst: - { - row = index / nCols; - column = index % nCols; - break; - } - } -} - -/* inherits documentation from base class */ -void QCPLayoutGrid::updateLayout() -{ - QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - - // go through cells and set rects accordingly: - int yOffset = mRect.top(); - for (int row=0; row 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; - int xOffset = mRect.left(); - for (int col=0; col 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); - } - } -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const -{ - if (index >= 0 && index < elementCount()) - { - int row, col; - indexToRowCol(index, row, col); - return mElements.at(row).at(col); - } else - return 0; -} - -/*! - \seebaseclassmethod - - Note that the association of the linear \a index to the row/column based cells depends on the - current setting of \ref setFillOrder. - - \see rowColToIndex -*/ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - int row, col; - indexToRowCol(index, row, col); - mElements[row][col] = 0; - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i QCPLayoutGrid::elements(bool recursive) const -{ - QList result; - const int elCount = elementCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(elCount); -#endif - for (int i=0; ielements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing rows and columns which only contain empty cells. -*/ -void QCPLayoutGrid::simplify() -{ - // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) - { - bool hasElements = false; - for (int col=0; col=0; --col) - { - bool hasElements = false; - for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i QWIDGETSIZE_MAX) - result.setHeight(QWIDGETSIZE_MAX); - if (result.width() > QWIDGETSIZE_MAX) - result.setWidth(QWIDGETSIZE_MAX); - return result; -} - -/*! \internal - - Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights - respectively. - - The minimum height of a row is the largest minimum height of any element's outer rect in that - row. The minimum width of a column is the largest minimum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMaximumRowColSizes -*/ -void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const -{ - *minColWidths = QVector(columnCount(), 0); - *minRowHeights = QVector(rowCount(), 0); - for (int row=0; rowat(col) < minSize.width()) - (*minColWidths)[col] = minSize.width(); - if (minRowHeights->at(row) < minSize.height()) - (*minRowHeights)[row] = minSize.height(); - } - } - } -} - -/*! \internal - - Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights - respectively. - - The maximum height of a row is the smallest maximum height of any element's outer rect in that - row. The maximum width of a column is the smallest maximum width of any element's outer rect in - that column. - - This is a helper function for \ref updateLayout. - - \see getMinimumRowColSizes -*/ -void QCPLayoutGrid::getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const -{ - *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; rowat(col) > maxSize.width()) - (*maxColWidths)[col] = maxSize.width(); - if (maxRowHeights->at(row) > maxSize.height()) - (*maxRowHeights)[row] = maxSize.height(); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutInset -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPLayoutInset - \brief A layout that places child elements aligned to the border or arbitrarily positioned - - Elements are placed either aligned to the border or at arbitrary position in the area of the - layout. Which placement applies is controlled with the \ref InsetPlacement (\ref - setInsetPlacement). - - Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or - addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset - placement will default to \ref ipBorderAligned and the element will be aligned according to the - \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at - arbitrary position and size, defined by \a rect. - - The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. - - This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual void QCPLayoutInset::simplify() - - The QCPInsetLayout does not need simplification since it can never have empty cells due to its - linear index structure. This method does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutInset and sets default values. -*/ -QCPLayoutInset::QCPLayoutInset() -{ -} - -QCPLayoutInset::~QCPLayoutInset() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the placement type of the element with the specified \a index. -*/ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const -{ - if (elementAt(index)) - return mInsetPlacement.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return ipFree; - } -} - -/*! - Returns the alignment of the element with the specified \a index. The alignment only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. -*/ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const -{ - if (elementAt(index)) - return mInsetAlignment.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return 0; - } -} - -/*! - Returns the rect of the element with the specified \a index. The rect only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. -*/ -QRectF QCPLayoutInset::insetRect(int index) const -{ - if (elementAt(index)) - return mInsetRect.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return QRectF(); - } -} - -/*! - Sets the inset placement type of the element with the specified \a index to \a placement. - - \see InsetPlacement -*/ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) -{ - if (elementAt(index)) - mInsetPlacement[index] = placement; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function - is used to set the alignment of the element with the specified \a index to \a alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. -*/ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) -{ - if (elementAt(index)) - mInsetAlignment[index] = alignment; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the - position and size of the element with the specified \a index to \a rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - Note that the minimum and maximum sizes of the embedded element (\ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. -*/ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) -{ - if (elementAt(index)) - mInsetRect[index] = rect; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/* inherits documentation from base class */ -void QCPLayoutInset::updateLayout() -{ - for (int i=0; i finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter - } - mElements.at(i)->setOuterRect(insetRect); - } -} - -/* inherits documentation from base class */ -int QCPLayoutInset::elementCount() const -{ - return mElements.size(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const -{ - if (index >= 0 && index < mElements.size()) - return mElements.at(index); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! - Adds the specified \a element to the layout as an inset aligned at the border (\ref - setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a - alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. - - \see addElement(QCPLayoutElement *element, const QRectF &rect) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - -/*! - Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref - setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a - rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} -/* end of 'src/layout.cpp' */ - - -/* including file 'src/lineending.cpp', size 11536 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLineEnding -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLineEnding - \brief Handles the different ending decorations for line-like items - - \image html QCPLineEnding.png "The various ending styles currently supported" - - For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine - has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. - - The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can - be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of - the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. - For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite - directions, e.g. "outward". This can be changed by \ref setInverted, which would make the - respective arrow point inward. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify a - QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. - \snippet documentation/doc-code-snippets/mainwindow.cpp qcplineending-sethead -*/ - -/*! - Creates a QCPLineEnding instance with default values (style \ref esNone). -*/ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) -{ -} - -/*! - Creates a QCPLineEnding instance with the specified values. -*/ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) -{ -} - -/*! - Sets the style of the ending decoration. -*/ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) -{ - mStyle = style; -} - -/*! - Sets the width of the ending decoration, if the style supports it. On arrows, for example, the - width defines the size perpendicular to the arrow's pointing direction. - - \see setLength -*/ -void QCPLineEnding::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the length of the ending decoration, if the style supports it. On arrows, for example, the - length defines the size in pointing direction. - - \see setWidth -*/ -void QCPLineEnding::setLength(double length) -{ - mLength = length; -} - -/*! - Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point - inward when \a inverted is set to true. - - Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or - discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are - affected by it, which can be used to control to which side the half bar points to. -*/ -void QCPLineEnding::setInverted(bool inverted) -{ - mInverted = inverted; -} - -/*! \internal - - Returns the maximum pixel radius the ending decoration might cover, starting from the position - the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). - - This is relevant for clipping. Only omit painting of the decoration when the position where the - decoration is supposed to be drawn is farther away from the clipping rect than the returned - distance. -*/ -double QCPLineEnding::boundingDistance() const -{ - switch (mStyle) - { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) - - } - return 0; -} - -/*! - Starting from the origin of this line ending (which is style specific), returns the length - covered by the line ending symbol, in backward direction. - - For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if - both have the same \ref setLength value, because the spike arrow has an inward curved back, which - reduces the length along its center axis (the drawing origin for arrows is at the tip). - - This function is used for precise, style specific placement of line endings, for example in - QCPAxes. -*/ -double QCPLineEnding::realLength() const -{ - switch (mStyle) - { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; - } - return 0; -} - -/*! \internal - - Draws the line ending with the specified \a painter at the position \a pos. The direction of the - line ending is controlled with \a dir. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const -{ - if (mStyle == esNone) - return; - - QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); - if (lengthVec.isNull()) - lengthVec = QCPVector2D(1, 0); - QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); - - QPen penBackup = painter->pen(); - QBrush brushBackup = painter->brush(); - QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) - { - case esNone: break; - case esFlatArrow: - { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esSpikeArrow: - { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; - } - } -} - -/*! \internal - \overload - - Draws the line ending. The direction is controlled with the \a angle parameter in radians. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const -{ - draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); -} -/* end of 'src/lineending.cpp' */ - - -/* including file 'src/axis/axisticker.cpp', size 18664 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTicker -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTicker - \brief The base class tick generator used by QCPAxis to create tick positions and tick labels - - Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions - and tick labels for the current axis range. The ticker of an axis can be set via \ref - QCPAxis::setTicker. Since that method takes a QSharedPointer, multiple - axes can share the same ticker instance. - - This base class generates normal tick coordinates and numeric labels for linear axes. It picks a - reasonable tick step (the separation between ticks) which results in readable tick labels. The - number of ticks that should be approximately generated can be set via \ref setTickCount. - Depending on the current tick step strategy (\ref setTickStepStrategy), the algorithm either - sacrifices readability to better match the specified tick count (\ref - QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (\ref - QCPAxisTicker::tssReadability), which is the default. - - The following more specialized axis ticker subclasses are available, see details in the - respective class documentation: - -
- - - - - - - -
QCPAxisTickerFixed\image html axisticker-fixed.png
QCPAxisTickerLog\image html axisticker-log.png
QCPAxisTickerPi\image html axisticker-pi.png
QCPAxisTickerText\image html axisticker-text.png
QCPAxisTickerDateTime\image html axisticker-datetime.png
QCPAxisTickerTime\image html axisticker-time.png - \image html axisticker-time2.png
-
- - \section axisticker-subclassing Creating own axis tickers - - Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and - reimplementing some or all of the available virtual methods. - - In the simplest case you might wish to just generate different tick steps than the other tickers, - so you only reimplement the method \ref getTickStep. If you additionally want control over the - string that will be shown as tick label, reimplement \ref getTickLabel. - - If you wish to have complete control, you can generate the tick vectors and tick label vectors - yourself by reimplementing \ref createTickVector and \ref createLabelVector. The default - implementations use the previously mentioned virtual methods \ref getTickStep and \ref - getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case - of unequal tick steps, the method \ref getTickStep loses its usefulness and can be ignored. - - The sub tick count between major ticks can be controlled with \ref getSubTickCount. Full sub tick - placement control is obtained by reimplementing \ref createSubTickVector. - - See the documentation of all these virtual methods in QCPAxisTicker for detailed information - about the parameters and expected return values. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTicker::QCPAxisTicker() : - mTickStepStrategy(tssReadability), - mTickCount(5), - mTickOrigin(0) -{ -} - -QCPAxisTicker::~QCPAxisTicker() -{ - -} - -/*! - Sets which strategy the axis ticker follows when choosing the size of the tick step. For the - available strategies, see \ref TickStepStrategy. -*/ -void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) -{ - mTickStepStrategy = strategy; -} - -/*! - Sets how many ticks this ticker shall aim to generate across the axis range. Note that \a count - is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with - the requested number of ticks. - - Whether the readability has priority over meeting the requested \a count can be specified with - \ref setTickStepStrategy. -*/ -void QCPAxisTicker::setTickCount(int count) -{ - if (count > 0) - mTickCount = count; - else - qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; -} - -/*! - Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a - concept and doesn't need to be inside the currently visible axis range. - - By default \a origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick - step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be - {-4, 1, 6, 11, 16,...}. -*/ -void QCPAxisTicker::setTickOrigin(double origin) -{ - mTickOrigin = origin; -} - -/*! - This is the method called by QCPAxis in order to actually generate tick coordinates (\a ticks), - tick label strings (\a tickLabels) and sub tick coordinates (\a subTicks). - - The ticks are generated for the specified \a range. The generated labels typically follow the - specified \a locale, \a formatChar and number \a precision, however this might be different (or - even irrelevant) for certain QCPAxisTicker subclasses. - - The output parameter \a ticks is filled with the generated tick positions in axis coordinates. - The output parameters \a subTicks and \a tickLabels are optional (set them to 0 if not needed) - and are respectively filled with sub tick coordinates, and tick label strings belonging to \a - ticks by index. -*/ -void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) -{ - // generate (major) ticks: - double tickStep = getTickStep(range); - ticks = createTickVector(tickStep, range); - trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) - - // generate sub ticks between major ticks: - if (subTicks) - { - if (ticks.size() > 0) - { - *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); - trimTicks(range, *subTicks, false); - } else - *subTicks = QVector(); - } - - // finally trim also outliers (no further clipping happens in axis drawing): - trimTicks(range, ticks, false); - // generate labels for visible ticks if requested: - if (tickLabels) - *tickLabels = createLabelVector(ticks, locale, formatChar, precision); -} - -/*! \internal - - Takes the entire currently visible axis range and returns a sensible tick step in - order to provide readable tick labels as well as a reasonable number of tick counts (see \ref - setTickCount, \ref setTickStepStrategy). - - If a QCPAxisTicker subclass only wants a different tick step behaviour than the default - implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper - function. -*/ -double QCPAxisTicker::getTickStep(const QCPRange &range) -{ - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return cleanMantissa(exactStep); -} - -/*! \internal - - Takes the \a tickStep, i.e. the distance between two consecutive ticks, and returns - an appropriate number of sub ticks for that specific tick step. - - Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. -*/ -int QCPAxisTicker::getSubTickCount(double tickStep) -{ - int result = 1; // default to 1, if no proper value can be found - - // separate integer and fractional part of mantissa: - double epsilon = 0.01; - double intPartf; - int intPart; - double fracPart = modf(getMantissa(tickStep), &intPartf); - intPart = intPartf; - - // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) - { - if (1.0-fracPart < epsilon) - ++intPart; - switch (intPart) - { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep - } - } else - { - // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa - { - switch (intPart) - { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep - } - } - // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default - } - - return result; -} - -/*! \internal - - This method returns the tick label string as it should be printed under the \a tick coordinate. - If a textual number is returned, it should respect the provided \a locale, \a formatChar and \a - precision. - - If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is - enabled in the QCPAxis number format (\ref QCPAxis::setNumberFormat), the exponential part will - be formatted accordingly using multiplication symbol and superscript during rendering of the - label automatically. -*/ -QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - return locale.toString(tick, formatChar.toLatin1(), precision); -} - -/*! \internal - - Returns a vector containing all coordinates of sub ticks that should be drawn. It generates \a - subTickCount sub ticks between each tick pair given in \a ticks. - - If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should - reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to - base its result on \a subTickCount or \a ticks. -*/ -QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) -{ - QVector result; - if (subTickCount <= 0 || ticks.size() < 2) - return result; - - result.reserve((ticks.size()-1)*subTickCount); - for (int i=1; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result; - // Generate tick positions according to tickStep: - qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - result.resize(tickcount); - for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) -{ - QVector result; - result.reserve(ticks.size()); - for (int i=0; i &ticks, bool keepOneOutlier) const -{ - bool lowFound = false; - bool highFound = false; - int lowIndex = 0; - int highIndex = -1; - - for (int i=0; i < ticks.size(); ++i) - { - if (ticks.at(i) >= range.lower) - { - lowFound = true; - lowIndex = i; - break; - } - } - for (int i=ticks.size()-1; i >= 0; --i) - { - if (ticks.at(i) <= range.upper) - { - highFound = true; - highIndex = i; - break; - } - } - - if (highFound && lowFound) - { - int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); - int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); - if (trimFront > 0 || trimBack > 0) - ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); - } else // all ticks are either all below or all above the range - ticks.clear(); -} - -/*! \internal - - Returns the coordinate contained in \a candidates which is closest to the provided \a target. - - This method assumes \a candidates is not empty and sorted in ascending order. -*/ -double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const -{ - if (candidates.size() == 1) - return candidates.first(); - QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); - if (it == candidates.constEnd()) - return *(it-1); - else if (it == candidates.constBegin()) - return *it; - else - return target-*(it-1) < *it-target ? *(it-1) : *it; -} - -/*! \internal - - Returns the decimal mantissa of \a input. Optionally, if \a magnitude is not set to zero, it also - returns the magnitude of \a input as a power of 10. - - For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. -*/ -double QCPAxisTicker::getMantissa(double input, double *magnitude) const -{ - const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); - if (magnitude) *magnitude = mag; - return input/mag; -} - -/*! \internal - - Returns a number that is close to \a input but has a clean, easier human readable mantissa. How - strongly the mantissa is altered, and thus how strong the result deviates from the original \a - input, depends on the current tick step strategy (see \ref setTickStepStrategy). -*/ -double QCPAxisTicker::cleanMantissa(double input) const -{ - double magnitude; - const double mantissa = getMantissa(input, &magnitude); - switch (mTickStepStrategy) - { - case tssReadability: - { - return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; - } - case tssMeetTickCount: - { - // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 - if (mantissa <= 5.0) - return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 - else - return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 - } - } - return input; -} -/* end of 'src/axis/axisticker.cpp' */ - - -/* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerDateTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerDateTime - \brief Specialized axis ticker for calendar dates and times as axis ticks - - \image html axisticker-datetime.png - - This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The - plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 - UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t() methods - with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime - by using QDateTime::fromMSecsSinceEpoch()/1000.0. The static methods \ref dateTimeToKey - and \ref keyToDateTime conveniently perform this conversion achieving a precision of one - millisecond on all Qt versions. - - The format of the date/time display in the tick labels is controlled with \ref setDateTimeFormat. - If a different time spec (time zone) shall be used, see \ref setDateTimeSpec. - - This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day - ticks. For example, if the axis range spans a few years such that there is one tick per year, - ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, - will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in - the image above: even though the number of days varies month by month, this ticker generates - ticks on the same day of each month. - - If you would like to change the date/time that is used as a (mathematical) starting date for the - ticks, use the \ref setTickOrigin(const QDateTime &origin) method overload, which takes a - QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at - 9:45 of every year. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerdatetime-creation - - \note If you rather wish to display relative times in terms of days, hours, minutes, seconds and - milliseconds, and are not interested in the intricacies of real calendar dates with months and - (leap) years, have a look at QCPAxisTickerTime instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerDateTime::QCPAxisTickerDateTime() : - mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), - mDateTimeSpec(Qt::LocalTime), - mDateStrategy(dsNone) -{ - setTickCount(4); -} - -/*! - Sets the format in which dates and times are displayed as tick labels. For details about the \a - format string, see the documentation of QDateTime::toString(). - - Newlines can be inserted with "\n". - - \see setDateTimeSpec -*/ -void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) -{ - mDateTimeFormat = format; -} - -/*! - Sets the time spec that is used for creating the tick labels from corresponding dates/times. - - The default value of QDateTime objects (and also QCPAxisTickerDateTime) is - Qt::LocalTime. However, if the date time values passed to QCustomPlot (e.g. in the form - of axis ranges or keys of a plottable) are given in the UTC spec, set \a spec to Qt::UTC - to get the correct axis labels. - - \see setDateTimeFormat -*/ -void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) -{ - mDateTimeSpec = spec; -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, - 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which - directly takes a QDateTime, see \ref setTickOrigin(const QDateTime &origin). - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(double origin) -{ - QCPAxisTicker::setTickOrigin(origin); -} - -/*! - Sets the tick origin (see \ref QCPAxisTicker::setTickOrigin) as a QDateTime \a origin. - - This is useful to define the month/day/time recurring at greater tick interval steps. For - example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick - per year, the ticks will end up on 15. July at 9:45 of every year. -*/ -void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) -{ - setTickOrigin(dateTimeToKey(origin)); -} - -/*! \internal - - Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - Note that this tick step isn't used exactly when generating the tick vector in \ref - createTickVector, but only as a guiding value requiring some correction for each individual tick - interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day - in the month to the last day in the previous month from tick to tick, due to the non-uniform - length of months. The same problem arises with leap years. - - \seebaseclassmethod -*/ -double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - mDateStrategy = dsNone; - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - result = cleanMantissa(result); - } else if (result < 86400*30.4375*12) // below a year - { - result = pickClosest(result, QVector() - << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range - << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range - << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) - if (result > 86400*30.4375-1) // month tick intervals or larger - mDateStrategy = dsUniformDayInMonth; - else if (result > 3600*24-1) // day tick intervals or larger - mDateStrategy = dsUniformTimeInDay; - } else // more than a year, go back to normal clean mantissa algorithm but in units of years - { - const double secondsPerYear = 86400*30.4375*12; // average including leap years - result = cleanMantissa(result/secondsPerYear)*secondsPerYear; - mDateStrategy = dsUniformDayInMonth; - } - return result; -} - -/*! \internal - - Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, - monthly, bi-monthly, etc. - - \seebaseclassmethod -*/ -int QCPAxisTickerDateTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - case 86400*2: result = 1; break; - case 86400*5: result = 4; break; - case 86400*7: result = 6; break; - case 86400*14: result = 1; break; - case (int)(86400*30.4375+0.5): result = 3; break; - case (int)(86400*30.4375*2+0.5): result = 1; break; - case (int)(86400*30.4375*3+0.5): result = 2; break; - case (int)(86400*30.4375*6+0.5): result = 5; break; - case (int)(86400*30.4375*12+0.5): result = 3; break; - } - return result; -} - -/*! \internal - - Generates a date/time tick label for tick coordinate \a tick, based on the currently set format - (\ref setDateTimeFormat) and time spec (\ref setDateTimeSpec). - - \seebaseclassmethod -*/ -QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -} - -/*! \internal - - Uses the passed \a tickStep as a guiding value and applies corrections in order to obtain - non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month. - - \seebaseclassmethod -*/ -QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) -{ - QVector result = QCPAxisTicker::createTickVector(tickStep, range); - if (!result.isEmpty()) - { - if (mDateStrategy == dsUniformTimeInDay) - { - QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible - QDateTime tickDateTime; - for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day - tickDateTime = tickDateTime.addMonths(-1); - tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); - result[i] = dateTimeToKey(tickDateTime); - } - } - } - return result; -} - -/*! - A convenience method which turns \a key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a - QDateTime object. This can be used to turn axis coordinates to actual QDateTimes. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6) - - \see dateTimeToKey -*/ -QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); -# else - return QDateTime::fromMSecsSinceEpoch(key*1000.0); -# endif -} - -/*! \overload - - A convenience method which turns a QDateTime object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it - works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6) - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return dateTime.toTime_t()+dateTime.time().msec()/1000.0; -# else - return dateTime.toMSecsSinceEpoch()/1000.0; -# endif -} - -/*! \overload - - A convenience method which turns a QDate object into a double value that corresponds to - seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by - QCPAxisTickerDateTime. - - \see keyToDateTime -*/ -double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) -{ -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime(date).toTime_t(); -# else - return QDateTime(date).toMSecsSinceEpoch()/1000.0; -# endif -} -/* end of 'src/axis/axistickerdatetime.cpp' */ - - -/* including file 'src/axis/axistickertime.cpp', size 11747 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerTime -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerTime - \brief Specialized axis ticker for time spans in units of milliseconds to days - - \image html axisticker-time.png - - This QCPAxisTicker subclass generates ticks that corresponds to time intervals. - - The format of the time display in the tick labels is controlled with \ref setTimeFormat and \ref - setFieldWidth. The time coordinate is in the unit of seconds with respect to the time coordinate - zero. Unlike with QCPAxisTickerDateTime, the ticks don't correspond to a specific calendar date - and time. - - The time can be displayed in milliseconds, seconds, minutes, hours and days. Depending on the - largest available unit in the format specified with \ref setTimeFormat, any time spans above will - be carried in that largest unit. So for example if the format string is "%m:%s" and a tick at - coordinate value 7815 (being 2 hours, 10 minutes and 15 seconds) is created, the resulting tick - label will show "130:15" (130 minutes, 15 seconds). If the format string is "%h:%m:%s", the hour - unit will be used and the label will thus be "02:10:15". Negative times with respect to the axis - zero will carry a leading minus sign. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation - - Here is an example of a time axis providing time information in days, hours and minutes. Due to - the axis range spanning a few days and the wanted tick count (\ref setTickCount), the ticker - decided to use tick steps of 12 hours: - - \image html axisticker-time2.png - - The format string for this example is - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertime-creation-2 - - \note If you rather wish to display calendar dates and times, have a look at QCPAxisTickerDateTime - instead. -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerTime::QCPAxisTickerTime() : - mTimeFormat(QLatin1String("%h:%m:%s")), - mSmallestUnit(tuSeconds), - mBiggestUnit(tuHours) -{ - setTickCount(4); - mFieldWidth[tuMilliseconds] = 3; - mFieldWidth[tuSeconds] = 2; - mFieldWidth[tuMinutes] = 2; - mFieldWidth[tuHours] = 2; - mFieldWidth[tuDays] = 1; - - mFormatPattern[tuMilliseconds] = QLatin1String("%z"); - mFormatPattern[tuSeconds] = QLatin1String("%s"); - mFormatPattern[tuMinutes] = QLatin1String("%m"); - mFormatPattern[tuHours] = QLatin1String("%h"); - mFormatPattern[tuDays] = QLatin1String("%d"); -} - -/*! - Sets the format that will be used to display time in the tick labels. - - The available patterns are: - - %%z for milliseconds - - %%s for seconds - - %%m for minutes - - %%h for hours - - %%d for days - - The field width (zero padding) can be controlled for each unit with \ref setFieldWidth. - - The largest unit that appears in \a format will carry all the remaining time of a certain tick - coordinate, even if it overflows the natural limit of the unit. For example, if %%m is the - largest unit it might become larger than 59 in order to consume larger time values. If on the - other hand %%h is available, the minutes will wrap around to zero after 59 and the time will - carry to the hour digit. -*/ -void QCPAxisTickerTime::setTimeFormat(const QString &format) -{ - mTimeFormat = format; - - // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest - // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) - mSmallestUnit = tuMilliseconds; - mBiggestUnit = tuMilliseconds; - bool hasSmallest = false; - for (int i = tuMilliseconds; i <= tuDays; ++i) - { - TimeUnit unit = static_cast(i); - if (mTimeFormat.contains(mFormatPattern.value(unit))) - { - if (!hasSmallest) - { - mSmallestUnit = unit; - hasSmallest = true; - } - mBiggestUnit = unit; - } - } -} - -/*! - Sets the field widh of the specified \a unit to be \a width digits, when displayed in the tick - label. If the number for the specific unit is shorter than \a width, it will be padded with an - according number of zeros to the left in order to reach the field width. - - \see setTimeFormat -*/ -void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) -{ - mFieldWidth[unit] = qMax(width, 1); -} - -/*! \internal - - Returns the tick step appropriate for time displays, depending on the provided \a range and the - smallest available time unit in the current format (\ref setTimeFormat). For example if the unit - of seconds isn't available in the format, this method will not generate steps (like 2.5 minutes) - that require sub-minute precision to be displayed correctly. - - \seebaseclassmethod -*/ -double QCPAxisTickerTime::getTickStep(const QCPRange &range) -{ - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds - { - if (mSmallestUnit == tuMilliseconds) - result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond - else // have no milliseconds available in format, so stick with 1 second tickstep - result = 1.0; - } else if (result < 3600*24) // below a day - { - // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run - QVector availableSteps; - // seconds range: - if (mSmallestUnit <= tuSeconds) - availableSteps << 1; - if (mSmallestUnit == tuMilliseconds) - availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it - else if (mSmallestUnit == tuSeconds) - availableSteps << 2; - if (mSmallestUnit <= tuSeconds) - availableSteps << 5 << 10 << 15 << 30; - // minutes range: - if (mSmallestUnit <= tuMinutes) - availableSteps << 1*60; - if (mSmallestUnit <= tuSeconds) - availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it - else if (mSmallestUnit == tuMinutes) - availableSteps << 2*60; - if (mSmallestUnit <= tuMinutes) - availableSteps << 5*60 << 10*60 << 15*60 << 30*60; - // hours range: - if (mSmallestUnit <= tuHours) - availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; - // pick available step that is most appropriate to approximate ideal step: - result = pickClosest(result, availableSteps); - } else // more than a day, go back to normal clean mantissa algorithm but in units of days - { - const double secondsPerDay = 3600*24; - result = cleanMantissa(result/secondsPerDay)*secondsPerDay; - } - return result; -} - -/*! \internal - - Returns the sub tick count appropriate for the provided \a tickStep and time displays. - - \seebaseclassmethod -*/ -int QCPAxisTickerTime::getSubTickCount(double tickStep) -{ - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) - { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - } - return result; -} - -/*! \internal - - Returns the tick label corresponding to the provided \a tick and the configured format and field - widths (\ref setTimeFormat, \ref setFieldWidth). - - \seebaseclassmethod -*/ -QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - Q_UNUSED(precision) - Q_UNUSED(formatChar) - Q_UNUSED(locale) - bool negative = tick < 0; - if (negative) tick *= -1; - double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) - double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time - - restValues[tuMilliseconds] = tick*1000; - values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; - values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; - values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; - values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; - // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) - - QString result = mTimeFormat; - for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) - { - TimeUnit iUnit = static_cast(i); - replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); - } - if (negative) - result.prepend(QLatin1Char('-')); - return result; -} - -/*! \internal - - Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified - \a value, using the field width as specified with \ref setFieldWidth for the \a unit. -*/ -void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const -{ - QString valueStr = QString::number(value); - while (valueStr.size() < mFieldWidth.value(unit)) - valueStr.prepend(QLatin1Char('0')); - - text.replace(mFormatPattern.value(unit), valueStr); -} -/* end of 'src/axis/axistickertime.cpp' */ - - -/* including file 'src/axis/axistickerfixed.cpp', size 5583 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerFixed -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerFixed - \brief Specialized axis ticker with a fixed tick step - - \image html axisticker-fixed.png - - This QCPAxisTicker subclass generates ticks with a fixed tick step set with \ref setTickStep. It - is also possible to allow integer multiples and integer powers of the specified tick step with - \ref setScaleStrategy. - - A typical application of this ticker is to make an axis only display integers, by setting the - tick step of the ticker to 1.0 and the scale strategy to \ref ssMultiples. - - Another case is when a certain number has a special meaning and axis ticks should only appear at - multiples of that value. In this case you might also want to consider \ref QCPAxisTickerPi - because despite the name it is not limited to only pi symbols/values. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerfixed-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerFixed::QCPAxisTickerFixed() : - mTickStep(1.0), - mScaleStrategy(ssNone) -{ -} - -/*! - Sets the fixed tick interval to \a step. - - The axis ticker will only use this tick step when generating axis ticks. This might cause a very - high tick density and overlapping labels if the axis range is zoomed out. Using \ref - setScaleStrategy it is possible to relax the fixed step and also allow multiples or powers of \a - step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref - setTickCount). -*/ -void QCPAxisTickerFixed::setTickStep(double step) -{ - if (step > 0) - mTickStep = step; - else - qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; -} - -/*! - Sets whether the specified tick step (\ref setTickStep) is absolutely fixed or whether - modifications may be applied to it before calculating the finally used tick step, such as - permitting multiples or powers. See \ref ScaleStrategy for details. - - The default strategy is \ref ssNone, which means the tick step is absolutely fixed. -*/ -void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) -{ - mScaleStrategy = strategy; -} - -/*! \internal - - Determines the actually used tick step from the specified tick step and scale strategy (\ref - setTickStep, \ref setScaleStrategy). - - This method either returns the specified tick step exactly, or, if the scale strategy is not \ref - ssNone, a modification of it to allow varying the number of ticks in the current axis range. - - \seebaseclassmethod -*/ -double QCPAxisTickerFixed::getTickStep(const QCPRange &range) -{ - switch (mScaleStrategy) - { - case ssNone: - { - return mTickStep; - } - case ssMultiples: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - if (exactStep < mTickStep) - return mTickStep; - else - return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; - } - case ssPowers: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); - } - } - return mTickStep; -} -/* end of 'src/axis/axistickerfixed.cpp' */ - - -/* including file 'src/axis/axistickertext.cpp', size 8653 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerText -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerText - \brief Specialized axis ticker which allows arbitrary labels at specified coordinates - - \image html axisticker-text.png - - This QCPAxisTicker subclass generates ticks which can be directly specified by the user as - coordinates and associated strings. They can be passed as a whole with \ref setTicks or one at a - time with \ref addTick. Alternatively you can directly access the internal storage via \ref ticks - and modify the tick/label data there. - - This is useful for cases where the axis represents categories rather than numerical values. - - If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on - the axis range), it is a sign that you should probably create an own ticker by subclassing - QCPAxisTicker, instead of using this one. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickertext-creation -*/ - -/* start of documentation of inline functions */ - -/*! \fn QMap &QCPAxisTickerText::ticks() - - Returns a non-const reference to the internal map which stores the tick coordinates and their - labels. - - You can access the map directly in order to add, remove or manipulate ticks, as an alternative to - using the methods provided by QCPAxisTickerText, such as \ref setTicks and \ref addTick. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerText::QCPAxisTickerText() : - mSubTickCount(0) -{ -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The map key of \a ticks corresponds to the axis - coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QMap &ticks) -{ - mTicks = ticks; -} - -/*! \overload - - Sets the ticks that shall appear on the axis. The entries of \a positions correspond to the axis - coordinates, and the entries of \a labels are the respective strings that will appear as tick - labels. - - \see addTicks, addTick, clear -*/ -void QCPAxisTickerText::setTicks(const QVector &positions, const QVector labels) -{ - clear(); - addTicks(positions, labels); -} - -/*! - Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no - automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this - method. -*/ -void QCPAxisTickerText::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! - Clears all ticks. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see setTicks, addTicks, addTick -*/ -void QCPAxisTickerText::clear() -{ - mTicks.clear(); -} - -/*! - Adds a single tick to the axis at the given axis coordinate \a position, with the provided tick \a - label. - - \see addTicks, setTicks, clear -*/ -void QCPAxisTickerText::addTick(double position, QString label) -{ - mTicks.insert(position, label); -} - -/*! \overload - - Adds the provided \a ticks to the ones already existing. The map key of \a ticks corresponds to - the axis coordinate, and the map value is the string that will appear as tick label. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QMap &ticks) -{ - mTicks.unite(ticks); -} - -/*! \overload - - Adds the provided ticks to the ones already existing. The entries of \a positions correspond to - the axis coordinates, and the entries of \a labels are the respective strings that will appear as - tick labels. - - An alternative to manipulate ticks is to directly access the internal storage with the \ref ticks - getter. - - \see addTick, setTicks, clear -*/ -void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) -{ - if (positions.size() != labels.size()) - qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); - int n = qMin(positions.size(), labels.size()); - for (int i=0; i QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (mTicks.isEmpty()) - return result; - - QMap::const_iterator start = mTicks.lowerBound(range.lower); - QMap::const_iterator end = mTicks.upperBound(range.upper); - // this method should try to give one tick outside of range so proper subticks can be generated: - if (start != mTicks.constBegin()) --start; - if (end != mTicks.constEnd()) ++end; - for (QMap::const_iterator it = start; it != end; ++it) - result.append(it.key()); - - return result; -} -/* end of 'src/axis/axistickertext.cpp' */ - - -/* including file 'src/axis/axistickerpi.cpp', size 11170 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerPi -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerPi - \brief Specialized axis ticker to display ticks in units of an arbitrary constant, for example pi - - \image html axisticker-pi.png - - This QCPAxisTicker subclass generates ticks that are expressed with respect to a given symbolic - constant with a numerical value specified with \ref setPiValue and an appearance in the tick - labels specified with \ref setPiSymbol. - - Ticks may be generated at fractions of the symbolic constant. How these fractions appear in the - tick label can be configured with \ref setFractionStyle. - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerpi-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerPi::QCPAxisTickerPi() : - mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), - mPiValue(M_PI), - mPeriodicity(0), - mFractionStyle(fsUnicodeFractions), - mPiTickStep(0) -{ - setTickCount(4); -} - -/*! - Sets how the symbol part (which is always a suffix to the number) shall appear in the axis tick - label. - - If a space shall appear between the number and the symbol, make sure the space is contained in \a - symbol. -*/ -void QCPAxisTickerPi::setPiSymbol(QString symbol) -{ - mPiSymbol = symbol; -} - -/*! - Sets the numerical value that the symbolic constant has. - - This will be used to place the appropriate fractions of the symbol at the respective axis - coordinates. -*/ -void QCPAxisTickerPi::setPiValue(double pi) -{ - mPiValue = pi; -} - -/*! - Sets whether the axis labels shall appear periodicly and if so, at which multiplicity of the - symbolic constant. - - To disable periodicity, set \a multiplesOfPi to zero. - - For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. -*/ -void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) -{ - mPeriodicity = qAbs(multiplesOfPi); -} - -/*! - Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick - labels. See \ref FractionStyle for the various options. -*/ -void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) -{ - mFractionStyle = style; -} - -/*! \internal - - Returns the tick step, using the constant's value (\ref setPiValue) as base unit. In consequence - the numerical/fractional part preceding the symbolic constant is made to have a readable - mantissa. - - \seebaseclassmethod -*/ -double QCPAxisTickerPi::getTickStep(const QCPRange &range) -{ - mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - mPiTickStep = cleanMantissa(mPiTickStep); - return mPiTickStep*mPiValue; -} - -/*! \internal - - Returns the sub tick count, using the constant's value (\ref setPiValue) as base unit. In - consequence the sub ticks divide the numerical/fractional part preceding the symbolic constant - reasonably, and not the total tick coordinate. - - \seebaseclassmethod -*/ -int QCPAxisTickerPi::getSubTickCount(double tickStep) -{ - return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); -} - -/*! \internal - - Returns the tick label as a fractional/numerical part and a symbolic string as suffix. The - formatting of the fraction is done according to the specified \ref setFractionStyle. The appended - symbol is specified with \ref setPiSymbol. - - \seebaseclassmethod -*/ -QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) -{ - double tickInPis = tick/mPiValue; - if (mPeriodicity > 0) - tickInPis = fmod(tickInPis, mPeriodicity); - - if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) - { - // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above - int denominator = 1000; - int numerator = qRound(tickInPis*denominator); - simplifyFraction(numerator, denominator); - if (qAbs(numerator) == 1 && denominator == 1) - return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else if (numerator == 0) - return QLatin1String("0"); - else - return fractionToString(numerator, denominator) + mPiSymbol; - } else - { - if (qFuzzyIsNull(tickInPis)) - return QLatin1String("0"); - else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) - return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else - return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; - } -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure - the fraction is in irreducible form, i.e. numerator and denominator don't share any common - factors which could be cancelled. -*/ -void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const -{ - if (numerator == 0 || denominator == 0) - return; - - int num = numerator; - int denom = denominator; - while (denom != 0) // euclidean gcd algorithm - { - int oldDenom = denom; - denom = num % denom; - num = oldDenom; - } - // num is now gcd of numerator and denominator - numerator /= num; - denominator /= num; -} - -/*! \internal - - Takes the fraction given by \a numerator and \a denominator and returns a string representation. - The result depends on the configured fraction style (\ref setFractionStyle). - - This method is used to format the numerical/fractional part when generating tick labels. It - simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out - any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). -*/ -QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const -{ - if (denominator == 0) - { - qDebug() << Q_FUNC_INFO << "called with zero denominator"; - return QString(); - } - if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function - { - qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; - return QString::number(numerator/(double)denominator); // failsafe - } - int sign = numerator*denominator < 0 ? -1 : 1; - numerator = qAbs(numerator); - denominator = qAbs(denominator); - - if (denominator == 1) - { - return QString::number(sign*numerator); - } else - { - int integerPart = numerator/denominator; - int remainder = numerator%denominator; - if (remainder == 0) - { - return QString::number(sign*integerPart); - } else - { - if (mFractionStyle == fsAsciiFractions) - { - return QString(QLatin1String("%1%2%3/%4")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) - .arg(remainder) - .arg(denominator); - } else if (mFractionStyle == fsUnicodeFractions) - { - return QString(QLatin1String("%1%2%3")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) - .arg(unicodeFraction(remainder, denominator)); - } - } - } - return QString(); -} - -/*! \internal - - Returns the unicode string representation of the fraction given by \a numerator and \a - denominator. This is the representation used in \ref fractionToString when the fraction style - (\ref setFractionStyle) is \ref fsUnicodeFractions. - - This method doesn't use the single-character common fractions but builds each fraction from a - superscript unicode number, the unicode fraction character, and a subscript unicode number. -*/ -QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const -{ - return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); -} - -/*! \internal - - Returns the unicode string representing \a number as superscript. This is used to build - unicode fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSuperscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2070)); - - QString result; - while (number > 0) - { - const int digit = number%10; - switch (digit) - { - case 1: { result.prepend(QChar(0x00B9)); break; } - case 2: { result.prepend(QChar(0x00B2)); break; } - case 3: { result.prepend(QChar(0x00B3)); break; } - default: { result.prepend(QChar(0x2070+digit)); break; } - } - number /= 10; - } - return result; -} - -/*! \internal - - Returns the unicode string representing \a number as subscript. This is used to build unicode - fractions in \ref unicodeFraction. -*/ -QString QCPAxisTickerPi::unicodeSubscript(int number) const -{ - if (number == 0) - return QString(QChar(0x2080)); - - QString result; - while (number > 0) - { - result.prepend(QChar(0x2080+number%10)); - number /= 10; - } - return result; -} -/* end of 'src/axis/axistickerpi.cpp' */ - - -/* including file 'src/axis/axistickerlog.cpp', size 7106 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisTickerLog -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPAxisTickerLog - \brief Specialized axis ticker suited for logarithmic axes - - \image html axisticker-log.png - - This QCPAxisTicker subclass generates ticks with unequal tick intervals suited for logarithmic - axis scales. The ticks are placed at powers of the specified log base (\ref setLogBase). - - Especially in the case of a log base equal to 10 (the default), it might be desirable to have - tick labels in the form of powers of ten without mantissa display. To achieve this, set the - number precision (\ref QCPAxis::setNumberPrecision) to zero and the number format (\ref - QCPAxis::setNumberFormat) to scientific (exponential) display with beautifully typeset decimal - powers, so a format string of "eb". This will result in the following axis tick labels: - - \image html axisticker-log-powers.png - - The ticker can be created and assigned to an axis like this: - \snippet documentation/doc-image-generator/mainwindow.cpp axistickerlog-creation -*/ - -/*! - Constructs the ticker and sets reasonable default values. Axis tickers are commonly created - managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. -*/ -QCPAxisTickerLog::QCPAxisTickerLog() : - mLogBase(10.0), - mSubTickCount(8), // generates 10 intervals - mLogBaseLnInv(1.0/qLn(mLogBase)) -{ -} - -/*! - Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer - powers of \a base. -*/ -void QCPAxisTickerLog::setLogBase(double base) -{ - if (base > 0) - { - mLogBase = base; - mLogBaseLnInv = 1.0/qLn(mLogBase); - } else - qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; -} - -/*! - Sets the number of sub ticks in a tick interval. Within each interval, the sub ticks are spaced - linearly to provide a better visual guide, so the sub tick density increases toward the higher - tick. - - Note that \a subTicks is the number of sub ticks (not sub intervals) in one tick interval. So in - the case of logarithm base 10 an intuitive sub tick spacing would be achieved with eight sub - ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, - namely at 20, 30, 40, 50, 60, 70, 80 and 90. -*/ -void QCPAxisTickerLog::setSubTickCount(int subTicks) -{ - if (subTicks >= 0) - mSubTickCount = subTicks; - else - qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; -} - -/*! \internal - - Since logarithmic tick steps are necessarily different for each tick interval, this method does - nothing in the case of QCPAxisTickerLog - - \seebaseclassmethod -*/ -double QCPAxisTickerLog::getTickStep(const QCPRange &range) -{ - // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method - Q_UNUSED(range) - return 1.0; -} - -/*! \internal - - Returns the sub tick count specified in \ref setSubTickCount. For QCPAxisTickerLog, there is no - automatic sub tick count calculation necessary. - - \seebaseclassmethod -*/ -int QCPAxisTickerLog::getSubTickCount(double tickStep) -{ - Q_UNUSED(tickStep) - return mSubTickCount; -} - -/*! \internal - - Creates ticks with a spacing given by the logarithm base and an increasing integer power in the - provided \a range. The step in which the power increases tick by tick is chosen in order to keep - the total number of ticks as close as possible to the tick count (\ref setTickCount). The - parameter \a tickStep is ignored for QCPAxisTickerLog - - \seebaseclassmethod -*/ -QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) -{ - Q_UNUSED(tickStep) - QVector result; - if (range.lower > 0 && range.upper > 0) // positive range - { - double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick *= newLogBase; - result.append(currentTick); - } - } else if (range.lower < 0 && range.upper < 0) // negative range - { - double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentTick /= newLogBase; - result.append(currentTick); - } - } else // invalid range for logarithmic scale, because lower and upper have different sign - { - qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; - } - - return result; -} -/* end of 'src/axis/axistickerlog.cpp' */ - - -/* including file 'src/axis/axis.cpp', size 99397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGrid - \brief Responsible for drawing the grid of a QCPAxis. - - This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the - grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref - QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. - - The axis and grid drawing was split into two classes to allow them to be placed on different - layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid - in the background and the axes in the foreground, and any plottables/items in between. This - described situation is the default setup, see the QCPLayer documentation. -*/ - -/*! - Creates a QCPGrid instance and sets default values. - - You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. -*/ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), - mParentAxis(parentAxis) -{ - // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); -} - -/*! - Sets whether grid lines at sub tick marks are drawn. - - \see setSubGridPen -*/ -void QCPGrid::setSubGridVisible(bool visible) -{ - mSubGridVisible = visible; -} - -/*! - Sets whether sub grid lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedSubGrid(bool enabled) -{ - mAntialiasedSubGrid = enabled; -} - -/*! - Sets whether zero lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedZeroLine(bool enabled) -{ - mAntialiasedZeroLine = enabled; -} - -/*! - Sets the pen with which (major) grid lines are drawn. -*/ -void QCPGrid::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen with which sub grid lines are drawn. -*/ -void QCPGrid::setSubGridPen(const QPen &pen) -{ - mSubGridPen = pen; -} - -/*! - Sets the pen with which zero lines are drawn. - - Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid - lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. -*/ -void QCPGrid::setZeroLinePen(const QPen &pen) -{ - mZeroLinePen = pen; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing the major grid lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); -} - -/*! \internal - - Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning - over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). -*/ -void QCPGrid::draw(QCPPainter *painter) -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mParentAxis->subTicks() && mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); -} - -/*! \internal - - Draws the main grid lines and possibly a zero line with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - const int tickCount = mParentAxis->mTickVector.size(); - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=0; imTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; icoordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - -/*! \internal - - Draws the sub grid lines with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - for (int i=0; imSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxis -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxis - \brief Manages a single axis inside a QCustomPlot. - - Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via - QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and - QCustomPlot::yAxis2 (right). - - Axes are always part of an axis rect, see QCPAxisRect. - \image html AxisNamesOverview.png -
Naming convention of axis parts
- \n - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line - on the left represents the QCustomPlot widget border.
- - Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and - tick labels. You can access the currently installed \ref ticker or set a new one (possibly one of - the specialized subclasses, or your own subclass) via \ref setTicker. For details, see the - documentation of QCPAxisTicker. -*/ - -/* start of documentation of inline functions */ - -/*! \fn Qt::Orientation QCPAxis::orientation() const - - Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced - from the axis type (left, top, right or bottom). - - \see orientation(AxisType type), pixelOrientation -*/ - -/*! \fn QCPGrid *QCPAxis::grid() const - - Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the - grid is displayed. -*/ - -/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) - - Returns the orientation of the specified axis type - - \see orientation(), pixelOrientation -*/ - -/*! \fn int QCPAxis::pixelOrientation() const - - Returns which direction points towards higher coordinate values/keys, in pixel space. - - This method returns either 1 or -1. If it returns 1, then going in the positive direction along - the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. - On the other hand, if this method returns -1, going to smaller pixel values corresponds to going - from lower to higher axis coordinates. - - For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, - without having to care about reversed or vertically aligned axes: - - \code - double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation()); - \endcode - - \a newKey will then contain a key that is ten pixels towards higher keys, starting from \a oldKey. -*/ - -/*! \fn QSharedPointer QCPAxis::ticker() const - - Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is - responsible for generating the tick positions and tick labels of this axis. You can access the - \ref QCPAxisTicker with this method and modify basic properties such as the approximate tick count - (\ref QCPAxisTicker::setTickCount). - - You can gain more control over the axis ticks by setting a different \ref QCPAxisTicker subclass, see - the documentation there. A new axis ticker can be set with \ref setTicker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see setTicker -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) - - This signal is emitted when the range of this axis has changed. You can connect it to the \ref - setRange slot of another axis to communicate the new range to the other axis, in order for it to - be synchronized. - - You may also manipulate/correct the range with \ref setRange in a slot connected to this signal. - This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper - range shouldn't go beyond certain values (see \ref QCPRange::bounded). For example, the following - slot would limit the x axis to ranges between 0 and 10: - \code - customPlot->xAxis->setRange(newRange.bounded(0, 10)) - \endcode -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) - \overload - - Additionally to the new range, this signal also provides the previous range held by the axis as - \a oldRange. -*/ - -/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the scale type changes, by calls to \ref setScaleType -*/ - -/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) - - This signal is emitted when the selection state of this axis has changed, either by user interaction - or by a direct call to \ref setSelectedParts. -*/ - -/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); - - This signal is emitted when the selectability changes, by calls to \ref setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs an Axis instance of Type \a type for the axis rect \a parent. - - Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create - them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, - create them manually and then inject them also via \ref QCPAxisRect::addAxis. -*/ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), QString(), parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mTicker(new QCPAxisTicker), - mCachedMarginValid(false), - mCachedMargin(0) -{ - setParent(parent); - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) - { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) - { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) - { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) - { - setTickLabelPadding(5); - setLabelPadding(10); - } -} - -QCPAxis::~QCPAxis() -{ - delete mAxisPainter; - delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLabelPadding() const -{ - return mAxisPainter->tickLabelPadding; -} - -/* No documentation as it is a property getter */ -double QCPAxis::tickLabelRotation() const -{ - return mAxisPainter->tickLabelRotation; -} - -/* No documentation as it is a property getter */ -QCPAxis::LabelSide QCPAxis::tickLabelSide() const -{ - return mAxisPainter->tickLabelSide; -} - -/* No documentation as it is a property getter */ -QString QCPAxis::numberFormat() const -{ - QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) - { - result.append(QLatin1Char('b')); - if (mAxisPainter->numberMultiplyCross) - result.append(QLatin1Char('c')); - } - return result; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthIn() const -{ - return mAxisPainter->tickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthOut() const -{ - return mAxisPainter->tickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthIn() const -{ - return mAxisPainter->subTickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthOut() const -{ - return mAxisPainter->subTickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::labelPadding() const -{ - return mAxisPainter->labelPadding; -} - -/* No documentation as it is a property getter */ -int QCPAxis::offset() const -{ - return mAxisPainter->offset; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::lowerEnding() const -{ - return mAxisPainter->lowerEnding; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::upperEnding() const -{ - return mAxisPainter->upperEnding; -} - -/*! - Sets whether the axis uses a linear scale or a logarithmic scale. - - Note that this method controls the coordinate transformation. You will likely also want to use a - logarithmic tick spacing and labeling, which can be achieved by setting an instance of \ref - QCPAxisTickerLog via \ref setTicker. See the documentation of \ref QCPAxisTickerLog about the - details of logarithmic axis tick creation. - - \ref setNumberPrecision -*/ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) -{ - if (mScaleType != type) - { - mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); - mCachedMarginValid = false; - Q_EMIT scaleTypeChanged(mScaleType); - } -} - -/*! - Sets the range of the axis. - - This slot may be connected with the \ref rangeChanged signal of another axis so this axis - is always synchronized with the other axis range, when it changes. - - To invert the direction of an axis, use \ref setRangeReversed. -*/ -void QCPAxis::setRange(const QCPRange &range) -{ - if (range.lower == mRange.lower && range.upper == mRange.upper) - return; - - if (!QCPRange::validRange(range)) return; - QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) - { - mRange = range.sanitizedForLogScale(); - } else - { - mRange = range.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectAxes.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font. - - The entire selection mechanism for axes is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you - wish to change the selection state manually. - - This function can change the selection state of a part, independent of the \ref setSelectableParts setting. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, - setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor -*/ -void QCPAxis::setSelectedParts(const SelectableParts &selected) -{ - if (mSelectedParts != selected) - { - mSelectedParts = selected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - \overload - - Sets the lower and upper bound of the axis range. - - To invert the direction of an axis, use \ref setRangeReversed. - - There is also a slot to set a range, see \ref setRange(const QCPRange &range). -*/ -void QCPAxis::setRange(double lower, double upper) -{ - if (lower == mRange.lower && upper == mRange.upper) - return; - - if (!QCPRange::validRange(lower, upper)) return; - QCPRange oldRange = mRange; - mRange.lower = lower; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - \overload - - Sets the range of the axis. - - The \a position coordinate indicates together with the \a alignment parameter, where the new - range will be positioned. \a size defines the size of the new axis range. \a alignment may be - Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, - or center of the range to be aligned with \a position. Any other values of \a alignment will - default to Qt::AlignCenter. -*/ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) -{ - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); -} - -/*! - Sets the lower bound of the axis range. The upper bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeLower(double lower) -{ - if (mRange.lower == lower) - return; - - QCPRange oldRange = mRange; - mRange.lower = lower; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets the upper bound of the axis range. The lower bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeUpper(double upper) -{ - if (mRange.upper == upper) - return; - - QCPRange oldRange = mRange; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal - axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the - direction of increasing values is inverted. - - Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part - of the \ref setRange interface will still reference the mathematically smaller number than the \a - upper part. -*/ -void QCPAxis::setRangeReversed(bool reversed) -{ - mRangeReversed = reversed; -} - -/*! - The axis ticker is responsible for generating the tick positions and tick labels. See the - documentation of QCPAxisTicker for details on how to work with axis tickers. - - You can change the tick positioning/labeling behaviour of this axis by setting a different - QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis - ticker, access it via \ref ticker. - - Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis - ticker simply by passing the same shared pointer to multiple axes. - - \see ticker -*/ -void QCPAxis::setTicker(QSharedPointer ticker) -{ - if (ticker) - mTicker = ticker; - else - qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; - // no need to invalidate margin cache here because produced tick labels are checked for changes in setupTickVector -} - -/*! - Sets whether tick marks are displayed. - - Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve - that, see \ref setTickLabels. - - \see setSubTicks -*/ -void QCPAxis::setTicks(bool show) -{ - if (mTicks != show) - { - mTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. -*/ -void QCPAxis::setTickLabels(bool show) -{ - if (mTickLabels != show) - { - mTickLabels = show; - mCachedMarginValid = false; - if (!mTickLabels) - mTickVectorLabels.clear(); - } -} - -/*! - Sets the distance between the axis base line (including any outward ticks) and the tick labels. - \see setLabelPadding, setPadding -*/ -void QCPAxis::setTickLabelPadding(int padding) -{ - if (mAxisPainter->tickLabelPadding != padding) - { - mAxisPainter->tickLabelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the font of the tick labels. - - \see setTickLabels, setTickLabelColor -*/ -void QCPAxis::setTickLabelFont(const QFont &font) -{ - if (font != mTickLabelFont) - { - mTickLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the tick labels. - - \see setTickLabels, setTickLabelFont -*/ -void QCPAxis::setTickLabelColor(const QColor &color) -{ - mTickLabelColor = color; -} - -/*! - Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, - the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values - from -90 to 90 degrees. - - If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For - other angles, the label is drawn with an offset such that it seems to point toward or away from - the tick mark. -*/ -void QCPAxis::setTickLabelRotation(double degrees) -{ - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) - { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick labels (numbers) shall appear inside or outside the axis rect. - - The usual and default setting is \ref lsOutside. Very compact plots sometimes require tick labels - to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels - appear on the inside are additionally clipped to the axis rect. -*/ -void QCPAxis::setTickLabelSide(LabelSide side) -{ - mAxisPainter->tickLabelSide = side; - mCachedMarginValid = false; -} - -/*! - Sets the number format for the numbers in tick labels. This \a formatCode is an extended version - of the format code used e.g. by QString::number() and QLocale::toString(). For reference about - that, see the "Argument Formats" section in the detailed description of the QString class. - - \a formatCode is a string of one, two or three characters. The first character is identical to - the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed - format, 'g'/'G' scientific or fixed, whichever is shorter. - - The second and third characters are optional and specific to QCustomPlot:\n - If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. - "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for - "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 - [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. - If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can - be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the - cross and 183 (0xB7) for the dot. - - Examples for \a formatCode: - \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, - normal scientific format is used - \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with - beautifully typeset decimal powers and a dot as multiplication sign - \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as - multiplication sign - \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal - powers. Format code will be reduced to 'f'. - \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format - code will not be changed. -*/ -void QCPAxis::setNumberFormat(const QString &formatCode) -{ - if (formatCode.isEmpty()) - { - qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; - return; - } - mCachedMarginValid = false; - - // interpret first char as number format char: - QString allowedFormatChars(QLatin1String("eEfgG")); - if (allowedFormatChars.contains(formatCode.at(0))) - { - mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; - return; - } - if (formatCode.length() < 2) - { - mNumberBeautifulPowers = false; - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) - { - mNumberBeautifulPowers = true; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - return; - } - if (formatCode.length() < 3) - { - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == QLatin1Char('c')) - { - mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == QLatin1Char('d')) - { - mAxisPainter->numberMultiplyCross = false; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; - return; - } -} - -/*! - Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) - for details. The effect of precisions are most notably for number Formats starting with 'e', see - \ref setNumberFormat -*/ -void QCPAxis::setNumberPrecision(int precision) -{ - if (mNumberPrecision != precision) - { - mNumberPrecision = precision; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the - plot and \a outside is the length they will reach outside the plot. If \a outside is greater than - zero, the tick labels and axis label will increase their distance to the axis accordingly, so - they won't collide with the ticks. - - \see setSubTickLength, setTickLengthIn, setTickLengthOut -*/ -void QCPAxis::setTickLength(int inside, int outside) -{ - setTickLengthIn(inside); - setTickLengthOut(outside); -} - -/*! - Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach - inside the plot. - - \see setTickLengthOut, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthIn(int inside) -{ - if (mAxisPainter->tickLengthIn != inside) - { - mAxisPainter->tickLengthIn = inside; - } -} - -/*! - Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach - outside the plot. If \a outside is greater than zero, the tick labels and axis label will - increase their distance to the axis accordingly, so they won't collide with the ticks. - - \see setTickLengthIn, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthOut(int outside) -{ - if (mAxisPainter->tickLengthOut != outside) - { - mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets whether sub tick marks are displayed. - - Sub ticks are only potentially visible if (major) ticks are also visible (see \ref setTicks) - - \see setTicks -*/ -void QCPAxis::setSubTicks(bool show) -{ - if (mSubTicks != show) - { - mSubTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside - the plot and \a outside is the length they will reach outside the plot. If \a outside is greater - than zero, the tick labels and axis label will increase their distance to the axis accordingly, - so they won't collide with the ticks. - - \see setTickLength, setSubTickLengthIn, setSubTickLengthOut -*/ -void QCPAxis::setSubTickLength(int inside, int outside) -{ - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); -} - -/*! - Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside - the plot. - - \see setSubTickLengthOut, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthIn(int inside) -{ - if (mAxisPainter->subTickLengthIn != inside) - { - mAxisPainter->subTickLengthIn = inside; - } -} - -/*! - Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach - outside the plot. If \a outside is greater than zero, the tick labels will increase their - distance to the axis accordingly, so they won't collide with the ticks. - - \see setSubTickLengthIn, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthOut(int outside) -{ - if (mAxisPainter->subTickLengthOut != outside) - { - mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the pen, the axis base line is drawn with. - - \see setTickPen, setSubTickPen -*/ -void QCPAxis::setBasePen(const QPen &pen) -{ - mBasePen = pen; -} - -/*! - Sets the pen, tick marks will be drawn with. - - \see setTickLength, setBasePen -*/ -void QCPAxis::setTickPen(const QPen &pen) -{ - mTickPen = pen; -} - -/*! - Sets the pen, subtick marks will be drawn with. - - \see setSubTickCount, setSubTickLength, setBasePen -*/ -void QCPAxis::setSubTickPen(const QPen &pen) -{ - mSubTickPen = pen; -} - -/*! - Sets the font of the axis label. - - \see setLabelColor -*/ -void QCPAxis::setLabelFont(const QFont &font) -{ - if (mLabelFont != font) - { - mLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the axis label. - - \see setLabelFont -*/ -void QCPAxis::setLabelColor(const QColor &color) -{ - mLabelColor = color; -} - -/*! - Sets the text of the axis label that will be shown below/above or next to the axis, depending on - its orientation. To disable axis labels, pass an empty string as \a str. -*/ -void QCPAxis::setLabel(const QString &str) -{ - if (mLabel != str) - { - mLabel = str; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the tick labels and the axis label. - - \see setTickLabelPadding, setPadding -*/ -void QCPAxis::setLabelPadding(int padding) -{ - if (mAxisPainter->labelPadding != padding) - { - mAxisPainter->labelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the padding of the axis. - - When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, - that is left blank. - - The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. - - \see setLabelPadding, setTickLabelPadding -*/ -void QCPAxis::setPadding(int padding) -{ - if (mPadding != padding) - { - mPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the offset the axis has to its axis rect side. - - If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, - only the offset of the inner most axis has meaning (even if it is set to be invisible). The - offset of the other, outer axes is controlled automatically, to place them at appropriate - positions. -*/ -void QCPAxis::setOffset(int offset) -{ - mAxisPainter->offset = offset; -} - -/*! - Sets the font that is used for tick labels when they are selected. - - \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) -{ - if (font != mSelectedTickLabelFont) - { - mSelectedTickLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts - } -} - -/*! - Sets the font that is used for the axis label when it is selected. - - \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelFont(const QFont &font) -{ - mSelectedLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts -} - -/*! - Sets the color that is used for tick labels when they are selected. - - \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) -{ - if (color != mSelectedTickLabelColor) - { - mSelectedTickLabelColor = color; - } -} - -/*! - Sets the color that is used for the axis label when it is selected. - - \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelColor(const QColor &color) -{ - mSelectedLabelColor = color; -} - -/*! - Sets the pen that is used to draw the axis base line when selected. - - \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedBasePen(const QPen &pen) -{ - mSelectedBasePen = pen; -} - -/*! - Sets the pen that is used to draw the (major) ticks when selected. - - \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickPen(const QPen &pen) -{ - mSelectedTickPen = pen; -} - -/*! - Sets the pen that is used to draw the subticks when selected. - - \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) -{ - mSelectedSubTickPen = pen; -} - -/*! - Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setUpperEnding -*/ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) -{ - mAxisPainter->lowerEnding = ending; -} - -/*! - Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the right ending, for vertical axes the top ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setLowerEnding -*/ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) -{ - mAxisPainter->upperEnding = ending; -} - -/*! - If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper - bounds of the range. The range is simply moved by \a diff. - - If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This - corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). -*/ -void QCPAxis::moveRange(double diff) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - mRange.lower += diff; - mRange.upper += diff; - } else // mScaleType == stLogarithmic - { - mRange.lower *= diff; - mRange.upper *= diff; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis by \a factor around the center of the current axis range. For - example, if \a factor is 2.0, then the axis range will double its size, and the point at the axis - range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around - the center will have moved symmetrically closer). - - If you wish to scale around a different coordinate than the current axis range center, use the - overload \ref scaleRange(double factor, double center). -*/ -void QCPAxis::scaleRange(double factor) -{ - scaleRange(factor, range().center()); -} - -/*! \overload - - Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a - factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at - coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates - around 1.0 will have moved symmetrically closer to 1.0). - - \see scaleRange(double factor) -*/ -void QCPAxis::scaleRange(double factor, double center) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic - { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range - { - QCPRange newRange; - newRange.lower = qPow(mRange.lower/center, factor)*center; - newRange.upper = qPow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLogScale(); - } else - qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; - } - Q_EMIT rangeChanged(mRange); - Q_EMIT rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will - be done around the center of the current axis range. - - For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs - plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the - axis rect has. - - This is an operation that changes the range of this axis once, it doesn't fix the scale ratio - indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent - won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent - will follow. -*/ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) -{ - int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) - otherPixelSize = otherAxis->axisRect()->width(); - else - otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) - ownPixelSize = axisRect()->width(); - else - ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); -} - -/*! - Changes the axis range such that all plottables associated with this axis are fully visible in - that dimension. - - \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPAxis::rescale(bool onlyVisiblePlottables) -{ - QList p = plottables(); - QCPRange newRange; - bool haveRange = false; - for (int i=0; irealVisibility() && onlyVisiblePlottables) - continue; - QCPRange plottableRange; - bool currentFoundRange; - QCP::SignDomain signDomain = QCP::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); - else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) - { - if (!haveRange) - newRange = plottableRange; - else - newRange.expand(plottableRange); - haveRange = true; - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) - { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); - } - } - setRange(newRange); - } -} - -/*! - Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. -*/ -double QCPAxis::pixelToCoord(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; - else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; - else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; - } - } -} - -/*! - Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. -*/ -double QCPAxis::coordToPixel(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; - else - { - if (!mRangeReversed) - return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - else - return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - } - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); - else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic - { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; - else - { - if (!mRangeReversed) - return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - else - return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); - } - } - } -} - -/*! - Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function - is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this - function does not change the current selection state of the axis. - - If the axis is not visible (\ref setVisible), this function always returns \ref spNone. - - \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions -*/ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const -{ - if (!mVisible) - return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) - return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) - return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) - return spAxisLabel; - else - return spNone; -} - -/* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) - return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; -} - -/*! - Returns a list of all the plottables that have this axis as key or value axis. - - If you are only interested in plottables of type QCPGraph, see \ref graphs. - - \see graphs, items -*/ -QList QCPAxis::plottables() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that have this axis as key or value axis. - - \see plottables, items -*/ -QList QCPAxis::graphs() const -{ - QList result; - if (!mParentPlot) return result; - - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis. An item is considered - associated with an axis if at least one of its positions uses the axis as key or value axis. - - \see plottables, graphs -*/ -QList QCPAxis::items() const -{ - QList result; - if (!mParentPlot) return result; - - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdkeyAxis() == this || positions.at(posId)->valueAxis() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to - QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) -*/ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; - } - qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; - return atLeft; -} - -/*! - Returns the axis type that describes the opposite axis of an axis with the specified \a type. -*/ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) -{ - switch (type) - { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; - } -} - -/* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - SelectablePart part = details.value(); - if (mSelectableParts.testFlag(part)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) -{ - SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - For the axis to accept this event and perform the single axis drag, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range dragging in the orientation of this axis - (\ref QCPAxisRect::setRangeDrag) and this axis must be a draggable axis (\ref - QCPAxisRect::setRangeDragAxes) - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. -*/ -void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || - !mAxisRect->rangeDrag().testFlag(orientation()) || - !mAxisRect->rangeDragAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - mDragStartRange = mRange; - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (mDragging) - { - const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); - const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); - if (mScaleType == QCPAxis::stLinear) - { - const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); - setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); - } else if (mScaleType == QCPAxis::stLogarithmic) - { - const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); - setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); - } - - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user drag individual axes - exclusively, by startig the drag on top of the axis. - - \seebaseclassmethod - - \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis - rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. - - \see QCPAxis::mousePressEvent -*/ -void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - This mouse event reimplementation provides the functionality to let the user zoom individual axes - exclusively, by performing the wheel event on top of the axis. - - For the axis to accept this event and perform the single axis zoom, the parent \ref QCPAxisRect - must be configured accordingly, i.e. it must allow range zooming in the orientation of this axis - (\ref QCPAxisRect::setRangeZoom) and this axis must be a zoomable axis (\ref - QCPAxisRect::setRangeZoomAxes) - - \seebaseclassmethod - - \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the - axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. -*/ -void QCPAxis::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || - !mAxisRect->rangeZoom().testFlag(orientation()) || - !mAxisRect->rangeZoomAxes(orientation()).contains(this)) - { - event->ignore(); - return; - } - - const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); - scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); - mParentPlot->replot(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing axis lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); -} - -/*! \internal - - Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. - - \seebaseclassmethod -*/ -void QCPAxis::draw(QCPPainter *painter) -{ - QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->basePen = getBasePen(); - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->labelColor = getLabelColor(); - mAxisPainter->label = mLabel; - mAxisPainter->substituteExponent = mNumberBeautifulPowers; - mAxisPainter->tickPen = getTickPen(); - mAxisPainter->subTickPen = getSubTickPen(); - mAxisPainter->tickLabelFont = getTickLabelFont(); - mAxisPainter->tickLabelColor = getTickLabelColor(); - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; - mAxisPainter->reversedEndings = mRangeReversed; - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); -} - -/*! \internal - - Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling - QCPAxisTicker::generate on the currently installed ticker. - - If a change in the label text/count is detected, the cached axis margin is invalidated to make - sure the next margin calculation recalculates the label sizes and returns an up-to-date value. -*/ -void QCPAxis::setupTickVectors() -{ - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - - QVector oldLabels = mTickVectorLabels; - mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too -} - -/*! \internal - - Returns the pen that is used to draw the axis base line. Depending on the selection state, this - is either mSelectedBasePen or mBasePen. -*/ -QPen QCPAxis::getBasePen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; -} - -/*! \internal - - Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this - is either mSelectedTickPen or mTickPen. -*/ -QPen QCPAxis::getTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; -} - -/*! \internal - - Returns the pen that is used to draw the subticks. Depending on the selection state, this - is either mSelectedSubTickPen or mSubTickPen. -*/ -QPen QCPAxis::getSubTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; -} - -/*! \internal - - Returns the font that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelFont or mTickLabelFont. -*/ -QFont QCPAxis::getTickLabelFont() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; -} - -/*! \internal - - Returns the font that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelFont or mLabelFont. -*/ -QFont QCPAxis::getLabelFont() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; -} - -/*! \internal - - Returns the color that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelColor or mTickLabelColor. -*/ -QColor QCPAxis::getTickLabelColor() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; -} - -/*! \internal - - Returns the color that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelColor or mLabelColor. -*/ -QColor QCPAxis::getLabelColor() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; -} - -/*! \internal - - Returns the appropriate outward margin for this axis. It is needed if \ref - QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref - atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom - margin and so forth. For the calculation, this function goes through similar steps as \ref draw, - so changing one function likely requires the modification of the other one as well. - - The margin consists of the outward tick length, tick label padding, tick label size, label - padding, label size, and padding. - - The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. - unchanged are very fast. -*/ -int QCPAxis::calculateMargin() -{ - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis - return 0; - - if (mCachedMarginValid) - return mCachedMargin; - - // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels - int margin = 0; - - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - - if (mTicks) - { - for (int i=0; itype = mAxisType; - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->label = mLabel; - mAxisPainter->tickLabelFont = mTickLabelFont; - mAxisPainter->axisRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - margin += mAxisPainter->size(); - margin += mPadding; - - mCachedMargin = margin; - mCachedMarginValid = true; - return margin; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAxis::selectionCategory() const -{ - return QCP::iSelectAxes; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisPainterPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisPainterPrivate - - \internal - \brief (Private) - - This is a private class and not part of the public QCustomPlot interface. - - It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and - axis label. It also buffers the labels to reduce replot times. The parameters are configured by - directly accessing the public member variables. -*/ - -/*! - Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every - redraw, to utilize the caching mechanisms. -*/ -QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : - type(QCPAxis::atLeft), - basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - lowerEnding(QCPLineEnding::esNone), - upperEnding(QCPLineEnding::esNone), - labelPadding(0), - tickLabelPadding(0), - tickLabelRotation(0), - tickLabelSide(QCPAxis::lsOutside), - substituteExponent(true), - numberMultiplyCross(false), - tickLengthIn(5), - tickLengthOut(0), - subTickLengthIn(2), - subTickLengthOut(0), - tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - offset(0), - abbreviateDecimalPowers(false), - reversedEndings(false), - mParentPlot(parentPlot), - mLabelCache(16) // cache at most 16 (tick) labels -{ -} - -QCPAxisPainterPrivate::~QCPAxisPainterPrivate() -{ -} - -/*! \internal - - Draws the axis with the specified \a painter. - - The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set - here, too. -*/ -void QCPAxisPainterPrivate::draw(QCPPainter *painter) -{ - QByteArray newHash = generateLabelParameterHash(); - if (newHash != mLabelParameterHash) - { - mLabelCache.clear(); - mLabelParameterHash = newHash; - } - - QPoint origin; - switch (type) - { - case QCPAxis::atLeft: origin = axisRect.bottomLeft() +QPoint(-offset, 0); break; - case QCPAxis::atRight: origin = axisRect.bottomRight()+QPoint(+offset, 0); break; - case QCPAxis::atTop: origin = axisRect.topLeft() +QPoint(0, -offset); break; - case QCPAxis::atBottom: origin = axisRect.bottomLeft() +QPoint(0, +offset); break; - } - - double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) - switch (type) - { - case QCPAxis::atTop: yCor = -1; break; - case QCPAxis::atRight: xCor = 1; break; - default: break; - } - int margin = 0; - // draw baseline: - QLineF baseLine; - painter->setPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); - else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - - // draw ticks: - if (!tickPositions.isEmpty()) - { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); - } - } - - // draw subticks: - if (!subTickPositions.isEmpty()) - { - painter->setPen(subTickPen); - // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); - } - } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // draw axis base endings: - bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - - // tick labels: - QRect oldClipRect; - if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect - { - oldClipRect = painter->clipRegion().boundingRect(); - painter->setClipRect(axisRect); - } - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) - { - if (tickLabelSide == QCPAxis::lsOutside) - margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); - int distanceToAxis = margin; - if (tickLabelSide == QCPAxis::lsInside) - distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - for (int i=0; isetClipRect(oldClipRect); - - // axis label: - QRect labelBounds; - if (!label.isEmpty()) - { - margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atRight) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); - painter->rotate(90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - } - - // set selection boxes: - int selectionTolerance = 0; - if (mParentPlot) - selectionTolerance = mParentPlot->selectionTolerance(); - else - qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); - int selAxisInSize = selectionTolerance; - int selTickLabelSize; - int selTickLabelOffset; - if (tickLabelSide == QCPAxis::lsOutside) - { - selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - } else - { - selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - } - int selLabelSize = labelBounds.height(); - int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; - if (type == QCPAxis::atLeft) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atRight) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atTop) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) - { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); - } - mAxisSelectionBox = mAxisSelectionBox.normalized(); - mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); - mLabelSelectionBox = mLabelSelectionBox.normalized(); - // draw hitboxes for debug purposes: - //painter->setBrush(Qt::NoBrush); - //painter->drawRects(QVector() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); -} - -/*! \internal - - Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone - direction) needed to fit the axis. -*/ -int QCPAxisPainterPrivate::size() const -{ - int result = 0; - - // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // calculate size of tick labels: - if (tickLabelSide == QCPAxis::lsOutside) - { - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) - { - for (int i=0; ibufferDevicePixelRatio())); - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)tickLabelSide)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString().toLatin1()); - return result; -} - -/*! \internal - - Draws a single tick label with the provided \a painter, utilizing the internal label cache to - significantly speed up drawing of labels that were drawn in previous calls. The tick label is - always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in - pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence - for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), - at which the label should be drawn. - - In order to later draw the axis label in a place that doesn't overlap with the tick labels, the - largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref - drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a - tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently - holds. - - The label is drawn with the font and pen that are currently set on the \a painter. To draw - superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref - getTickLabelData). -*/ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) -{ - // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; - QSize finalSize; - QPointF labelAnchor; - switch (type) - { - case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; - } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled - { - CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache - if (!cachedLabel) // no cached label existed, create it - { - cachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); - if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) - { - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); -# else - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); -# endif -#endif - } else - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - cachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&cachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); - } - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); - else - labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } - mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created - } else // label caching disabled, draw text directly on surface: - { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); - // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) - { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); - else - labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); - } - if (!labelClippedByBorder) - { - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); - finalSize = labelData.rotatedTotalBounds.size(); - } - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a - y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to - directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when - QCP::phCacheLabels plotting hint is not set. -*/ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const -{ - // backup painter settings that we're about to change: - QTransform oldTransform = painter->transform(); - QFont oldFont = painter->font(); - - // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - - // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - if (!labelData.suffixPart.isEmpty()) - painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); - } - - // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Transforms the passed \a text and \a font to a tickLabelData structure that can then be further - processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and - exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. -*/ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const -{ - TickLabelData result; - - // determine whether beautiful decimal powers should be used - bool useBeautifulPowers = false; - int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart - int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart - if (substituteExponent) - { - ePos = text.indexOf(QLatin1Char('e')); - if (ePos > 0 && text.at(ePos-1).isDigit()) - { - eLast = ePos; - while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) - ++eLast; - if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power - useBeautifulPowers = true; - } - } - - // calculate text bounding rects and do string preparation for beautiful decimal powers: - result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) - { - // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent - // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) - result.basePart = QLatin1String("10"); - else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); - result.expPart = text.mid(ePos+1, eLast-ePos); - // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) - result.expPart.remove(0, 1); - // prepare smaller font for exponent: - result.expFont = font; - if (result.expFont.pointSize() > 0) - result.expFont.setPointSize(result.expFont.pointSize()*0.75); - else - result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); - // calculate bounding rects of base part(s), exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - if (!result.suffixPart.isEmpty()) - result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false - { - result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); - } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - - // calculate possibly different bounding rect after rotation: - result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) - { - QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); - } - - return result; -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Calculates the offset at which the top left corner of the specified tick label shall be drawn. - The offset is relative to a point right next to the tick the label belongs to. - - This function is thus responsible for e.g. centering tick labels under ticks and positioning them - appropriately when they are rotated. -*/ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const -{ - /* - calculate label offset from base point at tick (non-trivial, for best visual appearance): short - explanation for bottom axis: The anchor, i.e. the point in the label that is placed - horizontally under the corresponding tick is always on the label side that is closer to the - axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height - is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text - will be centered under the tick (i.e. displaced horizontally by half its height). At the same - time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick - labels. - */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = 0; - y = -labelData.totalBounds.height()/2.0; - } - } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = -labelData.totalBounds.height(); - } - } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; - y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = 0; - } - } - - return QPointF(x, y); -} - -/*! \internal - - Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label - to be drawn, depending on number format etc. Since only the largest tick label is wanted for the - margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a - smaller width/height. -*/ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const -{ - // note: this function must return the same tick label sizes as the placeTickLabel function. - QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label - { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } else // label caching disabled or no label with this text cached: - { - TickLabelData labelData = getTickLabelData(font, text); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} -/* end of 'src/axis/axis.cpp' */ - - -/* including file 'src/scatterstyle.cpp', size 17450 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPScatterStyle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPScatterStyle - \brief Represents the visual appearance of scatter points - - This class holds information about shape, color and size of scatter points. In plottables like - QCPGraph it is used to store how scatter points shall be drawn. For example, \ref - QCPGraph::setScatterStyle takes a QCPScatterStyle instance. - - A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a - fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can - be controlled with \ref setSize. - - \section QCPScatterStyle-defining Specifying a scatter style - - You can set all these configurations either by calling the respective functions on an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-1 - - Or you can use one of the various constructors that take different parameter combinations, making - it easy to specify a scatter style in a single call, like so: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-creation-2 - - \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable - - There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref - QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref - isPenDefined will return false. It leads to scatter points that inherit the pen from the - plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line - color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes - it very convenient to set up typical scatter settings: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpscatterstyle-shortcreation - - Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works - because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly - into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) - constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref - ScatterShape, where actually a QCPScatterStyle is expected. - - \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps - - QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. - - For custom shapes, you can provide a QPainterPath with the desired shape to the \ref - setCustomPath function or call the constructor that takes a painter path. The scatter shape will - automatically be set to \ref ssCustom. - - For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the - constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. - Note that \ref setSize does not influence the appearance of the pixmap. -*/ - -/* start documentation of inline functions */ - -/*! \fn bool QCPScatterStyle::isNone() const - - Returns whether the scatter shape is \ref ssNone. - - \see setShape -*/ - -/*! \fn bool QCPScatterStyle::isPenDefined() const - - Returns whether a pen has been defined for this scatter style. - - The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those - are \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen - is undefined, the pen of the respective plottable will be used for drawing scatters. - - If a pen was defined for this scatter style instance, and you now wish to undefine the pen, call - \ref undefinePen. - - \see setPen -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or - brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - and size to \a size. No brush is defined, i.e. the scatter point will not be filled. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - the brush color to \a fill (with a solid pattern), and size to \a size. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the - brush to \a brush, and size to \a size. - - \warning In some cases it might be tempting to directly use a pen style like Qt::NoPen as \a pen - and a color like Qt::blue as \a brush. Notice however, that the corresponding call\n - QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)\n - doesn't necessarily lead C++ to use this constructor in some cases, but might mistake - Qt::NoPen for a QColor and use the - \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) - constructor instead (which will lead to an unexpected look of the scatter points). To prevent - this, be more explicit with the parameter types. For example, use QBrush(Qt::blue) - instead of just Qt::blue, to clearly point out to the compiler that this constructor is - wanted. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape - is set to \ref ssPixmap. -*/ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The - scatter shape is set to \ref ssCustom. - - The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly - different meaning than for built-in scatter points: The custom path will be drawn scaled by a - factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its - original size by default. To for example double the size of the path, set \a size to 12. -*/ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Copies the specified \a properties from the \a other scatter style to this scatter style. -*/ -void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) -{ - if (properties.testFlag(spPen)) - { - setPen(other.pen()); - if (!other.isPenDefined()) - undefinePen(); - } - if (properties.testFlag(spBrush)) - setBrush(other.brush()); - if (properties.testFlag(spSize)) - setSize(other.size()); - if (properties.testFlag(spShape)) - { - setShape(other.shape()); - if (other.shape() == ssPixmap) - setPixmap(other.pixmap()); - else if (other.shape() == ssCustom) - setCustomPath(other.customPath()); - } -} - -/*! - Sets the size (pixel diameter) of the drawn scatter points to \a size. - - \see setShape -*/ -void QCPScatterStyle::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the shape to \a shape. - - Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref - ssPixmap and \ref ssCustom, respectively. - - \see setSize -*/ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) -{ - mShape = shape; -} - -/*! - Sets the pen that will be used to draw scatter points to \a pen. - - If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after - a call to this function, even if \a pen is Qt::NoPen. If you have defined a pen - previously by calling this function and now wish to undefine the pen, call \ref undefinePen. - - \see setBrush -*/ -void QCPScatterStyle::setPen(const QPen &pen) -{ - mPenDefined = true; - mPen = pen; -} - -/*! - Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter - shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. - - \see setPen -*/ -void QCPScatterStyle::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the pixmap that will be drawn as scatter point to \a pixmap. - - Note that \ref setSize does not influence the appearance of the pixmap. - - The scatter shape is automatically set to \ref ssPixmap. -*/ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) -{ - setShape(ssPixmap); - mPixmap = pixmap; -} - -/*! - Sets the custom shape that will be drawn as scatter point to \a customPath. - - The scatter shape is automatically set to \ref ssCustom. -*/ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) -{ - setShape(ssCustom); - mCustomPath = customPath; -} - -/*! - Sets this scatter style to have an undefined pen (see \ref isPenDefined for what an undefined pen - implies). - - A call to \ref setPen will define a pen. -*/ -void QCPScatterStyle::undefinePen() -{ - mPenDefined = false; -} - -/*! - Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an - undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. - - This function is used by plottables (or any class that wants to draw scatters) just before a - number of scatters with this style shall be drawn with the \a painter. - - \see drawShape -*/ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const -{ - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); -} - -/*! - Draws the scatter shape with \a painter at position \a pos. - - This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be - called before scatter points are drawn with \ref drawShape. - - \see applyTo -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const -{ - drawShape(painter, pos.x(), pos.y()); -} - -/*! \overload - Draws the scatter shape with \a painter at position \a x and \a y. -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const -{ - double w = mSize/2.0; - switch (mShape) - { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - QPointF lineArray[4] = {QPointF(x-w, y), - QPointF( x, y-w), - QPointF(x+w, y), - QPointF( x, y+w)}; - painter->drawPolygon(lineArray, 4); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), - QPointF(x+w, y+0.755*w), - QPointF( x, y-0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssTriangleInverted: - { - QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), - QPointF(x+w, y-0.755*w), - QPointF( x, y+0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssCrossSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - break; - } - case ssPlusSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCrossCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - break; - } - case ssPlusCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssPeace: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - break; - } - case ssPixmap: - { - const double widthHalf = mPixmap.width()*0.5; - const double heightHalf = mPixmap.height()*0.5; -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) - const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#else - const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); -#endif - if (clipRect.contains(x, y)) - painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } - } -} -/* end of 'src/scatterstyle.cpp' */ - -//amalgamation: add datacontainer.cpp - -/* including file 'src/plottable.cpp', size 38845 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecorator -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecorator - \brief Controls how a plottable's data selection is drawn - - Each \ref QCPAbstractPlottable instance has one \ref QCPSelectionDecorator (accessible via \ref - QCPAbstractPlottable::selectionDecorator) and uses it when drawing selected segments of its data. - - The selection decorator controls both pen (\ref setPen) and brush (\ref setBrush), as well as the - scatter style (\ref setScatterStyle) if the plottable draws scatters. Since a \ref - QCPScatterStyle is itself composed of different properties such as color shape and size, the - decorator allows specifying exactly which of those properties shall be used for the selected data - point, via \ref setUsedScatterProperties. - - A \ref QCPSelectionDecorator subclass instance can be passed to a plottable via \ref - QCPAbstractPlottable::setSelectionDecorator, allowing greater customizability of the appearance - of selected segments. - - Use \ref copyFrom to easily transfer the settings of one decorator to another one. This is - especially useful since plottables take ownership of the passed selection decorator, and thus the - same decorator instance can not be passed to multiple plottables. - - Selection decorators can also themselves perform drawing operations by reimplementing \ref - drawDecoration, which is called by the plottable's draw method. The base class \ref - QCPSelectionDecorator does not make use of this however. For example, \ref - QCPSelectionDecoratorBracket draws brackets around selected data segments. -*/ - -/*! - Creates a new QCPSelectionDecorator instance with default values -*/ -QCPSelectionDecorator::QCPSelectionDecorator() : - mPen(QColor(80, 80, 255), 2.5), - mBrush(Qt::NoBrush), - mScatterStyle(), - mUsedScatterProperties(QCPScatterStyle::spNone), - mPlottable(0) -{ -} - -QCPSelectionDecorator::~QCPSelectionDecorator() -{ -} - -/*! - Sets the pen that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the brush that will be used by the parent plottable to draw selected data segments. -*/ -void QCPSelectionDecorator::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the scatter style that will be used by the parent plottable to draw scatters in selected - data segments. - - \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the - plottable. The used properties can also be changed via \ref setUsedScatterProperties. -*/ -void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) -{ - mScatterStyle = scatterStyle; - setUsedScatterProperties(usedProperties); -} - -/*! - Use this method to define which properties of the scatter style (set via \ref setScatterStyle) - will be used for selected data segments. All properties of the scatter style that are not - specified in \a properties will remain as specified in the plottable's original scatter style. - - \see QCPScatterStyle::ScatterProperty -*/ -void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) -{ - mUsedScatterProperties = properties; -} - -/*! - Sets the pen of \a painter to the pen of this selection decorator. - - \see applyBrush, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyPen(QCPPainter *painter) const -{ - painter->setPen(mPen); -} - -/*! - Sets the brush of \a painter to the brush of this selection decorator. - - \see applyPen, getFinalScatterStyle -*/ -void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const -{ - painter->setBrush(mBrush); -} - -/*! - Returns the scatter style that the parent plottable shall use for selected scatter points. The - plottable's original (unselected) scatter style must be passed as \a unselectedStyle. Depending - on the setting of \ref setUsedScatterProperties, the returned scatter style is a mixture of this - selecion decorator's scatter style (\ref setScatterStyle), and \a unselectedStyle. - - \see applyPen, applyBrush, setScatterStyle -*/ -QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const -{ - QCPScatterStyle result(unselectedStyle); - result.setFromOther(mScatterStyle, mUsedScatterProperties); - - // if style shall inherit pen from plottable (has no own pen defined), give it the selected - // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the - // plottable: - if (!result.isPenDefined()) - result.setPen(mPen); - - return result; -} - -/*! - Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to - this selection decorator. -*/ -void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) -{ - setPen(other->pen()); - setBrush(other->brush()); - setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); -} - -/*! - This method is called by all plottables' draw methods to allow custom selection decorations to be - drawn. Use the passed \a painter to perform the drawing operations. \a selection carries the data - selection for which the decoration shall be drawn. - - The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so - this method does nothing. -*/ -void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - Q_UNUSED(painter) - Q_UNUSED(selection) -} - -/*! \internal - - This method is called as soon as a selection decorator is associated with a plottable, by a call - to \ref QCPAbstractPlottable::setSelectionDecorator. This way the selection decorator can obtain a pointer to the plottable that uses it (e.g. to access - data points via the \ref QCPAbstractPlottable::interface1D interface). - - If the selection decorator was already added to a different plottable before, this method aborts - the registration and returns false. -*/ -bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottable) - { - mPlottable = plottable; - return true; - } else - { - qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); - return false; - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable - \brief The abstract base class for all data representing objects in a plot. - - It defines a very basic interface like name, pen, brush, visibility etc. Since this class is - abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to - create new ways of displaying data (see "Creating own plottables" below). Plottables that display - one-dimensional data (i.e. data points have a single key dimension and one or multiple values at - each key) are based off of the template subclass \ref QCPAbstractPlottable1D, see details - there. - - All further specifics are in the subclasses, for example: - \li A normal graph with possibly a line and/or scatter points \ref QCPGraph - (typically created with \ref QCustomPlot::addGraph) - \li A parametric curve: \ref QCPCurve - \li A bar chart: \ref QCPBars - \li A statistical box plot: \ref QCPStatisticalBox - \li A color encoded two-dimensional map: \ref QCPColorMap - \li An OHLC/Candlestick chart: \ref QCPFinancial - - \section plottables-subclassing Creating own plottables - - Subclassing directly from QCPAbstractPlottable is only recommended if you wish to display - two-dimensional data like \ref QCPColorMap, i.e. two logical key dimensions and one (or more) - data dimensions. If you want to display data with only one logical key dimension, you should - rather derive from \ref QCPAbstractPlottable1D. - - If subclassing QCPAbstractPlottable directly, these are the pure virtual functions you must - implement: - \li \ref selectTest - \li \ref draw - \li \ref drawLegendIcon - \li \ref getKeyRange - \li \ref getValueRange - - See the documentation of those functions for what they need to do. - - For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot - coordinates to pixel coordinates. This function is quite convenient, because it takes the - orientation of the key and value axes into account for you (x and y are swapped when the key axis - is vertical and the value axis horizontal). If you are worried about performance (i.e. you need - to translate many points in a loop like QCPGraph), you can directly use \ref - QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis - yourself. - - Here are some important members you inherit from QCPAbstractPlottable: - - - - - - - - - - - - - - - - - - - - - - - - - - -
QCustomPlot *\b mParentPlotA pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.
QString \b mNameThe name of the plottable.
QPen \b mPenThe generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable - (e.g QCPGraph uses this pen for its graph lines and scatters)
QBrush \b mBrushThe generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable - (e.g. QCPGraph uses this brush to control filling under the graph)
QPointer<\ref QCPAxis> \b mKeyAxis, \b mValueAxisThe key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates - to pixels in either the key or value dimension. Make sure to check whether the pointer is null before using it. If one of - the axes is null, don't draw the plottable.
\ref QCPSelectionDecorator \b mSelectionDecoratorThe currently set selection decorator which specifies how selected data of the plottable shall be drawn and decorated. - When drawing your data, you must consult this decorator for the appropriate pen/brush before drawing unselected/selected data segments. - Finally, you should call its \ref QCPSelectionDecorator::drawDecoration method at the end of your \ref draw implementation.
\ref QCP::SelectionType \b mSelectableIn which composition, if at all, this plottable's data may be selected. Enforcing this setting on the data selection is done - by QCPAbstractPlottable automatically.
\ref QCPDataSelection \b mSelectionHolds the current selection state of the plottable's data, i.e. the selected data ranges (\ref QCPDataRange).
-*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionDecorator *QCPAbstractPlottable::selectionDecorator() const - - Provides access to the selection decorator of this plottable. The selection decorator controls - how selected data ranges are drawn (e.g. their pen color and fill), see \ref - QCPSelectionDecorator for details. - - If you wish to use an own \ref QCPSelectionDecorator subclass, pass an instance of it to \ref - setSelectionDecorator. -*/ - -/*! \fn bool QCPAbstractPlottable::selected() const - - Returns true if there are any data points of the plottable currently selected. Use \ref selection - to retrieve the current \ref QCPDataSelection. -*/ - -/*! \fn QCPDataSelection QCPAbstractPlottable::selection() const - - Returns a \ref QCPDataSelection encompassing all the data points that are currently selected on - this plottable. - - \see selected, setSelection, setSelectable -*/ - -/*! \fn virtual QCPPlottableInterface1D *QCPAbstractPlottable::interface1D() - - If this plottable is a one-dimensional plottable, i.e. it implements the \ref - QCPPlottableInterface1D, returns the \a this pointer with that type. Otherwise (e.g. in the case - of a \ref QCPColorMap) returns zero. - - You can use this method to gain read access to data coordinates while holding a pointer to the - abstract base class only. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of pure virtual functions */ - -/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 - \internal - - called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation - of this plottable inside \a rect, next to the plottable name. - - The passed \a painter has its cliprect set to \a rect, so painting outside of \a rect won't - appear outside the legend icon border. -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const = 0 - - Returns the coordinate range that all data in this plottable span in the key axis dimension. For - logarithmic plots, one can set \a inSignDomain to either \ref QCP::sdNegative or \ref - QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only - negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and all positive points - will be ignored for range calculation. For no restriction, just set \a inSignDomain to \ref - QCP::sdBoth (default). \a foundRange is an output parameter that indicates whether a range could - be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getValueRange -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const = 0 - - Returns the coordinate range that the data points in the specified key range (\a inKeyRange) span - in the value axis dimension. For logarithmic plots, one can set \a inSignDomain to either \ref - QCP::sdNegative or \ref QCP::sdPositive in order to restrict the returned range to that sign - domain. E.g. when only negative range is wanted, set \a inSignDomain to \ref QCP::sdNegative and - all positive points will be ignored for range calculation. For no restriction, just set \a - inSignDomain to \ref QCP::sdBoth (default). \a foundRange is an output parameter that indicates - whether a range could be found or not. If this is false, you shouldn't use the returned range - (e.g. no points in data). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero (e.g. when there is only one data point). In this case \a - foundRange would return true, but the returned range is not a valid range in terms of \ref - QCPRange::validRange. - - \see rescaleAxes, getKeyRange -*/ - -/* end of documentation of pure virtual functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selected indicates whether - there are any points selected or not. - - \see selectionChanged(const QCPDataSelection &selection) -*/ - -/*! \fn void QCPAbstractPlottable::selectionChanged(const QCPDataSelection &selection) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelection. The parameter \a selection holds the - currently selected data ranges. - - \see selectionChanged(bool selected) -*/ - -/*! \fn void QCPAbstractPlottable::selectableChanged(QCP::SelectionType selectable); - - This signal is emitted when the selectability of this plottable has changed. - - \see setSelectable -*/ - -/* end of documentation of signals */ - -/*! - Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as - its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance - and have perpendicular orientations. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, - it can't be directly instantiated. - - You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. -*/ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), - mName(), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mPen(Qt::black), - mBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(QCP::stWhole), - mSelectionDecorator(0) -{ - if (keyAxis->parentPlot() != valueAxis->parentPlot()) - qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) - qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; - - mParentPlot->registerPlottable(this); - setSelectionDecorator(new QCPSelectionDecorator); -} - -QCPAbstractPlottable::~QCPAbstractPlottable() -{ - if (mSelectionDecorator) - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - The name is the textual representation of this plottable as it is displayed in the legend - (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. -*/ -void QCPAbstractPlottable::setName(const QString &name) -{ - mName = name; -} - -/*! - Sets whether fills of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) -{ - mAntialiasedFill = enabled; -} - -/*! - Sets whether the scatter symbols of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) -{ - mAntialiasedScatters = enabled; -} - -/*! - The pen is used to draw basic lines that make up the plottable representation in the - plot. - - For example, the \ref QCPGraph subclass draws its graph lines with this pen. - - \see setBrush -*/ -void QCPAbstractPlottable::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - The brush is used to draw basic fills of the plottable representation in the - plot. The Fill can be a color, gradient or texture, see the usage of QBrush. - - For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when - it's not set to Qt::NoBrush. - - \see setPen -*/ -void QCPAbstractPlottable::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal - to the plottable's value axis. This function performs no checks to make sure this is the case. - The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the - y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setValueAxis -*/ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) -{ - mKeyAxis = axis; -} - -/*! - The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is - orthogonal to the plottable's key axis. This function performs no checks to make sure this is the - case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and - the y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setKeyAxis -*/ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) -{ - mValueAxis = axis; -} - - -/*! - Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently - (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref - selectionDecorator). - - The entire selection mechanism for plottables is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when - you wish to change the selection state programmatically. - - Using \ref setSelectable you can further specify for each plottable whether and to which - granularity it is selectable. If \a selection is not compatible with the current \ref - QCP::SelectionType set via \ref setSelectable, the resulting selection will be adjusted - accordingly (see \ref QCPDataSelection::enforceType). - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractPlottable::setSelection(QCPDataSelection selection) -{ - selection.enforceType(mSelectable); - if (mSelection != selection) - { - mSelection = selection; - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } -} - -/*! - Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to - customize the visual representation of selected data ranges further than by using the default - QCPSelectionDecorator. - - The plottable takes ownership of the \a decorator. - - The currently set decorator can be accessed via \ref selectionDecorator. -*/ -void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) -{ - if (decorator) - { - if (decorator->registerWithPlottable(this)) - { - if (mSelectionDecorator) // delete old decorator if necessary - delete mSelectionDecorator; - mSelectionDecorator = decorator; - } - } else if (mSelectionDecorator) // just clear decorator - { - delete mSelectionDecorator; - mSelectionDecorator = 0; - } -} - -/*! - Sets whether and to which granularity this plottable can be selected. - - A selection can happen by clicking on the QCustomPlot surface (When \ref - QCustomPlot::setInteractions contains \ref QCP::iSelectPlottables), by dragging a selection rect - (When \ref QCustomPlot::setSelectionRectMode is \ref QCP::srmSelect), or programmatically by - calling \ref setSelection. - - \see setSelection, QCP::SelectionType -*/ -void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - QCPDataSelection oldSelection = mSelection; - mSelection.enforceType(mSelectable); - Q_EMIT selectableChanged(mSelectable); - if (mSelection != oldSelection) - { - Q_EMIT selectionChanged(selected()); - Q_EMIT selectionChanged(mSelection); - } - } -} - - -/*! - Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. - - \see pixelsToCoords, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else - { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); - } -} - -/*! \overload - - Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. -*/ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); - else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); -} - -/*! - Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. - - \see coordsToPixels, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else - { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); - } -} - -/*! \overload - - Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. -*/ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const -{ - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); -} - -/*! - Rescales the key and value axes associated with this plottable to contain all displayed data, so - the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make - sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. - Instead it will stay in the current sign domain and ignore all parts of the plottable that lie - outside of that domain. - - \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show - multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has - \a onlyEnlarge set to false (the default), and all subsequent set to true. - - \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale -*/ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const -{ - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); -} - -/*! - Rescales the key axis of the plottable so the whole plottable is visible. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); - } - } - keyAxis->setRange(newRange); - } -} - -/*! - Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is - set to true, only the data points which are in the currently visible key axis range are - considered. - - Returns true if the axis was actually scaled. This might not be the case if this plottable has an - invalid range, e.g. because it has no data points. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); - } - } - valueAxis->setRange(newRange); - } -} - -/*! \overload - - Adds this plottable to the specified \a legend. - - Creates a QCPPlottableLegendItem which is inserted into the legend. Returns true on success, i.e. - when the legend exists and a legend item associated with this plottable isn't already in the - legend. - - If the plottable needs a more specialized representation in the legend, you can create a - corresponding subclass of \ref QCPPlottableLegendItem and add it to the legend manually instead - of calling this method. - - \see removeFromLegend, QCPLegend::addItem -*/ -bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - if (legend->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; - return false; - } - - if (!legend->hasItemWithPlottable(this)) - { - legend->addItem(new QCPPlottableLegendItem(legend, this)); - return true; - } else - return false; -} - -/*! \overload - - Adds this plottable to the legend of the parent QCustomPlot (\ref QCustomPlot::legend). - - \see removeFromLegend -*/ -bool QCPAbstractPlottable::addToLegend() -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return addToLegend(mParentPlot->legend); -} - -/*! \overload - - Removes the plottable from the specifed \a legend. This means the \ref QCPPlottableLegendItem - that is associated with this plottable is removed. - - Returns true on success, i.e. if the legend exists and a legend item associated with this - plottable was found and removed. - - \see addToLegend, QCPLegend::removeItem -*/ -bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const -{ - if (!legend) - { - qDebug() << Q_FUNC_INFO << "passed legend is null"; - return false; - } - - if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) - return legend->removeItem(lip); - else - return false; -} - -/*! \overload - - Removes the plottable from the legend of the parent QCustomPlot. - - \see addToLegend -*/ -bool QCPAbstractPlottable::removeFromLegend() const -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - else - return removeFromLegend(mParentPlot->legend); -} - -/* inherits documentation from base class */ -QRect QCPAbstractPlottable::clipRect() const -{ - if (mKeyAxis && mValueAxis) - return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - else - return QRect(); -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractPlottable::selectionCategory() const -{ - return QCP::iSelectPlottables; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable fills. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint -*/ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable scatter points. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint -*/ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - - if (mSelectable != QCP::stNone) - { - QCPDataSelection newSelection = details.value(); - QCPDataSelection selectionBefore = mSelection; - if (additive) - { - if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit - { - if (selected()) - setSelection(QCPDataSelection()); - else - setSelection(newSelection); - } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments - { - if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection - setSelection(mSelection-newSelection); - else - setSelection(mSelection+newSelection); - } - } else - setSelection(newSelection); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable != QCP::stNone) - { - QCPDataSelection selectionBefore = mSelection; - setSelection(QCPDataSelection()); - if (selectionStateChanged) - *selectionStateChanged = mSelection != selectionBefore; - } -} -/* end of 'src/plottable.cpp' */ - - -/* including file 'src/item.cpp', size 49269 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemAnchor -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemAnchor - \brief An anchor of an item to which positions can be attached to. - - An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't - control anything on its item, but provides a way to tie other items via their positions to the - anchor. - - For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. - Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can - attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by - calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the - QCPItemRect. This way the start of the line will now always follow the respective anchor location - on the rect item. - - Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an - anchor to other positions. - - To learn how to provide anchors in your own item subclasses, see the subclassing section of the - QCPAbstractItem documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() - - Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if - it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). - - This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids - dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with - gcc compiler). -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) -{ -} - -QCPItemAnchor::~QCPItemAnchor() -{ - // unregister as parent at children: - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } -} - -/*! - Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. - - The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the - parent item, QCPItemAnchor is just an intermediary. -*/ -QPointF QCPItemAnchor::pixelPosition() const -{ - if (mParentItem) - { - if (mAnchorId > -1) - { - return mParentItem->anchorPixelPosition(mAnchorId); - } else - { - qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; - return QPointF(); - } - } else - { - qDebug() << Q_FUNC_INFO << "no parent item set"; - return QPointF(); - } -} - -/*! \internal - - Adds \a pos to the childX list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.contains(pos)) - mChildrenX.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childX list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildX(QCPItemPosition *pos) -{ - if (!mChildrenX.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - -/*! \internal - - Adds \a pos to the childY list of this anchor, which keeps track of which children use this - anchor as parent anchor for the respective coordinate. This is necessary to notify the children - prior to destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.contains(pos)) - mChildrenY.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); -} - -/*! \internal - - Removes \a pos from the childY list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChildY(QCPItemPosition *pos) -{ - if (!mChildrenY.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPosition -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPosition - \brief Manages the position of an item. - - Every item has at least one public QCPItemPosition member pointer which provides ways to position the - item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: - \a topLeft and \a bottomRight. - - QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type - defines how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel - coordinates, as plot coordinates of certain axes, etc. For more advanced plots it is also - possible to assign different types per X/Y coordinate of the position (see \ref setTypeX, \ref - setTypeY). This way an item could be positioned at a fixed pixel distance from the top in the Y - direction, while following a plot coordinate in the X direction. - - A QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. This way you can tie - multiple items together. If the QCPItemPosition has a parent, its coordinates (\ref setCoords) - are considered to be absolute pixels in the reference frame of the parent anchor, where (0, 0) - means directly ontop of the parent anchor. For example, You could attach the \a start position of - a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting point of the line - always be centered under the text label, no matter where the text is moved to. For more advanced - plots, it is possible to assign different parent anchors per X/Y coordinate of the position, see - \ref setParentAnchorX, \ref setParentAnchorY. This way an item could follow another item in the X - direction but stay at a fixed position in the Y direction. Or even follow item A in X, and item B - in Y. - - Note that every QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent - anchor for other positions. - - To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPosition. This - works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref - setPixelPosition transforms the coordinates appropriately, to make the position appear at the specified - pixel values. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPItemPosition::PositionType *QCPItemPosition::type() const - - Returns the current position type. - - If different types were set for X and Y (\ref setTypeX, \ref setTypeY), this method returns the - type of the X coordinate. In that case rather use \a typeX() and \a typeY(). - - \see setType -*/ - -/*! \fn QCPItemAnchor *QCPItemPosition::parentAnchor() const - - Returns the current parent anchor. - - If different parent anchors were set for X and Y (\ref setParentAnchorX, \ref setParentAnchorY), - this method returns the parent anchor of the Y coordinate. In that case rather use \a - parentAnchorX() and \a parentAnchorY(). - - \see setParentAnchor -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionTypeX(ptAbsolute), - mPositionTypeY(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchorX(0), - mParentAnchorY(0) -{ -} - -QCPItemPosition::~QCPItemPosition() -{ - // unregister as parent at children: - // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then - // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition - Q_FOREACH (QCPItemPosition *child, mChildrenX.toList()) - { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX - } - Q_FOREACH (QCPItemPosition *child, mChildrenY.toList()) - { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY - } - // unregister as child in parent: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const -{ - return mAxisRect.data(); -} - -/*! - Sets the type of the position. The type defines how the coordinates passed to \ref setCoords - should be handled and how the QCPItemPosition should behave in the plot. - - The possible values for \a type can be separated in two main categories: - - \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords - and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. - By default, the QCustomPlot's x- and yAxis are used. - - \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This - corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref - ptAxisRectRatio. They differ only in the way the absolute position is described, see the - documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify - the axis rect with \ref setAxisRect. By default this is set to the main axis rect. - - Note that the position type \ref ptPlotCoords is only available (and sensible) when the position - has no parent anchor (\ref setParentAnchor). - - If the type is changed, the apparent pixel position on the plot is preserved. This means - the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. - - This method sets the type for both X and Y directions. It is also possible to set different types - for X and Y, see \ref setTypeX, \ref setTypeY. -*/ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) -{ - setTypeX(type); - setTypeY(type); -} - -/*! - This method sets the position type of the X coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeY -*/ -void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) -{ - if (mPositionTypeX != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeX = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - This method sets the position type of the Y coordinate to \a type. - - For a detailed description of what a position type is, see the documentation of \ref setType. - - \see setType, setTypeX -*/ -void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) -{ - if (mPositionTypeY != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. - bool retainPixelPosition = true; - if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - retainPixelPosition = false; - if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - retainPixelPosition = false; - - QPointF pixel; - if (retainPixelPosition) - pixel = pixelPosition(); - - mPositionTypeY = type; - - if (retainPixelPosition) - setPixelPosition(pixel); - } -} - -/*! - Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now - follow any position changes of the anchor. The local coordinate system of positions with a parent - anchor always is absolute pixels, with (0, 0) being exactly on top of the parent anchor. (Hence - the type shouldn't be set to \ref ptPlotCoords for positions with parent anchors.) - - if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved - during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position - will be exactly on top of the parent anchor. - - To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. - - If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is - set to \ref ptAbsolute, to keep the position in a valid state. - - This method sets the parent anchor for both X and Y directions. It is also possible to set - different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. -*/ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); - bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); - return successX && successY; -} - -/*! - This method sets the parent anchor of the X coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorY -*/ -bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorX(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) - setTypeX(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildX(this); - mParentAnchorX = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(0, coords().y()); - return true; -} - -/*! - This method sets the parent anchor of the Y coordinate to \a parentAnchor. - - For a detailed description of what a parent anchor is, see the documentation of \ref setParentAnchor. - - \see setParentAnchor, setParentAnchorX -*/ -bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); - return false; - } - currentParent = currentParentPos->parentAnchorY(); - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) - setTypeY(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPosition(); - // unregister at current parent anchor: - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildY(this); - mParentAnchorY = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); - else - setCoords(coords().x(), 0); - return true; -} - -/*! - Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type - (\ref setType, \ref setTypeX, \ref setTypeY). - - For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position - on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the - QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the - plot coordinate system defined by the axes set by \ref setAxes. By default those are the - QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available - coordinate types and their meaning. - - If different types were configured for X and Y (\ref setTypeX, \ref setTypeY), \a key and \a - value must also be provided in the different coordinate systems. Here, the X type refers to \a - key, and the Y type refers to \a value. - - \see setPixelPosition -*/ -void QCPItemPosition::setCoords(double key, double value) -{ - mKey = key; - mValue = value; -} - -/*! \overload - - Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the - meaning of \a value of the \ref setCoords(double key, double value) method. -*/ -void QCPItemPosition::setCoords(const QPointF &pos) -{ - setCoords(pos.x(), pos.y()); -} - -/*! - Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It - includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). - - \see setPixelPosition -*/ -QPointF QCPItemPosition::pixelPosition() const -{ - QPointF result; - - // determine X: - switch (mPositionTypeX) - { - case ptAbsolute: - { - result.rx() = mKey; - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - result.rx() = mKey*mParentPlot->viewport().width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mParentPlot->viewport().left(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.rx() = mKey*mAxisRect.data()->width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mAxisRect.data()->left(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - // determine Y: - switch (mPositionTypeY) - { - case ptAbsolute: - { - result.ry() = mValue; - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - result.ry() = mValue*mParentPlot->viewport().height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mParentPlot->viewport().top(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.ry() = mValue*mAxisRect.data()->height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mAxisRect.data()->top(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - result.ry() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - result.ry() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - return result; -} - -/*! - When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the - coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and - yAxis of the QCustomPlot. -*/ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - mKeyAxis = keyAxis; - mValueAxis = valueAxis; -} - -/*! - When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the - coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of - the QCustomPlot. -*/ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) -{ - mAxisRect = axisRect; -} - -/*! - Sets the apparent pixel position. This works no matter what type (\ref setType) this - QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed - appropriately, to make the position finally appear at the specified pixel values. - - Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is - identical to that of \ref setCoords. - - \see pixelPosition, setCoords -*/ -void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) -{ - double x = pixelPosition.x(); - double y = pixelPosition.y(); - - switch (mPositionTypeX) - { - case ptAbsolute: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mParentPlot->viewport().left(); - x /= (double)mParentPlot->viewport().width(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mAxisRect.data()->left(); - x /= (double)mAxisRect.data()->width(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - x = mKeyAxis.data()->pixelToCoord(x); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - y = mValueAxis.data()->pixelToCoord(x); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - switch (mPositionTypeY) - { - case ptAbsolute: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mParentPlot->viewport().top(); - y /= (double)mParentPlot->viewport().height(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mAxisRect.data()->top(); - y /= (double)mAxisRect.data()->height(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - x = mKeyAxis.data()->pixelToCoord(y); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - y = mValueAxis.data()->pixelToCoord(y); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - setCoords(x, y); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractItem - \brief The abstract base class for all items in a plot. - - In QCustomPlot, items are supplemental graphical elements that are neither plottables - (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus - plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each - specific item has at least one QCPItemPosition member which controls the positioning. Some items - are defined by more than one coordinate and thus have two or more QCPItemPosition members (For - example, QCPItemRect has \a topLeft and \a bottomRight). - - This abstract base class defines a very basic interface like visibility and clipping. Since this - class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass - yourself to create new items. - - The built-in items are: - - - - - - - - - - -
QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.
- - \section items-clipping Clipping - - Items are by default clipped to the main axis rect (they are only visible inside the axis rect). - To make an item visible outside that axis rect, disable clipping via \ref setClipToAxisRect - "setClipToAxisRect(false)". - - On the other hand if you want the item to be clipped to a different axis rect, specify it via - \ref setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and - in principle is independent of the coordinate axes the item might be tied to via its position - members (\ref QCPItemPosition::setAxes). However, it is common that the axis rect for clipping - also contains the axes used for the item positions. - - \section items-using Using items - - First you instantiate the item you want to use and add it to the plot: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-1 - by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just - set the plot coordinates where the line should start/end: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-2 - If we don't want the line to be positioned in plot coordinates but a different coordinate system, - e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-3 - Then we can set the coordinates, this time in pixels: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-4 - and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpitemline-creation-5 - - For more advanced plots, it is even possible to set different types and parent anchors per X/Y - coordinate of an item position, using for example \ref QCPItemPosition::setTypeX or \ref - QCPItemPosition::setParentAnchorX. For details, see the documentation of \ref QCPItemPosition. - - \section items-subclassing Creating own items - - To create an own item, you implement a subclass of QCPAbstractItem. These are the pure - virtual functions, you must implement: - \li \ref selectTest - \li \ref draw - - See the documentation of those functions for what they need to do. - - \subsection items-positioning Allowing the item to be positioned - - As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall - have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add - a public member of type QCPItemPosition like so: - - \code QCPItemPosition * const myPosition;\endcode - - the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition - instance it points to, can be modified, of course). - The initialization of this pointer is made easy with the \ref createPosition function. Just assign - the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition - takes a string which is the name of the position, typically this is identical to the variable name. - For example, the constructor of QCPItemExample could look like this: - - \code - QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - myPosition(createPosition("myPosition")) - { - // other constructor code - } - \endcode - - \subsection items-drawing The draw function - - To give your item a visual representation, reimplement the \ref draw function and use the passed - QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the - position member(s) via \ref QCPItemPosition::pixelPosition. - - To optimize performance you should calculate a bounding rect first (don't forget to take the pen - width into account), check whether it intersects the \ref clipRect, and only draw the item at all - if this is the case. - - \subsection items-selection The selectTest function - - Your implementation of the \ref selectTest function may use the helpers \ref - QCPVector2D::distanceSquaredToLine and \ref rectDistance. With these, the implementation of the - selection test becomes significantly simpler for most items. See the documentation of \ref - selectTest for what the function parameters mean and what the function should return. - - \subsection anchors Providing anchors - - Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public - member, e.g. - - \code QCPItemAnchor * const bottom;\endcode - - and create it in the constructor with the \ref createAnchor function, assigning it a name and an - anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). - Since anchors can be placed anywhere, relative to the item's position(s), your item needs to - provide the position of every anchor with the reimplementation of the \ref anchorPixelPosition(int - anchorId) function. - - In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel - position when anything attached to the anchor needs to know the coordinates. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QList QCPAbstractItem::positions() const - - Returns all positions of the item in a list. - - \see anchors, position -*/ - -/*! \fn QList QCPAbstractItem::anchors() const - - Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always - also an anchor, the list will also contain the positions of this item. - - \see positions, anchor -*/ - -/* end of documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 - \internal - - Draws this item with the provided \a painter. - - The cliprect of the provided painter is set to the rect returned by \ref clipRect before this - function is called. The clipRect depends on the clipping settings defined by \ref - setClipToAxisRect and \ref setClipAxisRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPAbstractItem::selectionChanged(bool selected) - This signal is emitted when the selection state of this item has changed, either by user interaction - or by a direct call to \ref setSelected. -*/ - -/* end documentation of signals */ - -/*! - Base class constructor which initializes base class members. -*/ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) -{ - parentPlot->registerItem(this); - - QList rects = parentPlot->axisRects(); - if (rects.size() > 0) - { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); - } -} - -QCPAbstractItem::~QCPAbstractItem() -{ - // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const -{ - return mClipAxisRect.data(); -} - -/*! - Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the - entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. - - \see setClipAxisRect -*/ -void QCPAbstractItem::setClipToAxisRect(bool clip) -{ - mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref - setClipToAxisRect is set to true. - - \see setClipToAxisRect -*/ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) -{ - mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected. - - \see QCustomPlot::setInteractions, setSelected -*/ -void QCPAbstractItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this item is selected or not. When selected, it might use a different visual - appearance (e.g. pen and brush), this depends on the specific item though. - - The entire selection mechanism for items is handled automatically when \ref - QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this - function when you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/*! - Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by - that name, returns 0. - - This function provides an alternative way to access item positions. Normally, you access - positions direcly by their member pointers (which typically have the same variable name as \a - name). - - \see positions, anchor -*/ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const -{ - for (int i=0; iname() == name) - return mPositions.at(i); - } - qDebug() << Q_FUNC_INFO << "position with name not found:" << name; - return 0; -} - -/*! - Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by - that name, returns 0. - - This function provides an alternative way to access item anchors. Normally, you access - anchors direcly by their member pointers (which typically have the same variable name as \a - name). - - \see anchors, position -*/ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const -{ - for (int i=0; iname() == name) - return mAnchors.at(i); - } - qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; - return 0; -} - -/*! - Returns whether this item has an anchor with the specified \a name. - - Note that you can check for positions with this function, too. This is because every position is - also an anchor (QCPItemPosition inherits from QCPItemAnchor). - - \see anchor, position -*/ -bool QCPAbstractItem::hasAnchor(const QString &name) const -{ - for (int i=0; iname() == name) - return true; - } - return false; -} - -/*! \internal - - Returns the rect the visual representation of this item is clipped to. This depends on the - current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. - - If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned. - - \see draw -*/ -QRect QCPAbstractItem::clipRect() const -{ - if (mClipToAxisRect && mClipAxisRect) - return mClipAxisRect.data()->rect(); - else - return mParentPlot->viewport(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing item lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); -} - -/*! \internal - - A convenience function which returns the selectTest value for a specified \a rect and a specified - click position \a pos. \a filledRect defines whether a click inside the rect should also be - considered a hit or whether only the rect border is sensitive to hits. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - For example, if your item consists of four rects, call this function four times, once for each - rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four - returned values. -*/ -double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const -{ - double result = -1; - - // distance to border: - QList lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = std::numeric_limits::max(); - for (int i=0; i mParentPlot->selectionTolerance()*0.99) - { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/*! \internal - - Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in - item subclasses if they want to provide anchors (QCPItemAnchor). - - For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor - ids and returns the respective pixel points of the specified anchor. - - \see createAnchor -*/ -QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const -{ - qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the position - member (This is needed to provide the name-based \ref position access to positions). - - Don't delete positions created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each position member. Don't create QCPItemPositions with \b new yourself, because they - won't be registered with the item properly. - - \see createAnchor -*/ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); - return newPosition; -} - -/*! \internal - - Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the anchor - member (This is needed to provide the name based \ref anchor access to anchors). - - The \a anchorId must be a number identifying the created anchor. It is recommended to create an - enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor - to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns - the correct pixel coordinates for the passed anchor id. - - Don't delete anchors created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they - won't be registered with the item properly. - - \see createPosition -*/ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); - return newAnchor; -} - -/* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractItem::selectionCategory() const -{ - return QCP::iSelectItems; -} -/* end of 'src/item.cpp' */ - - -/* including file 'src/core.cpp', size 125037 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCustomPlot -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCustomPlot - - \brief The central class of the library. This is the QWidget which displays the plot and - interacts with the user. - - For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPSelectionRect *QCustomPlot::selectionRect() const - - Allows access to the currently used QCPSelectionRect instance (or subclass thereof), that is used - to handle and draw selection rect interactions (see \ref setSelectionRectMode). - - \see setSelectionRect -*/ - -/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const - - Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just - one cell with the main QCPAxisRect inside. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse double click event. -*/ - -/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse press event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. -*/ - -/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse move event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. - - \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, - because the dragging starting point was saved the moment the mouse was pressed. Thus it only has - a meaning for the range drag axes that were set at that moment. If you want to change the drag - axes, consider doing this in the \ref mousePress signal instead. -*/ - -/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse release event. - - It is emitted before QCustomPlot handles any other mechanisms like object selection. So a - slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or - \ref QCPAbstractPlottable::setSelectable. -*/ - -/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse wheel event. - - It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref - QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. -*/ - -/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableDoubleClick -*/ - -/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) - - This signal is emitted when a plottable is double clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. The parameter \a dataIndex indicates the data point that was closest to the click - position. - - \see plottableClick -*/ - -/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemDoubleClick -*/ - -/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is double clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemClick -*/ - -/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisDoubleClick -*/ - -/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is double clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisClick -*/ - -/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendDoubleClick -*/ - -/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is double clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendClick -*/ - -/*! \fn void QCustomPlot::selectionChangedByUser() - - This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by - clicking. It is not emitted when the selection state of an object has changed programmatically by - a direct call to setSelected()/setSelection() on an object or by calling \ref - deselectAll. - - In addition to this signal, selectable objects also provide individual signals, for example \ref - QCPAxis::selectionChanged or \ref QCPAbstractPlottable::selectionChanged. Note that those signals - are emitted even if the selection state is changed programmatically. - - See the documentation of \ref setInteractions for details about the selection mechanism. - - \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends -*/ - -/*! \fn void QCustomPlot::beforeReplot() - - This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, afterReplot -*/ - -/*! \fn void QCustomPlot::afterReplot() - - This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, beforeReplot -*/ - -/* end of documentation of signals */ -/* start of documentation of public members */ - -/*! \var QCPAxis *QCustomPlot::xAxis - - A pointer to the primary x Axis (bottom) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis - - A pointer to the primary y Axis (left) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::xAxis2 - - A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis2 - - A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/*! \var QCPLegend *QCustomPlot::legend - - A pointer to the default legend of the main axis rect. The legend is invisible by default. Use - QCPLegend::setVisible to change this. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple legends to the plot, use the layout system interface to - access the new legend. For example, legends can be placed inside an axis rect's \ref - QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If - the default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointer becomes 0. - - If an axis convenience pointer is currently zero and a new axis rect or a corresponding axis is - added in the place of the main axis rect, QCustomPlot resets the convenience pointers to the - according new axes. Similarly the \ref legend convenience pointer will be reset if a legend is - added after the main legend was removed before. -*/ - -/* end of documentation of public members */ - -/*! - Constructs a QCustomPlot and sets reasonable default values. -*/ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), - mMultiSelectModifier(Qt::ControlModifier), - mSelectionRectMode(QCP::srmNone), - mSelectionRect(0), - mOpenGl(false), - mMouseHasMoved(false), - mMouseEventLayerable(0), - mMouseSignalLayerable(0), - mReplotting(false), - mReplotQueued(false), - mOpenGlMultisamples(16), - mOpenGlAntialiasedElementsBackup(QCP::aeNone), - mOpenGlCacheLabelsBackup(true) -{ - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); -# else - setBufferDevicePixelRatio(QWidget::devicePixelRatio()); -# endif -#endif - - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // create initial layers: - mLayers.append(new QCPLayer(this, QLatin1String("background"))); - mLayers.append(new QCPLayer(this, QLatin1String("grid"))); - mLayers.append(new QCPLayer(this, QLatin1String("main"))); - mLayers.append(new QCPLayer(this, QLatin1String("axes"))); - mLayers.append(new QCPLayer(this, QLatin1String("legend"))); - mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); - updateLayerIndices(); - setCurrentLayer(QLatin1String("main")); - layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); - - // create initial layout, axis rect and legend: - mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer(QLatin1String("main")); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); - legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer(QLatin1String("background")); - xAxis->setLayer(QLatin1String("axes")); - yAxis->setLayer(QLatin1String("axes")); - xAxis2->setLayer(QLatin1String("axes")); - yAxis2->setLayer(QLatin1String("axes")); - xAxis->grid()->setLayer(QLatin1String("grid")); - yAxis->grid()->setLayer(QLatin1String("grid")); - xAxis2->grid()->setLayer(QLatin1String("grid")); - yAxis2->grid()->setLayer(QLatin1String("grid")); - legend->setLayer(QLatin1String("legend")); - - // create selection rect instance: - mSelectionRect = new QCPSelectionRect(this); - mSelectionRect->setLayer(QLatin1String("overlay")); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(rpQueuedReplot); -} - -QCustomPlot::~QCustomPlot() -{ - clearPlottables(); - clearItems(); - - if (mPlotLayout) - { - delete mPlotLayout; - mPlotLayout = 0; - } - - mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed - mLayers.clear(); -} - -/*! - Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is - removed from there. - - \see setNotAntialiasedElements -*/ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) -{ - mAntialiasedElements = antialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. - - See \ref setAntialiasedElements for details. - - \see setNotAntialiasedElement -*/ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) -{ - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements |= antialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets which elements are forcibly drawn not antialiased as an \a or combination of - QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is - removed from there. - - \see setAntialiasedElements -*/ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) -{ - mNotAntialiasedElements = notAntialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. - - See \ref setNotAntialiasedElements for details. - - \see setAntialiasedElement -*/ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) -{ - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements |= notAntialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the - plottable to the legend (QCustomPlot::legend). - - \see addGraph, QCPLegend::addItem -*/ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) -{ - mAutoAddPlottableToLegend = on; -} - -/*! - Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction - enums. There are the following types of interactions: - - Axis range manipulation is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the - respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. - For details how to control which axes the user may drag/zoom and in what orientations, see \ref - QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, - \ref QCPAxisRect::setRangeZoomAxes. - - Plottable data selection is controlled by \ref QCP::iSelectPlottables. If \ref - QCP::iSelectPlottables is set, the user may select plottables (graphs, curves, bars,...) and - their data by clicking on them or in their vicinity (\ref setSelectionTolerance). Whether the - user can actually select a plottable and its data can further be restricted with the \ref - QCPAbstractPlottable::setSelectable method on the specific plottable. For details, see the - special page about the \ref dataselection "data selection mechanism". To retrieve a list of all - currently selected plottables, call \ref selectedPlottables. If you're only interested in - QCPGraphs, you may use the convenience function \ref selectedGraphs. - - Item selection is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user - may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find - out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of - all currently selected items, call \ref selectedItems. - - Axis selection is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user - may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick - labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for - each axis. To retrieve a list of all axes that currently contain selected parts, call \ref - selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). - - Legend selection is controlled with \ref QCP::iSelectLegend. If this is set, the user may - select the legend itself or individual items by clicking on them. What parts exactly are - selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the - legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To - find out which child items are selected, call \ref QCPLegend::selectedItems. - - All other selectable elements The selection of all other selectable objects (e.g. - QCPTextElement, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the - user may select those objects by clicking on them. To find out which are currently selected, you - need to check their selected state explicitly. - - If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is - emitted. Each selectable object additionally emits an individual selectionChanged signal whenever - their selection state has changed, i.e. not only by user interaction. - - To allow multiple objects to be selected by holding the selection modifier (\ref - setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. - - \note In addition to the selection mechanism presented here, QCustomPlot always emits - corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and - \ref plottableDoubleClick for example. - - \see setInteraction, setSelectionTolerance -*/ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) -{ - mInteractions = interactions; -} - -/*! - Sets the single \a interaction of this QCustomPlot to \a enabled. - - For details about the interaction system, see \ref setInteractions. - - \see setInteractions -*/ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) -{ - if (!enabled && mInteractions.testFlag(interaction)) - mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) - mInteractions |= interaction; -} - -/*! - Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or - not. - - If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a - potential selection when the minimum distance between the click position and the graph line is - smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks - directly inside the area and ignore this selection tolerance. In other words, it only has meaning - for parts of objects that are too thin to exactly hit with a click and thus need such a - tolerance. - - \see setInteractions, QCPLayerable::selectTest -*/ -void QCustomPlot::setSelectionTolerance(int pixels) -{ - mSelectionTolerance = pixels; -} - -/*! - Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes - ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves - performance during dragging. Thus it creates a more responsive user experience. As soon as the - user stops dragging, the last replot is done with normal antialiasing, to restore high image - quality. - - \see setAntialiasedElements, setNotAntialiasedElements -*/ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) -{ - mNoAntialiasingOnDrag = enabled; -} - -/*! - Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. - - \see setPlottingHint -*/ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) -{ - mPlottingHints = hints; -} - -/*! - Sets the specified plotting \a hint to \a enabled. - - \see setPlottingHints -*/ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) -{ - QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) - newHints &= ~hint; - else - newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); -} - -/*! - Sets the keyboard modifier that will be recognized as multi-select-modifier. - - If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple - objects (or data points) by clicking on them one after the other while holding down \a modifier. - - By default the multi-select-modifier is set to Qt::ControlModifier. - - \see setInteractions -*/ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) -{ - mMultiSelectModifier = modifier; -} - -/*! - Sets how QCustomPlot processes mouse click-and-drag interactions by the user. - - If \a mode is \ref QCP::srmNone, the mouse drag is forwarded to the underlying objects. For - example, QCPAxisRect may process a mouse drag by dragging axis ranges, see \ref - QCPAxisRect::setRangeDrag. If \a mode is not \ref QCP::srmNone, the current selection rect (\ref - selectionRect) becomes activated and allows e.g. rect zooming and data point selection. - - If you wish to provide your user both with axis range dragging and data selection/range zooming, - use this method to switch between the modes just before the interaction is processed, e.g. in - reaction to the \ref mousePress or \ref mouseMove signals. For example you could check whether - the user is holding a certain keyboard modifier, and then decide which \a mode shall be set. - - If a selection rect interaction is currently active, and \a mode is set to \ref QCP::srmNone, the - interaction is canceled (\ref QCPSelectionRect::cancel). Switching between any of the other modes - will keep the selection rect active. Upon completion of the interaction, the behaviour is as - defined by the currently set \a mode, not the mode that was set when the interaction started. - - \see setInteractions, setSelectionRect, QCPSelectionRect -*/ -void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) -{ - if (mSelectionRect) - { - if (mode == QCP::srmNone) - mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect - - // disconnect old connections: - if (mSelectionRectMode == QCP::srmSelect) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - - // establish new ones: - if (mode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } - - mSelectionRectMode = mode; -} - -/*! - Sets the \ref QCPSelectionRect instance that QCustomPlot will use if \a mode is not \ref - QCP::srmNone and the user performs a click-and-drag interaction. QCustomPlot takes ownership of - the passed \a selectionRect. It can be accessed later via \ref selectionRect. - - This method is useful if you wish to replace the default QCPSelectionRect instance with an - instance of a QCPSelectionRect subclass, to introduce custom behaviour of the selection rect. - - \see setSelectionRectMode -*/ -void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) -{ - if (mSelectionRect) - delete mSelectionRect; - - mSelectionRect = selectionRect; - - if (mSelectionRect) - { - // establish connections with new selection rect: - if (mSelectionRectMode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - } -} - -/*! - \warning This is still an experimental feature and its performance depends on the system that it - runs on. Having multiple QCustomPlot widgets in one application with enabled OpenGL rendering - might cause context conflicts on some systems. - - This method allows to enable OpenGL plot rendering, for increased plotting performance of - graphically demanding plots (thick lines, translucent fills, etc.). - - If \a enabled is set to true, QCustomPlot will try to initialize OpenGL and, if successful, - continue plotting with hardware acceleration. The parameter \a multisampling controls how many - samples will be used per pixel, it essentially controls the antialiasing quality. If \a - multisampling is set too high for the current graphics hardware, the maximum allowed value will - be used. - - You can test whether switching to OpenGL rendering was successful by checking whether the - according getter \a QCustomPlot::openGl() returns true. If the OpenGL initialization fails, - rendering continues with the regular software rasterizer, and an according qDebug output is - generated. - - If switching to OpenGL was successful, this method disables label caching (\ref setPlottingHint - "setPlottingHint(QCP::phCacheLabels, false)") and turns on QCustomPlot's antialiasing override - for all elements (\ref setAntialiasedElements "setAntialiasedElements(QCP::aeAll)"), leading to a - higher quality output. The antialiasing override allows for pixel-grid aligned drawing in the - OpenGL paint device. As stated before, in OpenGL rendering the actual antialiasing of the plot is - controlled with \a multisampling. If \a enabled is set to false, the antialiasing/label caching - settings are restored to what they were before OpenGL was enabled, if they weren't altered in the - meantime. - - \note OpenGL support is only enabled if QCustomPlot is compiled with the macro \c QCUSTOMPLOT_USE_OPENGL - defined. This define must be set before including the QCustomPlot header both during compilation - of the QCustomPlot library as well as when compiling your application. It is best to just include - the line DEFINES += QCUSTOMPLOT_USE_OPENGL in the respective qmake project files. - \note If you are using a Qt version before 5.0, you must also add the module "opengl" to your \c - QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a - newer OpenGL interface which is already in the "gui" module. -*/ -void QCustomPlot::setOpenGl(bool enabled, int multisampling) -{ - mOpenGlMultisamples = qMax(0, multisampling); -#ifdef QCUSTOMPLOT_USE_OPENGL - mOpenGl = enabled; - if (mOpenGl) - { - if (setupOpenGl()) - { - // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL - mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); - // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): - setAntialiasedElements(QCP::aeAll); - setPlottingHint(QCP::phCacheLabels, false); - } else - { - qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; - mOpenGl = false; - } - } else - { - // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: - if (mAntialiasedElements == QCP::aeAll) - setAntialiasedElements(mOpenGlAntialiasedElementsBackup); - if (!mPlottingHints.testFlag(QCP::phCacheLabels)) - setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); - freeOpenGl(); - } - // recreate all paint buffers: - mPaintBuffers.clear(); - setupPaintBuffers(); -#else - Q_UNUSED(enabled) - qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; -#endif -} - -/*! - Sets the viewport of this QCustomPlot. Usually users of QCustomPlot don't need to change the - viewport manually. - - The viewport is the area in which the plot is drawn. All mechanisms, e.g. margin caluclation take - the viewport to be the outer border of the plot. The viewport normally is the rect() of the - QCustomPlot widget, i.e. a rect with top left (0, 0) and size of the QCustomPlot widget. - - Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically - an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger - and contains also the axes themselves, their tick numbers, their labels, or even additional axis - rects, color scales and other layout elements. - - This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref - savePdf, etc. by temporarily changing the viewport size. -*/ -void QCustomPlot::setViewport(const QRect &rect) -{ - mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); -} - -/*! - Sets the device pixel ratio used by the paint buffers of this QCustomPlot instance. - - Normally, this doesn't need to be set manually, because it is initialized with the regular \a - QWidget::devicePixelRatio which is configured by Qt to fit the display device (e.g. 1 for normal - displays, 2 for High-DPI displays). - - Device pixel ratios are supported by Qt only for Qt versions since 5.4. If this method is called - when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and - leaves the internal buffer device pixel ratio at 1.0. -*/ -void QCustomPlot::setBufferDevicePixelRatio(double ratio) -{ - if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBufferDevicePixelRatio = ratio; - for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here -#else - qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; - mBufferDevicePixelRatio = 1.0; -#endif - } -} - -/*! - Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn - below all other objects in the plot. - - For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is - preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will - first be filled with that brush, before drawing the background pixmap. This can be useful for - background pixmaps with translucent areas. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! - Sets the background brush of the viewport (see \ref setViewport). - - Before drawing everything else, the background is filled with \a brush. If a background pixmap - was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport - before the background pixmap is drawn. This can be useful for background pixmaps with translucent - areas. - - Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be - useful for exporting to image formats which support transparency, e.g. \ref savePng. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the viewport, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is - set to true, control whether and how the aspect ratio of the original pixmap is preserved with - \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the viewport dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCustomPlot::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this - function to define whether and how the aspect ratio of the original pixmap is preserved. - - \see setBackground, setBackgroundScaled -*/ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the plottable with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - plottable, see QCustomPlot::plottable() - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - { - return mPlottables.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last plottable that was added to the plot. If there are no plottables in the plot, - returns 0. - - \see plottableCount -*/ -QCPAbstractPlottable *QCustomPlot::plottable() -{ - if (!mPlottables.isEmpty()) - { - return mPlottables.last(); - } else - return 0; -} - -/*! - Removes the specified plottable from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). - - Returns true on success. - - \see clearPlottables -*/ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); - return false; - } - - // remove plottable from legend: - plottable->removeFromLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast(plottable)) - mGraphs.removeOne(graph); - // remove plottable: - delete plottable; - mPlottables.removeOne(plottable); - return true; -} - -/*! \overload - - Removes and deletes the plottable by its \a index. -*/ -bool QCustomPlot::removePlottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all plottables from the plot and deletes them. Corresponding legend items are also - removed from the default legend (QCustomPlot::legend). - - Returns the number of plottables removed. - - \see removePlottable -*/ -int QCustomPlot::clearPlottables() -{ - int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); - return c; -} - -/*! - Returns the number of currently existing plottables in the plot - - \see plottable -*/ -int QCustomPlot::plottableCount() const -{ - return mPlottables.size(); -} - -/*! - Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. - - There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. - - \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedPlottables() const -{ - QList result; - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (plottable->selected()) - result.append(plottable); - } - return result; -} - -/*! - Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines - (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple - plottables come into consideration, the one closest to \a pos is returned. - - If \a onlySelectable is true, only plottables that are selectable - (QCPAbstractPlottable::setSelectable) are considered. - - If there is no plottable at \a pos, the return value is 0. - - \see itemAt, layoutElementAt -*/ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractPlottable *plottable, mPlottables) - { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable - continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes - { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultPlottable = plottable; - resultDistance = currentDistance; - } - } - } - - return resultPlottable; -} - -/*! - Returns whether this QCustomPlot instance contains the \a plottable. -*/ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const -{ - return mPlottables.contains(plottable); -} - -/*! - Returns the graph with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last created - graph, see QCustomPlot::graph() - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph(int index) const -{ - if (index >= 0 && index < mGraphs.size()) - { - return mGraphs.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, - returns 0. - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph() const -{ - if (!mGraphs.isEmpty()) - { - return mGraphs.last(); - } else - return 0; -} - -/*! - Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the - bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a - keyAxis and \a valueAxis must reside in this QCustomPlot. - - \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically - "y") for the graph. - - Returns a pointer to the newly created graph, or 0 if adding the graph failed. - - \see graph, graphCount, removeGraph, clearGraphs -*/ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; - return 0; - } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; - return 0; - } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); - return newGraph; -} - -/*! - Removes the specified \a graph from the plot and deletes it. If necessary, the corresponding - legend item is also removed from the default legend (QCustomPlot::legend). If any other graphs in - the plot have a channel fill set towards the removed graph, the channel fill property of those - graphs is reset to zero (no channel fill). - - Returns true on success. - - \see clearGraphs -*/ -bool QCustomPlot::removeGraph(QCPGraph *graph) -{ - return removePlottable(graph); -} - -/*! \overload - - Removes and deletes the graph by its \a index. -*/ -bool QCustomPlot::removeGraph(int index) -{ - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); - else - return false; -} - -/*! - Removes all graphs from the plot and deletes them. Corresponding legend items are also removed - from the default legend (QCustomPlot::legend). - - Returns the number of graphs removed. - - \see removeGraph -*/ -int QCustomPlot::clearGraphs() -{ - int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); - return c; -} - -/*! - Returns the number of currently existing graphs in the plot - - \see graph, addGraph -*/ -int QCustomPlot::graphCount() const -{ - return mGraphs.size(); -} - -/*! - Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. - - If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, - etc., use \ref selectedPlottables. - - \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelection -*/ -QList QCustomPlot::selectedGraphs() const -{ - QList result; - Q_FOREACH (QCPGraph *graph, mGraphs) - { - if (graph->selected()) - result.append(graph); - } - return result; -} - -/*! - Returns the item with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - item, see QCustomPlot::item() - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item(int index) const -{ - if (index >= 0 && index < mItems.size()) - { - return mItems.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last item that was added to this plot. If there are no items in the plot, - returns 0. - - \see itemCount -*/ -QCPAbstractItem *QCustomPlot::item() const -{ - if (!mItems.isEmpty()) - { - return mItems.last(); - } else - return 0; -} - -/*! - Removes the specified item from the plot and deletes it. - - Returns true on success. - - \see clearItems -*/ -bool QCustomPlot::removeItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - delete item; - mItems.removeOne(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); - return false; - } -} - -/*! \overload - - Removes and deletes the item by its \a index. -*/ -bool QCustomPlot::removeItem(int index) -{ - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all items from the plot and deletes them. - - Returns the number of items removed. - - \see removeItem -*/ -int QCustomPlot::clearItems() -{ - int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); - return c; -} - -/*! - Returns the number of currently existing items in the plot - - \see item -*/ -int QCustomPlot::itemCount() const -{ - return mItems.size(); -} - -/*! - Returns a list of the selected items. If no items are currently selected, the list is empty. - - \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected -*/ -QList QCustomPlot::selectedItems() const -{ - QList result; - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (item->selected()) - result.append(item); - } - return result; -} - -/*! - Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref - QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref - setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is - returned. - - If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are - considered. - - If there is no item at \a pos, the return value is 0. - - \see plottableAt, layoutElementAt -*/ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - Q_FOREACH (QCPAbstractItem *item, mItems) - { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable - continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it - { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultItem = item; - resultDistance = currentDistance; - } - } - } - - return resultItem; -} - -/*! - Returns whether this QCustomPlot contains the \a item. - - \see item -*/ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const -{ - return mItems.contains(item); -} - -/*! - Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is - returned. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(const QString &name) const -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - if (layer->name() == name) - return layer; - } - return 0; -} - -/*! \overload - - Returns the layer by \a index. If the index is invalid, 0 is returned. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(int index) const -{ - if (index >= 0 && index < mLayers.size()) - { - return mLayers.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Returns the layer that is set as current layer (see \ref setCurrentLayer). -*/ -QCPLayer *QCustomPlot::currentLayer() const -{ - return mCurrentLayer; -} - -/*! - Sets the layer with the specified \a name to be the current layer. All layerables (\ref - QCPLayerable), e.g. plottables and items, are created on the current layer. - - Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer -*/ -bool QCustomPlot::setCurrentLayer(const QString &name) -{ - if (QCPLayer *newCurrentLayer = layer(name)) - { - return setCurrentLayer(newCurrentLayer); - } else - { - qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; - return false; - } -} - -/*! \overload - - Sets the provided \a layer to be the current layer. - - Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. - - \see addLayer, moveLayer, removeLayer -*/ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - - mCurrentLayer = layer; - return true; -} - -/*! - Returns the number of currently existing layers in the plot - - \see layer, addLayer -*/ -int QCustomPlot::layerCount() const -{ - return mLayers.size(); -} - -/*! - Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which - must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. - - Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a - valid layer inside this QCustomPlot. - - If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. - - For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. - - \see layer, moveLayer, removeLayer -*/ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!otherLayer) - otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - if (layer(name)) - { - qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; - return false; - } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); - updateLayerIndices(); - setupPaintBuffers(); // associates new layer with the appropriate paint buffer - return true; -} - -/*! - Removes the specified \a layer and returns true on success. - - All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below - \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both - cases, the total rendering order of all layerables in the QCustomPlot is preserved. - - If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom - layer) becomes the new current layer. - - It is not possible to remove the last layer of the plot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::removeLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (mLayers.size() < 2) - { - qDebug() << Q_FUNC_INFO << "can't remove last layer"; - return false; - } - - // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) - int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); - QList children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) - { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally - { - for (int i=0; imoveToLayer(targetLayer, false); - } - // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); - // invalidate the paint buffer that was responsible for this layer: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - // remove layer: - delete layer; - mLayers.removeOne(layer); - updateLayerIndices(); - return true; -} - -/*! - Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or - below is controlled with \a insertMode. - - Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the - QCustomPlot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); - return false; - } - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); - return false; - } - - if (layer->index() > otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - else if (layer->index() < otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); - - // invalidate the paint buffers that are responsible for the layers: - if (!layer->mPaintBuffer.isNull()) - layer->mPaintBuffer.data()->setInvalidated(); - if (!otherLayer->mPaintBuffer.isNull()) - otherLayer->mPaintBuffer.data()->setInvalidated(); - - updateLayerIndices(); - return true; -} - -/*! - Returns the number of axis rects in the plot. - - All axis rects can be accessed via QCustomPlot::axisRect(). - - Initially, only one axis rect exists in the plot. - - \see axisRect, axisRects -*/ -int QCustomPlot::axisRectCount() const -{ - return axisRects().size(); -} - -/*! - Returns the axis rect with \a index. - - Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were - added, all of them may be accessed with this function in a linear fashion (even when they are - nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). - - \see axisRectCount, axisRects -*/ -QCPAxisRect *QCustomPlot::axisRect(int index) const -{ - const QList rectList = axisRects(); - if (index >= 0 && index < rectList.size()) - { - return rectList.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; - return 0; - } -} - -/*! - Returns all axis rects in the plot. - - \see axisRectCount, axisRect -*/ -QList QCustomPlot::axisRects() const -{ - QList result; - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *element, elementStack.pop()->elements(false)) - { - if (element) - { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast(element)) - result.append(ar); - } - } - } - - return result; -} - -/*! - Returns the layout element at pixel position \a pos. If there is no element at that position, - returns 0. - - Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on - any of its parent elements is set to false, it will not be considered. - - \see itemAt, plottableAt -*/ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const -{ - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - break; - } - } - } - return currentElement; -} - -/*! - Returns the layout element of type \ref QCPAxisRect at pixel position \a pos. This method ignores - other layout elements even if they are visually in front of the axis rect (e.g. a \ref - QCPLegend). If there is no axis rect at that position, returns 0. - - Only visible axis rects are used. If \ref QCPLayoutElement::setVisible on the axis rect itself or - on any of its parent elements is set to false, it will not be considered. - - \see layoutElementAt -*/ -QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const -{ - QCPAxisRect *result = 0; - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - Q_FOREACH (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - if (QCPAxisRect *ar = qobject_cast(currentElement)) - result = ar; - break; - } - } - } - return result; -} - -/*! - Returns the axes that currently have selected parts, i.e. whose selection state is not \ref - QCPAxis::spNone. - - \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, - QCPAxis::setSelectableParts -*/ -QList QCustomPlot::selectedAxes() const -{ - QList result, allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); - } - - return result; -} - -/*! - Returns the legends that currently have selected parts, i.e. whose selection state is not \ref - QCPLegend::spNone. - - \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, - QCPLegend::setSelectableParts, QCPLegend::selectedItems -*/ -QList QCustomPlot::selectedLegends() const -{ - QList result; - - QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - Q_FOREACH (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) - { - if (subElement) - { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast(subElement)) - { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); - } - } - } - } - - return result; -} - -/*! - Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. - - Since calling this function is not a user interaction, this does not emit the \ref - selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the - objects were previously selected. - - \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends -*/ -void QCustomPlot::deselectAll() -{ - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); - } -} - -/*! - Causes a complete replot into the internal paint buffer(s). Finally, the widget surface is - refreshed with the new buffer contents. This is the method that must be called to make changes to - the plot, e.g. on the axis ranges or data points of graphs, visible. - - The parameter \a refreshPriority can be used to fine-tune the timing of the replot. For example - if your application calls \ref replot very quickly in succession (e.g. multiple independent - functions change some aspects of the plot and each wants to make sure the change gets replotted), - it is advisable to set \a refreshPriority to \ref QCustomPlot::rpQueuedReplot. This way, the - actual replotting is deferred to the next event loop iteration. Multiple successive calls of \ref - replot with this priority will only cause a single replot, avoiding redundant replots and - improving performance. - - Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the - QCustomPlot widget and user interactions (object selection and range dragging/zooming). - - Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref - afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two - signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite - recursion. - - If a layer is in mode \ref QCPLayer::lmBuffered (\ref QCPLayer::setMode), it is also possible to - replot only that specific layer via \ref QCPLayer::replot. See the documentation there for - details. -*/ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) -{ - if (refreshPriority == QCustomPlot::rpQueuedReplot) - { - if (!mReplotQueued) - { - mReplotQueued = true; - QTimer::singleShot(0, this, SLOT(replot())); - } - return; - } - - if (mReplotting) // incase signals loop back to replot slot - return; - mReplotting = true; - mReplotQueued = false; - Q_EMIT beforeReplot(); - - updateLayout(); - // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: - setupPaintBuffers(); - Q_FOREACH (QCPLayer *layer, mLayers) - layer->drawToPaintBuffer(); - for (int i=0; isetInvalidated(false); - - if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) - repaint(); - else - update(); - - Q_EMIT afterReplot(); - mReplotting = false; -} - -/*! - Rescales the axes such that all plottables (like graphs) in the plot are fully visible. - - if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true - (QCPLayerable::setVisible), will be used to rescale the axes. - - \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale -*/ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) -{ - QList allAxes; - Q_FOREACH (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - Q_FOREACH (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); -} - -/*! - Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale - of texts and lines will be derived from the specified \a width and \a height. This means, the - output will look like the normal on-screen output of a QCustomPlot widget with the corresponding - pixel width and height. If either \a width or \a height is zero, the exported image will have the - same dimensions as the QCustomPlot widget currently has. - - Setting \a exportPen to \ref QCP::epNoCosmetic allows to disable the use of cosmetic pens when - drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as - a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information - about cosmetic pens, see the QPainter and QPen documentation. - - The objects of the plot will appear in the current selection state. If you don't want any - selected objects to be painted in their selected look, deselect everything with \ref deselectAll - before calling this function. - - Returns true on success. - - \warning - \li If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it - is advised to set \a exportPen to \ref QCP::epNoCosmetic to avoid losing those cosmetic lines - (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). - \li If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting - PDF file. - - \note On Android systems, this method does nothing and issues an according qDebug warning - message. This is also the case if for other reasons the define flag \c QT_NO_PRINTER is set. - - \see savePng, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) -{ - bool success = false; -#ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(exportPen) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(pdfCreator) - Q_UNUSED(pdfTitle) - qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; -#else - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); -#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) - printer.setFullPage(true); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); -#else - QPageLayout pageLayout; - pageLayout.setMode(QPageLayout::FullPageMode); - pageLayout.setOrientation(QPageLayout::Portrait); - pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); - pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); - printer.setPageLayout(pageLayout); -#endif - QCPPainter printpainter; - if (printpainter.begin(&printer)) - { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && - mBackgroundBrush.color() != Qt::white && - mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); - printpainter.end(); - success = true; - } - setViewport(oldViewport); -#endif // QT_NO_PRINTER - return success; -} - -/*! - Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the PNG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - If you want the PNG to have a transparent background, call \ref setBackground(const QBrush &brush) - with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); -} - -/*! - Saves a JPEG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - image compression can be controlled with the \a quality parameter which must be between 0 and 100 - or -1 to use the default setting. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the JPEG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveBmp, saveRastered -*/ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); -} - -/*! - Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels, multiplied by \a scale. If either \a width or \a height is zero, the - current width and height of the QCustomPlot widget is used instead. Line widths and texts etc. - are not scaled up when larger widths/heights are used. If you want that effect, use the \a scale - parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements by - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - The \a resolution will be written to the image file header and has no direct consequence for the - quality or the pixel size. However, if opening the image with a tool which respects the metadata, - it will be able to scale the image to match either a given size in real units of length (inch, - centimeters, etc.), or the target display DPI. You can specify in which units \a resolution is - given, by setting \a resolutionUnit. The \a resolution is converted to the format's expected - resolution unit internally. - - Returns true on success. If this function fails, most likely the BMP format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \see savePdf, savePng, saveJpg, saveRastered -*/ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); -} - -/*! \internal - - Returns a minimum size hint that corresponds to the minimum size of the top level layout - (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum - size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. - This is especially important, when placed in a QLayout where other components try to take in as - much space as possible (e.g. QMdiArea). -*/ -QSize QCustomPlot::minimumSizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Returns a size hint that is the same as \ref minimumSizeHint. - -*/ -QSize QCustomPlot::sizeHint() const -{ - return mPlotLayout->minimumOuterSizeHint(); -} - -/*! \internal - - Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but - draws the internal buffer on the widget surface. -*/ -void QCustomPlot::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - QCPPainter painter(this); - if (painter.isActive()) - { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - drawBackground(&painter); - for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) - mPaintBuffers.at(bufferIndex)->draw(&painter); - } -} - -/*! \internal - - Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect - of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. -*/ -void QCustomPlot::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event) - // resize and repaint the buffer: - setViewport(rect()); - replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) -} - -/*! \internal - - Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then - determines the layerable under the cursor and forwards the event to it. Finally, emits the - specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref - axisDoubleClick, etc.). - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_EMIT mouseDoubleClick(event); - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - // determine layerable under the cursor (this event is called instead of the second press event in a double-click): - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - - // emit specialized object double click signals: - if (!candidates.isEmpty()) - { - if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) - { - int dataIndex = 0; - if (!details.first().value().isEmpty()) - dataIndex = details.first().value().dataRange().begin(); - Q_EMIT plottableDoubleClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(candidates.first())) - Q_EMIT axisDoubleClick(ax, details.first().value(), event); - else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) - Q_EMIT itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) - Q_EMIT legendDoubleClick(li->parentLegend(), li, event); - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is pressed. Emits the mousePress signal. - - If the current \ref setSelectionRectMode is not \ref QCP::srmNone, passes the event to the - selection rect. Otherwise determines the layerable under the cursor and forwards the event to it. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCustomPlot::mousePressEvent(QMouseEvent *event) -{ - Q_EMIT mousePress(event); - // save some state to tell in releaseEvent whether it was a click: - mMouseHasMoved = false; - mMousePressPos = event->pos(); - - if (mSelectionRect && mSelectionRectMode != QCP::srmNone) - { - if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect - mSelectionRect->startSelection(event); - } else - { - // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: - QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - if (!candidates.isEmpty()) - { - mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) - mMouseSignalLayerableDetails = details.first(); - } - // forward event to topmost candidate which accepts the event: - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list - candidates.at(i)->mousePressEvent(event, details.at(i)); - if (event->isAccepted()) - { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); - break; - } - } - } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when the cursor is moved. Emits the \ref mouseMove signal. - - If the selection rect (\ref setSelectionRect) is currently active, the event is forwarded to it - in order to update the rect geometry. - - Otherwise, if a layout element has mouse capture focus (a mousePressEvent happened on top of the - layout element before), the mouseMoveEvent is forwarded to that element. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) -{ - Q_EMIT mouseMove(event); - - if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) - mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release - - if (mSelectionRect && mSelectionRect->isActive()) - mSelectionRect->moveSelection(event); - else if (mMouseEventLayerable) // call event of affected layerable: - mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. - - If the mouse was moved less than a certain threshold in any direction since the \ref - mousePressEvent, it is considered a click which causes the selection mechanism (if activated via - \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse - click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) - - If a layerable is the mouse capturer (a \ref mousePressEvent happened on top of the layerable - before), the \ref mouseReleaseEvent is forwarded to that element. - - \see mousePressEvent, mouseMoveEvent -*/ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) -{ - Q_EMIT mouseRelease(event); - - if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click - { - if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here - mSelectionRect->cancel(); - if (event->button() == Qt::LeftButton) - processPointSelection(event); - - // emit specialized click signals of QCustomPlot instance: - if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) - { - int dataIndex = 0; - if (!mMouseSignalLayerableDetails.value().isEmpty()) - dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); - Q_EMIT plottableClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) - Q_EMIT axisClick(ax, mMouseSignalLayerableDetails.value(), event); - else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) - Q_EMIT itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) - Q_EMIT legendClick(li->parentLegend(), li, event); - mMouseSignalLayerable = 0; - } - - if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there - { - // finish selection rect, the appropriate action will be taken via signal-slot connection: - mSelectionRect->endSelection(event); - } else - { - // call event of affected layerable: - if (mMouseEventLayerable) - { - mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); - mMouseEventLayerable = 0; - } - } - - if (noAntialiasingOnDrag()) - replot(rpQueuedReplot); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then - determines the affected layerable and forwards the event to it. -*/ -void QCustomPlot::wheelEvent(QWheelEvent *event) -{ - Q_EMIT mouseWheel(event); - // forward event to layerable under cursor: - QList candidates = layerableListAt(event->pos(), false); - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->wheelEvent(event); - if (event->isAccepted()) - break; - } - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. -} - -/*! \internal - - This function draws the entire plot, including background pixmap, with the specified \a painter. - It does not make use of the paint buffers like \ref replot, so this is the function typically - used by saving/exporting methods such as \ref savePdf or \ref toPainter. - - Note that it does not fill the background with the background brush (as the user may specify with - \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this - method. -*/ -void QCustomPlot::draw(QCPPainter *painter) -{ - updateLayout(); - - // draw viewport background pixmap: - drawBackground(painter); - - // draw all layered objects (grid, axes, plottables, items, legend,...): - Q_FOREACH (QCPLayer *layer, mLayers) - layer->draw(painter); - - /* Debug code to draw all layout element rects - foreach (QCPLayoutElement* el, findChildren()) - { - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->rect()); - painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->outerRect()); - } - */ -} - -/*! \internal - - Performs the layout update steps defined by \ref QCPLayoutElement::UpdatePhase, by calling \ref - QCPLayoutElement::update on the main plot layout. - - Here, the layout elements calculate their positions and margins, and prepare for the following - draw call. -*/ -void QCustomPlot::updateLayout() -{ - // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); -} - -/*! \internal - - Draws the viewport background pixmap of the plot. - - If a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the viewport with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - Note that this function does not draw a fill with the background brush - (\ref setBackground(const QBrush &brush)) beneath the pixmap. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::drawBackground(QCPPainter *painter) -{ - // Note: background color is handled in individual replot/save functions - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); - } - } -} - -/*! \internal - - Goes through the layers and makes sure this QCustomPlot instance holds the correct number of - paint buffers and that they have the correct configuration (size, pixel ratio, etc.). - Allocations, reallocations and deletions of paint buffers are performed as necessary. It also - associates the paint buffers with the layers, so they draw themselves into the right buffer when - \ref QCPLayer::drawToPaintBuffer is called. This means it associates adjacent \ref - QCPLayer::lmLogical layers to a mutual paint buffer and creates dedicated paint buffers for - layers in \ref QCPLayer::lmBuffered mode. - - This method uses \ref createPaintBuffer to create new paint buffers. - - After this method, the paint buffers are empty (filled with \c Qt::transparent) and invalidated - (so an attempt to replot only a single buffered layer causes a full replot). - - This method is called in every \ref replot call, prior to actually drawing the layers (into their - associated paint buffer). If the paint buffers don't need changing/reallocating, this method - basically leaves them alone and thus finishes very fast. -*/ -void QCustomPlot::setupPaintBuffers() -{ - int bufferIndex = 0; - if (mPaintBuffers.isEmpty()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - - for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) - { - QCPLayer *layer = mLayers.at(layerIndex); - if (layer->mode() == QCPLayer::lmLogical) - { - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - } else if (layer->mode() == QCPLayer::lmBuffered) - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables - { - ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - } - } - } - // remove unneeded buffers: - while (mPaintBuffers.size()-1 > bufferIndex) - mPaintBuffers.removeLast(); - // resize buffers to viewport size and clear contents: - for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size - mPaintBuffers.at(i)->clear(Qt::transparent); - mPaintBuffers.at(i)->setInvalidated(); - } -} - -/*! \internal - - This method is used by \ref setupPaintBuffers when it needs to create new paint buffers. - - Depending on the current setting of \ref setOpenGl, and the current Qt version, different - backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper - size and device pixel ratio, and returned. -*/ -QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() -{ - if (mOpenGl) - { -#if defined(QCP_OPENGL_FBO) - return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); -#elif defined(QCP_OPENGL_PBUFFER) - return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); -#else - qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -#endif - } else - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); -} - -/*! - This method returns whether any of the paint buffers held by this QCustomPlot instance are - invalidated. - - If any buffer is invalidated, a partial replot (\ref QCPLayer::replot) is not allowed and always - causes a full replot (\ref QCustomPlot::replot) of all layers. This is the case when for example - the layer order has changed, new layers were added, layers were removed, or layer modes were - changed (\ref QCPLayer::setMode). - - \see QCPAbstractPaintBuffer::setInvalidated -*/ -bool QCustomPlot::hasInvalidatedPaintBuffers() -{ - for (int i=0; iinvalidated()) - return true; - } - return false; -} - -/*! \internal - - When \ref setOpenGl is set to true, this method is used to initialize OpenGL (create a context, - surface, paint device). - - Returns true on success. - - If this method is successful, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the OpenGL-based paint buffer subclasses (\ref - QCPPaintBufferGlPbuffer, \ref QCPPaintBufferGlFbo) are used for subsequent replots. - - \see freeOpenGl -*/ -bool QCustomPlot::setupOpenGl() -{ -#ifdef QCP_OPENGL_FBO - freeOpenGl(); - QSurfaceFormat proposedSurfaceFormat; - proposedSurfaceFormat.setSamples(mOpenGlMultisamples); -#ifdef QCP_OPENGL_OFFSCREENSURFACE - QOffscreenSurface *surface = new QOffscreenSurface; -#else - QWindow *surface = new QWindow; - surface->setSurfaceType(QSurface::OpenGLSurface); -#endif - surface->setFormat(proposedSurfaceFormat); - surface->create(); - mGlSurface = QSharedPointer(surface); - mGlContext = QSharedPointer(new QOpenGLContext); - mGlContext->setFormat(mGlSurface->format()); - if (!mGlContext->create()) - { - qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device - { - qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) - { - qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; - mGlContext.clear(); - mGlSurface.clear(); - return false; - } - mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); - return true; -#elif defined(QCP_OPENGL_PBUFFER) - return QGLFormat::hasOpenGL(); -#else - return false; -#endif -} - -/*! \internal - - When \ref setOpenGl is set to false, this method is used to deinitialize OpenGL (releases the - context and frees resources). - - After OpenGL is disabled, all paint buffers should be deleted and then reallocated by calling - \ref setupPaintBuffers, so the standard software rendering paint buffer subclass (\ref - QCPPaintBufferPixmap) is used for subsequent replots. - - \see setupOpenGl -*/ -void QCustomPlot::freeOpenGl() -{ -#ifdef QCP_OPENGL_FBO - mGlPaintDevice.clear(); - mGlContext.clear(); - mGlSurface.clear(); -#endif -} - -/*! \internal - - This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot - so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. -*/ -void QCustomPlot::axisRemoved(QCPAxis *axis) -{ - if (xAxis == axis) - xAxis = 0; - if (xAxis2 == axis) - xAxis2 = 0; - if (yAxis == axis) - yAxis = 0; - if (yAxis2 == axis) - yAxis2 = 0; - - // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers -} - -/*! \internal - - This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so - it may clear its QCustomPlot::legend member accordingly. -*/ -void QCustomPlot::legendRemoved(QCPLegend *legend) -{ - if (this->legend == legend) - this->legend = 0; -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmSelect. - - First, it determines which axis rect was the origin of the selection rect judging by the starting - point of the selection. Then it goes through the plottables (\ref QCPAbstractPlottable1D to be - precise) associated with that axis rect and finds the data points that are in \a rect. It does - this by querying their \ref QCPAbstractPlottable1D::selectTestRect method. - - Then, the actual selection is done by calling the plottables' \ref - QCPAbstractPlottable::selectEvent, placing the found selected data points in the \a details - parameter as QVariant(\ref QCPDataSelection). All plottables that weren't touched by \a - rect receive a \ref QCPAbstractPlottable::deselectEvent. - - \see processRectZoom -*/ -void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) -{ - bool selectionStateChanged = false; - - if (mInteractions.testFlag(QCP::iSelectPlottables)) - { - QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size - QRectF rectF(rect.normalized()); - if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) - { - // determine plottables that were hit by the rect and thus are candidates for selection: - Q_FOREACH (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) - { - if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) - { - QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); - if (!dataSel.isEmpty()) - potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); - } - } - - if (!mInteractions.testFlag(QCP::iMultiSelect)) - { - // only leave plottable with most selected points in map, since we will only select a single plottable: - if (!potentialSelections.isEmpty()) - { - QMap >::iterator it = potentialSelections.begin(); - while (it != potentialSelections.end()-1) // erase all except last element - it = potentialSelections.erase(it); - } - } - - bool additive = event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - // emit deselection except to those plottables who will be selected afterwards: - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - // go through selections in reverse (largest selection first) and emit select events: - QMap >::const_iterator it = potentialSelections.constEnd(); - while (it != potentialSelections.constBegin()) - { - --it; - if (mInteractions.testFlag(it.value().first->selectionCategory())) - { - bool selChanged = false; - it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } else if (mSelectionRect) - mSelectionRect->layer()->replot(); -} - -/*! \internal - - This slot is connected to the selection rect's \ref QCPSelectionRect::accepted signal when \ref - setSelectionRectMode is set to \ref QCP::srmZoom. - - It determines which axis rect was the origin of the selection rect judging by the starting point - of the selection, and then zooms the axes defined via \ref QCPAxisRect::setRangeZoomAxes to the - provided \a rect (see \ref QCPAxisRect::zoom). - - \see processRectSelection -*/ -void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) -{ - Q_UNUSED(event) - if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) - { - QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); - affectedAxes.removeAll(static_cast(0)); - axisRect->zoom(QRectF(rect), affectedAxes); - } - replot(rpQueuedReplot); // always replot to make selection rect disappear -} - -/*! \internal - - This method is called when a simple left mouse click was detected on the QCustomPlot surface. - - It first determines the layerable that was hit by the click, and then calls its \ref - QCPLayerable::selectEvent. All other layerables receive a QCPLayerable::deselectEvent (unless the - multi-select modifier was pressed, see \ref setMultiSelectModifier). - - In this method the hit layerable is determined a second time using \ref layerableAt (after the - one in \ref mousePressEvent), because we want \a onlySelectable set to true this time. This - implies that the mouse event grabber (mMouseEventLayerable) may be a different one from the - clicked layerable determined here. For example, if a non-selectable layerable is in front of a - selectable layerable at the click position, the front layerable will receive mouse events but the - selectable one in the back will receive the \ref QCPLayerable::selectEvent. - - \see processRectSelection, QCPLayerable::selectTest -*/ -void QCustomPlot::processPointSelection(QMouseEvent *event) -{ - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); - bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - Q_FOREACH (QCPLayer *layer, mLayers) - { - Q_FOREACH (QCPLayerable *layerable, layer->children()) - { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) - { - // a layerable was actually clicked, call its selectEvent: - bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); - selectionStateChanged |= selChanged; - } - if (selectionStateChanged) - { - Q_EMIT selectionChangedByUser(); - replot(rpQueuedReplot); - } -} - -/*! \internal - - Registers the specified plottable with this QCustomPlot and, if \ref setAutoAddPlottableToLegend - is enabled, adds it to the legend (QCustomPlot::legend). QCustomPlot takes ownership of the - plottable. - - Returns true on success, i.e. when \a plottable isn't already in this plot and the parent plot of - \a plottable is this QCustomPlot. - - This method is called automatically in the QCPAbstractPlottable base class constructor. -*/ -bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) -{ - if (mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); - return false; - } - if (plottable->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); - return false; - } - - mPlottables.append(plottable); - // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) - plottable->addToLegend(); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); - return true; -} - -/*! \internal - - In order to maintain the simplified graph interface of QCustomPlot, this method is called by the - QCPGraph constructor to register itself with this QCustomPlot's internal graph list. Returns true - on success, i.e. if \a graph is valid and wasn't already registered with this QCustomPlot. - - This graph specific registration happens in addition to the call to \ref registerPlottable by the - QCPAbstractPlottable base class. -*/ -bool QCustomPlot::registerGraph(QCPGraph *graph) -{ - if (!graph) - { - qDebug() << Q_FUNC_INFO << "passed graph is zero"; - return false; - } - if (mGraphs.contains(graph)) - { - qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; - return false; - } - - mGraphs.append(graph); - return true; -} - - -/*! \internal - - Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. - - Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a - item is this QCustomPlot. - - This method is called automatically in the QCPAbstractItem base class constructor. -*/ -bool QCustomPlot::registerItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); - return false; - } - if (item->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); - return false; - } - - mItems.append(item); - if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) - item->setLayer(currentLayer()); - return true; -} - -/*! \internal - - Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called - after every operation that changes the layer indices, like layer removal, layer creation, layer - moving. -*/ -void QCustomPlot::updateLayerIndices() const -{ - for (int i=0; imIndex = i; -} - -/*! \internal - - Returns the top-most layerable at pixel position \a pos. If \a onlySelectable is set to true, - only those layerables that are selectable will be considered. (Layerable subclasses communicate - their selectability via the QCPLayerable::selectTest method, by returning -1.) - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableListAt, layoutElementAt, axisRectAt -*/ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const -{ - QList details; - QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); - if (selectionDetails && !details.isEmpty()) - *selectionDetails = details.first(); - if (!candidates.isEmpty()) - return candidates.first(); - else - return 0; -} - -/*! \internal - - Returns the layerables at pixel position \a pos. If \a onlySelectable is set to true, only those - layerables that are selectable will be considered. (Layerable subclasses communicate their - selectability via the QCPLayerable::selectTest method, by returning -1.) - - The returned list is sorted by the layerable/drawing order. If you only need to know the top-most - layerable, rather use \ref layerableAt. - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). If the layerable is a plottable, \a selectionDetails contains a \ref - QCPDataSelection instance with the single data point which is closest to \a pos. - - \see layerableAt, layoutElementAt, axisRectAt -*/ -QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const -{ - QList result; - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) - { - const QList layerables = mLayers.at(layerIndex)->children(); - for (int i=layerables.size()-1; i>=0; --i) - { - if (!layerables.at(i)->realVisibility()) - continue; - QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); - if (dist >= 0 && dist < selectionTolerance()) - { - result.append(layerables.at(i)); - if (selectionDetails) - selectionDetails->append(details); - } - } - } - return result; -} - -/*! - Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is - sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead - to a full resolution file with width 200.) If the \a format supports compression, \a quality may - be between 0 and 100 to control it. - - Returns true on success. If this function fails, most likely the given \a format isn't supported - by the system, see Qt docs about QImageWriter::supportedImageFormats(). - - The \a resolution will be written to the image file header (if the file format supports this) and - has no direct consequence for the quality or the pixel size. However, if opening the image with a - tool which respects the metadata, it will be able to scale the image to match either a given size - in real units of length (inch, centimeters, etc.), or the target display DPI. You can specify in - which units \a resolution is given, by setting \a resolutionUnit. The \a resolution is converted - to the format's expected resolution unit internally. - - \see saveBmp, saveJpg, savePng, savePdf -*/ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) -{ - QImage buffer = toPixmap(width, height, scale).toImage(); - - int dotsPerMeter = 0; - switch (resolutionUnit) - { - case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; - case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; - case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; - } - buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); - else - return false; -} - -/*! - Renders the plot to a pixmap and returns it. - - The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and - scale 2.0 lead to a full resolution pixmap with width 200.) - - \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf -*/ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) -{ - // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); - - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later - QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) - { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); - } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); - painter.end(); - } else // might happen if pixmap has width or height zero - { - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; - return QPixmap(); - } - return result; -} - -/*! - Renders the plot using the passed \a painter. - - The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will - appear scaled accordingly. - - \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter - on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with - the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. - - \see toPixmap -*/ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) -{ - // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - if (painter->isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else - qDebug() << Q_FUNC_INFO << "Passed painter is not active"; -} -/* end of 'src/core.cpp' */ - -//amalgamation: add plottable1d.cpp - -/* including file 'src/colorgradient.cpp', size 24646 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorGradient -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorGradient - \brief Defines a color gradient for use with e.g. \ref QCPColorMap - - This class describes a color gradient which can be used to encode data with color. For example, - QCPColorMap and QCPColorScale have \ref QCPColorMap::setGradient "setGradient" methods which - take an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) - with a \a position from 0 to 1. In between these defined color positions, the - color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. - - Alternatively, load one of the preset color gradients shown in the image below, with \ref - loadPreset, or by directly specifying the preset in the constructor. - - Apart from red, green and blue components, the gradient also interpolates the alpha values of the - configured color stops. This allows to display some portions of the data range as transparent in - the plot. - - \image html QCPColorGradient.png - - The \ref QCPColorGradient(GradientPreset preset) constructor allows directly converting a \ref - GradientPreset to a QCPColorGradient. This means that you can directly pass \ref GradientPreset - to all the \a setGradient methods, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorgradient-setgradient - - The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the - color gradient shall be applied periodically (wrapping around) to data values that lie outside - the data range specified on the plottable instance can be controlled with \ref setPeriodic. -*/ - -/*! - Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color - stops with \ref setColorStopAt. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient() : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); -} - -/*! - Constructs a new QCPColorGradient initialized with the colors and color interpolation according - to \a preset. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); -} - -/* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const -{ - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); -} - -/*! - Sets the number of discretization levels of the color gradient to \a n. The default is 350 which - is typically enough to create a smooth appearance. The minimum number of levels is 2. - - \image html QCPColorGradient-levelcount.png -*/ -void QCPColorGradient::setLevelCount(int n) -{ - if (n < 2) - { - qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; - n = 2; - } - if (n != mLevelCount) - { - mLevelCount = n; - mColorBufferInvalidated = true; - } -} - -/*! - Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the - colors are the values of the passed QMap \a colorStops. In between these color stops, the color - is interpolated according to \ref setColorInterpolation. - - A more convenient way to create a custom gradient may be to clear all color stops with \ref - clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with - \ref setColorStopAt. - - \see clearColorStops -*/ -void QCPColorGradient::setColorStops(const QMap &colorStops) -{ - mColorStops = colorStops; - mColorBufferInvalidated = true; -} - -/*! - Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between - these color stops, the color is interpolated according to \ref setColorInterpolation. - - \see setColorStops, clearColorStops -*/ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) -{ - mColorStops.insert(position, color); - mColorBufferInvalidated = true; -} - -/*! - Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be - interpolated linearly in RGB or in HSV color space. - - For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, - whereas in HSV space the intermediate color is yellow. -*/ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) -{ - if (interpolation != mColorInterpolation) - { - mColorInterpolation = interpolation; - mColorBufferInvalidated = true; - } -} - -/*! - Sets whether data points that are outside the configured data range (e.g. \ref - QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether - they all have the same color, corresponding to the respective gradient boundary color. - - \image html QCPColorGradient-periodic.png - - As shown in the image above, gradients that have the same start and end color are especially - suitable for a periodic gradient mapping, since they produce smooth color transitions throughout - the color map. A preset that has this property is \ref gpHues. - - In practice, using periodic color gradients makes sense when the data corresponds to a periodic - dimension, such as an angle or a phase. If this is not the case, the color encoding might become - ambiguous, because multiple different data values are shown as the same color. -*/ -void QCPColorGradient::setPeriodic(bool enabled) -{ - mPeriodic = enabled; -} - -/*! \overload - - This method is used to quickly convert a \a data array to colors. The colors will be output in - the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this - function. The data range that shall be used for mapping the data value to the gradient is passed - in \a range. \a logarithmic indicates whether the data values shall be mapped to colors - logarithmically. - - if \a data actually contains 2D-data linearized via [row*columnCount + column], you can - set \a dataIndexFactor to columnCount to convert a column instead of a row of the data - array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data - is addressed data[i*dataIndexFactor]. - - Use the overloaded method to additionally provide alpha map data. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } -} - -/*! \overload - - Additionally to the other overload of \ref colorize, this method takes the array \a alpha, which - has the same size and structure as \a data and encodes the alpha information per data point. - - The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied - with alpha (see QImage::Format_ARGB32_Premultiplied). -*/ -void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!alpha) - { - qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) - { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); - } - } - } - } -} - -/*! \internal - - This method is used to colorize a single data value given in \a position, to colors. The data - range that shall be used for mapping the data value to the gradient is passed in \a range. \a - logarithmic indicates whether the data value shall be mapped to a color logarithmically. - - If an entire array of data values shall be converted, rather use \ref colorize, for better - performance. - - The returned QRgb has its r, g and b components premultiplied with alpha (see - QImage::Format_ARGB32_Premultiplied). -*/ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) - updateColorBuffer(); - int index = 0; - if (!logarithmic) - index = (position-range.lower)*(mLevelCount-1)/range.size(); - else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); - if (mPeriodic) - { - index = index % mLevelCount; - if (index < 0) - index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - } - return mColorBuffer.at(index); -} - -/*! - Clears the current color stops and loads the specified \a preset. A preset consists of predefined - color stops and the corresponding color interpolation method. - - The available presets are: - \image html QCPColorGradient.png -*/ -void QCPColorGradient::loadPreset(GradientPreset preset) -{ - clearColorStops(); - switch (preset) - { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; - } -} - -/*! - Clears all color stops. - - \see setColorStops, setColorStopAt -*/ -void QCPColorGradient::clearColorStops() -{ - mColorStops.clear(); - mColorBufferInvalidated = true; -} - -/*! - Returns an inverted gradient. The inverted gradient has all properties as this \ref - QCPColorGradient, but the order of the color stops is inverted. - - \see setColorStops, setColorStopAt -*/ -QCPColorGradient QCPColorGradient::inverted() const -{ - QCPColorGradient result(*this); - result.clearColorStops(); - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); - return result; -} - -/*! \internal - - Returns true if the color gradient uses transparency, i.e. if any of the configured color stops - has an alpha value below 255. -*/ -bool QCPColorGradient::stopsUseAlpha() const -{ - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - { - if (it.value().alpha() < 255) - return true; - } - return false; -} - -/*! \internal - - Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly - convert positions to colors. This is where the interpolation between color stops is calculated. -*/ -void QCPColorGradient::updateColorBuffer() -{ - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) - { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); - const bool useAlpha = stopsUseAlpha(); - for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop - { - mColorBuffer[i] = (it-1).value().rgba(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop - { - mColorBuffer[i] = it.value().rgba(); - } else // position is in between stops (or on an intermediate stop), interpolate color - { - QMap::const_iterator high = it; - QMap::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) - { - case ciRGB: - { - if (useAlpha) - { - const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); - const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, - ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, - ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, - alpha); - } else - { - mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), - ((1-t)*low.value().green() + t*high.value().green()), - ((1-t)*low.value().blue() + t*high.value().blue())); - } - break; - } - case ciHSV: - { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - if (useAlpha) - { - const QRgb rgb = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); - mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); - } - else - { - mColorBuffer[i] = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - } - break; - } - } - } - } - } else if (mColorStops.size() == 1) - { - const QRgb rgb = mColorStops.constBegin().value().rgb(); - const float alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); - } else // mColorStops is empty, fill color buffer with black - { - mColorBuffer.fill(qRgb(0, 0, 0)); - } - mColorBufferInvalidated = false; -} -/* end of 'src/colorgradient.cpp' */ - - -/* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPSelectionDecoratorBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPSelectionDecoratorBracket - \brief A selection decorator which draws brackets around each selected data segment - - Additionally to the regular highlighting of selected segments via color, fill and scatter style, - this \ref QCPSelectionDecorator subclass draws markers at the begin and end of each selected data - segment of the plottable. - - The shape of the markers can be controlled with \ref setBracketStyle, \ref setBracketWidth and - \ref setBracketHeight. The color/fill can be controlled with \ref setBracketPen and \ref - setBracketBrush. - - To introduce custom bracket styles, it is only necessary to sublcass \ref - QCPSelectionDecoratorBracket and reimplement \ref drawBracket. The rest will be managed by the - base class. -*/ - -/*! - Creates a new QCPSelectionDecoratorBracket instance with default values. -*/ -QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : - mBracketPen(QPen(Qt::black)), - mBracketBrush(Qt::NoBrush), - mBracketWidth(5), - mBracketHeight(50), - mBracketStyle(bsSquareBracket), - mTangentToData(false), - mTangentAverage(2) -{ - -} - -QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() -{ -} - -/*! - Sets the pen that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) -{ - mBracketPen = pen; -} - -/*! - Sets the brush that will be used to draw the brackets at the beginning and end of each selected - data segment. -*/ -void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) -{ - mBracketBrush = brush; -} - -/*! - Sets the width of the drawn bracket. The width dimension is always parallel to the key axis of - the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketWidth(int width) -{ - mBracketWidth = width; -} - -/*! - Sets the height of the drawn bracket. The height dimension is always perpendicular to the key axis - of the data, or the tangent direction of the current data slope, if \ref setTangentToData is - enabled. -*/ -void QCPSelectionDecoratorBracket::setBracketHeight(int height) -{ - mBracketHeight = height; -} - -/*! - Sets the shape that the bracket/marker will have. - - \see setBracketWidth, setBracketHeight -*/ -void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) -{ - mBracketStyle = style; -} - -/*! - Sets whether the brackets will be rotated such that they align with the slope of the data at the - position that they appear in. - - For noisy data, it might be more visually appealing to average the slope over multiple data - points. This can be configured via \ref setTangentAverage. -*/ -void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) -{ - mTangentToData = enabled; -} - -/*! - Controls over how many data points the slope shall be averaged, when brackets shall be aligned - with the data (if \ref setTangentToData is true). - - From the position of the bracket, \a pointCount points towards the selected data range will be - taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to - disabling \ref setTangentToData. -*/ -void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) -{ - mTangentAverage = pointCount; - if (mTangentAverage < 1) - mTangentAverage = 1; -} - -/*! - Draws the bracket shape with \a painter. The parameter \a direction is either -1 or 1 and - indicates whether the bracket shall point to the left or the right (i.e. is a closing or opening - bracket, respectively). - - The passed \a painter already contains all transformations that are necessary to position and - rotate the bracket appropriately. Painting operations can be performed as if drawing upright - brackets on flat data with horizontal key axis, with (0, 0) being the center of the bracket. - - If you wish to sublcass \ref QCPSelectionDecoratorBracket in order to provide custom bracket - shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should - reimplement. -*/ -void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const -{ - switch (mBracketStyle) - { - case bsSquareBracket: - { - painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); - painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - break; - } - case bsHalfEllipse: - { - painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); - break; - } - case bsEllipse: - { - painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); - break; - } - case bsPlus: - { - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); - break; - } - default: - { - qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); - break; - } - } -} - -/*! - Draws the bracket decoration on the data points at the begin and end of each selected data - segment given in \a seletion. - - It uses the method \ref drawBracket to actually draw the shapes. - - \seebaseclassmethod -*/ -void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) -{ - if (!mPlottable || selection.isEmpty()) return; - - if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) - { - Q_FOREACH (const QCPDataRange &dataRange, selection.dataRanges()) - { - // determine position and (if tangent mode is enabled) angle of brackets: - int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; - int closeBracketDir = -openBracketDir; - QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); - QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); - double openBracketAngle = 0; - double closeBracketAngle = 0; - if (mTangentToData) - { - openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); - closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); - } - // draw opening bracket: - QTransform oldTransform = painter->transform(); - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(openBracketPos); - painter->rotate(openBracketAngle/M_PI*180.0); - drawBracket(painter, openBracketDir); - painter->setTransform(oldTransform); - // draw closing bracket: - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(closeBracketPos); - painter->rotate(closeBracketAngle/M_PI*180.0); - drawBracket(painter, closeBracketDir); - painter->setTransform(oldTransform); - } - } -} - -/*! \internal - - If \ref setTangentToData is enabled, brackets need to be rotated according to the data slope. - This method returns the angle in radians by which a bracket at the given \a dataIndex must be - rotated. - - The parameter \a direction must be set to either -1 or 1, representing whether it is an opening - or closing bracket. Since for slope calculation multiple data points are required, this defines - the direction in which the algorithm walks, starting at \a dataIndex, to average those data - points. (see \ref setTangentToData and \ref setTangentAverage) - - \a interface1d is the interface to the plottable's data which is used to query data coordinates. -*/ -double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const -{ - if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) - return 0; - direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 - - // how many steps we can actually go from index in the given direction without exceeding data bounds: - int averageCount; - if (direction < 0) - averageCount = qMin(mTangentAverage, dataIndex); - else - averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); - qDebug() << averageCount; - // calculate point average of averageCount points: - QVector points(averageCount); - QPointF pointsAverage; - int currentIndex = dataIndex; - for (int i=0; ikeyAxis(); - QCPAxis *valueAxis = mPlottable->valueAxis(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); - else - return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); -} -/* end of 'src/selectiondecorator-bracket.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisRect - \brief Holds multiple axes and arranges them in a rectangular shape. - - This class represents an axis rect, a rectangular area that is bounded on all sides with an - arbitrary number of axes. - - Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the - layout system allows to have multiple axis rects, e.g. arranged in a grid layout - (QCustomPlot::plotLayout). - - By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be - accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. - If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be - invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref - addAxes. To remove an axis, use \ref removeAxis. - - The axis rect layerable itself only draws a background pixmap or color, if specified (\ref - setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an - explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be - placed on other layers, independently of the axis rect. - - Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref - insetLayout and can be used to have other layout elements (or even other layouts with multiple - elements) hovering inside the axis rect. - - If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The - behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel - is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable - via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are - only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref - QCP::iRangeZoom. - - \image html AxisRectSpacingOverview.png -
Overview of the spacings and paddings that define the geometry of an axis. The dashed - line on the far left indicates the viewport/widget border.
-*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const - - Returns the inset layout of this axis rect. It can be used to place other layout elements (or - even layouts with multiple other elements) inside/on top of an axis rect. - - \see QCPLayoutInset -*/ - -/*! \fn int QCPAxisRect::left() const - - Returns the pixel position of the left border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::right() const - - Returns the pixel position of the right border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::top() const - - Returns the pixel position of the top border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::bottom() const - - Returns the pixel position of the bottom border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::width() const - - Returns the pixel width of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::height() const - - Returns the pixel height of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QSize QCPAxisRect::size() const - - Returns the pixel size of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topLeft() const - - Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, - so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topRight() const - - Returns the top right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomLeft() const - - Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomRight() const - - Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::center() const - - Returns the center of this axis rect in pixels. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four - sides, the top and right axes are set invisible initially. -*/ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) -{ - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList()); - mAxes.insert(QCPAxis::atRight, QList()); - mAxes.insert(QCPAxis::atTop, QList()); - mAxes.insert(QCPAxis::atBottom, QList()); - - if (setupDefaultAxes) - { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - } -} - -QCPAxisRect::~QCPAxisRect() -{ - delete mInsetLayout; - mInsetLayout = 0; - - QList axesList = axes(); - for (int i=0; i ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) - { - return ax.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; - return 0; - } -} - -/*! - Returns all axes on the axis rect sides specified with \a types. - - \a types may be a single \ref QCPAxis::AxisType or an or-combination, to get the axes of - multiple sides. - - \see axis -*/ -QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); - return result; -} - -/*! \overload - - Returns all axes of this axis rect. -*/ -QList QCPAxisRect::axes() const -{ - QList result; - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - result << it.value(); - } - return result; -} - -/*! - Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a - new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to - remove an axis, use \ref removeAxis instead of deleting it manually. - - You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was - previously created outside QCustomPlot. It is important to note that QCustomPlot takes ownership - of the axis, so you may not delete it afterwards. Further, the \a axis must have been created - with this axis rect as parent and with the same axis type as specified in \a type. If this is not - the case, a debug output is generated, the axis is not added, and the method returns 0. - - This method can not be used to move \a axis between axis rects. The same \a axis instance must - not be added multiple times to the same or different axis rects. - - If an axis rect side already contains one or more axes, the lower and upper endings of the new - axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are set to \ref - QCPLineEnding::esHalfBar. - - \see addAxes, setupFullAxesBox -*/ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) -{ - QCPAxis *newAxis = axis; - if (!newAxis) - { - newAxis = new QCPAxis(this, type); - } else // user provided existing axis instance, do some sanity checks - { - if (newAxis->axisType() != type) - { - qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; - return 0; - } - if (newAxis->axisRect() != this) - { - qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; - return 0; - } - if (axes().contains(newAxis)) - { - qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; - return 0; - } - } - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset - { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); - } - mAxes[type].append(newAxis); - - // reset convenience axis pointers on parent QCustomPlot if they are unset: - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - switch (type) - { - case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } - case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } - case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } - case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } - } - } - - return newAxis; -} - -/*! - Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an - or-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. - - Returns a list of the added axes. - - \see addAxis, setupFullAxesBox -*/ -QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) -{ - QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); - return result; -} - -/*! - Removes the specified \a axis from the axis rect and deletes it. - - Returns true on success, i.e. if \a axis was a valid axis in this axis rect. - - \see addAxis -*/ -bool QCPAxisRect::removeAxis(QCPAxis *axis) -{ - // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator > it(mAxes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(axis)) - { - if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) - it.value()[1]->setOffset(axis->offset()); - mAxes[it.key()].removeOne(axis); - if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); - delete axis; - return true; - } - } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); - return false; -} - -/*! - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - All axes of this axis rect will have their range zoomed accordingly. If you only wish to zoom - specific axes, use the overloaded version of this method. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect) -{ - zoom(pixelRect, axes()); -} - -/*! \overload - - Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. - - Only the axes passed in \a affectedAxes will have their ranges zoomed accordingly. - - \see QCustomPlot::setSelectionRectMode -*/ -void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) -{ - Q_FOREACH (QCPAxis *axis, affectedAxes) - { - if (!axis) - { - qDebug() << Q_FUNC_INFO << "a passed axis was zero"; - continue; - } - QCPRange pixelRange; - if (axis->orientation() == Qt::Horizontal) - pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); - else - pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); - axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); - } -} - -/*! - Convenience function to create an axis on each side that doesn't have any axes yet and set their - visibility to true. Further, the top/right axes are assigned the following properties of the - bottom/left axes: - - \li range (\ref QCPAxis::setRange) - \li range reversed (\ref QCPAxis::setRangeReversed) - \li scale type (\ref QCPAxis::setScaleType) - \li tick visibility (\ref QCPAxis::setTicks) - \li number format (\ref QCPAxis::setNumberFormat) - \li number precision (\ref QCPAxis::setNumberPrecision) - \li tick count of ticker (\ref QCPAxisTicker::setTickCount) - \li tick origin of ticker (\ref QCPAxisTicker::setTickOrigin) - - Tick label visibility (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. - - If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom - and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. -*/ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) -{ - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); - else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); - else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); - else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); - else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); - xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); - yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); - - if (connectRanges) - { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); - } -} - -/*! - Returns a list of all the plottables that are associated with this axis rect. - - A plottable is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see graphs, items -*/ -QList QCPAxisRect::plottables() const -{ - // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries - QList result; - for (int i=0; imPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that are associated with this axis rect. - - A graph is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see plottables, items -*/ -QList QCPAxisRect::graphs() const -{ - // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries - QList result; - for (int i=0; imGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis rect. - - An item is considered associated with an axis rect if any of its positions has key or value axis - set to an axis that is in this axis rect, or if any of its positions has \ref - QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref - QCPAbstractItem::setClipAxisRect) is set to this axis rect. - - \see plottables, graphs -*/ -QList QCPAxisRect::items() const -{ - // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries - // and miss those items that have this axis rect as clipAxisRect. - QList result; - for (int itemId=0; itemIdmItems.size(); ++itemId) - { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - continue; - } - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posIdaxisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - This method is called automatically upon replot and doesn't need to be called by users of - QCPAxisRect. - - Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), - and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its - QCPInsetLayout::update function. - - \seebaseclassmethod -*/ -void QCPAxisRect::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - switch (phase) - { - case upPreparation: - { - QList allAxes = axes(); - for (int i=0; isetupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; - } - - // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); -} - -/* inherits documentation from base class */ -QList QCPAxisRect::elements(bool recursive) const -{ - QList result; - if (mInsetLayout) - { - result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); - } - return result; -} - -/* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) -{ - drawBackground(painter); -} - -/*! - Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the - axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect - backgrounds are usually drawn below everything else. - - For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio - is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref - setBackground(const QBrush &brush). - - \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) -*/ -void QCPAxisRect::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! \overload - - Sets \a brush as the background brush. The axis rect background will be filled with this brush. - Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds - are usually drawn below everything else. - - The brush will be drawn before (under) any background pixmap, which may be specified with \ref - setBackground(const QPixmap &pm). - - To disable drawing of a background brush, set \a brush to Qt::NoBrush. - - \see setBackground(const QPixmap &pm) -*/ -void QCPAxisRect::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled - is set to true, you may control whether and how the aspect ratio of the original pixmap is - preserved with \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the axis rect dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to - define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. - \see setBackground, setBackgroundScaled -*/ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the range drag axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeDragAxes to retrieve a list with all set axes). - - \see setRangeDragAxes -*/ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); - else - return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); -} - -/*! - Returns the range zoom axis of the \a orientation provided. If multiple axes were set, returns - the first one (use \ref rangeZoomAxes to retrieve a list with all set axes). - - \see setRangeZoomAxes -*/ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) -{ - if (orientation == Qt::Horizontal) - return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); - else - return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); -} - -/*! - Returns all range drag axes of the \a orientation provided. - - \see rangeZoomAxis, setRangeZoomAxes -*/ -QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) -{ - QList result; - if (orientation == Qt::Horizontal) - { - for (int i=0; iQt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeDrag to enable the range dragging interaction. - - \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag -*/ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) -{ - mRangeDrag = orientations; -} - -/*! - Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation - corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, - QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical - axis is the left axis (yAxis). - - To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref - QCustomPlot::setInteractions. To enable range zooming for both directions, pass Qt::Horizontal | - Qt::Vertical as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeZoom to enable the range zooming interaction. - - \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag -*/ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) -{ - mRangeZoom = orientations; -} - -/*! \overload - - Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging on - the QCustomPlot widget. Pass 0 if no axis shall be dragged in the respective orientation. - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to dragging interactions. - - \see setRangeZoomAxes -*/ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical dragging. The drag - orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag - motion, use the overload taking two separate lists for horizontal and vertical dragging. -*/ -void QCPAxisRect::setRangeDragAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeDragAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical dragging, and - define specifically which axis reacts to which drag orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) -{ - mRangeDragHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeDragVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on - the QCustomPlot widget. Pass 0 if no axis shall be zoomed in the respective orientation. - - The two axes can be zoomed with different strengths, when different factors are passed to \ref - setRangeZoomFactor(double horizontalFactor, double verticalFactor). - - Use the overload taking a list of axes, if multiple axes (more than one per orientation) shall - react to zooming interactions. - - \see setRangeDragAxes -*/ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set up multiple axes to react to horizontal and vertical range zooming. The - zoom orientation that the respective axis will react to is deduced from its orientation (\ref - QCPAxis::orientation). - - In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom - interaction, use the overload taking two separate lists for horizontal and vertical zooming. -*/ -void QCPAxisRect::setRangeZoomAxes(QList axes) -{ - QList horz, vert; - Q_FOREACH (QCPAxis *ax, axes) - { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); - else - vert.append(ax); - } - setRangeZoomAxes(horz, vert); -} - -/*! \overload - - This method allows to set multiple axes up to react to horizontal and vertical zooming, and - define specifically which axis reacts to which zoom orientation (irrespective of the axis - orientation). -*/ -void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) -{ - mRangeZoomHorzAxis.clear(); - Q_FOREACH (QCPAxis *ax, horizontal) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomHorzAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); - } - mRangeZoomVertAxis.clear(); - Q_FOREACH (QCPAxis *ax, vertical) - { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomVertAxis.append(axPointer); - else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); - } -} - -/*! - Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with - \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to - let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal - and which is vertical, can be set with \ref setRangeZoomAxes. - - When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) - will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the - same scrolling direction will zoom out. -*/ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) -{ - mRangeZoomFactorHorz = horizontalFactor; - mRangeZoomFactorVert = verticalFactor; -} - -/*! \overload - - Sets both the horizontal and vertical zoom \a factor. -*/ -void QCPAxisRect::setRangeZoomFactor(double factor) -{ - mRangeZoomFactorHorz = factor; - mRangeZoomFactorVert = factor; -} - -/*! \internal - - Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a - pixmap. - - If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an - according filling inside the axis rect with the provided \a painter. - - Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the axis rect with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::drawBackground(QCPPainter *painter) -{ - // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); - } - } -} - -/*! \internal - - This function makes sure multiple axes on the side specified with \a type don't collide, but are - distributed according to their respective space requirement (QCPAxis::calculateMargin). - - It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the - one with index zero. - - This function is called by \ref calculateAutoMargin. -*/ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) -{ - const QList axesList = mAxes.value(type); - if (axesList.isEmpty()) - return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; ioffset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) - { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); - isFirstVisible = false; - } - axesList.at(i)->setOffset(offset); - } -} - -/* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) -{ - if (!mAutoMargins.testFlag(side)) - qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - - // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) - return axesList.last()->offset() + axesList.last()->calculateMargin(); - else - return 0; -} - -/*! \internal - - Reacts to a change in layout to potentially set the convenience axis pointers \ref - QCustomPlot::xAxis, \ref QCustomPlot::yAxis, etc. of the parent QCustomPlot to the respective - axes of this axis rect. This is only done if the respective convenience pointer is currently zero - and if there is no QCPAxisRect at position (0, 0) of the plot layout. - - This automation makes it simpler to replace the main axis rect with a newly created one, without - the need to manually reset the convenience pointers. -*/ -void QCPAxisRect::layoutChanged() -{ - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) - { - if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) - mParentPlot->xAxis = axis(QCPAxis::atBottom); - if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) - mParentPlot->yAxis = axis(QCPAxis::atLeft); - if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) - mParentPlot->xAxis2 = axis(QCPAxis::atTop); - if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) - mParentPlot->yAxis2 = axis(QCPAxis::atRight); - } -} - -/*! \internal - - Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is - pressed, the range dragging interaction is initialized (the actual range manipulation happens in - the \ref mouseMoveEvent). - - The mDragging flag is set to true and some anchor points are set that are needed to determine the - distance the mouse was dragged in the mouse move/release events later. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - mDragStartHorzRange.clear(); - for (int i=0; irange()); - mDragStartVertRange.clear(); - for (int i=0; irange()); - } - } -} - -/*! \internal - - Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a - preceding \ref mousePressEvent, the range is moved accordingly. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(startPos) - // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - - if (mRangeDrag.testFlag(Qt::Horizontal)) - { - for (int i=0; i= mDragStartHorzRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag.testFlag(Qt::Vertical)) - { - for (int i=0; i= mDragStartVertRange.size()) - break; - if (ax->mScaleType == QCPAxis::stLinear) - { - double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) - { - double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); - } - } - } - - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot - { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); - } - - } -} - -/* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - Q_UNUSED(event) - Q_UNUSED(startPos) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the - ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of - the scaling operation is the current cursor position inside the axis rect. The scaling factor is - dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural - zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. - - Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse - wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be - multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as - exponent of the range zoom factor. This takes care of the wheel direction automatically, by - inverting the factor, when the wheel step is negative (f^-1 = 1/f). -*/ -void QCPAxisRect::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) - { - if (mRangeZoom != 0) - { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) - { - factor = qPow(mRangeZoomFactorHorz, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); - } - } - if (mRangeZoom.testFlag(Qt::Vertical)) - { - factor = qPow(mRangeZoomFactorVert, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); - } - } - mParentPlot->replot(); - } - } -} -/* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-legend.cpp', size 31097 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractLegendItem - \brief The abstract base class for all entries in a QCPLegend. - - It defines a very basic interface for entries in a QCPLegend. For representing plottables in the - legend, the subclass \ref QCPPlottableLegendItem is more suitable. - - Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry - that's not even associated with a plottable). - - You must implement the following pure virtual functions: - \li \ref draw (from QCPLayerable) - - You inherit the following members you may use: - - - - - - - - -
QCPLegend *\b mParentLegendA pointer to the parent QCPLegend.
QFont \b mFontThe generic font of the item. You should use this font for all or at least the most prominent text of the item.
-*/ - -/* start of documentation of signals */ - -/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) - - This signal is emitted when the selection state of this legend item has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/* end of documentation of signals */ - -/*! - Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not - cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. -*/ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) -{ - setLayer(QLatin1String("legend")); - setMargins(QMargins(0, 0, 0, 0)); -} - -/*! - Sets the default font of this specific legend item to \a font. - - \see setTextColor, QCPLegend::setFont -*/ -void QCPAbstractLegendItem::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the default text color of this specific legend item to \a color. - - \see setFont, QCPLegend::setTextColor -*/ -void QCPAbstractLegendItem::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - When this legend item is selected, \a font is used to draw generic text, instead of the normal - font set with \ref setFont. - - \see setFont, QCPLegend::setSelectedFont -*/ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - When this legend item is selected, \a color is used to draw generic text, instead of the normal - color set with \ref setTextColor. - - \see setTextColor, QCPLegend::setSelectedTextColor -*/ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether this specific legend item is selectable. - - \see setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets whether this specific legend item is selected. - - It is possible to set the selection state of this item by calling this function directly, even if - setSelectable is set to false. - - \see setSelectableParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) - return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); -} - -/* inherits documentation from base class */ -QRect QCPAbstractLegendItem::clipRect() const -{ - return mOuterRect; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableLegendItem - \brief A legend item representing a plottable with an icon and the plottable name. - - This is the standard legend item for plottables. It displays an icon of the plottable next to the - plottable name. The icon is drawn by the respective plottable itself (\ref - QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. - For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the - middle. - - Legend items of this type are always associated with one plottable (retrievable via the - plottable() function and settable with the constructor). You may change the font of the plottable - name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref - QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. - - The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend - creates/removes legend items of this type. - - Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of - QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout - interface, QCPLegend has specialized functions for handling legend items conveniently, see the - documentation of \ref QCPLegend. -*/ - -/*! - Creates a new legend item associated with \a plottable. - - Once it's created, it can be added to the legend via \ref QCPLegend::addItem. - - A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref - QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. -*/ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) -{ - setAntialiased(false); -} - -/*! \internal - - Returns the pen that shall be used to draw the icon border, taking into account the selection - state of this item. -*/ -QPen QCPPlottableLegendItem::getIconBorderPen() const -{ - return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); -} - -/*! \internal - - Returns the text color that shall be used to draw text, taking into account the selection state - of this item. -*/ -QColor QCPPlottableLegendItem::getTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - -/*! \internal - - Returns the font that shall be used to draw text, taking into account the selection state of this - item. -*/ -QFont QCPPlottableLegendItem::getFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Draws the item with \a painter. The size and position of the drawn legend item is defined by the - parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref - maximumOuterSizeHint of this legend item. -*/ -void QCPPlottableLegendItem::draw(QCPPainter *painter) -{ - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); - QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); - // draw icon: - painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); - painter->restore(); - // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) - { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - int halfPen = qCeil(painter->pen().widthF()*0.5)+1; - painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped - painter->drawRect(iconRect); - } -} - -/*! \internal - - Calculates and returns the size of this item. This includes the icon, the text and the padding in - between. - - \seebaseclassmethod -*/ -QSize QCPPlottableLegendItem::minimumOuterSizeHint() const -{ - if (!mPlottable) return QSize(); - QSize result(0, 0); - QRect textRect; - QFontMetrics fontMetrics(getFont()); - QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); - result.setHeight(qMax(textRect.height(), iconSize.height())); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLegend -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLegend - \brief Manages a legend inside a QCustomPlot. - - A legend is a small box somewhere in the plot which lists plottables with their name and icon. - - A legend is populated with legend items by calling \ref QCPAbstractPlottable::addToLegend on the - plottable, for which a legend item shall be created. In the case of the main legend (\ref - QCustomPlot::legend), simply adding plottables to the plot while \ref - QCustomPlot::setAutoAddPlottableToLegend is set to true (the default) creates corresponding - legend items. The legend item associated with a certain plottable can be removed with \ref - QCPAbstractPlottable::removeFromLegend. However, QCPLegend also offers an interface to add and - manipulate legend items directly: \ref item, \ref itemWithPlottable, \ref itemCount, \ref - addItem, \ref removeItem, etc. - - Since \ref QCPLegend derives from \ref QCPLayoutGrid, it can be placed in any position a \ref - QCPLayoutElement may be positioned. The legend items are themselves \ref QCPLayoutElement - "QCPLayoutElements" which are placed in the grid layout of the legend. \ref QCPLegend only adds - an interface specialized for handling child elements of type \ref QCPAbstractLegendItem, as - mentioned above. In principle, any other layout elements may also be added to a legend via the - normal \ref QCPLayoutGrid interface. See the special page about \link thelayoutsystem The Layout - System\endlink for examples on how to add other elements to the legend and move it outside the axis - rect. - - Use the methods \ref setFillOrder and \ref setWrap inherited from \ref QCPLayoutGrid to control - in which order (column first or row first) the legend is filled up when calling \ref addItem, and - at which column or row wrapping occurs. - - By default, every QCustomPlot has one legend (\ref QCustomPlot::legend) which is placed in the - inset layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another - position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend - outside of the axis rect, place it anywhere else with the \ref QCPLayout/\ref QCPLayoutElement - interface. -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); - - This signal is emitted when the selection state of this legend has changed. - - \see setSelectedParts, setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs a new QCPLegend instance with default values. - - Note that by default, QCustomPlot already contains a legend ready to be used as \ref - QCustomPlot::legend -*/ -QCPLegend::QCPLegend() -{ - setFillOrder(QCPLayoutGrid::foRowsFirst); - setWrap(0); - - setRowSpacing(3); - setColumnSpacing(8); - setMargins(QMargins(7, 5, 7, 4)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black, 0)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); -} - -QCPLegend::~QCPLegend() -{ - clearItems(); - if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) - mParentPlot->legendRemoved(this); -} - -/* no doc for getter, see setSelectedParts */ -QCPLegend::SelectableParts QCPLegend::selectedParts() const -{ - // check whether any legend elements selected, if yes, add spItems to return value - bool hasSelectedItems = false; - for (int i=0; iselected()) - { - hasSelectedItems = true; - break; - } - } - if (hasSelectedItems) - return mSelectedParts | spItems; - else - return mSelectedParts & ~spItems; -} - -/*! - Sets the pen, the border of the entire legend is drawn with. -*/ -void QCPLegend::setBorderPen(const QPen &pen) -{ - mBorderPen = pen; -} - -/*! - Sets the brush of the legend background. -*/ -void QCPLegend::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will - use this font by default. However, a different font can be specified on a per-item-basis by - accessing the specific legend item. - - This function will also set \a font on all already existing legend items. - - \see QCPAbstractLegendItem::setFont -*/ -void QCPLegend::setFont(const QFont &font) -{ - mFont = font; - for (int i=0; isetFont(mFont); - } -} - -/*! - Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) - will use this color by default. However, a different colors can be specified on a per-item-basis - by accessing the specific legend item. - - This function will also set \a color on all already existing legend items. - - \see QCPAbstractLegendItem::setTextColor -*/ -void QCPLegend::setTextColor(const QColor &color) -{ - mTextColor = color; - for (int i=0; isetTextColor(color); - } -} - -/*! - Sets the size of legend icons. Legend items that draw an icon (e.g. a visual - representation of the graph) will use this size by default. -*/ -void QCPLegend::setIconSize(const QSize &size) -{ - mIconSize = size; -} - -/*! \overload -*/ -void QCPLegend::setIconSize(int width, int height) -{ - mIconSize.setWidth(width); - mIconSize.setHeight(height); -} - -/*! - Sets the horizontal space in pixels between the legend icon and the text next to it. - Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the - name of the graph) will use this space by default. -*/ -void QCPLegend::setIconTextPadding(int padding) -{ - mIconTextPadding = padding; -} - -/*! - Sets the pen used to draw a border around each legend icon. Legend items that draw an - icon (e.g. a visual representation of the graph) will use this pen by default. - - If no border is wanted, set this to \a Qt::NoPen. -*/ -void QCPLegend::setIconBorderPen(const QPen &pen) -{ - mIconBorderPen = pen; -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - Q_EMIT selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected - doesn't contain \ref spItems, those items become deselected. - - The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions - contains iSelectLegend. You only need to call this function when you wish to change the selection - state manually. - - This function can change the selection state of a part even when \ref setSelectableParts was set to a - value that actually excludes the part. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set - before, because there's no way to specify which exact items to newly select. Do this by calling - \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, - setSelectedFont -*/ -void QCPLegend::setSelectedParts(const SelectableParts &selected) -{ - SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - - if (mSelectedParts != newSelected) - { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) - { - qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; - newSelected &= ~spItems; - } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection - { - for (int i=0; isetSelected(false); - } - } - mSelectedParts = newSelected; - Q_EMIT selectionChanged(mSelectedParts); - } -} - -/*! - When the legend box is selected, this pen is used to draw the border instead of the normal pen - set via \ref setBorderPen. - - \see setSelectedParts, setSelectableParts, setSelectedBrush -*/ -void QCPLegend::setSelectedBorderPen(const QPen &pen) -{ - mSelectedBorderPen = pen; -} - -/*! - Sets the pen legend items will use to draw their icon borders, when they are selected. - - \see setSelectedParts, setSelectableParts, setSelectedFont -*/ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) -{ - mSelectedIconBorderPen = pen; -} - -/*! - When the legend box is selected, this brush is used to draw the legend background instead of the normal brush - set via \ref setBrush. - - \see setSelectedParts, setSelectableParts, setSelectedBorderPen -*/ -void QCPLegend::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the default font that is used by legend items when they are selected. - - This function will also set \a font on all already existing legend items. - - \see setFont, QCPAbstractLegendItem::setSelectedFont -*/ -void QCPLegend::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; - for (int i=0; isetSelectedFont(font); - } -} - -/*! - Sets the default text color that is used by legend items when they are selected. - - This function will also set \a color on all already existing legend items. - - \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor -*/ -void QCPLegend::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; - for (int i=0; isetSelectedTextColor(color); - } -} - -/*! - Returns the item with index \a i. - - Note that the linear index depends on the current fill order (\ref setFillOrder). - - \see itemCount, addItem, itemWithPlottable -*/ -QCPAbstractLegendItem *QCPLegend::item(int index) const -{ - return qobject_cast(elementAt(index)); -} - -/*! - Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns 0. - - \see hasItemWithPlottable -*/ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - for (int i=0; i(item(i))) - { - if (pli->plottable() == plottable) - return pli; - } - } - return 0; -} - -/*! - Returns the number of items currently in the legend. - - Note that if empty cells are in the legend (e.g. by calling methods of the \ref QCPLayoutGrid - base class which allows creating empty cells), they are included in the returned count. - - \see item -*/ -int QCPLegend::itemCount() const -{ - return elementCount(); -} - -/*! - Returns whether the legend contains \a item. - - \see hasItemWithPlottable -*/ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const -{ - for (int i=0; iitem(i)) - return true; - } - return false; -} - -/*! - Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns false. - - \see itemWithPlottable -*/ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - return itemWithPlottable(plottable); -} - -/*! - Adds \a item to the legend, if it's not present already. The element is arranged according to the - current fill order (\ref setFillOrder) and wrapping (\ref setWrap). - - Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. - - The legend takes ownership of the item. - - \see removeItem, item, hasItem -*/ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) -{ - return addElement(item); -} - -/*! \overload - - Removes the item with the specified \a index from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. Unlike \ref QCPLayoutGrid::removeAt, this method only removes - elements derived from \ref QCPAbstractLegendItem. - - \see itemCount, clearItems -*/ -bool QCPLegend::removeItem(int index) -{ - if (QCPAbstractLegendItem *ali = item(index)) - { - bool success = remove(ali); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; - } else - return false; -} - -/*! \overload - - Removes \a item from the legend and deletes it. - - After successful removal, the legend is reordered according to the current fill order (\ref - setFillOrder) and wrapping (\ref setWrap), so no empty cell remains where the removed \a item - was. If you don't want this, rather use the raw element interface of \ref QCPLayoutGrid. - - Returns true, if successful. - - \see clearItems -*/ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) -{ - bool success = remove(item); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering - return success; -} - -/*! - Removes all items from the legend. -*/ -void QCPLegend::clearItems() -{ - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); -} - -/*! - Returns the legend items that are currently selected. If no items are selected, - the list is empty. - - \see QCPAbstractLegendItem::setSelected, setSelectable -*/ -QList QCPLegend::selectedItems() const -{ - QList result; - for (int i=0; iselected()) - result.append(ali); - } - } - return result; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing main legend elements. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \seebaseclassmethod - - \see setAntialiased -*/ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); -} - -/*! \internal - - Returns the pen used to paint the border of the legend, taking into account the selection state - of the legend box. -*/ -QPen QCPLegend::getBorderPen() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; -} - -/*! \internal - - Returns the brush used to paint the background of the legend, taking into account the selection - state of the legend box. -*/ -QBrush QCPLegend::getBrush() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; -} - -/*! \internal - - Draws the legend box with the provided \a painter. The individual legend items are layerables - themselves, thus are drawn independently. -*/ -void QCPLegend::draw(QCPPainter *painter) -{ - // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); -} - -/* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) - return -1; - - if (mOuterRect.contains(pos.toPoint())) - { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) -{ - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPLegend::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractLegendItem::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) -{ - if (parentPlot && !parentPlot->legend) - parentPlot->legend = this; -} -/* end of 'src/layoutelements/layoutelement-legend.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPTextElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPTextElement - \brief A layout element displaying a text - - The text may be specified with \ref setText, the formatting can be controlled with \ref setFont, - \ref setTextColor, and \ref setTextFlags. - - A text element can be added as follows: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcptextelement-creation -*/ - -/* start documentation of signals */ - -/*! \fn void QCPTextElement::selectionChanged(bool selected) - - This signal is emitted when the selection state has changed to \a selected, either by user - interaction or by a direct call to \ref setSelected. - - \see setSelected, setSelectable -*/ - -/*! \fn void QCPTextElement::clicked(QMouseEvent *event) - - This signal is emitted when the text element is clicked. - - \see doubleClicked, selectTest -*/ - -/*! \fn void QCPTextElement::doubleClicked(QMouseEvent *event) - - This signal is emitted when the text element is double clicked. - - \see clicked, selectTest -*/ - -/* end documentation of signals */ - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref - setText). -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mText(), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mSelectedFont = parentPlot->font(); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - mFont = parentPlot->font(); - mFont.setPointSizeF(pointSize); - mSelectedFont = parentPlot->font(); - mSelectedFont.setPointSizeF(pointSize); - } - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with \a pointSize and the specified \a fontFamily. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(fontFamily, pointSize)), - mTextColor(Qt::black), - mSelectedFont(QFont(fontFamily, pointSize)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! \overload - - Creates a new QCPTextElement instance and sets default values. - - The initial text is set to \a text with the specified \a font. -*/ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(font), - mTextColor(Qt::black), - mSelectedFont(font), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setMargins(QMargins(2, 2, 2, 2)); -} - -/*! - Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". - - \see setFont, setTextColor, setTextFlags -*/ -void QCPTextElement::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets options for text alignment and wrapping behaviour. \a flags is a bitwise OR-combination of - \c Qt::AlignmentFlag and \c Qt::TextFlag enums. - - Possible enums are: - - Qt::AlignLeft - - Qt::AlignRight - - Qt::AlignHCenter - - Qt::AlignJustify - - Qt::AlignTop - - Qt::AlignBottom - - Qt::AlignVCenter - - Qt::AlignCenter - - Qt::TextDontClip - - Qt::TextSingleLine - - Qt::TextExpandTabs - - Qt::TextShowMnemonic - - Qt::TextWordWrap - - Qt::TextIncludeTrailingSpaces -*/ -void QCPTextElement::setTextFlags(int flags) -{ - mTextFlags = flags; -} - -/*! - Sets the \a font of the text. - - \see setTextColor, setSelectedFont -*/ -void QCPTextElement::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the \a color of the text. - - \see setFont, setSelectedTextColor -*/ -void QCPTextElement::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - Sets the \a font of the text that will be used if the text element is selected (\ref setSelected). - - \see setFont -*/ -void QCPTextElement::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the \a color of the text that will be used if the text element is selected (\ref setSelected). - - \see setTextColor -*/ -void QCPTextElement::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether the user may select this text element. - - Note that even when \a selectable is set to false, the selection state may be changed - programmatically via \ref setSelected. -*/ -void QCPTextElement::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - Q_EMIT selectableChanged(mSelectable); - } -} - -/*! - Sets the selection state of this text element to \a selected. If the selection has changed, \ref - selectionChanged is emitted. - - Note that this function can change the selection state independently of the current \ref - setSelectable state. -*/ -void QCPTextElement::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - Q_EMIT selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); -} - -/* inherits documentation from base class */ -void QCPTextElement::draw(QCPPainter *painter) -{ - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); -} - -/* inherits documentation from base class */ -QSize QCPTextElement::minimumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPTextElement::maximumOuterSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.setWidth(QWIDGETSIZE_MAX); - result.rheight() += mMargins.top()+mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPTextElement::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/*! - Returns 0.99*selectionTolerance (see \ref QCustomPlot::setSelectionTolerance) when \a pos is - within the bounding box of the text element's text. Note that this bounding box is updated in the - draw call. - - If \a pos is outside the text's bounding box or if \a onlySelectable is true and this text - element is not selectable (\ref setSelectable), returns -1. - - \seebaseclassmethod -*/ -double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/*! - Accepts the mouse event in order to emit the according click signal in the \ref - mouseReleaseEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - event->accept(); -} - -/*! - Emits the \ref clicked signal if the cursor hasn't moved by more than a few pixels since the \ref - mousePressEvent. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) - Q_EMIT clicked(event); -} - -/*! - Emits the \ref doubleClicked signal. - - \seebaseclassmethod -*/ -void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) -{ - Q_UNUSED(details) - Q_EMIT doubleClicked(event); -} - -/*! \internal - - Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to - true, else mFont is returned. -*/ -QFont QCPTextElement::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to - true, else mTextColor is returned. -*/ -QColor QCPTextElement::mainTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} -/* end of 'src/layoutelements/layoutelement-textelement.cpp' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 25770 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScale -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScale - \brief A color scale for use with color coding data such as QCPColorMap - - This layout element can be placed on the plot to correlate a color gradient with data values. It - is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". - - \image html QCPColorScale.png - - The color scale can be either horizontal or vertical, as shown in the image above. The - orientation and the side where the numbers appear is controlled with \ref setType. - - Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are - connected, they share their gradient, data range and data scale type (\ref setGradient, \ref - setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color - scale, to make them all synchronize these properties. - - To have finer control over the number display and axis behaviour, you can directly access the - \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if - you want to change the number of automatically generated ticks, call - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-tickcount - - Placing a color scale next to the main axis rect works like with any other layout element: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-creation - In this case we have placed it to the right of the default axis rect, so it wasn't necessary to - call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color - scale can be set with \ref setLabel. - - For optimum appearance (like in the image above), it may be desirable to line up the axis rect and - the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcolorscale-margingroup - - Color scales are initialized with a non-zero minimum top and bottom margin (\ref - setMinimumMargins), because vertical color scales are most common and the minimum top/bottom - margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a - horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you - might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)). -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPAxis *QCPColorScale::axis() const - - Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the - appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its - interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref - setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref - QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on - the QCPColorScale or on its QCPAxis. - - If the type of the color scale is changed with \ref setType, the axis returned by this method - will change, too, to either the left, right, bottom or top axis, depending on which type was set. -*/ - -/* end documentation of signals */ -/* start documentation of signals */ - -/*! \fn void QCPColorScale::dataRangeChanged(const QCPRange &newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorScale::gradientChanged(const QCPColorGradient &newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a new QCPColorScale. -*/ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) -{ - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); -} - -QCPColorScale::~QCPColorScale() -{ - delete mAxisRect; -} - -/* undocumented getter */ -QString QCPColorScale::label() const -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return QString(); - } - - return mColorAxis.data()->label(); -} - -/* undocumented getter */ -bool QCPColorScale::rangeDrag() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/* undocumented getter */ -bool QCPColorScale::rangeZoom() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/*! - Sets at which side of the color scale the axis is placed, and thus also its orientation. - - Note that after setting \a type to a different value, the axis returned by \ref axis() will - be a different one. The new axis will adopt the following properties from the previous axis: The - range, scale type, label and ticker (the latter will be shared and not copied). -*/ -void QCPColorScale::setType(QCPAxis::AxisType type) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - if (mType != type) - { - mType = type; - QCPRange rangeTransfer(0, 6); - QString labelTransfer; - QSharedPointer tickerTransfer; - // transfer/revert some settings on old axis if it exists: - bool doTransfer = (bool)mColorAxis; - if (doTransfer) - { - rangeTransfer = mColorAxis.data()->range(); - labelTransfer = mColorAxis.data()->label(); - tickerTransfer = mColorAxis.data()->ticker(); - mColorAxis.data()->setLabel(QString()); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; - Q_FOREACH (QCPAxis::AxisType atype, allAxisTypes) - { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); - } - // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); - // transfer settings to new axis: - if (doTransfer) - { - mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setTicker(tickerTransfer); - } - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); - } -} - -/*! - Sets the range spanned by the color gradient and that is shown by the axis in the color scale. - - It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its range with \ref - QCPAxis::setRange. - - \see setDataScaleType, setGradient, rescaleDataRange -*/ -void QCPColorScale::setDataRange(const QCPRange &dataRange) -{ - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets the scale type of the color scale, i.e. whether values are linearly associated with colors - or logarithmically. - - It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its scale type with \ref - QCPAxis::setScaleType. - - \see setDataRange, setGradient -*/ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - Q_EMIT dataScaleTypeChanged(mDataScaleType); - } -} - -/*! - Sets the color gradient that will be used to represent data values. - - It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. - - \see setDataRange, setDataScaleType -*/ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - if (mAxisRect) - mAxisRect.data()->mGradientImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on - the internal \ref axis. -*/ -void QCPColorScale::setLabel(const QString &str) -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return; - } - - mColorAxis.data()->setLabel(str); -} - -/*! - Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed - will have. -*/ -void QCPColorScale::setBarWidth(int width) -{ - mBarWidth = width; -} - -/*! - Sets whether the user can drag the data range (\ref setDataRange). - - Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeDrag(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeDrag(0); -} - -/*! - Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. - - Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeZoom(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeZoom(0); -} - -/*! - Returns a list of all the color maps associated with this color scale. -*/ -QList QCPColorScale::colorMaps() const -{ - QList result; - for (int i=0; iplottableCount(); ++i) - { - if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); - } - return result; -} - -/*! - Changes the data range such that all color maps associated with this color scale are fully mapped - to the gradient in the data dimension. - - \see setDataRange -*/ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) -{ - QList maps = colorMaps(); - QCPRange newRange; - bool haveRange = false; - QCP::SignDomain sign = QCP::sdBoth; - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - for (int i=0; irealVisibility() && onlyVisibleMaps) - continue; - QCPRange mapRange; - if (maps.at(i)->colorScale() == this) - { - bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == QCP::sdPositive) - { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == QCP::sdNegative) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) - currentFoundRange = false; - } - if (currentFoundRange) - { - if (!haveRange) - newRange = mapRange; - else - newRange.expand(mapRange); - haveRange = true; - } - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) - { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); - } - } - setDataRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - mAxisRect.data()->update(phase); - - switch (phase) - { - case upMargins: - { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); - } - break; - } - case upLayout: - { - mAxisRect.data()->setOuterRect(rect()); - break; - } - default: break; - } -} - -/* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mousePressEvent(event, details); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseMoveEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseReleaseEvent(event, startPos); -} - -/* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->wheelEvent(event); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScaleAxisRectPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScaleAxisRectPrivate - - \internal - \brief An axis rect subclass for use in a QCPColorScale - - This is a private class and not part of the public QCustomPlot interface. - - It provides the axis rect functionality for the QCPColorScale class. -*/ - - -/*! - Creates a new instance, as a child of \a parentColorScale. -*/ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) -{ - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); - } - - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - - // make layer transfers of color scale transfer to axis rect and axes - // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); -} - -/*! \internal - - Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws - it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. - - \seebaseclassmethod -*/ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) -{ - if (mGradientImageInvalidated) - updateGradientImage(); - - bool mirrorHorz = false; - bool mirrorVert = false; - if (mParentColorScale->mColorAxis) - { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); - } - - painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); -} - -/*! \internal - - Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to - generate a gradient image. This gradient image will be used in the \ref draw method. -*/ -void QCPColorScaleAxisRectPrivate::updateGradientImage() -{ - if (rect().isEmpty()) - return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - int n = mParentColorScale->mGradient.levelCount(); - int w, h; - QVector data(n); - for (int i=0; imType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) - { - w = n; - h = rect().height(); - mGradientImage = QImage(w, h, format); - QVector pixels; - for (int y=0; y(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); - else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); - } - } -} - -/*! \internal - - This slot is connected to the selectableChanged signals of the four axes in the constructor. It - synchronizes the selectability of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) -{ - // synchronize axis base selectability: - QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - Q_FOREACH (QCPAxis::AxisType type, allAxisTypes) - { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); - else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); - } - } -} -/* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ - - -/* including file 'src/plottables/plottable-graph.cpp', size 73960 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraphData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraphData - \brief Holds the data of one single data point for QCPGraph. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a value: coordinate on the value axis of this data point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPGraphDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPGraphData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPGraphDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPGraphData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPGraphData QCPGraphData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPGraphData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPGraphData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPGraphData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and value set to zero. -*/ -QCPGraphData::QCPGraphData() : - key(0), - value(0) -{ -} - -/*! - Constructs a data point with the specified \a key and \a value. -*/ -QCPGraphData::QCPGraphData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraph -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraph - \brief A plottable representing a graph in a plot. - - \image html QCPGraph.png - - Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be - accessed via QCustomPlot::graph. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPGraphDataContainer. - - Graphs are used to display single-valued data. Single-valued means that there should only be one - data point per unique key coordinate. In other words, the graph can't have \a loops. If you do - want to plot non-single-valued curves, rather use the QCPCurve plottable. - - Gaps in the graph line can be created by adding data points with NaN as value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpgraph-appearance Changing the appearance - - The appearance of the graph is mainly determined by the line style, scatter style, brush and pen - of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). - - \subsection filling Filling under or between graphs - - QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to - the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, - just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. - - By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill - between this graph and another one, call \ref setChannelFillGraph with the other graph as - parameter. - - \see QCustomPlot::addGraph, QCustomPlot::graph -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPGraph::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPGraphDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPGraph is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually - but use QCustomPlot::removePlottable() instead. - - To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. -*/ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // special handling for QCPGraphs to maintain the simple graph interface: - mParentPlot->registerGraph(this); - - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setScatterSkip(0); - setChannelFillGraph(0); - setAdaptiveSampling(true); -} - -QCPGraph::~QCPGraph() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. - Modifying the data in the container will then affect all graphs that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the graph's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpgraph-datasharing-2 - - \see addData -*/ -void QCPGraph::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to - \ref lsNone and \ref setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPGraph::setLineStyle(LineStyle ls) -{ - mLineStyle = ls; -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points - are drawn (e.g. for line-only-plots with appropriate line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPGraph::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets the target graph for filling the area between this graph and \a targetGraph with the current - brush (\ref setBrush). - - When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To - disable any filling, set the brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) -{ - // prevent setting channel target to this graph itself: - if (targetGraph == this) - { - qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; - mChannelFillGraph = 0; - return; - } - // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; - mChannelFillGraph = 0; - return; - } - - mChannelFillGraph = targetGraph; -} - -/*! - Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive - sampling technique can drastically improve the replot performance for graphs with a larger number - of points (e.g. above 10,000), without notably changing the appearance of the graph. - - By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive - sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no - disadvantage in almost all cases. - - \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" - - As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are - reproduced reliably, as well as the overall shape of the data set. The replot time reduces - dramatically though. This allows QCustomPlot to display large amounts of data in realtime. - - \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" - - Care must be taken when using high-density scatter plots in combination with adaptive sampling. - The adaptive sampling algorithm treats scatter plots more carefully than line plots which still - gives a significant reduction of replot times, but not quite as much as for line plots. This is - because scatter plots inherently need more data points to be preserved in order to still resemble - the original, non-adaptive-sampling plot. As shown above, the results still aren't quite - identical, as banding occurs for the outer data points. This is in fact intentional, such that - the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, - depends on the point density, i.e. the number of points in the plot. - - For some situations with scatter plots it might thus be desirable to manually turn adaptive - sampling off. For example, when saving the plot to disk. This can be achieved by setting \a - enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled - back to true afterwards. -*/ -void QCPGraph::setAdaptiveSampling(bool enabled) -{ - mAdaptiveSampling = enabled; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPGraph::addData(double key, double value) -{ - mDataContainer->add(QCPGraphData(key, value)); -} - -/* inherits documentation from base class */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - // get line pixel points appropriate to line style: - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) - getLines(&lines, lineDataRange); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPGraphDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw fill of graph: - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - drawFill(painter, &lines); - - // draw line: - if (mLineStyle != lsNone) - { - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - painter->setBrush(Qt::NoBrush); - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lines); - else - drawLinePlot(painter, lines); // also step plots can be drawn as a line plot - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i)); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedLineData, an branches - out to the line style specific functions such as \ref dataToLines, \ref dataToStepLeftLines, etc. - according to the line style of the graph. - - \a lines will be filled with points in pixel coordinates, that can be drawn with the according - draw functions like \ref drawLinePlot and \ref drawImpulsePlot. The points returned in \a lines - aren't necessarily the original data points. For example, step line styles require additional - points to form the steps when drawn. If the line style of the graph is \ref lsNone, the \a - lines vector will be empty. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. - - \see getScatters -*/ -void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const -{ - if (!lines) return; - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - lines->clear(); - return; - } - - QVector lineData; - if (mLineStyle != lsNone) - getOptimizedLineData(&lineData, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) - std::reverse(lineData.begin(), lineData.end()); - - switch (mLineStyle) - { - case lsNone: lines->clear(); break; - case lsLine: *lines = dataToLines(lineData); break; - case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; - case lsStepRight: *lines = dataToStepRightLines(lineData); break; - case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; - case lsImpulse: *lines = dataToImpulseLines(lineData); break; - } -} - -/*! \internal - - This method retrieves an optimized set of data points via \ref getOptimizedScatterData and then - converts them to pixel coordinates. The resulting points are returned in \a scatters, and can be - passed to \ref drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. In this function, the specified range may exceed the total data bounds without harm: - a correspondingly trimmed data range will be used. This takes the burden off the user of this - function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref - getDataSegments. -*/ -void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const -{ - if (!scatters) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } - - QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) - { - scatters->clear(); - return; - } - - QVector data; - getOptimizedScatterData(&data, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) - std::reverse(data.begin(), data.end()); - - scatters->resize(data.size()); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } - } else - { - for (int i=0; icoordToPixel(data.at(i).key)); - (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - } -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsLine. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).value)); - result[i].setY(keyAxis->coordToPixel(data.at(i).key)); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key)); - result[i].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepLeft. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepLeftLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(lastValue); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(key); - result[i*2+1].setY(lastValue); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepRight. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepRightLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(value); - result[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(value); - result[i*2+1].setY(lastKey); - } - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel(data.at(i).value); - result[i*2+0].setX(lastKey); - result[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(lastKey); - result[i*2+1].setY(value); - } - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsStepCenter. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot -*/ -QVector QCPGraph::dataToStepCenterLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastValue); - result[0].setY(lastKey); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(lastValue); - result[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - } - result[data.size()*2-1].setX(lastValue); - result[data.size()*2-1].setY(lastKey); - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastKey); - result[0].setY(lastValue); - for (int i=1; icoordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(key); - result[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - } - result[data.size()*2-1].setX(lastKey); - result[data.size()*2-1].setY(lastValue); - } - return result; -} - -/*! \internal - - Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel - coordinate points which are suitable for drawing the line style \ref lsImpulse. - - The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a - getLines if the line style is set accordingly. - - \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot -*/ -QVector QCPGraph::dataToImpulseLines(const QVector &data) const -{ - QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(valueAxis->coordToPixel(0)); - result[i*2+0].setY(key); - result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); - result[i*2+1].setY(key); - } - } else // key axis is horizontal - { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(valueAxis->coordToPixel(0)); - result[i*2+1].setX(key); - result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); - } - } - return result; -} - -/*! \internal - - Draws the fill of the graph using the specified \a painter, with the currently set brush. - - Depending on whether a normal fill or a channel fill (\ref setChannelFillGraph) is needed, \ref - getFillPolygon or \ref getChannelFillPolygon are used to find the according fill polygons. - - In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), - this method first determines a list of non-NaN segments with \ref getNonNanSegments, on which to - operate. In the channel fill case, \ref getOverlappingSegments is used to consolidate the non-NaN - segments of the two involved graphs, before passing the overlapping pairs to \ref - getChannelFillPolygon. - - Pass the points of this graph's line as \a lines, in pixel coordinates. - - \see drawLinePlot, drawImpulsePlot, drawScatterPlot -*/ -void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const -{ - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); - if (!mChannelFillGraph) - { - // draw base fill under graph, fill goes all the way to the zero-value-line: - for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); - } else - { - // draw fill between this graph and mChannelFillGraph: - QVector otherLines; - mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); - if (!otherLines.isEmpty()) - { - QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); - QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); - for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); - } - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a scatters, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawLinePlot, drawImpulsePlot -*/ -void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const -{ - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws impulses from the provided data, i.e. it connects all line pairs in \a lines, given in - pixel coordinates. The \a lines necessary for impulses are generated by \ref dataToImpulseLines - from the regular graph data points. - - \see drawLinePlot, drawScatterPlot -*/ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - QPen oldPen = painter->pen(); - QPen newPen = painter->pen(); - newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(newPen); - painter->drawLines(lines); - painter->setPen(oldPen); - } -} - -/*! \internal - - Returns via \a lineData the data points that need to be visualized for this graph when plotting - graph lines, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getLines to retrieve the basic working set of data. - - \see getOptimizedScatterData -*/ -void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const -{ - if (!lineData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (begin == end) return; - - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - if (2*keyPixelSpan+2 < (double)std::numeric_limits::max()) - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - QCPGraphDataContainer::const_iterator it = begin; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary - { - if (it->value < minValue) - minValue = it->value; - else if (it->value > maxValue) - maxValue = it->value; - ++intervalDataCount; - } else // new pixel interval started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - lastIntervalEndKey = (it-1)->key; - minValue = it->value; - maxValue = it->value; - currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - lineData->resize(dataCount); - std::copy(begin, end, lineData->begin()); - } -} - -/*! \internal - - Returns via \a scatterData the data points that need to be visualized for this graph when - plotting scatter points, taking into consideration the currently visible axis ranges and, if \ref - setAdaptiveSampling is enabled, local point densities. The considered data can be restricted - further by \a begin and \a end, e.g. to only plot a certain segment of the data (see \ref - getDataSegments). - - This method is used by \ref getScatters to retrieve the basic working set of data. - - \see getOptimizedLineData -*/ -void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const -{ - if (!scatterData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int beginIndex = begin-mDataContainer->constBegin(); - int endIndex = end-mDataContainer->constBegin(); - while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++beginIndex; - ++begin; - } - if (begin == end) return; - int dataCount = end-begin; - int maxCount = std::numeric_limits::max(); - if (mAdaptiveSampling) - { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - maxCount = 2*keyPixelSpan+2; - } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - double valueMaxRange = valueAxis->range().upper; - double valueMinRange = valueAxis->range().lower; - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - double minValue = it->value; - double maxValue = it->value; - QCPGraphDataContainer::const_iterator minValueIt = it; - QCPGraphDataContainer::const_iterator maxValueIt = it; - QCPGraphDataContainer::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - // main loop over data points: - while (it != end) - { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary - { - if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) - { - minValue = it->value; - minValueIt = it; - } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) - { - maxValue = it->value; - maxValueIt = it; - } - ++intervalDataCount; - } else // new pixel started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else - intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - minValue = it->value; - maxValue = it->value; - currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int intervalItIndex = intervalIt-mDataContainer->constBegin(); - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); - ++c; - if (!doScatterSkip) - ++intervalIt; - else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: - { - intervalItIndex += scatterModulo; - if (intervalItIndex < itIndex) - intervalIt += scatterModulo; - else - { - intervalIt = it; - intervalItIndex = itIndex; - } - } - } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output - { - QCPGraphDataContainer::const_iterator it = begin; - int itIndex = beginIndex; - scatterData->reserve(dataCount); - while (it != end) - { - scatterData->append(*it); - // advance to next data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - This method takes into account that the drawing of data lines at the axis rect border always - requires the points just outside the visible axis range. So \a begin and \a end may actually - indicate a range that contains one additional data point to the left and right of the visible - axis range. -*/ -void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - if (rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - } else - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - // get visible data range: - begin = mDataContainer->findBegin(keyAxis->range().lower); - end = mDataContainer->findEnd(keyAxis->range().upper); - // limit lower/upperEnd to rangeRestriction: - mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything - } -} - -/*! \internal - - This method goes through the passed points in \a lineData and returns a list of the segments - which don't contain NaN data points. - - \a keyOrientation defines whether the \a x or \a y member of the passed QPointF is used to check - for NaN. If \a keyOrientation is \c Qt::Horizontal, the \a y member is checked, if it is \c - Qt::Vertical, the \a x member is checked. - - \see getOverlappingSegments, drawFill -*/ -QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const -{ - QVector result; - const int n = lineData->size(); - - QCPDataRange currentSegment(-1, -1); - int i = 0; - - if (keyOrientation == Qt::Horizontal) - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } else // keyOrientation == Qt::Vertical - { - while (i < n) - { - while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point - ++i; - if (i == n) - break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data - ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); - } - } - return result; -} - -/*! \internal - - This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and - \a otherSegments, and their associated point data \a thisData and \a otherData. - - It returns all pairs of segments (the first from \a thisSegments, the second from \a - otherSegments), which overlap in plot coordinates. - - This method is useful in the case of a channel fill between two graphs, when only those non-NaN - segments which actually overlap in their key coordinate shall be considered for drawing a channel - fill polygon. - - It is assumed that the passed segments in \a thisSegments are ordered ascending by index, and - that the segments don't overlap themselves. The same is assumed for the segments in \a - otherSegments. This is fulfilled when the segments are obtained via \ref getNonNanSegments. - - \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon -*/ -QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const -{ - QVector > result; - if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) - return result; - - int thisIndex = 0; - int otherIndex = 0; - const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; - while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) - { - if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++thisIndex; - continue; - } - if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow - { - ++otherIndex; - continue; - } - double thisLower, thisUpper, otherLower, otherUpper; - if (!verticalKey) - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); - } else - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); - } - - int bPrecedence; - if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) - result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); - - if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment - ++otherIndex; - else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment - ++thisIndex; - } - - return result; -} - -/*! \internal - - Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) - have overlap. - - The output parameter \a bPrecedence indicates whether the \a b segment reaches farther than the - \a a segment or not. If \a bPrecedence returns 1, segment \a b reaches the farthest to higher - coordinates (i.e. bUpper > aUpper). If it returns -1, segment \a a reaches the farthest. Only if - both segment's upper bounds are identical, 0 is returned as \a bPrecedence. - - It is assumed that the lower bounds always have smaller or equal values than the upper bounds. - - \see getOverlappingSegments -*/ -bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const -{ - bPrecedence = 0; - if (aLower > bUpper) - { - bPrecedence = -1; - return false; - } else if (bLower > aUpper) - { - bPrecedence = 1; - return false; - } else - { - if (aUpper > bUpper) - bPrecedence = -1; - else if (aUpper < bUpper) - bPrecedence = 1; - - return true; - } -} - -/*! \internal - - Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. - The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates - is in positive or negative infinity. So this case is handled separately by just closing the fill - polygon on the axis which lies in the direction towards the zero value. - - \a matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether - the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or - y value of the returned point, respectively. -*/ -QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF result; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->orientation() == Qt::Horizontal) - { - result.setX(matchingDataPoint.x()); - result.setY(valueAxis->coordToPixel(0)); - } else // keyAxis->orientation() == Qt::Vertical - { - result.setX(valueAxis->coordToPixel(0)); - result.setY(matchingDataPoint.y()); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value 0 so we just fill all the way - // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setX(keyAxis->axisRect()->right()); - else - result.setX(keyAxis->axisRect()->left()); - result.setY(matchingDataPoint.y()); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - result.setX(matchingDataPoint.x()); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setY(keyAxis->axisRect()->top()); - else - result.setY(keyAxis->axisRect()->bottom()); - } - } - return result; -} - -/*! \internal - - Returns the polygon needed for drawing normal fills between this graph and the key axis. - - Pass the graph's data points (in pixel coordinates) as \a lineData, and specify the \a segment - which shall be used for the fill. The collection of \a lineData points described by \a segment - must not contain NaN data points (see \ref getNonNanSegments). - - The returned fill polygon will be closed at the key axis (the zero-value line) for linear value - axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect - side (see \ref getFillBasePoint). - - For increased performance (due to implicit sharing), keep the returned QPolygonF const. - - \see drawFill, getNonNanSegments -*/ -const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const -{ - if (segment.size() < 2) - return QPolygonF(); - QPolygonF result(segment.size()+2); - - result[0] = getFillBasePoint(lineData->at(segment.begin())); - std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); - result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); - - return result; -} - -/*! \internal - - Returns the polygon needed for drawing (partial) channel fills between this graph and the graph - specified by \ref setChannelFillGraph. - - The data points of this graph are passed as pixel coordinates via \a thisData, the data of the - other graph as \a otherData. The returned polygon will be calculated for the specified data - segments \a thisSegment and \a otherSegment, pertaining to the respective \a thisData and \a - otherData, respectively. - - The passed \a thisSegment and \a otherSegment should correspond to the segment pairs returned by - \ref getOverlappingSegments, to make sure only segments that actually have key coordinate overlap - need to be processed here. - - For increased performance due to implicit sharing, keep the returned QPolygonF const. - - \see drawFill, getOverlappingSegments, getNonNanSegments -*/ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const -{ - if (!mChannelFillGraph) - return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (thisData->isEmpty()) return QPolygonF(); - QVector thisSegmentData(thisSegment.size()); - QVector otherSegmentData(otherSegment.size()); - std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); - std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); - // pointers to be able to swap them, depending which data range needs cropping: - QVector *staticData = &thisSegmentData; - QVector *croppedData = &otherSegmentData; - - // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) - { - // x is key - // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); - else - slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - - // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - const int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); - else - slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical - { - // y is key - // crop lower bound: - if (staticData->first().y() < croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); - else - slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - - // crop upper bound: - if (staticData->last().y() > croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); - else - slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); - } - - // return joined: - for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisSegmentData << otherSegmentData.at(i); - return QPolygonF(thisSegmentData); -} - -/*! \internal - - Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveX(const QVector *data, double x) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).x() < x) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is horizontal. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowX(const QVector *data, double x) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).x() > x) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in - \a data points are ordered ascending, as is ensured by \ref getLines/\ref getScatters if the key - axis is vertical. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveY(const QVector *data, double y) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).y() < y) - { - if (isize()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Calculates the minimum distance in pixels the graph's representation has from the given \a - pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that if - the graph has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the graph line is also taken into account. - - If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. -*/ -double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - // calculate minimum distances to graph data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); - QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); - for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - // line displayed, calculate distance to line segments: - QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); - QCPVector2D p(pixelPoint); - const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected - for (int i=0; i *data, double y) const -{ - for (int i=0; isize(); ++i) - { - if (data->at(i).y() > y) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} -/* end of 'src/plottables/plottable-graph.cpp' */ - - -/* including file 'src/plottables/plottable-curve.cpp', size 63527 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurveData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurveData - \brief Holds the data of one single data point for QCPCurve. - - The stored data is: - \li \a t: the free ordering parameter of this curve point, like in the mathematical vector (x(t), y(t)). (This is the \a sortKey) - \li \a key: coordinate on the key axis of this curve point (this is the \a mainKey) - \li \a value: coordinate on the value axis of this curve point (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPCurveDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPCurveData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPCurveDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPCurveData::sortKey() const - - Returns the \a t member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPCurveData QCPCurveData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey (assigned to the data point's \a t member). - All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPCurveData::sortKeyIsMainKey() - - Since the member \a key is the data point key coordinate and the member \a t is the data ordering - parameter, this method returns false. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPCurveData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPCurveData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a curve data point with t, key and value set to zero. -*/ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) -{ -} - -/*! - Constructs a curve data point with the specified \a t, \a key and \a value. -*/ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurve - \brief A plottable representing a parametric curve in a plot. - - \image html QCPCurve.png - - Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, - so their visual representation can have \a loops. This is realized by introducing a third - coordinate \a t, which defines the order of the points described by the other two coordinates \a - x and \a y. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the curve's data via the \ref data method, which returns a pointer to the - internal \ref QCPCurveDataContainer. - - Gaps in the curve can be created by adding data points with NaN as key and value - (qQNaN() or std::numeric_limits::quiet_NaN()) in between the two data points that shall be - separated. - - \section qcpcurve-appearance Changing the appearance - - The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). - - \section qcpcurve-usage Usage - - Like all data representing objects in QCustomPlot, the QCPCurve is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPCurve::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPCurveDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPCurve is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) -{ - // modify inherited properties from abstract plottable: - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); - setScatterSkip(0); -} - -QCPCurve::~QCPCurve() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPCurves may share the same data container safely. - Modifying the data in the container will then affect all curves that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the curve's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpcurve-datasharing-2 - - \see addData -*/ -void QCPCurve::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a t, \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a t in ascending order, you can - set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(t, keys, values, alreadySorted); -} - - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - \see addData -*/ -void QCPCurve::setData(const QVector &keys, const QVector &values) -{ - mDataContainer->clear(); - addData(keys, values); -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref - QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate - line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - If scatters are displayed (scatter style not \ref QCPScatterStyle::ssNone), \a skip number of - scatter points are skipped/not drawn after every drawn scatter point. - - This can be used to make the data appear sparser while for example still having a smooth line, - and to improve performance for very high density plots. - - If \a skip is set to 0 (default), all scatter points are drawn. - - \see setScatterStyle -*/ -void QCPCurve::setScatterSkip(int skip) -{ - mScatterSkip = qMax(0, skip); -} - -/*! - Sets how the single data points are connected in the plot or how they are represented visually - apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref - setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) -{ - mLineStyle = style; -} - -/*! \overload - - Adds the provided points in \a t, \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (t.size() != keys.size() || t.size() != values.size()) - qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); - const int n = qMin(qMin(t.size(), keys.size()), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = t[i]; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - The t parameter of each data point will be set to the integer index of the respective key/value - pair. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(const QVector &keys, const QVector &values) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - double tStart; - if (!mDataContainer->isEmpty()) - tStart = (mDataContainer->constEnd()-1)->t + 1.0; - else - tStart = 0; - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->t = tStart + i; - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a t, \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double t, double key, double value) -{ - mDataContainer->add(QCPCurveData(t, key, value)); -} - -/*! \overload - - Adds the provided data point as \a key and \a value to the current data. - - The t parameter is generated automatically by increments of 1 for each point, starting at the - highest t of previously existing data or 0, if the curve data is empty. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPCurve::addData(double key, double value) -{ - if (!mDataContainer->isEmpty()) - mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); - else - mDataContainer->add(QCPCurveData(0.0, key, value)); -} - -/* inherits documentation from base class */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - return mDataContainer->keyRange(foundRange, inSignDomain); -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - - // allocate line vector: - QVector lines, scatters; - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - - // fill with curve data: - QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width - if (isSelectedSegment && mSelectionDecorator) - finalCurvePen = mSelectionDecorator->pen(); - - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) - getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); - - // check data validity if flag set: - #ifdef QCUSTOMPLOT_CHECK_DATA - for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->t) || - QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); - } - #endif - - // draw curve fill: - applyFillAntialiasingHint(painter); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); - else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) - painter->drawPolygon(QPolygonF(lines)); - - // draw curve line: - if (mLineStyle != lsNone) - { - painter->setPen(finalCurvePen); - painter->setBrush(Qt::NoBrush); - drawCurveLine(painter, lines); - } - - // draw scatters: - QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) - { - getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); - drawScatterPlot(painter, scatters, finalScatterStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - Draws lines between the points in \a lines, given in pixel coordinates. - - \see drawScatterPlot, getCurveLines -*/ -void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const -{ - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); - } -} - -/*! \internal - - Draws scatter symbols at every point passed in \a points, given in pixel coordinates. The - scatters will be drawn with \a painter and have the appearance as specified in \a style. - - \see drawCurveLine, getCurveLines -*/ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const -{ - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i *lines, const QCPDataRange &dataRange, double penWidth) const -{ - if (!lines) return; - lines->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // add margins to rect to compensate for stroke width - const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety - const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); - const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); - const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); - const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); - QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); - if (itBegin == itEnd) - return; - QCPCurveDataContainer::const_iterator it = itBegin; - QCPCurveDataContainer::const_iterator prevIt = itEnd-1; - int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); - QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) - while (it != itEnd) - { - const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); - if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R - { - if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal - { - QPointF crossA, crossB; - if (prevRegion == 5) // we're coming from R, so add this point optimized - { - lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); - // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } else if (mayTraverse(prevRegion, currentRegion) && - getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) - { - // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: - QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; - getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); - if (it != itBegin) - { - *lines << beforeTraverseCornerPoints; - lines->append(crossA); - lines->append(crossB); - *lines << afterTraverseCornerPoints; - } else - { - lines->append(crossB); - *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA ; - } - } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) - { - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } - } else // segment does end in R, so we add previous point optimized and this point at original position - { - if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end - trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - else - lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); - lines->append(coordsToPixels(it->key, it->value)); - } - } else // region didn't change - { - if (currentRegion == 5) // still in R, keep adding original points - { - lines->append(coordsToPixels(it->key, it->value)); - } else // still outside R, no need to add anything - { - // see how this is not doing anything? That's the main optimization... - } - } - prevIt = it; - prevRegion = currentRegion; - ++it; - } - *lines << trailingPoints; -} - -/*! \internal - - Called by \ref draw to generate points in pixel coordinates which represent the scatters of the - curve. If a scatter skip is configured (\ref setScatterSkip), the returned points are accordingly - sparser. - - Scatters that aren't visible in the current axis rect are optimized away. - - \a scatters will be filled with points in pixel coordinates, that can be drawn with \ref - drawScatterPlot. - - \a dataRange specifies the beginning and ending data indices that will be taken into account for - conversion. - - \a scatterWidth specifies the scatter width that will be used to later draw the scatters at pixel - coordinates generated by this function. This is needed here to calculate an accordingly wider - margin around the axis rect when performing the data point reduction. - - \see draw, drawScatterPlot -*/ -void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const -{ - if (!scatters) return; - scatters->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); - if (begin == end) - return; - const int scatterModulo = mScatterSkip+1; - const bool doScatterSkip = mScatterSkip > 0; - int endIndex = end-mDataContainer->constBegin(); - - QCPRange keyRange = keyAxis->range(); - QCPRange valueRange = valueAxis->range(); - // extend range to include width of scatter symbols: - keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); - keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); - valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); - valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); - - QCPCurveDataContainer::const_iterator it = begin; - int itIndex = begin-mDataContainer->constBegin(); - while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter - { - ++itIndex; - ++it; - } - if (keyAxis->orientation() == Qt::Vertical) - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } else - { - while (it != end) - { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); - - // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) - ++it; - else - { - itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end - it += scatterModulo; - else - { - it = end; - itIndex = endIndex; - } - } - } - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - It returns the region of the given point (\a key, \a value) with respect to a rectangle defined - by \a keyMin, \a keyMax, \a valueMin, and \a valueMax. - - The regions are enumerated from top to bottom (\a valueMin to \a valueMax) and left to right (\a - keyMin to \a keyMax): - - - - - -
147
258
369
- - With the rectangle being region 5, and the outer regions extending infinitely outwards. In the - curve optimization algorithm, region 5 is considered to be the visible portion of the plot. -*/ -int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - if (key < keyMin) // region 123 - { - if (value > valueMax) - return 1; - else if (value < valueMin) - return 3; - else - return 2; - } else if (key > keyMax) // region 789 - { - if (value > valueMax) - return 7; - else if (value < valueMin) - return 9; - else - return 8; - } else // region 456 - { - if (value > valueMax) - return 4; - else if (value < valueMin) - return 6; - else - return 5; - } -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method is used in case the current segment passes from inside the visible rect (region 5, - see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by - the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). - - It returns the intersection point of the segment with the border of region 5. - - For this function it doesn't matter whether (\a key, \a value) is the point inside region 5 or - whether it's (\a otherKey, \a otherValue), i.e. whether the segment is coming from region 5 or - leaving it. It is important though that \a otherRegion correctly identifies the other region not - equal to 5. -*/ -QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double otherValuePx = mValueAxis->coordToPixel(otherValue); - const double valuePx = mValueAxis->coordToPixel(value); - const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); - const double keyPx = mKeyAxis->coordToPixel(key); - double intersectKeyPx = keyMinPx; // initial key just a fail-safe - double intersectValuePx = valueMinPx; // initial value just a fail-safe - switch (otherRegion) - { - case 1: // top and left edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 2: // left edge - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 3: // bottom and left edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 4: // top edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 5: - { - break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table - } - case 6: // bottom edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 7: // top and right edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 8: // right edge - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 9: // bottom and right edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - } - if (mKeyAxis->orientation() == Qt::Horizontal) - return QPointF(intersectKeyPx, intersectValuePx); - else - return QPointF(intersectValuePx, intersectKeyPx); -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - In situations where a single segment skips over multiple regions it might become necessary to add - extra points at the corners of region 5 (see \ref getRegion) such that the optimized segment - doesn't unintentionally cut through the visible area of the axis rect and create plot artifacts. - This method provides these points that must be added, assuming the original segment doesn't - start, end, or traverse region 5. (Corner points where region 5 is traversed are calculated by - \ref getTraverseCornerPoints.) - - For example, consider a segment which directly goes from region 4 to 2 but originally is far out - to the top left such that it doesn't cross region 5. Naively optimizing these points by - projecting them on the top and left borders of region 5 will create a segment that surely crosses - 5, creating a visual artifact in the plot. This method prevents this by providing extra points at - the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without - traversing 5. -*/ -QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const -{ - QVector result; - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMax); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } - case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - else - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - break; - } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 2: { result << coordsToPixels(keyMin, valueMin); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); break; } - case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - else - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - break; - } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 6: - { - switch (currentRegion) - { - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 4: { result << coordsToPixels(keyMax, valueMax); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); break; } - case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - else - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - break; - } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 6: { result << coordsToPixels(keyMax, valueMin); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - else - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - break; - } - } - break; - } - } - return result; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method returns whether a segment going from \a prevRegion to \a currentRegion (see \ref - getRegion) may traverse the visible region 5. This function assumes that neither \a prevRegion - nor \a currentRegion is 5 itself. - - If this method returns false, the segment for sure doesn't pass region 5. If it returns true, the - segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref - getTraverse). -*/ -bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 4: - case 7: - case 2: - case 3: return false; - default: return true; - } - } - case 2: - { - switch (currentRegion) - { - case 1: - case 3: return false; - default: return true; - } - } - case 3: - { - switch (currentRegion) - { - case 1: - case 2: - case 6: - case 9: return false; - default: return true; - } - } - case 4: - { - switch (currentRegion) - { - case 1: - case 7: return false; - default: return true; - } - } - case 5: return false; // should never occur - case 6: - { - switch (currentRegion) - { - case 3: - case 9: return false; - default: return true; - } - } - case 7: - { - switch (currentRegion) - { - case 1: - case 4: - case 8: - case 9: return false; - default: return true; - } - } - case 8: - { - switch (currentRegion) - { - case 7: - case 9: return false; - default: return true; - } - } - case 9: - { - switch (currentRegion) - { - case 3: - case 6: - case 8: - case 7: return false; - default: return true; - } - } - default: return true; - } -} - - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref mayTraverse test has returned true, so there is a chance the - segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible - region 5. - - The return value of this method indicates whether the segment actually traverses region 5 or not. - - If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and - exit points of region 5. They will become the optimized points for that segment. -*/ -bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const -{ - // The intersection point interpolation here is done in pixel coordinates, so we don't need to - // differentiate between different axis scale types. Note that the nomenclature - // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be - // different in pixel coordinates (horz/vert key axes, reversed ranges) - - QList intersections; - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double keyPx = mKeyAxis->coordToPixel(key); - const double valuePx = mValueAxis->coordToPixel(value); - const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); - const double prevValuePx = mValueAxis->coordToPixel(prevValue); - if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); - } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis - { - // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); - } else // line is skewed - { - double gamma; - double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); - // check top of rect: - gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); - // check bottom of rect: - gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); - const double valuePerKeyPx = 1.0/keyPerValuePx; - // check left of rect: - gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); - // check right of rect: - gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); - } - - // handle cases where found points isn't exactly 2: - if (intersections.size() > 2) - { - // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: - double distSqrMax = 0; - QPointF pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = intersections.at(i); - pv2 = intersections.at(k); - distSqrMax = distSqr; - } - } - } - intersections = QList() << pv1 << pv2; - } else if (intersections.size() != 2) - { - // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment - return false; - } - - // possibly re-sort points so optimized point segment has same direction as original segment: - double xDelta = keyPx-prevKeyPx; - double yDelta = valuePx-prevValuePx; - if (mKeyAxis->orientation() != Qt::Horizontal) - qSwap(xDelta, yDelta); - if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction - intersections.move(0, 1); - crossA = intersections.at(0); - crossB = intersections.at(1); - return true; -} - -/*! \internal - - This function is part of the curve optimization algorithm of \ref getCurveLines. - - This method assumes that the \ref getTraverse test has returned true, so the segment definitely - traverses the visible region 5 when going from \a prevRegion to \a currentRegion. - - In certain situations it is not sufficient to merely generate the entry and exit points of the - segment into/out of region 5, as \ref getTraverse provides. It may happen that a single segment, in - addition to traversing region 5, skips another region outside of region 5, which makes it - necessary to add an optimized corner point there (very similar to the job \ref - getOptimizedCornerPoints does for segments that are completely in outside regions and don't - traverse 5). - - As an example, consider a segment going from region 1 to region 6, traversing the lower left - corner of region 5. In this configuration, the segment additionally crosses the border between - region 1 and 2 before entering region 5. This makes it necessary to add an additional point in - the top left corner, before adding the optimized traverse points. So in this case, the output - parameter \a beforeTraverse will contain the top left corner point, and \a afterTraverse will be - empty. - - In some cases, such as when going from region 1 to 9, it may even be necessary to add additional - corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse - return the respective corner points. -*/ -void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const -{ - switch (prevRegion) - { - case 1: - { - switch (currentRegion) - { - case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - } - break; - } - case 2: - { - switch (currentRegion) - { - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 3: - { - switch (currentRegion) - { - case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 4: - { - switch (currentRegion) - { - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - case 5: { break; } // shouldn't happen because this method only handles full traverses - case 6: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - } - break; - } - } -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in - \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. Note that - if the curve has a line representation, the returned distance may be smaller than the distance to - the \a closestData point, since the distance to the curve line is also taken into account. - - If either the curve has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns - -1.0. -*/ -double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) - return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return -1.0; - - if (mDataContainer->size() == 1) - { - QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); - closestData = mDataContainer->constBegin(); - return QCPVector2D(dataPoint-pixelPoint).length(); - } - - // calculate minimum distances to curve data points and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - // iterate over found data points and then choose the one with the shortest distance to pos: - QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); - QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestData = it; - } - } - - // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) - { - QVector lines; - getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width - for (int i=0; i QCPBarsGroup::bars() const - - Returns all bars currently in this group. - - \see bars(int index) -*/ - -/*! \fn int QCPBarsGroup::size() const - - Returns the number of QCPBars plottables that are part of this group. - -*/ - -/*! \fn bool QCPBarsGroup::isEmpty() const - - Returns whether this bars group is empty. - - \see size -*/ - -/*! \fn bool QCPBarsGroup::contains(QCPBars *bars) - - Returns whether the specified \a bars plottable is part of this group. - -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new bars group for the specified QCustomPlot instance. -*/ -QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot), - mSpacingType(stAbsolute), - mSpacing(4) -{ -} - -QCPBarsGroup::~QCPBarsGroup() -{ - clear(); -} - -/*! - Sets how the spacing between adjacent bars is interpreted. See \ref SpacingType. - - The actual spacing can then be specified with \ref setSpacing. - - \see setSpacing -*/ -void QCPBarsGroup::setSpacingType(SpacingType spacingType) -{ - mSpacingType = spacingType; -} - -/*! - Sets the spacing between adjacent bars. What the number passed as \a spacing actually means, is - defined by the current \ref SpacingType, which can be set with \ref setSpacingType. - - \see setSpacingType -*/ -void QCPBarsGroup::setSpacing(double spacing) -{ - mSpacing = spacing; -} - -/*! - Returns the QCPBars instance with the specified \a index in this group. If no such QCPBars - exists, returns 0. - - \see bars(), size -*/ -QCPBars *QCPBarsGroup::bars(int index) const -{ - if (index >= 0 && index < mBars.size()) - { - return mBars.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Removes all QCPBars plottables from this group. - - \see isEmpty -*/ -void QCPBarsGroup::clear() -{ - Q_FOREACH (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay - bars->setBarsGroup(0); // removes itself via removeBars -} - -/*! - Adds the specified \a bars plottable to this group. Alternatively, you can also use \ref - QCPBars::setBarsGroup on the \a bars instance. - - \see insert, remove -*/ -void QCPBarsGroup::append(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - else - qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); -} - -/*! - Inserts the specified \a bars plottable into this group at the specified index position \a i. - This gives you full control over the ordering of the bars. - - \a bars may already be part of this group. In that case, \a bars is just moved to the new index - position. - - \see append, remove -*/ -void QCPBarsGroup::insert(int i, QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - // first append to bars list normally: - if (!mBars.contains(bars)) - bars->setBarsGroup(this); - // then move to according position: - mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); -} - -/*! - Removes the specified \a bars plottable from this group. - - \see contains, clear -*/ -void QCPBarsGroup::remove(QCPBars *bars) -{ - if (!bars) - { - qDebug() << Q_FUNC_INFO << "bars is 0"; - return; - } - - if (mBars.contains(bars)) - bars->setBarsGroup(0); - else - qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); -} - -/*! \internal - - Adds the specified \a bars to the internal mBars list of bars. This method does not change the - barsGroup property on \a bars. - - \see unregisterBars -*/ -void QCPBarsGroup::registerBars(QCPBars *bars) -{ - if (!mBars.contains(bars)) - mBars.append(bars); -} - -/*! \internal - - Removes the specified \a bars from the internal mBars list of bars. This method does not change - the barsGroup property on \a bars. - - \see registerBars -*/ -void QCPBarsGroup::unregisterBars(QCPBars *bars) -{ - mBars.removeOne(bars); -} - -/*! \internal - - Returns the pixel offset in the key dimension the specified \a bars plottable should have at the - given key coordinate \a keyCoord. The offset is relative to the pixel position of the key - coordinate \a keyCoord. -*/ -double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) -{ - // find list of all base bars in case some mBars are stacked: - QList baseBars; - Q_FOREACH (const QCPBars *b, mBars) - { - while (b->barBelow()) - b = b->barBelow(); - if (!baseBars.contains(b)) - baseBars.append(b); - } - // find base bar this "bars" is stacked on: - const QCPBars *thisBase = bars; - while (thisBase->barBelow()) - thisBase = thisBase->barBelow(); - - // determine key pixel offset of this base bars considering all other base bars in this barsgroup: - double result = 0; - int index = baseBars.indexOf(thisBase); - if (index >= 0) - { - if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) - { - return result; - } else - { - double lowerPixelWidth, upperPixelWidth; - int startIndex; - int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative - if (baseBars.size() % 2 == 0) // even number of bars - { - startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); - result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing - } else // uneven number of bars - { - startIndex = (baseBars.size()-1)/2+dir; - baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar - result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing - } - for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars - { - baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth); - result += getPixelSpacing(baseBars.at(i), keyCoord); - } - // finally half of our bars width: - baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; - // correct sign of result depending on orientation and direction of key axis: - result *= dir*thisBase->keyAxis()->pixelOrientation(); - } - } - return result; -} - -/*! \internal - - Returns the spacing in pixels which is between this \a bars and the following one, both at the - key coordinate \a keyCoord. - - \note Typically the returned value doesn't depend on \a bars or \a keyCoord. \a bars is only - needed to get access to the key axis transformation and axis rect for the modes \ref - stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in - \ref stPlotCoords on a logarithmic axis. -*/ -double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) -{ - switch (mSpacingType) - { - case stAbsolute: - { - return mSpacing; - } - case stAxisRectRatio: - { - if (bars->keyAxis()->orientation() == Qt::Horizontal) - return bars->keyAxis()->axisRect()->width()*mSpacing; - else - return bars->keyAxis()->axisRect()->height()*mSpacing; - } - case stPlotCoords: - { - double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); - return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); - } - } - return 0; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBarsData - \brief Holds the data of one single data point (one bar) for QCPBars. - - The stored data is: - \li \a key: coordinate on the key axis of this bar (this is the \a mainKey and the \a sortKey) - \li \a value: height coordinate on the value axis of this bar (this is the \a mainValue) - - The container for storing multiple data points is \ref QCPBarsDataContainer. It is a typedef for - \ref QCPDataContainer with \ref QCPBarsData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPBarsDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPBarsData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPBarsData QCPBarsData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPBarsData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPBarsData::mainValue() const - - Returns the \a value member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPBarsData::valueRange() const - - Returns a QCPRange with both lower and upper boundary set to \a value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a bar data point with key and value set to zero. -*/ -QCPBarsData::QCPBarsData() : - key(0), - value(0) -{ -} - -/*! - Constructs a bar data point with the specified \a key and \a value. -*/ -QCPBarsData::QCPBarsData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBars - \brief A plottable representing a bar chart in a plot. - - \image html QCPBars.png - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section qcpbars-appearance Changing the appearance - - The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). - The width of the individual bars can be controlled with \ref setWidthType and \ref setWidth. - - Bar charts are stackable. This means, two QCPBars plottables can be placed on top of each other - (see \ref QCPBars::moveAbove). So when two bars are at the same key position, they will appear - stacked. - - If you would like to group multiple QCPBars plottables together so they appear side by side as - shown below, use QCPBarsGroup. - - \image html QCPBarsGroup.png - - \section qcpbars-usage Usage - - Like all data representing objects in QCustomPlot, the QCPBars is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-creation-2 -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPBarsDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods. -*/ - -/*! \fn QCPBars *QCPBars::barBelow() const - Returns the bars plottable that is directly below this bars plottable. - If there is no such plottable, returns 0. - - \see barAbove, moveBelow, moveAbove -*/ - -/*! \fn QCPBars *QCPBars::barAbove() const - Returns the bars plottable that is directly above this bars plottable. - If there is no such plottable, returns 0. - - \see barBelow, moveBelow, moveAbove -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPBars is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.75), - mWidthType(wtPlotCoords), - mBarsGroup(0), - mBaseValue(0), - mStackingGap(0) -{ - // modify inherited properties from abstract plottable: - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPBars::~QCPBars() -{ - setBarsGroup(0); - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPBars may share the same data container safely. - Modifying the data in the container will then affect all bars that share the container. Sharing - can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the bar's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpbars-datasharing-2 - - \see addData -*/ -void QCPBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys and \a values. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, values, alreadySorted); -} - -/*! - Sets the width of the bars. - - How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), - depends on the currently set width type, see \ref setWidthType and \ref WidthType. -*/ -void QCPBars::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the bars is defined. See the documentation of \ref WidthType for an - explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPBars::setWidthType(QCPBars::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets to which QCPBarsGroup this QCPBars instance belongs to. Alternatively, you can also use \ref - QCPBarsGroup::append. - - To remove this QCPBars from any group, set \a barsGroup to 0. -*/ -void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) -{ - // deregister at old group: - if (mBarsGroup) - mBarsGroup->unregisterBars(this); - mBarsGroup = barsGroup; - // register at new group: - if (mBarsGroup) - mBarsGroup->registerBars(this); -} - -/*! - Sets the base value of this bars plottable. - - The base value defines where on the value coordinate the bars start. How far the bars extend from - the base value is given by their individual value data. For example, if the base value is set to - 1, a bar with data value 2 will have its lowest point at value coordinate 1 and highest point at - 3. - - For stacked bars, only the base value of the bottom-most QCPBars has meaning. - - The default base value is 0. -*/ -void QCPBars::setBaseValue(double baseValue) -{ - mBaseValue = baseValue; -} - -/*! - If this bars plottable is stacked on top of another bars plottable (\ref moveAbove), this method - allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by - the bars below it. -*/ -void QCPBars::setStackingGap(double pixels) -{ - mStackingGap = pixels; -} - -/*! \overload - - Adds the provided points in \a keys and \a values to the current data. The provided vectors - should have equal length. Else, the number of added points will be the size of the smallest - vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) -{ - if (keys.size() != values.size()) - qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->value = values[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - Adds the provided data point as \a key and \a value to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPBars::addData(double key, double value) -{ - mDataContainer->add(QCPBarsData(key, value)); -} - -/*! - Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear - below the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barAbove, barBelow -*/ -void QCPBars::moveBelow(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar below it: - if (bars) - { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); - } -} - -/*! - Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear - above the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object above itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barBelow, barAbove -*/ -void QCPBars::moveAbove(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar above it: - if (bars) - { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getBarRect(it->key, it->value))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getBarRect(it->key, it->value).contains(pos)) - { - if (details) - { - int pointIndex = it-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return mParentPlot->selectionTolerance()*0.99; - } - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in - absolute pixels), using this method to adapt the key axis range to fit the bars into the - currently visible axis range will not work perfectly. Because in the moment the axis range is - changed to the new range, the fixed pixel widths/spacings will represent different coordinate - spans than before, which in turn would require a different key range to perfectly fit, and so on. - The only solution would be to iteratively approach the perfect fitting axis range, but the - mismatch isn't large enough in most applications, to warrant this here. If a user does need a - better fit, he should call the corresponding axis rescale multiple times in a row. - */ - QCPRange range; - range = mDataContainer->keyRange(foundRange, inSignDomain); - - // determine exact range of bars by including bar width and barsgroup offset: - if (foundRange && mKeyAxis) - { - double lowerPixelWidth, upperPixelWidth, keyPixel; - // lower range bound: - getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); - const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) - range.lower = lowerCorrected; - // upper range bound: - getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); - const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) - range.upper = upperCorrected; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - // Note: can't simply use mDataContainer->valueRange here because we need to - // take into account bar base value and possible stacking of multiple bars - QCPRange range; - range.lower = mBaseValue; - range.upper = mBaseValue; - bool haveLower = true; // set to true, because baseValue should always be visible in bar charts - bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts - QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (inKeyRange != QCPRange()) - { - itBegin = mDataContainer->findBegin(inKeyRange.lower); - itEnd = mDataContainer->findEnd(inKeyRange.upper); - } - for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - - foundRange = true; // return true because bar charts always have the 0-line visible - return range; -} - -/* inherits documentation from base class */ -QPointF QCPBars::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); - const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyPixel, valuePixel); - else - return QPointF(valuePixel, keyPixel); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mDataContainer->isEmpty()) return; - - QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPBarsDataContainer::const_iterator begin = visibleBegin; - QCPBarsDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -#endif - // draw bar: - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyBrush(painter); - mSelectionDecorator->applyPen(painter); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - } - applyDefaultAntialiasingHint(painter); - painter->drawPolygon(getBarRect(it->key, it->value)); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - if (mDataContainer->isEmpty()) - { - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - - // get visible data range as QMap iterators - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); - double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); - double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); - bool isVisible = false; - // walk left from begin to find lower bar that actually is completely outside visible pixel range: - QCPBarsDataContainer::const_iterator it = begin; - while (it != mDataContainer->constBegin()) - { - --it; - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); - if (isVisible) - begin = it; - else - break; - } - // walk right from ubound to find upper bar that actually is completely outside visible pixel range: - it = end; - while (it != mDataContainer->constEnd()) - { - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); - if (isVisible) - end = it+1; - else - break; - ++it; - } -} - -/*! \internal - - Returns the rect in pixel coordinates of a single bar with the specified \a key and \a value. The - rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref - setBaseValue), and to have non-overlapping border lines with the bars stacked below. -*/ -QRectF QCPBars::getBarRect(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double lowerPixelWidth, upperPixelWidth; - getPixelWidth(key, lowerPixelWidth, upperPixelWidth); - double base = getStackedBaseValue(key, value >= 0); - double basePixel = valueAxis->coordToPixel(base); - double valuePixel = valueAxis->coordToPixel(base+value); - double keyPixel = keyAxis->coordToPixel(key); - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, key); - double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); - bottomOffset += mBarBelow ? mStackingGap : 0; - bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); - if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) - bottomOffset = valuePixel-basePixel; - if (keyAxis->orientation() == Qt::Horizontal) - { - return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); - } else - { - return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). - - The output parameters \a lower and \a upper return the number of pixels the bar extends to lower - and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a - lower is negative and \a upper positive). -*/ -void QCPBars::getPixelWidth(double key, double &lower, double &upper) const -{ - lower = 0; - upper = 0; - switch (mWidthType) - { - case wtAbsolute: - { - upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - { - double keyPixel = mKeyAxis.data()->coordToPixel(key); - upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; - // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by - // coordinate transform which includes range direction - } else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } -} - -/*! \internal - - This function is called to find at which value to start drawing the base of a bar at \a key, when - it is stacked on top of another QCPBars (e.g. with \ref moveAbove). - - positive and negative bars are separated per stack (positive are stacked above baseValue upwards, - negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the - bar for which we need the base value is negative, set \a positive to false. -*/ -double QCPBars::getStackedBaseValue(double key, bool positive) const -{ - if (mBarBelow) - { - double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack - // find bars of mBarBelow that are approximately at key and find largest one: - double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point - if (key == 0) - epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); - QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); - QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); - while (it != itEnd) - { - if (it->key > key-epsilon && it->key < key+epsilon) - { - if ((positive && it->value > max) || - (!positive && it->value < max)) - max = it->value; - } - ++it; - } - // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getStackedBaseValue(key, positive); - } else - return mBaseValue; -} - -/*! \internal - - Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. The bar(s) - currently above lower and below upper will become disconnected to lower/upper. - - If lower is zero, upper will be disconnected at the bottom. - If upper is zero, lower will be disconnected at the top. -*/ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) -{ - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom - { - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - lower->mBarAbove = 0; - } else // connect lower and upper - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - lower->mBarAbove = upper; - upper->mBarBelow = lower; - } -} -/* end of 'src/plottables/plottable-bars.cpp' */ - - -/* including file 'src/plottables/plottable-statisticalbox.cpp', size 28622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBoxData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBoxData - \brief Holds the data of one single data point for QCPStatisticalBox. - - The stored data is: - - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - - \li \a minimum: the position of the lower whisker, typically the minimum measurement of the - sample that's not considered an outlier. - - \li \a lowerQuartile: the lower end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a median: the value of the median mark inside the quartile box. The median separates the - sample data in half (50% of the sample data is below/above the median). (This is the \a mainValue) - - \li \a upperQuartile: the upper end of the box. The lower and the upper quartiles are the two - statistical quartiles around the median of the sample, they should contain 50% of the sample - data. - - \li \a maximum: the position of the upper whisker, typically the maximum measurement of the - sample that's not considered an outlier. - - \li \a outliers: a QVector of outlier values that will be drawn as scatter points at the \a key - coordinate of this data point (see \ref QCPStatisticalBox::setOutlierStyle) - - The container for storing multiple data points is \ref QCPStatisticalBoxDataContainer. It is a - typedef for \ref QCPDataContainer with \ref QCPStatisticalBoxData as the DataType template - parameter. See the documentation there for an explanation regarding the data type's generic - methods. - - \see QCPStatisticalBoxDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPStatisticalBoxData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPStatisticalBoxData QCPStatisticalBoxData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPStatisticalBoxData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPStatisticalBoxData::mainValue() const - - Returns the \a median member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPStatisticalBoxData::valueRange() const - - Returns a QCPRange spanning from the \a minimum to the \a maximum member of this statistical box - data point, possibly further expanded by outliers. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData() : - key(0), - minimum(0), - lowerQuartile(0), - median(0), - upperQuartile(0), - maximum(0) -{ -} - -/*! - Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a - upperQuartile, \a maximum and optionally a number of \a outliers. -*/ -QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : - key(key), - minimum(minimum), - lowerQuartile(lowerQuartile), - median(median), - upperQuartile(upperQuartile), - maximum(maximum), - outliers(outliers) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBox -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBox - \brief A plottable representing a single statistical box in a plot. - - \image html QCPStatisticalBox.png - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the data via the \ref data method, which returns a pointer to the internal - \ref QCPStatisticalBoxDataContainer. - - Additionally each data point can itself have a list of outliers, drawn as scatter points at the - key coordinate of the respective statistical box data point. They can either be set by using the - respective \ref addData(double,double,double,double,double,double,const QVector&) - "addData" method or accessing the individual data points through \ref data, and setting the - QVector outliers of the data points directly. - - \section qcpstatisticalbox-appearance Changing the appearance - - The appearance of each data point box, ranging from the lower to the upper quartile, is - controlled via \ref setPen and \ref setBrush. You may change the width of the boxes with \ref - setWidth in plot coordinates. - - Each data point's visual representation also consists of two whiskers. Whiskers are the lines - which reach from the upper quartile to the maximum, and from the lower quartile to the minimum. - The appearance of the whiskers can be modified with: \ref setWhiskerPen, \ref setWhiskerBarPen, - \ref setWhiskerWidth. The whisker width is the width of the bar perpendicular to the whisker at - the top (for maximum) and bottom (for minimum). If the whisker pen is changed, make sure to set - the \c capStyle to \c Qt::FlatCap. Otherwise the backbone line might exceed the whisker bars by a - few pixels due to the pen cap being not perfectly flat. - - The median indicator line inside the box has its own pen, \ref setMedianPen. - - The outlier data points are drawn as normal scatter points. Their look can be controlled with - \ref setOutlierStyle - - \section qcpstatisticalbox-usage Usage - - Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes - ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. - The newly created plottable can be modified, e.g.: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-creation-2 -*/ - -/* start documentation of inline functions */ - -/*! \fn QSharedPointer QCPStatisticalBox::data() const - - Returns a shared pointer to the internal data storage of type \ref - QCPStatisticalBoxDataContainer. You may use it to directly manipulate the data, which may be more - convenient and faster than using the regular \ref setData or \ref addData methods. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its - value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and - not have the same orientation. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPStatisticalBox is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not - delete it manually but use QCustomPlot::removePlottable() instead. -*/ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.5), - mWhiskerWidth(0.2), - mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), - mWhiskerBarPen(Qt::black), - mWhiskerAntialiased(false), - mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), - mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) -{ - setPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPStatisticalBoxes may share the same data container - safely. Modifying the data in the container will then affect all statistical boxes that share the - container. Sharing can be achieved by simply exchanging the data containers wrapped in shared - pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the statistical box data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpstatisticalbox-datasharing-2 - - \see addData -*/ -void QCPStatisticalBox::setData(QSharedPointer data) -{ - mDataContainer = data; -} -/*! \overload - - Replaces the current data with the provided points in \a keys, \a minimum, \a lowerQuartile, \a - median, \a upperQuartile and \a maximum. The provided vectors should have equal length. Else, the - number of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData -*/ -void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); -} - -/*! - Sets the width of the boxes in key coordinates. - - \see setWhiskerWidth -*/ -void QCPStatisticalBox::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the width of the whiskers in key coordinates. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWidth -*/ -void QCPStatisticalBox::setWhiskerWidth(double width) -{ - mWhiskerWidth = width; -} - -/*! - Sets the pen used for drawing the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - Make sure to set the \c capStyle of the passed \a pen to \c Qt::FlatCap. Otherwise the backbone - line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat. - - \see setWhiskerBarPen -*/ -void QCPStatisticalBox::setWhiskerPen(const QPen &pen) -{ - mWhiskerPen = pen; -} - -/*! - Sets the pen used for drawing the whisker bars. Those are the lines parallel to the key axis at - each end of the whisker backbone. - - Whiskers are the lines which reach from the upper quartile to the maximum, and from the lower - quartile to the minimum. - - \see setWhiskerPen -*/ -void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) -{ - mWhiskerBarPen = pen; -} - -/*! - Sets whether the statistical boxes whiskers are drawn with antialiasing or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPStatisticalBox::setWhiskerAntialiased(bool enabled) -{ - mWhiskerAntialiased = enabled; -} - -/*! - Sets the pen used for drawing the median indicator line inside the statistical boxes. -*/ -void QCPStatisticalBox::setMedianPen(const QPen &pen) -{ - mMedianPen = pen; -} - -/*! - Sets the appearance of the outlier data points. - - Outliers can be specified with the method - \ref addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -*/ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) -{ - mOutlierStyle = style; -} - -/*! \overload - - Adds the provided points in \a keys, \a minimum, \a lowerQuartile, \a median, \a upperQuartile and - \a maximum to the current data. The provided vectors should have equal length. Else, the number - of added points will be the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) -{ - if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || - median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" - << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); - const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->minimum = minimum[i]; - it->lowerQuartile = lowerQuartile[i]; - it->median = median[i]; - it->upperQuartile = upperQuartile[i]; - it->maximum = maximum[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile - and \a maximum to the current data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. -*/ -void QCPStatisticalBox::addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) -{ - mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(getQuartileBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - double minDistSqr = std::numeric_limits::max(); - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (getQuartileBox(it).contains(pos)) // quartile box - { - double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } else // whiskers - { - const QVector whiskerBackbones(getWhiskerBackboneLines(it)); - for (int i=0; iconstBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return qSqrt(minDistSqr); - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) -{ - if (mDataContainer->isEmpty()) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; - QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) - { - // check data validity if flag set: -# ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->minimum) || - QCP::isInvalidData(it->lowerQuartile, it->median) || - QCP::isInvalidData(it->upperQuartile, it->maximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; ioutliers.size(); ++i) - if (QCP::isInvalidData(it->outliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -# endif - - if (isSelectedSegment && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - QCPScatterStyle finalOutlierStyle = mOutlierStyle; - if (isSelectedSegment && mSelectionDecorator) - finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); - drawStatisticalBox(painter, it, finalOutlierStyle); - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! - Draws the graphical representation of a single statistical box with the data given by the - iterator \a it with the provided \a painter. - - If the statistical box has a set of outlier data points, they are drawn with \a outlierStyle. - - \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const -{ - // draw quartile box: - applyDefaultAntialiasingHint(painter); - const QRectF quartileBox = getQuartileBox(it); - painter->drawRect(quartileBox); - // draw median line with cliprect set to quartile box: - painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - painter->setPen(mMedianPen); - painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); - painter->restore(); - // draw whisker lines: - applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); - painter->setPen(mWhiskerPen); - painter->drawLines(getWhiskerBackboneLines(it)); - painter->setPen(mWhiskerBarPen); - painter->drawLines(getWhiskerBarLines(it)); - // draw outliers: - applyScattersAntialiasingHint(painter); - outlierStyle.applyTo(painter, mPen); - for (int i=0; ioutliers.size(); ++i) - outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); -} - -/*! \internal - - called by \ref draw to determine which data (key) range is visible at the current key axis range - setting, so only that needs to be processed. It also takes into account the bar width. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a end returns an iterator one higher than the highest visible data point. Same as before, \a end - may also lie just outside of the visible range. - - if the plottable contains no data, both \a begin and \a end point to constEnd. -*/ -void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points -} - -/*! \internal - - Returns the box in plot coordinates (keys in x, values in y of the returned rect) that covers the - value range from the lower to the upper quartile, of the data given by \a it. - - \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines -*/ -QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QRectF result; - result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); - result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); - return result; -} - -/*! \internal - - Returns the whisker backbones (keys in x, values in y of the returned lines) that cover the value - range from the minimum to the lower quartile, and from the upper quartile to the maximum of the - data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines -*/ -QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone - result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone - return result; -} - -/*! \internal - - Returns the whisker bars (keys in x, values in y of the returned lines) that are placed at the - end of the whisker backbones, at the minimum and maximum of the data given by \a it. - - \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines -*/ -QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const -{ - QVector result(2); - result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar - result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar - return result; -} -/* end of 'src/plottables/plottable-statisticalbox.cpp' */ - - -/* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMapData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMapData - \brief Holds the two-dimensional data of a QCPColorMap plottable. - - This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref - QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a - color, depending on the value. - - The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). - Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref - setKeyRange, \ref setValueRange). - - The data cells can be accessed in two ways: They can be directly addressed by an integer index - with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot - coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are - provided by the functions \ref coordToCell and \ref cellToCoord. - - A \ref QCPColorMapData also holds an on-demand two-dimensional array of alpha values which (if - allocated) has the same size as the data map. It can be accessed via \ref setAlpha, \ref - fillAlpha and \ref clearAlpha. The memory for the alpha map is only allocated if needed, i.e. on - the first call of \ref setAlpha. \ref clearAlpha restores full opacity and frees the alpha map. - - This class also buffers the minimum and maximum values that are in the data set, to provide - QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value - that is greater than the current maximum increases this maximum to the new value. However, - setting the cell that currently holds the maximum value to a smaller value doesn't decrease the - maximum again, because finding the true new maximum would require going through the entire data - array, which might be time consuming. The same holds for the data minimum. This functionality is - given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the - true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience - parameter \a recalculateDataBounds which may be set to true to automatically call \ref - recalculateDataBounds internally. -*/ - -/* start of documentation of inline functions */ - -/*! \fn bool QCPColorMapData::isEmpty() const - - Returns whether this instance carries no data. This is equivalent to having a size where at least - one of the dimensions is 0 (see \ref setSize). -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction - and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap - at the coordinates \a keyRange and \a valueRange. - - \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange -*/ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - setSize(keySize, valueSize); - fill(0); -} - -QCPColorMapData::~QCPColorMapData() -{ - if (mData) - delete[] mData; - if (mAlpha) - delete[] mAlpha; -} - -/*! - Constructs a new QCPColorMapData instance copying the data and range of \a other. -*/ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) -{ - *this = other; -} - -/*! - Overwrites this color map data instance with the data stored in \a other. The alpha map state is - transferred, too. -*/ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) -{ - if (&other != this) - { - const int keySize = other.keySize(); - const int valueSize = other.valueSize(); - if (!other.mAlpha && mAlpha) - clearAlpha(); - setSize(keySize, valueSize); - if (other.mAlpha && !mAlpha) - createAlpha(false); - setRange(other.keyRange(), other.valueRange()); - if (!isEmpty()) - { - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - if (mAlpha) - memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); - } - mDataBounds = other.mDataBounds; - mDataModified = true; - } - return *this; -} - -/* undocumented getter */ -double QCPColorMapData::data(double key, double value) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; - else - return 0; -} - -/* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; - else - return 0; -} - -/*! - Returns the alpha map value of the cell with the indices \a keyIndex and \a valueIndex. - - If this color map data doesn't have an alpha map (because \ref setAlpha was never called after - creation or after a call to \ref clearAlpha), returns 255, which corresponds to full opacity. - - \see setAlpha -*/ -unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) -{ - if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mAlpha[valueIndex*mKeySize + keyIndex]; - else - return 255; -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in - the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref - isEmpty returns true. - - \see setRange, setKeySize, setValueSize -*/ -void QCPColorMapData::setSize(int keySize, int valueSize) -{ - if (keySize != mKeySize || valueSize != mValueSize) - { - mKeySize = keySize; - mValueSize = valueSize; - if (mData) - delete[] mData; - mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) - { -#ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message -#endif - mData = new double[mKeySize*mValueSize]; -#ifdef __EXCEPTIONS - } catch (...) { mData = 0; } -#endif - if (mData) - fill(0); - else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else - mData = 0; - - if (mAlpha) // if we had an alpha map, recreate it with new size - createAlpha(); - - mDataModified = true; - } -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. - - \see setKeyRange, setSize, setValueSize -*/ -void QCPColorMapData::setKeySize(int keySize) -{ - setSize(keySize, mValueSize); -} - -/*! - Resizes the data array to have \a valueSize cells in the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. - - \see setValueRange, setSize, setKeySize -*/ -void QCPColorMapData::setValueSize(int valueSize) -{ - setSize(mKeySize, valueSize); -} - -/*! - Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area - covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setSize -*/ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) -{ - setKeyRange(keyRange); - setValueRange(valueRange); -} - -/*! - Sets the coordinate range the data shall be distributed over in the key dimension. Together with - the value range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to QCPRange(2, 3) there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setRange, setValueRange, setSize -*/ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) -{ - mKeyRange = keyRange; -} - -/*! - Sets the coordinate range the data shall be distributed over in the value dimension. Together with - the key range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the value size (\ref setValueSize) is 3 and \a valueRange is set to QCPRange(2, 3) there - will be cells centered on the value coordinates 2, 2.5 and 3. - - \see setRange, setKeyRange, setSize -*/ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) -{ - mValueRange = valueRange; -} - -/*! - Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a - z. - - \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or - value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, - you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to - determine the cell index. Rather directly access the cell index with \ref - QCPColorMapData::setCell. - - \see setCell, setRange -*/ -void QCPColorMapData::setData(double key, double value, double z) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices - enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see - \ref setSize). - - In the standard plot configuration (horizontal key axis and vertical value axis, both not - range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with - indices (keySize-1, valueSize-1) is in the top right corner of the color map. - - \see setData, setSize -*/ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Sets the alpha of the color map cell given by \a keyIndex and \a valueIndex to \a alpha. A value - of 0 for \a alpha results in a fully transparent cell, and a value of 255 results in a fully - opaque cell. - - If an alpha map doesn't exist yet for this color map data, it will be created here. If you wish - to restore full opacity and free any allocated memory of the alpha map, call \ref clearAlpha. - - Note that the cell-wise alpha which can be configured here is independent of any alpha configured - in the color map's gradient (\ref QCPColorGradient). If a cell is affected both by the cell-wise - and gradient alpha, the alpha values will be blended accordingly during rendering of the color - map. - - \see fillAlpha, clearAlpha -*/ -void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - if (mAlpha || createAlpha()) - { - mAlpha[valueIndex*mKeySize + keyIndex] = alpha; - mDataModified = true; - } - } else - qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; -} - -/*! - Goes through the data and updates the buffered minimum and maximum data values. - - Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange - and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten - with a smaller or larger value respectively, since the buffered maximum/minimum values have been - updated the last time. Why this is the case is explained in the class description (\ref - QCPColorMapData). - - Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a - recalculateDataBounds for convenience. Setting this to true will call this method for you, before - doing the rescale. -*/ -void QCPColorMapData::recalculateDataBounds() -{ - if (mKeySize > 0 && mValueSize > 0) - { - double minHeight = mData[0]; - double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i maxHeight) - maxHeight = mData[i]; - if (mData[i] < minHeight) - minHeight = mData[i]; - } - mDataBounds.lower = minHeight; - mDataBounds.upper = maxHeight; - } -} - -/*! - Frees the internal data memory. - - This is equivalent to calling \ref setSize "setSize(0, 0)". -*/ -void QCPColorMapData::clear() -{ - setSize(0, 0); -} - -/*! - Frees the internal alpha map. The color map will have full opacity again. -*/ -void QCPColorMapData::clearAlpha() -{ - if (mAlpha) - { - delete[] mAlpha; - mAlpha = 0; - mDataModified = true; - } -} - -/*! - Sets all cells to the value \a z. -*/ -void QCPColorMapData::fill(double z) -{ - const int dataCount = mValueSize*mKeySize; - for (int i=0; i(data); - return; - } - if (copy) - { - *mMapData = *data; - } else - { - delete mMapData; - mMapData = data; - } - mMapImageInvalidated = true; -} - -/*! - Sets the data range of this color map to \a dataRange. The data range defines which data values - are mapped to the color gradient. - - To make the data range span the full range of the data set, use \ref rescaleDataRange. - - \see QCPColorScale::setDataRange -*/ -void QCPColorMap::setDataRange(const QCPRange &dataRange) -{ - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - if (mDataScaleType == QCPAxis::stLogarithmic) - mDataRange = dataRange.sanitizedForLogScale(); - else - mDataRange = dataRange.sanitizedForLinScale(); - mMapImageInvalidated = true; - Q_EMIT dataRangeChanged(mDataRange); - } -} - -/*! - Sets whether the data is correlated with the color gradient linearly or logarithmically. - - \see QCPColorScale::setDataScaleType -*/ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - mMapImageInvalidated = true; - Q_EMIT dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - } -} - -/*! - Sets the color gradient that is used to represent the data. For more details on how to create an - own gradient or use one of the preset gradients, see \ref QCPColorGradient. - - The colors defined by the gradient will be used to represent data values in the currently set - data range, see \ref setDataRange. Data points that are outside this data range will either be - colored uniformly with the respective gradient boundary color, or the gradient will repeat, - depending on \ref QCPColorGradient::setPeriodic. - - \see QCPColorScale::setGradient -*/ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - mMapImageInvalidated = true; - Q_EMIT gradientChanged(mGradient); - } -} - -/*! - Sets whether the color map image shall use bicubic interpolation when displaying the color map - shrinked or expanded, and not at a 1:1 pixel-to-data scale. - - \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" -*/ -void QCPColorMap::setInterpolate(bool enabled) -{ - mInterpolate = enabled; - mMapImageInvalidated = true; // because oversampling factors might need to change -} - -/*! - Sets whether the outer most data rows and columns are clipped to the specified key and value - range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). - - if \a enabled is set to false, the data points at the border of the color map are drawn with the - same width and height as all other data points. Since the data points are represented by - rectangles of one color centered on the data coordinate, this means that the shown color map - extends by half a data point over the specified key/value range in each direction. - - \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" -*/ -void QCPColorMap::setTightBoundary(bool enabled) -{ - mTightBoundary = enabled; -} - -/*! - Associates the color scale \a colorScale with this color map. - - This means that both the color scale and the color map synchronize their gradient, data range and - data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps - can be associated with one single color scale. This causes the color maps to also synchronize - those properties, via the mutual color scale. - - This function causes the color map to adopt the current color gradient, data range and data scale - type of \a colorScale. After this call, you may change these properties at either the color map - or the color scale, and the setting will be applied to both. - - Pass 0 as \a colorScale to disconnect the color scale from this color map again. -*/ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) -{ - if (mColorScale) // unconnect signals from old color scale - { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale - { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } -} - -/*! - Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the - current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, - only for the third data dimension of the color map. - - The minimum and maximum values of the data set are buffered in the internal QCPColorMapData - instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref - QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For - performance reasons, however, they are only updated in an expanding fashion. So the buffered - maximum can only increase and the buffered minimum can only decrease. In consequence, changes to - the data that actually lower the maximum of the data set (by overwriting the cell holding the - current maximum with a smaller value), aren't recognized and the buffered maximum overestimates - the true maximum of the data set. The same happens for the buffered minimum. To recalculate the - true minimum and maximum by explicitly looking at each cell, the method - QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a - recalculateDataBounds calls this method before setting the data range to the buffered minimum and - maximum. - - \see setDataRange -*/ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) -{ - if (recalculateDataBounds) - mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); -} - -/*! - Takes the current appearance of the color map and updates the legend icon, which is used to - represent this color map in the legend (see \ref QCPLegend). - - The \a transformMode specifies whether the rescaling is done by a faster, low quality image - scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm - (Qt::SmoothTransformation). - - The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to - the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured - legend icon size, the thumb will be rescaled during drawing of the legend item. - - \see setDataRange -*/ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) -{ - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again - { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); - } -} - -/* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) - { - if (details) - details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. - return mParentPlot->selectionTolerance()*0.99; - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->keyRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (inKeyRange != QCPRange()) - { - if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) - { - foundRange = false; - return QCPRange(); - } - } - - foundRange = true; - QCPRange result = mMapData->valueRange(); - result.normalize(); - if (inSignDomain == QCP::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCP::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/*! \internal - - Updates the internal map image buffer by going through the internal \ref QCPColorMapData and - turning the data values into color pixels with \ref QCPColorGradient::colorize. - - This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image - has been invalidated for a different reason (e.g. a change of the data range with \ref - setDataRange). - - If the map cell count is low, the image created will be oversampled in order to avoid a - QPainter::drawImage bug which makes inner pixel boundaries jitter when stretch-drawing images - without smooth transform enabled. Accordingly, oversampling isn't performed if \ref - setInterpolate is true. -*/ -void QCPColorMap::updateMapImage() -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - if (mMapData->isEmpty()) return; - - const QImage::Format format = QImage::Format_ARGB32_Premultiplied; - const int keySize = mMapData->keySize(); - const int valueSize = mMapData->valueSize(); - int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - - // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) - mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) - mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); - - if (mMapImage.isNull()) - { - qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; - mMapImage = QImage(QSize(10, 10), format); - mMapImage.fill(Qt::black); - } else - { - QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - // resize undersampled map image to actual key/value cell sizes: - if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) - mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); - else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) - mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); - localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image - } else if (!mUndersampledMapImage.isNull()) - mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it - - const double *rawData = mMapData->mData; - const unsigned char *rawAlpha = mMapData->mAlpha; - if (keyAxis->orientation() == Qt::Horizontal) - { - const int lineCount = valueSize; - const int rowCount = keySize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - } - } else // keyAxis->orientation() == Qt::Vertical - { - const int lineCount = keySize; - const int rowCount = valueSize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - else - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - } - } - - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) - { - if (keyAxis->orientation() == Qt::Horizontal) - mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - else - mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); - } - } - mMapData->mDataModified = false; - mMapImageInvalidated = false; -} - -/* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) -{ - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) - updateMapImage(); - - // use buffer if painting vectorized (PDF): - const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); - QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized - QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in - QPixmap mapBuffer; - if (useBuffer) - { - const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps - mapBufferTarget = painter->clipRegion().boundingRect(); - mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); - mapBuffer.fill(Qt::transparent); - localPainter = new QCPPainter(&mapBuffer); - localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); - localPainter->translate(-mapBufferTarget.topLeft()); - } - - QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): - double halfCellWidth = 0; // in pixels - double halfCellHeight = 0; // in pixels - if (keyAxis()->orientation() == Qt::Horizontal) - { - if (mMapData->keySize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); - } else // keyAxis orientation is Qt::Vertical - { - if (mMapData->keySize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); - } - imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); - const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); - QRegion clipBackup; - if (mTightBoundary) - { - clipBackup = localPainter->clipRegion(); - QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - localPainter->setClipRect(tightClipRect, Qt::IntersectClip); - } - localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - localPainter->setClipRegion(clipBackup); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); - - if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter - { - delete localPainter; - painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); - } -} - -/* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - // draw map thumbnail: - if (!mLegendIcon.isNull()) - { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); - } - /* - // draw frame: - painter->setBrush(Qt::NoBrush); - painter->setPen(Qt::black); - painter->drawRect(rect.adjusted(1, 1, 0, 0)); - */ -} -/* end of 'src/plottables/plottable-colormap.cpp' */ - - -/* including file 'src/plottables/plottable-financial.cpp', size 42610 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancialData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancialData - \brief Holds the data of one single data point for QCPFinancial. - - The stored data is: - \li \a key: coordinate on the key axis of this data point (this is the \a mainKey and the \a sortKey) - \li \a open: The opening value at the data point (this is the \a mainValue) - \li \a high: The high/maximum value at the data point - \li \a low: The low/minimum value at the data point - \li \a close: The closing value at the data point - - The container for storing multiple data points is \ref QCPFinancialDataContainer. It is a typedef - for \ref QCPDataContainer with \ref QCPFinancialData as the DataType template parameter. See the - documentation there for an explanation regarding the data type's generic methods. - - \see QCPFinancialDataContainer -*/ - -/* start documentation of inline functions */ - -/*! \fn double QCPFinancialData::sortKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static QCPFinancialData QCPFinancialData::fromSortKey(double sortKey) - - Returns a data point with the specified \a sortKey. All other members are set to zero. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn static static bool QCPFinancialData::sortKeyIsMainKey() - - Since the member \a key is both the data point key coordinate and the data ordering parameter, - this method returns true. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainKey() const - - Returns the \a key member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn double QCPFinancialData::mainValue() const - - Returns the \a open member of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/*! \fn QCPRange QCPFinancialData::valueRange() const - - Returns a QCPRange spanning from the \a low to the \a high value of this data point. - - For a general explanation of what this method is good for in the context of the data container, - see the documentation of \ref QCPDataContainer. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a data point with key and all values set to zero. -*/ -QCPFinancialData::QCPFinancialData() : - key(0), - open(0), - high(0), - low(0), - close(0) -{ -} - -/*! - Constructs a data point with the specified \a key and OHLC values. -*/ -QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : - key(key), - open(open), - high(high), - low(low), - close(close) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPFinancial -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPFinancial - \brief A plottable representing a financial stock chart - - \image html QCPFinancial.png - - This plottable represents time series data binned to certain intervals, mainly used for stock - charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be - set via \ref setChartStyle. - - The data is passed via \ref setData as a set of open/high/low/close values at certain keys - (typically times). This means the data must be already binned appropriately. If data is only - available as a series of values (e.g. \a price against \a time), you can use the static - convenience function \ref timeSeriesToOhlc to generate binned OHLC-data which can then be passed - to \ref setData. - - The width of the OHLC bars/candlesticks can be controlled with \ref setWidth and \ref - setWidthType. A typical choice is to set the width type to \ref wtPlotCoords (the default) and - the width to (or slightly less than) one time bin interval width. - - \section qcpfinancial-appearance Changing the appearance - - Charts can be either single- or two-colored (\ref setTwoColored). If set to be single-colored, - lines are drawn with the plottable's pen (\ref setPen) and fills with the brush (\ref setBrush). - - If set to two-colored, positive changes of the value during an interval (\a close >= \a open) are - represented with a different pen and brush than negative changes (\a close < \a open). These can - be configured with \ref setPenPositive, \ref setPenNegative, \ref setBrushPositive, and \ref - setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection - however, the normal selected pen/brush (provided by the \ref selectionDecorator) is used, - irrespective of whether the chart is single- or two-colored. - - \section qcpfinancial-usage Usage - - Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-1 - which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot - instance takes ownership of the plottable, so do not delete it manually but use - QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.: - - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-creation-2 - Here we have used the static helper method \ref timeSeriesToOhlc, to turn a time-price data - series into a 24-hour binned open-high-low-close data series as QCPFinancial uses. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPFinancialDataContainer *QCPFinancial::data() const - - Returns a pointer to the internal data storage of type \ref QCPFinancialDataContainer. You may - use it to directly manipulate the data, which may be more convenient and faster than using the - regular \ref setData or \ref addData methods, in certain situations. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a financial chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The created QCPFinancial is automatically registered with the QCustomPlot instance inferred from \a - keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually - but use QCustomPlot::removePlottable() instead. -*/ -QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mChartStyle(csCandlestick), - mWidth(0.5), - mWidthType(wtPlotCoords), - mTwoColored(true), - mBrushPositive(QBrush(QColor(50, 160, 0))), - mBrushNegative(QBrush(QColor(180, 0, 15))), - mPenPositive(QPen(QColor(40, 150, 0))), - mPenNegative(QPen(QColor(170, 5, 5))) -{ - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); -} - -QCPFinancial::~QCPFinancial() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple QCPFinancials may share the same data container safely. - Modifying the data in the container will then affect all financials that share the container. - Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, rather use - the \ref QCPDataContainer::set method on the financial's data container directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcpfinancial-datasharing-2 - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Replaces the current data with the provided points in \a keys, \a open, \a high, \a low and \a - close. The provided vectors should have equal length. Else, the number of added points will be - the size of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - \see addData, timeSeriesToOhlc -*/ -void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - mDataContainer->clear(); - addData(keys, open, high, low, close, alreadySorted); -} - -/*! - Sets which representation style shall be used to display the OHLC data. -*/ -void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) -{ - mChartStyle = style; -} - -/*! - Sets the width of the individual bars/candlesticks to \a width in plot key coordinates. - - A typical choice is to set it to (or slightly less than) one bin interval width. -*/ -void QCPFinancial::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets how the width of the financial bars is defined. See the documentation of \ref WidthType for - an explanation of the possible values for \a widthType. - - The default value is \ref wtPlotCoords. - - \see setWidth -*/ -void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) -{ - mWidthType = widthType; -} - -/*! - Sets whether this chart shall contrast positive from negative trends per data point by using two - separate colors to draw the respective bars/candlesticks. - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setTwoColored(bool twoColored) -{ - mTwoColored = twoColored; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushNegative, setPenPositive, setPenNegative -*/ -void QCPFinancial::setBrushPositive(const QBrush &brush) -{ - mBrushPositive = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the brush that is used to draw fills - of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setBrushPositive, setPenNegative, setPenPositive -*/ -void QCPFinancial::setBrushNegative(const QBrush &brush) -{ - mBrushNegative = brush; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenNegative, setBrushPositive, setBrushNegative -*/ -void QCPFinancial::setPenPositive(const QPen &pen) -{ - mPenPositive = pen; -} - -/*! - If \ref setTwoColored is set to true, this function controls the pen that is used to draw - outlines of data points with a negative trend (i.e. bars/candlesticks with close < open). - - If \a twoColored is false, the normal plottable's pen and brush are used (\ref setPen, \ref - setBrush). - - \see setPenPositive, setBrushNegative, setBrushPositive -*/ -void QCPFinancial::setPenNegative(const QPen &pen) -{ - mPenNegative = pen; -} - -/*! \overload - - Adds the provided points in \a keys, \a open, \a high, \a low and \a close to the current data. - The provided vectors should have equal length. Else, the number of added points will be the size - of the smallest vector. - - If you can guarantee that the passed data points are sorted by \a keys in ascending order, you - can set \a alreadySorted to true, to improve performance by saving a sorting run. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) -{ - if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) - qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); - const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); - QVector tempData(n); - QVector::iterator it = tempData.begin(); - const QVector::iterator itEnd = tempData.end(); - int i = 0; - while (it != itEnd) - { - it->key = keys[i]; - it->open = open[i]; - it->high = high[i]; - it->low = low[i]; - it->close = close[i]; - ++it; - ++i; - } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write -} - -/*! \overload - - Adds the provided data point as \a key, \a open, \a high, \a low and \a close to the current - data. - - Alternatively, you can also access and modify the data directly via the \ref data method, which - returns a pointer to the internal data container. - - \see timeSeriesToOhlc -*/ -void QCPFinancial::addData(double key, double open, double high, double low, double close) -{ - mDataContainer->add(QCPFinancialData(key, open, high, low, close)); -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - if (rect.intersects(selectionHitBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - // perform select test according to configured style: - double result = -1; - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - case QCPFinancial::csCandlestick: - result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - } - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } - - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); - // determine exact range by including width of bars/flags: - if (foundRange) - { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; - } - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); -} - -/*! - A convenience function that converts time series data (\a value against \a time) to OHLC binned - data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const - QCPFinancialDataContainer&). - - The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. - For example, if the unit of \a time is seconds and single OHLC/Candlesticks should span an hour - each, set \a timeBinSize to 3600. - - \a timeBinOffset allows to control precisely at what \a time coordinate a bin should start. The - value passed as \a timeBinOffset doesn't need to be in the range encompassed by the \a time keys. - It merely defines the mathematical offset/phase of the bins that will be used to process the - data. -*/ -QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) -{ - QCPFinancialDataContainer data; - int count = qMin(time.size(), value.size()); - if (count == 0) - return QCPFinancialDataContainer(); - - QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); - int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); - for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); - if (i == count-1) // last data point is in current bin, finalize bin: - { - currentBinData.close = value.at(i); - currentBinData.key = timeBinOffset+(index)*timeBinSize; - data.add(currentBinData); - } - } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: - { - // finalize current bin: - currentBinData.close = value.at(i-1); - currentBinData.key = timeBinOffset+(index-1)*timeBinSize; - data.add(currentBinData); - // start next bin: - currentBinIndex = index; - currentBinData.open = value.at(i); - currentBinData.high = value.at(i); - currentBinData.low = value.at(i); - } - } - - return data; -} - -/* inherits documentation from base class */ -void QCPFinancial::draw(QCPPainter *painter) -{ - // get visible data range: - QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - QCPFinancialDataContainer::const_iterator begin = visibleBegin; - QCPFinancialDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) - continue; - - // draw data segment according to configured style: - switch (mChartStyle) - { - case QCPFinancial::csOhlc: - drawOhlcPlot(painter, begin, end, isSelectedSegment); break; - case QCPFinancial::csCandlestick: - drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; - } - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing - if (mChartStyle == csOhlc) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } - } else if (mChartStyle == csCandlestick) - { - if (mTwoColored) - { - // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as OHLC bars with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. -*/ -void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); - // draw close: - painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); - } - } else - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw backbone: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); - // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); - // draw close: - painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); - } - } -} - -/*! \internal - - Draws the data from \a begin to \a end-1 as Candlesticks with the provided \a painter. - - This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. -*/ -void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - // draw low: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) - { - if (isSelected && mSelectionDecorator) - { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); - } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); - // draw high: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - // draw low: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); - } - } -} - -/*! \internal - - This function is used to determine the width of the bar at coordinate \a key, according to the - specified width (\ref setWidth) and width type (\ref setWidthType). Provide the pixel position of - \a key in \a keyPixel (because usually this was already calculated via \ref QCPAxis::coordToPixel - when this function is called). - - It returns the number of pixels the bar extends to higher keys, relative to the \a key - coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed - horizontal axis, the return value is negative. This is important so the open/close flags on the - \ref csOhlc bar are drawn to the correct side. -*/ -double QCPFinancial::getPixelWidth(double key, double keyPixel) const -{ - double result = 0; - switch (mWidthType) - { - case wtAbsolute: - { - if (mKeyAxis) - result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } - } - return result; -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - This method is a helper function for \ref selectTest. It is used to test for selection when the - chart style is \ref csCandlestick. It only tests against the data points between \a begin and \a - end. - - Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical - representation of the plottable, and \a closestDataPoint will point to the respective data point. -*/ -double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const -{ - closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - double minDistSqr = std::numeric_limits::max(); - if (keyAxis->orientation() == Qt::Horizontal) - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt(minDistSqr); -} - -/*! \internal - - called by the drawing methods to determine which data (key) range is visible at the current key - axis range setting, so only that needs to be processed. - - \a begin returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - begin may still be just outside the visible range. - - \a end returns the iterator just above the highest data point that needs to be taken into - account. Same as before, \a end may also lie just outside of the visible range - - if the plottable contains no data, both \a begin and \a end point to \c constEnd. -*/ -void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const -{ - if (!mKeyAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - begin = mDataContainer->constEnd(); - end = mDataContainer->constEnd(); - return; - } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points -} - -/*! \internal - - Returns the hit box in pixel coordinates that will be used for data selection with the selection - rect (\ref selectTestRect), of the data point given by \a it. -*/ -QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double keyPixel = keyAxis->coordToPixel(it->key); - double highPixel = valueAxis->coordToPixel(it->high); - double lowPixel = valueAxis->coordToPixel(it->low); - double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); - if (keyAxis->orientation() == Qt::Horizontal) - return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); - else - return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); -} -/* end of 'src/plottables/plottable-financial.cpp' */ - - -/* including file 'src/plottables/plottable-errorbar.cpp', size 37355 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBarsData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBarsData - \brief Holds the data of one single error bar for QCPErrorBars. - - The stored data is: - \li \a errorMinus: how much the error bar extends towards negative coordinates from the data - point position - \li \a errorPlus: how much the error bar extends towards positive coordinates from the data point - position - - The container for storing the error bar information is \ref QCPErrorBarsDataContainer. It is a - typedef for QVector<\ref QCPErrorBarsData>. - - \see QCPErrorBarsDataContainer -*/ - -/*! - Constructs an error bar with errors set to zero. -*/ -QCPErrorBarsData::QCPErrorBarsData() : - errorMinus(0), - errorPlus(0) -{ -} - -/*! - Constructs an error bar with equal \a error in both negative and positive direction. -*/ -QCPErrorBarsData::QCPErrorBarsData(double error) : - errorMinus(error), - errorPlus(error) -{ -} - -/*! - Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, - respectively. -*/ -QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : - errorMinus(errorMinus), - errorPlus(errorPlus) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPErrorBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPErrorBars - \brief A plottable that adds a set of error bars to other plottables. - - \image html QCPErrorBars.png - - The \ref QCPErrorBars plottable can be attached to other one-dimensional plottables (e.g. \ref - QCPGraph, \ref QCPCurve, \ref QCPBars, etc.) and equips them with error bars. - - Use \ref setDataPlottable to define for which plottable the \ref QCPErrorBars shall display the - error bars. The orientation of the error bars can be controlled with \ref setErrorType. - - By using \ref setData, you can supply the actual error data, either as symmetric error or - plus/minus asymmetric errors. \ref QCPErrorBars only stores the error data. The absolute - key/value position of each error bar will be adopted from the configured data plottable. The - error data of the \ref QCPErrorBars are associated one-to-one via their index to the data points - of the data plottable. You can directly access and manipulate the error bar data via \ref data. - - Set either of the plus/minus errors to NaN (qQNaN() or - std::numeric_limits::quiet_NaN()) to not show the respective error bar on the data point at - that index. - - \section qcperrorbars-appearance Changing the appearance - - The appearance of the error bars is defined by the pen (\ref setPen), and the width of the - whiskers (\ref setWhiskerWidth). Further, the error bar backbones may leave a gap around the data - point center to prevent that error bars are drawn too close to or even through scatter points. - This gap size can be controlled via \ref setSymbolGap. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QSharedPointer QCPErrorBars::data() const - - Returns a shared pointer to the internal data storage of type \ref QCPErrorBarsDataContainer. You - may use it to directly manipulate the error values, which may be more convenient and faster than - using the regular \ref setData methods. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs an error bars plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - It is also important that the \a keyAxis and \a valueAxis are the same for the error bars - plottable and the data plottable that the error bars shall be drawn on (\ref setDataPlottable). - - The created \ref QCPErrorBars is automatically registered with the QCustomPlot instance inferred - from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not - delete it manually but use \ref QCustomPlot::removePlottable() instead. -*/ -QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QVector), - mErrorType(etValueError), - mWhiskerWidth(9), - mSymbolGap(10) -{ - setPen(QPen(Qt::black, 0)); - setBrush(Qt::NoBrush); -} - -QCPErrorBars::~QCPErrorBars() -{ -} - -/*! \overload - - Replaces the current data container with the provided \a data container. - - Since a QSharedPointer is used, multiple \ref QCPErrorBars instances may share the same data - container safely. Modifying the data in the container will then affect all \ref QCPErrorBars - instances that share the container. Sharing can be achieved by simply exchanging the data - containers wrapped in shared pointers: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-1 - - If you do not wish to share containers, but create a copy from an existing container, assign the - data containers directly: - \snippet documentation/doc-code-snippets/mainwindow.cpp qcperrorbars-datasharing-2 - (This uses different notation compared with other plottables, because the \ref QCPErrorBars - uses a \c QVector as its data container, instead of a \ref QCPDataContainer.) - - \see addData -*/ -void QCPErrorBars::setData(QSharedPointer data) -{ - mDataContainer = data; -} - -/*! \overload - - Sets symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &error) -{ - mDataContainer->clear(); - addData(error); -} - -/*! \overload - - Sets asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see addData -*/ -void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) -{ - mDataContainer->clear(); - addData(errorMinus, errorPlus); -} - -/*! - Sets the data plottable to which the error bars will be applied. The error values specified e.g. - via \ref setData will be associated one-to-one by the data point index to the data points of \a - plottable. This means that the error bars will adopt the key/value coordinates of the data point - with the same index. - - The passed \a plottable must be a one-dimensional plottable, i.e. it must implement the \ref - QCPPlottableInterface1D. Further, it must not be a \ref QCPErrorBars instance itself. If either - of these restrictions is violated, a corresponding qDebug output is generated, and the data - plottable of this \ref QCPErrorBars instance is set to zero. - - For proper display, care must also be taken that the key and value axes of the \a plottable match - those configured for this \ref QCPErrorBars instance. -*/ -void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) -{ - if (plottable && qobject_cast(plottable)) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; - return; - } - if (plottable && !plottable->interface1D()) - { - mDataPlottable = 0; - qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; - return; - } - - mDataPlottable = plottable; -} - -/*! - Sets in which orientation the error bars shall appear on the data points. If your data needs both - error dimensions, create two \ref QCPErrorBars with different \a type. -*/ -void QCPErrorBars::setErrorType(ErrorType type) -{ - mErrorType = type; -} - -/*! - Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to - \a pixels. -*/ -void QCPErrorBars::setWhiskerWidth(double pixels) -{ - mWhiskerWidth = pixels; -} - -/*! - Sets the gap diameter around the data points that will be left out when drawing the error bar - backbones. This gap prevents that error bars are drawn too close to or even through scatter - points. -*/ -void QCPErrorBars::setSymbolGap(double pixels) -{ - mSymbolGap = pixels; -} - -/*! \overload - - Adds symmetrical error values as specified in \a error. The errors will be associated one-to-one - by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &error) -{ - addData(error, error); -} - -/*! \overload - - Adds asymmetrical errors as specified in \a errorMinus and \a errorPlus. The errors will be - associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) -{ - if (errorMinus.size() != errorPlus.size()) - qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); - const int n = qMin(errorMinus.size(), errorPlus.size()); - mDataContainer->reserve(n); - for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); -} - -/*! \overload - - Adds a single symmetrical error bar as specified in \a error. The errors will be associated - one-to-one by the data point index to the associated data plottable (\ref setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double error) -{ - mDataContainer->append(QCPErrorBarsData(error)); -} - -/*! \overload - - Adds a single asymmetrical error bar as specified in \a errorMinus and \a errorPlus. The errors - will be associated one-to-one by the data point index to the associated data plottable (\ref - setDataPlottable). - - You can directly access and manipulate the error bar data via \ref data. - - \see setData -*/ -void QCPErrorBars::addData(double errorMinus, double errorPlus) -{ - mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); -} - -/* inherits documentation from base class */ -int QCPErrorBars::dataCount() const -{ - return mDataContainer->size(); -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataSortKey(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataSortKey(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::dataMainValue(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainValue(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::dataValueRange(int index) const -{ - if (mDataPlottable) - { - const double value = mDataPlottable->interface1D()->dataMainValue(index); - if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) - return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); - else - return QCPRange(value, value); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QCPRange(); - } -} - -/* inherits documentation from base class */ -QPointF QCPErrorBars::dataPixelPosition(int index) const -{ - if (mDataPlottable) - return mDataPlottable->interface1D()->dataPixelPosition(index); - else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return QPointF(); -} - -/* inherits documentation from base class */ -bool QCPErrorBars::sortKeyIsMainKey() const -{ - if (mDataPlottable) - { - return mDataPlottable->interface1D()->sortKeyIsMainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return true; - } -} - -/*! - \copydoc QCPPlottableInterface1D::selectTestRect -*/ -QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if (!mDataPlottable) - return result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); - - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) - { - backbones.clear(); - whiskers.clear(); - getErrorBarLines(it, backbones, whiskers); - for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); - break; - } - } - } - result.simplify(); - return result; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); - if (beginIndex >= mDataContainer->size()) - beginIndex = mDataContainer->size()-1; - return beginIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const -{ - if (mDataPlottable) - { - if (mDataContainer->isEmpty()) - return 0; - int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); - if (endIndex > mDataContainer->size()) - endIndex = mDataContainer->size(); - return endIndex; - } else - qDebug() << Q_FUNC_INFO << "no data plottable set"; - return 0; -} - -/* inherits documentation from base class */ -double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mDataPlottable) return -1; - - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) - { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); - } - return result; - } else - return -1; -} - -/* inherits documentation from base class */ -void QCPErrorBars::draw(QCPPainter *painter) -{ - if (!mDataPlottable) return; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - - // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually - // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): - bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); - } -#endif - - applyDefaultAntialiasingHint(painter); - painter->setBrush(Qt::NoBrush); - // loop over and draw segments of unselected/selected data: - QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); - allSegments << unselectedSegments << selectedSegments; - QVector backbones, whiskers; - for (int i=0; i= unselectedSegments.size(); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else - painter->setPen(mPen); - if (painter->pen().capStyle() == Qt::SquareCap) - { - QPen capFixPen(painter->pen()); - capFixPen.setCapStyle(Qt::FlatCap); - painter->setPen(capFixPen); - } - backbones.clear(); - whiskers.clear(); - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) - getErrorBarLines(it, backbones, whiskers); - } - painter->drawLines(backbones); - painter->drawLines(whiskers); - } - - // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); -} - -/* inherits documentation from base class */ -void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) - { - painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); - painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); - painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); - } else - { - painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); - painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); - painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); - } -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) - { - if (mErrorType == etValueError) - { - // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } else // mErrorType == etKeyError - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(dataKey)) continue; - // plus error: - double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const -{ - if (!mDataPlottable) - { - foundRange = false; - return QCPRange(); - } - - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); - QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); - itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); - } - for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange) - { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) - continue; - } - if (mErrorType == etValueError) - { - const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(dataValue)) continue; - // plus error: - double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - // minus error: - current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - } - } else // mErrorType == etKeyError - { - // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - } - } - - if (haveUpper && !haveLower) - { - range.lower = range.upper; - haveLower = true; - } else if (haveLower && !haveUpper) - { - range.upper = range.lower; - haveUpper = true; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! \internal - - Calculates the lines that make up the error bar belonging to the data point \a it. - - The resulting lines are added to \a backbones and \a whiskers. The vectors are not cleared, so - calling this method with different \a it but the same \a backbones and \a whiskers allows to - accumulate lines for multiple data points. - - This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars - instance and within the bounds of the associated data plottable. -*/ -void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const -{ - if (!mDataPlottable) return; - - int index = it-mDataContainer->constBegin(); - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) - return; - QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); - QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); - const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value - const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); - // plus error: - double errorStart, errorEnd; - if (!qIsNaN(it->errorPlus)) - { - errorStart = centerErrorAxisPixel+symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } - // minus error: - if (!qIsNaN(it->errorMinus)) - { - errorStart = centerErrorAxisPixel-symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); - if (errorAxis->orientation() == Qt::Vertical) - { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else - { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); - } - } -} - -/*! \internal - - This method outputs the currently visible data range via \a begin and \a end. The returned range - will also never exceed \a rangeRestriction. - - Since error bars with type \ref etKeyError may extend to arbitrarily positive and negative key - coordinates relative to their data point key, this method checks all outer error bars whether - they truly don't reach into the visible portion of the axis rect, by calling \ref - errorBarVisible. On the other hand error bars with type \ref etValueError that are associated - with data plottables whose sort key is equal to the main key (see \ref qcpdatacontainer-datatype - "QCPDataContainer DataType") can be handled very efficiently by finding the visible range of - error bars through binary search (\ref QCPPlottableInterface1D::findBegin and \ref - QCPPlottableInterface1D::findEnd). - - If the plottable's sort key is not equal to the main key, this method returns the full data - range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a - point-by-point basis in the \ref draw method. -*/ -void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable || rangeRestriction.isEmpty()) - { - end = mDataContainer->constEnd(); - begin = end; - return; - } - if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) - { - // if the sort key isn't the main key, it's not possible to find a contiguous range of visible - // data points, so this method then only applies the range restriction and otherwise returns - // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing - QCPDataRange dataRange(0, mDataContainer->size()); - dataRange = dataRange.bounded(rangeRestriction); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); - return; - } - - // get visible data range via interface from data plottable, and then restrict to available error data points: - const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); - int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); - int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); - int i = beginIndex; - while (i > 0 && i < n && i > rangeRestriction.begin()) - { - if (errorBarVisible(i)) - beginIndex = i; - --i; - } - i = endIndex; - while (i >= 0 && i < n && i < rangeRestriction.end()) - { - if (errorBarVisible(i)) - endIndex = i+1; - ++i; - } - QCPDataRange dataRange(beginIndex, endIndex); - dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); -} - -/*! \internal - - Calculates the minimum distance in pixels the error bars' representation has from the given \a - pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref - selectTest. The closest data point to \a pixelPoint is returned in \a closestData. -*/ -double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const -{ - closestData = mDataContainer->constEnd(); - if (!mDataPlottable || mDataContainer->isEmpty()) - return -1.0; - if (!mKeyAxis || !mValueAxis) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return -1.0; - } - - QCPErrorBarsDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); - - // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: - double minDistSqr = std::numeric_limits::max(); - QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) - { - getErrorBarLines(it, backbones, whiskers); - for (int i=0; i &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! \internal - - Returns whether the error bar at the specified \a index is visible within the current key axis - range. - - This method assumes for performance reasons without checking that the key axis, the value axis, - and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid - bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. -*/ -bool QCPErrorBars::errorBarVisible(int index) const -{ - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - if (qIsNaN(centerKeyPixel)) - return false; - - double keyMin, keyMax; - if (mErrorType == etKeyError) - { - const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); - const double errorPlus = mDataContainer->at(index).errorPlus; - const double errorMinus = mDataContainer->at(index).errorMinus; - keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); - keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); - } else // mErrorType == etValueError - { - keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - } - return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); -} - -/*! \internal - - Returns whether \a line intersects (or is contained in) \a pixelRect. - - \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for - error bar lines. -*/ -bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const -{ - if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) - return false; - else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) - return false; - else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) - return false; - else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) - return false; - else - return true; -} -/* end of 'src/plottables/plottable-errorbar.cpp' */ - - -/* including file 'src/items/item-straightline.cpp', size 7592 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemStraightLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemStraightLine - \brief A straight line that spans infinitely in both directions - - \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a point1 and \a point2, which define the straight line. -*/ - -/*! - Creates a straight line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition(QLatin1String("point1"))), - point2(createPosition(QLatin1String("point2"))) -{ - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemStraightLine::~QCPItemStraightLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemStraightLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); -} - -/* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) -{ - QCPVector2D start(point1->pixelPosition()); - QCPVector2D end(point2->pixelPosition()); - // get visible segment of straight line inside clipRect: - double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - } -} - -/*! \internal - - Returns the section of the straight line defined by \a base and direction vector \a - vec, that is visible in the specified \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const -{ - double bx, by; - double gamma; - QLineF result; - if (vec.x() == 0 && vec.y() == 0) - return result; - if (qFuzzyIsNull(vec.x())) // line is vertical - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed - { - QList pointVectors; - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - // check right of rect: - bx = rect.right(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemStraightLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-straightline.cpp' */ - - -/* including file 'src/items/item-line.cpp', size 8498 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemLine - \brief A line from one point to another - - \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a start and \a end, which define the end points of the line. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. -*/ - -/*! - Creates a line item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemLine::~QCPItemLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemLine::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemLine::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); -} - -/* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) -{ - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if (qFuzzyIsNull((startVec-endVec).lengthSquared())) - return; - // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); - } -} - -/*! \internal - - Returns the section of the line defined by \a start and \a end, that is visible in the specified - \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const -{ - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - - QCPVector2D base = start; - QCPVector2D vec = end-start; - double bx, by; - double gamma, mu; - QLineF result; - QList pointVectors; - - if (!qFuzzyIsNull(vec.y())) // line is not horizontal - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); - } - } - if (!qFuzzyIsNull(vec.x())) // line is not vertical - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - // check right of rect: - bx = rect.right(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - } - } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-line.cpp' */ - - -/* including file 'src/items/item-curve.cpp', size 7159 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemCurve - \brief A curved line from one point to another - - \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." - - It has four positions, \a start and \a end, which define the end points of the line, and two - control points which define the direction the line exits from the start and the direction from - which it approaches the end: \a startDir and \a endDir. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an - arrow. - - Often it is desirable for the control points to stay at fixed relative positions to the start/end - point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, - and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. -*/ - -/*! - Creates a curve item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - startDir(createPosition(QLatin1String("startDir"))), - endDir(createPosition(QLatin1String("endDir"))), - end(createPosition(QLatin1String("end"))) -{ - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemCurve::~QCPItemCurve() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemCurve::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemCurve::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemCurve::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemCurve::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF startVec(start->pixelPosition()); - QPointF startDirVec(startDir->pixelPosition()); - QPointF endDirVec(endDir->pixelPosition()); - QPointF endVec(end->pixelPosition()); - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - QPolygonF polygon = cubicPath.toSubpathPolygons().first(); - QCPVector2D p(pos); - double minDistSqr = std::numeric_limits::max(); - for (int i=1; ipixelPosition()); - QCPVector2D startDirVec(startDir->pixelPosition()); - QCPVector2D endDirVec(endDir->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if ((endVec-startVec).length() > 1e10) // too large curves cause crash - return; - - QPainterPath cubicPath(startVec.toPointF()); - cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); - - // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) - { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemCurve::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-curve.cpp' */ - - -/* including file 'src/items/item-rect.cpp', size 6479 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemRect - \brief A rectangle - - \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemRect::~QCPItemRect() -{ -} - -/*! - Sets the pen that will be used to draw the line of the rectangle - - \see setSelectedPen, setBrush -*/ -void QCPItemRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the rectangle when selected - - \see setPen, setSelected -*/ -void QCPItemRect::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemRect::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); -} - -/* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF rect = QRectF(p1, p2).normalized(); - double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemRect::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemRect::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-rect.cpp' */ - - -/* including file 'src/items/item-text.cpp', size 13338 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemText -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemText - \brief A text label - - \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." - - Its position is defined by the member \a position and the setting of \ref setPositionAlignment. - The latter controls which part of the text rect shall be aligned with \a position. - - The text alignment itself (i.e. left, center, right) can be controlled with \ref - setTextAlignment. - - The text may be rotated around the \a position point with \ref setRotation. -*/ - -/*! - Creates a text item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mText(QLatin1String("text")), - mPositionAlignment(Qt::AlignCenter), - mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), - mRotation(0) -{ - position->setCoords(0, 0); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); -} - -QCPItemText::~QCPItemText() -{ -} - -/*! - Sets the color of the text. -*/ -void QCPItemText::setColor(const QColor &color) -{ - mColor = color; -} - -/*! - Sets the color of the text that will be used when the item is selected. -*/ -void QCPItemText::setSelectedColor(const QColor &color) -{ - mSelectedColor = color; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text. To disable the - border, set \a pen to Qt::NoPen. - - \see setSelectedPen, setBrush, setPadding -*/ -void QCPItemText::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text, when the item is - selected. To disable the border, set \a pen to Qt::NoPen. - - \see setPen -*/ -void QCPItemText::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used do fill the background of the text. To disable the - background, set \a brush to Qt::NoBrush. - - \see setSelectedBrush, setPen, setPadding -*/ -void QCPItemText::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the - background, set \a brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemText::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the font of the text. - - \see setSelectedFont, setColor -*/ -void QCPItemText::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the font of the text that will be used when the item is selected. - - \see setFont -*/ -void QCPItemText::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the text that will be displayed. Multi-line texts are supported by inserting a line break - character, e.g. '\n'. - - \see setFont, setColor, setTextAlignment -*/ -void QCPItemText::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets which point of the text rect shall be aligned with \a position. - - Examples: - \li If \a alignment is Qt::AlignHCenter | Qt::AlignTop, the text will be positioned such - that the top of the text rect will be horizontally centered on \a position. - \li If \a alignment is Qt::AlignLeft | Qt::AlignBottom, \a position will indicate the - bottom left corner of the text rect. - - If you want to control the alignment of (multi-lined) text within the text rect, use \ref - setTextAlignment. -*/ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) -{ - mPositionAlignment = alignment; -} - -/*! - Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). -*/ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) -{ - mTextAlignment = alignment; -} - -/*! - Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated - around \a position. -*/ -void QCPItemText::setRotation(double degrees) -{ - mRotation = degrees; -} - -/*! - Sets the distance between the border of the text rectangle and the text. The appearance (and - visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. -*/ -void QCPItemText::setPadding(const QMargins &padding) -{ - mPadding = padding; -} - -/* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - // The rect may be rotated, so we transform the actual clicked pos to the rotated - // coordinate system, so we can use the normal rectDistance function for non-rotated rects: - QPointF positionPixels(position->pixelPosition()); - QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); - - return rectDistance(textBoxRect, rotatedPos, true); -} - -/* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) -{ - QPointF pos(position->pixelPosition()); - QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); - double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) - { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); - } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPosition(int anchorId) const -{ - // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPosition()); - QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) - { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the point that must be given to the QPainter::drawText function (which expects the top - left point of the text rect), according to the position \a pos, the text bounding box \a rect and - the requested \a positionAlignment. - - For example, if \a positionAlignment is Qt::AlignLeft | Qt::AlignBottom the returned point - will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally - drawn at that point, the lower left corner of the resulting text rect is at \a pos. -*/ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const -{ - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) - return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) - result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) - result.ry() -= rect.height(); - return result; -} - -/*! \internal - - Returns the font that should be used for drawing text. Returns mFont when the item is not selected - and mSelectedFont when it is. -*/ -QFont QCPItemText::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the color that should be used for drawing text. Returns mColor when the item is not - selected and mSelectedColor when it is. -*/ -QColor QCPItemText::mainColor() const -{ - return mSelected ? mSelectedColor : mColor; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemText::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemText::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-text.cpp' */ - - -/* including file 'src/items/item-ellipse.cpp', size 7863 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemEllipse -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemEllipse - \brief An ellipse - - \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. -*/ - -/*! - Creates an ellipse item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), - left(createAnchor(QLatin1String("left"), aiLeft)), - center(createAnchor(QLatin1String("center"), aiCenter)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemEllipse::~QCPItemEllipse() -{ -} - -/*! - Sets the pen that will be used to draw the line of the ellipse - - \see setSelectedPen, setBrush -*/ -void QCPItemEllipse::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the ellipse when selected - - \see setPen, setSelected -*/ -void QCPItemEllipse::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemEllipse::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - - // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - double result = qAbs(c-1)*qSqrt(x*x+y*y); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPosition(); - QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); -#ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big - { -#endif - painter->drawEllipse(ellipseRect); -#ifdef __EXCEPTIONS - } catch (...) - { - qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); - } -#endif - } -} - -/* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) - { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemEllipse::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemEllipse::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-ellipse.cpp' */ - - -/* including file 'src/items/item-pixmap.cpp', size 10615 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPixmap - \brief An arbitrary pixmap - - \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will - be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to - fit the rectangle or be drawn aligned to the topLeft position. - - If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown - on the right side of the example image), the pixmap will be flipped in the respective - orientations. -*/ - -/*! - Creates a rectangle item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mScaled(false), - mScaledPixmapInvalidated(true), - mAspectRatioMode(Qt::KeepAspectRatio), - mTransformationMode(Qt::SmoothTransformation) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); -} - -QCPItemPixmap::~QCPItemPixmap() -{ -} - -/*! - Sets the pixmap that will be displayed. -*/ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) -{ - mPixmap = pixmap; - mScaledPixmapInvalidated = true; - if (mPixmap.isNull()) - qDebug() << Q_FUNC_INFO << "pixmap is null"; -} - -/*! - Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a - bottomRight positions. -*/ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) -{ - mScaled = scaled; - mAspectRatioMode = aspectRatioMode; - mTransformationMode = transformationMode; - mScaledPixmapInvalidated = true; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap. - - \see setSelectedPen, setBrush -*/ -void QCPItemPixmap::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap when selected - - \see setPen, setSelected -*/ -void QCPItemPixmap::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return rectDistance(getFinalRect(), pos, true); -} - -/* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) -{ - bool flipHorz = false; - bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); - double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) - { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); - QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) - { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const -{ - bool flipHorz; - bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); - // we actually want denormal rects (negative width/height) here, so restore - // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The - parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped - horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a - bottomRight.) - - This function only creates the scaled pixmap when the buffered pixmap has a different size than - the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does - not cause expensive rescaling every time. - - If scaling is disabled, sets mScaledPixmap to a null QPixmap. -*/ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) -{ - if (mPixmap.isNull()) - return; - - if (mScaled) - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - double devicePixelRatio = mPixmap.devicePixelRatio(); -#else - double devicePixelRatio = 1.0; -#endif - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) - { - mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mScaledPixmap.setDevicePixelRatio(devicePixelRatio); -#endif - } - } else if (!mScaledPixmap.isNull()) - mScaledPixmap = QPixmap(); - mScaledPixmapInvalidated = false; -} - -/*! \internal - - Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions - and scaling settings. - - The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn - flipped horizontally or vertically in the returned rect. (The returned rect itself is always - normalized, i.e. the top left corner of the rect is actually further to the top/left than the - bottom right corner). This is the case when the item position \a topLeft is further to the - bottom/right than \a bottomRight. - - If scaling is disabled, returns a rect with size of the original pixmap and the top left corner - aligned with the item position \a topLeft. The position \a bottomRight is ignored. -*/ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const -{ - QRect result; - bool flipHorz = false; - bool flipVert = false; - QPoint p1 = topLeft->pixelPosition().toPoint(); - QPoint p2 = bottomRight->pixelPosition().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) - { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); - QPoint topLeft = p1; - if (newSize.width() < 0) - { - flipHorz = true; - newSize.rwidth() *= -1; - topLeft.setX(p2.x()); - } - if (newSize.height() < 0) - { - flipVert = true; - newSize.rheight() *= -1; - topLeft.setY(p2.y()); - } - QSize scaledSize = mPixmap.size(); -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - scaledSize /= mPixmap.devicePixelRatio(); - scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); -#else - scaledSize.scale(newSize, mAspectRatioMode); -#endif - result = QRect(topLeft, scaledSize); - } else - { -#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); -#else - result = QRect(p1, mPixmap.size()); -#endif - } - if (flippedHorz) - *flippedHorz = flipHorz; - if (flippedVert) - *flippedVert = flipVert; - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemPixmap::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-pixmap.cpp' */ - - -/* including file 'src/items/item-tracer.cpp', size 14624 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemTracer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemTracer - \brief Item that sticks to QCPGraph data points - - \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." - - The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt - the coordinate axes of the graph and update its \a position to be on the graph's data. This means - the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a - QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a - position will have no effect because they will be overriden in the next redraw (this is when the - coordinate update happens). - - If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will - stay at the corresponding end of the graph. - - With \ref setInterpolating you may specify whether the tracer may only stay exactly on data - points or whether it interpolates data points linearly, if given a key that lies between two data - points of the graph. - - The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer - have no own visual appearance (set the style to \ref tsNone), and just connect other item - positions to the tracer \a position (used as an anchor) via \ref - QCPItemPosition::setParentAnchor. - - \note The tracer position is only automatically updated upon redraws. So when the data of the - graph changes and immediately afterwards (without a redraw) the position coordinates of the - tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref - updatePosition must be called manually, prior to reading the tracer coordinates. -*/ - -/*! - Creates a tracer item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - mSize(6), - mStyle(tsCrosshair), - mGraph(0), - mGraphKey(0), - mInterpolating(false) -{ - position->setCoords(0, 0); - - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemTracer::~QCPItemTracer() -{ -} - -/*! - Sets the pen that will be used to draw the line of the tracer - - \see setSelectedPen, setBrush -*/ -void QCPItemTracer::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the tracer when selected - - \see setPen, setSelected -*/ -void QCPItemTracer::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer - - \see setSelectedBrush, setPen -*/ -void QCPItemTracer::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer, when selected. - - \see setBrush, setSelected -*/ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare - does, \ref tsCrosshair does not). -*/ -void QCPItemTracer::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the style/visual appearance of the tracer. - - If you only want to use the tracer \a position as an anchor for other items, set \a style to - \ref tsNone. -*/ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) -{ - mStyle = style; -} - -/*! - Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type - QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. - - To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed - freely like any other item position. This is the state the tracer will assume when its graph gets - deleted while still attached to it. - - \see setGraphKey -*/ -void QCPItemTracer::setGraph(QCPGraph *graph) -{ - if (graph) - { - if (graph->parentPlot() == mParentPlot) - { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); - mGraph = graph; - updatePosition(); - } else - qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else - { - mGraph = 0; - } -} - -/*! - Sets the key of the graph's data point the tracer will be positioned at. This is the only free - coordinate of a tracer when attached to a graph. - - Depending on \ref setInterpolating, the tracer will be either positioned on the data point - closest to \a key, or will stay exactly at \a key and interpolate the value linearly. - - \see setGraph, setInterpolating -*/ -void QCPItemTracer::setGraphKey(double key) -{ - mGraphKey = key; -} - -/*! - Sets whether the value of the graph's data points shall be interpolated, when positioning the - tracer. - - If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on - the data point of the graph which is closest to the key, but which is not necessarily exactly - there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and - the appropriate value will be interpolated from the graph's data points linearly. - - \see setGraph, setGraphKey -*/ -void QCPItemTracer::setInterpolating(bool enabled) -{ - mInterpolating = enabled; -} - -/* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return -1; - case tsPlus: - { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), - QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), - QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - // distance to border: - double centerDist = QCPVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; - } - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); - } - break; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) -{ - updatePosition(); - if (mStyle == tsNone) - return; - - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPosition()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return; - case tsPlus: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; - } - } -} - -/*! - If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a - position to reside on the graph data, depending on the configured key (\ref setGraphKey). - - It is called automatically on every redraw and normally doesn't need to be called manually. One - exception is when you want to read the tracer coordinates via \a position and are not sure that - the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. - In that situation, call this function before accessing \a position, to make sure you don't get - out-of-date coordinates. - - If there is no graph set on this tracer, this function does nothing. -*/ -void QCPItemTracer::updatePosition() -{ - if (mGraph) - { - if (mParentPlot->hasPlottable(mGraph)) - { - if (mGraph->data()->size() > 1) - { - QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); - QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey <= first->key) - position->setCoords(first->key, first->value); - else if (mGraphKey >= last->key) - position->setCoords(last->key, last->value); - else - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); - if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators - { - QCPGraphDataContainer::const_iterator prevIt = it; - ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before - if (mInterpolating) - { - // interpolate between iterators around mGraphKey: - double slope = 0; - if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) - slope = (it->value-prevIt->value)/(it->key-prevIt->key); - position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); - } else - { - // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt->key+it->key)*0.5) - position->setCoords(prevIt->key, prevIt->value); - else - position->setCoords(it->key, it->value); - } - } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) - position->setCoords(it->key, it->value); - } - } else if (mGraph->data()->size() == 1) - { - QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it->key, it->value); - } else - qDebug() << Q_FUNC_INFO << "graph has no data"; - } else - qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemTracer::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemTracer::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} -/* end of 'src/items/item-tracer.cpp' */ - - -/* including file 'src/items/item-bracket.cpp', size 10687 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemBracket - \brief A bracket for referencing/highlighting certain parts in the plot. - - \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a left and \a right, which define the span of the bracket. If \a left is - actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the - example image. - - The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket - stretches away from the embraced span, can be controlled with \ref setLength. - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
- - It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine - or QCPItemCurve) or a text label (QCPItemText), to the bracket. -*/ - -/*! - Creates a bracket item and sets default values. - - The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes - ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. -*/ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition(QLatin1String("left"))), - right(createPosition(QLatin1String("right"))), - center(createAnchor(QLatin1String("center"), aiCenter)), - mLength(8), - mStyle(bsCalligraphic) -{ - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); -} - -QCPItemBracket::~QCPItemBracket() -{ -} - -/*! - Sets the pen that will be used to draw the bracket. - - Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the - stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use - \ref setLength, which has a similar effect. - - \see setSelectedPen -*/ -void QCPItemBracket::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the bracket when selected - - \see setPen, setSelected -*/ -void QCPItemBracket::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the \a length in pixels how far the bracket extends in the direction towards the embraced - span of the bracket (i.e. perpendicular to the left-right-direction) - - \image html QCPItemBracket-length.png -
Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
-*/ -void QCPItemBracket::setLength(double length) -{ - mLength = length; -} - -/*! - Sets the style of the bracket, i.e. the shape/visual appearance. - - \see setPen -*/ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) -{ - mStyle = style; -} - -/* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QCPVector2D p(pos); - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return -1; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (mStyle) - { - case QCPItemBracket::bsSquare: - case QCPItemBracket::bsRound: - { - double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); - double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); - return qSqrt(qMin(qMin(a, b), c)); - } - case QCPItemBracket::bsCurly: - case QCPItemBracket::bsCalligraphic: - { - double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); - double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); - return qSqrt(qMin(qMin(a, b), qMin(c, d))); - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - QPolygon boundingPoly; - boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) - { - painter->setPen(mainPen()); - switch (mStyle) - { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); - path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const -{ - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) - return leftVec.toPointF(); - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (anchorId) - { - case aiCenter: - return centerVec.toPointF(); - } - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemBracket::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} -/* end of 'src/items/item-bracket.cpp' */ - - From 5ea551a6cc97fd209afedcd67db0e5afdd01aeb4 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:30:22 -0400 Subject: [PATCH 1132/1324] Delete profilepage.cpp --- src/qt/profilepage.cpp | 314 ----------------------------------------- 1 file changed, 314 deletions(-) delete mode 100644 src/qt/profilepage.cpp diff --git a/src/qt/profilepage.cpp b/src/qt/profilepage.cpp deleted file mode 100644 index cc8ac1a0..00000000 --- a/src/qt/profilepage.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "profilepage.h" -#include "ui_profilepage.h" -#include "homepage.h" - -//selim includes -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "QHBoxLayout" -#include "QVBoxLayout" -#include "QLabel" -#include "QSpacerItem" -#include "QPushButton" -#include -#include "posts.h" -#include "QString" -#include -#include "QFontMetrics" -#include "QGroupBox" -#include "QScrollBar" -#include "mainwindow.h" -#include "addcomment.h" -#define POSTSNUMBER 100 -#define COMMENTSNUMBER 3 -#define POSTSATATIME 15 -//_____ - -#include "qprocess.h" - -ProfilePage::ProfilePage(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::ProfilePage) -{ - ui->setupUi(this); - shownPostsNumber = 0; - //pagePosts = makePosts(); - // viewPosts(); - QWidget::setWindowIcon(QIcon(":/new/prefix1/logo.png")); - this->showMaximized(); - this->setWindowTitle("Social Network"); -} - - ProfilePage ::ProfilePage(int userID,QString email): ui(new Ui::ProfilePage) - { - - ui->setupUi(this); - user A; - // ui->lblUserName->setText(A.getUserName(userID)); // dyyy :(((( - ui->lblMail->setText(email);//user file's name is the email of the user - shownPostsNumber = 0; - qDebug()<<"id is "<userName = homePageOwnerMail; - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - HomePage *homePageWindow = new HomePage(); - homePageWindow->setCurrentSessionUser_Ptr(currentSessionUser); - homePageWindow->show(); - this->hide(); -} - - -void ProfilePage::setCurrentSessionUser_Ptr(user *currentSessionUser_ptr) -{ - this->currentSessionUser = currentSessionUser_ptr; - pagePosts = currentSessionUser_ptr->userFileManipulator.getPosts_new(currentSessionUser_ptr->userName); - viewPosts(); - if(homePageOwnerMail != "") - { - fileman x; - QList friendsList = x.getFriends(homePageOwnerMail); - for(QList::iterator it = friendsList.begin(); it != friendsList.end(); it++) - { - if(*it == currentSessionUser_ptr->userName) - { - ui->addFriendBtn->setEnabled(false); - break; - } - } - } -} - -//Selim functions -void ProfilePage::viewPosts() -{ - ui->lblUserName->setText(currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName)); - ui->lblMail->setText(currentSessionUser->userName); - ui->labelNumber->setText(QString::number(currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName).size()/3)); - QList friendsList = currentSessionUser->userFileManipulator.getFriends(currentSessionUser->userName); - if(homePageOwnerMail == "") - ui->addFriendBtn->setEnabled(false); - int j,k; - for(j = 1; j < friendsList.size() - 1; j = j + 3) - { - ui->friendsComboBox->addItem(friendsList[j]); - } - static QVBoxLayout *ParentVerticalLayout = new QVBoxLayout; - qDebug("now"); - QList oldPosts = ui->scrollAreaWidgetContents->children(); - for(int i = 1; i < oldPosts.size(); i++) - delete oldPosts[i]; - for(k = shownPostsNumber; k < pagePosts->size() && shownPostsNumber < k + POSTSATATIME; k++,shownPostsNumber++) - { - QGroupBox *postframe = new QGroupBox; - //postframe->setObjectName("frame"+QString::number(k)); - QVBoxLayout *postLayout = new QVBoxLayout; - postframe->setLayout(postLayout); - postframe->setStyleSheet("background-color: rgb(255, 255, 255);"); - QLabel *postOwner = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"); - QLabel *postDate = new QLabel((*pagePosts)[shownPostsNumber].getPostOwner()+":"+(*pagePosts)[shownPostsNumber].getPostDate()); - postLayout->addWidget(postDate); - QTextBrowser *postBody = new QTextBrowser; - postBody->setText((*pagePosts)[k].getPostText()); /////////// shownPostsNumber - QFontMetrics font_metrics(postBody->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? -Added - int height = font_height * 6; - postBody->setMinimumHeight(height); - postBody->setMaximumHeight(height); - postLayout->addWidget(postBody); - ParentVerticalLayout->addWidget(postframe); - QHBoxLayout *likeAndComment = new QHBoxLayout; - QPushButton *like = new QPushButton("Like"); - like->setObjectName("LikeButton"+QString::number(shownPostsNumber)); - connect(like,SIGNAL(clicked(bool)),this,SLOT(on_LikeButton_clicked())); - like->setStyleSheet("background-color: rgb(c0,c6,c8);"); - QPushButton *comment = new QPushButton("Comment",postframe); - comment->setObjectName("CommentButton"+QString::number(shownPostsNumber)); - connect(comment,SIGNAL(clicked(bool)),this,SLOT(on_CommentButton_clicked())); - comment->setStyleSheet("background-color: rgb(c0,c6,c8);"); - likeAndComment->addWidget(like); - likeAndComment->addWidget(comment); - postLayout->addLayout(likeAndComment); - std::vector* likesOwnersVector_Ptr = (*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr(); - for(int cnt = 0; cnt < likesOwnersVector_Ptr->size(); cnt++) - { - if((currentSessionUser->userName == (*likesOwnersVector_Ptr)[cnt] && homePageOwnerMail == "") || (homePageOwnerMail == (*likesOwnersVector_Ptr)[cnt])) - { - like->setEnabled(false); - break; - } - } - QPushButton *likesOwners = new QPushButton(QString::number((*pagePosts)[shownPostsNumber].getPostLikesOwnersVectorPtr()->size()) - +" people are liking this!"); - likesOwners->setObjectName("likesOwnersButton"); - connect(likesOwners,SIGNAL(clicked(bool)),this,SLOT(on_likesOwners_clicked())); - QHBoxLayout *likesOwnersLayout = new QHBoxLayout; - likesOwnersLayout->addWidget(likesOwners); - postLayout->addLayout(likesOwnersLayout); - for(j = 0; j < (*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()->size(); j++) - { - QHBoxLayout *commentLayout = new QHBoxLayout; - QLabel *commentOwner = new QLabel ((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentOwner()); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBody = new QTextBrowser; - commentBody->setText((*((*pagePosts)[shownPostsNumber].getPostCommentsVectorPtr()))[j].getCommentText()); - commentBody->setMinimumHeight(height); - commentBody->setMaximumHeight(height); - commentLayout->addWidget(commentBody); - postLayout->addLayout(commentLayout); - } - QFrame* line = new QFrame(); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - ParentVerticalLayout->addWidget(line); - } - ParentVerticalLayout->addSpacerItem(new QSpacerItem(20,40,QSizePolicy::Fixed,QSizePolicy::Expanding)); - ui->scrollAreaWidgetContents->setLayout(ParentVerticalLayout); - //connect(ui->PostsArea,SIGNAL(ui->PostsArea->scroll(50,50)),this,SLOT(close())); - QScrollBar *verticalScrollBar = ui->PostsArea->verticalScrollBar(); - connect(verticalScrollBar,SIGNAL(valueChanged(int)),this,SLOT(viewMorePosts(int))); -} -void ProfilePage::on_LikeButton_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - button->setEnabled(false); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - if(homePageOwnerMail == "") - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , currentSessionUser->userName); - else - currentSessionUser->userFileManipulator.addLikeByPostDate(labelString.mid(0,labelString.indexOf(":")), - labelString.mid(labelString.indexOf(":") + 1) , homePageOwnerMail); - int postsNumber,likesNumber; - currentSessionUser->userFileManipulator.getActivity(currentSessionUser->userName,postsNumber,likesNumber); - currentSessionUser->userFileManipulator.updateActivity(currentSessionUser->userName,++likesNumber,0); - -} -void ProfilePage::on_CommentButton_clicked() -{ - QString commentBody; - QVBoxLayout *postLayout; - AddComment commentWindow; - commentWindow.setModal(true); - commentWindow.exec(); - commentBody = commentWindow.getCommentBody(); - qDebug(commentBody.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QHBoxLayout *commentLayout = new QHBoxLayout; - QString commentOwnerName = currentSessionUser->userFileManipulator.getUserNameByEmail(currentSessionUser->userName); - QLabel *commentOwner = new QLabel (commentOwnerName); - commentLayout->addWidget(commentOwner); - QTextBrowser *commentBodyTextBrowser = new QTextBrowser; - commentBodyTextBrowser->setText(commentBody); - QFontMetrics font_metrics(commentBodyTextBrowser->font()); - int font_height = font_metrics.height(); - // Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin? - int height = font_height * 2; - commentBodyTextBrowser->setMinimumHeight(height); - commentBodyTextBrowser->setMaximumHeight(height); - commentLayout->addWidget(commentBodyTextBrowser); - postLayout->addLayout(commentLayout); - /*QLabel labelInfo = *(qobject_cast*/QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - qDebug(labelString.toLatin1()); - currentSessionUser->userFileManipulator.addCommentByPostDate(commentBody,labelString.mid(labelString.indexOf(":") + 1,labelString.length()) - ,currentSessionUser->userName,labelString.mid(0,labelString.indexOf(":"))); -} - -void ProfilePage::on_likesOwners_clicked() -{ - QVBoxLayout *postLayout; - QPushButton *button = qobject_cast( QObject::sender() ); - QString name = button->objectName(); - qDebug(name.toLatin1()); - QGroupBox *postframe = qobject_cast (QObject::sender()->parent()); - postLayout = qobject_cast (postframe->layout()); - QObject* labelObject = (postframe->children()[1]); - QLabel* commentLabel = qobject_cast (labelObject); - QString labelString = commentLabel->text(); - QList *userPosts = currentSessionUser->userFileManipulator.getPosts_new(labelString.mid(0,labelString.indexOf(":"))); - QScrollArea* likesOwners = new QScrollArea; - QVBoxLayout* scrollingAreaLayout = new QVBoxLayout; - likesOwners->setLayout(scrollingAreaLayout); - for(QList::iterator it = userPosts->begin(); it != userPosts->end(); it++) - { - if(it->getPostDate() == labelString.mid(labelString.indexOf(":") + 1)) - { - std::vector* likesVector = it->getPostLikesOwnersVectorPtr(); - for(int i = 0; i < likesVector->size(); i++) - { - QLabel* userLabel = new QLabel((*likesVector)[i]); - scrollingAreaLayout->addWidget(userLabel); - } - } - } - likesOwners->show(); -} - -void ProfilePage::viewMorePosts(int i) -{ - QScrollBar *bar = qobject_cast (QObject::sender()); - int max = bar ->maximum(); - if (i > .9 * max && shownPostsNumber != (*pagePosts).size()) - { - viewPosts(); - } -} - - - -void ProfilePage::on_Post_btn_clicked() -{ - QString postText = ui->newPost_txtEdit->toPlainText(); -// currentSessionUser.userFileManipulator.addPost(postText); - Date Now; - Post recentlyAddedPost = Post(currentSessionUser->userName,postText,Now.getDateNow()); - pagePosts->push_front(recentlyAddedPost); - shownPostsNumber = 0; - // clear the post area - //ui->PostsArea-> - viewPosts(); - currentSessionUser->userFileManipulator.addPost_new(postText,Now.getDateNow(),currentSessionUser->userName); -} - -void ProfilePage::setHomePageOwnerMail(QString owner) -{ - homePageOwnerMail = owner; - ui->newPost_txtEdit->setVisible(false); - ui->Post_btn->setVisible(false); -} - - -void ProfilePage::on_addFriendBtn_clicked() -{ - currentSessionUser->userFileManipulator.addFriends(homePageOwnerMail,ui->lblMail->text()); - ui->addFriendBtn->setEnabled(false); -} - -void ProfilePage::on_actionLog_out_triggered() -{ - qApp->quit(); - QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); -} From 7c7a71a2234cda54545633c1d3c3278e321e26a0 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:30:38 -0400 Subject: [PATCH 1133/1324] Delete qcustomplot.h --- src/qt/qcustomplot.h | 6661 ------------------------------------------ 1 file changed, 6661 deletions(-) delete mode 100644 src/qt/qcustomplot.h diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h deleted file mode 100644 index ba91eea1..00000000 --- a/src/qt/qcustomplot.h +++ /dev/null @@ -1,6661 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2017 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 04.09.17 ** -** Version: 2.0.0 ** -****************************************************************************/ - -#ifndef QCUSTOMPLOT_H -#define QCUSTOMPLOT_H - -#include - -// some Qt version/configuration dependent macros to include or exclude certain code paths: -#ifdef QCUSTOMPLOT_USE_OPENGL -# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# define QCP_OPENGL_PBUFFER -# else -# define QCP_OPENGL_FBO -# endif -# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) -# define QCP_OPENGL_OFFSCREENSURFACE -# endif -#endif - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) -# define QCP_DEVICEPIXELRATIO_SUPPORTED -# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) -# define QCP_DEVICEPIXELRATIO_FLOAT -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef QCP_OPENGL_FBO -# include -# include -# ifdef QCP_OPENGL_OFFSCREENSURFACE -# include -# else -# include -# endif -#endif -#ifdef QCP_OPENGL_PBUFFER -# include -#endif -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# include -# include -# include -# include -#else -# include -# include -# include -#endif - -class QCPPainter; -class QCustomPlot; -class QCPLayerable; -class QCPLayoutElement; -class QCPLayout; -class QCPAxis; -class QCPAxisRect; -class QCPAxisPainterPrivate; -class QCPAbstractPlottable; -class QCPGraph; -class QCPAbstractItem; -class QCPPlottableInterface1D; -class QCPLegend; -class QCPItemPosition; -class QCPLayer; -class QCPAbstractLegendItem; -class QCPSelectionRect; -class QCPColorMap; -class QCPColorScale; -class QCPBars; - -/* including file 'src/global.h', size 16225 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -// decl definitions for shared library compilation/usage: -#if defined(QCUSTOMPLOT_COMPILE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_EXPORT -#elif defined(QCUSTOMPLOT_USE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_IMPORT -#else -# define QCP_LIB_DECL -#endif - -// define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5) -#ifndef Q_DECL_OVERRIDE -# define Q_DECL_OVERRIDE -#endif - -/*! - The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot - library. - - It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. -*/ -#ifndef Q_MOC_RUN -namespace QCP { -#else -class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace - Q_GADGET - Q_ENUMS(ExportPen) - Q_ENUMS(ResolutionUnit) - Q_ENUMS(SignDomain) - Q_ENUMS(MarginSide) - Q_FLAGS(MarginSides) - Q_ENUMS(AntialiasedElement) - Q_FLAGS(AntialiasedElements) - Q_ENUMS(PlottingHint) - Q_FLAGS(PlottingHints) - Q_ENUMS(Interaction) - Q_FLAGS(Interactions) - Q_ENUMS(SelectionRectMode) - Q_ENUMS(SelectionType) -public: -#endif - -/*! - Defines the different units in which the image resolution can be specified in the export - functions. - - \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered -*/ -enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) - ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) - ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) - }; - -/*! - Defines how cosmetic pens (pens with numerical width 0) are handled during export. - - \see QCustomPlot::savePdf -*/ -enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting - ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) - }; - -/*! - Represents negative and positive sign domain, e.g. for passing to \ref - QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange. - - This is primarily needed when working with logarithmic axis scales, since only one of the sign - domains can be visible at a time. -*/ -enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero - ,sdBoth ///< Both sign domains, including zero, i.e. all numbers - ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero - }; - -/*! - Defines the sides of a rectangular entity to which margins can be applied. - - \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins -*/ -enum MarginSide { msLeft = 0x01 ///< 0x01 left margin - ,msRight = 0x02 ///< 0x02 right margin - ,msTop = 0x04 ///< 0x04 top margin - ,msBottom = 0x08 ///< 0x08 bottom margin - ,msAll = 0xFF ///< 0xFF all margins - ,msNone = 0x00 ///< 0x00 no margin - }; -Q_DECLARE_FLAGS(MarginSides, MarginSide) - -/*! - Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is - neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective - element how it is drawn. Typically it provides a \a setAntialiased function for this. - - \c AntialiasedElements is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements -*/ -enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks - ,aeGrid = 0x0002 ///< 0x0002 Grid lines - ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines - ,aeLegend = 0x0008 ///< 0x0008 Legend box - ,aeLegendItems = 0x0010 ///< 0x0010 Legend items - ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables - ,aeItems = 0x0040 ///< 0x0040 Main lines of items - ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) - ,aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) - ,aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen - ,aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories - ,aeAll = 0xFFFF ///< 0xFFFF All elements - ,aeNone = 0x0000 ///< 0x0000 No elements - }; -Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) - -/*! - Defines plotting hints that control various aspects of the quality and speed of plotting. - - \see QCustomPlot::setPlottingHints -*/ -enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set - ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment - ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. - ,phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. - ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). - ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. - }; -Q_DECLARE_FLAGS(PlottingHints, PlottingHint) - -/*! - Defines the mouse interactions possible with QCustomPlot. - - \c Interactions is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setInteractions -*/ -enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) - ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) - ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking - ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) - ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) - ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) - ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) - ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) - }; -Q_DECLARE_FLAGS(Interactions, Interaction) - -/*! - Defines the behaviour of the selection rect. - - \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect -*/ -enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging - ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. - ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) - ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's Q_SIGNALS (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. - }; - -/*! - Defines the different ways a plottable can be selected. These images show the effect of the - different selection types, when the indicated selection rect was dragged: - -
- - - - - - - - -
\image html selectiontype-none.png stNone\image html selectiontype-whole.png stWhole\image html selectiontype-singledata.png stSingleData\image html selectiontype-datarange.png stDataRange\image html selectiontype-multipledataranges.png stMultipleDataRanges
-
- - \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType -*/ -enum SelectionType { stNone ///< The plottable is not selectable - ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. - ,stSingleData ///< One individual data point can be selected at a time - ,stDataRange ///< Multiple contiguous data points (a data range) can be selected - ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected - }; - -/*! \internal - - Returns whether the specified \a value is considered an invalid data value for plottables (i.e. - is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the - compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. -*/ -inline bool isInvalidData(double value) -{ - return qIsNaN(value) || qIsInf(value); -} - -/*! \internal - \overload - - Checks two arguments instead of one. -*/ -inline bool isInvalidData(double value1, double value2) -{ - return isInvalidData(value1) || isInvalidData(value2); -} - -/*! \internal - - Sets the specified \a side of \a margins to \a value - - \see getMarginValue -*/ -inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) -{ - switch (side) - { - case QCP::msLeft: margins.setLeft(value); break; - case QCP::msRight: margins.setRight(value); break; - case QCP::msTop: margins.setTop(value); break; - case QCP::msBottom: margins.setBottom(value); break; - case QCP::msAll: margins = QMargins(value, value, value, value); break; - default: break; - } -} - -/*! \internal - - Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or - \ref QCP::msAll, returns 0. - - \see setMarginValue -*/ -inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return margins.left(); - case QCP::msRight: return margins.right(); - case QCP::msTop: return margins.top(); - case QCP::msBottom: return margins.bottom(); - default: break; - } - return 0; -} - - -extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace - -} // end of namespace QCP -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) -Q_DECLARE_METATYPE(QCP::ExportPen) -Q_DECLARE_METATYPE(QCP::ResolutionUnit) -Q_DECLARE_METATYPE(QCP::SignDomain) -Q_DECLARE_METATYPE(QCP::MarginSide) -Q_DECLARE_METATYPE(QCP::AntialiasedElement) -Q_DECLARE_METATYPE(QCP::PlottingHint) -Q_DECLARE_METATYPE(QCP::Interaction) -Q_DECLARE_METATYPE(QCP::SelectionRectMode) -Q_DECLARE_METATYPE(QCP::SelectionType) - -/* end of 'src/global.h' */ - - -/* including file 'src/vector2d.h', size 4928 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPVector2D -{ -public: - QCPVector2D(); - QCPVector2D(double x, double y); - QCPVector2D(const QPoint &point); - QCPVector2D(const QPointF &point); - - // getters: - double x() const { return mX; } - double y() const { return mY; } - double &rx() { return mX; } - double &ry() { return mY; } - - // setters: - void setX(double x) { mX = x; } - void setY(double y) { mY = y; } - - // non-virtual methods: - double length() const { return qSqrt(mX*mX+mY*mY); } - double lengthSquared() const { return mX*mX+mY*mY; } - QPoint toPoint() const { return QPoint(mX, mY); } - QPointF toPointF() const { return QPointF(mX, mY); } - - bool isNull() const { return qIsNull(mX) && qIsNull(mY); } - void normalize(); - QCPVector2D normalized() const; - QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); } - double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; } - double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const; - double distanceSquaredToLine(const QLineF &line) const; - double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const; - - QCPVector2D &operator*=(double factor); - QCPVector2D &operator/=(double divisor); - QCPVector2D &operator+=(const QCPVector2D &vector); - QCPVector2D &operator-=(const QCPVector2D &vector); - -private: - // property members: - double mX, mY; - - friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec); - friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor); - friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor); - friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec); -}; -Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE); - -inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); } -inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); } - -/*! \relates QCPVector2D - - Prints \a vec in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPVector2D &vec) -{ - d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; - return d.space(); -} - -/* end of 'src/vector2d.h' */ - - -/* including file 'src/painter.h', size 4035 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPPainter : public QPainter -{ - Q_GADGET -public: - /*! - Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, - depending on whether they are wanted on the respective output device. - */ - enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices - ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. - ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels - ,pmNonCosmetic = 0x04 ///< 0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.) - }; - Q_ENUMS(PainterMode) - Q_FLAGS(PainterModes) - Q_DECLARE_FLAGS(PainterModes, PainterMode) - - QCPPainter(); - explicit QCPPainter(QPaintDevice *device); - - // getters: - bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } - PainterModes modes() const { return mModes; } - - // setters: - void setAntialiasing(bool enabled); - void setMode(PainterMode mode, bool enabled=true); - void setModes(PainterModes modes); - - // methods hiding non-virtual base class functions (QPainter bug workarounds): - bool begin(QPaintDevice *device); - void setPen(const QPen &pen); - void setPen(const QColor &color); - void setPen(Qt::PenStyle penStyle); - void drawLine(const QLineF &line); - void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} - void save(); - void restore(); - - // non-virtual methods: - void makeNonCosmetic(); - -protected: - // property members: - PainterModes mModes; - bool mIsAntialiasing; - - // non-property members: - QStack mAntialiasingStack; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) -Q_DECLARE_METATYPE(QCPPainter::PainterMode) - -/* end of 'src/painter.h' */ - - -/* including file 'src/paintbuffer.h', size 4958 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAbstractPaintBuffer -{ -public: - explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio); - virtual ~QCPAbstractPaintBuffer(); - - // getters: - QSize size() const { return mSize; } - bool invalidated() const { return mInvalidated; } - double devicePixelRatio() const { return mDevicePixelRatio; } - - // setters: - void setSize(const QSize &size); - void setInvalidated(bool invalidated=true); - void setDevicePixelRatio(double ratio); - - // introduced virtual methods: - virtual QCPPainter *startPainting() = 0; - virtual void donePainting() {} - virtual void draw(QCPPainter *painter) const = 0; - virtual void clear(const QColor &color) = 0; - -protected: - // property members: - QSize mSize; - double mDevicePixelRatio; - - // non-property members: - bool mInvalidated; - - // introduced virtual methods: - virtual void reallocateBuffer() = 0; -}; - - -class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio); - virtual ~QCPPaintBufferPixmap(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QPixmap mBuffer; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; - - -#ifdef QCP_OPENGL_PBUFFER -class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples); - virtual ~QCPPaintBufferGlPbuffer(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QGLPixelBuffer *mGlPBuffer; - int mMultisamples; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; -#endif // QCP_OPENGL_PBUFFER - - -#ifdef QCP_OPENGL_FBO -class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer -{ -public: - explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice); - virtual ~QCPPaintBufferGlFbo(); - - // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void donePainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - -protected: - // non-property members: - QWeakPointer mGlContext; - QWeakPointer mGlPaintDevice; - QOpenGLFramebufferObject *mGlFrameBuffer; - - // reimplemented virtual methods: - virtual void reallocateBuffer() Q_DECL_OVERRIDE; -}; -#endif // QCP_OPENGL_FBO - -/* end of 'src/paintbuffer.h' */ - - -/* including file 'src/layer.h', size 6885 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPLayer : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(int index READ index) - Q_PROPERTY(QList children READ children) - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(LayerMode mode READ mode WRITE setMode) - /// \endcond -public: - - /*! - Defines the different rendering modes of a layer. Depending on the mode, certain layers can be - replotted individually, without the need to replot (possibly complex) layerables on other - layers. - - \see setMode - */ - enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. - ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). - }; - Q_ENUMS(LayerMode) - - QCPLayer(QCustomPlot* parentPlot, const QString &layerName); - virtual ~QCPLayer(); - - // getters: - QCustomPlot *parentPlot() const { return mParentPlot; } - QString name() const { return mName; } - int index() const { return mIndex; } - QList children() const { return mChildren; } - bool visible() const { return mVisible; } - LayerMode mode() const { return mMode; } - - // setters: - void setVisible(bool visible); - void setMode(LayerMode mode); - - // non-virtual methods: - void replot(); - -protected: - // property members: - QCustomPlot *mParentPlot; - QString mName; - int mIndex; - QList mChildren; - bool mVisible; - LayerMode mMode; - - // non-property members: - QWeakPointer mPaintBuffer; - - // non-virtual methods: - void draw(QCPPainter *painter); - void drawToPaintBuffer(); - void addChild(QCPLayerable *layerable, bool prepend); - void removeChild(QCPLayerable *layerable); - -private: - Q_DISABLE_COPY(QCPLayer) - - friend class QCustomPlot; - friend class QCPLayerable; -}; -Q_DECLARE_METATYPE(QCPLayer::LayerMode) - -class QCP_LIB_DECL QCPLayerable : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) - Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) - Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) - /// \endcond -public: - QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0); - virtual ~QCPLayerable(); - - // getters: - bool visible() const { return mVisible; } - QCustomPlot *parentPlot() const { return mParentPlot; } - QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } - QCPLayer *layer() const { return mLayer; } - bool antialiased() const { return mAntialiased; } - - // setters: - void setVisible(bool on); - Q_SLOT bool setLayer(QCPLayer *layer); - bool setLayer(const QString &layerName); - void setAntialiased(bool enabled); - - // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-property methods: - bool realVisibility() const; - -Q_SIGNALS: - void layerChanged(QCPLayer *newLayer); - -protected: - // property members: - bool mVisible; - QCustomPlot *mParentPlot; - QPointer mParentLayerable; - QCPLayer *mLayer; - bool mAntialiased; - - // introduced virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot); - virtual QCP::Interaction selectionCategory() const; - virtual QRect clipRect() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; - virtual void draw(QCPPainter *painter) = 0; - // selection events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - // low-level mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details); - virtual void wheelEvent(QWheelEvent *event); - - // non-property methods: - void initializeParentPlot(QCustomPlot *parentPlot); - void setParentLayerable(QCPLayerable* parentLayerable); - bool moveToLayer(QCPLayer *layer, bool prepend); - void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; - -private: - Q_DISABLE_COPY(QCPLayerable) - - friend class QCustomPlot; - friend class QCPLayer; - friend class QCPAxisRect; -}; - -/* end of 'src/layer.h' */ - - -/* including file 'src/axis/range.h', size 5280 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPRange -{ -public: - double lower, upper; - - QCPRange(); - QCPRange(double lower, double upper); - - bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; } - bool operator!=(const QCPRange& other) const { return !(*this == other); } - - QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } - QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } - QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } - QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } - friend inline const QCPRange operator+(const QCPRange&, double); - friend inline const QCPRange operator+(double, const QCPRange&); - friend inline const QCPRange operator-(const QCPRange& range, double value); - friend inline const QCPRange operator*(const QCPRange& range, double value); - friend inline const QCPRange operator*(double value, const QCPRange& range); - friend inline const QCPRange operator/(const QCPRange& range, double value); - - double size() const { return upper-lower; } - double center() const { return (upper+lower)*0.5; } - void normalize() { if (lower > upper) qSwap(lower, upper); } - void expand(const QCPRange &otherRange); - void expand(double includeCoord); - QCPRange expanded(const QCPRange &otherRange) const; - QCPRange expanded(double includeCoord) const; - QCPRange bounded(double lowerBound, double upperBound) const; - QCPRange sanitizedForLogScale() const; - QCPRange sanitizedForLinScale() const; - bool contains(double value) const { return value >= lower && value <= upper; } - - static bool validRange(double lower, double upper); - static bool validRange(const QCPRange &range); - static const double minRange; - static const double maxRange; - -}; -Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); - -/*! \relates QCPRange - - Prints \a range in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPRange &range) -{ - d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; - return d.space(); -} - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(const QCPRange& range, double value) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(double value, const QCPRange& range) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Subtracts \a value from both boundaries of the range. -*/ -inline const QCPRange operator-(const QCPRange& range, double value) -{ - QCPRange result(range); - result -= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(const QCPRange& range, double value) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(double value, const QCPRange& range) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Divides both boundaries of the range by \a value. -*/ -inline const QCPRange operator/(const QCPRange& range, double value) -{ - QCPRange result(range); - result /= value; - return result; -} - -/* end of 'src/axis/range.h' */ - - -/* including file 'src/selection.h', size 8579 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPDataRange -{ -public: - QCPDataRange(); - QCPDataRange(int begin, int end); - - bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; } - bool operator!=(const QCPDataRange& other) const { return !(*this == other); } - - // getters: - int begin() const { return mBegin; } - int end() const { return mEnd; } - int size() const { return mEnd-mBegin; } - int length() const { return size(); } - - // setters: - void setBegin(int begin) { mBegin = begin; } - void setEnd(int end) { mEnd = end; } - - // non-property methods: - bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); } - bool isEmpty() const { return length() == 0; } - QCPDataRange bounded(const QCPDataRange &other) const; - QCPDataRange expanded(const QCPDataRange &other) const; - QCPDataRange intersection(const QCPDataRange &other) const; - QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); } - bool intersects(const QCPDataRange &other) const; - bool contains(const QCPDataRange &other) const; - -private: - // property members: - int mBegin, mEnd; - -}; -Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE); - - -class QCP_LIB_DECL QCPDataSelection -{ -public: - explicit QCPDataSelection(); - explicit QCPDataSelection(const QCPDataRange &range); - - bool operator==(const QCPDataSelection& other) const; - bool operator!=(const QCPDataSelection& other) const { return !(*this == other); } - QCPDataSelection &operator+=(const QCPDataSelection& other); - QCPDataSelection &operator+=(const QCPDataRange& other); - QCPDataSelection &operator-=(const QCPDataSelection& other); - QCPDataSelection &operator-=(const QCPDataRange& other); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b); - - // getters: - int dataRangeCount() const { return mDataRanges.size(); } - int dataPointCount() const; - QCPDataRange dataRange(int index=0) const; - QList dataRanges() const { return mDataRanges; } - QCPDataRange span() const; - - // non-property methods: - void addDataRange(const QCPDataRange &dataRange, bool simplify=true); - void clear(); - bool isEmpty() const { return mDataRanges.isEmpty(); } - void simplify(); - void enforceType(QCP::SelectionType type); - bool contains(const QCPDataSelection &other) const; - QCPDataSelection intersection(const QCPDataRange &other) const; - QCPDataSelection intersection(const QCPDataSelection &other) const; - QCPDataSelection inverse(const QCPDataRange &outerRange) const; - -private: - // property members: - QList mDataRanges; - - inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); } -}; -Q_DECLARE_METATYPE(QCPDataSelection) - - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. - The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). -*/ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result += b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! - Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. -*/ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b) -{ - QCPDataSelection result(a); - result -= b; - return result; -} - -/*! \relates QCPDataRange - - Prints \a dataRange in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) -{ - d.nospace() << "[" << dataRange.begin() << ".." << dataRange.end()-1 << "]"; - return d.space(); -} - -/*! \relates QCPDataSelection - - Prints \a selection in a human readable format to the qDebug output. -*/ -inline QDebug operator<< (QDebug d, const QCPDataSelection &selection) -{ - d.nospace() << "QCPDataSelection("; - for (int i=0; i elements(QCP::MarginSide side) const { return mChildren.value(side); } - bool isEmpty() const; - void clear(); - -protected: - // non-property members: - QCustomPlot *mParentPlot; - QHash > mChildren; - - // introduced virtual methods: - virtual int commonMargin(QCP::MarginSide side) const; - - // non-virtual methods: - void addChild(QCP::MarginSide side, QCPLayoutElement *element); - void removeChild(QCP::MarginSide side, QCPLayoutElement *element); - -private: - Q_DISABLE_COPY(QCPMarginGroup) - - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLayout* layout READ layout) - Q_PROPERTY(QRect rect READ rect) - Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) - Q_PROPERTY(QMargins margins READ margins WRITE setMargins) - Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) - Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) - Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) - Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect) - /// \endcond -public: - /*! - Defines the phases of the update process, that happens just before a replot. At each phase, - \ref update is called with the according UpdatePhase value. - */ - enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout - ,upMargins ///< Phase in which the margins are calculated and set - ,upLayout ///< Final phase in which the layout system places the rects of the elements - }; - Q_ENUMS(UpdatePhase) - - /*! - Defines to which rect of a layout element the size constraints that can be set via \ref - setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the - margins (e.g. in the case of a QCPAxisRect the axis labels), whereas the inner rect (\ref rect) - does not. - - \see setSizeConstraintRect - */ - enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect - , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins - }; - Q_ENUMS(SizeConstraintRect) - - explicit QCPLayoutElement(QCustomPlot *parentPlot=0); - virtual ~QCPLayoutElement(); - - // getters: - QCPLayout *layout() const { return mParentLayout; } - QRect rect() const { return mRect; } - QRect outerRect() const { return mOuterRect; } - QMargins margins() const { return mMargins; } - QMargins minimumMargins() const { return mMinimumMargins; } - QCP::MarginSides autoMargins() const { return mAutoMargins; } - QSize minimumSize() const { return mMinimumSize; } - QSize maximumSize() const { return mMaximumSize; } - SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; } - QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } - QHash marginGroups() const { return mMarginGroups; } - - // setters: - void setOuterRect(const QRect &rect); - void setMargins(const QMargins &margins); - void setMinimumMargins(const QMargins &margins); - void setAutoMargins(QCP::MarginSides sides); - void setMinimumSize(const QSize &size); - void setMinimumSize(int width, int height); - void setMaximumSize(const QSize &size); - void setMaximumSize(int width, int height); - void setSizeConstraintRect(SizeConstraintRect constraintRect); - void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); - - // introduced virtual methods: - virtual void update(UpdatePhase phase); - virtual QSize minimumOuterSizeHint() const; - virtual QSize maximumOuterSizeHint() const; - virtual QList elements(bool recursive) const; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - -protected: - // property members: - QCPLayout *mParentLayout; - QSize mMinimumSize, mMaximumSize; - SizeConstraintRect mSizeConstraintRect; - QRect mRect, mOuterRect; - QMargins mMargins, mMinimumMargins; - QCP::MarginSides mAutoMargins; - QHash mMarginGroups; - - // introduced virtual methods: - virtual int calculateAutoMargin(QCP::MarginSide side); - virtual void layoutChanged(); - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPLayoutElement) - - friend class QCustomPlot; - friend class QCPLayout; - friend class QCPMarginGroup; -}; -Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase) - - -class QCP_LIB_DECL QCPLayout : public QCPLayoutElement -{ - Q_OBJECT -public: - explicit QCPLayout(); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual int elementCount() const = 0; - virtual QCPLayoutElement* elementAt(int index) const = 0; - virtual QCPLayoutElement* takeAt(int index) = 0; - virtual bool take(QCPLayoutElement* element) = 0; - virtual void simplify(); - - // non-virtual methods: - bool removeAt(int index); - bool remove(QCPLayoutElement* element); - void clear(); - -protected: - // introduced virtual methods: - virtual void updateLayout(); - - // non-virtual methods: - void sizeConstraintsChanged() const; - void adoptElement(QCPLayoutElement *el); - void releaseElement(QCPLayoutElement *el); - QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const; - static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el); - static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el); - -private: - Q_DISABLE_COPY(QCPLayout) - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(int rowCount READ rowCount) - Q_PROPERTY(int columnCount READ columnCount) - Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) - Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder) - Q_PROPERTY(int wrap READ wrap WRITE setWrap) - /// \endcond -public: - - /*! - Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*). - The column/row at which wrapping into the next row/column occurs can be specified with \ref - setWrap. - - \see setFillOrder - */ - enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. - ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. - }; - Q_ENUMS(FillOrder) - - explicit QCPLayoutGrid(); - virtual ~QCPLayoutGrid(); - - // getters: - int rowCount() const { return mElements.size(); } - int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } - QList columnStretchFactors() const { return mColumnStretchFactors; } - QList rowStretchFactors() const { return mRowStretchFactors; } - int columnSpacing() const { return mColumnSpacing; } - int rowSpacing() const { return mRowSpacing; } - int wrap() const { return mWrap; } - FillOrder fillOrder() const { return mFillOrder; } - - // setters: - void setColumnStretchFactor(int column, double factor); - void setColumnStretchFactors(const QList &factors); - void setRowStretchFactor(int row, double factor); - void setRowStretchFactors(const QList &factors); - void setColumnSpacing(int pixels); - void setRowSpacing(int pixels); - void setWrap(int count); - void setFillOrder(FillOrder order, bool rearrange=true); - - // reimplemented virtual methods: - virtual void updateLayout() Q_DECL_OVERRIDE; - virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); } - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - virtual void simplify() Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; - - // non-virtual methods: - QCPLayoutElement *element(int row, int column) const; - bool addElement(int row, int column, QCPLayoutElement *element); - bool addElement(QCPLayoutElement *element); - bool hasElement(int row, int column); - void expandTo(int newRowCount, int newColumnCount); - void insertRow(int newIndex); - void insertColumn(int newIndex); - int rowColToIndex(int row, int column) const; - void indexToRowCol(int index, int &row, int &column) const; - -protected: - // property members: - QList > mElements; - QList mColumnStretchFactors; - QList mRowStretchFactors; - int mColumnSpacing, mRowSpacing; - int mWrap; - FillOrder mFillOrder; - - // non-virtual methods: - void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; - void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; - -private: - Q_DISABLE_COPY(QCPLayoutGrid) -}; -Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) - - -class QCP_LIB_DECL QCPLayoutInset : public QCPLayout -{ - Q_OBJECT -public: - /*! - Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. - */ - enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect - ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment - }; - Q_ENUMS(InsetPlacement) - - explicit QCPLayoutInset(); - virtual ~QCPLayoutInset(); - - // getters: - InsetPlacement insetPlacement(int index) const; - Qt::Alignment insetAlignment(int index) const; - QRectF insetRect(int index) const; - - // setters: - void setInsetPlacement(int index, InsetPlacement placement); - void setInsetAlignment(int index, Qt::Alignment alignment); - void setInsetRect(int index, const QRectF &rect); - - // reimplemented virtual methods: - virtual void updateLayout() Q_DECL_OVERRIDE; - virtual int elementCount() const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; - virtual void simplify() Q_DECL_OVERRIDE {} - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void addElement(QCPLayoutElement *element, Qt::Alignment alignment); - void addElement(QCPLayoutElement *element, const QRectF &rect); - -protected: - // property members: - QList mElements; - QList mInsetPlacement; - QList mInsetAlignment; - QList mInsetRect; - -private: - Q_DISABLE_COPY(QCPLayoutInset) -}; -Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement) - -/* end of 'src/layout.h' */ - - -/* including file 'src/lineending.h', size 4426 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPLineEnding -{ - Q_GADGET -public: - /*! - Defines the type of ending decoration for line-like items, e.g. an arrow. - - \image html QCPLineEnding.png - - The width and length of these decorations can be controlled with the functions \ref setWidth - and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only - support a width, the length property is ignored. - - \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding - */ - enum EndingStyle { esNone ///< No ending decoration - ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) - ,esSpikeArrow ///< A filled arrow head with an indented back - ,esLineArrow ///< A non-filled arrow head with open back - ,esDisc ///< A filled circle - ,esSquare ///< A filled square - ,esDiamond ///< A filled diamond (45 degrees rotated square) - ,esBar ///< A bar perpendicular to the line - ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) - ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) - }; - Q_ENUMS(EndingStyle) - - QCPLineEnding(); - QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); - - // getters: - EndingStyle style() const { return mStyle; } - double width() const { return mWidth; } - double length() const { return mLength; } - bool inverted() const { return mInverted; } - - // setters: - void setStyle(EndingStyle style); - void setWidth(double width); - void setLength(double length); - void setInverted(bool inverted); - - // non-property methods: - double boundingDistance() const; - double realLength() const; - void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const; - void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const; - -protected: - // property members: - EndingStyle mStyle; - double mWidth, mLength; - bool mInverted; -}; -Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); -Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle) - -/* end of 'src/lineending.h' */ - - -/* including file 'src/axis/axisticker.h', size 4177 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines the strategies that the axis ticker may follow when choosing the size of the tick step. - - \see setTickStepStrategy - */ - enum TickStepStrategy - { - tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) - ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count - }; - Q_ENUMS(TickStepStrategy) - - QCPAxisTicker(); - virtual ~QCPAxisTicker(); - - // getters: - TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; } - int tickCount() const { return mTickCount; } - double tickOrigin() const { return mTickOrigin; } - - // setters: - void setTickStepStrategy(TickStepStrategy strategy); - void setTickCount(int count); - void setTickOrigin(double origin); - - // introduced virtual methods: - virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels); - -protected: - // property members: - TickStepStrategy mTickStepStrategy; - int mTickCount; - double mTickOrigin; - - // introduced virtual methods: - virtual double getTickStep(const QCPRange &range); - virtual int getSubTickCount(double tickStep); - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision); - virtual QVector createTickVector(double tickStep, const QCPRange &range); - virtual QVector createSubTickVector(int subTickCount, const QVector &ticks); - virtual QVector createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision); - - // non-virtual methods: - void trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const; - double pickClosest(double target, const QVector &candidates) const; - double getMantissa(double input, double *magnitude=0) const; - double cleanMantissa(double input) const; -}; -Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy) -Q_DECLARE_METATYPE(QSharedPointer) - -/* end of 'src/axis/axisticker.h' */ - - -/* including file 'src/axis/axistickerdatetime.h', size 3289 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker -{ -public: - QCPAxisTickerDateTime(); - - // getters: - QString dateTimeFormat() const { return mDateTimeFormat; } - Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } - - // setters: - void setDateTimeFormat(const QString &format); - void setDateTimeSpec(Qt::TimeSpec spec); - void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) - void setTickOrigin(const QDateTime &origin); - - // static methods: - static QDateTime keyToDateTime(double key); - static double dateTimeToKey(const QDateTime dateTime); - static double dateTimeToKey(const QDate date); - -protected: - // property members: - QString mDateTimeFormat; - Qt::TimeSpec mDateTimeSpec; - - // non-property members: - enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; -}; - -/* end of 'src/axis/axistickerdatetime.h' */ - - -/* including file 'src/axis/axistickertime.h', size 3542 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines the logical units in which fractions of time spans can be expressed. - - \see setFieldWidth, setTimeFormat - */ - enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) - ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat) - ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat) - ,tuHours ///< Hours (%%h in \ref setTimeFormat) - ,tuDays ///< Days (%%d in \ref setTimeFormat) - }; - Q_ENUMS(TimeUnit) - - QCPAxisTickerTime(); - - // getters: - QString timeFormat() const { return mTimeFormat; } - int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); } - - // setters: - void setTimeFormat(const QString &format); - void setFieldWidth(TimeUnit unit, int width); - -protected: - // property members: - QString mTimeFormat; - QHash mFieldWidth; - - // non-property members: - TimeUnit mSmallestUnit, mBiggestUnit; - QHash mFormatPattern; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - - // non-virtual methods: - void replaceUnit(QString &text, TimeUnit unit, int value) const; -}; -Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit) - -/* end of 'src/axis/axistickertime.h' */ - - -/* including file 'src/axis/axistickerfixed.h', size 3308 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines how the axis ticker may modify the specified tick step (\ref setTickStep) in order to - control the number of ticks in the axis range. - - \see setScaleStrategy - */ - enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. - ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. - ,ssPowers ///< An integer power of the specified tick step is allowed. - }; - Q_ENUMS(ScaleStrategy) - - QCPAxisTickerFixed(); - - // getters: - double tickStep() const { return mTickStep; } - ScaleStrategy scaleStrategy() const { return mScaleStrategy; } - - // setters: - void setTickStep(double step); - void setScaleStrategy(ScaleStrategy strategy); - -protected: - // property members: - double mTickStep; - ScaleStrategy mScaleStrategy; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; -}; -Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy) - -/* end of 'src/axis/axistickerfixed.h' */ - - -/* including file 'src/axis/axistickertext.h', size 3085 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker -{ -public: - QCPAxisTickerText(); - - // getters: - QMap &ticks() { return mTicks; } - int subTickCount() const { return mSubTickCount; } - - // setters: - void setTicks(const QMap &ticks); - void setTicks(const QVector &positions, const QVector labels); - void setSubTickCount(int subTicks); - - // non-virtual methods: - void clear(); - void addTick(double position, QString label); - void addTicks(const QMap &ticks); - void addTicks(const QVector &positions, const QVector &labels); - -protected: - // property members: - QMap mTicks; - int mSubTickCount; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; - -}; - -/* end of 'src/axis/axistickertext.h' */ - - -/* including file 'src/axis/axistickerpi.h', size 3911 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker -{ - Q_GADGET -public: - /*! - Defines how fractions should be displayed in tick labels. - - \see setFractionStyle - */ - enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". - ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" - ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. - }; - Q_ENUMS(FractionStyle) - - QCPAxisTickerPi(); - - // getters: - QString piSymbol() const { return mPiSymbol; } - double piValue() const { return mPiValue; } - bool periodicity() const { return mPeriodicity; } - FractionStyle fractionStyle() const { return mFractionStyle; } - - // setters: - void setPiSymbol(QString symbol); - void setPiValue(double pi); - void setPeriodicity(int multiplesOfPi); - void setFractionStyle(FractionStyle style); - -protected: - // property members: - QString mPiSymbol; - double mPiValue; - int mPeriodicity; - FractionStyle mFractionStyle; - - // non-property members: - double mPiTickStep; // size of one tick step in units of mPiValue - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - - // non-virtual methods: - void simplifyFraction(int &numerator, int &denominator) const; - QString fractionToString(int numerator, int denominator) const; - QString unicodeFraction(int numerator, int denominator) const; - QString unicodeSuperscript(int number) const; - QString unicodeSubscript(int number) const; -}; -Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle) - -/* end of 'src/axis/axistickerpi.h' */ - - -/* including file 'src/axis/axistickerlog.h', size 2663 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker -{ -public: - QCPAxisTickerLog(); - - // getters: - double logBase() const { return mLogBase; } - int subTickCount() const { return mSubTickCount; } - - // setters: - void setLogBase(double base); - void setSubTickCount(int subTicks); - -protected: - // property members: - double mLogBase; - int mSubTickCount; - - // non-property members: - double mLogBaseLnInv; - - // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; -}; - -/* end of 'src/axis/axistickerlog.h' */ - - -/* including file 'src/axis/axis.h', size 20634 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPGrid :public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) - Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) - Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) - Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) - /// \endcond -public: - explicit QCPGrid(QCPAxis *parentAxis); - - // getters: - bool subGridVisible() const { return mSubGridVisible; } - bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } - bool antialiasedZeroLine() const { return mAntialiasedZeroLine; } - QPen pen() const { return mPen; } - QPen subGridPen() const { return mSubGridPen; } - QPen zeroLinePen() const { return mZeroLinePen; } - - // setters: - void setSubGridVisible(bool visible); - void setAntialiasedSubGrid(bool enabled); - void setAntialiasedZeroLine(bool enabled); - void setPen(const QPen &pen); - void setSubGridPen(const QPen &pen); - void setZeroLinePen(const QPen &pen); - -protected: - // property members: - bool mSubGridVisible; - bool mAntialiasedSubGrid, mAntialiasedZeroLine; - QPen mPen, mSubGridPen, mZeroLinePen; - - // non-property members: - QCPAxis *mParentAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - void drawGridLines(QCPPainter *painter) const; - void drawSubGridLines(QCPPainter *painter) const; - - friend class QCPAxis; -}; - - -class QCP_LIB_DECL QCPAxis : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(AxisType axisType READ axisType) - Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) - Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) - Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) - Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) - Q_PROPERTY(QSharedPointer ticker READ ticker WRITE setTicker) - Q_PROPERTY(bool ticks READ ticks WRITE setTicks) - Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) - Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) - Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) - Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) - Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) - Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide) - Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) - Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) - Q_PROPERTY(QVector tickVector READ tickVector) - Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels) - Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) - Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) - Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks) - Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) - Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) - Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) - Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) - Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) - Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) - Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) - Q_PROPERTY(int padding READ padding WRITE setPadding) - Q_PROPERTY(int offset READ offset WRITE setOffset) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) - Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) - Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) - Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) - Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) - Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) - Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) - Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) - Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) - Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) - Q_PROPERTY(QCPGrid* grid READ grid) - /// \endcond -public: - /*! - Defines at which side of the axis rect the axis will appear. This also affects how the tick - marks are drawn, on which side the labels are placed etc. - */ - enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect - ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect - ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect - ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect - }; - Q_ENUMS(AxisType) - Q_FLAGS(AxisTypes) - Q_DECLARE_FLAGS(AxisTypes, AxisType) - /*! - Defines on which side of the axis the tick labels (numbers) shall appear. - - \see setTickLabelSide - */ - enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect - ,lsOutside ///< Tick labels will be displayed outside the axis rect - }; - Q_ENUMS(LabelSide) - /*! - Defines the scale of an axis. - \see setScaleType - */ - enum ScaleType { stLinear ///< Linear scaling - ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). - }; - Q_ENUMS(ScaleType) - /*! - Defines the selectable parts of an axis. - \see setSelectableParts, setSelectedParts - */ - enum SelectablePart { spNone = 0 ///< None of the selectable parts - ,spAxis = 0x001 ///< The axis backbone and tick marks - ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) - ,spAxisLabel = 0x004 ///< The axis label - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPAxis(QCPAxisRect *parent, AxisType type); - virtual ~QCPAxis(); - - // getters: - AxisType axisType() const { return mAxisType; } - QCPAxisRect *axisRect() const { return mAxisRect; } - ScaleType scaleType() const { return mScaleType; } - const QCPRange range() const { return mRange; } - bool rangeReversed() const { return mRangeReversed; } - QSharedPointer ticker() const { return mTicker; } - bool ticks() const { return mTicks; } - bool tickLabels() const { return mTickLabels; } - int tickLabelPadding() const; - QFont tickLabelFont() const { return mTickLabelFont; } - QColor tickLabelColor() const { return mTickLabelColor; } - double tickLabelRotation() const; - LabelSide tickLabelSide() const; - QString numberFormat() const; - int numberPrecision() const { return mNumberPrecision; } - QVector tickVector() const { return mTickVector; } - QVector tickVectorLabels() const { return mTickVectorLabels; } - int tickLengthIn() const; - int tickLengthOut() const; - bool subTicks() const { return mSubTicks; } - int subTickLengthIn() const; - int subTickLengthOut() const; - QPen basePen() const { return mBasePen; } - QPen tickPen() const { return mTickPen; } - QPen subTickPen() const { return mSubTickPen; } - QFont labelFont() const { return mLabelFont; } - QColor labelColor() const { return mLabelColor; } - QString label() const { return mLabel; } - int labelPadding() const; - int padding() const { return mPadding; } - int offset() const; - SelectableParts selectedParts() const { return mSelectedParts; } - SelectableParts selectableParts() const { return mSelectableParts; } - QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; } - QFont selectedLabelFont() const { return mSelectedLabelFont; } - QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; } - QColor selectedLabelColor() const { return mSelectedLabelColor; } - QPen selectedBasePen() const { return mSelectedBasePen; } - QPen selectedTickPen() const { return mSelectedTickPen; } - QPen selectedSubTickPen() const { return mSelectedSubTickPen; } - QCPLineEnding lowerEnding() const; - QCPLineEnding upperEnding() const; - QCPGrid *grid() const { return mGrid; } - - // setters: - Q_SLOT void setScaleType(QCPAxis::ScaleType type); - Q_SLOT void setRange(const QCPRange &range); - void setRange(double lower, double upper); - void setRange(double position, double size, Qt::AlignmentFlag alignment); - void setRangeLower(double lower); - void setRangeUpper(double upper); - void setRangeReversed(bool reversed); - void setTicker(QSharedPointer ticker); - void setTicks(bool show); - void setTickLabels(bool show); - void setTickLabelPadding(int padding); - void setTickLabelFont(const QFont &font); - void setTickLabelColor(const QColor &color); - void setTickLabelRotation(double degrees); - void setTickLabelSide(LabelSide side); - void setNumberFormat(const QString &formatCode); - void setNumberPrecision(int precision); - void setTickLength(int inside, int outside=0); - void setTickLengthIn(int inside); - void setTickLengthOut(int outside); - void setSubTicks(bool show); - void setSubTickLength(int inside, int outside=0); - void setSubTickLengthIn(int inside); - void setSubTickLengthOut(int outside); - void setBasePen(const QPen &pen); - void setTickPen(const QPen &pen); - void setSubTickPen(const QPen &pen); - void setLabelFont(const QFont &font); - void setLabelColor(const QColor &color); - void setLabel(const QString &str); - void setLabelPadding(int padding); - void setPadding(int padding); - void setOffset(int offset); - void setSelectedTickLabelFont(const QFont &font); - void setSelectedLabelFont(const QFont &font); - void setSelectedTickLabelColor(const QColor &color); - void setSelectedLabelColor(const QColor &color); - void setSelectedBasePen(const QPen &pen); - void setSelectedTickPen(const QPen &pen); - void setSelectedSubTickPen(const QPen &pen); - Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); - void setLowerEnding(const QCPLineEnding &ending); - void setUpperEnding(const QCPLineEnding &ending); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-property methods: - Qt::Orientation orientation() const { return mOrientation; } - int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; } - void moveRange(double diff); - void scaleRange(double factor); - void scaleRange(double factor, double center); - void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); - void rescale(bool onlyVisiblePlottables=false); - double pixelToCoord(double value) const; - double coordToPixel(double value) const; - SelectablePart getPartAt(const QPointF &pos) const; - QList plottables() const; - QList graphs() const; - QList items() const; - - static AxisType marginSideToAxisType(QCP::MarginSide side); - static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } - static AxisType opposite(AxisType type); - -Q_SIGNALS: - void rangeChanged(const QCPRange &newRange); - void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); - void scaleTypeChanged(QCPAxis::ScaleType scaleType); - void selectionChanged(const QCPAxis::SelectableParts &parts); - void selectableChanged(const QCPAxis::SelectableParts &parts); - -protected: - // property members: - // axis base: - AxisType mAxisType; - QCPAxisRect *mAxisRect; - //int mOffset; // in QCPAxisPainter - int mPadding; - Qt::Orientation mOrientation; - SelectableParts mSelectableParts, mSelectedParts; - QPen mBasePen, mSelectedBasePen; - //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter - // axis label: - //int mLabelPadding; // in QCPAxisPainter - QString mLabel; - QFont mLabelFont, mSelectedLabelFont; - QColor mLabelColor, mSelectedLabelColor; - // tick labels: - //int mTickLabelPadding; // in QCPAxisPainter - bool mTickLabels; - //double mTickLabelRotation; // in QCPAxisPainter - QFont mTickLabelFont, mSelectedTickLabelFont; - QColor mTickLabelColor, mSelectedTickLabelColor; - int mNumberPrecision; - QLatin1Char mNumberFormatChar; - bool mNumberBeautifulPowers; - //bool mNumberMultiplyCross; // QCPAxisPainter - // ticks and subticks: - bool mTicks; - bool mSubTicks; - //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter - QPen mTickPen, mSelectedTickPen; - QPen mSubTickPen, mSelectedSubTickPen; - // scale and range: - QCPRange mRange; - bool mRangeReversed; - ScaleType mScaleType; - - // non-property members: - QCPGrid *mGrid; - QCPAxisPainterPrivate *mAxisPainter; - QSharedPointer mTicker; - QVector mTickVector; - QVector mTickVectorLabels; - QVector mSubTickVector; - bool mCachedMarginValid; - int mCachedMargin; - bool mDragging; - QCPRange mDragStartRange; - QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - - // introduced virtual methods: - virtual int calculateMargin(); - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - // mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); - virtual void wheelEvent(QWheelEvent *event); - - // non-virtual methods: - void setupTickVectors(); - QPen getBasePen() const; - QPen getTickPen() const; - QPen getSubTickPen() const; - QFont getTickLabelFont() const; - QFont getLabelFont() const; - QColor getTickLabelColor() const; - QColor getLabelColor() const; - -private: - Q_DISABLE_COPY(QCPAxis) - - friend class QCustomPlot; - friend class QCPGrid; - friend class QCPAxisRect; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) -Q_DECLARE_METATYPE(QCPAxis::AxisType) -Q_DECLARE_METATYPE(QCPAxis::LabelSide) -Q_DECLARE_METATYPE(QCPAxis::ScaleType) -Q_DECLARE_METATYPE(QCPAxis::SelectablePart) - - -class QCPAxisPainterPrivate -{ -public: - explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); - virtual ~QCPAxisPainterPrivate(); - - virtual void draw(QCPPainter *painter); - virtual int size() const; - void clearCache(); - - QRect axisSelectionBox() const { return mAxisSelectionBox; } - QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } - QRect labelSelectionBox() const { return mLabelSelectionBox; } - - // public property members: - QCPAxis::AxisType type; - QPen basePen; - QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters - int labelPadding; // directly accessed by QCPAxis setters/getters - QFont labelFont; - QColor labelColor; - QString label; - int tickLabelPadding; // directly accessed by QCPAxis setters/getters - double tickLabelRotation; // directly accessed by QCPAxis setters/getters - QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters - bool substituteExponent; - bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters - int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters - QPen tickPen, subTickPen; - QFont tickLabelFont; - QColor tickLabelColor; - QRect axisRect, viewportRect; - double offset; // directly accessed by QCPAxis setters/getters - bool abbreviateDecimalPowers; - bool reversedEndings; - - QVector subTickPositions; - QVector tickPositions; - QVector tickLabels; - -protected: - struct CachedLabel - { - QPointF offset; - QPixmap pixmap; - }; - struct TickLabelData - { - QString basePart, expPart, suffixPart; - QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds; - QFont baseFont, expFont; - }; - QCustomPlot *mParentPlot; - QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters - QCache mLabelCache; - QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; - - virtual QByteArray generateLabelParameterHash() const; - - virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); - virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; - virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; - virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; - virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; -}; - -/* end of 'src/axis/axis.h' */ - - -/* including file 'src/scatterstyle.h', size 7275 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPScatterStyle -{ - Q_GADGET -public: - /*! - Represents the various properties of a scatter style instance. For example, this enum is used - to specify which properties of \ref QCPSelectionDecorator::setScatterStyle will be used when - highlighting selected data points. - - Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref - setFromOther. - */ - enum ScatterProperty { spNone = 0x00 ///< 0x00 None - ,spPen = 0x01 ///< 0x01 The pen property, see \ref setPen - ,spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush - ,spSize = 0x04 ///< 0x04 The size property, see \ref setSize - ,spShape = 0x08 ///< 0x08 The shape property, see \ref setShape - ,spAll = 0xFF ///< 0xFF All properties - }; - Q_ENUMS(ScatterProperty) - Q_FLAGS(ScatterProperties) - Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty) - - /*! - Defines the shape used for scatter points. - - On plottables/items that draw scatters, the sizes of these visualizations (with exception of - \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are - drawn with the pen and brush specified with \ref setPen and \ref setBrush. - */ - enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) - ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) - ,ssCross ///< \enumimage{ssCross.png} a cross - ,ssPlus ///< \enumimage{ssPlus.png} a plus - ,ssCircle ///< \enumimage{ssCircle.png} a circle - ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) - ,ssSquare ///< \enumimage{ssSquare.png} a square - ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond - ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus - ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline - ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner - ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside - ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside - ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside - ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside - ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines - ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates - ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) - }; - Q_ENUMS(ScatterShape) - - QCPScatterStyle(); - QCPScatterStyle(ScatterShape shape, double size=6); - QCPScatterStyle(ScatterShape shape, const QColor &color, double size); - QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); - QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); - QCPScatterStyle(const QPixmap &pixmap); - QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); - - // getters: - double size() const { return mSize; } - ScatterShape shape() const { return mShape; } - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QPixmap pixmap() const { return mPixmap; } - QPainterPath customPath() const { return mCustomPath; } - - // setters: - void setFromOther(const QCPScatterStyle &other, ScatterProperties properties); - void setSize(double size); - void setShape(ScatterShape shape); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setPixmap(const QPixmap &pixmap); - void setCustomPath(const QPainterPath &customPath); - - // non-property methods: - bool isNone() const { return mShape == ssNone; } - bool isPenDefined() const { return mPenDefined; } - void undefinePen(); - void applyTo(QCPPainter *painter, const QPen &defaultPen) const; - void drawShape(QCPPainter *painter, const QPointF &pos) const; - void drawShape(QCPPainter *painter, double x, double y) const; - -protected: - // property members: - double mSize; - ScatterShape mShape; - QPen mPen; - QBrush mBrush; - QPixmap mPixmap; - QPainterPath mCustomPath; - - // non-property members: - bool mPenDefined; -}; -Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) - -/* end of 'src/scatterstyle.h' */ - - -/* including file 'src/datacontainer.h', size 4596 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -/*! \relates QCPDataContainer - Returns whether the sort key of \a a is less than the sort key of \a b. - - \see QCPDataContainer::sort -*/ -template -inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); } - -template -class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) -{ -public: - typedef typename QVector::const_iterator const_iterator; - typedef typename QVector::iterator iterator; - - QCPDataContainer(); - - // getters: - int size() const { return mData.size()-mPreallocSize; } - bool isEmpty() const { return size() == 0; } - bool autoSqueeze() const { return mAutoSqueeze; } - - // setters: - void setAutoSqueeze(bool enabled); - - // non-virtual methods: - void set(const QCPDataContainer &data); - void set(const QVector &data, bool alreadySorted=false); - void add(const QCPDataContainer &data); - void add(const QVector &data, bool alreadySorted=false); - void add(const DataType &data); - void removeBefore(double sortKey); - void removeAfter(double sortKey); - void remove(double sortKeyFrom, double sortKeyTo); - void remove(double sortKey); - void clear(); - void sort(); - void squeeze(bool preAllocation=true, bool postAllocation=true); - - const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; } - const_iterator constEnd() const { return mData.constEnd(); } - iterator begin() { return mData.begin()+mPreallocSize; } - iterator end() { return mData.end(); } - const_iterator findBegin(double sortKey, bool expandedRange=true) const; - const_iterator findEnd(double sortKey, bool expandedRange=true) const; - const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); } - QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth); - QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()); - QCPDataRange dataRange() const { return QCPDataRange(0, size()); } - void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const; - -protected: - // property members: - bool mAutoSqueeze; - - // non-property memebers: - QVector mData; - int mPreallocSize; - int mPreallocIteration; - - // non-virtual methods: - void preallocateGrow(int minimumPreallocSize); - void performAutoSqueeze(); -}; - -// include implementation in header since it is a class template: - -/* including file 'src/datacontainer.cpp', size 31349 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPDataContainer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPDataContainer - \brief The generic data container for one-dimensional plottables - - This class template provides a fast container for data storage of one-dimensional data. The data - type is specified as template parameter (called \a DataType in the following) and must provide - some methods as described in the \ref qcpdatacontainer-datatype "next section". - - The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well - as retrieval of ranges (see \ref findBegin, \ref findEnd, \ref keyRange) using binary search. The - container uses a preallocation and a postallocation scheme, such that appending and prepending - data (with respect to the sort key) is very fast and minimizes reallocations. If data is added - which needs to be inserted between existing keys, the merge usually can be done quickly too, - using the fact that existing data is always sorted. The user can further improve performance by - specifying that added data is already itself sorted by key, if he can guarantee that this is the - case (see for example \ref add(const QVector &data, bool alreadySorted)). - - The data can be accessed with the provided const iterators (\ref constBegin, \ref constEnd). If - it is necessary to alter existing data in-place, the non-const iterators can be used (\ref begin, - \ref end). Changing data members that are not the sort key (for most data types called \a key) is - safe from the container's perspective. - - Great care must be taken however if the sort key is modified through the non-const iterators. For - performance reasons, the iterators don't automatically cause a re-sorting upon their - manipulation. It is thus the responsibility of the user to leave the container in a sorted state - when finished with the data manipulation, before calling any other methods on the container. A - complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling \ref - sort. Failing to do so can not be detected by the container efficiently and will cause both - rendering artifacts and potential data loss. - - Implementing one-dimensional plottables that make use of a \ref QCPDataContainer is usually - done by subclassing from \ref QCPAbstractPlottable1D "QCPAbstractPlottable1D", which - introduces an according \a mDataContainer member and some convenience methods. - - \section qcpdatacontainer-datatype Requirements for the DataType template parameter - - The template parameter DataType is the type of the stored data points. It must be - trivially copyable and have the following public methods, preferably inline: - - \li double sortKey() const\n Returns the member variable of this data point that is the - sort key, defining the ordering in the container. Often this variable is simply called \a key. - - \li static DataType fromSortKey(double sortKey)\n Returns a new instance of the data - type initialized with its sort key set to \a sortKey. - - \li static bool sortKeyIsMainKey()\n Returns true if the sort key is equal to the main - key (see method \c mainKey below). For most plottables this is the case. It is not the case for - example for \ref QCPCurve, which uses \a t as sort key and \a key as main key. This is the reason - why QCPCurve unlike QCPGraph can display parametric curves with loops. - - \li double mainKey() const\n Returns the variable of this data point considered the main - key. This is commonly the variable that is used as the coordinate of this data point on the key - axis of the plottable. This method is used for example when determining the automatic axis - rescaling of key axes (\ref QCPAxis::rescale). - - \li double mainValue() const\n Returns the variable of this data point considered the - main value. This is commonly the variable that is used as the coordinate of this data point on - the value axis of the plottable. - - \li QCPRange valueRange() const\n Returns the range this data point spans in the value - axis coordinate. If the data is single-valued (e.g. QCPGraphData), this is simply a range with - both lower and upper set to the main data point value. However if the data points can represent - multiple values at once (e.g QCPFinancialData with its \a high, \a low, \a open and \a close - values at each \a key) this method should return the range those values span. This method is used - for example when determining the automatic axis rescaling of value axes (\ref - QCPAxis::rescale). -*/ - -/* start documentation of inline functions */ - -/*! \fn int QCPDataContainer::size() const - - Returns the number of data points in the container. -*/ - -/*! \fn bool QCPDataContainer::isEmpty() const - - Returns whether this container holds no data points. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constBegin() const - - Returns a const iterator to the first data point in this container. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::constEnd() const - - Returns a const iterator to the element past the last data point in this container. -*/ - -/*! \fn QCPDataContainer::iterator QCPDataContainer::begin() const - - Returns a non-const iterator to the first data point in this container. - - You can manipulate the data points in-place through the non-const iterators, but great care must - be taken when manipulating the sort key of a data point, see \ref sort, or the detailed - description of this class. -*/ - -/*! \fn QCPDataContainer::iterator QCPDataContainer::end() const - - Returns a non-const iterator to the element past the last data point in this container. - - You can manipulate the data points in-place through the non-const iterators, but great care must - be taken when manipulating the sort key of a data point, see \ref sort, or the detailed - description of this class. -*/ - -/*! \fn QCPDataContainer::const_iterator QCPDataContainer::at(int index) const - - Returns a const iterator to the element with the specified \a index. If \a index points beyond - the available elements in this container, returns \ref constEnd, i.e. an iterator past the last - valid element. - - You can use this method to easily obtain iterators from a \ref QCPDataRange, see the \ref - dataselection-accessing "data selection page" for an example. -*/ - -/*! \fn QCPDataRange QCPDataContainer::dataRange() const - - Returns a \ref QCPDataRange encompassing the entire data set of this container. This means the - begin index of the returned range is 0, and the end index is \ref size. -*/ - -/* end documentation of inline functions */ - -/*! - Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted - data -*/ -template -QCPDataContainer::QCPDataContainer() : - mAutoSqueeze(true), - mPreallocSize(0), - mPreallocIteration(0) -{ -} - -/*! - Sets whether the container automatically decides when to release memory from its post- and - preallocation pools when data points are removed. By default this is enabled and for typical - applications shouldn't be changed. - - If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with - \ref squeeze. -*/ -template -void QCPDataContainer::setAutoSqueeze(bool enabled) -{ - if (mAutoSqueeze != enabled) - { - mAutoSqueeze = enabled; - if (mAutoSqueeze) - performAutoSqueeze(); - } -} - -/*! \overload - - Replaces the current data in this container with the provided \a data. - - \see add, remove -*/ -template -void QCPDataContainer::set(const QCPDataContainer &data) -{ - clear(); - add(data); -} - -/*! \overload - - Replaces the current data in this container with the provided \a data - - If you can guarantee that the data points in \a data have ascending order with respect to the - DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. - - \see add, remove -*/ -template -void QCPDataContainer::set(const QVector &data, bool alreadySorted) -{ - mData = data; - mPreallocSize = 0; - mPreallocIteration = 0; - if (!alreadySorted) - sort(); -} - -/*! \overload - - Adds the provided \a data to the current data in this container. - - \see set, remove -*/ -template -void QCPDataContainer::add(const QCPDataContainer &data) -{ - if (data.isEmpty()) - return; - - const int n = data.size(); - const int oldSize = size(); - - if (oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones - { - if (mPreallocSize < n) - preallocateGrow(n); - mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and merge if necessary - { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); - } -} - -/*! - Adds the provided data points in \a data to the current data. - - If you can guarantee that the data points in \a data have ascending order with respect to the - DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run. - - \see set, remove -*/ -template -void QCPDataContainer::add(const QVector &data, bool alreadySorted) -{ - if (data.isEmpty()) - return; - if (isEmpty()) - { - set(data, alreadySorted); - return; - } - - const int n = data.size(); - const int oldSize = size(); - - if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones - { - if (mPreallocSize < n) - preallocateGrow(n); - mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and then sort and merge if necessary - { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (!alreadySorted) // sort appended subrange if it wasn't already sorted - std::sort(end()-n, end(), qcpLessThanSortKey); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); - } -} - -/*! \overload - - Adds the provided single data point to the current data. - - \see remove -*/ -template -void QCPDataContainer::add(const DataType &data) -{ - if (isEmpty() || !qcpLessThanSortKey(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones - { - mData.append(data); - } else if (qcpLessThanSortKey(data, *constBegin())) // quickly handle prepends using preallocated space - { - if (mPreallocSize < 1) - preallocateGrow(1); - --mPreallocSize; - *begin() = data; - } else // handle inserts, maintaining sorted keys - { - QCPDataContainer::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey); - mData.insert(insertionPoint, data); - } -} - -/*! - Removes all data points with (sort-)keys smaller than or equal to \a sortKey. - - \see removeAfter, remove, clear -*/ -template -void QCPDataContainer::removeBefore(double sortKey) -{ - QCPDataContainer::iterator it = begin(); - QCPDataContainer::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - mPreallocSize += itEnd-it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points with (sort-)keys greater than or equal to \a sortKey. - - \see removeBefore, remove, clear -*/ -template -void QCPDataContainer::removeAfter(double sortKey) -{ - QCPDataContainer::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - QCPDataContainer::iterator itEnd = end(); - mData.erase(it, itEnd); // typically adds it to the postallocated block - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points with (sort-)keys between \a sortKeyFrom and \a sortKeyTo. if \a - sortKeyFrom is greater or equal to \a sortKeyTo, the function does nothing. To remove a single - data point with known (sort-)key, use \ref remove(double sortKey). - - \see removeBefore, removeAfter, clear -*/ -template -void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) -{ - if (sortKeyFrom >= sortKeyTo || isEmpty()) - return; - - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey); - QCPDataContainer::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey); - mData.erase(it, itEnd); - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! \overload - - Removes a single data point at \a sortKey. If the position is not known with absolute (binary) - precision, consider using \ref remove(double sortKeyFrom, double sortKeyTo) with a small - fuzziness interval around the suspected position, depeding on the precision with which the - (sort-)key is known. - - \see removeBefore, removeAfter, clear -*/ -template -void QCPDataContainer::remove(double sortKey) -{ - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (it != end() && it->sortKey() == sortKey) - { - if (it == begin()) - ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) - else - mData.erase(it); - } - if (mAutoSqueeze) - performAutoSqueeze(); -} - -/*! - Removes all data points. - - \see remove, removeAfter, removeBefore -*/ -template -void QCPDataContainer::clear() -{ - mData.clear(); - mPreallocIteration = 0; - mPreallocSize = 0; -} - -/*! - Re-sorts all data points in the container by their sort key. - - When setting, adding or removing points using the QCPDataContainer interface (\ref set, \ref add, - \ref remove, etc.), the container makes sure to always stay in a sorted state such that a full - resort is never necessary. However, if you choose to directly manipulate the sort key on data - points by accessing and modifying it through the non-const iterators (\ref begin, \ref end), it - is your responsibility to bring the container back into a sorted state before any other methods - are called on it. This can be achieved by calling this method immediately after finishing the - sort key manipulation. -*/ -template -void QCPDataContainer::sort() -{ - std::sort(begin(), end(), qcpLessThanSortKey); -} - -/*! - Frees all unused memory that is currently in the preallocation and postallocation pools. - - Note that QCPDataContainer automatically decides whether squeezing is necessary, if \ref - setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical - applications. - - The parameters \a preAllocation and \a postAllocation control whether pre- and/or post allocation - should be freed, respectively. -*/ -template -void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation) -{ - if (preAllocation) - { - if (mPreallocSize > 0) - { - std::copy(begin(), end(), mData.begin()); - mData.resize(size()); - mPreallocSize = 0; - } - mPreallocIteration = 0; - } - if (postAllocation) - mData.squeeze(); -} - -/*! - Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just - above \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be - considered, otherwise the one just above. - - This can be used in conjunction with \ref findEnd to iterate over data points within a given key - range, including or excluding the bounding data points that are just beyond the specified range. - - If \a expandedRange is true but there are no data points below \a sortKey, \ref constBegin is - returned. - - If the container is empty, returns \ref constEnd. - - \see findEnd, QCPPlottableInterface1D::findBegin -*/ -template -typename QCPDataContainer::const_iterator QCPDataContainer::findBegin(double sortKey, bool expandedRange) const -{ - if (isEmpty()) - return constEnd(); - - QCPDataContainer::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty - --it; - return it; -} - -/*! - Returns an iterator to the element after the data point with a (sort-)key that is equal to, just - above or just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey - will be considered, otherwise the one just below. - - This can be used in conjunction with \ref findBegin to iterate over data points within a given - key range, including the bounding data points that are just below and above the specified range. - - If \a expandedRange is true but there are no data points above \a sortKey, \ref constEnd is - returned. - - If the container is empty, \ref constEnd is returned. - - \see findBegin, QCPPlottableInterface1D::findEnd -*/ -template -typename QCPDataContainer::const_iterator QCPDataContainer::findEnd(double sortKey, bool expandedRange) const -{ - if (isEmpty()) - return constEnd(); - - QCPDataContainer::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constEnd()) - ++it; - return it; -} - -/*! - Returns the range encompassed by the (main-)key coordinate of all data points. The output - parameter \a foundRange indicates whether a sensible range was found. If this is false, you - should not use the returned QCPRange (e.g. the data container is empty or all points have the - same key). - - Use \a signDomain to control which sign of the key coordinates should be considered. This is - relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a - time. - - If the DataType reports that its main key is equal to the sort key (\a sortKeyIsMainKey), as is - the case for most plottables, this method uses this fact and finds the range very quickly. - - \see valueRange -*/ -template -QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain signDomain) -{ - if (isEmpty()) - { - foundRange = false; - return QCPRange(); - } - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - double current; - - QCPDataContainer::const_iterator it = constBegin(); - QCPDataContainer::const_iterator itEnd = constEnd(); - if (signDomain == QCP::sdBoth) // range may be anywhere - { - if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value - { - while (it != itEnd) // find first non-nan going up from left - { - if (!qIsNaN(it->mainValue())) - { - range.lower = it->mainKey(); - haveLower = true; - break; - } - ++it; - } - it = itEnd; - while (it != constBegin()) // find first non-nan going down from right - { - --it; - if (!qIsNaN(it->mainValue())) - { - range.upper = it->mainKey(); - haveUpper = true; - break; - } - } - } else // DataType is not sorted by main key, go through all data points and accordingly expand range - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if ((current < range.lower || !haveLower) && current < 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current < 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if ((current < range.lower || !haveLower) && current > 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current > 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! - Returns the range encompassed by the value coordinates of the data points in the specified key - range (\a inKeyRange), using the full \a DataType::valueRange reported by the data points. The - output parameter \a foundRange indicates whether a sensible range was found. If this is false, - you should not use the returned QCPRange (e.g. the data container is empty or all points have the - same value). - - If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), - all data points are considered, without any restriction on the keys. - - Use \a signDomain to control which sign of the value coordinates should be considered. This is - relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a - time. - - \see keyRange -*/ -template -QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange) -{ - if (isEmpty()) - { - foundRange = false; - return QCPRange(); - } - QCPRange range; - const bool restrictKeyRange = inKeyRange != QCPRange(); - bool haveLower = false; - bool haveUpper = false; - QCPRange current; - QCPDataContainer::const_iterator itBegin = constBegin(); - QCPDataContainer::const_iterator itEnd = constEnd(); - if (DataType::sortKeyIsMainKey() && restrictKeyRange) - { - itBegin = findBegin(inKeyRange.lower); - itEnd = findEnd(inKeyRange.upper); - } - if (signDomain == QCP::sdBoth) // range may be anywhere - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! - Makes sure \a begin and \a end mark a data range that is both within the bounds of this data - container's data, as well as within the specified \a dataRange. The initial range described by - the passed iterators \a begin and \a end is never expanded, only contracted if necessary. - - This function doesn't require for \a dataRange to be within the bounds of this data container's - valid range. -*/ -template -void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const -{ - QCPDataRange iteratorRange(begin-constBegin(), end-constBegin()); - iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); - begin = constBegin()+iteratorRange.begin(); - end = constBegin()+iteratorRange.end(); -} - -/*! \internal - - Increases the preallocation pool to have a size of at least \a minimumPreallocSize. Depending on - the preallocation history, the container will grow by more than requested, to speed up future - consecutive size increases. - - if \a minimumPreallocSize is smaller than or equal to the current preallocation pool size, this - method does nothing. -*/ -template -void QCPDataContainer::preallocateGrow(int minimumPreallocSize) -{ - if (minimumPreallocSize <= mPreallocSize) - return; - - int newPreallocSize = minimumPreallocSize; - newPreallocSize += (1u< -void QCPDataContainer::performAutoSqueeze() -{ - const int totalAlloc = mData.capacity(); - const int postAllocSize = totalAlloc-mData.size(); - const int usedSize = size(); - bool shrinkPostAllocation = false; - bool shrinkPreAllocation = false; - if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size - { - shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! - shrinkPreAllocation = mPreallocSize*10 > usedSize; - } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother - { - shrinkPostAllocation = postAllocSize > usedSize*5; - shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller - } - - if (shrinkPreAllocation || shrinkPostAllocation) - squeeze(shrinkPreAllocation, shrinkPostAllocation); -} -/* end of 'src/datacontainer.cpp' */ - - -/* end of 'src/datacontainer.h' */ - - -/* including file 'src/plottable.h', size 8312 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPSelectionDecorator -{ - Q_GADGET -public: - QCPSelectionDecorator(); - virtual ~QCPSelectionDecorator(); - - // getters: - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; } - - // setters: - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen); - void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties); - - // non-virtual methods: - void applyPen(QCPPainter *painter) const; - void applyBrush(QCPPainter *painter) const; - QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const; - - // introduced virtual methods: - virtual void copyFrom(const QCPSelectionDecorator *other); - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection); - -protected: - // property members: - QPen mPen; - QBrush mBrush; - QCPScatterStyle mScatterStyle; - QCPScatterStyle::ScatterProperties mUsedScatterProperties; - // non-property members: - QCPAbstractPlottable *mPlottable; - - // introduced virtual methods: - virtual bool registerWithPlottable(QCPAbstractPlottable *plottable); - -private: - Q_DISABLE_COPY(QCPSelectionDecorator) - friend class QCPAbstractPlottable; -}; -Q_DECLARE_METATYPE(QCPSelectionDecorator*) - - -class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) - Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) - Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) - Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged) - Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator) - /// \endcond -public: - QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPAbstractPlottable(); - - // getters: - QString name() const { return mName; } - bool antialiasedFill() const { return mAntialiasedFill; } - bool antialiasedScatters() const { return mAntialiasedScatters; } - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCP::SelectionType selectable() const { return mSelectable; } - bool selected() const { return !mSelection.isEmpty(); } - QCPDataSelection selection() const { return mSelection; } - QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; } - - // setters: - void setName(const QString &name); - void setAntialiasedFill(bool enabled); - void setAntialiasedScatters(bool enabled); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setKeyAxis(QCPAxis *axis); - void setValueAxis(QCPAxis *axis); - Q_SLOT void setSelectable(QCP::SelectionType selectable); - Q_SLOT void setSelection(QCPDataSelection selection); - void setSelectionDecorator(QCPSelectionDecorator *decorator); - - // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; - virtual QCPPlottableInterface1D *interface1D() { return 0; } - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0; - - // non-property methods: - void coordsToPixels(double key, double value, double &x, double &y) const; - const QPointF coordsToPixels(double key, double value) const; - void pixelsToCoords(double x, double y, double &key, double &value) const; - void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; - void rescaleAxes(bool onlyEnlarge=false) const; - void rescaleKeyAxis(bool onlyEnlarge=false) const; - void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const; - bool addToLegend(QCPLegend *legend); - bool addToLegend(); - bool removeFromLegend(QCPLegend *legend) const; - bool removeFromLegend() const; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectionChanged(const QCPDataSelection &selection); - void selectableChanged(QCP::SelectionType selectable); - -protected: - // property members: - QString mName; - bool mAntialiasedFill, mAntialiasedScatters; - QPen mPen; - QBrush mBrush; - QPointer mKeyAxis, mValueAxis; - QCP::SelectionType mSelectable; - QCPDataSelection mSelection; - QCPSelectionDecorator *mSelectionDecorator; - - // reimplemented virtual methods: - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; - - // non-virtual methods: - void applyFillAntialiasingHint(QCPPainter *painter) const; - void applyScattersAntialiasingHint(QCPPainter *painter) const; - -private: - Q_DISABLE_COPY(QCPAbstractPlottable) - - friend class QCustomPlot; - friend class QCPAxis; - friend class QCPPlottableLegendItem; -}; - - -/* end of 'src/plottable.h' */ - - -/* including file 'src/item.h', size 9384 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemAnchor -{ - Q_GADGET -public: - QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1); - virtual ~QCPItemAnchor(); - - // getters: - QString name() const { return mName; } - virtual QPointF pixelPosition() const; - -protected: - // property members: - QString mName; - - // non-property members: - QCustomPlot *mParentPlot; - QCPAbstractItem *mParentItem; - int mAnchorId; - QSet mChildrenX, mChildrenY; - - // introduced virtual methods: - virtual QCPItemPosition *toQCPItemPosition() { return 0; } - - // non-virtual methods: - void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - -private: - Q_DISABLE_COPY(QCPItemAnchor) - - friend class QCPItemPosition; -}; - - - -class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor -{ - Q_GADGET -public: - /*! - Defines the ways an item position can be specified. Thus it defines what the numbers passed to - \ref setCoords actually mean. - - \see setType - */ - enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. - ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the viewport/widget, etc. - ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. - ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). - }; - Q_ENUMS(PositionType) - - QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name); - virtual ~QCPItemPosition(); - - // getters: - PositionType type() const { return typeX(); } - PositionType typeX() const { return mPositionTypeX; } - PositionType typeY() const { return mPositionTypeY; } - QCPItemAnchor *parentAnchor() const { return parentAnchorX(); } - QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; } - QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; } - double key() const { return mKey; } - double value() const { return mValue; } - QPointF coords() const { return QPointF(mKey, mValue); } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCPAxisRect *axisRect() const; - virtual QPointF pixelPosition() const Q_DECL_OVERRIDE; - - // setters: - void setType(PositionType type); - void setTypeX(PositionType type); - void setTypeY(PositionType type); - bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - void setCoords(double key, double value); - void setCoords(const QPointF &coords); - void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); - void setAxisRect(QCPAxisRect *axisRect); - void setPixelPosition(const QPointF &pixelPosition); - -protected: - // property members: - PositionType mPositionTypeX, mPositionTypeY; - QPointer mKeyAxis, mValueAxis; - QPointer mAxisRect; - double mKey, mValue; - QCPItemAnchor *mParentAnchorX, *mParentAnchorY; - - // reimplemented virtual methods: - virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } - -private: - Q_DISABLE_COPY(QCPItemPosition) - -}; -Q_DECLARE_METATYPE(QCPItemPosition::PositionType) - - -class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) - Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - explicit QCPAbstractItem(QCustomPlot *parentPlot); - virtual ~QCPAbstractItem(); - - // getters: - bool clipToAxisRect() const { return mClipToAxisRect; } - QCPAxisRect *clipAxisRect() const; - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setClipToAxisRect(bool clip); - void setClipAxisRect(QCPAxisRect *rect); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; - - // non-virtual methods: - QList positions() const { return mPositions; } - QList anchors() const { return mAnchors; } - QCPItemPosition *position(const QString &name) const; - QCPItemAnchor *anchor(const QString &name) const; - bool hasAnchor(const QString &name) const; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - bool mClipToAxisRect; - QPointer mClipAxisRect; - QList mPositions; - QList mAnchors; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual QPointF anchorPixelPosition(int anchorId) const; - - // non-virtual methods: - double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const; - QCPItemPosition *createPosition(const QString &name); - QCPItemAnchor *createAnchor(const QString &name, int anchorId); - -private: - Q_DISABLE_COPY(QCPAbstractItem) - - friend class QCustomPlot; - friend class QCPItemAnchor; -}; - -/* end of 'src/item.h' */ - - -/* including file 'src/core.h', size 14886 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCustomPlot : public QWidget -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) - Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) - Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) - Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) - Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) - Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl) - /// \endcond -public: - /*! - Defines how a layer should be inserted relative to an other layer. - - \see addLayer, moveLayer - */ - enum LayerInsertMode { limBelow ///< Layer is inserted below other layer - ,limAbove ///< Layer is inserted above other layer - }; - Q_ENUMS(LayerInsertMode) - - /*! - Defines with what timing the QCustomPlot surface is refreshed after a replot. - - \see replot - */ - enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot - ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. - ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. - ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. - }; - Q_ENUMS(RefreshPriority) - - explicit QCustomPlot(QWidget *parent = 0); - virtual ~QCustomPlot(); - - // getters: - QRect viewport() const { return mViewport; } - double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; } - QPixmap background() const { return mBackgroundPixmap; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - QCPLayoutGrid *plotLayout() const { return mPlotLayout; } - QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } - QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } - bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } - const QCP::Interactions interactions() const { return mInteractions; } - int selectionTolerance() const { return mSelectionTolerance; } - bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; } - QCP::PlottingHints plottingHints() const { return mPlottingHints; } - Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } - QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; } - QCPSelectionRect *selectionRect() const { return mSelectionRect; } - bool openGl() const { return mOpenGl; } - - // setters: - void setViewport(const QRect &rect); - void setBufferDevicePixelRatio(double ratio); - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); - void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); - void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); - void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); - void setAutoAddPlottableToLegend(bool on); - void setInteractions(const QCP::Interactions &interactions); - void setInteraction(const QCP::Interaction &interaction, bool enabled=true); - void setSelectionTolerance(int pixels); - void setNoAntialiasingOnDrag(bool enabled); - void setPlottingHints(const QCP::PlottingHints &hints); - void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); - void setMultiSelectModifier(Qt::KeyboardModifier modifier); - void setSelectionRectMode(QCP::SelectionRectMode mode); - void setSelectionRect(QCPSelectionRect *selectionRect); - void setOpenGl(bool enabled, int multisampling=16); - - // non-property methods: - // plottable interface: - QCPAbstractPlottable *plottable(int index); - QCPAbstractPlottable *plottable(); - bool removePlottable(QCPAbstractPlottable *plottable); - bool removePlottable(int index); - int clearPlottables(); - int plottableCount() const; - QList selectedPlottables() const; - QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasPlottable(QCPAbstractPlottable *plottable) const; - - // specialized interface for QCPGraph: - QCPGraph *graph(int index) const; - QCPGraph *graph() const; - QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); - bool removeGraph(QCPGraph *graph); - bool removeGraph(int index); - int clearGraphs(); - int graphCount() const; - QList selectedGraphs() const; - - // item interface: - QCPAbstractItem *item(int index) const; - QCPAbstractItem *item() const; - bool removeItem(QCPAbstractItem *item); - bool removeItem(int index); - int clearItems(); - int itemCount() const; - QList selectedItems() const; - QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasItem(QCPAbstractItem *item) const; - - // layer interface: - QCPLayer *layer(const QString &name) const; - QCPLayer *layer(int index) const; - QCPLayer *currentLayer() const; - bool setCurrentLayer(const QString &name); - bool setCurrentLayer(QCPLayer *layer); - int layerCount() const; - bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); - bool removeLayer(QCPLayer *layer); - bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); - - // axis rect/layout interface: - int axisRectCount() const; - QCPAxisRect* axisRect(int index=0) const; - QList axisRects() const; - QCPLayoutElement* layoutElementAt(const QPointF &pos) const; - QCPAxisRect* axisRectAt(const QPointF &pos) const; - Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); - - QList selectedAxes() const; - QList selectedLegends() const; - Q_SLOT void deselectAll(); - - bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); - bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - QPixmap toPixmap(int width=0, int height=0, double scale=1.0); - void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); - - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - QCPLegend *legend; - -Q_SIGNALS: - void mouseDoubleClick(QMouseEvent *event); - void mousePress(QMouseEvent *event); - void mouseMove(QMouseEvent *event); - void mouseRelease(QMouseEvent *event); - void mouseWheel(QWheelEvent *event); - - void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void itemClick(QCPAbstractItem *item, QMouseEvent *event); - void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); - void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - - void selectionChangedByUser(); - void beforeReplot(); - void afterReplot(); - -protected: - // property members: - QRect mViewport; - double mBufferDevicePixelRatio; - QCPLayoutGrid *mPlotLayout; - bool mAutoAddPlottableToLegend; - QList mPlottables; - QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph - QList mItems; - QList mLayers; - QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; - QCP::Interactions mInteractions; - int mSelectionTolerance; - bool mNoAntialiasingOnDrag; - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayer *mCurrentLayer; - QCP::PlottingHints mPlottingHints; - Qt::KeyboardModifier mMultiSelectModifier; - QCP::SelectionRectMode mSelectionRectMode; - QCPSelectionRect *mSelectionRect; - bool mOpenGl; - - // non-property members: - QList > mPaintBuffers; - QPoint mMousePressPos; - bool mMouseHasMoved; - QPointer mMouseEventLayerable; - QPointer mMouseSignalLayerable; - QVariant mMouseEventLayerableDetails; - QVariant mMouseSignalLayerableDetails; - bool mReplotting; - bool mReplotQueued; - int mOpenGlMultisamples; - QCP::AntialiasedElements mOpenGlAntialiasedElementsBackup; - bool mOpenGlCacheLabelsBackup; -#ifdef QCP_OPENGL_FBO - QSharedPointer mGlContext; - QSharedPointer mGlSurface; - QSharedPointer mGlPaintDevice; -#endif - - // reimplemented virtual methods: - virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; - virtual QSize sizeHint() const Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void draw(QCPPainter *painter); - virtual void updateLayout(); - virtual void axisRemoved(QCPAxis *axis); - virtual void legendRemoved(QCPLegend *legend); - Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processPointSelection(QMouseEvent *event); - - // non-virtual methods: - bool registerPlottable(QCPAbstractPlottable *plottable); - bool registerGraph(QCPGraph *graph); - bool registerItem(QCPAbstractItem* item); - void updateLayerIndices() const; - QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; - QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=0) const; - void drawBackground(QCPPainter *painter); - void setupPaintBuffers(); - QCPAbstractPaintBuffer *createPaintBuffer(); - bool hasInvalidatedPaintBuffers(); - bool setupOpenGl(); - void freeOpenGl(); - - friend class QCPLegend; - friend class QCPAxis; - friend class QCPLayer; - friend class QCPAxisRect; - friend class QCPAbstractPlottable; - friend class QCPGraph; - friend class QCPAbstractItem; -}; -Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode) -Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority) - -/* end of 'src/core.h' */ - - -/* including file 'src/plottable1d.h', size 4544 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCPPlottableInterface1D -{ -public: - virtual ~QCPPlottableInterface1D() {} - // introduced pure virtual methods: - virtual int dataCount() const = 0; - virtual double dataMainKey(int index) const = 0; - virtual double dataSortKey(int index) const = 0; - virtual double dataMainValue(int index) const = 0; - virtual QCPRange dataValueRange(int index) const = 0; - virtual QPointF dataPixelPosition(int index) const = 0; - virtual bool sortKeyIsMainKey() const = 0; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; - virtual int findBegin(double sortKey, bool expandedRange=true) const = 0; - virtual int findEnd(double sortKey, bool expandedRange=true) const = 0; -}; - -template -class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) -{ - // No Q_OBJECT macro due to template class - -public: - QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPAbstractPlottable1D(); - - // virtual methods of 1d plottable interface: - virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - -protected: - // property members: - QSharedPointer > mDataContainer; - - // helpers for subclasses: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - void drawPolyline(QCPPainter *painter, const QVector &lineData) const; - -private: - Q_DISABLE_COPY(QCPAbstractPlottable1D) - -}; - -// include implementation in header since it is a class template: - -/* including file 'src/plottable1d.cpp', size 22240 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableInterface1D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableInterface1D - \brief Defines an abstract interface for one-dimensional plottables - - This class contains only pure virtual methods which define a common interface to the data - of one-dimensional plottables. - - For example, it is implemented by the template class \ref QCPAbstractPlottable1D (the preferred - base class for one-dimensional plottables). So if you use that template class as base class of - your one-dimensional plottable, you won't have to care about implementing the 1d interface - yourself. - - If your plottable doesn't derive from \ref QCPAbstractPlottable1D but still wants to provide a 1d - interface (e.g. like \ref QCPErrorBars does), you should inherit from both \ref - QCPAbstractPlottable and \ref QCPPlottableInterface1D and accordingly reimplement the pure - virtual methods of the 1d interface, matching your data container. Also, reimplement \ref - QCPAbstractPlottable::interface1D to return the \c this pointer. - - If you have a \ref QCPAbstractPlottable pointer, you can check whether it implements this - interface by calling \ref QCPAbstractPlottable::interface1D and testing it for a non-zero return - value. If it indeed implements this interface, you may use it to access the plottable's data - without needing to know the exact type of the plottable or its data point type. -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPPlottableInterface1D::dataCount() const = 0; - - Returns the number of data points of the plottable. -*/ - -/*! \fn virtual QCPDataSelection QCPPlottableInterface1D::selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; - - Returns a data selection containing all the data points of this plottable which are contained (or - hit by) \a rect. This is used mainly in the selection rect interaction for data selection (\ref - dataselection "data selection mechanism"). - - If \a onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not - selectable (i.e. if \ref QCPAbstractPlottable::setSelectable is \ref QCP::stNone). - - \note \a rect must be a normalized rect (positive or zero width and height). This is especially - important when using the rect of \ref QCPSelectionRect::accepted, which is not necessarily - normalized. Use QRect::normalized() when passing a rect which might not be normalized. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataMainKey(int index) const = 0 - - Returns the main key of the data point at the given \a index. - - What the main key is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataSortKey(int index) const = 0 - - Returns the sort key of the data point at the given \a index. - - What the sort key is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual double QCPPlottableInterface1D::dataMainValue(int index) const = 0 - - Returns the main value of the data point at the given \a index. - - What the main value is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual QCPRange QCPPlottableInterface1D::dataValueRange(int index) const = 0 - - Returns the value range of the data point at the given \a index. - - What the value range is, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual QPointF QCPPlottableInterface1D::dataPixelPosition(int index) const = 0 - - Returns the pixel position on the widget surface at which the data point at the given \a index - appears. - - Usually this corresponds to the point of \ref dataMainKey/\ref dataMainValue, in pixel - coordinates. However, depending on the plottable, this might be a different apparent position - than just a coord-to-pixel transform of those values. For example, \ref QCPBars apparent data - values can be shifted depending on their stacking, bar grouping or configured base value. -*/ - -/*! \fn virtual bool QCPPlottableInterface1D::sortKeyIsMainKey() const = 0 - - Returns whether the sort key (\ref dataSortKey) is identical to the main key (\ref dataMainKey). - - What the sort and main keys are, is defined by the plottable's data type. See the \ref - qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming - convention. -*/ - -/*! \fn virtual int QCPPlottableInterface1D::findBegin(double sortKey, bool expandedRange) const = 0 - - Returns the index of the data point with a (sort-)key that is equal to, just below, or just above - \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be considered, - otherwise the one just above. - - This can be used in conjunction with \ref findEnd to iterate over data points within a given key - range, including or excluding the bounding data points that are just beyond the specified range. - - If \a expandedRange is true but there are no data points below \a sortKey, 0 is returned. - - If the container is empty, returns 0 (in that case, \ref findEnd will also return 0, so a loop - using these methods will not iterate over the index 0). - - \see findEnd, QCPDataContainer::findBegin -*/ - -/*! \fn virtual int QCPPlottableInterface1D::findEnd(double sortKey, bool expandedRange) const = 0 - - Returns the index one after the data point with a (sort-)key that is equal to, just above, or - just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey will be - considered, otherwise the one just below. - - This can be used in conjunction with \ref findBegin to iterate over data points within a given - key range, including the bounding data points that are just below and above the specified range. - - If \a expandedRange is true but there are no data points above \a sortKey, the index just above the - highest data point is returned. - - If the container is empty, returns 0. - - \see findBegin, QCPDataContainer::findEnd -*/ - -/* end documentation of pure virtual functions */ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable1D -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable1D - \brief A template base class for plottables with one-dimensional data - - This template class derives from \ref QCPAbstractPlottable and from the abstract interface \ref - QCPPlottableInterface1D. It serves as a base class for all one-dimensional data (i.e. data with - one key dimension), such as \ref QCPGraph and QCPCurve. - - The template parameter \a DataType is the type of the data points of this plottable (e.g. \ref - QCPGraphData or \ref QCPCurveData). The main purpose of this base class is to provide the member - \a mDataContainer (a shared pointer to a \ref QCPDataContainer "QCPDataContainer") and - implement the according virtual methods of the \ref QCPPlottableInterface1D, such that most - subclassed plottables don't need to worry about this anymore. - - Further, it provides a convenience method for retrieving selected/unselected data segments via - \ref getDataSegments. This is useful when subclasses implement their \ref draw method and need to - draw selected segments with a different pen/brush than unselected segments (also see \ref - QCPSelectionDecorator). - - This class implements basic functionality of \ref QCPAbstractPlottable::selectTest and \ref - QCPPlottableInterface1D::selectTestRect, assuming point-like data points, based on the 1D data - interface. In spite of that, most plottable subclasses will want to reimplement those methods - again, to provide a more accurate hit test based on their specific data visualization geometry. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPPlottableInterface1D *QCPAbstractPlottable1D::interface1D() - - Returns a \ref QCPPlottableInterface1D pointer to this plottable, providing access to its 1D - interface. - - \seebaseclassmethod -*/ - -/* end documentation of inline functions */ - -/*! - Forwards \a keyAxis and \a valueAxis to the \ref QCPAbstractPlottable::QCPAbstractPlottable - "QCPAbstractPlottable" constructor and allocates the \a mDataContainer. -*/ -template -QCPAbstractPlottable1D::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QCPDataContainer) -{ -} - -template -QCPAbstractPlottable1D::~QCPAbstractPlottable1D() -{ -} - -/*! - \copydoc QCPPlottableInterface1D::dataCount -*/ -template -int QCPAbstractPlottable1D::dataCount() const -{ - return mDataContainer->size(); -} - -/*! - \copydoc QCPPlottableInterface1D::dataMainKey -*/ -template -double QCPAbstractPlottable1D::dataMainKey(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->mainKey(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataSortKey -*/ -template -double QCPAbstractPlottable1D::dataSortKey(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->sortKey(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataMainValue -*/ -template -double QCPAbstractPlottable1D::dataMainValue(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->mainValue(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return 0; - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataValueRange -*/ -template -QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - return (mDataContainer->constBegin()+index)->valueRange(); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QCPRange(0, 0); - } -} - -/*! - \copydoc QCPPlottableInterface1D::dataPixelPosition -*/ -template -QPointF QCPAbstractPlottable1D::dataPixelPosition(int index) const -{ - if (index >= 0 && index < mDataContainer->size()) - { - const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - return coordsToPixels(it->mainKey(), it->mainValue()); - } else - { - qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QPointF(); - } -} - -/*! - \copydoc QCPPlottableInterface1D::sortKeyIsMainKey -*/ -template -bool QCPAbstractPlottable1D::sortKeyIsMainKey() const -{ - return DataType::sortKeyIsMainKey(); -} - -/*! - Implements a rect-selection algorithm assuming the data (accessed via the 1D data interface) is - point-like. Most subclasses will want to reimplement this method again, to provide a more - accurate hit test based on the true data visualization geometry. - - \seebaseclassmethod -*/ -template -QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF &rect, bool onlySelectable) const -{ - QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return result; - if (!mKeyAxis || !mValueAxis) - return result; - - // convert rect given in pixels to ranges given in plot coordinates: - double key1, value1, key2, value2; - pixelsToCoords(rect.topLeft(), key1, value1); - pixelsToCoords(rect.bottomRight(), key2, value2); - QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 - QCPRange valueRange(value1, value2); - typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); - typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: - { - begin = mDataContainer->findBegin(keyRange.lower, false); - end = mDataContainer->findEnd(keyRange.upper, false); - } - if (begin == end) - return result; - - int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) - { - if (currentSegmentBegin == -1) - { - if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment - currentSegmentBegin = it-mDataContainer->constBegin(); - } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended - { - result.addDataRange(QCPDataRange(currentSegmentBegin, it-mDataContainer->constBegin()), false); - currentSegmentBegin = -1; - } - } - // process potential last segment: - if (currentSegmentBegin != -1) - result.addDataRange(QCPDataRange(currentSegmentBegin, end-mDataContainer->constBegin()), false); - - result.simplify(); - return result; -} - -/*! - \copydoc QCPPlottableInterface1D::findBegin -*/ -template -int QCPAbstractPlottable1D::findBegin(double sortKey, bool expandedRange) const -{ - return mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin(); -} - -/*! - \copydoc QCPPlottableInterface1D::findEnd -*/ -template -int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange) const -{ - return mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin(); -} - -/*! - Implements a point-selection algorithm assuming the data (accessed via the 1D data interface) is - point-like. Most subclasses will want to reimplement this method again, to provide a more - accurate hit test based on the true data visualization geometry. - - \seebaseclassmethod -*/ -template -double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) - return -1; - - QCPDataSelection selectionResult; - double minDistSqr = std::numeric_limits::max(); - int minDistIndex = mDataContainer->size(); - - typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); - typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: - { - // determine which key range comes into question, taking selection tolerance around pos into account: - double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - begin = mDataContainer->findBegin(posKeyMin, true); - end = mDataContainer->findEnd(posKeyMax, true); - } - if (begin == end) - return -1; - QCPRange keyRange(mKeyAxis->range()); - QCPRange valueRange(mValueAxis->range()); - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) - { - const double mainKey = it->mainKey(); - const double mainValue = it->mainValue(); - if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points - { - const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared(); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - minDistIndex = it-mDataContainer->constBegin(); - } - } - } - if (minDistIndex != mDataContainer->size()) - selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false); - - selectionResult.simplify(); - if (details) - details->setValue(selectionResult); - return qSqrt(minDistSqr); -} - -/*! - Splits all data into selected and unselected segments and outputs them via \a selectedSegments - and \a unselectedSegments, respectively. - - This is useful when subclasses implement their \ref draw method and need to draw selected - segments with a different pen/brush than unselected segments (also see \ref - QCPSelectionDecorator). - - \see setSelection -*/ -template -void QCPAbstractPlottable1D::getDataSegments(QList &selectedSegments, QList &unselectedSegments) const -{ - selectedSegments.clear(); - unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty - { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); - else - unselectedSegments << QCPDataRange(0, dataCount()); - } else - { - QCPDataSelection sel(selection()); - sel.simplify(); - selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); - } -} - -/*! - A helper method which draws a line with the passed \a painter, according to the pixel data in \a - lineData. NaN points create gaps in the line, as expected from QCustomPlot's plottables (this is - the main difference to QPainter's regular drawPolyline, which handles NaNs by lagging or - crashing). - - Further it uses a faster line drawing technique based on \ref QCPPainter::drawLine rather than \c - QPainter::drawPolyline if the configured \ref QCustomPlot::setPlottingHints() and \a painter - style allows. -*/ -template -void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const -{ - // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: - if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && - painter->pen().style() == Qt::SolidLine && - !painter->modes().testFlag(QCPPainter::pmVectorized) && - !painter->modes().testFlag(QCPPainter::pmNoCaching)) - { - int i = 0; - bool lastIsNan = false; - const int lineDataSize = lineData.size(); - while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN - ++i; - ++i; // because drawing works in 1 point retrospect - while (i < lineDataSize) - { - if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line - { - if (!lastIsNan) - painter->drawLine(lineData.at(i-1), lineData.at(i)); - else - lastIsNan = false; - } else - lastIsNan = true; - ++i; - } - } else - { - int segmentStart = 0; - int i = 0; - const int lineDataSize = lineData.size(); - while (i < lineDataSize) - { - if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block - { - painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point - segmentStart = i+1; - } - ++i; - } - // draw last segment: - painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart); - } -} -/* end of 'src/plottable1d.cpp' */ - - -/* end of 'src/plottable1d.h' */ - - -/* including file 'src/colorgradient.h', size 6243 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPColorGradient -{ - Q_GADGET -public: - /*! - Defines the color spaces in which color interpolation between gradient stops can be performed. - - \see setColorInterpolation - */ - enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated - ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) - }; - Q_ENUMS(ColorInterpolation) - - /*! - Defines the available presets that can be loaded with \ref loadPreset. See the documentation - there for an image of the presets. - */ - enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) - ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) - ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) - ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) - ,gpCandy ///< Blue over pink to white - ,gpGeography ///< Colors suitable to represent different elevations on geographical maps - ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) - ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white - ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values - ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) - ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) - ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) - }; - Q_ENUMS(GradientPreset) - - QCPColorGradient(); - QCPColorGradient(GradientPreset preset); - bool operator==(const QCPColorGradient &other) const; - bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } - - // getters: - int levelCount() const { return mLevelCount; } - QMap colorStops() const { return mColorStops; } - ColorInterpolation colorInterpolation() const { return mColorInterpolation; } - bool periodic() const { return mPeriodic; } - - // setters: - void setLevelCount(int n); - void setColorStops(const QMap &colorStops); - void setColorStopAt(double position, const QColor &color); - void setColorInterpolation(ColorInterpolation interpolation); - void setPeriodic(bool enabled); - - // non-property methods: - void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - QRgb color(double position, const QCPRange &range, bool logarithmic=false); - void loadPreset(GradientPreset preset); - void clearColorStops(); - QCPColorGradient inverted() const; - -protected: - // property members: - int mLevelCount; - QMap mColorStops; - ColorInterpolation mColorInterpolation; - bool mPeriodic; - - // non-property members: - QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) - bool mColorBufferInvalidated; - - // non-virtual methods: - bool stopsUseAlpha() const; - void updateColorBuffer(); -}; -Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) -Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) - -/* end of 'src/colorgradient.h' */ - - -/* including file 'src/selectiondecorator-bracket.h', size 4442 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator -{ - Q_GADGET -public: - - /*! - Defines which shape is drawn at the boundaries of selected data ranges. - - Some of the bracket styles further allow specifying a height and/or width, see \ref - setBracketHeight and \ref setBracketWidth. - */ - enum BracketStyle { bsSquareBracket ///< A square bracket is drawn. - ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsPlus ///< A plus is drawn. - ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. - }; - Q_ENUMS(BracketStyle) - - QCPSelectionDecoratorBracket(); - virtual ~QCPSelectionDecoratorBracket(); - - // getters: - QPen bracketPen() const { return mBracketPen; } - QBrush bracketBrush() const { return mBracketBrush; } - int bracketWidth() const { return mBracketWidth; } - int bracketHeight() const { return mBracketHeight; } - BracketStyle bracketStyle() const { return mBracketStyle; } - bool tangentToData() const { return mTangentToData; } - int tangentAverage() const { return mTangentAverage; } - - // setters: - void setBracketPen(const QPen &pen); - void setBracketBrush(const QBrush &brush); - void setBracketWidth(int width); - void setBracketHeight(int height); - void setBracketStyle(BracketStyle style); - void setTangentToData(bool enabled); - void setTangentAverage(int pointCount); - - // introduced virtual methods: - virtual void drawBracket(QCPPainter *painter, int direction) const; - - // virtual methods: - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE; - -protected: - // property members: - QPen mBracketPen; - QBrush mBracketBrush; - int mBracketWidth; - int mBracketHeight; - BracketStyle mBracketStyle; - bool mTangentToData; - int mTangentAverage; - - // non-virtual methods: - double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const; - QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const; - -}; -Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle) - -/* end of 'src/selectiondecorator-bracket.h' */ - - -/* including file 'src/layoutelements/layoutelement-axisrect.h', size 7507 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); - virtual ~QCPAxisRect(); - - // getters: - QPixmap background() const { return mBackgroundPixmap; } - QBrush backgroundBrush() const { return mBackgroundBrush; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - Qt::Orientations rangeDrag() const { return mRangeDrag; } - Qt::Orientations rangeZoom() const { return mRangeZoom; } - QCPAxis *rangeDragAxis(Qt::Orientation orientation); - QCPAxis *rangeZoomAxis(Qt::Orientation orientation); - QList rangeDragAxes(Qt::Orientation orientation); - QList rangeZoomAxes(Qt::Orientation orientation); - double rangeZoomFactor(Qt::Orientation orientation); - - // setters: - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setRangeDrag(Qt::Orientations orientations); - void setRangeZoom(Qt::Orientations orientations); - void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeDragAxes(QList axes); - void setRangeDragAxes(QList horizontal, QList vertical); - void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeZoomAxes(QList axes); - void setRangeZoomAxes(QList horizontal, QList vertical); - void setRangeZoomFactor(double horizontalFactor, double verticalFactor); - void setRangeZoomFactor(double factor); - - // non-property methods: - int axisCount(QCPAxis::AxisType type) const; - QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; - QList axes(QCPAxis::AxisTypes types) const; - QList axes() const; - QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0); - QList addAxes(QCPAxis::AxisTypes types); - bool removeAxis(QCPAxis *axis); - QCPLayoutInset *insetLayout() const { return mInsetLayout; } - - void zoom(const QRectF &pixelRect); - void zoom(const QRectF &pixelRect, const QList &affectedAxes); - void setupFullAxesBox(bool connectRanges=false); - QList plottables() const; - QList graphs() const; - QList items() const; - - // read-only interface imitating a QRect: - int left() const { return mRect.left(); } - int right() const { return mRect.right(); } - int top() const { return mRect.top(); } - int bottom() const { return mRect.bottom(); } - int width() const { return mRect.width(); } - int height() const { return mRect.height(); } - QSize size() const { return mRect.size(); } - QPoint topLeft() const { return mRect.topLeft(); } - QPoint topRight() const { return mRect.topRight(); } - QPoint bottomLeft() const { return mRect.bottomLeft(); } - QPoint bottomRight() const { return mRect.bottomRight(); } - QPoint center() const { return mRect.center(); } - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - -protected: - // property members: - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayoutInset *mInsetLayout; - Qt::Orientations mRangeDrag, mRangeZoom; - QList > mRangeDragHorzAxis, mRangeDragVertAxis; - QList > mRangeZoomHorzAxis, mRangeZoomVertAxis; - double mRangeZoomFactorHorz, mRangeZoomFactorVert; - - // non-property members: - QList mDragStartHorzRange, mDragStartVertRange; - QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - bool mDragging; - QHash > mAxes; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE; - virtual void layoutChanged() Q_DECL_OVERRIDE; - // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - - // non-property methods: - void drawBackground(QCPPainter *painter); - void updateAxesOffset(QCPAxis::AxisType type); - -private: - Q_DISABLE_COPY(QCPAxisRect) - - friend class QCustomPlot; -}; - - -/* end of 'src/layoutelements/layoutelement-axisrect.h' */ - - -/* including file 'src/layoutelements/layoutelement-legend.h', size 10397 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) - /// \endcond -public: - explicit QCPAbstractLegendItem(QCPLegend *parent); - - // getters: - QCPLegend *parentLegend() const { return mParentLegend; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - QCPLegend *mParentLegend; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPAbstractLegendItem) - - friend class QCPLegend; -}; - - -class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem -{ - Q_OBJECT -public: - QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); - - // getters: - QCPAbstractPlottable *plottable() { return mPlottable; } - -protected: - // property members: - QCPAbstractPlottable *mPlottable; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen getIconBorderPen() const; - QColor getTextColor() const; - QFont getFont() const; -}; - - -class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) - Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) - Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) - Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) - Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - /// \endcond -public: - /*! - Defines the selectable parts of a legend - - \see setSelectedParts, setSelectableParts - */ - enum SelectablePart { spNone = 0x000 ///< 0x000 None - ,spLegendBox = 0x001 ///< 0x001 The legend box (frame) - ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPLegend(); - virtual ~QCPLegend(); - - // getters: - QPen borderPen() const { return mBorderPen; } - QBrush brush() const { return mBrush; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QSize iconSize() const { return mIconSize; } - int iconTextPadding() const { return mIconTextPadding; } - QPen iconBorderPen() const { return mIconBorderPen; } - SelectableParts selectableParts() const { return mSelectableParts; } - SelectableParts selectedParts() const; - QPen selectedBorderPen() const { return mSelectedBorderPen; } - QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - - // setters: - void setBorderPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setIconSize(const QSize &size); - void setIconSize(int width, int height); - void setIconTextPadding(int padding); - void setIconBorderPen(const QPen &pen); - Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); - void setSelectedBorderPen(const QPen &pen); - void setSelectedIconBorderPen(const QPen &pen); - void setSelectedBrush(const QBrush &brush); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QCPAbstractLegendItem *item(int index) const; - QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; - int itemCount() const; - bool hasItem(QCPAbstractLegendItem *item) const; - bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; - bool addItem(QCPAbstractLegendItem *item); - bool removeItem(int index); - bool removeItem(QCPAbstractLegendItem *item); - void clearItems(); - QList selectedItems() const; - -Q_SIGNALS: - void selectionChanged(QCPLegend::SelectableParts parts); - void selectableChanged(QCPLegend::SelectableParts parts); - -protected: - // property members: - QPen mBorderPen, mIconBorderPen; - QBrush mBrush; - QFont mFont; - QColor mTextColor; - QSize mIconSize; - int mIconTextPadding; - SelectableParts mSelectedParts, mSelectableParts; - QPen mSelectedBorderPen, mSelectedIconBorderPen; - QBrush mSelectedBrush; - QFont mSelectedFont; - QColor mSelectedTextColor; - - // reimplemented virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; - virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen getBorderPen() const; - QBrush getBrush() const; - -private: - Q_DISABLE_COPY(QCPLegend) - - friend class QCustomPlot; - friend class QCPAbstractLegendItem; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) -Q_DECLARE_METATYPE(QCPLegend::SelectablePart) - -/* end of 'src/layoutelements/layoutelement-legend.h' */ - - -/* including file 'src/layoutelements/layoutelement-textelement.h', size 5353 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - explicit QCPTextElement(QCustomPlot *parentPlot); - QCPTextElement(QCustomPlot *parentPlot, const QString &text); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font); - - // getters: - QString text() const { return mText; } - int textFlags() const { return mTextFlags; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setText(const QString &text); - void setTextFlags(int flags); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - void clicked(QMouseEvent *event); - void doubleClicked(QMouseEvent *event); - -protected: - // property members: - QString mText; - int mTextFlags; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - QRect mTextBoundingRect; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - - // non-virtual methods: - QFont mainFont() const; - QColor mainTextColor() const; - -private: - Q_DISABLE_COPY(QCPTextElement) -}; - - - -/* end of 'src/layoutelements/layoutelement-textelement.h' */ - - -/* including file 'src/layoutelements/layoutelement-colorscale.h', size 5923 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - - -class QCPColorScaleAxisRectPrivate : public QCPAxisRect -{ - Q_OBJECT -public: - explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); -protected: - QCPColorScale *mParentColorScale; - QImage mGradientImage; - bool mGradientImageInvalidated; - // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale - using QCPAxisRect::calculateAutoMargin; - using QCPAxisRect::mousePressEvent; - using QCPAxisRect::mouseMoveEvent; - using QCPAxisRect::mouseReleaseEvent; - using QCPAxisRect::wheelEvent; - using QCPAxisRect::update; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - void updateGradientImage(); - Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); - friend class QCPColorScale; -}; - - -class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) - Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPColorScale(QCustomPlot *parentPlot); - virtual ~QCPColorScale(); - - // getters: - QCPAxis *axis() const { return mColorAxis.data(); } - QCPAxis::AxisType type() const { return mType; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - QCPColorGradient gradient() const { return mGradient; } - QString label() const; - int barWidth () const { return mBarWidth; } - bool rangeDrag() const; - bool rangeZoom() const; - - // setters: - void setType(QCPAxis::AxisType type); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setLabel(const QString &str); - void setBarWidth(int width); - void setRangeDrag(bool enabled); - void setRangeZoom(bool enabled); - - // non-property methods: - QList colorMaps() const; - void rescaleDataRange(bool onlyVisibleMaps); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); - -protected: - // property members: - QCPAxis::AxisType mType; - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorGradient mGradient; - int mBarWidth; - - // non-property members: - QPointer mAxisRect; - QPointer mColorAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QCPColorScale) - - friend class QCPColorScaleAxisRectPrivate; -}; - - -/* end of 'src/layoutelements/layoutelement-colorscale.h' */ - - -/* including file 'src/plottables/plottable-graph.h', size 9294 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPGraphData -{ -public: - QCPGraphData(); - QCPGraphData(double key, double value); - - inline double sortKey() const { return key; } - inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - - double key, value; -}; -Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPGraphDataContainer - - Container for storing \ref QCPGraphData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPGraph holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPGraphData, QCPGraph::setData -*/ -typedef QCPDataContainer QCPGraphDataContainer; - -class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) - Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) - /// \endcond -public: - /*! - Defines how the graph's line is represented visually in the plot. The line is drawn with the - current pen of the graph (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented - ///< with symbols according to the scatter style, see \ref setScatterStyle) - ,lsLine ///< data points are connected by a straight line - ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point - ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point - ,lsStepCenter ///< line is drawn as steps where the step is in between two data points - ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line - }; - Q_ENUMS(LineStyle) - - explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPGraph(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - LineStyle lineStyle() const { return mLineStyle; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - int scatterSkip() const { return mScatterSkip; } - QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } - bool adaptiveSampling() const { return mAdaptiveSampling; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setLineStyle(LineStyle ls); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setChannelFillGraph(QCPGraph *targetGraph); - void setAdaptiveSampling(bool enabled); - - // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - LineStyle mLineStyle; - QCPScatterStyle mScatterStyle; - int mScatterSkip; - QPointer mChannelFillGraph; - bool mAdaptiveSampling; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawFill(QCPPainter *painter, QVector *lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; - virtual void drawLinePlot(QCPPainter *painter, const QVector &lines) const; - virtual void drawImpulsePlot(QCPPainter *painter, const QVector &lines) const; - - virtual void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; - virtual void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; - - // non-virtual methods: - void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - void getLines(QVector *lines, const QCPDataRange &dataRange) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange) const; - QVector dataToLines(const QVector &data) const; - QVector dataToStepLeftLines(const QVector &data) const; - QVector dataToStepRightLines(const QVector &data) const; - QVector dataToStepCenterLines(const QVector &data) const; - QVector dataToImpulseLines(const QVector &data) const; - QVector getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const; - QVector > getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const; - bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const; - QPointF getFillBasePoint(QPointF matchingDataPoint) const; - const QPolygonF getFillPolygon(const QVector *lineData, QCPDataRange segment) const; - const QPolygonF getChannelFillPolygon(const QVector *lineData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const; - int findIndexBelowX(const QVector *data, double x) const; - int findIndexAboveX(const QVector *data, double x) const; - int findIndexBelowY(const QVector *data, double y) const; - int findIndexAboveY(const QVector *data, double y) const; - double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPGraph::LineStyle) - -/* end of 'src/plottables/plottable-graph.h' */ - - -/* including file 'src/plottables/plottable-curve.h', size 7409 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPCurveData -{ -public: - QCPCurveData(); - QCPCurveData(double t, double key, double value); - - inline double sortKey() const { return t; } - inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); } - inline static bool sortKeyIsMainKey() { return false; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - - double t, key, value; -}; -Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPCurveDataContainer - - Container for storing \ref QCPCurveData points. The data is stored sorted by \a t, so the \a - sortKey() (returning \a t) is different from \a mainKey() (returning \a key). - - This template instantiation is the container in which QCPCurve holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPCurveData, QCPCurve::setData -*/ -typedef QCPDataContainer QCPCurveDataContainer; - -class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - /// \endcond -public: - /*! - Defines how the curve's line is represented visually in the plot. The line is drawn with the - current pen of the curve (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) - ,lsLine ///< Data points are connected with a straight line - }; - Q_ENUMS(LineStyle) - - explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPCurve(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - int scatterSkip() const { return mScatterSkip; } - LineStyle lineStyle() const { return mLineStyle; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void setData(const QVector &keys, const QVector &values); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setLineStyle(LineStyle style); - - // non-property methods: - void addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(const QVector &keys, const QVector &values); - void addData(double t, double key, double value); - void addData(double key, double value); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - QCPScatterStyle mScatterStyle; - int mScatterSkip; - LineStyle mLineStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawCurveLine(QCPPainter *painter, const QVector &lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const; - - // non-virtual methods: - void getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const; - int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QVector getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - bool mayTraverse(int prevRegion, int currentRegion) const; - bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const; - void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const; - double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPCurve::LineStyle) - -/* end of 'src/plottables/plottable-curve.h' */ - - -/* including file 'src/plottables/plottable-bars.h', size 8924 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPBarsGroup : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType) - Q_PROPERTY(double spacing READ spacing WRITE setSpacing) - /// \endcond -public: - /*! - Defines the ways the spacing between bars in the group can be specified. Thus it defines what - the number passed to \ref setSpacing actually means. - - \see setSpacingType, setSpacing - */ - enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels - ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size - ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(SpacingType) - - QCPBarsGroup(QCustomPlot *parentPlot); - virtual ~QCPBarsGroup(); - - // getters: - SpacingType spacingType() const { return mSpacingType; } - double spacing() const { return mSpacing; } - - // setters: - void setSpacingType(SpacingType spacingType); - void setSpacing(double spacing); - - // non-virtual methods: - QList bars() const { return mBars; } - QCPBars* bars(int index) const; - int size() const { return mBars.size(); } - bool isEmpty() const { return mBars.isEmpty(); } - void clear(); - bool contains(QCPBars *bars) const { return mBars.contains(bars); } - void append(QCPBars *bars); - void insert(int i, QCPBars *bars); - void remove(QCPBars *bars); - -protected: - // non-property members: - QCustomPlot *mParentPlot; - SpacingType mSpacingType; - double mSpacing; - QList mBars; - - // non-virtual methods: - void registerBars(QCPBars *bars); - void unregisterBars(QCPBars *bars); - - // virtual methods: - double keyPixelOffset(const QCPBars *bars, double keyCoord); - double getPixelSpacing(const QCPBars *bars, double keyCoord); - -private: - Q_DISABLE_COPY(QCPBarsGroup) - - friend class QCPBars; -}; -Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType) - - -class QCP_LIB_DECL QCPBarsData -{ -public: - QCPBarsData(); - QCPBarsData(double key, double value); - - inline double sortKey() const { return key; } - inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here - - double key, value; -}; -Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPBarsDataContainer - - Container for storing \ref QCPBarsData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPBars holds its data. For details about - the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPBarsData, QCPBars::setData -*/ -typedef QCPDataContainer QCPBarsDataContainer; - -class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) - Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup) - Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue) - Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap) - Q_PROPERTY(QCPBars* barBelow READ barBelow) - Q_PROPERTY(QCPBars* barAbove READ barAbove) - /// \endcond -public: - /*! - Defines the ways the width of the bar can be specified. Thus it defines what the number passed - to \ref setWidth actually means. - - \see setWidthType, setWidth - */ - enum WidthType { wtAbsolute ///< Bar width is in absolute pixels - ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size - ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(WidthType) - - explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPBars(); - - // getters: - double width() const { return mWidth; } - WidthType widthType() const { return mWidthType; } - QCPBarsGroup *barsGroup() const { return mBarsGroup; } - double baseValue() const { return mBaseValue; } - double stackingGap() const { return mStackingGap; } - QCPBars *barBelow() const { return mBarBelow.data(); } - QCPBars *barAbove() const { return mBarAbove.data(); } - QSharedPointer data() const { return mDataContainer; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setBarsGroup(QCPBarsGroup *barsGroup); - void setBaseValue(double baseValue); - void setStackingGap(double pixels); - - // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - void moveBelow(QCPBars *bars); - void moveAbove(QCPBars *bars); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - -protected: - // property members: - double mWidth; - WidthType mWidthType; - QCPBarsGroup *mBarsGroup; - double mBaseValue; - double mStackingGap; - QPointer mBarBelow, mBarAbove; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const; - QRectF getBarRect(double key, double value) const; - void getPixelWidth(double key, double &lower, double &upper) const; - double getStackedBaseValue(double key, bool positive) const; - static void connectBars(QCPBars* lower, QCPBars* upper); - - friend class QCustomPlot; - friend class QCPLegend; - friend class QCPBarsGroup; -}; -Q_DECLARE_METATYPE(QCPBars::WidthType) - -/* end of 'src/plottables/plottable-bars.h' */ - - -/* including file 'src/plottables/plottable-statisticalbox.h', size 7516 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPStatisticalBoxData -{ -public: - QCPStatisticalBoxData(); - QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers=QVector()); - - inline double sortKey() const { return key; } - inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return median; } - - inline QCPRange valueRange() const - { - QCPRange result(minimum, maximum); - for (QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it) - result.expand(*it); - return result; - } - - double key, minimum, lowerQuartile, median, upperQuartile, maximum; - QVector outliers; -}; -Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE); - - -/*! \typedef QCPStatisticalBoxDataContainer - - Container for storing \ref QCPStatisticalBoxData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPStatisticalBox holds its data. For - details about the generic container, see the documentation of the class template \ref - QCPDataContainer. - - \see QCPStatisticalBoxData, QCPStatisticalBox::setData -*/ -typedef QCPDataContainer QCPStatisticalBoxDataContainer; - -class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen) - Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen) - Q_PROPERTY(bool whiskerAntialiased READ whiskerAntialiased WRITE setWhiskerAntialiased) - Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen) - Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle) - /// \endcond -public: - explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis); - - // getters: - QSharedPointer data() const { return mDataContainer; } - double width() const { return mWidth; } - double whiskerWidth() const { return mWhiskerWidth; } - QPen whiskerPen() const { return mWhiskerPen; } - QPen whiskerBarPen() const { return mWhiskerBarPen; } - bool whiskerAntialiased() const { return mWhiskerAntialiased; } - QPen medianPen() const { return mMedianPen; } - QCPScatterStyle outlierStyle() const { return mOutlierStyle; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void setWidth(double width); - void setWhiskerWidth(double width); - void setWhiskerPen(const QPen &pen); - void setWhiskerBarPen(const QPen &pen); - void setWhiskerAntialiased(bool enabled); - void setMedianPen(const QPen &pen); - void setOutlierStyle(const QCPScatterStyle &style); - - // non-property methods: - void addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers=QVector()); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -protected: - // property members: - double mWidth; - double mWhiskerWidth; - QPen mWhiskerPen, mWhiskerBarPen; - bool mWhiskerAntialiased; - QPen mMedianPen; - QCPScatterStyle mOutlierStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // introduced virtual methods: - virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const; - - // non-virtual methods: - void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const; - QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-statisticalbox.h' */ - - -/* including file 'src/plottables/plottable-colormap.h', size 7070 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPColorMapData -{ -public: - QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); - ~QCPColorMapData(); - QCPColorMapData(const QCPColorMapData &other); - QCPColorMapData &operator=(const QCPColorMapData &other); - - // getters: - int keySize() const { return mKeySize; } - int valueSize() const { return mValueSize; } - QCPRange keyRange() const { return mKeyRange; } - QCPRange valueRange() const { return mValueRange; } - QCPRange dataBounds() const { return mDataBounds; } - double data(double key, double value); - double cell(int keyIndex, int valueIndex); - unsigned char alpha(int keyIndex, int valueIndex); - - // setters: - void setSize(int keySize, int valueSize); - void setKeySize(int keySize); - void setValueSize(int valueSize); - void setRange(const QCPRange &keyRange, const QCPRange &valueRange); - void setKeyRange(const QCPRange &keyRange); - void setValueRange(const QCPRange &valueRange); - void setData(double key, double value, double z); - void setCell(int keyIndex, int valueIndex, double z); - void setAlpha(int keyIndex, int valueIndex, unsigned char alpha); - - // non-property methods: - void recalculateDataBounds(); - void clear(); - void clearAlpha(); - void fill(double z); - void fillAlpha(unsigned char alpha); - bool isEmpty() const { return mIsEmpty; } - void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; - void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; - -protected: - // property members: - int mKeySize, mValueSize; - QCPRange mKeyRange, mValueRange; - bool mIsEmpty; - - // non-property members: - double *mData; - unsigned char *mAlpha; - QCPRange mDataBounds; - bool mDataModified; - - bool createAlpha(bool initializeOpaque=true); - - friend class QCPColorMap; -}; - - -class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) - Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) - Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) - /// \endcond -public: - explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPColorMap(); - - // getters: - QCPColorMapData *data() const { return mMapData; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - bool interpolate() const { return mInterpolate; } - bool tightBoundary() const { return mTightBoundary; } - QCPColorGradient gradient() const { return mGradient; } - QCPColorScale *colorScale() const { return mColorScale.data(); } - - // setters: - void setData(QCPColorMapData *data, bool copy=false); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setInterpolate(bool enabled); - void setTightBoundary(bool enabled); - void setColorScale(QCPColorScale *colorScale); - - // non-property methods: - void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - -Q_SIGNALS: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); - -protected: - // property members: - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorMapData *mMapData; - QCPColorGradient mGradient; - bool mInterpolate; - bool mTightBoundary; - QPointer mColorScale; - - // non-property members: - QImage mMapImage, mUndersampledMapImage; - QPixmap mLegendIcon; - bool mMapImageInvalidated; - - // introduced virtual methods: - virtual void updateMapImage(); - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-colormap.h' */ - - -/* including file 'src/plottables/plottable-financial.h', size 8622 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPFinancialData -{ -public: - QCPFinancialData(); - QCPFinancialData(double key, double open, double high, double low, double close); - - inline double sortKey() const { return key; } - inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); } - inline static bool sortKeyIsMainKey() { return true; } - - inline double mainKey() const { return key; } - inline double mainValue() const { return open; } - - inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them - - double key, open, high, low, close; -}; -Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPFinancialDataContainer - - Container for storing \ref QCPFinancialData points. The data is stored sorted by \a key. - - This template instantiation is the container in which QCPFinancial holds its data. For details - about the generic container, see the documentation of the class template \ref QCPDataContainer. - - \see QCPFinancialData, QCPFinancial::setData -*/ -typedef QCPDataContainer QCPFinancialDataContainer; - -class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle) - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) - Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored) - Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive) - Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative) - Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive) - Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative) - /// \endcond -public: - /*! - Defines the ways the width of the financial bar can be specified. Thus it defines what the - number passed to \ref setWidth actually means. - - \see setWidthType, setWidth - */ - enum WidthType { wtAbsolute ///< width is in absolute pixels - ,wtAxisRectRatio ///< width is given by a fraction of the axis rect size - ,wtPlotCoords ///< width is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(WidthType) - - /*! - Defines the possible representations of OHLC data in the plot. - - \see setChartStyle - */ - enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation - ,csCandlestick ///< Candlestick representation - }; - Q_ENUMS(ChartStyle) - - explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPFinancial(); - - // getters: - QSharedPointer data() const { return mDataContainer; } - ChartStyle chartStyle() const { return mChartStyle; } - double width() const { return mWidth; } - WidthType widthType() const { return mWidthType; } - bool twoColored() const { return mTwoColored; } - QBrush brushPositive() const { return mBrushPositive; } - QBrush brushNegative() const { return mBrushNegative; } - QPen penPositive() const { return mPenPositive; } - QPen penNegative() const { return mPenNegative; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void setChartStyle(ChartStyle style); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setTwoColored(bool twoColored); - void setBrushPositive(const QBrush &brush); - void setBrushNegative(const QBrush &brush); - void setPenPositive(const QPen &pen); - void setPenNegative(const QPen &pen); - - // non-property methods: - void addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void addData(double key, double open, double high, double low, double close); - - // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - - // static methods: - static QCPFinancialDataContainer timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset = 0); - -protected: - // property members: - ChartStyle mChartStyle; - double mWidth; - WidthType mWidthType; - bool mTwoColored; - QBrush mBrushPositive, mBrushNegative; - QPen mPenPositive, mPenNegative; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - double getPixelWidth(double key, double keyPixel) const; - double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const; - QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; -Q_DECLARE_METATYPE(QCPFinancial::ChartStyle) - -/* end of 'src/plottables/plottable-financial.h' */ - - -/* including file 'src/plottables/plottable-errorbar.h', size 7727 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPErrorBarsData -{ -public: - QCPErrorBarsData(); - explicit QCPErrorBarsData(double error); - QCPErrorBarsData(double errorMinus, double errorPlus); - - double errorMinus, errorPlus; -}; -Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE); - - -/*! \typedef QCPErrorBarsDataContainer - - Container for storing \ref QCPErrorBarsData points. It is a typedef for QVector<\ref - QCPErrorBarsData>. - - This is the container in which \ref QCPErrorBars holds its data. Unlike most other data - containers for plottables, it is not based on \ref QCPDataContainer. This is because the error - bars plottable is special in that it doesn't store its own key and value coordinate per error - bar. It adopts the key and value from the plottable to which the error bars shall be applied - (\ref QCPErrorBars::setDataPlottable). So the stored \ref QCPErrorBarsData doesn't need a - sortable key, but merely an index (as \c QVector provides), which maps one-to-one to the indices - of the other plottable's data. - - \see QCPErrorBarsData, QCPErrorBars::setData -*/ -typedef QVector QCPErrorBarsDataContainer; - -class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottableInterface1D -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QSharedPointer data READ data WRITE setData) - Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable) - Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap) - /// \endcond -public: - - /*! - Defines in which orientation the error bars shall appear. If your data needs both error - dimensions, create two \ref QCPErrorBars with different \ref ErrorType. - - \see setErrorType - */ - enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) - ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) - }; - Q_ENUMS(ErrorType) - - explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPErrorBars(); - // getters: - QSharedPointer data() const { return mDataContainer; } - QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); } - ErrorType errorType() const { return mErrorType; } - double whiskerWidth() const { return mWhiskerWidth; } - double symbolGap() const { return mSymbolGap; } - - // setters: - void setData(QSharedPointer data); - void setData(const QVector &error); - void setData(const QVector &errorMinus, const QVector &errorPlus); - void setDataPlottable(QCPAbstractPlottable* plottable); - void setErrorType(ErrorType type); - void setWhiskerWidth(double pixels); - void setSymbolGap(double pixels); - - // non-property methods: - void addData(const QVector &error); - void addData(const QVector &errorMinus, const QVector &errorPlus); - void addData(double error); - void addData(double errorMinus, double errorPlus); - - // virtual methods of 1d plottable interface: - virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - -protected: - // property members: - QSharedPointer mDataContainer; - QPointer mDataPlottable; - ErrorType mErrorType; - double mWhiskerWidth; - double mSymbolGap; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const; - void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const; - // helpers: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - bool errorBarVisible(int index) const; - bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - -/* end of 'src/plottables/plottable-errorbar.h' */ - - -/* including file 'src/items/item-straightline.h', size 3117 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - explicit QCPItemStraightLine(QCustomPlot *parentPlot); - virtual ~QCPItemStraightLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const point1; - QCPItemPosition * const point2; - -protected: - // property members: - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QLineF getRectClippedStraightLine(const QCPVector2D &point1, const QCPVector2D &vec, const QRect &rect) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-straightline.h' */ - - -/* including file 'src/items/item-line.h', size 3407 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - explicit QCPItemLine(QCustomPlot *parentPlot); - virtual ~QCPItemLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-line.h' */ - - -/* including file 'src/items/item-curve.h', size 3379 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - explicit QCPItemCurve(QCustomPlot *parentPlot); - virtual ~QCPItemCurve(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const startDir; - QCPItemPosition * const endDir; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; -}; - -/* end of 'src/items/item-curve.h' */ - - -/* including file 'src/items/item-rect.h', size 3688 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - explicit QCPItemRect(QCustomPlot *parentPlot); - virtual ~QCPItemRect(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-rect.h' */ - - -/* including file 'src/items/item-text.h', size 5554 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemText : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) - Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) - Q_PROPERTY(double rotation READ rotation WRITE setRotation) - Q_PROPERTY(QMargins padding READ padding WRITE setPadding) - /// \endcond -public: - explicit QCPItemText(QCustomPlot *parentPlot); - virtual ~QCPItemText(); - - // getters: - QColor color() const { return mColor; } - QColor selectedColor() const { return mSelectedColor; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont font() const { return mFont; } - QFont selectedFont() const { return mSelectedFont; } - QString text() const { return mText; } - Qt::Alignment positionAlignment() const { return mPositionAlignment; } - Qt::Alignment textAlignment() const { return mTextAlignment; } - double rotation() const { return mRotation; } - QMargins padding() const { return mPadding; } - - // setters; - void setColor(const QColor &color); - void setSelectedColor(const QColor &color); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setFont(const QFont &font); - void setSelectedFont(const QFont &font); - void setText(const QString &text); - void setPositionAlignment(Qt::Alignment alignment); - void setTextAlignment(Qt::Alignment alignment); - void setRotation(double degrees); - void setPadding(const QMargins &padding); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const position; - QCPItemAnchor * const topLeft; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRight; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QColor mColor, mSelectedColor; - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - QFont mFont, mSelectedFont; - QString mText; - Qt::Alignment mPositionAlignment; - Qt::Alignment mTextAlignment; - double mRotation; - QMargins mPadding; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; - QFont mainFont() const; - QColor mainColor() const; - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-text.h' */ - - -/* including file 'src/items/item-ellipse.h', size 3868 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - explicit QCPItemEllipse(QCustomPlot *parentPlot); - virtual ~QCPItemEllipse(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const topLeftRim; - QCPItemAnchor * const top; - QCPItemAnchor * const topRightRim; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRightRim; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeftRim; - QCPItemAnchor * const left; - QCPItemAnchor * const center; - -protected: - enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - -/* end of 'src/items/item-ellipse.h' */ - - -/* including file 'src/items/item-pixmap.h', size 4373 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) - Q_PROPERTY(bool scaled READ scaled WRITE setScaled) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) - Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - explicit QCPItemPixmap(QCustomPlot *parentPlot); - virtual ~QCPItemPixmap(); - - // getters: - QPixmap pixmap() const { return mPixmap; } - bool scaled() const { return mScaled; } - Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; } - Qt::TransformationMode transformationMode() const { return mTransformationMode; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPixmap(const QPixmap &pixmap); - void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPixmap mPixmap; - QPixmap mScaledPixmap; - bool mScaled; - bool mScaledPixmapInvalidated; - Qt::AspectRatioMode mAspectRatioMode; - Qt::TransformationMode mTransformationMode; - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); - QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; - QPen mainPen() const; -}; - -/* end of 'src/items/item-pixmap.h' */ - - -/* including file 'src/items/item-tracer.h', size 4762 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(double size READ size WRITE setSize) - Q_PROPERTY(TracerStyle style READ style WRITE setStyle) - Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) - Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) - Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) - /// \endcond -public: - /*! - The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize. - - \see setStyle - */ - enum TracerStyle { tsNone ///< The tracer is not visible - ,tsPlus ///< A plus shaped crosshair with limited size - ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect - ,tsCircle ///< A circle - ,tsSquare ///< A square - }; - Q_ENUMS(TracerStyle) - - explicit QCPItemTracer(QCustomPlot *parentPlot); - virtual ~QCPItemTracer(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - double size() const { return mSize; } - TracerStyle style() const { return mStyle; } - QCPGraph *graph() const { return mGraph; } - double graphKey() const { return mGraphKey; } - bool interpolating() const { return mInterpolating; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setSize(double size); - void setStyle(TracerStyle style); - void setGraph(QCPGraph *graph); - void setGraphKey(double key); - void setInterpolating(bool enabled); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - // non-virtual methods: - void updatePosition(); - - QCPItemPosition * const position; - -protected: - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - double mSize; - TracerStyle mStyle; - QCPGraph *mGraph; - double mGraphKey; - bool mInterpolating; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; -Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle) - -/* end of 'src/items/item-tracer.h' */ - - -/* including file 'src/items/item-bracket.h', size 3969 */ -/* commit 9868e55d3b412f2f89766bb482fcf299e93a0988 2017-09-04 01:56:22 +0200 */ - -class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(double length READ length WRITE setLength) - Q_PROPERTY(BracketStyle style READ style WRITE setStyle) - /// \endcond -public: - /*! - Defines the various visual shapes of the bracket item. The appearance can be further modified - by \ref setLength and \ref setPen. - - \see setStyle - */ - enum BracketStyle { bsSquare ///< A brace with angled edges - ,bsRound ///< A brace with round edges - ,bsCurly ///< A curly brace - ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression - }; - Q_ENUMS(BracketStyle) - - explicit QCPItemBracket(QCustomPlot *parentPlot); - virtual ~QCPItemBracket(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - double length() const { return mLength; } - BracketStyle style() const { return mStyle; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setLength(double length); - void setStyle(BracketStyle style); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const left; - QCPItemPosition * const right; - QCPItemAnchor * const center; - -protected: - // property members: - enum AnchorIndex {aiCenter}; - QPen mPen, mSelectedPen; - double mLength; - BracketStyle mStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - - // non-virtual methods: - QPen mainPen() const; -}; -Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) - -/* end of 'src/items/item-bracket.h' */ - - -#endif // QCUSTOMPLOT_H From d5551f2c2d8bfdf9346f7f6f9f4a166febb12d78 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:31:01 -0400 Subject: [PATCH 1134/1324] Delete user.cpp --- src/qt/user.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/qt/user.cpp diff --git a/src/qt/user.cpp b/src/qt/user.cpp deleted file mode 100644 index 1934e769..00000000 --- a/src/qt/user.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "user.h" - -user::user() -{ - userName=""; - id=0; -} - -user::user(QString passWord, QString email,QString name,int userID) -{ - userName=name; - userFileManipulator.name=name; - userFileManipulator.createFile(passWord,email,name,creationDate.getDateNow()); - id=userID; -} - -void user :: setUsersList(user A) -{ - usersList.append(A); -} - -QString user:: getUserName(int id) -{ - return usersList[id].userName; -} - - bool user:: usersEmpty() - { - return (usersList.size()==0); - } - -int user:: getUsersSize() -{ - return usersList.count(); -} From c04da273a62b08ffde9e910285098bebc109f1ba Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:31:11 -0400 Subject: [PATCH 1135/1324] Delete statistics.cpp --- src/qt/statistics.cpp | 46 ------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/qt/statistics.cpp diff --git a/src/qt/statistics.cpp b/src/qt/statistics.cpp deleted file mode 100644 index 50eb5373..00000000 --- a/src/qt/statistics.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "statistics.h" - -Statistics::Statistics() -{ - -} - -void Statistics::setLikesNumber(unsigned int number) -{ - likesNumber = number; -} - -void Statistics::setFriendsNumber(unsigned int number) -{ - friendsNumber = number; -} - -void Statistics::setPostsNumber(unsigned int number) -{ - postsNumber = number; -} - -void Statistics::setUserID(unsigned int number) -{ - userID = number; -} - -unsigned int Statistics::getLikesNumber() -{ - return likesNumber; -} - -unsigned int Statistics::getPostsNumber() -{ - return postsNumber; -} - -unsigned int Statistics::getFriendsNumber() -{ - return friendsNumber; -} - -unsigned int Statistics::getUserID() -{ - return userID; -} From 1504700505a7bce8f7f0be021a58988d4d2de548 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:31:21 -0400 Subject: [PATCH 1136/1324] Delete statistics.h --- src/qt/statistics.h | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/qt/statistics.h diff --git a/src/qt/statistics.h b/src/qt/statistics.h deleted file mode 100644 index 0cec4093..00000000 --- a/src/qt/statistics.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef STATISTICS_H -#define STATISTICS_H -#include - -class Statistics -{ -public: - Statistics(); - - void setLikesNumber(unsigned int number); - - void setFriendsNumber(unsigned int number); - - void setPostsNumber(unsigned int number); - - void setUserID(unsigned int number); - - unsigned int getLikesNumber(); - - unsigned int getPostsNumber(); - - unsigned int getFriendsNumber(); - - unsigned int getUserID(); - - -private: - unsigned int userID; - - unsigned int likesNumber; - - unsigned int friendsNumber; - - unsigned int postsNumber; -}; - -#endif // STATISTICS_H From f3ac14de5ec60e9ada880d86d9b12da2a6bbe0e8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:31:33 -0400 Subject: [PATCH 1137/1324] Delete user.h --- src/qt/user.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/qt/user.h diff --git a/src/qt/user.h b/src/qt/user.h deleted file mode 100644 index 35a000b0..00000000 --- a/src/qt/user.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef USER_H -#define USER_H -#include "posts.h" -#include "fileman.h" -#include -#include -class user -{ -public: - QString userName; - int id; - Post userPost; - fileman userFileManipulator; - Date creationDate; - user(); - user(QString passWord, QString email, QString name,int userID); - void setUsersList( user A ); - QString getUserName(int id); - bool usersEmpty(); - int getUsersSize(); - -private: - QList usersList; -}; - -#endif // USER_H From 9b5ffcb74f978d7a693a8d3e1de9698332b068f6 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:32:13 -0400 Subject: [PATCH 1138/1324] Update walletview.h --- src/qt/walletview.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 3be6fd21..8393d6de 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,7 +8,6 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" -#include "mainwindow.h" #include @@ -25,7 +24,6 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; -class MainWindow; QT_BEGIN_NAMESPACE class QLabel; @@ -74,7 +72,6 @@ class WalletView : public QStackedWidget MasternodeList *masternodeListPage; PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; - MainWindow *mainWindow; TransactionView *transactionView; @@ -85,8 +82,6 @@ class WalletView : public QStackedWidget public Q_SLOTS: - /** Switch to social media page */ - void gotoMainWindow(); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 225ff65a9dc6c386ee7b6b7054af963b58f035e8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:33:12 -0400 Subject: [PATCH 1139/1324] Update walletview.cpp --- src/qt/walletview.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 27f5558d..7eb1c079 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -84,11 +84,8 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); - - mainWindow = new MainWindow(); - addWidget(mainWindow); - QSettings settings; + QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage = new MasternodeList(platformStyle); addWidget(masternodeListPage); @@ -234,11 +231,6 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } -void WalletView::gotoMainWindow() -{ - setCurrentWidget(mainWindow); -} - void WalletView::gotoGovernancePage() { QSettings settings; From 313acf2c7ecbab07dafd17afbf2564222c2eb027 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:33:33 -0400 Subject: [PATCH 1140/1324] Update walletframe.h --- src/qt/walletframe.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index cd335d21..90a1bb55 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -65,9 +65,7 @@ public Q_SLOTS: /** Switch to social media page */ - void gotoGovernancePage(); - /** Switch to social media page */ - void gotoMainWindow(); + void gotoGovernancePage(); /** Switch to private send page */ void gotoPrivateSendPage(); /** Switch to overview (home) page */ From cdff03e4341791eb87bf93bca720c27b92b7ed5a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:33:57 -0400 Subject: [PATCH 1141/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index abf30d21..6783019e 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,14 +108,6 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } -void WalletFrame::gotoMainWindow() -{ - - QMap::const_iterator i; - for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) - i.value()->gotoMainWindow(); -} - void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; From 94f91374cfba9481841e118e32eb12de05c54633 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:34:54 -0400 Subject: [PATCH 1142/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 050853f2..00451a57 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,6 @@ #include "amount.h" #include "governancelist.h" -#include "mainwindow.h" #include #include @@ -39,7 +38,6 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; -class MainWindow; class CWallet; @@ -105,7 +103,6 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; - QAction* mainWindow; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -234,30 +231,20 @@ private Q_SLOTS: #ifdef ENABLE_WALLET - /** Switch to social media page */ - void gotoMainWindow(); - /** Switch to masternode page */ - void gotoGovernancePage(); - + void gotoGovernancePage(); /** Switch to trading page */ - /* void gotoTradingDialogPage(); */ - + /* void gotoTradingDialogPage(); */ /** Switch to private send page */ /* void gotoPrivateSendPage(); */ - /** Switch to overview (home) page */ - void gotoOverviewPage(); - + void gotoOverviewPage(); /** Switch to history (transactions) page */ - void gotoHistoryPage(); - + void gotoHistoryPage(); /** Switch to masternode page */ - void gotoMasternodePage(); - + void gotoMasternodePage(); /** Switch to receive coins page */ - void gotoReceiveCoinsPage(); - + void gotoReceiveCoinsPage(); /** Switch to send coins page */ void gotoSendCoinsPage(QString addr = ""); From 51bf808453abd27c70dc6791254bb656470c133c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:36:46 -0400 Subject: [PATCH 1143/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index b8a33e51..efc0f6e7 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,7 +22,6 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" -#include "mainwindow.h" /* #include "tradingdialogpage.h" */ @@ -143,7 +142,6 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * spinnerFrame(0), externalDonate(0), governanceAction(0), - mainWindow(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -605,10 +603,7 @@ void BitcoinGUI::createActions() // HTHW Donate externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); - // HTH Chat - mainWindow = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH World"), this); - mainWindow->setStatusTip(tr("HTH World")); - + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); @@ -619,9 +614,7 @@ void BitcoinGUI::createActions() // HTHW Donate - connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); - // HTHW Chat - connect(mainWindow, SIGNAL(triggered()), this, SLOT(gotoMainWindow())); + connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); @@ -722,9 +715,6 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); - - QMenu* media = appMenuBar->addMenu(tr("&HTH World")); - media->addAction(mainWindow); } @@ -1052,12 +1042,6 @@ void BitcoinGUI::openClicked() } } -void BitcoinGUI::gotoMainWindow() -{ - mainWindow->setChecked(true); - if (walletFrame) walletFrame->gotoMainWindow(); -} - void BitcoinGUI::gotoGovernancePage() { governanceAction->setChecked(true); From 199f0438657321cfc5e12702d30bae60248ae31c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:36:56 -0400 Subject: [PATCH 1144/1324] Delete addcomment.ui --- src/qt/forms/addcomment.ui | 107 ------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 src/qt/forms/addcomment.ui diff --git a/src/qt/forms/addcomment.ui b/src/qt/forms/addcomment.ui deleted file mode 100644 index c670061d..00000000 --- a/src/qt/forms/addcomment.ui +++ /dev/null @@ -1,107 +0,0 @@ - - - AddComment - - - - 0 - 0 - 348 - 222 - - - - Dialog - - - - - 11 - 183 - 193 - 28 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 75 - 15 - 262 - 151 - - - - - - - 10 - 70 - 57 - 41 - - - - - - - Add - - - Qt::AlignCenter - - - - - - - Comment - - - - - - - - - - buttonBox - accepted() - AddComment - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - AddComment - reject() - - - 316 - 260 - - - 286 - 274 - - - - - From 3b50d25ae1c75c64558f764c489368ed2ed707e3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:01 -0400 Subject: [PATCH 1145/1324] Delete adminwindow.ui --- src/qt/forms/adminwindow.ui | 71 ------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/qt/forms/adminwindow.ui diff --git a/src/qt/forms/adminwindow.ui b/src/qt/forms/adminwindow.ui deleted file mode 100644 index 4eb710bd..00000000 --- a/src/qt/forms/adminwindow.ui +++ /dev/null @@ -1,71 +0,0 @@ - - - AdminWindow - - - - 0 - 0 - 800 - 550 - - - - MainWindow - - - - - - - true - - - - - 0 - 0 - 776 - 440 - - - - - - - - - - - - - - Show Statistics - - - - - - - - - 0 - 0 - 800 - 26 - - - - - - - - QCustomPlot - QWidget -
qcustomplot.h
- 1 -
-
- - -
From da70a006e895d3a574bcbfe3ec5d7eb1f0a1770f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:10 -0400 Subject: [PATCH 1146/1324] Delete form.ui --- src/qt/forms/form.ui | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/qt/forms/form.ui diff --git a/src/qt/forms/form.ui b/src/qt/forms/form.ui deleted file mode 100644 index 55b96fdf..00000000 --- a/src/qt/forms/form.ui +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Form - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - From 400e1b4479bf0cba35aa77ec49ac2324ed6fa726 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:30 -0400 Subject: [PATCH 1147/1324] Delete homepage.ui --- src/qt/forms/homepage.ui | 188 --------------------------------------- 1 file changed, 188 deletions(-) delete mode 100644 src/qt/forms/homepage.ui diff --git a/src/qt/forms/homepage.ui b/src/qt/forms/homepage.ui deleted file mode 100644 index 0d3cdb97..00000000 --- a/src/qt/forms/homepage.ui +++ /dev/null @@ -1,188 +0,0 @@ - - - HomePage - - - - 0 - 0 - 1102 - 761 - - - - MainWindow - - - - - - - - - - - - - - - - 400 - 16777215 - - - - - - - - - - - View Profile - - - - - - - View Network Staristics Window - - - - - - - - - - - - 16777215 - 100 - - - - 1 - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - What's On Your Mind ?! - - - - - - - Post - - - - - - - - - - - - - - - true - - - - - 0 - 0 - 1045 - 335 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - 0 - 0 - 1102 - 26 - - - - - File - - - - - - - - - - Log Out - - - - - - From 07ba08567365e693fb5d066e0e7f0d38dce6546c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:39 -0400 Subject: [PATCH 1148/1324] Delete mainwindow.ui --- src/qt/forms/mainwindow.ui | 561 ------------------------------------- 1 file changed, 561 deletions(-) delete mode 100644 src/qt/forms/mainwindow.ui diff --git a/src/qt/forms/mainwindow.ui b/src/qt/forms/mainwindow.ui deleted file mode 100644 index bf97769c..00000000 --- a/src/qt/forms/mainwindow.ui +++ /dev/null @@ -1,561 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 767 - 534 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 233 - 228 - 219 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 255 - - - - - - - 233 - 228 - 219 - - - - - - - 106 - 100 - 92 - - - - - - - 141 - 134 - 123 - - - - - - - 106 - 100 - 92 - - - - - - - 255 - 255 - 255 - - - - - - - 106 - 100 - 92 - - - - - - - 212 - 201 - 184 - - - - - - - 212 - 201 - 184 - - - - - - - 0 - 0 - 0 - - - - - - - 212 - 201 - 184 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - MainWindow - - - - - - 330 - 60 - 101 - 31 - - - - PointingHandCursor - - - Sign Up - - - - - - 150 - 220 - 91 - 31 - - - - PointingHandCursor - - - Log In - - - - - - 170 - 130 - 171 - 21 - - - - - - - 170 - 170 - 171 - 21 - - - - - - - 20 - 130 - 121 - 21 - - - - - 10 - 75 - true - - - - Username - - - - - - 20 - 170 - 131 - 16 - - - - - 10 - 75 - true - - - - Password - - - - - - 320 - 30 - 141 - 21 - - - - No account? Create one! - - - - - - - 0 - 0 - 767 - 26 - - - - - - TopToolBarArea - - - false - - - - - - - - From 842171a83e7eef077b6e50a8705f0c2b6539a445 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:47 -0400 Subject: [PATCH 1149/1324] Delete newaccount.ui --- src/qt/forms/newaccount.ui | 203 ------------------------------------- 1 file changed, 203 deletions(-) delete mode 100644 src/qt/forms/newaccount.ui diff --git a/src/qt/forms/newaccount.ui b/src/qt/forms/newaccount.ui deleted file mode 100644 index 1103a2c9..00000000 --- a/src/qt/forms/newaccount.ui +++ /dev/null @@ -1,203 +0,0 @@ - - - newAccount - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - - 250 - 290 - 161 - 20 - - - - QLineEdit::Password - - - - - - 70 - 320 - 151 - 20 - - - - - Times New Roman - 14 - 75 - true - - - - confirm password - - - lineEdit_3 - - - - - - 610 - 280 - 81 - 31 - - - - - Times New Roman - 11 - 75 - true - - - - Sign Up - - - - - - 250 - 320 - 161 - 20 - - - - QLineEdit::Password - - - - - - 90 - 290 - 101 - 16 - - - - - Times New Roman - 14 - 75 - true - - - - password - - - lineEdit_2 - - - - - - 500 - 80 - 121 - 31 - - - - - Times New Roman - 11 - 75 - true - - - - Sign In - - - - - - 100 - 260 - 61 - 16 - - - - - Times New Roman - 14 - 75 - true - - - - Email - - - lineEdit - - - - - - 250 - 260 - 161 - 20 - - - - - - - 110 - 130 - 321 - 20 - - - - - Times New Roman - 16 - 75 - true - - - - if you already have an account ---> - - - - - - - 0 - 0 - 800 - 26 - - - - - - - - From 16cb8d4c6a04f6fd36244b4419b6d5a2a87b753d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:37:56 -0400 Subject: [PATCH 1150/1324] Delete profilepage.ui --- src/qt/forms/profilepage.ui | 271 ------------------------------------ 1 file changed, 271 deletions(-) delete mode 100644 src/qt/forms/profilepage.ui diff --git a/src/qt/forms/profilepage.ui b/src/qt/forms/profilepage.ui deleted file mode 100644 index 8114320a..00000000 --- a/src/qt/forms/profilepage.ui +++ /dev/null @@ -1,271 +0,0 @@ - - - ProfilePage - - - - 0 - 0 - 1008 - 596 - - - - MainWindow - - - - - - - - - - - - Arial - 15 - 75 - true - - - - User name label Area - - - - - - - Add as a friend - - - - - - - - - - - - Arial - 9 - 75 - true - - - - Home - - - - - - - - Arial - 9 - 75 - true - - - - Friends - - - 8 - - - - Friends - - - - - - - - - - - - - Arial - 12 - 75 - true - - - - INFO - - - - - - - - - - - - - Arial - 9 - - - - Email - - - - - - - lblMail - - - - - - - - - - - - Arial - 9 - - - - Number of friends - - - - - - - labelNumber - - - - - - - - - - - border-color:blue; - - - - true - - - - - 0 - 0 - 982 - 349 - - - - - - - - 16777215 - 100 - - - - - - - What's on your mind? - - - - - - - - Arial - 9 - 75 - true - - - - false - - - background-color: rgb(85, 0, 255); -color:white; -selection-color: rgb(255, 255, 255); - - - Post - - - - - - - true - - - - - 0 - 0 - 958 - 183 - - - - - - - - - - - - - - - - - - - - 0 - 0 - 1008 - 26 - - - - - File - - - - - - - - - - Log out - - - - - - From 944fc1758994685e304038ebe3fcf59471bce2da Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 20:39:51 -0400 Subject: [PATCH 1151/1324] Update Makefile.qt.include --- src/Makefile.qt.include | 59 +++-------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index a22f9aa5..faa4d1cc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -52,15 +52,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ - qt/forms/transactiondescdialog.ui \ - qt/forms/addcomment.ui \ - qt/forms/adminwindow.ui \ - qt/forms/dialog.ui \ - qt/forms/form.ui \ - qt/forms/homepage.ui \ - qt/forms/profilepage.ui \ - qt/forms/mainwindow.ui \ - qt/forms/newaccount.ui + qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ qt/moc_addressbookpage.cpp \ @@ -112,21 +104,7 @@ QT_MOC_CPP = \ qt/moc_utilitydialog.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ - qt/moc_walletview.cpp \ - qt/moc_activity.cpp \ - qt/moc_addcomment.cpp \ - qt/moc_adminwindow.cpp \ - qt/moc_comment.cpp \ - qt/moc_fileman.cpp \ - qt/moc_form.cpp \ - qt/moc_homepage.cpp \ - qt/moc_posts.cpp \ - qt/moc_profilepage.cpp \ - qt/moc_qcustomplot.cpp \ - qt/moc_statistics.cpp \ - qt/moc_user.cpp \ - qt/moc_mainwindow.cpp \ - qt/moc_newaccount.cpp + qt/moc_walletview.cpp BITCOIN_MM = \ qt/macdockiconhandler.mm \ @@ -209,21 +187,7 @@ BITCOIN_QT_H = \ qt/walletmodel.h \ qt/walletmodeltransaction.h \ qt/walletview.h \ - qt/winshutdownmonitor.h \ - qt/activity.h \ - qt/addcomment.h \ - qt/adminwindow.h \ - qt/comment.h \ - qt/fileman.h \ - qt/form.h \ - qt/homepage.h \ - qt/posts.h \ - qt/profilepage.h \ - qt/qcustomplot.h \ - qt/statistics.h \ - qt/user.h \ - qt/mainwindow.h \ - qt/newaccount.h + qt/winshutdownmonitor.h RES_ICONS = \ qt/res/icons/bitcoin.ico \ @@ -561,22 +525,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/walletframe.cpp \ qt/walletmodel.cpp \ qt/walletmodeltransaction.cpp \ - qt/walletview.cpp \ - qt/activity.cpp \ - qt/addcomment.cpp \ - qt/adminwindow.cpp \ - qt/comment.cpp \ - qt/fileman.cpp \ - qt/form.cpp \ - qt/homepage.cpp \ - qt/posts.cpp \ - qt/profilepage.cpp \ - qt/qcustomplot.cpp \ - qt/statistics.cpp \ - qt/user.cpp \ - qt/main.cpp \ - qt/mainwindow.cpp \ - qt/newaccount.cpp + qt/walletview.cpp BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP) if TARGET_WINDOWS From 1914b0fc5721d67390e9a56cc5d9f68803479386 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:04:40 -0400 Subject: [PATCH 1152/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 74 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 7299c197..0fecfe2a 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -71,7 +71,10 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) currentWatchOnlyBalance(-1), currentWatchUnconfBalance(-1), currentWatchImmatureBalance(-1), - cachedNumISLocks(-1) + cachedNumISLocks(-1), + labelCurrentMarket(0), + labelCurrentPrice(0), + pricingTimer(0) { @@ -90,7 +93,10 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) //information block update - + labelCurrentMarket = new QLabel(); + labelCurrentPrice = new QLabel(); + pricingTimer = new QTimer(); + timerinfo_mn = new QTimer(this); connect(timerinfo_mn, SIGNAL(timeout()), this, SLOT(updateMasternodeInfo())); timerinfo_mn->start(1000); @@ -263,6 +269,70 @@ void OverviewPage::updateBlockChainInfo() } } +/** Price Information **/ + + +// Network request code for the header widget + QObject::connect(networkManager, &QNetworkAccessManager::finished, + this, [=](QNetworkReply *reply) { + if (reply->error()) { + labelCurrentPrice->setText(""); + qDebug() << reply->errorString(); + return; + } + // Get the data from the network request + QString answer = reply->readAll(); + + // Create regex expression to find the value with 8 decimals + QRegExp rx("\\d*.\\d\\d\\d\\d\\d\\d\\d\\d"); + rx.indexIn(answer); + + // List the found values + QStringList list = rx.capturedTexts(); + + QString currentPriceStyleSheet = ".QLabel{color: #debf12;}"; + // Evaluate the current and next numbers and assign a color (green for positive, red for negative) + bool ok; + if (!list.isEmpty()) { + double next = list.first().toDouble(&ok); + if (!ok) { + /* labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); */ + labelCurrentPrice->setText(""); + } else { + double current = labelCurrentPrice->text().toDouble(&ok); + if (!ok) { + current = 0.00000000; + } else { + if (next < current) + labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("red")); + else if (next > current) + labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("green")); + /* else + labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); */ + } + labelCurrentPrice->setText(QString("%1").arg(QString().setNum(next, 'f', 8))); + labelCurrentPrice->setToolTip(tr("Brought to you by binance.com")); + } + } + } + ); + + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + // Create the timer + connect(pricingTimer, SIGNAL(timeout()), this, SLOT(getPriceInfo())); + pricingTimer->start(10000); + getPriceInfo(); + /** RVN END */ + +void OverviewPage::getPriceInfo() +{ + request->setUrl(QUrl("https://api.binance.com/api/v1/ticker/price?symbol=RVNBTC")); + networkManager->get(*request); +} + +/** Price Information ** + /**** End Blockchain Information ******/ From 1af3d8fa84f53bd0eb7d341dab39d49937477d17 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:05:42 -0400 Subject: [PATCH 1153/1324] Update overviewpage.h --- src/qt/overviewpage.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 71c54401..cc9068f1 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -84,6 +84,11 @@ public Q_SLOTS: private: + QLabel *labelCurrentMarket; + QLabel *labelCurrentPrice; + QTimer *pricingTimer; + QNetworkAccessManager* networkManager; + QNetworkRequest* request; QTimer *timer; QTimer* timerinfo_mn; QTimer* timerinfo_blockchain; @@ -132,6 +137,7 @@ private Q_SLOTS: void updateBlockChainInfo(); void updateMasternodeInfo(); void updatePeersInfo(); + void getPriceInfo(); }; #endif // BITCOIN_QT_OVERVIEWPAGE_H From e25d6b712a8c7199f4a06cc770bf5b92e68066b5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:06:33 -0400 Subject: [PATCH 1154/1324] Update overviewpage.ui --- src/qt/forms/overviewpage.ui | 192 +++++++++++++++++++++-------------- 1 file changed, 116 insertions(+), 76 deletions(-) diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index 095fb42b..1183889f 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -46,7 +46,7 @@ 0 300 461 - 201 + 231 @@ -75,6 +75,29 @@ QFrame::Raised + + + + + + + Difficulty: + + + Qt::AlignVCenter + + + + + + + 0 + + + Qt::AlignVCenter + + + @@ -100,8 +123,8 @@ - - + + Qt::Vertical @@ -113,69 +136,28 @@ - - - - - - - Difficulty: - - - Qt::AlignVCenter - - - - - - - Peers: - - - - - - - 0 - - - Qt::AlignVCenter - - - - - - - Qt::Vertical + + + + + 110 + 0 + - + - 20 - 40 + 130 + 16777215 - - - - - - - 0 - 0 - + + - 0 + Algorithm: - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Node Count: + Qt::AlignVCenter @@ -229,6 +211,42 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Node Count: + + + @@ -265,30 +283,52 @@ - - - - - 110 - 0 - + + + + Peers: - + + + + + + Price2: + + + + + + + Price: + + + + + + + Qt::Vertical + + - 130 - 16777215 + 20 + 40 - - - - - Algorithm: + + + + + + Qt::Vertical - - Qt::AlignVCenter + + + 20 + 40 + - + From 5ae36cef0b60193969818b97586819aea64399b3 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:10:54 -0400 Subject: [PATCH 1155/1324] Update overviewpage.h --- src/qt/overviewpage.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index cc9068f1..f3ad2c68 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -87,8 +87,6 @@ public Q_SLOTS: QLabel *labelCurrentMarket; QLabel *labelCurrentPrice; QTimer *pricingTimer; - QNetworkAccessManager* networkManager; - QNetworkRequest* request; QTimer *timer; QTimer* timerinfo_mn; QTimer* timerinfo_blockchain; From d198b79452d19261839fa3a3fa5762fabc8b3f2f Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:17:17 -0400 Subject: [PATCH 1156/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 0fecfe2a..d3a59764 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -95,7 +95,11 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) labelCurrentMarket = new QLabel(); labelCurrentPrice = new QLabel(); - pricingTimer = new QTimer(); + + pricingTimer = new QTimer(); + connect(pricingTimer, SIGNAL(timeout()), this, SLOT(getPriceInfo())); + pricingTimer->start(10000); + getPriceInfo(); timerinfo_mn = new QTimer(this); connect(timerinfo_mn, SIGNAL(timeout()), this, SLOT(updateMasternodeInfo())); @@ -316,15 +320,6 @@ void OverviewPage::updateBlockChainInfo() } } ); - - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - - // Create the timer - connect(pricingTimer, SIGNAL(timeout()), this, SLOT(getPriceInfo())); - pricingTimer->start(10000); - getPriceInfo(); - /** RVN END */ - void OverviewPage::getPriceInfo() { request->setUrl(QUrl("https://api.binance.com/api/v1/ticker/price?symbol=RVNBTC")); From 798fc49368821f75ad48ba3fdb84e53e546331be Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:25:58 -0400 Subject: [PATCH 1157/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d3a59764..91562635 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -319,7 +319,8 @@ void OverviewPage::updateBlockChainInfo() } } } - ); + ) + void OverviewPage::getPriceInfo() { request->setUrl(QUrl("https://api.binance.com/api/v1/ticker/price?symbol=RVNBTC")); From 1f2150c4af4bdca2b5c875b67f35c2f36743e7c8 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:33:28 -0400 Subject: [PATCH 1158/1324] Update overviewpage.h --- src/qt/overviewpage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index f3ad2c68..a9b459a2 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define MASTERNODELIST_UPDATE_SECONDS 3 #define MASTERNODELIST_FILTER_COOLDOWN_SECONDS 3 From a60fea8b9fdc610adc76646dfb5369c193ca1989 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:35:10 -0400 Subject: [PATCH 1159/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 91562635..6f2331e2 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -319,7 +319,7 @@ void OverviewPage::updateBlockChainInfo() } } } - ) + ); void OverviewPage::getPriceInfo() { From 52d3e04a053b5768b5d0baa2df9a0f84f7416a87 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:36:12 -0400 Subject: [PATCH 1160/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 6f2331e2..5bbf891d 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #define ICON_OFFSET 16 #define DECORATION_SIZE 54 From 374ee1c37ab329d27ae4aa6f193859ee48f60620 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:40:29 -0400 Subject: [PATCH 1161/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 5bbf891d..44eb1136 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -75,7 +75,9 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) cachedNumISLocks(-1), labelCurrentMarket(0), labelCurrentPrice(0), - pricingTimer(0) + pricingTimer(0), + networkManager(0), + request(0) { @@ -96,6 +98,8 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) labelCurrentMarket = new QLabel(); labelCurrentPrice = new QLabel(); + networkManager = new QNetworkAccessManager(); + request = new QNetworkRequest(); pricingTimer = new QTimer(); connect(pricingTimer, SIGNAL(timeout()), this, SLOT(getPriceInfo())); From 9e5eaed8fd6734026400228f195df6fde898e2fb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:57:36 -0400 Subject: [PATCH 1162/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 44eb1136..d7c00819 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -324,7 +324,7 @@ void OverviewPage::updateBlockChainInfo() } } } - ); + ) void OverviewPage::getPriceInfo() { From 0e6448b86438be1b5f1fc21c3243d5490d0e250d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:02:00 -0400 Subject: [PATCH 1163/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d7c00819..b7c3db37 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,7 +282,8 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget - QObject::connect(networkManager, &QNetworkAccessManager::finished, + QObject::connect() + {networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); @@ -324,7 +325,7 @@ void OverviewPage::updateBlockChainInfo() } } } - ) + } void OverviewPage::getPriceInfo() { From 8765310fbef26edcac9cac1ed051b409d1917bcd Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:02:38 -0400 Subject: [PATCH 1164/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index b7c3db37..05c2d968 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,8 +282,7 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget - QObject::connect() - {networkManager, &QNetworkAccessManager::finished, + QObject::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); @@ -325,7 +324,7 @@ void OverviewPage::updateBlockChainInfo() } } } - } + ) void OverviewPage::getPriceInfo() { From 90c531b937a91a18edb3b8420f2962ec623b2108 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:06:16 -0400 Subject: [PATCH 1165/1324] Update overviewpage.h --- src/qt/overviewpage.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index a9b459a2..68dd8cb2 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -72,6 +72,8 @@ public Q_SLOTS: void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); + + void getPriceInfo(); @@ -137,7 +139,6 @@ private Q_SLOTS: void updateBlockChainInfo(); void updateMasternodeInfo(); void updatePeersInfo(); - void getPriceInfo(); - }; + }; #endif // BITCOIN_QT_OVERVIEWPAGE_H From fa6352521fda11d8c56c7867087820dc1ccc227c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:12:14 -0400 Subject: [PATCH 1166/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 05c2d968..b82bbc41 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,7 +282,7 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget - QObject::connect(networkManager, &QNetworkAccessManager::finished, + bool OverviewPage::QObject::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); From 6762696695c21b401088260cf9242c0310b3077c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:13:59 -0400 Subject: [PATCH 1167/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index b82bbc41..9422ebe7 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,7 +282,7 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget - bool OverviewPage::QObject::connect(networkManager, &QNetworkAccessManager::finished, + bool OverviewPage::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); From 5f4b0405ff1a8b96d6969b457accb16c76d77900 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:15:19 -0400 Subject: [PATCH 1168/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 9422ebe7..adc1b38b 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,7 +282,7 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget - bool OverviewPage::connect(networkManager, &QNetworkAccessManager::finished, +void OverviewPage::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); From 784703f7d7869d66a08a13d92fe71a11fb95667e Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Thu, 2 Jul 2020 22:16:26 -0400 Subject: [PATCH 1169/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index adc1b38b..8e525c81 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -282,7 +282,7 @@ void OverviewPage::updateBlockChainInfo() // Network request code for the header widget -void OverviewPage::connect(networkManager, &QNetworkAccessManager::finished, +QObject::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); From c111b9545e573cb923460bac5e4ca8c590fd3a7c Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:31:59 -0400 Subject: [PATCH 1170/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 8e525c81..fcc37f09 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -281,8 +281,8 @@ void OverviewPage::updateBlockChainInfo() /** Price Information **/ -// Network request code for the header widget -QObject::connect(networkManager, &QNetworkAccessManager::finished, + // Network request code for the header widget + QObject::connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { if (reply->error()) { labelCurrentPrice->setText(""); @@ -305,7 +305,7 @@ QObject::connect(networkManager, &QNetworkAccessManager::finished, if (!list.isEmpty()) { double next = list.first().toDouble(&ok); if (!ok) { - /* labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); */ + labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); labelCurrentPrice->setText(""); } else { double current = labelCurrentPrice->text().toDouble(&ok); @@ -316,15 +316,15 @@ QObject::connect(networkManager, &QNetworkAccessManager::finished, labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("red")); else if (next > current) labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("green")); - /* else - labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); */ + else + labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); } labelCurrentPrice->setText(QString("%1").arg(QString().setNum(next, 'f', 8))); labelCurrentPrice->setToolTip(tr("Brought to you by binance.com")); } } } - ) + ); void OverviewPage::getPriceInfo() { From b2403f9b1b20d639c6af46f710ae80f7d80351c2 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:34:59 -0400 Subject: [PATCH 1171/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index fcc37f09..742d5c67 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -276,7 +276,7 @@ void OverviewPage::updateBlockChainInfo() ui->label_Nethash_3->setText(tr("Difficulty:")); ui->label_Nethash_value_3->setText(QString::number(CurrentDiff,'f',4)); } -} +}; /** Price Information **/ From f2752277dc52d6de9736746d3c66a49d84cb5e0a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:37:38 -0400 Subject: [PATCH 1172/1324] Update overviewpage.cpp --- src/qt/overviewpage.cpp | 74 ++--------------------------------------- 1 file changed, 2 insertions(+), 72 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 742d5c67..9a2e9818 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -72,12 +72,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) currentWatchOnlyBalance(-1), currentWatchUnconfBalance(-1), currentWatchImmatureBalance(-1), - cachedNumISLocks(-1), - labelCurrentMarket(0), - labelCurrentPrice(0), - pricingTimer(0), - networkManager(0), - request(0) + cachedNumISLocks(-1) { @@ -95,17 +90,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) ui->labelWalletStatus->setText("(" + tr("out of sync") + ")"); //information block update - - labelCurrentMarket = new QLabel(); - labelCurrentPrice = new QLabel(); - networkManager = new QNetworkAccessManager(); - request = new QNetworkRequest(); - - pricingTimer = new QTimer(); - connect(pricingTimer, SIGNAL(timeout()), this, SLOT(getPriceInfo())); - pricingTimer->start(10000); - getPriceInfo(); - + timerinfo_mn = new QTimer(this); connect(timerinfo_mn, SIGNAL(timeout()), this, SLOT(updateMasternodeInfo())); timerinfo_mn->start(1000); @@ -278,61 +263,6 @@ void OverviewPage::updateBlockChainInfo() } }; -/** Price Information **/ - - - // Network request code for the header widget - QObject::connect(networkManager, &QNetworkAccessManager::finished, - this, [=](QNetworkReply *reply) { - if (reply->error()) { - labelCurrentPrice->setText(""); - qDebug() << reply->errorString(); - return; - } - // Get the data from the network request - QString answer = reply->readAll(); - - // Create regex expression to find the value with 8 decimals - QRegExp rx("\\d*.\\d\\d\\d\\d\\d\\d\\d\\d"); - rx.indexIn(answer); - - // List the found values - QStringList list = rx.capturedTexts(); - - QString currentPriceStyleSheet = ".QLabel{color: #debf12;}"; - // Evaluate the current and next numbers and assign a color (green for positive, red for negative) - bool ok; - if (!list.isEmpty()) { - double next = list.first().toDouble(&ok); - if (!ok) { - labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); - labelCurrentPrice->setText(""); - } else { - double current = labelCurrentPrice->text().toDouble(&ok); - if (!ok) { - current = 0.00000000; - } else { - if (next < current) - labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("red")); - else if (next > current) - labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg("green")); - else - labelCurrentPrice->setStyleSheet(currentPriceStyleSheet.arg(COLOR_LABELS.name())); - } - labelCurrentPrice->setText(QString("%1").arg(QString().setNum(next, 'f', 8))); - labelCurrentPrice->setToolTip(tr("Brought to you by binance.com")); - } - } - } - ); - -void OverviewPage::getPriceInfo() -{ - request->setUrl(QUrl("https://api.binance.com/api/v1/ticker/price?symbol=RVNBTC")); - networkManager->get(*request); -} - -/** Price Information ** /**** End Blockchain Information ******/ From 033751bbe3cb193ff739bf370f21a188fb1db32a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:38:50 -0400 Subject: [PATCH 1173/1324] Update overviewpage.h --- src/qt/overviewpage.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 68dd8cb2..2fb3cb84 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -71,9 +71,7 @@ class OverviewPage : public QWidget public Q_SLOTS: void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, - const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); - - void getPriceInfo(); + const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance); @@ -87,10 +85,6 @@ public Q_SLOTS: private: - - QLabel *labelCurrentMarket; - QLabel *labelCurrentPrice; - QTimer *pricingTimer; QTimer *timer; QTimer* timerinfo_mn; QTimer* timerinfo_blockchain; From c667a8f8456b7a466314f8fe1c55d27c76de9618 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:39:40 -0400 Subject: [PATCH 1174/1324] Update overviewpage.ui --- src/qt/forms/overviewpage.ui | 104 +++++++++++------------------------ 1 file changed, 32 insertions(+), 72 deletions(-) diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index 1183889f..dbdd1fa8 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -75,19 +75,6 @@ QFrame::Raised - - - - - - - Difficulty: - - - Qt::AlignVCenter - - - @@ -186,6 +173,19 @@ + + + + + + + Difficulty: + + + Qt::AlignVCenter + + + @@ -211,18 +211,12 @@ - - - - Qt::Vertical - - - - 20 - 40 - + + + + Node Count: - + @@ -240,39 +234,6 @@ - - - - Node Count: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -290,22 +251,21 @@ - - - - Price2: + + + + Qt::Vertical - - - - - - Price: + + + 20 + 40 + - + - - + + Qt::Vertical @@ -317,8 +277,8 @@ - - + + Qt::Vertical From 262f021db66e6d595e62b557da5e5a97dbea433a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 21:44:29 -0400 Subject: [PATCH 1175/1324] Update chainparams.cpp --- src/chainparams.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index dfa3e578..8709e385 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -198,7 +198,7 @@ class CMainParams : public CChainParams { CMainParams() { strNetworkID = "main"; consensus.nSubsidyHalvingInterval = 525600; // halves once a year (86400/60)*365 - consensus.nMasternodePaymentsStartBlock = 90; + consensus.nMasternodePaymentsStartBlock = 100; consensus.nMasternodePaymentsIncreaseBlock = -1; consensus.nMasternodePaymentsIncreasePeriod = -1; consensus.nInstantSendConfirmationsRequired = 6; @@ -208,19 +208,19 @@ class CMainParams : public CChainParams { consensus.nBudgetPaymentsStartBlock = -1; consensus.nBudgetPaymentsCycleBlocks = -1; consensus.nBudgetPaymentsWindowBlocks = 100; - consensus.nSuperblockStartBlock = 1048576; + consensus.nSuperblockStartBlock = 150; consensus.nSuperblockStartHash = uint256S("0000000000000000000000000000000000000000000000000000000000000000"); - consensus.nSuperblockCycle = 1048576; + consensus.nSuperblockCycle = 150; consensus.nGovernanceMinQuorum = 10; consensus.nGovernanceFilterElements = 20000; consensus.nMasternodeMinimumConfirmations = 15; - consensus.BIP34Height = 30; + consensus.BIP34Height = 5; consensus.BIP34Hash = uint256S("0000000000000000000000000000000000000000000000000000000000000000"); - consensus.BIP65Height = 30; - consensus.BIP66Height = 30; - consensus.DIP0001Height = 50; - consensus.DIP0003Height = 1000; - consensus.DIP0003EnforcementHeight = 1048576; // this can be dropped back later + consensus.BIP65Height = 5; + consensus.BIP66Height = 5; + consensus.DIP0001Height = 5; + consensus.DIP0003Height = 5; + consensus.DIP0003EnforcementHeight = 100; // this can be dropped back later consensus.DIP0003EnforcementHash = uint256S("0000000000000000000000000000000000000000000000000000000000000000"); consensus.powLimit = uint256S("0000fffff0000000000000000000000000000000000000000000000000000000"); consensus.nPowTargetTimespan = 60; @@ -231,7 +231,7 @@ class CMainParams : public CChainParams { consensus.nMinerConfirmationWindow = 2016; consensus.devAddress = "hWrjjP7w4iE5tezxDG3jD7xCTmikw3Kgoy"; consensus.devAddressPubKey = "b027849d3febd03af8063fc9f1f1226fbe3eb74c"; - consensus.nDevelopersFeeBegin = 250; + consensus.nDevelopersFeeBegin = 200; /* consensus.FoundationAddress = "BB2BwSbDCqCqNsfc7FgWFJn4sRgnUt4tsM"; consensus.FoundationPODSAddress = "BScSypUZVEEY4TMz1ehyyPcS5wrnMM7WPB"; From f2bc79c6a181b9c515afa159806c4d5eead2506d Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:39:24 -0400 Subject: [PATCH 1176/1324] Update bitcoingui.cpp --- src/qt/bitcoingui.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index efc0f6e7..b7f1bc81 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -561,6 +561,8 @@ void BitcoinGUI::createActions() signMessageAction->setStatusTip(tr("Sign messages with your HelpTheHomeless addresses to prove you own them")); verifyMessageAction = new QAction(QIcon(":/icons/" + theme + "/transaction_0"), tr("&Verify message..."), this); verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified HelpTheHomeless addresses")); + proposalGeneratorAction = new QAction(QIcon(":/icons/sign"), tr("New Proposal..."), this); + proposalGeneratorAction->setStatusTip(tr("Create a proposal and submit it to the network")); openInfoAction = new QAction(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation), tr("&Information"), this); openInfoAction->setStatusTip(tr("Show diagnostic information")); @@ -646,6 +648,8 @@ void BitcoinGUI::createActions() connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses())); connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses())); connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked())); + connect(proposalGeneratorAction, &QAction::triggered, [this]{ showNormalIfMinimized(); }); + connect(proposalGeneratorAction, &QAction::triggered, [this]{ gotoProposalGenerator(); }); } #endif // ENABLE_WALLET @@ -678,6 +682,7 @@ void BitcoinGUI::createMenuBar() file->addAction(usedSendingAddressesAction); file->addAction(usedReceivingAddressesAction); file->addSeparator(); + file->addAction(proposalGeneratorAction); } file->addAction(quitAction); @@ -901,7 +906,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) verifyMessageAction->setEnabled(enabled); usedSendingAddressesAction->setEnabled(enabled); usedReceivingAddressesAction->setEnabled(enabled); - openAction->setEnabled(enabled); + openAction->setEnabled(enabled); + proposalGeneratorAction->setEnabled(enabled); } @@ -937,6 +943,7 @@ void BitcoinGUI::createIconMenu(QMenu *pmenu) pmenu->addAction(showBackupsAction); #ifndef Q_OS_MAC // This is built-in on Mac pmenu->addSeparator(); + pmenu->addAction(proposalGeneratorAction); pmenu->addAction(quitAction); #endif } @@ -1042,6 +1049,11 @@ void BitcoinGUI::openClicked() } } +void BitcoinGUI::gotoProposalGenerator(QString addr) +{ + if (walletFrame) walletFrame->gotoProposalGenerator(addr); +} + void BitcoinGUI::gotoGovernancePage() { governanceAction->setChecked(true); From fc72fca4b44d2eac5d8d5640345084be4c6f6e6a Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:40:34 -0400 Subject: [PATCH 1177/1324] Update bitcoingui.h --- src/qt/bitcoingui.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 00451a57..7b443f83 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -103,6 +103,7 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; + QAction* proposalGeneratorAction = nullptr; QAction* externalDonate; QAction *governanceAction; /* QAction* privatesendAction; */ @@ -230,7 +231,8 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - + /** Show Proposal Generator */ + void gotoProposalGenerator(QString addr = ""); /** Switch to masternode page */ void gotoGovernancePage(); /** Switch to trading page */ From dfc523bd6067b1cb2d2bc6f1bffe2adf9fe47535 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:40:55 -0400 Subject: [PATCH 1178/1324] Update walletframe.cpp --- src/qt/walletframe.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 6783019e..9c802eb5 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,6 +108,13 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } +void WalletFrame::gotoProposalGenerator(QString addr) +{ + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->gotoProposalGenerator(addr); +} + void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; From d86d5392eac3425fd8fe5f1edc7d891ae1f12f31 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:41:23 -0400 Subject: [PATCH 1179/1324] Update walletframe.h --- src/qt/walletframe.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 90a1bb55..6e777b1e 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,7 +63,8 @@ class WalletFrame : public QFrame public Q_SLOTS: - + /** Show Proposal Generator */ + void gotoProposalGenerator(QString addr = ""); /** Switch to social media page */ void gotoGovernancePage(); /** Switch to private send page */ From ac2ff465d8e8c988650f2b280cd93171e15098bf Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:42:32 -0400 Subject: [PATCH 1180/1324] Update walletview.cpp --- src/qt/walletview.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 7eb1c079..cf240004 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -231,6 +231,24 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } +void WalletView::gotoProposalGenerator(QString addr) +{ + ProposalDialog *proposalDialog = new ProposalDialog(platformStyle, this); + proposalDialog->setAttribute(Qt::WA_DeleteOnClose); + proposalDialog->setClientModel(clientModel); + proposalDialog->setModel(walletModel); + + // Pass through messages from proposalDialog + connect(proposalDialog, &ProposalDialog::message, this, &WalletView::message); + + // Highlight transaction after send + connect(proposalDialog, &ProposalDialog::coinsSent, transactionView, static_cast(&TransactionView::focusTransaction)); + + if (!addr.isEmpty()) + proposalDialog->setAddress(addr); + proposalDialog->show(); +} + void WalletView::gotoGovernancePage() { QSettings settings; From 3154266fd996e7d299101d23fe34bed098e9b670 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:42:56 -0400 Subject: [PATCH 1181/1324] Update walletview.h --- src/qt/walletview.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 8393d6de..352db8d7 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -81,7 +81,9 @@ class WalletView : public QStackedWidget public Q_SLOTS: - + + /** Show Proposal Generator */ + void gotoProposalGenerator(QString addr = ""); /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ From 7afe4b75312483d59b0d30bddbef322a7adfc814 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:44:23 -0400 Subject: [PATCH 1182/1324] Create proposaldialog.cpp --- src/qt/proposaldialog.cpp | 296 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 src/qt/proposaldialog.cpp diff --git a/src/qt/proposaldialog.cpp b/src/qt/proposaldialog.cpp new file mode 100644 index 00000000..1745e61e --- /dev/null +++ b/src/qt/proposaldialog.cpp @@ -0,0 +1,296 @@ +// Copyright (c) 2019 PM-Tech +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +static const int MAX_DATA_SIZE = 256; + +ProposalDialog::ProposalDialog(const PlatformStyle *_platformStyle, QWidget *parent) : + QDialog(parent), + ui(new Ui::ProposalDialog), + clientModel(nullptr), + model(nullptr), + platformStyle(_platformStyle) +{ + ui->setupUi(this); + +#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac + ui->submitButton->setIcon(QIcon()); + ui->clearButton->setIcon(QIcon()); +#else + ui->submitButton->setIcon(QIcon(":/icons/edit")); + ui->clearButton->setIcon(QIcon(":/icons/remove")); +#endif + + // These icons are needed on Mac also + ui->addressBookButton->setIcon(QIcon(":/icons/address-book")); + ui->pasteButton->setIcon(QIcon(":/icons/editpaste")); + + GUIUtil::setupAddressWidget(ui->addressIn, this); + + ui->dateEdit->setDate(QDate::currentDate()); + ui->dateEdit->setMinimumDate(QDate::currentDate()); + + ui->addressIn->installEventFilter(this); + ui->proposalIn->installEventFilter(this); + ui->amountIn->installEventFilter(this); +} + +ProposalDialog::~ProposalDialog() +{ + delete ui; +} + +void ProposalDialog::setClientModel(ClientModel *_clientModel) +{ + this->clientModel = _clientModel; +} + +void ProposalDialog::setModel(WalletModel *_model) +{ + this->model = _model; +} + +void ProposalDialog::setAddress(const QString &address) +{ + ui->addressIn->setText(address); + ui->proposalIn->setFocus(); +} + +void ProposalDialog::on_addressBookButton_clicked() +{ + if (model && model->getAddressTableModel()) + { + AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); + dlg.setModel(model->getAddressTableModel()); + if (dlg.exec()) + { + setAddress(dlg.getReturnValue()); + } + } +} + +void ProposalDialog::on_pasteButton_clicked() +{ + setAddress(QApplication::clipboard()->text()); +} + +void ProposalDialog::on_submitButton_clicked() +{ + if (!clientModel) return; + if (!model) return; + + CTxDestination destination = DecodeDestination(ui->addressIn->text().toStdString()); + if (!IsValidDestination(destination)) { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); + return; + } + + QUrl url(QUrl::fromUserInput(ui->urlIn->text())); + if (!url.isValid()) { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("The entered URL is invalid.") + QString(" ") + tr("Please check the URL and try again.")); + return; + } + + ui->urlIn->setText(url.toDisplayString(QUrl::FullyDecoded)); + + QDate date(ui->dateEdit->date()); + QDateTime dt = QDateTime::fromString(date.toString() + " 00:00:00"); + int64_t startEpoch = dt.toTime_t(); + int64_t endEpoch = startEpoch + ui->spinBox->value() * Params().GetConsensus().nSuperblockCycle * Params().GetConsensus().nPowTargetSpacing; + + CAmount amount = 0; + std::string errRet = ""; + std::string name = ui->proposalIn->toPlainText().toStdString(); + + for (size_t i = 0; i < name.length(); i++){ + if (isspace(name[i])) name[i] = '_'; + } + + + std::string data = "[[\"proposal\",{\"end_epoch\":" + std::to_string(endEpoch) + + ",\"name\":\"" + name + + "\",\"payment_address\":\"" + ui->addressIn->text().toStdString() + + "\",\"payment_amount\":" + std::to_string(ui->amountIn->value() / COIN) + + ",\"start_epoch\":" + std::to_string(startEpoch) + + ",\"type\":1,\"url\":\"" + url.toDisplayString(QUrl::FullyDecoded).toStdString() + + "\"}]]"; + + uint256 hash = clientModel->node().validateProposal(data, uint256(), amount, errRet); + + if (hash == uint256()) { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("The entered Proposal is invalid: ") + QString::fromStdString(errRet)); + return; + } + + WalletModel::UnlockContext ctx(model->requestUnlock()); + if (!ctx.isValid()) + { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("Wallet unlock was cancelled.")); + return; + } + + QList recipients; + // prepare transaction for getting txFee earlier + WalletModelTransaction currentTransaction(recipients); + WalletModel::SendCoinsReturn prepareStatus; + + // Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled + CCoinControl ctrl; + if (model->getOptionsModel()->getCoinControlFeatures()) + ctrl = *CoinControlDialog::coinControl(); + + prepareStatus = model->prepareCollateral(currentTransaction, ctrl, hash, amount); + + // process prepareStatus and on error generate message shown to user + processSendCoinsReturn(prepareStatus, + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); + + if(prepareStatus.status != WalletModel::OK) { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("Error creating collateral transaction. Please check your wallet balance and make sure your wallet is unlocked.")); + return; + } + + // now send the prepared transaction + WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); + // process sendStatus and on error generate message shown to user + processSendCoinsReturn(sendStatus); + + if (sendStatus.status == WalletModel::OK) { + CoinControlDialog::coinControl()->UnSelectAll(); + Q_EMIT coinsSent(currentTransaction.getWtx()->get().GetHash()); + } + + // and finalize our proposal + hash = clientModel->node().validateProposal(data, currentTransaction.getWtx()->get().GetHash(), amount, errRet); + + if(hash == uint256()) { + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("Error creating collateral proposal: ") + QString::fromStdString(errRet)); + return; + } + + ui->statusLabel->setStyleSheet("QLabel { color: green; }"); + ui->statusLabel->setText(QString("") + tr("Proposal OK, Hash: ") + QString::fromStdString(hash.ToString()) + QString("")); + + ui->addressIn->setPlaceholderText(ui->addressIn->text()); + ui->urlIn->setPlaceholderText(url.toDisplayString(QUrl::FullyDecoded)); + ui->proposalIn->setPlaceholderText(ui->proposalIn->toPlainText()); + + ui->addressIn->clear(); + ui->urlIn->clear(); + ui->proposalIn->clear(); + ui->amountIn->clear(); + + ui->addressIn->setFocus(); +} + +void ProposalDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) +{ + QPair msgParams; + // Default to a warning message, override if error message is needed + msgParams.second = CClientUIInterface::MSG_WARNING; + + // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. + // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() + // all others are used only in WalletModel::prepareTransaction() + switch(sendCoinsReturn.status) + { + case WalletModel::InvalidAddress: + msgParams.first = tr("The recipient address is not valid. Please recheck."); + break; + case WalletModel::InvalidAmount: + msgParams.first = tr("The amount to pay must be larger than 0."); + break; + case WalletModel::AmountExceedsBalance: + msgParams.first = tr("The amount exceeds your balance."); + break; + case WalletModel::AmountWithFeeExceedsBalance: + msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); + break; + case WalletModel::DuplicateAddress: + msgParams.first = tr("Duplicate address found: addresses should only be used once each."); + break; + case WalletModel::TransactionCreationFailed: + msgParams.first = tr("Transaction creation failed!"); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::TransactionCommitFailed: + msgParams.first = tr("The transaction was rejected with the following reason: %1").arg(sendCoinsReturn.reasonCommitFailed); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::AbsurdFee: + msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->node().getMaxTxFee())); + break; + case WalletModel::PaymentRequestExpired: + msgParams.first = tr("Payment request expired."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + // included to prevent a compiler warning. + case WalletModel::OK: + default: + return; + } + + Q_EMIT message(tr("Send Collateral"), msgParams.first, msgParams.second); +} + +void ProposalDialog::on_clearButton_clicked() +{ + ui->addressIn->clear(); + ui->urlIn->clear(); + ui->proposalIn->clear(); + ui->amountIn->clear(); + ui->statusLabel->clear(); + + ui->addressIn->setFocus(); +} + +// close button +void ProposalDialog::on_closeButton_clicked(QAbstractButton *button) +{ + if (ui->closeButton->buttonRole(button) == QDialogButtonBox::RejectRole) + done(QDialog::Accepted); // closes the dialog +} + +void ProposalDialog::on_proposalIn_textChanged() +{ + if(ui->proposalIn->toPlainText().length() > MAX_DATA_SIZE) + { + int diff = ui->proposalIn->toPlainText().length() - MAX_DATA_SIZE; + QString newStr = ui->proposalIn->toPlainText(); + newStr.chop(diff); + ui->proposalIn->setPlainText(newStr); + QTextCursor cursor(ui->proposalIn->textCursor()); + cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); + ui->proposalIn->setTextCursor(cursor); + } +} From 7f277434a5a1cd2416787ab5bbecc9f359895ffb Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:44:51 -0400 Subject: [PATCH 1183/1324] Create proposaldialog.h --- src/qt/proposaldialog.h | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/qt/proposaldialog.h diff --git a/src/qt/proposaldialog.h b/src/qt/proposaldialog.h new file mode 100644 index 00000000..ba7b5138 --- /dev/null +++ b/src/qt/proposaldialog.h @@ -0,0 +1,53 @@ +// Copyright (c) 2019 PM-Tech +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_PROPOSALDIALOG_H +#define BITCOIN_QT_PROPOSALDIALOG_H + +#include + +#include +#include + +class ClientModel; +class PlatformStyle; + +namespace Ui { + class ProposalDialog; +} + +class ProposalDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProposalDialog(const PlatformStyle *platformStyle, QWidget *parent); + ~ProposalDialog(); + + void setClientModel(ClientModel *_clientModel); + void setModel(WalletModel *_model); + void setAddress(const QString &address); + +private: + Ui::ProposalDialog *ui; + ClientModel *clientModel; + WalletModel *model; + const PlatformStyle *platformStyle; + void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString()); + +private Q_SLOTS: + void on_addressBookButton_clicked(); + void on_pasteButton_clicked(); + void on_submitButton_clicked(); + void on_clearButton_clicked(); + void on_closeButton_clicked(QAbstractButton* button); + void on_proposalIn_textChanged(); + +Q_SIGNALS: + // Fired when a message should be reported to the user + void message(const QString &title, const QString &message, unsigned int style); + void coinsSent(const uint256& txid); +}; + +#endif // BITCOIN_QT_PROPOSALDIALOG_H From 2bca2953ad019af4cf5e6350c7f96662464f6505 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:45:41 -0400 Subject: [PATCH 1184/1324] Create proposaldialog.ui --- src/qt/forms/proposaldialog.ui | 247 +++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 src/qt/forms/proposaldialog.ui diff --git a/src/qt/forms/proposaldialog.ui b/src/qt/forms/proposaldialog.ui new file mode 100644 index 00000000..3a56a27a --- /dev/null +++ b/src/qt/forms/proposaldialog.ui @@ -0,0 +1,247 @@ + + + ProposalDialog + + + + 0 + 0 + 700 + 380 + + + + Proposal Generator - Submit Proposal + + + true + + + + + + Please enter your proposal details below. NOTE: Successfully submitting the data will result in a transaction of 50 CHC being created and sent automatically. + + + Qt::PlainText + + + true + + + + + + + 0 + + + + + The Chaincoin address to sign the message with + + + + + + + + + + + + + Choose previously used address + + + + + + + :/icons/green/address-book:/icons/green/address-book + + + Alt+A + + + false + + + + + + + Paste address from clipboard + + + + + + Alt+P + + + false + + + + + + + + + Enter valid URL (https://chaincoin.org, www.example.com) + + + + + + + + + + Enter description (256 characters max) + + + + + + + + + Amount: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Payment date (earliest): + + + + + + + true + + + + + + + Payments: + + + + + + + 1 + + + 12 + + + + + + + + + + + Validate and submit data + + + Submit + + + false + + + + + + + Reset all sign message fields + + + Clear &All + + + false + + + + + + + + 75 + true + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 48 + + + + + + + + QDialogButtonBox::Close + + + + + + + + + + QValidatedLineEdit + QLineEdit +
qt/qvalidatedlineedit.h
+
+ + BitcoinAmountField + QLineEdit +
qt/bitcoinamountfield.h
+ 1 +
+
+ + +
From a85d4ebc32052736005528bda274536c2ba479d5 Mon Sep 17 00:00:00 2001 From: devilking6105 <43361618+devilking6105@users.noreply.github.com> Date: Sun, 5 Jul 2020 23:46:29 -0400 Subject: [PATCH 1185/1324] Create key_io.cpp --- src/key_io.cpp | 229 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 src/key_io.cpp diff --git a/src/key_io.cpp b/src/key_io.cpp new file mode 100644 index 00000000..bc154f3a --- /dev/null +++ b/src/key_io.cpp @@ -0,0 +1,229 @@ +// Copyright (c) 2014-2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include